]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.8.2-201303072205.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.2-201303072205.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..0afd461 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,13 @@ 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 pcbit= [HW,ISDN]
254
255 pcd. [PARIDE]
256 diff --git a/Makefile b/Makefile
257 index 20d5318..d5cec9c 100644
258 --- a/Makefile
259 +++ b/Makefile
260 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
261
262 HOSTCC = gcc
263 HOSTCXX = g++
264 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
265 -HOSTCXXFLAGS = -O2
266 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
267 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
268 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
269
270 # Decide whether to build built-in, modular, or both.
271 # Normally, just do built-in.
272 @@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
273 # Rules shared between *config targets and build targets
274
275 # Basic helpers built in scripts/
276 -PHONY += scripts_basic
277 -scripts_basic:
278 +PHONY += scripts_basic gcc-plugins
279 +scripts_basic: gcc-plugins
280 $(Q)$(MAKE) $(build)=scripts/basic
281 $(Q)rm -f .tmp_quiet_recordmcount
282
283 @@ -575,6 +576,62 @@ else
284 KBUILD_CFLAGS += -O2
285 endif
286
287 +ifndef DISABLE_PAX_PLUGINS
288 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
289 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
290 +else
291 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
292 +endif
293 +ifneq ($(PLUGINCC),)
294 +ifndef CONFIG_UML
295 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
296 +endif
297 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
298 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
299 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
300 +endif
301 +ifdef CONFIG_KALLOCSTAT_PLUGIN
302 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
303 +endif
304 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
305 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
306 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
307 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
308 +endif
309 +ifdef CONFIG_CHECKER_PLUGIN
310 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
311 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
312 +endif
313 +endif
314 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
315 +ifdef CONFIG_PAX_SIZE_OVERFLOW
316 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
317 +endif
318 +ifdef CONFIG_PAX_LATENT_ENTROPY
319 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
320 +endif
321 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
322 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
323 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
324 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
325 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
326 +ifeq ($(KBUILD_EXTMOD),)
327 +gcc-plugins:
328 + $(Q)$(MAKE) $(build)=tools/gcc
329 +else
330 +gcc-plugins: ;
331 +endif
332 +else
333 +gcc-plugins:
334 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
335 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
336 +else
337 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
338 +endif
339 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
340 +endif
341 +endif
342 +
343 include $(srctree)/arch/$(SRCARCH)/Makefile
344
345 ifdef CONFIG_READABLE_ASM
346 @@ -731,7 +788,7 @@ export mod_sign_cmd
347
348
349 ifeq ($(KBUILD_EXTMOD),)
350 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
351 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
352
353 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
354 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
355 @@ -778,6 +835,8 @@ endif
356
357 # The actual objects are generated when descending,
358 # make sure no implicit rule kicks in
359 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
360 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
361 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
362
363 # Handle descending into subdirectories listed in $(vmlinux-dirs)
364 @@ -787,7 +846,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
365 # Error messages still appears in the original language
366
367 PHONY += $(vmlinux-dirs)
368 -$(vmlinux-dirs): prepare scripts
369 +$(vmlinux-dirs): gcc-plugins prepare scripts
370 $(Q)$(MAKE) $(build)=$@
371
372 # Store (new) KERNELRELASE string in include/config/kernel.release
373 @@ -831,6 +890,7 @@ prepare0: archprepare FORCE
374 $(Q)$(MAKE) $(build)=.
375
376 # All the preparing..
377 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
378 prepare: prepare0
379
380 # Generate some files
381 @@ -938,6 +998,8 @@ all: modules
382 # using awk while concatenating to the final file.
383
384 PHONY += modules
385 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
386 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
387 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
388 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
389 @$(kecho) ' Building modules, stage 2.';
390 @@ -953,7 +1015,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
391
392 # Target to prepare building external modules
393 PHONY += modules_prepare
394 -modules_prepare: prepare scripts
395 +modules_prepare: gcc-plugins prepare scripts
396
397 # Target to install modules
398 PHONY += modules_install
399 @@ -1019,7 +1081,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
400 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
401 signing_key.priv signing_key.x509 x509.genkey \
402 extra_certificates signing_key.x509.keyid \
403 - signing_key.x509.signer
404 + signing_key.x509.signer tools/gcc/size_overflow_hash.h
405
406 # clean - Delete most, but leave enough to build external modules
407 #
408 @@ -1059,6 +1121,7 @@ distclean: mrproper
409 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
410 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
411 -o -name '.*.rej' \
412 + -o -name '.*.rej' -o -name '*.so' \
413 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
414 -type f -print | xargs rm -f
415
416 @@ -1219,6 +1282,8 @@ PHONY += $(module-dirs) modules
417 $(module-dirs): crmodverdir $(objtree)/Module.symvers
418 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
419
420 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 modules: $(module-dirs)
423 @$(kecho) ' Building modules, stage 2.';
424 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
425 @@ -1355,17 +1420,21 @@ else
426 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
427 endif
428
429 -%.s: %.c prepare scripts FORCE
430 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
431 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
432 +%.s: %.c gcc-plugins prepare scripts FORCE
433 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
434 %.i: %.c prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 -%.o: %.c prepare scripts FORCE
437 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
438 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
439 +%.o: %.c gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 %.lst: %.c prepare scripts FORCE
442 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
443 -%.s: %.S prepare scripts FORCE
444 +%.s: %.S gcc-plugins prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 -%.o: %.S prepare scripts FORCE
447 +%.o: %.S gcc-plugins prepare scripts FORCE
448 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
449 %.symtypes: %.c prepare scripts FORCE
450 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
451 @@ -1375,11 +1444,15 @@ endif
452 $(cmd_crmodverdir)
453 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
454 $(build)=$(build-dir)
455 -%/: prepare scripts FORCE
456 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
457 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
458 +%/: gcc-plugins prepare scripts FORCE
459 $(cmd_crmodverdir)
460 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
461 $(build)=$(build-dir)
462 -%.ko: prepare scripts FORCE
463 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
464 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
465 +%.ko: gcc-plugins prepare scripts FORCE
466 $(cmd_crmodverdir)
467 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
468 $(build)=$(build-dir) $(@:.ko=.o)
469 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
470 index c2cbe4f..f7264b4 100644
471 --- a/arch/alpha/include/asm/atomic.h
472 +++ b/arch/alpha/include/asm/atomic.h
473 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
474 #define atomic_dec(v) atomic_sub(1,(v))
475 #define atomic64_dec(v) atomic64_sub(1,(v))
476
477 +#define atomic64_read_unchecked(v) atomic64_read(v)
478 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
479 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
480 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
481 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
482 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
483 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
484 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
485 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
486 +
487 #define smp_mb__before_atomic_dec() smp_mb()
488 #define smp_mb__after_atomic_dec() smp_mb()
489 #define smp_mb__before_atomic_inc() smp_mb()
490 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
491 index ad368a9..fbe0f25 100644
492 --- a/arch/alpha/include/asm/cache.h
493 +++ b/arch/alpha/include/asm/cache.h
494 @@ -4,19 +4,19 @@
495 #ifndef __ARCH_ALPHA_CACHE_H
496 #define __ARCH_ALPHA_CACHE_H
497
498 +#include <linux/const.h>
499
500 /* Bytes per L1 (data) cache line. */
501 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
502 -# define L1_CACHE_BYTES 64
503 # define L1_CACHE_SHIFT 6
504 #else
505 /* Both EV4 and EV5 are write-through, read-allocate,
506 direct-mapped, physical.
507 */
508 -# define L1_CACHE_BYTES 32
509 # define L1_CACHE_SHIFT 5
510 #endif
511
512 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
513 #define SMP_CACHE_BYTES L1_CACHE_BYTES
514
515 #endif
516 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
517 index 968d999..d36b2df 100644
518 --- a/arch/alpha/include/asm/elf.h
519 +++ b/arch/alpha/include/asm/elf.h
520 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
521
522 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
523
524 +#ifdef CONFIG_PAX_ASLR
525 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
526 +
527 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
528 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
529 +#endif
530 +
531 /* $0 is set by ld.so to a pointer to a function which might be
532 registered using atexit. This provides a mean for the dynamic
533 linker to call DT_FINI functions for shared libraries that have
534 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
535 index bc2a0da..8ad11ee 100644
536 --- a/arch/alpha/include/asm/pgalloc.h
537 +++ b/arch/alpha/include/asm/pgalloc.h
538 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 pgd_set(pgd, pmd);
540 }
541
542 +static inline void
543 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
544 +{
545 + pgd_populate(mm, pgd, pmd);
546 +}
547 +
548 extern pgd_t *pgd_alloc(struct mm_struct *mm);
549
550 static inline void
551 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
552 index 81a4342..348b927 100644
553 --- a/arch/alpha/include/asm/pgtable.h
554 +++ b/arch/alpha/include/asm/pgtable.h
555 @@ -102,6 +102,17 @@ struct vm_area_struct;
556 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
557 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
558 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
559 +
560 +#ifdef CONFIG_PAX_PAGEEXEC
561 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
562 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
563 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
564 +#else
565 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
566 +# define PAGE_COPY_NOEXEC PAGE_COPY
567 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
568 +#endif
569 +
570 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
571
572 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
573 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
574 index 2fd00b7..cfd5069 100644
575 --- a/arch/alpha/kernel/module.c
576 +++ b/arch/alpha/kernel/module.c
577 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
578
579 /* The small sections were sorted to the end of the segment.
580 The following should definitely cover them. */
581 - gp = (u64)me->module_core + me->core_size - 0x8000;
582 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
583 got = sechdrs[me->arch.gotsecindex].sh_addr;
584
585 for (i = 0; i < n; i++) {
586 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
587 index 14db93e..47bed62 100644
588 --- a/arch/alpha/kernel/osf_sys.c
589 +++ b/arch/alpha/kernel/osf_sys.c
590 @@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
591 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
592
593 static unsigned long
594 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
595 - unsigned long limit)
596 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
597 + unsigned long limit, unsigned long flags)
598 {
599 struct vm_area_struct *vma = find_vma(current->mm, addr);
600 -
601 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
602 while (1) {
603 /* At this point: (!vma || addr < vma->vm_end). */
604 if (limit - len < addr)
605 return -ENOMEM;
606 - if (!vma || addr + len <= vma->vm_start)
607 + if (check_heap_stack_gap(vma, addr, len, offset))
608 return addr;
609 addr = vma->vm_end;
610 vma = vma->vm_next;
611 @@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
612 merely specific addresses, but regions of memory -- perhaps
613 this feature should be incorporated into all ports? */
614
615 +#ifdef CONFIG_PAX_RANDMMAP
616 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
617 +#endif
618 +
619 if (addr) {
620 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
621 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
622 if (addr != (unsigned long) -ENOMEM)
623 return addr;
624 }
625
626 /* Next, try allocating at TASK_UNMAPPED_BASE. */
627 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
628 - len, limit);
629 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
630 +
631 if (addr != (unsigned long) -ENOMEM)
632 return addr;
633
634 /* Finally, try allocating in low memory. */
635 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
636 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
637
638 return addr;
639 }
640 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
641 index 0c4132d..88f0d53 100644
642 --- a/arch/alpha/mm/fault.c
643 +++ b/arch/alpha/mm/fault.c
644 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
645 __reload_thread(pcb);
646 }
647
648 +#ifdef CONFIG_PAX_PAGEEXEC
649 +/*
650 + * PaX: decide what to do with offenders (regs->pc = fault address)
651 + *
652 + * returns 1 when task should be killed
653 + * 2 when patched PLT trampoline was detected
654 + * 3 when unpatched PLT trampoline was detected
655 + */
656 +static int pax_handle_fetch_fault(struct pt_regs *regs)
657 +{
658 +
659 +#ifdef CONFIG_PAX_EMUPLT
660 + int err;
661 +
662 + do { /* PaX: patched PLT emulation #1 */
663 + unsigned int ldah, ldq, jmp;
664 +
665 + err = get_user(ldah, (unsigned int *)regs->pc);
666 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
667 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
668 +
669 + if (err)
670 + break;
671 +
672 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
673 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
674 + jmp == 0x6BFB0000U)
675 + {
676 + unsigned long r27, addr;
677 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
678 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
679 +
680 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
681 + err = get_user(r27, (unsigned long *)addr);
682 + if (err)
683 + break;
684 +
685 + regs->r27 = r27;
686 + regs->pc = r27;
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: patched PLT emulation #2 */
692 + unsigned int ldah, lda, br;
693 +
694 + err = get_user(ldah, (unsigned int *)regs->pc);
695 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
696 + err |= get_user(br, (unsigned int *)(regs->pc+8));
697 +
698 + if (err)
699 + break;
700 +
701 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
702 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
703 + (br & 0xFFE00000U) == 0xC3E00000U)
704 + {
705 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
706 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
707 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
708 +
709 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
710 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
711 + return 2;
712 + }
713 + } while (0);
714 +
715 + do { /* PaX: unpatched PLT emulation */
716 + unsigned int br;
717 +
718 + err = get_user(br, (unsigned int *)regs->pc);
719 +
720 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
721 + unsigned int br2, ldq, nop, jmp;
722 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
723 +
724 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
725 + err = get_user(br2, (unsigned int *)addr);
726 + err |= get_user(ldq, (unsigned int *)(addr+4));
727 + err |= get_user(nop, (unsigned int *)(addr+8));
728 + err |= get_user(jmp, (unsigned int *)(addr+12));
729 + err |= get_user(resolver, (unsigned long *)(addr+16));
730 +
731 + if (err)
732 + break;
733 +
734 + if (br2 == 0xC3600000U &&
735 + ldq == 0xA77B000CU &&
736 + nop == 0x47FF041FU &&
737 + jmp == 0x6B7B0000U)
738 + {
739 + regs->r28 = regs->pc+4;
740 + regs->r27 = addr+16;
741 + regs->pc = resolver;
742 + return 3;
743 + }
744 + }
745 + } while (0);
746 +#endif
747 +
748 + return 1;
749 +}
750 +
751 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
752 +{
753 + unsigned long i;
754 +
755 + printk(KERN_ERR "PAX: bytes at PC: ");
756 + for (i = 0; i < 5; i++) {
757 + unsigned int c;
758 + if (get_user(c, (unsigned int *)pc+i))
759 + printk(KERN_CONT "???????? ");
760 + else
761 + printk(KERN_CONT "%08x ", c);
762 + }
763 + printk("\n");
764 +}
765 +#endif
766
767 /*
768 * This routine handles page faults. It determines the address,
769 @@ -133,8 +251,29 @@ retry:
770 good_area:
771 si_code = SEGV_ACCERR;
772 if (cause < 0) {
773 - if (!(vma->vm_flags & VM_EXEC))
774 + if (!(vma->vm_flags & VM_EXEC)) {
775 +
776 +#ifdef CONFIG_PAX_PAGEEXEC
777 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
778 + goto bad_area;
779 +
780 + up_read(&mm->mmap_sem);
781 + switch (pax_handle_fetch_fault(regs)) {
782 +
783 +#ifdef CONFIG_PAX_EMUPLT
784 + case 2:
785 + case 3:
786 + return;
787 +#endif
788 +
789 + }
790 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
791 + do_group_exit(SIGKILL);
792 +#else
793 goto bad_area;
794 +#endif
795 +
796 + }
797 } else if (!cause) {
798 /* Allow reads even for write-only mappings */
799 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
800 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
801 index 67874b8..0e40765 100644
802 --- a/arch/arm/Kconfig
803 +++ b/arch/arm/Kconfig
804 @@ -1813,7 +1813,7 @@ config ALIGNMENT_TRAP
805
806 config UACCESS_WITH_MEMCPY
807 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
808 - depends on MMU
809 + depends on MMU && !PAX_MEMORY_UDEREF
810 default y if CPU_FEROCEON
811 help
812 Implement faster copy_to_user and clear_user methods for CPU
813 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
814 index c79f61f..9ac0642 100644
815 --- a/arch/arm/include/asm/atomic.h
816 +++ b/arch/arm/include/asm/atomic.h
817 @@ -17,17 +17,35 @@
818 #include <asm/barrier.h>
819 #include <asm/cmpxchg.h>
820
821 +#ifdef CONFIG_GENERIC_ATOMIC64
822 +#include <asm-generic/atomic64.h>
823 +#endif
824 +
825 #define ATOMIC_INIT(i) { (i) }
826
827 #ifdef __KERNEL__
828
829 +#define _ASM_EXTABLE(from, to) \
830 +" .pushsection __ex_table,\"a\"\n"\
831 +" .align 3\n" \
832 +" .long " #from ", " #to"\n" \
833 +" .popsection"
834 +
835 /*
836 * On ARM, ordinary assignment (str instruction) doesn't clear the local
837 * strex/ldrex monitor on some implementations. The reason we can use it for
838 * atomic_set() is the clrex or dummy strex done on every exception return.
839 */
840 #define atomic_read(v) (*(volatile int *)&(v)->counter)
841 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
842 +{
843 + return v->counter;
844 +}
845 #define atomic_set(v,i) (((v)->counter) = (i))
846 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
847 +{
848 + v->counter = i;
849 +}
850
851 #if __LINUX_ARM_ARCH__ >= 6
852
853 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
854 int result;
855
856 __asm__ __volatile__("@ atomic_add\n"
857 +"1: ldrex %1, [%3]\n"
858 +" adds %0, %1, %4\n"
859 +
860 +#ifdef CONFIG_PAX_REFCOUNT
861 +" bvc 3f\n"
862 +"2: bkpt 0xf103\n"
863 +"3:\n"
864 +#endif
865 +
866 +" strex %1, %0, [%3]\n"
867 +" teq %1, #0\n"
868 +" bne 1b"
869 +
870 +#ifdef CONFIG_PAX_REFCOUNT
871 +"\n4:\n"
872 + _ASM_EXTABLE(2b, 4b)
873 +#endif
874 +
875 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876 + : "r" (&v->counter), "Ir" (i)
877 + : "cc");
878 +}
879 +
880 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
881 +{
882 + unsigned long tmp;
883 + int result;
884 +
885 + __asm__ __volatile__("@ atomic_add_unchecked\n"
886 "1: ldrex %0, [%3]\n"
887 " add %0, %0, %4\n"
888 " strex %1, %0, [%3]\n"
889 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
890 smp_mb();
891
892 __asm__ __volatile__("@ atomic_add_return\n"
893 +"1: ldrex %1, [%3]\n"
894 +" adds %0, %1, %4\n"
895 +
896 +#ifdef CONFIG_PAX_REFCOUNT
897 +" bvc 3f\n"
898 +" mov %0, %1\n"
899 +"2: bkpt 0xf103\n"
900 +"3:\n"
901 +#endif
902 +
903 +" strex %1, %0, [%3]\n"
904 +" teq %1, #0\n"
905 +" bne 1b"
906 +
907 +#ifdef CONFIG_PAX_REFCOUNT
908 +"\n4:\n"
909 + _ASM_EXTABLE(2b, 4b)
910 +#endif
911 +
912 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
913 + : "r" (&v->counter), "Ir" (i)
914 + : "cc");
915 +
916 + smp_mb();
917 +
918 + return result;
919 +}
920 +
921 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
922 +{
923 + unsigned long tmp;
924 + int result;
925 +
926 + smp_mb();
927 +
928 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
929 "1: ldrex %0, [%3]\n"
930 " add %0, %0, %4\n"
931 " strex %1, %0, [%3]\n"
932 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
933 int result;
934
935 __asm__ __volatile__("@ atomic_sub\n"
936 +"1: ldrex %1, [%3]\n"
937 +" subs %0, %1, %4\n"
938 +
939 +#ifdef CONFIG_PAX_REFCOUNT
940 +" bvc 3f\n"
941 +"2: bkpt 0xf103\n"
942 +"3:\n"
943 +#endif
944 +
945 +" strex %1, %0, [%3]\n"
946 +" teq %1, #0\n"
947 +" bne 1b"
948 +
949 +#ifdef CONFIG_PAX_REFCOUNT
950 +"\n4:\n"
951 + _ASM_EXTABLE(2b, 4b)
952 +#endif
953 +
954 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
955 + : "r" (&v->counter), "Ir" (i)
956 + : "cc");
957 +}
958 +
959 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
960 +{
961 + unsigned long tmp;
962 + int result;
963 +
964 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
965 "1: ldrex %0, [%3]\n"
966 " sub %0, %0, %4\n"
967 " strex %1, %0, [%3]\n"
968 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
969 smp_mb();
970
971 __asm__ __volatile__("@ atomic_sub_return\n"
972 -"1: ldrex %0, [%3]\n"
973 -" sub %0, %0, %4\n"
974 +"1: ldrex %1, [%3]\n"
975 +" subs %0, %1, %4\n"
976 +
977 +#ifdef CONFIG_PAX_REFCOUNT
978 +" bvc 3f\n"
979 +" mov %0, %1\n"
980 +"2: bkpt 0xf103\n"
981 +"3:\n"
982 +#endif
983 +
984 " strex %1, %0, [%3]\n"
985 " teq %1, #0\n"
986 " bne 1b"
987 +
988 +#ifdef CONFIG_PAX_REFCOUNT
989 +"\n4:\n"
990 + _ASM_EXTABLE(2b, 4b)
991 +#endif
992 +
993 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
994 : "r" (&v->counter), "Ir" (i)
995 : "cc");
996 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
997 return oldval;
998 }
999
1000 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1001 +{
1002 + unsigned long oldval, res;
1003 +
1004 + smp_mb();
1005 +
1006 + do {
1007 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1008 + "ldrex %1, [%3]\n"
1009 + "mov %0, #0\n"
1010 + "teq %1, %4\n"
1011 + "strexeq %0, %5, [%3]\n"
1012 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1013 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1014 + : "cc");
1015 + } while (res);
1016 +
1017 + smp_mb();
1018 +
1019 + return oldval;
1020 +}
1021 +
1022 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1023 {
1024 unsigned long tmp, tmp2;
1025 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1026
1027 return val;
1028 }
1029 +
1030 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1031 +{
1032 + return atomic_add_return(i, v);
1033 +}
1034 +
1035 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1036 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1037 +{
1038 + (void) atomic_add_return(i, v);
1039 +}
1040
1041 static inline int atomic_sub_return(int i, atomic_t *v)
1042 {
1043 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1044 return val;
1045 }
1046 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1047 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1048 +{
1049 + (void) atomic_sub_return(i, v);
1050 +}
1051
1052 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1053 {
1054 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1055 return ret;
1056 }
1057
1058 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1059 +{
1060 + return atomic_cmpxchg(v, old, new);
1061 +}
1062 +
1063 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1064 {
1065 unsigned long flags;
1066 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1067 #endif /* __LINUX_ARM_ARCH__ */
1068
1069 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1070 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1071 +{
1072 + return xchg(&v->counter, new);
1073 +}
1074
1075 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1076 {
1077 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1078 }
1079
1080 #define atomic_inc(v) atomic_add(1, v)
1081 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1082 +{
1083 + atomic_add_unchecked(1, v);
1084 +}
1085 #define atomic_dec(v) atomic_sub(1, v)
1086 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1087 +{
1088 + atomic_sub_unchecked(1, v);
1089 +}
1090
1091 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1092 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1093 +{
1094 + return atomic_add_return_unchecked(1, v) == 0;
1095 +}
1096 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1097 #define atomic_inc_return(v) (atomic_add_return(1, v))
1098 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1099 +{
1100 + return atomic_add_return_unchecked(1, v);
1101 +}
1102 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1103 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1104
1105 @@ -241,6 +428,14 @@ typedef struct {
1106 u64 __aligned(8) counter;
1107 } atomic64_t;
1108
1109 +#ifdef CONFIG_PAX_REFCOUNT
1110 +typedef struct {
1111 + u64 __aligned(8) counter;
1112 +} atomic64_unchecked_t;
1113 +#else
1114 +typedef atomic64_t atomic64_unchecked_t;
1115 +#endif
1116 +
1117 #define ATOMIC64_INIT(i) { (i) }
1118
1119 static inline u64 atomic64_read(const atomic64_t *v)
1120 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1121 return result;
1122 }
1123
1124 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1125 +{
1126 + u64 result;
1127 +
1128 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1129 +" ldrexd %0, %H0, [%1]"
1130 + : "=&r" (result)
1131 + : "r" (&v->counter), "Qo" (v->counter)
1132 + );
1133 +
1134 + return result;
1135 +}
1136 +
1137 static inline void atomic64_set(atomic64_t *v, u64 i)
1138 {
1139 u64 tmp;
1140 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1141 : "cc");
1142 }
1143
1144 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1145 +{
1146 + u64 tmp;
1147 +
1148 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1149 +"1: ldrexd %0, %H0, [%2]\n"
1150 +" strexd %0, %3, %H3, [%2]\n"
1151 +" teq %0, #0\n"
1152 +" bne 1b"
1153 + : "=&r" (tmp), "=Qo" (v->counter)
1154 + : "r" (&v->counter), "r" (i)
1155 + : "cc");
1156 +}
1157 +
1158 static inline void atomic64_add(u64 i, atomic64_t *v)
1159 {
1160 u64 result;
1161 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162 __asm__ __volatile__("@ atomic64_add\n"
1163 "1: ldrexd %0, %H0, [%3]\n"
1164 " adds %0, %0, %4\n"
1165 +" adcs %H0, %H0, %H4\n"
1166 +
1167 +#ifdef CONFIG_PAX_REFCOUNT
1168 +" bvc 3f\n"
1169 +"2: bkpt 0xf103\n"
1170 +"3:\n"
1171 +#endif
1172 +
1173 +" strexd %1, %0, %H0, [%3]\n"
1174 +" teq %1, #0\n"
1175 +" bne 1b"
1176 +
1177 +#ifdef CONFIG_PAX_REFCOUNT
1178 +"\n4:\n"
1179 + _ASM_EXTABLE(2b, 4b)
1180 +#endif
1181 +
1182 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1183 + : "r" (&v->counter), "r" (i)
1184 + : "cc");
1185 +}
1186 +
1187 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1188 +{
1189 + u64 result;
1190 + unsigned long tmp;
1191 +
1192 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1193 +"1: ldrexd %0, %H0, [%3]\n"
1194 +" adds %0, %0, %4\n"
1195 " adc %H0, %H0, %H4\n"
1196 " strexd %1, %0, %H0, [%3]\n"
1197 " teq %1, #0\n"
1198 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1199
1200 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1201 {
1202 - u64 result;
1203 - unsigned long tmp;
1204 + u64 result, tmp;
1205
1206 smp_mb();
1207
1208 __asm__ __volatile__("@ atomic64_add_return\n"
1209 +"1: ldrexd %1, %H1, [%3]\n"
1210 +" adds %0, %1, %4\n"
1211 +" adcs %H0, %H1, %H4\n"
1212 +
1213 +#ifdef CONFIG_PAX_REFCOUNT
1214 +" bvc 3f\n"
1215 +" mov %0, %1\n"
1216 +" mov %H0, %H1\n"
1217 +"2: bkpt 0xf103\n"
1218 +"3:\n"
1219 +#endif
1220 +
1221 +" strexd %1, %0, %H0, [%3]\n"
1222 +" teq %1, #0\n"
1223 +" bne 1b"
1224 +
1225 +#ifdef CONFIG_PAX_REFCOUNT
1226 +"\n4:\n"
1227 + _ASM_EXTABLE(2b, 4b)
1228 +#endif
1229 +
1230 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1231 + : "r" (&v->counter), "r" (i)
1232 + : "cc");
1233 +
1234 + smp_mb();
1235 +
1236 + return result;
1237 +}
1238 +
1239 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1240 +{
1241 + u64 result;
1242 + unsigned long tmp;
1243 +
1244 + smp_mb();
1245 +
1246 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1247 "1: ldrexd %0, %H0, [%3]\n"
1248 " adds %0, %0, %4\n"
1249 " adc %H0, %H0, %H4\n"
1250 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251 __asm__ __volatile__("@ atomic64_sub\n"
1252 "1: ldrexd %0, %H0, [%3]\n"
1253 " subs %0, %0, %4\n"
1254 +" sbcs %H0, %H0, %H4\n"
1255 +
1256 +#ifdef CONFIG_PAX_REFCOUNT
1257 +" bvc 3f\n"
1258 +"2: bkpt 0xf103\n"
1259 +"3:\n"
1260 +#endif
1261 +
1262 +" strexd %1, %0, %H0, [%3]\n"
1263 +" teq %1, #0\n"
1264 +" bne 1b"
1265 +
1266 +#ifdef CONFIG_PAX_REFCOUNT
1267 +"\n4:\n"
1268 + _ASM_EXTABLE(2b, 4b)
1269 +#endif
1270 +
1271 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1272 + : "r" (&v->counter), "r" (i)
1273 + : "cc");
1274 +}
1275 +
1276 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1277 +{
1278 + u64 result;
1279 + unsigned long tmp;
1280 +
1281 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1282 +"1: ldrexd %0, %H0, [%3]\n"
1283 +" subs %0, %0, %4\n"
1284 " sbc %H0, %H0, %H4\n"
1285 " strexd %1, %0, %H0, [%3]\n"
1286 " teq %1, #0\n"
1287 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1288
1289 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1290 {
1291 - u64 result;
1292 - unsigned long tmp;
1293 + u64 result, tmp;
1294
1295 smp_mb();
1296
1297 __asm__ __volatile__("@ atomic64_sub_return\n"
1298 -"1: ldrexd %0, %H0, [%3]\n"
1299 -" subs %0, %0, %4\n"
1300 -" sbc %H0, %H0, %H4\n"
1301 +"1: ldrexd %1, %H1, [%3]\n"
1302 +" subs %0, %1, %4\n"
1303 +" sbcs %H0, %H1, %H4\n"
1304 +
1305 +#ifdef CONFIG_PAX_REFCOUNT
1306 +" bvc 3f\n"
1307 +" mov %0, %1\n"
1308 +" mov %H0, %H1\n"
1309 +"2: bkpt 0xf103\n"
1310 +"3:\n"
1311 +#endif
1312 +
1313 " strexd %1, %0, %H0, [%3]\n"
1314 " teq %1, #0\n"
1315 " bne 1b"
1316 +
1317 +#ifdef CONFIG_PAX_REFCOUNT
1318 +"\n4:\n"
1319 + _ASM_EXTABLE(2b, 4b)
1320 +#endif
1321 +
1322 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1323 : "r" (&v->counter), "r" (i)
1324 : "cc");
1325 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1326 return oldval;
1327 }
1328
1329 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1330 +{
1331 + u64 oldval;
1332 + unsigned long res;
1333 +
1334 + smp_mb();
1335 +
1336 + do {
1337 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1338 + "ldrexd %1, %H1, [%3]\n"
1339 + "mov %0, #0\n"
1340 + "teq %1, %4\n"
1341 + "teqeq %H1, %H4\n"
1342 + "strexdeq %0, %5, %H5, [%3]"
1343 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1344 + : "r" (&ptr->counter), "r" (old), "r" (new)
1345 + : "cc");
1346 + } while (res);
1347 +
1348 + smp_mb();
1349 +
1350 + return oldval;
1351 +}
1352 +
1353 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1354 {
1355 u64 result;
1356 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1357
1358 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1359 {
1360 - u64 result;
1361 - unsigned long tmp;
1362 + u64 result, tmp;
1363
1364 smp_mb();
1365
1366 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1367 -"1: ldrexd %0, %H0, [%3]\n"
1368 -" subs %0, %0, #1\n"
1369 -" sbc %H0, %H0, #0\n"
1370 +"1: ldrexd %1, %H1, [%3]\n"
1371 +" subs %0, %1, #1\n"
1372 +" sbcs %H0, %H1, #0\n"
1373 +
1374 +#ifdef CONFIG_PAX_REFCOUNT
1375 +" bvc 3f\n"
1376 +" mov %0, %1\n"
1377 +" mov %H0, %H1\n"
1378 +"2: bkpt 0xf103\n"
1379 +"3:\n"
1380 +#endif
1381 +
1382 " teq %H0, #0\n"
1383 -" bmi 2f\n"
1384 +" bmi 4f\n"
1385 " strexd %1, %0, %H0, [%3]\n"
1386 " teq %1, #0\n"
1387 " bne 1b\n"
1388 -"2:"
1389 +"4:\n"
1390 +
1391 +#ifdef CONFIG_PAX_REFCOUNT
1392 + _ASM_EXTABLE(2b, 4b)
1393 +#endif
1394 +
1395 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1396 : "r" (&v->counter)
1397 : "cc");
1398 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1399 " teq %0, %5\n"
1400 " teqeq %H0, %H5\n"
1401 " moveq %1, #0\n"
1402 -" beq 2f\n"
1403 +" beq 4f\n"
1404 " adds %0, %0, %6\n"
1405 -" adc %H0, %H0, %H6\n"
1406 +" adcs %H0, %H0, %H6\n"
1407 +
1408 +#ifdef CONFIG_PAX_REFCOUNT
1409 +" bvc 3f\n"
1410 +"2: bkpt 0xf103\n"
1411 +"3:\n"
1412 +#endif
1413 +
1414 " strexd %2, %0, %H0, [%4]\n"
1415 " teq %2, #0\n"
1416 " bne 1b\n"
1417 -"2:"
1418 +"4:\n"
1419 +
1420 +#ifdef CONFIG_PAX_REFCOUNT
1421 + _ASM_EXTABLE(2b, 4b)
1422 +#endif
1423 +
1424 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1425 : "r" (&v->counter), "r" (u), "r" (a)
1426 : "cc");
1427 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1428
1429 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1430 #define atomic64_inc(v) atomic64_add(1LL, (v))
1431 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1432 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1433 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1434 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1435 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1436 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1437 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1438 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1439 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1440 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1441 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1442 index 75fe66b..ba3dee4 100644
1443 --- a/arch/arm/include/asm/cache.h
1444 +++ b/arch/arm/include/asm/cache.h
1445 @@ -4,8 +4,10 @@
1446 #ifndef __ASMARM_CACHE_H
1447 #define __ASMARM_CACHE_H
1448
1449 +#include <linux/const.h>
1450 +
1451 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1452 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1453 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1454
1455 /*
1456 * Memory returned by kmalloc() may be used for DMA, so we must make
1457 @@ -24,5 +26,6 @@
1458 #endif
1459
1460 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1461 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1462
1463 #endif
1464 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1465 index e1489c5..d418304 100644
1466 --- a/arch/arm/include/asm/cacheflush.h
1467 +++ b/arch/arm/include/asm/cacheflush.h
1468 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1469 void (*dma_unmap_area)(const void *, size_t, int);
1470
1471 void (*dma_flush_range)(const void *, const void *);
1472 -};
1473 +} __no_const;
1474
1475 /*
1476 * Select the calling method
1477 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1478 index 6dcc164..b14d917 100644
1479 --- a/arch/arm/include/asm/checksum.h
1480 +++ b/arch/arm/include/asm/checksum.h
1481 @@ -37,7 +37,19 @@ __wsum
1482 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1483
1484 __wsum
1485 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1486 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1487 +
1488 +static inline __wsum
1489 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1490 +{
1491 + __wsum ret;
1492 + pax_open_userland();
1493 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1494 + pax_close_userland();
1495 + return ret;
1496 +}
1497 +
1498 +
1499
1500 /*
1501 * Fold a partial checksum without adding pseudo headers
1502 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1503 index 7eb18c1..e38b6d2 100644
1504 --- a/arch/arm/include/asm/cmpxchg.h
1505 +++ b/arch/arm/include/asm/cmpxchg.h
1506 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1507
1508 #define xchg(ptr,x) \
1509 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1510 +#define xchg_unchecked(ptr,x) \
1511 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1512
1513 #include <asm-generic/cmpxchg-local.h>
1514
1515 diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1516 index ab98fdd..6b19938 100644
1517 --- a/arch/arm/include/asm/delay.h
1518 +++ b/arch/arm/include/asm/delay.h
1519 @@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1520 void (*delay)(unsigned long);
1521 void (*const_udelay)(unsigned long);
1522 void (*udelay)(unsigned long);
1523 -} arm_delay_ops;
1524 +} *arm_delay_ops;
1525
1526 -#define __delay(n) arm_delay_ops.delay(n)
1527 +#define __delay(n) arm_delay_ops->delay(n)
1528
1529 /*
1530 * This function intentionally does not exist; if you see references to
1531 @@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1532 * first constant multiplications gets optimized away if the delay is
1533 * a constant)
1534 */
1535 -#define __udelay(n) arm_delay_ops.udelay(n)
1536 -#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1537 +#define __udelay(n) arm_delay_ops->udelay(n)
1538 +#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1539
1540 #define udelay(n) \
1541 (__builtin_constant_p(n) ? \
1542 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1543 index 6ddbe44..b5e38b1 100644
1544 --- a/arch/arm/include/asm/domain.h
1545 +++ b/arch/arm/include/asm/domain.h
1546 @@ -48,18 +48,37 @@
1547 * Domain types
1548 */
1549 #define DOMAIN_NOACCESS 0
1550 -#define DOMAIN_CLIENT 1
1551 #ifdef CONFIG_CPU_USE_DOMAINS
1552 +#define DOMAIN_USERCLIENT 1
1553 +#define DOMAIN_KERNELCLIENT 1
1554 #define DOMAIN_MANAGER 3
1555 +#define DOMAIN_VECTORS DOMAIN_USER
1556 #else
1557 +
1558 +#ifdef CONFIG_PAX_KERNEXEC
1559 #define DOMAIN_MANAGER 1
1560 +#define DOMAIN_KERNEXEC 3
1561 +#else
1562 +#define DOMAIN_MANAGER 1
1563 +#endif
1564 +
1565 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1566 +#define DOMAIN_USERCLIENT 0
1567 +#define DOMAIN_UDEREF 1
1568 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1569 +#else
1570 +#define DOMAIN_USERCLIENT 1
1571 +#define DOMAIN_VECTORS DOMAIN_USER
1572 +#endif
1573 +#define DOMAIN_KERNELCLIENT 1
1574 +
1575 #endif
1576
1577 #define domain_val(dom,type) ((type) << (2*(dom)))
1578
1579 #ifndef __ASSEMBLY__
1580
1581 -#ifdef CONFIG_CPU_USE_DOMAINS
1582 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1583 static inline void set_domain(unsigned val)
1584 {
1585 asm volatile(
1586 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1587 isb();
1588 }
1589
1590 -#define modify_domain(dom,type) \
1591 - do { \
1592 - struct thread_info *thread = current_thread_info(); \
1593 - unsigned int domain = thread->cpu_domain; \
1594 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1595 - thread->cpu_domain = domain | domain_val(dom, type); \
1596 - set_domain(thread->cpu_domain); \
1597 - } while (0)
1598 -
1599 +extern void modify_domain(unsigned int dom, unsigned int type);
1600 #else
1601 static inline void set_domain(unsigned val) { }
1602 static inline void modify_domain(unsigned dom, unsigned type) { }
1603 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1604 index 38050b1..9d90e8b 100644
1605 --- a/arch/arm/include/asm/elf.h
1606 +++ b/arch/arm/include/asm/elf.h
1607 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1608 the loader. We need to make sure that it is out of the way of the program
1609 that it will "exec", and that there is sufficient room for the brk. */
1610
1611 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1612 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1613 +
1614 +#ifdef CONFIG_PAX_ASLR
1615 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1616 +
1617 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1618 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1619 +#endif
1620
1621 /* When the program starts, a1 contains a pointer to a function to be
1622 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1623 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1624 extern void elf_set_personality(const struct elf32_hdr *);
1625 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1626
1627 -struct mm_struct;
1628 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1629 -#define arch_randomize_brk arch_randomize_brk
1630 -
1631 #endif
1632 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1633 index de53547..52b9a28 100644
1634 --- a/arch/arm/include/asm/fncpy.h
1635 +++ b/arch/arm/include/asm/fncpy.h
1636 @@ -81,7 +81,9 @@
1637 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1638 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1639 \
1640 + pax_open_kernel(); \
1641 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1642 + pax_close_kernel(); \
1643 flush_icache_range((unsigned long)(dest_buf), \
1644 (unsigned long)(dest_buf) + (size)); \
1645 \
1646 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1647 index e42cf59..7b94b8f 100644
1648 --- a/arch/arm/include/asm/futex.h
1649 +++ b/arch/arm/include/asm/futex.h
1650 @@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1651 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1652 return -EFAULT;
1653
1654 + pax_open_userland();
1655 +
1656 smp_mb();
1657 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1658 "1: ldrex %1, [%4]\n"
1659 @@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1660 : "cc", "memory");
1661 smp_mb();
1662
1663 + pax_close_userland();
1664 +
1665 *uval = val;
1666 return ret;
1667 }
1668 @@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1669 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1670 return -EFAULT;
1671
1672 + pax_open_userland();
1673 +
1674 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1675 "1: " TUSER(ldr) " %1, [%4]\n"
1676 " teq %1, %2\n"
1677 @@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1678 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1679 : "cc", "memory");
1680
1681 + pax_close_userland();
1682 +
1683 *uval = val;
1684 return ret;
1685 }
1686 @@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1687 return -EFAULT;
1688
1689 pagefault_disable(); /* implies preempt_disable() */
1690 + pax_open_userland();
1691
1692 switch (op) {
1693 case FUTEX_OP_SET:
1694 @@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1695 ret = -ENOSYS;
1696 }
1697
1698 + pax_close_userland();
1699 pagefault_enable(); /* subsumes preempt_enable() */
1700
1701 if (!ret) {
1702 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1703 index 83eb2f7..ed77159 100644
1704 --- a/arch/arm/include/asm/kmap_types.h
1705 +++ b/arch/arm/include/asm/kmap_types.h
1706 @@ -4,6 +4,6 @@
1707 /*
1708 * This is the "bare minimum". AIO seems to require this.
1709 */
1710 -#define KM_TYPE_NR 16
1711 +#define KM_TYPE_NR 17
1712
1713 #endif
1714 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1715 index 9e614a1..3302cca 100644
1716 --- a/arch/arm/include/asm/mach/dma.h
1717 +++ b/arch/arm/include/asm/mach/dma.h
1718 @@ -22,7 +22,7 @@ struct dma_ops {
1719 int (*residue)(unsigned int, dma_t *); /* optional */
1720 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1721 const char *type;
1722 -};
1723 +} __do_const;
1724
1725 struct dma_struct {
1726 void *addr; /* single DMA address */
1727 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1728 index 2fe141f..192dc01 100644
1729 --- a/arch/arm/include/asm/mach/map.h
1730 +++ b/arch/arm/include/asm/mach/map.h
1731 @@ -27,13 +27,16 @@ struct map_desc {
1732 #define MT_MINICLEAN 6
1733 #define MT_LOW_VECTORS 7
1734 #define MT_HIGH_VECTORS 8
1735 -#define MT_MEMORY 9
1736 +#define MT_MEMORY_RWX 9
1737 #define MT_ROM 10
1738 -#define MT_MEMORY_NONCACHED 11
1739 +#define MT_MEMORY_NONCACHED_RX 11
1740 #define MT_MEMORY_DTCM 12
1741 #define MT_MEMORY_ITCM 13
1742 #define MT_MEMORY_SO 14
1743 #define MT_MEMORY_DMA_READY 15
1744 +#define MT_MEMORY_RW 16
1745 +#define MT_MEMORY_RX 17
1746 +#define MT_MEMORY_NONCACHED_RW 18
1747
1748 #ifdef CONFIG_MMU
1749 extern void iotable_init(struct map_desc *, int);
1750 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1751 index 53426c6..c7baff3 100644
1752 --- a/arch/arm/include/asm/outercache.h
1753 +++ b/arch/arm/include/asm/outercache.h
1754 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1755 #endif
1756 void (*set_debug)(unsigned long);
1757 void (*resume)(void);
1758 -};
1759 +} __no_const;
1760
1761 #ifdef CONFIG_OUTER_CACHE
1762
1763 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1764 index 812a494..71fc0b6 100644
1765 --- a/arch/arm/include/asm/page.h
1766 +++ b/arch/arm/include/asm/page.h
1767 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1768 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1769 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1770 unsigned long vaddr, struct vm_area_struct *vma);
1771 -};
1772 +} __no_const;
1773
1774 #ifdef MULTI_USER
1775 extern struct cpu_user_fns cpu_user;
1776 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1777 index 943504f..c37a730 100644
1778 --- a/arch/arm/include/asm/pgalloc.h
1779 +++ b/arch/arm/include/asm/pgalloc.h
1780 @@ -17,6 +17,7 @@
1781 #include <asm/processor.h>
1782 #include <asm/cacheflush.h>
1783 #include <asm/tlbflush.h>
1784 +#include <asm/system_info.h>
1785
1786 #define check_pgt_cache() do { } while (0)
1787
1788 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1789 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1790 }
1791
1792 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1793 +{
1794 + pud_populate(mm, pud, pmd);
1795 +}
1796 +
1797 #else /* !CONFIG_ARM_LPAE */
1798
1799 /*
1800 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1801 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1802 #define pmd_free(mm, pmd) do { } while (0)
1803 #define pud_populate(mm,pmd,pte) BUG()
1804 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1805
1806 #endif /* CONFIG_ARM_LPAE */
1807
1808 @@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1809 __free_page(pte);
1810 }
1811
1812 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1813 +{
1814 +#ifdef CONFIG_ARM_LPAE
1815 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1816 +#else
1817 + if (addr & SECTION_SIZE)
1818 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1819 + else
1820 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1821 +#endif
1822 + flush_pmd_entry(pmdp);
1823 +}
1824 +
1825 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1826 pmdval_t prot)
1827 {
1828 @@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1829 static inline void
1830 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1831 {
1832 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1833 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1834 }
1835 #define pmd_pgtable(pmd) pmd_page(pmd)
1836
1837 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1838 index 5cfba15..f415e1a 100644
1839 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1840 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1841 @@ -20,12 +20,15 @@
1842 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1843 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1844 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1845 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1846 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1847 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1848 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1849 +
1850 /*
1851 * - section
1852 */
1853 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1854 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1855 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1856 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1857 @@ -37,6 +40,7 @@
1858 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1859 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1860 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1861 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1862
1863 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1864 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1865 @@ -66,6 +70,7 @@
1866 * - extended small page/tiny page
1867 */
1868 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1869 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1870 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1871 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1872 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1873 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1874 index f97ee02..07f1be5 100644
1875 --- a/arch/arm/include/asm/pgtable-2level.h
1876 +++ b/arch/arm/include/asm/pgtable-2level.h
1877 @@ -125,6 +125,7 @@
1878 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1879 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1880 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1881 +#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1882
1883 /*
1884 * These are the memory types, defined to be compatible with
1885 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1886 index d795282..a43ea90 100644
1887 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1888 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1889 @@ -32,15 +32,18 @@
1890 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1891 #define PMD_BIT4 (_AT(pmdval_t, 0))
1892 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1893 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1894
1895 /*
1896 * - section
1897 */
1898 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1899 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1900 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1901 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1902 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1903 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1904 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1905 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1906 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1907 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1908 @@ -66,6 +69,7 @@
1909 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1910 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1911 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1912 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1913 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1914
1915 /*
1916 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1917 index a3f3792..7b932a6 100644
1918 --- a/arch/arm/include/asm/pgtable-3level.h
1919 +++ b/arch/arm/include/asm/pgtable-3level.h
1920 @@ -74,6 +74,7 @@
1921 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1922 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1923 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1924 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1925 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1926 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1927 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1928 @@ -82,6 +83,7 @@
1929 /*
1930 * To be used in assembly code with the upper page attributes.
1931 */
1932 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1933 #define L_PTE_XN_HIGH (1 << (54 - 32))
1934 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1935
1936 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1937 index 9c82f988..514705a 100644
1938 --- a/arch/arm/include/asm/pgtable.h
1939 +++ b/arch/arm/include/asm/pgtable.h
1940 @@ -30,6 +30,9 @@
1941 #include <asm/pgtable-2level.h>
1942 #endif
1943
1944 +#define ktla_ktva(addr) (addr)
1945 +#define ktva_ktla(addr) (addr)
1946 +
1947 /*
1948 * Just any arbitrary offset to the start of the vmalloc VM area: the
1949 * current 8MB value just means that there will be a 8MB "hole" after the
1950 @@ -45,6 +48,9 @@
1951 #define LIBRARY_TEXT_START 0x0c000000
1952
1953 #ifndef __ASSEMBLY__
1954 +extern pteval_t __supported_pte_mask;
1955 +extern pmdval_t __supported_pmd_mask;
1956 +
1957 extern void __pte_error(const char *file, int line, pte_t);
1958 extern void __pmd_error(const char *file, int line, pmd_t);
1959 extern void __pgd_error(const char *file, int line, pgd_t);
1960 @@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1961 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1962 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1963
1964 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
1965 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1966 +
1967 +#ifdef CONFIG_PAX_KERNEXEC
1968 +#include <asm/domain.h>
1969 +#include <linux/thread_info.h>
1970 +#include <linux/preempt.h>
1971 +#endif
1972 +
1973 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1974 +static inline int test_domain(int domain, int domaintype)
1975 +{
1976 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
1977 +}
1978 +#endif
1979 +
1980 +#ifdef CONFIG_PAX_KERNEXEC
1981 +static inline unsigned long pax_open_kernel(void) {
1982 +#ifdef CONFIG_ARM_LPAE
1983 + /* TODO */
1984 +#else
1985 + preempt_disable();
1986 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
1987 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
1988 +#endif
1989 + return 0;
1990 +}
1991 +
1992 +static inline unsigned long pax_close_kernel(void) {
1993 +#ifdef CONFIG_ARM_LPAE
1994 + /* TODO */
1995 +#else
1996 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
1997 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
1998 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
1999 + preempt_enable_no_resched();
2000 +#endif
2001 + return 0;
2002 +}
2003 +#else
2004 +static inline unsigned long pax_open_kernel(void) { return 0; }
2005 +static inline unsigned long pax_close_kernel(void) { return 0; }
2006 +#endif
2007 +
2008 /*
2009 * This is the lowest virtual address we can permit any user space
2010 * mapping to be mapped at. This is particularly important for
2011 @@ -63,8 +113,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2012 /*
2013 * The pgprot_* and protection_map entries will be fixed up in runtime
2014 * to include the cachable and bufferable bits based on memory policy,
2015 - * as well as any architecture dependent bits like global/ASID and SMP
2016 - * shared mapping bits.
2017 + * as well as any architecture dependent bits like global/ASID, PXN,
2018 + * and SMP shared mapping bits.
2019 */
2020 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2021
2022 @@ -240,7 +290,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2023
2024 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2025 {
2026 - const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE;
2027 + const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE | __supported_pte_mask;
2028 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2029 return pte;
2030 }
2031 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2032 index f3628fb..a0672dd 100644
2033 --- a/arch/arm/include/asm/proc-fns.h
2034 +++ b/arch/arm/include/asm/proc-fns.h
2035 @@ -75,7 +75,7 @@ extern struct processor {
2036 unsigned int suspend_size;
2037 void (*do_suspend)(void *);
2038 void (*do_resume)(void *);
2039 -} processor;
2040 +} __do_const processor;
2041
2042 #ifndef MULTI_CPU
2043 extern void cpu_proc_init(void);
2044 diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2045 index 06e7d50..8a8e251 100644
2046 --- a/arch/arm/include/asm/processor.h
2047 +++ b/arch/arm/include/asm/processor.h
2048 @@ -65,9 +65,8 @@ struct thread_struct {
2049 regs->ARM_cpsr |= PSR_ENDSTATE; \
2050 regs->ARM_pc = pc & ~1; /* pc */ \
2051 regs->ARM_sp = sp; /* sp */ \
2052 - regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2053 - regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2054 - regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2055 + /* r2 (envp), r1 (argv), r0 (argc) */ \
2056 + (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2057 nommu_start_thread(regs); \
2058 })
2059
2060 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2061 index d3a22be..3a69ad5 100644
2062 --- a/arch/arm/include/asm/smp.h
2063 +++ b/arch/arm/include/asm/smp.h
2064 @@ -107,7 +107,7 @@ struct smp_operations {
2065 int (*cpu_disable)(unsigned int cpu);
2066 #endif
2067 #endif
2068 -};
2069 +} __no_const;
2070
2071 /*
2072 * set platform specific SMP operations
2073 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2074 index cddda1f..ff357f7 100644
2075 --- a/arch/arm/include/asm/thread_info.h
2076 +++ b/arch/arm/include/asm/thread_info.h
2077 @@ -77,9 +77,9 @@ struct thread_info {
2078 .flags = 0, \
2079 .preempt_count = INIT_PREEMPT_COUNT, \
2080 .addr_limit = KERNEL_DS, \
2081 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2082 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2083 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2084 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2085 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2086 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2087 .restart_block = { \
2088 .fn = do_no_restart_syscall, \
2089 }, \
2090 @@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2091 #define TIF_SYSCALL_AUDIT 9
2092 #define TIF_SYSCALL_TRACEPOINT 10
2093 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2094 +
2095 +/* within 8 bits of TIF_SYSCALL_TRACE
2096 + * to meet flexible second operand requirements
2097 + */
2098 +#define TIF_GRSEC_SETXID 12
2099 +
2100 #define TIF_USING_IWMMXT 17
2101 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2102 #define TIF_RESTORE_SIGMASK 20
2103 @@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2104 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2105 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2106 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2107 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2108
2109 /* Checks for any syscall work in entry-common.S */
2110 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2111 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2112 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2113
2114 /*
2115 * Change these and you break ASM code in entry-common.S
2116 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2117 index 7e1f760..752fcb7 100644
2118 --- a/arch/arm/include/asm/uaccess.h
2119 +++ b/arch/arm/include/asm/uaccess.h
2120 @@ -18,6 +18,7 @@
2121 #include <asm/domain.h>
2122 #include <asm/unified.h>
2123 #include <asm/compiler.h>
2124 +#include <asm/pgtable.h>
2125
2126 #define VERIFY_READ 0
2127 #define VERIFY_WRITE 1
2128 @@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2129 #define USER_DS TASK_SIZE
2130 #define get_fs() (current_thread_info()->addr_limit)
2131
2132 +static inline void pax_open_userland(void)
2133 +{
2134 +
2135 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2136 + if (get_fs() == USER_DS) {
2137 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2138 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2139 + }
2140 +#endif
2141 +
2142 +}
2143 +
2144 +static inline void pax_close_userland(void)
2145 +{
2146 +
2147 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2148 + if (get_fs() == USER_DS) {
2149 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2150 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2151 + }
2152 +#endif
2153 +
2154 +}
2155 +
2156 static inline void set_fs(mm_segment_t fs)
2157 {
2158 current_thread_info()->addr_limit = fs;
2159 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2160 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2161 }
2162
2163 #define segment_eq(a,b) ((a) == (b))
2164 @@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2165
2166 #define get_user(x,p) \
2167 ({ \
2168 + int __e; \
2169 might_fault(); \
2170 - __get_user_check(x,p); \
2171 + pax_open_userland(); \
2172 + __e = __get_user_check(x,p); \
2173 + pax_close_userland(); \
2174 + __e; \
2175 })
2176
2177 extern int __put_user_1(void *, unsigned int);
2178 @@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2179
2180 #define put_user(x,p) \
2181 ({ \
2182 + int __e; \
2183 might_fault(); \
2184 - __put_user_check(x,p); \
2185 + pax_open_userland(); \
2186 + __e = __put_user_check(x,p); \
2187 + pax_close_userland(); \
2188 + __e; \
2189 })
2190
2191 #else /* CONFIG_MMU */
2192 @@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2193 #define __get_user(x,ptr) \
2194 ({ \
2195 long __gu_err = 0; \
2196 + pax_open_userland(); \
2197 __get_user_err((x),(ptr),__gu_err); \
2198 + pax_close_userland(); \
2199 __gu_err; \
2200 })
2201
2202 #define __get_user_error(x,ptr,err) \
2203 ({ \
2204 + pax_open_userland(); \
2205 __get_user_err((x),(ptr),err); \
2206 + pax_close_userland(); \
2207 (void) 0; \
2208 })
2209
2210 @@ -312,13 +349,17 @@ do { \
2211 #define __put_user(x,ptr) \
2212 ({ \
2213 long __pu_err = 0; \
2214 + pax_open_userland(); \
2215 __put_user_err((x),(ptr),__pu_err); \
2216 + pax_close_userland(); \
2217 __pu_err; \
2218 })
2219
2220 #define __put_user_error(x,ptr,err) \
2221 ({ \
2222 + pax_open_userland(); \
2223 __put_user_err((x),(ptr),err); \
2224 + pax_close_userland(); \
2225 (void) 0; \
2226 })
2227
2228 @@ -418,11 +459,44 @@ do { \
2229
2230
2231 #ifdef CONFIG_MMU
2232 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2233 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2234 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2235 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2236 +
2237 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2238 +{
2239 + unsigned long ret;
2240 +
2241 + check_object_size(to, n, false);
2242 + pax_open_userland();
2243 + ret = ___copy_from_user(to, from, n);
2244 + pax_close_userland();
2245 + return ret;
2246 +}
2247 +
2248 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2249 +{
2250 + unsigned long ret;
2251 +
2252 + check_object_size(from, n, true);
2253 + pax_open_userland();
2254 + ret = ___copy_to_user(to, from, n);
2255 + pax_close_userland();
2256 + return ret;
2257 +}
2258 +
2259 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2260 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2261 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2262 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2263 +
2264 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2265 +{
2266 + unsigned long ret;
2267 + pax_open_userland();
2268 + ret = ___clear_user(addr, n);
2269 + pax_close_userland();
2270 + return ret;
2271 +}
2272 +
2273 #else
2274 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2275 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2276 @@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2277
2278 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2279 {
2280 + if ((long)n < 0)
2281 + return n;
2282 +
2283 if (access_ok(VERIFY_READ, from, n))
2284 n = __copy_from_user(to, from, n);
2285 else /* security hole - plug it */
2286 @@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2287
2288 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2289 {
2290 + if ((long)n < 0)
2291 + return n;
2292 +
2293 if (access_ok(VERIFY_WRITE, to, n))
2294 n = __copy_to_user(to, from, n);
2295 return n;
2296 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2297 index 96ee092..37f1844 100644
2298 --- a/arch/arm/include/uapi/asm/ptrace.h
2299 +++ b/arch/arm/include/uapi/asm/ptrace.h
2300 @@ -73,7 +73,7 @@
2301 * ARMv7 groups of PSR bits
2302 */
2303 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2304 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2305 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2306 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2307 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2308
2309 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2310 index 60d3b73..d27ee09 100644
2311 --- a/arch/arm/kernel/armksyms.c
2312 +++ b/arch/arm/kernel/armksyms.c
2313 @@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2314 #ifdef CONFIG_MMU
2315 EXPORT_SYMBOL(copy_page);
2316
2317 -EXPORT_SYMBOL(__copy_from_user);
2318 -EXPORT_SYMBOL(__copy_to_user);
2319 -EXPORT_SYMBOL(__clear_user);
2320 +EXPORT_SYMBOL(___copy_from_user);
2321 +EXPORT_SYMBOL(___copy_to_user);
2322 +EXPORT_SYMBOL(___clear_user);
2323
2324 EXPORT_SYMBOL(__get_user_1);
2325 EXPORT_SYMBOL(__get_user_2);
2326 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2327 index 0f82098..3dbd3ee 100644
2328 --- a/arch/arm/kernel/entry-armv.S
2329 +++ b/arch/arm/kernel/entry-armv.S
2330 @@ -47,6 +47,87 @@
2331 9997:
2332 .endm
2333
2334 + .macro pax_enter_kernel
2335 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2336 + @ make aligned space for saved DACR
2337 + sub sp, sp, #8
2338 + @ save regs
2339 + stmdb sp!, {r1, r2}
2340 + @ read DACR from cpu_domain into r1
2341 + mov r2, sp
2342 + @ assume 8K pages, since we have to split the immediate in two
2343 + bic r2, r2, #(0x1fc0)
2344 + bic r2, r2, #(0x3f)
2345 + ldr r1, [r2, #TI_CPU_DOMAIN]
2346 + @ store old DACR on stack
2347 + str r1, [sp, #8]
2348 +#ifdef CONFIG_PAX_KERNEXEC
2349 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2350 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2351 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2352 +#endif
2353 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2354 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2355 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2356 +#endif
2357 + @ write r1 to current_thread_info()->cpu_domain
2358 + str r1, [r2, #TI_CPU_DOMAIN]
2359 + @ write r1 to DACR
2360 + mcr p15, 0, r1, c3, c0, 0
2361 + @ instruction sync
2362 + instr_sync
2363 + @ restore regs
2364 + ldmia sp!, {r1, r2}
2365 +#endif
2366 + .endm
2367 +
2368 + .macro pax_open_userland
2369 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2370 + @ save regs
2371 + stmdb sp!, {r0, r1}
2372 + @ read DACR from cpu_domain into r1
2373 + mov r0, sp
2374 + @ assume 8K pages, since we have to split the immediate in two
2375 + bic r0, r0, #(0x1fc0)
2376 + bic r0, r0, #(0x3f)
2377 + ldr r1, [r0, #TI_CPU_DOMAIN]
2378 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2379 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2380 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2381 + @ write r1 to current_thread_info()->cpu_domain
2382 + str r1, [r0, #TI_CPU_DOMAIN]
2383 + @ write r1 to DACR
2384 + mcr p15, 0, r1, c3, c0, 0
2385 + @ instruction sync
2386 + instr_sync
2387 + @ restore regs
2388 + ldmia sp!, {r0, r1}
2389 +#endif
2390 + .endm
2391 +
2392 + .macro pax_close_userland
2393 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2394 + @ save regs
2395 + stmdb sp!, {r0, r1}
2396 + @ read DACR from cpu_domain into r1
2397 + mov r0, sp
2398 + @ assume 8K pages, since we have to split the immediate in two
2399 + bic r0, r0, #(0x1fc0)
2400 + bic r0, r0, #(0x3f)
2401 + ldr r1, [r0, #TI_CPU_DOMAIN]
2402 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2403 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2404 + @ write r1 to current_thread_info()->cpu_domain
2405 + str r1, [r0, #TI_CPU_DOMAIN]
2406 + @ write r1 to DACR
2407 + mcr p15, 0, r1, c3, c0, 0
2408 + @ instruction sync
2409 + instr_sync
2410 + @ restore regs
2411 + ldmia sp!, {r0, r1}
2412 +#endif
2413 + .endm
2414 +
2415 .macro pabt_helper
2416 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2417 #ifdef MULTI_PABORT
2418 @@ -89,11 +170,15 @@
2419 * Invalid mode handlers
2420 */
2421 .macro inv_entry, reason
2422 +
2423 + pax_enter_kernel
2424 +
2425 sub sp, sp, #S_FRAME_SIZE
2426 ARM( stmib sp, {r1 - lr} )
2427 THUMB( stmia sp, {r0 - r12} )
2428 THUMB( str sp, [sp, #S_SP] )
2429 THUMB( str lr, [sp, #S_LR] )
2430 +
2431 mov r1, #\reason
2432 .endm
2433
2434 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2435 .macro svc_entry, stack_hole=0
2436 UNWIND(.fnstart )
2437 UNWIND(.save {r0 - pc} )
2438 +
2439 + pax_enter_kernel
2440 +
2441 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2442 +
2443 #ifdef CONFIG_THUMB2_KERNEL
2444 SPFIX( str r0, [sp] ) @ temporarily saved
2445 SPFIX( mov r0, sp )
2446 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2447 ldmia r0, {r3 - r5}
2448 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2449 mov r6, #-1 @ "" "" "" ""
2450 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2451 + @ offset sp by 8 as done in pax_enter_kernel
2452 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2453 +#else
2454 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2455 +#endif
2456 SPFIX( addeq r2, r2, #4 )
2457 str r3, [sp, #-4]! @ save the "real" r0 copied
2458 @ from the exception stack
2459 @@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2460 .macro usr_entry
2461 UNWIND(.fnstart )
2462 UNWIND(.cantunwind ) @ don't unwind the user space
2463 +
2464 + pax_enter_kernel_user
2465 +
2466 sub sp, sp, #S_FRAME_SIZE
2467 ARM( stmib sp, {r1 - r12} )
2468 THUMB( stmia sp, {r0 - r12} )
2469 @@ -456,7 +553,9 @@ __und_usr:
2470 tst r3, #PSR_T_BIT @ Thumb mode?
2471 bne __und_usr_thumb
2472 sub r4, r2, #4 @ ARM instr at LR - 4
2473 + pax_open_userland
2474 1: ldrt r0, [r4]
2475 + pax_close_userland
2476 #ifdef CONFIG_CPU_ENDIAN_BE8
2477 rev r0, r0 @ little endian instruction
2478 #endif
2479 @@ -491,10 +590,14 @@ __und_usr_thumb:
2480 */
2481 .arch armv6t2
2482 #endif
2483 + pax_open_userland
2484 2: ldrht r5, [r4]
2485 + pax_close_userland
2486 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2487 blo __und_usr_fault_16 @ 16bit undefined instruction
2488 + pax_open_userland
2489 3: ldrht r0, [r2]
2490 + pax_close_userland
2491 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2492 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2493 orr r0, r0, r5, lsl #16
2494 @@ -733,7 +836,7 @@ ENTRY(__switch_to)
2495 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2496 THUMB( str sp, [ip], #4 )
2497 THUMB( str lr, [ip], #4 )
2498 -#ifdef CONFIG_CPU_USE_DOMAINS
2499 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2500 ldr r6, [r2, #TI_CPU_DOMAIN]
2501 #endif
2502 set_tls r3, r4, r5
2503 @@ -742,7 +845,7 @@ ENTRY(__switch_to)
2504 ldr r8, =__stack_chk_guard
2505 ldr r7, [r7, #TSK_STACK_CANARY]
2506 #endif
2507 -#ifdef CONFIG_CPU_USE_DOMAINS
2508 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2509 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2510 #endif
2511 mov r5, r0
2512 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2513 index a6c301e..908821b 100644
2514 --- a/arch/arm/kernel/entry-common.S
2515 +++ b/arch/arm/kernel/entry-common.S
2516 @@ -10,18 +10,46 @@
2517
2518 #include <asm/unistd.h>
2519 #include <asm/ftrace.h>
2520 +#include <asm/domain.h>
2521 #include <asm/unwind.h>
2522
2523 +#include "entry-header.S"
2524 +
2525 #ifdef CONFIG_NEED_RET_TO_USER
2526 #include <mach/entry-macro.S>
2527 #else
2528 .macro arch_ret_to_user, tmp1, tmp2
2529 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2530 + @ save regs
2531 + stmdb sp!, {r1, r2}
2532 + @ read DACR from cpu_domain into r1
2533 + mov r2, sp
2534 + @ assume 8K pages, since we have to split the immediate in two
2535 + bic r2, r2, #(0x1fc0)
2536 + bic r2, r2, #(0x3f)
2537 + ldr r1, [r2, #TI_CPU_DOMAIN]
2538 +#ifdef CONFIG_PAX_KERNEXEC
2539 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2540 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2541 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2542 +#endif
2543 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2544 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2545 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2546 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2547 +#endif
2548 + @ write r1 to current_thread_info()->cpu_domain
2549 + str r1, [r2, #TI_CPU_DOMAIN]
2550 + @ write r1 to DACR
2551 + mcr p15, 0, r1, c3, c0, 0
2552 + @ instruction sync
2553 + instr_sync
2554 + @ restore regs
2555 + ldmia sp!, {r1, r2}
2556 +#endif
2557 .endm
2558 #endif
2559
2560 -#include "entry-header.S"
2561 -
2562 -
2563 .align 5
2564 /*
2565 * This is the fast syscall return path. We do as little as
2566 @@ -339,6 +367,7 @@ ENDPROC(ftrace_stub)
2567
2568 .align 5
2569 ENTRY(vector_swi)
2570 +
2571 sub sp, sp, #S_FRAME_SIZE
2572 stmia sp, {r0 - r12} @ Calling r0 - r12
2573 ARM( add r8, sp, #S_PC )
2574 @@ -388,6 +417,12 @@ ENTRY(vector_swi)
2575 ldr scno, [lr, #-4] @ get SWI instruction
2576 #endif
2577
2578 + /*
2579 + * do this here to avoid a performance hit of wrapping the code above
2580 + * that directly dereferences userland to parse the SWI instruction
2581 + */
2582 + pax_enter_kernel_user
2583 +
2584 #ifdef CONFIG_ALIGNMENT_TRAP
2585 ldr ip, __cr_alignment
2586 ldr ip, [ip]
2587 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2588 index 9a8531e..812e287 100644
2589 --- a/arch/arm/kernel/entry-header.S
2590 +++ b/arch/arm/kernel/entry-header.S
2591 @@ -73,9 +73,66 @@
2592 msr cpsr_c, \rtemp @ switch back to the SVC mode
2593 .endm
2594
2595 + .macro pax_enter_kernel_user
2596 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2597 + @ save regs
2598 + stmdb sp!, {r0, r1}
2599 + @ read DACR from cpu_domain into r1
2600 + mov r0, sp
2601 + @ assume 8K pages, since we have to split the immediate in two
2602 + bic r0, r0, #(0x1fc0)
2603 + bic r0, r0, #(0x3f)
2604 + ldr r1, [r0, #TI_CPU_DOMAIN]
2605 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2606 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2607 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2608 +#endif
2609 +#ifdef CONFIG_PAX_KERNEXEC
2610 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2611 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2612 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2613 +#endif
2614 + @ write r1 to current_thread_info()->cpu_domain
2615 + str r1, [r0, #TI_CPU_DOMAIN]
2616 + @ write r1 to DACR
2617 + mcr p15, 0, r1, c3, c0, 0
2618 + @ instruction sync
2619 + instr_sync
2620 + @ restore regs
2621 + ldmia sp!, {r0, r1}
2622 +#endif
2623 + .endm
2624 +
2625 + .macro pax_exit_kernel
2626 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2627 + @ save regs
2628 + stmdb sp!, {r0, r1}
2629 + @ read old DACR from stack into r1
2630 + ldr r1, [sp, #(8 + S_SP)]
2631 + sub r1, r1, #8
2632 + ldr r1, [r1]
2633 +
2634 + @ write r1 to current_thread_info()->cpu_domain
2635 + mov r0, sp
2636 + @ assume 8K pages, since we have to split the immediate in two
2637 + bic r0, r0, #(0x1fc0)
2638 + bic r0, r0, #(0x3f)
2639 + str r1, [r0, #TI_CPU_DOMAIN]
2640 + @ write r1 to DACR
2641 + mcr p15, 0, r1, c3, c0, 0
2642 + @ instruction sync
2643 + instr_sync
2644 + @ restore regs
2645 + ldmia sp!, {r0, r1}
2646 +#endif
2647 + .endm
2648 +
2649 #ifndef CONFIG_THUMB2_KERNEL
2650 .macro svc_exit, rpsr
2651 msr spsr_cxsf, \rpsr
2652 +
2653 + pax_exit_kernel
2654 +
2655 #if defined(CONFIG_CPU_V6)
2656 ldr r0, [sp]
2657 strex r1, r2, [sp] @ clear the exclusive monitor
2658 @@ -121,6 +178,9 @@
2659 .endm
2660 #else /* CONFIG_THUMB2_KERNEL */
2661 .macro svc_exit, rpsr
2662 +
2663 + pax_exit_kernel
2664 +
2665 ldr lr, [sp, #S_SP] @ top of the stack
2666 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2667 clrex @ clear the exclusive monitor
2668 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2669 index 2adda11..7fbe958 100644
2670 --- a/arch/arm/kernel/fiq.c
2671 +++ b/arch/arm/kernel/fiq.c
2672 @@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2673 #if defined(CONFIG_CPU_USE_DOMAINS)
2674 memcpy((void *)0xffff001c, start, length);
2675 #else
2676 + pax_open_kernel();
2677 memcpy(vectors_page + 0x1c, start, length);
2678 + pax_close_kernel();
2679 #endif
2680 flush_icache_range(0xffff001c, 0xffff001c + length);
2681 if (!vectors_high())
2682 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2683 index 486a15a..2d6880e 100644
2684 --- a/arch/arm/kernel/head.S
2685 +++ b/arch/arm/kernel/head.S
2686 @@ -52,7 +52,9 @@
2687 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2688
2689 .macro pgtbl, rd, phys
2690 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2691 + mov \rd, #TEXT_OFFSET
2692 + sub \rd, #PG_DIR_SIZE
2693 + add \rd, \rd, \phys
2694 .endm
2695
2696 /*
2697 @@ -416,7 +418,7 @@ __enable_mmu:
2698 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2699 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2700 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2701 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2702 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2703 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2704 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2705 #endif
2706 diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2707 index 5ff2e77..556d030 100644
2708 --- a/arch/arm/kernel/hw_breakpoint.c
2709 +++ b/arch/arm/kernel/hw_breakpoint.c
2710 @@ -1011,7 +1011,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2711 return NOTIFY_OK;
2712 }
2713
2714 -static struct notifier_block __cpuinitdata dbg_reset_nb = {
2715 +static struct notifier_block dbg_reset_nb = {
2716 .notifier_call = dbg_reset_notify,
2717 };
2718
2719 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2720 index 1e9be5d..03edbc2 100644
2721 --- a/arch/arm/kernel/module.c
2722 +++ b/arch/arm/kernel/module.c
2723 @@ -37,12 +37,37 @@
2724 #endif
2725
2726 #ifdef CONFIG_MMU
2727 -void *module_alloc(unsigned long size)
2728 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2729 {
2730 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2731 + return NULL;
2732 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2733 - GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2734 + GFP_KERNEL, prot, -1,
2735 __builtin_return_address(0));
2736 }
2737 +
2738 +void *module_alloc(unsigned long size)
2739 +{
2740 +
2741 +#ifdef CONFIG_PAX_KERNEXEC
2742 + return __module_alloc(size, PAGE_KERNEL);
2743 +#else
2744 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2745 +#endif
2746 +
2747 +}
2748 +
2749 +#ifdef CONFIG_PAX_KERNEXEC
2750 +void module_free_exec(struct module *mod, void *module_region)
2751 +{
2752 + module_free(mod, module_region);
2753 +}
2754 +
2755 +void *module_alloc_exec(unsigned long size)
2756 +{
2757 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2758 +}
2759 +#endif
2760 #endif
2761
2762 int
2763 diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2764 index 5f66206..dce492f 100644
2765 --- a/arch/arm/kernel/perf_event_cpu.c
2766 +++ b/arch/arm/kernel/perf_event_cpu.c
2767 @@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2768 return NOTIFY_OK;
2769 }
2770
2771 -static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2772 +static struct notifier_block cpu_pmu_hotplug_notifier = {
2773 .notifier_call = cpu_pmu_notify,
2774 };
2775
2776 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2777 index c6dec5f..f853532 100644
2778 --- a/arch/arm/kernel/process.c
2779 +++ b/arch/arm/kernel/process.c
2780 @@ -28,7 +28,6 @@
2781 #include <linux/tick.h>
2782 #include <linux/utsname.h>
2783 #include <linux/uaccess.h>
2784 -#include <linux/random.h>
2785 #include <linux/hw_breakpoint.h>
2786 #include <linux/cpuidle.h>
2787 #include <linux/leds.h>
2788 @@ -256,9 +255,10 @@ void machine_power_off(void)
2789 machine_shutdown();
2790 if (pm_power_off)
2791 pm_power_off();
2792 + BUG();
2793 }
2794
2795 -void machine_restart(char *cmd)
2796 +__noreturn void machine_restart(char *cmd)
2797 {
2798 machine_shutdown();
2799
2800 @@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2801 init_utsname()->release,
2802 (int)strcspn(init_utsname()->version, " "),
2803 init_utsname()->version);
2804 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2805 - print_symbol("LR is at %s\n", regs->ARM_lr);
2806 + printk("PC is at %pA\n", instruction_pointer(regs));
2807 + printk("LR is at %pA\n", regs->ARM_lr);
2808 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2809 "sp : %08lx ip : %08lx fp : %08lx\n",
2810 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2811 @@ -452,12 +452,6 @@ unsigned long get_wchan(struct task_struct *p)
2812 return 0;
2813 }
2814
2815 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2816 -{
2817 - unsigned long range_end = mm->brk + 0x02000000;
2818 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2819 -}
2820 -
2821 #ifdef CONFIG_MMU
2822 /*
2823 * The vectors page is always readable from user space for the
2824 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2825 index 03deeff..741ce88 100644
2826 --- a/arch/arm/kernel/ptrace.c
2827 +++ b/arch/arm/kernel/ptrace.c
2828 @@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2829 return current_thread_info()->syscall;
2830 }
2831
2832 +#ifdef CONFIG_GRKERNSEC_SETXID
2833 +extern void gr_delayed_cred_worker(void);
2834 +#endif
2835 +
2836 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2837 {
2838 current_thread_info()->syscall = scno;
2839
2840 +#ifdef CONFIG_GRKERNSEC_SETXID
2841 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2842 + gr_delayed_cred_worker();
2843 +#endif
2844 +
2845 /* Do the secure computing check first; failures should be fast. */
2846 if (secure_computing(scno) == -1)
2847 return -1;
2848 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2849 index 3f6cbb2..6d856f5 100644
2850 --- a/arch/arm/kernel/setup.c
2851 +++ b/arch/arm/kernel/setup.c
2852 @@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2853 unsigned int elf_hwcap __read_mostly;
2854 EXPORT_SYMBOL(elf_hwcap);
2855
2856 +pteval_t __supported_pte_mask __read_only;
2857 +pmdval_t __supported_pmd_mask __read_only;
2858
2859 #ifdef MULTI_CPU
2860 -struct processor processor __read_mostly;
2861 +struct processor processor;
2862 #endif
2863 #ifdef MULTI_TLB
2864 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2865 +struct cpu_tlb_fns cpu_tlb __read_only;
2866 #endif
2867 #ifdef MULTI_USER
2868 -struct cpu_user_fns cpu_user __read_mostly;
2869 +struct cpu_user_fns cpu_user __read_only;
2870 #endif
2871 #ifdef MULTI_CACHE
2872 -struct cpu_cache_fns cpu_cache __read_mostly;
2873 +struct cpu_cache_fns cpu_cache __read_only;
2874 #endif
2875 #ifdef CONFIG_OUTER_CACHE
2876 -struct outer_cache_fns outer_cache __read_mostly;
2877 +struct outer_cache_fns outer_cache __read_only;
2878 EXPORT_SYMBOL(outer_cache);
2879 #endif
2880
2881 @@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2882 asm("mrc p15, 0, %0, c0, c1, 4"
2883 : "=r" (mmfr0));
2884 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2885 - (mmfr0 & 0x000000f0) >= 0x00000030)
2886 + (mmfr0 & 0x000000f0) >= 0x00000030) {
2887 cpu_arch = CPU_ARCH_ARMv7;
2888 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2889 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2890 + __supported_pte_mask |= L_PTE_PXN;
2891 + __supported_pmd_mask |= PMD_PXNTABLE;
2892 + }
2893 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2894 (mmfr0 & 0x000000f0) == 0x00000020)
2895 cpu_arch = CPU_ARCH_ARMv6;
2896 else
2897 @@ -462,7 +468,7 @@ static void __init setup_processor(void)
2898 __cpu_architecture = __get_cpu_architecture();
2899
2900 #ifdef MULTI_CPU
2901 - processor = *list->proc;
2902 + memcpy((void *)&processor, list->proc, sizeof processor);
2903 #endif
2904 #ifdef MULTI_TLB
2905 cpu_tlb = *list->tlb;
2906 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2907 index 84f4cbf..672f5b8 100644
2908 --- a/arch/arm/kernel/smp.c
2909 +++ b/arch/arm/kernel/smp.c
2910 @@ -70,7 +70,7 @@ enum ipi_msg_type {
2911
2912 static DECLARE_COMPLETION(cpu_running);
2913
2914 -static struct smp_operations smp_ops;
2915 +static struct smp_operations smp_ops __read_only;
2916
2917 void __init smp_set_ops(struct smp_operations *ops)
2918 {
2919 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2920 index b0179b8..b7b16c7 100644
2921 --- a/arch/arm/kernel/traps.c
2922 +++ b/arch/arm/kernel/traps.c
2923 @@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2924 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2925 {
2926 #ifdef CONFIG_KALLSYMS
2927 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2928 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2929 #else
2930 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2931 #endif
2932 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2933 static int die_owner = -1;
2934 static unsigned int die_nest_count;
2935
2936 +extern void gr_handle_kernel_exploit(void);
2937 +
2938 static unsigned long oops_begin(void)
2939 {
2940 int cpu;
2941 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2942 panic("Fatal exception in interrupt");
2943 if (panic_on_oops)
2944 panic("Fatal exception");
2945 +
2946 + gr_handle_kernel_exploit();
2947 +
2948 if (signr)
2949 do_exit(signr);
2950 }
2951 @@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
2952 * The user helper at 0xffff0fe0 must be used instead.
2953 * (see entry-armv.S for details)
2954 */
2955 + pax_open_kernel();
2956 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
2957 + pax_close_kernel();
2958 }
2959 return 0;
2960
2961 @@ -849,5 +856,9 @@ void __init early_trap_init(void *vectors_base)
2962 sigreturn_codes, sizeof(sigreturn_codes));
2963
2964 flush_icache_range(vectors, vectors + PAGE_SIZE);
2965 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
2966 +
2967 +#ifndef CONFIG_PAX_MEMORY_UDEREF
2968 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
2969 +#endif
2970 +
2971 }
2972 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2973 index 11c1785..c67d54c 100644
2974 --- a/arch/arm/kernel/vmlinux.lds.S
2975 +++ b/arch/arm/kernel/vmlinux.lds.S
2976 @@ -8,7 +8,11 @@
2977 #include <asm/thread_info.h>
2978 #include <asm/memory.h>
2979 #include <asm/page.h>
2980 -
2981 +
2982 +#ifdef CONFIG_PAX_KERNEXEC
2983 +#include <asm/pgtable.h>
2984 +#endif
2985 +
2986 #define PROC_INFO \
2987 . = ALIGN(4); \
2988 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2989 @@ -90,6 +94,11 @@ SECTIONS
2990 _text = .;
2991 HEAD_TEXT
2992 }
2993 +
2994 +#ifdef CONFIG_PAX_KERNEXEC
2995 + . = ALIGN(1<<SECTION_SHIFT);
2996 +#endif
2997 +
2998 .text : { /* Real text segment */
2999 _stext = .; /* Text and read-only data */
3000 __exception_text_start = .;
3001 @@ -144,6 +153,10 @@ SECTIONS
3002
3003 _etext = .; /* End of text and rodata section */
3004
3005 +#ifdef CONFIG_PAX_KERNEXEC
3006 + . = ALIGN(1<<SECTION_SHIFT);
3007 +#endif
3008 +
3009 #ifndef CONFIG_XIP_KERNEL
3010 . = ALIGN(PAGE_SIZE);
3011 __init_begin = .;
3012 @@ -203,6 +216,11 @@ SECTIONS
3013 . = PAGE_OFFSET + TEXT_OFFSET;
3014 #else
3015 __init_end = .;
3016 +
3017 +#ifdef CONFIG_PAX_KERNEXEC
3018 + . = ALIGN(1<<SECTION_SHIFT);
3019 +#endif
3020 +
3021 . = ALIGN(THREAD_SIZE);
3022 __data_loc = .;
3023 #endif
3024 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3025 index 14a0d98..7771a7d 100644
3026 --- a/arch/arm/lib/clear_user.S
3027 +++ b/arch/arm/lib/clear_user.S
3028 @@ -12,14 +12,14 @@
3029
3030 .text
3031
3032 -/* Prototype: int __clear_user(void *addr, size_t sz)
3033 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3034 * Purpose : clear some user memory
3035 * Params : addr - user memory address to clear
3036 * : sz - number of bytes to clear
3037 * Returns : number of bytes NOT cleared
3038 */
3039 ENTRY(__clear_user_std)
3040 -WEAK(__clear_user)
3041 +WEAK(___clear_user)
3042 stmfd sp!, {r1, lr}
3043 mov r2, #0
3044 cmp r1, #4
3045 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3046 USER( strnebt r2, [r0])
3047 mov r0, #0
3048 ldmfd sp!, {r1, pc}
3049 -ENDPROC(__clear_user)
3050 +ENDPROC(___clear_user)
3051 ENDPROC(__clear_user_std)
3052
3053 .pushsection .fixup,"ax"
3054 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3055 index 66a477a..bee61d3 100644
3056 --- a/arch/arm/lib/copy_from_user.S
3057 +++ b/arch/arm/lib/copy_from_user.S
3058 @@ -16,7 +16,7 @@
3059 /*
3060 * Prototype:
3061 *
3062 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3063 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3064 *
3065 * Purpose:
3066 *
3067 @@ -84,11 +84,11 @@
3068
3069 .text
3070
3071 -ENTRY(__copy_from_user)
3072 +ENTRY(___copy_from_user)
3073
3074 #include "copy_template.S"
3075
3076 -ENDPROC(__copy_from_user)
3077 +ENDPROC(___copy_from_user)
3078
3079 .pushsection .fixup,"ax"
3080 .align 0
3081 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3082 index 6ee2f67..d1cce76 100644
3083 --- a/arch/arm/lib/copy_page.S
3084 +++ b/arch/arm/lib/copy_page.S
3085 @@ -10,6 +10,7 @@
3086 * ASM optimised string functions
3087 */
3088 #include <linux/linkage.h>
3089 +#include <linux/const.h>
3090 #include <asm/assembler.h>
3091 #include <asm/asm-offsets.h>
3092 #include <asm/cache.h>
3093 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3094 index d066df6..df28194 100644
3095 --- a/arch/arm/lib/copy_to_user.S
3096 +++ b/arch/arm/lib/copy_to_user.S
3097 @@ -16,7 +16,7 @@
3098 /*
3099 * Prototype:
3100 *
3101 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3102 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3103 *
3104 * Purpose:
3105 *
3106 @@ -88,11 +88,11 @@
3107 .text
3108
3109 ENTRY(__copy_to_user_std)
3110 -WEAK(__copy_to_user)
3111 +WEAK(___copy_to_user)
3112
3113 #include "copy_template.S"
3114
3115 -ENDPROC(__copy_to_user)
3116 +ENDPROC(___copy_to_user)
3117 ENDPROC(__copy_to_user_std)
3118
3119 .pushsection .fixup,"ax"
3120 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3121 index 7d08b43..f7ca7ea 100644
3122 --- a/arch/arm/lib/csumpartialcopyuser.S
3123 +++ b/arch/arm/lib/csumpartialcopyuser.S
3124 @@ -57,8 +57,8 @@
3125 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3126 */
3127
3128 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3129 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3130 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3131 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3132
3133 #include "csumpartialcopygeneric.S"
3134
3135 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3136 index 0dc5385..45833ef 100644
3137 --- a/arch/arm/lib/delay.c
3138 +++ b/arch/arm/lib/delay.c
3139 @@ -28,12 +28,14 @@
3140 /*
3141 * Default to the loop-based delay implementation.
3142 */
3143 -struct arm_delay_ops arm_delay_ops = {
3144 +static struct arm_delay_ops arm_loop_delay_ops = {
3145 .delay = __loop_delay,
3146 .const_udelay = __loop_const_udelay,
3147 .udelay = __loop_udelay,
3148 };
3149
3150 +struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
3151 +
3152 static const struct delay_timer *delay_timer;
3153 static bool delay_calibrated;
3154
3155 @@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
3156 __timer_const_udelay(usecs * UDELAY_MULT);
3157 }
3158
3159 +static struct arm_delay_ops arm_timer_delay_ops = {
3160 + .delay = __timer_delay,
3161 + .const_udelay = __timer_const_udelay,
3162 + .udelay = __timer_udelay,
3163 +};
3164 +
3165 void __init register_current_timer_delay(const struct delay_timer *timer)
3166 {
3167 if (!delay_calibrated) {
3168 @@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
3169 delay_timer = timer;
3170 lpj_fine = timer->freq / HZ;
3171 loops_per_jiffy = lpj_fine;
3172 - arm_delay_ops.delay = __timer_delay;
3173 - arm_delay_ops.const_udelay = __timer_const_udelay;
3174 - arm_delay_ops.udelay = __timer_udelay;
3175 + arm_delay_ops = &arm_timer_delay_ops;
3176 delay_calibrated = true;
3177 } else {
3178 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
3179 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3180 index 025f742..8432b08 100644
3181 --- a/arch/arm/lib/uaccess_with_memcpy.c
3182 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3183 @@ -104,7 +104,7 @@ out:
3184 }
3185
3186 unsigned long
3187 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3188 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3189 {
3190 /*
3191 * This test is stubbed out of the main function above to keep
3192 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3193 index bac21a5..b67ef8e 100644
3194 --- a/arch/arm/mach-kirkwood/common.c
3195 +++ b/arch/arm/mach-kirkwood/common.c
3196 @@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3197 clk_gate_ops.disable(hw);
3198 }
3199
3200 -static struct clk_ops clk_gate_fn_ops;
3201 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3202 +{
3203 + return clk_gate_ops.is_enabled(hw);
3204 +}
3205 +
3206 +static struct clk_ops clk_gate_fn_ops = {
3207 + .enable = clk_gate_fn_enable,
3208 + .disable = clk_gate_fn_disable,
3209 + .is_enabled = clk_gate_fn_is_enabled,
3210 +};
3211
3212 static struct clk __init *clk_register_gate_fn(struct device *dev,
3213 const char *name,
3214 @@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3215 gate_fn->fn_en = fn_en;
3216 gate_fn->fn_dis = fn_dis;
3217
3218 - /* ops is the gate ops, but with our enable/disable functions */
3219 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3220 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3221 - clk_gate_fn_ops = clk_gate_ops;
3222 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3223 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3224 - }
3225 -
3226 clk = clk_register(dev, &gate_fn->gate.hw);
3227
3228 if (IS_ERR(clk))
3229 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3230 index 0abb30f..54064da 100644
3231 --- a/arch/arm/mach-omap2/board-n8x0.c
3232 +++ b/arch/arm/mach-omap2/board-n8x0.c
3233 @@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3234 }
3235 #endif
3236
3237 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3238 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3239 .late_init = n8x0_menelaus_late_init,
3240 };
3241
3242 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3243 index 5d3b4f4..ddba3c0 100644
3244 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3245 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3246 @@ -340,7 +340,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3247 return NOTIFY_OK;
3248 }
3249
3250 -static struct notifier_block __refdata irq_hotplug_notifier = {
3251 +static struct notifier_block irq_hotplug_notifier = {
3252 .notifier_call = irq_cpu_hotplug_notify,
3253 };
3254
3255 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3256 index 4653efb..8c60bf7 100644
3257 --- a/arch/arm/mach-omap2/omap_hwmod.c
3258 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3259 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
3260 int (*init_clkdm)(struct omap_hwmod *oh);
3261 void (*update_context_lost)(struct omap_hwmod *oh);
3262 int (*get_context_lost)(struct omap_hwmod *oh);
3263 -};
3264 +} __no_const;
3265
3266 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3267 -static struct omap_hwmod_soc_ops soc_ops;
3268 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3269
3270 /* omap_hwmod_list contains all registered struct omap_hwmods */
3271 static LIST_HEAD(omap_hwmod_list);
3272 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3273 index 7c2b4ed..b2ea51f 100644
3274 --- a/arch/arm/mach-omap2/wd_timer.c
3275 +++ b/arch/arm/mach-omap2/wd_timer.c
3276 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3277 struct omap_hwmod *oh;
3278 char *oh_name = "wd_timer2";
3279 char *dev_name = "omap_wdt";
3280 - struct omap_wd_timer_platform_data pdata;
3281 + static struct omap_wd_timer_platform_data pdata = {
3282 + .read_reset_sources = prm_read_reset_sources
3283 + };
3284
3285 if (!cpu_class_is_omap2() || of_have_populated_dt())
3286 return 0;
3287 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3288 return -EINVAL;
3289 }
3290
3291 - pdata.read_reset_sources = prm_read_reset_sources;
3292 -
3293 pdev = omap_device_build(dev_name, id, oh, &pdata,
3294 sizeof(struct omap_wd_timer_platform_data),
3295 NULL, 0, 0);
3296 diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3297 index 6be4c4d..32ac32a 100644
3298 --- a/arch/arm/mach-ux500/include/mach/setup.h
3299 +++ b/arch/arm/mach-ux500/include/mach/setup.h
3300 @@ -38,13 +38,6 @@ extern struct sys_timer ux500_timer;
3301 .type = MT_DEVICE, \
3302 }
3303
3304 -#define __MEM_DEV_DESC(x, sz) { \
3305 - .virtual = IO_ADDRESS(x), \
3306 - .pfn = __phys_to_pfn(x), \
3307 - .length = sz, \
3308 - .type = MT_MEMORY, \
3309 -}
3310 -
3311 extern struct smp_operations ux500_smp_ops;
3312 extern void ux500_cpu_die(unsigned int cpu);
3313
3314 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3315 index 3fd629d..8b1aca9 100644
3316 --- a/arch/arm/mm/Kconfig
3317 +++ b/arch/arm/mm/Kconfig
3318 @@ -425,7 +425,7 @@ config CPU_32v5
3319
3320 config CPU_32v6
3321 bool
3322 - select CPU_USE_DOMAINS if CPU_V6 && MMU
3323 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3324 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3325
3326 config CPU_32v6K
3327 @@ -577,6 +577,7 @@ config CPU_CP15_MPU
3328
3329 config CPU_USE_DOMAINS
3330 bool
3331 + depends on !ARM_LPAE && !PAX_KERNEXEC
3332 help
3333 This option enables or disables the use of domain switching
3334 via the set_fs() function.
3335 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3336 index 5dbf13f..6393f55 100644
3337 --- a/arch/arm/mm/fault.c
3338 +++ b/arch/arm/mm/fault.c
3339 @@ -25,6 +25,7 @@
3340 #include <asm/system_misc.h>
3341 #include <asm/system_info.h>
3342 #include <asm/tlbflush.h>
3343 +#include <asm/sections.h>
3344
3345 #include "fault.h"
3346
3347 @@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3348 if (fixup_exception(regs))
3349 return;
3350
3351 +#ifdef CONFIG_PAX_KERNEXEC
3352 + if ((fsr & FSR_WRITE) &&
3353 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3354 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3355 + {
3356 + if (current->signal->curr_ip)
3357 + 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),
3358 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3359 + else
3360 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3361 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3362 + }
3363 +#endif
3364 +
3365 /*
3366 * No handler, we'll have to terminate things with extreme prejudice.
3367 */
3368 @@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3369 }
3370 #endif
3371
3372 +#ifdef CONFIG_PAX_PAGEEXEC
3373 + if (fsr & FSR_LNX_PF) {
3374 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3375 + do_group_exit(SIGKILL);
3376 + }
3377 +#endif
3378 +
3379 tsk->thread.address = addr;
3380 tsk->thread.error_code = fsr;
3381 tsk->thread.trap_no = 14;
3382 @@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3383 }
3384 #endif /* CONFIG_MMU */
3385
3386 +#ifdef CONFIG_PAX_PAGEEXEC
3387 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3388 +{
3389 + long i;
3390 +
3391 + printk(KERN_ERR "PAX: bytes at PC: ");
3392 + for (i = 0; i < 20; i++) {
3393 + unsigned char c;
3394 + if (get_user(c, (__force unsigned char __user *)pc+i))
3395 + printk(KERN_CONT "?? ");
3396 + else
3397 + printk(KERN_CONT "%02x ", c);
3398 + }
3399 + printk("\n");
3400 +
3401 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3402 + for (i = -1; i < 20; i++) {
3403 + unsigned long c;
3404 + if (get_user(c, (__force unsigned long __user *)sp+i))
3405 + printk(KERN_CONT "???????? ");
3406 + else
3407 + printk(KERN_CONT "%08lx ", c);
3408 + }
3409 + printk("\n");
3410 +}
3411 +#endif
3412 +
3413 /*
3414 * First Level Translation Fault Handler
3415 *
3416 @@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3417 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3418 struct siginfo info;
3419
3420 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3421 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3422 + if (current->signal->curr_ip)
3423 + 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),
3424 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3425 + else
3426 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3427 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3428 + goto die;
3429 + }
3430 +#endif
3431 +
3432 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3433 return;
3434
3435 +die:
3436 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3437 inf->name, fsr, addr);
3438
3439 @@ -575,9 +637,38 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3440 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3441 struct siginfo info;
3442
3443 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3444 + if (!user_mode(regs) && (is_domain_fault(ifsr) || is_xn_fault(ifsr))) {
3445 + if (current->signal->curr_ip)
3446 + 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),
3447 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3448 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3449 + else
3450 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3451 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3452 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3453 + goto die;
3454 + }
3455 +#endif
3456 +
3457 +#ifdef CONFIG_PAX_REFCOUNT
3458 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3459 + unsigned int bkpt;
3460 +
3461 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3462 + current->thread.error_code = ifsr;
3463 + current->thread.trap_no = 0;
3464 + pax_report_refcount_overflow(regs);
3465 + fixup_exception(regs);
3466 + return;
3467 + }
3468 + }
3469 +#endif
3470 +
3471 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3472 return;
3473
3474 +die:
3475 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3476 inf->name, ifsr, addr);
3477
3478 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3479 index cf08bdf..772656c 100644
3480 --- a/arch/arm/mm/fault.h
3481 +++ b/arch/arm/mm/fault.h
3482 @@ -3,6 +3,7 @@
3483
3484 /*
3485 * Fault status register encodings. We steal bit 31 for our own purposes.
3486 + * Set when the FSR value is from an instruction fault.
3487 */
3488 #define FSR_LNX_PF (1 << 31)
3489 #define FSR_WRITE (1 << 11)
3490 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3491 }
3492 #endif
3493
3494 +/* valid for LPAE and !LPAE */
3495 +static inline int is_xn_fault(unsigned int fsr)
3496 +{
3497 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
3498 +}
3499 +
3500 +static inline int is_domain_fault(unsigned int fsr)
3501 +{
3502 + return ((fsr_fs(fsr) & 0xD) == 0x9);
3503 +}
3504 +
3505 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3506 unsigned long search_exception_table(unsigned long addr);
3507
3508 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3509 index ad722f1..763fdd3 100644
3510 --- a/arch/arm/mm/init.c
3511 +++ b/arch/arm/mm/init.c
3512 @@ -30,6 +30,8 @@
3513 #include <asm/setup.h>
3514 #include <asm/tlb.h>
3515 #include <asm/fixmap.h>
3516 +#include <asm/system_info.h>
3517 +#include <asm/cp15.h>
3518
3519 #include <asm/mach/arch.h>
3520 #include <asm/mach/map.h>
3521 @@ -736,7 +738,46 @@ void free_initmem(void)
3522 {
3523 #ifdef CONFIG_HAVE_TCM
3524 extern char __tcm_start, __tcm_end;
3525 +#endif
3526
3527 +#ifdef CONFIG_PAX_KERNEXEC
3528 + unsigned long addr;
3529 + pgd_t *pgd;
3530 + pud_t *pud;
3531 + pmd_t *pmd;
3532 + int cpu_arch = cpu_architecture();
3533 + unsigned int cr = get_cr();
3534 +
3535 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3536 + /* make pages tables, etc before .text NX */
3537 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3538 + pgd = pgd_offset_k(addr);
3539 + pud = pud_offset(pgd, addr);
3540 + pmd = pmd_offset(pud, addr);
3541 + __section_update(pmd, addr, PMD_SECT_XN);
3542 + }
3543 + /* make init NX */
3544 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3545 + pgd = pgd_offset_k(addr);
3546 + pud = pud_offset(pgd, addr);
3547 + pmd = pmd_offset(pud, addr);
3548 + __section_update(pmd, addr, PMD_SECT_XN);
3549 + }
3550 + /* make kernel code/rodata RX */
3551 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3552 + pgd = pgd_offset_k(addr);
3553 + pud = pud_offset(pgd, addr);
3554 + pmd = pmd_offset(pud, addr);
3555 +#ifdef CONFIG_ARM_LPAE
3556 + __section_update(pmd, addr, PMD_SECT_RDONLY);
3557 +#else
3558 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3559 +#endif
3560 + }
3561 + }
3562 +#endif
3563 +
3564 +#ifdef CONFIG_HAVE_TCM
3565 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3566 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3567 __phys_to_pfn(__pa(&__tcm_end)),
3568 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3569 index 88fd86c..7a224ce 100644
3570 --- a/arch/arm/mm/ioremap.c
3571 +++ b/arch/arm/mm/ioremap.c
3572 @@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3573 unsigned int mtype;
3574
3575 if (cached)
3576 - mtype = MT_MEMORY;
3577 + mtype = MT_MEMORY_RX;
3578 else
3579 - mtype = MT_MEMORY_NONCACHED;
3580 + mtype = MT_MEMORY_NONCACHED_RX;
3581
3582 return __arm_ioremap_caller(phys_addr, size, mtype,
3583 __builtin_return_address(0));
3584 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3585 index 10062ce..aa96dd7 100644
3586 --- a/arch/arm/mm/mmap.c
3587 +++ b/arch/arm/mm/mmap.c
3588 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3589 struct vm_area_struct *vma;
3590 int do_align = 0;
3591 int aliasing = cache_is_vipt_aliasing();
3592 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3593 struct vm_unmapped_area_info info;
3594
3595 /*
3596 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3597 if (len > TASK_SIZE)
3598 return -ENOMEM;
3599
3600 +#ifdef CONFIG_PAX_RANDMMAP
3601 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3602 +#endif
3603 +
3604 if (addr) {
3605 if (do_align)
3606 addr = COLOUR_ALIGN(addr, pgoff);
3607 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3608 addr = PAGE_ALIGN(addr);
3609
3610 vma = find_vma(mm, addr);
3611 - if (TASK_SIZE - len >= addr &&
3612 - (!vma || addr + len <= vma->vm_start))
3613 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3614 return addr;
3615 }
3616
3617 @@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3618 unsigned long addr = addr0;
3619 int do_align = 0;
3620 int aliasing = cache_is_vipt_aliasing();
3621 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3622 struct vm_unmapped_area_info info;
3623
3624 /*
3625 @@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3626 return addr;
3627 }
3628
3629 +#ifdef CONFIG_PAX_RANDMMAP
3630 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3631 +#endif
3632 +
3633 /* requesting a specific address */
3634 if (addr) {
3635 if (do_align)
3636 @@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3637 else
3638 addr = PAGE_ALIGN(addr);
3639 vma = find_vma(mm, addr);
3640 - if (TASK_SIZE - len >= addr &&
3641 - (!vma || addr + len <= vma->vm_start))
3642 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3643 return addr;
3644 }
3645
3646 @@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3647 VM_BUG_ON(addr != -ENOMEM);
3648 info.flags = 0;
3649 info.low_limit = mm->mmap_base;
3650 +
3651 +#ifdef CONFIG_PAX_RANDMMAP
3652 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3653 + info.low_limit += mm->delta_mmap;
3654 +#endif
3655 +
3656 info.high_limit = TASK_SIZE;
3657 addr = vm_unmapped_area(&info);
3658 }
3659 @@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3660 {
3661 unsigned long random_factor = 0UL;
3662
3663 +#ifdef CONFIG_PAX_RANDMMAP
3664 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3665 +#endif
3666 +
3667 /* 8 bits of randomness in 20 address space bits */
3668 if ((current->flags & PF_RANDOMIZE) &&
3669 !(current->personality & ADDR_NO_RANDOMIZE))
3670 @@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3671
3672 if (mmap_is_legacy()) {
3673 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3674 +
3675 +#ifdef CONFIG_PAX_RANDMMAP
3676 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3677 + mm->mmap_base += mm->delta_mmap;
3678 +#endif
3679 +
3680 mm->get_unmapped_area = arch_get_unmapped_area;
3681 mm->unmap_area = arch_unmap_area;
3682 } else {
3683 mm->mmap_base = mmap_base(random_factor);
3684 +
3685 +#ifdef CONFIG_PAX_RANDMMAP
3686 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3687 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3688 +#endif
3689 +
3690 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3691 mm->unmap_area = arch_unmap_area_topdown;
3692 }
3693 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3694 index ce328c7..f82bebb 100644
3695 --- a/arch/arm/mm/mmu.c
3696 +++ b/arch/arm/mm/mmu.c
3697 @@ -35,6 +35,23 @@
3698
3699 #include "mm.h"
3700
3701 +
3702 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3703 +void modify_domain(unsigned int dom, unsigned int type)
3704 +{
3705 + struct thread_info *thread = current_thread_info();
3706 + unsigned int domain = thread->cpu_domain;
3707 + /*
3708 + * DOMAIN_MANAGER might be defined to some other value,
3709 + * use the arch-defined constant
3710 + */
3711 + domain &= ~domain_val(dom, 3);
3712 + thread->cpu_domain = domain | domain_val(dom, type);
3713 + set_domain(thread->cpu_domain);
3714 +}
3715 +EXPORT_SYMBOL(modify_domain);
3716 +#endif
3717 +
3718 /*
3719 * empty_zero_page is a special page that is used for
3720 * zero-initialized data and COW.
3721 @@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
3722 }
3723 #endif
3724
3725 -#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
3726 +#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
3727 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
3728
3729 -static struct mem_type mem_types[] = {
3730 +#ifdef CONFIG_PAX_KERNEXEC
3731 +#define L_PTE_KERNEXEC L_PTE_RDONLY
3732 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
3733 +#else
3734 +#define L_PTE_KERNEXEC L_PTE_DIRTY
3735 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
3736 +#endif
3737 +
3738 +static struct mem_type mem_types[] __read_only = {
3739 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
3740 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
3741 L_PTE_SHARED,
3742 @@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
3743 [MT_UNCACHED] = {
3744 .prot_pte = PROT_PTE_DEVICE,
3745 .prot_l1 = PMD_TYPE_TABLE,
3746 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3747 + .prot_sect = PROT_SECT_DEVICE,
3748 .domain = DOMAIN_IO,
3749 },
3750 [MT_CACHECLEAN] = {
3751 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3752 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3753 .domain = DOMAIN_KERNEL,
3754 },
3755 #ifndef CONFIG_ARM_LPAE
3756 [MT_MINICLEAN] = {
3757 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
3758 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
3759 .domain = DOMAIN_KERNEL,
3760 },
3761 #endif
3762 @@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
3763 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3764 L_PTE_RDONLY,
3765 .prot_l1 = PMD_TYPE_TABLE,
3766 - .domain = DOMAIN_USER,
3767 + .domain = DOMAIN_VECTORS,
3768 },
3769 [MT_HIGH_VECTORS] = {
3770 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3771 L_PTE_USER | L_PTE_RDONLY,
3772 .prot_l1 = PMD_TYPE_TABLE,
3773 - .domain = DOMAIN_USER,
3774 + .domain = DOMAIN_VECTORS,
3775 },
3776 - [MT_MEMORY] = {
3777 + [MT_MEMORY_RWX] = {
3778 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3779 .prot_l1 = PMD_TYPE_TABLE,
3780 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3781 .domain = DOMAIN_KERNEL,
3782 },
3783 + [MT_MEMORY_RW] = {
3784 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3785 + .prot_l1 = PMD_TYPE_TABLE,
3786 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3787 + .domain = DOMAIN_KERNEL,
3788 + },
3789 + [MT_MEMORY_RX] = {
3790 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
3791 + .prot_l1 = PMD_TYPE_TABLE,
3792 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3793 + .domain = DOMAIN_KERNEL,
3794 + },
3795 [MT_ROM] = {
3796 - .prot_sect = PMD_TYPE_SECT,
3797 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3798 .domain = DOMAIN_KERNEL,
3799 },
3800 - [MT_MEMORY_NONCACHED] = {
3801 + [MT_MEMORY_NONCACHED_RW] = {
3802 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3803 L_PTE_MT_BUFFERABLE,
3804 .prot_l1 = PMD_TYPE_TABLE,
3805 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3806 .domain = DOMAIN_KERNEL,
3807 },
3808 + [MT_MEMORY_NONCACHED_RX] = {
3809 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
3810 + L_PTE_MT_BUFFERABLE,
3811 + .prot_l1 = PMD_TYPE_TABLE,
3812 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3813 + .domain = DOMAIN_KERNEL,
3814 + },
3815 [MT_MEMORY_DTCM] = {
3816 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3817 - L_PTE_XN,
3818 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3819 .prot_l1 = PMD_TYPE_TABLE,
3820 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3821 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3822 .domain = DOMAIN_KERNEL,
3823 },
3824 [MT_MEMORY_ITCM] = {
3825 @@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
3826 },
3827 [MT_MEMORY_SO] = {
3828 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3829 - L_PTE_MT_UNCACHED | L_PTE_XN,
3830 + L_PTE_MT_UNCACHED,
3831 .prot_l1 = PMD_TYPE_TABLE,
3832 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
3833 - PMD_SECT_UNCACHED | PMD_SECT_XN,
3834 + PMD_SECT_UNCACHED,
3835 .domain = DOMAIN_KERNEL,
3836 },
3837 [MT_MEMORY_DMA_READY] = {
3838 @@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
3839 * to prevent speculative instruction fetches.
3840 */
3841 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
3842 + mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
3843 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
3844 + mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
3845 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
3846 + mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
3847 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
3848 + mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
3849 +
3850 + /* Mark other regions on ARMv6+ as execute-never */
3851 +
3852 +#ifdef CONFIG_PAX_KERNEXEC
3853 + mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
3854 + mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
3855 + mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
3856 + mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
3857 +#ifndef CONFIG_ARM_LPAE
3858 + mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
3859 + mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
3860 +#endif
3861 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
3862 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
3863 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
3864 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
3865 + mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
3866 + mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
3867 +#endif
3868 +
3869 + mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
3870 + mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
3871 }
3872 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3873 /*
3874 @@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
3875 * from SVC mode and no access from userspace.
3876 */
3877 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3878 +#ifdef CONFIG_PAX_KERNEXEC
3879 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3880 +#endif
3881 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3882 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3883 #endif
3884 @@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
3885 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
3886 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
3887 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
3888 - mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
3889 - mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
3890 + mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
3891 + mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
3892 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
3893 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
3894 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
3895 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
3896 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
3897 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
3898 - mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
3899 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
3900 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
3901 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
3902 + mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
3903 }
3904 }
3905
3906 @@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
3907 if (cpu_arch >= CPU_ARCH_ARMv6) {
3908 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3909 /* Non-cacheable Normal is XCB = 001 */
3910 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3911 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3912 + PMD_SECT_BUFFERED;
3913 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3914 PMD_SECT_BUFFERED;
3915 } else {
3916 /* For both ARMv6 and non-TEX-remapping ARMv7 */
3917 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3918 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3919 + PMD_SECT_TEX(1);
3920 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3921 PMD_SECT_TEX(1);
3922 }
3923 } else {
3924 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
3925 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
3926 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
3927 }
3928
3929 #ifdef CONFIG_ARM_LPAE
3930 @@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
3931 vecs_pgprot |= PTE_EXT_AF;
3932 #endif
3933
3934 + user_pgprot |= __supported_pte_mask;
3935 +
3936 for (i = 0; i < 16; i++) {
3937 pteval_t v = pgprot_val(protection_map[i]);
3938 protection_map[i] = __pgprot(v | user_pgprot);
3939 @@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
3940
3941 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
3942 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
3943 - mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
3944 - mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
3945 + mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
3946 + mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
3947 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
3948 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
3949 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
3950 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
3951 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
3952 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
3953 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
3954 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
3955 mem_types[MT_ROM].prot_sect |= cp->pmd;
3956
3957 switch (cp->pmd) {
3958 @@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
3959 * called function. This means you can't use any function or debugging
3960 * method which may touch any device, otherwise the kernel _will_ crash.
3961 */
3962 +
3963 +static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
3964 +
3965 static void __init devicemaps_init(struct machine_desc *mdesc)
3966 {
3967 struct map_desc map;
3968 unsigned long addr;
3969 - void *vectors;
3970
3971 - /*
3972 - * Allocate the vector page early.
3973 - */
3974 - vectors = early_alloc(PAGE_SIZE);
3975 -
3976 - early_trap_init(vectors);
3977 + early_trap_init(&vectors);
3978
3979 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
3980 pmd_clear(pmd_off_k(addr));
3981 @@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
3982 * location (0xffff0000). If we aren't using high-vectors, also
3983 * create a mapping at the low-vectors virtual address.
3984 */
3985 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
3986 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
3987 map.virtual = 0xffff0000;
3988 map.length = PAGE_SIZE;
3989 map.type = MT_HIGH_VECTORS;
3990 @@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
3991 map.pfn = __phys_to_pfn(start);
3992 map.virtual = __phys_to_virt(start);
3993 map.length = end - start;
3994 - map.type = MT_MEMORY;
3995
3996 +#ifdef CONFIG_PAX_KERNEXEC
3997 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
3998 + struct map_desc kernel;
3999 + struct map_desc initmap;
4000 +
4001 + /* when freeing initmem we will make this RW */
4002 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4003 + initmap.virtual = (unsigned long)__init_begin;
4004 + initmap.length = _sdata - __init_begin;
4005 + initmap.type = MT_MEMORY_RWX;
4006 + create_mapping(&initmap);
4007 +
4008 + /* when freeing initmem we will make this RX */
4009 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4010 + kernel.virtual = (unsigned long)_stext;
4011 + kernel.length = __init_begin - _stext;
4012 + kernel.type = MT_MEMORY_RWX;
4013 + create_mapping(&kernel);
4014 +
4015 + if (map.virtual < (unsigned long)_stext) {
4016 + map.length = (unsigned long)_stext - map.virtual;
4017 + map.type = MT_MEMORY_RWX;
4018 + create_mapping(&map);
4019 + }
4020 +
4021 + map.pfn = __phys_to_pfn(__pa(_sdata));
4022 + map.virtual = (unsigned long)_sdata;
4023 + map.length = end - __pa(_sdata);
4024 + }
4025 +#endif
4026 +
4027 + map.type = MT_MEMORY_RW;
4028 create_mapping(&map);
4029 }
4030 }
4031 diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4032 index 6d98c13..3cfb174 100644
4033 --- a/arch/arm/mm/proc-v7-2level.S
4034 +++ b/arch/arm/mm/proc-v7-2level.S
4035 @@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4036 tst r1, #L_PTE_XN
4037 orrne r3, r3, #PTE_EXT_XN
4038
4039 + tst r1, #L_PTE_PXN
4040 + orrne r3, r3, #PTE_EXT_PXN
4041 +
4042 tst r1, #L_PTE_YOUNG
4043 tstne r1, #L_PTE_VALID
4044 #ifndef CONFIG_CPU_USE_DOMAINS
4045 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4046 index a5bc92d..0bb4730 100644
4047 --- a/arch/arm/plat-omap/sram.c
4048 +++ b/arch/arm/plat-omap/sram.c
4049 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4050 * Looks like we need to preserve some bootloader code at the
4051 * beginning of SRAM for jumping to flash for reboot to work...
4052 */
4053 + pax_open_kernel();
4054 memset_io(omap_sram_base + omap_sram_skip, 0,
4055 omap_sram_size - omap_sram_skip);
4056 + pax_close_kernel();
4057 }
4058 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
4059 index b76c065..b6e766b 100644
4060 --- a/arch/arm/plat-orion/include/plat/addr-map.h
4061 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
4062 @@ -27,7 +27,7 @@ struct orion_addr_map_cfg {
4063 value in bridge_virt_base */
4064 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
4065 const int win);
4066 -};
4067 +} __no_const;
4068
4069 /*
4070 * Information needed to setup one address mapping.
4071 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4072 index f5144cd..71f6d1f 100644
4073 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4074 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4075 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4076 int (*started)(unsigned ch);
4077 int (*flush)(unsigned ch);
4078 int (*stop)(unsigned ch);
4079 -};
4080 +} __no_const;
4081
4082 extern void *samsung_dmadev_get_ops(void);
4083 extern void *s3c_dma_get_ops(void);
4084 diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4085 index 0c3ba9f..95722b3 100644
4086 --- a/arch/arm64/kernel/debug-monitors.c
4087 +++ b/arch/arm64/kernel/debug-monitors.c
4088 @@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4089 return NOTIFY_OK;
4090 }
4091
4092 -static struct notifier_block __cpuinitdata os_lock_nb = {
4093 +static struct notifier_block os_lock_nb = {
4094 .notifier_call = os_lock_notify,
4095 };
4096
4097 diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4098 index 5ab825c..96aaec8 100644
4099 --- a/arch/arm64/kernel/hw_breakpoint.c
4100 +++ b/arch/arm64/kernel/hw_breakpoint.c
4101 @@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4102 return NOTIFY_OK;
4103 }
4104
4105 -static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4106 +static struct notifier_block hw_breakpoint_reset_nb = {
4107 .notifier_call = hw_breakpoint_reset_notify,
4108 };
4109
4110 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4111 index c3a58a1..78fbf54 100644
4112 --- a/arch/avr32/include/asm/cache.h
4113 +++ b/arch/avr32/include/asm/cache.h
4114 @@ -1,8 +1,10 @@
4115 #ifndef __ASM_AVR32_CACHE_H
4116 #define __ASM_AVR32_CACHE_H
4117
4118 +#include <linux/const.h>
4119 +
4120 #define L1_CACHE_SHIFT 5
4121 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4122 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4123
4124 /*
4125 * Memory returned by kmalloc() may be used for DMA, so we must make
4126 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4127 index e2c3287..6c4f98c 100644
4128 --- a/arch/avr32/include/asm/elf.h
4129 +++ b/arch/avr32/include/asm/elf.h
4130 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4131 the loader. We need to make sure that it is out of the way of the program
4132 that it will "exec", and that there is sufficient room for the brk. */
4133
4134 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4135 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4136
4137 +#ifdef CONFIG_PAX_ASLR
4138 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4139 +
4140 +#define PAX_DELTA_MMAP_LEN 15
4141 +#define PAX_DELTA_STACK_LEN 15
4142 +#endif
4143
4144 /* This yields a mask that user programs can use to figure out what
4145 instruction set this CPU supports. This could be done in user space,
4146 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4147 index 479330b..53717a8 100644
4148 --- a/arch/avr32/include/asm/kmap_types.h
4149 +++ b/arch/avr32/include/asm/kmap_types.h
4150 @@ -2,9 +2,9 @@
4151 #define __ASM_AVR32_KMAP_TYPES_H
4152
4153 #ifdef CONFIG_DEBUG_HIGHMEM
4154 -# define KM_TYPE_NR 29
4155 +# define KM_TYPE_NR 30
4156 #else
4157 -# define KM_TYPE_NR 14
4158 +# define KM_TYPE_NR 15
4159 #endif
4160
4161 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4162 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4163 index b2f2d2d..d1c85cb 100644
4164 --- a/arch/avr32/mm/fault.c
4165 +++ b/arch/avr32/mm/fault.c
4166 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4167
4168 int exception_trace = 1;
4169
4170 +#ifdef CONFIG_PAX_PAGEEXEC
4171 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4172 +{
4173 + unsigned long i;
4174 +
4175 + printk(KERN_ERR "PAX: bytes at PC: ");
4176 + for (i = 0; i < 20; i++) {
4177 + unsigned char c;
4178 + if (get_user(c, (unsigned char *)pc+i))
4179 + printk(KERN_CONT "???????? ");
4180 + else
4181 + printk(KERN_CONT "%02x ", c);
4182 + }
4183 + printk("\n");
4184 +}
4185 +#endif
4186 +
4187 /*
4188 * This routine handles page faults. It determines the address and the
4189 * problem, and then passes it off to one of the appropriate routines.
4190 @@ -174,6 +191,16 @@ bad_area:
4191 up_read(&mm->mmap_sem);
4192
4193 if (user_mode(regs)) {
4194 +
4195 +#ifdef CONFIG_PAX_PAGEEXEC
4196 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4197 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4198 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4199 + do_group_exit(SIGKILL);
4200 + }
4201 + }
4202 +#endif
4203 +
4204 if (exception_trace && printk_ratelimit())
4205 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4206 "sp %08lx ecr %lu\n",
4207 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4208 index 568885a..f8008df 100644
4209 --- a/arch/blackfin/include/asm/cache.h
4210 +++ b/arch/blackfin/include/asm/cache.h
4211 @@ -7,6 +7,7 @@
4212 #ifndef __ARCH_BLACKFIN_CACHE_H
4213 #define __ARCH_BLACKFIN_CACHE_H
4214
4215 +#include <linux/const.h>
4216 #include <linux/linkage.h> /* for asmlinkage */
4217
4218 /*
4219 @@ -14,7 +15,7 @@
4220 * Blackfin loads 32 bytes for cache
4221 */
4222 #define L1_CACHE_SHIFT 5
4223 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4224 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4225 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4226
4227 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4228 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4229 index aea2718..3639a60 100644
4230 --- a/arch/cris/include/arch-v10/arch/cache.h
4231 +++ b/arch/cris/include/arch-v10/arch/cache.h
4232 @@ -1,8 +1,9 @@
4233 #ifndef _ASM_ARCH_CACHE_H
4234 #define _ASM_ARCH_CACHE_H
4235
4236 +#include <linux/const.h>
4237 /* Etrax 100LX have 32-byte cache-lines. */
4238 -#define L1_CACHE_BYTES 32
4239 #define L1_CACHE_SHIFT 5
4240 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4241
4242 #endif /* _ASM_ARCH_CACHE_H */
4243 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4244 index 7caf25d..ee65ac5 100644
4245 --- a/arch/cris/include/arch-v32/arch/cache.h
4246 +++ b/arch/cris/include/arch-v32/arch/cache.h
4247 @@ -1,11 +1,12 @@
4248 #ifndef _ASM_CRIS_ARCH_CACHE_H
4249 #define _ASM_CRIS_ARCH_CACHE_H
4250
4251 +#include <linux/const.h>
4252 #include <arch/hwregs/dma.h>
4253
4254 /* A cache-line is 32 bytes. */
4255 -#define L1_CACHE_BYTES 32
4256 #define L1_CACHE_SHIFT 5
4257 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4258
4259 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4260
4261 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4262 index b86329d..6709906 100644
4263 --- a/arch/frv/include/asm/atomic.h
4264 +++ b/arch/frv/include/asm/atomic.h
4265 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4266 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4267 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4268
4269 +#define atomic64_read_unchecked(v) atomic64_read(v)
4270 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4271 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4272 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4273 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4274 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4275 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4276 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4277 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4278 +
4279 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4280 {
4281 int c, old;
4282 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4283 index 2797163..c2a401d 100644
4284 --- a/arch/frv/include/asm/cache.h
4285 +++ b/arch/frv/include/asm/cache.h
4286 @@ -12,10 +12,11 @@
4287 #ifndef __ASM_CACHE_H
4288 #define __ASM_CACHE_H
4289
4290 +#include <linux/const.h>
4291
4292 /* bytes per L1 cache line */
4293 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4294 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4295 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4296
4297 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4298 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4299 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4300 index 43901f2..0d8b865 100644
4301 --- a/arch/frv/include/asm/kmap_types.h
4302 +++ b/arch/frv/include/asm/kmap_types.h
4303 @@ -2,6 +2,6 @@
4304 #ifndef _ASM_KMAP_TYPES_H
4305 #define _ASM_KMAP_TYPES_H
4306
4307 -#define KM_TYPE_NR 17
4308 +#define KM_TYPE_NR 18
4309
4310 #endif
4311 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4312 index 385fd30..3aaf4fe 100644
4313 --- a/arch/frv/mm/elf-fdpic.c
4314 +++ b/arch/frv/mm/elf-fdpic.c
4315 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4316 {
4317 struct vm_area_struct *vma;
4318 unsigned long limit;
4319 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4320
4321 if (len > TASK_SIZE)
4322 return -ENOMEM;
4323 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4324 if (addr) {
4325 addr = PAGE_ALIGN(addr);
4326 vma = find_vma(current->mm, addr);
4327 - if (TASK_SIZE - len >= addr &&
4328 - (!vma || addr + len <= vma->vm_start))
4329 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4330 goto success;
4331 }
4332
4333 @@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4334 for (; vma; vma = vma->vm_next) {
4335 if (addr > limit)
4336 break;
4337 - if (addr + len <= vma->vm_start)
4338 + if (check_heap_stack_gap(vma, addr, len, offset))
4339 goto success;
4340 addr = vma->vm_end;
4341 }
4342 @@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4343 for (; vma; vma = vma->vm_next) {
4344 if (addr > limit)
4345 break;
4346 - if (addr + len <= vma->vm_start)
4347 + if (check_heap_stack_gap(vma, addr, len, offset))
4348 goto success;
4349 addr = vma->vm_end;
4350 }
4351 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4352 index f4ca594..adc72fd6 100644
4353 --- a/arch/hexagon/include/asm/cache.h
4354 +++ b/arch/hexagon/include/asm/cache.h
4355 @@ -21,9 +21,11 @@
4356 #ifndef __ASM_CACHE_H
4357 #define __ASM_CACHE_H
4358
4359 +#include <linux/const.h>
4360 +
4361 /* Bytes per L1 cache line */
4362 -#define L1_CACHE_SHIFT (5)
4363 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4364 +#define L1_CACHE_SHIFT 5
4365 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4366
4367 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4368 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4369 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4370 index 6e6fe18..a6ae668 100644
4371 --- a/arch/ia64/include/asm/atomic.h
4372 +++ b/arch/ia64/include/asm/atomic.h
4373 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4374 #define atomic64_inc(v) atomic64_add(1, (v))
4375 #define atomic64_dec(v) atomic64_sub(1, (v))
4376
4377 +#define atomic64_read_unchecked(v) atomic64_read(v)
4378 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4379 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4380 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4381 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4382 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4383 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4384 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4385 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4386 +
4387 /* Atomic operations are already serializing */
4388 #define smp_mb__before_atomic_dec() barrier()
4389 #define smp_mb__after_atomic_dec() barrier()
4390 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4391 index 988254a..e1ee885 100644
4392 --- a/arch/ia64/include/asm/cache.h
4393 +++ b/arch/ia64/include/asm/cache.h
4394 @@ -1,6 +1,7 @@
4395 #ifndef _ASM_IA64_CACHE_H
4396 #define _ASM_IA64_CACHE_H
4397
4398 +#include <linux/const.h>
4399
4400 /*
4401 * Copyright (C) 1998-2000 Hewlett-Packard Co
4402 @@ -9,7 +10,7 @@
4403
4404 /* Bytes per L1 (data) cache line. */
4405 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4406 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4407 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4408
4409 #ifdef CONFIG_SMP
4410 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4411 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4412 index b5298eb..67c6e62 100644
4413 --- a/arch/ia64/include/asm/elf.h
4414 +++ b/arch/ia64/include/asm/elf.h
4415 @@ -42,6 +42,13 @@
4416 */
4417 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4418
4419 +#ifdef CONFIG_PAX_ASLR
4420 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4421 +
4422 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4423 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4424 +#endif
4425 +
4426 #define PT_IA_64_UNWIND 0x70000001
4427
4428 /* IA-64 relocations: */
4429 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4430 index 96a8d92..617a1cf 100644
4431 --- a/arch/ia64/include/asm/pgalloc.h
4432 +++ b/arch/ia64/include/asm/pgalloc.h
4433 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4434 pgd_val(*pgd_entry) = __pa(pud);
4435 }
4436
4437 +static inline void
4438 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4439 +{
4440 + pgd_populate(mm, pgd_entry, pud);
4441 +}
4442 +
4443 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4444 {
4445 return quicklist_alloc(0, GFP_KERNEL, NULL);
4446 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4447 pud_val(*pud_entry) = __pa(pmd);
4448 }
4449
4450 +static inline void
4451 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4452 +{
4453 + pud_populate(mm, pud_entry, pmd);
4454 +}
4455 +
4456 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4457 {
4458 return quicklist_alloc(0, GFP_KERNEL, NULL);
4459 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4460 index 815810c..d60bd4c 100644
4461 --- a/arch/ia64/include/asm/pgtable.h
4462 +++ b/arch/ia64/include/asm/pgtable.h
4463 @@ -12,7 +12,7 @@
4464 * David Mosberger-Tang <davidm@hpl.hp.com>
4465 */
4466
4467 -
4468 +#include <linux/const.h>
4469 #include <asm/mman.h>
4470 #include <asm/page.h>
4471 #include <asm/processor.h>
4472 @@ -142,6 +142,17 @@
4473 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4474 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4475 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4476 +
4477 +#ifdef CONFIG_PAX_PAGEEXEC
4478 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4479 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4480 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4481 +#else
4482 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4483 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4484 +# define PAGE_COPY_NOEXEC PAGE_COPY
4485 +#endif
4486 +
4487 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4488 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4489 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4490 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4491 index 54ff557..70c88b7 100644
4492 --- a/arch/ia64/include/asm/spinlock.h
4493 +++ b/arch/ia64/include/asm/spinlock.h
4494 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4495 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4496
4497 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4498 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4499 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4500 }
4501
4502 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4503 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4504 index 449c8c0..50cdf87 100644
4505 --- a/arch/ia64/include/asm/uaccess.h
4506 +++ b/arch/ia64/include/asm/uaccess.h
4507 @@ -42,6 +42,8 @@
4508 #include <asm/pgtable.h>
4509 #include <asm/io.h>
4510
4511 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
4512 +
4513 /*
4514 * For historical reasons, the following macros are grossly misnamed:
4515 */
4516 @@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4517 static inline unsigned long
4518 __copy_to_user (void __user *to, const void *from, unsigned long count)
4519 {
4520 + if (count > INT_MAX)
4521 + return count;
4522 +
4523 + if (!__builtin_constant_p(count))
4524 + check_object_size(from, count, true);
4525 +
4526 return __copy_user(to, (__force void __user *) from, count);
4527 }
4528
4529 static inline unsigned long
4530 __copy_from_user (void *to, const void __user *from, unsigned long count)
4531 {
4532 + if (count > INT_MAX)
4533 + return count;
4534 +
4535 + if (!__builtin_constant_p(count))
4536 + check_object_size(to, count, false);
4537 +
4538 return __copy_user((__force void __user *) to, from, count);
4539 }
4540
4541 @@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4542 ({ \
4543 void __user *__cu_to = (to); \
4544 const void *__cu_from = (from); \
4545 - long __cu_len = (n); \
4546 + unsigned long __cu_len = (n); \
4547 \
4548 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
4549 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4550 + if (!__builtin_constant_p(n)) \
4551 + check_object_size(__cu_from, __cu_len, true); \
4552 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4553 + } \
4554 __cu_len; \
4555 })
4556
4557 @@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4558 ({ \
4559 void *__cu_to = (to); \
4560 const void __user *__cu_from = (from); \
4561 - long __cu_len = (n); \
4562 + unsigned long __cu_len = (n); \
4563 \
4564 __chk_user_ptr(__cu_from); \
4565 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
4566 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4567 + if (!__builtin_constant_p(n)) \
4568 + check_object_size(__cu_to, __cu_len, false); \
4569 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4570 + } \
4571 __cu_len; \
4572 })
4573
4574 diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4575 index 2d67317..07d8bfa 100644
4576 --- a/arch/ia64/kernel/err_inject.c
4577 +++ b/arch/ia64/kernel/err_inject.c
4578 @@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4579 return NOTIFY_OK;
4580 }
4581
4582 -static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4583 +static struct notifier_block err_inject_cpu_notifier =
4584 {
4585 .notifier_call = err_inject_cpu_callback,
4586 };
4587 diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4588 index 65bf9cd..794f06b 100644
4589 --- a/arch/ia64/kernel/mca.c
4590 +++ b/arch/ia64/kernel/mca.c
4591 @@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4592 return NOTIFY_OK;
4593 }
4594
4595 -static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4596 +static struct notifier_block mca_cpu_notifier = {
4597 .notifier_call = mca_cpu_callback
4598 };
4599
4600 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4601 index 24603be..948052d 100644
4602 --- a/arch/ia64/kernel/module.c
4603 +++ b/arch/ia64/kernel/module.c
4604 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4605 void
4606 module_free (struct module *mod, void *module_region)
4607 {
4608 - if (mod && mod->arch.init_unw_table &&
4609 - module_region == mod->module_init) {
4610 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4611 unw_remove_unwind_table(mod->arch.init_unw_table);
4612 mod->arch.init_unw_table = NULL;
4613 }
4614 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4615 }
4616
4617 static inline int
4618 +in_init_rx (const struct module *mod, uint64_t addr)
4619 +{
4620 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4621 +}
4622 +
4623 +static inline int
4624 +in_init_rw (const struct module *mod, uint64_t addr)
4625 +{
4626 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4627 +}
4628 +
4629 +static inline int
4630 in_init (const struct module *mod, uint64_t addr)
4631 {
4632 - return addr - (uint64_t) mod->module_init < mod->init_size;
4633 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4634 +}
4635 +
4636 +static inline int
4637 +in_core_rx (const struct module *mod, uint64_t addr)
4638 +{
4639 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4640 +}
4641 +
4642 +static inline int
4643 +in_core_rw (const struct module *mod, uint64_t addr)
4644 +{
4645 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4646 }
4647
4648 static inline int
4649 in_core (const struct module *mod, uint64_t addr)
4650 {
4651 - return addr - (uint64_t) mod->module_core < mod->core_size;
4652 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4653 }
4654
4655 static inline int
4656 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4657 break;
4658
4659 case RV_BDREL:
4660 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4661 + if (in_init_rx(mod, val))
4662 + val -= (uint64_t) mod->module_init_rx;
4663 + else if (in_init_rw(mod, val))
4664 + val -= (uint64_t) mod->module_init_rw;
4665 + else if (in_core_rx(mod, val))
4666 + val -= (uint64_t) mod->module_core_rx;
4667 + else if (in_core_rw(mod, val))
4668 + val -= (uint64_t) mod->module_core_rw;
4669 break;
4670
4671 case RV_LTV:
4672 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4673 * addresses have been selected...
4674 */
4675 uint64_t gp;
4676 - if (mod->core_size > MAX_LTOFF)
4677 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4678 /*
4679 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4680 * at the end of the module.
4681 */
4682 - gp = mod->core_size - MAX_LTOFF / 2;
4683 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4684 else
4685 - gp = mod->core_size / 2;
4686 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4687 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4688 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4689 mod->arch.gp = gp;
4690 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4691 }
4692 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4693 index 77597e5..6f28f3f 100644
4694 --- a/arch/ia64/kernel/palinfo.c
4695 +++ b/arch/ia64/kernel/palinfo.c
4696 @@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4697 return NOTIFY_OK;
4698 }
4699
4700 -static struct notifier_block __refdata palinfo_cpu_notifier =
4701 +static struct notifier_block palinfo_cpu_notifier =
4702 {
4703 .notifier_call = palinfo_cpu_callback,
4704 .priority = 0,
4705 diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4706 index 79802e5..1a89ec5 100644
4707 --- a/arch/ia64/kernel/salinfo.c
4708 +++ b/arch/ia64/kernel/salinfo.c
4709 @@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4710 return NOTIFY_OK;
4711 }
4712
4713 -static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4714 +static struct notifier_block salinfo_cpu_notifier =
4715 {
4716 .notifier_call = salinfo_cpu_callback,
4717 .priority = 0,
4718 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4719 index d9439ef..d0cac6b 100644
4720 --- a/arch/ia64/kernel/sys_ia64.c
4721 +++ b/arch/ia64/kernel/sys_ia64.c
4722 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4723 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
4724 struct mm_struct *mm = current->mm;
4725 struct vm_area_struct *vma;
4726 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4727
4728 if (len > RGN_MAP_LIMIT)
4729 return -ENOMEM;
4730 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4731 if (REGION_NUMBER(addr) == RGN_HPAGE)
4732 addr = 0;
4733 #endif
4734 +
4735 +#ifdef CONFIG_PAX_RANDMMAP
4736 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4737 + addr = mm->free_area_cache;
4738 + else
4739 +#endif
4740 +
4741 if (!addr)
4742 addr = mm->free_area_cache;
4743
4744 @@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4745 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
4746 /* At this point: (!vma || addr < vma->vm_end). */
4747 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
4748 - if (start_addr != TASK_UNMAPPED_BASE) {
4749 + if (start_addr != mm->mmap_base) {
4750 /* Start a new search --- just in case we missed some holes. */
4751 - addr = TASK_UNMAPPED_BASE;
4752 + addr = mm->mmap_base;
4753 goto full_search;
4754 }
4755 return -ENOMEM;
4756 }
4757 - if (!vma || addr + len <= vma->vm_start) {
4758 + if (check_heap_stack_gap(vma, addr, len, offset)) {
4759 /* Remember the address where we stopped this search: */
4760 mm->free_area_cache = addr + len;
4761 return addr;
4762 diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
4763 index dc00b2c..cce53c2 100644
4764 --- a/arch/ia64/kernel/topology.c
4765 +++ b/arch/ia64/kernel/topology.c
4766 @@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
4767 return NOTIFY_OK;
4768 }
4769
4770 -static struct notifier_block __cpuinitdata cache_cpu_notifier =
4771 +static struct notifier_block cache_cpu_notifier =
4772 {
4773 .notifier_call = cache_cpu_callback
4774 };
4775 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
4776 index 0ccb28f..8992469 100644
4777 --- a/arch/ia64/kernel/vmlinux.lds.S
4778 +++ b/arch/ia64/kernel/vmlinux.lds.S
4779 @@ -198,7 +198,7 @@ SECTIONS {
4780 /* Per-cpu data: */
4781 . = ALIGN(PERCPU_PAGE_SIZE);
4782 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
4783 - __phys_per_cpu_start = __per_cpu_load;
4784 + __phys_per_cpu_start = per_cpu_load;
4785 /*
4786 * ensure percpu data fits
4787 * into percpu page size
4788 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
4789 index 6cf0341..d352594 100644
4790 --- a/arch/ia64/mm/fault.c
4791 +++ b/arch/ia64/mm/fault.c
4792 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
4793 return pte_present(pte);
4794 }
4795
4796 +#ifdef CONFIG_PAX_PAGEEXEC
4797 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4798 +{
4799 + unsigned long i;
4800 +
4801 + printk(KERN_ERR "PAX: bytes at PC: ");
4802 + for (i = 0; i < 8; i++) {
4803 + unsigned int c;
4804 + if (get_user(c, (unsigned int *)pc+i))
4805 + printk(KERN_CONT "???????? ");
4806 + else
4807 + printk(KERN_CONT "%08x ", c);
4808 + }
4809 + printk("\n");
4810 +}
4811 +#endif
4812 +
4813 # define VM_READ_BIT 0
4814 # define VM_WRITE_BIT 1
4815 # define VM_EXEC_BIT 2
4816 @@ -149,8 +166,21 @@ retry:
4817 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
4818 goto bad_area;
4819
4820 - if ((vma->vm_flags & mask) != mask)
4821 + if ((vma->vm_flags & mask) != mask) {
4822 +
4823 +#ifdef CONFIG_PAX_PAGEEXEC
4824 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
4825 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
4826 + goto bad_area;
4827 +
4828 + up_read(&mm->mmap_sem);
4829 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
4830 + do_group_exit(SIGKILL);
4831 + }
4832 +#endif
4833 +
4834 goto bad_area;
4835 + }
4836
4837 /*
4838 * If for any reason at all we couldn't handle the fault, make
4839 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
4840 index 5ca674b..127c3cb 100644
4841 --- a/arch/ia64/mm/hugetlbpage.c
4842 +++ b/arch/ia64/mm/hugetlbpage.c
4843 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4844 unsigned long pgoff, unsigned long flags)
4845 {
4846 struct vm_area_struct *vmm;
4847 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
4848
4849 if (len > RGN_MAP_LIMIT)
4850 return -ENOMEM;
4851 @@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4852 /* At this point: (!vmm || addr < vmm->vm_end). */
4853 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
4854 return -ENOMEM;
4855 - if (!vmm || (addr + len) <= vmm->vm_start)
4856 + if (check_heap_stack_gap(vmm, addr, len, offset))
4857 return addr;
4858 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
4859 }
4860 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
4861 index b755ea9..b9a969e 100644
4862 --- a/arch/ia64/mm/init.c
4863 +++ b/arch/ia64/mm/init.c
4864 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
4865 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
4866 vma->vm_end = vma->vm_start + PAGE_SIZE;
4867 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
4868 +
4869 +#ifdef CONFIG_PAX_PAGEEXEC
4870 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
4871 + vma->vm_flags &= ~VM_EXEC;
4872 +
4873 +#ifdef CONFIG_PAX_MPROTECT
4874 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
4875 + vma->vm_flags &= ~VM_MAYEXEC;
4876 +#endif
4877 +
4878 + }
4879 +#endif
4880 +
4881 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4882 down_write(&current->mm->mmap_sem);
4883 if (insert_vm_struct(current->mm, vma)) {
4884 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
4885 index 40b3ee9..8c2c112 100644
4886 --- a/arch/m32r/include/asm/cache.h
4887 +++ b/arch/m32r/include/asm/cache.h
4888 @@ -1,8 +1,10 @@
4889 #ifndef _ASM_M32R_CACHE_H
4890 #define _ASM_M32R_CACHE_H
4891
4892 +#include <linux/const.h>
4893 +
4894 /* L1 cache line size */
4895 #define L1_CACHE_SHIFT 4
4896 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4897 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4898
4899 #endif /* _ASM_M32R_CACHE_H */
4900 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
4901 index 82abd15..d95ae5d 100644
4902 --- a/arch/m32r/lib/usercopy.c
4903 +++ b/arch/m32r/lib/usercopy.c
4904 @@ -14,6 +14,9 @@
4905 unsigned long
4906 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4907 {
4908 + if ((long)n < 0)
4909 + return n;
4910 +
4911 prefetch(from);
4912 if (access_ok(VERIFY_WRITE, to, n))
4913 __copy_user(to,from,n);
4914 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4915 unsigned long
4916 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
4917 {
4918 + if ((long)n < 0)
4919 + return n;
4920 +
4921 prefetchw(to);
4922 if (access_ok(VERIFY_READ, from, n))
4923 __copy_user_zeroing(to,from,n);
4924 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
4925 index 0395c51..5f26031 100644
4926 --- a/arch/m68k/include/asm/cache.h
4927 +++ b/arch/m68k/include/asm/cache.h
4928 @@ -4,9 +4,11 @@
4929 #ifndef __ARCH_M68K_CACHE_H
4930 #define __ARCH_M68K_CACHE_H
4931
4932 +#include <linux/const.h>
4933 +
4934 /* bytes per L1 cache line */
4935 #define L1_CACHE_SHIFT 4
4936 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
4937 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4938
4939 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4940
4941 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
4942 index 4efe96a..60e8699 100644
4943 --- a/arch/microblaze/include/asm/cache.h
4944 +++ b/arch/microblaze/include/asm/cache.h
4945 @@ -13,11 +13,12 @@
4946 #ifndef _ASM_MICROBLAZE_CACHE_H
4947 #define _ASM_MICROBLAZE_CACHE_H
4948
4949 +#include <linux/const.h>
4950 #include <asm/registers.h>
4951
4952 #define L1_CACHE_SHIFT 5
4953 /* word-granular cache in microblaze */
4954 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4955 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4956
4957 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4958
4959 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
4960 index 01cc6ba..bcb7a5d 100644
4961 --- a/arch/mips/include/asm/atomic.h
4962 +++ b/arch/mips/include/asm/atomic.h
4963 @@ -21,6 +21,10 @@
4964 #include <asm/cmpxchg.h>
4965 #include <asm/war.h>
4966
4967 +#ifdef CONFIG_GENERIC_ATOMIC64
4968 +#include <asm-generic/atomic64.h>
4969 +#endif
4970 +
4971 #define ATOMIC_INIT(i) { (i) }
4972
4973 /*
4974 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4975 */
4976 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
4977
4978 +#define atomic64_read_unchecked(v) atomic64_read(v)
4979 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4980 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4981 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4982 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4983 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4984 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4985 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4986 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4987 +
4988 #endif /* CONFIG_64BIT */
4989
4990 /*
4991 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
4992 index b4db69f..8f3b093 100644
4993 --- a/arch/mips/include/asm/cache.h
4994 +++ b/arch/mips/include/asm/cache.h
4995 @@ -9,10 +9,11 @@
4996 #ifndef _ASM_CACHE_H
4997 #define _ASM_CACHE_H
4998
4999 +#include <linux/const.h>
5000 #include <kmalloc.h>
5001
5002 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5003 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5004 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5005
5006 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5007 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5008 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5009 index 455c0ac..ad65fbe 100644
5010 --- a/arch/mips/include/asm/elf.h
5011 +++ b/arch/mips/include/asm/elf.h
5012 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
5013 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5014 #endif
5015
5016 +#ifdef CONFIG_PAX_ASLR
5017 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5018 +
5019 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5020 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5021 +#endif
5022 +
5023 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5024 struct linux_binprm;
5025 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5026 int uses_interp);
5027
5028 -struct mm_struct;
5029 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5030 -#define arch_randomize_brk arch_randomize_brk
5031 -
5032 #endif /* _ASM_ELF_H */
5033 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5034 index c1f6afa..38cc6e9 100644
5035 --- a/arch/mips/include/asm/exec.h
5036 +++ b/arch/mips/include/asm/exec.h
5037 @@ -12,6 +12,6 @@
5038 #ifndef _ASM_EXEC_H
5039 #define _ASM_EXEC_H
5040
5041 -extern unsigned long arch_align_stack(unsigned long sp);
5042 +#define arch_align_stack(x) ((x) & ~0xfUL)
5043
5044 #endif /* _ASM_EXEC_H */
5045 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5046 index dbaec94..6a14935 100644
5047 --- a/arch/mips/include/asm/page.h
5048 +++ b/arch/mips/include/asm/page.h
5049 @@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5050 #ifdef CONFIG_CPU_MIPS32
5051 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5052 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5053 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5054 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5055 #else
5056 typedef struct { unsigned long long pte; } pte_t;
5057 #define pte_val(x) ((x).pte)
5058 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5059 index 881d18b..cea38bc 100644
5060 --- a/arch/mips/include/asm/pgalloc.h
5061 +++ b/arch/mips/include/asm/pgalloc.h
5062 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5063 {
5064 set_pud(pud, __pud((unsigned long)pmd));
5065 }
5066 +
5067 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5068 +{
5069 + pud_populate(mm, pud, pmd);
5070 +}
5071 #endif
5072
5073 /*
5074 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5075 index b2050b9..d71bb1b 100644
5076 --- a/arch/mips/include/asm/thread_info.h
5077 +++ b/arch/mips/include/asm/thread_info.h
5078 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5079 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5080 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5081 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5082 +/* li takes a 32bit immediate */
5083 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5084 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5085
5086 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5087 @@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5088 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5089 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5090 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5091 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5092 +
5093 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5094
5095 /* work to do in syscall_trace_leave() */
5096 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5097 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5098
5099 /* work to do on interrupt/exception return */
5100 #define _TIF_WORK_MASK \
5101 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5102 /* work to do on any return to u-space */
5103 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5104 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5105
5106 #endif /* __KERNEL__ */
5107
5108 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5109 index 9fdd8bc..4bd7f1a 100644
5110 --- a/arch/mips/kernel/binfmt_elfn32.c
5111 +++ b/arch/mips/kernel/binfmt_elfn32.c
5112 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5113 #undef ELF_ET_DYN_BASE
5114 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5115
5116 +#ifdef CONFIG_PAX_ASLR
5117 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5118 +
5119 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5120 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5121 +#endif
5122 +
5123 #include <asm/processor.h>
5124 #include <linux/module.h>
5125 #include <linux/elfcore.h>
5126 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5127 index ff44823..97f8906 100644
5128 --- a/arch/mips/kernel/binfmt_elfo32.c
5129 +++ b/arch/mips/kernel/binfmt_elfo32.c
5130 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5131 #undef ELF_ET_DYN_BASE
5132 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5133
5134 +#ifdef CONFIG_PAX_ASLR
5135 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5136 +
5137 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5138 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5139 +#endif
5140 +
5141 #include <asm/processor.h>
5142
5143 /*
5144 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5145 index a11c6f9..be5e164 100644
5146 --- a/arch/mips/kernel/process.c
5147 +++ b/arch/mips/kernel/process.c
5148 @@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5149 out:
5150 return pc;
5151 }
5152 -
5153 -/*
5154 - * Don't forget that the stack pointer must be aligned on a 8 bytes
5155 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5156 - */
5157 -unsigned long arch_align_stack(unsigned long sp)
5158 -{
5159 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5160 - sp -= get_random_int() & ~PAGE_MASK;
5161 -
5162 - return sp & ALMASK;
5163 -}
5164 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5165 index 4812c6d..2069554 100644
5166 --- a/arch/mips/kernel/ptrace.c
5167 +++ b/arch/mips/kernel/ptrace.c
5168 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
5169 return arch;
5170 }
5171
5172 +#ifdef CONFIG_GRKERNSEC_SETXID
5173 +extern void gr_delayed_cred_worker(void);
5174 +#endif
5175 +
5176 /*
5177 * Notification of system call entry/exit
5178 * - triggered by current->work.syscall_trace
5179 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5180 /* do the secure computing check first */
5181 secure_computing_strict(regs->regs[2]);
5182
5183 +#ifdef CONFIG_GRKERNSEC_SETXID
5184 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5185 + gr_delayed_cred_worker();
5186 +#endif
5187 +
5188 if (!(current->ptrace & PT_PTRACED))
5189 goto out;
5190
5191 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5192 index d20a4bc..7096ae5 100644
5193 --- a/arch/mips/kernel/scall32-o32.S
5194 +++ b/arch/mips/kernel/scall32-o32.S
5195 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5196
5197 stack_done:
5198 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5199 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5200 + li t1, _TIF_SYSCALL_WORK
5201 and t0, t1
5202 bnez t0, syscall_trace_entry # -> yes
5203
5204 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5205 index b64f642..0fe6eab 100644
5206 --- a/arch/mips/kernel/scall64-64.S
5207 +++ b/arch/mips/kernel/scall64-64.S
5208 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5209
5210 sd a3, PT_R26(sp) # save a3 for syscall restarting
5211
5212 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5213 + li t1, _TIF_SYSCALL_WORK
5214 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5215 and t0, t1, t0
5216 bnez t0, syscall_trace_entry
5217 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5218 index c29ac19..c592d05 100644
5219 --- a/arch/mips/kernel/scall64-n32.S
5220 +++ b/arch/mips/kernel/scall64-n32.S
5221 @@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5222
5223 sd a3, PT_R26(sp) # save a3 for syscall restarting
5224
5225 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5226 + li t1, _TIF_SYSCALL_WORK
5227 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5228 and t0, t1, t0
5229 bnez t0, n32_syscall_trace_entry
5230 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5231 index cf3e75e..72e93fe 100644
5232 --- a/arch/mips/kernel/scall64-o32.S
5233 +++ b/arch/mips/kernel/scall64-o32.S
5234 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5235 PTR 4b, bad_stack
5236 .previous
5237
5238 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5239 + li t1, _TIF_SYSCALL_WORK
5240 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5241 and t0, t1, t0
5242 bnez t0, trace_a_syscall
5243 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5244 index ddcec1e..c7f983e 100644
5245 --- a/arch/mips/mm/fault.c
5246 +++ b/arch/mips/mm/fault.c
5247 @@ -27,6 +27,23 @@
5248 #include <asm/highmem.h> /* For VMALLOC_END */
5249 #include <linux/kdebug.h>
5250
5251 +#ifdef CONFIG_PAX_PAGEEXEC
5252 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5253 +{
5254 + unsigned long i;
5255 +
5256 + printk(KERN_ERR "PAX: bytes at PC: ");
5257 + for (i = 0; i < 5; i++) {
5258 + unsigned int c;
5259 + if (get_user(c, (unsigned int *)pc+i))
5260 + printk(KERN_CONT "???????? ");
5261 + else
5262 + printk(KERN_CONT "%08x ", c);
5263 + }
5264 + printk("\n");
5265 +}
5266 +#endif
5267 +
5268 /*
5269 * This routine handles page faults. It determines the address,
5270 * and the problem, and then passes it off to one of the appropriate
5271 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5272 index 7e5fe27..479a219 100644
5273 --- a/arch/mips/mm/mmap.c
5274 +++ b/arch/mips/mm/mmap.c
5275 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5276 struct vm_area_struct *vma;
5277 unsigned long addr = addr0;
5278 int do_color_align;
5279 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5280 struct vm_unmapped_area_info info;
5281
5282 if (unlikely(len > TASK_SIZE))
5283 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5284 do_color_align = 1;
5285
5286 /* requesting a specific address */
5287 +
5288 +#ifdef CONFIG_PAX_RANDMMAP
5289 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5290 +#endif
5291 +
5292 if (addr) {
5293 if (do_color_align)
5294 addr = COLOUR_ALIGN(addr, pgoff);
5295 @@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5296 addr = PAGE_ALIGN(addr);
5297
5298 vma = find_vma(mm, addr);
5299 - if (TASK_SIZE - len >= addr &&
5300 - (!vma || addr + len <= vma->vm_start))
5301 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5302 return addr;
5303 }
5304
5305 @@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5306 {
5307 unsigned long random_factor = 0UL;
5308
5309 +#ifdef CONFIG_PAX_RANDMMAP
5310 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5311 +#endif
5312 +
5313 if (current->flags & PF_RANDOMIZE) {
5314 random_factor = get_random_int();
5315 random_factor = random_factor << PAGE_SHIFT;
5316 @@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5317
5318 if (mmap_is_legacy()) {
5319 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5320 +
5321 +#ifdef CONFIG_PAX_RANDMMAP
5322 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5323 + mm->mmap_base += mm->delta_mmap;
5324 +#endif
5325 +
5326 mm->get_unmapped_area = arch_get_unmapped_area;
5327 mm->unmap_area = arch_unmap_area;
5328 } else {
5329 mm->mmap_base = mmap_base(random_factor);
5330 +
5331 +#ifdef CONFIG_PAX_RANDMMAP
5332 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5333 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5334 +#endif
5335 +
5336 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5337 mm->unmap_area = arch_unmap_area_topdown;
5338 }
5339 }
5340
5341 -static inline unsigned long brk_rnd(void)
5342 -{
5343 - unsigned long rnd = get_random_int();
5344 -
5345 - rnd = rnd << PAGE_SHIFT;
5346 - /* 8MB for 32bit, 256MB for 64bit */
5347 - if (TASK_IS_32BIT_ADDR)
5348 - rnd = rnd & 0x7ffffful;
5349 - else
5350 - rnd = rnd & 0xffffffful;
5351 -
5352 - return rnd;
5353 -}
5354 -
5355 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5356 -{
5357 - unsigned long base = mm->brk;
5358 - unsigned long ret;
5359 -
5360 - ret = PAGE_ALIGN(base + brk_rnd());
5361 -
5362 - if (ret < mm->brk)
5363 - return mm->brk;
5364 -
5365 - return ret;
5366 -}
5367 -
5368 int __virt_addr_valid(const volatile void *kaddr)
5369 {
5370 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5371 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5372 index 967d144..db12197 100644
5373 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5374 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5375 @@ -11,12 +11,14 @@
5376 #ifndef _ASM_PROC_CACHE_H
5377 #define _ASM_PROC_CACHE_H
5378
5379 +#include <linux/const.h>
5380 +
5381 /* L1 cache */
5382
5383 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5384 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5385 -#define L1_CACHE_BYTES 16 /* bytes per entry */
5386 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5387 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5388 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5389
5390 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5391 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5392 index bcb5df2..84fabd2 100644
5393 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5394 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5395 @@ -16,13 +16,15 @@
5396 #ifndef _ASM_PROC_CACHE_H
5397 #define _ASM_PROC_CACHE_H
5398
5399 +#include <linux/const.h>
5400 +
5401 /*
5402 * L1 cache
5403 */
5404 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5405 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5406 -#define L1_CACHE_BYTES 32 /* bytes per entry */
5407 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5408 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5409 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5410
5411 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5412 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5413 index 4ce7a01..449202a 100644
5414 --- a/arch/openrisc/include/asm/cache.h
5415 +++ b/arch/openrisc/include/asm/cache.h
5416 @@ -19,11 +19,13 @@
5417 #ifndef __ASM_OPENRISC_CACHE_H
5418 #define __ASM_OPENRISC_CACHE_H
5419
5420 +#include <linux/const.h>
5421 +
5422 /* FIXME: How can we replace these with values from the CPU...
5423 * they shouldn't be hard-coded!
5424 */
5425
5426 -#define L1_CACHE_BYTES 16
5427 #define L1_CACHE_SHIFT 4
5428 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5429
5430 #endif /* __ASM_OPENRISC_CACHE_H */
5431 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5432 index af9cf30..2aae9b2 100644
5433 --- a/arch/parisc/include/asm/atomic.h
5434 +++ b/arch/parisc/include/asm/atomic.h
5435 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5436
5437 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5438
5439 +#define atomic64_read_unchecked(v) atomic64_read(v)
5440 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5441 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5442 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5443 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5444 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5445 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5446 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5447 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5448 +
5449 #endif /* !CONFIG_64BIT */
5450
5451
5452 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5453 index 47f11c7..3420df2 100644
5454 --- a/arch/parisc/include/asm/cache.h
5455 +++ b/arch/parisc/include/asm/cache.h
5456 @@ -5,6 +5,7 @@
5457 #ifndef __ARCH_PARISC_CACHE_H
5458 #define __ARCH_PARISC_CACHE_H
5459
5460 +#include <linux/const.h>
5461
5462 /*
5463 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5464 @@ -15,13 +16,13 @@
5465 * just ruin performance.
5466 */
5467 #ifdef CONFIG_PA20
5468 -#define L1_CACHE_BYTES 64
5469 #define L1_CACHE_SHIFT 6
5470 #else
5471 -#define L1_CACHE_BYTES 32
5472 #define L1_CACHE_SHIFT 5
5473 #endif
5474
5475 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5476 +
5477 #ifndef __ASSEMBLY__
5478
5479 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5480 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5481 index 19f6cb1..6c78cf2 100644
5482 --- a/arch/parisc/include/asm/elf.h
5483 +++ b/arch/parisc/include/asm/elf.h
5484 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5485
5486 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5487
5488 +#ifdef CONFIG_PAX_ASLR
5489 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5490 +
5491 +#define PAX_DELTA_MMAP_LEN 16
5492 +#define PAX_DELTA_STACK_LEN 16
5493 +#endif
5494 +
5495 /* This yields a mask that user programs can use to figure out what
5496 instruction set this CPU supports. This could be done in user space,
5497 but it's not easy, and we've already done it here. */
5498 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5499 index fc987a1..6e068ef 100644
5500 --- a/arch/parisc/include/asm/pgalloc.h
5501 +++ b/arch/parisc/include/asm/pgalloc.h
5502 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5503 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5504 }
5505
5506 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5507 +{
5508 + pgd_populate(mm, pgd, pmd);
5509 +}
5510 +
5511 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5512 {
5513 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5514 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5515 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5516 #define pmd_free(mm, x) do { } while (0)
5517 #define pgd_populate(mm, pmd, pte) BUG()
5518 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
5519
5520 #endif
5521
5522 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5523 index 7df49fa..38b62bf 100644
5524 --- a/arch/parisc/include/asm/pgtable.h
5525 +++ b/arch/parisc/include/asm/pgtable.h
5526 @@ -218,6 +218,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5527 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5528 #define PAGE_COPY PAGE_EXECREAD
5529 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5530 +
5531 +#ifdef CONFIG_PAX_PAGEEXEC
5532 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5533 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5534 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5535 +#else
5536 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5537 +# define PAGE_COPY_NOEXEC PAGE_COPY
5538 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5539 +#endif
5540 +
5541 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5542 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5543 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5544 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5545 index 4ba2c93..f5e3974 100644
5546 --- a/arch/parisc/include/asm/uaccess.h
5547 +++ b/arch/parisc/include/asm/uaccess.h
5548 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5549 const void __user *from,
5550 unsigned long n)
5551 {
5552 - int sz = __compiletime_object_size(to);
5553 + size_t sz = __compiletime_object_size(to);
5554 int ret = -EFAULT;
5555
5556 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5557 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5558 ret = __copy_from_user(to, from, n);
5559 else
5560 copy_from_user_overflow();
5561 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5562 index 2a625fb..9908930 100644
5563 --- a/arch/parisc/kernel/module.c
5564 +++ b/arch/parisc/kernel/module.c
5565 @@ -98,16 +98,38 @@
5566
5567 /* three functions to determine where in the module core
5568 * or init pieces the location is */
5569 +static inline int in_init_rx(struct module *me, void *loc)
5570 +{
5571 + return (loc >= me->module_init_rx &&
5572 + loc < (me->module_init_rx + me->init_size_rx));
5573 +}
5574 +
5575 +static inline int in_init_rw(struct module *me, void *loc)
5576 +{
5577 + return (loc >= me->module_init_rw &&
5578 + loc < (me->module_init_rw + me->init_size_rw));
5579 +}
5580 +
5581 static inline int in_init(struct module *me, void *loc)
5582 {
5583 - return (loc >= me->module_init &&
5584 - loc <= (me->module_init + me->init_size));
5585 + return in_init_rx(me, loc) || in_init_rw(me, loc);
5586 +}
5587 +
5588 +static inline int in_core_rx(struct module *me, void *loc)
5589 +{
5590 + return (loc >= me->module_core_rx &&
5591 + loc < (me->module_core_rx + me->core_size_rx));
5592 +}
5593 +
5594 +static inline int in_core_rw(struct module *me, void *loc)
5595 +{
5596 + return (loc >= me->module_core_rw &&
5597 + loc < (me->module_core_rw + me->core_size_rw));
5598 }
5599
5600 static inline int in_core(struct module *me, void *loc)
5601 {
5602 - return (loc >= me->module_core &&
5603 - loc <= (me->module_core + me->core_size));
5604 + return in_core_rx(me, loc) || in_core_rw(me, loc);
5605 }
5606
5607 static inline int in_local(struct module *me, void *loc)
5608 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5609 }
5610
5611 /* align things a bit */
5612 - me->core_size = ALIGN(me->core_size, 16);
5613 - me->arch.got_offset = me->core_size;
5614 - me->core_size += gots * sizeof(struct got_entry);
5615 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
5616 + me->arch.got_offset = me->core_size_rw;
5617 + me->core_size_rw += gots * sizeof(struct got_entry);
5618
5619 - me->core_size = ALIGN(me->core_size, 16);
5620 - me->arch.fdesc_offset = me->core_size;
5621 - me->core_size += fdescs * sizeof(Elf_Fdesc);
5622 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
5623 + me->arch.fdesc_offset = me->core_size_rw;
5624 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5625
5626 me->arch.got_max = gots;
5627 me->arch.fdesc_max = fdescs;
5628 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5629
5630 BUG_ON(value == 0);
5631
5632 - got = me->module_core + me->arch.got_offset;
5633 + got = me->module_core_rw + me->arch.got_offset;
5634 for (i = 0; got[i].addr; i++)
5635 if (got[i].addr == value)
5636 goto out;
5637 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5638 #ifdef CONFIG_64BIT
5639 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5640 {
5641 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5642 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5643
5644 if (!value) {
5645 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5646 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5647
5648 /* Create new one */
5649 fdesc->addr = value;
5650 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5651 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5652 return (Elf_Addr)fdesc;
5653 }
5654 #endif /* CONFIG_64BIT */
5655 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5656
5657 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5658 end = table + sechdrs[me->arch.unwind_section].sh_size;
5659 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5660 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5661
5662 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5663 me->arch.unwind_section, table, end, gp);
5664 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5665 index f76c108..92bad82 100644
5666 --- a/arch/parisc/kernel/sys_parisc.c
5667 +++ b/arch/parisc/kernel/sys_parisc.c
5668 @@ -33,9 +33,11 @@
5669 #include <linux/utsname.h>
5670 #include <linux/personality.h>
5671
5672 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5673 +static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5674 + unsigned long flags)
5675 {
5676 struct vm_area_struct *vma;
5677 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5678
5679 addr = PAGE_ALIGN(addr);
5680
5681 @@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5682 /* At this point: (!vma || addr < vma->vm_end). */
5683 if (TASK_SIZE - len < addr)
5684 return -ENOMEM;
5685 - if (!vma || addr + len <= vma->vm_start)
5686 + if (check_heap_stack_gap(vma, addr, len, offset))
5687 return addr;
5688 addr = vma->vm_end;
5689 }
5690 @@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
5691 return offset & 0x3FF000;
5692 }
5693
5694 -static unsigned long get_shared_area(struct address_space *mapping,
5695 - unsigned long addr, unsigned long len, unsigned long pgoff)
5696 +static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5697 + unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5698 {
5699 struct vm_area_struct *vma;
5700 int offset = mapping ? get_offset(mapping) : 0;
5701 + unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5702
5703 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
5704
5705 @@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5706 /* At this point: (!vma || addr < vma->vm_end). */
5707 if (TASK_SIZE - len < addr)
5708 return -ENOMEM;
5709 - if (!vma || addr + len <= vma->vm_start)
5710 + if (check_heap_stack_gap(vma, addr, len, rand_offset))
5711 return addr;
5712 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
5713 if (addr < vma->vm_end) /* handle wraparound */
5714 @@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5715 if (flags & MAP_FIXED)
5716 return addr;
5717 if (!addr)
5718 - addr = TASK_UNMAPPED_BASE;
5719 + addr = current->mm->mmap_base;
5720
5721 if (filp) {
5722 - addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
5723 + addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
5724 } else if(flags & MAP_SHARED) {
5725 - addr = get_shared_area(NULL, addr, len, pgoff);
5726 + addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
5727 } else {
5728 - addr = get_unshared_area(addr, len);
5729 + addr = get_unshared_area(filp, addr, len, flags);
5730 }
5731 return addr;
5732 }
5733 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
5734 index 45ba99f..8e22c33 100644
5735 --- a/arch/parisc/kernel/traps.c
5736 +++ b/arch/parisc/kernel/traps.c
5737 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
5738
5739 down_read(&current->mm->mmap_sem);
5740 vma = find_vma(current->mm,regs->iaoq[0]);
5741 - if (vma && (regs->iaoq[0] >= vma->vm_start)
5742 - && (vma->vm_flags & VM_EXEC)) {
5743 -
5744 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
5745 fault_address = regs->iaoq[0];
5746 fault_space = regs->iasq[0];
5747
5748 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
5749 index 18162ce..94de376 100644
5750 --- a/arch/parisc/mm/fault.c
5751 +++ b/arch/parisc/mm/fault.c
5752 @@ -15,6 +15,7 @@
5753 #include <linux/sched.h>
5754 #include <linux/interrupt.h>
5755 #include <linux/module.h>
5756 +#include <linux/unistd.h>
5757
5758 #include <asm/uaccess.h>
5759 #include <asm/traps.h>
5760 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
5761 static unsigned long
5762 parisc_acctyp(unsigned long code, unsigned int inst)
5763 {
5764 - if (code == 6 || code == 16)
5765 + if (code == 6 || code == 7 || code == 16)
5766 return VM_EXEC;
5767
5768 switch (inst & 0xf0000000) {
5769 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
5770 }
5771 #endif
5772
5773 +#ifdef CONFIG_PAX_PAGEEXEC
5774 +/*
5775 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
5776 + *
5777 + * returns 1 when task should be killed
5778 + * 2 when rt_sigreturn trampoline was detected
5779 + * 3 when unpatched PLT trampoline was detected
5780 + */
5781 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5782 +{
5783 +
5784 +#ifdef CONFIG_PAX_EMUPLT
5785 + int err;
5786 +
5787 + do { /* PaX: unpatched PLT emulation */
5788 + unsigned int bl, depwi;
5789 +
5790 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
5791 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
5792 +
5793 + if (err)
5794 + break;
5795 +
5796 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
5797 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
5798 +
5799 + err = get_user(ldw, (unsigned int *)addr);
5800 + err |= get_user(bv, (unsigned int *)(addr+4));
5801 + err |= get_user(ldw2, (unsigned int *)(addr+8));
5802 +
5803 + if (err)
5804 + break;
5805 +
5806 + if (ldw == 0x0E801096U &&
5807 + bv == 0xEAC0C000U &&
5808 + ldw2 == 0x0E881095U)
5809 + {
5810 + unsigned int resolver, map;
5811 +
5812 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
5813 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
5814 + if (err)
5815 + break;
5816 +
5817 + regs->gr[20] = instruction_pointer(regs)+8;
5818 + regs->gr[21] = map;
5819 + regs->gr[22] = resolver;
5820 + regs->iaoq[0] = resolver | 3UL;
5821 + regs->iaoq[1] = regs->iaoq[0] + 4;
5822 + return 3;
5823 + }
5824 + }
5825 + } while (0);
5826 +#endif
5827 +
5828 +#ifdef CONFIG_PAX_EMUTRAMP
5829 +
5830 +#ifndef CONFIG_PAX_EMUSIGRT
5831 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
5832 + return 1;
5833 +#endif
5834 +
5835 + do { /* PaX: rt_sigreturn emulation */
5836 + unsigned int ldi1, ldi2, bel, nop;
5837 +
5838 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
5839 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
5840 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
5841 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
5842 +
5843 + if (err)
5844 + break;
5845 +
5846 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
5847 + ldi2 == 0x3414015AU &&
5848 + bel == 0xE4008200U &&
5849 + nop == 0x08000240U)
5850 + {
5851 + regs->gr[25] = (ldi1 & 2) >> 1;
5852 + regs->gr[20] = __NR_rt_sigreturn;
5853 + regs->gr[31] = regs->iaoq[1] + 16;
5854 + regs->sr[0] = regs->iasq[1];
5855 + regs->iaoq[0] = 0x100UL;
5856 + regs->iaoq[1] = regs->iaoq[0] + 4;
5857 + regs->iasq[0] = regs->sr[2];
5858 + regs->iasq[1] = regs->sr[2];
5859 + return 2;
5860 + }
5861 + } while (0);
5862 +#endif
5863 +
5864 + return 1;
5865 +}
5866 +
5867 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5868 +{
5869 + unsigned long i;
5870 +
5871 + printk(KERN_ERR "PAX: bytes at PC: ");
5872 + for (i = 0; i < 5; i++) {
5873 + unsigned int c;
5874 + if (get_user(c, (unsigned int *)pc+i))
5875 + printk(KERN_CONT "???????? ");
5876 + else
5877 + printk(KERN_CONT "%08x ", c);
5878 + }
5879 + printk("\n");
5880 +}
5881 +#endif
5882 +
5883 int fixup_exception(struct pt_regs *regs)
5884 {
5885 const struct exception_table_entry *fix;
5886 @@ -192,8 +303,33 @@ good_area:
5887
5888 acc_type = parisc_acctyp(code,regs->iir);
5889
5890 - if ((vma->vm_flags & acc_type) != acc_type)
5891 + if ((vma->vm_flags & acc_type) != acc_type) {
5892 +
5893 +#ifdef CONFIG_PAX_PAGEEXEC
5894 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
5895 + (address & ~3UL) == instruction_pointer(regs))
5896 + {
5897 + up_read(&mm->mmap_sem);
5898 + switch (pax_handle_fetch_fault(regs)) {
5899 +
5900 +#ifdef CONFIG_PAX_EMUPLT
5901 + case 3:
5902 + return;
5903 +#endif
5904 +
5905 +#ifdef CONFIG_PAX_EMUTRAMP
5906 + case 2:
5907 + return;
5908 +#endif
5909 +
5910 + }
5911 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
5912 + do_group_exit(SIGKILL);
5913 + }
5914 +#endif
5915 +
5916 goto bad_area;
5917 + }
5918
5919 /*
5920 * If for any reason at all we couldn't handle the fault, make
5921 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
5922 index e3b1d41..8e81edf 100644
5923 --- a/arch/powerpc/include/asm/atomic.h
5924 +++ b/arch/powerpc/include/asm/atomic.h
5925 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
5926 return t1;
5927 }
5928
5929 +#define atomic64_read_unchecked(v) atomic64_read(v)
5930 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5931 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5932 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5933 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5934 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5935 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5936 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5937 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5938 +
5939 #endif /* __powerpc64__ */
5940
5941 #endif /* __KERNEL__ */
5942 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
5943 index 9e495c9..b6878e5 100644
5944 --- a/arch/powerpc/include/asm/cache.h
5945 +++ b/arch/powerpc/include/asm/cache.h
5946 @@ -3,6 +3,7 @@
5947
5948 #ifdef __KERNEL__
5949
5950 +#include <linux/const.h>
5951
5952 /* bytes per L1 cache line */
5953 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
5954 @@ -22,7 +23,7 @@
5955 #define L1_CACHE_SHIFT 7
5956 #endif
5957
5958 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5959 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5960
5961 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5962
5963 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
5964 index 6abf0a1..459d0f1 100644
5965 --- a/arch/powerpc/include/asm/elf.h
5966 +++ b/arch/powerpc/include/asm/elf.h
5967 @@ -28,8 +28,19 @@
5968 the loader. We need to make sure that it is out of the way of the program
5969 that it will "exec", and that there is sufficient room for the brk. */
5970
5971 -extern unsigned long randomize_et_dyn(unsigned long base);
5972 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
5973 +#define ELF_ET_DYN_BASE (0x20000000)
5974 +
5975 +#ifdef CONFIG_PAX_ASLR
5976 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
5977 +
5978 +#ifdef __powerpc64__
5979 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
5980 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
5981 +#else
5982 +#define PAX_DELTA_MMAP_LEN 15
5983 +#define PAX_DELTA_STACK_LEN 15
5984 +#endif
5985 +#endif
5986
5987 /*
5988 * Our registers are always unsigned longs, whether we're a 32 bit
5989 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5990 (0x7ff >> (PAGE_SHIFT - 12)) : \
5991 (0x3ffff >> (PAGE_SHIFT - 12)))
5992
5993 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5994 -#define arch_randomize_brk arch_randomize_brk
5995 -
5996 -
5997 #ifdef CONFIG_SPU_BASE
5998 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
5999 #define NT_SPU 1
6000 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6001 index 8196e9c..d83a9f3 100644
6002 --- a/arch/powerpc/include/asm/exec.h
6003 +++ b/arch/powerpc/include/asm/exec.h
6004 @@ -4,6 +4,6 @@
6005 #ifndef _ASM_POWERPC_EXEC_H
6006 #define _ASM_POWERPC_EXEC_H
6007
6008 -extern unsigned long arch_align_stack(unsigned long sp);
6009 +#define arch_align_stack(x) ((x) & ~0xfUL)
6010
6011 #endif /* _ASM_POWERPC_EXEC_H */
6012 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6013 index 5acabbd..7ea14fa 100644
6014 --- a/arch/powerpc/include/asm/kmap_types.h
6015 +++ b/arch/powerpc/include/asm/kmap_types.h
6016 @@ -10,7 +10,7 @@
6017 * 2 of the License, or (at your option) any later version.
6018 */
6019
6020 -#define KM_TYPE_NR 16
6021 +#define KM_TYPE_NR 17
6022
6023 #endif /* __KERNEL__ */
6024 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6025 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6026 index 8565c25..2865190 100644
6027 --- a/arch/powerpc/include/asm/mman.h
6028 +++ b/arch/powerpc/include/asm/mman.h
6029 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6030 }
6031 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6032
6033 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6034 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6035 {
6036 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6037 }
6038 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6039 index f072e97..b436dee 100644
6040 --- a/arch/powerpc/include/asm/page.h
6041 +++ b/arch/powerpc/include/asm/page.h
6042 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6043 * and needs to be executable. This means the whole heap ends
6044 * up being executable.
6045 */
6046 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6047 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6048 +#define VM_DATA_DEFAULT_FLAGS32 \
6049 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6050 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6051
6052 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6053 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6054 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6055 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6056 #endif
6057
6058 +#define ktla_ktva(addr) (addr)
6059 +#define ktva_ktla(addr) (addr)
6060 +
6061 /*
6062 * Use the top bit of the higher-level page table entries to indicate whether
6063 * the entries we point to contain hugepages. This works because we know that
6064 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6065 index cd915d6..c10cee8 100644
6066 --- a/arch/powerpc/include/asm/page_64.h
6067 +++ b/arch/powerpc/include/asm/page_64.h
6068 @@ -154,15 +154,18 @@ do { \
6069 * stack by default, so in the absence of a PT_GNU_STACK program header
6070 * we turn execute permission off.
6071 */
6072 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6073 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6074 +#define VM_STACK_DEFAULT_FLAGS32 \
6075 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6076 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6077
6078 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6079 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6080
6081 +#ifndef CONFIG_PAX_PAGEEXEC
6082 #define VM_STACK_DEFAULT_FLAGS \
6083 (is_32bit_task() ? \
6084 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6085 +#endif
6086
6087 #include <asm-generic/getorder.h>
6088
6089 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6090 index 292725c..f87ae14 100644
6091 --- a/arch/powerpc/include/asm/pgalloc-64.h
6092 +++ b/arch/powerpc/include/asm/pgalloc-64.h
6093 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6094 #ifndef CONFIG_PPC_64K_PAGES
6095
6096 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6097 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6098
6099 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6100 {
6101 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6102 pud_set(pud, (unsigned long)pmd);
6103 }
6104
6105 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6106 +{
6107 + pud_populate(mm, pud, pmd);
6108 +}
6109 +
6110 #define pmd_populate(mm, pmd, pte_page) \
6111 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6112 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6113 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6114 #else /* CONFIG_PPC_64K_PAGES */
6115
6116 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6117 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6118
6119 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6120 pte_t *pte)
6121 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6122 index a9cbd3b..3b67efa 100644
6123 --- a/arch/powerpc/include/asm/pgtable.h
6124 +++ b/arch/powerpc/include/asm/pgtable.h
6125 @@ -2,6 +2,7 @@
6126 #define _ASM_POWERPC_PGTABLE_H
6127 #ifdef __KERNEL__
6128
6129 +#include <linux/const.h>
6130 #ifndef __ASSEMBLY__
6131 #include <asm/processor.h> /* For TASK_SIZE */
6132 #include <asm/mmu.h>
6133 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6134 index 4aad413..85d86bf 100644
6135 --- a/arch/powerpc/include/asm/pte-hash32.h
6136 +++ b/arch/powerpc/include/asm/pte-hash32.h
6137 @@ -21,6 +21,7 @@
6138 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6139 #define _PAGE_USER 0x004 /* usermode access allowed */
6140 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6141 +#define _PAGE_EXEC _PAGE_GUARDED
6142 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6143 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6144 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6145 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6146 index 3d5c9dc..62f8414 100644
6147 --- a/arch/powerpc/include/asm/reg.h
6148 +++ b/arch/powerpc/include/asm/reg.h
6149 @@ -215,6 +215,7 @@
6150 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6151 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6152 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6153 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6154 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6155 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6156 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6157 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6158 index 406b7b9..af63426 100644
6159 --- a/arch/powerpc/include/asm/thread_info.h
6160 +++ b/arch/powerpc/include/asm/thread_info.h
6161 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6162 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6163 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6164 #define TIF_SINGLESTEP 8 /* singlestepping active */
6165 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6166 #define TIF_SECCOMP 10 /* secure computing */
6167 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6168 #define TIF_NOERROR 12 /* Force successful syscall return */
6169 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6170 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6171 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6172 for stack store? */
6173 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6174 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6175 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6176
6177 /* as above, but as bit values */
6178 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6179 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6180 #define _TIF_UPROBE (1<<TIF_UPROBE)
6181 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6182 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6183 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6184 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6185 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6186 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6187 + _TIF_GRSEC_SETXID)
6188
6189 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6190 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6191 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6192 index 4db4959..335e00c 100644
6193 --- a/arch/powerpc/include/asm/uaccess.h
6194 +++ b/arch/powerpc/include/asm/uaccess.h
6195 @@ -13,6 +13,8 @@
6196 #define VERIFY_READ 0
6197 #define VERIFY_WRITE 1
6198
6199 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
6200 +
6201 /*
6202 * The fs value determines whether argument validity checking should be
6203 * performed or not. If get_fs() == USER_DS, checking is performed, with
6204 @@ -318,52 +320,6 @@ do { \
6205 extern unsigned long __copy_tofrom_user(void __user *to,
6206 const void __user *from, unsigned long size);
6207
6208 -#ifndef __powerpc64__
6209 -
6210 -static inline unsigned long copy_from_user(void *to,
6211 - const void __user *from, unsigned long n)
6212 -{
6213 - unsigned long over;
6214 -
6215 - if (access_ok(VERIFY_READ, from, n))
6216 - return __copy_tofrom_user((__force void __user *)to, from, n);
6217 - if ((unsigned long)from < TASK_SIZE) {
6218 - over = (unsigned long)from + n - TASK_SIZE;
6219 - return __copy_tofrom_user((__force void __user *)to, from,
6220 - n - over) + over;
6221 - }
6222 - return n;
6223 -}
6224 -
6225 -static inline unsigned long copy_to_user(void __user *to,
6226 - const void *from, unsigned long n)
6227 -{
6228 - unsigned long over;
6229 -
6230 - if (access_ok(VERIFY_WRITE, to, n))
6231 - return __copy_tofrom_user(to, (__force void __user *)from, n);
6232 - if ((unsigned long)to < TASK_SIZE) {
6233 - over = (unsigned long)to + n - TASK_SIZE;
6234 - return __copy_tofrom_user(to, (__force void __user *)from,
6235 - n - over) + over;
6236 - }
6237 - return n;
6238 -}
6239 -
6240 -#else /* __powerpc64__ */
6241 -
6242 -#define __copy_in_user(to, from, size) \
6243 - __copy_tofrom_user((to), (from), (size))
6244 -
6245 -extern unsigned long copy_from_user(void *to, const void __user *from,
6246 - unsigned long n);
6247 -extern unsigned long copy_to_user(void __user *to, const void *from,
6248 - unsigned long n);
6249 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
6250 - unsigned long n);
6251 -
6252 -#endif /* __powerpc64__ */
6253 -
6254 static inline unsigned long __copy_from_user_inatomic(void *to,
6255 const void __user *from, unsigned long n)
6256 {
6257 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6258 if (ret == 0)
6259 return 0;
6260 }
6261 +
6262 + if (!__builtin_constant_p(n))
6263 + check_object_size(to, n, false);
6264 +
6265 return __copy_tofrom_user((__force void __user *)to, from, n);
6266 }
6267
6268 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6269 if (ret == 0)
6270 return 0;
6271 }
6272 +
6273 + if (!__builtin_constant_p(n))
6274 + check_object_size(from, n, true);
6275 +
6276 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6277 }
6278
6279 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6280 return __copy_to_user_inatomic(to, from, size);
6281 }
6282
6283 +#ifndef __powerpc64__
6284 +
6285 +static inline unsigned long __must_check copy_from_user(void *to,
6286 + const void __user *from, unsigned long n)
6287 +{
6288 + unsigned long over;
6289 +
6290 + if ((long)n < 0)
6291 + return n;
6292 +
6293 + if (access_ok(VERIFY_READ, from, n)) {
6294 + if (!__builtin_constant_p(n))
6295 + check_object_size(to, n, false);
6296 + return __copy_tofrom_user((__force void __user *)to, from, n);
6297 + }
6298 + if ((unsigned long)from < TASK_SIZE) {
6299 + over = (unsigned long)from + n - TASK_SIZE;
6300 + if (!__builtin_constant_p(n - over))
6301 + check_object_size(to, n - over, false);
6302 + return __copy_tofrom_user((__force void __user *)to, from,
6303 + n - over) + over;
6304 + }
6305 + return n;
6306 +}
6307 +
6308 +static inline unsigned long __must_check copy_to_user(void __user *to,
6309 + const void *from, unsigned long n)
6310 +{
6311 + unsigned long over;
6312 +
6313 + if ((long)n < 0)
6314 + return n;
6315 +
6316 + if (access_ok(VERIFY_WRITE, to, n)) {
6317 + if (!__builtin_constant_p(n))
6318 + check_object_size(from, n, true);
6319 + return __copy_tofrom_user(to, (__force void __user *)from, n);
6320 + }
6321 + if ((unsigned long)to < TASK_SIZE) {
6322 + over = (unsigned long)to + n - TASK_SIZE;
6323 + if (!__builtin_constant_p(n))
6324 + check_object_size(from, n - over, true);
6325 + return __copy_tofrom_user(to, (__force void __user *)from,
6326 + n - over) + over;
6327 + }
6328 + return n;
6329 +}
6330 +
6331 +#else /* __powerpc64__ */
6332 +
6333 +#define __copy_in_user(to, from, size) \
6334 + __copy_tofrom_user((to), (from), (size))
6335 +
6336 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6337 +{
6338 + if ((long)n < 0 || n > INT_MAX)
6339 + return n;
6340 +
6341 + if (!__builtin_constant_p(n))
6342 + check_object_size(to, n, false);
6343 +
6344 + if (likely(access_ok(VERIFY_READ, from, n)))
6345 + n = __copy_from_user(to, from, n);
6346 + else
6347 + memset(to, 0, n);
6348 + return n;
6349 +}
6350 +
6351 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6352 +{
6353 + if ((long)n < 0 || n > INT_MAX)
6354 + return n;
6355 +
6356 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
6357 + if (!__builtin_constant_p(n))
6358 + check_object_size(from, n, true);
6359 + n = __copy_to_user(to, from, n);
6360 + }
6361 + return n;
6362 +}
6363 +
6364 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
6365 + unsigned long n);
6366 +
6367 +#endif /* __powerpc64__ */
6368 +
6369 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6370
6371 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6372 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6373 index 4684e33..acc4d19e 100644
6374 --- a/arch/powerpc/kernel/exceptions-64e.S
6375 +++ b/arch/powerpc/kernel/exceptions-64e.S
6376 @@ -715,6 +715,7 @@ storage_fault_common:
6377 std r14,_DAR(r1)
6378 std r15,_DSISR(r1)
6379 addi r3,r1,STACK_FRAME_OVERHEAD
6380 + bl .save_nvgprs
6381 mr r4,r14
6382 mr r5,r15
6383 ld r14,PACA_EXGEN+EX_R14(r13)
6384 @@ -723,8 +724,7 @@ storage_fault_common:
6385 cmpdi r3,0
6386 bne- 1f
6387 b .ret_from_except_lite
6388 -1: bl .save_nvgprs
6389 - mr r5,r3
6390 +1: mr r5,r3
6391 addi r3,r1,STACK_FRAME_OVERHEAD
6392 ld r4,_DAR(r1)
6393 bl .bad_page_fault
6394 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6395 index 4665e82..080ea99 100644
6396 --- a/arch/powerpc/kernel/exceptions-64s.S
6397 +++ b/arch/powerpc/kernel/exceptions-64s.S
6398 @@ -1206,10 +1206,10 @@ handle_page_fault:
6399 11: ld r4,_DAR(r1)
6400 ld r5,_DSISR(r1)
6401 addi r3,r1,STACK_FRAME_OVERHEAD
6402 + bl .save_nvgprs
6403 bl .do_page_fault
6404 cmpdi r3,0
6405 beq+ 12f
6406 - bl .save_nvgprs
6407 mr r5,r3
6408 addi r3,r1,STACK_FRAME_OVERHEAD
6409 lwz r4,_DAR(r1)
6410 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6411 index 2e3200c..72095ce 100644
6412 --- a/arch/powerpc/kernel/module_32.c
6413 +++ b/arch/powerpc/kernel/module_32.c
6414 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6415 me->arch.core_plt_section = i;
6416 }
6417 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6418 - printk("Module doesn't contain .plt or .init.plt sections.\n");
6419 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6420 return -ENOEXEC;
6421 }
6422
6423 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6424
6425 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6426 /* Init, or core PLT? */
6427 - if (location >= mod->module_core
6428 - && location < mod->module_core + mod->core_size)
6429 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6430 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6431 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6432 - else
6433 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6434 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6435 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6436 + else {
6437 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6438 + return ~0UL;
6439 + }
6440
6441 /* Find this entry, or if that fails, the next avail. entry */
6442 while (entry->jump[0]) {
6443 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6444 index 8143067..21ae55b 100644
6445 --- a/arch/powerpc/kernel/process.c
6446 +++ b/arch/powerpc/kernel/process.c
6447 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6448 * Lookup NIP late so we have the best change of getting the
6449 * above info out without failing
6450 */
6451 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6452 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6453 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6454 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6455 #endif
6456 show_stack(current, (unsigned long *) regs->gpr[1]);
6457 if (!user_mode(regs))
6458 @@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6459 newsp = stack[0];
6460 ip = stack[STACK_FRAME_LR_SAVE];
6461 if (!firstframe || ip != lr) {
6462 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6463 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6464 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6465 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6466 - printk(" (%pS)",
6467 + printk(" (%pA)",
6468 (void *)current->ret_stack[curr_frame].ret);
6469 curr_frame--;
6470 }
6471 @@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6472 struct pt_regs *regs = (struct pt_regs *)
6473 (sp + STACK_FRAME_OVERHEAD);
6474 lr = regs->link;
6475 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
6476 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
6477 regs->trap, (void *)regs->nip, (void *)lr);
6478 firstframe = 1;
6479 }
6480 @@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
6481 mtspr(SPRN_CTRLT, ctrl);
6482 }
6483 #endif /* CONFIG_PPC64 */
6484 -
6485 -unsigned long arch_align_stack(unsigned long sp)
6486 -{
6487 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6488 - sp -= get_random_int() & ~PAGE_MASK;
6489 - return sp & ~0xf;
6490 -}
6491 -
6492 -static inline unsigned long brk_rnd(void)
6493 -{
6494 - unsigned long rnd = 0;
6495 -
6496 - /* 8MB for 32bit, 1GB for 64bit */
6497 - if (is_32bit_task())
6498 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6499 - else
6500 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6501 -
6502 - return rnd << PAGE_SHIFT;
6503 -}
6504 -
6505 -unsigned long arch_randomize_brk(struct mm_struct *mm)
6506 -{
6507 - unsigned long base = mm->brk;
6508 - unsigned long ret;
6509 -
6510 -#ifdef CONFIG_PPC_STD_MMU_64
6511 - /*
6512 - * If we are using 1TB segments and we are allowed to randomise
6513 - * the heap, we can put it above 1TB so it is backed by a 1TB
6514 - * segment. Otherwise the heap will be in the bottom 1TB
6515 - * which always uses 256MB segments and this may result in a
6516 - * performance penalty.
6517 - */
6518 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6519 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6520 -#endif
6521 -
6522 - ret = PAGE_ALIGN(base + brk_rnd());
6523 -
6524 - if (ret < mm->brk)
6525 - return mm->brk;
6526 -
6527 - return ret;
6528 -}
6529 -
6530 -unsigned long randomize_et_dyn(unsigned long base)
6531 -{
6532 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6533 -
6534 - if (ret < base)
6535 - return base;
6536 -
6537 - return ret;
6538 -}
6539 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6540 index c497000..8fde506 100644
6541 --- a/arch/powerpc/kernel/ptrace.c
6542 +++ b/arch/powerpc/kernel/ptrace.c
6543 @@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
6544 return ret;
6545 }
6546
6547 +#ifdef CONFIG_GRKERNSEC_SETXID
6548 +extern void gr_delayed_cred_worker(void);
6549 +#endif
6550 +
6551 /*
6552 * We must return the syscall number to actually look up in the table.
6553 * This can be -1L to skip running any syscall at all.
6554 @@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6555
6556 secure_computing_strict(regs->gpr[0]);
6557
6558 +#ifdef CONFIG_GRKERNSEC_SETXID
6559 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6560 + gr_delayed_cred_worker();
6561 +#endif
6562 +
6563 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6564 tracehook_report_syscall_entry(regs))
6565 /*
6566 @@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6567 {
6568 int step;
6569
6570 +#ifdef CONFIG_GRKERNSEC_SETXID
6571 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6572 + gr_delayed_cred_worker();
6573 +#endif
6574 +
6575 audit_syscall_exit(regs);
6576
6577 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6578 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6579 index 804e323..79181c1 100644
6580 --- a/arch/powerpc/kernel/signal_32.c
6581 +++ b/arch/powerpc/kernel/signal_32.c
6582 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6583 /* Save user registers on the stack */
6584 frame = &rt_sf->uc.uc_mcontext;
6585 addr = frame;
6586 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6587 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6588 if (save_user_regs(regs, frame, 0, 1))
6589 goto badframe;
6590 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6591 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6592 index 1ca045d..139c3f7 100644
6593 --- a/arch/powerpc/kernel/signal_64.c
6594 +++ b/arch/powerpc/kernel/signal_64.c
6595 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6596 current->thread.fpscr.val = 0;
6597
6598 /* Set up to return from userspace. */
6599 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6600 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6601 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6602 } else {
6603 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6604 diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6605 index 3ce1f86..c30e629 100644
6606 --- a/arch/powerpc/kernel/sysfs.c
6607 +++ b/arch/powerpc/kernel/sysfs.c
6608 @@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6609 return NOTIFY_OK;
6610 }
6611
6612 -static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6613 +static struct notifier_block sysfs_cpu_nb = {
6614 .notifier_call = sysfs_cpu_notify,
6615 };
6616
6617 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6618 index 3251840..3f7c77a 100644
6619 --- a/arch/powerpc/kernel/traps.c
6620 +++ b/arch/powerpc/kernel/traps.c
6621 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6622 return flags;
6623 }
6624
6625 +extern void gr_handle_kernel_exploit(void);
6626 +
6627 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6628 int signr)
6629 {
6630 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6631 panic("Fatal exception in interrupt");
6632 if (panic_on_oops)
6633 panic("Fatal exception");
6634 +
6635 + gr_handle_kernel_exploit();
6636 +
6637 do_exit(signr);
6638 }
6639
6640 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6641 index 1b2076f..835e4be 100644
6642 --- a/arch/powerpc/kernel/vdso.c
6643 +++ b/arch/powerpc/kernel/vdso.c
6644 @@ -34,6 +34,7 @@
6645 #include <asm/firmware.h>
6646 #include <asm/vdso.h>
6647 #include <asm/vdso_datapage.h>
6648 +#include <asm/mman.h>
6649
6650 #include "setup.h"
6651
6652 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6653 vdso_base = VDSO32_MBASE;
6654 #endif
6655
6656 - current->mm->context.vdso_base = 0;
6657 + current->mm->context.vdso_base = ~0UL;
6658
6659 /* vDSO has a problem and was disabled, just don't "enable" it for the
6660 * process
6661 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6662 vdso_base = get_unmapped_area(NULL, vdso_base,
6663 (vdso_pages << PAGE_SHIFT) +
6664 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6665 - 0, 0);
6666 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
6667 if (IS_ERR_VALUE(vdso_base)) {
6668 rc = vdso_base;
6669 goto fail_mmapsem;
6670 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6671 index 5eea6f3..5d10396 100644
6672 --- a/arch/powerpc/lib/usercopy_64.c
6673 +++ b/arch/powerpc/lib/usercopy_64.c
6674 @@ -9,22 +9,6 @@
6675 #include <linux/module.h>
6676 #include <asm/uaccess.h>
6677
6678 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6679 -{
6680 - if (likely(access_ok(VERIFY_READ, from, n)))
6681 - n = __copy_from_user(to, from, n);
6682 - else
6683 - memset(to, 0, n);
6684 - return n;
6685 -}
6686 -
6687 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6688 -{
6689 - if (likely(access_ok(VERIFY_WRITE, to, n)))
6690 - n = __copy_to_user(to, from, n);
6691 - return n;
6692 -}
6693 -
6694 unsigned long copy_in_user(void __user *to, const void __user *from,
6695 unsigned long n)
6696 {
6697 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6698 return n;
6699 }
6700
6701 -EXPORT_SYMBOL(copy_from_user);
6702 -EXPORT_SYMBOL(copy_to_user);
6703 EXPORT_SYMBOL(copy_in_user);
6704
6705 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6706 index 3a8489a..6a63b3b 100644
6707 --- a/arch/powerpc/mm/fault.c
6708 +++ b/arch/powerpc/mm/fault.c
6709 @@ -32,6 +32,10 @@
6710 #include <linux/perf_event.h>
6711 #include <linux/magic.h>
6712 #include <linux/ratelimit.h>
6713 +#include <linux/slab.h>
6714 +#include <linux/pagemap.h>
6715 +#include <linux/compiler.h>
6716 +#include <linux/unistd.h>
6717
6718 #include <asm/firmware.h>
6719 #include <asm/page.h>
6720 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6721 }
6722 #endif
6723
6724 +#ifdef CONFIG_PAX_PAGEEXEC
6725 +/*
6726 + * PaX: decide what to do with offenders (regs->nip = fault address)
6727 + *
6728 + * returns 1 when task should be killed
6729 + */
6730 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6731 +{
6732 + return 1;
6733 +}
6734 +
6735 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6736 +{
6737 + unsigned long i;
6738 +
6739 + printk(KERN_ERR "PAX: bytes at PC: ");
6740 + for (i = 0; i < 5; i++) {
6741 + unsigned int c;
6742 + if (get_user(c, (unsigned int __user *)pc+i))
6743 + printk(KERN_CONT "???????? ");
6744 + else
6745 + printk(KERN_CONT "%08x ", c);
6746 + }
6747 + printk("\n");
6748 +}
6749 +#endif
6750 +
6751 /*
6752 * Check whether the instruction at regs->nip is a store using
6753 * an update addressing form which will update r1.
6754 @@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
6755 * indicate errors in DSISR but can validly be set in SRR1.
6756 */
6757 if (trap == 0x400)
6758 - error_code &= 0x48200000;
6759 + error_code &= 0x58200000;
6760 else
6761 is_write = error_code & DSISR_ISSTORE;
6762 #else
6763 @@ -364,7 +395,7 @@ good_area:
6764 * "undefined". Of those that can be set, this is the only
6765 * one which seems bad.
6766 */
6767 - if (error_code & 0x10000000)
6768 + if (error_code & DSISR_GUARDED)
6769 /* Guarded storage error. */
6770 goto bad_area;
6771 #endif /* CONFIG_8xx */
6772 @@ -379,7 +410,7 @@ good_area:
6773 * processors use the same I/D cache coherency mechanism
6774 * as embedded.
6775 */
6776 - if (error_code & DSISR_PROTFAULT)
6777 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
6778 goto bad_area;
6779 #endif /* CONFIG_PPC_STD_MMU */
6780
6781 @@ -462,6 +493,23 @@ bad_area:
6782 bad_area_nosemaphore:
6783 /* User mode accesses cause a SIGSEGV */
6784 if (user_mode(regs)) {
6785 +
6786 +#ifdef CONFIG_PAX_PAGEEXEC
6787 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
6788 +#ifdef CONFIG_PPC_STD_MMU
6789 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
6790 +#else
6791 + if (is_exec && regs->nip == address) {
6792 +#endif
6793 + switch (pax_handle_fetch_fault(regs)) {
6794 + }
6795 +
6796 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
6797 + do_group_exit(SIGKILL);
6798 + }
6799 + }
6800 +#endif
6801 +
6802 _exception(SIGSEGV, regs, code, address);
6803 return 0;
6804 }
6805 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
6806 index 67a42ed..cd463e0 100644
6807 --- a/arch/powerpc/mm/mmap_64.c
6808 +++ b/arch/powerpc/mm/mmap_64.c
6809 @@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
6810 {
6811 unsigned long rnd = 0;
6812
6813 +#ifdef CONFIG_PAX_RANDMMAP
6814 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6815 +#endif
6816 +
6817 if (current->flags & PF_RANDOMIZE) {
6818 /* 8MB for 32bit, 1GB for 64bit */
6819 if (is_32bit_task())
6820 @@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6821 */
6822 if (mmap_is_legacy()) {
6823 mm->mmap_base = TASK_UNMAPPED_BASE;
6824 +
6825 +#ifdef CONFIG_PAX_RANDMMAP
6826 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6827 + mm->mmap_base += mm->delta_mmap;
6828 +#endif
6829 +
6830 mm->get_unmapped_area = arch_get_unmapped_area;
6831 mm->unmap_area = arch_unmap_area;
6832 } else {
6833 mm->mmap_base = mmap_base();
6834 +
6835 +#ifdef CONFIG_PAX_RANDMMAP
6836 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6837 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6838 +#endif
6839 +
6840 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6841 mm->unmap_area = arch_unmap_area_topdown;
6842 }
6843 diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
6844 index e779642..e5bb889 100644
6845 --- a/arch/powerpc/mm/mmu_context_nohash.c
6846 +++ b/arch/powerpc/mm/mmu_context_nohash.c
6847 @@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
6848 return NOTIFY_OK;
6849 }
6850
6851 -static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
6852 +static struct notifier_block mmu_context_cpu_nb = {
6853 .notifier_call = mmu_context_cpu_notify,
6854 };
6855
6856 diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
6857 index bba87ca..c346a33 100644
6858 --- a/arch/powerpc/mm/numa.c
6859 +++ b/arch/powerpc/mm/numa.c
6860 @@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
6861 return ret;
6862 }
6863
6864 -static struct notifier_block __cpuinitdata ppc64_numa_nb = {
6865 +static struct notifier_block ppc64_numa_nb = {
6866 .notifier_call = cpu_numa_callback,
6867 .priority = 1 /* Must run before sched domains notifier. */
6868 };
6869 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
6870 index cf9dada..241529f 100644
6871 --- a/arch/powerpc/mm/slice.c
6872 +++ b/arch/powerpc/mm/slice.c
6873 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
6874 if ((mm->task_size - len) < addr)
6875 return 0;
6876 vma = find_vma(mm, addr);
6877 - return (!vma || (addr + len) <= vma->vm_start);
6878 + return check_heap_stack_gap(vma, addr, len, 0);
6879 }
6880
6881 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
6882 @@ -272,7 +272,7 @@ full_search:
6883 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
6884 continue;
6885 }
6886 - if (!vma || addr + len <= vma->vm_start) {
6887 + if (check_heap_stack_gap(vma, addr, len, 0)) {
6888 /*
6889 * Remember the place where we stopped the search:
6890 */
6891 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6892 }
6893 }
6894
6895 - addr = mm->mmap_base;
6896 - while (addr > len) {
6897 + if (mm->mmap_base < len)
6898 + addr = -ENOMEM;
6899 + else
6900 + addr = mm->mmap_base - len;
6901 +
6902 + while (!IS_ERR_VALUE(addr)) {
6903 /* Go down by chunk size */
6904 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
6905 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
6906
6907 /* Check for hit with different page size */
6908 mask = slice_range_to_mask(addr, len);
6909 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6910 * return with success:
6911 */
6912 vma = find_vma(mm, addr);
6913 - if (!vma || (addr + len) <= vma->vm_start) {
6914 + if (check_heap_stack_gap(vma, addr, len, 0)) {
6915 /* remember the address as a hint for next time */
6916 if (use_cache)
6917 mm->free_area_cache = addr;
6918 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6919 mm->cached_hole_size = vma->vm_start - addr;
6920
6921 /* try just below the current vma->vm_start */
6922 - addr = vma->vm_start;
6923 + addr = skip_heap_stack_gap(vma, len, 0);
6924 }
6925
6926 /*
6927 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
6928 if (fixed && addr > (mm->task_size - len))
6929 return -EINVAL;
6930
6931 +#ifdef CONFIG_PAX_RANDMMAP
6932 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
6933 + addr = 0;
6934 +#endif
6935 +
6936 /* If hint, make sure it matches our alignment restrictions */
6937 if (!fixed && addr) {
6938 addr = _ALIGN_UP(addr, 1ul << pshift);
6939 diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
6940 index bdb738a..49c9f95 100644
6941 --- a/arch/powerpc/platforms/powermac/smp.c
6942 +++ b/arch/powerpc/platforms/powermac/smp.c
6943 @@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
6944 return NOTIFY_OK;
6945 }
6946
6947 -static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
6948 +static struct notifier_block smp_core99_cpu_nb = {
6949 .notifier_call = smp_core99_cpu_notify,
6950 };
6951 #endif /* CONFIG_HOTPLUG_CPU */
6952 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
6953 index c797832..ce575c8 100644
6954 --- a/arch/s390/include/asm/atomic.h
6955 +++ b/arch/s390/include/asm/atomic.h
6956 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
6957 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
6958 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6959
6960 +#define atomic64_read_unchecked(v) atomic64_read(v)
6961 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6962 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6963 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6964 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6965 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
6966 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6967 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
6968 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6969 +
6970 #define smp_mb__before_atomic_dec() smp_mb()
6971 #define smp_mb__after_atomic_dec() smp_mb()
6972 #define smp_mb__before_atomic_inc() smp_mb()
6973 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
6974 index 4d7ccac..d03d0ad 100644
6975 --- a/arch/s390/include/asm/cache.h
6976 +++ b/arch/s390/include/asm/cache.h
6977 @@ -9,8 +9,10 @@
6978 #ifndef __ARCH_S390_CACHE_H
6979 #define __ARCH_S390_CACHE_H
6980
6981 -#define L1_CACHE_BYTES 256
6982 +#include <linux/const.h>
6983 +
6984 #define L1_CACHE_SHIFT 8
6985 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6986 #define NET_SKB_PAD 32
6987
6988 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6989 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
6990 index 178ff96..8c93bd1 100644
6991 --- a/arch/s390/include/asm/elf.h
6992 +++ b/arch/s390/include/asm/elf.h
6993 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
6994 the loader. We need to make sure that it is out of the way of the program
6995 that it will "exec", and that there is sufficient room for the brk. */
6996
6997 -extern unsigned long randomize_et_dyn(unsigned long base);
6998 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
6999 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7000 +
7001 +#ifdef CONFIG_PAX_ASLR
7002 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7003 +
7004 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7005 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7006 +#endif
7007
7008 /* This yields a mask that user programs can use to figure out what
7009 instruction set this CPU supports. */
7010 @@ -210,9 +216,6 @@ struct linux_binprm;
7011 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7012 int arch_setup_additional_pages(struct linux_binprm *, int);
7013
7014 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7015 -#define arch_randomize_brk arch_randomize_brk
7016 -
7017 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7018
7019 #endif
7020 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7021 index c4a93d6..4d2a9b4 100644
7022 --- a/arch/s390/include/asm/exec.h
7023 +++ b/arch/s390/include/asm/exec.h
7024 @@ -7,6 +7,6 @@
7025 #ifndef __ASM_EXEC_H
7026 #define __ASM_EXEC_H
7027
7028 -extern unsigned long arch_align_stack(unsigned long sp);
7029 +#define arch_align_stack(x) ((x) & ~0xfUL)
7030
7031 #endif /* __ASM_EXEC_H */
7032 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7033 index 34268df..ea97318 100644
7034 --- a/arch/s390/include/asm/uaccess.h
7035 +++ b/arch/s390/include/asm/uaccess.h
7036 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
7037 copy_to_user(void __user *to, const void *from, unsigned long n)
7038 {
7039 might_fault();
7040 +
7041 + if ((long)n < 0)
7042 + return n;
7043 +
7044 if (access_ok(VERIFY_WRITE, to, n))
7045 n = __copy_to_user(to, from, n);
7046 return n;
7047 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7048 static inline unsigned long __must_check
7049 __copy_from_user(void *to, const void __user *from, unsigned long n)
7050 {
7051 + if ((long)n < 0)
7052 + return n;
7053 +
7054 if (__builtin_constant_p(n) && (n <= 256))
7055 return uaccess.copy_from_user_small(n, from, to);
7056 else
7057 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7058 static inline unsigned long __must_check
7059 copy_from_user(void *to, const void __user *from, unsigned long n)
7060 {
7061 - unsigned int sz = __compiletime_object_size(to);
7062 + size_t sz = __compiletime_object_size(to);
7063
7064 might_fault();
7065 - if (unlikely(sz != -1 && sz < n)) {
7066 +
7067 + if ((long)n < 0)
7068 + return n;
7069 +
7070 + if (unlikely(sz != (size_t)-1 && sz < n)) {
7071 copy_from_user_overflow();
7072 return n;
7073 }
7074 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7075 index 4610dea..cf0af21 100644
7076 --- a/arch/s390/kernel/module.c
7077 +++ b/arch/s390/kernel/module.c
7078 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7079
7080 /* Increase core size by size of got & plt and set start
7081 offsets for got and plt. */
7082 - me->core_size = ALIGN(me->core_size, 4);
7083 - me->arch.got_offset = me->core_size;
7084 - me->core_size += me->arch.got_size;
7085 - me->arch.plt_offset = me->core_size;
7086 - me->core_size += me->arch.plt_size;
7087 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
7088 + me->arch.got_offset = me->core_size_rw;
7089 + me->core_size_rw += me->arch.got_size;
7090 + me->arch.plt_offset = me->core_size_rx;
7091 + me->core_size_rx += me->arch.plt_size;
7092 return 0;
7093 }
7094
7095 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7096 if (info->got_initialized == 0) {
7097 Elf_Addr *gotent;
7098
7099 - gotent = me->module_core + me->arch.got_offset +
7100 + gotent = me->module_core_rw + me->arch.got_offset +
7101 info->got_offset;
7102 *gotent = val;
7103 info->got_initialized = 1;
7104 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7105 else if (r_type == R_390_GOTENT ||
7106 r_type == R_390_GOTPLTENT)
7107 *(unsigned int *) loc =
7108 - (val + (Elf_Addr) me->module_core - loc) >> 1;
7109 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7110 else if (r_type == R_390_GOT64 ||
7111 r_type == R_390_GOTPLT64)
7112 *(unsigned long *) loc = val;
7113 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7114 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7115 if (info->plt_initialized == 0) {
7116 unsigned int *ip;
7117 - ip = me->module_core + me->arch.plt_offset +
7118 + ip = me->module_core_rx + me->arch.plt_offset +
7119 info->plt_offset;
7120 #ifndef CONFIG_64BIT
7121 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7122 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7123 val - loc + 0xffffUL < 0x1ffffeUL) ||
7124 (r_type == R_390_PLT32DBL &&
7125 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7126 - val = (Elf_Addr) me->module_core +
7127 + val = (Elf_Addr) me->module_core_rx +
7128 me->arch.plt_offset +
7129 info->plt_offset;
7130 val += rela->r_addend - loc;
7131 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7132 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7133 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7134 val = val + rela->r_addend -
7135 - ((Elf_Addr) me->module_core + me->arch.got_offset);
7136 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7137 if (r_type == R_390_GOTOFF16)
7138 *(unsigned short *) loc = val;
7139 else if (r_type == R_390_GOTOFF32)
7140 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7141 break;
7142 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7143 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7144 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
7145 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7146 rela->r_addend - loc;
7147 if (r_type == R_390_GOTPC)
7148 *(unsigned int *) loc = val;
7149 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7150 index 536d645..4a5bd9e 100644
7151 --- a/arch/s390/kernel/process.c
7152 +++ b/arch/s390/kernel/process.c
7153 @@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7154 }
7155 return 0;
7156 }
7157 -
7158 -unsigned long arch_align_stack(unsigned long sp)
7159 -{
7160 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7161 - sp -= get_random_int() & ~PAGE_MASK;
7162 - return sp & ~0xf;
7163 -}
7164 -
7165 -static inline unsigned long brk_rnd(void)
7166 -{
7167 - /* 8MB for 32bit, 1GB for 64bit */
7168 - if (is_32bit_task())
7169 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7170 - else
7171 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7172 -}
7173 -
7174 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7175 -{
7176 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7177 -
7178 - if (ret < mm->brk)
7179 - return mm->brk;
7180 - return ret;
7181 -}
7182 -
7183 -unsigned long randomize_et_dyn(unsigned long base)
7184 -{
7185 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7186 -
7187 - if (!(current->flags & PF_RANDOMIZE))
7188 - return base;
7189 - if (ret < base)
7190 - return base;
7191 - return ret;
7192 -}
7193 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7194 index c59a5ef..3fae59c 100644
7195 --- a/arch/s390/mm/mmap.c
7196 +++ b/arch/s390/mm/mmap.c
7197 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7198 */
7199 if (mmap_is_legacy()) {
7200 mm->mmap_base = TASK_UNMAPPED_BASE;
7201 +
7202 +#ifdef CONFIG_PAX_RANDMMAP
7203 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7204 + mm->mmap_base += mm->delta_mmap;
7205 +#endif
7206 +
7207 mm->get_unmapped_area = arch_get_unmapped_area;
7208 mm->unmap_area = arch_unmap_area;
7209 } else {
7210 mm->mmap_base = mmap_base();
7211 +
7212 +#ifdef CONFIG_PAX_RANDMMAP
7213 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7214 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7215 +#endif
7216 +
7217 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7218 mm->unmap_area = arch_unmap_area_topdown;
7219 }
7220 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7221 */
7222 if (mmap_is_legacy()) {
7223 mm->mmap_base = TASK_UNMAPPED_BASE;
7224 +
7225 +#ifdef CONFIG_PAX_RANDMMAP
7226 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7227 + mm->mmap_base += mm->delta_mmap;
7228 +#endif
7229 +
7230 mm->get_unmapped_area = s390_get_unmapped_area;
7231 mm->unmap_area = arch_unmap_area;
7232 } else {
7233 mm->mmap_base = mmap_base();
7234 +
7235 +#ifdef CONFIG_PAX_RANDMMAP
7236 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7237 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7238 +#endif
7239 +
7240 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7241 mm->unmap_area = arch_unmap_area_topdown;
7242 }
7243 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7244 index ae3d59f..f65f075 100644
7245 --- a/arch/score/include/asm/cache.h
7246 +++ b/arch/score/include/asm/cache.h
7247 @@ -1,7 +1,9 @@
7248 #ifndef _ASM_SCORE_CACHE_H
7249 #define _ASM_SCORE_CACHE_H
7250
7251 +#include <linux/const.h>
7252 +
7253 #define L1_CACHE_SHIFT 4
7254 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7255 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7256
7257 #endif /* _ASM_SCORE_CACHE_H */
7258 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7259 index f9f3cd5..58ff438 100644
7260 --- a/arch/score/include/asm/exec.h
7261 +++ b/arch/score/include/asm/exec.h
7262 @@ -1,6 +1,6 @@
7263 #ifndef _ASM_SCORE_EXEC_H
7264 #define _ASM_SCORE_EXEC_H
7265
7266 -extern unsigned long arch_align_stack(unsigned long sp);
7267 +#define arch_align_stack(x) (x)
7268
7269 #endif /* _ASM_SCORE_EXEC_H */
7270 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7271 index 7956846..5f37677 100644
7272 --- a/arch/score/kernel/process.c
7273 +++ b/arch/score/kernel/process.c
7274 @@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7275
7276 return task_pt_regs(task)->cp0_epc;
7277 }
7278 -
7279 -unsigned long arch_align_stack(unsigned long sp)
7280 -{
7281 - return sp;
7282 -}
7283 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7284 index ef9e555..331bd29 100644
7285 --- a/arch/sh/include/asm/cache.h
7286 +++ b/arch/sh/include/asm/cache.h
7287 @@ -9,10 +9,11 @@
7288 #define __ASM_SH_CACHE_H
7289 #ifdef __KERNEL__
7290
7291 +#include <linux/const.h>
7292 #include <linux/init.h>
7293 #include <cpu/cache.h>
7294
7295 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7296 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7297
7298 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7299
7300 diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7301 index 03f2b55..b027032 100644
7302 --- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7303 +++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7304 @@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7305 return NOTIFY_OK;
7306 }
7307
7308 -static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7309 +static struct notifier_block shx3_cpu_notifier = {
7310 .notifier_call = shx3_cpu_callback,
7311 };
7312
7313 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7314 index 6777177..cb5e44f 100644
7315 --- a/arch/sh/mm/mmap.c
7316 +++ b/arch/sh/mm/mmap.c
7317 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7318 struct mm_struct *mm = current->mm;
7319 struct vm_area_struct *vma;
7320 int do_colour_align;
7321 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7322 struct vm_unmapped_area_info info;
7323
7324 if (flags & MAP_FIXED) {
7325 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7326 if (filp || (flags & MAP_SHARED))
7327 do_colour_align = 1;
7328
7329 +#ifdef CONFIG_PAX_RANDMMAP
7330 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7331 +#endif
7332 +
7333 if (addr) {
7334 if (do_colour_align)
7335 addr = COLOUR_ALIGN(addr, pgoff);
7336 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7337 addr = PAGE_ALIGN(addr);
7338
7339 vma = find_vma(mm, addr);
7340 - if (TASK_SIZE - len >= addr &&
7341 - (!vma || addr + len <= vma->vm_start))
7342 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7343 return addr;
7344 }
7345
7346 info.flags = 0;
7347 info.length = len;
7348 - info.low_limit = TASK_UNMAPPED_BASE;
7349 + info.low_limit = mm->mmap_base;
7350 info.high_limit = TASK_SIZE;
7351 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7352 info.align_offset = pgoff << PAGE_SHIFT;
7353 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7354 struct mm_struct *mm = current->mm;
7355 unsigned long addr = addr0;
7356 int do_colour_align;
7357 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7358 struct vm_unmapped_area_info info;
7359
7360 if (flags & MAP_FIXED) {
7361 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7362 if (filp || (flags & MAP_SHARED))
7363 do_colour_align = 1;
7364
7365 +#ifdef CONFIG_PAX_RANDMMAP
7366 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7367 +#endif
7368 +
7369 /* requesting a specific address */
7370 if (addr) {
7371 if (do_colour_align)
7372 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7373 addr = PAGE_ALIGN(addr);
7374
7375 vma = find_vma(mm, addr);
7376 - if (TASK_SIZE - len >= addr &&
7377 - (!vma || addr + len <= vma->vm_start))
7378 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7379 return addr;
7380 }
7381
7382 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7383 VM_BUG_ON(addr != -ENOMEM);
7384 info.flags = 0;
7385 info.low_limit = TASK_UNMAPPED_BASE;
7386 +
7387 +#ifdef CONFIG_PAX_RANDMMAP
7388 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7389 + info.low_limit += mm->delta_mmap;
7390 +#endif
7391 +
7392 info.high_limit = TASK_SIZE;
7393 addr = vm_unmapped_area(&info);
7394 }
7395 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7396 index be56a24..443328f 100644
7397 --- a/arch/sparc/include/asm/atomic_64.h
7398 +++ b/arch/sparc/include/asm/atomic_64.h
7399 @@ -14,18 +14,40 @@
7400 #define ATOMIC64_INIT(i) { (i) }
7401
7402 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7403 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7404 +{
7405 + return v->counter;
7406 +}
7407 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7408 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7409 +{
7410 + return v->counter;
7411 +}
7412
7413 #define atomic_set(v, i) (((v)->counter) = i)
7414 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7415 +{
7416 + v->counter = i;
7417 +}
7418 #define atomic64_set(v, i) (((v)->counter) = i)
7419 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7420 +{
7421 + v->counter = i;
7422 +}
7423
7424 extern void atomic_add(int, atomic_t *);
7425 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7426 extern void atomic64_add(long, atomic64_t *);
7427 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7428 extern void atomic_sub(int, atomic_t *);
7429 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7430 extern void atomic64_sub(long, atomic64_t *);
7431 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7432
7433 extern int atomic_add_ret(int, atomic_t *);
7434 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7435 extern long atomic64_add_ret(long, atomic64_t *);
7436 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7437 extern int atomic_sub_ret(int, atomic_t *);
7438 extern long atomic64_sub_ret(long, atomic64_t *);
7439
7440 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7441 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7442
7443 #define atomic_inc_return(v) atomic_add_ret(1, v)
7444 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7445 +{
7446 + return atomic_add_ret_unchecked(1, v);
7447 +}
7448 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7449 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7450 +{
7451 + return atomic64_add_ret_unchecked(1, v);
7452 +}
7453
7454 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7455 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7456
7457 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7458 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7459 +{
7460 + return atomic_add_ret_unchecked(i, v);
7461 +}
7462 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7463 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7464 +{
7465 + return atomic64_add_ret_unchecked(i, v);
7466 +}
7467
7468 /*
7469 * atomic_inc_and_test - increment and test
7470 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7471 * other cases.
7472 */
7473 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7474 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7475 +{
7476 + return atomic_inc_return_unchecked(v) == 0;
7477 +}
7478 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7479
7480 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7481 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7482 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7483
7484 #define atomic_inc(v) atomic_add(1, v)
7485 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7486 +{
7487 + atomic_add_unchecked(1, v);
7488 +}
7489 #define atomic64_inc(v) atomic64_add(1, v)
7490 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7491 +{
7492 + atomic64_add_unchecked(1, v);
7493 +}
7494
7495 #define atomic_dec(v) atomic_sub(1, v)
7496 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7497 +{
7498 + atomic_sub_unchecked(1, v);
7499 +}
7500 #define atomic64_dec(v) atomic64_sub(1, v)
7501 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7502 +{
7503 + atomic64_sub_unchecked(1, v);
7504 +}
7505
7506 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7507 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7508
7509 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7510 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7511 +{
7512 + return cmpxchg(&v->counter, old, new);
7513 +}
7514 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7515 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7516 +{
7517 + return xchg(&v->counter, new);
7518 +}
7519
7520 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7521 {
7522 - int c, old;
7523 + int c, old, new;
7524 c = atomic_read(v);
7525 for (;;) {
7526 - if (unlikely(c == (u)))
7527 + if (unlikely(c == u))
7528 break;
7529 - old = atomic_cmpxchg((v), c, c + (a));
7530 +
7531 + asm volatile("addcc %2, %0, %0\n"
7532 +
7533 +#ifdef CONFIG_PAX_REFCOUNT
7534 + "tvs %%icc, 6\n"
7535 +#endif
7536 +
7537 + : "=r" (new)
7538 + : "0" (c), "ir" (a)
7539 + : "cc");
7540 +
7541 + old = atomic_cmpxchg(v, c, new);
7542 if (likely(old == c))
7543 break;
7544 c = old;
7545 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7546 #define atomic64_cmpxchg(v, o, n) \
7547 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7548 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7549 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7550 +{
7551 + return xchg(&v->counter, new);
7552 +}
7553
7554 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7555 {
7556 - long c, old;
7557 + long c, old, new;
7558 c = atomic64_read(v);
7559 for (;;) {
7560 - if (unlikely(c == (u)))
7561 + if (unlikely(c == u))
7562 break;
7563 - old = atomic64_cmpxchg((v), c, c + (a));
7564 +
7565 + asm volatile("addcc %2, %0, %0\n"
7566 +
7567 +#ifdef CONFIG_PAX_REFCOUNT
7568 + "tvs %%xcc, 6\n"
7569 +#endif
7570 +
7571 + : "=r" (new)
7572 + : "0" (c), "ir" (a)
7573 + : "cc");
7574 +
7575 + old = atomic64_cmpxchg(v, c, new);
7576 if (likely(old == c))
7577 break;
7578 c = old;
7579 }
7580 - return c != (u);
7581 + return c != u;
7582 }
7583
7584 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7585 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7586 index 5bb6991..5c2132e 100644
7587 --- a/arch/sparc/include/asm/cache.h
7588 +++ b/arch/sparc/include/asm/cache.h
7589 @@ -7,10 +7,12 @@
7590 #ifndef _SPARC_CACHE_H
7591 #define _SPARC_CACHE_H
7592
7593 +#include <linux/const.h>
7594 +
7595 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7596
7597 #define L1_CACHE_SHIFT 5
7598 -#define L1_CACHE_BYTES 32
7599 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7600
7601 #ifdef CONFIG_SPARC32
7602 #define SMP_CACHE_BYTES_SHIFT 5
7603 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7604 index ac74a2c..a9e58af 100644
7605 --- a/arch/sparc/include/asm/elf_32.h
7606 +++ b/arch/sparc/include/asm/elf_32.h
7607 @@ -114,6 +114,13 @@ typedef struct {
7608
7609 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7610
7611 +#ifdef CONFIG_PAX_ASLR
7612 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7613 +
7614 +#define PAX_DELTA_MMAP_LEN 16
7615 +#define PAX_DELTA_STACK_LEN 16
7616 +#endif
7617 +
7618 /* This yields a mask that user programs can use to figure out what
7619 instruction set this cpu supports. This can NOT be done in userspace
7620 on Sparc. */
7621 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7622 index 370ca1e..d4f4a98 100644
7623 --- a/arch/sparc/include/asm/elf_64.h
7624 +++ b/arch/sparc/include/asm/elf_64.h
7625 @@ -189,6 +189,13 @@ typedef struct {
7626 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7627 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7628
7629 +#ifdef CONFIG_PAX_ASLR
7630 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7631 +
7632 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7633 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7634 +#endif
7635 +
7636 extern unsigned long sparc64_elf_hwcap;
7637 #define ELF_HWCAP sparc64_elf_hwcap
7638
7639 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7640 index 9b1c36d..209298b 100644
7641 --- a/arch/sparc/include/asm/pgalloc_32.h
7642 +++ b/arch/sparc/include/asm/pgalloc_32.h
7643 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7644 }
7645
7646 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7647 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7648
7649 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7650 unsigned long address)
7651 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7652 index bcfe063..b333142 100644
7653 --- a/arch/sparc/include/asm/pgalloc_64.h
7654 +++ b/arch/sparc/include/asm/pgalloc_64.h
7655 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7656 }
7657
7658 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7659 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7660
7661 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7662 {
7663 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7664 index 6fc1348..390c50a 100644
7665 --- a/arch/sparc/include/asm/pgtable_32.h
7666 +++ b/arch/sparc/include/asm/pgtable_32.h
7667 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7668 #define PAGE_SHARED SRMMU_PAGE_SHARED
7669 #define PAGE_COPY SRMMU_PAGE_COPY
7670 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7671 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7672 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7673 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7674 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7675
7676 /* Top-level page directory - dummy used by init-mm.
7677 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7678
7679 /* xwr */
7680 #define __P000 PAGE_NONE
7681 -#define __P001 PAGE_READONLY
7682 -#define __P010 PAGE_COPY
7683 -#define __P011 PAGE_COPY
7684 +#define __P001 PAGE_READONLY_NOEXEC
7685 +#define __P010 PAGE_COPY_NOEXEC
7686 +#define __P011 PAGE_COPY_NOEXEC
7687 #define __P100 PAGE_READONLY
7688 #define __P101 PAGE_READONLY
7689 #define __P110 PAGE_COPY
7690 #define __P111 PAGE_COPY
7691
7692 #define __S000 PAGE_NONE
7693 -#define __S001 PAGE_READONLY
7694 -#define __S010 PAGE_SHARED
7695 -#define __S011 PAGE_SHARED
7696 +#define __S001 PAGE_READONLY_NOEXEC
7697 +#define __S010 PAGE_SHARED_NOEXEC
7698 +#define __S011 PAGE_SHARED_NOEXEC
7699 #define __S100 PAGE_READONLY
7700 #define __S101 PAGE_READONLY
7701 #define __S110 PAGE_SHARED
7702 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7703 index 79da178..c2eede8 100644
7704 --- a/arch/sparc/include/asm/pgtsrmmu.h
7705 +++ b/arch/sparc/include/asm/pgtsrmmu.h
7706 @@ -115,6 +115,11 @@
7707 SRMMU_EXEC | SRMMU_REF)
7708 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7709 SRMMU_EXEC | SRMMU_REF)
7710 +
7711 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7712 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7713 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7714 +
7715 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7716 SRMMU_DIRTY | SRMMU_REF)
7717
7718 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7719 index 9689176..63c18ea 100644
7720 --- a/arch/sparc/include/asm/spinlock_64.h
7721 +++ b/arch/sparc/include/asm/spinlock_64.h
7722 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7723
7724 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7725
7726 -static void inline arch_read_lock(arch_rwlock_t *lock)
7727 +static inline void arch_read_lock(arch_rwlock_t *lock)
7728 {
7729 unsigned long tmp1, tmp2;
7730
7731 __asm__ __volatile__ (
7732 "1: ldsw [%2], %0\n"
7733 " brlz,pn %0, 2f\n"
7734 -"4: add %0, 1, %1\n"
7735 +"4: addcc %0, 1, %1\n"
7736 +
7737 +#ifdef CONFIG_PAX_REFCOUNT
7738 +" tvs %%icc, 6\n"
7739 +#endif
7740 +
7741 " cas [%2], %0, %1\n"
7742 " cmp %0, %1\n"
7743 " bne,pn %%icc, 1b\n"
7744 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
7745 " .previous"
7746 : "=&r" (tmp1), "=&r" (tmp2)
7747 : "r" (lock)
7748 - : "memory");
7749 + : "memory", "cc");
7750 }
7751
7752 -static int inline arch_read_trylock(arch_rwlock_t *lock)
7753 +static inline int arch_read_trylock(arch_rwlock_t *lock)
7754 {
7755 int tmp1, tmp2;
7756
7757 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7758 "1: ldsw [%2], %0\n"
7759 " brlz,a,pn %0, 2f\n"
7760 " mov 0, %0\n"
7761 -" add %0, 1, %1\n"
7762 +" addcc %0, 1, %1\n"
7763 +
7764 +#ifdef CONFIG_PAX_REFCOUNT
7765 +" tvs %%icc, 6\n"
7766 +#endif
7767 +
7768 " cas [%2], %0, %1\n"
7769 " cmp %0, %1\n"
7770 " bne,pn %%icc, 1b\n"
7771 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7772 return tmp1;
7773 }
7774
7775 -static void inline arch_read_unlock(arch_rwlock_t *lock)
7776 +static inline void arch_read_unlock(arch_rwlock_t *lock)
7777 {
7778 unsigned long tmp1, tmp2;
7779
7780 __asm__ __volatile__(
7781 "1: lduw [%2], %0\n"
7782 -" sub %0, 1, %1\n"
7783 +" subcc %0, 1, %1\n"
7784 +
7785 +#ifdef CONFIG_PAX_REFCOUNT
7786 +" tvs %%icc, 6\n"
7787 +#endif
7788 +
7789 " cas [%2], %0, %1\n"
7790 " cmp %0, %1\n"
7791 " bne,pn %%xcc, 1b\n"
7792 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
7793 : "memory");
7794 }
7795
7796 -static void inline arch_write_lock(arch_rwlock_t *lock)
7797 +static inline void arch_write_lock(arch_rwlock_t *lock)
7798 {
7799 unsigned long mask, tmp1, tmp2;
7800
7801 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
7802 : "memory");
7803 }
7804
7805 -static void inline arch_write_unlock(arch_rwlock_t *lock)
7806 +static inline void arch_write_unlock(arch_rwlock_t *lock)
7807 {
7808 __asm__ __volatile__(
7809 " stw %%g0, [%0]"
7810 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
7811 : "memory");
7812 }
7813
7814 -static int inline arch_write_trylock(arch_rwlock_t *lock)
7815 +static inline int arch_write_trylock(arch_rwlock_t *lock)
7816 {
7817 unsigned long mask, tmp1, tmp2, result;
7818
7819 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
7820 index 25849ae..924c54b 100644
7821 --- a/arch/sparc/include/asm/thread_info_32.h
7822 +++ b/arch/sparc/include/asm/thread_info_32.h
7823 @@ -49,6 +49,8 @@ struct thread_info {
7824 unsigned long w_saved;
7825
7826 struct restart_block restart_block;
7827 +
7828 + unsigned long lowest_stack;
7829 };
7830
7831 /*
7832 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
7833 index 269bd92..e46a9b8 100644
7834 --- a/arch/sparc/include/asm/thread_info_64.h
7835 +++ b/arch/sparc/include/asm/thread_info_64.h
7836 @@ -63,6 +63,8 @@ struct thread_info {
7837 struct pt_regs *kern_una_regs;
7838 unsigned int kern_una_insn;
7839
7840 + unsigned long lowest_stack;
7841 +
7842 unsigned long fpregs[0] __attribute__ ((aligned(64)));
7843 };
7844
7845 @@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
7846 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
7847 /* flag bit 6 is available */
7848 #define TIF_32BIT 7 /* 32-bit binary */
7849 -/* flag bit 8 is available */
7850 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
7851 #define TIF_SECCOMP 9 /* secure computing */
7852 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
7853 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
7854 +
7855 /* NOTE: Thread flags >= 12 should be ones we have no interest
7856 * in using in assembly, else we can't use the mask as
7857 * an immediate value in instructions such as andcc.
7858 @@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
7859 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
7860 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7861 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
7862 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7863
7864 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
7865 _TIF_DO_NOTIFY_RESUME_MASK | \
7866 _TIF_NEED_RESCHED)
7867 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
7868
7869 +#define _TIF_WORK_SYSCALL \
7870 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
7871 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7872 +
7873 +
7874 /*
7875 * Thread-synchronous status.
7876 *
7877 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
7878 index 0167d26..9acd8ed 100644
7879 --- a/arch/sparc/include/asm/uaccess.h
7880 +++ b/arch/sparc/include/asm/uaccess.h
7881 @@ -1,5 +1,13 @@
7882 #ifndef ___ASM_SPARC_UACCESS_H
7883 #define ___ASM_SPARC_UACCESS_H
7884 +
7885 +#ifdef __KERNEL__
7886 +#ifndef __ASSEMBLY__
7887 +#include <linux/types.h>
7888 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
7889 +#endif
7890 +#endif
7891 +
7892 #if defined(__sparc__) && defined(__arch64__)
7893 #include <asm/uaccess_64.h>
7894 #else
7895 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
7896 index 53a28dd..50c38c3 100644
7897 --- a/arch/sparc/include/asm/uaccess_32.h
7898 +++ b/arch/sparc/include/asm/uaccess_32.h
7899 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
7900
7901 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
7902 {
7903 - if (n && __access_ok((unsigned long) to, n))
7904 + if ((long)n < 0)
7905 + return n;
7906 +
7907 + if (n && __access_ok((unsigned long) to, n)) {
7908 + if (!__builtin_constant_p(n))
7909 + check_object_size(from, n, true);
7910 return __copy_user(to, (__force void __user *) from, n);
7911 - else
7912 + } else
7913 return n;
7914 }
7915
7916 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
7917 {
7918 + if ((long)n < 0)
7919 + return n;
7920 +
7921 + if (!__builtin_constant_p(n))
7922 + check_object_size(from, n, true);
7923 +
7924 return __copy_user(to, (__force void __user *) from, n);
7925 }
7926
7927 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
7928 {
7929 - if (n && __access_ok((unsigned long) from, n))
7930 + if ((long)n < 0)
7931 + return n;
7932 +
7933 + if (n && __access_ok((unsigned long) from, n)) {
7934 + if (!__builtin_constant_p(n))
7935 + check_object_size(to, n, false);
7936 return __copy_user((__force void __user *) to, from, n);
7937 - else
7938 + } else
7939 return n;
7940 }
7941
7942 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
7943 {
7944 + if ((long)n < 0)
7945 + return n;
7946 +
7947 return __copy_user((__force void __user *) to, from, n);
7948 }
7949
7950 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
7951 index e562d3c..191f176 100644
7952 --- a/arch/sparc/include/asm/uaccess_64.h
7953 +++ b/arch/sparc/include/asm/uaccess_64.h
7954 @@ -10,6 +10,7 @@
7955 #include <linux/compiler.h>
7956 #include <linux/string.h>
7957 #include <linux/thread_info.h>
7958 +#include <linux/kernel.h>
7959 #include <asm/asi.h>
7960 #include <asm/spitfire.h>
7961 #include <asm-generic/uaccess-unaligned.h>
7962 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
7963 static inline unsigned long __must_check
7964 copy_from_user(void *to, const void __user *from, unsigned long size)
7965 {
7966 - unsigned long ret = ___copy_from_user(to, from, size);
7967 + unsigned long ret;
7968
7969 + if ((long)size < 0 || size > INT_MAX)
7970 + return size;
7971 +
7972 + if (!__builtin_constant_p(size))
7973 + check_object_size(to, size, false);
7974 +
7975 + ret = ___copy_from_user(to, from, size);
7976 if (unlikely(ret))
7977 ret = copy_from_user_fixup(to, from, size);
7978
7979 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
7980 static inline unsigned long __must_check
7981 copy_to_user(void __user *to, const void *from, unsigned long size)
7982 {
7983 - unsigned long ret = ___copy_to_user(to, from, size);
7984 + unsigned long ret;
7985
7986 + if ((long)size < 0 || size > INT_MAX)
7987 + return size;
7988 +
7989 + if (!__builtin_constant_p(size))
7990 + check_object_size(from, size, true);
7991 +
7992 + ret = ___copy_to_user(to, from, size);
7993 if (unlikely(ret))
7994 ret = copy_to_user_fixup(to, from, size);
7995 return ret;
7996 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
7997 index 6cf591b..b49e65a 100644
7998 --- a/arch/sparc/kernel/Makefile
7999 +++ b/arch/sparc/kernel/Makefile
8000 @@ -3,7 +3,7 @@
8001 #
8002
8003 asflags-y := -ansi
8004 -ccflags-y := -Werror
8005 +#ccflags-y := -Werror
8006
8007 extra-y := head_$(BITS).o
8008
8009 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8010 index be8e862..5b50b12 100644
8011 --- a/arch/sparc/kernel/process_32.c
8012 +++ b/arch/sparc/kernel/process_32.c
8013 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
8014
8015 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8016 r->psr, r->pc, r->npc, r->y, print_tainted());
8017 - printk("PC: <%pS>\n", (void *) r->pc);
8018 + printk("PC: <%pA>\n", (void *) r->pc);
8019 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8020 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8021 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8022 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8023 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8024 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8025 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8026 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8027
8028 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8029 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8030 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8031 rw = (struct reg_window32 *) fp;
8032 pc = rw->ins[7];
8033 printk("[%08lx : ", pc);
8034 - printk("%pS ] ", (void *) pc);
8035 + printk("%pA ] ", (void *) pc);
8036 fp = rw->ins[6];
8037 } while (++count < 16);
8038 printk("\n");
8039 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8040 index cdb80b2..5ca141d 100644
8041 --- a/arch/sparc/kernel/process_64.c
8042 +++ b/arch/sparc/kernel/process_64.c
8043 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8044 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8045 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8046 if (regs->tstate & TSTATE_PRIV)
8047 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8048 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8049 }
8050
8051 void show_regs(struct pt_regs *regs)
8052 {
8053 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8054 regs->tpc, regs->tnpc, regs->y, print_tainted());
8055 - printk("TPC: <%pS>\n", (void *) regs->tpc);
8056 + printk("TPC: <%pA>\n", (void *) regs->tpc);
8057 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8058 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8059 regs->u_regs[3]);
8060 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8061 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8062 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8063 regs->u_regs[15]);
8064 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8065 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8066 show_regwindow(regs);
8067 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8068 }
8069 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8070 ((tp && tp->task) ? tp->task->pid : -1));
8071
8072 if (gp->tstate & TSTATE_PRIV) {
8073 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8074 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8075 (void *) gp->tpc,
8076 (void *) gp->o7,
8077 (void *) gp->i7,
8078 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8079 index 7ff45e4..a58f271 100644
8080 --- a/arch/sparc/kernel/ptrace_64.c
8081 +++ b/arch/sparc/kernel/ptrace_64.c
8082 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8083 return ret;
8084 }
8085
8086 +#ifdef CONFIG_GRKERNSEC_SETXID
8087 +extern void gr_delayed_cred_worker(void);
8088 +#endif
8089 +
8090 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8091 {
8092 int ret = 0;
8093 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8094 /* do the secure computing check first */
8095 secure_computing_strict(regs->u_regs[UREG_G1]);
8096
8097 +#ifdef CONFIG_GRKERNSEC_SETXID
8098 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8099 + gr_delayed_cred_worker();
8100 +#endif
8101 +
8102 if (test_thread_flag(TIF_SYSCALL_TRACE))
8103 ret = tracehook_report_syscall_entry(regs);
8104
8105 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8106
8107 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8108 {
8109 +#ifdef CONFIG_GRKERNSEC_SETXID
8110 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8111 + gr_delayed_cred_worker();
8112 +#endif
8113 +
8114 audit_syscall_exit(regs);
8115
8116 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8117 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8118 index 2da0bdc..79128d2 100644
8119 --- a/arch/sparc/kernel/sys_sparc_32.c
8120 +++ b/arch/sparc/kernel/sys_sparc_32.c
8121 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8122 if (len > TASK_SIZE - PAGE_SIZE)
8123 return -ENOMEM;
8124 if (!addr)
8125 - addr = TASK_UNMAPPED_BASE;
8126 + addr = current->mm->mmap_base;
8127
8128 info.flags = 0;
8129 info.length = len;
8130 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8131 index 708bc29..f0129cb 100644
8132 --- a/arch/sparc/kernel/sys_sparc_64.c
8133 +++ b/arch/sparc/kernel/sys_sparc_64.c
8134 @@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8135 struct vm_area_struct * vma;
8136 unsigned long task_size = TASK_SIZE;
8137 int do_color_align;
8138 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8139 struct vm_unmapped_area_info info;
8140
8141 if (flags & MAP_FIXED) {
8142 /* We do not accept a shared mapping if it would violate
8143 * cache aliasing constraints.
8144 */
8145 - if ((flags & MAP_SHARED) &&
8146 + if ((filp || (flags & MAP_SHARED)) &&
8147 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8148 return -EINVAL;
8149 return addr;
8150 @@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8151 if (filp || (flags & MAP_SHARED))
8152 do_color_align = 1;
8153
8154 +#ifdef CONFIG_PAX_RANDMMAP
8155 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8156 +#endif
8157 +
8158 if (addr) {
8159 if (do_color_align)
8160 addr = COLOR_ALIGN(addr, pgoff);
8161 @@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8162 addr = PAGE_ALIGN(addr);
8163
8164 vma = find_vma(mm, addr);
8165 - if (task_size - len >= addr &&
8166 - (!vma || addr + len <= vma->vm_start))
8167 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8168 return addr;
8169 }
8170
8171 info.flags = 0;
8172 info.length = len;
8173 - info.low_limit = TASK_UNMAPPED_BASE;
8174 + info.low_limit = mm->mmap_base;
8175 info.high_limit = min(task_size, VA_EXCLUDE_START);
8176 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8177 info.align_offset = pgoff << PAGE_SHIFT;
8178 @@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8179 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8180 VM_BUG_ON(addr != -ENOMEM);
8181 info.low_limit = VA_EXCLUDE_END;
8182 +
8183 +#ifdef CONFIG_PAX_RANDMMAP
8184 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8185 + info.low_limit += mm->delta_mmap;
8186 +#endif
8187 +
8188 info.high_limit = task_size;
8189 addr = vm_unmapped_area(&info);
8190 }
8191 @@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8192 unsigned long task_size = STACK_TOP32;
8193 unsigned long addr = addr0;
8194 int do_color_align;
8195 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8196 struct vm_unmapped_area_info info;
8197
8198 /* This should only ever run for 32-bit processes. */
8199 @@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8200 /* We do not accept a shared mapping if it would violate
8201 * cache aliasing constraints.
8202 */
8203 - if ((flags & MAP_SHARED) &&
8204 + if ((filp || (flags & MAP_SHARED)) &&
8205 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8206 return -EINVAL;
8207 return addr;
8208 @@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8209 if (filp || (flags & MAP_SHARED))
8210 do_color_align = 1;
8211
8212 +#ifdef CONFIG_PAX_RANDMMAP
8213 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8214 +#endif
8215 +
8216 /* requesting a specific address */
8217 if (addr) {
8218 if (do_color_align)
8219 @@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8220 addr = PAGE_ALIGN(addr);
8221
8222 vma = find_vma(mm, addr);
8223 - if (task_size - len >= addr &&
8224 - (!vma || addr + len <= vma->vm_start))
8225 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8226 return addr;
8227 }
8228
8229 @@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8230 VM_BUG_ON(addr != -ENOMEM);
8231 info.flags = 0;
8232 info.low_limit = TASK_UNMAPPED_BASE;
8233 +
8234 +#ifdef CONFIG_PAX_RANDMMAP
8235 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8236 + info.low_limit += mm->delta_mmap;
8237 +#endif
8238 +
8239 info.high_limit = STACK_TOP32;
8240 addr = vm_unmapped_area(&info);
8241 }
8242 @@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8243 {
8244 unsigned long rnd = 0UL;
8245
8246 +#ifdef CONFIG_PAX_RANDMMAP
8247 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8248 +#endif
8249 +
8250 if (current->flags & PF_RANDOMIZE) {
8251 unsigned long val = get_random_int();
8252 if (test_thread_flag(TIF_32BIT))
8253 @@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8254 gap == RLIM_INFINITY ||
8255 sysctl_legacy_va_layout) {
8256 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8257 +
8258 +#ifdef CONFIG_PAX_RANDMMAP
8259 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8260 + mm->mmap_base += mm->delta_mmap;
8261 +#endif
8262 +
8263 mm->get_unmapped_area = arch_get_unmapped_area;
8264 mm->unmap_area = arch_unmap_area;
8265 } else {
8266 @@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8267 gap = (task_size / 6 * 5);
8268
8269 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8270 +
8271 +#ifdef CONFIG_PAX_RANDMMAP
8272 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8273 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8274 +#endif
8275 +
8276 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8277 mm->unmap_area = arch_unmap_area_topdown;
8278 }
8279 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8280 index e0fed77..604a7e5 100644
8281 --- a/arch/sparc/kernel/syscalls.S
8282 +++ b/arch/sparc/kernel/syscalls.S
8283 @@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8284 #endif
8285 .align 32
8286 1: ldx [%g6 + TI_FLAGS], %l5
8287 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8288 + andcc %l5, _TIF_WORK_SYSCALL, %g0
8289 be,pt %icc, rtrap
8290 nop
8291 call syscall_trace_leave
8292 @@ -190,7 +190,7 @@ linux_sparc_syscall32:
8293
8294 srl %i5, 0, %o5 ! IEU1
8295 srl %i2, 0, %o2 ! IEU0 Group
8296 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8297 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8298 bne,pn %icc, linux_syscall_trace32 ! CTI
8299 mov %i0, %l5 ! IEU1
8300 call %l7 ! CTI Group brk forced
8301 @@ -213,7 +213,7 @@ linux_sparc_syscall:
8302
8303 mov %i3, %o3 ! IEU1
8304 mov %i4, %o4 ! IEU0 Group
8305 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8306 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8307 bne,pn %icc, linux_syscall_trace ! CTI Group
8308 mov %i0, %l5 ! IEU0
8309 2: call %l7 ! CTI Group brk forced
8310 @@ -229,7 +229,7 @@ ret_sys_call:
8311
8312 cmp %o0, -ERESTART_RESTARTBLOCK
8313 bgeu,pn %xcc, 1f
8314 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8315 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8316 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8317
8318 2:
8319 diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8320 index 654e8aa..45f431b 100644
8321 --- a/arch/sparc/kernel/sysfs.c
8322 +++ b/arch/sparc/kernel/sysfs.c
8323 @@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8324 return NOTIFY_OK;
8325 }
8326
8327 -static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8328 +static struct notifier_block sysfs_cpu_nb = {
8329 .notifier_call = sysfs_cpu_notify,
8330 };
8331
8332 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8333 index a5785ea..405c5f7 100644
8334 --- a/arch/sparc/kernel/traps_32.c
8335 +++ b/arch/sparc/kernel/traps_32.c
8336 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8337 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8338 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8339
8340 +extern void gr_handle_kernel_exploit(void);
8341 +
8342 void die_if_kernel(char *str, struct pt_regs *regs)
8343 {
8344 static int die_counter;
8345 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8346 count++ < 30 &&
8347 (((unsigned long) rw) >= PAGE_OFFSET) &&
8348 !(((unsigned long) rw) & 0x7)) {
8349 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
8350 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
8351 (void *) rw->ins[7]);
8352 rw = (struct reg_window32 *)rw->ins[6];
8353 }
8354 }
8355 printk("Instruction DUMP:");
8356 instruction_dump ((unsigned long *) regs->pc);
8357 - if(regs->psr & PSR_PS)
8358 + if(regs->psr & PSR_PS) {
8359 + gr_handle_kernel_exploit();
8360 do_exit(SIGKILL);
8361 + }
8362 do_exit(SIGSEGV);
8363 }
8364
8365 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8366 index e7ecf15..6520e65 100644
8367 --- a/arch/sparc/kernel/traps_64.c
8368 +++ b/arch/sparc/kernel/traps_64.c
8369 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8370 i + 1,
8371 p->trapstack[i].tstate, p->trapstack[i].tpc,
8372 p->trapstack[i].tnpc, p->trapstack[i].tt);
8373 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8374 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8375 }
8376 }
8377
8378 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8379
8380 lvl -= 0x100;
8381 if (regs->tstate & TSTATE_PRIV) {
8382 +
8383 +#ifdef CONFIG_PAX_REFCOUNT
8384 + if (lvl == 6)
8385 + pax_report_refcount_overflow(regs);
8386 +#endif
8387 +
8388 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8389 die_if_kernel(buffer, regs);
8390 }
8391 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8392 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8393 {
8394 char buffer[32];
8395 -
8396 +
8397 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8398 0, lvl, SIGTRAP) == NOTIFY_STOP)
8399 return;
8400
8401 +#ifdef CONFIG_PAX_REFCOUNT
8402 + if (lvl == 6)
8403 + pax_report_refcount_overflow(regs);
8404 +#endif
8405 +
8406 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8407
8408 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8409 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8410 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8411 printk("%s" "ERROR(%d): ",
8412 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8413 - printk("TPC<%pS>\n", (void *) regs->tpc);
8414 + printk("TPC<%pA>\n", (void *) regs->tpc);
8415 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8416 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8417 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8418 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8419 smp_processor_id(),
8420 (type & 0x1) ? 'I' : 'D',
8421 regs->tpc);
8422 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8423 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8424 panic("Irrecoverable Cheetah+ parity error.");
8425 }
8426
8427 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8428 smp_processor_id(),
8429 (type & 0x1) ? 'I' : 'D',
8430 regs->tpc);
8431 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8432 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8433 }
8434
8435 struct sun4v_error_entry {
8436 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8437
8438 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8439 regs->tpc, tl);
8440 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8441 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8442 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8443 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8444 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8445 (void *) regs->u_regs[UREG_I7]);
8446 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8447 "pte[%lx] error[%lx]\n",
8448 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8449
8450 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8451 regs->tpc, tl);
8452 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8453 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8454 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8455 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8456 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8457 (void *) regs->u_regs[UREG_I7]);
8458 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8459 "pte[%lx] error[%lx]\n",
8460 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8461 fp = (unsigned long)sf->fp + STACK_BIAS;
8462 }
8463
8464 - printk(" [%016lx] %pS\n", pc, (void *) pc);
8465 + printk(" [%016lx] %pA\n", pc, (void *) pc);
8466 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8467 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8468 int index = tsk->curr_ret_stack;
8469 if (tsk->ret_stack && index >= graph) {
8470 pc = tsk->ret_stack[index - graph].ret;
8471 - printk(" [%016lx] %pS\n", pc, (void *) pc);
8472 + printk(" [%016lx] %pA\n", pc, (void *) pc);
8473 graph++;
8474 }
8475 }
8476 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8477 return (struct reg_window *) (fp + STACK_BIAS);
8478 }
8479
8480 +extern void gr_handle_kernel_exploit(void);
8481 +
8482 void die_if_kernel(char *str, struct pt_regs *regs)
8483 {
8484 static int die_counter;
8485 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8486 while (rw &&
8487 count++ < 30 &&
8488 kstack_valid(tp, (unsigned long) rw)) {
8489 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
8490 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
8491 (void *) rw->ins[7]);
8492
8493 rw = kernel_stack_up(rw);
8494 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8495 }
8496 user_instruction_dump ((unsigned int __user *) regs->tpc);
8497 }
8498 - if (regs->tstate & TSTATE_PRIV)
8499 + if (regs->tstate & TSTATE_PRIV) {
8500 + gr_handle_kernel_exploit();
8501 do_exit(SIGKILL);
8502 + }
8503 do_exit(SIGSEGV);
8504 }
8505 EXPORT_SYMBOL(die_if_kernel);
8506 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8507 index 8201c25e..072a2a7 100644
8508 --- a/arch/sparc/kernel/unaligned_64.c
8509 +++ b/arch/sparc/kernel/unaligned_64.c
8510 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8511 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8512
8513 if (__ratelimit(&ratelimit)) {
8514 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
8515 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
8516 regs->tpc, (void *) regs->tpc);
8517 }
8518 }
8519 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8520 index 8410065f2..4fd4ca22 100644
8521 --- a/arch/sparc/lib/Makefile
8522 +++ b/arch/sparc/lib/Makefile
8523 @@ -2,7 +2,7 @@
8524 #
8525
8526 asflags-y := -ansi -DST_DIV0=0x02
8527 -ccflags-y := -Werror
8528 +#ccflags-y := -Werror
8529
8530 lib-$(CONFIG_SPARC32) += ashrdi3.o
8531 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8532 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8533 index 85c233d..68500e0 100644
8534 --- a/arch/sparc/lib/atomic_64.S
8535 +++ b/arch/sparc/lib/atomic_64.S
8536 @@ -17,7 +17,12 @@
8537 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8538 BACKOFF_SETUP(%o2)
8539 1: lduw [%o1], %g1
8540 - add %g1, %o0, %g7
8541 + addcc %g1, %o0, %g7
8542 +
8543 +#ifdef CONFIG_PAX_REFCOUNT
8544 + tvs %icc, 6
8545 +#endif
8546 +
8547 cas [%o1], %g1, %g7
8548 cmp %g1, %g7
8549 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8550 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8551 2: BACKOFF_SPIN(%o2, %o3, 1b)
8552 ENDPROC(atomic_add)
8553
8554 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8555 + BACKOFF_SETUP(%o2)
8556 +1: lduw [%o1], %g1
8557 + add %g1, %o0, %g7
8558 + cas [%o1], %g1, %g7
8559 + cmp %g1, %g7
8560 + bne,pn %icc, 2f
8561 + nop
8562 + retl
8563 + nop
8564 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8565 +ENDPROC(atomic_add_unchecked)
8566 +
8567 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8568 BACKOFF_SETUP(%o2)
8569 1: lduw [%o1], %g1
8570 - sub %g1, %o0, %g7
8571 + subcc %g1, %o0, %g7
8572 +
8573 +#ifdef CONFIG_PAX_REFCOUNT
8574 + tvs %icc, 6
8575 +#endif
8576 +
8577 cas [%o1], %g1, %g7
8578 cmp %g1, %g7
8579 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8580 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8581 2: BACKOFF_SPIN(%o2, %o3, 1b)
8582 ENDPROC(atomic_sub)
8583
8584 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8585 + BACKOFF_SETUP(%o2)
8586 +1: lduw [%o1], %g1
8587 + sub %g1, %o0, %g7
8588 + cas [%o1], %g1, %g7
8589 + cmp %g1, %g7
8590 + bne,pn %icc, 2f
8591 + nop
8592 + retl
8593 + nop
8594 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8595 +ENDPROC(atomic_sub_unchecked)
8596 +
8597 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8598 BACKOFF_SETUP(%o2)
8599 1: lduw [%o1], %g1
8600 - add %g1, %o0, %g7
8601 + addcc %g1, %o0, %g7
8602 +
8603 +#ifdef CONFIG_PAX_REFCOUNT
8604 + tvs %icc, 6
8605 +#endif
8606 +
8607 cas [%o1], %g1, %g7
8608 cmp %g1, %g7
8609 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8610 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8611 2: BACKOFF_SPIN(%o2, %o3, 1b)
8612 ENDPROC(atomic_add_ret)
8613
8614 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8615 + BACKOFF_SETUP(%o2)
8616 +1: lduw [%o1], %g1
8617 + addcc %g1, %o0, %g7
8618 + cas [%o1], %g1, %g7
8619 + cmp %g1, %g7
8620 + bne,pn %icc, 2f
8621 + add %g7, %o0, %g7
8622 + sra %g7, 0, %o0
8623 + retl
8624 + nop
8625 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8626 +ENDPROC(atomic_add_ret_unchecked)
8627 +
8628 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8629 BACKOFF_SETUP(%o2)
8630 1: lduw [%o1], %g1
8631 - sub %g1, %o0, %g7
8632 + subcc %g1, %o0, %g7
8633 +
8634 +#ifdef CONFIG_PAX_REFCOUNT
8635 + tvs %icc, 6
8636 +#endif
8637 +
8638 cas [%o1], %g1, %g7
8639 cmp %g1, %g7
8640 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8641 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8642 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8643 BACKOFF_SETUP(%o2)
8644 1: ldx [%o1], %g1
8645 - add %g1, %o0, %g7
8646 + addcc %g1, %o0, %g7
8647 +
8648 +#ifdef CONFIG_PAX_REFCOUNT
8649 + tvs %xcc, 6
8650 +#endif
8651 +
8652 casx [%o1], %g1, %g7
8653 cmp %g1, %g7
8654 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8655 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8656 2: BACKOFF_SPIN(%o2, %o3, 1b)
8657 ENDPROC(atomic64_add)
8658
8659 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8660 + BACKOFF_SETUP(%o2)
8661 +1: ldx [%o1], %g1
8662 + addcc %g1, %o0, %g7
8663 + casx [%o1], %g1, %g7
8664 + cmp %g1, %g7
8665 + bne,pn %xcc, 2f
8666 + nop
8667 + retl
8668 + nop
8669 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8670 +ENDPROC(atomic64_add_unchecked)
8671 +
8672 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8673 BACKOFF_SETUP(%o2)
8674 1: ldx [%o1], %g1
8675 - sub %g1, %o0, %g7
8676 + subcc %g1, %o0, %g7
8677 +
8678 +#ifdef CONFIG_PAX_REFCOUNT
8679 + tvs %xcc, 6
8680 +#endif
8681 +
8682 casx [%o1], %g1, %g7
8683 cmp %g1, %g7
8684 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8685 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8686 2: BACKOFF_SPIN(%o2, %o3, 1b)
8687 ENDPROC(atomic64_sub)
8688
8689 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8690 + BACKOFF_SETUP(%o2)
8691 +1: ldx [%o1], %g1
8692 + subcc %g1, %o0, %g7
8693 + casx [%o1], %g1, %g7
8694 + cmp %g1, %g7
8695 + bne,pn %xcc, 2f
8696 + nop
8697 + retl
8698 + nop
8699 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8700 +ENDPROC(atomic64_sub_unchecked)
8701 +
8702 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8703 BACKOFF_SETUP(%o2)
8704 1: ldx [%o1], %g1
8705 - add %g1, %o0, %g7
8706 + addcc %g1, %o0, %g7
8707 +
8708 +#ifdef CONFIG_PAX_REFCOUNT
8709 + tvs %xcc, 6
8710 +#endif
8711 +
8712 casx [%o1], %g1, %g7
8713 cmp %g1, %g7
8714 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8715 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8716 2: BACKOFF_SPIN(%o2, %o3, 1b)
8717 ENDPROC(atomic64_add_ret)
8718
8719 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8720 + BACKOFF_SETUP(%o2)
8721 +1: ldx [%o1], %g1
8722 + addcc %g1, %o0, %g7
8723 + casx [%o1], %g1, %g7
8724 + cmp %g1, %g7
8725 + bne,pn %xcc, 2f
8726 + add %g7, %o0, %g7
8727 + mov %g7, %o0
8728 + retl
8729 + nop
8730 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8731 +ENDPROC(atomic64_add_ret_unchecked)
8732 +
8733 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8734 BACKOFF_SETUP(%o2)
8735 1: ldx [%o1], %g1
8736 - sub %g1, %o0, %g7
8737 + subcc %g1, %o0, %g7
8738 +
8739 +#ifdef CONFIG_PAX_REFCOUNT
8740 + tvs %xcc, 6
8741 +#endif
8742 +
8743 casx [%o1], %g1, %g7
8744 cmp %g1, %g7
8745 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8746 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
8747 index 0c4e35e..745d3e4 100644
8748 --- a/arch/sparc/lib/ksyms.c
8749 +++ b/arch/sparc/lib/ksyms.c
8750 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
8751
8752 /* Atomic counter implementation. */
8753 EXPORT_SYMBOL(atomic_add);
8754 +EXPORT_SYMBOL(atomic_add_unchecked);
8755 EXPORT_SYMBOL(atomic_add_ret);
8756 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
8757 EXPORT_SYMBOL(atomic_sub);
8758 +EXPORT_SYMBOL(atomic_sub_unchecked);
8759 EXPORT_SYMBOL(atomic_sub_ret);
8760 EXPORT_SYMBOL(atomic64_add);
8761 +EXPORT_SYMBOL(atomic64_add_unchecked);
8762 EXPORT_SYMBOL(atomic64_add_ret);
8763 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
8764 EXPORT_SYMBOL(atomic64_sub);
8765 +EXPORT_SYMBOL(atomic64_sub_unchecked);
8766 EXPORT_SYMBOL(atomic64_sub_ret);
8767 EXPORT_SYMBOL(atomic64_dec_if_positive);
8768
8769 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
8770 index 30c3ecc..736f015 100644
8771 --- a/arch/sparc/mm/Makefile
8772 +++ b/arch/sparc/mm/Makefile
8773 @@ -2,7 +2,7 @@
8774 #
8775
8776 asflags-y := -ansi
8777 -ccflags-y := -Werror
8778 +#ccflags-y := -Werror
8779
8780 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
8781 obj-y += fault_$(BITS).o
8782 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
8783 index e98bfda..ea8d221 100644
8784 --- a/arch/sparc/mm/fault_32.c
8785 +++ b/arch/sparc/mm/fault_32.c
8786 @@ -21,6 +21,9 @@
8787 #include <linux/perf_event.h>
8788 #include <linux/interrupt.h>
8789 #include <linux/kdebug.h>
8790 +#include <linux/slab.h>
8791 +#include <linux/pagemap.h>
8792 +#include <linux/compiler.h>
8793
8794 #include <asm/page.h>
8795 #include <asm/pgtable.h>
8796 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
8797 return safe_compute_effective_address(regs, insn);
8798 }
8799
8800 +#ifdef CONFIG_PAX_PAGEEXEC
8801 +#ifdef CONFIG_PAX_DLRESOLVE
8802 +static void pax_emuplt_close(struct vm_area_struct *vma)
8803 +{
8804 + vma->vm_mm->call_dl_resolve = 0UL;
8805 +}
8806 +
8807 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8808 +{
8809 + unsigned int *kaddr;
8810 +
8811 + vmf->page = alloc_page(GFP_HIGHUSER);
8812 + if (!vmf->page)
8813 + return VM_FAULT_OOM;
8814 +
8815 + kaddr = kmap(vmf->page);
8816 + memset(kaddr, 0, PAGE_SIZE);
8817 + kaddr[0] = 0x9DE3BFA8U; /* save */
8818 + flush_dcache_page(vmf->page);
8819 + kunmap(vmf->page);
8820 + return VM_FAULT_MAJOR;
8821 +}
8822 +
8823 +static const struct vm_operations_struct pax_vm_ops = {
8824 + .close = pax_emuplt_close,
8825 + .fault = pax_emuplt_fault
8826 +};
8827 +
8828 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
8829 +{
8830 + int ret;
8831 +
8832 + INIT_LIST_HEAD(&vma->anon_vma_chain);
8833 + vma->vm_mm = current->mm;
8834 + vma->vm_start = addr;
8835 + vma->vm_end = addr + PAGE_SIZE;
8836 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
8837 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
8838 + vma->vm_ops = &pax_vm_ops;
8839 +
8840 + ret = insert_vm_struct(current->mm, vma);
8841 + if (ret)
8842 + return ret;
8843 +
8844 + ++current->mm->total_vm;
8845 + return 0;
8846 +}
8847 +#endif
8848 +
8849 +/*
8850 + * PaX: decide what to do with offenders (regs->pc = fault address)
8851 + *
8852 + * returns 1 when task should be killed
8853 + * 2 when patched PLT trampoline was detected
8854 + * 3 when unpatched PLT trampoline was detected
8855 + */
8856 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8857 +{
8858 +
8859 +#ifdef CONFIG_PAX_EMUPLT
8860 + int err;
8861 +
8862 + do { /* PaX: patched PLT emulation #1 */
8863 + unsigned int sethi1, sethi2, jmpl;
8864 +
8865 + err = get_user(sethi1, (unsigned int *)regs->pc);
8866 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
8867 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
8868 +
8869 + if (err)
8870 + break;
8871 +
8872 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8873 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
8874 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
8875 + {
8876 + unsigned int addr;
8877 +
8878 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8879 + addr = regs->u_regs[UREG_G1];
8880 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8881 + regs->pc = addr;
8882 + regs->npc = addr+4;
8883 + return 2;
8884 + }
8885 + } while (0);
8886 +
8887 + do { /* PaX: patched PLT emulation #2 */
8888 + unsigned int ba;
8889 +
8890 + err = get_user(ba, (unsigned int *)regs->pc);
8891 +
8892 + if (err)
8893 + break;
8894 +
8895 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8896 + unsigned int addr;
8897 +
8898 + if ((ba & 0xFFC00000U) == 0x30800000U)
8899 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8900 + else
8901 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8902 + regs->pc = addr;
8903 + regs->npc = addr+4;
8904 + return 2;
8905 + }
8906 + } while (0);
8907 +
8908 + do { /* PaX: patched PLT emulation #3 */
8909 + unsigned int sethi, bajmpl, nop;
8910 +
8911 + err = get_user(sethi, (unsigned int *)regs->pc);
8912 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
8913 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
8914 +
8915 + if (err)
8916 + break;
8917 +
8918 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8919 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8920 + nop == 0x01000000U)
8921 + {
8922 + unsigned int addr;
8923 +
8924 + addr = (sethi & 0x003FFFFFU) << 10;
8925 + regs->u_regs[UREG_G1] = addr;
8926 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8927 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8928 + else
8929 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8930 + regs->pc = addr;
8931 + regs->npc = addr+4;
8932 + return 2;
8933 + }
8934 + } while (0);
8935 +
8936 + do { /* PaX: unpatched PLT emulation step 1 */
8937 + unsigned int sethi, ba, nop;
8938 +
8939 + err = get_user(sethi, (unsigned int *)regs->pc);
8940 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
8941 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
8942 +
8943 + if (err)
8944 + break;
8945 +
8946 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8947 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8948 + nop == 0x01000000U)
8949 + {
8950 + unsigned int addr, save, call;
8951 +
8952 + if ((ba & 0xFFC00000U) == 0x30800000U)
8953 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8954 + else
8955 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8956 +
8957 + err = get_user(save, (unsigned int *)addr);
8958 + err |= get_user(call, (unsigned int *)(addr+4));
8959 + err |= get_user(nop, (unsigned int *)(addr+8));
8960 + if (err)
8961 + break;
8962 +
8963 +#ifdef CONFIG_PAX_DLRESOLVE
8964 + if (save == 0x9DE3BFA8U &&
8965 + (call & 0xC0000000U) == 0x40000000U &&
8966 + nop == 0x01000000U)
8967 + {
8968 + struct vm_area_struct *vma;
8969 + unsigned long call_dl_resolve;
8970 +
8971 + down_read(&current->mm->mmap_sem);
8972 + call_dl_resolve = current->mm->call_dl_resolve;
8973 + up_read(&current->mm->mmap_sem);
8974 + if (likely(call_dl_resolve))
8975 + goto emulate;
8976 +
8977 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8978 +
8979 + down_write(&current->mm->mmap_sem);
8980 + if (current->mm->call_dl_resolve) {
8981 + call_dl_resolve = current->mm->call_dl_resolve;
8982 + up_write(&current->mm->mmap_sem);
8983 + if (vma)
8984 + kmem_cache_free(vm_area_cachep, vma);
8985 + goto emulate;
8986 + }
8987 +
8988 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8989 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8990 + up_write(&current->mm->mmap_sem);
8991 + if (vma)
8992 + kmem_cache_free(vm_area_cachep, vma);
8993 + return 1;
8994 + }
8995 +
8996 + if (pax_insert_vma(vma, call_dl_resolve)) {
8997 + up_write(&current->mm->mmap_sem);
8998 + kmem_cache_free(vm_area_cachep, vma);
8999 + return 1;
9000 + }
9001 +
9002 + current->mm->call_dl_resolve = call_dl_resolve;
9003 + up_write(&current->mm->mmap_sem);
9004 +
9005 +emulate:
9006 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9007 + regs->pc = call_dl_resolve;
9008 + regs->npc = addr+4;
9009 + return 3;
9010 + }
9011 +#endif
9012 +
9013 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9014 + if ((save & 0xFFC00000U) == 0x05000000U &&
9015 + (call & 0xFFFFE000U) == 0x85C0A000U &&
9016 + nop == 0x01000000U)
9017 + {
9018 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9019 + regs->u_regs[UREG_G2] = addr + 4;
9020 + addr = (save & 0x003FFFFFU) << 10;
9021 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9022 + regs->pc = addr;
9023 + regs->npc = addr+4;
9024 + return 3;
9025 + }
9026 + }
9027 + } while (0);
9028 +
9029 + do { /* PaX: unpatched PLT emulation step 2 */
9030 + unsigned int save, call, nop;
9031 +
9032 + err = get_user(save, (unsigned int *)(regs->pc-4));
9033 + err |= get_user(call, (unsigned int *)regs->pc);
9034 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
9035 + if (err)
9036 + break;
9037 +
9038 + if (save == 0x9DE3BFA8U &&
9039 + (call & 0xC0000000U) == 0x40000000U &&
9040 + nop == 0x01000000U)
9041 + {
9042 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9043 +
9044 + regs->u_regs[UREG_RETPC] = regs->pc;
9045 + regs->pc = dl_resolve;
9046 + regs->npc = dl_resolve+4;
9047 + return 3;
9048 + }
9049 + } while (0);
9050 +#endif
9051 +
9052 + return 1;
9053 +}
9054 +
9055 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9056 +{
9057 + unsigned long i;
9058 +
9059 + printk(KERN_ERR "PAX: bytes at PC: ");
9060 + for (i = 0; i < 8; i++) {
9061 + unsigned int c;
9062 + if (get_user(c, (unsigned int *)pc+i))
9063 + printk(KERN_CONT "???????? ");
9064 + else
9065 + printk(KERN_CONT "%08x ", c);
9066 + }
9067 + printk("\n");
9068 +}
9069 +#endif
9070 +
9071 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9072 int text_fault)
9073 {
9074 @@ -230,6 +504,24 @@ good_area:
9075 if (!(vma->vm_flags & VM_WRITE))
9076 goto bad_area;
9077 } else {
9078 +
9079 +#ifdef CONFIG_PAX_PAGEEXEC
9080 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9081 + up_read(&mm->mmap_sem);
9082 + switch (pax_handle_fetch_fault(regs)) {
9083 +
9084 +#ifdef CONFIG_PAX_EMUPLT
9085 + case 2:
9086 + case 3:
9087 + return;
9088 +#endif
9089 +
9090 + }
9091 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9092 + do_group_exit(SIGKILL);
9093 + }
9094 +#endif
9095 +
9096 /* Allow reads even for write-only mappings */
9097 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9098 goto bad_area;
9099 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9100 index 5062ff3..e0b75f3 100644
9101 --- a/arch/sparc/mm/fault_64.c
9102 +++ b/arch/sparc/mm/fault_64.c
9103 @@ -21,6 +21,9 @@
9104 #include <linux/kprobes.h>
9105 #include <linux/kdebug.h>
9106 #include <linux/percpu.h>
9107 +#include <linux/slab.h>
9108 +#include <linux/pagemap.h>
9109 +#include <linux/compiler.h>
9110
9111 #include <asm/page.h>
9112 #include <asm/pgtable.h>
9113 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9114 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9115 regs->tpc);
9116 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9117 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9118 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9119 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9120 dump_stack();
9121 unhandled_fault(regs->tpc, current, regs);
9122 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9123 show_regs(regs);
9124 }
9125
9126 +#ifdef CONFIG_PAX_PAGEEXEC
9127 +#ifdef CONFIG_PAX_DLRESOLVE
9128 +static void pax_emuplt_close(struct vm_area_struct *vma)
9129 +{
9130 + vma->vm_mm->call_dl_resolve = 0UL;
9131 +}
9132 +
9133 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9134 +{
9135 + unsigned int *kaddr;
9136 +
9137 + vmf->page = alloc_page(GFP_HIGHUSER);
9138 + if (!vmf->page)
9139 + return VM_FAULT_OOM;
9140 +
9141 + kaddr = kmap(vmf->page);
9142 + memset(kaddr, 0, PAGE_SIZE);
9143 + kaddr[0] = 0x9DE3BFA8U; /* save */
9144 + flush_dcache_page(vmf->page);
9145 + kunmap(vmf->page);
9146 + return VM_FAULT_MAJOR;
9147 +}
9148 +
9149 +static const struct vm_operations_struct pax_vm_ops = {
9150 + .close = pax_emuplt_close,
9151 + .fault = pax_emuplt_fault
9152 +};
9153 +
9154 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9155 +{
9156 + int ret;
9157 +
9158 + INIT_LIST_HEAD(&vma->anon_vma_chain);
9159 + vma->vm_mm = current->mm;
9160 + vma->vm_start = addr;
9161 + vma->vm_end = addr + PAGE_SIZE;
9162 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9163 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9164 + vma->vm_ops = &pax_vm_ops;
9165 +
9166 + ret = insert_vm_struct(current->mm, vma);
9167 + if (ret)
9168 + return ret;
9169 +
9170 + ++current->mm->total_vm;
9171 + return 0;
9172 +}
9173 +#endif
9174 +
9175 +/*
9176 + * PaX: decide what to do with offenders (regs->tpc = fault address)
9177 + *
9178 + * returns 1 when task should be killed
9179 + * 2 when patched PLT trampoline was detected
9180 + * 3 when unpatched PLT trampoline was detected
9181 + */
9182 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9183 +{
9184 +
9185 +#ifdef CONFIG_PAX_EMUPLT
9186 + int err;
9187 +
9188 + do { /* PaX: patched PLT emulation #1 */
9189 + unsigned int sethi1, sethi2, jmpl;
9190 +
9191 + err = get_user(sethi1, (unsigned int *)regs->tpc);
9192 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9193 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9194 +
9195 + if (err)
9196 + break;
9197 +
9198 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9199 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
9200 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
9201 + {
9202 + unsigned long addr;
9203 +
9204 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9205 + addr = regs->u_regs[UREG_G1];
9206 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9207 +
9208 + if (test_thread_flag(TIF_32BIT))
9209 + addr &= 0xFFFFFFFFUL;
9210 +
9211 + regs->tpc = addr;
9212 + regs->tnpc = addr+4;
9213 + return 2;
9214 + }
9215 + } while (0);
9216 +
9217 + do { /* PaX: patched PLT emulation #2 */
9218 + unsigned int ba;
9219 +
9220 + err = get_user(ba, (unsigned int *)regs->tpc);
9221 +
9222 + if (err)
9223 + break;
9224 +
9225 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9226 + unsigned long addr;
9227 +
9228 + if ((ba & 0xFFC00000U) == 0x30800000U)
9229 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9230 + else
9231 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9232 +
9233 + if (test_thread_flag(TIF_32BIT))
9234 + addr &= 0xFFFFFFFFUL;
9235 +
9236 + regs->tpc = addr;
9237 + regs->tnpc = addr+4;
9238 + return 2;
9239 + }
9240 + } while (0);
9241 +
9242 + do { /* PaX: patched PLT emulation #3 */
9243 + unsigned int sethi, bajmpl, nop;
9244 +
9245 + err = get_user(sethi, (unsigned int *)regs->tpc);
9246 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9247 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9248 +
9249 + if (err)
9250 + break;
9251 +
9252 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9253 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9254 + nop == 0x01000000U)
9255 + {
9256 + unsigned long addr;
9257 +
9258 + addr = (sethi & 0x003FFFFFU) << 10;
9259 + regs->u_regs[UREG_G1] = addr;
9260 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9261 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9262 + else
9263 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9264 +
9265 + if (test_thread_flag(TIF_32BIT))
9266 + addr &= 0xFFFFFFFFUL;
9267 +
9268 + regs->tpc = addr;
9269 + regs->tnpc = addr+4;
9270 + return 2;
9271 + }
9272 + } while (0);
9273 +
9274 + do { /* PaX: patched PLT emulation #4 */
9275 + unsigned int sethi, mov1, call, mov2;
9276 +
9277 + err = get_user(sethi, (unsigned int *)regs->tpc);
9278 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9279 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
9280 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9281 +
9282 + if (err)
9283 + break;
9284 +
9285 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9286 + mov1 == 0x8210000FU &&
9287 + (call & 0xC0000000U) == 0x40000000U &&
9288 + mov2 == 0x9E100001U)
9289 + {
9290 + unsigned long addr;
9291 +
9292 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9293 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9294 +
9295 + if (test_thread_flag(TIF_32BIT))
9296 + addr &= 0xFFFFFFFFUL;
9297 +
9298 + regs->tpc = addr;
9299 + regs->tnpc = addr+4;
9300 + return 2;
9301 + }
9302 + } while (0);
9303 +
9304 + do { /* PaX: patched PLT emulation #5 */
9305 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9306 +
9307 + err = get_user(sethi, (unsigned int *)regs->tpc);
9308 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9309 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9310 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9311 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9312 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9313 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9314 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9315 +
9316 + if (err)
9317 + break;
9318 +
9319 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9320 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
9321 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9322 + (or1 & 0xFFFFE000U) == 0x82106000U &&
9323 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
9324 + sllx == 0x83287020U &&
9325 + jmpl == 0x81C04005U &&
9326 + nop == 0x01000000U)
9327 + {
9328 + unsigned long addr;
9329 +
9330 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9331 + regs->u_regs[UREG_G1] <<= 32;
9332 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9333 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9334 + regs->tpc = addr;
9335 + regs->tnpc = addr+4;
9336 + return 2;
9337 + }
9338 + } while (0);
9339 +
9340 + do { /* PaX: patched PLT emulation #6 */
9341 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9342 +
9343 + err = get_user(sethi, (unsigned int *)regs->tpc);
9344 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9345 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9346 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9347 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
9348 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9349 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9350 +
9351 + if (err)
9352 + break;
9353 +
9354 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9355 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
9356 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9357 + sllx == 0x83287020U &&
9358 + (or & 0xFFFFE000U) == 0x8A116000U &&
9359 + jmpl == 0x81C04005U &&
9360 + nop == 0x01000000U)
9361 + {
9362 + unsigned long addr;
9363 +
9364 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9365 + regs->u_regs[UREG_G1] <<= 32;
9366 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9367 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9368 + regs->tpc = addr;
9369 + regs->tnpc = addr+4;
9370 + return 2;
9371 + }
9372 + } while (0);
9373 +
9374 + do { /* PaX: unpatched PLT emulation step 1 */
9375 + unsigned int sethi, ba, nop;
9376 +
9377 + err = get_user(sethi, (unsigned int *)regs->tpc);
9378 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9379 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9380 +
9381 + if (err)
9382 + break;
9383 +
9384 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9385 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9386 + nop == 0x01000000U)
9387 + {
9388 + unsigned long addr;
9389 + unsigned int save, call;
9390 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9391 +
9392 + if ((ba & 0xFFC00000U) == 0x30800000U)
9393 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9394 + else
9395 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9396 +
9397 + if (test_thread_flag(TIF_32BIT))
9398 + addr &= 0xFFFFFFFFUL;
9399 +
9400 + err = get_user(save, (unsigned int *)addr);
9401 + err |= get_user(call, (unsigned int *)(addr+4));
9402 + err |= get_user(nop, (unsigned int *)(addr+8));
9403 + if (err)
9404 + break;
9405 +
9406 +#ifdef CONFIG_PAX_DLRESOLVE
9407 + if (save == 0x9DE3BFA8U &&
9408 + (call & 0xC0000000U) == 0x40000000U &&
9409 + nop == 0x01000000U)
9410 + {
9411 + struct vm_area_struct *vma;
9412 + unsigned long call_dl_resolve;
9413 +
9414 + down_read(&current->mm->mmap_sem);
9415 + call_dl_resolve = current->mm->call_dl_resolve;
9416 + up_read(&current->mm->mmap_sem);
9417 + if (likely(call_dl_resolve))
9418 + goto emulate;
9419 +
9420 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9421 +
9422 + down_write(&current->mm->mmap_sem);
9423 + if (current->mm->call_dl_resolve) {
9424 + call_dl_resolve = current->mm->call_dl_resolve;
9425 + up_write(&current->mm->mmap_sem);
9426 + if (vma)
9427 + kmem_cache_free(vm_area_cachep, vma);
9428 + goto emulate;
9429 + }
9430 +
9431 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9432 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9433 + up_write(&current->mm->mmap_sem);
9434 + if (vma)
9435 + kmem_cache_free(vm_area_cachep, vma);
9436 + return 1;
9437 + }
9438 +
9439 + if (pax_insert_vma(vma, call_dl_resolve)) {
9440 + up_write(&current->mm->mmap_sem);
9441 + kmem_cache_free(vm_area_cachep, vma);
9442 + return 1;
9443 + }
9444 +
9445 + current->mm->call_dl_resolve = call_dl_resolve;
9446 + up_write(&current->mm->mmap_sem);
9447 +
9448 +emulate:
9449 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9450 + regs->tpc = call_dl_resolve;
9451 + regs->tnpc = addr+4;
9452 + return 3;
9453 + }
9454 +#endif
9455 +
9456 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9457 + if ((save & 0xFFC00000U) == 0x05000000U &&
9458 + (call & 0xFFFFE000U) == 0x85C0A000U &&
9459 + nop == 0x01000000U)
9460 + {
9461 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9462 + regs->u_regs[UREG_G2] = addr + 4;
9463 + addr = (save & 0x003FFFFFU) << 10;
9464 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9465 +
9466 + if (test_thread_flag(TIF_32BIT))
9467 + addr &= 0xFFFFFFFFUL;
9468 +
9469 + regs->tpc = addr;
9470 + regs->tnpc = addr+4;
9471 + return 3;
9472 + }
9473 +
9474 + /* PaX: 64-bit PLT stub */
9475 + err = get_user(sethi1, (unsigned int *)addr);
9476 + err |= get_user(sethi2, (unsigned int *)(addr+4));
9477 + err |= get_user(or1, (unsigned int *)(addr+8));
9478 + err |= get_user(or2, (unsigned int *)(addr+12));
9479 + err |= get_user(sllx, (unsigned int *)(addr+16));
9480 + err |= get_user(add, (unsigned int *)(addr+20));
9481 + err |= get_user(jmpl, (unsigned int *)(addr+24));
9482 + err |= get_user(nop, (unsigned int *)(addr+28));
9483 + if (err)
9484 + break;
9485 +
9486 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9487 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9488 + (or1 & 0xFFFFE000U) == 0x88112000U &&
9489 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
9490 + sllx == 0x89293020U &&
9491 + add == 0x8A010005U &&
9492 + jmpl == 0x89C14000U &&
9493 + nop == 0x01000000U)
9494 + {
9495 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9496 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9497 + regs->u_regs[UREG_G4] <<= 32;
9498 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9499 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9500 + regs->u_regs[UREG_G4] = addr + 24;
9501 + addr = regs->u_regs[UREG_G5];
9502 + regs->tpc = addr;
9503 + regs->tnpc = addr+4;
9504 + return 3;
9505 + }
9506 + }
9507 + } while (0);
9508 +
9509 +#ifdef CONFIG_PAX_DLRESOLVE
9510 + do { /* PaX: unpatched PLT emulation step 2 */
9511 + unsigned int save, call, nop;
9512 +
9513 + err = get_user(save, (unsigned int *)(regs->tpc-4));
9514 + err |= get_user(call, (unsigned int *)regs->tpc);
9515 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9516 + if (err)
9517 + break;
9518 +
9519 + if (save == 0x9DE3BFA8U &&
9520 + (call & 0xC0000000U) == 0x40000000U &&
9521 + nop == 0x01000000U)
9522 + {
9523 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9524 +
9525 + if (test_thread_flag(TIF_32BIT))
9526 + dl_resolve &= 0xFFFFFFFFUL;
9527 +
9528 + regs->u_regs[UREG_RETPC] = regs->tpc;
9529 + regs->tpc = dl_resolve;
9530 + regs->tnpc = dl_resolve+4;
9531 + return 3;
9532 + }
9533 + } while (0);
9534 +#endif
9535 +
9536 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9537 + unsigned int sethi, ba, nop;
9538 +
9539 + err = get_user(sethi, (unsigned int *)regs->tpc);
9540 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9541 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9542 +
9543 + if (err)
9544 + break;
9545 +
9546 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9547 + (ba & 0xFFF00000U) == 0x30600000U &&
9548 + nop == 0x01000000U)
9549 + {
9550 + unsigned long addr;
9551 +
9552 + addr = (sethi & 0x003FFFFFU) << 10;
9553 + regs->u_regs[UREG_G1] = addr;
9554 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9555 +
9556 + if (test_thread_flag(TIF_32BIT))
9557 + addr &= 0xFFFFFFFFUL;
9558 +
9559 + regs->tpc = addr;
9560 + regs->tnpc = addr+4;
9561 + return 2;
9562 + }
9563 + } while (0);
9564 +
9565 +#endif
9566 +
9567 + return 1;
9568 +}
9569 +
9570 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9571 +{
9572 + unsigned long i;
9573 +
9574 + printk(KERN_ERR "PAX: bytes at PC: ");
9575 + for (i = 0; i < 8; i++) {
9576 + unsigned int c;
9577 + if (get_user(c, (unsigned int *)pc+i))
9578 + printk(KERN_CONT "???????? ");
9579 + else
9580 + printk(KERN_CONT "%08x ", c);
9581 + }
9582 + printk("\n");
9583 +}
9584 +#endif
9585 +
9586 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9587 {
9588 struct mm_struct *mm = current->mm;
9589 @@ -341,6 +804,29 @@ retry:
9590 if (!vma)
9591 goto bad_area;
9592
9593 +#ifdef CONFIG_PAX_PAGEEXEC
9594 + /* PaX: detect ITLB misses on non-exec pages */
9595 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9596 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9597 + {
9598 + if (address != regs->tpc)
9599 + goto good_area;
9600 +
9601 + up_read(&mm->mmap_sem);
9602 + switch (pax_handle_fetch_fault(regs)) {
9603 +
9604 +#ifdef CONFIG_PAX_EMUPLT
9605 + case 2:
9606 + case 3:
9607 + return;
9608 +#endif
9609 +
9610 + }
9611 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9612 + do_group_exit(SIGKILL);
9613 + }
9614 +#endif
9615 +
9616 /* Pure DTLB misses do not tell us whether the fault causing
9617 * load/store/atomic was a write or not, it only says that there
9618 * was no match. So in such a case we (carefully) read the
9619 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9620 index d2b5944..bd813f2 100644
9621 --- a/arch/sparc/mm/hugetlbpage.c
9622 +++ b/arch/sparc/mm/hugetlbpage.c
9623 @@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9624
9625 info.flags = 0;
9626 info.length = len;
9627 - info.low_limit = TASK_UNMAPPED_BASE;
9628 + info.low_limit = mm->mmap_base;
9629 info.high_limit = min(task_size, VA_EXCLUDE_START);
9630 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9631 info.align_offset = 0;
9632 @@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9633 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9634 VM_BUG_ON(addr != -ENOMEM);
9635 info.low_limit = VA_EXCLUDE_END;
9636 +
9637 +#ifdef CONFIG_PAX_RANDMMAP
9638 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9639 + info.low_limit += mm->delta_mmap;
9640 +#endif
9641 +
9642 info.high_limit = task_size;
9643 addr = vm_unmapped_area(&info);
9644 }
9645 @@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9646 VM_BUG_ON(addr != -ENOMEM);
9647 info.flags = 0;
9648 info.low_limit = TASK_UNMAPPED_BASE;
9649 +
9650 +#ifdef CONFIG_PAX_RANDMMAP
9651 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9652 + info.low_limit += mm->delta_mmap;
9653 +#endif
9654 +
9655 info.high_limit = STACK_TOP32;
9656 addr = vm_unmapped_area(&info);
9657 }
9658 @@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9659 struct mm_struct *mm = current->mm;
9660 struct vm_area_struct *vma;
9661 unsigned long task_size = TASK_SIZE;
9662 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9663
9664 if (test_thread_flag(TIF_32BIT))
9665 task_size = STACK_TOP32;
9666 @@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9667 return addr;
9668 }
9669
9670 +#ifdef CONFIG_PAX_RANDMMAP
9671 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9672 +#endif
9673 +
9674 if (addr) {
9675 addr = ALIGN(addr, HPAGE_SIZE);
9676 vma = find_vma(mm, addr);
9677 - if (task_size - len >= addr &&
9678 - (!vma || addr + len <= vma->vm_start))
9679 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9680 return addr;
9681 }
9682 if (mm->get_unmapped_area == arch_get_unmapped_area)
9683 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9684 index f4500c6..889656c 100644
9685 --- a/arch/tile/include/asm/atomic_64.h
9686 +++ b/arch/tile/include/asm/atomic_64.h
9687 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9688
9689 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9690
9691 +#define atomic64_read_unchecked(v) atomic64_read(v)
9692 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9693 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9694 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9695 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9696 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9697 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9698 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9699 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9700 +
9701 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
9702 #define smp_mb__before_atomic_dec() smp_mb()
9703 #define smp_mb__after_atomic_dec() smp_mb()
9704 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
9705 index a9a5299..0fce79e 100644
9706 --- a/arch/tile/include/asm/cache.h
9707 +++ b/arch/tile/include/asm/cache.h
9708 @@ -15,11 +15,12 @@
9709 #ifndef _ASM_TILE_CACHE_H
9710 #define _ASM_TILE_CACHE_H
9711
9712 +#include <linux/const.h>
9713 #include <arch/chip.h>
9714
9715 /* bytes per L1 data cache line */
9716 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
9717 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9718 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9719
9720 /* bytes per L2 cache line */
9721 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
9722 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
9723 index 9ab078a..d6635c2 100644
9724 --- a/arch/tile/include/asm/uaccess.h
9725 +++ b/arch/tile/include/asm/uaccess.h
9726 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
9727 const void __user *from,
9728 unsigned long n)
9729 {
9730 - int sz = __compiletime_object_size(to);
9731 + size_t sz = __compiletime_object_size(to);
9732
9733 - if (likely(sz == -1 || sz >= n))
9734 + if (likely(sz == (size_t)-1 || sz >= n))
9735 n = _copy_from_user(to, from, n);
9736 else
9737 copy_from_user_overflow();
9738 diff --git a/arch/um/Makefile b/arch/um/Makefile
9739 index 133f7de..1d6f2f1 100644
9740 --- a/arch/um/Makefile
9741 +++ b/arch/um/Makefile
9742 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
9743 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
9744 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
9745
9746 +ifdef CONSTIFY_PLUGIN
9747 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
9748 +endif
9749 +
9750 #This will adjust *FLAGS accordingly to the platform.
9751 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
9752
9753 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
9754 index 19e1bdd..3665b77 100644
9755 --- a/arch/um/include/asm/cache.h
9756 +++ b/arch/um/include/asm/cache.h
9757 @@ -1,6 +1,7 @@
9758 #ifndef __UM_CACHE_H
9759 #define __UM_CACHE_H
9760
9761 +#include <linux/const.h>
9762
9763 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
9764 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9765 @@ -12,6 +13,6 @@
9766 # define L1_CACHE_SHIFT 5
9767 #endif
9768
9769 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9770 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9771
9772 #endif
9773 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
9774 index 2e0a6b1..a64d0f5 100644
9775 --- a/arch/um/include/asm/kmap_types.h
9776 +++ b/arch/um/include/asm/kmap_types.h
9777 @@ -8,6 +8,6 @@
9778
9779 /* No more #include "asm/arch/kmap_types.h" ! */
9780
9781 -#define KM_TYPE_NR 14
9782 +#define KM_TYPE_NR 15
9783
9784 #endif
9785 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
9786 index 5ff53d9..5850cdf 100644
9787 --- a/arch/um/include/asm/page.h
9788 +++ b/arch/um/include/asm/page.h
9789 @@ -14,6 +14,9 @@
9790 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
9791 #define PAGE_MASK (~(PAGE_SIZE-1))
9792
9793 +#define ktla_ktva(addr) (addr)
9794 +#define ktva_ktla(addr) (addr)
9795 +
9796 #ifndef __ASSEMBLY__
9797
9798 struct page;
9799 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
9800 index 0032f92..cd151e0 100644
9801 --- a/arch/um/include/asm/pgtable-3level.h
9802 +++ b/arch/um/include/asm/pgtable-3level.h
9803 @@ -58,6 +58,7 @@
9804 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
9805 #define pud_populate(mm, pud, pmd) \
9806 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
9807 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9808
9809 #ifdef CONFIG_64BIT
9810 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
9811 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
9812 index b462b13..e7a19aa 100644
9813 --- a/arch/um/kernel/process.c
9814 +++ b/arch/um/kernel/process.c
9815 @@ -386,22 +386,6 @@ int singlestepping(void * t)
9816 return 2;
9817 }
9818
9819 -/*
9820 - * Only x86 and x86_64 have an arch_align_stack().
9821 - * All other arches have "#define arch_align_stack(x) (x)"
9822 - * in their asm/system.h
9823 - * As this is included in UML from asm-um/system-generic.h,
9824 - * we can use it to behave as the subarch does.
9825 - */
9826 -#ifndef arch_align_stack
9827 -unsigned long arch_align_stack(unsigned long sp)
9828 -{
9829 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9830 - sp -= get_random_int() % 8192;
9831 - return sp & ~0xf;
9832 -}
9833 -#endif
9834 -
9835 unsigned long get_wchan(struct task_struct *p)
9836 {
9837 unsigned long stack_page, sp, ip;
9838 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
9839 index ad8f795..2c7eec6 100644
9840 --- a/arch/unicore32/include/asm/cache.h
9841 +++ b/arch/unicore32/include/asm/cache.h
9842 @@ -12,8 +12,10 @@
9843 #ifndef __UNICORE_CACHE_H__
9844 #define __UNICORE_CACHE_H__
9845
9846 -#define L1_CACHE_SHIFT (5)
9847 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9848 +#include <linux/const.h>
9849 +
9850 +#define L1_CACHE_SHIFT 5
9851 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9852
9853 /*
9854 * Memory returned by kmalloc() may be used for DMA, so we must make
9855 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
9856 index 0694d09..b58b3aa 100644
9857 --- a/arch/x86/Kconfig
9858 +++ b/arch/x86/Kconfig
9859 @@ -238,7 +238,7 @@ config X86_HT
9860
9861 config X86_32_LAZY_GS
9862 def_bool y
9863 - depends on X86_32 && !CC_STACKPROTECTOR
9864 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
9865
9866 config ARCH_HWEIGHT_CFLAGS
9867 string
9868 @@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
9869
9870 config X86_MSR
9871 tristate "/dev/cpu/*/msr - Model-specific register support"
9872 + depends on !GRKERNSEC_KMEM
9873 ---help---
9874 This device gives privileged processes access to the x86
9875 Model-Specific Registers (MSRs). It is a character device with
9876 @@ -1054,7 +1055,7 @@ choice
9877
9878 config NOHIGHMEM
9879 bool "off"
9880 - depends on !X86_NUMAQ
9881 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9882 ---help---
9883 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
9884 However, the address space of 32-bit x86 processors is only 4
9885 @@ -1091,7 +1092,7 @@ config NOHIGHMEM
9886
9887 config HIGHMEM4G
9888 bool "4GB"
9889 - depends on !X86_NUMAQ
9890 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9891 ---help---
9892 Select this if you have a 32-bit processor and between 1 and 4
9893 gigabytes of physical RAM.
9894 @@ -1145,7 +1146,7 @@ config PAGE_OFFSET
9895 hex
9896 default 0xB0000000 if VMSPLIT_3G_OPT
9897 default 0x80000000 if VMSPLIT_2G
9898 - default 0x78000000 if VMSPLIT_2G_OPT
9899 + default 0x70000000 if VMSPLIT_2G_OPT
9900 default 0x40000000 if VMSPLIT_1G
9901 default 0xC0000000
9902 depends on X86_32
9903 @@ -1542,6 +1543,7 @@ config SECCOMP
9904
9905 config CC_STACKPROTECTOR
9906 bool "Enable -fstack-protector buffer overflow detection"
9907 + depends on X86_64 || !PAX_MEMORY_UDEREF
9908 ---help---
9909 This option turns on the -fstack-protector GCC feature. This
9910 feature puts, at the beginning of functions, a canary value on
9911 @@ -1599,6 +1601,7 @@ config KEXEC_JUMP
9912 config PHYSICAL_START
9913 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
9914 default "0x1000000"
9915 + range 0x400000 0x40000000
9916 ---help---
9917 This gives the physical address where the kernel is loaded.
9918
9919 @@ -1662,6 +1665,7 @@ config X86_NEED_RELOCS
9920 config PHYSICAL_ALIGN
9921 hex "Alignment value to which kernel should be aligned" if X86_32
9922 default "0x1000000"
9923 + range 0x400000 0x1000000 if PAX_KERNEXEC
9924 range 0x2000 0x1000000
9925 ---help---
9926 This value puts the alignment restrictions on physical address
9927 @@ -1737,9 +1741,10 @@ config DEBUG_HOTPLUG_CPU0
9928 If unsure, say N.
9929
9930 config COMPAT_VDSO
9931 - def_bool y
9932 + def_bool n
9933 prompt "Compat VDSO support"
9934 depends on X86_32 || IA32_EMULATION
9935 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
9936 ---help---
9937 Map the 32-bit VDSO to the predictable old-style address too.
9938
9939 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
9940 index c026cca..14657ae 100644
9941 --- a/arch/x86/Kconfig.cpu
9942 +++ b/arch/x86/Kconfig.cpu
9943 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
9944
9945 config X86_F00F_BUG
9946 def_bool y
9947 - depends on M586MMX || M586TSC || M586 || M486
9948 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
9949
9950 config X86_INVD_BUG
9951 def_bool y
9952 @@ -327,7 +327,7 @@ config X86_INVD_BUG
9953
9954 config X86_ALIGNMENT_16
9955 def_bool y
9956 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
9957 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
9958
9959 config X86_INTEL_USERCOPY
9960 def_bool y
9961 @@ -373,7 +373,7 @@ config X86_CMPXCHG64
9962 # generates cmov.
9963 config X86_CMOV
9964 def_bool y
9965 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
9966 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
9967
9968 config X86_MINIMUM_CPU_FAMILY
9969 int
9970 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
9971 index b322f12..652d0d9 100644
9972 --- a/arch/x86/Kconfig.debug
9973 +++ b/arch/x86/Kconfig.debug
9974 @@ -84,7 +84,7 @@ config X86_PTDUMP
9975 config DEBUG_RODATA
9976 bool "Write protect kernel read-only data structures"
9977 default y
9978 - depends on DEBUG_KERNEL
9979 + depends on DEBUG_KERNEL && BROKEN
9980 ---help---
9981 Mark the kernel read-only data as write-protected in the pagetables,
9982 in order to catch accidental (and incorrect) writes to such const
9983 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
9984
9985 config DEBUG_SET_MODULE_RONX
9986 bool "Set loadable kernel module data as NX and text as RO"
9987 - depends on MODULES
9988 + depends on MODULES && BROKEN
9989 ---help---
9990 This option helps catch unintended modifications to loadable
9991 kernel module's text and read-only data. It also prevents execution
9992 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
9993
9994 config DEBUG_STRICT_USER_COPY_CHECKS
9995 bool "Strict copy size checks"
9996 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
9997 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
9998 ---help---
9999 Enabling this option turns a certain set of sanity checks for user
10000 copy operations into compile time failures.
10001 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10002 index e71fc42..7829607 100644
10003 --- a/arch/x86/Makefile
10004 +++ b/arch/x86/Makefile
10005 @@ -50,6 +50,7 @@ else
10006 UTS_MACHINE := x86_64
10007 CHECKFLAGS += -D__x86_64__ -m64
10008
10009 + biarch := $(call cc-option,-m64)
10010 KBUILD_AFLAGS += -m64
10011 KBUILD_CFLAGS += -m64
10012
10013 @@ -230,3 +231,12 @@ define archhelp
10014 echo ' FDARGS="..." arguments for the booted kernel'
10015 echo ' FDINITRD=file initrd for the booted kernel'
10016 endef
10017 +
10018 +define OLD_LD
10019 +
10020 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10021 +*** Please upgrade your binutils to 2.18 or newer
10022 +endef
10023 +
10024 +archprepare:
10025 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10026 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10027 index 379814b..add62ce 100644
10028 --- a/arch/x86/boot/Makefile
10029 +++ b/arch/x86/boot/Makefile
10030 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10031 $(call cc-option, -fno-stack-protector) \
10032 $(call cc-option, -mpreferred-stack-boundary=2)
10033 KBUILD_CFLAGS += $(call cc-option, -m32)
10034 +ifdef CONSTIFY_PLUGIN
10035 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10036 +endif
10037 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10038 GCOV_PROFILE := n
10039
10040 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10041 index 878e4b9..20537ab 100644
10042 --- a/arch/x86/boot/bitops.h
10043 +++ b/arch/x86/boot/bitops.h
10044 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10045 u8 v;
10046 const u32 *p = (const u32 *)addr;
10047
10048 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10049 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10050 return v;
10051 }
10052
10053 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10054
10055 static inline void set_bit(int nr, void *addr)
10056 {
10057 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10058 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10059 }
10060
10061 #endif /* BOOT_BITOPS_H */
10062 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10063 index 18997e5..83d9c67 100644
10064 --- a/arch/x86/boot/boot.h
10065 +++ b/arch/x86/boot/boot.h
10066 @@ -85,7 +85,7 @@ static inline void io_delay(void)
10067 static inline u16 ds(void)
10068 {
10069 u16 seg;
10070 - asm("movw %%ds,%0" : "=rm" (seg));
10071 + asm volatile("movw %%ds,%0" : "=rm" (seg));
10072 return seg;
10073 }
10074
10075 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10076 static inline int memcmp(const void *s1, const void *s2, size_t len)
10077 {
10078 u8 diff;
10079 - asm("repe; cmpsb; setnz %0"
10080 + asm volatile("repe; cmpsb; setnz %0"
10081 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10082 return diff;
10083 }
10084 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10085 index 8a84501..b2d165f 100644
10086 --- a/arch/x86/boot/compressed/Makefile
10087 +++ b/arch/x86/boot/compressed/Makefile
10088 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10089 KBUILD_CFLAGS += $(cflags-y)
10090 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10091 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10092 +ifdef CONSTIFY_PLUGIN
10093 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10094 +endif
10095
10096 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10097 GCOV_PROFILE := n
10098 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10099 index c205035..5853587 100644
10100 --- a/arch/x86/boot/compressed/eboot.c
10101 +++ b/arch/x86/boot/compressed/eboot.c
10102 @@ -150,7 +150,6 @@ again:
10103 *addr = max_addr;
10104 }
10105
10106 -free_pool:
10107 efi_call_phys1(sys_table->boottime->free_pool, map);
10108
10109 fail:
10110 @@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10111 if (i == map_size / desc_size)
10112 status = EFI_NOT_FOUND;
10113
10114 -free_pool:
10115 efi_call_phys1(sys_table->boottime->free_pool, map);
10116 fail:
10117 return status;
10118 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10119 index 1e3184f..0d11e2e 100644
10120 --- a/arch/x86/boot/compressed/head_32.S
10121 +++ b/arch/x86/boot/compressed/head_32.S
10122 @@ -118,7 +118,7 @@ preferred_addr:
10123 notl %eax
10124 andl %eax, %ebx
10125 #else
10126 - movl $LOAD_PHYSICAL_ADDR, %ebx
10127 + movl $____LOAD_PHYSICAL_ADDR, %ebx
10128 #endif
10129
10130 /* Target address to relocate to for decompression */
10131 @@ -204,7 +204,7 @@ relocated:
10132 * and where it was actually loaded.
10133 */
10134 movl %ebp, %ebx
10135 - subl $LOAD_PHYSICAL_ADDR, %ebx
10136 + subl $____LOAD_PHYSICAL_ADDR, %ebx
10137 jz 2f /* Nothing to be done if loaded at compiled addr. */
10138 /*
10139 * Process relocations.
10140 @@ -212,8 +212,7 @@ relocated:
10141
10142 1: subl $4, %edi
10143 movl (%edi), %ecx
10144 - testl %ecx, %ecx
10145 - jz 2f
10146 + jecxz 2f
10147 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10148 jmp 1b
10149 2:
10150 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10151 index f5d1aaa..cce11dc 100644
10152 --- a/arch/x86/boot/compressed/head_64.S
10153 +++ b/arch/x86/boot/compressed/head_64.S
10154 @@ -91,7 +91,7 @@ ENTRY(startup_32)
10155 notl %eax
10156 andl %eax, %ebx
10157 #else
10158 - movl $LOAD_PHYSICAL_ADDR, %ebx
10159 + movl $____LOAD_PHYSICAL_ADDR, %ebx
10160 #endif
10161
10162 /* Target address to relocate to for decompression */
10163 @@ -273,7 +273,7 @@ preferred_addr:
10164 notq %rax
10165 andq %rax, %rbp
10166 #else
10167 - movq $LOAD_PHYSICAL_ADDR, %rbp
10168 + movq $____LOAD_PHYSICAL_ADDR, %rbp
10169 #endif
10170
10171 /* Target address to relocate to for decompression */
10172 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10173 index 88f7ff6..ed695dd 100644
10174 --- a/arch/x86/boot/compressed/misc.c
10175 +++ b/arch/x86/boot/compressed/misc.c
10176 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
10177 case PT_LOAD:
10178 #ifdef CONFIG_RELOCATABLE
10179 dest = output;
10180 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10181 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10182 #else
10183 dest = (void *)(phdr->p_paddr);
10184 #endif
10185 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10186 error("Destination address too large");
10187 #endif
10188 #ifndef CONFIG_RELOCATABLE
10189 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10190 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10191 error("Wrong destination address");
10192 #endif
10193
10194 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10195 index 4d3ff03..e4972ff 100644
10196 --- a/arch/x86/boot/cpucheck.c
10197 +++ b/arch/x86/boot/cpucheck.c
10198 @@ -74,7 +74,7 @@ static int has_fpu(void)
10199 u16 fcw = -1, fsw = -1;
10200 u32 cr0;
10201
10202 - asm("movl %%cr0,%0" : "=r" (cr0));
10203 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
10204 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10205 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10206 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10207 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10208 {
10209 u32 f0, f1;
10210
10211 - asm("pushfl ; "
10212 + asm volatile("pushfl ; "
10213 "pushfl ; "
10214 "popl %0 ; "
10215 "movl %0,%1 ; "
10216 @@ -115,7 +115,7 @@ static void get_flags(void)
10217 set_bit(X86_FEATURE_FPU, cpu.flags);
10218
10219 if (has_eflag(X86_EFLAGS_ID)) {
10220 - asm("cpuid"
10221 + asm volatile("cpuid"
10222 : "=a" (max_intel_level),
10223 "=b" (cpu_vendor[0]),
10224 "=d" (cpu_vendor[1]),
10225 @@ -124,7 +124,7 @@ static void get_flags(void)
10226
10227 if (max_intel_level >= 0x00000001 &&
10228 max_intel_level <= 0x0000ffff) {
10229 - asm("cpuid"
10230 + asm volatile("cpuid"
10231 : "=a" (tfms),
10232 "=c" (cpu.flags[4]),
10233 "=d" (cpu.flags[0])
10234 @@ -136,7 +136,7 @@ static void get_flags(void)
10235 cpu.model += ((tfms >> 16) & 0xf) << 4;
10236 }
10237
10238 - asm("cpuid"
10239 + asm volatile("cpuid"
10240 : "=a" (max_amd_level)
10241 : "a" (0x80000000)
10242 : "ebx", "ecx", "edx");
10243 @@ -144,7 +144,7 @@ static void get_flags(void)
10244 if (max_amd_level >= 0x80000001 &&
10245 max_amd_level <= 0x8000ffff) {
10246 u32 eax = 0x80000001;
10247 - asm("cpuid"
10248 + asm volatile("cpuid"
10249 : "+a" (eax),
10250 "=c" (cpu.flags[6]),
10251 "=d" (cpu.flags[1])
10252 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10253 u32 ecx = MSR_K7_HWCR;
10254 u32 eax, edx;
10255
10256 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10257 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10258 eax &= ~(1 << 15);
10259 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10260 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10261
10262 get_flags(); /* Make sure it really did something */
10263 err = check_flags();
10264 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10265 u32 ecx = MSR_VIA_FCR;
10266 u32 eax, edx;
10267
10268 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10269 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10270 eax |= (1<<1)|(1<<7);
10271 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10272 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10273
10274 set_bit(X86_FEATURE_CX8, cpu.flags);
10275 err = check_flags();
10276 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10277 u32 eax, edx;
10278 u32 level = 1;
10279
10280 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10281 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10282 - asm("cpuid"
10283 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10284 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10285 + asm volatile("cpuid"
10286 : "+a" (level), "=d" (cpu.flags[0])
10287 : : "ecx", "ebx");
10288 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10289 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10290
10291 err = check_flags();
10292 }
10293 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10294 index 944ce59..87ee37a 100644
10295 --- a/arch/x86/boot/header.S
10296 +++ b/arch/x86/boot/header.S
10297 @@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10298 # single linked list of
10299 # struct setup_data
10300
10301 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10302 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10303
10304 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10305 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10306 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10307 +#else
10308 #define VO_INIT_SIZE (VO__end - VO__text)
10309 +#endif
10310 #if ZO_INIT_SIZE > VO_INIT_SIZE
10311 #define INIT_SIZE ZO_INIT_SIZE
10312 #else
10313 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10314 index db75d07..8e6d0af 100644
10315 --- a/arch/x86/boot/memory.c
10316 +++ b/arch/x86/boot/memory.c
10317 @@ -19,7 +19,7 @@
10318
10319 static int detect_memory_e820(void)
10320 {
10321 - int count = 0;
10322 + unsigned int count = 0;
10323 struct biosregs ireg, oreg;
10324 struct e820entry *desc = boot_params.e820_map;
10325 static struct e820entry buf; /* static so it is zeroed */
10326 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10327 index 11e8c6e..fdbb1ed 100644
10328 --- a/arch/x86/boot/video-vesa.c
10329 +++ b/arch/x86/boot/video-vesa.c
10330 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10331
10332 boot_params.screen_info.vesapm_seg = oreg.es;
10333 boot_params.screen_info.vesapm_off = oreg.di;
10334 + boot_params.screen_info.vesapm_size = oreg.cx;
10335 }
10336
10337 /*
10338 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10339 index 43eda28..5ab5fdb 100644
10340 --- a/arch/x86/boot/video.c
10341 +++ b/arch/x86/boot/video.c
10342 @@ -96,7 +96,7 @@ static void store_mode_params(void)
10343 static unsigned int get_entry(void)
10344 {
10345 char entry_buf[4];
10346 - int i, len = 0;
10347 + unsigned int i, len = 0;
10348 int key;
10349 unsigned int v;
10350
10351 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10352 index 5b577d5..3c1fed4 100644
10353 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
10354 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10355 @@ -8,6 +8,8 @@
10356 * including this sentence is retained in full.
10357 */
10358
10359 +#include <asm/alternative-asm.h>
10360 +
10361 .extern crypto_ft_tab
10362 .extern crypto_it_tab
10363 .extern crypto_fl_tab
10364 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
10365 je B192; \
10366 leaq 32(r9),r9;
10367
10368 +#define ret pax_force_retaddr 0, 1; ret
10369 +
10370 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10371 movq r1,r2; \
10372 movq r3,r4; \
10373 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10374 index 3470624..201259d 100644
10375 --- a/arch/x86/crypto/aesni-intel_asm.S
10376 +++ b/arch/x86/crypto/aesni-intel_asm.S
10377 @@ -31,6 +31,7 @@
10378
10379 #include <linux/linkage.h>
10380 #include <asm/inst.h>
10381 +#include <asm/alternative-asm.h>
10382
10383 #ifdef __x86_64__
10384 .data
10385 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
10386 pop %r14
10387 pop %r13
10388 pop %r12
10389 + pax_force_retaddr 0, 1
10390 ret
10391 +ENDPROC(aesni_gcm_dec)
10392
10393
10394 /*****************************************************************************
10395 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
10396 pop %r14
10397 pop %r13
10398 pop %r12
10399 + pax_force_retaddr 0, 1
10400 ret
10401 +ENDPROC(aesni_gcm_enc)
10402
10403 #endif
10404
10405 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
10406 pxor %xmm1, %xmm0
10407 movaps %xmm0, (TKEYP)
10408 add $0x10, TKEYP
10409 + pax_force_retaddr_bts
10410 ret
10411
10412 .align 4
10413 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
10414 shufps $0b01001110, %xmm2, %xmm1
10415 movaps %xmm1, 0x10(TKEYP)
10416 add $0x20, TKEYP
10417 + pax_force_retaddr_bts
10418 ret
10419
10420 .align 4
10421 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
10422
10423 movaps %xmm0, (TKEYP)
10424 add $0x10, TKEYP
10425 + pax_force_retaddr_bts
10426 ret
10427
10428 .align 4
10429 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
10430 pxor %xmm1, %xmm2
10431 movaps %xmm2, (TKEYP)
10432 add $0x10, TKEYP
10433 + pax_force_retaddr_bts
10434 ret
10435
10436 /*
10437 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
10438 #ifndef __x86_64__
10439 popl KEYP
10440 #endif
10441 + pax_force_retaddr 0, 1
10442 ret
10443 +ENDPROC(aesni_set_key)
10444
10445 /*
10446 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
10447 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
10448 popl KLEN
10449 popl KEYP
10450 #endif
10451 + pax_force_retaddr 0, 1
10452 ret
10453 +ENDPROC(aesni_enc)
10454
10455 /*
10456 * _aesni_enc1: internal ABI
10457 @@ -1959,6 +1972,7 @@ _aesni_enc1:
10458 AESENC KEY STATE
10459 movaps 0x70(TKEYP), KEY
10460 AESENCLAST KEY STATE
10461 + pax_force_retaddr_bts
10462 ret
10463
10464 /*
10465 @@ -2067,6 +2081,7 @@ _aesni_enc4:
10466 AESENCLAST KEY STATE2
10467 AESENCLAST KEY STATE3
10468 AESENCLAST KEY STATE4
10469 + pax_force_retaddr_bts
10470 ret
10471
10472 /*
10473 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
10474 popl KLEN
10475 popl KEYP
10476 #endif
10477 + pax_force_retaddr 0, 1
10478 ret
10479 +ENDPROC(aesni_dec)
10480
10481 /*
10482 * _aesni_dec1: internal ABI
10483 @@ -2146,6 +2163,7 @@ _aesni_dec1:
10484 AESDEC KEY STATE
10485 movaps 0x70(TKEYP), KEY
10486 AESDECLAST KEY STATE
10487 + pax_force_retaddr_bts
10488 ret
10489
10490 /*
10491 @@ -2254,6 +2272,7 @@ _aesni_dec4:
10492 AESDECLAST KEY STATE2
10493 AESDECLAST KEY STATE3
10494 AESDECLAST KEY STATE4
10495 + pax_force_retaddr_bts
10496 ret
10497
10498 /*
10499 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
10500 popl KEYP
10501 popl LEN
10502 #endif
10503 + pax_force_retaddr 0, 1
10504 ret
10505 +ENDPROC(aesni_ecb_enc)
10506
10507 /*
10508 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10509 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
10510 popl KEYP
10511 popl LEN
10512 #endif
10513 + pax_force_retaddr 0, 1
10514 ret
10515 +ENDPROC(aesni_ecb_dec)
10516
10517 /*
10518 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10519 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
10520 popl LEN
10521 popl IVP
10522 #endif
10523 + pax_force_retaddr 0, 1
10524 ret
10525 +ENDPROC(aesni_cbc_enc)
10526
10527 /*
10528 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10529 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
10530 popl LEN
10531 popl IVP
10532 #endif
10533 + pax_force_retaddr 0, 1
10534 ret
10535 +ENDPROC(aesni_cbc_dec)
10536
10537 #ifdef __x86_64__
10538 .align 16
10539 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
10540 mov $1, TCTR_LOW
10541 MOVQ_R64_XMM TCTR_LOW INC
10542 MOVQ_R64_XMM CTR TCTR_LOW
10543 + pax_force_retaddr_bts
10544 ret
10545
10546 /*
10547 @@ -2554,6 +2582,7 @@ _aesni_inc:
10548 .Linc_low:
10549 movaps CTR, IV
10550 PSHUFB_XMM BSWAP_MASK IV
10551 + pax_force_retaddr_bts
10552 ret
10553
10554 /*
10555 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
10556 .Lctr_enc_ret:
10557 movups IV, (IVP)
10558 .Lctr_enc_just_ret:
10559 + pax_force_retaddr 0, 1
10560 ret
10561 +ENDPROC(aesni_ctr_enc)
10562 #endif
10563 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10564 index 391d245..67f35c2 100644
10565 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10566 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10567 @@ -20,6 +20,8 @@
10568 *
10569 */
10570
10571 +#include <asm/alternative-asm.h>
10572 +
10573 .file "blowfish-x86_64-asm.S"
10574 .text
10575
10576 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
10577 jnz __enc_xor;
10578
10579 write_block();
10580 + pax_force_retaddr 0, 1
10581 ret;
10582 __enc_xor:
10583 xor_block();
10584 + pax_force_retaddr 0, 1
10585 ret;
10586
10587 .align 8
10588 @@ -188,6 +192,7 @@ blowfish_dec_blk:
10589
10590 movq %r11, %rbp;
10591
10592 + pax_force_retaddr 0, 1
10593 ret;
10594
10595 /**********************************************************************
10596 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
10597
10598 popq %rbx;
10599 popq %rbp;
10600 + pax_force_retaddr 0, 1
10601 ret;
10602
10603 __enc_xor4:
10604 @@ -349,6 +355,7 @@ __enc_xor4:
10605
10606 popq %rbx;
10607 popq %rbp;
10608 + pax_force_retaddr 0, 1
10609 ret;
10610
10611 .align 8
10612 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
10613 popq %rbx;
10614 popq %rbp;
10615
10616 + pax_force_retaddr 0, 1
10617 ret;
10618
10619 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10620 index 0b33743..7a56206 100644
10621 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10622 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10623 @@ -20,6 +20,8 @@
10624 *
10625 */
10626
10627 +#include <asm/alternative-asm.h>
10628 +
10629 .file "camellia-x86_64-asm_64.S"
10630 .text
10631
10632 @@ -229,12 +231,14 @@ __enc_done:
10633 enc_outunpack(mov, RT1);
10634
10635 movq RRBP, %rbp;
10636 + pax_force_retaddr 0, 1
10637 ret;
10638
10639 __enc_xor:
10640 enc_outunpack(xor, RT1);
10641
10642 movq RRBP, %rbp;
10643 + pax_force_retaddr 0, 1
10644 ret;
10645
10646 .global camellia_dec_blk;
10647 @@ -275,6 +279,7 @@ __dec_rounds16:
10648 dec_outunpack();
10649
10650 movq RRBP, %rbp;
10651 + pax_force_retaddr 0, 1
10652 ret;
10653
10654 /**********************************************************************
10655 @@ -468,6 +473,7 @@ __enc2_done:
10656
10657 movq RRBP, %rbp;
10658 popq %rbx;
10659 + pax_force_retaddr 0, 1
10660 ret;
10661
10662 __enc2_xor:
10663 @@ -475,6 +481,7 @@ __enc2_xor:
10664
10665 movq RRBP, %rbp;
10666 popq %rbx;
10667 + pax_force_retaddr 0, 1
10668 ret;
10669
10670 .global camellia_dec_blk_2way;
10671 @@ -517,4 +524,5 @@ __dec2_rounds16:
10672
10673 movq RRBP, %rbp;
10674 movq RXOR, %rbx;
10675 + pax_force_retaddr 0, 1
10676 ret;
10677 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10678 index 15b00ac..2071784 100644
10679 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10680 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10681 @@ -23,6 +23,8 @@
10682 *
10683 */
10684
10685 +#include <asm/alternative-asm.h>
10686 +
10687 .file "cast5-avx-x86_64-asm_64.S"
10688
10689 .extern cast_s1
10690 @@ -281,6 +283,7 @@ __skip_enc:
10691 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10692 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10693
10694 + pax_force_retaddr 0, 1
10695 ret;
10696
10697 .align 16
10698 @@ -353,6 +356,7 @@ __dec_tail:
10699 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10700 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10701
10702 + pax_force_retaddr 0, 1
10703 ret;
10704
10705 __skip_dec:
10706 @@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
10707 vmovdqu RR4, (6*4*4)(%r11);
10708 vmovdqu RL4, (7*4*4)(%r11);
10709
10710 + pax_force_retaddr
10711 ret;
10712
10713 .align 16
10714 @@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
10715 vmovdqu RR4, (6*4*4)(%r11);
10716 vmovdqu RL4, (7*4*4)(%r11);
10717
10718 + pax_force_retaddr
10719 ret;
10720
10721 .align 16
10722 @@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
10723
10724 popq %r12;
10725
10726 + pax_force_retaddr
10727 ret;
10728
10729 .align 16
10730 @@ -555,4 +562,5 @@ cast5_ctr_16way:
10731
10732 popq %r12;
10733
10734 + pax_force_retaddr
10735 ret;
10736 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10737 index 2569d0d..637c289 100644
10738 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10739 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10740 @@ -23,6 +23,8 @@
10741 *
10742 */
10743
10744 +#include <asm/alternative-asm.h>
10745 +
10746 #include "glue_helper-asm-avx.S"
10747
10748 .file "cast6-avx-x86_64-asm_64.S"
10749 @@ -294,6 +296,7 @@ __cast6_enc_blk8:
10750 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10751 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10752
10753 + pax_force_retaddr 0, 1
10754 ret;
10755
10756 .align 8
10757 @@ -340,6 +343,7 @@ __cast6_dec_blk8:
10758 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10759 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10760
10761 + pax_force_retaddr 0, 1
10762 ret;
10763
10764 .align 8
10765 @@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
10766
10767 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10768
10769 + pax_force_retaddr
10770 ret;
10771
10772 .align 8
10773 @@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
10774
10775 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10776
10777 + pax_force_retaddr
10778 ret;
10779
10780 .align 8
10781 @@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
10782
10783 popq %r12;
10784
10785 + pax_force_retaddr
10786 ret;
10787
10788 .align 8
10789 @@ -436,4 +443,5 @@ cast6_ctr_8way:
10790
10791 popq %r12;
10792
10793 + pax_force_retaddr
10794 ret;
10795 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10796 index 6214a9b..1f4fc9a 100644
10797 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
10798 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10799 @@ -1,3 +1,5 @@
10800 +#include <asm/alternative-asm.h>
10801 +
10802 # enter ECRYPT_encrypt_bytes
10803 .text
10804 .p2align 5
10805 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
10806 add %r11,%rsp
10807 mov %rdi,%rax
10808 mov %rsi,%rdx
10809 + pax_force_retaddr 0, 1
10810 ret
10811 # bytesatleast65:
10812 ._bytesatleast65:
10813 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
10814 add %r11,%rsp
10815 mov %rdi,%rax
10816 mov %rsi,%rdx
10817 + pax_force_retaddr
10818 ret
10819 # enter ECRYPT_ivsetup
10820 .text
10821 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
10822 add %r11,%rsp
10823 mov %rdi,%rax
10824 mov %rsi,%rdx
10825 + pax_force_retaddr
10826 ret
10827 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10828 index 02b0e9f..cf4cf5c 100644
10829 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10830 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10831 @@ -24,6 +24,8 @@
10832 *
10833 */
10834
10835 +#include <asm/alternative-asm.h>
10836 +
10837 #include "glue_helper-asm-avx.S"
10838
10839 .file "serpent-avx-x86_64-asm_64.S"
10840 @@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
10841 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10842 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10843
10844 + pax_force_retaddr
10845 ret;
10846
10847 .align 8
10848 @@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
10849 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10850 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10851
10852 + pax_force_retaddr
10853 ret;
10854
10855 .align 8
10856 @@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
10857
10858 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10859
10860 + pax_force_retaddr
10861 ret;
10862
10863 .align 8
10864 @@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
10865
10866 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10867
10868 + pax_force_retaddr
10869 ret;
10870
10871 .align 8
10872 @@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
10873
10874 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10875
10876 + pax_force_retaddr
10877 ret;
10878
10879 .align 8
10880 @@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
10881
10882 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10883
10884 + pax_force_retaddr
10885 ret;
10886 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10887 index 3ee1ff0..cbc568b 100644
10888 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10889 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10890 @@ -24,6 +24,8 @@
10891 *
10892 */
10893
10894 +#include <asm/alternative-asm.h>
10895 +
10896 .file "serpent-sse2-x86_64-asm_64.S"
10897 .text
10898
10899 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
10900 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10901 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10902
10903 + pax_force_retaddr
10904 ret;
10905
10906 __enc_xor8:
10907 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10908 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10909
10910 + pax_force_retaddr
10911 ret;
10912
10913 .align 8
10914 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
10915 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10916 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10917
10918 + pax_force_retaddr
10919 ret;
10920 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
10921 index 49d6987..df66bd4 100644
10922 --- a/arch/x86/crypto/sha1_ssse3_asm.S
10923 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
10924 @@ -28,6 +28,8 @@
10925 * (at your option) any later version.
10926 */
10927
10928 +#include <asm/alternative-asm.h>
10929 +
10930 #define CTX %rdi // arg1
10931 #define BUF %rsi // arg2
10932 #define CNT %rdx // arg3
10933 @@ -104,6 +106,7 @@
10934 pop %r12
10935 pop %rbp
10936 pop %rbx
10937 + pax_force_retaddr 0, 1
10938 ret
10939
10940 .size \name, .-\name
10941 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10942 index ebac16b..8092eb9 100644
10943 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10944 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10945 @@ -23,6 +23,8 @@
10946 *
10947 */
10948
10949 +#include <asm/alternative-asm.h>
10950 +
10951 #include "glue_helper-asm-avx.S"
10952
10953 .file "twofish-avx-x86_64-asm_64.S"
10954 @@ -283,6 +285,7 @@ __twofish_enc_blk8:
10955 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
10956 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
10957
10958 + pax_force_retaddr 0, 1
10959 ret;
10960
10961 .align 8
10962 @@ -324,6 +327,7 @@ __twofish_dec_blk8:
10963 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
10964 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
10965
10966 + pax_force_retaddr 0, 1
10967 ret;
10968
10969 .align 8
10970 @@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
10971
10972 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
10973
10974 + pax_force_retaddr 0, 1
10975 ret;
10976
10977 .align 8
10978 @@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
10979
10980 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10981
10982 + pax_force_retaddr 0, 1
10983 ret;
10984
10985 .align 8
10986 @@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
10987
10988 popq %r12;
10989
10990 + pax_force_retaddr 0, 1
10991 ret;
10992
10993 .align 8
10994 @@ -420,4 +427,5 @@ twofish_ctr_8way:
10995
10996 popq %r12;
10997
10998 + pax_force_retaddr 0, 1
10999 ret;
11000 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11001 index 5b012a2..36d5364 100644
11002 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11003 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11004 @@ -20,6 +20,8 @@
11005 *
11006 */
11007
11008 +#include <asm/alternative-asm.h>
11009 +
11010 .file "twofish-x86_64-asm-3way.S"
11011 .text
11012
11013 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
11014 popq %r13;
11015 popq %r14;
11016 popq %r15;
11017 + pax_force_retaddr 0, 1
11018 ret;
11019
11020 __enc_xor3:
11021 @@ -271,6 +274,7 @@ __enc_xor3:
11022 popq %r13;
11023 popq %r14;
11024 popq %r15;
11025 + pax_force_retaddr 0, 1
11026 ret;
11027
11028 .global twofish_dec_blk_3way
11029 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11030 popq %r13;
11031 popq %r14;
11032 popq %r15;
11033 + pax_force_retaddr 0, 1
11034 ret;
11035
11036 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11037 index 7bcf3fc..f53832f 100644
11038 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11039 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11040 @@ -21,6 +21,7 @@
11041 .text
11042
11043 #include <asm/asm-offsets.h>
11044 +#include <asm/alternative-asm.h>
11045
11046 #define a_offset 0
11047 #define b_offset 4
11048 @@ -268,6 +269,7 @@ twofish_enc_blk:
11049
11050 popq R1
11051 movq $1,%rax
11052 + pax_force_retaddr 0, 1
11053 ret
11054
11055 twofish_dec_blk:
11056 @@ -319,4 +321,5 @@ twofish_dec_blk:
11057
11058 popq R1
11059 movq $1,%rax
11060 + pax_force_retaddr 0, 1
11061 ret
11062 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11063 index a703af1..f5b9c36 100644
11064 --- a/arch/x86/ia32/ia32_aout.c
11065 +++ b/arch/x86/ia32/ia32_aout.c
11066 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11067 unsigned long dump_start, dump_size;
11068 struct user32 dump;
11069
11070 + memset(&dump, 0, sizeof(dump));
11071 +
11072 fs = get_fs();
11073 set_fs(KERNEL_DS);
11074 has_dumped = 1;
11075 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11076 index a1daf4a..f8c4537 100644
11077 --- a/arch/x86/ia32/ia32_signal.c
11078 +++ b/arch/x86/ia32/ia32_signal.c
11079 @@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11080 sp -= frame_size;
11081 /* Align the stack pointer according to the i386 ABI,
11082 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11083 - sp = ((sp + 4) & -16ul) - 4;
11084 + sp = ((sp - 12) & -16ul) - 4;
11085 return (void __user *) sp;
11086 }
11087
11088 @@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11089 * These are actually not used anymore, but left because some
11090 * gdb versions depend on them as a marker.
11091 */
11092 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11093 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11094 } put_user_catch(err);
11095
11096 if (err)
11097 @@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11098 0xb8,
11099 __NR_ia32_rt_sigreturn,
11100 0x80cd,
11101 - 0,
11102 + 0
11103 };
11104
11105 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11106 @@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11107
11108 if (ka->sa.sa_flags & SA_RESTORER)
11109 restorer = ka->sa.sa_restorer;
11110 + else if (current->mm->context.vdso)
11111 + /* Return stub is in 32bit vsyscall page */
11112 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11113 else
11114 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11115 - rt_sigreturn);
11116 + restorer = &frame->retcode;
11117 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11118
11119 /*
11120 * Not actually used anymore, but left because some gdb
11121 * versions need it.
11122 */
11123 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11124 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11125 } put_user_catch(err);
11126
11127 err |= copy_siginfo_to_user32(&frame->info, info);
11128 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11129 index 142c4ce..19b683f 100644
11130 --- a/arch/x86/ia32/ia32entry.S
11131 +++ b/arch/x86/ia32/ia32entry.S
11132 @@ -15,8 +15,10 @@
11133 #include <asm/irqflags.h>
11134 #include <asm/asm.h>
11135 #include <asm/smap.h>
11136 +#include <asm/pgtable.h>
11137 #include <linux/linkage.h>
11138 #include <linux/err.h>
11139 +#include <asm/alternative-asm.h>
11140
11141 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11142 #include <linux/elf-em.h>
11143 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11144 ENDPROC(native_irq_enable_sysexit)
11145 #endif
11146
11147 + .macro pax_enter_kernel_user
11148 + pax_set_fptr_mask
11149 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11150 + call pax_enter_kernel_user
11151 +#endif
11152 + .endm
11153 +
11154 + .macro pax_exit_kernel_user
11155 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11156 + call pax_exit_kernel_user
11157 +#endif
11158 +#ifdef CONFIG_PAX_RANDKSTACK
11159 + pushq %rax
11160 + pushq %r11
11161 + call pax_randomize_kstack
11162 + popq %r11
11163 + popq %rax
11164 +#endif
11165 + .endm
11166 +
11167 +.macro pax_erase_kstack
11168 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11169 + call pax_erase_kstack
11170 +#endif
11171 +.endm
11172 +
11173 /*
11174 * 32bit SYSENTER instruction entry.
11175 *
11176 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11177 CFI_REGISTER rsp,rbp
11178 SWAPGS_UNSAFE_STACK
11179 movq PER_CPU_VAR(kernel_stack), %rsp
11180 - addq $(KERNEL_STACK_OFFSET),%rsp
11181 - /*
11182 - * No need to follow this irqs on/off section: the syscall
11183 - * disabled irqs, here we enable it straight after entry:
11184 - */
11185 - ENABLE_INTERRUPTS(CLBR_NONE)
11186 movl %ebp,%ebp /* zero extension */
11187 pushq_cfi $__USER32_DS
11188 /*CFI_REL_OFFSET ss,0*/
11189 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11190 CFI_REL_OFFSET rsp,0
11191 pushfq_cfi
11192 /*CFI_REL_OFFSET rflags,0*/
11193 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11194 - CFI_REGISTER rip,r10
11195 + orl $X86_EFLAGS_IF,(%rsp)
11196 + GET_THREAD_INFO(%r11)
11197 + movl TI_sysenter_return(%r11), %r11d
11198 + CFI_REGISTER rip,r11
11199 pushq_cfi $__USER32_CS
11200 /*CFI_REL_OFFSET cs,0*/
11201 movl %eax, %eax
11202 - pushq_cfi %r10
11203 + pushq_cfi %r11
11204 CFI_REL_OFFSET rip,0
11205 pushq_cfi %rax
11206 cld
11207 SAVE_ARGS 0,1,0
11208 + pax_enter_kernel_user
11209 +
11210 +#ifdef CONFIG_PAX_RANDKSTACK
11211 + pax_erase_kstack
11212 +#endif
11213 +
11214 + /*
11215 + * No need to follow this irqs on/off section: the syscall
11216 + * disabled irqs, here we enable it straight after entry:
11217 + */
11218 + ENABLE_INTERRUPTS(CLBR_NONE)
11219 /* no need to do an access_ok check here because rbp has been
11220 32bit zero extended */
11221 +
11222 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11223 + mov $PAX_USER_SHADOW_BASE,%r11
11224 + add %r11,%rbp
11225 +#endif
11226 +
11227 ASM_STAC
11228 1: movl (%rbp),%ebp
11229 _ASM_EXTABLE(1b,ia32_badarg)
11230 ASM_CLAC
11231 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11232 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11233 + GET_THREAD_INFO(%r11)
11234 + orl $TS_COMPAT,TI_status(%r11)
11235 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11236 CFI_REMEMBER_STATE
11237 jnz sysenter_tracesys
11238 cmpq $(IA32_NR_syscalls-1),%rax
11239 @@ -162,12 +204,15 @@ sysenter_do_call:
11240 sysenter_dispatch:
11241 call *ia32_sys_call_table(,%rax,8)
11242 movq %rax,RAX-ARGOFFSET(%rsp)
11243 + GET_THREAD_INFO(%r11)
11244 DISABLE_INTERRUPTS(CLBR_NONE)
11245 TRACE_IRQS_OFF
11246 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11247 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11248 jnz sysexit_audit
11249 sysexit_from_sys_call:
11250 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11251 + pax_exit_kernel_user
11252 + pax_erase_kstack
11253 + andl $~TS_COMPAT,TI_status(%r11)
11254 /* clear IF, that popfq doesn't enable interrupts early */
11255 andl $~0x200,EFLAGS-R11(%rsp)
11256 movl RIP-R11(%rsp),%edx /* User %eip */
11257 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
11258 movl %eax,%esi /* 2nd arg: syscall number */
11259 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11260 call __audit_syscall_entry
11261 +
11262 + pax_erase_kstack
11263 +
11264 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11265 cmpq $(IA32_NR_syscalls-1),%rax
11266 ja ia32_badsys
11267 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
11268 .endm
11269
11270 .macro auditsys_exit exit
11271 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11272 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11273 jnz ia32_ret_from_sys_call
11274 TRACE_IRQS_ON
11275 ENABLE_INTERRUPTS(CLBR_NONE)
11276 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
11277 1: setbe %al /* 1 if error, 0 if not */
11278 movzbl %al,%edi /* zero-extend that into %edi */
11279 call __audit_syscall_exit
11280 + GET_THREAD_INFO(%r11)
11281 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11282 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11283 DISABLE_INTERRUPTS(CLBR_NONE)
11284 TRACE_IRQS_OFF
11285 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11286 + testl %edi,TI_flags(%r11)
11287 jz \exit
11288 CLEAR_RREGS -ARGOFFSET
11289 jmp int_with_check
11290 @@ -237,7 +286,7 @@ sysexit_audit:
11291
11292 sysenter_tracesys:
11293 #ifdef CONFIG_AUDITSYSCALL
11294 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11295 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11296 jz sysenter_auditsys
11297 #endif
11298 SAVE_REST
11299 @@ -249,6 +298,9 @@ sysenter_tracesys:
11300 RESTORE_REST
11301 cmpq $(IA32_NR_syscalls-1),%rax
11302 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11303 +
11304 + pax_erase_kstack
11305 +
11306 jmp sysenter_do_call
11307 CFI_ENDPROC
11308 ENDPROC(ia32_sysenter_target)
11309 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11310 ENTRY(ia32_cstar_target)
11311 CFI_STARTPROC32 simple
11312 CFI_SIGNAL_FRAME
11313 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11314 + CFI_DEF_CFA rsp,0
11315 CFI_REGISTER rip,rcx
11316 /*CFI_REGISTER rflags,r11*/
11317 SWAPGS_UNSAFE_STACK
11318 movl %esp,%r8d
11319 CFI_REGISTER rsp,r8
11320 movq PER_CPU_VAR(kernel_stack),%rsp
11321 + SAVE_ARGS 8*6,0,0
11322 + pax_enter_kernel_user
11323 +
11324 +#ifdef CONFIG_PAX_RANDKSTACK
11325 + pax_erase_kstack
11326 +#endif
11327 +
11328 /*
11329 * No need to follow this irqs on/off section: the syscall
11330 * disabled irqs and here we enable it straight after entry:
11331 */
11332 ENABLE_INTERRUPTS(CLBR_NONE)
11333 - SAVE_ARGS 8,0,0
11334 movl %eax,%eax /* zero extension */
11335 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11336 movq %rcx,RIP-ARGOFFSET(%rsp)
11337 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11338 /* no need to do an access_ok check here because r8 has been
11339 32bit zero extended */
11340 /* hardware stack frame is complete now */
11341 +
11342 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11343 + mov $PAX_USER_SHADOW_BASE,%r11
11344 + add %r11,%r8
11345 +#endif
11346 +
11347 ASM_STAC
11348 1: movl (%r8),%r9d
11349 _ASM_EXTABLE(1b,ia32_badarg)
11350 ASM_CLAC
11351 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11352 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11353 + GET_THREAD_INFO(%r11)
11354 + orl $TS_COMPAT,TI_status(%r11)
11355 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11356 CFI_REMEMBER_STATE
11357 jnz cstar_tracesys
11358 cmpq $IA32_NR_syscalls-1,%rax
11359 @@ -319,12 +384,15 @@ cstar_do_call:
11360 cstar_dispatch:
11361 call *ia32_sys_call_table(,%rax,8)
11362 movq %rax,RAX-ARGOFFSET(%rsp)
11363 + GET_THREAD_INFO(%r11)
11364 DISABLE_INTERRUPTS(CLBR_NONE)
11365 TRACE_IRQS_OFF
11366 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11367 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11368 jnz sysretl_audit
11369 sysretl_from_sys_call:
11370 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11371 + pax_exit_kernel_user
11372 + pax_erase_kstack
11373 + andl $~TS_COMPAT,TI_status(%r11)
11374 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11375 movl RIP-ARGOFFSET(%rsp),%ecx
11376 CFI_REGISTER rip,rcx
11377 @@ -352,7 +420,7 @@ sysretl_audit:
11378
11379 cstar_tracesys:
11380 #ifdef CONFIG_AUDITSYSCALL
11381 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11382 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11383 jz cstar_auditsys
11384 #endif
11385 xchgl %r9d,%ebp
11386 @@ -366,6 +434,9 @@ cstar_tracesys:
11387 xchgl %ebp,%r9d
11388 cmpq $(IA32_NR_syscalls-1),%rax
11389 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11390 +
11391 + pax_erase_kstack
11392 +
11393 jmp cstar_do_call
11394 END(ia32_cstar_target)
11395
11396 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11397 CFI_REL_OFFSET rip,RIP-RIP
11398 PARAVIRT_ADJUST_EXCEPTION_FRAME
11399 SWAPGS
11400 - /*
11401 - * No need to follow this irqs on/off section: the syscall
11402 - * disabled irqs and here we enable it straight after entry:
11403 - */
11404 - ENABLE_INTERRUPTS(CLBR_NONE)
11405 movl %eax,%eax
11406 pushq_cfi %rax
11407 cld
11408 /* note the registers are not zero extended to the sf.
11409 this could be a problem. */
11410 SAVE_ARGS 0,1,0
11411 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11412 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11413 + pax_enter_kernel_user
11414 +
11415 +#ifdef CONFIG_PAX_RANDKSTACK
11416 + pax_erase_kstack
11417 +#endif
11418 +
11419 + /*
11420 + * No need to follow this irqs on/off section: the syscall
11421 + * disabled irqs and here we enable it straight after entry:
11422 + */
11423 + ENABLE_INTERRUPTS(CLBR_NONE)
11424 + GET_THREAD_INFO(%r11)
11425 + orl $TS_COMPAT,TI_status(%r11)
11426 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11427 jnz ia32_tracesys
11428 cmpq $(IA32_NR_syscalls-1),%rax
11429 ja ia32_badsys
11430 @@ -442,6 +520,9 @@ ia32_tracesys:
11431 RESTORE_REST
11432 cmpq $(IA32_NR_syscalls-1),%rax
11433 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11434 +
11435 + pax_erase_kstack
11436 +
11437 jmp ia32_do_call
11438 END(ia32_syscall)
11439
11440 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11441 index d0b689b..34be51d 100644
11442 --- a/arch/x86/ia32/sys_ia32.c
11443 +++ b/arch/x86/ia32/sys_ia32.c
11444 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11445 */
11446 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11447 {
11448 - typeof(ubuf->st_uid) uid = 0;
11449 - typeof(ubuf->st_gid) gid = 0;
11450 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
11451 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
11452 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11453 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11454 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11455 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11456 mm_segment_t old_fs = get_fs();
11457
11458 set_fs(KERNEL_DS);
11459 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
11460 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
11461 set_fs(old_fs);
11462 if (put_compat_timespec(&t, interval))
11463 return -EFAULT;
11464 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
11465 mm_segment_t old_fs = get_fs();
11466
11467 set_fs(KERNEL_DS);
11468 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
11469 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
11470 set_fs(old_fs);
11471 if (!ret) {
11472 switch (_NSIG_WORDS) {
11473 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
11474 if (copy_siginfo_from_user32(&info, uinfo))
11475 return -EFAULT;
11476 set_fs(KERNEL_DS);
11477 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
11478 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
11479 set_fs(old_fs);
11480 return ret;
11481 }
11482 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11483 return -EFAULT;
11484
11485 set_fs(KERNEL_DS);
11486 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11487 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11488 count);
11489 set_fs(old_fs);
11490
11491 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11492 index 372231c..a5aa1a1 100644
11493 --- a/arch/x86/include/asm/alternative-asm.h
11494 +++ b/arch/x86/include/asm/alternative-asm.h
11495 @@ -18,6 +18,45 @@
11496 .endm
11497 #endif
11498
11499 +#ifdef KERNEXEC_PLUGIN
11500 + .macro pax_force_retaddr_bts rip=0
11501 + btsq $63,\rip(%rsp)
11502 + .endm
11503 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11504 + .macro pax_force_retaddr rip=0, reload=0
11505 + btsq $63,\rip(%rsp)
11506 + .endm
11507 + .macro pax_force_fptr ptr
11508 + btsq $63,\ptr
11509 + .endm
11510 + .macro pax_set_fptr_mask
11511 + .endm
11512 +#endif
11513 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11514 + .macro pax_force_retaddr rip=0, reload=0
11515 + .if \reload
11516 + pax_set_fptr_mask
11517 + .endif
11518 + orq %r10,\rip(%rsp)
11519 + .endm
11520 + .macro pax_force_fptr ptr
11521 + orq %r10,\ptr
11522 + .endm
11523 + .macro pax_set_fptr_mask
11524 + movabs $0x8000000000000000,%r10
11525 + .endm
11526 +#endif
11527 +#else
11528 + .macro pax_force_retaddr rip=0, reload=0
11529 + .endm
11530 + .macro pax_force_fptr ptr
11531 + .endm
11532 + .macro pax_force_retaddr_bts rip=0
11533 + .endm
11534 + .macro pax_set_fptr_mask
11535 + .endm
11536 +#endif
11537 +
11538 .macro altinstruction_entry orig alt feature orig_len alt_len
11539 .long \orig - .
11540 .long \alt - .
11541 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11542 index 58ed6d9..f1cbe58 100644
11543 --- a/arch/x86/include/asm/alternative.h
11544 +++ b/arch/x86/include/asm/alternative.h
11545 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11546 ".pushsection .discard,\"aw\",@progbits\n" \
11547 DISCARD_ENTRY(1) \
11548 ".popsection\n" \
11549 - ".pushsection .altinstr_replacement, \"ax\"\n" \
11550 + ".pushsection .altinstr_replacement, \"a\"\n" \
11551 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11552 ".popsection"
11553
11554 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11555 DISCARD_ENTRY(1) \
11556 DISCARD_ENTRY(2) \
11557 ".popsection\n" \
11558 - ".pushsection .altinstr_replacement, \"ax\"\n" \
11559 + ".pushsection .altinstr_replacement, \"a\"\n" \
11560 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11561 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11562 ".popsection"
11563 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11564 index 3388034..050f0b9 100644
11565 --- a/arch/x86/include/asm/apic.h
11566 +++ b/arch/x86/include/asm/apic.h
11567 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11568
11569 #ifdef CONFIG_X86_LOCAL_APIC
11570
11571 -extern unsigned int apic_verbosity;
11572 +extern int apic_verbosity;
11573 extern int local_apic_timer_c2_ok;
11574
11575 extern int disable_apic;
11576 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11577 index 20370c6..a2eb9b0 100644
11578 --- a/arch/x86/include/asm/apm.h
11579 +++ b/arch/x86/include/asm/apm.h
11580 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11581 __asm__ __volatile__(APM_DO_ZERO_SEGS
11582 "pushl %%edi\n\t"
11583 "pushl %%ebp\n\t"
11584 - "lcall *%%cs:apm_bios_entry\n\t"
11585 + "lcall *%%ss:apm_bios_entry\n\t"
11586 "setc %%al\n\t"
11587 "popl %%ebp\n\t"
11588 "popl %%edi\n\t"
11589 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11590 __asm__ __volatile__(APM_DO_ZERO_SEGS
11591 "pushl %%edi\n\t"
11592 "pushl %%ebp\n\t"
11593 - "lcall *%%cs:apm_bios_entry\n\t"
11594 + "lcall *%%ss:apm_bios_entry\n\t"
11595 "setc %%bl\n\t"
11596 "popl %%ebp\n\t"
11597 "popl %%edi\n\t"
11598 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11599 index 722aa3b..3a0bb27 100644
11600 --- a/arch/x86/include/asm/atomic.h
11601 +++ b/arch/x86/include/asm/atomic.h
11602 @@ -22,7 +22,18 @@
11603 */
11604 static inline int atomic_read(const atomic_t *v)
11605 {
11606 - return (*(volatile int *)&(v)->counter);
11607 + return (*(volatile const int *)&(v)->counter);
11608 +}
11609 +
11610 +/**
11611 + * atomic_read_unchecked - read atomic variable
11612 + * @v: pointer of type atomic_unchecked_t
11613 + *
11614 + * Atomically reads the value of @v.
11615 + */
11616 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11617 +{
11618 + return (*(volatile const int *)&(v)->counter);
11619 }
11620
11621 /**
11622 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11623 }
11624
11625 /**
11626 + * atomic_set_unchecked - set atomic variable
11627 + * @v: pointer of type atomic_unchecked_t
11628 + * @i: required value
11629 + *
11630 + * Atomically sets the value of @v to @i.
11631 + */
11632 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
11633 +{
11634 + v->counter = i;
11635 +}
11636 +
11637 +/**
11638 * atomic_add - add integer to atomic variable
11639 * @i: integer value to add
11640 * @v: pointer of type atomic_t
11641 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
11642 */
11643 static inline void atomic_add(int i, atomic_t *v)
11644 {
11645 - asm volatile(LOCK_PREFIX "addl %1,%0"
11646 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
11647 +
11648 +#ifdef CONFIG_PAX_REFCOUNT
11649 + "jno 0f\n"
11650 + LOCK_PREFIX "subl %1,%0\n"
11651 + "int $4\n0:\n"
11652 + _ASM_EXTABLE(0b, 0b)
11653 +#endif
11654 +
11655 + : "+m" (v->counter)
11656 + : "ir" (i));
11657 +}
11658 +
11659 +/**
11660 + * atomic_add_unchecked - add integer to atomic variable
11661 + * @i: integer value to add
11662 + * @v: pointer of type atomic_unchecked_t
11663 + *
11664 + * Atomically adds @i to @v.
11665 + */
11666 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
11667 +{
11668 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
11669 : "+m" (v->counter)
11670 : "ir" (i));
11671 }
11672 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
11673 */
11674 static inline void atomic_sub(int i, atomic_t *v)
11675 {
11676 - asm volatile(LOCK_PREFIX "subl %1,%0"
11677 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
11678 +
11679 +#ifdef CONFIG_PAX_REFCOUNT
11680 + "jno 0f\n"
11681 + LOCK_PREFIX "addl %1,%0\n"
11682 + "int $4\n0:\n"
11683 + _ASM_EXTABLE(0b, 0b)
11684 +#endif
11685 +
11686 + : "+m" (v->counter)
11687 + : "ir" (i));
11688 +}
11689 +
11690 +/**
11691 + * atomic_sub_unchecked - subtract integer from atomic variable
11692 + * @i: integer value to subtract
11693 + * @v: pointer of type atomic_unchecked_t
11694 + *
11695 + * Atomically subtracts @i from @v.
11696 + */
11697 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
11698 +{
11699 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
11700 : "+m" (v->counter)
11701 : "ir" (i));
11702 }
11703 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11704 {
11705 unsigned char c;
11706
11707 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
11708 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
11709 +
11710 +#ifdef CONFIG_PAX_REFCOUNT
11711 + "jno 0f\n"
11712 + LOCK_PREFIX "addl %2,%0\n"
11713 + "int $4\n0:\n"
11714 + _ASM_EXTABLE(0b, 0b)
11715 +#endif
11716 +
11717 + "sete %1\n"
11718 : "+m" (v->counter), "=qm" (c)
11719 : "ir" (i) : "memory");
11720 return c;
11721 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11722 */
11723 static inline void atomic_inc(atomic_t *v)
11724 {
11725 - asm volatile(LOCK_PREFIX "incl %0"
11726 + asm volatile(LOCK_PREFIX "incl %0\n"
11727 +
11728 +#ifdef CONFIG_PAX_REFCOUNT
11729 + "jno 0f\n"
11730 + LOCK_PREFIX "decl %0\n"
11731 + "int $4\n0:\n"
11732 + _ASM_EXTABLE(0b, 0b)
11733 +#endif
11734 +
11735 + : "+m" (v->counter));
11736 +}
11737 +
11738 +/**
11739 + * atomic_inc_unchecked - increment atomic variable
11740 + * @v: pointer of type atomic_unchecked_t
11741 + *
11742 + * Atomically increments @v by 1.
11743 + */
11744 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
11745 +{
11746 + asm volatile(LOCK_PREFIX "incl %0\n"
11747 : "+m" (v->counter));
11748 }
11749
11750 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
11751 */
11752 static inline void atomic_dec(atomic_t *v)
11753 {
11754 - asm volatile(LOCK_PREFIX "decl %0"
11755 + asm volatile(LOCK_PREFIX "decl %0\n"
11756 +
11757 +#ifdef CONFIG_PAX_REFCOUNT
11758 + "jno 0f\n"
11759 + LOCK_PREFIX "incl %0\n"
11760 + "int $4\n0:\n"
11761 + _ASM_EXTABLE(0b, 0b)
11762 +#endif
11763 +
11764 + : "+m" (v->counter));
11765 +}
11766 +
11767 +/**
11768 + * atomic_dec_unchecked - decrement atomic variable
11769 + * @v: pointer of type atomic_unchecked_t
11770 + *
11771 + * Atomically decrements @v by 1.
11772 + */
11773 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
11774 +{
11775 + asm volatile(LOCK_PREFIX "decl %0\n"
11776 : "+m" (v->counter));
11777 }
11778
11779 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
11780 {
11781 unsigned char c;
11782
11783 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
11784 + asm volatile(LOCK_PREFIX "decl %0\n"
11785 +
11786 +#ifdef CONFIG_PAX_REFCOUNT
11787 + "jno 0f\n"
11788 + LOCK_PREFIX "incl %0\n"
11789 + "int $4\n0:\n"
11790 + _ASM_EXTABLE(0b, 0b)
11791 +#endif
11792 +
11793 + "sete %1\n"
11794 : "+m" (v->counter), "=qm" (c)
11795 : : "memory");
11796 return c != 0;
11797 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
11798 {
11799 unsigned char c;
11800
11801 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
11802 + asm volatile(LOCK_PREFIX "incl %0\n"
11803 +
11804 +#ifdef CONFIG_PAX_REFCOUNT
11805 + "jno 0f\n"
11806 + LOCK_PREFIX "decl %0\n"
11807 + "int $4\n0:\n"
11808 + _ASM_EXTABLE(0b, 0b)
11809 +#endif
11810 +
11811 + "sete %1\n"
11812 + : "+m" (v->counter), "=qm" (c)
11813 + : : "memory");
11814 + return c != 0;
11815 +}
11816 +
11817 +/**
11818 + * atomic_inc_and_test_unchecked - increment and test
11819 + * @v: pointer of type atomic_unchecked_t
11820 + *
11821 + * Atomically increments @v by 1
11822 + * and returns true if the result is zero, or false for all
11823 + * other cases.
11824 + */
11825 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
11826 +{
11827 + unsigned char c;
11828 +
11829 + asm volatile(LOCK_PREFIX "incl %0\n"
11830 + "sete %1\n"
11831 : "+m" (v->counter), "=qm" (c)
11832 : : "memory");
11833 return c != 0;
11834 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11835 {
11836 unsigned char c;
11837
11838 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
11839 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
11840 +
11841 +#ifdef CONFIG_PAX_REFCOUNT
11842 + "jno 0f\n"
11843 + LOCK_PREFIX "subl %2,%0\n"
11844 + "int $4\n0:\n"
11845 + _ASM_EXTABLE(0b, 0b)
11846 +#endif
11847 +
11848 + "sets %1\n"
11849 : "+m" (v->counter), "=qm" (c)
11850 : "ir" (i) : "memory");
11851 return c;
11852 @@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11853 */
11854 static inline int atomic_add_return(int i, atomic_t *v)
11855 {
11856 + return i + xadd_check_overflow(&v->counter, i);
11857 +}
11858 +
11859 +/**
11860 + * atomic_add_return_unchecked - add integer and return
11861 + * @i: integer value to add
11862 + * @v: pointer of type atomic_unchecked_t
11863 + *
11864 + * Atomically adds @i to @v and returns @i + @v
11865 + */
11866 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
11867 +{
11868 return i + xadd(&v->counter, i);
11869 }
11870
11871 @@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
11872 }
11873
11874 #define atomic_inc_return(v) (atomic_add_return(1, v))
11875 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
11876 +{
11877 + return atomic_add_return_unchecked(1, v);
11878 +}
11879 #define atomic_dec_return(v) (atomic_sub_return(1, v))
11880
11881 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11882 @@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11883 return cmpxchg(&v->counter, old, new);
11884 }
11885
11886 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
11887 +{
11888 + return cmpxchg(&v->counter, old, new);
11889 +}
11890 +
11891 static inline int atomic_xchg(atomic_t *v, int new)
11892 {
11893 return xchg(&v->counter, new);
11894 }
11895
11896 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
11897 +{
11898 + return xchg(&v->counter, new);
11899 +}
11900 +
11901 /**
11902 * __atomic_add_unless - add unless the number is already a given value
11903 * @v: pointer of type atomic_t
11904 @@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
11905 */
11906 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11907 {
11908 - int c, old;
11909 + int c, old, new;
11910 c = atomic_read(v);
11911 for (;;) {
11912 - if (unlikely(c == (u)))
11913 + if (unlikely(c == u))
11914 break;
11915 - old = atomic_cmpxchg((v), c, c + (a));
11916 +
11917 + asm volatile("addl %2,%0\n"
11918 +
11919 +#ifdef CONFIG_PAX_REFCOUNT
11920 + "jno 0f\n"
11921 + "subl %2,%0\n"
11922 + "int $4\n0:\n"
11923 + _ASM_EXTABLE(0b, 0b)
11924 +#endif
11925 +
11926 + : "=r" (new)
11927 + : "0" (c), "ir" (a));
11928 +
11929 + old = atomic_cmpxchg(v, c, new);
11930 if (likely(old == c))
11931 break;
11932 c = old;
11933 @@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11934 }
11935
11936 /**
11937 + * atomic_inc_not_zero_hint - increment if not null
11938 + * @v: pointer of type atomic_t
11939 + * @hint: probable value of the atomic before the increment
11940 + *
11941 + * This version of atomic_inc_not_zero() gives a hint of probable
11942 + * value of the atomic. This helps processor to not read the memory
11943 + * before doing the atomic read/modify/write cycle, lowering
11944 + * number of bus transactions on some arches.
11945 + *
11946 + * Returns: 0 if increment was not done, 1 otherwise.
11947 + */
11948 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
11949 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
11950 +{
11951 + int val, c = hint, new;
11952 +
11953 + /* sanity test, should be removed by compiler if hint is a constant */
11954 + if (!hint)
11955 + return __atomic_add_unless(v, 1, 0);
11956 +
11957 + do {
11958 + asm volatile("incl %0\n"
11959 +
11960 +#ifdef CONFIG_PAX_REFCOUNT
11961 + "jno 0f\n"
11962 + "decl %0\n"
11963 + "int $4\n0:\n"
11964 + _ASM_EXTABLE(0b, 0b)
11965 +#endif
11966 +
11967 + : "=r" (new)
11968 + : "0" (c));
11969 +
11970 + val = atomic_cmpxchg(v, c, new);
11971 + if (val == c)
11972 + return 1;
11973 + c = val;
11974 + } while (c);
11975 +
11976 + return 0;
11977 +}
11978 +
11979 +/**
11980 * atomic_inc_short - increment of a short integer
11981 * @v: pointer to type int
11982 *
11983 @@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
11984 #endif
11985
11986 /* These are x86-specific, used by some header files */
11987 -#define atomic_clear_mask(mask, addr) \
11988 - asm volatile(LOCK_PREFIX "andl %0,%1" \
11989 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
11990 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
11991 +{
11992 + asm volatile(LOCK_PREFIX "andl %1,%0"
11993 + : "+m" (v->counter)
11994 + : "r" (~(mask))
11995 + : "memory");
11996 +}
11997
11998 -#define atomic_set_mask(mask, addr) \
11999 - asm volatile(LOCK_PREFIX "orl %0,%1" \
12000 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12001 - : "memory")
12002 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12003 +{
12004 + asm volatile(LOCK_PREFIX "andl %1,%0"
12005 + : "+m" (v->counter)
12006 + : "r" (~(mask))
12007 + : "memory");
12008 +}
12009 +
12010 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12011 +{
12012 + asm volatile(LOCK_PREFIX "orl %1,%0"
12013 + : "+m" (v->counter)
12014 + : "r" (mask)
12015 + : "memory");
12016 +}
12017 +
12018 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12019 +{
12020 + asm volatile(LOCK_PREFIX "orl %1,%0"
12021 + : "+m" (v->counter)
12022 + : "r" (mask)
12023 + : "memory");
12024 +}
12025
12026 /* Atomic operations are already serializing on x86 */
12027 #define smp_mb__before_atomic_dec() barrier()
12028 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12029 index b154de7..aadebd8 100644
12030 --- a/arch/x86/include/asm/atomic64_32.h
12031 +++ b/arch/x86/include/asm/atomic64_32.h
12032 @@ -12,6 +12,14 @@ typedef struct {
12033 u64 __aligned(8) counter;
12034 } atomic64_t;
12035
12036 +#ifdef CONFIG_PAX_REFCOUNT
12037 +typedef struct {
12038 + u64 __aligned(8) counter;
12039 +} atomic64_unchecked_t;
12040 +#else
12041 +typedef atomic64_t atomic64_unchecked_t;
12042 +#endif
12043 +
12044 #define ATOMIC64_INIT(val) { (val) }
12045
12046 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12047 @@ -37,21 +45,31 @@ typedef struct {
12048 ATOMIC64_DECL_ONE(sym##_386)
12049
12050 ATOMIC64_DECL_ONE(add_386);
12051 +ATOMIC64_DECL_ONE(add_unchecked_386);
12052 ATOMIC64_DECL_ONE(sub_386);
12053 +ATOMIC64_DECL_ONE(sub_unchecked_386);
12054 ATOMIC64_DECL_ONE(inc_386);
12055 +ATOMIC64_DECL_ONE(inc_unchecked_386);
12056 ATOMIC64_DECL_ONE(dec_386);
12057 +ATOMIC64_DECL_ONE(dec_unchecked_386);
12058 #endif
12059
12060 #define alternative_atomic64(f, out, in...) \
12061 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12062
12063 ATOMIC64_DECL(read);
12064 +ATOMIC64_DECL(read_unchecked);
12065 ATOMIC64_DECL(set);
12066 +ATOMIC64_DECL(set_unchecked);
12067 ATOMIC64_DECL(xchg);
12068 ATOMIC64_DECL(add_return);
12069 +ATOMIC64_DECL(add_return_unchecked);
12070 ATOMIC64_DECL(sub_return);
12071 +ATOMIC64_DECL(sub_return_unchecked);
12072 ATOMIC64_DECL(inc_return);
12073 +ATOMIC64_DECL(inc_return_unchecked);
12074 ATOMIC64_DECL(dec_return);
12075 +ATOMIC64_DECL(dec_return_unchecked);
12076 ATOMIC64_DECL(dec_if_positive);
12077 ATOMIC64_DECL(inc_not_zero);
12078 ATOMIC64_DECL(add_unless);
12079 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12080 }
12081
12082 /**
12083 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12084 + * @p: pointer to type atomic64_unchecked_t
12085 + * @o: expected value
12086 + * @n: new value
12087 + *
12088 + * Atomically sets @v to @n if it was equal to @o and returns
12089 + * the old value.
12090 + */
12091 +
12092 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12093 +{
12094 + return cmpxchg64(&v->counter, o, n);
12095 +}
12096 +
12097 +/**
12098 * atomic64_xchg - xchg atomic64 variable
12099 * @v: pointer to type atomic64_t
12100 * @n: value to assign
12101 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12102 }
12103
12104 /**
12105 + * atomic64_set_unchecked - set atomic64 variable
12106 + * @v: pointer to type atomic64_unchecked_t
12107 + * @n: value to assign
12108 + *
12109 + * Atomically sets the value of @v to @n.
12110 + */
12111 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12112 +{
12113 + unsigned high = (unsigned)(i >> 32);
12114 + unsigned low = (unsigned)i;
12115 + alternative_atomic64(set, /* no output */,
12116 + "S" (v), "b" (low), "c" (high)
12117 + : "eax", "edx", "memory");
12118 +}
12119 +
12120 +/**
12121 * atomic64_read - read atomic64 variable
12122 * @v: pointer to type atomic64_t
12123 *
12124 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12125 }
12126
12127 /**
12128 + * atomic64_read_unchecked - read atomic64 variable
12129 + * @v: pointer to type atomic64_unchecked_t
12130 + *
12131 + * Atomically reads the value of @v and returns it.
12132 + */
12133 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12134 +{
12135 + long long r;
12136 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12137 + return r;
12138 + }
12139 +
12140 +/**
12141 * atomic64_add_return - add and return
12142 * @i: integer value to add
12143 * @v: pointer to type atomic64_t
12144 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12145 return i;
12146 }
12147
12148 +/**
12149 + * atomic64_add_return_unchecked - add and return
12150 + * @i: integer value to add
12151 + * @v: pointer to type atomic64_unchecked_t
12152 + *
12153 + * Atomically adds @i to @v and returns @i + *@v
12154 + */
12155 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12156 +{
12157 + alternative_atomic64(add_return_unchecked,
12158 + ASM_OUTPUT2("+A" (i), "+c" (v)),
12159 + ASM_NO_INPUT_CLOBBER("memory"));
12160 + return i;
12161 +}
12162 +
12163 /*
12164 * Other variants with different arithmetic operators:
12165 */
12166 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12167 return a;
12168 }
12169
12170 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12171 +{
12172 + long long a;
12173 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
12174 + "S" (v) : "memory", "ecx");
12175 + return a;
12176 +}
12177 +
12178 static inline long long atomic64_dec_return(atomic64_t *v)
12179 {
12180 long long a;
12181 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12182 }
12183
12184 /**
12185 + * atomic64_add_unchecked - add integer to atomic64 variable
12186 + * @i: integer value to add
12187 + * @v: pointer to type atomic64_unchecked_t
12188 + *
12189 + * Atomically adds @i to @v.
12190 + */
12191 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12192 +{
12193 + __alternative_atomic64(add_unchecked, add_return_unchecked,
12194 + ASM_OUTPUT2("+A" (i), "+c" (v)),
12195 + ASM_NO_INPUT_CLOBBER("memory"));
12196 + return i;
12197 +}
12198 +
12199 +/**
12200 * atomic64_sub - subtract the atomic64 variable
12201 * @i: integer value to subtract
12202 * @v: pointer to type atomic64_t
12203 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12204 index 0e1cbfc..5623683 100644
12205 --- a/arch/x86/include/asm/atomic64_64.h
12206 +++ b/arch/x86/include/asm/atomic64_64.h
12207 @@ -18,7 +18,19 @@
12208 */
12209 static inline long atomic64_read(const atomic64_t *v)
12210 {
12211 - return (*(volatile long *)&(v)->counter);
12212 + return (*(volatile const long *)&(v)->counter);
12213 +}
12214 +
12215 +/**
12216 + * atomic64_read_unchecked - read atomic64 variable
12217 + * @v: pointer of type atomic64_unchecked_t
12218 + *
12219 + * Atomically reads the value of @v.
12220 + * Doesn't imply a read memory barrier.
12221 + */
12222 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12223 +{
12224 + return (*(volatile const long *)&(v)->counter);
12225 }
12226
12227 /**
12228 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12229 }
12230
12231 /**
12232 + * atomic64_set_unchecked - set atomic64 variable
12233 + * @v: pointer to type atomic64_unchecked_t
12234 + * @i: required value
12235 + *
12236 + * Atomically sets the value of @v to @i.
12237 + */
12238 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12239 +{
12240 + v->counter = i;
12241 +}
12242 +
12243 +/**
12244 * atomic64_add - add integer to atomic64 variable
12245 * @i: integer value to add
12246 * @v: pointer to type atomic64_t
12247 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12248 */
12249 static inline void atomic64_add(long i, atomic64_t *v)
12250 {
12251 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
12252 +
12253 +#ifdef CONFIG_PAX_REFCOUNT
12254 + "jno 0f\n"
12255 + LOCK_PREFIX "subq %1,%0\n"
12256 + "int $4\n0:\n"
12257 + _ASM_EXTABLE(0b, 0b)
12258 +#endif
12259 +
12260 + : "=m" (v->counter)
12261 + : "er" (i), "m" (v->counter));
12262 +}
12263 +
12264 +/**
12265 + * atomic64_add_unchecked - add integer to atomic64 variable
12266 + * @i: integer value to add
12267 + * @v: pointer to type atomic64_unchecked_t
12268 + *
12269 + * Atomically adds @i to @v.
12270 + */
12271 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12272 +{
12273 asm volatile(LOCK_PREFIX "addq %1,%0"
12274 : "=m" (v->counter)
12275 : "er" (i), "m" (v->counter));
12276 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12277 */
12278 static inline void atomic64_sub(long i, atomic64_t *v)
12279 {
12280 - asm volatile(LOCK_PREFIX "subq %1,%0"
12281 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
12282 +
12283 +#ifdef CONFIG_PAX_REFCOUNT
12284 + "jno 0f\n"
12285 + LOCK_PREFIX "addq %1,%0\n"
12286 + "int $4\n0:\n"
12287 + _ASM_EXTABLE(0b, 0b)
12288 +#endif
12289 +
12290 + : "=m" (v->counter)
12291 + : "er" (i), "m" (v->counter));
12292 +}
12293 +
12294 +/**
12295 + * atomic64_sub_unchecked - subtract the atomic64 variable
12296 + * @i: integer value to subtract
12297 + * @v: pointer to type atomic64_unchecked_t
12298 + *
12299 + * Atomically subtracts @i from @v.
12300 + */
12301 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12302 +{
12303 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
12304 : "=m" (v->counter)
12305 : "er" (i), "m" (v->counter));
12306 }
12307 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12308 {
12309 unsigned char c;
12310
12311 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12312 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
12313 +
12314 +#ifdef CONFIG_PAX_REFCOUNT
12315 + "jno 0f\n"
12316 + LOCK_PREFIX "addq %2,%0\n"
12317 + "int $4\n0:\n"
12318 + _ASM_EXTABLE(0b, 0b)
12319 +#endif
12320 +
12321 + "sete %1\n"
12322 : "=m" (v->counter), "=qm" (c)
12323 : "er" (i), "m" (v->counter) : "memory");
12324 return c;
12325 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12326 */
12327 static inline void atomic64_inc(atomic64_t *v)
12328 {
12329 + asm volatile(LOCK_PREFIX "incq %0\n"
12330 +
12331 +#ifdef CONFIG_PAX_REFCOUNT
12332 + "jno 0f\n"
12333 + LOCK_PREFIX "decq %0\n"
12334 + "int $4\n0:\n"
12335 + _ASM_EXTABLE(0b, 0b)
12336 +#endif
12337 +
12338 + : "=m" (v->counter)
12339 + : "m" (v->counter));
12340 +}
12341 +
12342 +/**
12343 + * atomic64_inc_unchecked - increment atomic64 variable
12344 + * @v: pointer to type atomic64_unchecked_t
12345 + *
12346 + * Atomically increments @v by 1.
12347 + */
12348 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12349 +{
12350 asm volatile(LOCK_PREFIX "incq %0"
12351 : "=m" (v->counter)
12352 : "m" (v->counter));
12353 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12354 */
12355 static inline void atomic64_dec(atomic64_t *v)
12356 {
12357 - asm volatile(LOCK_PREFIX "decq %0"
12358 + asm volatile(LOCK_PREFIX "decq %0\n"
12359 +
12360 +#ifdef CONFIG_PAX_REFCOUNT
12361 + "jno 0f\n"
12362 + LOCK_PREFIX "incq %0\n"
12363 + "int $4\n0:\n"
12364 + _ASM_EXTABLE(0b, 0b)
12365 +#endif
12366 +
12367 + : "=m" (v->counter)
12368 + : "m" (v->counter));
12369 +}
12370 +
12371 +/**
12372 + * atomic64_dec_unchecked - decrement atomic64 variable
12373 + * @v: pointer to type atomic64_t
12374 + *
12375 + * Atomically decrements @v by 1.
12376 + */
12377 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12378 +{
12379 + asm volatile(LOCK_PREFIX "decq %0\n"
12380 : "=m" (v->counter)
12381 : "m" (v->counter));
12382 }
12383 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12384 {
12385 unsigned char c;
12386
12387 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
12388 + asm volatile(LOCK_PREFIX "decq %0\n"
12389 +
12390 +#ifdef CONFIG_PAX_REFCOUNT
12391 + "jno 0f\n"
12392 + LOCK_PREFIX "incq %0\n"
12393 + "int $4\n0:\n"
12394 + _ASM_EXTABLE(0b, 0b)
12395 +#endif
12396 +
12397 + "sete %1\n"
12398 : "=m" (v->counter), "=qm" (c)
12399 : "m" (v->counter) : "memory");
12400 return c != 0;
12401 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12402 {
12403 unsigned char c;
12404
12405 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
12406 + asm volatile(LOCK_PREFIX "incq %0\n"
12407 +
12408 +#ifdef CONFIG_PAX_REFCOUNT
12409 + "jno 0f\n"
12410 + LOCK_PREFIX "decq %0\n"
12411 + "int $4\n0:\n"
12412 + _ASM_EXTABLE(0b, 0b)
12413 +#endif
12414 +
12415 + "sete %1\n"
12416 : "=m" (v->counter), "=qm" (c)
12417 : "m" (v->counter) : "memory");
12418 return c != 0;
12419 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12420 {
12421 unsigned char c;
12422
12423 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12424 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
12425 +
12426 +#ifdef CONFIG_PAX_REFCOUNT
12427 + "jno 0f\n"
12428 + LOCK_PREFIX "subq %2,%0\n"
12429 + "int $4\n0:\n"
12430 + _ASM_EXTABLE(0b, 0b)
12431 +#endif
12432 +
12433 + "sets %1\n"
12434 : "=m" (v->counter), "=qm" (c)
12435 : "er" (i), "m" (v->counter) : "memory");
12436 return c;
12437 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12438 */
12439 static inline long atomic64_add_return(long i, atomic64_t *v)
12440 {
12441 + return i + xadd_check_overflow(&v->counter, i);
12442 +}
12443 +
12444 +/**
12445 + * atomic64_add_return_unchecked - add and return
12446 + * @i: integer value to add
12447 + * @v: pointer to type atomic64_unchecked_t
12448 + *
12449 + * Atomically adds @i to @v and returns @i + @v
12450 + */
12451 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12452 +{
12453 return i + xadd(&v->counter, i);
12454 }
12455
12456 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12457 }
12458
12459 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12460 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12461 +{
12462 + return atomic64_add_return_unchecked(1, v);
12463 +}
12464 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12465
12466 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12467 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12468 return cmpxchg(&v->counter, old, new);
12469 }
12470
12471 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12472 +{
12473 + return cmpxchg(&v->counter, old, new);
12474 +}
12475 +
12476 static inline long atomic64_xchg(atomic64_t *v, long new)
12477 {
12478 return xchg(&v->counter, new);
12479 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12480 */
12481 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12482 {
12483 - long c, old;
12484 + long c, old, new;
12485 c = atomic64_read(v);
12486 for (;;) {
12487 - if (unlikely(c == (u)))
12488 + if (unlikely(c == u))
12489 break;
12490 - old = atomic64_cmpxchg((v), c, c + (a));
12491 +
12492 + asm volatile("add %2,%0\n"
12493 +
12494 +#ifdef CONFIG_PAX_REFCOUNT
12495 + "jno 0f\n"
12496 + "sub %2,%0\n"
12497 + "int $4\n0:\n"
12498 + _ASM_EXTABLE(0b, 0b)
12499 +#endif
12500 +
12501 + : "=r" (new)
12502 + : "0" (c), "ir" (a));
12503 +
12504 + old = atomic64_cmpxchg(v, c, new);
12505 if (likely(old == c))
12506 break;
12507 c = old;
12508 }
12509 - return c != (u);
12510 + return c != u;
12511 }
12512
12513 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12514 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12515 index 6dfd019..0c6699f 100644
12516 --- a/arch/x86/include/asm/bitops.h
12517 +++ b/arch/x86/include/asm/bitops.h
12518 @@ -40,7 +40,7 @@
12519 * a mask operation on a byte.
12520 */
12521 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12522 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12523 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12524 #define CONST_MASK(nr) (1 << ((nr) & 7))
12525
12526 /**
12527 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12528 index 4fa687a..60f2d39 100644
12529 --- a/arch/x86/include/asm/boot.h
12530 +++ b/arch/x86/include/asm/boot.h
12531 @@ -6,10 +6,15 @@
12532 #include <uapi/asm/boot.h>
12533
12534 /* Physical address where kernel should be loaded. */
12535 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12536 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12537 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12538 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12539
12540 +#ifndef __ASSEMBLY__
12541 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
12542 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12543 +#endif
12544 +
12545 /* Minimum kernel alignment, as a power of two */
12546 #ifdef CONFIG_X86_64
12547 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12548 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12549 index 48f99f1..d78ebf9 100644
12550 --- a/arch/x86/include/asm/cache.h
12551 +++ b/arch/x86/include/asm/cache.h
12552 @@ -5,12 +5,13 @@
12553
12554 /* L1 cache line size */
12555 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12556 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12557 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12558
12559 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12560 +#define __read_only __attribute__((__section__(".data..read_only")))
12561
12562 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12563 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12564 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12565
12566 #ifdef CONFIG_X86_VSMP
12567 #ifdef CONFIG_SMP
12568 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12569 index 9863ee3..4a1f8e1 100644
12570 --- a/arch/x86/include/asm/cacheflush.h
12571 +++ b/arch/x86/include/asm/cacheflush.h
12572 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12573 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12574
12575 if (pg_flags == _PGMT_DEFAULT)
12576 - return -1;
12577 + return ~0UL;
12578 else if (pg_flags == _PGMT_WC)
12579 return _PAGE_CACHE_WC;
12580 else if (pg_flags == _PGMT_UC_MINUS)
12581 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12582 index 46fc474..b02b0f9 100644
12583 --- a/arch/x86/include/asm/checksum_32.h
12584 +++ b/arch/x86/include/asm/checksum_32.h
12585 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12586 int len, __wsum sum,
12587 int *src_err_ptr, int *dst_err_ptr);
12588
12589 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12590 + int len, __wsum sum,
12591 + int *src_err_ptr, int *dst_err_ptr);
12592 +
12593 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12594 + int len, __wsum sum,
12595 + int *src_err_ptr, int *dst_err_ptr);
12596 +
12597 /*
12598 * Note: when you get a NULL pointer exception here this means someone
12599 * passed in an incorrect kernel address to one of these functions.
12600 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12601 int *err_ptr)
12602 {
12603 might_sleep();
12604 - return csum_partial_copy_generic((__force void *)src, dst,
12605 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
12606 len, sum, err_ptr, NULL);
12607 }
12608
12609 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12610 {
12611 might_sleep();
12612 if (access_ok(VERIFY_WRITE, dst, len))
12613 - return csum_partial_copy_generic(src, (__force void *)dst,
12614 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12615 len, sum, NULL, err_ptr);
12616
12617 if (len)
12618 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
12619 index 8d871ea..c1a0dc9 100644
12620 --- a/arch/x86/include/asm/cmpxchg.h
12621 +++ b/arch/x86/include/asm/cmpxchg.h
12622 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
12623 __compiletime_error("Bad argument size for cmpxchg");
12624 extern void __xadd_wrong_size(void)
12625 __compiletime_error("Bad argument size for xadd");
12626 +extern void __xadd_check_overflow_wrong_size(void)
12627 + __compiletime_error("Bad argument size for xadd_check_overflow");
12628 extern void __add_wrong_size(void)
12629 __compiletime_error("Bad argument size for add");
12630 +extern void __add_check_overflow_wrong_size(void)
12631 + __compiletime_error("Bad argument size for add_check_overflow");
12632
12633 /*
12634 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
12635 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
12636 __ret; \
12637 })
12638
12639 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
12640 + ({ \
12641 + __typeof__ (*(ptr)) __ret = (arg); \
12642 + switch (sizeof(*(ptr))) { \
12643 + case __X86_CASE_L: \
12644 + asm volatile (lock #op "l %0, %1\n" \
12645 + "jno 0f\n" \
12646 + "mov %0,%1\n" \
12647 + "int $4\n0:\n" \
12648 + _ASM_EXTABLE(0b, 0b) \
12649 + : "+r" (__ret), "+m" (*(ptr)) \
12650 + : : "memory", "cc"); \
12651 + break; \
12652 + case __X86_CASE_Q: \
12653 + asm volatile (lock #op "q %q0, %1\n" \
12654 + "jno 0f\n" \
12655 + "mov %0,%1\n" \
12656 + "int $4\n0:\n" \
12657 + _ASM_EXTABLE(0b, 0b) \
12658 + : "+r" (__ret), "+m" (*(ptr)) \
12659 + : : "memory", "cc"); \
12660 + break; \
12661 + default: \
12662 + __ ## op ## _check_overflow_wrong_size(); \
12663 + } \
12664 + __ret; \
12665 + })
12666 +
12667 /*
12668 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
12669 * Since this is generally used to protect other memory information, we
12670 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
12671 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
12672 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
12673
12674 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
12675 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
12676 +
12677 #define __add(ptr, inc, lock) \
12678 ({ \
12679 __typeof__ (*(ptr)) __ret = (inc); \
12680 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
12681 index 2d9075e..b75a844 100644
12682 --- a/arch/x86/include/asm/cpufeature.h
12683 +++ b/arch/x86/include/asm/cpufeature.h
12684 @@ -206,7 +206,7 @@
12685 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
12686 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
12687 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
12688 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
12689 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
12690 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
12691 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
12692 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
12693 @@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
12694 ".section .discard,\"aw\",@progbits\n"
12695 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
12696 ".previous\n"
12697 - ".section .altinstr_replacement,\"ax\"\n"
12698 + ".section .altinstr_replacement,\"a\"\n"
12699 "3: movb $1,%0\n"
12700 "4:\n"
12701 ".previous\n"
12702 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
12703 index 8bf1c06..f723dfd 100644
12704 --- a/arch/x86/include/asm/desc.h
12705 +++ b/arch/x86/include/asm/desc.h
12706 @@ -4,6 +4,7 @@
12707 #include <asm/desc_defs.h>
12708 #include <asm/ldt.h>
12709 #include <asm/mmu.h>
12710 +#include <asm/pgtable.h>
12711
12712 #include <linux/smp.h>
12713 #include <linux/percpu.h>
12714 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12715
12716 desc->type = (info->read_exec_only ^ 1) << 1;
12717 desc->type |= info->contents << 2;
12718 + desc->type |= info->seg_not_present ^ 1;
12719
12720 desc->s = 1;
12721 desc->dpl = 0x3;
12722 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12723 }
12724
12725 extern struct desc_ptr idt_descr;
12726 -extern gate_desc idt_table[];
12727 extern struct desc_ptr nmi_idt_descr;
12728 -extern gate_desc nmi_idt_table[];
12729 -
12730 -struct gdt_page {
12731 - struct desc_struct gdt[GDT_ENTRIES];
12732 -} __attribute__((aligned(PAGE_SIZE)));
12733 -
12734 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
12735 +extern gate_desc idt_table[256];
12736 +extern gate_desc nmi_idt_table[256];
12737
12738 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
12739 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
12740 {
12741 - return per_cpu(gdt_page, cpu).gdt;
12742 + return cpu_gdt_table[cpu];
12743 }
12744
12745 #ifdef CONFIG_X86_64
12746 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
12747 unsigned long base, unsigned dpl, unsigned flags,
12748 unsigned short seg)
12749 {
12750 - gate->a = (seg << 16) | (base & 0xffff);
12751 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
12752 + gate->gate.offset_low = base;
12753 + gate->gate.seg = seg;
12754 + gate->gate.reserved = 0;
12755 + gate->gate.type = type;
12756 + gate->gate.s = 0;
12757 + gate->gate.dpl = dpl;
12758 + gate->gate.p = 1;
12759 + gate->gate.offset_high = base >> 16;
12760 }
12761
12762 #endif
12763 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
12764
12765 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
12766 {
12767 + pax_open_kernel();
12768 memcpy(&idt[entry], gate, sizeof(*gate));
12769 + pax_close_kernel();
12770 }
12771
12772 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
12773 {
12774 + pax_open_kernel();
12775 memcpy(&ldt[entry], desc, 8);
12776 + pax_close_kernel();
12777 }
12778
12779 static inline void
12780 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
12781 default: size = sizeof(*gdt); break;
12782 }
12783
12784 + pax_open_kernel();
12785 memcpy(&gdt[entry], desc, size);
12786 + pax_close_kernel();
12787 }
12788
12789 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
12790 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
12791
12792 static inline void native_load_tr_desc(void)
12793 {
12794 + pax_open_kernel();
12795 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
12796 + pax_close_kernel();
12797 }
12798
12799 static inline void native_load_gdt(const struct desc_ptr *dtr)
12800 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
12801 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
12802 unsigned int i;
12803
12804 + pax_open_kernel();
12805 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
12806 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
12807 + pax_close_kernel();
12808 }
12809
12810 #define _LDT_empty(info) \
12811 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
12812 }
12813
12814 #ifdef CONFIG_X86_64
12815 -static inline void set_nmi_gate(int gate, void *addr)
12816 +static inline void set_nmi_gate(int gate, const void *addr)
12817 {
12818 gate_desc s;
12819
12820 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
12821 }
12822 #endif
12823
12824 -static inline void _set_gate(int gate, unsigned type, void *addr,
12825 +static inline void _set_gate(int gate, unsigned type, const void *addr,
12826 unsigned dpl, unsigned ist, unsigned seg)
12827 {
12828 gate_desc s;
12829 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
12830 * Pentium F0 0F bugfix can have resulted in the mapped
12831 * IDT being write-protected.
12832 */
12833 -static inline void set_intr_gate(unsigned int n, void *addr)
12834 +static inline void set_intr_gate(unsigned int n, const void *addr)
12835 {
12836 BUG_ON((unsigned)n > 0xFF);
12837 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
12838 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
12839 /*
12840 * This routine sets up an interrupt gate at directory privilege level 3.
12841 */
12842 -static inline void set_system_intr_gate(unsigned int n, void *addr)
12843 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
12844 {
12845 BUG_ON((unsigned)n > 0xFF);
12846 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
12847 }
12848
12849 -static inline void set_system_trap_gate(unsigned int n, void *addr)
12850 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
12851 {
12852 BUG_ON((unsigned)n > 0xFF);
12853 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
12854 }
12855
12856 -static inline void set_trap_gate(unsigned int n, void *addr)
12857 +static inline void set_trap_gate(unsigned int n, const void *addr)
12858 {
12859 BUG_ON((unsigned)n > 0xFF);
12860 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
12861 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
12862 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
12863 {
12864 BUG_ON((unsigned)n > 0xFF);
12865 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
12866 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
12867 }
12868
12869 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
12870 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
12871 {
12872 BUG_ON((unsigned)n > 0xFF);
12873 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
12874 }
12875
12876 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
12877 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
12878 {
12879 BUG_ON((unsigned)n > 0xFF);
12880 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
12881 }
12882
12883 +#ifdef CONFIG_X86_32
12884 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
12885 +{
12886 + struct desc_struct d;
12887 +
12888 + if (likely(limit))
12889 + limit = (limit - 1UL) >> PAGE_SHIFT;
12890 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
12891 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
12892 +}
12893 +#endif
12894 +
12895 #endif /* _ASM_X86_DESC_H */
12896 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
12897 index 278441f..b95a174 100644
12898 --- a/arch/x86/include/asm/desc_defs.h
12899 +++ b/arch/x86/include/asm/desc_defs.h
12900 @@ -31,6 +31,12 @@ struct desc_struct {
12901 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
12902 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
12903 };
12904 + struct {
12905 + u16 offset_low;
12906 + u16 seg;
12907 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
12908 + unsigned offset_high: 16;
12909 + } gate;
12910 };
12911 } __attribute__((packed));
12912
12913 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
12914 index 9c999c1..3860cb8 100644
12915 --- a/arch/x86/include/asm/elf.h
12916 +++ b/arch/x86/include/asm/elf.h
12917 @@ -243,7 +243,25 @@ extern int force_personality32;
12918 the loader. We need to make sure that it is out of the way of the program
12919 that it will "exec", and that there is sufficient room for the brk. */
12920
12921 +#ifdef CONFIG_PAX_SEGMEXEC
12922 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
12923 +#else
12924 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
12925 +#endif
12926 +
12927 +#ifdef CONFIG_PAX_ASLR
12928 +#ifdef CONFIG_X86_32
12929 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
12930 +
12931 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12932 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12933 +#else
12934 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
12935 +
12936 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
12937 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
12938 +#endif
12939 +#endif
12940
12941 /* This yields a mask that user programs can use to figure out what
12942 instruction set this CPU supports. This could be done in user space,
12943 @@ -296,16 +314,12 @@ do { \
12944
12945 #define ARCH_DLINFO \
12946 do { \
12947 - if (vdso_enabled) \
12948 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
12949 - (unsigned long)current->mm->context.vdso); \
12950 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
12951 } while (0)
12952
12953 #define ARCH_DLINFO_X32 \
12954 do { \
12955 - if (vdso_enabled) \
12956 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
12957 - (unsigned long)current->mm->context.vdso); \
12958 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
12959 } while (0)
12960
12961 #define AT_SYSINFO 32
12962 @@ -320,7 +334,7 @@ else \
12963
12964 #endif /* !CONFIG_X86_32 */
12965
12966 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
12967 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
12968
12969 #define VDSO_ENTRY \
12970 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
12971 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
12972 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
12973 #define compat_arch_setup_additional_pages syscall32_setup_pages
12974
12975 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
12976 -#define arch_randomize_brk arch_randomize_brk
12977 -
12978 /*
12979 * True on X86_32 or when emulating IA32 on X86_64
12980 */
12981 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
12982 index 75ce3f4..882e801 100644
12983 --- a/arch/x86/include/asm/emergency-restart.h
12984 +++ b/arch/x86/include/asm/emergency-restart.h
12985 @@ -13,6 +13,6 @@ enum reboot_type {
12986
12987 extern enum reboot_type reboot_type;
12988
12989 -extern void machine_emergency_restart(void);
12990 +extern void machine_emergency_restart(void) __noreturn;
12991
12992 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
12993 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
12994 index 41ab26e..a88c9e6 100644
12995 --- a/arch/x86/include/asm/fpu-internal.h
12996 +++ b/arch/x86/include/asm/fpu-internal.h
12997 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
12998 ({ \
12999 int err; \
13000 asm volatile(ASM_STAC "\n" \
13001 - "1:" #insn "\n\t" \
13002 + "1:" \
13003 + __copyuser_seg \
13004 + #insn "\n\t" \
13005 "2: " ASM_CLAC "\n" \
13006 ".section .fixup,\"ax\"\n" \
13007 "3: movl $-1,%[err]\n" \
13008 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13009 "emms\n\t" /* clear stack tags */
13010 "fildl %P[addr]", /* set F?P to defined value */
13011 X86_FEATURE_FXSAVE_LEAK,
13012 - [addr] "m" (tsk->thread.fpu.has_fpu));
13013 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13014
13015 return fpu_restore_checking(&tsk->thread.fpu);
13016 }
13017 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13018 index be27ba1..8f13ff9 100644
13019 --- a/arch/x86/include/asm/futex.h
13020 +++ b/arch/x86/include/asm/futex.h
13021 @@ -12,6 +12,7 @@
13022 #include <asm/smap.h>
13023
13024 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13025 + typecheck(u32 __user *, uaddr); \
13026 asm volatile("\t" ASM_STAC "\n" \
13027 "1:\t" insn "\n" \
13028 "2:\t" ASM_CLAC "\n" \
13029 @@ -20,15 +21,16 @@
13030 "\tjmp\t2b\n" \
13031 "\t.previous\n" \
13032 _ASM_EXTABLE(1b, 3b) \
13033 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13034 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13035 : "i" (-EFAULT), "0" (oparg), "1" (0))
13036
13037 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13038 + typecheck(u32 __user *, uaddr); \
13039 asm volatile("\t" ASM_STAC "\n" \
13040 "1:\tmovl %2, %0\n" \
13041 "\tmovl\t%0, %3\n" \
13042 "\t" insn "\n" \
13043 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13044 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13045 "\tjnz\t1b\n" \
13046 "3:\t" ASM_CLAC "\n" \
13047 "\t.section .fixup,\"ax\"\n" \
13048 @@ -38,7 +40,7 @@
13049 _ASM_EXTABLE(1b, 4b) \
13050 _ASM_EXTABLE(2b, 4b) \
13051 : "=&a" (oldval), "=&r" (ret), \
13052 - "+m" (*uaddr), "=&r" (tem) \
13053 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13054 : "r" (oparg), "i" (-EFAULT), "1" (0))
13055
13056 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13057 @@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13058
13059 switch (op) {
13060 case FUTEX_OP_SET:
13061 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13062 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13063 break;
13064 case FUTEX_OP_ADD:
13065 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13066 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13067 uaddr, oparg);
13068 break;
13069 case FUTEX_OP_OR:
13070 @@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13071 return -EFAULT;
13072
13073 asm volatile("\t" ASM_STAC "\n"
13074 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13075 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13076 "2:\t" ASM_CLAC "\n"
13077 "\t.section .fixup, \"ax\"\n"
13078 "3:\tmov %3, %0\n"
13079 "\tjmp 2b\n"
13080 "\t.previous\n"
13081 _ASM_EXTABLE(1b, 3b)
13082 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13083 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13084 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13085 : "memory"
13086 );
13087 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13088 index eb92a6e..b98b2f4 100644
13089 --- a/arch/x86/include/asm/hw_irq.h
13090 +++ b/arch/x86/include/asm/hw_irq.h
13091 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13092 extern void enable_IO_APIC(void);
13093
13094 /* Statistics */
13095 -extern atomic_t irq_err_count;
13096 -extern atomic_t irq_mis_count;
13097 +extern atomic_unchecked_t irq_err_count;
13098 +extern atomic_unchecked_t irq_mis_count;
13099
13100 /* EISA */
13101 extern void eisa_set_level_irq(unsigned int irq);
13102 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13103 index a203659..9889f1c 100644
13104 --- a/arch/x86/include/asm/i8259.h
13105 +++ b/arch/x86/include/asm/i8259.h
13106 @@ -62,7 +62,7 @@ struct legacy_pic {
13107 void (*init)(int auto_eoi);
13108 int (*irq_pending)(unsigned int irq);
13109 void (*make_irq)(unsigned int irq);
13110 -};
13111 +} __do_const;
13112
13113 extern struct legacy_pic *legacy_pic;
13114 extern struct legacy_pic null_legacy_pic;
13115 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13116 index d8e8eef..15b1179 100644
13117 --- a/arch/x86/include/asm/io.h
13118 +++ b/arch/x86/include/asm/io.h
13119 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13120 return ioremap_nocache(offset, size);
13121 }
13122
13123 -extern void iounmap(volatile void __iomem *addr);
13124 +extern void iounmap(const volatile void __iomem *addr);
13125
13126 extern void set_iounmap_nonlazy(void);
13127
13128 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13129
13130 #include <linux/vmalloc.h>
13131
13132 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13133 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13134 +{
13135 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13136 +}
13137 +
13138 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13139 +{
13140 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13141 +}
13142 +
13143 /*
13144 * Convert a virtual cached pointer to an uncached pointer
13145 */
13146 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13147 index bba3cf8..06bc8da 100644
13148 --- a/arch/x86/include/asm/irqflags.h
13149 +++ b/arch/x86/include/asm/irqflags.h
13150 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13151 sti; \
13152 sysexit
13153
13154 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
13155 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13156 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
13157 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13158 +
13159 #else
13160 #define INTERRUPT_RETURN iret
13161 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13162 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13163 index d3ddd17..c9fb0cc 100644
13164 --- a/arch/x86/include/asm/kprobes.h
13165 +++ b/arch/x86/include/asm/kprobes.h
13166 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13167 #define RELATIVEJUMP_SIZE 5
13168 #define RELATIVECALL_OPCODE 0xe8
13169 #define RELATIVE_ADDR_SIZE 4
13170 -#define MAX_STACK_SIZE 64
13171 -#define MIN_STACK_SIZE(ADDR) \
13172 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13173 - THREAD_SIZE - (unsigned long)(ADDR))) \
13174 - ? (MAX_STACK_SIZE) \
13175 - : (((unsigned long)current_thread_info()) + \
13176 - THREAD_SIZE - (unsigned long)(ADDR)))
13177 +#define MAX_STACK_SIZE 64UL
13178 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13179
13180 #define flush_insn_slot(p) do { } while (0)
13181
13182 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13183 index 2d89e39..baee879 100644
13184 --- a/arch/x86/include/asm/local.h
13185 +++ b/arch/x86/include/asm/local.h
13186 @@ -10,33 +10,97 @@ typedef struct {
13187 atomic_long_t a;
13188 } local_t;
13189
13190 +typedef struct {
13191 + atomic_long_unchecked_t a;
13192 +} local_unchecked_t;
13193 +
13194 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13195
13196 #define local_read(l) atomic_long_read(&(l)->a)
13197 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13198 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13199 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13200
13201 static inline void local_inc(local_t *l)
13202 {
13203 - asm volatile(_ASM_INC "%0"
13204 + asm volatile(_ASM_INC "%0\n"
13205 +
13206 +#ifdef CONFIG_PAX_REFCOUNT
13207 + "jno 0f\n"
13208 + _ASM_DEC "%0\n"
13209 + "int $4\n0:\n"
13210 + _ASM_EXTABLE(0b, 0b)
13211 +#endif
13212 +
13213 + : "+m" (l->a.counter));
13214 +}
13215 +
13216 +static inline void local_inc_unchecked(local_unchecked_t *l)
13217 +{
13218 + asm volatile(_ASM_INC "%0\n"
13219 : "+m" (l->a.counter));
13220 }
13221
13222 static inline void local_dec(local_t *l)
13223 {
13224 - asm volatile(_ASM_DEC "%0"
13225 + asm volatile(_ASM_DEC "%0\n"
13226 +
13227 +#ifdef CONFIG_PAX_REFCOUNT
13228 + "jno 0f\n"
13229 + _ASM_INC "%0\n"
13230 + "int $4\n0:\n"
13231 + _ASM_EXTABLE(0b, 0b)
13232 +#endif
13233 +
13234 + : "+m" (l->a.counter));
13235 +}
13236 +
13237 +static inline void local_dec_unchecked(local_unchecked_t *l)
13238 +{
13239 + asm volatile(_ASM_DEC "%0\n"
13240 : "+m" (l->a.counter));
13241 }
13242
13243 static inline void local_add(long i, local_t *l)
13244 {
13245 - asm volatile(_ASM_ADD "%1,%0"
13246 + asm volatile(_ASM_ADD "%1,%0\n"
13247 +
13248 +#ifdef CONFIG_PAX_REFCOUNT
13249 + "jno 0f\n"
13250 + _ASM_SUB "%1,%0\n"
13251 + "int $4\n0:\n"
13252 + _ASM_EXTABLE(0b, 0b)
13253 +#endif
13254 +
13255 + : "+m" (l->a.counter)
13256 + : "ir" (i));
13257 +}
13258 +
13259 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
13260 +{
13261 + asm volatile(_ASM_ADD "%1,%0\n"
13262 : "+m" (l->a.counter)
13263 : "ir" (i));
13264 }
13265
13266 static inline void local_sub(long i, local_t *l)
13267 {
13268 - asm volatile(_ASM_SUB "%1,%0"
13269 + asm volatile(_ASM_SUB "%1,%0\n"
13270 +
13271 +#ifdef CONFIG_PAX_REFCOUNT
13272 + "jno 0f\n"
13273 + _ASM_ADD "%1,%0\n"
13274 + "int $4\n0:\n"
13275 + _ASM_EXTABLE(0b, 0b)
13276 +#endif
13277 +
13278 + : "+m" (l->a.counter)
13279 + : "ir" (i));
13280 +}
13281 +
13282 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13283 +{
13284 + asm volatile(_ASM_SUB "%1,%0\n"
13285 : "+m" (l->a.counter)
13286 : "ir" (i));
13287 }
13288 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13289 {
13290 unsigned char c;
13291
13292 - asm volatile(_ASM_SUB "%2,%0; sete %1"
13293 + asm volatile(_ASM_SUB "%2,%0\n"
13294 +
13295 +#ifdef CONFIG_PAX_REFCOUNT
13296 + "jno 0f\n"
13297 + _ASM_ADD "%2,%0\n"
13298 + "int $4\n0:\n"
13299 + _ASM_EXTABLE(0b, 0b)
13300 +#endif
13301 +
13302 + "sete %1\n"
13303 : "+m" (l->a.counter), "=qm" (c)
13304 : "ir" (i) : "memory");
13305 return c;
13306 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13307 {
13308 unsigned char c;
13309
13310 - asm volatile(_ASM_DEC "%0; sete %1"
13311 + asm volatile(_ASM_DEC "%0\n"
13312 +
13313 +#ifdef CONFIG_PAX_REFCOUNT
13314 + "jno 0f\n"
13315 + _ASM_INC "%0\n"
13316 + "int $4\n0:\n"
13317 + _ASM_EXTABLE(0b, 0b)
13318 +#endif
13319 +
13320 + "sete %1\n"
13321 : "+m" (l->a.counter), "=qm" (c)
13322 : : "memory");
13323 return c != 0;
13324 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13325 {
13326 unsigned char c;
13327
13328 - asm volatile(_ASM_INC "%0; sete %1"
13329 + asm volatile(_ASM_INC "%0\n"
13330 +
13331 +#ifdef CONFIG_PAX_REFCOUNT
13332 + "jno 0f\n"
13333 + _ASM_DEC "%0\n"
13334 + "int $4\n0:\n"
13335 + _ASM_EXTABLE(0b, 0b)
13336 +#endif
13337 +
13338 + "sete %1\n"
13339 : "+m" (l->a.counter), "=qm" (c)
13340 : : "memory");
13341 return c != 0;
13342 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13343 {
13344 unsigned char c;
13345
13346 - asm volatile(_ASM_ADD "%2,%0; sets %1"
13347 + asm volatile(_ASM_ADD "%2,%0\n"
13348 +
13349 +#ifdef CONFIG_PAX_REFCOUNT
13350 + "jno 0f\n"
13351 + _ASM_SUB "%2,%0\n"
13352 + "int $4\n0:\n"
13353 + _ASM_EXTABLE(0b, 0b)
13354 +#endif
13355 +
13356 + "sets %1\n"
13357 : "+m" (l->a.counter), "=qm" (c)
13358 : "ir" (i) : "memory");
13359 return c;
13360 @@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13361 static inline long local_add_return(long i, local_t *l)
13362 {
13363 long __i = i;
13364 + asm volatile(_ASM_XADD "%0, %1\n"
13365 +
13366 +#ifdef CONFIG_PAX_REFCOUNT
13367 + "jno 0f\n"
13368 + _ASM_MOV "%0,%1\n"
13369 + "int $4\n0:\n"
13370 + _ASM_EXTABLE(0b, 0b)
13371 +#endif
13372 +
13373 + : "+r" (i), "+m" (l->a.counter)
13374 + : : "memory");
13375 + return i + __i;
13376 +}
13377 +
13378 +/**
13379 + * local_add_return_unchecked - add and return
13380 + * @i: integer value to add
13381 + * @l: pointer to type local_unchecked_t
13382 + *
13383 + * Atomically adds @i to @l and returns @i + @l
13384 + */
13385 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13386 +{
13387 + long __i = i;
13388 asm volatile(_ASM_XADD "%0, %1;"
13389 : "+r" (i), "+m" (l->a.counter)
13390 : : "memory");
13391 @@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13392
13393 #define local_cmpxchg(l, o, n) \
13394 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13395 +#define local_cmpxchg_unchecked(l, o, n) \
13396 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
13397 /* Always has a lock prefix */
13398 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13399
13400 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13401 new file mode 100644
13402 index 0000000..2bfd3ba
13403 --- /dev/null
13404 +++ b/arch/x86/include/asm/mman.h
13405 @@ -0,0 +1,15 @@
13406 +#ifndef _X86_MMAN_H
13407 +#define _X86_MMAN_H
13408 +
13409 +#include <uapi/asm/mman.h>
13410 +
13411 +#ifdef __KERNEL__
13412 +#ifndef __ASSEMBLY__
13413 +#ifdef CONFIG_X86_32
13414 +#define arch_mmap_check i386_mmap_check
13415 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13416 +#endif
13417 +#endif
13418 +#endif
13419 +
13420 +#endif /* X86_MMAN_H */
13421 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13422 index 5f55e69..e20bfb1 100644
13423 --- a/arch/x86/include/asm/mmu.h
13424 +++ b/arch/x86/include/asm/mmu.h
13425 @@ -9,7 +9,7 @@
13426 * we put the segment information here.
13427 */
13428 typedef struct {
13429 - void *ldt;
13430 + struct desc_struct *ldt;
13431 int size;
13432
13433 #ifdef CONFIG_X86_64
13434 @@ -18,7 +18,19 @@ typedef struct {
13435 #endif
13436
13437 struct mutex lock;
13438 - void *vdso;
13439 + unsigned long vdso;
13440 +
13441 +#ifdef CONFIG_X86_32
13442 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13443 + unsigned long user_cs_base;
13444 + unsigned long user_cs_limit;
13445 +
13446 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13447 + cpumask_t cpu_user_cs_mask;
13448 +#endif
13449 +
13450 +#endif
13451 +#endif
13452 } mm_context_t;
13453
13454 #ifdef CONFIG_SMP
13455 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13456 index cdbf367..adb37ac 100644
13457 --- a/arch/x86/include/asm/mmu_context.h
13458 +++ b/arch/x86/include/asm/mmu_context.h
13459 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13460
13461 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13462 {
13463 +
13464 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13465 + unsigned int i;
13466 + pgd_t *pgd;
13467 +
13468 + pax_open_kernel();
13469 + pgd = get_cpu_pgd(smp_processor_id());
13470 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13471 + set_pgd_batched(pgd+i, native_make_pgd(0));
13472 + pax_close_kernel();
13473 +#endif
13474 +
13475 #ifdef CONFIG_SMP
13476 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13477 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13478 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13479 struct task_struct *tsk)
13480 {
13481 unsigned cpu = smp_processor_id();
13482 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13483 + int tlbstate = TLBSTATE_OK;
13484 +#endif
13485
13486 if (likely(prev != next)) {
13487 #ifdef CONFIG_SMP
13488 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13489 + tlbstate = this_cpu_read(cpu_tlbstate.state);
13490 +#endif
13491 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13492 this_cpu_write(cpu_tlbstate.active_mm, next);
13493 #endif
13494 cpumask_set_cpu(cpu, mm_cpumask(next));
13495
13496 /* Re-load page tables */
13497 +#ifdef CONFIG_PAX_PER_CPU_PGD
13498 + pax_open_kernel();
13499 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13500 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13501 + pax_close_kernel();
13502 + load_cr3(get_cpu_pgd(cpu));
13503 +#else
13504 load_cr3(next->pgd);
13505 +#endif
13506
13507 /* stop flush ipis for the previous mm */
13508 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13509 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13510 */
13511 if (unlikely(prev->context.ldt != next->context.ldt))
13512 load_LDT_nolock(&next->context);
13513 - }
13514 +
13515 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13516 + if (!(__supported_pte_mask & _PAGE_NX)) {
13517 + smp_mb__before_clear_bit();
13518 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13519 + smp_mb__after_clear_bit();
13520 + cpu_set(cpu, next->context.cpu_user_cs_mask);
13521 + }
13522 +#endif
13523 +
13524 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13525 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13526 + prev->context.user_cs_limit != next->context.user_cs_limit))
13527 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13528 #ifdef CONFIG_SMP
13529 + else if (unlikely(tlbstate != TLBSTATE_OK))
13530 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13531 +#endif
13532 +#endif
13533 +
13534 + }
13535 else {
13536 +
13537 +#ifdef CONFIG_PAX_PER_CPU_PGD
13538 + pax_open_kernel();
13539 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13540 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13541 + pax_close_kernel();
13542 + load_cr3(get_cpu_pgd(cpu));
13543 +#endif
13544 +
13545 +#ifdef CONFIG_SMP
13546 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13547 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13548
13549 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13550 * tlb flush IPI delivery. We must reload CR3
13551 * to make sure to use no freed page tables.
13552 */
13553 +
13554 +#ifndef CONFIG_PAX_PER_CPU_PGD
13555 load_cr3(next->pgd);
13556 +#endif
13557 +
13558 load_LDT_nolock(&next->context);
13559 +
13560 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13561 + if (!(__supported_pte_mask & _PAGE_NX))
13562 + cpu_set(cpu, next->context.cpu_user_cs_mask);
13563 +#endif
13564 +
13565 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13566 +#ifdef CONFIG_PAX_PAGEEXEC
13567 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
13568 +#endif
13569 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13570 +#endif
13571 +
13572 }
13573 +#endif
13574 }
13575 -#endif
13576 }
13577
13578 #define activate_mm(prev, next) \
13579 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
13580 index e3b7819..b257c64 100644
13581 --- a/arch/x86/include/asm/module.h
13582 +++ b/arch/x86/include/asm/module.h
13583 @@ -5,6 +5,7 @@
13584
13585 #ifdef CONFIG_X86_64
13586 /* X86_64 does not define MODULE_PROC_FAMILY */
13587 +#define MODULE_PROC_FAMILY ""
13588 #elif defined CONFIG_M486
13589 #define MODULE_PROC_FAMILY "486 "
13590 #elif defined CONFIG_M586
13591 @@ -57,8 +58,20 @@
13592 #error unknown processor family
13593 #endif
13594
13595 -#ifdef CONFIG_X86_32
13596 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
13597 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13598 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
13599 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
13600 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
13601 +#else
13602 +#define MODULE_PAX_KERNEXEC ""
13603 #endif
13604
13605 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13606 +#define MODULE_PAX_UDEREF "UDEREF "
13607 +#else
13608 +#define MODULE_PAX_UDEREF ""
13609 +#endif
13610 +
13611 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
13612 +
13613 #endif /* _ASM_X86_MODULE_H */
13614 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
13615 index c0fa356..eecfb9f 100644
13616 --- a/arch/x86/include/asm/nmi.h
13617 +++ b/arch/x86/include/asm/nmi.h
13618 @@ -42,11 +42,11 @@ struct nmiaction {
13619 nmi_handler_t handler;
13620 unsigned long flags;
13621 const char *name;
13622 -};
13623 +} __do_const;
13624
13625 #define register_nmi_handler(t, fn, fg, n, init...) \
13626 ({ \
13627 - static struct nmiaction init fn##_na = { \
13628 + static const struct nmiaction init fn##_na = { \
13629 .handler = (fn), \
13630 .name = (n), \
13631 .flags = (fg), \
13632 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
13633 index 320f7bb..e89f8f8 100644
13634 --- a/arch/x86/include/asm/page_64_types.h
13635 +++ b/arch/x86/include/asm/page_64_types.h
13636 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
13637
13638 /* duplicated to the one in bootmem.h */
13639 extern unsigned long max_pfn;
13640 -extern unsigned long phys_base;
13641 +extern const unsigned long phys_base;
13642
13643 extern unsigned long __phys_addr(unsigned long);
13644 #define __phys_reloc_hide(x) (x)
13645 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
13646 index 5edd174..9cf5821 100644
13647 --- a/arch/x86/include/asm/paravirt.h
13648 +++ b/arch/x86/include/asm/paravirt.h
13649 @@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
13650 val);
13651 }
13652
13653 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
13654 +{
13655 + pgdval_t val = native_pgd_val(pgd);
13656 +
13657 + if (sizeof(pgdval_t) > sizeof(long))
13658 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
13659 + val, (u64)val >> 32);
13660 + else
13661 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
13662 + val);
13663 +}
13664 +
13665 static inline void pgd_clear(pgd_t *pgdp)
13666 {
13667 set_pgd(pgdp, __pgd(0));
13668 @@ -711,6 +723,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
13669 pv_mmu_ops.set_fixmap(idx, phys, flags);
13670 }
13671
13672 +#ifdef CONFIG_PAX_KERNEXEC
13673 +static inline unsigned long pax_open_kernel(void)
13674 +{
13675 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
13676 +}
13677 +
13678 +static inline unsigned long pax_close_kernel(void)
13679 +{
13680 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
13681 +}
13682 +#else
13683 +static inline unsigned long pax_open_kernel(void) { return 0; }
13684 +static inline unsigned long pax_close_kernel(void) { return 0; }
13685 +#endif
13686 +
13687 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
13688
13689 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
13690 @@ -927,7 +954,7 @@ extern void default_banner(void);
13691
13692 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
13693 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
13694 -#define PARA_INDIRECT(addr) *%cs:addr
13695 +#define PARA_INDIRECT(addr) *%ss:addr
13696 #endif
13697
13698 #define INTERRUPT_RETURN \
13699 @@ -1002,6 +1029,21 @@ extern void default_banner(void);
13700 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
13701 CLBR_NONE, \
13702 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
13703 +
13704 +#define GET_CR0_INTO_RDI \
13705 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
13706 + mov %rax,%rdi
13707 +
13708 +#define SET_RDI_INTO_CR0 \
13709 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13710 +
13711 +#define GET_CR3_INTO_RDI \
13712 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
13713 + mov %rax,%rdi
13714 +
13715 +#define SET_RDI_INTO_CR3 \
13716 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
13717 +
13718 #endif /* CONFIG_X86_32 */
13719
13720 #endif /* __ASSEMBLY__ */
13721 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
13722 index 142236e..5446ffbc 100644
13723 --- a/arch/x86/include/asm/paravirt_types.h
13724 +++ b/arch/x86/include/asm/paravirt_types.h
13725 @@ -84,7 +84,7 @@ struct pv_init_ops {
13726 */
13727 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
13728 unsigned long addr, unsigned len);
13729 -};
13730 +} __no_const;
13731
13732
13733 struct pv_lazy_ops {
13734 @@ -97,7 +97,7 @@ struct pv_time_ops {
13735 unsigned long long (*sched_clock)(void);
13736 unsigned long long (*steal_clock)(int cpu);
13737 unsigned long (*get_tsc_khz)(void);
13738 -};
13739 +} __no_const;
13740
13741 struct pv_cpu_ops {
13742 /* hooks for various privileged instructions */
13743 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
13744
13745 void (*start_context_switch)(struct task_struct *prev);
13746 void (*end_context_switch)(struct task_struct *next);
13747 -};
13748 +} __no_const;
13749
13750 struct pv_irq_ops {
13751 /*
13752 @@ -222,7 +222,7 @@ struct pv_apic_ops {
13753 unsigned long start_eip,
13754 unsigned long start_esp);
13755 #endif
13756 -};
13757 +} __no_const;
13758
13759 struct pv_mmu_ops {
13760 unsigned long (*read_cr2)(void);
13761 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
13762 struct paravirt_callee_save make_pud;
13763
13764 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
13765 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
13766 #endif /* PAGETABLE_LEVELS == 4 */
13767 #endif /* PAGETABLE_LEVELS >= 3 */
13768
13769 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
13770 an mfn. We can tell which is which from the index. */
13771 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
13772 phys_addr_t phys, pgprot_t flags);
13773 +
13774 +#ifdef CONFIG_PAX_KERNEXEC
13775 + unsigned long (*pax_open_kernel)(void);
13776 + unsigned long (*pax_close_kernel)(void);
13777 +#endif
13778 +
13779 };
13780
13781 struct arch_spinlock;
13782 @@ -333,7 +340,7 @@ struct pv_lock_ops {
13783 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
13784 int (*spin_trylock)(struct arch_spinlock *lock);
13785 void (*spin_unlock)(struct arch_spinlock *lock);
13786 -};
13787 +} __no_const;
13788
13789 /* This contains all the paravirt structures: we get a convenient
13790 * number for each function using the offset which we use to indicate
13791 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
13792 index b4389a4..7024269 100644
13793 --- a/arch/x86/include/asm/pgalloc.h
13794 +++ b/arch/x86/include/asm/pgalloc.h
13795 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
13796 pmd_t *pmd, pte_t *pte)
13797 {
13798 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13799 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
13800 +}
13801 +
13802 +static inline void pmd_populate_user(struct mm_struct *mm,
13803 + pmd_t *pmd, pte_t *pte)
13804 +{
13805 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13806 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
13807 }
13808
13809 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
13810
13811 #ifdef CONFIG_X86_PAE
13812 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
13813 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
13814 +{
13815 + pud_populate(mm, pudp, pmd);
13816 +}
13817 #else /* !CONFIG_X86_PAE */
13818 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13819 {
13820 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13821 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
13822 }
13823 +
13824 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13825 +{
13826 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13827 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
13828 +}
13829 #endif /* CONFIG_X86_PAE */
13830
13831 #if PAGETABLE_LEVELS > 3
13832 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13833 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
13834 }
13835
13836 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13837 +{
13838 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
13839 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
13840 +}
13841 +
13842 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
13843 {
13844 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
13845 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
13846 index f2b489c..4f7e2e5 100644
13847 --- a/arch/x86/include/asm/pgtable-2level.h
13848 +++ b/arch/x86/include/asm/pgtable-2level.h
13849 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
13850
13851 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13852 {
13853 + pax_open_kernel();
13854 *pmdp = pmd;
13855 + pax_close_kernel();
13856 }
13857
13858 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13859 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
13860 index 4cc9f2b..5fd9226 100644
13861 --- a/arch/x86/include/asm/pgtable-3level.h
13862 +++ b/arch/x86/include/asm/pgtable-3level.h
13863 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13864
13865 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13866 {
13867 + pax_open_kernel();
13868 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
13869 + pax_close_kernel();
13870 }
13871
13872 static inline void native_set_pud(pud_t *pudp, pud_t pud)
13873 {
13874 + pax_open_kernel();
13875 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
13876 + pax_close_kernel();
13877 }
13878
13879 /*
13880 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
13881 index 1c1a955..50f828c 100644
13882 --- a/arch/x86/include/asm/pgtable.h
13883 +++ b/arch/x86/include/asm/pgtable.h
13884 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13885
13886 #ifndef __PAGETABLE_PUD_FOLDED
13887 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
13888 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
13889 #define pgd_clear(pgd) native_pgd_clear(pgd)
13890 #endif
13891
13892 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13893
13894 #define arch_end_context_switch(prev) do {} while(0)
13895
13896 +#define pax_open_kernel() native_pax_open_kernel()
13897 +#define pax_close_kernel() native_pax_close_kernel()
13898 #endif /* CONFIG_PARAVIRT */
13899
13900 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
13901 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
13902 +
13903 +#ifdef CONFIG_PAX_KERNEXEC
13904 +static inline unsigned long native_pax_open_kernel(void)
13905 +{
13906 + unsigned long cr0;
13907 +
13908 + preempt_disable();
13909 + barrier();
13910 + cr0 = read_cr0() ^ X86_CR0_WP;
13911 + BUG_ON(cr0 & X86_CR0_WP);
13912 + write_cr0(cr0);
13913 + return cr0 ^ X86_CR0_WP;
13914 +}
13915 +
13916 +static inline unsigned long native_pax_close_kernel(void)
13917 +{
13918 + unsigned long cr0;
13919 +
13920 + cr0 = read_cr0() ^ X86_CR0_WP;
13921 + BUG_ON(!(cr0 & X86_CR0_WP));
13922 + write_cr0(cr0);
13923 + barrier();
13924 + preempt_enable_no_resched();
13925 + return cr0 ^ X86_CR0_WP;
13926 +}
13927 +#else
13928 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
13929 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
13930 +#endif
13931 +
13932 /*
13933 * The following only work if pte_present() is true.
13934 * Undefined behaviour if not..
13935 */
13936 +static inline int pte_user(pte_t pte)
13937 +{
13938 + return pte_val(pte) & _PAGE_USER;
13939 +}
13940 +
13941 static inline int pte_dirty(pte_t pte)
13942 {
13943 return pte_flags(pte) & _PAGE_DIRTY;
13944 @@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
13945 return pte_clear_flags(pte, _PAGE_RW);
13946 }
13947
13948 +static inline pte_t pte_mkread(pte_t pte)
13949 +{
13950 + return __pte(pte_val(pte) | _PAGE_USER);
13951 +}
13952 +
13953 static inline pte_t pte_mkexec(pte_t pte)
13954 {
13955 - return pte_clear_flags(pte, _PAGE_NX);
13956 +#ifdef CONFIG_X86_PAE
13957 + if (__supported_pte_mask & _PAGE_NX)
13958 + return pte_clear_flags(pte, _PAGE_NX);
13959 + else
13960 +#endif
13961 + return pte_set_flags(pte, _PAGE_USER);
13962 +}
13963 +
13964 +static inline pte_t pte_exprotect(pte_t pte)
13965 +{
13966 +#ifdef CONFIG_X86_PAE
13967 + if (__supported_pte_mask & _PAGE_NX)
13968 + return pte_set_flags(pte, _PAGE_NX);
13969 + else
13970 +#endif
13971 + return pte_clear_flags(pte, _PAGE_USER);
13972 }
13973
13974 static inline pte_t pte_mkdirty(pte_t pte)
13975 @@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
13976 #endif
13977
13978 #ifndef __ASSEMBLY__
13979 +
13980 +#ifdef CONFIG_PAX_PER_CPU_PGD
13981 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
13982 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
13983 +{
13984 + return cpu_pgd[cpu];
13985 +}
13986 +#endif
13987 +
13988 #include <linux/mm_types.h>
13989
13990 static inline int pte_none(pte_t pte)
13991 @@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
13992
13993 static inline int pgd_bad(pgd_t pgd)
13994 {
13995 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
13996 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
13997 }
13998
13999 static inline int pgd_none(pgd_t pgd)
14000 @@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
14001 * pgd_offset() returns a (pgd_t *)
14002 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14003 */
14004 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14005 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14006 +
14007 +#ifdef CONFIG_PAX_PER_CPU_PGD
14008 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14009 +#endif
14010 +
14011 /*
14012 * a shortcut which implies the use of the kernel's pgd, instead
14013 * of a process's
14014 @@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
14015 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14016 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14017
14018 +#ifdef CONFIG_X86_32
14019 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14020 +#else
14021 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14022 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14023 +
14024 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14025 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
14026 +#else
14027 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
14028 +#endif
14029 +
14030 +#endif
14031 +
14032 #ifndef __ASSEMBLY__
14033
14034 extern int direct_gbpages;
14035 @@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14036 * dst and src can be on the same page, but the range must not overlap,
14037 * and must not cross a page boundary.
14038 */
14039 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14040 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14041 {
14042 - memcpy(dst, src, count * sizeof(pgd_t));
14043 + pax_open_kernel();
14044 + while (count--)
14045 + *dst++ = *src++;
14046 + pax_close_kernel();
14047 }
14048
14049 +#ifdef CONFIG_PAX_PER_CPU_PGD
14050 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14051 +#endif
14052 +
14053 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14054 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14055 +#else
14056 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14057 +#endif
14058
14059 #include <asm-generic/pgtable.h>
14060 #endif /* __ASSEMBLY__ */
14061 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14062 index 8faa215..a8a17ea 100644
14063 --- a/arch/x86/include/asm/pgtable_32.h
14064 +++ b/arch/x86/include/asm/pgtable_32.h
14065 @@ -25,9 +25,6 @@
14066 struct mm_struct;
14067 struct vm_area_struct;
14068
14069 -extern pgd_t swapper_pg_dir[1024];
14070 -extern pgd_t initial_page_table[1024];
14071 -
14072 static inline void pgtable_cache_init(void) { }
14073 static inline void check_pgt_cache(void) { }
14074 void paging_init(void);
14075 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14076 # include <asm/pgtable-2level.h>
14077 #endif
14078
14079 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14080 +extern pgd_t initial_page_table[PTRS_PER_PGD];
14081 +#ifdef CONFIG_X86_PAE
14082 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14083 +#endif
14084 +
14085 #if defined(CONFIG_HIGHPTE)
14086 #define pte_offset_map(dir, address) \
14087 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14088 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14089 /* Clear a kernel PTE and flush it from the TLB */
14090 #define kpte_clear_flush(ptep, vaddr) \
14091 do { \
14092 + pax_open_kernel(); \
14093 pte_clear(&init_mm, (vaddr), (ptep)); \
14094 + pax_close_kernel(); \
14095 __flush_tlb_one((vaddr)); \
14096 } while (0)
14097
14098 @@ -75,6 +80,9 @@ do { \
14099
14100 #endif /* !__ASSEMBLY__ */
14101
14102 +#define HAVE_ARCH_UNMAPPED_AREA
14103 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14104 +
14105 /*
14106 * kern_addr_valid() is (1) for FLATMEM and (0) for
14107 * SPARSEMEM and DISCONTIGMEM
14108 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14109 index ed5903b..c7fe163 100644
14110 --- a/arch/x86/include/asm/pgtable_32_types.h
14111 +++ b/arch/x86/include/asm/pgtable_32_types.h
14112 @@ -8,7 +8,7 @@
14113 */
14114 #ifdef CONFIG_X86_PAE
14115 # include <asm/pgtable-3level_types.h>
14116 -# define PMD_SIZE (1UL << PMD_SHIFT)
14117 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14118 # define PMD_MASK (~(PMD_SIZE - 1))
14119 #else
14120 # include <asm/pgtable-2level_types.h>
14121 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14122 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14123 #endif
14124
14125 +#ifdef CONFIG_PAX_KERNEXEC
14126 +#ifndef __ASSEMBLY__
14127 +extern unsigned char MODULES_EXEC_VADDR[];
14128 +extern unsigned char MODULES_EXEC_END[];
14129 +#endif
14130 +#include <asm/boot.h>
14131 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14132 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14133 +#else
14134 +#define ktla_ktva(addr) (addr)
14135 +#define ktva_ktla(addr) (addr)
14136 +#endif
14137 +
14138 #define MODULES_VADDR VMALLOC_START
14139 #define MODULES_END VMALLOC_END
14140 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14141 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14142 index 47356f9..deb94a2 100644
14143 --- a/arch/x86/include/asm/pgtable_64.h
14144 +++ b/arch/x86/include/asm/pgtable_64.h
14145 @@ -16,10 +16,14 @@
14146
14147 extern pud_t level3_kernel_pgt[512];
14148 extern pud_t level3_ident_pgt[512];
14149 +extern pud_t level3_vmalloc_start_pgt[512];
14150 +extern pud_t level3_vmalloc_end_pgt[512];
14151 +extern pud_t level3_vmemmap_pgt[512];
14152 +extern pud_t level2_vmemmap_pgt[512];
14153 extern pmd_t level2_kernel_pgt[512];
14154 extern pmd_t level2_fixmap_pgt[512];
14155 -extern pmd_t level2_ident_pgt[512];
14156 -extern pgd_t init_level4_pgt[];
14157 +extern pmd_t level2_ident_pgt[512*2];
14158 +extern pgd_t init_level4_pgt[512];
14159
14160 #define swapper_pg_dir init_level4_pgt
14161
14162 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14163
14164 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14165 {
14166 + pax_open_kernel();
14167 *pmdp = pmd;
14168 + pax_close_kernel();
14169 }
14170
14171 static inline void native_pmd_clear(pmd_t *pmd)
14172 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14173
14174 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14175 {
14176 + pax_open_kernel();
14177 *pudp = pud;
14178 + pax_close_kernel();
14179 }
14180
14181 static inline void native_pud_clear(pud_t *pud)
14182 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14183
14184 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14185 {
14186 + pax_open_kernel();
14187 + *pgdp = pgd;
14188 + pax_close_kernel();
14189 +}
14190 +
14191 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14192 +{
14193 *pgdp = pgd;
14194 }
14195
14196 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14197 index 766ea16..5b96cb3 100644
14198 --- a/arch/x86/include/asm/pgtable_64_types.h
14199 +++ b/arch/x86/include/asm/pgtable_64_types.h
14200 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14201 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14202 #define MODULES_END _AC(0xffffffffff000000, UL)
14203 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14204 +#define MODULES_EXEC_VADDR MODULES_VADDR
14205 +#define MODULES_EXEC_END MODULES_END
14206 +
14207 +#define ktla_ktva(addr) (addr)
14208 +#define ktva_ktla(addr) (addr)
14209
14210 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14211 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14212 index 3c32db8..1ddccf5 100644
14213 --- a/arch/x86/include/asm/pgtable_types.h
14214 +++ b/arch/x86/include/asm/pgtable_types.h
14215 @@ -16,13 +16,12 @@
14216 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14217 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14218 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14219 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14220 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14221 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14222 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14223 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14224 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14225 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14226 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14227 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14228 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14229 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14230
14231 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14232 @@ -40,7 +39,6 @@
14233 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14234 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14235 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14236 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14237 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14238 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14239 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14240 @@ -57,8 +55,10 @@
14241
14242 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14243 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14244 -#else
14245 +#elif defined(CONFIG_KMEMCHECK)
14246 #define _PAGE_NX (_AT(pteval_t, 0))
14247 +#else
14248 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14249 #endif
14250
14251 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14252 @@ -116,6 +116,9 @@
14253 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14254 _PAGE_ACCESSED)
14255
14256 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
14257 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
14258 +
14259 #define __PAGE_KERNEL_EXEC \
14260 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14261 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14262 @@ -126,7 +129,7 @@
14263 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14264 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14265 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14266 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14267 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14268 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14269 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14270 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14271 @@ -188,8 +191,8 @@
14272 * bits are combined, this will alow user to access the high address mapped
14273 * VDSO in the presence of CONFIG_COMPAT_VDSO
14274 */
14275 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14276 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14277 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14278 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14279 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14280 #endif
14281
14282 @@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14283 {
14284 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14285 }
14286 +#endif
14287
14288 +#if PAGETABLE_LEVELS == 3
14289 +#include <asm-generic/pgtable-nopud.h>
14290 +#endif
14291 +
14292 +#if PAGETABLE_LEVELS == 2
14293 +#include <asm-generic/pgtable-nopmd.h>
14294 +#endif
14295 +
14296 +#ifndef __ASSEMBLY__
14297 #if PAGETABLE_LEVELS > 3
14298 typedef struct { pudval_t pud; } pud_t;
14299
14300 @@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14301 return pud.pud;
14302 }
14303 #else
14304 -#include <asm-generic/pgtable-nopud.h>
14305 -
14306 static inline pudval_t native_pud_val(pud_t pud)
14307 {
14308 return native_pgd_val(pud.pgd);
14309 @@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14310 return pmd.pmd;
14311 }
14312 #else
14313 -#include <asm-generic/pgtable-nopmd.h>
14314 -
14315 static inline pmdval_t native_pmd_val(pmd_t pmd)
14316 {
14317 return native_pgd_val(pmd.pud.pgd);
14318 @@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14319
14320 extern pteval_t __supported_pte_mask;
14321 extern void set_nx(void);
14322 -extern int nx_enabled;
14323
14324 #define pgprot_writecombine pgprot_writecombine
14325 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14326 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14327 index 888184b..a07ac89 100644
14328 --- a/arch/x86/include/asm/processor.h
14329 +++ b/arch/x86/include/asm/processor.h
14330 @@ -287,7 +287,7 @@ struct tss_struct {
14331
14332 } ____cacheline_aligned;
14333
14334 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14335 +extern struct tss_struct init_tss[NR_CPUS];
14336
14337 /*
14338 * Save the original ist values for checking stack pointers during debugging
14339 @@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
14340 */
14341 #define TASK_SIZE PAGE_OFFSET
14342 #define TASK_SIZE_MAX TASK_SIZE
14343 +
14344 +#ifdef CONFIG_PAX_SEGMEXEC
14345 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14346 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14347 +#else
14348 #define STACK_TOP TASK_SIZE
14349 -#define STACK_TOP_MAX STACK_TOP
14350 +#endif
14351 +
14352 +#define STACK_TOP_MAX TASK_SIZE
14353
14354 #define INIT_THREAD { \
14355 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
14356 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14357 .vm86_info = NULL, \
14358 .sysenter_cs = __KERNEL_CS, \
14359 .io_bitmap_ptr = NULL, \
14360 @@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
14361 */
14362 #define INIT_TSS { \
14363 .x86_tss = { \
14364 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
14365 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14366 .ss0 = __KERNEL_DS, \
14367 .ss1 = __KERNEL_CS, \
14368 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14369 @@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
14370 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14371
14372 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14373 -#define KSTK_TOP(info) \
14374 -({ \
14375 - unsigned long *__ptr = (unsigned long *)(info); \
14376 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14377 -})
14378 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14379
14380 /*
14381 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14382 @@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14383 #define task_pt_regs(task) \
14384 ({ \
14385 struct pt_regs *__regs__; \
14386 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14387 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14388 __regs__ - 1; \
14389 })
14390
14391 @@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14392 /*
14393 * User space process size. 47bits minus one guard page.
14394 */
14395 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14396 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14397
14398 /* This decides where the kernel will search for a free chunk of vm
14399 * space during mmap's.
14400 */
14401 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14402 - 0xc0000000 : 0xFFFFe000)
14403 + 0xc0000000 : 0xFFFFf000)
14404
14405 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14406 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14407 @@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14408 #define STACK_TOP_MAX TASK_SIZE_MAX
14409
14410 #define INIT_THREAD { \
14411 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14412 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14413 }
14414
14415 #define INIT_TSS { \
14416 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14417 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14418 }
14419
14420 /*
14421 @@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14422 */
14423 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14424
14425 +#ifdef CONFIG_PAX_SEGMEXEC
14426 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14427 +#endif
14428 +
14429 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14430
14431 /* Get/set a process' ability to use the timestamp counter instruction */
14432 @@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
14433 #define cpu_has_amd_erratum(x) (false)
14434 #endif /* CONFIG_CPU_SUP_AMD */
14435
14436 -extern unsigned long arch_align_stack(unsigned long sp);
14437 +#define arch_align_stack(x) ((x) & ~0xfUL)
14438 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14439
14440 void default_idle(void);
14441 bool set_pm_idle_to_default(void);
14442
14443 -void stop_this_cpu(void *dummy);
14444 +void stop_this_cpu(void *dummy) __noreturn;
14445
14446 #endif /* _ASM_X86_PROCESSOR_H */
14447 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14448 index 942a086..6c26446 100644
14449 --- a/arch/x86/include/asm/ptrace.h
14450 +++ b/arch/x86/include/asm/ptrace.h
14451 @@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14452 }
14453
14454 /*
14455 - * user_mode_vm(regs) determines whether a register set came from user mode.
14456 + * user_mode(regs) determines whether a register set came from user mode.
14457 * This is true if V8086 mode was enabled OR if the register set was from
14458 * protected mode with RPL-3 CS value. This tricky test checks that with
14459 * one comparison. Many places in the kernel can bypass this full check
14460 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14461 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14462 + * be used.
14463 */
14464 -static inline int user_mode(struct pt_regs *regs)
14465 +static inline int user_mode_novm(struct pt_regs *regs)
14466 {
14467 #ifdef CONFIG_X86_32
14468 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14469 #else
14470 - return !!(regs->cs & 3);
14471 + return !!(regs->cs & SEGMENT_RPL_MASK);
14472 #endif
14473 }
14474
14475 -static inline int user_mode_vm(struct pt_regs *regs)
14476 +static inline int user_mode(struct pt_regs *regs)
14477 {
14478 #ifdef CONFIG_X86_32
14479 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14480 USER_RPL;
14481 #else
14482 - return user_mode(regs);
14483 + return user_mode_novm(regs);
14484 #endif
14485 }
14486
14487 @@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14488 #ifdef CONFIG_X86_64
14489 static inline bool user_64bit_mode(struct pt_regs *regs)
14490 {
14491 + unsigned long cs = regs->cs & 0xffff;
14492 #ifndef CONFIG_PARAVIRT
14493 /*
14494 * On non-paravirt systems, this is the only long mode CPL 3
14495 * selector. We do not allow long mode selectors in the LDT.
14496 */
14497 - return regs->cs == __USER_CS;
14498 + return cs == __USER_CS;
14499 #else
14500 /* Headers are too twisted for this to go in paravirt.h. */
14501 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14502 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14503 #endif
14504 }
14505
14506 @@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14507 * Traps from the kernel do not save sp and ss.
14508 * Use the helper function to retrieve sp.
14509 */
14510 - if (offset == offsetof(struct pt_regs, sp) &&
14511 - regs->cs == __KERNEL_CS)
14512 - return kernel_stack_pointer(regs);
14513 + if (offset == offsetof(struct pt_regs, sp)) {
14514 + unsigned long cs = regs->cs & 0xffff;
14515 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
14516 + return kernel_stack_pointer(regs);
14517 + }
14518 #endif
14519 return *(unsigned long *)((unsigned long)regs + offset);
14520 }
14521 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
14522 index fe1ec5b..dc5c3fe 100644
14523 --- a/arch/x86/include/asm/realmode.h
14524 +++ b/arch/x86/include/asm/realmode.h
14525 @@ -22,16 +22,14 @@ struct real_mode_header {
14526 #endif
14527 /* APM/BIOS reboot */
14528 u32 machine_real_restart_asm;
14529 -#ifdef CONFIG_X86_64
14530 u32 machine_real_restart_seg;
14531 -#endif
14532 };
14533
14534 /* This must match data at trampoline_32/64.S */
14535 struct trampoline_header {
14536 #ifdef CONFIG_X86_32
14537 u32 start;
14538 - u16 gdt_pad;
14539 + u16 boot_cs;
14540 u16 gdt_limit;
14541 u32 gdt_base;
14542 #else
14543 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
14544 index a82c4f1..ac45053 100644
14545 --- a/arch/x86/include/asm/reboot.h
14546 +++ b/arch/x86/include/asm/reboot.h
14547 @@ -6,13 +6,13 @@
14548 struct pt_regs;
14549
14550 struct machine_ops {
14551 - void (*restart)(char *cmd);
14552 - void (*halt)(void);
14553 - void (*power_off)(void);
14554 + void (* __noreturn restart)(char *cmd);
14555 + void (* __noreturn halt)(void);
14556 + void (* __noreturn power_off)(void);
14557 void (*shutdown)(void);
14558 void (*crash_shutdown)(struct pt_regs *);
14559 - void (*emergency_restart)(void);
14560 -};
14561 + void (* __noreturn emergency_restart)(void);
14562 +} __no_const;
14563
14564 extern struct machine_ops machine_ops;
14565
14566 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
14567 index 2dbe4a7..ce1db00 100644
14568 --- a/arch/x86/include/asm/rwsem.h
14569 +++ b/arch/x86/include/asm/rwsem.h
14570 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
14571 {
14572 asm volatile("# beginning down_read\n\t"
14573 LOCK_PREFIX _ASM_INC "(%1)\n\t"
14574 +
14575 +#ifdef CONFIG_PAX_REFCOUNT
14576 + "jno 0f\n"
14577 + LOCK_PREFIX _ASM_DEC "(%1)\n"
14578 + "int $4\n0:\n"
14579 + _ASM_EXTABLE(0b, 0b)
14580 +#endif
14581 +
14582 /* adds 0x00000001 */
14583 " jns 1f\n"
14584 " call call_rwsem_down_read_failed\n"
14585 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
14586 "1:\n\t"
14587 " mov %1,%2\n\t"
14588 " add %3,%2\n\t"
14589 +
14590 +#ifdef CONFIG_PAX_REFCOUNT
14591 + "jno 0f\n"
14592 + "sub %3,%2\n"
14593 + "int $4\n0:\n"
14594 + _ASM_EXTABLE(0b, 0b)
14595 +#endif
14596 +
14597 " jle 2f\n\t"
14598 LOCK_PREFIX " cmpxchg %2,%0\n\t"
14599 " jnz 1b\n\t"
14600 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
14601 long tmp;
14602 asm volatile("# beginning down_write\n\t"
14603 LOCK_PREFIX " xadd %1,(%2)\n\t"
14604 +
14605 +#ifdef CONFIG_PAX_REFCOUNT
14606 + "jno 0f\n"
14607 + "mov %1,(%2)\n"
14608 + "int $4\n0:\n"
14609 + _ASM_EXTABLE(0b, 0b)
14610 +#endif
14611 +
14612 /* adds 0xffff0001, returns the old value */
14613 " test %1,%1\n\t"
14614 /* was the count 0 before? */
14615 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
14616 long tmp;
14617 asm volatile("# beginning __up_read\n\t"
14618 LOCK_PREFIX " xadd %1,(%2)\n\t"
14619 +
14620 +#ifdef CONFIG_PAX_REFCOUNT
14621 + "jno 0f\n"
14622 + "mov %1,(%2)\n"
14623 + "int $4\n0:\n"
14624 + _ASM_EXTABLE(0b, 0b)
14625 +#endif
14626 +
14627 /* subtracts 1, returns the old value */
14628 " jns 1f\n\t"
14629 " call call_rwsem_wake\n" /* expects old value in %edx */
14630 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
14631 long tmp;
14632 asm volatile("# beginning __up_write\n\t"
14633 LOCK_PREFIX " xadd %1,(%2)\n\t"
14634 +
14635 +#ifdef CONFIG_PAX_REFCOUNT
14636 + "jno 0f\n"
14637 + "mov %1,(%2)\n"
14638 + "int $4\n0:\n"
14639 + _ASM_EXTABLE(0b, 0b)
14640 +#endif
14641 +
14642 /* subtracts 0xffff0001, returns the old value */
14643 " jns 1f\n\t"
14644 " call call_rwsem_wake\n" /* expects old value in %edx */
14645 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14646 {
14647 asm volatile("# beginning __downgrade_write\n\t"
14648 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
14649 +
14650 +#ifdef CONFIG_PAX_REFCOUNT
14651 + "jno 0f\n"
14652 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
14653 + "int $4\n0:\n"
14654 + _ASM_EXTABLE(0b, 0b)
14655 +#endif
14656 +
14657 /*
14658 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
14659 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
14660 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14661 */
14662 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14663 {
14664 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
14665 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
14666 +
14667 +#ifdef CONFIG_PAX_REFCOUNT
14668 + "jno 0f\n"
14669 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
14670 + "int $4\n0:\n"
14671 + _ASM_EXTABLE(0b, 0b)
14672 +#endif
14673 +
14674 : "+m" (sem->count)
14675 : "er" (delta));
14676 }
14677 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14678 */
14679 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
14680 {
14681 - return delta + xadd(&sem->count, delta);
14682 + return delta + xadd_check_overflow(&sem->count, delta);
14683 }
14684
14685 #endif /* __KERNEL__ */
14686 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
14687 index c48a950..c6d7468 100644
14688 --- a/arch/x86/include/asm/segment.h
14689 +++ b/arch/x86/include/asm/segment.h
14690 @@ -64,10 +64,15 @@
14691 * 26 - ESPFIX small SS
14692 * 27 - per-cpu [ offset to per-cpu data area ]
14693 * 28 - stack_canary-20 [ for stack protector ]
14694 - * 29 - unused
14695 - * 30 - unused
14696 + * 29 - PCI BIOS CS
14697 + * 30 - PCI BIOS DS
14698 * 31 - TSS for double fault handler
14699 */
14700 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
14701 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
14702 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
14703 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
14704 +
14705 #define GDT_ENTRY_TLS_MIN 6
14706 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
14707
14708 @@ -79,6 +84,8 @@
14709
14710 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
14711
14712 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
14713 +
14714 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
14715
14716 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
14717 @@ -104,6 +111,12 @@
14718 #define __KERNEL_STACK_CANARY 0
14719 #endif
14720
14721 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
14722 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
14723 +
14724 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
14725 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
14726 +
14727 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
14728
14729 /*
14730 @@ -141,7 +154,7 @@
14731 */
14732
14733 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
14734 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
14735 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
14736
14737
14738 #else
14739 @@ -165,6 +178,8 @@
14740 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
14741 #define __USER32_DS __USER_DS
14742
14743 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
14744 +
14745 #define GDT_ENTRY_TSS 8 /* needs two entries */
14746 #define GDT_ENTRY_LDT 10 /* needs two entries */
14747 #define GDT_ENTRY_TLS_MIN 12
14748 @@ -185,6 +200,7 @@
14749 #endif
14750
14751 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
14752 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
14753 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
14754 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
14755 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
14756 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
14757 {
14758 unsigned long __limit;
14759 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
14760 - return __limit + 1;
14761 + return __limit;
14762 }
14763
14764 #endif /* !__ASSEMBLY__ */
14765 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
14766 index b073aae..39f9bdd 100644
14767 --- a/arch/x86/include/asm/smp.h
14768 +++ b/arch/x86/include/asm/smp.h
14769 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
14770 /* cpus sharing the last level cache: */
14771 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
14772 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
14773 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
14774 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
14775
14776 static inline struct cpumask *cpu_sibling_mask(int cpu)
14777 {
14778 @@ -79,7 +79,7 @@ struct smp_ops {
14779
14780 void (*send_call_func_ipi)(const struct cpumask *mask);
14781 void (*send_call_func_single_ipi)(int cpu);
14782 -};
14783 +} __no_const;
14784
14785 /* Globals due to paravirt */
14786 extern void set_cpu_sibling_map(int cpu);
14787 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
14788 extern int safe_smp_processor_id(void);
14789
14790 #elif defined(CONFIG_X86_64_SMP)
14791 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14792 -
14793 -#define stack_smp_processor_id() \
14794 -({ \
14795 - struct thread_info *ti; \
14796 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
14797 - ti->cpu; \
14798 -})
14799 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14800 +#define stack_smp_processor_id() raw_smp_processor_id()
14801 #define safe_smp_processor_id() smp_processor_id()
14802
14803 #endif
14804 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
14805 index 33692ea..350a534 100644
14806 --- a/arch/x86/include/asm/spinlock.h
14807 +++ b/arch/x86/include/asm/spinlock.h
14808 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
14809 static inline void arch_read_lock(arch_rwlock_t *rw)
14810 {
14811 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
14812 +
14813 +#ifdef CONFIG_PAX_REFCOUNT
14814 + "jno 0f\n"
14815 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
14816 + "int $4\n0:\n"
14817 + _ASM_EXTABLE(0b, 0b)
14818 +#endif
14819 +
14820 "jns 1f\n"
14821 "call __read_lock_failed\n\t"
14822 "1:\n"
14823 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
14824 static inline void arch_write_lock(arch_rwlock_t *rw)
14825 {
14826 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
14827 +
14828 +#ifdef CONFIG_PAX_REFCOUNT
14829 + "jno 0f\n"
14830 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
14831 + "int $4\n0:\n"
14832 + _ASM_EXTABLE(0b, 0b)
14833 +#endif
14834 +
14835 "jz 1f\n"
14836 "call __write_lock_failed\n\t"
14837 "1:\n"
14838 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
14839
14840 static inline void arch_read_unlock(arch_rwlock_t *rw)
14841 {
14842 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
14843 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
14844 +
14845 +#ifdef CONFIG_PAX_REFCOUNT
14846 + "jno 0f\n"
14847 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
14848 + "int $4\n0:\n"
14849 + _ASM_EXTABLE(0b, 0b)
14850 +#endif
14851 +
14852 :"+m" (rw->lock) : : "memory");
14853 }
14854
14855 static inline void arch_write_unlock(arch_rwlock_t *rw)
14856 {
14857 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
14858 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
14859 +
14860 +#ifdef CONFIG_PAX_REFCOUNT
14861 + "jno 0f\n"
14862 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
14863 + "int $4\n0:\n"
14864 + _ASM_EXTABLE(0b, 0b)
14865 +#endif
14866 +
14867 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
14868 }
14869
14870 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
14871 index 6a99859..03cb807 100644
14872 --- a/arch/x86/include/asm/stackprotector.h
14873 +++ b/arch/x86/include/asm/stackprotector.h
14874 @@ -47,7 +47,7 @@
14875 * head_32 for boot CPU and setup_per_cpu_areas() for others.
14876 */
14877 #define GDT_STACK_CANARY_INIT \
14878 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
14879 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
14880
14881 /*
14882 * Initialize the stackprotector canary value.
14883 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
14884
14885 static inline void load_stack_canary_segment(void)
14886 {
14887 -#ifdef CONFIG_X86_32
14888 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
14889 asm volatile ("mov %0, %%gs" : : "r" (0));
14890 #endif
14891 }
14892 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
14893 index 70bbe39..4ae2bd4 100644
14894 --- a/arch/x86/include/asm/stacktrace.h
14895 +++ b/arch/x86/include/asm/stacktrace.h
14896 @@ -11,28 +11,20 @@
14897
14898 extern int kstack_depth_to_print;
14899
14900 -struct thread_info;
14901 +struct task_struct;
14902 struct stacktrace_ops;
14903
14904 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
14905 - unsigned long *stack,
14906 - unsigned long bp,
14907 - const struct stacktrace_ops *ops,
14908 - void *data,
14909 - unsigned long *end,
14910 - int *graph);
14911 +typedef unsigned long walk_stack_t(struct task_struct *task,
14912 + void *stack_start,
14913 + unsigned long *stack,
14914 + unsigned long bp,
14915 + const struct stacktrace_ops *ops,
14916 + void *data,
14917 + unsigned long *end,
14918 + int *graph);
14919
14920 -extern unsigned long
14921 -print_context_stack(struct thread_info *tinfo,
14922 - unsigned long *stack, unsigned long bp,
14923 - const struct stacktrace_ops *ops, void *data,
14924 - unsigned long *end, int *graph);
14925 -
14926 -extern unsigned long
14927 -print_context_stack_bp(struct thread_info *tinfo,
14928 - unsigned long *stack, unsigned long bp,
14929 - const struct stacktrace_ops *ops, void *data,
14930 - unsigned long *end, int *graph);
14931 +extern walk_stack_t print_context_stack;
14932 +extern walk_stack_t print_context_stack_bp;
14933
14934 /* Generic stack tracer with callbacks */
14935
14936 @@ -40,7 +32,7 @@ struct stacktrace_ops {
14937 void (*address)(void *data, unsigned long address, int reliable);
14938 /* On negative return stop dumping */
14939 int (*stack)(void *data, char *name);
14940 - walk_stack_t walk_stack;
14941 + walk_stack_t *walk_stack;
14942 };
14943
14944 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
14945 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
14946 index 4ec45b3..a4f0a8a 100644
14947 --- a/arch/x86/include/asm/switch_to.h
14948 +++ b/arch/x86/include/asm/switch_to.h
14949 @@ -108,7 +108,7 @@ do { \
14950 "call __switch_to\n\t" \
14951 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
14952 __switch_canary \
14953 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
14954 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
14955 "movq %%rax,%%rdi\n\t" \
14956 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
14957 "jnz ret_from_fork\n\t" \
14958 @@ -119,7 +119,7 @@ do { \
14959 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
14960 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
14961 [_tif_fork] "i" (_TIF_FORK), \
14962 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
14963 + [thread_info] "m" (current_tinfo), \
14964 [current_task] "m" (current_task) \
14965 __switch_canary_iparam \
14966 : "memory", "cc" __EXTRA_CLOBBER)
14967 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
14968 index 2d946e6..e453ec4 100644
14969 --- a/arch/x86/include/asm/thread_info.h
14970 +++ b/arch/x86/include/asm/thread_info.h
14971 @@ -10,6 +10,7 @@
14972 #include <linux/compiler.h>
14973 #include <asm/page.h>
14974 #include <asm/types.h>
14975 +#include <asm/percpu.h>
14976
14977 /*
14978 * low level task data that entry.S needs immediate access to
14979 @@ -24,7 +25,6 @@ struct exec_domain;
14980 #include <linux/atomic.h>
14981
14982 struct thread_info {
14983 - struct task_struct *task; /* main task structure */
14984 struct exec_domain *exec_domain; /* execution domain */
14985 __u32 flags; /* low level flags */
14986 __u32 status; /* thread synchronous flags */
14987 @@ -34,19 +34,13 @@ struct thread_info {
14988 mm_segment_t addr_limit;
14989 struct restart_block restart_block;
14990 void __user *sysenter_return;
14991 -#ifdef CONFIG_X86_32
14992 - unsigned long previous_esp; /* ESP of the previous stack in
14993 - case of nested (IRQ) stacks
14994 - */
14995 - __u8 supervisor_stack[0];
14996 -#endif
14997 + unsigned long lowest_stack;
14998 unsigned int sig_on_uaccess_error:1;
14999 unsigned int uaccess_err:1; /* uaccess failed */
15000 };
15001
15002 -#define INIT_THREAD_INFO(tsk) \
15003 +#define INIT_THREAD_INFO \
15004 { \
15005 - .task = &tsk, \
15006 .exec_domain = &default_exec_domain, \
15007 .flags = 0, \
15008 .cpu = 0, \
15009 @@ -57,7 +51,7 @@ struct thread_info {
15010 }, \
15011 }
15012
15013 -#define init_thread_info (init_thread_union.thread_info)
15014 +#define init_thread_info (init_thread_union.stack)
15015 #define init_stack (init_thread_union.stack)
15016
15017 #else /* !__ASSEMBLY__ */
15018 @@ -98,6 +92,7 @@ struct thread_info {
15019 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15020 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15021 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15022 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15023
15024 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15025 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15026 @@ -122,17 +117,18 @@ struct thread_info {
15027 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15028 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15029 #define _TIF_X32 (1 << TIF_X32)
15030 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15031
15032 /* work to do in syscall_trace_enter() */
15033 #define _TIF_WORK_SYSCALL_ENTRY \
15034 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15035 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15036 - _TIF_NOHZ)
15037 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
15038
15039 /* work to do in syscall_trace_leave() */
15040 #define _TIF_WORK_SYSCALL_EXIT \
15041 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15042 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15043 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15044
15045 /* work to do on interrupt/exception return */
15046 #define _TIF_WORK_MASK \
15047 @@ -143,7 +139,7 @@ struct thread_info {
15048 /* work to do on any return to user space */
15049 #define _TIF_ALLWORK_MASK \
15050 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15051 - _TIF_NOHZ)
15052 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
15053
15054 /* Only used for 64 bit */
15055 #define _TIF_DO_NOTIFY_MASK \
15056 @@ -159,45 +155,40 @@ struct thread_info {
15057
15058 #define PREEMPT_ACTIVE 0x10000000
15059
15060 -#ifdef CONFIG_X86_32
15061 -
15062 -#define STACK_WARN (THREAD_SIZE/8)
15063 -/*
15064 - * macros/functions for gaining access to the thread information structure
15065 - *
15066 - * preempt_count needs to be 1 initially, until the scheduler is functional.
15067 - */
15068 -#ifndef __ASSEMBLY__
15069 -
15070 -
15071 -/* how to get the current stack pointer from C */
15072 -register unsigned long current_stack_pointer asm("esp") __used;
15073 -
15074 -/* how to get the thread information struct from C */
15075 -static inline struct thread_info *current_thread_info(void)
15076 -{
15077 - return (struct thread_info *)
15078 - (current_stack_pointer & ~(THREAD_SIZE - 1));
15079 -}
15080 -
15081 -#else /* !__ASSEMBLY__ */
15082 -
15083 +#ifdef __ASSEMBLY__
15084 /* how to get the thread information struct from ASM */
15085 #define GET_THREAD_INFO(reg) \
15086 - movl $-THREAD_SIZE, reg; \
15087 - andl %esp, reg
15088 + mov PER_CPU_VAR(current_tinfo), reg
15089
15090 /* use this one if reg already contains %esp */
15091 -#define GET_THREAD_INFO_WITH_ESP(reg) \
15092 - andl $-THREAD_SIZE, reg
15093 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15094 +#else
15095 +/* how to get the thread information struct from C */
15096 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15097 +
15098 +static __always_inline struct thread_info *current_thread_info(void)
15099 +{
15100 + return this_cpu_read_stable(current_tinfo);
15101 +}
15102 +#endif
15103 +
15104 +#ifdef CONFIG_X86_32
15105 +
15106 +#define STACK_WARN (THREAD_SIZE/8)
15107 +/*
15108 + * macros/functions for gaining access to the thread information structure
15109 + *
15110 + * preempt_count needs to be 1 initially, until the scheduler is functional.
15111 + */
15112 +#ifndef __ASSEMBLY__
15113 +
15114 +/* how to get the current stack pointer from C */
15115 +register unsigned long current_stack_pointer asm("esp") __used;
15116
15117 #endif
15118
15119 #else /* X86_32 */
15120
15121 -#include <asm/percpu.h>
15122 -#define KERNEL_STACK_OFFSET (5*8)
15123 -
15124 /*
15125 * macros/functions for gaining access to the thread information structure
15126 * preempt_count needs to be 1 initially, until the scheduler is functional.
15127 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15128 #ifndef __ASSEMBLY__
15129 DECLARE_PER_CPU(unsigned long, kernel_stack);
15130
15131 -static inline struct thread_info *current_thread_info(void)
15132 -{
15133 - struct thread_info *ti;
15134 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
15135 - KERNEL_STACK_OFFSET - THREAD_SIZE);
15136 - return ti;
15137 -}
15138 -
15139 -#else /* !__ASSEMBLY__ */
15140 -
15141 -/* how to get the thread information struct from ASM */
15142 -#define GET_THREAD_INFO(reg) \
15143 - movq PER_CPU_VAR(kernel_stack),reg ; \
15144 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15145 -
15146 -/*
15147 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15148 - * a certain register (to be used in assembler memory operands).
15149 - */
15150 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15151 -
15152 +/* how to get the current stack pointer from C */
15153 +register unsigned long current_stack_pointer asm("rsp") __used;
15154 #endif
15155
15156 #endif /* !X86_32 */
15157 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15158 extern void arch_task_cache_init(void);
15159 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15160 extern void arch_release_task_struct(struct task_struct *tsk);
15161 +
15162 +#define __HAVE_THREAD_FUNCTIONS
15163 +#define task_thread_info(task) (&(task)->tinfo)
15164 +#define task_stack_page(task) ((task)->stack)
15165 +#define setup_thread_stack(p, org) do {} while (0)
15166 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15167 +
15168 #endif
15169 #endif /* _ASM_X86_THREAD_INFO_H */
15170 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15171 index 1709801..0a60f2f 100644
15172 --- a/arch/x86/include/asm/uaccess.h
15173 +++ b/arch/x86/include/asm/uaccess.h
15174 @@ -7,6 +7,7 @@
15175 #include <linux/compiler.h>
15176 #include <linux/thread_info.h>
15177 #include <linux/string.h>
15178 +#include <linux/sched.h>
15179 #include <asm/asm.h>
15180 #include <asm/page.h>
15181 #include <asm/smap.h>
15182 @@ -29,7 +30,12 @@
15183
15184 #define get_ds() (KERNEL_DS)
15185 #define get_fs() (current_thread_info()->addr_limit)
15186 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15187 +void __set_fs(mm_segment_t x);
15188 +void set_fs(mm_segment_t x);
15189 +#else
15190 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15191 +#endif
15192
15193 #define segment_eq(a, b) ((a).seg == (b).seg)
15194
15195 @@ -77,8 +83,33 @@
15196 * checks that the pointer is in the user space range - after calling
15197 * this function, memory access functions may still return -EFAULT.
15198 */
15199 -#define access_ok(type, addr, size) \
15200 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15201 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15202 +#define access_ok(type, addr, size) \
15203 +({ \
15204 + long __size = size; \
15205 + unsigned long __addr = (unsigned long)addr; \
15206 + unsigned long __addr_ao = __addr & PAGE_MASK; \
15207 + unsigned long __end_ao = __addr + __size - 1; \
15208 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15209 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15210 + while(__addr_ao <= __end_ao) { \
15211 + char __c_ao; \
15212 + __addr_ao += PAGE_SIZE; \
15213 + if (__size > PAGE_SIZE) \
15214 + cond_resched(); \
15215 + if (__get_user(__c_ao, (char __user *)__addr)) \
15216 + break; \
15217 + if (type != VERIFY_WRITE) { \
15218 + __addr = __addr_ao; \
15219 + continue; \
15220 + } \
15221 + if (__put_user(__c_ao, (char __user *)__addr)) \
15222 + break; \
15223 + __addr = __addr_ao; \
15224 + } \
15225 + } \
15226 + __ret_ao; \
15227 +})
15228
15229 /*
15230 * The exception table consists of pairs of addresses relative to the
15231 @@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15232 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15233 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15234
15235 -
15236 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15237 +#define __copyuser_seg "gs;"
15238 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15239 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15240 +#else
15241 +#define __copyuser_seg
15242 +#define __COPYUSER_SET_ES
15243 +#define __COPYUSER_RESTORE_ES
15244 +#endif
15245
15246 #ifdef CONFIG_X86_32
15247 #define __put_user_asm_u64(x, addr, err, errret) \
15248 asm volatile(ASM_STAC "\n" \
15249 - "1: movl %%eax,0(%2)\n" \
15250 - "2: movl %%edx,4(%2)\n" \
15251 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15252 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15253 "3: " ASM_CLAC "\n" \
15254 ".section .fixup,\"ax\"\n" \
15255 "4: movl %3,%0\n" \
15256 @@ -208,8 +247,8 @@ extern int __get_user_bad(void);
15257
15258 #define __put_user_asm_ex_u64(x, addr) \
15259 asm volatile(ASM_STAC "\n" \
15260 - "1: movl %%eax,0(%1)\n" \
15261 - "2: movl %%edx,4(%1)\n" \
15262 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15263 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15264 "3: " ASM_CLAC "\n" \
15265 _ASM_EXTABLE_EX(1b, 2b) \
15266 _ASM_EXTABLE_EX(2b, 3b) \
15267 @@ -259,7 +298,7 @@ extern void __put_user_8(void);
15268 __typeof__(*(ptr)) __pu_val; \
15269 __chk_user_ptr(ptr); \
15270 might_fault(); \
15271 - __pu_val = x; \
15272 + __pu_val = (x); \
15273 switch (sizeof(*(ptr))) { \
15274 case 1: \
15275 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15276 @@ -358,7 +397,7 @@ do { \
15277
15278 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15279 asm volatile(ASM_STAC "\n" \
15280 - "1: mov"itype" %2,%"rtype"1\n" \
15281 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15282 "2: " ASM_CLAC "\n" \
15283 ".section .fixup,\"ax\"\n" \
15284 "3: mov %3,%0\n" \
15285 @@ -366,7 +405,7 @@ do { \
15286 " jmp 2b\n" \
15287 ".previous\n" \
15288 _ASM_EXTABLE(1b, 3b) \
15289 - : "=r" (err), ltype(x) \
15290 + : "=r" (err), ltype (x) \
15291 : "m" (__m(addr)), "i" (errret), "0" (err))
15292
15293 #define __get_user_size_ex(x, ptr, size) \
15294 @@ -391,7 +430,7 @@ do { \
15295 } while (0)
15296
15297 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15298 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15299 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15300 "2:\n" \
15301 _ASM_EXTABLE_EX(1b, 2b) \
15302 : ltype(x) : "m" (__m(addr)))
15303 @@ -408,13 +447,24 @@ do { \
15304 int __gu_err; \
15305 unsigned long __gu_val; \
15306 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15307 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
15308 + (x) = (__typeof__(*(ptr)))__gu_val; \
15309 __gu_err; \
15310 })
15311
15312 /* FIXME: this hack is definitely wrong -AK */
15313 struct __large_struct { unsigned long buf[100]; };
15314 -#define __m(x) (*(struct __large_struct __user *)(x))
15315 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15316 +#define ____m(x) \
15317 +({ \
15318 + unsigned long ____x = (unsigned long)(x); \
15319 + if (____x < PAX_USER_SHADOW_BASE) \
15320 + ____x += PAX_USER_SHADOW_BASE; \
15321 + (void __user *)____x; \
15322 +})
15323 +#else
15324 +#define ____m(x) (x)
15325 +#endif
15326 +#define __m(x) (*(struct __large_struct __user *)____m(x))
15327
15328 /*
15329 * Tell gcc we read from memory instead of writing: this is because
15330 @@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
15331 */
15332 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15333 asm volatile(ASM_STAC "\n" \
15334 - "1: mov"itype" %"rtype"1,%2\n" \
15335 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15336 "2: " ASM_CLAC "\n" \
15337 ".section .fixup,\"ax\"\n" \
15338 "3: mov %3,%0\n" \
15339 @@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
15340 ".previous\n" \
15341 _ASM_EXTABLE(1b, 3b) \
15342 : "=r"(err) \
15343 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15344 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15345
15346 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15347 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15348 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15349 "2:\n" \
15350 _ASM_EXTABLE_EX(1b, 2b) \
15351 : : ltype(x), "m" (__m(addr)))
15352 @@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
15353 * On error, the variable @x is set to zero.
15354 */
15355
15356 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15357 +#define __get_user(x, ptr) get_user((x), (ptr))
15358 +#else
15359 #define __get_user(x, ptr) \
15360 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15361 +#endif
15362
15363 /**
15364 * __put_user: - Write a simple value into user space, with less checking.
15365 @@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
15366 * Returns zero on success, or -EFAULT on error.
15367 */
15368
15369 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15370 +#define __put_user(x, ptr) put_user((x), (ptr))
15371 +#else
15372 #define __put_user(x, ptr) \
15373 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15374 +#endif
15375
15376 #define __get_user_unaligned __get_user
15377 #define __put_user_unaligned __put_user
15378 @@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
15379 #define get_user_ex(x, ptr) do { \
15380 unsigned long __gue_val; \
15381 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15382 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
15383 + (x) = (__typeof__(*(ptr)))__gue_val; \
15384 } while (0)
15385
15386 #define put_user_try uaccess_try
15387 @@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15388 extern __must_check long strlen_user(const char __user *str);
15389 extern __must_check long strnlen_user(const char __user *str, long n);
15390
15391 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15392 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15393 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15394 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15395
15396 /*
15397 * movsl can be slow when source and dest are not both 8-byte aligned
15398 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15399 index 7f760a9..04b1c65 100644
15400 --- a/arch/x86/include/asm/uaccess_32.h
15401 +++ b/arch/x86/include/asm/uaccess_32.h
15402 @@ -11,15 +11,15 @@
15403 #include <asm/page.h>
15404
15405 unsigned long __must_check __copy_to_user_ll
15406 - (void __user *to, const void *from, unsigned long n);
15407 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15408 unsigned long __must_check __copy_from_user_ll
15409 - (void *to, const void __user *from, unsigned long n);
15410 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15411 unsigned long __must_check __copy_from_user_ll_nozero
15412 - (void *to, const void __user *from, unsigned long n);
15413 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15414 unsigned long __must_check __copy_from_user_ll_nocache
15415 - (void *to, const void __user *from, unsigned long n);
15416 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15417 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15418 - (void *to, const void __user *from, unsigned long n);
15419 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15420
15421 /**
15422 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15423 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15424 static __always_inline unsigned long __must_check
15425 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15426 {
15427 + if ((long)n < 0)
15428 + return n;
15429 +
15430 + check_object_size(from, n, true);
15431 +
15432 if (__builtin_constant_p(n)) {
15433 unsigned long ret;
15434
15435 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15436 __copy_to_user(void __user *to, const void *from, unsigned long n)
15437 {
15438 might_fault();
15439 +
15440 return __copy_to_user_inatomic(to, from, n);
15441 }
15442
15443 static __always_inline unsigned long
15444 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15445 {
15446 + if ((long)n < 0)
15447 + return n;
15448 +
15449 /* Avoid zeroing the tail if the copy fails..
15450 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15451 * but as the zeroing behaviour is only significant when n is not
15452 @@ -137,6 +146,12 @@ static __always_inline unsigned long
15453 __copy_from_user(void *to, const void __user *from, unsigned long n)
15454 {
15455 might_fault();
15456 +
15457 + if ((long)n < 0)
15458 + return n;
15459 +
15460 + check_object_size(to, n, false);
15461 +
15462 if (__builtin_constant_p(n)) {
15463 unsigned long ret;
15464
15465 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15466 const void __user *from, unsigned long n)
15467 {
15468 might_fault();
15469 +
15470 + if ((long)n < 0)
15471 + return n;
15472 +
15473 if (__builtin_constant_p(n)) {
15474 unsigned long ret;
15475
15476 @@ -181,15 +200,19 @@ static __always_inline unsigned long
15477 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15478 unsigned long n)
15479 {
15480 - return __copy_from_user_ll_nocache_nozero(to, from, n);
15481 + if ((long)n < 0)
15482 + return n;
15483 +
15484 + return __copy_from_user_ll_nocache_nozero(to, from, n);
15485 }
15486
15487 -unsigned long __must_check copy_to_user(void __user *to,
15488 - const void *from, unsigned long n);
15489 -unsigned long __must_check _copy_from_user(void *to,
15490 - const void __user *from,
15491 - unsigned long n);
15492 -
15493 +extern void copy_to_user_overflow(void)
15494 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15495 + __compiletime_error("copy_to_user() buffer size is not provably correct")
15496 +#else
15497 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
15498 +#endif
15499 +;
15500
15501 extern void copy_from_user_overflow(void)
15502 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15503 @@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15504 #endif
15505 ;
15506
15507 -static inline unsigned long __must_check copy_from_user(void *to,
15508 - const void __user *from,
15509 - unsigned long n)
15510 +/**
15511 + * copy_to_user: - Copy a block of data into user space.
15512 + * @to: Destination address, in user space.
15513 + * @from: Source address, in kernel space.
15514 + * @n: Number of bytes to copy.
15515 + *
15516 + * Context: User context only. This function may sleep.
15517 + *
15518 + * Copy data from kernel space to user space.
15519 + *
15520 + * Returns number of bytes that could not be copied.
15521 + * On success, this will be zero.
15522 + */
15523 +static inline unsigned long __must_check
15524 +copy_to_user(void __user *to, const void *from, unsigned long n)
15525 {
15526 - int sz = __compiletime_object_size(to);
15527 + size_t sz = __compiletime_object_size(from);
15528
15529 - if (likely(sz == -1 || sz >= n))
15530 - n = _copy_from_user(to, from, n);
15531 - else
15532 + if (unlikely(sz != (size_t)-1 && sz < n))
15533 + copy_to_user_overflow();
15534 + else if (access_ok(VERIFY_WRITE, to, n))
15535 + n = __copy_to_user(to, from, n);
15536 + return n;
15537 +}
15538 +
15539 +/**
15540 + * copy_from_user: - Copy a block of data from user space.
15541 + * @to: Destination address, in kernel space.
15542 + * @from: Source address, in user space.
15543 + * @n: Number of bytes to copy.
15544 + *
15545 + * Context: User context only. This function may sleep.
15546 + *
15547 + * Copy data from user space to kernel space.
15548 + *
15549 + * Returns number of bytes that could not be copied.
15550 + * On success, this will be zero.
15551 + *
15552 + * If some data could not be copied, this function will pad the copied
15553 + * data to the requested size using zero bytes.
15554 + */
15555 +static inline unsigned long __must_check
15556 +copy_from_user(void *to, const void __user *from, unsigned long n)
15557 +{
15558 + size_t sz = __compiletime_object_size(to);
15559 +
15560 + check_object_size(to, n, false);
15561 +
15562 + if (unlikely(sz != (size_t)-1 && sz < n))
15563 copy_from_user_overflow();
15564 -
15565 + else if (access_ok(VERIFY_READ, from, n))
15566 + n = __copy_from_user(to, from, n);
15567 + else if ((long)n > 0)
15568 + memset(to, 0, n);
15569 return n;
15570 }
15571
15572 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
15573 index 142810c..747941a 100644
15574 --- a/arch/x86/include/asm/uaccess_64.h
15575 +++ b/arch/x86/include/asm/uaccess_64.h
15576 @@ -10,6 +10,9 @@
15577 #include <asm/alternative.h>
15578 #include <asm/cpufeature.h>
15579 #include <asm/page.h>
15580 +#include <asm/pgtable.h>
15581 +
15582 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
15583
15584 /*
15585 * Copy To/From Userspace
15586 @@ -17,13 +20,13 @@
15587
15588 /* Handles exceptions in both to and from, but doesn't do access_ok */
15589 __must_check unsigned long
15590 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
15591 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
15592 __must_check unsigned long
15593 -copy_user_generic_string(void *to, const void *from, unsigned len);
15594 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
15595 __must_check unsigned long
15596 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
15597 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
15598
15599 -static __always_inline __must_check unsigned long
15600 +static __always_inline __must_check __size_overflow(3) unsigned long
15601 copy_user_generic(void *to, const void *from, unsigned len)
15602 {
15603 unsigned ret;
15604 @@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
15605 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
15606 "=d" (len)),
15607 "1" (to), "2" (from), "3" (len)
15608 - : "memory", "rcx", "r8", "r9", "r10", "r11");
15609 + : "memory", "rcx", "r8", "r9", "r11");
15610 return ret;
15611 }
15612
15613 +static __always_inline __must_check unsigned long
15614 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
15615 +static __always_inline __must_check unsigned long
15616 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
15617 __must_check unsigned long
15618 -_copy_to_user(void __user *to, const void *from, unsigned len);
15619 -__must_check unsigned long
15620 -_copy_from_user(void *to, const void __user *from, unsigned len);
15621 -__must_check unsigned long
15622 -copy_in_user(void __user *to, const void __user *from, unsigned len);
15623 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
15624 +
15625 +extern void copy_to_user_overflow(void)
15626 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15627 + __compiletime_error("copy_to_user() buffer size is not provably correct")
15628 +#else
15629 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
15630 +#endif
15631 +;
15632 +
15633 +extern void copy_from_user_overflow(void)
15634 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15635 + __compiletime_error("copy_from_user() buffer size is not provably correct")
15636 +#else
15637 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
15638 +#endif
15639 +;
15640
15641 static inline unsigned long __must_check copy_from_user(void *to,
15642 const void __user *from,
15643 unsigned long n)
15644 {
15645 - int sz = __compiletime_object_size(to);
15646 -
15647 might_fault();
15648 - if (likely(sz == -1 || sz >= n))
15649 - n = _copy_from_user(to, from, n);
15650 -#ifdef CONFIG_DEBUG_VM
15651 - else
15652 - WARN(1, "Buffer overflow detected!\n");
15653 -#endif
15654 +
15655 + check_object_size(to, n, false);
15656 +
15657 + if (access_ok(VERIFY_READ, from, n))
15658 + n = __copy_from_user(to, from, n);
15659 + else if (n < INT_MAX)
15660 + memset(to, 0, n);
15661 return n;
15662 }
15663
15664 static __always_inline __must_check
15665 -int copy_to_user(void __user *dst, const void *src, unsigned size)
15666 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
15667 {
15668 might_fault();
15669
15670 - return _copy_to_user(dst, src, size);
15671 + if (access_ok(VERIFY_WRITE, dst, size))
15672 + size = __copy_to_user(dst, src, size);
15673 + return size;
15674 }
15675
15676 static __always_inline __must_check
15677 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
15678 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
15679 {
15680 - int ret = 0;
15681 + size_t sz = __compiletime_object_size(dst);
15682 + unsigned ret = 0;
15683
15684 might_fault();
15685 +
15686 + if (size > INT_MAX)
15687 + return size;
15688 +
15689 + check_object_size(dst, size, false);
15690 +
15691 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15692 + if (!__access_ok(VERIFY_READ, src, size))
15693 + return size;
15694 +#endif
15695 +
15696 + if (unlikely(sz != (size_t)-1 && sz < size)) {
15697 + copy_from_user_overflow();
15698 + return size;
15699 + }
15700 +
15701 if (!__builtin_constant_p(size))
15702 - return copy_user_generic(dst, (__force void *)src, size);
15703 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15704 switch (size) {
15705 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
15706 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
15707 ret, "b", "b", "=q", 1);
15708 return ret;
15709 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
15710 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
15711 ret, "w", "w", "=r", 2);
15712 return ret;
15713 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
15714 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
15715 ret, "l", "k", "=r", 4);
15716 return ret;
15717 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
15718 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15719 ret, "q", "", "=r", 8);
15720 return ret;
15721 case 10:
15722 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15723 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15724 ret, "q", "", "=r", 10);
15725 if (unlikely(ret))
15726 return ret;
15727 __get_user_asm(*(u16 *)(8 + (char *)dst),
15728 - (u16 __user *)(8 + (char __user *)src),
15729 + (const u16 __user *)(8 + (const char __user *)src),
15730 ret, "w", "w", "=r", 2);
15731 return ret;
15732 case 16:
15733 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15734 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15735 ret, "q", "", "=r", 16);
15736 if (unlikely(ret))
15737 return ret;
15738 __get_user_asm(*(u64 *)(8 + (char *)dst),
15739 - (u64 __user *)(8 + (char __user *)src),
15740 + (const u64 __user *)(8 + (const char __user *)src),
15741 ret, "q", "", "=r", 8);
15742 return ret;
15743 default:
15744 - return copy_user_generic(dst, (__force void *)src, size);
15745 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15746 }
15747 }
15748
15749 static __always_inline __must_check
15750 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
15751 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
15752 {
15753 - int ret = 0;
15754 + size_t sz = __compiletime_object_size(src);
15755 + unsigned ret = 0;
15756
15757 might_fault();
15758 +
15759 + if (size > INT_MAX)
15760 + return size;
15761 +
15762 + check_object_size(src, size, true);
15763 +
15764 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15765 + if (!__access_ok(VERIFY_WRITE, dst, size))
15766 + return size;
15767 +#endif
15768 +
15769 + if (unlikely(sz != (size_t)-1 && sz < size)) {
15770 + copy_to_user_overflow();
15771 + return size;
15772 + }
15773 +
15774 if (!__builtin_constant_p(size))
15775 - return copy_user_generic((__force void *)dst, src, size);
15776 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15777 switch (size) {
15778 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
15779 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
15780 ret, "b", "b", "iq", 1);
15781 return ret;
15782 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
15783 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
15784 ret, "w", "w", "ir", 2);
15785 return ret;
15786 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
15787 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
15788 ret, "l", "k", "ir", 4);
15789 return ret;
15790 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
15791 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15792 ret, "q", "", "er", 8);
15793 return ret;
15794 case 10:
15795 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15796 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15797 ret, "q", "", "er", 10);
15798 if (unlikely(ret))
15799 return ret;
15800 asm("":::"memory");
15801 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
15802 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
15803 ret, "w", "w", "ir", 2);
15804 return ret;
15805 case 16:
15806 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15807 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15808 ret, "q", "", "er", 16);
15809 if (unlikely(ret))
15810 return ret;
15811 asm("":::"memory");
15812 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
15813 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
15814 ret, "q", "", "er", 8);
15815 return ret;
15816 default:
15817 - return copy_user_generic((__force void *)dst, src, size);
15818 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15819 }
15820 }
15821
15822 static __always_inline __must_check
15823 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15824 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
15825 {
15826 - int ret = 0;
15827 + unsigned ret = 0;
15828
15829 might_fault();
15830 +
15831 + if (size > INT_MAX)
15832 + return size;
15833 +
15834 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15835 + if (!__access_ok(VERIFY_READ, src, size))
15836 + return size;
15837 + if (!__access_ok(VERIFY_WRITE, dst, size))
15838 + return size;
15839 +#endif
15840 +
15841 if (!__builtin_constant_p(size))
15842 - return copy_user_generic((__force void *)dst,
15843 - (__force void *)src, size);
15844 + return copy_user_generic((__force_kernel void *)____m(dst),
15845 + (__force_kernel const void *)____m(src), size);
15846 switch (size) {
15847 case 1: {
15848 u8 tmp;
15849 - __get_user_asm(tmp, (u8 __user *)src,
15850 + __get_user_asm(tmp, (const u8 __user *)src,
15851 ret, "b", "b", "=q", 1);
15852 if (likely(!ret))
15853 __put_user_asm(tmp, (u8 __user *)dst,
15854 @@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15855 }
15856 case 2: {
15857 u16 tmp;
15858 - __get_user_asm(tmp, (u16 __user *)src,
15859 + __get_user_asm(tmp, (const u16 __user *)src,
15860 ret, "w", "w", "=r", 2);
15861 if (likely(!ret))
15862 __put_user_asm(tmp, (u16 __user *)dst,
15863 @@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15864
15865 case 4: {
15866 u32 tmp;
15867 - __get_user_asm(tmp, (u32 __user *)src,
15868 + __get_user_asm(tmp, (const u32 __user *)src,
15869 ret, "l", "k", "=r", 4);
15870 if (likely(!ret))
15871 __put_user_asm(tmp, (u32 __user *)dst,
15872 @@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15873 }
15874 case 8: {
15875 u64 tmp;
15876 - __get_user_asm(tmp, (u64 __user *)src,
15877 + __get_user_asm(tmp, (const u64 __user *)src,
15878 ret, "q", "", "=r", 8);
15879 if (likely(!ret))
15880 __put_user_asm(tmp, (u64 __user *)dst,
15881 @@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15882 return ret;
15883 }
15884 default:
15885 - return copy_user_generic((__force void *)dst,
15886 - (__force void *)src, size);
15887 + return copy_user_generic((__force_kernel void *)____m(dst),
15888 + (__force_kernel const void *)____m(src), size);
15889 }
15890 }
15891
15892 static __must_check __always_inline int
15893 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
15894 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
15895 {
15896 - return copy_user_generic(dst, (__force const void *)src, size);
15897 + if (size > INT_MAX)
15898 + return size;
15899 +
15900 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15901 + if (!__access_ok(VERIFY_READ, src, size))
15902 + return size;
15903 +#endif
15904 +
15905 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15906 }
15907
15908 -static __must_check __always_inline int
15909 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
15910 +static __must_check __always_inline unsigned long
15911 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
15912 {
15913 - return copy_user_generic((__force void *)dst, src, size);
15914 + if (size > INT_MAX)
15915 + return size;
15916 +
15917 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15918 + if (!__access_ok(VERIFY_WRITE, dst, size))
15919 + return size;
15920 +#endif
15921 +
15922 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15923 }
15924
15925 -extern long __copy_user_nocache(void *dst, const void __user *src,
15926 - unsigned size, int zerorest);
15927 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
15928 + unsigned long size, int zerorest) __size_overflow(3);
15929
15930 -static inline int
15931 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
15932 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
15933 {
15934 might_sleep();
15935 +
15936 + if (size > INT_MAX)
15937 + return size;
15938 +
15939 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15940 + if (!__access_ok(VERIFY_READ, src, size))
15941 + return size;
15942 +#endif
15943 +
15944 return __copy_user_nocache(dst, src, size, 1);
15945 }
15946
15947 -static inline int
15948 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
15949 - unsigned size)
15950 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
15951 + unsigned long size)
15952 {
15953 + if (size > INT_MAX)
15954 + return size;
15955 +
15956 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15957 + if (!__access_ok(VERIFY_READ, src, size))
15958 + return size;
15959 +#endif
15960 +
15961 return __copy_user_nocache(dst, src, size, 0);
15962 }
15963
15964 -unsigned long
15965 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
15966 +extern unsigned long
15967 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
15968
15969 #endif /* _ASM_X86_UACCESS_64_H */
15970 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
15971 index 5b238981..77fdd78 100644
15972 --- a/arch/x86/include/asm/word-at-a-time.h
15973 +++ b/arch/x86/include/asm/word-at-a-time.h
15974 @@ -11,7 +11,7 @@
15975 * and shift, for example.
15976 */
15977 struct word_at_a_time {
15978 - const unsigned long one_bits, high_bits;
15979 + unsigned long one_bits, high_bits;
15980 };
15981
15982 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
15983 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
15984 index 5769349..a3d3e2a 100644
15985 --- a/arch/x86/include/asm/x86_init.h
15986 +++ b/arch/x86/include/asm/x86_init.h
15987 @@ -141,7 +141,7 @@ struct x86_init_ops {
15988 struct x86_init_timers timers;
15989 struct x86_init_iommu iommu;
15990 struct x86_init_pci pci;
15991 -};
15992 +} __no_const;
15993
15994 /**
15995 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
15996 @@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
15997 void (*setup_percpu_clockev)(void);
15998 void (*early_percpu_clock_init)(void);
15999 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16000 -};
16001 +} __no_const;
16002
16003 /**
16004 * struct x86_platform_ops - platform specific runtime functions
16005 @@ -178,7 +178,7 @@ struct x86_platform_ops {
16006 void (*save_sched_clock_state)(void);
16007 void (*restore_sched_clock_state)(void);
16008 void (*apic_post_init)(void);
16009 -};
16010 +} __no_const;
16011
16012 struct pci_dev;
16013
16014 @@ -187,14 +187,14 @@ struct x86_msi_ops {
16015 void (*teardown_msi_irq)(unsigned int irq);
16016 void (*teardown_msi_irqs)(struct pci_dev *dev);
16017 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16018 -};
16019 +} __no_const;
16020
16021 struct x86_io_apic_ops {
16022 void (*init) (void);
16023 unsigned int (*read) (unsigned int apic, unsigned int reg);
16024 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
16025 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
16026 -};
16027 +} __no_const;
16028
16029 extern struct x86_init_ops x86_init;
16030 extern struct x86_cpuinit_ops x86_cpuinit;
16031 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16032 index 0415cda..b43d877 100644
16033 --- a/arch/x86/include/asm/xsave.h
16034 +++ b/arch/x86/include/asm/xsave.h
16035 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16036 return -EFAULT;
16037
16038 __asm__ __volatile__(ASM_STAC "\n"
16039 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16040 + "1:"
16041 + __copyuser_seg
16042 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16043 "2: " ASM_CLAC "\n"
16044 ".section .fixup,\"ax\"\n"
16045 "3: movl $-1,%[err]\n"
16046 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16047 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16048 {
16049 int err;
16050 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16051 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16052 u32 lmask = mask;
16053 u32 hmask = mask >> 32;
16054
16055 __asm__ __volatile__(ASM_STAC "\n"
16056 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16057 + "1:"
16058 + __copyuser_seg
16059 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16060 "2: " ASM_CLAC "\n"
16061 ".section .fixup,\"ax\"\n"
16062 "3: movl $-1,%[err]\n"
16063 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16064 index bbae024..e1528f9 100644
16065 --- a/arch/x86/include/uapi/asm/e820.h
16066 +++ b/arch/x86/include/uapi/asm/e820.h
16067 @@ -63,7 +63,7 @@ struct e820map {
16068 #define ISA_START_ADDRESS 0xa0000
16069 #define ISA_END_ADDRESS 0x100000
16070
16071 -#define BIOS_BEGIN 0x000a0000
16072 +#define BIOS_BEGIN 0x000c0000
16073 #define BIOS_END 0x00100000
16074
16075 #define BIOS_ROM_BASE 0xffe00000
16076 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16077 index 34e923a..0c6bb6e 100644
16078 --- a/arch/x86/kernel/Makefile
16079 +++ b/arch/x86/kernel/Makefile
16080 @@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16081 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16082 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16083 obj-y += probe_roms.o
16084 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16085 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16086 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16087 obj-y += syscall_$(BITS).o
16088 obj-$(CONFIG_X86_64) += vsyscall_64.o
16089 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16090 index bacf4b0..4ede72e 100644
16091 --- a/arch/x86/kernel/acpi/boot.c
16092 +++ b/arch/x86/kernel/acpi/boot.c
16093 @@ -1358,7 +1358,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16094 * If your system is blacklisted here, but you find that acpi=force
16095 * works for you, please contact linux-acpi@vger.kernel.org
16096 */
16097 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
16098 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16099 /*
16100 * Boxes that need ACPI disabled
16101 */
16102 @@ -1433,7 +1433,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16103 };
16104
16105 /* second table for DMI checks that should run after early-quirks */
16106 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16107 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16108 /*
16109 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16110 * which includes some code which overrides all temperature
16111 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16112 index d5e0d71..6533e08 100644
16113 --- a/arch/x86/kernel/acpi/sleep.c
16114 +++ b/arch/x86/kernel/acpi/sleep.c
16115 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16116 #else /* CONFIG_64BIT */
16117 #ifdef CONFIG_SMP
16118 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16119 +
16120 + pax_open_kernel();
16121 early_gdt_descr.address =
16122 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16123 + pax_close_kernel();
16124 +
16125 initial_gs = per_cpu_offset(smp_processor_id());
16126 #endif
16127 initial_code = (unsigned long)wakeup_long64;
16128 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16129 index 13ab720..95d5442 100644
16130 --- a/arch/x86/kernel/acpi/wakeup_32.S
16131 +++ b/arch/x86/kernel/acpi/wakeup_32.S
16132 @@ -30,13 +30,11 @@ wakeup_pmode_return:
16133 # and restore the stack ... but you need gdt for this to work
16134 movl saved_context_esp, %esp
16135
16136 - movl %cs:saved_magic, %eax
16137 - cmpl $0x12345678, %eax
16138 + cmpl $0x12345678, saved_magic
16139 jne bogus_magic
16140
16141 # jump to place where we left off
16142 - movl saved_eip, %eax
16143 - jmp *%eax
16144 + jmp *(saved_eip)
16145
16146 bogus_magic:
16147 jmp bogus_magic
16148 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16149 index ef5ccca..bd83949 100644
16150 --- a/arch/x86/kernel/alternative.c
16151 +++ b/arch/x86/kernel/alternative.c
16152 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16153 */
16154 for (a = start; a < end; a++) {
16155 instr = (u8 *)&a->instr_offset + a->instr_offset;
16156 +
16157 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16158 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16159 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16160 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16161 +#endif
16162 +
16163 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16164 BUG_ON(a->replacementlen > a->instrlen);
16165 BUG_ON(a->instrlen > sizeof(insnbuf));
16166 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16167 for (poff = start; poff < end; poff++) {
16168 u8 *ptr = (u8 *)poff + *poff;
16169
16170 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16171 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16172 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16173 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16174 +#endif
16175 +
16176 if (!*poff || ptr < text || ptr >= text_end)
16177 continue;
16178 /* turn DS segment override prefix into lock prefix */
16179 - if (*ptr == 0x3e)
16180 + if (*ktla_ktva(ptr) == 0x3e)
16181 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16182 }
16183 mutex_unlock(&text_mutex);
16184 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16185 for (poff = start; poff < end; poff++) {
16186 u8 *ptr = (u8 *)poff + *poff;
16187
16188 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16189 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16190 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16191 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16192 +#endif
16193 +
16194 if (!*poff || ptr < text || ptr >= text_end)
16195 continue;
16196 /* turn lock prefix into DS segment override prefix */
16197 - if (*ptr == 0xf0)
16198 + if (*ktla_ktva(ptr) == 0xf0)
16199 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16200 }
16201 mutex_unlock(&text_mutex);
16202 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16203
16204 BUG_ON(p->len > MAX_PATCH_LEN);
16205 /* prep the buffer with the original instructions */
16206 - memcpy(insnbuf, p->instr, p->len);
16207 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16208 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16209 (unsigned long)p->instr, p->len);
16210
16211 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16212 if (!uniproc_patched || num_possible_cpus() == 1)
16213 free_init_pages("SMP alternatives",
16214 (unsigned long)__smp_locks,
16215 - (unsigned long)__smp_locks_end);
16216 + PAGE_ALIGN((unsigned long)__smp_locks_end));
16217 #endif
16218
16219 apply_paravirt(__parainstructions, __parainstructions_end);
16220 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16221 * instructions. And on the local CPU you need to be protected again NMI or MCE
16222 * handlers seeing an inconsistent instruction while you patch.
16223 */
16224 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
16225 +void *__kprobes text_poke_early(void *addr, const void *opcode,
16226 size_t len)
16227 {
16228 unsigned long flags;
16229 local_irq_save(flags);
16230 - memcpy(addr, opcode, len);
16231 +
16232 + pax_open_kernel();
16233 + memcpy(ktla_ktva(addr), opcode, len);
16234 sync_core();
16235 + pax_close_kernel();
16236 +
16237 local_irq_restore(flags);
16238 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16239 that causes hangs on some VIA CPUs. */
16240 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16241 */
16242 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16243 {
16244 - unsigned long flags;
16245 - char *vaddr;
16246 + unsigned char *vaddr = ktla_ktva(addr);
16247 struct page *pages[2];
16248 - int i;
16249 + size_t i;
16250
16251 if (!core_kernel_text((unsigned long)addr)) {
16252 - pages[0] = vmalloc_to_page(addr);
16253 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16254 + pages[0] = vmalloc_to_page(vaddr);
16255 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16256 } else {
16257 - pages[0] = virt_to_page(addr);
16258 + pages[0] = virt_to_page(vaddr);
16259 WARN_ON(!PageReserved(pages[0]));
16260 - pages[1] = virt_to_page(addr + PAGE_SIZE);
16261 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16262 }
16263 BUG_ON(!pages[0]);
16264 - local_irq_save(flags);
16265 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16266 - if (pages[1])
16267 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16268 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16269 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16270 - clear_fixmap(FIX_TEXT_POKE0);
16271 - if (pages[1])
16272 - clear_fixmap(FIX_TEXT_POKE1);
16273 - local_flush_tlb();
16274 - sync_core();
16275 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
16276 - that causes hangs on some VIA CPUs. */
16277 + text_poke_early(addr, opcode, len);
16278 for (i = 0; i < len; i++)
16279 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16280 - local_irq_restore(flags);
16281 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16282 return addr;
16283 }
16284
16285 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16286 index cbf5121..812b537 100644
16287 --- a/arch/x86/kernel/apic/apic.c
16288 +++ b/arch/x86/kernel/apic/apic.c
16289 @@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16290 /*
16291 * Debug level, exported for io_apic.c
16292 */
16293 -unsigned int apic_verbosity;
16294 +int apic_verbosity;
16295
16296 int pic_mode;
16297
16298 @@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16299 apic_write(APIC_ESR, 0);
16300 v1 = apic_read(APIC_ESR);
16301 ack_APIC_irq();
16302 - atomic_inc(&irq_err_count);
16303 + atomic_inc_unchecked(&irq_err_count);
16304
16305 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16306 smp_processor_id(), v0 , v1);
16307 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16308 index 00c77cf..2dc6a2d 100644
16309 --- a/arch/x86/kernel/apic/apic_flat_64.c
16310 +++ b/arch/x86/kernel/apic/apic_flat_64.c
16311 @@ -157,7 +157,7 @@ static int flat_probe(void)
16312 return 1;
16313 }
16314
16315 -static struct apic apic_flat = {
16316 +static struct apic apic_flat __read_only = {
16317 .name = "flat",
16318 .probe = flat_probe,
16319 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16320 @@ -271,7 +271,7 @@ static int physflat_probe(void)
16321 return 0;
16322 }
16323
16324 -static struct apic apic_physflat = {
16325 +static struct apic apic_physflat __read_only = {
16326
16327 .name = "physical flat",
16328 .probe = physflat_probe,
16329 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16330 index e145f28..2752888 100644
16331 --- a/arch/x86/kernel/apic/apic_noop.c
16332 +++ b/arch/x86/kernel/apic/apic_noop.c
16333 @@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16334 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16335 }
16336
16337 -struct apic apic_noop = {
16338 +struct apic apic_noop __read_only = {
16339 .name = "noop",
16340 .probe = noop_probe,
16341 .acpi_madt_oem_check = NULL,
16342 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16343 index d50e364..543bee3 100644
16344 --- a/arch/x86/kernel/apic/bigsmp_32.c
16345 +++ b/arch/x86/kernel/apic/bigsmp_32.c
16346 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16347 return dmi_bigsmp;
16348 }
16349
16350 -static struct apic apic_bigsmp = {
16351 +static struct apic apic_bigsmp __read_only = {
16352
16353 .name = "bigsmp",
16354 .probe = probe_bigsmp,
16355 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16356 index 0874799..a7a7892 100644
16357 --- a/arch/x86/kernel/apic/es7000_32.c
16358 +++ b/arch/x86/kernel/apic/es7000_32.c
16359 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16360 return ret && es7000_apic_is_cluster();
16361 }
16362
16363 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16364 -static struct apic __refdata apic_es7000_cluster = {
16365 +static struct apic apic_es7000_cluster __read_only = {
16366
16367 .name = "es7000",
16368 .probe = probe_es7000,
16369 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16370 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16371 };
16372
16373 -static struct apic __refdata apic_es7000 = {
16374 +static struct apic apic_es7000 __read_only = {
16375
16376 .name = "es7000",
16377 .probe = probe_es7000,
16378 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16379 index b739d39..aebc14c 100644
16380 --- a/arch/x86/kernel/apic/io_apic.c
16381 +++ b/arch/x86/kernel/apic/io_apic.c
16382 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16383 }
16384 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16385
16386 -void lock_vector_lock(void)
16387 +void lock_vector_lock(void) __acquires(vector_lock)
16388 {
16389 /* Used to the online set of cpus does not change
16390 * during assign_irq_vector.
16391 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
16392 raw_spin_lock(&vector_lock);
16393 }
16394
16395 -void unlock_vector_lock(void)
16396 +void unlock_vector_lock(void) __releases(vector_lock)
16397 {
16398 raw_spin_unlock(&vector_lock);
16399 }
16400 @@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
16401 ack_APIC_irq();
16402 }
16403
16404 -atomic_t irq_mis_count;
16405 +atomic_unchecked_t irq_mis_count;
16406
16407 #ifdef CONFIG_GENERIC_PENDING_IRQ
16408 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16409 @@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
16410 * at the cpu.
16411 */
16412 if (!(v & (1 << (i & 0x1f)))) {
16413 - atomic_inc(&irq_mis_count);
16414 + atomic_inc_unchecked(&irq_mis_count);
16415
16416 eoi_ioapic_irq(irq, cfg);
16417 }
16418 @@ -2567,11 +2567,13 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
16419
16420 static void irq_remap_modify_chip_defaults(struct irq_chip *chip)
16421 {
16422 - chip->irq_print_chip = ir_print_prefix;
16423 - chip->irq_ack = ir_ack_apic_edge;
16424 - chip->irq_eoi = ir_ack_apic_level;
16425 + pax_open_kernel();
16426 + *(void **)&chip->irq_print_chip = ir_print_prefix;
16427 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
16428 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
16429
16430 - chip->irq_set_affinity = set_remapped_irq_affinity;
16431 + *(void **)&chip->irq_set_affinity = set_remapped_irq_affinity;
16432 + pax_close_kernel();
16433 }
16434 #endif /* CONFIG_IRQ_REMAP */
16435
16436 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16437 index d661ee9..791fd33 100644
16438 --- a/arch/x86/kernel/apic/numaq_32.c
16439 +++ b/arch/x86/kernel/apic/numaq_32.c
16440 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16441 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16442 }
16443
16444 -/* Use __refdata to keep false positive warning calm. */
16445 -static struct apic __refdata apic_numaq = {
16446 +static struct apic apic_numaq __read_only = {
16447
16448 .name = "NUMAQ",
16449 .probe = probe_numaq,
16450 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16451 index eb35ef9..f184a21 100644
16452 --- a/arch/x86/kernel/apic/probe_32.c
16453 +++ b/arch/x86/kernel/apic/probe_32.c
16454 @@ -72,7 +72,7 @@ static int probe_default(void)
16455 return 1;
16456 }
16457
16458 -static struct apic apic_default = {
16459 +static struct apic apic_default __read_only = {
16460
16461 .name = "default",
16462 .probe = probe_default,
16463 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16464 index 77c95c0..434f8a4 100644
16465 --- a/arch/x86/kernel/apic/summit_32.c
16466 +++ b/arch/x86/kernel/apic/summit_32.c
16467 @@ -486,7 +486,7 @@ void setup_summit(void)
16468 }
16469 #endif
16470
16471 -static struct apic apic_summit = {
16472 +static struct apic apic_summit __read_only = {
16473
16474 .name = "summit",
16475 .probe = probe_summit,
16476 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16477 index c88baa4..757aee1 100644
16478 --- a/arch/x86/kernel/apic/x2apic_cluster.c
16479 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
16480 @@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16481 return notifier_from_errno(err);
16482 }
16483
16484 -static struct notifier_block __refdata x2apic_cpu_notifier = {
16485 +static struct notifier_block x2apic_cpu_notifier = {
16486 .notifier_call = update_clusterinfo,
16487 };
16488
16489 @@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16490 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16491 }
16492
16493 -static struct apic apic_x2apic_cluster = {
16494 +static struct apic apic_x2apic_cluster __read_only = {
16495
16496 .name = "cluster x2apic",
16497 .probe = x2apic_cluster_probe,
16498 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16499 index 562a76d..a003c0f 100644
16500 --- a/arch/x86/kernel/apic/x2apic_phys.c
16501 +++ b/arch/x86/kernel/apic/x2apic_phys.c
16502 @@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16503 return apic == &apic_x2apic_phys;
16504 }
16505
16506 -static struct apic apic_x2apic_phys = {
16507 +static struct apic apic_x2apic_phys __read_only = {
16508
16509 .name = "physical x2apic",
16510 .probe = x2apic_phys_probe,
16511 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16512 index 8cfade9..b9d04fc 100644
16513 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
16514 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16515 @@ -333,7 +333,7 @@ static int uv_probe(void)
16516 return apic == &apic_x2apic_uv_x;
16517 }
16518
16519 -static struct apic __refdata apic_x2apic_uv_x = {
16520 +static struct apic apic_x2apic_uv_x __read_only = {
16521
16522 .name = "UV large system",
16523 .probe = uv_probe,
16524 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16525 index d65464e..1035d31 100644
16526 --- a/arch/x86/kernel/apm_32.c
16527 +++ b/arch/x86/kernel/apm_32.c
16528 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
16529 * This is for buggy BIOS's that refer to (real mode) segment 0x40
16530 * even though they are called in protected mode.
16531 */
16532 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
16533 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
16534 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
16535
16536 static const char driver_version[] = "1.16ac"; /* no spaces */
16537 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
16538 BUG_ON(cpu != 0);
16539 gdt = get_cpu_gdt_table(cpu);
16540 save_desc_40 = gdt[0x40 / 8];
16541 +
16542 + pax_open_kernel();
16543 gdt[0x40 / 8] = bad_bios_desc;
16544 + pax_close_kernel();
16545
16546 apm_irq_save(flags);
16547 APM_DO_SAVE_SEGS;
16548 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
16549 &call->esi);
16550 APM_DO_RESTORE_SEGS;
16551 apm_irq_restore(flags);
16552 +
16553 + pax_open_kernel();
16554 gdt[0x40 / 8] = save_desc_40;
16555 + pax_close_kernel();
16556 +
16557 put_cpu();
16558
16559 return call->eax & 0xff;
16560 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
16561 BUG_ON(cpu != 0);
16562 gdt = get_cpu_gdt_table(cpu);
16563 save_desc_40 = gdt[0x40 / 8];
16564 +
16565 + pax_open_kernel();
16566 gdt[0x40 / 8] = bad_bios_desc;
16567 + pax_close_kernel();
16568
16569 apm_irq_save(flags);
16570 APM_DO_SAVE_SEGS;
16571 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
16572 &call->eax);
16573 APM_DO_RESTORE_SEGS;
16574 apm_irq_restore(flags);
16575 +
16576 + pax_open_kernel();
16577 gdt[0x40 / 8] = save_desc_40;
16578 + pax_close_kernel();
16579 +
16580 put_cpu();
16581 return error;
16582 }
16583 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
16584 * code to that CPU.
16585 */
16586 gdt = get_cpu_gdt_table(0);
16587 +
16588 + pax_open_kernel();
16589 set_desc_base(&gdt[APM_CS >> 3],
16590 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
16591 set_desc_base(&gdt[APM_CS_16 >> 3],
16592 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
16593 set_desc_base(&gdt[APM_DS >> 3],
16594 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
16595 + pax_close_kernel();
16596
16597 proc_create("apm", 0, NULL, &apm_file_ops);
16598
16599 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
16600 index 2861082..6d4718e 100644
16601 --- a/arch/x86/kernel/asm-offsets.c
16602 +++ b/arch/x86/kernel/asm-offsets.c
16603 @@ -33,6 +33,8 @@ void common(void) {
16604 OFFSET(TI_status, thread_info, status);
16605 OFFSET(TI_addr_limit, thread_info, addr_limit);
16606 OFFSET(TI_preempt_count, thread_info, preempt_count);
16607 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
16608 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
16609
16610 BLANK();
16611 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
16612 @@ -53,8 +55,26 @@ void common(void) {
16613 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
16614 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
16615 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
16616 +
16617 +#ifdef CONFIG_PAX_KERNEXEC
16618 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
16619 #endif
16620
16621 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16622 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
16623 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
16624 +#ifdef CONFIG_X86_64
16625 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
16626 +#endif
16627 +#endif
16628 +
16629 +#endif
16630 +
16631 + BLANK();
16632 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
16633 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
16634 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
16635 +
16636 #ifdef CONFIG_XEN
16637 BLANK();
16638 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
16639 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
16640 index 1b4754f..fbb4227 100644
16641 --- a/arch/x86/kernel/asm-offsets_64.c
16642 +++ b/arch/x86/kernel/asm-offsets_64.c
16643 @@ -76,6 +76,7 @@ int main(void)
16644 BLANK();
16645 #undef ENTRY
16646
16647 + DEFINE(TSS_size, sizeof(struct tss_struct));
16648 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
16649 BLANK();
16650
16651 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
16652 index a0e067d..9c7db16 100644
16653 --- a/arch/x86/kernel/cpu/Makefile
16654 +++ b/arch/x86/kernel/cpu/Makefile
16655 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
16656 CFLAGS_REMOVE_perf_event.o = -pg
16657 endif
16658
16659 -# Make sure load_percpu_segment has no stackprotector
16660 -nostackp := $(call cc-option, -fno-stack-protector)
16661 -CFLAGS_common.o := $(nostackp)
16662 -
16663 obj-y := intel_cacheinfo.o scattered.o topology.o
16664 obj-y += proc.o capflags.o powerflags.o common.o
16665 obj-y += vmware.o hypervisor.o mshyperv.o
16666 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
16667 index 15239ff..e23e04e 100644
16668 --- a/arch/x86/kernel/cpu/amd.c
16669 +++ b/arch/x86/kernel/cpu/amd.c
16670 @@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
16671 unsigned int size)
16672 {
16673 /* AMD errata T13 (order #21922) */
16674 - if ((c->x86 == 6)) {
16675 + if (c->x86 == 6) {
16676 /* Duron Rev A0 */
16677 if (c->x86_model == 3 && c->x86_mask == 0)
16678 size = 64;
16679 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
16680 index 9c3ab43..51e6366 100644
16681 --- a/arch/x86/kernel/cpu/common.c
16682 +++ b/arch/x86/kernel/cpu/common.c
16683 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
16684
16685 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
16686
16687 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
16688 -#ifdef CONFIG_X86_64
16689 - /*
16690 - * We need valid kernel segments for data and code in long mode too
16691 - * IRET will check the segment types kkeil 2000/10/28
16692 - * Also sysret mandates a special GDT layout
16693 - *
16694 - * TLS descriptors are currently at a different place compared to i386.
16695 - * Hopefully nobody expects them at a fixed place (Wine?)
16696 - */
16697 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
16698 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
16699 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
16700 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
16701 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
16702 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
16703 -#else
16704 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
16705 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16706 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
16707 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
16708 - /*
16709 - * Segments used for calling PnP BIOS have byte granularity.
16710 - * They code segments and data segments have fixed 64k limits,
16711 - * the transfer segment sizes are set at run time.
16712 - */
16713 - /* 32-bit code */
16714 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16715 - /* 16-bit code */
16716 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16717 - /* 16-bit data */
16718 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
16719 - /* 16-bit data */
16720 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
16721 - /* 16-bit data */
16722 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
16723 - /*
16724 - * The APM segments have byte granularity and their bases
16725 - * are set at run time. All have 64k limits.
16726 - */
16727 - /* 32-bit code */
16728 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16729 - /* 16-bit code */
16730 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16731 - /* data */
16732 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
16733 -
16734 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16735 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16736 - GDT_STACK_CANARY_INIT
16737 -#endif
16738 -} };
16739 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
16740 -
16741 static int __init x86_xsave_setup(char *s)
16742 {
16743 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
16744 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
16745 {
16746 struct desc_ptr gdt_descr;
16747
16748 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
16749 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16750 gdt_descr.size = GDT_SIZE - 1;
16751 load_gdt(&gdt_descr);
16752 /* Reload the per-cpu base */
16753 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
16754 /* Filter out anything that depends on CPUID levels we don't have */
16755 filter_cpuid_features(c, true);
16756
16757 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16758 + setup_clear_cpu_cap(X86_FEATURE_SEP);
16759 +#endif
16760 +
16761 /* If the model name is still unset, do table lookup. */
16762 if (!c->x86_model_id[0]) {
16763 const char *p;
16764 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
16765 }
16766 __setup("clearcpuid=", setup_disablecpuid);
16767
16768 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
16769 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
16770 +
16771 #ifdef CONFIG_X86_64
16772 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
16773 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
16774 - (unsigned long) nmi_idt_table };
16775 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
16776
16777 DEFINE_PER_CPU_FIRST(union irq_stack_union,
16778 irq_stack_union) __aligned(PAGE_SIZE);
16779 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
16780 EXPORT_PER_CPU_SYMBOL(current_task);
16781
16782 DEFINE_PER_CPU(unsigned long, kernel_stack) =
16783 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
16784 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
16785 EXPORT_PER_CPU_SYMBOL(kernel_stack);
16786
16787 DEFINE_PER_CPU(char *, irq_stack_ptr) =
16788 @@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
16789 int i;
16790
16791 cpu = stack_smp_processor_id();
16792 - t = &per_cpu(init_tss, cpu);
16793 + t = init_tss + cpu;
16794 oist = &per_cpu(orig_ist, cpu);
16795
16796 #ifdef CONFIG_NUMA
16797 @@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
16798 switch_to_new_gdt(cpu);
16799 loadsegment(fs, 0);
16800
16801 - load_idt((const struct desc_ptr *)&idt_descr);
16802 + load_idt(&idt_descr);
16803
16804 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
16805 syscall_init();
16806 @@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
16807 wrmsrl(MSR_KERNEL_GS_BASE, 0);
16808 barrier();
16809
16810 - x86_configure_nx();
16811 enable_x2apic();
16812
16813 /*
16814 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
16815 {
16816 int cpu = smp_processor_id();
16817 struct task_struct *curr = current;
16818 - struct tss_struct *t = &per_cpu(init_tss, cpu);
16819 + struct tss_struct *t = init_tss + cpu;
16820 struct thread_struct *thread = &curr->thread;
16821
16822 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
16823 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
16824 index fcaabd0..7b55a26 100644
16825 --- a/arch/x86/kernel/cpu/intel.c
16826 +++ b/arch/x86/kernel/cpu/intel.c
16827 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
16828 * Update the IDT descriptor and reload the IDT so that
16829 * it uses the read-only mapped virtual address.
16830 */
16831 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
16832 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
16833 load_idt(&idt_descr);
16834 }
16835 #endif
16836 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
16837 index 84c1309..39b7224 100644
16838 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
16839 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
16840 @@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
16841 };
16842
16843 #ifdef CONFIG_AMD_NB
16844 +static struct attribute *default_attrs_amd_nb[] = {
16845 + &type.attr,
16846 + &level.attr,
16847 + &coherency_line_size.attr,
16848 + &physical_line_partition.attr,
16849 + &ways_of_associativity.attr,
16850 + &number_of_sets.attr,
16851 + &size.attr,
16852 + &shared_cpu_map.attr,
16853 + &shared_cpu_list.attr,
16854 + NULL,
16855 + NULL,
16856 + NULL,
16857 + NULL
16858 +};
16859 +
16860 static struct attribute ** __cpuinit amd_l3_attrs(void)
16861 {
16862 static struct attribute **attrs;
16863 @@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
16864
16865 n = ARRAY_SIZE(default_attrs);
16866
16867 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
16868 - n += 2;
16869 -
16870 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
16871 - n += 1;
16872 -
16873 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
16874 - if (attrs == NULL)
16875 - return attrs = default_attrs;
16876 -
16877 - for (n = 0; default_attrs[n]; n++)
16878 - attrs[n] = default_attrs[n];
16879 + attrs = default_attrs_amd_nb;
16880
16881 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
16882 attrs[n++] = &cache_disable_0.attr;
16883 @@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
16884 .default_attrs = default_attrs,
16885 };
16886
16887 +#ifdef CONFIG_AMD_NB
16888 +static struct kobj_type ktype_cache_amd_nb = {
16889 + .sysfs_ops = &sysfs_ops,
16890 + .default_attrs = default_attrs_amd_nb,
16891 +};
16892 +#endif
16893 +
16894 static struct kobj_type ktype_percpu_entry = {
16895 .sysfs_ops = &sysfs_ops,
16896 };
16897 @@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
16898 return retval;
16899 }
16900
16901 +#ifdef CONFIG_AMD_NB
16902 + amd_l3_attrs();
16903 +#endif
16904 +
16905 for (i = 0; i < num_cache_leaves; i++) {
16906 + struct kobj_type *ktype;
16907 +
16908 this_object = INDEX_KOBJECT_PTR(cpu, i);
16909 this_object->cpu = cpu;
16910 this_object->index = i;
16911
16912 this_leaf = CPUID4_INFO_IDX(cpu, i);
16913
16914 - ktype_cache.default_attrs = default_attrs;
16915 + ktype = &ktype_cache;
16916 #ifdef CONFIG_AMD_NB
16917 if (this_leaf->base.nb)
16918 - ktype_cache.default_attrs = amd_l3_attrs();
16919 + ktype = &ktype_cache_amd_nb;
16920 #endif
16921 retval = kobject_init_and_add(&(this_object->kobj),
16922 - &ktype_cache,
16923 + ktype,
16924 per_cpu(ici_cache_kobject, cpu),
16925 "index%1lu", i);
16926 if (unlikely(retval)) {
16927 @@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
16928 return NOTIFY_OK;
16929 }
16930
16931 -static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
16932 +static struct notifier_block cacheinfo_cpu_notifier = {
16933 .notifier_call = cacheinfo_cpu_callback,
16934 };
16935
16936 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
16937 index 80dbda8..be16652 100644
16938 --- a/arch/x86/kernel/cpu/mcheck/mce.c
16939 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
16940 @@ -45,6 +45,7 @@
16941 #include <asm/processor.h>
16942 #include <asm/mce.h>
16943 #include <asm/msr.h>
16944 +#include <asm/local.h>
16945
16946 #include "mce-internal.h"
16947
16948 @@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
16949 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
16950 m->cs, m->ip);
16951
16952 - if (m->cs == __KERNEL_CS)
16953 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
16954 print_symbol("{%s}", m->ip);
16955 pr_cont("\n");
16956 }
16957 @@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
16958
16959 #define PANIC_TIMEOUT 5 /* 5 seconds */
16960
16961 -static atomic_t mce_paniced;
16962 +static atomic_unchecked_t mce_paniced;
16963
16964 static int fake_panic;
16965 -static atomic_t mce_fake_paniced;
16966 +static atomic_unchecked_t mce_fake_paniced;
16967
16968 /* Panic in progress. Enable interrupts and wait for final IPI */
16969 static void wait_for_panic(void)
16970 @@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
16971 /*
16972 * Make sure only one CPU runs in machine check panic
16973 */
16974 - if (atomic_inc_return(&mce_paniced) > 1)
16975 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
16976 wait_for_panic();
16977 barrier();
16978
16979 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
16980 console_verbose();
16981 } else {
16982 /* Don't log too much for fake panic */
16983 - if (atomic_inc_return(&mce_fake_paniced) > 1)
16984 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
16985 return;
16986 }
16987 /* First print corrected ones that are still unlogged */
16988 @@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
16989 * might have been modified by someone else.
16990 */
16991 rmb();
16992 - if (atomic_read(&mce_paniced))
16993 + if (atomic_read_unchecked(&mce_paniced))
16994 wait_for_panic();
16995 if (!mca_cfg.monarch_timeout)
16996 goto out;
16997 @@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
16998 }
16999
17000 /* Call the installed machine check handler for this CPU setup. */
17001 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
17002 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17003 unexpected_machine_check;
17004
17005 /*
17006 @@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17007 return;
17008 }
17009
17010 + pax_open_kernel();
17011 machine_check_vector = do_machine_check;
17012 + pax_close_kernel();
17013
17014 __mcheck_cpu_init_generic();
17015 __mcheck_cpu_init_vendor(c);
17016 @@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17017 */
17018
17019 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17020 -static int mce_chrdev_open_count; /* #times opened */
17021 +static local_t mce_chrdev_open_count; /* #times opened */
17022 static int mce_chrdev_open_exclu; /* already open exclusive? */
17023
17024 static int mce_chrdev_open(struct inode *inode, struct file *file)
17025 @@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17026 spin_lock(&mce_chrdev_state_lock);
17027
17028 if (mce_chrdev_open_exclu ||
17029 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17030 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17031 spin_unlock(&mce_chrdev_state_lock);
17032
17033 return -EBUSY;
17034 @@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17035
17036 if (file->f_flags & O_EXCL)
17037 mce_chrdev_open_exclu = 1;
17038 - mce_chrdev_open_count++;
17039 + local_inc(&mce_chrdev_open_count);
17040
17041 spin_unlock(&mce_chrdev_state_lock);
17042
17043 @@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17044 {
17045 spin_lock(&mce_chrdev_state_lock);
17046
17047 - mce_chrdev_open_count--;
17048 + local_dec(&mce_chrdev_open_count);
17049 mce_chrdev_open_exclu = 0;
17050
17051 spin_unlock(&mce_chrdev_state_lock);
17052 @@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17053 return NOTIFY_OK;
17054 }
17055
17056 -static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17057 +static struct notifier_block mce_cpu_notifier = {
17058 .notifier_call = mce_cpu_callback,
17059 };
17060
17061 @@ -2382,7 +2385,7 @@ static __init void mce_init_banks(void)
17062
17063 for (i = 0; i < mca_cfg.banks; i++) {
17064 struct mce_bank *b = &mce_banks[i];
17065 - struct device_attribute *a = &b->attr;
17066 + device_attribute_no_const *a = &b->attr;
17067
17068 sysfs_attr_init(&a->attr);
17069 a->attr.name = b->attrname;
17070 @@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
17071 static void mce_reset(void)
17072 {
17073 cpu_missing = 0;
17074 - atomic_set(&mce_fake_paniced, 0);
17075 + atomic_set_unchecked(&mce_fake_paniced, 0);
17076 atomic_set(&mce_executing, 0);
17077 atomic_set(&mce_callin, 0);
17078 atomic_set(&global_nwo, 0);
17079 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17080 index 2d5454c..51987eb 100644
17081 --- a/arch/x86/kernel/cpu/mcheck/p5.c
17082 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
17083 @@ -11,6 +11,7 @@
17084 #include <asm/processor.h>
17085 #include <asm/mce.h>
17086 #include <asm/msr.h>
17087 +#include <asm/pgtable.h>
17088
17089 /* By default disabled */
17090 int mce_p5_enabled __read_mostly;
17091 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17092 if (!cpu_has(c, X86_FEATURE_MCE))
17093 return;
17094
17095 + pax_open_kernel();
17096 machine_check_vector = pentium_machine_check;
17097 + pax_close_kernel();
17098 /* Make sure the vector pointer is visible before we enable MCEs: */
17099 wmb();
17100
17101 diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17102 index 47a1870..8c019a7 100644
17103 --- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17104 +++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17105 @@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17106 return notifier_from_errno(err);
17107 }
17108
17109 -static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17110 +static struct notifier_block thermal_throttle_cpu_notifier =
17111 {
17112 .notifier_call = thermal_throttle_cpu_callback,
17113 };
17114 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17115 index 2d7998f..17c9de1 100644
17116 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
17117 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17118 @@ -10,6 +10,7 @@
17119 #include <asm/processor.h>
17120 #include <asm/mce.h>
17121 #include <asm/msr.h>
17122 +#include <asm/pgtable.h>
17123
17124 /* Machine check handler for WinChip C6: */
17125 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17126 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17127 {
17128 u32 lo, hi;
17129
17130 + pax_open_kernel();
17131 machine_check_vector = winchip_machine_check;
17132 + pax_close_kernel();
17133 /* Make sure the vector pointer is visible before we enable MCEs: */
17134 wmb();
17135
17136 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17137 index 726bf96..81f0526 100644
17138 --- a/arch/x86/kernel/cpu/mtrr/main.c
17139 +++ b/arch/x86/kernel/cpu/mtrr/main.c
17140 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17141 u64 size_or_mask, size_and_mask;
17142 static bool mtrr_aps_delayed_init;
17143
17144 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17145 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17146
17147 const struct mtrr_ops *mtrr_if;
17148
17149 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17150 index df5e41f..816c719 100644
17151 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17152 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17153 @@ -25,7 +25,7 @@ struct mtrr_ops {
17154 int (*validate_add_page)(unsigned long base, unsigned long size,
17155 unsigned int type);
17156 int (*have_wrcomb)(void);
17157 -};
17158 +} __do_const;
17159
17160 extern int generic_get_free_region(unsigned long base, unsigned long size,
17161 int replace_reg);
17162 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17163 index 6774c17..72c1b22 100644
17164 --- a/arch/x86/kernel/cpu/perf_event.c
17165 +++ b/arch/x86/kernel/cpu/perf_event.c
17166 @@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17167 pr_info("no hardware sampling interrupt available.\n");
17168 }
17169
17170 -static struct attribute_group x86_pmu_format_group = {
17171 +static attribute_group_no_const x86_pmu_format_group = {
17172 .name = "format",
17173 .attrs = NULL,
17174 };
17175 @@ -1313,7 +1313,7 @@ static struct attribute_group x86_pmu_format_group = {
17176 struct perf_pmu_events_attr {
17177 struct device_attribute attr;
17178 u64 id;
17179 -};
17180 +} __do_const;
17181
17182 /*
17183 * Remove all undefined events (x86_pmu.event_map(id) == 0)
17184 @@ -1381,7 +1381,7 @@ static struct attribute *events_attr[] = {
17185 NULL,
17186 };
17187
17188 -static struct attribute_group x86_pmu_events_group = {
17189 +static attribute_group_no_const x86_pmu_events_group = {
17190 .name = "events",
17191 .attrs = events_attr,
17192 };
17193 @@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17194 if (idx > GDT_ENTRIES)
17195 return 0;
17196
17197 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17198 + desc = get_cpu_gdt_table(smp_processor_id());
17199 }
17200
17201 return get_desc_base(desc + idx);
17202 @@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17203 break;
17204
17205 perf_callchain_store(entry, frame.return_address);
17206 - fp = frame.next_frame;
17207 + fp = (const void __force_user *)frame.next_frame;
17208 }
17209 }
17210
17211 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17212 index 4914e94..60b06e3 100644
17213 --- a/arch/x86/kernel/cpu/perf_event_intel.c
17214 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
17215 @@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17216 * v2 and above have a perf capabilities MSR
17217 */
17218 if (version > 1) {
17219 - u64 capabilities;
17220 + u64 capabilities = x86_pmu.intel_cap.capabilities;
17221
17222 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17223 - x86_pmu.intel_cap.capabilities = capabilities;
17224 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17225 + x86_pmu.intel_cap.capabilities = capabilities;
17226 }
17227
17228 intel_ds_init();
17229 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17230 index b43200d..7fdcdbb 100644
17231 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17232 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17233 @@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17234 static int __init uncore_type_init(struct intel_uncore_type *type)
17235 {
17236 struct intel_uncore_pmu *pmus;
17237 - struct attribute_group *events_group;
17238 + attribute_group_no_const *events_group;
17239 struct attribute **attrs;
17240 int i, j;
17241
17242 @@ -2826,7 +2826,7 @@ static int
17243 return NOTIFY_OK;
17244 }
17245
17246 -static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17247 +static struct notifier_block uncore_cpu_nb = {
17248 .notifier_call = uncore_cpu_notifier,
17249 /*
17250 * to migrate uncore events, our notifier should be executed
17251 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17252 index e68a455..975a932 100644
17253 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17254 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17255 @@ -428,7 +428,7 @@ struct intel_uncore_box {
17256 struct uncore_event_desc {
17257 struct kobj_attribute attr;
17258 const char *config;
17259 -};
17260 +} __do_const;
17261
17262 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17263 { \
17264 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17265 index 60c7891..9e911d3 100644
17266 --- a/arch/x86/kernel/cpuid.c
17267 +++ b/arch/x86/kernel/cpuid.c
17268 @@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17269 return notifier_from_errno(err);
17270 }
17271
17272 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
17273 +static struct notifier_block cpuid_class_cpu_notifier =
17274 {
17275 .notifier_call = cpuid_class_cpu_callback,
17276 };
17277 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17278 index 74467fe..18793d5 100644
17279 --- a/arch/x86/kernel/crash.c
17280 +++ b/arch/x86/kernel/crash.c
17281 @@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17282 {
17283 #ifdef CONFIG_X86_32
17284 struct pt_regs fixed_regs;
17285 -#endif
17286
17287 -#ifdef CONFIG_X86_32
17288 - if (!user_mode_vm(regs)) {
17289 + if (!user_mode(regs)) {
17290 crash_fixup_ss_esp(&fixed_regs, regs);
17291 regs = &fixed_regs;
17292 }
17293 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17294 index 37250fe..bf2ec74 100644
17295 --- a/arch/x86/kernel/doublefault_32.c
17296 +++ b/arch/x86/kernel/doublefault_32.c
17297 @@ -11,7 +11,7 @@
17298
17299 #define DOUBLEFAULT_STACKSIZE (1024)
17300 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17301 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17302 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17303
17304 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17305
17306 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
17307 unsigned long gdt, tss;
17308
17309 store_gdt(&gdt_desc);
17310 - gdt = gdt_desc.address;
17311 + gdt = (unsigned long)gdt_desc.address;
17312
17313 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17314
17315 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17316 /* 0x2 bit is always set */
17317 .flags = X86_EFLAGS_SF | 0x2,
17318 .sp = STACK_START,
17319 - .es = __USER_DS,
17320 + .es = __KERNEL_DS,
17321 .cs = __KERNEL_CS,
17322 .ss = __KERNEL_DS,
17323 - .ds = __USER_DS,
17324 + .ds = __KERNEL_DS,
17325 .fs = __KERNEL_PERCPU,
17326
17327 .__cr3 = __pa_nodebug(swapper_pg_dir),
17328 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17329 index ae42418b..787c16b 100644
17330 --- a/arch/x86/kernel/dumpstack.c
17331 +++ b/arch/x86/kernel/dumpstack.c
17332 @@ -2,6 +2,9 @@
17333 * Copyright (C) 1991, 1992 Linus Torvalds
17334 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17335 */
17336 +#ifdef CONFIG_GRKERNSEC_HIDESYM
17337 +#define __INCLUDED_BY_HIDESYM 1
17338 +#endif
17339 #include <linux/kallsyms.h>
17340 #include <linux/kprobes.h>
17341 #include <linux/uaccess.h>
17342 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17343 static void
17344 print_ftrace_graph_addr(unsigned long addr, void *data,
17345 const struct stacktrace_ops *ops,
17346 - struct thread_info *tinfo, int *graph)
17347 + struct task_struct *task, int *graph)
17348 {
17349 - struct task_struct *task;
17350 unsigned long ret_addr;
17351 int index;
17352
17353 if (addr != (unsigned long)return_to_handler)
17354 return;
17355
17356 - task = tinfo->task;
17357 index = task->curr_ret_stack;
17358
17359 if (!task->ret_stack || index < *graph)
17360 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17361 static inline void
17362 print_ftrace_graph_addr(unsigned long addr, void *data,
17363 const struct stacktrace_ops *ops,
17364 - struct thread_info *tinfo, int *graph)
17365 + struct task_struct *task, int *graph)
17366 { }
17367 #endif
17368
17369 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17370 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17371 */
17372
17373 -static inline int valid_stack_ptr(struct thread_info *tinfo,
17374 - void *p, unsigned int size, void *end)
17375 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17376 {
17377 - void *t = tinfo;
17378 if (end) {
17379 if (p < end && p >= (end-THREAD_SIZE))
17380 return 1;
17381 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17382 }
17383
17384 unsigned long
17385 -print_context_stack(struct thread_info *tinfo,
17386 +print_context_stack(struct task_struct *task, void *stack_start,
17387 unsigned long *stack, unsigned long bp,
17388 const struct stacktrace_ops *ops, void *data,
17389 unsigned long *end, int *graph)
17390 {
17391 struct stack_frame *frame = (struct stack_frame *)bp;
17392
17393 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17394 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17395 unsigned long addr;
17396
17397 addr = *stack;
17398 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17399 } else {
17400 ops->address(data, addr, 0);
17401 }
17402 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17403 + print_ftrace_graph_addr(addr, data, ops, task, graph);
17404 }
17405 stack++;
17406 }
17407 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17408 EXPORT_SYMBOL_GPL(print_context_stack);
17409
17410 unsigned long
17411 -print_context_stack_bp(struct thread_info *tinfo,
17412 +print_context_stack_bp(struct task_struct *task, void *stack_start,
17413 unsigned long *stack, unsigned long bp,
17414 const struct stacktrace_ops *ops, void *data,
17415 unsigned long *end, int *graph)
17416 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17417 struct stack_frame *frame = (struct stack_frame *)bp;
17418 unsigned long *ret_addr = &frame->return_address;
17419
17420 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17421 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17422 unsigned long addr = *ret_addr;
17423
17424 if (!__kernel_text_address(addr))
17425 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17426 ops->address(data, addr, 1);
17427 frame = frame->next_frame;
17428 ret_addr = &frame->return_address;
17429 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17430 + print_ftrace_graph_addr(addr, data, ops, task, graph);
17431 }
17432
17433 return (unsigned long)frame;
17434 @@ -189,7 +188,7 @@ void dump_stack(void)
17435
17436 bp = stack_frame(current, NULL);
17437 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17438 - current->pid, current->comm, print_tainted(),
17439 + task_pid_nr(current), current->comm, print_tainted(),
17440 init_utsname()->release,
17441 (int)strcspn(init_utsname()->version, " "),
17442 init_utsname()->version);
17443 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17444 }
17445 EXPORT_SYMBOL_GPL(oops_begin);
17446
17447 +extern void gr_handle_kernel_exploit(void);
17448 +
17449 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17450 {
17451 if (regs && kexec_should_crash(current))
17452 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17453 panic("Fatal exception in interrupt");
17454 if (panic_on_oops)
17455 panic("Fatal exception");
17456 - do_exit(signr);
17457 +
17458 + gr_handle_kernel_exploit();
17459 +
17460 + do_group_exit(signr);
17461 }
17462
17463 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17464 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17465 print_modules();
17466 show_regs(regs);
17467 #ifdef CONFIG_X86_32
17468 - if (user_mode_vm(regs)) {
17469 + if (user_mode(regs)) {
17470 sp = regs->sp;
17471 ss = regs->ss & 0xffff;
17472 } else {
17473 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17474 unsigned long flags = oops_begin();
17475 int sig = SIGSEGV;
17476
17477 - if (!user_mode_vm(regs))
17478 + if (!user_mode(regs))
17479 report_bug(regs->ip, regs);
17480
17481 if (__die(str, regs, err))
17482 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17483 index 1038a41..db2c12b 100644
17484 --- a/arch/x86/kernel/dumpstack_32.c
17485 +++ b/arch/x86/kernel/dumpstack_32.c
17486 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17487 bp = stack_frame(task, regs);
17488
17489 for (;;) {
17490 - struct thread_info *context;
17491 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17492
17493 - context = (struct thread_info *)
17494 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17495 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17496 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17497
17498 - stack = (unsigned long *)context->previous_esp;
17499 - if (!stack)
17500 + if (stack_start == task_stack_page(task))
17501 break;
17502 + stack = *(unsigned long **)stack_start;
17503 if (ops->stack(data, "IRQ") < 0)
17504 break;
17505 touch_nmi_watchdog();
17506 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17507 {
17508 int i;
17509
17510 - __show_regs(regs, !user_mode_vm(regs));
17511 + __show_regs(regs, !user_mode(regs));
17512
17513 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17514 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17515 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17516 * When in-kernel, we also print out the stack and code at the
17517 * time of the fault..
17518 */
17519 - if (!user_mode_vm(regs)) {
17520 + if (!user_mode(regs)) {
17521 unsigned int code_prologue = code_bytes * 43 / 64;
17522 unsigned int code_len = code_bytes;
17523 unsigned char c;
17524 u8 *ip;
17525 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
17526
17527 pr_emerg("Stack:\n");
17528 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
17529
17530 pr_emerg("Code:");
17531
17532 - ip = (u8 *)regs->ip - code_prologue;
17533 + ip = (u8 *)regs->ip - code_prologue + cs_base;
17534 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
17535 /* try starting at IP */
17536 - ip = (u8 *)regs->ip;
17537 + ip = (u8 *)regs->ip + cs_base;
17538 code_len = code_len - code_prologue + 1;
17539 }
17540 for (i = 0; i < code_len; i++, ip++) {
17541 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
17542 pr_cont(" Bad EIP value.");
17543 break;
17544 }
17545 - if (ip == (u8 *)regs->ip)
17546 + if (ip == (u8 *)regs->ip + cs_base)
17547 pr_cont(" <%02x>", c);
17548 else
17549 pr_cont(" %02x", c);
17550 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
17551 {
17552 unsigned short ud2;
17553
17554 + ip = ktla_ktva(ip);
17555 if (ip < PAGE_OFFSET)
17556 return 0;
17557 if (probe_kernel_address((unsigned short *)ip, ud2))
17558 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
17559
17560 return ud2 == 0x0b0f;
17561 }
17562 +
17563 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17564 +void pax_check_alloca(unsigned long size)
17565 +{
17566 + unsigned long sp = (unsigned long)&sp, stack_left;
17567 +
17568 + /* all kernel stacks are of the same size */
17569 + stack_left = sp & (THREAD_SIZE - 1);
17570 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17571 +}
17572 +EXPORT_SYMBOL(pax_check_alloca);
17573 +#endif
17574 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
17575 index b653675..51cc8c0 100644
17576 --- a/arch/x86/kernel/dumpstack_64.c
17577 +++ b/arch/x86/kernel/dumpstack_64.c
17578 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17579 unsigned long *irq_stack_end =
17580 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
17581 unsigned used = 0;
17582 - struct thread_info *tinfo;
17583 int graph = 0;
17584 unsigned long dummy;
17585 + void *stack_start;
17586
17587 if (!task)
17588 task = current;
17589 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17590 * current stack address. If the stacks consist of nested
17591 * exceptions
17592 */
17593 - tinfo = task_thread_info(task);
17594 for (;;) {
17595 char *id;
17596 unsigned long *estack_end;
17597 +
17598 estack_end = in_exception_stack(cpu, (unsigned long)stack,
17599 &used, &id);
17600
17601 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17602 if (ops->stack(data, id) < 0)
17603 break;
17604
17605 - bp = ops->walk_stack(tinfo, stack, bp, ops,
17606 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
17607 data, estack_end, &graph);
17608 ops->stack(data, "<EOE>");
17609 /*
17610 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17611 * second-to-last pointer (index -2 to end) in the
17612 * exception stack:
17613 */
17614 + if ((u16)estack_end[-1] != __KERNEL_DS)
17615 + goto out;
17616 stack = (unsigned long *) estack_end[-2];
17617 continue;
17618 }
17619 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17620 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
17621 if (ops->stack(data, "IRQ") < 0)
17622 break;
17623 - bp = ops->walk_stack(tinfo, stack, bp,
17624 + bp = ops->walk_stack(task, irq_stack, stack, bp,
17625 ops, data, irq_stack_end, &graph);
17626 /*
17627 * We link to the next stack (which would be
17628 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17629 /*
17630 * This handles the process stack:
17631 */
17632 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
17633 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17634 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17635 +out:
17636 put_cpu();
17637 }
17638 EXPORT_SYMBOL(dump_trace);
17639 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
17640 {
17641 int i;
17642 unsigned long sp;
17643 - const int cpu = smp_processor_id();
17644 + const int cpu = raw_smp_processor_id();
17645 struct task_struct *cur = current;
17646
17647 sp = regs->sp;
17648 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
17649
17650 return ud2 == 0x0b0f;
17651 }
17652 +
17653 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17654 +void pax_check_alloca(unsigned long size)
17655 +{
17656 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
17657 + unsigned cpu, used;
17658 + char *id;
17659 +
17660 + /* check the process stack first */
17661 + stack_start = (unsigned long)task_stack_page(current);
17662 + stack_end = stack_start + THREAD_SIZE;
17663 + if (likely(stack_start <= sp && sp < stack_end)) {
17664 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
17665 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17666 + return;
17667 + }
17668 +
17669 + cpu = get_cpu();
17670 +
17671 + /* check the irq stacks */
17672 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
17673 + stack_start = stack_end - IRQ_STACK_SIZE;
17674 + if (stack_start <= sp && sp < stack_end) {
17675 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
17676 + put_cpu();
17677 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17678 + return;
17679 + }
17680 +
17681 + /* check the exception stacks */
17682 + used = 0;
17683 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
17684 + stack_start = stack_end - EXCEPTION_STKSZ;
17685 + if (stack_end && stack_start <= sp && sp < stack_end) {
17686 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
17687 + put_cpu();
17688 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17689 + return;
17690 + }
17691 +
17692 + put_cpu();
17693 +
17694 + /* unknown stack */
17695 + BUG();
17696 +}
17697 +EXPORT_SYMBOL(pax_check_alloca);
17698 +#endif
17699 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
17700 index 9b9f18b..9fcaa04 100644
17701 --- a/arch/x86/kernel/early_printk.c
17702 +++ b/arch/x86/kernel/early_printk.c
17703 @@ -7,6 +7,7 @@
17704 #include <linux/pci_regs.h>
17705 #include <linux/pci_ids.h>
17706 #include <linux/errno.h>
17707 +#include <linux/sched.h>
17708 #include <asm/io.h>
17709 #include <asm/processor.h>
17710 #include <asm/fcntl.h>
17711 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
17712 index 6ed91d9..6cc365b 100644
17713 --- a/arch/x86/kernel/entry_32.S
17714 +++ b/arch/x86/kernel/entry_32.S
17715 @@ -177,13 +177,153 @@
17716 /*CFI_REL_OFFSET gs, PT_GS*/
17717 .endm
17718 .macro SET_KERNEL_GS reg
17719 +
17720 +#ifdef CONFIG_CC_STACKPROTECTOR
17721 movl $(__KERNEL_STACK_CANARY), \reg
17722 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17723 + movl $(__USER_DS), \reg
17724 +#else
17725 + xorl \reg, \reg
17726 +#endif
17727 +
17728 movl \reg, %gs
17729 .endm
17730
17731 #endif /* CONFIG_X86_32_LAZY_GS */
17732
17733 -.macro SAVE_ALL
17734 +.macro pax_enter_kernel
17735 +#ifdef CONFIG_PAX_KERNEXEC
17736 + call pax_enter_kernel
17737 +#endif
17738 +.endm
17739 +
17740 +.macro pax_exit_kernel
17741 +#ifdef CONFIG_PAX_KERNEXEC
17742 + call pax_exit_kernel
17743 +#endif
17744 +.endm
17745 +
17746 +#ifdef CONFIG_PAX_KERNEXEC
17747 +ENTRY(pax_enter_kernel)
17748 +#ifdef CONFIG_PARAVIRT
17749 + pushl %eax
17750 + pushl %ecx
17751 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
17752 + mov %eax, %esi
17753 +#else
17754 + mov %cr0, %esi
17755 +#endif
17756 + bts $16, %esi
17757 + jnc 1f
17758 + mov %cs, %esi
17759 + cmp $__KERNEL_CS, %esi
17760 + jz 3f
17761 + ljmp $__KERNEL_CS, $3f
17762 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
17763 +2:
17764 +#ifdef CONFIG_PARAVIRT
17765 + mov %esi, %eax
17766 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17767 +#else
17768 + mov %esi, %cr0
17769 +#endif
17770 +3:
17771 +#ifdef CONFIG_PARAVIRT
17772 + popl %ecx
17773 + popl %eax
17774 +#endif
17775 + ret
17776 +ENDPROC(pax_enter_kernel)
17777 +
17778 +ENTRY(pax_exit_kernel)
17779 +#ifdef CONFIG_PARAVIRT
17780 + pushl %eax
17781 + pushl %ecx
17782 +#endif
17783 + mov %cs, %esi
17784 + cmp $__KERNEXEC_KERNEL_CS, %esi
17785 + jnz 2f
17786 +#ifdef CONFIG_PARAVIRT
17787 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
17788 + mov %eax, %esi
17789 +#else
17790 + mov %cr0, %esi
17791 +#endif
17792 + btr $16, %esi
17793 + ljmp $__KERNEL_CS, $1f
17794 +1:
17795 +#ifdef CONFIG_PARAVIRT
17796 + mov %esi, %eax
17797 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
17798 +#else
17799 + mov %esi, %cr0
17800 +#endif
17801 +2:
17802 +#ifdef CONFIG_PARAVIRT
17803 + popl %ecx
17804 + popl %eax
17805 +#endif
17806 + ret
17807 +ENDPROC(pax_exit_kernel)
17808 +#endif
17809 +
17810 +.macro pax_erase_kstack
17811 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17812 + call pax_erase_kstack
17813 +#endif
17814 +.endm
17815 +
17816 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17817 +/*
17818 + * ebp: thread_info
17819 + */
17820 +ENTRY(pax_erase_kstack)
17821 + pushl %edi
17822 + pushl %ecx
17823 + pushl %eax
17824 +
17825 + mov TI_lowest_stack(%ebp), %edi
17826 + mov $-0xBEEF, %eax
17827 + std
17828 +
17829 +1: mov %edi, %ecx
17830 + and $THREAD_SIZE_asm - 1, %ecx
17831 + shr $2, %ecx
17832 + repne scasl
17833 + jecxz 2f
17834 +
17835 + cmp $2*16, %ecx
17836 + jc 2f
17837 +
17838 + mov $2*16, %ecx
17839 + repe scasl
17840 + jecxz 2f
17841 + jne 1b
17842 +
17843 +2: cld
17844 + mov %esp, %ecx
17845 + sub %edi, %ecx
17846 +
17847 + cmp $THREAD_SIZE_asm, %ecx
17848 + jb 3f
17849 + ud2
17850 +3:
17851 +
17852 + shr $2, %ecx
17853 + rep stosl
17854 +
17855 + mov TI_task_thread_sp0(%ebp), %edi
17856 + sub $128, %edi
17857 + mov %edi, TI_lowest_stack(%ebp)
17858 +
17859 + popl %eax
17860 + popl %ecx
17861 + popl %edi
17862 + ret
17863 +ENDPROC(pax_erase_kstack)
17864 +#endif
17865 +
17866 +.macro __SAVE_ALL _DS
17867 cld
17868 PUSH_GS
17869 pushl_cfi %fs
17870 @@ -206,7 +346,7 @@
17871 CFI_REL_OFFSET ecx, 0
17872 pushl_cfi %ebx
17873 CFI_REL_OFFSET ebx, 0
17874 - movl $(__USER_DS), %edx
17875 + movl $\_DS, %edx
17876 movl %edx, %ds
17877 movl %edx, %es
17878 movl $(__KERNEL_PERCPU), %edx
17879 @@ -214,6 +354,15 @@
17880 SET_KERNEL_GS %edx
17881 .endm
17882
17883 +.macro SAVE_ALL
17884 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
17885 + __SAVE_ALL __KERNEL_DS
17886 + pax_enter_kernel
17887 +#else
17888 + __SAVE_ALL __USER_DS
17889 +#endif
17890 +.endm
17891 +
17892 .macro RESTORE_INT_REGS
17893 popl_cfi %ebx
17894 CFI_RESTORE ebx
17895 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
17896 popfl_cfi
17897 jmp syscall_exit
17898 CFI_ENDPROC
17899 -END(ret_from_fork)
17900 +ENDPROC(ret_from_fork)
17901
17902 ENTRY(ret_from_kernel_thread)
17903 CFI_STARTPROC
17904 @@ -344,7 +493,15 @@ ret_from_intr:
17905 andl $SEGMENT_RPL_MASK, %eax
17906 #endif
17907 cmpl $USER_RPL, %eax
17908 +
17909 +#ifdef CONFIG_PAX_KERNEXEC
17910 + jae resume_userspace
17911 +
17912 + pax_exit_kernel
17913 + jmp resume_kernel
17914 +#else
17915 jb resume_kernel # not returning to v8086 or userspace
17916 +#endif
17917
17918 ENTRY(resume_userspace)
17919 LOCKDEP_SYS_EXIT
17920 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
17921 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
17922 # int/exception return?
17923 jne work_pending
17924 - jmp restore_all
17925 -END(ret_from_exception)
17926 + jmp restore_all_pax
17927 +ENDPROC(ret_from_exception)
17928
17929 #ifdef CONFIG_PREEMPT
17930 ENTRY(resume_kernel)
17931 @@ -372,7 +529,7 @@ need_resched:
17932 jz restore_all
17933 call preempt_schedule_irq
17934 jmp need_resched
17935 -END(resume_kernel)
17936 +ENDPROC(resume_kernel)
17937 #endif
17938 CFI_ENDPROC
17939 /*
17940 @@ -406,30 +563,45 @@ sysenter_past_esp:
17941 /*CFI_REL_OFFSET cs, 0*/
17942 /*
17943 * Push current_thread_info()->sysenter_return to the stack.
17944 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
17945 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
17946 */
17947 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
17948 + pushl_cfi $0
17949 CFI_REL_OFFSET eip, 0
17950
17951 pushl_cfi %eax
17952 SAVE_ALL
17953 + GET_THREAD_INFO(%ebp)
17954 + movl TI_sysenter_return(%ebp),%ebp
17955 + movl %ebp,PT_EIP(%esp)
17956 ENABLE_INTERRUPTS(CLBR_NONE)
17957
17958 /*
17959 * Load the potential sixth argument from user stack.
17960 * Careful about security.
17961 */
17962 + movl PT_OLDESP(%esp),%ebp
17963 +
17964 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17965 + mov PT_OLDSS(%esp),%ds
17966 +1: movl %ds:(%ebp),%ebp
17967 + push %ss
17968 + pop %ds
17969 +#else
17970 cmpl $__PAGE_OFFSET-3,%ebp
17971 jae syscall_fault
17972 ASM_STAC
17973 1: movl (%ebp),%ebp
17974 ASM_CLAC
17975 +#endif
17976 +
17977 movl %ebp,PT_EBP(%esp)
17978 _ASM_EXTABLE(1b,syscall_fault)
17979
17980 GET_THREAD_INFO(%ebp)
17981
17982 +#ifdef CONFIG_PAX_RANDKSTACK
17983 + pax_erase_kstack
17984 +#endif
17985 +
17986 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
17987 jnz sysenter_audit
17988 sysenter_do_call:
17989 @@ -444,12 +616,24 @@ sysenter_do_call:
17990 testl $_TIF_ALLWORK_MASK, %ecx
17991 jne sysexit_audit
17992 sysenter_exit:
17993 +
17994 +#ifdef CONFIG_PAX_RANDKSTACK
17995 + pushl_cfi %eax
17996 + movl %esp, %eax
17997 + call pax_randomize_kstack
17998 + popl_cfi %eax
17999 +#endif
18000 +
18001 + pax_erase_kstack
18002 +
18003 /* if something modifies registers it must also disable sysexit */
18004 movl PT_EIP(%esp), %edx
18005 movl PT_OLDESP(%esp), %ecx
18006 xorl %ebp,%ebp
18007 TRACE_IRQS_ON
18008 1: mov PT_FS(%esp), %fs
18009 +2: mov PT_DS(%esp), %ds
18010 +3: mov PT_ES(%esp), %es
18011 PTGS_TO_GS
18012 ENABLE_INTERRUPTS_SYSEXIT
18013
18014 @@ -466,6 +650,9 @@ sysenter_audit:
18015 movl %eax,%edx /* 2nd arg: syscall number */
18016 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18017 call __audit_syscall_entry
18018 +
18019 + pax_erase_kstack
18020 +
18021 pushl_cfi %ebx
18022 movl PT_EAX(%esp),%eax /* reload syscall number */
18023 jmp sysenter_do_call
18024 @@ -491,10 +678,16 @@ sysexit_audit:
18025
18026 CFI_ENDPROC
18027 .pushsection .fixup,"ax"
18028 -2: movl $0,PT_FS(%esp)
18029 +4: movl $0,PT_FS(%esp)
18030 + jmp 1b
18031 +5: movl $0,PT_DS(%esp)
18032 + jmp 1b
18033 +6: movl $0,PT_ES(%esp)
18034 jmp 1b
18035 .popsection
18036 - _ASM_EXTABLE(1b,2b)
18037 + _ASM_EXTABLE(1b,4b)
18038 + _ASM_EXTABLE(2b,5b)
18039 + _ASM_EXTABLE(3b,6b)
18040 PTGS_TO_GS_EX
18041 ENDPROC(ia32_sysenter_target)
18042
18043 @@ -509,6 +702,11 @@ ENTRY(system_call)
18044 pushl_cfi %eax # save orig_eax
18045 SAVE_ALL
18046 GET_THREAD_INFO(%ebp)
18047 +
18048 +#ifdef CONFIG_PAX_RANDKSTACK
18049 + pax_erase_kstack
18050 +#endif
18051 +
18052 # system call tracing in operation / emulation
18053 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18054 jnz syscall_trace_entry
18055 @@ -527,6 +725,15 @@ syscall_exit:
18056 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18057 jne syscall_exit_work
18058
18059 +restore_all_pax:
18060 +
18061 +#ifdef CONFIG_PAX_RANDKSTACK
18062 + movl %esp, %eax
18063 + call pax_randomize_kstack
18064 +#endif
18065 +
18066 + pax_erase_kstack
18067 +
18068 restore_all:
18069 TRACE_IRQS_IRET
18070 restore_all_notrace:
18071 @@ -583,14 +790,34 @@ ldt_ss:
18072 * compensating for the offset by changing to the ESPFIX segment with
18073 * a base address that matches for the difference.
18074 */
18075 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18076 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18077 mov %esp, %edx /* load kernel esp */
18078 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18079 mov %dx, %ax /* eax: new kernel esp */
18080 sub %eax, %edx /* offset (low word is 0) */
18081 +#ifdef CONFIG_SMP
18082 + movl PER_CPU_VAR(cpu_number), %ebx
18083 + shll $PAGE_SHIFT_asm, %ebx
18084 + addl $cpu_gdt_table, %ebx
18085 +#else
18086 + movl $cpu_gdt_table, %ebx
18087 +#endif
18088 shr $16, %edx
18089 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18090 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18091 +
18092 +#ifdef CONFIG_PAX_KERNEXEC
18093 + mov %cr0, %esi
18094 + btr $16, %esi
18095 + mov %esi, %cr0
18096 +#endif
18097 +
18098 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18099 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18100 +
18101 +#ifdef CONFIG_PAX_KERNEXEC
18102 + bts $16, %esi
18103 + mov %esi, %cr0
18104 +#endif
18105 +
18106 pushl_cfi $__ESPFIX_SS
18107 pushl_cfi %eax /* new kernel esp */
18108 /* Disable interrupts, but do not irqtrace this section: we
18109 @@ -619,20 +846,18 @@ work_resched:
18110 movl TI_flags(%ebp), %ecx
18111 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18112 # than syscall tracing?
18113 - jz restore_all
18114 + jz restore_all_pax
18115 testb $_TIF_NEED_RESCHED, %cl
18116 jnz work_resched
18117
18118 work_notifysig: # deal with pending signals and
18119 # notify-resume requests
18120 + movl %esp, %eax
18121 #ifdef CONFIG_VM86
18122 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18123 - movl %esp, %eax
18124 jne work_notifysig_v86 # returning to kernel-space or
18125 # vm86-space
18126 1:
18127 -#else
18128 - movl %esp, %eax
18129 #endif
18130 TRACE_IRQS_ON
18131 ENABLE_INTERRUPTS(CLBR_NONE)
18132 @@ -653,7 +878,7 @@ work_notifysig_v86:
18133 movl %eax, %esp
18134 jmp 1b
18135 #endif
18136 -END(work_pending)
18137 +ENDPROC(work_pending)
18138
18139 # perform syscall exit tracing
18140 ALIGN
18141 @@ -661,11 +886,14 @@ syscall_trace_entry:
18142 movl $-ENOSYS,PT_EAX(%esp)
18143 movl %esp, %eax
18144 call syscall_trace_enter
18145 +
18146 + pax_erase_kstack
18147 +
18148 /* What it returned is what we'll actually use. */
18149 cmpl $(NR_syscalls), %eax
18150 jnae syscall_call
18151 jmp syscall_exit
18152 -END(syscall_trace_entry)
18153 +ENDPROC(syscall_trace_entry)
18154
18155 # perform syscall exit tracing
18156 ALIGN
18157 @@ -678,21 +906,25 @@ syscall_exit_work:
18158 movl %esp, %eax
18159 call syscall_trace_leave
18160 jmp resume_userspace
18161 -END(syscall_exit_work)
18162 +ENDPROC(syscall_exit_work)
18163 CFI_ENDPROC
18164
18165 RING0_INT_FRAME # can't unwind into user space anyway
18166 syscall_fault:
18167 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18168 + push %ss
18169 + pop %ds
18170 +#endif
18171 ASM_CLAC
18172 GET_THREAD_INFO(%ebp)
18173 movl $-EFAULT,PT_EAX(%esp)
18174 jmp resume_userspace
18175 -END(syscall_fault)
18176 +ENDPROC(syscall_fault)
18177
18178 syscall_badsys:
18179 movl $-ENOSYS,PT_EAX(%esp)
18180 jmp resume_userspace
18181 -END(syscall_badsys)
18182 +ENDPROC(syscall_badsys)
18183 CFI_ENDPROC
18184 /*
18185 * End of kprobes section
18186 @@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18187 * normal stack and adjusts ESP with the matching offset.
18188 */
18189 /* fixup the stack */
18190 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18191 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18192 +#ifdef CONFIG_SMP
18193 + movl PER_CPU_VAR(cpu_number), %ebx
18194 + shll $PAGE_SHIFT_asm, %ebx
18195 + addl $cpu_gdt_table, %ebx
18196 +#else
18197 + movl $cpu_gdt_table, %ebx
18198 +#endif
18199 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18200 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18201 shl $16, %eax
18202 addl %esp, %eax /* the adjusted stack pointer */
18203 pushl_cfi $__KERNEL_DS
18204 @@ -807,7 +1046,7 @@ vector=vector+1
18205 .endr
18206 2: jmp common_interrupt
18207 .endr
18208 -END(irq_entries_start)
18209 +ENDPROC(irq_entries_start)
18210
18211 .previous
18212 END(interrupt)
18213 @@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18214 pushl_cfi $do_coprocessor_error
18215 jmp error_code
18216 CFI_ENDPROC
18217 -END(coprocessor_error)
18218 +ENDPROC(coprocessor_error)
18219
18220 ENTRY(simd_coprocessor_error)
18221 RING0_INT_FRAME
18222 @@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
18223 #endif
18224 jmp error_code
18225 CFI_ENDPROC
18226 -END(simd_coprocessor_error)
18227 +ENDPROC(simd_coprocessor_error)
18228
18229 ENTRY(device_not_available)
18230 RING0_INT_FRAME
18231 @@ -889,18 +1128,18 @@ ENTRY(device_not_available)
18232 pushl_cfi $do_device_not_available
18233 jmp error_code
18234 CFI_ENDPROC
18235 -END(device_not_available)
18236 +ENDPROC(device_not_available)
18237
18238 #ifdef CONFIG_PARAVIRT
18239 ENTRY(native_iret)
18240 iret
18241 _ASM_EXTABLE(native_iret, iret_exc)
18242 -END(native_iret)
18243 +ENDPROC(native_iret)
18244
18245 ENTRY(native_irq_enable_sysexit)
18246 sti
18247 sysexit
18248 -END(native_irq_enable_sysexit)
18249 +ENDPROC(native_irq_enable_sysexit)
18250 #endif
18251
18252 ENTRY(overflow)
18253 @@ -910,7 +1149,7 @@ ENTRY(overflow)
18254 pushl_cfi $do_overflow
18255 jmp error_code
18256 CFI_ENDPROC
18257 -END(overflow)
18258 +ENDPROC(overflow)
18259
18260 ENTRY(bounds)
18261 RING0_INT_FRAME
18262 @@ -919,7 +1158,7 @@ ENTRY(bounds)
18263 pushl_cfi $do_bounds
18264 jmp error_code
18265 CFI_ENDPROC
18266 -END(bounds)
18267 +ENDPROC(bounds)
18268
18269 ENTRY(invalid_op)
18270 RING0_INT_FRAME
18271 @@ -928,7 +1167,7 @@ ENTRY(invalid_op)
18272 pushl_cfi $do_invalid_op
18273 jmp error_code
18274 CFI_ENDPROC
18275 -END(invalid_op)
18276 +ENDPROC(invalid_op)
18277
18278 ENTRY(coprocessor_segment_overrun)
18279 RING0_INT_FRAME
18280 @@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
18281 pushl_cfi $do_coprocessor_segment_overrun
18282 jmp error_code
18283 CFI_ENDPROC
18284 -END(coprocessor_segment_overrun)
18285 +ENDPROC(coprocessor_segment_overrun)
18286
18287 ENTRY(invalid_TSS)
18288 RING0_EC_FRAME
18289 @@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
18290 pushl_cfi $do_invalid_TSS
18291 jmp error_code
18292 CFI_ENDPROC
18293 -END(invalid_TSS)
18294 +ENDPROC(invalid_TSS)
18295
18296 ENTRY(segment_not_present)
18297 RING0_EC_FRAME
18298 @@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
18299 pushl_cfi $do_segment_not_present
18300 jmp error_code
18301 CFI_ENDPROC
18302 -END(segment_not_present)
18303 +ENDPROC(segment_not_present)
18304
18305 ENTRY(stack_segment)
18306 RING0_EC_FRAME
18307 @@ -961,7 +1200,7 @@ ENTRY(stack_segment)
18308 pushl_cfi $do_stack_segment
18309 jmp error_code
18310 CFI_ENDPROC
18311 -END(stack_segment)
18312 +ENDPROC(stack_segment)
18313
18314 ENTRY(alignment_check)
18315 RING0_EC_FRAME
18316 @@ -969,7 +1208,7 @@ ENTRY(alignment_check)
18317 pushl_cfi $do_alignment_check
18318 jmp error_code
18319 CFI_ENDPROC
18320 -END(alignment_check)
18321 +ENDPROC(alignment_check)
18322
18323 ENTRY(divide_error)
18324 RING0_INT_FRAME
18325 @@ -978,7 +1217,7 @@ ENTRY(divide_error)
18326 pushl_cfi $do_divide_error
18327 jmp error_code
18328 CFI_ENDPROC
18329 -END(divide_error)
18330 +ENDPROC(divide_error)
18331
18332 #ifdef CONFIG_X86_MCE
18333 ENTRY(machine_check)
18334 @@ -988,7 +1227,7 @@ ENTRY(machine_check)
18335 pushl_cfi machine_check_vector
18336 jmp error_code
18337 CFI_ENDPROC
18338 -END(machine_check)
18339 +ENDPROC(machine_check)
18340 #endif
18341
18342 ENTRY(spurious_interrupt_bug)
18343 @@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
18344 pushl_cfi $do_spurious_interrupt_bug
18345 jmp error_code
18346 CFI_ENDPROC
18347 -END(spurious_interrupt_bug)
18348 +ENDPROC(spurious_interrupt_bug)
18349 /*
18350 * End of kprobes section
18351 */
18352 @@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
18353
18354 ENTRY(mcount)
18355 ret
18356 -END(mcount)
18357 +ENDPROC(mcount)
18358
18359 ENTRY(ftrace_caller)
18360 cmpl $0, function_trace_stop
18361 @@ -1134,7 +1373,7 @@ ftrace_graph_call:
18362 .globl ftrace_stub
18363 ftrace_stub:
18364 ret
18365 -END(ftrace_caller)
18366 +ENDPROC(ftrace_caller)
18367
18368 ENTRY(ftrace_regs_caller)
18369 pushf /* push flags before compare (in cs location) */
18370 @@ -1235,7 +1474,7 @@ trace:
18371 popl %ecx
18372 popl %eax
18373 jmp ftrace_stub
18374 -END(mcount)
18375 +ENDPROC(mcount)
18376 #endif /* CONFIG_DYNAMIC_FTRACE */
18377 #endif /* CONFIG_FUNCTION_TRACER */
18378
18379 @@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
18380 popl %ecx
18381 popl %eax
18382 ret
18383 -END(ftrace_graph_caller)
18384 +ENDPROC(ftrace_graph_caller)
18385
18386 .globl return_to_handler
18387 return_to_handler:
18388 @@ -1309,15 +1548,18 @@ error_code:
18389 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18390 REG_TO_PTGS %ecx
18391 SET_KERNEL_GS %ecx
18392 - movl $(__USER_DS), %ecx
18393 + movl $(__KERNEL_DS), %ecx
18394 movl %ecx, %ds
18395 movl %ecx, %es
18396 +
18397 + pax_enter_kernel
18398 +
18399 TRACE_IRQS_OFF
18400 movl %esp,%eax # pt_regs pointer
18401 call *%edi
18402 jmp ret_from_exception
18403 CFI_ENDPROC
18404 -END(page_fault)
18405 +ENDPROC(page_fault)
18406
18407 /*
18408 * Debug traps and NMI can happen at the one SYSENTER instruction
18409 @@ -1360,7 +1602,7 @@ debug_stack_correct:
18410 call do_debug
18411 jmp ret_from_exception
18412 CFI_ENDPROC
18413 -END(debug)
18414 +ENDPROC(debug)
18415
18416 /*
18417 * NMI is doubly nasty. It can happen _while_ we're handling
18418 @@ -1398,6 +1640,9 @@ nmi_stack_correct:
18419 xorl %edx,%edx # zero error code
18420 movl %esp,%eax # pt_regs pointer
18421 call do_nmi
18422 +
18423 + pax_exit_kernel
18424 +
18425 jmp restore_all_notrace
18426 CFI_ENDPROC
18427
18428 @@ -1434,12 +1679,15 @@ nmi_espfix_stack:
18429 FIXUP_ESPFIX_STACK # %eax == %esp
18430 xorl %edx,%edx # zero error code
18431 call do_nmi
18432 +
18433 + pax_exit_kernel
18434 +
18435 RESTORE_REGS
18436 lss 12+4(%esp), %esp # back to espfix stack
18437 CFI_ADJUST_CFA_OFFSET -24
18438 jmp irq_return
18439 CFI_ENDPROC
18440 -END(nmi)
18441 +ENDPROC(nmi)
18442
18443 ENTRY(int3)
18444 RING0_INT_FRAME
18445 @@ -1452,14 +1700,14 @@ ENTRY(int3)
18446 call do_int3
18447 jmp ret_from_exception
18448 CFI_ENDPROC
18449 -END(int3)
18450 +ENDPROC(int3)
18451
18452 ENTRY(general_protection)
18453 RING0_EC_FRAME
18454 pushl_cfi $do_general_protection
18455 jmp error_code
18456 CFI_ENDPROC
18457 -END(general_protection)
18458 +ENDPROC(general_protection)
18459
18460 #ifdef CONFIG_KVM_GUEST
18461 ENTRY(async_page_fault)
18462 @@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
18463 pushl_cfi $do_async_page_fault
18464 jmp error_code
18465 CFI_ENDPROC
18466 -END(async_page_fault)
18467 +ENDPROC(async_page_fault)
18468 #endif
18469
18470 /*
18471 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18472 index cb3c591..bc63707 100644
18473 --- a/arch/x86/kernel/entry_64.S
18474 +++ b/arch/x86/kernel/entry_64.S
18475 @@ -59,6 +59,8 @@
18476 #include <asm/context_tracking.h>
18477 #include <asm/smap.h>
18478 #include <linux/err.h>
18479 +#include <asm/pgtable.h>
18480 +#include <asm/alternative-asm.h>
18481
18482 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18483 #include <linux/elf-em.h>
18484 @@ -80,8 +82,9 @@
18485 #ifdef CONFIG_DYNAMIC_FTRACE
18486
18487 ENTRY(function_hook)
18488 + pax_force_retaddr
18489 retq
18490 -END(function_hook)
18491 +ENDPROC(function_hook)
18492
18493 /* skip is set if stack has been adjusted */
18494 .macro ftrace_caller_setup skip=0
18495 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18496 #endif
18497
18498 GLOBAL(ftrace_stub)
18499 + pax_force_retaddr
18500 retq
18501 -END(ftrace_caller)
18502 +ENDPROC(ftrace_caller)
18503
18504 ENTRY(ftrace_regs_caller)
18505 /* Save the current flags before compare (in SS location)*/
18506 @@ -191,7 +195,7 @@ ftrace_restore_flags:
18507 popfq
18508 jmp ftrace_stub
18509
18510 -END(ftrace_regs_caller)
18511 +ENDPROC(ftrace_regs_caller)
18512
18513
18514 #else /* ! CONFIG_DYNAMIC_FTRACE */
18515 @@ -212,6 +216,7 @@ ENTRY(function_hook)
18516 #endif
18517
18518 GLOBAL(ftrace_stub)
18519 + pax_force_retaddr
18520 retq
18521
18522 trace:
18523 @@ -225,12 +230,13 @@ trace:
18524 #endif
18525 subq $MCOUNT_INSN_SIZE, %rdi
18526
18527 + pax_force_fptr ftrace_trace_function
18528 call *ftrace_trace_function
18529
18530 MCOUNT_RESTORE_FRAME
18531
18532 jmp ftrace_stub
18533 -END(function_hook)
18534 +ENDPROC(function_hook)
18535 #endif /* CONFIG_DYNAMIC_FTRACE */
18536 #endif /* CONFIG_FUNCTION_TRACER */
18537
18538 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
18539
18540 MCOUNT_RESTORE_FRAME
18541
18542 + pax_force_retaddr
18543 retq
18544 -END(ftrace_graph_caller)
18545 +ENDPROC(ftrace_graph_caller)
18546
18547 GLOBAL(return_to_handler)
18548 subq $24, %rsp
18549 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
18550 movq 8(%rsp), %rdx
18551 movq (%rsp), %rax
18552 addq $24, %rsp
18553 + pax_force_fptr %rdi
18554 jmp *%rdi
18555 +ENDPROC(return_to_handler)
18556 #endif
18557
18558
18559 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
18560 ENDPROC(native_usergs_sysret64)
18561 #endif /* CONFIG_PARAVIRT */
18562
18563 + .macro ljmpq sel, off
18564 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
18565 + .byte 0x48; ljmp *1234f(%rip)
18566 + .pushsection .rodata
18567 + .align 16
18568 + 1234: .quad \off; .word \sel
18569 + .popsection
18570 +#else
18571 + pushq $\sel
18572 + pushq $\off
18573 + lretq
18574 +#endif
18575 + .endm
18576 +
18577 + .macro pax_enter_kernel
18578 + pax_set_fptr_mask
18579 +#ifdef CONFIG_PAX_KERNEXEC
18580 + call pax_enter_kernel
18581 +#endif
18582 + .endm
18583 +
18584 + .macro pax_exit_kernel
18585 +#ifdef CONFIG_PAX_KERNEXEC
18586 + call pax_exit_kernel
18587 +#endif
18588 + .endm
18589 +
18590 +#ifdef CONFIG_PAX_KERNEXEC
18591 +ENTRY(pax_enter_kernel)
18592 + pushq %rdi
18593 +
18594 +#ifdef CONFIG_PARAVIRT
18595 + PV_SAVE_REGS(CLBR_RDI)
18596 +#endif
18597 +
18598 + GET_CR0_INTO_RDI
18599 + bts $16,%rdi
18600 + jnc 3f
18601 + mov %cs,%edi
18602 + cmp $__KERNEL_CS,%edi
18603 + jnz 2f
18604 +1:
18605 +
18606 +#ifdef CONFIG_PARAVIRT
18607 + PV_RESTORE_REGS(CLBR_RDI)
18608 +#endif
18609 +
18610 + popq %rdi
18611 + pax_force_retaddr
18612 + retq
18613 +
18614 +2: ljmpq __KERNEL_CS,1f
18615 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
18616 +4: SET_RDI_INTO_CR0
18617 + jmp 1b
18618 +ENDPROC(pax_enter_kernel)
18619 +
18620 +ENTRY(pax_exit_kernel)
18621 + pushq %rdi
18622 +
18623 +#ifdef CONFIG_PARAVIRT
18624 + PV_SAVE_REGS(CLBR_RDI)
18625 +#endif
18626 +
18627 + mov %cs,%rdi
18628 + cmp $__KERNEXEC_KERNEL_CS,%edi
18629 + jz 2f
18630 +1:
18631 +
18632 +#ifdef CONFIG_PARAVIRT
18633 + PV_RESTORE_REGS(CLBR_RDI);
18634 +#endif
18635 +
18636 + popq %rdi
18637 + pax_force_retaddr
18638 + retq
18639 +
18640 +2: GET_CR0_INTO_RDI
18641 + btr $16,%rdi
18642 + ljmpq __KERNEL_CS,3f
18643 +3: SET_RDI_INTO_CR0
18644 + jmp 1b
18645 +ENDPROC(pax_exit_kernel)
18646 +#endif
18647 +
18648 + .macro pax_enter_kernel_user
18649 + pax_set_fptr_mask
18650 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18651 + call pax_enter_kernel_user
18652 +#endif
18653 + .endm
18654 +
18655 + .macro pax_exit_kernel_user
18656 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18657 + call pax_exit_kernel_user
18658 +#endif
18659 +#ifdef CONFIG_PAX_RANDKSTACK
18660 + pushq %rax
18661 + call pax_randomize_kstack
18662 + popq %rax
18663 +#endif
18664 + .endm
18665 +
18666 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18667 +ENTRY(pax_enter_kernel_user)
18668 + pushq %rdi
18669 + pushq %rbx
18670 +
18671 +#ifdef CONFIG_PARAVIRT
18672 + PV_SAVE_REGS(CLBR_RDI)
18673 +#endif
18674 +
18675 + GET_CR3_INTO_RDI
18676 + mov %rdi,%rbx
18677 + add $__START_KERNEL_map,%rbx
18678 + sub phys_base(%rip),%rbx
18679 +
18680 +#ifdef CONFIG_PARAVIRT
18681 + pushq %rdi
18682 + cmpl $0, pv_info+PARAVIRT_enabled
18683 + jz 1f
18684 + i = 0
18685 + .rept USER_PGD_PTRS
18686 + mov i*8(%rbx),%rsi
18687 + mov $0,%sil
18688 + lea i*8(%rbx),%rdi
18689 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18690 + i = i + 1
18691 + .endr
18692 + jmp 2f
18693 +1:
18694 +#endif
18695 +
18696 + i = 0
18697 + .rept USER_PGD_PTRS
18698 + movb $0,i*8(%rbx)
18699 + i = i + 1
18700 + .endr
18701 +
18702 +#ifdef CONFIG_PARAVIRT
18703 +2: popq %rdi
18704 +#endif
18705 + SET_RDI_INTO_CR3
18706 +
18707 +#ifdef CONFIG_PAX_KERNEXEC
18708 + GET_CR0_INTO_RDI
18709 + bts $16,%rdi
18710 + SET_RDI_INTO_CR0
18711 +#endif
18712 +
18713 +#ifdef CONFIG_PARAVIRT
18714 + PV_RESTORE_REGS(CLBR_RDI)
18715 +#endif
18716 +
18717 + popq %rbx
18718 + popq %rdi
18719 + pax_force_retaddr
18720 + retq
18721 +ENDPROC(pax_enter_kernel_user)
18722 +
18723 +ENTRY(pax_exit_kernel_user)
18724 + push %rdi
18725 +
18726 +#ifdef CONFIG_PARAVIRT
18727 + pushq %rbx
18728 + PV_SAVE_REGS(CLBR_RDI)
18729 +#endif
18730 +
18731 +#ifdef CONFIG_PAX_KERNEXEC
18732 + GET_CR0_INTO_RDI
18733 + btr $16,%rdi
18734 + SET_RDI_INTO_CR0
18735 +#endif
18736 +
18737 + GET_CR3_INTO_RDI
18738 + add $__START_KERNEL_map,%rdi
18739 + sub phys_base(%rip),%rdi
18740 +
18741 +#ifdef CONFIG_PARAVIRT
18742 + cmpl $0, pv_info+PARAVIRT_enabled
18743 + jz 1f
18744 + mov %rdi,%rbx
18745 + i = 0
18746 + .rept USER_PGD_PTRS
18747 + mov i*8(%rbx),%rsi
18748 + mov $0x67,%sil
18749 + lea i*8(%rbx),%rdi
18750 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18751 + i = i + 1
18752 + .endr
18753 + jmp 2f
18754 +1:
18755 +#endif
18756 +
18757 + i = 0
18758 + .rept USER_PGD_PTRS
18759 + movb $0x67,i*8(%rdi)
18760 + i = i + 1
18761 + .endr
18762 +
18763 +#ifdef CONFIG_PARAVIRT
18764 +2: PV_RESTORE_REGS(CLBR_RDI)
18765 + popq %rbx
18766 +#endif
18767 +
18768 + popq %rdi
18769 + pax_force_retaddr
18770 + retq
18771 +ENDPROC(pax_exit_kernel_user)
18772 +#endif
18773 +
18774 +.macro pax_erase_kstack
18775 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18776 + call pax_erase_kstack
18777 +#endif
18778 +.endm
18779 +
18780 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18781 +ENTRY(pax_erase_kstack)
18782 + pushq %rdi
18783 + pushq %rcx
18784 + pushq %rax
18785 + pushq %r11
18786 +
18787 + GET_THREAD_INFO(%r11)
18788 + mov TI_lowest_stack(%r11), %rdi
18789 + mov $-0xBEEF, %rax
18790 + std
18791 +
18792 +1: mov %edi, %ecx
18793 + and $THREAD_SIZE_asm - 1, %ecx
18794 + shr $3, %ecx
18795 + repne scasq
18796 + jecxz 2f
18797 +
18798 + cmp $2*8, %ecx
18799 + jc 2f
18800 +
18801 + mov $2*8, %ecx
18802 + repe scasq
18803 + jecxz 2f
18804 + jne 1b
18805 +
18806 +2: cld
18807 + mov %esp, %ecx
18808 + sub %edi, %ecx
18809 +
18810 + cmp $THREAD_SIZE_asm, %rcx
18811 + jb 3f
18812 + ud2
18813 +3:
18814 +
18815 + shr $3, %ecx
18816 + rep stosq
18817 +
18818 + mov TI_task_thread_sp0(%r11), %rdi
18819 + sub $256, %rdi
18820 + mov %rdi, TI_lowest_stack(%r11)
18821 +
18822 + popq %r11
18823 + popq %rax
18824 + popq %rcx
18825 + popq %rdi
18826 + pax_force_retaddr
18827 + ret
18828 +ENDPROC(pax_erase_kstack)
18829 +#endif
18830
18831 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
18832 #ifdef CONFIG_TRACE_IRQFLAGS
18833 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
18834 .endm
18835
18836 .macro UNFAKE_STACK_FRAME
18837 - addq $8*6, %rsp
18838 - CFI_ADJUST_CFA_OFFSET -(6*8)
18839 + addq $8*6 + ARG_SKIP, %rsp
18840 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
18841 .endm
18842
18843 /*
18844 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
18845 movq %rsp, %rsi
18846
18847 leaq -RBP(%rsp),%rdi /* arg1 for handler */
18848 - testl $3, CS-RBP(%rsi)
18849 + testb $3, CS-RBP(%rsi)
18850 je 1f
18851 SWAPGS
18852 /*
18853 @@ -498,9 +774,10 @@ ENTRY(save_rest)
18854 movq_cfi r15, R15+16
18855 movq %r11, 8(%rsp) /* return address */
18856 FIXUP_TOP_OF_STACK %r11, 16
18857 + pax_force_retaddr
18858 ret
18859 CFI_ENDPROC
18860 -END(save_rest)
18861 +ENDPROC(save_rest)
18862
18863 /* save complete stack frame */
18864 .pushsection .kprobes.text, "ax"
18865 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
18866 js 1f /* negative -> in kernel */
18867 SWAPGS
18868 xorl %ebx,%ebx
18869 -1: ret
18870 +1: pax_force_retaddr_bts
18871 + ret
18872 CFI_ENDPROC
18873 -END(save_paranoid)
18874 +ENDPROC(save_paranoid)
18875 .popsection
18876
18877 /*
18878 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
18879
18880 RESTORE_REST
18881
18882 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18883 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18884 jz 1f
18885
18886 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
18887 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
18888 RESTORE_REST
18889 jmp int_ret_from_sys_call
18890 CFI_ENDPROC
18891 -END(ret_from_fork)
18892 +ENDPROC(ret_from_fork)
18893
18894 /*
18895 * System call entry. Up to 6 arguments in registers are supported.
18896 @@ -608,7 +886,7 @@ END(ret_from_fork)
18897 ENTRY(system_call)
18898 CFI_STARTPROC simple
18899 CFI_SIGNAL_FRAME
18900 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
18901 + CFI_DEF_CFA rsp,0
18902 CFI_REGISTER rip,rcx
18903 /*CFI_REGISTER rflags,r11*/
18904 SWAPGS_UNSAFE_STACK
18905 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
18906
18907 movq %rsp,PER_CPU_VAR(old_rsp)
18908 movq PER_CPU_VAR(kernel_stack),%rsp
18909 + SAVE_ARGS 8*6,0
18910 + pax_enter_kernel_user
18911 +
18912 +#ifdef CONFIG_PAX_RANDKSTACK
18913 + pax_erase_kstack
18914 +#endif
18915 +
18916 /*
18917 * No need to follow this irqs off/on section - it's straight
18918 * and short:
18919 */
18920 ENABLE_INTERRUPTS(CLBR_NONE)
18921 - SAVE_ARGS 8,0
18922 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
18923 movq %rcx,RIP-ARGOFFSET(%rsp)
18924 CFI_REL_OFFSET rip,RIP-ARGOFFSET
18925 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18926 + GET_THREAD_INFO(%rcx)
18927 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
18928 jnz tracesys
18929 system_call_fastpath:
18930 #if __SYSCALL_MASK == ~0
18931 @@ -640,7 +925,7 @@ system_call_fastpath:
18932 cmpl $__NR_syscall_max,%eax
18933 #endif
18934 ja badsys
18935 - movq %r10,%rcx
18936 + movq R10-ARGOFFSET(%rsp),%rcx
18937 call *sys_call_table(,%rax,8) # XXX: rip relative
18938 movq %rax,RAX-ARGOFFSET(%rsp)
18939 /*
18940 @@ -654,10 +939,13 @@ sysret_check:
18941 LOCKDEP_SYS_EXIT
18942 DISABLE_INTERRUPTS(CLBR_NONE)
18943 TRACE_IRQS_OFF
18944 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
18945 + GET_THREAD_INFO(%rcx)
18946 + movl TI_flags(%rcx),%edx
18947 andl %edi,%edx
18948 jnz sysret_careful
18949 CFI_REMEMBER_STATE
18950 + pax_exit_kernel_user
18951 + pax_erase_kstack
18952 /*
18953 * sysretq will re-enable interrupts:
18954 */
18955 @@ -709,14 +997,18 @@ badsys:
18956 * jump back to the normal fast path.
18957 */
18958 auditsys:
18959 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
18960 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
18961 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
18962 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
18963 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
18964 movq %rax,%rsi /* 2nd arg: syscall number */
18965 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
18966 call __audit_syscall_entry
18967 +
18968 + pax_erase_kstack
18969 +
18970 LOAD_ARGS 0 /* reload call-clobbered registers */
18971 + pax_set_fptr_mask
18972 jmp system_call_fastpath
18973
18974 /*
18975 @@ -737,7 +1029,7 @@ sysret_audit:
18976 /* Do syscall tracing */
18977 tracesys:
18978 #ifdef CONFIG_AUDITSYSCALL
18979 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18980 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
18981 jz auditsys
18982 #endif
18983 SAVE_REST
18984 @@ -745,12 +1037,16 @@ tracesys:
18985 FIXUP_TOP_OF_STACK %rdi
18986 movq %rsp,%rdi
18987 call syscall_trace_enter
18988 +
18989 + pax_erase_kstack
18990 +
18991 /*
18992 * Reload arg registers from stack in case ptrace changed them.
18993 * We don't reload %rax because syscall_trace_enter() returned
18994 * the value it wants us to use in the table lookup.
18995 */
18996 LOAD_ARGS ARGOFFSET, 1
18997 + pax_set_fptr_mask
18998 RESTORE_REST
18999 #if __SYSCALL_MASK == ~0
19000 cmpq $__NR_syscall_max,%rax
19001 @@ -759,7 +1055,7 @@ tracesys:
19002 cmpl $__NR_syscall_max,%eax
19003 #endif
19004 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19005 - movq %r10,%rcx /* fixup for C */
19006 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19007 call *sys_call_table(,%rax,8)
19008 movq %rax,RAX-ARGOFFSET(%rsp)
19009 /* Use IRET because user could have changed frame */
19010 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
19011 andl %edi,%edx
19012 jnz int_careful
19013 andl $~TS_COMPAT,TI_status(%rcx)
19014 - jmp retint_swapgs
19015 + pax_exit_kernel_user
19016 + pax_erase_kstack
19017 + jmp retint_swapgs_pax
19018
19019 /* Either reschedule or signal or syscall exit tracking needed. */
19020 /* First do a reschedule test. */
19021 @@ -826,7 +1124,7 @@ int_restore_rest:
19022 TRACE_IRQS_OFF
19023 jmp int_with_check
19024 CFI_ENDPROC
19025 -END(system_call)
19026 +ENDPROC(system_call)
19027
19028 /*
19029 * Certain special system calls that need to save a complete full stack frame.
19030 @@ -842,7 +1140,7 @@ ENTRY(\label)
19031 call \func
19032 jmp ptregscall_common
19033 CFI_ENDPROC
19034 -END(\label)
19035 +ENDPROC(\label)
19036 .endm
19037
19038 .macro FORK_LIKE func
19039 @@ -856,9 +1154,10 @@ ENTRY(stub_\func)
19040 DEFAULT_FRAME 0 8 /* offset 8: return address */
19041 call sys_\func
19042 RESTORE_TOP_OF_STACK %r11, 8
19043 + pax_force_retaddr
19044 ret $REST_SKIP /* pop extended registers */
19045 CFI_ENDPROC
19046 -END(stub_\func)
19047 +ENDPROC(stub_\func)
19048 .endm
19049
19050 FORK_LIKE clone
19051 @@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
19052 movq_cfi_restore R12+8, r12
19053 movq_cfi_restore RBP+8, rbp
19054 movq_cfi_restore RBX+8, rbx
19055 + pax_force_retaddr
19056 ret $REST_SKIP /* pop extended registers */
19057 CFI_ENDPROC
19058 -END(ptregscall_common)
19059 +ENDPROC(ptregscall_common)
19060
19061 ENTRY(stub_execve)
19062 CFI_STARTPROC
19063 @@ -891,7 +1191,7 @@ ENTRY(stub_execve)
19064 RESTORE_REST
19065 jmp int_ret_from_sys_call
19066 CFI_ENDPROC
19067 -END(stub_execve)
19068 +ENDPROC(stub_execve)
19069
19070 /*
19071 * sigreturn is special because it needs to restore all registers on return.
19072 @@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
19073 RESTORE_REST
19074 jmp int_ret_from_sys_call
19075 CFI_ENDPROC
19076 -END(stub_rt_sigreturn)
19077 +ENDPROC(stub_rt_sigreturn)
19078
19079 #ifdef CONFIG_X86_X32_ABI
19080 ENTRY(stub_x32_rt_sigreturn)
19081 @@ -975,7 +1275,7 @@ vector=vector+1
19082 2: jmp common_interrupt
19083 .endr
19084 CFI_ENDPROC
19085 -END(irq_entries_start)
19086 +ENDPROC(irq_entries_start)
19087
19088 .previous
19089 END(interrupt)
19090 @@ -995,6 +1295,16 @@ END(interrupt)
19091 subq $ORIG_RAX-RBP, %rsp
19092 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19093 SAVE_ARGS_IRQ
19094 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19095 + testb $3, CS(%rdi)
19096 + jnz 1f
19097 + pax_enter_kernel
19098 + jmp 2f
19099 +1: pax_enter_kernel_user
19100 +2:
19101 +#else
19102 + pax_enter_kernel
19103 +#endif
19104 call \func
19105 .endm
19106
19107 @@ -1027,7 +1337,7 @@ ret_from_intr:
19108
19109 exit_intr:
19110 GET_THREAD_INFO(%rcx)
19111 - testl $3,CS-ARGOFFSET(%rsp)
19112 + testb $3,CS-ARGOFFSET(%rsp)
19113 je retint_kernel
19114
19115 /* Interrupt came from user space */
19116 @@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
19117 * The iretq could re-enable interrupts:
19118 */
19119 DISABLE_INTERRUPTS(CLBR_ANY)
19120 + pax_exit_kernel_user
19121 +retint_swapgs_pax:
19122 TRACE_IRQS_IRETQ
19123 SWAPGS
19124 jmp restore_args
19125
19126 retint_restore_args: /* return to kernel space */
19127 DISABLE_INTERRUPTS(CLBR_ANY)
19128 + pax_exit_kernel
19129 + pax_force_retaddr (RIP-ARGOFFSET)
19130 /*
19131 * The iretq could re-enable interrupts:
19132 */
19133 @@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
19134 #endif
19135
19136 CFI_ENDPROC
19137 -END(common_interrupt)
19138 +ENDPROC(common_interrupt)
19139 /*
19140 * End of kprobes section
19141 */
19142 @@ -1155,7 +1469,7 @@ ENTRY(\sym)
19143 interrupt \do_sym
19144 jmp ret_from_intr
19145 CFI_ENDPROC
19146 -END(\sym)
19147 +ENDPROC(\sym)
19148 .endm
19149
19150 #ifdef CONFIG_SMP
19151 @@ -1211,12 +1525,22 @@ ENTRY(\sym)
19152 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19153 call error_entry
19154 DEFAULT_FRAME 0
19155 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19156 + testb $3, CS(%rsp)
19157 + jnz 1f
19158 + pax_enter_kernel
19159 + jmp 2f
19160 +1: pax_enter_kernel_user
19161 +2:
19162 +#else
19163 + pax_enter_kernel
19164 +#endif
19165 movq %rsp,%rdi /* pt_regs pointer */
19166 xorl %esi,%esi /* no error code */
19167 call \do_sym
19168 jmp error_exit /* %ebx: no swapgs flag */
19169 CFI_ENDPROC
19170 -END(\sym)
19171 +ENDPROC(\sym)
19172 .endm
19173
19174 .macro paranoidzeroentry sym do_sym
19175 @@ -1229,15 +1553,25 @@ ENTRY(\sym)
19176 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19177 call save_paranoid
19178 TRACE_IRQS_OFF
19179 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19180 + testb $3, CS(%rsp)
19181 + jnz 1f
19182 + pax_enter_kernel
19183 + jmp 2f
19184 +1: pax_enter_kernel_user
19185 +2:
19186 +#else
19187 + pax_enter_kernel
19188 +#endif
19189 movq %rsp,%rdi /* pt_regs pointer */
19190 xorl %esi,%esi /* no error code */
19191 call \do_sym
19192 jmp paranoid_exit /* %ebx: no swapgs flag */
19193 CFI_ENDPROC
19194 -END(\sym)
19195 +ENDPROC(\sym)
19196 .endm
19197
19198 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19199 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19200 .macro paranoidzeroentry_ist sym do_sym ist
19201 ENTRY(\sym)
19202 INTR_FRAME
19203 @@ -1248,14 +1582,30 @@ ENTRY(\sym)
19204 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19205 call save_paranoid
19206 TRACE_IRQS_OFF_DEBUG
19207 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19208 + testb $3, CS(%rsp)
19209 + jnz 1f
19210 + pax_enter_kernel
19211 + jmp 2f
19212 +1: pax_enter_kernel_user
19213 +2:
19214 +#else
19215 + pax_enter_kernel
19216 +#endif
19217 movq %rsp,%rdi /* pt_regs pointer */
19218 xorl %esi,%esi /* no error code */
19219 +#ifdef CONFIG_SMP
19220 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19221 + lea init_tss(%r12), %r12
19222 +#else
19223 + lea init_tss(%rip), %r12
19224 +#endif
19225 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19226 call \do_sym
19227 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19228 jmp paranoid_exit /* %ebx: no swapgs flag */
19229 CFI_ENDPROC
19230 -END(\sym)
19231 +ENDPROC(\sym)
19232 .endm
19233
19234 .macro errorentry sym do_sym
19235 @@ -1267,13 +1617,23 @@ ENTRY(\sym)
19236 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19237 call error_entry
19238 DEFAULT_FRAME 0
19239 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19240 + testb $3, CS(%rsp)
19241 + jnz 1f
19242 + pax_enter_kernel
19243 + jmp 2f
19244 +1: pax_enter_kernel_user
19245 +2:
19246 +#else
19247 + pax_enter_kernel
19248 +#endif
19249 movq %rsp,%rdi /* pt_regs pointer */
19250 movq ORIG_RAX(%rsp),%rsi /* get error code */
19251 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19252 call \do_sym
19253 jmp error_exit /* %ebx: no swapgs flag */
19254 CFI_ENDPROC
19255 -END(\sym)
19256 +ENDPROC(\sym)
19257 .endm
19258
19259 /* error code is on the stack already */
19260 @@ -1287,13 +1647,23 @@ ENTRY(\sym)
19261 call save_paranoid
19262 DEFAULT_FRAME 0
19263 TRACE_IRQS_OFF
19264 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19265 + testb $3, CS(%rsp)
19266 + jnz 1f
19267 + pax_enter_kernel
19268 + jmp 2f
19269 +1: pax_enter_kernel_user
19270 +2:
19271 +#else
19272 + pax_enter_kernel
19273 +#endif
19274 movq %rsp,%rdi /* pt_regs pointer */
19275 movq ORIG_RAX(%rsp),%rsi /* get error code */
19276 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19277 call \do_sym
19278 jmp paranoid_exit /* %ebx: no swapgs flag */
19279 CFI_ENDPROC
19280 -END(\sym)
19281 +ENDPROC(\sym)
19282 .endm
19283
19284 zeroentry divide_error do_divide_error
19285 @@ -1323,9 +1693,10 @@ gs_change:
19286 2: mfence /* workaround */
19287 SWAPGS
19288 popfq_cfi
19289 + pax_force_retaddr
19290 ret
19291 CFI_ENDPROC
19292 -END(native_load_gs_index)
19293 +ENDPROC(native_load_gs_index)
19294
19295 _ASM_EXTABLE(gs_change,bad_gs)
19296 .section .fixup,"ax"
19297 @@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
19298 CFI_DEF_CFA_REGISTER rsp
19299 CFI_ADJUST_CFA_OFFSET -8
19300 decl PER_CPU_VAR(irq_count)
19301 + pax_force_retaddr
19302 ret
19303 CFI_ENDPROC
19304 -END(call_softirq)
19305 +ENDPROC(call_softirq)
19306
19307 #ifdef CONFIG_XEN
19308 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19309 @@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19310 decl PER_CPU_VAR(irq_count)
19311 jmp error_exit
19312 CFI_ENDPROC
19313 -END(xen_do_hypervisor_callback)
19314 +ENDPROC(xen_do_hypervisor_callback)
19315
19316 /*
19317 * Hypervisor uses this for application faults while it executes.
19318 @@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
19319 SAVE_ALL
19320 jmp error_exit
19321 CFI_ENDPROC
19322 -END(xen_failsafe_callback)
19323 +ENDPROC(xen_failsafe_callback)
19324
19325 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
19326 xen_hvm_callback_vector xen_evtchn_do_upcall
19327 @@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
19328 TRACE_IRQS_OFF_DEBUG
19329 testl %ebx,%ebx /* swapgs needed? */
19330 jnz paranoid_restore
19331 - testl $3,CS(%rsp)
19332 + testb $3,CS(%rsp)
19333 jnz paranoid_userspace
19334 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19335 + pax_exit_kernel
19336 + TRACE_IRQS_IRETQ 0
19337 + SWAPGS_UNSAFE_STACK
19338 + RESTORE_ALL 8
19339 + pax_force_retaddr_bts
19340 + jmp irq_return
19341 +#endif
19342 paranoid_swapgs:
19343 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19344 + pax_exit_kernel_user
19345 +#else
19346 + pax_exit_kernel
19347 +#endif
19348 TRACE_IRQS_IRETQ 0
19349 SWAPGS_UNSAFE_STACK
19350 RESTORE_ALL 8
19351 jmp irq_return
19352 paranoid_restore:
19353 + pax_exit_kernel
19354 TRACE_IRQS_IRETQ_DEBUG 0
19355 RESTORE_ALL 8
19356 + pax_force_retaddr_bts
19357 jmp irq_return
19358 paranoid_userspace:
19359 GET_THREAD_INFO(%rcx)
19360 @@ -1539,7 +1926,7 @@ paranoid_schedule:
19361 TRACE_IRQS_OFF
19362 jmp paranoid_userspace
19363 CFI_ENDPROC
19364 -END(paranoid_exit)
19365 +ENDPROC(paranoid_exit)
19366
19367 /*
19368 * Exception entry point. This expects an error code/orig_rax on the stack.
19369 @@ -1566,12 +1953,13 @@ ENTRY(error_entry)
19370 movq_cfi r14, R14+8
19371 movq_cfi r15, R15+8
19372 xorl %ebx,%ebx
19373 - testl $3,CS+8(%rsp)
19374 + testb $3,CS+8(%rsp)
19375 je error_kernelspace
19376 error_swapgs:
19377 SWAPGS
19378 error_sti:
19379 TRACE_IRQS_OFF
19380 + pax_force_retaddr_bts
19381 ret
19382
19383 /*
19384 @@ -1598,7 +1986,7 @@ bstep_iret:
19385 movq %rcx,RIP+8(%rsp)
19386 jmp error_swapgs
19387 CFI_ENDPROC
19388 -END(error_entry)
19389 +ENDPROC(error_entry)
19390
19391
19392 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19393 @@ -1618,7 +2006,7 @@ ENTRY(error_exit)
19394 jnz retint_careful
19395 jmp retint_swapgs
19396 CFI_ENDPROC
19397 -END(error_exit)
19398 +ENDPROC(error_exit)
19399
19400 /*
19401 * Test if a given stack is an NMI stack or not.
19402 @@ -1676,9 +2064,11 @@ ENTRY(nmi)
19403 * If %cs was not the kernel segment, then the NMI triggered in user
19404 * space, which means it is definitely not nested.
19405 */
19406 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19407 + je 1f
19408 cmpl $__KERNEL_CS, 16(%rsp)
19409 jne first_nmi
19410 -
19411 +1:
19412 /*
19413 * Check the special variable on the stack to see if NMIs are
19414 * executing.
19415 @@ -1847,6 +2237,17 @@ end_repeat_nmi:
19416 */
19417 movq %cr2, %r12
19418
19419 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19420 + testb $3, CS(%rsp)
19421 + jnz 1f
19422 + pax_enter_kernel
19423 + jmp 2f
19424 +1: pax_enter_kernel_user
19425 +2:
19426 +#else
19427 + pax_enter_kernel
19428 +#endif
19429 +
19430 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19431 movq %rsp,%rdi
19432 movq $-1,%rsi
19433 @@ -1862,23 +2263,34 @@ end_repeat_nmi:
19434 testl %ebx,%ebx /* swapgs needed? */
19435 jnz nmi_restore
19436 nmi_swapgs:
19437 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19438 + pax_exit_kernel_user
19439 +#else
19440 + pax_exit_kernel
19441 +#endif
19442 SWAPGS_UNSAFE_STACK
19443 + RESTORE_ALL 6*8
19444 + /* Clear the NMI executing stack variable */
19445 + movq $0, 5*8(%rsp)
19446 + jmp irq_return
19447 nmi_restore:
19448 + pax_exit_kernel
19449 /* Pop the extra iret frame at once */
19450 RESTORE_ALL 6*8
19451 + pax_force_retaddr_bts
19452
19453 /* Clear the NMI executing stack variable */
19454 movq $0, 5*8(%rsp)
19455 jmp irq_return
19456 CFI_ENDPROC
19457 -END(nmi)
19458 +ENDPROC(nmi)
19459
19460 ENTRY(ignore_sysret)
19461 CFI_STARTPROC
19462 mov $-ENOSYS,%eax
19463 sysret
19464 CFI_ENDPROC
19465 -END(ignore_sysret)
19466 +ENDPROC(ignore_sysret)
19467
19468 /*
19469 * End of kprobes section
19470 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19471 index 1d41402..af9a46a 100644
19472 --- a/arch/x86/kernel/ftrace.c
19473 +++ b/arch/x86/kernel/ftrace.c
19474 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19475 {
19476 unsigned char replaced[MCOUNT_INSN_SIZE];
19477
19478 + ip = ktla_ktva(ip);
19479 +
19480 /*
19481 * Note: Due to modules and __init, code can
19482 * disappear and change, we need to protect against faulting
19483 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19484 unsigned char old[MCOUNT_INSN_SIZE], *new;
19485 int ret;
19486
19487 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
19488 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
19489 new = ftrace_call_replace(ip, (unsigned long)func);
19490
19491 /* See comment above by declaration of modifying_ftrace_code */
19492 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19493 /* Also update the regs callback function */
19494 if (!ret) {
19495 ip = (unsigned long)(&ftrace_regs_call);
19496 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
19497 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
19498 new = ftrace_call_replace(ip, (unsigned long)func);
19499 ret = ftrace_modify_code(ip, old, new);
19500 }
19501 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
19502 * kernel identity mapping to modify code.
19503 */
19504 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
19505 - ip = (unsigned long)__va(__pa(ip));
19506 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
19507
19508 return probe_kernel_write((void *)ip, val, size);
19509 }
19510 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
19511 unsigned char replaced[MCOUNT_INSN_SIZE];
19512 unsigned char brk = BREAKPOINT_INSTRUCTION;
19513
19514 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
19515 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
19516 return -EFAULT;
19517
19518 /* Make sure it is what we expect it to be */
19519 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
19520 return ret;
19521
19522 fail_update:
19523 - probe_kernel_write((void *)ip, &old_code[0], 1);
19524 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
19525 goto out;
19526 }
19527
19528 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
19529 {
19530 unsigned char code[MCOUNT_INSN_SIZE];
19531
19532 + ip = ktla_ktva(ip);
19533 +
19534 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
19535 return -EFAULT;
19536
19537 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
19538 index c18f59d..9c0c9f6 100644
19539 --- a/arch/x86/kernel/head32.c
19540 +++ b/arch/x86/kernel/head32.c
19541 @@ -18,6 +18,7 @@
19542 #include <asm/io_apic.h>
19543 #include <asm/bios_ebda.h>
19544 #include <asm/tlbflush.h>
19545 +#include <asm/boot.h>
19546
19547 static void __init i386_default_early_setup(void)
19548 {
19549 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
19550
19551 void __init i386_start_kernel(void)
19552 {
19553 - memblock_reserve(__pa_symbol(&_text),
19554 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
19555 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
19556
19557 #ifdef CONFIG_BLK_DEV_INITRD
19558 /* Reserve INITRD */
19559 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
19560 index c8932c7..d56b622 100644
19561 --- a/arch/x86/kernel/head_32.S
19562 +++ b/arch/x86/kernel/head_32.S
19563 @@ -26,6 +26,12 @@
19564 /* Physical address */
19565 #define pa(X) ((X) - __PAGE_OFFSET)
19566
19567 +#ifdef CONFIG_PAX_KERNEXEC
19568 +#define ta(X) (X)
19569 +#else
19570 +#define ta(X) ((X) - __PAGE_OFFSET)
19571 +#endif
19572 +
19573 /*
19574 * References to members of the new_cpu_data structure.
19575 */
19576 @@ -55,11 +61,7 @@
19577 * and small than max_low_pfn, otherwise will waste some page table entries
19578 */
19579
19580 -#if PTRS_PER_PMD > 1
19581 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
19582 -#else
19583 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
19584 -#endif
19585 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
19586
19587 /* Number of possible pages in the lowmem region */
19588 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
19589 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
19590 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19591
19592 /*
19593 + * Real beginning of normal "text" segment
19594 + */
19595 +ENTRY(stext)
19596 +ENTRY(_stext)
19597 +
19598 +/*
19599 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
19600 * %esi points to the real-mode code as a 32-bit pointer.
19601 * CS and DS must be 4 GB flat segments, but we don't depend on
19602 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19603 * can.
19604 */
19605 __HEAD
19606 +
19607 +#ifdef CONFIG_PAX_KERNEXEC
19608 + jmp startup_32
19609 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
19610 +.fill PAGE_SIZE-5,1,0xcc
19611 +#endif
19612 +
19613 ENTRY(startup_32)
19614 movl pa(stack_start),%ecx
19615
19616 @@ -106,6 +121,59 @@ ENTRY(startup_32)
19617 2:
19618 leal -__PAGE_OFFSET(%ecx),%esp
19619
19620 +#ifdef CONFIG_SMP
19621 + movl $pa(cpu_gdt_table),%edi
19622 + movl $__per_cpu_load,%eax
19623 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
19624 + rorl $16,%eax
19625 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
19626 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
19627 + movl $__per_cpu_end - 1,%eax
19628 + subl $__per_cpu_start,%eax
19629 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
19630 +#endif
19631 +
19632 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19633 + movl $NR_CPUS,%ecx
19634 + movl $pa(cpu_gdt_table),%edi
19635 +1:
19636 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
19637 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
19638 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
19639 + addl $PAGE_SIZE_asm,%edi
19640 + loop 1b
19641 +#endif
19642 +
19643 +#ifdef CONFIG_PAX_KERNEXEC
19644 + movl $pa(boot_gdt),%edi
19645 + movl $__LOAD_PHYSICAL_ADDR,%eax
19646 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
19647 + rorl $16,%eax
19648 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
19649 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
19650 + rorl $16,%eax
19651 +
19652 + ljmp $(__BOOT_CS),$1f
19653 +1:
19654 +
19655 + movl $NR_CPUS,%ecx
19656 + movl $pa(cpu_gdt_table),%edi
19657 + addl $__PAGE_OFFSET,%eax
19658 +1:
19659 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
19660 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
19661 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
19662 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
19663 + rorl $16,%eax
19664 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
19665 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
19666 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
19667 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
19668 + rorl $16,%eax
19669 + addl $PAGE_SIZE_asm,%edi
19670 + loop 1b
19671 +#endif
19672 +
19673 /*
19674 * Clear BSS first so that there are no surprises...
19675 */
19676 @@ -196,8 +264,11 @@ ENTRY(startup_32)
19677 movl %eax, pa(max_pfn_mapped)
19678
19679 /* Do early initialization of the fixmap area */
19680 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19681 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
19682 +#ifdef CONFIG_COMPAT_VDSO
19683 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
19684 +#else
19685 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
19686 +#endif
19687 #else /* Not PAE */
19688
19689 page_pde_offset = (__PAGE_OFFSET >> 20);
19690 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19691 movl %eax, pa(max_pfn_mapped)
19692
19693 /* Do early initialization of the fixmap area */
19694 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19695 - movl %eax,pa(initial_page_table+0xffc)
19696 +#ifdef CONFIG_COMPAT_VDSO
19697 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
19698 +#else
19699 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
19700 +#endif
19701 #endif
19702
19703 #ifdef CONFIG_PARAVIRT
19704 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19705 cmpl $num_subarch_entries, %eax
19706 jae bad_subarch
19707
19708 - movl pa(subarch_entries)(,%eax,4), %eax
19709 - subl $__PAGE_OFFSET, %eax
19710 - jmp *%eax
19711 + jmp *pa(subarch_entries)(,%eax,4)
19712
19713 bad_subarch:
19714 WEAK(lguest_entry)
19715 @@ -256,10 +328,10 @@ WEAK(xen_entry)
19716 __INITDATA
19717
19718 subarch_entries:
19719 - .long default_entry /* normal x86/PC */
19720 - .long lguest_entry /* lguest hypervisor */
19721 - .long xen_entry /* Xen hypervisor */
19722 - .long default_entry /* Moorestown MID */
19723 + .long ta(default_entry) /* normal x86/PC */
19724 + .long ta(lguest_entry) /* lguest hypervisor */
19725 + .long ta(xen_entry) /* Xen hypervisor */
19726 + .long ta(default_entry) /* Moorestown MID */
19727 num_subarch_entries = (. - subarch_entries) / 4
19728 .previous
19729 #else
19730 @@ -335,6 +407,7 @@ default_entry:
19731 movl pa(mmu_cr4_features),%eax
19732 movl %eax,%cr4
19733
19734 +#ifdef CONFIG_X86_PAE
19735 testb $X86_CR4_PAE, %al # check if PAE is enabled
19736 jz 6f
19737
19738 @@ -363,6 +436,9 @@ default_entry:
19739 /* Make changes effective */
19740 wrmsr
19741
19742 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
19743 +#endif
19744 +
19745 6:
19746
19747 /*
19748 @@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
19749 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
19750 movl %eax,%ss # after changing gdt.
19751
19752 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
19753 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
19754 movl %eax,%ds
19755 movl %eax,%es
19756
19757 movl $(__KERNEL_PERCPU), %eax
19758 movl %eax,%fs # set this cpu's percpu
19759
19760 +#ifdef CONFIG_CC_STACKPROTECTOR
19761 movl $(__KERNEL_STACK_CANARY),%eax
19762 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
19763 + movl $(__USER_DS),%eax
19764 +#else
19765 + xorl %eax,%eax
19766 +#endif
19767 movl %eax,%gs
19768
19769 xorl %eax,%eax # Clear LDT
19770 @@ -544,8 +626,11 @@ setup_once:
19771 * relocation. Manually set base address in stack canary
19772 * segment descriptor.
19773 */
19774 - movl $gdt_page,%eax
19775 + movl $cpu_gdt_table,%eax
19776 movl $stack_canary,%ecx
19777 +#ifdef CONFIG_SMP
19778 + addl $__per_cpu_load,%ecx
19779 +#endif
19780 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
19781 shrl $16, %ecx
19782 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
19783 @@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
19784 /* This is global to keep gas from relaxing the jumps */
19785 ENTRY(early_idt_handler)
19786 cld
19787 - cmpl $2,%ss:early_recursion_flag
19788 + cmpl $1,%ss:early_recursion_flag
19789 je hlt_loop
19790 incl %ss:early_recursion_flag
19791
19792 @@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
19793 pushl (20+6*4)(%esp) /* trapno */
19794 pushl $fault_msg
19795 call printk
19796 -#endif
19797 call dump_stack
19798 +#endif
19799 hlt_loop:
19800 hlt
19801 jmp hlt_loop
19802 @@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
19803 /* This is the default interrupt "handler" :-) */
19804 ALIGN
19805 ignore_int:
19806 - cld
19807 #ifdef CONFIG_PRINTK
19808 + cmpl $2,%ss:early_recursion_flag
19809 + je hlt_loop
19810 + incl %ss:early_recursion_flag
19811 + cld
19812 pushl %eax
19813 pushl %ecx
19814 pushl %edx
19815 @@ -644,9 +732,6 @@ ignore_int:
19816 movl $(__KERNEL_DS),%eax
19817 movl %eax,%ds
19818 movl %eax,%es
19819 - cmpl $2,early_recursion_flag
19820 - je hlt_loop
19821 - incl early_recursion_flag
19822 pushl 16(%esp)
19823 pushl 24(%esp)
19824 pushl 32(%esp)
19825 @@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
19826 /*
19827 * BSS section
19828 */
19829 -__PAGE_ALIGNED_BSS
19830 - .align PAGE_SIZE
19831 #ifdef CONFIG_X86_PAE
19832 +.section .initial_pg_pmd,"a",@progbits
19833 initial_pg_pmd:
19834 .fill 1024*KPMDS,4,0
19835 #else
19836 +.section .initial_page_table,"a",@progbits
19837 ENTRY(initial_page_table)
19838 .fill 1024,4,0
19839 #endif
19840 +.section .initial_pg_fixmap,"a",@progbits
19841 initial_pg_fixmap:
19842 .fill 1024,4,0
19843 +.section .empty_zero_page,"a",@progbits
19844 ENTRY(empty_zero_page)
19845 .fill 4096,1,0
19846 +.section .swapper_pg_dir,"a",@progbits
19847 ENTRY(swapper_pg_dir)
19848 +#ifdef CONFIG_X86_PAE
19849 + .fill 4,8,0
19850 +#else
19851 .fill 1024,4,0
19852 +#endif
19853 +
19854 +/*
19855 + * The IDT has to be page-aligned to simplify the Pentium
19856 + * F0 0F bug workaround.. We have a special link segment
19857 + * for this.
19858 + */
19859 +.section .idt,"a",@progbits
19860 +ENTRY(idt_table)
19861 + .fill 256,8,0
19862
19863 /*
19864 * This starts the data section.
19865 */
19866 #ifdef CONFIG_X86_PAE
19867 -__PAGE_ALIGNED_DATA
19868 - /* Page-aligned for the benefit of paravirt? */
19869 - .align PAGE_SIZE
19870 +.section .initial_page_table,"a",@progbits
19871 ENTRY(initial_page_table)
19872 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
19873 # if KPMDS == 3
19874 @@ -721,12 +820,20 @@ ENTRY(initial_page_table)
19875 # error "Kernel PMDs should be 1, 2 or 3"
19876 # endif
19877 .align PAGE_SIZE /* needs to be page-sized too */
19878 +
19879 +#ifdef CONFIG_PAX_PER_CPU_PGD
19880 +ENTRY(cpu_pgd)
19881 + .rept NR_CPUS
19882 + .fill 4,8,0
19883 + .endr
19884 +#endif
19885 +
19886 #endif
19887
19888 .data
19889 .balign 4
19890 ENTRY(stack_start)
19891 - .long init_thread_union+THREAD_SIZE
19892 + .long init_thread_union+THREAD_SIZE-8
19893
19894 __INITRODATA
19895 int_msg:
19896 @@ -754,7 +861,7 @@ fault_msg:
19897 * segment size, and 32-bit linear address value:
19898 */
19899
19900 - .data
19901 +.section .rodata,"a",@progbits
19902 .globl boot_gdt_descr
19903 .globl idt_descr
19904
19905 @@ -763,7 +870,7 @@ fault_msg:
19906 .word 0 # 32 bit align gdt_desc.address
19907 boot_gdt_descr:
19908 .word __BOOT_DS+7
19909 - .long boot_gdt - __PAGE_OFFSET
19910 + .long pa(boot_gdt)
19911
19912 .word 0 # 32-bit align idt_desc.address
19913 idt_descr:
19914 @@ -774,7 +881,7 @@ idt_descr:
19915 .word 0 # 32 bit align gdt_desc.address
19916 ENTRY(early_gdt_descr)
19917 .word GDT_ENTRIES*8-1
19918 - .long gdt_page /* Overwritten for secondary CPUs */
19919 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
19920
19921 /*
19922 * The boot_gdt must mirror the equivalent in setup.S and is
19923 @@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
19924 .align L1_CACHE_BYTES
19925 ENTRY(boot_gdt)
19926 .fill GDT_ENTRY_BOOT_CS,8,0
19927 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
19928 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
19929 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
19930 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
19931 +
19932 + .align PAGE_SIZE_asm
19933 +ENTRY(cpu_gdt_table)
19934 + .rept NR_CPUS
19935 + .quad 0x0000000000000000 /* NULL descriptor */
19936 + .quad 0x0000000000000000 /* 0x0b reserved */
19937 + .quad 0x0000000000000000 /* 0x13 reserved */
19938 + .quad 0x0000000000000000 /* 0x1b reserved */
19939 +
19940 +#ifdef CONFIG_PAX_KERNEXEC
19941 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
19942 +#else
19943 + .quad 0x0000000000000000 /* 0x20 unused */
19944 +#endif
19945 +
19946 + .quad 0x0000000000000000 /* 0x28 unused */
19947 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
19948 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
19949 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
19950 + .quad 0x0000000000000000 /* 0x4b reserved */
19951 + .quad 0x0000000000000000 /* 0x53 reserved */
19952 + .quad 0x0000000000000000 /* 0x5b reserved */
19953 +
19954 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
19955 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
19956 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
19957 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
19958 +
19959 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
19960 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
19961 +
19962 + /*
19963 + * Segments used for calling PnP BIOS have byte granularity.
19964 + * The code segments and data segments have fixed 64k limits,
19965 + * the transfer segment sizes are set at run time.
19966 + */
19967 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
19968 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
19969 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
19970 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
19971 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
19972 +
19973 + /*
19974 + * The APM segments have byte granularity and their bases
19975 + * are set at run time. All have 64k limits.
19976 + */
19977 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
19978 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
19979 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
19980 +
19981 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
19982 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
19983 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
19984 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
19985 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
19986 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
19987 +
19988 + /* Be sure this is zeroed to avoid false validations in Xen */
19989 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
19990 + .endr
19991 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
19992 index 980053c..74d3b44 100644
19993 --- a/arch/x86/kernel/head_64.S
19994 +++ b/arch/x86/kernel/head_64.S
19995 @@ -20,6 +20,8 @@
19996 #include <asm/processor-flags.h>
19997 #include <asm/percpu.h>
19998 #include <asm/nops.h>
19999 +#include <asm/cpufeature.h>
20000 +#include <asm/alternative-asm.h>
20001
20002 #ifdef CONFIG_PARAVIRT
20003 #include <asm/asm-offsets.h>
20004 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20005 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20006 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20007 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20008 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
20009 +L3_VMALLOC_START = pud_index(VMALLOC_START)
20010 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
20011 +L3_VMALLOC_END = pud_index(VMALLOC_END)
20012 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20013 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20014
20015 .text
20016 __HEAD
20017 @@ -88,35 +96,23 @@ startup_64:
20018 */
20019 addq %rbp, init_level4_pgt + 0(%rip)
20020 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20021 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20022 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20023 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20024 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20025
20026 addq %rbp, level3_ident_pgt + 0(%rip)
20027 +#ifndef CONFIG_XEN
20028 + addq %rbp, level3_ident_pgt + 8(%rip)
20029 +#endif
20030
20031 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20032 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20033 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20034 +
20035 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20036 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
20037
20038 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20039 -
20040 - /* Add an Identity mapping if I am above 1G */
20041 - leaq _text(%rip), %rdi
20042 - andq $PMD_PAGE_MASK, %rdi
20043 -
20044 - movq %rdi, %rax
20045 - shrq $PUD_SHIFT, %rax
20046 - andq $(PTRS_PER_PUD - 1), %rax
20047 - jz ident_complete
20048 -
20049 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
20050 - leaq level3_ident_pgt(%rip), %rbx
20051 - movq %rdx, 0(%rbx, %rax, 8)
20052 -
20053 - movq %rdi, %rax
20054 - shrq $PMD_SHIFT, %rax
20055 - andq $(PTRS_PER_PMD - 1), %rax
20056 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
20057 - leaq level2_spare_pgt(%rip), %rbx
20058 - movq %rdx, 0(%rbx, %rax, 8)
20059 -ident_complete:
20060 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20061
20062 /*
20063 * Fixup the kernel text+data virtual addresses. Note that
20064 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
20065 * after the boot processor executes this code.
20066 */
20067
20068 - /* Enable PAE mode and PGE */
20069 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
20070 + /* Enable PAE mode and PSE/PGE */
20071 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
20072 movq %rax, %cr4
20073
20074 /* Setup early boot stage 4 level pagetables. */
20075 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
20076 movl $MSR_EFER, %ecx
20077 rdmsr
20078 btsl $_EFER_SCE, %eax /* Enable System Call */
20079 - btl $20,%edi /* No Execute supported? */
20080 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20081 jnc 1f
20082 btsl $_EFER_NX, %eax
20083 + leaq init_level4_pgt(%rip), %rdi
20084 +#ifndef CONFIG_EFI
20085 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20086 +#endif
20087 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20088 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20089 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20090 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20091 1: wrmsr /* Make changes effective */
20092
20093 /* Setup cr0 */
20094 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
20095 * jump. In addition we need to ensure %cs is set so we make this
20096 * a far return.
20097 */
20098 + pax_set_fptr_mask
20099 movq initial_code(%rip),%rax
20100 pushq $0 # fake return address to stop unwinder
20101 pushq $__KERNEL_CS # set correct cs
20102 @@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
20103 bad_address:
20104 jmp bad_address
20105
20106 - .section ".init.text","ax"
20107 + __INIT
20108 .globl early_idt_handlers
20109 early_idt_handlers:
20110 # 104(%rsp) %rflags
20111 @@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
20112 call dump_stack
20113 #ifdef CONFIG_KALLSYMS
20114 leaq early_idt_ripmsg(%rip),%rdi
20115 - movq 40(%rsp),%rsi # %rip again
20116 + movq 88(%rsp),%rsi # %rip again
20117 call __print_symbol
20118 #endif
20119 #endif /* EARLY_PRINTK */
20120 @@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
20121 addq $16,%rsp # drop vector number and error code
20122 decl early_recursion_flag(%rip)
20123 INTERRUPT_RETURN
20124 + .previous
20125
20126 + __INITDATA
20127 .balign 4
20128 early_recursion_flag:
20129 .long 0
20130 + .previous
20131
20132 + .section .rodata,"a",@progbits
20133 #ifdef CONFIG_EARLY_PRINTK
20134 early_idt_msg:
20135 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20136 @@ -376,6 +385,7 @@ early_idt_ripmsg:
20137 #endif /* CONFIG_EARLY_PRINTK */
20138 .previous
20139
20140 + .section .rodata,"a",@progbits
20141 #define NEXT_PAGE(name) \
20142 .balign PAGE_SIZE; \
20143 ENTRY(name)
20144 @@ -388,7 +398,6 @@ ENTRY(name)
20145 i = i + 1 ; \
20146 .endr
20147
20148 - .data
20149 /*
20150 * This default setting generates an ident mapping at address 0x100000
20151 * and a mapping for the kernel that precisely maps virtual address
20152 @@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
20153 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20154 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20155 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20156 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
20157 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20158 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
20159 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20160 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20161 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20162 .org init_level4_pgt + L4_START_KERNEL*8, 0
20163 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20164 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20165
20166 +#ifdef CONFIG_PAX_PER_CPU_PGD
20167 +NEXT_PAGE(cpu_pgd)
20168 + .rept NR_CPUS
20169 + .fill 512,8,0
20170 + .endr
20171 +#endif
20172 +
20173 NEXT_PAGE(level3_ident_pgt)
20174 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20175 +#ifdef CONFIG_XEN
20176 .fill 511,8,0
20177 +#else
20178 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20179 + .fill 510,8,0
20180 +#endif
20181 +
20182 +NEXT_PAGE(level3_vmalloc_start_pgt)
20183 + .fill 512,8,0
20184 +
20185 +NEXT_PAGE(level3_vmalloc_end_pgt)
20186 + .fill 512,8,0
20187 +
20188 +NEXT_PAGE(level3_vmemmap_pgt)
20189 + .fill L3_VMEMMAP_START,8,0
20190 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20191
20192 NEXT_PAGE(level3_kernel_pgt)
20193 .fill L3_START_KERNEL,8,0
20194 @@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
20195 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20196 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20197
20198 +NEXT_PAGE(level2_vmemmap_pgt)
20199 + .fill 512,8,0
20200 +
20201 NEXT_PAGE(level2_fixmap_pgt)
20202 - .fill 506,8,0
20203 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20204 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20205 - .fill 5,8,0
20206 + .fill 507,8,0
20207 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20208 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20209 + .fill 4,8,0
20210
20211 -NEXT_PAGE(level1_fixmap_pgt)
20212 +NEXT_PAGE(level1_vsyscall_pgt)
20213 .fill 512,8,0
20214
20215 -NEXT_PAGE(level2_ident_pgt)
20216 - /* Since I easily can, map the first 1G.
20217 + /* Since I easily can, map the first 2G.
20218 * Don't set NX because code runs from these pages.
20219 */
20220 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20221 +NEXT_PAGE(level2_ident_pgt)
20222 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20223
20224 NEXT_PAGE(level2_kernel_pgt)
20225 /*
20226 @@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
20227 * If you want to increase this then increase MODULES_VADDR
20228 * too.)
20229 */
20230 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
20231 - KERNEL_IMAGE_SIZE/PMD_SIZE)
20232 -
20233 -NEXT_PAGE(level2_spare_pgt)
20234 - .fill 512, 8, 0
20235 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
20236
20237 #undef PMDS
20238 #undef NEXT_PAGE
20239
20240 - .data
20241 + .align PAGE_SIZE
20242 +ENTRY(cpu_gdt_table)
20243 + .rept NR_CPUS
20244 + .quad 0x0000000000000000 /* NULL descriptor */
20245 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20246 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
20247 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
20248 + .quad 0x00cffb000000ffff /* __USER32_CS */
20249 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20250 + .quad 0x00affb000000ffff /* __USER_CS */
20251 +
20252 +#ifdef CONFIG_PAX_KERNEXEC
20253 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20254 +#else
20255 + .quad 0x0 /* unused */
20256 +#endif
20257 +
20258 + .quad 0,0 /* TSS */
20259 + .quad 0,0 /* LDT */
20260 + .quad 0,0,0 /* three TLS descriptors */
20261 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
20262 + /* asm/segment.h:GDT_ENTRIES must match this */
20263 +
20264 + /* zero the remaining page */
20265 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20266 + .endr
20267 +
20268 .align 16
20269 .globl early_gdt_descr
20270 early_gdt_descr:
20271 .word GDT_ENTRIES*8-1
20272 early_gdt_descr_base:
20273 - .quad INIT_PER_CPU_VAR(gdt_page)
20274 + .quad cpu_gdt_table
20275
20276 ENTRY(phys_base)
20277 /* This must match the first entry in level2_kernel_pgt */
20278 .quad 0x0000000000000000
20279
20280 #include "../../x86/xen/xen-head.S"
20281 -
20282 - .section .bss, "aw", @nobits
20283 +
20284 + .section .rodata,"a",@progbits
20285 .align L1_CACHE_BYTES
20286 ENTRY(idt_table)
20287 - .skip IDT_ENTRIES * 16
20288 + .fill 512,8,0
20289
20290 .align L1_CACHE_BYTES
20291 ENTRY(nmi_idt_table)
20292 - .skip IDT_ENTRIES * 16
20293 + .fill 512,8,0
20294
20295 __PAGE_ALIGNED_BSS
20296 .align PAGE_SIZE
20297 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20298 index 9c3bd4a..e1d9b35 100644
20299 --- a/arch/x86/kernel/i386_ksyms_32.c
20300 +++ b/arch/x86/kernel/i386_ksyms_32.c
20301 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20302 EXPORT_SYMBOL(cmpxchg8b_emu);
20303 #endif
20304
20305 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
20306 +
20307 /* Networking helper routines. */
20308 EXPORT_SYMBOL(csum_partial_copy_generic);
20309 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20310 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20311
20312 EXPORT_SYMBOL(__get_user_1);
20313 EXPORT_SYMBOL(__get_user_2);
20314 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
20315
20316 EXPORT_SYMBOL(csum_partial);
20317 EXPORT_SYMBOL(empty_zero_page);
20318 +
20319 +#ifdef CONFIG_PAX_KERNEXEC
20320 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20321 +#endif
20322 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20323 index 245a71d..89d9ce4 100644
20324 --- a/arch/x86/kernel/i387.c
20325 +++ b/arch/x86/kernel/i387.c
20326 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20327 static inline bool interrupted_user_mode(void)
20328 {
20329 struct pt_regs *regs = get_irq_regs();
20330 - return regs && user_mode_vm(regs);
20331 + return regs && user_mode(regs);
20332 }
20333
20334 /*
20335 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20336 index 9a5c460..b332a4b 100644
20337 --- a/arch/x86/kernel/i8259.c
20338 +++ b/arch/x86/kernel/i8259.c
20339 @@ -209,7 +209,7 @@ spurious_8259A_irq:
20340 "spurious 8259A interrupt: IRQ%d.\n", irq);
20341 spurious_irq_mask |= irqmask;
20342 }
20343 - atomic_inc(&irq_err_count);
20344 + atomic_inc_unchecked(&irq_err_count);
20345 /*
20346 * Theoretically we do not have to handle this IRQ,
20347 * but in Linux this does not cause problems and is
20348 @@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20349 /* (slave's support for AEOI in flat mode is to be investigated) */
20350 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20351
20352 + pax_open_kernel();
20353 if (auto_eoi)
20354 /*
20355 * In AEOI mode we just have to mask the interrupt
20356 * when acking.
20357 */
20358 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
20359 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20360 else
20361 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20362 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20363 + pax_close_kernel();
20364
20365 udelay(100); /* wait for 8259A to initialize */
20366
20367 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20368 index a979b5b..1d6db75 100644
20369 --- a/arch/x86/kernel/io_delay.c
20370 +++ b/arch/x86/kernel/io_delay.c
20371 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20372 * Quirk table for systems that misbehave (lock up, etc.) if port
20373 * 0x80 is used:
20374 */
20375 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20376 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20377 {
20378 .callback = dmi_io_delay_0xed_port,
20379 .ident = "Compaq Presario V6000",
20380 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20381 index 8c96897..be66bfa 100644
20382 --- a/arch/x86/kernel/ioport.c
20383 +++ b/arch/x86/kernel/ioport.c
20384 @@ -6,6 +6,7 @@
20385 #include <linux/sched.h>
20386 #include <linux/kernel.h>
20387 #include <linux/capability.h>
20388 +#include <linux/security.h>
20389 #include <linux/errno.h>
20390 #include <linux/types.h>
20391 #include <linux/ioport.h>
20392 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20393
20394 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20395 return -EINVAL;
20396 +#ifdef CONFIG_GRKERNSEC_IO
20397 + if (turn_on && grsec_disable_privio) {
20398 + gr_handle_ioperm();
20399 + return -EPERM;
20400 + }
20401 +#endif
20402 if (turn_on && !capable(CAP_SYS_RAWIO))
20403 return -EPERM;
20404
20405 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20406 * because the ->io_bitmap_max value must match the bitmap
20407 * contents:
20408 */
20409 - tss = &per_cpu(init_tss, get_cpu());
20410 + tss = init_tss + get_cpu();
20411
20412 if (turn_on)
20413 bitmap_clear(t->io_bitmap_ptr, from, num);
20414 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
20415 return -EINVAL;
20416 /* Trying to gain more privileges? */
20417 if (level > old) {
20418 +#ifdef CONFIG_GRKERNSEC_IO
20419 + if (grsec_disable_privio) {
20420 + gr_handle_iopl();
20421 + return -EPERM;
20422 + }
20423 +#endif
20424 if (!capable(CAP_SYS_RAWIO))
20425 return -EPERM;
20426 }
20427 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20428 index e4595f1..ee3bfb8 100644
20429 --- a/arch/x86/kernel/irq.c
20430 +++ b/arch/x86/kernel/irq.c
20431 @@ -18,7 +18,7 @@
20432 #include <asm/mce.h>
20433 #include <asm/hw_irq.h>
20434
20435 -atomic_t irq_err_count;
20436 +atomic_unchecked_t irq_err_count;
20437
20438 /* Function pointer for generic interrupt vector handling */
20439 void (*x86_platform_ipi_callback)(void) = NULL;
20440 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20441 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20442 seq_printf(p, " Machine check polls\n");
20443 #endif
20444 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20445 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20446 #if defined(CONFIG_X86_IO_APIC)
20447 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20448 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20449 #endif
20450 return 0;
20451 }
20452 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20453
20454 u64 arch_irq_stat(void)
20455 {
20456 - u64 sum = atomic_read(&irq_err_count);
20457 + u64 sum = atomic_read_unchecked(&irq_err_count);
20458
20459 #ifdef CONFIG_X86_IO_APIC
20460 - sum += atomic_read(&irq_mis_count);
20461 + sum += atomic_read_unchecked(&irq_mis_count);
20462 #endif
20463 return sum;
20464 }
20465 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20466 index 344faf8..355f60d 100644
20467 --- a/arch/x86/kernel/irq_32.c
20468 +++ b/arch/x86/kernel/irq_32.c
20469 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20470 __asm__ __volatile__("andl %%esp,%0" :
20471 "=r" (sp) : "0" (THREAD_SIZE - 1));
20472
20473 - return sp < (sizeof(struct thread_info) + STACK_WARN);
20474 + return sp < STACK_WARN;
20475 }
20476
20477 static void print_stack_overflow(void)
20478 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20479 * per-CPU IRQ handling contexts (thread information and stack)
20480 */
20481 union irq_ctx {
20482 - struct thread_info tinfo;
20483 - u32 stack[THREAD_SIZE/sizeof(u32)];
20484 + unsigned long previous_esp;
20485 + u32 stack[THREAD_SIZE/sizeof(u32)];
20486 } __attribute__((aligned(THREAD_SIZE)));
20487
20488 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20489 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20490 static inline int
20491 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20492 {
20493 - union irq_ctx *curctx, *irqctx;
20494 + union irq_ctx *irqctx;
20495 u32 *isp, arg1, arg2;
20496
20497 - curctx = (union irq_ctx *) current_thread_info();
20498 irqctx = __this_cpu_read(hardirq_ctx);
20499
20500 /*
20501 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20502 * handler) we can't do that and just have to keep using the
20503 * current stack (which is the irq stack already after all)
20504 */
20505 - if (unlikely(curctx == irqctx))
20506 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20507 return 0;
20508
20509 /* build the stack frame on the IRQ stack */
20510 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20511 - irqctx->tinfo.task = curctx->tinfo.task;
20512 - irqctx->tinfo.previous_esp = current_stack_pointer;
20513 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20514 + irqctx->previous_esp = current_stack_pointer;
20515
20516 - /* Copy the preempt_count so that the [soft]irq checks work. */
20517 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20518 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20519 + __set_fs(MAKE_MM_SEG(0));
20520 +#endif
20521
20522 if (unlikely(overflow))
20523 call_on_stack(print_stack_overflow, isp);
20524 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20525 : "0" (irq), "1" (desc), "2" (isp),
20526 "D" (desc->handle_irq)
20527 : "memory", "cc", "ecx");
20528 +
20529 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20530 + __set_fs(current_thread_info()->addr_limit);
20531 +#endif
20532 +
20533 return 1;
20534 }
20535
20536 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20537 */
20538 void __cpuinit irq_ctx_init(int cpu)
20539 {
20540 - union irq_ctx *irqctx;
20541 -
20542 if (per_cpu(hardirq_ctx, cpu))
20543 return;
20544
20545 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20546 - THREADINFO_GFP,
20547 - THREAD_SIZE_ORDER));
20548 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20549 - irqctx->tinfo.cpu = cpu;
20550 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
20551 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20552 -
20553 - per_cpu(hardirq_ctx, cpu) = irqctx;
20554 -
20555 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20556 - THREADINFO_GFP,
20557 - THREAD_SIZE_ORDER));
20558 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20559 - irqctx->tinfo.cpu = cpu;
20560 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20561 -
20562 - per_cpu(softirq_ctx, cpu) = irqctx;
20563 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20564 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20565 +
20566 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20567 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20568
20569 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20570 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20571 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
20572 asmlinkage void do_softirq(void)
20573 {
20574 unsigned long flags;
20575 - struct thread_info *curctx;
20576 union irq_ctx *irqctx;
20577 u32 *isp;
20578
20579 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
20580 local_irq_save(flags);
20581
20582 if (local_softirq_pending()) {
20583 - curctx = current_thread_info();
20584 irqctx = __this_cpu_read(softirq_ctx);
20585 - irqctx->tinfo.task = curctx->task;
20586 - irqctx->tinfo.previous_esp = current_stack_pointer;
20587 + irqctx->previous_esp = current_stack_pointer;
20588
20589 /* build the stack frame on the softirq stack */
20590 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20591 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20592 +
20593 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20594 + __set_fs(MAKE_MM_SEG(0));
20595 +#endif
20596
20597 call_on_stack(__do_softirq, isp);
20598 +
20599 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20600 + __set_fs(current_thread_info()->addr_limit);
20601 +#endif
20602 +
20603 /*
20604 * Shouldn't happen, we returned above if in_interrupt():
20605 */
20606 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
20607 if (unlikely(!desc))
20608 return false;
20609
20610 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20611 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20612 if (unlikely(overflow))
20613 print_stack_overflow();
20614 desc->handle_irq(irq, desc);
20615 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
20616 index d04d3ec..ea4b374 100644
20617 --- a/arch/x86/kernel/irq_64.c
20618 +++ b/arch/x86/kernel/irq_64.c
20619 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
20620 u64 estack_top, estack_bottom;
20621 u64 curbase = (u64)task_stack_page(current);
20622
20623 - if (user_mode_vm(regs))
20624 + if (user_mode(regs))
20625 return;
20626
20627 if (regs->sp >= curbase + sizeof(struct thread_info) +
20628 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
20629 index dc1404b..bbc43e7 100644
20630 --- a/arch/x86/kernel/kdebugfs.c
20631 +++ b/arch/x86/kernel/kdebugfs.c
20632 @@ -27,7 +27,7 @@ struct setup_data_node {
20633 u32 len;
20634 };
20635
20636 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
20637 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
20638 size_t count, loff_t *ppos)
20639 {
20640 struct setup_data_node *node = file->private_data;
20641 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
20642 index 836f832..a8bda67 100644
20643 --- a/arch/x86/kernel/kgdb.c
20644 +++ b/arch/x86/kernel/kgdb.c
20645 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
20646 #ifdef CONFIG_X86_32
20647 switch (regno) {
20648 case GDB_SS:
20649 - if (!user_mode_vm(regs))
20650 + if (!user_mode(regs))
20651 *(unsigned long *)mem = __KERNEL_DS;
20652 break;
20653 case GDB_SP:
20654 - if (!user_mode_vm(regs))
20655 + if (!user_mode(regs))
20656 *(unsigned long *)mem = kernel_stack_pointer(regs);
20657 break;
20658 case GDB_GS:
20659 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
20660 bp->attr.bp_addr = breakinfo[breakno].addr;
20661 bp->attr.bp_len = breakinfo[breakno].len;
20662 bp->attr.bp_type = breakinfo[breakno].type;
20663 - info->address = breakinfo[breakno].addr;
20664 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
20665 + info->address = ktla_ktva(breakinfo[breakno].addr);
20666 + else
20667 + info->address = breakinfo[breakno].addr;
20668 info->len = breakinfo[breakno].len;
20669 info->type = breakinfo[breakno].type;
20670 val = arch_install_hw_breakpoint(bp);
20671 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
20672 case 'k':
20673 /* clear the trace bit */
20674 linux_regs->flags &= ~X86_EFLAGS_TF;
20675 - atomic_set(&kgdb_cpu_doing_single_step, -1);
20676 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
20677
20678 /* set the trace bit if we're stepping */
20679 if (remcomInBuffer[0] == 's') {
20680 linux_regs->flags |= X86_EFLAGS_TF;
20681 - atomic_set(&kgdb_cpu_doing_single_step,
20682 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
20683 raw_smp_processor_id());
20684 }
20685
20686 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
20687
20688 switch (cmd) {
20689 case DIE_DEBUG:
20690 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
20691 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
20692 if (user_mode(regs))
20693 return single_step_cont(regs, args);
20694 break;
20695 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20696 #endif /* CONFIG_DEBUG_RODATA */
20697
20698 bpt->type = BP_BREAKPOINT;
20699 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
20700 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
20701 BREAK_INSTR_SIZE);
20702 if (err)
20703 return err;
20704 - err = probe_kernel_write((char *)bpt->bpt_addr,
20705 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20706 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
20707 #ifdef CONFIG_DEBUG_RODATA
20708 if (!err)
20709 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20710 return -EBUSY;
20711 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
20712 BREAK_INSTR_SIZE);
20713 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20714 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20715 if (err)
20716 return err;
20717 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
20718 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
20719 if (mutex_is_locked(&text_mutex))
20720 goto knl_write;
20721 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
20722 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20723 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20724 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
20725 goto knl_write;
20726 return err;
20727 knl_write:
20728 #endif /* CONFIG_DEBUG_RODATA */
20729 - return probe_kernel_write((char *)bpt->bpt_addr,
20730 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20731 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
20732 }
20733
20734 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
20735 index c5e410e..ed5a7f0 100644
20736 --- a/arch/x86/kernel/kprobes-opt.c
20737 +++ b/arch/x86/kernel/kprobes-opt.c
20738 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20739 * Verify if the address gap is in 2GB range, because this uses
20740 * a relative jump.
20741 */
20742 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
20743 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
20744 if (abs(rel) > 0x7fffffff)
20745 return -ERANGE;
20746
20747 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20748 op->optinsn.size = ret;
20749
20750 /* Copy arch-dep-instance from template */
20751 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
20752 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
20753
20754 /* Set probe information */
20755 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
20756
20757 /* Set probe function call */
20758 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
20759 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
20760
20761 /* Set returning jmp instruction at the tail of out-of-line buffer */
20762 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
20763 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
20764 (u8 *)op->kp.addr + op->optinsn.size);
20765
20766 flush_icache_range((unsigned long) buf,
20767 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
20768 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
20769
20770 /* Backup instructions which will be replaced by jump address */
20771 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
20772 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
20773 RELATIVE_ADDR_SIZE);
20774
20775 insn_buf[0] = RELATIVEJUMP_OPCODE;
20776 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
20777 /* This kprobe is really able to run optimized path. */
20778 op = container_of(p, struct optimized_kprobe, kp);
20779 /* Detour through copied instructions */
20780 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
20781 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
20782 if (!reenter)
20783 reset_current_kprobe();
20784 preempt_enable_no_resched();
20785 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
20786 index 57916c0..9e0b9d0 100644
20787 --- a/arch/x86/kernel/kprobes.c
20788 +++ b/arch/x86/kernel/kprobes.c
20789 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
20790 s32 raddr;
20791 } __attribute__((packed)) *insn;
20792
20793 - insn = (struct __arch_relative_insn *)from;
20794 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
20795 +
20796 + pax_open_kernel();
20797 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
20798 insn->op = op;
20799 + pax_close_kernel();
20800 }
20801
20802 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
20803 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
20804 kprobe_opcode_t opcode;
20805 kprobe_opcode_t *orig_opcodes = opcodes;
20806
20807 - if (search_exception_tables((unsigned long)opcodes))
20808 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
20809 return 0; /* Page fault may occur on this address. */
20810
20811 retry:
20812 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
20813 * for the first byte, we can recover the original instruction
20814 * from it and kp->opcode.
20815 */
20816 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20817 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20818 buf[0] = kp->opcode;
20819 - return (unsigned long)buf;
20820 + return ktva_ktla((unsigned long)buf);
20821 }
20822
20823 /*
20824 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20825 /* Another subsystem puts a breakpoint, failed to recover */
20826 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
20827 return 0;
20828 + pax_open_kernel();
20829 memcpy(dest, insn.kaddr, insn.length);
20830 + pax_close_kernel();
20831
20832 #ifdef CONFIG_X86_64
20833 if (insn_rip_relative(&insn)) {
20834 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20835 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
20836 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
20837 disp = (u8 *) dest + insn_offset_displacement(&insn);
20838 + pax_open_kernel();
20839 *(s32 *) disp = (s32) newdisp;
20840 + pax_close_kernel();
20841 }
20842 #endif
20843 return insn.length;
20844 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20845 * nor set current_kprobe, because it doesn't use single
20846 * stepping.
20847 */
20848 - regs->ip = (unsigned long)p->ainsn.insn;
20849 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20850 preempt_enable_no_resched();
20851 return;
20852 }
20853 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20854 regs->flags &= ~X86_EFLAGS_IF;
20855 /* single step inline if the instruction is an int3 */
20856 if (p->opcode == BREAKPOINT_INSTRUCTION)
20857 - regs->ip = (unsigned long)p->addr;
20858 + regs->ip = ktla_ktva((unsigned long)p->addr);
20859 else
20860 - regs->ip = (unsigned long)p->ainsn.insn;
20861 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20862 }
20863
20864 /*
20865 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
20866 setup_singlestep(p, regs, kcb, 0);
20867 return 1;
20868 }
20869 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
20870 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
20871 /*
20872 * The breakpoint instruction was removed right
20873 * after we hit it. Another cpu has removed
20874 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
20875 " movq %rax, 152(%rsp)\n"
20876 RESTORE_REGS_STRING
20877 " popfq\n"
20878 +#ifdef KERNEXEC_PLUGIN
20879 + " btsq $63,(%rsp)\n"
20880 +#endif
20881 #else
20882 " pushf\n"
20883 SAVE_REGS_STRING
20884 @@ -788,7 +798,7 @@ static void __kprobes
20885 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
20886 {
20887 unsigned long *tos = stack_addr(regs);
20888 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
20889 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
20890 unsigned long orig_ip = (unsigned long)p->addr;
20891 kprobe_opcode_t *insn = p->ainsn.insn;
20892
20893 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
20894 struct die_args *args = data;
20895 int ret = NOTIFY_DONE;
20896
20897 - if (args->regs && user_mode_vm(args->regs))
20898 + if (args->regs && user_mode(args->regs))
20899 return ret;
20900
20901 switch (val) {
20902 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
20903 index 9c2bd8b..bb1131c 100644
20904 --- a/arch/x86/kernel/kvm.c
20905 +++ b/arch/x86/kernel/kvm.c
20906 @@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
20907 return NOTIFY_OK;
20908 }
20909
20910 -static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
20911 +static struct notifier_block kvm_cpu_notifier = {
20912 .notifier_call = kvm_cpu_notify,
20913 };
20914 #endif
20915 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
20916 index ebc9873..1b9724b 100644
20917 --- a/arch/x86/kernel/ldt.c
20918 +++ b/arch/x86/kernel/ldt.c
20919 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
20920 if (reload) {
20921 #ifdef CONFIG_SMP
20922 preempt_disable();
20923 - load_LDT(pc);
20924 + load_LDT_nolock(pc);
20925 if (!cpumask_equal(mm_cpumask(current->mm),
20926 cpumask_of(smp_processor_id())))
20927 smp_call_function(flush_ldt, current->mm, 1);
20928 preempt_enable();
20929 #else
20930 - load_LDT(pc);
20931 + load_LDT_nolock(pc);
20932 #endif
20933 }
20934 if (oldsize) {
20935 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
20936 return err;
20937
20938 for (i = 0; i < old->size; i++)
20939 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
20940 + write_ldt_entry(new->ldt, i, old->ldt + i);
20941 return 0;
20942 }
20943
20944 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
20945 retval = copy_ldt(&mm->context, &old_mm->context);
20946 mutex_unlock(&old_mm->context.lock);
20947 }
20948 +
20949 + if (tsk == current) {
20950 + mm->context.vdso = 0;
20951 +
20952 +#ifdef CONFIG_X86_32
20953 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
20954 + mm->context.user_cs_base = 0UL;
20955 + mm->context.user_cs_limit = ~0UL;
20956 +
20957 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
20958 + cpus_clear(mm->context.cpu_user_cs_mask);
20959 +#endif
20960 +
20961 +#endif
20962 +#endif
20963 +
20964 + }
20965 +
20966 return retval;
20967 }
20968
20969 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
20970 }
20971 }
20972
20973 +#ifdef CONFIG_PAX_SEGMEXEC
20974 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
20975 + error = -EINVAL;
20976 + goto out_unlock;
20977 + }
20978 +#endif
20979 +
20980 fill_ldt(&ldt, &ldt_info);
20981 if (oldmode)
20982 ldt.avl = 0;
20983 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
20984 index 5b19e4d..6476a76 100644
20985 --- a/arch/x86/kernel/machine_kexec_32.c
20986 +++ b/arch/x86/kernel/machine_kexec_32.c
20987 @@ -26,7 +26,7 @@
20988 #include <asm/cacheflush.h>
20989 #include <asm/debugreg.h>
20990
20991 -static void set_idt(void *newidt, __u16 limit)
20992 +static void set_idt(struct desc_struct *newidt, __u16 limit)
20993 {
20994 struct desc_ptr curidt;
20995
20996 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
20997 }
20998
20999
21000 -static void set_gdt(void *newgdt, __u16 limit)
21001 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21002 {
21003 struct desc_ptr curgdt;
21004
21005 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21006 }
21007
21008 control_page = page_address(image->control_code_page);
21009 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21010 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21011
21012 relocate_kernel_ptr = control_page;
21013 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21014 diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21015 index 3a04b22..1d2eb09 100644
21016 --- a/arch/x86/kernel/microcode_core.c
21017 +++ b/arch/x86/kernel/microcode_core.c
21018 @@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21019 return NOTIFY_OK;
21020 }
21021
21022 -static struct notifier_block __refdata mc_cpu_notifier = {
21023 +static struct notifier_block mc_cpu_notifier = {
21024 .notifier_call = mc_cpu_callback,
21025 };
21026
21027 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21028 index 3544aed..01ddc1c 100644
21029 --- a/arch/x86/kernel/microcode_intel.c
21030 +++ b/arch/x86/kernel/microcode_intel.c
21031 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21032
21033 static int get_ucode_user(void *to, const void *from, size_t n)
21034 {
21035 - return copy_from_user(to, from, n);
21036 + return copy_from_user(to, (const void __force_user *)from, n);
21037 }
21038
21039 static enum ucode_state
21040 request_microcode_user(int cpu, const void __user *buf, size_t size)
21041 {
21042 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21043 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21044 }
21045
21046 static void microcode_fini_cpu(int cpu)
21047 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21048 index 216a4d7..228255a 100644
21049 --- a/arch/x86/kernel/module.c
21050 +++ b/arch/x86/kernel/module.c
21051 @@ -43,15 +43,60 @@ do { \
21052 } while (0)
21053 #endif
21054
21055 -void *module_alloc(unsigned long size)
21056 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21057 {
21058 - if (PAGE_ALIGN(size) > MODULES_LEN)
21059 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21060 return NULL;
21061 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21062 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21063 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21064 -1, __builtin_return_address(0));
21065 }
21066
21067 +void *module_alloc(unsigned long size)
21068 +{
21069 +
21070 +#ifdef CONFIG_PAX_KERNEXEC
21071 + return __module_alloc(size, PAGE_KERNEL);
21072 +#else
21073 + return __module_alloc(size, PAGE_KERNEL_EXEC);
21074 +#endif
21075 +
21076 +}
21077 +
21078 +#ifdef CONFIG_PAX_KERNEXEC
21079 +#ifdef CONFIG_X86_32
21080 +void *module_alloc_exec(unsigned long size)
21081 +{
21082 + struct vm_struct *area;
21083 +
21084 + if (size == 0)
21085 + return NULL;
21086 +
21087 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21088 + return area ? area->addr : NULL;
21089 +}
21090 +EXPORT_SYMBOL(module_alloc_exec);
21091 +
21092 +void module_free_exec(struct module *mod, void *module_region)
21093 +{
21094 + vunmap(module_region);
21095 +}
21096 +EXPORT_SYMBOL(module_free_exec);
21097 +#else
21098 +void module_free_exec(struct module *mod, void *module_region)
21099 +{
21100 + module_free(mod, module_region);
21101 +}
21102 +EXPORT_SYMBOL(module_free_exec);
21103 +
21104 +void *module_alloc_exec(unsigned long size)
21105 +{
21106 + return __module_alloc(size, PAGE_KERNEL_RX);
21107 +}
21108 +EXPORT_SYMBOL(module_alloc_exec);
21109 +#endif
21110 +#endif
21111 +
21112 #ifdef CONFIG_X86_32
21113 int apply_relocate(Elf32_Shdr *sechdrs,
21114 const char *strtab,
21115 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21116 unsigned int i;
21117 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21118 Elf32_Sym *sym;
21119 - uint32_t *location;
21120 + uint32_t *plocation, location;
21121
21122 DEBUGP("Applying relocate section %u to %u\n",
21123 relsec, sechdrs[relsec].sh_info);
21124 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21125 /* This is where to make the change */
21126 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21127 - + rel[i].r_offset;
21128 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21129 + location = (uint32_t)plocation;
21130 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21131 + plocation = ktla_ktva((void *)plocation);
21132 /* This is the symbol it is referring to. Note that all
21133 undefined symbols have been resolved. */
21134 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21135 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21136 switch (ELF32_R_TYPE(rel[i].r_info)) {
21137 case R_386_32:
21138 /* We add the value into the location given */
21139 - *location += sym->st_value;
21140 + pax_open_kernel();
21141 + *plocation += sym->st_value;
21142 + pax_close_kernel();
21143 break;
21144 case R_386_PC32:
21145 /* Add the value, subtract its position */
21146 - *location += sym->st_value - (uint32_t)location;
21147 + pax_open_kernel();
21148 + *plocation += sym->st_value - location;
21149 + pax_close_kernel();
21150 break;
21151 default:
21152 pr_err("%s: Unknown relocation: %u\n",
21153 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21154 case R_X86_64_NONE:
21155 break;
21156 case R_X86_64_64:
21157 + pax_open_kernel();
21158 *(u64 *)loc = val;
21159 + pax_close_kernel();
21160 break;
21161 case R_X86_64_32:
21162 + pax_open_kernel();
21163 *(u32 *)loc = val;
21164 + pax_close_kernel();
21165 if (val != *(u32 *)loc)
21166 goto overflow;
21167 break;
21168 case R_X86_64_32S:
21169 + pax_open_kernel();
21170 *(s32 *)loc = val;
21171 + pax_close_kernel();
21172 if ((s64)val != *(s32 *)loc)
21173 goto overflow;
21174 break;
21175 case R_X86_64_PC32:
21176 val -= (u64)loc;
21177 + pax_open_kernel();
21178 *(u32 *)loc = val;
21179 + pax_close_kernel();
21180 +
21181 #if 0
21182 if ((s64)val != *(s32 *)loc)
21183 goto overflow;
21184 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21185 index 4929502..686c291 100644
21186 --- a/arch/x86/kernel/msr.c
21187 +++ b/arch/x86/kernel/msr.c
21188 @@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21189 return notifier_from_errno(err);
21190 }
21191
21192 -static struct notifier_block __refdata msr_class_cpu_notifier = {
21193 +static struct notifier_block msr_class_cpu_notifier = {
21194 .notifier_call = msr_class_cpu_callback,
21195 };
21196
21197 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21198 index f84f5c5..861d20d 100644
21199 --- a/arch/x86/kernel/nmi.c
21200 +++ b/arch/x86/kernel/nmi.c
21201 @@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21202 * event confuses some handlers (kdump uses this flag)
21203 */
21204 if (action->flags & NMI_FLAG_FIRST)
21205 - list_add_rcu(&action->list, &desc->head);
21206 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21207 else
21208 - list_add_tail_rcu(&action->list, &desc->head);
21209 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21210
21211 spin_unlock_irqrestore(&desc->lock, flags);
21212 return 0;
21213 @@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21214 if (!strcmp(n->name, name)) {
21215 WARN(in_nmi(),
21216 "Trying to free NMI (%s) from NMI context!\n", n->name);
21217 - list_del_rcu(&n->list);
21218 + pax_list_del_rcu((struct list_head *)&n->list);
21219 break;
21220 }
21221 }
21222 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21223 dotraplinkage notrace __kprobes void
21224 do_nmi(struct pt_regs *regs, long error_code)
21225 {
21226 +
21227 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21228 + if (!user_mode(regs)) {
21229 + unsigned long cs = regs->cs & 0xFFFF;
21230 + unsigned long ip = ktva_ktla(regs->ip);
21231 +
21232 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21233 + regs->ip = ip;
21234 + }
21235 +#endif
21236 +
21237 nmi_nesting_preprocess(regs);
21238
21239 nmi_enter();
21240 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21241 index 6d9582e..f746287 100644
21242 --- a/arch/x86/kernel/nmi_selftest.c
21243 +++ b/arch/x86/kernel/nmi_selftest.c
21244 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21245 {
21246 /* trap all the unknown NMIs we may generate */
21247 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21248 - __initdata);
21249 + __initconst);
21250 }
21251
21252 static void __init cleanup_nmi_testsuite(void)
21253 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21254 unsigned long timeout;
21255
21256 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21257 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21258 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21259 nmi_fail = FAILURE;
21260 return;
21261 }
21262 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21263 index 676b8c7..870ba04 100644
21264 --- a/arch/x86/kernel/paravirt-spinlocks.c
21265 +++ b/arch/x86/kernel/paravirt-spinlocks.c
21266 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21267 arch_spin_lock(lock);
21268 }
21269
21270 -struct pv_lock_ops pv_lock_ops = {
21271 +struct pv_lock_ops pv_lock_ops __read_only = {
21272 #ifdef CONFIG_SMP
21273 .spin_is_locked = __ticket_spin_is_locked,
21274 .spin_is_contended = __ticket_spin_is_contended,
21275 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21276 index 17fff18..5cfa0f4 100644
21277 --- a/arch/x86/kernel/paravirt.c
21278 +++ b/arch/x86/kernel/paravirt.c
21279 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21280 {
21281 return x;
21282 }
21283 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21284 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21285 +#endif
21286
21287 void __init default_banner(void)
21288 {
21289 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21290 if (opfunc == NULL)
21291 /* If there's no function, patch it with a ud2a (BUG) */
21292 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21293 - else if (opfunc == _paravirt_nop)
21294 + else if (opfunc == (void *)_paravirt_nop)
21295 /* If the operation is a nop, then nop the callsite */
21296 ret = paravirt_patch_nop();
21297
21298 /* identity functions just return their single argument */
21299 - else if (opfunc == _paravirt_ident_32)
21300 + else if (opfunc == (void *)_paravirt_ident_32)
21301 ret = paravirt_patch_ident_32(insnbuf, len);
21302 - else if (opfunc == _paravirt_ident_64)
21303 + else if (opfunc == (void *)_paravirt_ident_64)
21304 ret = paravirt_patch_ident_64(insnbuf, len);
21305 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21306 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21307 + ret = paravirt_patch_ident_64(insnbuf, len);
21308 +#endif
21309
21310 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21311 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21312 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21313 if (insn_len > len || start == NULL)
21314 insn_len = len;
21315 else
21316 - memcpy(insnbuf, start, insn_len);
21317 + memcpy(insnbuf, ktla_ktva(start), insn_len);
21318
21319 return insn_len;
21320 }
21321 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
21322 preempt_enable();
21323 }
21324
21325 -struct pv_info pv_info = {
21326 +struct pv_info pv_info __read_only = {
21327 .name = "bare hardware",
21328 .paravirt_enabled = 0,
21329 .kernel_rpl = 0,
21330 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
21331 #endif
21332 };
21333
21334 -struct pv_init_ops pv_init_ops = {
21335 +struct pv_init_ops pv_init_ops __read_only = {
21336 .patch = native_patch,
21337 };
21338
21339 -struct pv_time_ops pv_time_ops = {
21340 +struct pv_time_ops pv_time_ops __read_only = {
21341 .sched_clock = native_sched_clock,
21342 .steal_clock = native_steal_clock,
21343 };
21344
21345 -struct pv_irq_ops pv_irq_ops = {
21346 +struct pv_irq_ops pv_irq_ops __read_only = {
21347 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21348 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21349 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21350 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21351 #endif
21352 };
21353
21354 -struct pv_cpu_ops pv_cpu_ops = {
21355 +struct pv_cpu_ops pv_cpu_ops __read_only = {
21356 .cpuid = native_cpuid,
21357 .get_debugreg = native_get_debugreg,
21358 .set_debugreg = native_set_debugreg,
21359 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21360 .end_context_switch = paravirt_nop,
21361 };
21362
21363 -struct pv_apic_ops pv_apic_ops = {
21364 +struct pv_apic_ops pv_apic_ops __read_only= {
21365 #ifdef CONFIG_X86_LOCAL_APIC
21366 .startup_ipi_hook = paravirt_nop,
21367 #endif
21368 };
21369
21370 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21371 +#ifdef CONFIG_X86_32
21372 +#ifdef CONFIG_X86_PAE
21373 +/* 64-bit pagetable entries */
21374 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21375 +#else
21376 /* 32-bit pagetable entries */
21377 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21378 +#endif
21379 #else
21380 /* 64-bit pagetable entries */
21381 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21382 #endif
21383
21384 -struct pv_mmu_ops pv_mmu_ops = {
21385 +struct pv_mmu_ops pv_mmu_ops __read_only = {
21386
21387 .read_cr2 = native_read_cr2,
21388 .write_cr2 = native_write_cr2,
21389 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21390 .make_pud = PTE_IDENT,
21391
21392 .set_pgd = native_set_pgd,
21393 + .set_pgd_batched = native_set_pgd_batched,
21394 #endif
21395 #endif /* PAGETABLE_LEVELS >= 3 */
21396
21397 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21398 },
21399
21400 .set_fixmap = native_set_fixmap,
21401 +
21402 +#ifdef CONFIG_PAX_KERNEXEC
21403 + .pax_open_kernel = native_pax_open_kernel,
21404 + .pax_close_kernel = native_pax_close_kernel,
21405 +#endif
21406 +
21407 };
21408
21409 EXPORT_SYMBOL_GPL(pv_time_ops);
21410 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21411 index 35ccf75..7a15747 100644
21412 --- a/arch/x86/kernel/pci-iommu_table.c
21413 +++ b/arch/x86/kernel/pci-iommu_table.c
21414 @@ -2,7 +2,7 @@
21415 #include <asm/iommu_table.h>
21416 #include <linux/string.h>
21417 #include <linux/kallsyms.h>
21418 -
21419 +#include <linux/sched.h>
21420
21421 #define DEBUG 1
21422
21423 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
21424 index 6c483ba..d10ce2f 100644
21425 --- a/arch/x86/kernel/pci-swiotlb.c
21426 +++ b/arch/x86/kernel/pci-swiotlb.c
21427 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
21428 void *vaddr, dma_addr_t dma_addr,
21429 struct dma_attrs *attrs)
21430 {
21431 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
21432 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
21433 }
21434
21435 static struct dma_map_ops swiotlb_dma_ops = {
21436 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21437 index 2ed787f..f70c9f6 100644
21438 --- a/arch/x86/kernel/process.c
21439 +++ b/arch/x86/kernel/process.c
21440 @@ -36,7 +36,8 @@
21441 * section. Since TSS's are completely CPU-local, we want them
21442 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21443 */
21444 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21445 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21446 +EXPORT_SYMBOL(init_tss);
21447
21448 #ifdef CONFIG_X86_64
21449 static DEFINE_PER_CPU(unsigned char, is_idle);
21450 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21451 task_xstate_cachep =
21452 kmem_cache_create("task_xstate", xstate_size,
21453 __alignof__(union thread_xstate),
21454 - SLAB_PANIC | SLAB_NOTRACK, NULL);
21455 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21456 }
21457
21458 /*
21459 @@ -105,7 +106,7 @@ void exit_thread(void)
21460 unsigned long *bp = t->io_bitmap_ptr;
21461
21462 if (bp) {
21463 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21464 + struct tss_struct *tss = init_tss + get_cpu();
21465
21466 t->io_bitmap_ptr = NULL;
21467 clear_thread_flag(TIF_IO_BITMAP);
21468 @@ -136,7 +137,7 @@ void show_regs_common(void)
21469 board = dmi_get_system_info(DMI_BOARD_NAME);
21470
21471 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21472 - current->pid, current->comm, print_tainted(),
21473 + task_pid_nr(current), current->comm, print_tainted(),
21474 init_utsname()->release,
21475 (int)strcspn(init_utsname()->version, " "),
21476 init_utsname()->version,
21477 @@ -149,6 +150,9 @@ void flush_thread(void)
21478 {
21479 struct task_struct *tsk = current;
21480
21481 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21482 + loadsegment(gs, 0);
21483 +#endif
21484 flush_ptrace_hw_breakpoint(tsk);
21485 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21486 drop_init_fpu(tsk);
21487 @@ -301,7 +305,7 @@ static void __exit_idle(void)
21488 void exit_idle(void)
21489 {
21490 /* idle loop has pid 0 */
21491 - if (current->pid)
21492 + if (task_pid_nr(current))
21493 return;
21494 __exit_idle();
21495 }
21496 @@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
21497
21498 return ret;
21499 }
21500 -void stop_this_cpu(void *dummy)
21501 +__noreturn void stop_this_cpu(void *dummy)
21502 {
21503 local_irq_disable();
21504 /*
21505 @@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
21506 }
21507 early_param("idle", idle_setup);
21508
21509 -unsigned long arch_align_stack(unsigned long sp)
21510 +#ifdef CONFIG_PAX_RANDKSTACK
21511 +void pax_randomize_kstack(struct pt_regs *regs)
21512 {
21513 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
21514 - sp -= get_random_int() % 8192;
21515 - return sp & ~0xf;
21516 -}
21517 + struct thread_struct *thread = &current->thread;
21518 + unsigned long time;
21519
21520 -unsigned long arch_randomize_brk(struct mm_struct *mm)
21521 -{
21522 - unsigned long range_end = mm->brk + 0x02000000;
21523 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
21524 -}
21525 + if (!randomize_va_space)
21526 + return;
21527 +
21528 + if (v8086_mode(regs))
21529 + return;
21530
21531 + rdtscl(time);
21532 +
21533 + /* P4 seems to return a 0 LSB, ignore it */
21534 +#ifdef CONFIG_MPENTIUM4
21535 + time &= 0x3EUL;
21536 + time <<= 2;
21537 +#elif defined(CONFIG_X86_64)
21538 + time &= 0xFUL;
21539 + time <<= 4;
21540 +#else
21541 + time &= 0x1FUL;
21542 + time <<= 3;
21543 +#endif
21544 +
21545 + thread->sp0 ^= time;
21546 + load_sp0(init_tss + smp_processor_id(), thread);
21547 +
21548 +#ifdef CONFIG_X86_64
21549 + this_cpu_write(kernel_stack, thread->sp0);
21550 +#endif
21551 +}
21552 +#endif
21553 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
21554 index b5a8905..d9cacac 100644
21555 --- a/arch/x86/kernel/process_32.c
21556 +++ b/arch/x86/kernel/process_32.c
21557 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
21558 unsigned long thread_saved_pc(struct task_struct *tsk)
21559 {
21560 return ((unsigned long *)tsk->thread.sp)[3];
21561 +//XXX return tsk->thread.eip;
21562 }
21563
21564 void __show_regs(struct pt_regs *regs, int all)
21565 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
21566 unsigned long sp;
21567 unsigned short ss, gs;
21568
21569 - if (user_mode_vm(regs)) {
21570 + if (user_mode(regs)) {
21571 sp = regs->sp;
21572 ss = regs->ss & 0xffff;
21573 - gs = get_user_gs(regs);
21574 } else {
21575 sp = kernel_stack_pointer(regs);
21576 savesegment(ss, ss);
21577 - savesegment(gs, gs);
21578 }
21579 + gs = get_user_gs(regs);
21580
21581 show_regs_common();
21582
21583 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
21584 (u16)regs->cs, regs->ip, regs->flags,
21585 - smp_processor_id());
21586 + raw_smp_processor_id());
21587 print_symbol("EIP is at %s\n", regs->ip);
21588
21589 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
21590 @@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
21591 int copy_thread(unsigned long clone_flags, unsigned long sp,
21592 unsigned long arg, struct task_struct *p)
21593 {
21594 - struct pt_regs *childregs = task_pt_regs(p);
21595 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
21596 struct task_struct *tsk;
21597 int err;
21598
21599 p->thread.sp = (unsigned long) childregs;
21600 p->thread.sp0 = (unsigned long) (childregs+1);
21601 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21602
21603 if (unlikely(p->flags & PF_KTHREAD)) {
21604 /* kernel thread */
21605 memset(childregs, 0, sizeof(struct pt_regs));
21606 p->thread.ip = (unsigned long) ret_from_kernel_thread;
21607 - task_user_gs(p) = __KERNEL_STACK_CANARY;
21608 - childregs->ds = __USER_DS;
21609 - childregs->es = __USER_DS;
21610 + savesegment(gs, childregs->gs);
21611 + childregs->ds = __KERNEL_DS;
21612 + childregs->es = __KERNEL_DS;
21613 childregs->fs = __KERNEL_PERCPU;
21614 childregs->bx = sp; /* function */
21615 childregs->bp = arg;
21616 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21617 struct thread_struct *prev = &prev_p->thread,
21618 *next = &next_p->thread;
21619 int cpu = smp_processor_id();
21620 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21621 + struct tss_struct *tss = init_tss + cpu;
21622 fpu_switch_t fpu;
21623
21624 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
21625 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21626 */
21627 lazy_save_gs(prev->gs);
21628
21629 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21630 + __set_fs(task_thread_info(next_p)->addr_limit);
21631 +#endif
21632 +
21633 /*
21634 * Load the per-thread Thread-Local Storage descriptor.
21635 */
21636 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21637 */
21638 arch_end_context_switch(next_p);
21639
21640 + this_cpu_write(current_task, next_p);
21641 + this_cpu_write(current_tinfo, &next_p->tinfo);
21642 +
21643 /*
21644 * Restore %gs if needed (which is common)
21645 */
21646 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21647
21648 switch_fpu_finish(next_p, fpu);
21649
21650 - this_cpu_write(current_task, next_p);
21651 -
21652 return prev_p;
21653 }
21654
21655 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
21656 } while (count++ < 16);
21657 return 0;
21658 }
21659 -
21660 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
21661 index 6e68a61..955a9a5 100644
21662 --- a/arch/x86/kernel/process_64.c
21663 +++ b/arch/x86/kernel/process_64.c
21664 @@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
21665 struct pt_regs *childregs;
21666 struct task_struct *me = current;
21667
21668 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
21669 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
21670 childregs = task_pt_regs(p);
21671 p->thread.sp = (unsigned long) childregs;
21672 p->thread.usersp = me->thread.usersp;
21673 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21674 set_tsk_thread_flag(p, TIF_FORK);
21675 p->fpu_counter = 0;
21676 p->thread.io_bitmap_ptr = NULL;
21677 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21678 struct thread_struct *prev = &prev_p->thread;
21679 struct thread_struct *next = &next_p->thread;
21680 int cpu = smp_processor_id();
21681 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21682 + struct tss_struct *tss = init_tss + cpu;
21683 unsigned fsindex, gsindex;
21684 fpu_switch_t fpu;
21685
21686 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21687 prev->usersp = this_cpu_read(old_rsp);
21688 this_cpu_write(old_rsp, next->usersp);
21689 this_cpu_write(current_task, next_p);
21690 + this_cpu_write(current_tinfo, &next_p->tinfo);
21691
21692 - this_cpu_write(kernel_stack,
21693 - (unsigned long)task_stack_page(next_p) +
21694 - THREAD_SIZE - KERNEL_STACK_OFFSET);
21695 + this_cpu_write(kernel_stack, next->sp0);
21696
21697 /*
21698 * Now maybe reload the debug registers and handle I/O bitmaps
21699 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
21700 if (!p || p == current || p->state == TASK_RUNNING)
21701 return 0;
21702 stack = (unsigned long)task_stack_page(p);
21703 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
21704 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
21705 return 0;
21706 fp = *(u64 *)(p->thread.sp);
21707 do {
21708 - if (fp < (unsigned long)stack ||
21709 - fp >= (unsigned long)stack+THREAD_SIZE)
21710 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
21711 return 0;
21712 ip = *(u64 *)(fp+8);
21713 if (!in_sched_functions(ip))
21714 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
21715 index b629bbe..0fa615a 100644
21716 --- a/arch/x86/kernel/ptrace.c
21717 +++ b/arch/x86/kernel/ptrace.c
21718 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
21719 {
21720 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
21721 unsigned long sp = (unsigned long)&regs->sp;
21722 - struct thread_info *tinfo;
21723
21724 - if (context == (sp & ~(THREAD_SIZE - 1)))
21725 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
21726 return sp;
21727
21728 - tinfo = (struct thread_info *)context;
21729 - if (tinfo->previous_esp)
21730 - return tinfo->previous_esp;
21731 + sp = *(unsigned long *)context;
21732 + if (sp)
21733 + return sp;
21734
21735 return (unsigned long)regs;
21736 }
21737 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
21738 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
21739 {
21740 int i;
21741 - int dr7 = 0;
21742 + unsigned long dr7 = 0;
21743 struct arch_hw_breakpoint *info;
21744
21745 for (i = 0; i < HBP_NUM; i++) {
21746 @@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
21747 unsigned long addr, unsigned long data)
21748 {
21749 int ret;
21750 - unsigned long __user *datap = (unsigned long __user *)data;
21751 + unsigned long __user *datap = (__force unsigned long __user *)data;
21752
21753 switch (request) {
21754 /* read the word at location addr in the USER area. */
21755 @@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
21756 if ((int) addr < 0)
21757 return -EIO;
21758 ret = do_get_thread_area(child, addr,
21759 - (struct user_desc __user *)data);
21760 + (__force struct user_desc __user *) data);
21761 break;
21762
21763 case PTRACE_SET_THREAD_AREA:
21764 if ((int) addr < 0)
21765 return -EIO;
21766 ret = do_set_thread_area(child, addr,
21767 - (struct user_desc __user *)data, 0);
21768 + (__force struct user_desc __user *) data, 0);
21769 break;
21770 #endif
21771
21772 @@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
21773
21774 #ifdef CONFIG_X86_64
21775
21776 -static struct user_regset x86_64_regsets[] __read_mostly = {
21777 +static user_regset_no_const x86_64_regsets[] __read_only = {
21778 [REGSET_GENERAL] = {
21779 .core_note_type = NT_PRSTATUS,
21780 .n = sizeof(struct user_regs_struct) / sizeof(long),
21781 @@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
21782 #endif /* CONFIG_X86_64 */
21783
21784 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
21785 -static struct user_regset x86_32_regsets[] __read_mostly = {
21786 +static user_regset_no_const x86_32_regsets[] __read_only = {
21787 [REGSET_GENERAL] = {
21788 .core_note_type = NT_PRSTATUS,
21789 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
21790 @@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
21791 */
21792 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
21793
21794 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21795 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21796 {
21797 #ifdef CONFIG_X86_64
21798 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
21799 @@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
21800 memset(info, 0, sizeof(*info));
21801 info->si_signo = SIGTRAP;
21802 info->si_code = si_code;
21803 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
21804 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
21805 }
21806
21807 void user_single_step_siginfo(struct task_struct *tsk,
21808 @@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
21809 # define IS_IA32 0
21810 #endif
21811
21812 +#ifdef CONFIG_GRKERNSEC_SETXID
21813 +extern void gr_delayed_cred_worker(void);
21814 +#endif
21815 +
21816 /*
21817 * We must return the syscall number to actually look up in the table.
21818 * This can be -1L to skip running any syscall at all.
21819 @@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
21820
21821 user_exit();
21822
21823 +#ifdef CONFIG_GRKERNSEC_SETXID
21824 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21825 + gr_delayed_cred_worker();
21826 +#endif
21827 +
21828 /*
21829 * If we stepped into a sysenter/syscall insn, it trapped in
21830 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
21831 @@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
21832 */
21833 user_exit();
21834
21835 +#ifdef CONFIG_GRKERNSEC_SETXID
21836 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21837 + gr_delayed_cred_worker();
21838 +#endif
21839 +
21840 audit_syscall_exit(regs);
21841
21842 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
21843 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
21844 index 85c3959..76b89f9 100644
21845 --- a/arch/x86/kernel/pvclock.c
21846 +++ b/arch/x86/kernel/pvclock.c
21847 @@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
21848 return pv_tsc_khz;
21849 }
21850
21851 -static atomic64_t last_value = ATOMIC64_INIT(0);
21852 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
21853
21854 void pvclock_resume(void)
21855 {
21856 - atomic64_set(&last_value, 0);
21857 + atomic64_set_unchecked(&last_value, 0);
21858 }
21859
21860 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
21861 @@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
21862 * updating at the same time, and one of them could be slightly behind,
21863 * making the assumption that last_value always go forward fail to hold.
21864 */
21865 - last = atomic64_read(&last_value);
21866 + last = atomic64_read_unchecked(&last_value);
21867 do {
21868 if (ret < last)
21869 return last;
21870 - last = atomic64_cmpxchg(&last_value, last, ret);
21871 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
21872 } while (unlikely(last != ret));
21873
21874 return ret;
21875 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
21876 index 76fa1e9..abf09ea 100644
21877 --- a/arch/x86/kernel/reboot.c
21878 +++ b/arch/x86/kernel/reboot.c
21879 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
21880 EXPORT_SYMBOL(pm_power_off);
21881
21882 static const struct desc_ptr no_idt = {};
21883 -static int reboot_mode;
21884 +static unsigned short reboot_mode;
21885 enum reboot_type reboot_type = BOOT_ACPI;
21886 int reboot_force;
21887
21888 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
21889
21890 void __noreturn machine_real_restart(unsigned int type)
21891 {
21892 +
21893 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21894 + struct desc_struct *gdt;
21895 +#endif
21896 +
21897 local_irq_disable();
21898
21899 /*
21900 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
21901
21902 /* Jump to the identity-mapped low memory code */
21903 #ifdef CONFIG_X86_32
21904 - asm volatile("jmpl *%0" : :
21905 +
21906 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21907 + gdt = get_cpu_gdt_table(smp_processor_id());
21908 + pax_open_kernel();
21909 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21910 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
21911 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
21912 + loadsegment(ds, __KERNEL_DS);
21913 + loadsegment(es, __KERNEL_DS);
21914 + loadsegment(ss, __KERNEL_DS);
21915 +#endif
21916 +#ifdef CONFIG_PAX_KERNEXEC
21917 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
21918 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
21919 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
21920 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
21921 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
21922 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
21923 +#endif
21924 + pax_close_kernel();
21925 +#endif
21926 +
21927 + asm volatile("ljmpl *%0" : :
21928 "rm" (real_mode_header->machine_real_restart_asm),
21929 "a" (type));
21930 #else
21931 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
21932 * try to force a triple fault and then cycle between hitting the keyboard
21933 * controller and doing that
21934 */
21935 -static void native_machine_emergency_restart(void)
21936 +static void __noreturn native_machine_emergency_restart(void)
21937 {
21938 int i;
21939 int attempt = 0;
21940 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
21941 #endif
21942 }
21943
21944 -static void __machine_emergency_restart(int emergency)
21945 +static void __noreturn __machine_emergency_restart(int emergency)
21946 {
21947 reboot_emergency = emergency;
21948 machine_ops.emergency_restart();
21949 }
21950
21951 -static void native_machine_restart(char *__unused)
21952 +static void __noreturn native_machine_restart(char *__unused)
21953 {
21954 pr_notice("machine restart\n");
21955
21956 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
21957 __machine_emergency_restart(0);
21958 }
21959
21960 -static void native_machine_halt(void)
21961 +static void __noreturn native_machine_halt(void)
21962 {
21963 /* Stop other cpus and apics */
21964 machine_shutdown();
21965 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
21966 stop_this_cpu(NULL);
21967 }
21968
21969 -static void native_machine_power_off(void)
21970 +static void __noreturn native_machine_power_off(void)
21971 {
21972 if (pm_power_off) {
21973 if (!reboot_force)
21974 @@ -688,9 +715,10 @@ static void native_machine_power_off(void)
21975 }
21976 /* A fallback in case there is no PM info available */
21977 tboot_shutdown(TB_SHUTDOWN_HALT);
21978 + unreachable();
21979 }
21980
21981 -struct machine_ops machine_ops = {
21982 +struct machine_ops machine_ops __read_only = {
21983 .power_off = native_machine_power_off,
21984 .shutdown = native_machine_shutdown,
21985 .emergency_restart = native_machine_emergency_restart,
21986 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
21987 index 7a6f3b3..bed145d7 100644
21988 --- a/arch/x86/kernel/relocate_kernel_64.S
21989 +++ b/arch/x86/kernel/relocate_kernel_64.S
21990 @@ -11,6 +11,7 @@
21991 #include <asm/kexec.h>
21992 #include <asm/processor-flags.h>
21993 #include <asm/pgtable_types.h>
21994 +#include <asm/alternative-asm.h>
21995
21996 /*
21997 * Must be relocatable PIC code callable as a C function
21998 @@ -160,13 +161,14 @@ identity_mapped:
21999 xorq %rbp, %rbp
22000 xorq %r8, %r8
22001 xorq %r9, %r9
22002 - xorq %r10, %r9
22003 + xorq %r10, %r10
22004 xorq %r11, %r11
22005 xorq %r12, %r12
22006 xorq %r13, %r13
22007 xorq %r14, %r14
22008 xorq %r15, %r15
22009
22010 + pax_force_retaddr 0, 1
22011 ret
22012
22013 1:
22014 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22015 index 8b24289..d37b58b 100644
22016 --- a/arch/x86/kernel/setup.c
22017 +++ b/arch/x86/kernel/setup.c
22018 @@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
22019
22020 switch (data->type) {
22021 case SETUP_E820_EXT:
22022 - parse_e820_ext(data);
22023 + parse_e820_ext((struct setup_data __force_kernel *)data);
22024 break;
22025 case SETUP_DTB:
22026 add_dtb(pa_data);
22027 @@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
22028 * area (640->1Mb) as ram even though it is not.
22029 * take them out.
22030 */
22031 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22032 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22033
22034 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22035 }
22036 @@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
22037
22038 if (!boot_params.hdr.root_flags)
22039 root_mountflags &= ~MS_RDONLY;
22040 - init_mm.start_code = (unsigned long) _text;
22041 - init_mm.end_code = (unsigned long) _etext;
22042 + init_mm.start_code = ktla_ktva((unsigned long) _text);
22043 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
22044 init_mm.end_data = (unsigned long) _edata;
22045 init_mm.brk = _brk_end;
22046
22047 - code_resource.start = virt_to_phys(_text);
22048 - code_resource.end = virt_to_phys(_etext)-1;
22049 - data_resource.start = virt_to_phys(_etext);
22050 + code_resource.start = virt_to_phys(ktla_ktva(_text));
22051 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
22052 + data_resource.start = virt_to_phys(_sdata);
22053 data_resource.end = virt_to_phys(_edata)-1;
22054 bss_resource.start = virt_to_phys(&__bss_start);
22055 bss_resource.end = virt_to_phys(&__bss_stop)-1;
22056 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22057 index 5cdff03..5810740 100644
22058 --- a/arch/x86/kernel/setup_percpu.c
22059 +++ b/arch/x86/kernel/setup_percpu.c
22060 @@ -21,19 +21,17 @@
22061 #include <asm/cpu.h>
22062 #include <asm/stackprotector.h>
22063
22064 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22065 +#ifdef CONFIG_SMP
22066 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22067 EXPORT_PER_CPU_SYMBOL(cpu_number);
22068 +#endif
22069
22070 -#ifdef CONFIG_X86_64
22071 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22072 -#else
22073 -#define BOOT_PERCPU_OFFSET 0
22074 -#endif
22075
22076 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22077 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22078
22079 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22080 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22081 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22082 };
22083 EXPORT_SYMBOL(__per_cpu_offset);
22084 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22085 {
22086 #ifdef CONFIG_X86_32
22087 struct desc_struct gdt;
22088 + unsigned long base = per_cpu_offset(cpu);
22089
22090 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22091 - 0x2 | DESCTYPE_S, 0x8);
22092 - gdt.s = 1;
22093 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22094 + 0x83 | DESCTYPE_S, 0xC);
22095 write_gdt_entry(get_cpu_gdt_table(cpu),
22096 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22097 #endif
22098 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22099 /* alrighty, percpu areas up and running */
22100 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22101 for_each_possible_cpu(cpu) {
22102 +#ifdef CONFIG_CC_STACKPROTECTOR
22103 +#ifdef CONFIG_X86_32
22104 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
22105 +#endif
22106 +#endif
22107 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22108 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22109 per_cpu(cpu_number, cpu) = cpu;
22110 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22111 */
22112 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22113 #endif
22114 +#ifdef CONFIG_CC_STACKPROTECTOR
22115 +#ifdef CONFIG_X86_32
22116 + if (!cpu)
22117 + per_cpu(stack_canary.canary, cpu) = canary;
22118 +#endif
22119 +#endif
22120 /*
22121 * Up to this point, the boot CPU has been using .init.data
22122 * area. Reload any changed state for the boot CPU.
22123 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22124 index d6bf1f3..3ffce5a 100644
22125 --- a/arch/x86/kernel/signal.c
22126 +++ b/arch/x86/kernel/signal.c
22127 @@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22128 * Align the stack pointer according to the i386 ABI,
22129 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22130 */
22131 - sp = ((sp + 4) & -16ul) - 4;
22132 + sp = ((sp - 12) & -16ul) - 4;
22133 #else /* !CONFIG_X86_32 */
22134 sp = round_down(sp, 16) - 8;
22135 #endif
22136 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22137 }
22138
22139 if (current->mm->context.vdso)
22140 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22141 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22142 else
22143 - restorer = &frame->retcode;
22144 + restorer = (void __user *)&frame->retcode;
22145 if (ka->sa.sa_flags & SA_RESTORER)
22146 restorer = ka->sa.sa_restorer;
22147
22148 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22149 * reasons and because gdb uses it as a signature to notice
22150 * signal handler stack frames.
22151 */
22152 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22153 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22154
22155 if (err)
22156 return -EFAULT;
22157 @@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22158 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22159
22160 /* Set up to return from userspace. */
22161 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22162 + if (current->mm->context.vdso)
22163 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22164 + else
22165 + restorer = (void __user *)&frame->retcode;
22166 if (ka->sa.sa_flags & SA_RESTORER)
22167 restorer = ka->sa.sa_restorer;
22168 put_user_ex(restorer, &frame->pretcode);
22169 @@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22170 * reasons and because gdb uses it as a signature to notice
22171 * signal handler stack frames.
22172 */
22173 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22174 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22175 } put_user_catch(err);
22176
22177 err |= copy_siginfo_to_user(&frame->info, info);
22178 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22179 index 48d2b7d..90d328a 100644
22180 --- a/arch/x86/kernel/smp.c
22181 +++ b/arch/x86/kernel/smp.c
22182 @@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22183
22184 __setup("nonmi_ipi", nonmi_ipi_setup);
22185
22186 -struct smp_ops smp_ops = {
22187 +struct smp_ops smp_ops __read_only = {
22188 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22189 .smp_prepare_cpus = native_smp_prepare_cpus,
22190 .smp_cpus_done = native_smp_cpus_done,
22191 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22192 index ed0fe38..87fc692 100644
22193 --- a/arch/x86/kernel/smpboot.c
22194 +++ b/arch/x86/kernel/smpboot.c
22195 @@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22196 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22197 (THREAD_SIZE + task_stack_page(idle))) - 1);
22198 per_cpu(current_task, cpu) = idle;
22199 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
22200
22201 #ifdef CONFIG_X86_32
22202 /* Stack for startup_32 can be just as for start_secondary onwards */
22203 @@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22204 #else
22205 clear_tsk_thread_flag(idle, TIF_FORK);
22206 initial_gs = per_cpu_offset(cpu);
22207 - per_cpu(kernel_stack, cpu) =
22208 - (unsigned long)task_stack_page(idle) -
22209 - KERNEL_STACK_OFFSET + THREAD_SIZE;
22210 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22211 #endif
22212 +
22213 + pax_open_kernel();
22214 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22215 + pax_close_kernel();
22216 +
22217 initial_code = (unsigned long)start_secondary;
22218 stack_start = idle->thread.sp;
22219
22220 @@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22221 /* the FPU context is blank, nobody can own it */
22222 __cpu_disable_lazy_restore(cpu);
22223
22224 +#ifdef CONFIG_PAX_PER_CPU_PGD
22225 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22226 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22227 + KERNEL_PGD_PTRS);
22228 +#endif
22229 +
22230 + /* the FPU context is blank, nobody can own it */
22231 + __cpu_disable_lazy_restore(cpu);
22232 +
22233 err = do_boot_cpu(apicid, cpu, tidle);
22234 if (err) {
22235 pr_debug("do_boot_cpu failed %d\n", err);
22236 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22237 index 9b4d51d..5d28b58 100644
22238 --- a/arch/x86/kernel/step.c
22239 +++ b/arch/x86/kernel/step.c
22240 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22241 struct desc_struct *desc;
22242 unsigned long base;
22243
22244 - seg &= ~7UL;
22245 + seg >>= 3;
22246
22247 mutex_lock(&child->mm->context.lock);
22248 - if (unlikely((seg >> 3) >= child->mm->context.size))
22249 + if (unlikely(seg >= child->mm->context.size))
22250 addr = -1L; /* bogus selector, access would fault */
22251 else {
22252 desc = child->mm->context.ldt + seg;
22253 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22254 addr += base;
22255 }
22256 mutex_unlock(&child->mm->context.lock);
22257 - }
22258 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22259 + addr = ktla_ktva(addr);
22260
22261 return addr;
22262 }
22263 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22264 unsigned char opcode[15];
22265 unsigned long addr = convert_ip_to_linear(child, regs);
22266
22267 + if (addr == -EINVAL)
22268 + return 0;
22269 +
22270 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22271 for (i = 0; i < copied; i++) {
22272 switch (opcode[i]) {
22273 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22274 new file mode 100644
22275 index 0000000..26bb1af
22276 --- /dev/null
22277 +++ b/arch/x86/kernel/sys_i386_32.c
22278 @@ -0,0 +1,249 @@
22279 +/*
22280 + * This file contains various random system calls that
22281 + * have a non-standard calling sequence on the Linux/i386
22282 + * platform.
22283 + */
22284 +
22285 +#include <linux/errno.h>
22286 +#include <linux/sched.h>
22287 +#include <linux/mm.h>
22288 +#include <linux/fs.h>
22289 +#include <linux/smp.h>
22290 +#include <linux/sem.h>
22291 +#include <linux/msg.h>
22292 +#include <linux/shm.h>
22293 +#include <linux/stat.h>
22294 +#include <linux/syscalls.h>
22295 +#include <linux/mman.h>
22296 +#include <linux/file.h>
22297 +#include <linux/utsname.h>
22298 +#include <linux/ipc.h>
22299 +
22300 +#include <linux/uaccess.h>
22301 +#include <linux/unistd.h>
22302 +
22303 +#include <asm/syscalls.h>
22304 +
22305 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22306 +{
22307 + unsigned long pax_task_size = TASK_SIZE;
22308 +
22309 +#ifdef CONFIG_PAX_SEGMEXEC
22310 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22311 + pax_task_size = SEGMEXEC_TASK_SIZE;
22312 +#endif
22313 +
22314 + if (len > pax_task_size || addr > pax_task_size - len)
22315 + return -EINVAL;
22316 +
22317 + return 0;
22318 +}
22319 +
22320 +unsigned long
22321 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
22322 + unsigned long len, unsigned long pgoff, unsigned long flags)
22323 +{
22324 + struct mm_struct *mm = current->mm;
22325 + struct vm_area_struct *vma;
22326 + unsigned long start_addr, pax_task_size = TASK_SIZE;
22327 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22328 +
22329 +#ifdef CONFIG_PAX_SEGMEXEC
22330 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22331 + pax_task_size = SEGMEXEC_TASK_SIZE;
22332 +#endif
22333 +
22334 + pax_task_size -= PAGE_SIZE;
22335 +
22336 + if (len > pax_task_size)
22337 + return -ENOMEM;
22338 +
22339 + if (flags & MAP_FIXED)
22340 + return addr;
22341 +
22342 +#ifdef CONFIG_PAX_RANDMMAP
22343 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22344 +#endif
22345 +
22346 + if (addr) {
22347 + addr = PAGE_ALIGN(addr);
22348 + if (pax_task_size - len >= addr) {
22349 + vma = find_vma(mm, addr);
22350 + if (check_heap_stack_gap(vma, addr, len, offset))
22351 + return addr;
22352 + }
22353 + }
22354 + if (len > mm->cached_hole_size) {
22355 + start_addr = addr = mm->free_area_cache;
22356 + } else {
22357 + start_addr = addr = mm->mmap_base;
22358 + mm->cached_hole_size = 0;
22359 + }
22360 +
22361 +#ifdef CONFIG_PAX_PAGEEXEC
22362 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22363 + start_addr = 0x00110000UL;
22364 +
22365 +#ifdef CONFIG_PAX_RANDMMAP
22366 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22367 + start_addr += mm->delta_mmap & 0x03FFF000UL;
22368 +#endif
22369 +
22370 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22371 + start_addr = addr = mm->mmap_base;
22372 + else
22373 + addr = start_addr;
22374 + }
22375 +#endif
22376 +
22377 +full_search:
22378 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22379 + /* At this point: (!vma || addr < vma->vm_end). */
22380 + if (pax_task_size - len < addr) {
22381 + /*
22382 + * Start a new search - just in case we missed
22383 + * some holes.
22384 + */
22385 + if (start_addr != mm->mmap_base) {
22386 + start_addr = addr = mm->mmap_base;
22387 + mm->cached_hole_size = 0;
22388 + goto full_search;
22389 + }
22390 + return -ENOMEM;
22391 + }
22392 + if (check_heap_stack_gap(vma, addr, len, offset))
22393 + break;
22394 + if (addr + mm->cached_hole_size < vma->vm_start)
22395 + mm->cached_hole_size = vma->vm_start - addr;
22396 + addr = vma->vm_end;
22397 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
22398 + start_addr = addr = mm->mmap_base;
22399 + mm->cached_hole_size = 0;
22400 + goto full_search;
22401 + }
22402 + }
22403 +
22404 + /*
22405 + * Remember the place where we stopped the search:
22406 + */
22407 + mm->free_area_cache = addr + len;
22408 + return addr;
22409 +}
22410 +
22411 +unsigned long
22412 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22413 + const unsigned long len, const unsigned long pgoff,
22414 + const unsigned long flags)
22415 +{
22416 + struct vm_area_struct *vma;
22417 + struct mm_struct *mm = current->mm;
22418 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22419 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22420 +
22421 +#ifdef CONFIG_PAX_SEGMEXEC
22422 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22423 + pax_task_size = SEGMEXEC_TASK_SIZE;
22424 +#endif
22425 +
22426 + pax_task_size -= PAGE_SIZE;
22427 +
22428 + /* requested length too big for entire address space */
22429 + if (len > pax_task_size)
22430 + return -ENOMEM;
22431 +
22432 + if (flags & MAP_FIXED)
22433 + return addr;
22434 +
22435 +#ifdef CONFIG_PAX_PAGEEXEC
22436 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22437 + goto bottomup;
22438 +#endif
22439 +
22440 +#ifdef CONFIG_PAX_RANDMMAP
22441 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22442 +#endif
22443 +
22444 + /* requesting a specific address */
22445 + if (addr) {
22446 + addr = PAGE_ALIGN(addr);
22447 + if (pax_task_size - len >= addr) {
22448 + vma = find_vma(mm, addr);
22449 + if (check_heap_stack_gap(vma, addr, len, offset))
22450 + return addr;
22451 + }
22452 + }
22453 +
22454 + /* check if free_area_cache is useful for us */
22455 + if (len <= mm->cached_hole_size) {
22456 + mm->cached_hole_size = 0;
22457 + mm->free_area_cache = mm->mmap_base;
22458 + }
22459 +
22460 + /* either no address requested or can't fit in requested address hole */
22461 + addr = mm->free_area_cache;
22462 +
22463 + /* make sure it can fit in the remaining address space */
22464 + if (addr > len) {
22465 + vma = find_vma(mm, addr-len);
22466 + if (check_heap_stack_gap(vma, addr - len, len, offset))
22467 + /* remember the address as a hint for next time */
22468 + return (mm->free_area_cache = addr-len);
22469 + }
22470 +
22471 + if (mm->mmap_base < len)
22472 + goto bottomup;
22473 +
22474 + addr = mm->mmap_base-len;
22475 +
22476 + do {
22477 + /*
22478 + * Lookup failure means no vma is above this address,
22479 + * else if new region fits below vma->vm_start,
22480 + * return with success:
22481 + */
22482 + vma = find_vma(mm, addr);
22483 + if (check_heap_stack_gap(vma, addr, len, offset))
22484 + /* remember the address as a hint for next time */
22485 + return (mm->free_area_cache = addr);
22486 +
22487 + /* remember the largest hole we saw so far */
22488 + if (addr + mm->cached_hole_size < vma->vm_start)
22489 + mm->cached_hole_size = vma->vm_start - addr;
22490 +
22491 + /* try just below the current vma->vm_start */
22492 + addr = skip_heap_stack_gap(vma, len, offset);
22493 + } while (!IS_ERR_VALUE(addr));
22494 +
22495 +bottomup:
22496 + /*
22497 + * A failed mmap() very likely causes application failure,
22498 + * so fall back to the bottom-up function here. This scenario
22499 + * can happen with large stack limits and large mmap()
22500 + * allocations.
22501 + */
22502 +
22503 +#ifdef CONFIG_PAX_SEGMEXEC
22504 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22505 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22506 + else
22507 +#endif
22508 +
22509 + mm->mmap_base = TASK_UNMAPPED_BASE;
22510 +
22511 +#ifdef CONFIG_PAX_RANDMMAP
22512 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22513 + mm->mmap_base += mm->delta_mmap;
22514 +#endif
22515 +
22516 + mm->free_area_cache = mm->mmap_base;
22517 + mm->cached_hole_size = ~0UL;
22518 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
22519 + /*
22520 + * Restore the topdown base:
22521 + */
22522 + mm->mmap_base = base;
22523 + mm->free_area_cache = base;
22524 + mm->cached_hole_size = ~0UL;
22525 +
22526 + return addr;
22527 +}
22528 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
22529 index 97ef74b..57a1882 100644
22530 --- a/arch/x86/kernel/sys_x86_64.c
22531 +++ b/arch/x86/kernel/sys_x86_64.c
22532 @@ -81,8 +81,8 @@ out:
22533 return error;
22534 }
22535
22536 -static void find_start_end(unsigned long flags, unsigned long *begin,
22537 - unsigned long *end)
22538 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
22539 + unsigned long *begin, unsigned long *end)
22540 {
22541 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
22542 unsigned long new_begin;
22543 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
22544 *begin = new_begin;
22545 }
22546 } else {
22547 - *begin = TASK_UNMAPPED_BASE;
22548 + *begin = mm->mmap_base;
22549 *end = TASK_SIZE;
22550 }
22551 }
22552 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
22553 struct vm_area_struct *vma;
22554 struct vm_unmapped_area_info info;
22555 unsigned long begin, end;
22556 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22557
22558 if (flags & MAP_FIXED)
22559 return addr;
22560
22561 - find_start_end(flags, &begin, &end);
22562 + find_start_end(mm, flags, &begin, &end);
22563
22564 if (len > end)
22565 return -ENOMEM;
22566
22567 +#ifdef CONFIG_PAX_RANDMMAP
22568 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22569 +#endif
22570 +
22571 if (addr) {
22572 addr = PAGE_ALIGN(addr);
22573 vma = find_vma(mm, addr);
22574 - if (end - len >= addr &&
22575 - (!vma || addr + len <= vma->vm_start))
22576 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
22577 return addr;
22578 }
22579
22580 @@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22581 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
22582 goto bottomup;
22583
22584 +#ifdef CONFIG_PAX_RANDMMAP
22585 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22586 +#endif
22587 +
22588 /* requesting a specific address */
22589 if (addr) {
22590 addr = PAGE_ALIGN(addr);
22591 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
22592 index f84fe00..f41d9f1 100644
22593 --- a/arch/x86/kernel/tboot.c
22594 +++ b/arch/x86/kernel/tboot.c
22595 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
22596
22597 void tboot_shutdown(u32 shutdown_type)
22598 {
22599 - void (*shutdown)(void);
22600 + void (* __noreturn shutdown)(void);
22601
22602 if (!tboot_enabled())
22603 return;
22604 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
22605
22606 switch_to_tboot_pt();
22607
22608 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
22609 + shutdown = (void *)tboot->shutdown_entry;
22610 shutdown();
22611
22612 /* should not reach here */
22613 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
22614 return 0;
22615 }
22616
22617 -static atomic_t ap_wfs_count;
22618 +static atomic_unchecked_t ap_wfs_count;
22619
22620 static int tboot_wait_for_aps(int num_aps)
22621 {
22622 @@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
22623 {
22624 switch (action) {
22625 case CPU_DYING:
22626 - atomic_inc(&ap_wfs_count);
22627 + atomic_inc_unchecked(&ap_wfs_count);
22628 if (num_online_cpus() == 1)
22629 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
22630 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
22631 return NOTIFY_BAD;
22632 break;
22633 }
22634 return NOTIFY_OK;
22635 }
22636
22637 -static struct notifier_block tboot_cpu_notifier __cpuinitdata =
22638 +static struct notifier_block tboot_cpu_notifier =
22639 {
22640 .notifier_call = tboot_cpu_callback,
22641 };
22642 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
22643
22644 tboot_create_trampoline();
22645
22646 - atomic_set(&ap_wfs_count, 0);
22647 + atomic_set_unchecked(&ap_wfs_count, 0);
22648 register_hotcpu_notifier(&tboot_cpu_notifier);
22649
22650 acpi_os_set_prepare_sleep(&tboot_sleep);
22651 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
22652 index 24d3c91..d06b473 100644
22653 --- a/arch/x86/kernel/time.c
22654 +++ b/arch/x86/kernel/time.c
22655 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
22656 {
22657 unsigned long pc = instruction_pointer(regs);
22658
22659 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
22660 + if (!user_mode(regs) && in_lock_functions(pc)) {
22661 #ifdef CONFIG_FRAME_POINTER
22662 - return *(unsigned long *)(regs->bp + sizeof(long));
22663 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
22664 #else
22665 unsigned long *sp =
22666 (unsigned long *)kernel_stack_pointer(regs);
22667 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
22668 * or above a saved flags. Eflags has bits 22-31 zero,
22669 * kernel addresses don't.
22670 */
22671 +
22672 +#ifdef CONFIG_PAX_KERNEXEC
22673 + return ktla_ktva(sp[0]);
22674 +#else
22675 if (sp[0] >> 22)
22676 return sp[0];
22677 if (sp[1] >> 22)
22678 return sp[1];
22679 #endif
22680 +
22681 +#endif
22682 }
22683 return pc;
22684 }
22685 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
22686 index 9d9d2f9..cad418a 100644
22687 --- a/arch/x86/kernel/tls.c
22688 +++ b/arch/x86/kernel/tls.c
22689 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
22690 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
22691 return -EINVAL;
22692
22693 +#ifdef CONFIG_PAX_SEGMEXEC
22694 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
22695 + return -EINVAL;
22696 +#endif
22697 +
22698 set_tls_desc(p, idx, &info, 1);
22699
22700 return 0;
22701 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
22702
22703 if (kbuf)
22704 info = kbuf;
22705 - else if (__copy_from_user(infobuf, ubuf, count))
22706 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
22707 return -EFAULT;
22708 else
22709 info = infobuf;
22710 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
22711 index ecffca1..95c4d13 100644
22712 --- a/arch/x86/kernel/traps.c
22713 +++ b/arch/x86/kernel/traps.c
22714 @@ -68,12 +68,6 @@
22715 #include <asm/setup.h>
22716
22717 asmlinkage int system_call(void);
22718 -
22719 -/*
22720 - * The IDT has to be page-aligned to simplify the Pentium
22721 - * F0 0F bug workaround.
22722 - */
22723 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
22724 #endif
22725
22726 DECLARE_BITMAP(used_vectors, NR_VECTORS);
22727 @@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
22728 }
22729
22730 static int __kprobes
22731 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22732 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
22733 struct pt_regs *regs, long error_code)
22734 {
22735 #ifdef CONFIG_X86_32
22736 - if (regs->flags & X86_VM_MASK) {
22737 + if (v8086_mode(regs)) {
22738 /*
22739 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
22740 * On nmi (interrupt 2), do_trap should not be called.
22741 @@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22742 return -1;
22743 }
22744 #endif
22745 - if (!user_mode(regs)) {
22746 + if (!user_mode_novm(regs)) {
22747 if (!fixup_exception(regs)) {
22748 tsk->thread.error_code = error_code;
22749 tsk->thread.trap_nr = trapnr;
22750 +
22751 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22752 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
22753 + str = "PAX: suspicious stack segment fault";
22754 +#endif
22755 +
22756 die(str, regs, error_code);
22757 }
22758 +
22759 +#ifdef CONFIG_PAX_REFCOUNT
22760 + if (trapnr == 4)
22761 + pax_report_refcount_overflow(regs);
22762 +#endif
22763 +
22764 return 0;
22765 }
22766
22767 @@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22768 }
22769
22770 static void __kprobes
22771 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22772 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
22773 long error_code, siginfo_t *info)
22774 {
22775 struct task_struct *tsk = current;
22776 @@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22777 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
22778 printk_ratelimit()) {
22779 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
22780 - tsk->comm, tsk->pid, str,
22781 + tsk->comm, task_pid_nr(tsk), str,
22782 regs->ip, regs->sp, error_code);
22783 print_vma_addr(" in ", regs->ip);
22784 pr_cont("\n");
22785 @@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
22786 conditional_sti(regs);
22787
22788 #ifdef CONFIG_X86_32
22789 - if (regs->flags & X86_VM_MASK) {
22790 + if (v8086_mode(regs)) {
22791 local_irq_enable();
22792 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
22793 goto exit;
22794 @@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
22795 #endif
22796
22797 tsk = current;
22798 - if (!user_mode(regs)) {
22799 + if (!user_mode_novm(regs)) {
22800 if (fixup_exception(regs))
22801 goto exit;
22802
22803 tsk->thread.error_code = error_code;
22804 tsk->thread.trap_nr = X86_TRAP_GP;
22805 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
22806 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
22807 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
22808 +
22809 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22810 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
22811 + die("PAX: suspicious general protection fault", regs, error_code);
22812 + else
22813 +#endif
22814 +
22815 die("general protection fault", regs, error_code);
22816 + }
22817 goto exit;
22818 }
22819
22820 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22821 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
22822 + struct mm_struct *mm = tsk->mm;
22823 + unsigned long limit;
22824 +
22825 + down_write(&mm->mmap_sem);
22826 + limit = mm->context.user_cs_limit;
22827 + if (limit < TASK_SIZE) {
22828 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
22829 + up_write(&mm->mmap_sem);
22830 + return;
22831 + }
22832 + up_write(&mm->mmap_sem);
22833 + }
22834 +#endif
22835 +
22836 tsk->thread.error_code = error_code;
22837 tsk->thread.trap_nr = X86_TRAP_GP;
22838
22839 @@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22840 /* It's safe to allow irq's after DR6 has been saved */
22841 preempt_conditional_sti(regs);
22842
22843 - if (regs->flags & X86_VM_MASK) {
22844 + if (v8086_mode(regs)) {
22845 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
22846 X86_TRAP_DB);
22847 preempt_conditional_cli(regs);
22848 @@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22849 * We already checked v86 mode above, so we can check for kernel mode
22850 * by just checking the CPL of CS.
22851 */
22852 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
22853 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
22854 tsk->thread.debugreg6 &= ~DR_STEP;
22855 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
22856 regs->flags &= ~X86_EFLAGS_TF;
22857 @@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
22858 return;
22859 conditional_sti(regs);
22860
22861 - if (!user_mode_vm(regs))
22862 + if (!user_mode(regs))
22863 {
22864 if (!fixup_exception(regs)) {
22865 task->thread.error_code = error_code;
22866 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
22867 index c71025b..b117501 100644
22868 --- a/arch/x86/kernel/uprobes.c
22869 +++ b/arch/x86/kernel/uprobes.c
22870 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
22871 int ret = NOTIFY_DONE;
22872
22873 /* We are only interested in userspace traps */
22874 - if (regs && !user_mode_vm(regs))
22875 + if (regs && !user_mode(regs))
22876 return NOTIFY_DONE;
22877
22878 switch (val) {
22879 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
22880 index b9242ba..50c5edd 100644
22881 --- a/arch/x86/kernel/verify_cpu.S
22882 +++ b/arch/x86/kernel/verify_cpu.S
22883 @@ -20,6 +20,7 @@
22884 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
22885 * arch/x86/kernel/trampoline_64.S: secondary processor verification
22886 * arch/x86/kernel/head_32.S: processor startup
22887 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
22888 *
22889 * verify_cpu, returns the status of longmode and SSE in register %eax.
22890 * 0: Success 1: Failure
22891 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
22892 index 1dfe69c..a3df6f6 100644
22893 --- a/arch/x86/kernel/vm86_32.c
22894 +++ b/arch/x86/kernel/vm86_32.c
22895 @@ -43,6 +43,7 @@
22896 #include <linux/ptrace.h>
22897 #include <linux/audit.h>
22898 #include <linux/stddef.h>
22899 +#include <linux/grsecurity.h>
22900
22901 #include <asm/uaccess.h>
22902 #include <asm/io.h>
22903 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
22904 do_exit(SIGSEGV);
22905 }
22906
22907 - tss = &per_cpu(init_tss, get_cpu());
22908 + tss = init_tss + get_cpu();
22909 current->thread.sp0 = current->thread.saved_sp0;
22910 current->thread.sysenter_cs = __KERNEL_CS;
22911 load_sp0(tss, &current->thread);
22912 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
22913 struct task_struct *tsk;
22914 int tmp, ret = -EPERM;
22915
22916 +#ifdef CONFIG_GRKERNSEC_VM86
22917 + if (!capable(CAP_SYS_RAWIO)) {
22918 + gr_handle_vm86();
22919 + goto out;
22920 + }
22921 +#endif
22922 +
22923 tsk = current;
22924 if (tsk->thread.saved_sp0)
22925 goto out;
22926 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
22927 int tmp, ret;
22928 struct vm86plus_struct __user *v86;
22929
22930 +#ifdef CONFIG_GRKERNSEC_VM86
22931 + if (!capable(CAP_SYS_RAWIO)) {
22932 + gr_handle_vm86();
22933 + ret = -EPERM;
22934 + goto out;
22935 + }
22936 +#endif
22937 +
22938 tsk = current;
22939 switch (cmd) {
22940 case VM86_REQUEST_IRQ:
22941 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
22942 tsk->thread.saved_fs = info->regs32->fs;
22943 tsk->thread.saved_gs = get_user_gs(info->regs32);
22944
22945 - tss = &per_cpu(init_tss, get_cpu());
22946 + tss = init_tss + get_cpu();
22947 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
22948 if (cpu_has_sep)
22949 tsk->thread.sysenter_cs = 0;
22950 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
22951 goto cannot_handle;
22952 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
22953 goto cannot_handle;
22954 - intr_ptr = (unsigned long __user *) (i << 2);
22955 + intr_ptr = (__force unsigned long __user *) (i << 2);
22956 if (get_user(segoffs, intr_ptr))
22957 goto cannot_handle;
22958 if ((segoffs >> 16) == BIOSSEG)
22959 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
22960 index 22a1530..8fbaaad 100644
22961 --- a/arch/x86/kernel/vmlinux.lds.S
22962 +++ b/arch/x86/kernel/vmlinux.lds.S
22963 @@ -26,6 +26,13 @@
22964 #include <asm/page_types.h>
22965 #include <asm/cache.h>
22966 #include <asm/boot.h>
22967 +#include <asm/segment.h>
22968 +
22969 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22970 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
22971 +#else
22972 +#define __KERNEL_TEXT_OFFSET 0
22973 +#endif
22974
22975 #undef i386 /* in case the preprocessor is a 32bit one */
22976
22977 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
22978
22979 PHDRS {
22980 text PT_LOAD FLAGS(5); /* R_E */
22981 +#ifdef CONFIG_X86_32
22982 + module PT_LOAD FLAGS(5); /* R_E */
22983 +#endif
22984 +#ifdef CONFIG_XEN
22985 + rodata PT_LOAD FLAGS(5); /* R_E */
22986 +#else
22987 + rodata PT_LOAD FLAGS(4); /* R__ */
22988 +#endif
22989 data PT_LOAD FLAGS(6); /* RW_ */
22990 -#ifdef CONFIG_X86_64
22991 + init.begin PT_LOAD FLAGS(6); /* RW_ */
22992 #ifdef CONFIG_SMP
22993 percpu PT_LOAD FLAGS(6); /* RW_ */
22994 #endif
22995 + text.init PT_LOAD FLAGS(5); /* R_E */
22996 + text.exit PT_LOAD FLAGS(5); /* R_E */
22997 init PT_LOAD FLAGS(7); /* RWE */
22998 -#endif
22999 note PT_NOTE FLAGS(0); /* ___ */
23000 }
23001
23002 SECTIONS
23003 {
23004 #ifdef CONFIG_X86_32
23005 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23006 - phys_startup_32 = startup_32 - LOAD_OFFSET;
23007 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23008 #else
23009 - . = __START_KERNEL;
23010 - phys_startup_64 = startup_64 - LOAD_OFFSET;
23011 + . = __START_KERNEL;
23012 #endif
23013
23014 /* Text and read-only data */
23015 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
23016 - _text = .;
23017 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23018 /* bootstrapping code */
23019 +#ifdef CONFIG_X86_32
23020 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23021 +#else
23022 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23023 +#endif
23024 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23025 + _text = .;
23026 HEAD_TEXT
23027 #ifdef CONFIG_X86_32
23028 . = ALIGN(PAGE_SIZE);
23029 @@ -108,13 +128,48 @@ SECTIONS
23030 IRQENTRY_TEXT
23031 *(.fixup)
23032 *(.gnu.warning)
23033 - /* End of text section */
23034 - _etext = .;
23035 } :text = 0x9090
23036
23037 - NOTES :text :note
23038 + . += __KERNEL_TEXT_OFFSET;
23039
23040 - EXCEPTION_TABLE(16) :text = 0x9090
23041 +#ifdef CONFIG_X86_32
23042 + . = ALIGN(PAGE_SIZE);
23043 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23044 +
23045 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
23046 + MODULES_EXEC_VADDR = .;
23047 + BYTE(0)
23048 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23049 + . = ALIGN(HPAGE_SIZE) - 1;
23050 + MODULES_EXEC_END = .;
23051 +#endif
23052 +
23053 + } :module
23054 +#endif
23055 +
23056 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23057 + /* End of text section */
23058 + BYTE(0)
23059 + _etext = . - __KERNEL_TEXT_OFFSET;
23060 + }
23061 +
23062 +#ifdef CONFIG_X86_32
23063 + . = ALIGN(PAGE_SIZE);
23064 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23065 + *(.idt)
23066 + . = ALIGN(PAGE_SIZE);
23067 + *(.empty_zero_page)
23068 + *(.initial_pg_fixmap)
23069 + *(.initial_pg_pmd)
23070 + *(.initial_page_table)
23071 + *(.swapper_pg_dir)
23072 + } :rodata
23073 +#endif
23074 +
23075 + . = ALIGN(PAGE_SIZE);
23076 + NOTES :rodata :note
23077 +
23078 + EXCEPTION_TABLE(16) :rodata
23079
23080 #if defined(CONFIG_DEBUG_RODATA)
23081 /* .text should occupy whole number of pages */
23082 @@ -126,16 +181,20 @@ SECTIONS
23083
23084 /* Data */
23085 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23086 +
23087 +#ifdef CONFIG_PAX_KERNEXEC
23088 + . = ALIGN(HPAGE_SIZE);
23089 +#else
23090 + . = ALIGN(PAGE_SIZE);
23091 +#endif
23092 +
23093 /* Start of data section */
23094 _sdata = .;
23095
23096 /* init_task */
23097 INIT_TASK_DATA(THREAD_SIZE)
23098
23099 -#ifdef CONFIG_X86_32
23100 - /* 32 bit has nosave before _edata */
23101 NOSAVE_DATA
23102 -#endif
23103
23104 PAGE_ALIGNED_DATA(PAGE_SIZE)
23105
23106 @@ -176,12 +235,19 @@ SECTIONS
23107 #endif /* CONFIG_X86_64 */
23108
23109 /* Init code and data - will be freed after init */
23110 - . = ALIGN(PAGE_SIZE);
23111 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23112 + BYTE(0)
23113 +
23114 +#ifdef CONFIG_PAX_KERNEXEC
23115 + . = ALIGN(HPAGE_SIZE);
23116 +#else
23117 + . = ALIGN(PAGE_SIZE);
23118 +#endif
23119 +
23120 __init_begin = .; /* paired with __init_end */
23121 - }
23122 + } :init.begin
23123
23124 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23125 +#ifdef CONFIG_SMP
23126 /*
23127 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23128 * output PHDR, so the next output section - .init.text - should
23129 @@ -190,12 +256,27 @@ SECTIONS
23130 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23131 #endif
23132
23133 - INIT_TEXT_SECTION(PAGE_SIZE)
23134 -#ifdef CONFIG_X86_64
23135 - :init
23136 -#endif
23137 + . = ALIGN(PAGE_SIZE);
23138 + init_begin = .;
23139 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23140 + VMLINUX_SYMBOL(_sinittext) = .;
23141 + INIT_TEXT
23142 + VMLINUX_SYMBOL(_einittext) = .;
23143 + . = ALIGN(PAGE_SIZE);
23144 + } :text.init
23145
23146 - INIT_DATA_SECTION(16)
23147 + /*
23148 + * .exit.text is discard at runtime, not link time, to deal with
23149 + * references from .altinstructions and .eh_frame
23150 + */
23151 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23152 + EXIT_TEXT
23153 + . = ALIGN(16);
23154 + } :text.exit
23155 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23156 +
23157 + . = ALIGN(PAGE_SIZE);
23158 + INIT_DATA_SECTION(16) :init
23159
23160 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23161 __x86_cpu_dev_start = .;
23162 @@ -257,19 +338,12 @@ SECTIONS
23163 }
23164
23165 . = ALIGN(8);
23166 - /*
23167 - * .exit.text is discard at runtime, not link time, to deal with
23168 - * references from .altinstructions and .eh_frame
23169 - */
23170 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23171 - EXIT_TEXT
23172 - }
23173
23174 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23175 EXIT_DATA
23176 }
23177
23178 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23179 +#ifndef CONFIG_SMP
23180 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23181 #endif
23182
23183 @@ -288,16 +362,10 @@ SECTIONS
23184 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23185 __smp_locks = .;
23186 *(.smp_locks)
23187 - . = ALIGN(PAGE_SIZE);
23188 __smp_locks_end = .;
23189 + . = ALIGN(PAGE_SIZE);
23190 }
23191
23192 -#ifdef CONFIG_X86_64
23193 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23194 - NOSAVE_DATA
23195 - }
23196 -#endif
23197 -
23198 /* BSS */
23199 . = ALIGN(PAGE_SIZE);
23200 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23201 @@ -313,6 +381,7 @@ SECTIONS
23202 __brk_base = .;
23203 . += 64 * 1024; /* 64k alignment slop space */
23204 *(.brk_reservation) /* areas brk users have reserved */
23205 + . = ALIGN(HPAGE_SIZE);
23206 __brk_limit = .;
23207 }
23208
23209 @@ -339,13 +408,12 @@ SECTIONS
23210 * for the boot processor.
23211 */
23212 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23213 -INIT_PER_CPU(gdt_page);
23214 INIT_PER_CPU(irq_stack_union);
23215
23216 /*
23217 * Build-time check on the image size:
23218 */
23219 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23220 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23221 "kernel image bigger than KERNEL_IMAGE_SIZE");
23222
23223 #ifdef CONFIG_SMP
23224 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23225 index 9a907a6..f83f921 100644
23226 --- a/arch/x86/kernel/vsyscall_64.c
23227 +++ b/arch/x86/kernel/vsyscall_64.c
23228 @@ -56,15 +56,13 @@
23229 DEFINE_VVAR(int, vgetcpu_mode);
23230 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23231
23232 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23233 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23234
23235 static int __init vsyscall_setup(char *str)
23236 {
23237 if (str) {
23238 if (!strcmp("emulate", str))
23239 vsyscall_mode = EMULATE;
23240 - else if (!strcmp("native", str))
23241 - vsyscall_mode = NATIVE;
23242 else if (!strcmp("none", str))
23243 vsyscall_mode = NONE;
23244 else
23245 @@ -323,8 +321,7 @@ do_ret:
23246 return true;
23247
23248 sigsegv:
23249 - force_sig(SIGSEGV, current);
23250 - return true;
23251 + do_group_exit(SIGKILL);
23252 }
23253
23254 /*
23255 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23256 extern char __vvar_page;
23257 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23258
23259 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23260 - vsyscall_mode == NATIVE
23261 - ? PAGE_KERNEL_VSYSCALL
23262 - : PAGE_KERNEL_VVAR);
23263 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23264 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23265 (unsigned long)VSYSCALL_START);
23266
23267 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23268 index 1330dd1..d220b99 100644
23269 --- a/arch/x86/kernel/x8664_ksyms_64.c
23270 +++ b/arch/x86/kernel/x8664_ksyms_64.c
23271 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23272 EXPORT_SYMBOL(copy_user_generic_unrolled);
23273 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23274 EXPORT_SYMBOL(__copy_user_nocache);
23275 -EXPORT_SYMBOL(_copy_from_user);
23276 -EXPORT_SYMBOL(_copy_to_user);
23277
23278 EXPORT_SYMBOL(copy_page);
23279 EXPORT_SYMBOL(clear_page);
23280 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23281 index 7a3d075..6cb373d 100644
23282 --- a/arch/x86/kernel/x86_init.c
23283 +++ b/arch/x86/kernel/x86_init.c
23284 @@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
23285 },
23286 };
23287
23288 -struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23289 +struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23290 .early_percpu_clock_init = x86_init_noop,
23291 .setup_percpu_clockev = setup_secondary_APIC_clock,
23292 };
23293 @@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23294 static void default_nmi_init(void) { };
23295 static int default_i8042_detect(void) { return 1; };
23296
23297 -struct x86_platform_ops x86_platform = {
23298 +struct x86_platform_ops x86_platform __read_only = {
23299 .calibrate_tsc = native_calibrate_tsc,
23300 .get_wallclock = mach_get_cmos_time,
23301 .set_wallclock = mach_set_rtc_mmss,
23302 @@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
23303 };
23304
23305 EXPORT_SYMBOL_GPL(x86_platform);
23306 -struct x86_msi_ops x86_msi = {
23307 +struct x86_msi_ops x86_msi __read_only = {
23308 .setup_msi_irqs = native_setup_msi_irqs,
23309 .teardown_msi_irq = native_teardown_msi_irq,
23310 .teardown_msi_irqs = default_teardown_msi_irqs,
23311 .restore_msi_irqs = default_restore_msi_irqs,
23312 };
23313
23314 -struct x86_io_apic_ops x86_io_apic_ops = {
23315 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23316 .init = native_io_apic_init_mappings,
23317 .read = native_io_apic_read,
23318 .write = native_io_apic_write,
23319 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23320 index ada87a3..afea76d 100644
23321 --- a/arch/x86/kernel/xsave.c
23322 +++ b/arch/x86/kernel/xsave.c
23323 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23324 {
23325 int err;
23326
23327 + buf = (struct xsave_struct __user *)____m(buf);
23328 if (use_xsave())
23329 err = xsave_user(buf);
23330 else if (use_fxsr())
23331 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23332 */
23333 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23334 {
23335 + buf = (void __user *)____m(buf);
23336 if (use_xsave()) {
23337 if ((unsigned long)buf % 64 || fx_only) {
23338 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23339 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23340 index a20ecb5..d0e2194 100644
23341 --- a/arch/x86/kvm/cpuid.c
23342 +++ b/arch/x86/kvm/cpuid.c
23343 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23344 struct kvm_cpuid2 *cpuid,
23345 struct kvm_cpuid_entry2 __user *entries)
23346 {
23347 - int r;
23348 + int r, i;
23349
23350 r = -E2BIG;
23351 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23352 goto out;
23353 r = -EFAULT;
23354 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23355 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23356 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23357 goto out;
23358 + for (i = 0; i < cpuid->nent; ++i) {
23359 + struct kvm_cpuid_entry2 cpuid_entry;
23360 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23361 + goto out;
23362 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
23363 + }
23364 vcpu->arch.cpuid_nent = cpuid->nent;
23365 kvm_apic_set_version(vcpu);
23366 kvm_x86_ops->cpuid_update(vcpu);
23367 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23368 struct kvm_cpuid2 *cpuid,
23369 struct kvm_cpuid_entry2 __user *entries)
23370 {
23371 - int r;
23372 + int r, i;
23373
23374 r = -E2BIG;
23375 if (cpuid->nent < vcpu->arch.cpuid_nent)
23376 goto out;
23377 r = -EFAULT;
23378 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23379 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23380 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23381 goto out;
23382 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23383 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23384 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23385 + goto out;
23386 + }
23387 return 0;
23388
23389 out:
23390 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23391 index a27e763..54bfe43 100644
23392 --- a/arch/x86/kvm/emulate.c
23393 +++ b/arch/x86/kvm/emulate.c
23394 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23395
23396 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23397 do { \
23398 + unsigned long _tmp; \
23399 __asm__ __volatile__ ( \
23400 _PRE_EFLAGS("0", "4", "2") \
23401 _op _suffix " %"_x"3,%1; " \
23402 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23403 /* Raw emulation: instruction has two explicit operands. */
23404 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23405 do { \
23406 - unsigned long _tmp; \
23407 - \
23408 switch ((ctxt)->dst.bytes) { \
23409 case 2: \
23410 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23411 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23412
23413 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23414 do { \
23415 - unsigned long _tmp; \
23416 switch ((ctxt)->dst.bytes) { \
23417 case 1: \
23418 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
23419 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
23420 index 9392f52..0e56d77 100644
23421 --- a/arch/x86/kvm/lapic.c
23422 +++ b/arch/x86/kvm/lapic.c
23423 @@ -55,7 +55,7 @@
23424 #define APIC_BUS_CYCLE_NS 1
23425
23426 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
23427 -#define apic_debug(fmt, arg...)
23428 +#define apic_debug(fmt, arg...) do {} while (0)
23429
23430 #define APIC_LVT_NUM 6
23431 /* 14 is the version for Xeon and Pentium 8.4.8*/
23432 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
23433 index 891eb6d..e027900 100644
23434 --- a/arch/x86/kvm/paging_tmpl.h
23435 +++ b/arch/x86/kvm/paging_tmpl.h
23436 @@ -208,7 +208,7 @@ retry_walk:
23437 if (unlikely(kvm_is_error_hva(host_addr)))
23438 goto error;
23439
23440 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
23441 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
23442 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
23443 goto error;
23444 walker->ptep_user[walker->level - 1] = ptep_user;
23445 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
23446 index d29d3cd..ec9d522 100644
23447 --- a/arch/x86/kvm/svm.c
23448 +++ b/arch/x86/kvm/svm.c
23449 @@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
23450 int cpu = raw_smp_processor_id();
23451
23452 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
23453 +
23454 + pax_open_kernel();
23455 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
23456 + pax_close_kernel();
23457 +
23458 load_TR_desc();
23459 }
23460
23461 @@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
23462 #endif
23463 #endif
23464
23465 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23466 + __set_fs(current_thread_info()->addr_limit);
23467 +#endif
23468 +
23469 reload_tss(vcpu);
23470
23471 local_irq_disable();
23472 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
23473 index 9120ae1..238abc0 100644
23474 --- a/arch/x86/kvm/vmx.c
23475 +++ b/arch/x86/kvm/vmx.c
23476 @@ -1370,7 +1370,11 @@ static void reload_tss(void)
23477 struct desc_struct *descs;
23478
23479 descs = (void *)gdt->address;
23480 +
23481 + pax_open_kernel();
23482 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
23483 + pax_close_kernel();
23484 +
23485 load_TR_desc();
23486 }
23487
23488 @@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
23489 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
23490 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
23491
23492 +#ifdef CONFIG_PAX_PER_CPU_PGD
23493 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23494 +#endif
23495 +
23496 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23497 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
23498 vmx->loaded_vmcs->cpu = cpu;
23499 @@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
23500 if (!cpu_has_vmx_flexpriority())
23501 flexpriority_enabled = 0;
23502
23503 - if (!cpu_has_vmx_tpr_shadow())
23504 - kvm_x86_ops->update_cr8_intercept = NULL;
23505 + if (!cpu_has_vmx_tpr_shadow()) {
23506 + pax_open_kernel();
23507 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
23508 + pax_close_kernel();
23509 + }
23510
23511 if (enable_ept && !cpu_has_vmx_ept_2m_page())
23512 kvm_disable_largepages();
23513 @@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
23514
23515 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
23516 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
23517 +
23518 +#ifndef CONFIG_PAX_PER_CPU_PGD
23519 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23520 +#endif
23521
23522 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
23523 #ifdef CONFIG_X86_64
23524 @@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
23525 native_store_idt(&dt);
23526 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
23527
23528 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
23529 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
23530
23531 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
23532 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
23533 @@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23534 "jmp 2f \n\t"
23535 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
23536 "2: "
23537 +
23538 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23539 + "ljmp %[cs],$3f\n\t"
23540 + "3: "
23541 +#endif
23542 +
23543 /* Save guest registers, load host registers, keep flags */
23544 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
23545 "pop %0 \n\t"
23546 @@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23547 #endif
23548 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
23549 [wordsize]"i"(sizeof(ulong))
23550 +
23551 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23552 + ,[cs]"i"(__KERNEL_CS)
23553 +#endif
23554 +
23555 : "cc", "memory"
23556 #ifdef CONFIG_X86_64
23557 , "rax", "rbx", "rdi", "rsi"
23558 @@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23559 if (debugctlmsr)
23560 update_debugctlmsr(debugctlmsr);
23561
23562 -#ifndef CONFIG_X86_64
23563 +#ifdef CONFIG_X86_32
23564 /*
23565 * The sysexit path does not restore ds/es, so we must set them to
23566 * a reasonable value ourselves.
23567 @@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23568 * may be executed in interrupt context, which saves and restore segments
23569 * around it, nullifying its effect.
23570 */
23571 - loadsegment(ds, __USER_DS);
23572 - loadsegment(es, __USER_DS);
23573 + loadsegment(ds, __KERNEL_DS);
23574 + loadsegment(es, __KERNEL_DS);
23575 + loadsegment(ss, __KERNEL_DS);
23576 +
23577 +#ifdef CONFIG_PAX_KERNEXEC
23578 + loadsegment(fs, __KERNEL_PERCPU);
23579 +#endif
23580 +
23581 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23582 + __set_fs(current_thread_info()->addr_limit);
23583 +#endif
23584 +
23585 #endif
23586
23587 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
23588 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
23589 index c243b81..9eb193f 100644
23590 --- a/arch/x86/kvm/x86.c
23591 +++ b/arch/x86/kvm/x86.c
23592 @@ -1692,8 +1692,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
23593 {
23594 struct kvm *kvm = vcpu->kvm;
23595 int lm = is_long_mode(vcpu);
23596 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23597 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23598 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23599 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23600 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
23601 : kvm->arch.xen_hvm_config.blob_size_32;
23602 u32 page_num = data & ~PAGE_MASK;
23603 @@ -2571,6 +2571,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
23604 if (n < msr_list.nmsrs)
23605 goto out;
23606 r = -EFAULT;
23607 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
23608 + goto out;
23609 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
23610 num_msrs_to_save * sizeof(u32)))
23611 goto out;
23612 @@ -2700,7 +2702,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
23613 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
23614 struct kvm_interrupt *irq)
23615 {
23616 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
23617 + if (irq->irq >= KVM_NR_INTERRUPTS)
23618 return -EINVAL;
23619 if (irqchip_in_kernel(vcpu->kvm))
23620 return -ENXIO;
23621 @@ -5213,7 +5215,7 @@ static struct notifier_block pvclock_gtod_notifier = {
23622 };
23623 #endif
23624
23625 -int kvm_arch_init(void *opaque)
23626 +int kvm_arch_init(const void *opaque)
23627 {
23628 int r;
23629 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
23630 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
23631 index df4176c..23ce092 100644
23632 --- a/arch/x86/lguest/boot.c
23633 +++ b/arch/x86/lguest/boot.c
23634 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
23635 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
23636 * Launcher to reboot us.
23637 */
23638 -static void lguest_restart(char *reason)
23639 +static __noreturn void lguest_restart(char *reason)
23640 {
23641 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
23642 + BUG();
23643 }
23644
23645 /*G:050
23646 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
23647 index 00933d5..3a64af9 100644
23648 --- a/arch/x86/lib/atomic64_386_32.S
23649 +++ b/arch/x86/lib/atomic64_386_32.S
23650 @@ -48,6 +48,10 @@ BEGIN(read)
23651 movl (v), %eax
23652 movl 4(v), %edx
23653 RET_ENDP
23654 +BEGIN(read_unchecked)
23655 + movl (v), %eax
23656 + movl 4(v), %edx
23657 +RET_ENDP
23658 #undef v
23659
23660 #define v %esi
23661 @@ -55,6 +59,10 @@ BEGIN(set)
23662 movl %ebx, (v)
23663 movl %ecx, 4(v)
23664 RET_ENDP
23665 +BEGIN(set_unchecked)
23666 + movl %ebx, (v)
23667 + movl %ecx, 4(v)
23668 +RET_ENDP
23669 #undef v
23670
23671 #define v %esi
23672 @@ -70,6 +78,20 @@ RET_ENDP
23673 BEGIN(add)
23674 addl %eax, (v)
23675 adcl %edx, 4(v)
23676 +
23677 +#ifdef CONFIG_PAX_REFCOUNT
23678 + jno 0f
23679 + subl %eax, (v)
23680 + sbbl %edx, 4(v)
23681 + int $4
23682 +0:
23683 + _ASM_EXTABLE(0b, 0b)
23684 +#endif
23685 +
23686 +RET_ENDP
23687 +BEGIN(add_unchecked)
23688 + addl %eax, (v)
23689 + adcl %edx, 4(v)
23690 RET_ENDP
23691 #undef v
23692
23693 @@ -77,6 +99,24 @@ RET_ENDP
23694 BEGIN(add_return)
23695 addl (v), %eax
23696 adcl 4(v), %edx
23697 +
23698 +#ifdef CONFIG_PAX_REFCOUNT
23699 + into
23700 +1234:
23701 + _ASM_EXTABLE(1234b, 2f)
23702 +#endif
23703 +
23704 + movl %eax, (v)
23705 + movl %edx, 4(v)
23706 +
23707 +#ifdef CONFIG_PAX_REFCOUNT
23708 +2:
23709 +#endif
23710 +
23711 +RET_ENDP
23712 +BEGIN(add_return_unchecked)
23713 + addl (v), %eax
23714 + adcl 4(v), %edx
23715 movl %eax, (v)
23716 movl %edx, 4(v)
23717 RET_ENDP
23718 @@ -86,6 +126,20 @@ RET_ENDP
23719 BEGIN(sub)
23720 subl %eax, (v)
23721 sbbl %edx, 4(v)
23722 +
23723 +#ifdef CONFIG_PAX_REFCOUNT
23724 + jno 0f
23725 + addl %eax, (v)
23726 + adcl %edx, 4(v)
23727 + int $4
23728 +0:
23729 + _ASM_EXTABLE(0b, 0b)
23730 +#endif
23731 +
23732 +RET_ENDP
23733 +BEGIN(sub_unchecked)
23734 + subl %eax, (v)
23735 + sbbl %edx, 4(v)
23736 RET_ENDP
23737 #undef v
23738
23739 @@ -96,6 +150,27 @@ BEGIN(sub_return)
23740 sbbl $0, %edx
23741 addl (v), %eax
23742 adcl 4(v), %edx
23743 +
23744 +#ifdef CONFIG_PAX_REFCOUNT
23745 + into
23746 +1234:
23747 + _ASM_EXTABLE(1234b, 2f)
23748 +#endif
23749 +
23750 + movl %eax, (v)
23751 + movl %edx, 4(v)
23752 +
23753 +#ifdef CONFIG_PAX_REFCOUNT
23754 +2:
23755 +#endif
23756 +
23757 +RET_ENDP
23758 +BEGIN(sub_return_unchecked)
23759 + negl %edx
23760 + negl %eax
23761 + sbbl $0, %edx
23762 + addl (v), %eax
23763 + adcl 4(v), %edx
23764 movl %eax, (v)
23765 movl %edx, 4(v)
23766 RET_ENDP
23767 @@ -105,6 +180,20 @@ RET_ENDP
23768 BEGIN(inc)
23769 addl $1, (v)
23770 adcl $0, 4(v)
23771 +
23772 +#ifdef CONFIG_PAX_REFCOUNT
23773 + jno 0f
23774 + subl $1, (v)
23775 + sbbl $0, 4(v)
23776 + int $4
23777 +0:
23778 + _ASM_EXTABLE(0b, 0b)
23779 +#endif
23780 +
23781 +RET_ENDP
23782 +BEGIN(inc_unchecked)
23783 + addl $1, (v)
23784 + adcl $0, 4(v)
23785 RET_ENDP
23786 #undef v
23787
23788 @@ -114,6 +203,26 @@ BEGIN(inc_return)
23789 movl 4(v), %edx
23790 addl $1, %eax
23791 adcl $0, %edx
23792 +
23793 +#ifdef CONFIG_PAX_REFCOUNT
23794 + into
23795 +1234:
23796 + _ASM_EXTABLE(1234b, 2f)
23797 +#endif
23798 +
23799 + movl %eax, (v)
23800 + movl %edx, 4(v)
23801 +
23802 +#ifdef CONFIG_PAX_REFCOUNT
23803 +2:
23804 +#endif
23805 +
23806 +RET_ENDP
23807 +BEGIN(inc_return_unchecked)
23808 + movl (v), %eax
23809 + movl 4(v), %edx
23810 + addl $1, %eax
23811 + adcl $0, %edx
23812 movl %eax, (v)
23813 movl %edx, 4(v)
23814 RET_ENDP
23815 @@ -123,6 +232,20 @@ RET_ENDP
23816 BEGIN(dec)
23817 subl $1, (v)
23818 sbbl $0, 4(v)
23819 +
23820 +#ifdef CONFIG_PAX_REFCOUNT
23821 + jno 0f
23822 + addl $1, (v)
23823 + adcl $0, 4(v)
23824 + int $4
23825 +0:
23826 + _ASM_EXTABLE(0b, 0b)
23827 +#endif
23828 +
23829 +RET_ENDP
23830 +BEGIN(dec_unchecked)
23831 + subl $1, (v)
23832 + sbbl $0, 4(v)
23833 RET_ENDP
23834 #undef v
23835
23836 @@ -132,6 +255,26 @@ BEGIN(dec_return)
23837 movl 4(v), %edx
23838 subl $1, %eax
23839 sbbl $0, %edx
23840 +
23841 +#ifdef CONFIG_PAX_REFCOUNT
23842 + into
23843 +1234:
23844 + _ASM_EXTABLE(1234b, 2f)
23845 +#endif
23846 +
23847 + movl %eax, (v)
23848 + movl %edx, 4(v)
23849 +
23850 +#ifdef CONFIG_PAX_REFCOUNT
23851 +2:
23852 +#endif
23853 +
23854 +RET_ENDP
23855 +BEGIN(dec_return_unchecked)
23856 + movl (v), %eax
23857 + movl 4(v), %edx
23858 + subl $1, %eax
23859 + sbbl $0, %edx
23860 movl %eax, (v)
23861 movl %edx, 4(v)
23862 RET_ENDP
23863 @@ -143,6 +286,13 @@ BEGIN(add_unless)
23864 adcl %edx, %edi
23865 addl (v), %eax
23866 adcl 4(v), %edx
23867 +
23868 +#ifdef CONFIG_PAX_REFCOUNT
23869 + into
23870 +1234:
23871 + _ASM_EXTABLE(1234b, 2f)
23872 +#endif
23873 +
23874 cmpl %eax, %ecx
23875 je 3f
23876 1:
23877 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
23878 1:
23879 addl $1, %eax
23880 adcl $0, %edx
23881 +
23882 +#ifdef CONFIG_PAX_REFCOUNT
23883 + into
23884 +1234:
23885 + _ASM_EXTABLE(1234b, 2f)
23886 +#endif
23887 +
23888 movl %eax, (v)
23889 movl %edx, 4(v)
23890 movl $1, %eax
23891 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
23892 movl 4(v), %edx
23893 subl $1, %eax
23894 sbbl $0, %edx
23895 +
23896 +#ifdef CONFIG_PAX_REFCOUNT
23897 + into
23898 +1234:
23899 + _ASM_EXTABLE(1234b, 1f)
23900 +#endif
23901 +
23902 js 1f
23903 movl %eax, (v)
23904 movl %edx, 4(v)
23905 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
23906 index f5cc9eb..51fa319 100644
23907 --- a/arch/x86/lib/atomic64_cx8_32.S
23908 +++ b/arch/x86/lib/atomic64_cx8_32.S
23909 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
23910 CFI_STARTPROC
23911
23912 read64 %ecx
23913 + pax_force_retaddr
23914 ret
23915 CFI_ENDPROC
23916 ENDPROC(atomic64_read_cx8)
23917
23918 +ENTRY(atomic64_read_unchecked_cx8)
23919 + CFI_STARTPROC
23920 +
23921 + read64 %ecx
23922 + pax_force_retaddr
23923 + ret
23924 + CFI_ENDPROC
23925 +ENDPROC(atomic64_read_unchecked_cx8)
23926 +
23927 ENTRY(atomic64_set_cx8)
23928 CFI_STARTPROC
23929
23930 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
23931 cmpxchg8b (%esi)
23932 jne 1b
23933
23934 + pax_force_retaddr
23935 ret
23936 CFI_ENDPROC
23937 ENDPROC(atomic64_set_cx8)
23938
23939 +ENTRY(atomic64_set_unchecked_cx8)
23940 + CFI_STARTPROC
23941 +
23942 +1:
23943 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
23944 + * are atomic on 586 and newer */
23945 + cmpxchg8b (%esi)
23946 + jne 1b
23947 +
23948 + pax_force_retaddr
23949 + ret
23950 + CFI_ENDPROC
23951 +ENDPROC(atomic64_set_unchecked_cx8)
23952 +
23953 ENTRY(atomic64_xchg_cx8)
23954 CFI_STARTPROC
23955
23956 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
23957 cmpxchg8b (%esi)
23958 jne 1b
23959
23960 + pax_force_retaddr
23961 ret
23962 CFI_ENDPROC
23963 ENDPROC(atomic64_xchg_cx8)
23964
23965 -.macro addsub_return func ins insc
23966 -ENTRY(atomic64_\func\()_return_cx8)
23967 +.macro addsub_return func ins insc unchecked=""
23968 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
23969 CFI_STARTPROC
23970 SAVE ebp
23971 SAVE ebx
23972 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
23973 movl %edx, %ecx
23974 \ins\()l %esi, %ebx
23975 \insc\()l %edi, %ecx
23976 +
23977 +.ifb \unchecked
23978 +#ifdef CONFIG_PAX_REFCOUNT
23979 + into
23980 +2:
23981 + _ASM_EXTABLE(2b, 3f)
23982 +#endif
23983 +.endif
23984 +
23985 LOCK_PREFIX
23986 cmpxchg8b (%ebp)
23987 jne 1b
23988 -
23989 -10:
23990 movl %ebx, %eax
23991 movl %ecx, %edx
23992 +
23993 +.ifb \unchecked
23994 +#ifdef CONFIG_PAX_REFCOUNT
23995 +3:
23996 +#endif
23997 +.endif
23998 +
23999 RESTORE edi
24000 RESTORE esi
24001 RESTORE ebx
24002 RESTORE ebp
24003 + pax_force_retaddr
24004 ret
24005 CFI_ENDPROC
24006 -ENDPROC(atomic64_\func\()_return_cx8)
24007 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24008 .endm
24009
24010 addsub_return add add adc
24011 addsub_return sub sub sbb
24012 +addsub_return add add adc _unchecked
24013 +addsub_return sub sub sbb _unchecked
24014
24015 -.macro incdec_return func ins insc
24016 -ENTRY(atomic64_\func\()_return_cx8)
24017 +.macro incdec_return func ins insc unchecked=""
24018 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24019 CFI_STARTPROC
24020 SAVE ebx
24021
24022 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24023 movl %edx, %ecx
24024 \ins\()l $1, %ebx
24025 \insc\()l $0, %ecx
24026 +
24027 +.ifb \unchecked
24028 +#ifdef CONFIG_PAX_REFCOUNT
24029 + into
24030 +2:
24031 + _ASM_EXTABLE(2b, 3f)
24032 +#endif
24033 +.endif
24034 +
24035 LOCK_PREFIX
24036 cmpxchg8b (%esi)
24037 jne 1b
24038
24039 -10:
24040 movl %ebx, %eax
24041 movl %ecx, %edx
24042 +
24043 +.ifb \unchecked
24044 +#ifdef CONFIG_PAX_REFCOUNT
24045 +3:
24046 +#endif
24047 +.endif
24048 +
24049 RESTORE ebx
24050 + pax_force_retaddr
24051 ret
24052 CFI_ENDPROC
24053 -ENDPROC(atomic64_\func\()_return_cx8)
24054 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24055 .endm
24056
24057 incdec_return inc add adc
24058 incdec_return dec sub sbb
24059 +incdec_return inc add adc _unchecked
24060 +incdec_return dec sub sbb _unchecked
24061
24062 ENTRY(atomic64_dec_if_positive_cx8)
24063 CFI_STARTPROC
24064 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24065 movl %edx, %ecx
24066 subl $1, %ebx
24067 sbb $0, %ecx
24068 +
24069 +#ifdef CONFIG_PAX_REFCOUNT
24070 + into
24071 +1234:
24072 + _ASM_EXTABLE(1234b, 2f)
24073 +#endif
24074 +
24075 js 2f
24076 LOCK_PREFIX
24077 cmpxchg8b (%esi)
24078 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24079 movl %ebx, %eax
24080 movl %ecx, %edx
24081 RESTORE ebx
24082 + pax_force_retaddr
24083 ret
24084 CFI_ENDPROC
24085 ENDPROC(atomic64_dec_if_positive_cx8)
24086 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24087 movl %edx, %ecx
24088 addl %ebp, %ebx
24089 adcl %edi, %ecx
24090 +
24091 +#ifdef CONFIG_PAX_REFCOUNT
24092 + into
24093 +1234:
24094 + _ASM_EXTABLE(1234b, 3f)
24095 +#endif
24096 +
24097 LOCK_PREFIX
24098 cmpxchg8b (%esi)
24099 jne 1b
24100 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24101 CFI_ADJUST_CFA_OFFSET -8
24102 RESTORE ebx
24103 RESTORE ebp
24104 + pax_force_retaddr
24105 ret
24106 4:
24107 cmpl %edx, 4(%esp)
24108 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24109 xorl %ecx, %ecx
24110 addl $1, %ebx
24111 adcl %edx, %ecx
24112 +
24113 +#ifdef CONFIG_PAX_REFCOUNT
24114 + into
24115 +1234:
24116 + _ASM_EXTABLE(1234b, 3f)
24117 +#endif
24118 +
24119 LOCK_PREFIX
24120 cmpxchg8b (%esi)
24121 jne 1b
24122 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24123 movl $1, %eax
24124 3:
24125 RESTORE ebx
24126 + pax_force_retaddr
24127 ret
24128 CFI_ENDPROC
24129 ENDPROC(atomic64_inc_not_zero_cx8)
24130 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24131 index 2af5df3..62b1a5a 100644
24132 --- a/arch/x86/lib/checksum_32.S
24133 +++ b/arch/x86/lib/checksum_32.S
24134 @@ -29,7 +29,8 @@
24135 #include <asm/dwarf2.h>
24136 #include <asm/errno.h>
24137 #include <asm/asm.h>
24138 -
24139 +#include <asm/segment.h>
24140 +
24141 /*
24142 * computes a partial checksum, e.g. for TCP/UDP fragments
24143 */
24144 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24145
24146 #define ARGBASE 16
24147 #define FP 12
24148 -
24149 -ENTRY(csum_partial_copy_generic)
24150 +
24151 +ENTRY(csum_partial_copy_generic_to_user)
24152 CFI_STARTPROC
24153 +
24154 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24155 + pushl_cfi %gs
24156 + popl_cfi %es
24157 + jmp csum_partial_copy_generic
24158 +#endif
24159 +
24160 +ENTRY(csum_partial_copy_generic_from_user)
24161 +
24162 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24163 + pushl_cfi %gs
24164 + popl_cfi %ds
24165 +#endif
24166 +
24167 +ENTRY(csum_partial_copy_generic)
24168 subl $4,%esp
24169 CFI_ADJUST_CFA_OFFSET 4
24170 pushl_cfi %edi
24171 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24172 jmp 4f
24173 SRC(1: movw (%esi), %bx )
24174 addl $2, %esi
24175 -DST( movw %bx, (%edi) )
24176 +DST( movw %bx, %es:(%edi) )
24177 addl $2, %edi
24178 addw %bx, %ax
24179 adcl $0, %eax
24180 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24181 SRC(1: movl (%esi), %ebx )
24182 SRC( movl 4(%esi), %edx )
24183 adcl %ebx, %eax
24184 -DST( movl %ebx, (%edi) )
24185 +DST( movl %ebx, %es:(%edi) )
24186 adcl %edx, %eax
24187 -DST( movl %edx, 4(%edi) )
24188 +DST( movl %edx, %es:4(%edi) )
24189
24190 SRC( movl 8(%esi), %ebx )
24191 SRC( movl 12(%esi), %edx )
24192 adcl %ebx, %eax
24193 -DST( movl %ebx, 8(%edi) )
24194 +DST( movl %ebx, %es:8(%edi) )
24195 adcl %edx, %eax
24196 -DST( movl %edx, 12(%edi) )
24197 +DST( movl %edx, %es:12(%edi) )
24198
24199 SRC( movl 16(%esi), %ebx )
24200 SRC( movl 20(%esi), %edx )
24201 adcl %ebx, %eax
24202 -DST( movl %ebx, 16(%edi) )
24203 +DST( movl %ebx, %es:16(%edi) )
24204 adcl %edx, %eax
24205 -DST( movl %edx, 20(%edi) )
24206 +DST( movl %edx, %es:20(%edi) )
24207
24208 SRC( movl 24(%esi), %ebx )
24209 SRC( movl 28(%esi), %edx )
24210 adcl %ebx, %eax
24211 -DST( movl %ebx, 24(%edi) )
24212 +DST( movl %ebx, %es:24(%edi) )
24213 adcl %edx, %eax
24214 -DST( movl %edx, 28(%edi) )
24215 +DST( movl %edx, %es:28(%edi) )
24216
24217 lea 32(%esi), %esi
24218 lea 32(%edi), %edi
24219 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24220 shrl $2, %edx # This clears CF
24221 SRC(3: movl (%esi), %ebx )
24222 adcl %ebx, %eax
24223 -DST( movl %ebx, (%edi) )
24224 +DST( movl %ebx, %es:(%edi) )
24225 lea 4(%esi), %esi
24226 lea 4(%edi), %edi
24227 dec %edx
24228 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24229 jb 5f
24230 SRC( movw (%esi), %cx )
24231 leal 2(%esi), %esi
24232 -DST( movw %cx, (%edi) )
24233 +DST( movw %cx, %es:(%edi) )
24234 leal 2(%edi), %edi
24235 je 6f
24236 shll $16,%ecx
24237 SRC(5: movb (%esi), %cl )
24238 -DST( movb %cl, (%edi) )
24239 +DST( movb %cl, %es:(%edi) )
24240 6: addl %ecx, %eax
24241 adcl $0, %eax
24242 7:
24243 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24244
24245 6001:
24246 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24247 - movl $-EFAULT, (%ebx)
24248 + movl $-EFAULT, %ss:(%ebx)
24249
24250 # zero the complete destination - computing the rest
24251 # is too much work
24252 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24253
24254 6002:
24255 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24256 - movl $-EFAULT,(%ebx)
24257 + movl $-EFAULT,%ss:(%ebx)
24258 jmp 5000b
24259
24260 .previous
24261
24262 + pushl_cfi %ss
24263 + popl_cfi %ds
24264 + pushl_cfi %ss
24265 + popl_cfi %es
24266 popl_cfi %ebx
24267 CFI_RESTORE ebx
24268 popl_cfi %esi
24269 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24270 popl_cfi %ecx # equivalent to addl $4,%esp
24271 ret
24272 CFI_ENDPROC
24273 -ENDPROC(csum_partial_copy_generic)
24274 +ENDPROC(csum_partial_copy_generic_to_user)
24275
24276 #else
24277
24278 /* Version for PentiumII/PPro */
24279
24280 #define ROUND1(x) \
24281 + nop; nop; nop; \
24282 SRC(movl x(%esi), %ebx ) ; \
24283 addl %ebx, %eax ; \
24284 - DST(movl %ebx, x(%edi) ) ;
24285 + DST(movl %ebx, %es:x(%edi)) ;
24286
24287 #define ROUND(x) \
24288 + nop; nop; nop; \
24289 SRC(movl x(%esi), %ebx ) ; \
24290 adcl %ebx, %eax ; \
24291 - DST(movl %ebx, x(%edi) ) ;
24292 + DST(movl %ebx, %es:x(%edi)) ;
24293
24294 #define ARGBASE 12
24295 -
24296 -ENTRY(csum_partial_copy_generic)
24297 +
24298 +ENTRY(csum_partial_copy_generic_to_user)
24299 CFI_STARTPROC
24300 +
24301 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24302 + pushl_cfi %gs
24303 + popl_cfi %es
24304 + jmp csum_partial_copy_generic
24305 +#endif
24306 +
24307 +ENTRY(csum_partial_copy_generic_from_user)
24308 +
24309 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24310 + pushl_cfi %gs
24311 + popl_cfi %ds
24312 +#endif
24313 +
24314 +ENTRY(csum_partial_copy_generic)
24315 pushl_cfi %ebx
24316 CFI_REL_OFFSET ebx, 0
24317 pushl_cfi %edi
24318 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24319 subl %ebx, %edi
24320 lea -1(%esi),%edx
24321 andl $-32,%edx
24322 - lea 3f(%ebx,%ebx), %ebx
24323 + lea 3f(%ebx,%ebx,2), %ebx
24324 testl %esi, %esi
24325 jmp *%ebx
24326 1: addl $64,%esi
24327 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24328 jb 5f
24329 SRC( movw (%esi), %dx )
24330 leal 2(%esi), %esi
24331 -DST( movw %dx, (%edi) )
24332 +DST( movw %dx, %es:(%edi) )
24333 leal 2(%edi), %edi
24334 je 6f
24335 shll $16,%edx
24336 5:
24337 SRC( movb (%esi), %dl )
24338 -DST( movb %dl, (%edi) )
24339 +DST( movb %dl, %es:(%edi) )
24340 6: addl %edx, %eax
24341 adcl $0, %eax
24342 7:
24343 .section .fixup, "ax"
24344 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24345 - movl $-EFAULT, (%ebx)
24346 + movl $-EFAULT, %ss:(%ebx)
24347 # zero the complete destination (computing the rest is too much work)
24348 movl ARGBASE+8(%esp),%edi # dst
24349 movl ARGBASE+12(%esp),%ecx # len
24350 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24351 rep; stosb
24352 jmp 7b
24353 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24354 - movl $-EFAULT, (%ebx)
24355 + movl $-EFAULT, %ss:(%ebx)
24356 jmp 7b
24357 .previous
24358
24359 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24360 + pushl_cfi %ss
24361 + popl_cfi %ds
24362 + pushl_cfi %ss
24363 + popl_cfi %es
24364 +#endif
24365 +
24366 popl_cfi %esi
24367 CFI_RESTORE esi
24368 popl_cfi %edi
24369 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24370 CFI_RESTORE ebx
24371 ret
24372 CFI_ENDPROC
24373 -ENDPROC(csum_partial_copy_generic)
24374 +ENDPROC(csum_partial_copy_generic_to_user)
24375
24376 #undef ROUND
24377 #undef ROUND1
24378 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24379 index f2145cf..cea889d 100644
24380 --- a/arch/x86/lib/clear_page_64.S
24381 +++ b/arch/x86/lib/clear_page_64.S
24382 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24383 movl $4096/8,%ecx
24384 xorl %eax,%eax
24385 rep stosq
24386 + pax_force_retaddr
24387 ret
24388 CFI_ENDPROC
24389 ENDPROC(clear_page_c)
24390 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
24391 movl $4096,%ecx
24392 xorl %eax,%eax
24393 rep stosb
24394 + pax_force_retaddr
24395 ret
24396 CFI_ENDPROC
24397 ENDPROC(clear_page_c_e)
24398 @@ -43,6 +45,7 @@ ENTRY(clear_page)
24399 leaq 64(%rdi),%rdi
24400 jnz .Lloop
24401 nop
24402 + pax_force_retaddr
24403 ret
24404 CFI_ENDPROC
24405 .Lclear_page_end:
24406 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
24407
24408 #include <asm/cpufeature.h>
24409
24410 - .section .altinstr_replacement,"ax"
24411 + .section .altinstr_replacement,"a"
24412 1: .byte 0xeb /* jmp <disp8> */
24413 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
24414 2: .byte 0xeb /* jmp <disp8> */
24415 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
24416 index 1e572c5..2a162cd 100644
24417 --- a/arch/x86/lib/cmpxchg16b_emu.S
24418 +++ b/arch/x86/lib/cmpxchg16b_emu.S
24419 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
24420
24421 popf
24422 mov $1, %al
24423 + pax_force_retaddr
24424 ret
24425
24426 not_same:
24427 popf
24428 xor %al,%al
24429 + pax_force_retaddr
24430 ret
24431
24432 CFI_ENDPROC
24433 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
24434 index 176cca6..1166c50 100644
24435 --- a/arch/x86/lib/copy_page_64.S
24436 +++ b/arch/x86/lib/copy_page_64.S
24437 @@ -9,6 +9,7 @@ copy_page_rep:
24438 CFI_STARTPROC
24439 movl $4096/8, %ecx
24440 rep movsq
24441 + pax_force_retaddr
24442 ret
24443 CFI_ENDPROC
24444 ENDPROC(copy_page_rep)
24445 @@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
24446
24447 ENTRY(copy_page)
24448 CFI_STARTPROC
24449 - subq $2*8, %rsp
24450 - CFI_ADJUST_CFA_OFFSET 2*8
24451 + subq $3*8, %rsp
24452 + CFI_ADJUST_CFA_OFFSET 3*8
24453 movq %rbx, (%rsp)
24454 CFI_REL_OFFSET rbx, 0
24455 movq %r12, 1*8(%rsp)
24456 CFI_REL_OFFSET r12, 1*8
24457 + movq %r13, 2*8(%rsp)
24458 + CFI_REL_OFFSET r13, 2*8
24459
24460 movl $(4096/64)-5, %ecx
24461 .p2align 4
24462 @@ -36,7 +39,7 @@ ENTRY(copy_page)
24463 movq 0x8*2(%rsi), %rdx
24464 movq 0x8*3(%rsi), %r8
24465 movq 0x8*4(%rsi), %r9
24466 - movq 0x8*5(%rsi), %r10
24467 + movq 0x8*5(%rsi), %r13
24468 movq 0x8*6(%rsi), %r11
24469 movq 0x8*7(%rsi), %r12
24470
24471 @@ -47,7 +50,7 @@ ENTRY(copy_page)
24472 movq %rdx, 0x8*2(%rdi)
24473 movq %r8, 0x8*3(%rdi)
24474 movq %r9, 0x8*4(%rdi)
24475 - movq %r10, 0x8*5(%rdi)
24476 + movq %r13, 0x8*5(%rdi)
24477 movq %r11, 0x8*6(%rdi)
24478 movq %r12, 0x8*7(%rdi)
24479
24480 @@ -66,7 +69,7 @@ ENTRY(copy_page)
24481 movq 0x8*2(%rsi), %rdx
24482 movq 0x8*3(%rsi), %r8
24483 movq 0x8*4(%rsi), %r9
24484 - movq 0x8*5(%rsi), %r10
24485 + movq 0x8*5(%rsi), %r13
24486 movq 0x8*6(%rsi), %r11
24487 movq 0x8*7(%rsi), %r12
24488
24489 @@ -75,7 +78,7 @@ ENTRY(copy_page)
24490 movq %rdx, 0x8*2(%rdi)
24491 movq %r8, 0x8*3(%rdi)
24492 movq %r9, 0x8*4(%rdi)
24493 - movq %r10, 0x8*5(%rdi)
24494 + movq %r13, 0x8*5(%rdi)
24495 movq %r11, 0x8*6(%rdi)
24496 movq %r12, 0x8*7(%rdi)
24497
24498 @@ -87,8 +90,11 @@ ENTRY(copy_page)
24499 CFI_RESTORE rbx
24500 movq 1*8(%rsp), %r12
24501 CFI_RESTORE r12
24502 - addq $2*8, %rsp
24503 - CFI_ADJUST_CFA_OFFSET -2*8
24504 + movq 2*8(%rsp), %r13
24505 + CFI_RESTORE r13
24506 + addq $3*8, %rsp
24507 + CFI_ADJUST_CFA_OFFSET -3*8
24508 + pax_force_retaddr
24509 ret
24510 .Lcopy_page_end:
24511 CFI_ENDPROC
24512 @@ -99,7 +105,7 @@ ENDPROC(copy_page)
24513
24514 #include <asm/cpufeature.h>
24515
24516 - .section .altinstr_replacement,"ax"
24517 + .section .altinstr_replacement,"a"
24518 1: .byte 0xeb /* jmp <disp8> */
24519 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
24520 2:
24521 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
24522 index a30ca15..d25fab6 100644
24523 --- a/arch/x86/lib/copy_user_64.S
24524 +++ b/arch/x86/lib/copy_user_64.S
24525 @@ -18,6 +18,7 @@
24526 #include <asm/alternative-asm.h>
24527 #include <asm/asm.h>
24528 #include <asm/smap.h>
24529 +#include <asm/pgtable.h>
24530
24531 /*
24532 * By placing feature2 after feature1 in altinstructions section, we logically
24533 @@ -31,7 +32,7 @@
24534 .byte 0xe9 /* 32bit jump */
24535 .long \orig-1f /* by default jump to orig */
24536 1:
24537 - .section .altinstr_replacement,"ax"
24538 + .section .altinstr_replacement,"a"
24539 2: .byte 0xe9 /* near jump with 32bit immediate */
24540 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
24541 3: .byte 0xe9 /* near jump with 32bit immediate */
24542 @@ -70,47 +71,20 @@
24543 #endif
24544 .endm
24545
24546 -/* Standard copy_to_user with segment limit checking */
24547 -ENTRY(_copy_to_user)
24548 - CFI_STARTPROC
24549 - GET_THREAD_INFO(%rax)
24550 - movq %rdi,%rcx
24551 - addq %rdx,%rcx
24552 - jc bad_to_user
24553 - cmpq TI_addr_limit(%rax),%rcx
24554 - ja bad_to_user
24555 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24556 - copy_user_generic_unrolled,copy_user_generic_string, \
24557 - copy_user_enhanced_fast_string
24558 - CFI_ENDPROC
24559 -ENDPROC(_copy_to_user)
24560 -
24561 -/* Standard copy_from_user with segment limit checking */
24562 -ENTRY(_copy_from_user)
24563 - CFI_STARTPROC
24564 - GET_THREAD_INFO(%rax)
24565 - movq %rsi,%rcx
24566 - addq %rdx,%rcx
24567 - jc bad_from_user
24568 - cmpq TI_addr_limit(%rax),%rcx
24569 - ja bad_from_user
24570 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24571 - copy_user_generic_unrolled,copy_user_generic_string, \
24572 - copy_user_enhanced_fast_string
24573 - CFI_ENDPROC
24574 -ENDPROC(_copy_from_user)
24575 -
24576 .section .fixup,"ax"
24577 /* must zero dest */
24578 ENTRY(bad_from_user)
24579 bad_from_user:
24580 CFI_STARTPROC
24581 + testl %edx,%edx
24582 + js bad_to_user
24583 movl %edx,%ecx
24584 xorl %eax,%eax
24585 rep
24586 stosb
24587 bad_to_user:
24588 movl %edx,%eax
24589 + pax_force_retaddr
24590 ret
24591 CFI_ENDPROC
24592 ENDPROC(bad_from_user)
24593 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
24594 jz 17f
24595 1: movq (%rsi),%r8
24596 2: movq 1*8(%rsi),%r9
24597 -3: movq 2*8(%rsi),%r10
24598 +3: movq 2*8(%rsi),%rax
24599 4: movq 3*8(%rsi),%r11
24600 5: movq %r8,(%rdi)
24601 6: movq %r9,1*8(%rdi)
24602 -7: movq %r10,2*8(%rdi)
24603 +7: movq %rax,2*8(%rdi)
24604 8: movq %r11,3*8(%rdi)
24605 9: movq 4*8(%rsi),%r8
24606 10: movq 5*8(%rsi),%r9
24607 -11: movq 6*8(%rsi),%r10
24608 +11: movq 6*8(%rsi),%rax
24609 12: movq 7*8(%rsi),%r11
24610 13: movq %r8,4*8(%rdi)
24611 14: movq %r9,5*8(%rdi)
24612 -15: movq %r10,6*8(%rdi)
24613 +15: movq %rax,6*8(%rdi)
24614 16: movq %r11,7*8(%rdi)
24615 leaq 64(%rsi),%rsi
24616 leaq 64(%rdi),%rdi
24617 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
24618 jnz 21b
24619 23: xor %eax,%eax
24620 ASM_CLAC
24621 + pax_force_retaddr
24622 ret
24623
24624 .section .fixup,"ax"
24625 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
24626 movsb
24627 4: xorl %eax,%eax
24628 ASM_CLAC
24629 + pax_force_retaddr
24630 ret
24631
24632 .section .fixup,"ax"
24633 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
24634 movsb
24635 2: xorl %eax,%eax
24636 ASM_CLAC
24637 + pax_force_retaddr
24638 ret
24639
24640 .section .fixup,"ax"
24641 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
24642 index 6a4f43c..f5f9e26 100644
24643 --- a/arch/x86/lib/copy_user_nocache_64.S
24644 +++ b/arch/x86/lib/copy_user_nocache_64.S
24645 @@ -8,6 +8,7 @@
24646
24647 #include <linux/linkage.h>
24648 #include <asm/dwarf2.h>
24649 +#include <asm/alternative-asm.h>
24650
24651 #define FIX_ALIGNMENT 1
24652
24653 @@ -16,6 +17,7 @@
24654 #include <asm/thread_info.h>
24655 #include <asm/asm.h>
24656 #include <asm/smap.h>
24657 +#include <asm/pgtable.h>
24658
24659 .macro ALIGN_DESTINATION
24660 #ifdef FIX_ALIGNMENT
24661 @@ -49,6 +51,15 @@
24662 */
24663 ENTRY(__copy_user_nocache)
24664 CFI_STARTPROC
24665 +
24666 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24667 + mov $PAX_USER_SHADOW_BASE,%rcx
24668 + cmp %rcx,%rsi
24669 + jae 1f
24670 + add %rcx,%rsi
24671 +1:
24672 +#endif
24673 +
24674 ASM_STAC
24675 cmpl $8,%edx
24676 jb 20f /* less then 8 bytes, go to byte copy loop */
24677 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
24678 jz 17f
24679 1: movq (%rsi),%r8
24680 2: movq 1*8(%rsi),%r9
24681 -3: movq 2*8(%rsi),%r10
24682 +3: movq 2*8(%rsi),%rax
24683 4: movq 3*8(%rsi),%r11
24684 5: movnti %r8,(%rdi)
24685 6: movnti %r9,1*8(%rdi)
24686 -7: movnti %r10,2*8(%rdi)
24687 +7: movnti %rax,2*8(%rdi)
24688 8: movnti %r11,3*8(%rdi)
24689 9: movq 4*8(%rsi),%r8
24690 10: movq 5*8(%rsi),%r9
24691 -11: movq 6*8(%rsi),%r10
24692 +11: movq 6*8(%rsi),%rax
24693 12: movq 7*8(%rsi),%r11
24694 13: movnti %r8,4*8(%rdi)
24695 14: movnti %r9,5*8(%rdi)
24696 -15: movnti %r10,6*8(%rdi)
24697 +15: movnti %rax,6*8(%rdi)
24698 16: movnti %r11,7*8(%rdi)
24699 leaq 64(%rsi),%rsi
24700 leaq 64(%rdi),%rdi
24701 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
24702 23: xorl %eax,%eax
24703 ASM_CLAC
24704 sfence
24705 + pax_force_retaddr
24706 ret
24707
24708 .section .fixup,"ax"
24709 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
24710 index 2419d5f..953ee51 100644
24711 --- a/arch/x86/lib/csum-copy_64.S
24712 +++ b/arch/x86/lib/csum-copy_64.S
24713 @@ -9,6 +9,7 @@
24714 #include <asm/dwarf2.h>
24715 #include <asm/errno.h>
24716 #include <asm/asm.h>
24717 +#include <asm/alternative-asm.h>
24718
24719 /*
24720 * Checksum copy with exception handling.
24721 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
24722 CFI_RESTORE rbp
24723 addq $7*8, %rsp
24724 CFI_ADJUST_CFA_OFFSET -7*8
24725 + pax_force_retaddr 0, 1
24726 ret
24727 CFI_RESTORE_STATE
24728
24729 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
24730 index 25b7ae8..169fafc 100644
24731 --- a/arch/x86/lib/csum-wrappers_64.c
24732 +++ b/arch/x86/lib/csum-wrappers_64.c
24733 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
24734 len -= 2;
24735 }
24736 }
24737 - isum = csum_partial_copy_generic((__force const void *)src,
24738 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
24739 dst, len, isum, errp, NULL);
24740 if (unlikely(*errp))
24741 goto out_err;
24742 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
24743 }
24744
24745 *errp = 0;
24746 - return csum_partial_copy_generic(src, (void __force *)dst,
24747 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
24748 len, isum, NULL, errp);
24749 }
24750 EXPORT_SYMBOL(csum_partial_copy_to_user);
24751 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
24752 index 156b9c8..b144132 100644
24753 --- a/arch/x86/lib/getuser.S
24754 +++ b/arch/x86/lib/getuser.S
24755 @@ -34,17 +34,40 @@
24756 #include <asm/thread_info.h>
24757 #include <asm/asm.h>
24758 #include <asm/smap.h>
24759 +#include <asm/segment.h>
24760 +#include <asm/pgtable.h>
24761 +#include <asm/alternative-asm.h>
24762 +
24763 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24764 +#define __copyuser_seg gs;
24765 +#else
24766 +#define __copyuser_seg
24767 +#endif
24768
24769 .text
24770 ENTRY(__get_user_1)
24771 CFI_STARTPROC
24772 +
24773 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24774 GET_THREAD_INFO(%_ASM_DX)
24775 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24776 jae bad_get_user
24777 ASM_STAC
24778 -1: movzb (%_ASM_AX),%edx
24779 +
24780 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24781 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24782 + cmp %_ASM_DX,%_ASM_AX
24783 + jae 1234f
24784 + add %_ASM_DX,%_ASM_AX
24785 +1234:
24786 +#endif
24787 +
24788 +#endif
24789 +
24790 +1: __copyuser_seg movzb (%_ASM_AX),%edx
24791 xor %eax,%eax
24792 ASM_CLAC
24793 + pax_force_retaddr
24794 ret
24795 CFI_ENDPROC
24796 ENDPROC(__get_user_1)
24797 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
24798 ENTRY(__get_user_2)
24799 CFI_STARTPROC
24800 add $1,%_ASM_AX
24801 +
24802 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24803 jc bad_get_user
24804 GET_THREAD_INFO(%_ASM_DX)
24805 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24806 jae bad_get_user
24807 ASM_STAC
24808 -2: movzwl -1(%_ASM_AX),%edx
24809 +
24810 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24811 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24812 + cmp %_ASM_DX,%_ASM_AX
24813 + jae 1234f
24814 + add %_ASM_DX,%_ASM_AX
24815 +1234:
24816 +#endif
24817 +
24818 +#endif
24819 +
24820 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
24821 xor %eax,%eax
24822 ASM_CLAC
24823 + pax_force_retaddr
24824 ret
24825 CFI_ENDPROC
24826 ENDPROC(__get_user_2)
24827 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
24828 ENTRY(__get_user_4)
24829 CFI_STARTPROC
24830 add $3,%_ASM_AX
24831 +
24832 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24833 jc bad_get_user
24834 GET_THREAD_INFO(%_ASM_DX)
24835 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24836 jae bad_get_user
24837 ASM_STAC
24838 -3: mov -3(%_ASM_AX),%edx
24839 +
24840 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24841 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24842 + cmp %_ASM_DX,%_ASM_AX
24843 + jae 1234f
24844 + add %_ASM_DX,%_ASM_AX
24845 +1234:
24846 +#endif
24847 +
24848 +#endif
24849 +
24850 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
24851 xor %eax,%eax
24852 ASM_CLAC
24853 + pax_force_retaddr
24854 ret
24855 CFI_ENDPROC
24856 ENDPROC(__get_user_4)
24857 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
24858 GET_THREAD_INFO(%_ASM_DX)
24859 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24860 jae bad_get_user
24861 +
24862 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24863 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24864 + cmp %_ASM_DX,%_ASM_AX
24865 + jae 1234f
24866 + add %_ASM_DX,%_ASM_AX
24867 +1234:
24868 +#endif
24869 +
24870 ASM_STAC
24871 4: movq -7(%_ASM_AX),%_ASM_DX
24872 xor %eax,%eax
24873 ASM_CLAC
24874 + pax_force_retaddr
24875 ret
24876 CFI_ENDPROC
24877 ENDPROC(__get_user_8)
24878 @@ -101,6 +162,7 @@ bad_get_user:
24879 xor %edx,%edx
24880 mov $(-EFAULT),%_ASM_AX
24881 ASM_CLAC
24882 + pax_force_retaddr
24883 ret
24884 CFI_ENDPROC
24885 END(bad_get_user)
24886 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
24887 index 54fcffe..7be149e 100644
24888 --- a/arch/x86/lib/insn.c
24889 +++ b/arch/x86/lib/insn.c
24890 @@ -20,8 +20,10 @@
24891
24892 #ifdef __KERNEL__
24893 #include <linux/string.h>
24894 +#include <asm/pgtable_types.h>
24895 #else
24896 #include <string.h>
24897 +#define ktla_ktva(addr) addr
24898 #endif
24899 #include <asm/inat.h>
24900 #include <asm/insn.h>
24901 @@ -53,8 +55,8 @@
24902 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
24903 {
24904 memset(insn, 0, sizeof(*insn));
24905 - insn->kaddr = kaddr;
24906 - insn->next_byte = kaddr;
24907 + insn->kaddr = ktla_ktva(kaddr);
24908 + insn->next_byte = ktla_ktva(kaddr);
24909 insn->x86_64 = x86_64 ? 1 : 0;
24910 insn->opnd_bytes = 4;
24911 if (x86_64)
24912 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
24913 index 05a95e7..326f2fa 100644
24914 --- a/arch/x86/lib/iomap_copy_64.S
24915 +++ b/arch/x86/lib/iomap_copy_64.S
24916 @@ -17,6 +17,7 @@
24917
24918 #include <linux/linkage.h>
24919 #include <asm/dwarf2.h>
24920 +#include <asm/alternative-asm.h>
24921
24922 /*
24923 * override generic version in lib/iomap_copy.c
24924 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
24925 CFI_STARTPROC
24926 movl %edx,%ecx
24927 rep movsd
24928 + pax_force_retaddr
24929 ret
24930 CFI_ENDPROC
24931 ENDPROC(__iowrite32_copy)
24932 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
24933 index 1c273be..da9cc0e 100644
24934 --- a/arch/x86/lib/memcpy_64.S
24935 +++ b/arch/x86/lib/memcpy_64.S
24936 @@ -33,6 +33,7 @@
24937 rep movsq
24938 movl %edx, %ecx
24939 rep movsb
24940 + pax_force_retaddr
24941 ret
24942 .Lmemcpy_e:
24943 .previous
24944 @@ -49,6 +50,7 @@
24945 movq %rdi, %rax
24946 movq %rdx, %rcx
24947 rep movsb
24948 + pax_force_retaddr
24949 ret
24950 .Lmemcpy_e_e:
24951 .previous
24952 @@ -76,13 +78,13 @@ ENTRY(memcpy)
24953 */
24954 movq 0*8(%rsi), %r8
24955 movq 1*8(%rsi), %r9
24956 - movq 2*8(%rsi), %r10
24957 + movq 2*8(%rsi), %rcx
24958 movq 3*8(%rsi), %r11
24959 leaq 4*8(%rsi), %rsi
24960
24961 movq %r8, 0*8(%rdi)
24962 movq %r9, 1*8(%rdi)
24963 - movq %r10, 2*8(%rdi)
24964 + movq %rcx, 2*8(%rdi)
24965 movq %r11, 3*8(%rdi)
24966 leaq 4*8(%rdi), %rdi
24967 jae .Lcopy_forward_loop
24968 @@ -105,12 +107,12 @@ ENTRY(memcpy)
24969 subq $0x20, %rdx
24970 movq -1*8(%rsi), %r8
24971 movq -2*8(%rsi), %r9
24972 - movq -3*8(%rsi), %r10
24973 + movq -3*8(%rsi), %rcx
24974 movq -4*8(%rsi), %r11
24975 leaq -4*8(%rsi), %rsi
24976 movq %r8, -1*8(%rdi)
24977 movq %r9, -2*8(%rdi)
24978 - movq %r10, -3*8(%rdi)
24979 + movq %rcx, -3*8(%rdi)
24980 movq %r11, -4*8(%rdi)
24981 leaq -4*8(%rdi), %rdi
24982 jae .Lcopy_backward_loop
24983 @@ -130,12 +132,13 @@ ENTRY(memcpy)
24984 */
24985 movq 0*8(%rsi), %r8
24986 movq 1*8(%rsi), %r9
24987 - movq -2*8(%rsi, %rdx), %r10
24988 + movq -2*8(%rsi, %rdx), %rcx
24989 movq -1*8(%rsi, %rdx), %r11
24990 movq %r8, 0*8(%rdi)
24991 movq %r9, 1*8(%rdi)
24992 - movq %r10, -2*8(%rdi, %rdx)
24993 + movq %rcx, -2*8(%rdi, %rdx)
24994 movq %r11, -1*8(%rdi, %rdx)
24995 + pax_force_retaddr
24996 retq
24997 .p2align 4
24998 .Lless_16bytes:
24999 @@ -148,6 +151,7 @@ ENTRY(memcpy)
25000 movq -1*8(%rsi, %rdx), %r9
25001 movq %r8, 0*8(%rdi)
25002 movq %r9, -1*8(%rdi, %rdx)
25003 + pax_force_retaddr
25004 retq
25005 .p2align 4
25006 .Lless_8bytes:
25007 @@ -161,6 +165,7 @@ ENTRY(memcpy)
25008 movl -4(%rsi, %rdx), %r8d
25009 movl %ecx, (%rdi)
25010 movl %r8d, -4(%rdi, %rdx)
25011 + pax_force_retaddr
25012 retq
25013 .p2align 4
25014 .Lless_3bytes:
25015 @@ -179,6 +184,7 @@ ENTRY(memcpy)
25016 movb %cl, (%rdi)
25017
25018 .Lend:
25019 + pax_force_retaddr
25020 retq
25021 CFI_ENDPROC
25022 ENDPROC(memcpy)
25023 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25024 index ee16461..c39c199 100644
25025 --- a/arch/x86/lib/memmove_64.S
25026 +++ b/arch/x86/lib/memmove_64.S
25027 @@ -61,13 +61,13 @@ ENTRY(memmove)
25028 5:
25029 sub $0x20, %rdx
25030 movq 0*8(%rsi), %r11
25031 - movq 1*8(%rsi), %r10
25032 + movq 1*8(%rsi), %rcx
25033 movq 2*8(%rsi), %r9
25034 movq 3*8(%rsi), %r8
25035 leaq 4*8(%rsi), %rsi
25036
25037 movq %r11, 0*8(%rdi)
25038 - movq %r10, 1*8(%rdi)
25039 + movq %rcx, 1*8(%rdi)
25040 movq %r9, 2*8(%rdi)
25041 movq %r8, 3*8(%rdi)
25042 leaq 4*8(%rdi), %rdi
25043 @@ -81,10 +81,10 @@ ENTRY(memmove)
25044 4:
25045 movq %rdx, %rcx
25046 movq -8(%rsi, %rdx), %r11
25047 - lea -8(%rdi, %rdx), %r10
25048 + lea -8(%rdi, %rdx), %r9
25049 shrq $3, %rcx
25050 rep movsq
25051 - movq %r11, (%r10)
25052 + movq %r11, (%r9)
25053 jmp 13f
25054 .Lmemmove_end_forward:
25055
25056 @@ -95,14 +95,14 @@ ENTRY(memmove)
25057 7:
25058 movq %rdx, %rcx
25059 movq (%rsi), %r11
25060 - movq %rdi, %r10
25061 + movq %rdi, %r9
25062 leaq -8(%rsi, %rdx), %rsi
25063 leaq -8(%rdi, %rdx), %rdi
25064 shrq $3, %rcx
25065 std
25066 rep movsq
25067 cld
25068 - movq %r11, (%r10)
25069 + movq %r11, (%r9)
25070 jmp 13f
25071
25072 /*
25073 @@ -127,13 +127,13 @@ ENTRY(memmove)
25074 8:
25075 subq $0x20, %rdx
25076 movq -1*8(%rsi), %r11
25077 - movq -2*8(%rsi), %r10
25078 + movq -2*8(%rsi), %rcx
25079 movq -3*8(%rsi), %r9
25080 movq -4*8(%rsi), %r8
25081 leaq -4*8(%rsi), %rsi
25082
25083 movq %r11, -1*8(%rdi)
25084 - movq %r10, -2*8(%rdi)
25085 + movq %rcx, -2*8(%rdi)
25086 movq %r9, -3*8(%rdi)
25087 movq %r8, -4*8(%rdi)
25088 leaq -4*8(%rdi), %rdi
25089 @@ -151,11 +151,11 @@ ENTRY(memmove)
25090 * Move data from 16 bytes to 31 bytes.
25091 */
25092 movq 0*8(%rsi), %r11
25093 - movq 1*8(%rsi), %r10
25094 + movq 1*8(%rsi), %rcx
25095 movq -2*8(%rsi, %rdx), %r9
25096 movq -1*8(%rsi, %rdx), %r8
25097 movq %r11, 0*8(%rdi)
25098 - movq %r10, 1*8(%rdi)
25099 + movq %rcx, 1*8(%rdi)
25100 movq %r9, -2*8(%rdi, %rdx)
25101 movq %r8, -1*8(%rdi, %rdx)
25102 jmp 13f
25103 @@ -167,9 +167,9 @@ ENTRY(memmove)
25104 * Move data from 8 bytes to 15 bytes.
25105 */
25106 movq 0*8(%rsi), %r11
25107 - movq -1*8(%rsi, %rdx), %r10
25108 + movq -1*8(%rsi, %rdx), %r9
25109 movq %r11, 0*8(%rdi)
25110 - movq %r10, -1*8(%rdi, %rdx)
25111 + movq %r9, -1*8(%rdi, %rdx)
25112 jmp 13f
25113 10:
25114 cmpq $4, %rdx
25115 @@ -178,9 +178,9 @@ ENTRY(memmove)
25116 * Move data from 4 bytes to 7 bytes.
25117 */
25118 movl (%rsi), %r11d
25119 - movl -4(%rsi, %rdx), %r10d
25120 + movl -4(%rsi, %rdx), %r9d
25121 movl %r11d, (%rdi)
25122 - movl %r10d, -4(%rdi, %rdx)
25123 + movl %r9d, -4(%rdi, %rdx)
25124 jmp 13f
25125 11:
25126 cmp $2, %rdx
25127 @@ -189,9 +189,9 @@ ENTRY(memmove)
25128 * Move data from 2 bytes to 3 bytes.
25129 */
25130 movw (%rsi), %r11w
25131 - movw -2(%rsi, %rdx), %r10w
25132 + movw -2(%rsi, %rdx), %r9w
25133 movw %r11w, (%rdi)
25134 - movw %r10w, -2(%rdi, %rdx)
25135 + movw %r9w, -2(%rdi, %rdx)
25136 jmp 13f
25137 12:
25138 cmp $1, %rdx
25139 @@ -202,6 +202,7 @@ ENTRY(memmove)
25140 movb (%rsi), %r11b
25141 movb %r11b, (%rdi)
25142 13:
25143 + pax_force_retaddr
25144 retq
25145 CFI_ENDPROC
25146
25147 @@ -210,6 +211,7 @@ ENTRY(memmove)
25148 /* Forward moving data. */
25149 movq %rdx, %rcx
25150 rep movsb
25151 + pax_force_retaddr
25152 retq
25153 .Lmemmove_end_forward_efs:
25154 .previous
25155 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25156 index 2dcb380..963660a 100644
25157 --- a/arch/x86/lib/memset_64.S
25158 +++ b/arch/x86/lib/memset_64.S
25159 @@ -30,6 +30,7 @@
25160 movl %edx,%ecx
25161 rep stosb
25162 movq %r9,%rax
25163 + pax_force_retaddr
25164 ret
25165 .Lmemset_e:
25166 .previous
25167 @@ -52,6 +53,7 @@
25168 movq %rdx,%rcx
25169 rep stosb
25170 movq %r9,%rax
25171 + pax_force_retaddr
25172 ret
25173 .Lmemset_e_e:
25174 .previous
25175 @@ -59,7 +61,7 @@
25176 ENTRY(memset)
25177 ENTRY(__memset)
25178 CFI_STARTPROC
25179 - movq %rdi,%r10
25180 + movq %rdi,%r11
25181
25182 /* expand byte value */
25183 movzbl %sil,%ecx
25184 @@ -117,7 +119,8 @@ ENTRY(__memset)
25185 jnz .Lloop_1
25186
25187 .Lende:
25188 - movq %r10,%rax
25189 + movq %r11,%rax
25190 + pax_force_retaddr
25191 ret
25192
25193 CFI_RESTORE_STATE
25194 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25195 index c9f2d9b..e7fd2c0 100644
25196 --- a/arch/x86/lib/mmx_32.c
25197 +++ b/arch/x86/lib/mmx_32.c
25198 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25199 {
25200 void *p;
25201 int i;
25202 + unsigned long cr0;
25203
25204 if (unlikely(in_interrupt()))
25205 return __memcpy(to, from, len);
25206 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25207 kernel_fpu_begin();
25208
25209 __asm__ __volatile__ (
25210 - "1: prefetch (%0)\n" /* This set is 28 bytes */
25211 - " prefetch 64(%0)\n"
25212 - " prefetch 128(%0)\n"
25213 - " prefetch 192(%0)\n"
25214 - " prefetch 256(%0)\n"
25215 + "1: prefetch (%1)\n" /* This set is 28 bytes */
25216 + " prefetch 64(%1)\n"
25217 + " prefetch 128(%1)\n"
25218 + " prefetch 192(%1)\n"
25219 + " prefetch 256(%1)\n"
25220 "2: \n"
25221 ".section .fixup, \"ax\"\n"
25222 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25223 + "3: \n"
25224 +
25225 +#ifdef CONFIG_PAX_KERNEXEC
25226 + " movl %%cr0, %0\n"
25227 + " movl %0, %%eax\n"
25228 + " andl $0xFFFEFFFF, %%eax\n"
25229 + " movl %%eax, %%cr0\n"
25230 +#endif
25231 +
25232 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25233 +
25234 +#ifdef CONFIG_PAX_KERNEXEC
25235 + " movl %0, %%cr0\n"
25236 +#endif
25237 +
25238 " jmp 2b\n"
25239 ".previous\n"
25240 _ASM_EXTABLE(1b, 3b)
25241 - : : "r" (from));
25242 + : "=&r" (cr0) : "r" (from) : "ax");
25243
25244 for ( ; i > 5; i--) {
25245 __asm__ __volatile__ (
25246 - "1: prefetch 320(%0)\n"
25247 - "2: movq (%0), %%mm0\n"
25248 - " movq 8(%0), %%mm1\n"
25249 - " movq 16(%0), %%mm2\n"
25250 - " movq 24(%0), %%mm3\n"
25251 - " movq %%mm0, (%1)\n"
25252 - " movq %%mm1, 8(%1)\n"
25253 - " movq %%mm2, 16(%1)\n"
25254 - " movq %%mm3, 24(%1)\n"
25255 - " movq 32(%0), %%mm0\n"
25256 - " movq 40(%0), %%mm1\n"
25257 - " movq 48(%0), %%mm2\n"
25258 - " movq 56(%0), %%mm3\n"
25259 - " movq %%mm0, 32(%1)\n"
25260 - " movq %%mm1, 40(%1)\n"
25261 - " movq %%mm2, 48(%1)\n"
25262 - " movq %%mm3, 56(%1)\n"
25263 + "1: prefetch 320(%1)\n"
25264 + "2: movq (%1), %%mm0\n"
25265 + " movq 8(%1), %%mm1\n"
25266 + " movq 16(%1), %%mm2\n"
25267 + " movq 24(%1), %%mm3\n"
25268 + " movq %%mm0, (%2)\n"
25269 + " movq %%mm1, 8(%2)\n"
25270 + " movq %%mm2, 16(%2)\n"
25271 + " movq %%mm3, 24(%2)\n"
25272 + " movq 32(%1), %%mm0\n"
25273 + " movq 40(%1), %%mm1\n"
25274 + " movq 48(%1), %%mm2\n"
25275 + " movq 56(%1), %%mm3\n"
25276 + " movq %%mm0, 32(%2)\n"
25277 + " movq %%mm1, 40(%2)\n"
25278 + " movq %%mm2, 48(%2)\n"
25279 + " movq %%mm3, 56(%2)\n"
25280 ".section .fixup, \"ax\"\n"
25281 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25282 + "3:\n"
25283 +
25284 +#ifdef CONFIG_PAX_KERNEXEC
25285 + " movl %%cr0, %0\n"
25286 + " movl %0, %%eax\n"
25287 + " andl $0xFFFEFFFF, %%eax\n"
25288 + " movl %%eax, %%cr0\n"
25289 +#endif
25290 +
25291 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25292 +
25293 +#ifdef CONFIG_PAX_KERNEXEC
25294 + " movl %0, %%cr0\n"
25295 +#endif
25296 +
25297 " jmp 2b\n"
25298 ".previous\n"
25299 _ASM_EXTABLE(1b, 3b)
25300 - : : "r" (from), "r" (to) : "memory");
25301 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25302
25303 from += 64;
25304 to += 64;
25305 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25306 static void fast_copy_page(void *to, void *from)
25307 {
25308 int i;
25309 + unsigned long cr0;
25310
25311 kernel_fpu_begin();
25312
25313 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25314 * but that is for later. -AV
25315 */
25316 __asm__ __volatile__(
25317 - "1: prefetch (%0)\n"
25318 - " prefetch 64(%0)\n"
25319 - " prefetch 128(%0)\n"
25320 - " prefetch 192(%0)\n"
25321 - " prefetch 256(%0)\n"
25322 + "1: prefetch (%1)\n"
25323 + " prefetch 64(%1)\n"
25324 + " prefetch 128(%1)\n"
25325 + " prefetch 192(%1)\n"
25326 + " prefetch 256(%1)\n"
25327 "2: \n"
25328 ".section .fixup, \"ax\"\n"
25329 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25330 + "3: \n"
25331 +
25332 +#ifdef CONFIG_PAX_KERNEXEC
25333 + " movl %%cr0, %0\n"
25334 + " movl %0, %%eax\n"
25335 + " andl $0xFFFEFFFF, %%eax\n"
25336 + " movl %%eax, %%cr0\n"
25337 +#endif
25338 +
25339 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25340 +
25341 +#ifdef CONFIG_PAX_KERNEXEC
25342 + " movl %0, %%cr0\n"
25343 +#endif
25344 +
25345 " jmp 2b\n"
25346 ".previous\n"
25347 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
25348 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25349
25350 for (i = 0; i < (4096-320)/64; i++) {
25351 __asm__ __volatile__ (
25352 - "1: prefetch 320(%0)\n"
25353 - "2: movq (%0), %%mm0\n"
25354 - " movntq %%mm0, (%1)\n"
25355 - " movq 8(%0), %%mm1\n"
25356 - " movntq %%mm1, 8(%1)\n"
25357 - " movq 16(%0), %%mm2\n"
25358 - " movntq %%mm2, 16(%1)\n"
25359 - " movq 24(%0), %%mm3\n"
25360 - " movntq %%mm3, 24(%1)\n"
25361 - " movq 32(%0), %%mm4\n"
25362 - " movntq %%mm4, 32(%1)\n"
25363 - " movq 40(%0), %%mm5\n"
25364 - " movntq %%mm5, 40(%1)\n"
25365 - " movq 48(%0), %%mm6\n"
25366 - " movntq %%mm6, 48(%1)\n"
25367 - " movq 56(%0), %%mm7\n"
25368 - " movntq %%mm7, 56(%1)\n"
25369 + "1: prefetch 320(%1)\n"
25370 + "2: movq (%1), %%mm0\n"
25371 + " movntq %%mm0, (%2)\n"
25372 + " movq 8(%1), %%mm1\n"
25373 + " movntq %%mm1, 8(%2)\n"
25374 + " movq 16(%1), %%mm2\n"
25375 + " movntq %%mm2, 16(%2)\n"
25376 + " movq 24(%1), %%mm3\n"
25377 + " movntq %%mm3, 24(%2)\n"
25378 + " movq 32(%1), %%mm4\n"
25379 + " movntq %%mm4, 32(%2)\n"
25380 + " movq 40(%1), %%mm5\n"
25381 + " movntq %%mm5, 40(%2)\n"
25382 + " movq 48(%1), %%mm6\n"
25383 + " movntq %%mm6, 48(%2)\n"
25384 + " movq 56(%1), %%mm7\n"
25385 + " movntq %%mm7, 56(%2)\n"
25386 ".section .fixup, \"ax\"\n"
25387 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25388 + "3:\n"
25389 +
25390 +#ifdef CONFIG_PAX_KERNEXEC
25391 + " movl %%cr0, %0\n"
25392 + " movl %0, %%eax\n"
25393 + " andl $0xFFFEFFFF, %%eax\n"
25394 + " movl %%eax, %%cr0\n"
25395 +#endif
25396 +
25397 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25398 +
25399 +#ifdef CONFIG_PAX_KERNEXEC
25400 + " movl %0, %%cr0\n"
25401 +#endif
25402 +
25403 " jmp 2b\n"
25404 ".previous\n"
25405 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
25406 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25407
25408 from += 64;
25409 to += 64;
25410 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
25411 static void fast_copy_page(void *to, void *from)
25412 {
25413 int i;
25414 + unsigned long cr0;
25415
25416 kernel_fpu_begin();
25417
25418 __asm__ __volatile__ (
25419 - "1: prefetch (%0)\n"
25420 - " prefetch 64(%0)\n"
25421 - " prefetch 128(%0)\n"
25422 - " prefetch 192(%0)\n"
25423 - " prefetch 256(%0)\n"
25424 + "1: prefetch (%1)\n"
25425 + " prefetch 64(%1)\n"
25426 + " prefetch 128(%1)\n"
25427 + " prefetch 192(%1)\n"
25428 + " prefetch 256(%1)\n"
25429 "2: \n"
25430 ".section .fixup, \"ax\"\n"
25431 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25432 + "3: \n"
25433 +
25434 +#ifdef CONFIG_PAX_KERNEXEC
25435 + " movl %%cr0, %0\n"
25436 + " movl %0, %%eax\n"
25437 + " andl $0xFFFEFFFF, %%eax\n"
25438 + " movl %%eax, %%cr0\n"
25439 +#endif
25440 +
25441 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25442 +
25443 +#ifdef CONFIG_PAX_KERNEXEC
25444 + " movl %0, %%cr0\n"
25445 +#endif
25446 +
25447 " jmp 2b\n"
25448 ".previous\n"
25449 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
25450 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25451
25452 for (i = 0; i < 4096/64; i++) {
25453 __asm__ __volatile__ (
25454 - "1: prefetch 320(%0)\n"
25455 - "2: movq (%0), %%mm0\n"
25456 - " movq 8(%0), %%mm1\n"
25457 - " movq 16(%0), %%mm2\n"
25458 - " movq 24(%0), %%mm3\n"
25459 - " movq %%mm0, (%1)\n"
25460 - " movq %%mm1, 8(%1)\n"
25461 - " movq %%mm2, 16(%1)\n"
25462 - " movq %%mm3, 24(%1)\n"
25463 - " movq 32(%0), %%mm0\n"
25464 - " movq 40(%0), %%mm1\n"
25465 - " movq 48(%0), %%mm2\n"
25466 - " movq 56(%0), %%mm3\n"
25467 - " movq %%mm0, 32(%1)\n"
25468 - " movq %%mm1, 40(%1)\n"
25469 - " movq %%mm2, 48(%1)\n"
25470 - " movq %%mm3, 56(%1)\n"
25471 + "1: prefetch 320(%1)\n"
25472 + "2: movq (%1), %%mm0\n"
25473 + " movq 8(%1), %%mm1\n"
25474 + " movq 16(%1), %%mm2\n"
25475 + " movq 24(%1), %%mm3\n"
25476 + " movq %%mm0, (%2)\n"
25477 + " movq %%mm1, 8(%2)\n"
25478 + " movq %%mm2, 16(%2)\n"
25479 + " movq %%mm3, 24(%2)\n"
25480 + " movq 32(%1), %%mm0\n"
25481 + " movq 40(%1), %%mm1\n"
25482 + " movq 48(%1), %%mm2\n"
25483 + " movq 56(%1), %%mm3\n"
25484 + " movq %%mm0, 32(%2)\n"
25485 + " movq %%mm1, 40(%2)\n"
25486 + " movq %%mm2, 48(%2)\n"
25487 + " movq %%mm3, 56(%2)\n"
25488 ".section .fixup, \"ax\"\n"
25489 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25490 + "3:\n"
25491 +
25492 +#ifdef CONFIG_PAX_KERNEXEC
25493 + " movl %%cr0, %0\n"
25494 + " movl %0, %%eax\n"
25495 + " andl $0xFFFEFFFF, %%eax\n"
25496 + " movl %%eax, %%cr0\n"
25497 +#endif
25498 +
25499 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25500 +
25501 +#ifdef CONFIG_PAX_KERNEXEC
25502 + " movl %0, %%cr0\n"
25503 +#endif
25504 +
25505 " jmp 2b\n"
25506 ".previous\n"
25507 _ASM_EXTABLE(1b, 3b)
25508 - : : "r" (from), "r" (to) : "memory");
25509 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25510
25511 from += 64;
25512 to += 64;
25513 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
25514 index f6d13ee..aca5f0b 100644
25515 --- a/arch/x86/lib/msr-reg.S
25516 +++ b/arch/x86/lib/msr-reg.S
25517 @@ -3,6 +3,7 @@
25518 #include <asm/dwarf2.h>
25519 #include <asm/asm.h>
25520 #include <asm/msr.h>
25521 +#include <asm/alternative-asm.h>
25522
25523 #ifdef CONFIG_X86_64
25524 /*
25525 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
25526 CFI_STARTPROC
25527 pushq_cfi %rbx
25528 pushq_cfi %rbp
25529 - movq %rdi, %r10 /* Save pointer */
25530 + movq %rdi, %r9 /* Save pointer */
25531 xorl %r11d, %r11d /* Return value */
25532 movl (%rdi), %eax
25533 movl 4(%rdi), %ecx
25534 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
25535 movl 28(%rdi), %edi
25536 CFI_REMEMBER_STATE
25537 1: \op
25538 -2: movl %eax, (%r10)
25539 +2: movl %eax, (%r9)
25540 movl %r11d, %eax /* Return value */
25541 - movl %ecx, 4(%r10)
25542 - movl %edx, 8(%r10)
25543 - movl %ebx, 12(%r10)
25544 - movl %ebp, 20(%r10)
25545 - movl %esi, 24(%r10)
25546 - movl %edi, 28(%r10)
25547 + movl %ecx, 4(%r9)
25548 + movl %edx, 8(%r9)
25549 + movl %ebx, 12(%r9)
25550 + movl %ebp, 20(%r9)
25551 + movl %esi, 24(%r9)
25552 + movl %edi, 28(%r9)
25553 popq_cfi %rbp
25554 popq_cfi %rbx
25555 + pax_force_retaddr
25556 ret
25557 3:
25558 CFI_RESTORE_STATE
25559 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
25560 index fc6ba17..04471c5 100644
25561 --- a/arch/x86/lib/putuser.S
25562 +++ b/arch/x86/lib/putuser.S
25563 @@ -16,7 +16,9 @@
25564 #include <asm/errno.h>
25565 #include <asm/asm.h>
25566 #include <asm/smap.h>
25567 -
25568 +#include <asm/segment.h>
25569 +#include <asm/pgtable.h>
25570 +#include <asm/alternative-asm.h>
25571
25572 /*
25573 * __put_user_X
25574 @@ -30,57 +32,125 @@
25575 * as they get called from within inline assembly.
25576 */
25577
25578 -#define ENTER CFI_STARTPROC ; \
25579 - GET_THREAD_INFO(%_ASM_BX)
25580 -#define EXIT ASM_CLAC ; \
25581 - ret ; \
25582 +#define ENTER CFI_STARTPROC
25583 +#define EXIT ASM_CLAC ; \
25584 + pax_force_retaddr ; \
25585 + ret ; \
25586 CFI_ENDPROC
25587
25588 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25589 +#define _DEST %_ASM_CX,%_ASM_BX
25590 +#else
25591 +#define _DEST %_ASM_CX
25592 +#endif
25593 +
25594 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25595 +#define __copyuser_seg gs;
25596 +#else
25597 +#define __copyuser_seg
25598 +#endif
25599 +
25600 .text
25601 ENTRY(__put_user_1)
25602 ENTER
25603 +
25604 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25605 + GET_THREAD_INFO(%_ASM_BX)
25606 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
25607 jae bad_put_user
25608 ASM_STAC
25609 -1: movb %al,(%_ASM_CX)
25610 +
25611 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25612 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25613 + cmp %_ASM_BX,%_ASM_CX
25614 + jb 1234f
25615 + xor %ebx,%ebx
25616 +1234:
25617 +#endif
25618 +
25619 +#endif
25620 +
25621 +1: __copyuser_seg movb %al,(_DEST)
25622 xor %eax,%eax
25623 EXIT
25624 ENDPROC(__put_user_1)
25625
25626 ENTRY(__put_user_2)
25627 ENTER
25628 +
25629 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25630 + GET_THREAD_INFO(%_ASM_BX)
25631 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25632 sub $1,%_ASM_BX
25633 cmp %_ASM_BX,%_ASM_CX
25634 jae bad_put_user
25635 ASM_STAC
25636 -2: movw %ax,(%_ASM_CX)
25637 +
25638 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25639 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25640 + cmp %_ASM_BX,%_ASM_CX
25641 + jb 1234f
25642 + xor %ebx,%ebx
25643 +1234:
25644 +#endif
25645 +
25646 +#endif
25647 +
25648 +2: __copyuser_seg movw %ax,(_DEST)
25649 xor %eax,%eax
25650 EXIT
25651 ENDPROC(__put_user_2)
25652
25653 ENTRY(__put_user_4)
25654 ENTER
25655 +
25656 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25657 + GET_THREAD_INFO(%_ASM_BX)
25658 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25659 sub $3,%_ASM_BX
25660 cmp %_ASM_BX,%_ASM_CX
25661 jae bad_put_user
25662 ASM_STAC
25663 -3: movl %eax,(%_ASM_CX)
25664 +
25665 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25666 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25667 + cmp %_ASM_BX,%_ASM_CX
25668 + jb 1234f
25669 + xor %ebx,%ebx
25670 +1234:
25671 +#endif
25672 +
25673 +#endif
25674 +
25675 +3: __copyuser_seg movl %eax,(_DEST)
25676 xor %eax,%eax
25677 EXIT
25678 ENDPROC(__put_user_4)
25679
25680 ENTRY(__put_user_8)
25681 ENTER
25682 +
25683 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25684 + GET_THREAD_INFO(%_ASM_BX)
25685 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25686 sub $7,%_ASM_BX
25687 cmp %_ASM_BX,%_ASM_CX
25688 jae bad_put_user
25689 ASM_STAC
25690 -4: mov %_ASM_AX,(%_ASM_CX)
25691 +
25692 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25693 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25694 + cmp %_ASM_BX,%_ASM_CX
25695 + jb 1234f
25696 + xor %ebx,%ebx
25697 +1234:
25698 +#endif
25699 +
25700 +#endif
25701 +
25702 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
25703 #ifdef CONFIG_X86_32
25704 -5: movl %edx,4(%_ASM_CX)
25705 +5: __copyuser_seg movl %edx,4(_DEST)
25706 #endif
25707 xor %eax,%eax
25708 EXIT
25709 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
25710 index 1cad221..de671ee 100644
25711 --- a/arch/x86/lib/rwlock.S
25712 +++ b/arch/x86/lib/rwlock.S
25713 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
25714 FRAME
25715 0: LOCK_PREFIX
25716 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25717 +
25718 +#ifdef CONFIG_PAX_REFCOUNT
25719 + jno 1234f
25720 + LOCK_PREFIX
25721 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25722 + int $4
25723 +1234:
25724 + _ASM_EXTABLE(1234b, 1234b)
25725 +#endif
25726 +
25727 1: rep; nop
25728 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
25729 jne 1b
25730 LOCK_PREFIX
25731 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25732 +
25733 +#ifdef CONFIG_PAX_REFCOUNT
25734 + jno 1234f
25735 + LOCK_PREFIX
25736 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25737 + int $4
25738 +1234:
25739 + _ASM_EXTABLE(1234b, 1234b)
25740 +#endif
25741 +
25742 jnz 0b
25743 ENDFRAME
25744 + pax_force_retaddr
25745 ret
25746 CFI_ENDPROC
25747 END(__write_lock_failed)
25748 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
25749 FRAME
25750 0: LOCK_PREFIX
25751 READ_LOCK_SIZE(inc) (%__lock_ptr)
25752 +
25753 +#ifdef CONFIG_PAX_REFCOUNT
25754 + jno 1234f
25755 + LOCK_PREFIX
25756 + READ_LOCK_SIZE(dec) (%__lock_ptr)
25757 + int $4
25758 +1234:
25759 + _ASM_EXTABLE(1234b, 1234b)
25760 +#endif
25761 +
25762 1: rep; nop
25763 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
25764 js 1b
25765 LOCK_PREFIX
25766 READ_LOCK_SIZE(dec) (%__lock_ptr)
25767 +
25768 +#ifdef CONFIG_PAX_REFCOUNT
25769 + jno 1234f
25770 + LOCK_PREFIX
25771 + READ_LOCK_SIZE(inc) (%__lock_ptr)
25772 + int $4
25773 +1234:
25774 + _ASM_EXTABLE(1234b, 1234b)
25775 +#endif
25776 +
25777 js 0b
25778 ENDFRAME
25779 + pax_force_retaddr
25780 ret
25781 CFI_ENDPROC
25782 END(__read_lock_failed)
25783 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
25784 index 5dff5f0..cadebf4 100644
25785 --- a/arch/x86/lib/rwsem.S
25786 +++ b/arch/x86/lib/rwsem.S
25787 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
25788 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25789 CFI_RESTORE __ASM_REG(dx)
25790 restore_common_regs
25791 + pax_force_retaddr
25792 ret
25793 CFI_ENDPROC
25794 ENDPROC(call_rwsem_down_read_failed)
25795 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
25796 movq %rax,%rdi
25797 call rwsem_down_write_failed
25798 restore_common_regs
25799 + pax_force_retaddr
25800 ret
25801 CFI_ENDPROC
25802 ENDPROC(call_rwsem_down_write_failed)
25803 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
25804 movq %rax,%rdi
25805 call rwsem_wake
25806 restore_common_regs
25807 -1: ret
25808 +1: pax_force_retaddr
25809 + ret
25810 CFI_ENDPROC
25811 ENDPROC(call_rwsem_wake)
25812
25813 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
25814 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25815 CFI_RESTORE __ASM_REG(dx)
25816 restore_common_regs
25817 + pax_force_retaddr
25818 ret
25819 CFI_ENDPROC
25820 ENDPROC(call_rwsem_downgrade_wake)
25821 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
25822 index a63efd6..ccecad8 100644
25823 --- a/arch/x86/lib/thunk_64.S
25824 +++ b/arch/x86/lib/thunk_64.S
25825 @@ -8,6 +8,7 @@
25826 #include <linux/linkage.h>
25827 #include <asm/dwarf2.h>
25828 #include <asm/calling.h>
25829 +#include <asm/alternative-asm.h>
25830
25831 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
25832 .macro THUNK name, func, put_ret_addr_in_rdi=0
25833 @@ -41,5 +42,6 @@
25834 SAVE_ARGS
25835 restore:
25836 RESTORE_ARGS
25837 + pax_force_retaddr
25838 ret
25839 CFI_ENDPROC
25840 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
25841 index f0312d7..9c39d63 100644
25842 --- a/arch/x86/lib/usercopy_32.c
25843 +++ b/arch/x86/lib/usercopy_32.c
25844 @@ -42,11 +42,13 @@ do { \
25845 int __d0; \
25846 might_fault(); \
25847 __asm__ __volatile__( \
25848 + __COPYUSER_SET_ES \
25849 ASM_STAC "\n" \
25850 "0: rep; stosl\n" \
25851 " movl %2,%0\n" \
25852 "1: rep; stosb\n" \
25853 "2: " ASM_CLAC "\n" \
25854 + __COPYUSER_RESTORE_ES \
25855 ".section .fixup,\"ax\"\n" \
25856 "3: lea 0(%2,%0,4),%0\n" \
25857 " jmp 2b\n" \
25858 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
25859
25860 #ifdef CONFIG_X86_INTEL_USERCOPY
25861 static unsigned long
25862 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
25863 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
25864 {
25865 int d0, d1;
25866 __asm__ __volatile__(
25867 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25868 " .align 2,0x90\n"
25869 "3: movl 0(%4), %%eax\n"
25870 "4: movl 4(%4), %%edx\n"
25871 - "5: movl %%eax, 0(%3)\n"
25872 - "6: movl %%edx, 4(%3)\n"
25873 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
25874 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
25875 "7: movl 8(%4), %%eax\n"
25876 "8: movl 12(%4),%%edx\n"
25877 - "9: movl %%eax, 8(%3)\n"
25878 - "10: movl %%edx, 12(%3)\n"
25879 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
25880 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
25881 "11: movl 16(%4), %%eax\n"
25882 "12: movl 20(%4), %%edx\n"
25883 - "13: movl %%eax, 16(%3)\n"
25884 - "14: movl %%edx, 20(%3)\n"
25885 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
25886 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
25887 "15: movl 24(%4), %%eax\n"
25888 "16: movl 28(%4), %%edx\n"
25889 - "17: movl %%eax, 24(%3)\n"
25890 - "18: movl %%edx, 28(%3)\n"
25891 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
25892 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
25893 "19: movl 32(%4), %%eax\n"
25894 "20: movl 36(%4), %%edx\n"
25895 - "21: movl %%eax, 32(%3)\n"
25896 - "22: movl %%edx, 36(%3)\n"
25897 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
25898 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
25899 "23: movl 40(%4), %%eax\n"
25900 "24: movl 44(%4), %%edx\n"
25901 - "25: movl %%eax, 40(%3)\n"
25902 - "26: movl %%edx, 44(%3)\n"
25903 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
25904 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
25905 "27: movl 48(%4), %%eax\n"
25906 "28: movl 52(%4), %%edx\n"
25907 - "29: movl %%eax, 48(%3)\n"
25908 - "30: movl %%edx, 52(%3)\n"
25909 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
25910 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
25911 "31: movl 56(%4), %%eax\n"
25912 "32: movl 60(%4), %%edx\n"
25913 - "33: movl %%eax, 56(%3)\n"
25914 - "34: movl %%edx, 60(%3)\n"
25915 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
25916 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
25917 " addl $-64, %0\n"
25918 " addl $64, %4\n"
25919 " addl $64, %3\n"
25920 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25921 " shrl $2, %0\n"
25922 " andl $3, %%eax\n"
25923 " cld\n"
25924 + __COPYUSER_SET_ES
25925 "99: rep; movsl\n"
25926 "36: movl %%eax, %0\n"
25927 "37: rep; movsb\n"
25928 "100:\n"
25929 + __COPYUSER_RESTORE_ES
25930 ".section .fixup,\"ax\"\n"
25931 "101: lea 0(%%eax,%0,4),%0\n"
25932 " jmp 100b\n"
25933 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25934 }
25935
25936 static unsigned long
25937 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
25938 +{
25939 + int d0, d1;
25940 + __asm__ __volatile__(
25941 + " .align 2,0x90\n"
25942 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
25943 + " cmpl $67, %0\n"
25944 + " jbe 3f\n"
25945 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
25946 + " .align 2,0x90\n"
25947 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
25948 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
25949 + "5: movl %%eax, 0(%3)\n"
25950 + "6: movl %%edx, 4(%3)\n"
25951 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
25952 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
25953 + "9: movl %%eax, 8(%3)\n"
25954 + "10: movl %%edx, 12(%3)\n"
25955 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
25956 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
25957 + "13: movl %%eax, 16(%3)\n"
25958 + "14: movl %%edx, 20(%3)\n"
25959 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
25960 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
25961 + "17: movl %%eax, 24(%3)\n"
25962 + "18: movl %%edx, 28(%3)\n"
25963 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
25964 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
25965 + "21: movl %%eax, 32(%3)\n"
25966 + "22: movl %%edx, 36(%3)\n"
25967 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
25968 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
25969 + "25: movl %%eax, 40(%3)\n"
25970 + "26: movl %%edx, 44(%3)\n"
25971 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
25972 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
25973 + "29: movl %%eax, 48(%3)\n"
25974 + "30: movl %%edx, 52(%3)\n"
25975 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
25976 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
25977 + "33: movl %%eax, 56(%3)\n"
25978 + "34: movl %%edx, 60(%3)\n"
25979 + " addl $-64, %0\n"
25980 + " addl $64, %4\n"
25981 + " addl $64, %3\n"
25982 + " cmpl $63, %0\n"
25983 + " ja 1b\n"
25984 + "35: movl %0, %%eax\n"
25985 + " shrl $2, %0\n"
25986 + " andl $3, %%eax\n"
25987 + " cld\n"
25988 + "99: rep; "__copyuser_seg" movsl\n"
25989 + "36: movl %%eax, %0\n"
25990 + "37: rep; "__copyuser_seg" movsb\n"
25991 + "100:\n"
25992 + ".section .fixup,\"ax\"\n"
25993 + "101: lea 0(%%eax,%0,4),%0\n"
25994 + " jmp 100b\n"
25995 + ".previous\n"
25996 + _ASM_EXTABLE(1b,100b)
25997 + _ASM_EXTABLE(2b,100b)
25998 + _ASM_EXTABLE(3b,100b)
25999 + _ASM_EXTABLE(4b,100b)
26000 + _ASM_EXTABLE(5b,100b)
26001 + _ASM_EXTABLE(6b,100b)
26002 + _ASM_EXTABLE(7b,100b)
26003 + _ASM_EXTABLE(8b,100b)
26004 + _ASM_EXTABLE(9b,100b)
26005 + _ASM_EXTABLE(10b,100b)
26006 + _ASM_EXTABLE(11b,100b)
26007 + _ASM_EXTABLE(12b,100b)
26008 + _ASM_EXTABLE(13b,100b)
26009 + _ASM_EXTABLE(14b,100b)
26010 + _ASM_EXTABLE(15b,100b)
26011 + _ASM_EXTABLE(16b,100b)
26012 + _ASM_EXTABLE(17b,100b)
26013 + _ASM_EXTABLE(18b,100b)
26014 + _ASM_EXTABLE(19b,100b)
26015 + _ASM_EXTABLE(20b,100b)
26016 + _ASM_EXTABLE(21b,100b)
26017 + _ASM_EXTABLE(22b,100b)
26018 + _ASM_EXTABLE(23b,100b)
26019 + _ASM_EXTABLE(24b,100b)
26020 + _ASM_EXTABLE(25b,100b)
26021 + _ASM_EXTABLE(26b,100b)
26022 + _ASM_EXTABLE(27b,100b)
26023 + _ASM_EXTABLE(28b,100b)
26024 + _ASM_EXTABLE(29b,100b)
26025 + _ASM_EXTABLE(30b,100b)
26026 + _ASM_EXTABLE(31b,100b)
26027 + _ASM_EXTABLE(32b,100b)
26028 + _ASM_EXTABLE(33b,100b)
26029 + _ASM_EXTABLE(34b,100b)
26030 + _ASM_EXTABLE(35b,100b)
26031 + _ASM_EXTABLE(36b,100b)
26032 + _ASM_EXTABLE(37b,100b)
26033 + _ASM_EXTABLE(99b,101b)
26034 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
26035 + : "1"(to), "2"(from), "0"(size)
26036 + : "eax", "edx", "memory");
26037 + return size;
26038 +}
26039 +
26040 +static unsigned long __size_overflow(3)
26041 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26042 {
26043 int d0, d1;
26044 __asm__ __volatile__(
26045 " .align 2,0x90\n"
26046 - "0: movl 32(%4), %%eax\n"
26047 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26048 " cmpl $67, %0\n"
26049 " jbe 2f\n"
26050 - "1: movl 64(%4), %%eax\n"
26051 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26052 " .align 2,0x90\n"
26053 - "2: movl 0(%4), %%eax\n"
26054 - "21: movl 4(%4), %%edx\n"
26055 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26056 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26057 " movl %%eax, 0(%3)\n"
26058 " movl %%edx, 4(%3)\n"
26059 - "3: movl 8(%4), %%eax\n"
26060 - "31: movl 12(%4),%%edx\n"
26061 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26062 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26063 " movl %%eax, 8(%3)\n"
26064 " movl %%edx, 12(%3)\n"
26065 - "4: movl 16(%4), %%eax\n"
26066 - "41: movl 20(%4), %%edx\n"
26067 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26068 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26069 " movl %%eax, 16(%3)\n"
26070 " movl %%edx, 20(%3)\n"
26071 - "10: movl 24(%4), %%eax\n"
26072 - "51: movl 28(%4), %%edx\n"
26073 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26074 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26075 " movl %%eax, 24(%3)\n"
26076 " movl %%edx, 28(%3)\n"
26077 - "11: movl 32(%4), %%eax\n"
26078 - "61: movl 36(%4), %%edx\n"
26079 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26080 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26081 " movl %%eax, 32(%3)\n"
26082 " movl %%edx, 36(%3)\n"
26083 - "12: movl 40(%4), %%eax\n"
26084 - "71: movl 44(%4), %%edx\n"
26085 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26086 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26087 " movl %%eax, 40(%3)\n"
26088 " movl %%edx, 44(%3)\n"
26089 - "13: movl 48(%4), %%eax\n"
26090 - "81: movl 52(%4), %%edx\n"
26091 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26092 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26093 " movl %%eax, 48(%3)\n"
26094 " movl %%edx, 52(%3)\n"
26095 - "14: movl 56(%4), %%eax\n"
26096 - "91: movl 60(%4), %%edx\n"
26097 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26098 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26099 " movl %%eax, 56(%3)\n"
26100 " movl %%edx, 60(%3)\n"
26101 " addl $-64, %0\n"
26102 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26103 " shrl $2, %0\n"
26104 " andl $3, %%eax\n"
26105 " cld\n"
26106 - "6: rep; movsl\n"
26107 + "6: rep; "__copyuser_seg" movsl\n"
26108 " movl %%eax,%0\n"
26109 - "7: rep; movsb\n"
26110 + "7: rep; "__copyuser_seg" movsb\n"
26111 "8:\n"
26112 ".section .fixup,\"ax\"\n"
26113 "9: lea 0(%%eax,%0,4),%0\n"
26114 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26115 * hyoshiok@miraclelinux.com
26116 */
26117
26118 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26119 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26120 const void __user *from, unsigned long size)
26121 {
26122 int d0, d1;
26123
26124 __asm__ __volatile__(
26125 " .align 2,0x90\n"
26126 - "0: movl 32(%4), %%eax\n"
26127 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26128 " cmpl $67, %0\n"
26129 " jbe 2f\n"
26130 - "1: movl 64(%4), %%eax\n"
26131 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26132 " .align 2,0x90\n"
26133 - "2: movl 0(%4), %%eax\n"
26134 - "21: movl 4(%4), %%edx\n"
26135 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26136 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26137 " movnti %%eax, 0(%3)\n"
26138 " movnti %%edx, 4(%3)\n"
26139 - "3: movl 8(%4), %%eax\n"
26140 - "31: movl 12(%4),%%edx\n"
26141 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26142 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26143 " movnti %%eax, 8(%3)\n"
26144 " movnti %%edx, 12(%3)\n"
26145 - "4: movl 16(%4), %%eax\n"
26146 - "41: movl 20(%4), %%edx\n"
26147 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26148 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26149 " movnti %%eax, 16(%3)\n"
26150 " movnti %%edx, 20(%3)\n"
26151 - "10: movl 24(%4), %%eax\n"
26152 - "51: movl 28(%4), %%edx\n"
26153 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26154 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26155 " movnti %%eax, 24(%3)\n"
26156 " movnti %%edx, 28(%3)\n"
26157 - "11: movl 32(%4), %%eax\n"
26158 - "61: movl 36(%4), %%edx\n"
26159 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26160 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26161 " movnti %%eax, 32(%3)\n"
26162 " movnti %%edx, 36(%3)\n"
26163 - "12: movl 40(%4), %%eax\n"
26164 - "71: movl 44(%4), %%edx\n"
26165 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26166 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26167 " movnti %%eax, 40(%3)\n"
26168 " movnti %%edx, 44(%3)\n"
26169 - "13: movl 48(%4), %%eax\n"
26170 - "81: movl 52(%4), %%edx\n"
26171 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26172 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26173 " movnti %%eax, 48(%3)\n"
26174 " movnti %%edx, 52(%3)\n"
26175 - "14: movl 56(%4), %%eax\n"
26176 - "91: movl 60(%4), %%edx\n"
26177 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26178 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26179 " movnti %%eax, 56(%3)\n"
26180 " movnti %%edx, 60(%3)\n"
26181 " addl $-64, %0\n"
26182 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26183 " shrl $2, %0\n"
26184 " andl $3, %%eax\n"
26185 " cld\n"
26186 - "6: rep; movsl\n"
26187 + "6: rep; "__copyuser_seg" movsl\n"
26188 " movl %%eax,%0\n"
26189 - "7: rep; movsb\n"
26190 + "7: rep; "__copyuser_seg" movsb\n"
26191 "8:\n"
26192 ".section .fixup,\"ax\"\n"
26193 "9: lea 0(%%eax,%0,4),%0\n"
26194 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26195 return size;
26196 }
26197
26198 -static unsigned long __copy_user_intel_nocache(void *to,
26199 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26200 const void __user *from, unsigned long size)
26201 {
26202 int d0, d1;
26203
26204 __asm__ __volatile__(
26205 " .align 2,0x90\n"
26206 - "0: movl 32(%4), %%eax\n"
26207 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26208 " cmpl $67, %0\n"
26209 " jbe 2f\n"
26210 - "1: movl 64(%4), %%eax\n"
26211 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26212 " .align 2,0x90\n"
26213 - "2: movl 0(%4), %%eax\n"
26214 - "21: movl 4(%4), %%edx\n"
26215 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26216 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26217 " movnti %%eax, 0(%3)\n"
26218 " movnti %%edx, 4(%3)\n"
26219 - "3: movl 8(%4), %%eax\n"
26220 - "31: movl 12(%4),%%edx\n"
26221 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26222 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26223 " movnti %%eax, 8(%3)\n"
26224 " movnti %%edx, 12(%3)\n"
26225 - "4: movl 16(%4), %%eax\n"
26226 - "41: movl 20(%4), %%edx\n"
26227 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26228 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26229 " movnti %%eax, 16(%3)\n"
26230 " movnti %%edx, 20(%3)\n"
26231 - "10: movl 24(%4), %%eax\n"
26232 - "51: movl 28(%4), %%edx\n"
26233 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26234 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26235 " movnti %%eax, 24(%3)\n"
26236 " movnti %%edx, 28(%3)\n"
26237 - "11: movl 32(%4), %%eax\n"
26238 - "61: movl 36(%4), %%edx\n"
26239 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26240 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26241 " movnti %%eax, 32(%3)\n"
26242 " movnti %%edx, 36(%3)\n"
26243 - "12: movl 40(%4), %%eax\n"
26244 - "71: movl 44(%4), %%edx\n"
26245 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26246 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26247 " movnti %%eax, 40(%3)\n"
26248 " movnti %%edx, 44(%3)\n"
26249 - "13: movl 48(%4), %%eax\n"
26250 - "81: movl 52(%4), %%edx\n"
26251 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26252 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26253 " movnti %%eax, 48(%3)\n"
26254 " movnti %%edx, 52(%3)\n"
26255 - "14: movl 56(%4), %%eax\n"
26256 - "91: movl 60(%4), %%edx\n"
26257 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26258 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26259 " movnti %%eax, 56(%3)\n"
26260 " movnti %%edx, 60(%3)\n"
26261 " addl $-64, %0\n"
26262 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26263 " shrl $2, %0\n"
26264 " andl $3, %%eax\n"
26265 " cld\n"
26266 - "6: rep; movsl\n"
26267 + "6: rep; "__copyuser_seg" movsl\n"
26268 " movl %%eax,%0\n"
26269 - "7: rep; movsb\n"
26270 + "7: rep; "__copyuser_seg" movsb\n"
26271 "8:\n"
26272 ".section .fixup,\"ax\"\n"
26273 "9: lea 0(%%eax,%0,4),%0\n"
26274 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26275 */
26276 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26277 unsigned long size);
26278 -unsigned long __copy_user_intel(void __user *to, const void *from,
26279 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26280 + unsigned long size);
26281 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26282 unsigned long size);
26283 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26284 const void __user *from, unsigned long size);
26285 #endif /* CONFIG_X86_INTEL_USERCOPY */
26286
26287 /* Generic arbitrary sized copy. */
26288 -#define __copy_user(to, from, size) \
26289 +#define __copy_user(to, from, size, prefix, set, restore) \
26290 do { \
26291 int __d0, __d1, __d2; \
26292 __asm__ __volatile__( \
26293 + set \
26294 " cmp $7,%0\n" \
26295 " jbe 1f\n" \
26296 " movl %1,%0\n" \
26297 " negl %0\n" \
26298 " andl $7,%0\n" \
26299 " subl %0,%3\n" \
26300 - "4: rep; movsb\n" \
26301 + "4: rep; "prefix"movsb\n" \
26302 " movl %3,%0\n" \
26303 " shrl $2,%0\n" \
26304 " andl $3,%3\n" \
26305 " .align 2,0x90\n" \
26306 - "0: rep; movsl\n" \
26307 + "0: rep; "prefix"movsl\n" \
26308 " movl %3,%0\n" \
26309 - "1: rep; movsb\n" \
26310 + "1: rep; "prefix"movsb\n" \
26311 "2:\n" \
26312 + restore \
26313 ".section .fixup,\"ax\"\n" \
26314 "5: addl %3,%0\n" \
26315 " jmp 2b\n" \
26316 @@ -538,14 +650,14 @@ do { \
26317 " negl %0\n" \
26318 " andl $7,%0\n" \
26319 " subl %0,%3\n" \
26320 - "4: rep; movsb\n" \
26321 + "4: rep; "__copyuser_seg"movsb\n" \
26322 " movl %3,%0\n" \
26323 " shrl $2,%0\n" \
26324 " andl $3,%3\n" \
26325 " .align 2,0x90\n" \
26326 - "0: rep; movsl\n" \
26327 + "0: rep; "__copyuser_seg"movsl\n" \
26328 " movl %3,%0\n" \
26329 - "1: rep; movsb\n" \
26330 + "1: rep; "__copyuser_seg"movsb\n" \
26331 "2:\n" \
26332 ".section .fixup,\"ax\"\n" \
26333 "5: addl %3,%0\n" \
26334 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26335 {
26336 stac();
26337 if (movsl_is_ok(to, from, n))
26338 - __copy_user(to, from, n);
26339 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26340 else
26341 - n = __copy_user_intel(to, from, n);
26342 + n = __generic_copy_to_user_intel(to, from, n);
26343 clac();
26344 return n;
26345 }
26346 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26347 {
26348 stac();
26349 if (movsl_is_ok(to, from, n))
26350 - __copy_user(to, from, n);
26351 + __copy_user(to, from, n, __copyuser_seg, "", "");
26352 else
26353 - n = __copy_user_intel((void __user *)to,
26354 - (const void *)from, n);
26355 + n = __generic_copy_from_user_intel(to, from, n);
26356 clac();
26357 return n;
26358 }
26359 @@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26360 if (n > 64 && cpu_has_xmm2)
26361 n = __copy_user_intel_nocache(to, from, n);
26362 else
26363 - __copy_user(to, from, n);
26364 + __copy_user(to, from, n, __copyuser_seg, "", "");
26365 #else
26366 - __copy_user(to, from, n);
26367 + __copy_user(to, from, n, __copyuser_seg, "", "");
26368 #endif
26369 clac();
26370 return n;
26371 }
26372 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
26373
26374 -/**
26375 - * copy_to_user: - Copy a block of data into user space.
26376 - * @to: Destination address, in user space.
26377 - * @from: Source address, in kernel space.
26378 - * @n: Number of bytes to copy.
26379 - *
26380 - * Context: User context only. This function may sleep.
26381 - *
26382 - * Copy data from kernel space to user space.
26383 - *
26384 - * Returns number of bytes that could not be copied.
26385 - * On success, this will be zero.
26386 - */
26387 -unsigned long
26388 -copy_to_user(void __user *to, const void *from, unsigned long n)
26389 -{
26390 - if (access_ok(VERIFY_WRITE, to, n))
26391 - n = __copy_to_user(to, from, n);
26392 - return n;
26393 -}
26394 -EXPORT_SYMBOL(copy_to_user);
26395 -
26396 -/**
26397 - * copy_from_user: - Copy a block of data from user space.
26398 - * @to: Destination address, in kernel space.
26399 - * @from: Source address, in user space.
26400 - * @n: Number of bytes to copy.
26401 - *
26402 - * Context: User context only. This function may sleep.
26403 - *
26404 - * Copy data from user space to kernel space.
26405 - *
26406 - * Returns number of bytes that could not be copied.
26407 - * On success, this will be zero.
26408 - *
26409 - * If some data could not be copied, this function will pad the copied
26410 - * data to the requested size using zero bytes.
26411 - */
26412 -unsigned long
26413 -_copy_from_user(void *to, const void __user *from, unsigned long n)
26414 -{
26415 - if (access_ok(VERIFY_READ, from, n))
26416 - n = __copy_from_user(to, from, n);
26417 - else
26418 - memset(to, 0, n);
26419 - return n;
26420 -}
26421 -EXPORT_SYMBOL(_copy_from_user);
26422 -
26423 void copy_from_user_overflow(void)
26424 {
26425 WARN(1, "Buffer overflow detected!\n");
26426 }
26427 EXPORT_SYMBOL(copy_from_user_overflow);
26428 +
26429 +void copy_to_user_overflow(void)
26430 +{
26431 + WARN(1, "Buffer overflow detected!\n");
26432 +}
26433 +EXPORT_SYMBOL(copy_to_user_overflow);
26434 +
26435 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26436 +void __set_fs(mm_segment_t x)
26437 +{
26438 + switch (x.seg) {
26439 + case 0:
26440 + loadsegment(gs, 0);
26441 + break;
26442 + case TASK_SIZE_MAX:
26443 + loadsegment(gs, __USER_DS);
26444 + break;
26445 + case -1UL:
26446 + loadsegment(gs, __KERNEL_DS);
26447 + break;
26448 + default:
26449 + BUG();
26450 + }
26451 + return;
26452 +}
26453 +EXPORT_SYMBOL(__set_fs);
26454 +
26455 +void set_fs(mm_segment_t x)
26456 +{
26457 + current_thread_info()->addr_limit = x;
26458 + __set_fs(x);
26459 +}
26460 +EXPORT_SYMBOL(set_fs);
26461 +#endif
26462 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
26463 index 05928aa..b33dea1 100644
26464 --- a/arch/x86/lib/usercopy_64.c
26465 +++ b/arch/x86/lib/usercopy_64.c
26466 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
26467 _ASM_EXTABLE(0b,3b)
26468 _ASM_EXTABLE(1b,2b)
26469 : [size8] "=&c"(size), [dst] "=&D" (__d0)
26470 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
26471 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
26472 [zero] "r" (0UL), [eight] "r" (8UL));
26473 clac();
26474 return size;
26475 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
26476 }
26477 EXPORT_SYMBOL(clear_user);
26478
26479 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
26480 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
26481 {
26482 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
26483 - return copy_user_generic((__force void *)to, (__force void *)from, len);
26484 - }
26485 - return len;
26486 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
26487 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
26488 + return len;
26489 }
26490 EXPORT_SYMBOL(copy_in_user);
26491
26492 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
26493 * it is not necessary to optimize tail handling.
26494 */
26495 unsigned long
26496 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26497 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
26498 {
26499 char c;
26500 unsigned zero_len;
26501 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26502 clac();
26503 return len;
26504 }
26505 +
26506 +void copy_from_user_overflow(void)
26507 +{
26508 + WARN(1, "Buffer overflow detected!\n");
26509 +}
26510 +EXPORT_SYMBOL(copy_from_user_overflow);
26511 +
26512 +void copy_to_user_overflow(void)
26513 +{
26514 + WARN(1, "Buffer overflow detected!\n");
26515 +}
26516 +EXPORT_SYMBOL(copy_to_user_overflow);
26517 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
26518 index 903ec1e..c4166b2 100644
26519 --- a/arch/x86/mm/extable.c
26520 +++ b/arch/x86/mm/extable.c
26521 @@ -6,12 +6,24 @@
26522 static inline unsigned long
26523 ex_insn_addr(const struct exception_table_entry *x)
26524 {
26525 - return (unsigned long)&x->insn + x->insn;
26526 + unsigned long reloc = 0;
26527 +
26528 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26529 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26530 +#endif
26531 +
26532 + return (unsigned long)&x->insn + x->insn + reloc;
26533 }
26534 static inline unsigned long
26535 ex_fixup_addr(const struct exception_table_entry *x)
26536 {
26537 - return (unsigned long)&x->fixup + x->fixup;
26538 + unsigned long reloc = 0;
26539 +
26540 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26541 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26542 +#endif
26543 +
26544 + return (unsigned long)&x->fixup + x->fixup + reloc;
26545 }
26546
26547 int fixup_exception(struct pt_regs *regs)
26548 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
26549 unsigned long new_ip;
26550
26551 #ifdef CONFIG_PNPBIOS
26552 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
26553 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
26554 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
26555 extern u32 pnp_bios_is_utter_crap;
26556 pnp_bios_is_utter_crap = 1;
26557 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
26558 i += 4;
26559 p->fixup -= i;
26560 i += 4;
26561 +
26562 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26563 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
26564 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26565 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26566 +#endif
26567 +
26568 }
26569 }
26570
26571 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
26572 index fb674fd..272f369 100644
26573 --- a/arch/x86/mm/fault.c
26574 +++ b/arch/x86/mm/fault.c
26575 @@ -13,12 +13,19 @@
26576 #include <linux/perf_event.h> /* perf_sw_event */
26577 #include <linux/hugetlb.h> /* hstate_index_to_shift */
26578 #include <linux/prefetch.h> /* prefetchw */
26579 +#include <linux/unistd.h>
26580 +#include <linux/compiler.h>
26581
26582 #include <asm/traps.h> /* dotraplinkage, ... */
26583 #include <asm/pgalloc.h> /* pgd_*(), ... */
26584 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
26585 #include <asm/fixmap.h> /* VSYSCALL_START */
26586 #include <asm/context_tracking.h> /* exception_enter(), ... */
26587 +#include <asm/tlbflush.h>
26588 +
26589 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26590 +#include <asm/stacktrace.h>
26591 +#endif
26592
26593 /*
26594 * Page fault error code bits:
26595 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
26596 int ret = 0;
26597
26598 /* kprobe_running() needs smp_processor_id() */
26599 - if (kprobes_built_in() && !user_mode_vm(regs)) {
26600 + if (kprobes_built_in() && !user_mode(regs)) {
26601 preempt_disable();
26602 if (kprobe_running() && kprobe_fault_handler(regs, 14))
26603 ret = 1;
26604 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
26605 return !instr_lo || (instr_lo>>1) == 1;
26606 case 0x00:
26607 /* Prefetch instruction is 0x0F0D or 0x0F18 */
26608 - if (probe_kernel_address(instr, opcode))
26609 + if (user_mode(regs)) {
26610 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26611 + return 0;
26612 + } else if (probe_kernel_address(instr, opcode))
26613 return 0;
26614
26615 *prefetch = (instr_lo == 0xF) &&
26616 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
26617 while (instr < max_instr) {
26618 unsigned char opcode;
26619
26620 - if (probe_kernel_address(instr, opcode))
26621 + if (user_mode(regs)) {
26622 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26623 + break;
26624 + } else if (probe_kernel_address(instr, opcode))
26625 break;
26626
26627 instr++;
26628 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
26629 force_sig_info(si_signo, &info, tsk);
26630 }
26631
26632 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26633 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
26634 +#endif
26635 +
26636 +#ifdef CONFIG_PAX_EMUTRAMP
26637 +static int pax_handle_fetch_fault(struct pt_regs *regs);
26638 +#endif
26639 +
26640 +#ifdef CONFIG_PAX_PAGEEXEC
26641 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
26642 +{
26643 + pgd_t *pgd;
26644 + pud_t *pud;
26645 + pmd_t *pmd;
26646 +
26647 + pgd = pgd_offset(mm, address);
26648 + if (!pgd_present(*pgd))
26649 + return NULL;
26650 + pud = pud_offset(pgd, address);
26651 + if (!pud_present(*pud))
26652 + return NULL;
26653 + pmd = pmd_offset(pud, address);
26654 + if (!pmd_present(*pmd))
26655 + return NULL;
26656 + return pmd;
26657 +}
26658 +#endif
26659 +
26660 DEFINE_SPINLOCK(pgd_lock);
26661 LIST_HEAD(pgd_list);
26662
26663 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
26664 for (address = VMALLOC_START & PMD_MASK;
26665 address >= TASK_SIZE && address < FIXADDR_TOP;
26666 address += PMD_SIZE) {
26667 +
26668 +#ifdef CONFIG_PAX_PER_CPU_PGD
26669 + unsigned long cpu;
26670 +#else
26671 struct page *page;
26672 +#endif
26673
26674 spin_lock(&pgd_lock);
26675 +
26676 +#ifdef CONFIG_PAX_PER_CPU_PGD
26677 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26678 + pgd_t *pgd = get_cpu_pgd(cpu);
26679 + pmd_t *ret;
26680 +#else
26681 list_for_each_entry(page, &pgd_list, lru) {
26682 + pgd_t *pgd = page_address(page);
26683 spinlock_t *pgt_lock;
26684 pmd_t *ret;
26685
26686 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
26687 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26688
26689 spin_lock(pgt_lock);
26690 - ret = vmalloc_sync_one(page_address(page), address);
26691 +#endif
26692 +
26693 + ret = vmalloc_sync_one(pgd, address);
26694 +
26695 +#ifndef CONFIG_PAX_PER_CPU_PGD
26696 spin_unlock(pgt_lock);
26697 +#endif
26698
26699 if (!ret)
26700 break;
26701 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26702 * an interrupt in the middle of a task switch..
26703 */
26704 pgd_paddr = read_cr3();
26705 +
26706 +#ifdef CONFIG_PAX_PER_CPU_PGD
26707 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
26708 +#endif
26709 +
26710 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
26711 if (!pmd_k)
26712 return -1;
26713 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26714 * happen within a race in page table update. In the later
26715 * case just flush:
26716 */
26717 +
26718 +#ifdef CONFIG_PAX_PER_CPU_PGD
26719 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
26720 + pgd = pgd_offset_cpu(smp_processor_id(), address);
26721 +#else
26722 pgd = pgd_offset(current->active_mm, address);
26723 +#endif
26724 +
26725 pgd_ref = pgd_offset_k(address);
26726 if (pgd_none(*pgd_ref))
26727 return -1;
26728 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
26729 static int is_errata100(struct pt_regs *regs, unsigned long address)
26730 {
26731 #ifdef CONFIG_X86_64
26732 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
26733 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
26734 return 1;
26735 #endif
26736 return 0;
26737 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
26738 }
26739
26740 static const char nx_warning[] = KERN_CRIT
26741 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
26742 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
26743
26744 static void
26745 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26746 @@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26747 if (!oops_may_print())
26748 return;
26749
26750 - if (error_code & PF_INSTR) {
26751 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
26752 unsigned int level;
26753
26754 pte_t *pte = lookup_address(address, &level);
26755
26756 if (pte && pte_present(*pte) && !pte_exec(*pte))
26757 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
26758 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
26759 }
26760
26761 +#ifdef CONFIG_PAX_KERNEXEC
26762 + if (init_mm.start_code <= address && address < init_mm.end_code) {
26763 + if (current->signal->curr_ip)
26764 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
26765 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
26766 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26767 + else
26768 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
26769 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26770 + }
26771 +#endif
26772 +
26773 printk(KERN_ALERT "BUG: unable to handle kernel ");
26774 if (address < PAGE_SIZE)
26775 printk(KERN_CONT "NULL pointer dereference");
26776 @@ -748,6 +830,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
26777 return;
26778 }
26779 #endif
26780 +
26781 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26782 + if (pax_is_fetch_fault(regs, error_code, address)) {
26783 +
26784 +#ifdef CONFIG_PAX_EMUTRAMP
26785 + switch (pax_handle_fetch_fault(regs)) {
26786 + case 2:
26787 + return;
26788 + }
26789 +#endif
26790 +
26791 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26792 + do_group_exit(SIGKILL);
26793 + }
26794 +#endif
26795 +
26796 /* Kernel addresses are always protection faults: */
26797 if (address >= TASK_SIZE)
26798 error_code |= PF_PROT;
26799 @@ -833,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
26800 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
26801 printk(KERN_ERR
26802 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
26803 - tsk->comm, tsk->pid, address);
26804 + tsk->comm, task_pid_nr(tsk), address);
26805 code = BUS_MCEERR_AR;
26806 }
26807 #endif
26808 @@ -896,6 +994,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
26809 return 1;
26810 }
26811
26812 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26813 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
26814 +{
26815 + pte_t *pte;
26816 + pmd_t *pmd;
26817 + spinlock_t *ptl;
26818 + unsigned char pte_mask;
26819 +
26820 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
26821 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
26822 + return 0;
26823 +
26824 + /* PaX: it's our fault, let's handle it if we can */
26825 +
26826 + /* PaX: take a look at read faults before acquiring any locks */
26827 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
26828 + /* instruction fetch attempt from a protected page in user mode */
26829 + up_read(&mm->mmap_sem);
26830 +
26831 +#ifdef CONFIG_PAX_EMUTRAMP
26832 + switch (pax_handle_fetch_fault(regs)) {
26833 + case 2:
26834 + return 1;
26835 + }
26836 +#endif
26837 +
26838 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26839 + do_group_exit(SIGKILL);
26840 + }
26841 +
26842 + pmd = pax_get_pmd(mm, address);
26843 + if (unlikely(!pmd))
26844 + return 0;
26845 +
26846 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
26847 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
26848 + pte_unmap_unlock(pte, ptl);
26849 + return 0;
26850 + }
26851 +
26852 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
26853 + /* write attempt to a protected page in user mode */
26854 + pte_unmap_unlock(pte, ptl);
26855 + return 0;
26856 + }
26857 +
26858 +#ifdef CONFIG_SMP
26859 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
26860 +#else
26861 + if (likely(address > get_limit(regs->cs)))
26862 +#endif
26863 + {
26864 + set_pte(pte, pte_mkread(*pte));
26865 + __flush_tlb_one(address);
26866 + pte_unmap_unlock(pte, ptl);
26867 + up_read(&mm->mmap_sem);
26868 + return 1;
26869 + }
26870 +
26871 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
26872 +
26873 + /*
26874 + * PaX: fill DTLB with user rights and retry
26875 + */
26876 + __asm__ __volatile__ (
26877 + "orb %2,(%1)\n"
26878 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
26879 +/*
26880 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
26881 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
26882 + * page fault when examined during a TLB load attempt. this is true not only
26883 + * for PTEs holding a non-present entry but also present entries that will
26884 + * raise a page fault (such as those set up by PaX, or the copy-on-write
26885 + * mechanism). in effect it means that we do *not* need to flush the TLBs
26886 + * for our target pages since their PTEs are simply not in the TLBs at all.
26887 +
26888 + * the best thing in omitting it is that we gain around 15-20% speed in the
26889 + * fast path of the page fault handler and can get rid of tracing since we
26890 + * can no longer flush unintended entries.
26891 + */
26892 + "invlpg (%0)\n"
26893 +#endif
26894 + __copyuser_seg"testb $0,(%0)\n"
26895 + "xorb %3,(%1)\n"
26896 + :
26897 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
26898 + : "memory", "cc");
26899 + pte_unmap_unlock(pte, ptl);
26900 + up_read(&mm->mmap_sem);
26901 + return 1;
26902 +}
26903 +#endif
26904 +
26905 /*
26906 * Handle a spurious fault caused by a stale TLB entry.
26907 *
26908 @@ -968,6 +1159,9 @@ int show_unhandled_signals = 1;
26909 static inline int
26910 access_error(unsigned long error_code, struct vm_area_struct *vma)
26911 {
26912 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
26913 + return 1;
26914 +
26915 if (error_code & PF_WRITE) {
26916 /* write, present and write, not present: */
26917 if (unlikely(!(vma->vm_flags & VM_WRITE)))
26918 @@ -996,7 +1190,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
26919 if (error_code & PF_USER)
26920 return false;
26921
26922 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
26923 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
26924 return false;
26925
26926 return true;
26927 @@ -1012,18 +1206,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
26928 {
26929 struct vm_area_struct *vma;
26930 struct task_struct *tsk;
26931 - unsigned long address;
26932 struct mm_struct *mm;
26933 int fault;
26934 int write = error_code & PF_WRITE;
26935 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
26936 (write ? FAULT_FLAG_WRITE : 0);
26937
26938 - tsk = current;
26939 - mm = tsk->mm;
26940 -
26941 /* Get the faulting address: */
26942 - address = read_cr2();
26943 + unsigned long address = read_cr2();
26944 +
26945 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26946 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
26947 + if (!search_exception_tables(regs->ip)) {
26948 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
26949 + bad_area_nosemaphore(regs, error_code, address);
26950 + return;
26951 + }
26952 + if (address < PAX_USER_SHADOW_BASE) {
26953 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
26954 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
26955 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
26956 + } else
26957 + address -= PAX_USER_SHADOW_BASE;
26958 + }
26959 +#endif
26960 +
26961 + tsk = current;
26962 + mm = tsk->mm;
26963
26964 /*
26965 * Detect and handle instructions that would cause a page fault for
26966 @@ -1084,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
26967 * User-mode registers count as a user access even for any
26968 * potential system fault or CPU buglet:
26969 */
26970 - if (user_mode_vm(regs)) {
26971 + if (user_mode(regs)) {
26972 local_irq_enable();
26973 error_code |= PF_USER;
26974 } else {
26975 @@ -1146,6 +1355,11 @@ retry:
26976 might_sleep();
26977 }
26978
26979 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26980 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
26981 + return;
26982 +#endif
26983 +
26984 vma = find_vma(mm, address);
26985 if (unlikely(!vma)) {
26986 bad_area(regs, error_code, address);
26987 @@ -1157,18 +1371,24 @@ retry:
26988 bad_area(regs, error_code, address);
26989 return;
26990 }
26991 - if (error_code & PF_USER) {
26992 - /*
26993 - * Accessing the stack below %sp is always a bug.
26994 - * The large cushion allows instructions like enter
26995 - * and pusha to work. ("enter $65535, $31" pushes
26996 - * 32 pointers and then decrements %sp by 65535.)
26997 - */
26998 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
26999 - bad_area(regs, error_code, address);
27000 - return;
27001 - }
27002 + /*
27003 + * Accessing the stack below %sp is always a bug.
27004 + * The large cushion allows instructions like enter
27005 + * and pusha to work. ("enter $65535, $31" pushes
27006 + * 32 pointers and then decrements %sp by 65535.)
27007 + */
27008 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27009 + bad_area(regs, error_code, address);
27010 + return;
27011 }
27012 +
27013 +#ifdef CONFIG_PAX_SEGMEXEC
27014 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27015 + bad_area(regs, error_code, address);
27016 + return;
27017 + }
27018 +#endif
27019 +
27020 if (unlikely(expand_stack(vma, address))) {
27021 bad_area(regs, error_code, address);
27022 return;
27023 @@ -1232,3 +1452,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27024 __do_page_fault(regs, error_code);
27025 exception_exit(regs);
27026 }
27027 +
27028 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27029 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27030 +{
27031 + struct mm_struct *mm = current->mm;
27032 + unsigned long ip = regs->ip;
27033 +
27034 + if (v8086_mode(regs))
27035 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27036 +
27037 +#ifdef CONFIG_PAX_PAGEEXEC
27038 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27039 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27040 + return true;
27041 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27042 + return true;
27043 + return false;
27044 + }
27045 +#endif
27046 +
27047 +#ifdef CONFIG_PAX_SEGMEXEC
27048 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27049 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27050 + return true;
27051 + return false;
27052 + }
27053 +#endif
27054 +
27055 + return false;
27056 +}
27057 +#endif
27058 +
27059 +#ifdef CONFIG_PAX_EMUTRAMP
27060 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27061 +{
27062 + int err;
27063 +
27064 + do { /* PaX: libffi trampoline emulation */
27065 + unsigned char mov, jmp;
27066 + unsigned int addr1, addr2;
27067 +
27068 +#ifdef CONFIG_X86_64
27069 + if ((regs->ip + 9) >> 32)
27070 + break;
27071 +#endif
27072 +
27073 + err = get_user(mov, (unsigned char __user *)regs->ip);
27074 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27075 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27076 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27077 +
27078 + if (err)
27079 + break;
27080 +
27081 + if (mov == 0xB8 && jmp == 0xE9) {
27082 + regs->ax = addr1;
27083 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27084 + return 2;
27085 + }
27086 + } while (0);
27087 +
27088 + do { /* PaX: gcc trampoline emulation #1 */
27089 + unsigned char mov1, mov2;
27090 + unsigned short jmp;
27091 + unsigned int addr1, addr2;
27092 +
27093 +#ifdef CONFIG_X86_64
27094 + if ((regs->ip + 11) >> 32)
27095 + break;
27096 +#endif
27097 +
27098 + err = get_user(mov1, (unsigned char __user *)regs->ip);
27099 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27100 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27101 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27102 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27103 +
27104 + if (err)
27105 + break;
27106 +
27107 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27108 + regs->cx = addr1;
27109 + regs->ax = addr2;
27110 + regs->ip = addr2;
27111 + return 2;
27112 + }
27113 + } while (0);
27114 +
27115 + do { /* PaX: gcc trampoline emulation #2 */
27116 + unsigned char mov, jmp;
27117 + unsigned int addr1, addr2;
27118 +
27119 +#ifdef CONFIG_X86_64
27120 + if ((regs->ip + 9) >> 32)
27121 + break;
27122 +#endif
27123 +
27124 + err = get_user(mov, (unsigned char __user *)regs->ip);
27125 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27126 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27127 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27128 +
27129 + if (err)
27130 + break;
27131 +
27132 + if (mov == 0xB9 && jmp == 0xE9) {
27133 + regs->cx = addr1;
27134 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27135 + return 2;
27136 + }
27137 + } while (0);
27138 +
27139 + return 1; /* PaX in action */
27140 +}
27141 +
27142 +#ifdef CONFIG_X86_64
27143 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27144 +{
27145 + int err;
27146 +
27147 + do { /* PaX: libffi trampoline emulation */
27148 + unsigned short mov1, mov2, jmp1;
27149 + unsigned char stcclc, jmp2;
27150 + unsigned long addr1, addr2;
27151 +
27152 + err = get_user(mov1, (unsigned short __user *)regs->ip);
27153 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27154 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27155 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27156 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27157 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27158 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27159 +
27160 + if (err)
27161 + break;
27162 +
27163 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27164 + regs->r11 = addr1;
27165 + regs->r10 = addr2;
27166 + if (stcclc == 0xF8)
27167 + regs->flags &= ~X86_EFLAGS_CF;
27168 + else
27169 + regs->flags |= X86_EFLAGS_CF;
27170 + regs->ip = addr1;
27171 + return 2;
27172 + }
27173 + } while (0);
27174 +
27175 + do { /* PaX: gcc trampoline emulation #1 */
27176 + unsigned short mov1, mov2, jmp1;
27177 + unsigned char jmp2;
27178 + unsigned int addr1;
27179 + unsigned long addr2;
27180 +
27181 + err = get_user(mov1, (unsigned short __user *)regs->ip);
27182 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27183 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27184 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27185 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27186 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27187 +
27188 + if (err)
27189 + break;
27190 +
27191 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27192 + regs->r11 = addr1;
27193 + regs->r10 = addr2;
27194 + regs->ip = addr1;
27195 + return 2;
27196 + }
27197 + } while (0);
27198 +
27199 + do { /* PaX: gcc trampoline emulation #2 */
27200 + unsigned short mov1, mov2, jmp1;
27201 + unsigned char jmp2;
27202 + unsigned long addr1, addr2;
27203 +
27204 + err = get_user(mov1, (unsigned short __user *)regs->ip);
27205 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27206 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27207 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27208 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27209 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27210 +
27211 + if (err)
27212 + break;
27213 +
27214 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27215 + regs->r11 = addr1;
27216 + regs->r10 = addr2;
27217 + regs->ip = addr1;
27218 + return 2;
27219 + }
27220 + } while (0);
27221 +
27222 + return 1; /* PaX in action */
27223 +}
27224 +#endif
27225 +
27226 +/*
27227 + * PaX: decide what to do with offenders (regs->ip = fault address)
27228 + *
27229 + * returns 1 when task should be killed
27230 + * 2 when gcc trampoline was detected
27231 + */
27232 +static int pax_handle_fetch_fault(struct pt_regs *regs)
27233 +{
27234 + if (v8086_mode(regs))
27235 + return 1;
27236 +
27237 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27238 + return 1;
27239 +
27240 +#ifdef CONFIG_X86_32
27241 + return pax_handle_fetch_fault_32(regs);
27242 +#else
27243 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27244 + return pax_handle_fetch_fault_32(regs);
27245 + else
27246 + return pax_handle_fetch_fault_64(regs);
27247 +#endif
27248 +}
27249 +#endif
27250 +
27251 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27252 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27253 +{
27254 + long i;
27255 +
27256 + printk(KERN_ERR "PAX: bytes at PC: ");
27257 + for (i = 0; i < 20; i++) {
27258 + unsigned char c;
27259 + if (get_user(c, (unsigned char __force_user *)pc+i))
27260 + printk(KERN_CONT "?? ");
27261 + else
27262 + printk(KERN_CONT "%02x ", c);
27263 + }
27264 + printk("\n");
27265 +
27266 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27267 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
27268 + unsigned long c;
27269 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
27270 +#ifdef CONFIG_X86_32
27271 + printk(KERN_CONT "???????? ");
27272 +#else
27273 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27274 + printk(KERN_CONT "???????? ???????? ");
27275 + else
27276 + printk(KERN_CONT "???????????????? ");
27277 +#endif
27278 + } else {
27279 +#ifdef CONFIG_X86_64
27280 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27281 + printk(KERN_CONT "%08x ", (unsigned int)c);
27282 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27283 + } else
27284 +#endif
27285 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27286 + }
27287 + }
27288 + printk("\n");
27289 +}
27290 +#endif
27291 +
27292 +/**
27293 + * probe_kernel_write(): safely attempt to write to a location
27294 + * @dst: address to write to
27295 + * @src: pointer to the data that shall be written
27296 + * @size: size of the data chunk
27297 + *
27298 + * Safely write to address @dst from the buffer at @src. If a kernel fault
27299 + * happens, handle that and return -EFAULT.
27300 + */
27301 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27302 +{
27303 + long ret;
27304 + mm_segment_t old_fs = get_fs();
27305 +
27306 + set_fs(KERNEL_DS);
27307 + pagefault_disable();
27308 + pax_open_kernel();
27309 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27310 + pax_close_kernel();
27311 + pagefault_enable();
27312 + set_fs(old_fs);
27313 +
27314 + return ret ? -EFAULT : 0;
27315 +}
27316 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27317 index dd74e46..7d26398 100644
27318 --- a/arch/x86/mm/gup.c
27319 +++ b/arch/x86/mm/gup.c
27320 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27321 addr = start;
27322 len = (unsigned long) nr_pages << PAGE_SHIFT;
27323 end = start + len;
27324 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27325 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27326 (void __user *)start, len)))
27327 return 0;
27328
27329 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27330 index 6f31ee5..8ee4164 100644
27331 --- a/arch/x86/mm/highmem_32.c
27332 +++ b/arch/x86/mm/highmem_32.c
27333 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27334 idx = type + KM_TYPE_NR*smp_processor_id();
27335 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27336 BUG_ON(!pte_none(*(kmap_pte-idx)));
27337 +
27338 + pax_open_kernel();
27339 set_pte(kmap_pte-idx, mk_pte(page, prot));
27340 + pax_close_kernel();
27341 +
27342 arch_flush_lazy_mmu_mode();
27343
27344 return (void *)vaddr;
27345 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27346 index ae1aa71..56316db 100644
27347 --- a/arch/x86/mm/hugetlbpage.c
27348 +++ b/arch/x86/mm/hugetlbpage.c
27349 @@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27350 info.flags = 0;
27351 info.length = len;
27352 info.low_limit = TASK_UNMAPPED_BASE;
27353 +
27354 +#ifdef CONFIG_PAX_RANDMMAP
27355 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27356 + info.low_limit += current->mm->delta_mmap;
27357 +#endif
27358 +
27359 info.high_limit = TASK_SIZE;
27360 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27361 info.align_offset = 0;
27362 @@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
27363 VM_BUG_ON(addr != -ENOMEM);
27364 info.flags = 0;
27365 info.low_limit = TASK_UNMAPPED_BASE;
27366 +
27367 +#ifdef CONFIG_PAX_RANDMMAP
27368 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27369 + info.low_limit += current->mm->delta_mmap;
27370 +#endif
27371 +
27372 info.high_limit = TASK_SIZE;
27373 addr = vm_unmapped_area(&info);
27374 }
27375 @@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27376 struct hstate *h = hstate_file(file);
27377 struct mm_struct *mm = current->mm;
27378 struct vm_area_struct *vma;
27379 + unsigned long pax_task_size = TASK_SIZE;
27380 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
27381
27382 if (len & ~huge_page_mask(h))
27383 return -EINVAL;
27384 - if (len > TASK_SIZE)
27385 +
27386 +#ifdef CONFIG_PAX_SEGMEXEC
27387 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27388 + pax_task_size = SEGMEXEC_TASK_SIZE;
27389 +#endif
27390 +
27391 + pax_task_size -= PAGE_SIZE;
27392 +
27393 + if (len > pax_task_size)
27394 return -ENOMEM;
27395
27396 if (flags & MAP_FIXED) {
27397 @@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27398 return addr;
27399 }
27400
27401 +#ifdef CONFIG_PAX_RANDMMAP
27402 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27403 +#endif
27404 +
27405 if (addr) {
27406 addr = ALIGN(addr, huge_page_size(h));
27407 vma = find_vma(mm, addr);
27408 - if (TASK_SIZE - len >= addr &&
27409 - (!vma || addr + len <= vma->vm_start))
27410 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27411 return addr;
27412 }
27413 if (mm->get_unmapped_area == arch_get_unmapped_area)
27414 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
27415 index d7aea41..0fc945b 100644
27416 --- a/arch/x86/mm/init.c
27417 +++ b/arch/x86/mm/init.c
27418 @@ -4,6 +4,7 @@
27419 #include <linux/swap.h>
27420 #include <linux/memblock.h>
27421 #include <linux/bootmem.h> /* for max_low_pfn */
27422 +#include <linux/tboot.h>
27423
27424 #include <asm/cacheflush.h>
27425 #include <asm/e820.h>
27426 @@ -16,6 +17,8 @@
27427 #include <asm/tlb.h>
27428 #include <asm/proto.h>
27429 #include <asm/dma.h> /* for MAX_DMA_PFN */
27430 +#include <asm/desc.h>
27431 +#include <asm/bios_ebda.h>
27432
27433 unsigned long __initdata pgt_buf_start;
27434 unsigned long __meminitdata pgt_buf_end;
27435 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
27436 {
27437 int i;
27438 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
27439 - unsigned long start = 0, good_end;
27440 + unsigned long start = 0x100000, good_end;
27441 phys_addr_t base;
27442
27443 for (i = 0; i < nr_range; i++) {
27444 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
27445 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
27446 * mmio resources as well as potential bios/acpi data regions.
27447 */
27448 +
27449 +#ifdef CONFIG_GRKERNSEC_KMEM
27450 +static unsigned int ebda_start __read_only;
27451 +static unsigned int ebda_end __read_only;
27452 +#endif
27453 +
27454 int devmem_is_allowed(unsigned long pagenr)
27455 {
27456 - if (pagenr < 256)
27457 +#ifdef CONFIG_GRKERNSEC_KMEM
27458 + /* allow BDA */
27459 + if (!pagenr)
27460 return 1;
27461 + /* allow EBDA */
27462 + if (pagenr >= ebda_start && pagenr < ebda_end)
27463 + return 1;
27464 + /* if tboot is in use, allow access to its hardcoded serial log range */
27465 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
27466 + return 1;
27467 +#else
27468 + if (!pagenr)
27469 + return 1;
27470 +#ifdef CONFIG_VM86
27471 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
27472 + return 1;
27473 +#endif
27474 +#endif
27475 +
27476 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
27477 + return 1;
27478 +#ifdef CONFIG_GRKERNSEC_KMEM
27479 + /* throw out everything else below 1MB */
27480 + if (pagenr <= 256)
27481 + return 0;
27482 +#endif
27483 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
27484 return 0;
27485 if (!page_is_ram(pagenr))
27486 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
27487 #endif
27488 }
27489
27490 +#ifdef CONFIG_GRKERNSEC_KMEM
27491 +static inline void gr_init_ebda(void)
27492 +{
27493 + unsigned int ebda_addr;
27494 + unsigned int ebda_size = 0;
27495 +
27496 + ebda_addr = get_bios_ebda();
27497 + if (ebda_addr) {
27498 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
27499 + ebda_size <<= 10;
27500 + }
27501 + if (ebda_addr && ebda_size) {
27502 + ebda_start = ebda_addr >> PAGE_SHIFT;
27503 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
27504 + } else {
27505 + ebda_start = 0x9f000 >> PAGE_SHIFT;
27506 + ebda_end = 0xa0000 >> PAGE_SHIFT;
27507 + }
27508 +}
27509 +#else
27510 +static inline void gr_init_ebda(void) { }
27511 +#endif
27512 +
27513 void free_initmem(void)
27514 {
27515 +#ifdef CONFIG_PAX_KERNEXEC
27516 +#ifdef CONFIG_X86_32
27517 + /* PaX: limit KERNEL_CS to actual size */
27518 + unsigned long addr, limit;
27519 + struct desc_struct d;
27520 + int cpu;
27521 +#else
27522 + pgd_t *pgd;
27523 + pud_t *pud;
27524 + pmd_t *pmd;
27525 + unsigned long addr, end;
27526 +#endif
27527 +#endif
27528 +
27529 + gr_init_ebda();
27530 +
27531 +#ifdef CONFIG_PAX_KERNEXEC
27532 +#ifdef CONFIG_X86_32
27533 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
27534 + limit = (limit - 1UL) >> PAGE_SHIFT;
27535 +
27536 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
27537 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27538 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
27539 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
27540 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
27541 + }
27542 +
27543 + /* PaX: make KERNEL_CS read-only */
27544 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
27545 + if (!paravirt_enabled())
27546 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
27547 +/*
27548 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
27549 + pgd = pgd_offset_k(addr);
27550 + pud = pud_offset(pgd, addr);
27551 + pmd = pmd_offset(pud, addr);
27552 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27553 + }
27554 +*/
27555 +#ifdef CONFIG_X86_PAE
27556 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
27557 +/*
27558 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
27559 + pgd = pgd_offset_k(addr);
27560 + pud = pud_offset(pgd, addr);
27561 + pmd = pmd_offset(pud, addr);
27562 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27563 + }
27564 +*/
27565 +#endif
27566 +
27567 +#ifdef CONFIG_MODULES
27568 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
27569 +#endif
27570 +
27571 +#else
27572 + /* PaX: make kernel code/rodata read-only, rest non-executable */
27573 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
27574 + pgd = pgd_offset_k(addr);
27575 + pud = pud_offset(pgd, addr);
27576 + pmd = pmd_offset(pud, addr);
27577 + if (!pmd_present(*pmd))
27578 + continue;
27579 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
27580 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27581 + else
27582 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27583 + }
27584 +
27585 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
27586 + end = addr + KERNEL_IMAGE_SIZE;
27587 + for (; addr < end; addr += PMD_SIZE) {
27588 + pgd = pgd_offset_k(addr);
27589 + pud = pud_offset(pgd, addr);
27590 + pmd = pmd_offset(pud, addr);
27591 + if (!pmd_present(*pmd))
27592 + continue;
27593 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
27594 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27595 + }
27596 +#endif
27597 +
27598 + flush_tlb_all();
27599 +#endif
27600 +
27601 free_init_pages("unused kernel memory",
27602 (unsigned long)(&__init_begin),
27603 (unsigned long)(&__init_end));
27604 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
27605 index 745d66b..56bf568 100644
27606 --- a/arch/x86/mm/init_32.c
27607 +++ b/arch/x86/mm/init_32.c
27608 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
27609 }
27610
27611 /*
27612 - * Creates a middle page table and puts a pointer to it in the
27613 - * given global directory entry. This only returns the gd entry
27614 - * in non-PAE compilation mode, since the middle layer is folded.
27615 - */
27616 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
27617 -{
27618 - pud_t *pud;
27619 - pmd_t *pmd_table;
27620 -
27621 -#ifdef CONFIG_X86_PAE
27622 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
27623 - if (after_bootmem)
27624 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
27625 - else
27626 - pmd_table = (pmd_t *)alloc_low_page();
27627 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
27628 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
27629 - pud = pud_offset(pgd, 0);
27630 - BUG_ON(pmd_table != pmd_offset(pud, 0));
27631 -
27632 - return pmd_table;
27633 - }
27634 -#endif
27635 - pud = pud_offset(pgd, 0);
27636 - pmd_table = pmd_offset(pud, 0);
27637 -
27638 - return pmd_table;
27639 -}
27640 -
27641 -/*
27642 * Create a page table and place a pointer to it in a middle page
27643 * directory entry:
27644 */
27645 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
27646 page_table = (pte_t *)alloc_low_page();
27647
27648 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
27649 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27650 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
27651 +#else
27652 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
27653 +#endif
27654 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
27655 }
27656
27657 return pte_offset_kernel(pmd, 0);
27658 }
27659
27660 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
27661 +{
27662 + pud_t *pud;
27663 + pmd_t *pmd_table;
27664 +
27665 + pud = pud_offset(pgd, 0);
27666 + pmd_table = pmd_offset(pud, 0);
27667 +
27668 + return pmd_table;
27669 +}
27670 +
27671 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
27672 {
27673 int pgd_idx = pgd_index(vaddr);
27674 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27675 int pgd_idx, pmd_idx;
27676 unsigned long vaddr;
27677 pgd_t *pgd;
27678 + pud_t *pud;
27679 pmd_t *pmd;
27680 pte_t *pte = NULL;
27681
27682 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27683 pgd = pgd_base + pgd_idx;
27684
27685 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
27686 - pmd = one_md_table_init(pgd);
27687 - pmd = pmd + pmd_index(vaddr);
27688 + pud = pud_offset(pgd, vaddr);
27689 + pmd = pmd_offset(pud, vaddr);
27690 +
27691 +#ifdef CONFIG_X86_PAE
27692 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27693 +#endif
27694 +
27695 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
27696 pmd++, pmd_idx++) {
27697 pte = page_table_kmap_check(one_page_table_init(pmd),
27698 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27699 }
27700 }
27701
27702 -static inline int is_kernel_text(unsigned long addr)
27703 +static inline int is_kernel_text(unsigned long start, unsigned long end)
27704 {
27705 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
27706 - return 1;
27707 - return 0;
27708 + if ((start > ktla_ktva((unsigned long)_etext) ||
27709 + end <= ktla_ktva((unsigned long)_stext)) &&
27710 + (start > ktla_ktva((unsigned long)_einittext) ||
27711 + end <= ktla_ktva((unsigned long)_sinittext)) &&
27712 +
27713 +#ifdef CONFIG_ACPI_SLEEP
27714 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
27715 +#endif
27716 +
27717 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
27718 + return 0;
27719 + return 1;
27720 }
27721
27722 /*
27723 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
27724 unsigned long last_map_addr = end;
27725 unsigned long start_pfn, end_pfn;
27726 pgd_t *pgd_base = swapper_pg_dir;
27727 - int pgd_idx, pmd_idx, pte_ofs;
27728 + unsigned int pgd_idx, pmd_idx, pte_ofs;
27729 unsigned long pfn;
27730 pgd_t *pgd;
27731 + pud_t *pud;
27732 pmd_t *pmd;
27733 pte_t *pte;
27734 unsigned pages_2m, pages_4k;
27735 @@ -280,8 +281,13 @@ repeat:
27736 pfn = start_pfn;
27737 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27738 pgd = pgd_base + pgd_idx;
27739 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
27740 - pmd = one_md_table_init(pgd);
27741 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
27742 + pud = pud_offset(pgd, 0);
27743 + pmd = pmd_offset(pud, 0);
27744 +
27745 +#ifdef CONFIG_X86_PAE
27746 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27747 +#endif
27748
27749 if (pfn >= end_pfn)
27750 continue;
27751 @@ -293,14 +299,13 @@ repeat:
27752 #endif
27753 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
27754 pmd++, pmd_idx++) {
27755 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
27756 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
27757
27758 /*
27759 * Map with big pages if possible, otherwise
27760 * create normal page tables:
27761 */
27762 if (use_pse) {
27763 - unsigned int addr2;
27764 pgprot_t prot = PAGE_KERNEL_LARGE;
27765 /*
27766 * first pass will use the same initial
27767 @@ -310,11 +315,7 @@ repeat:
27768 __pgprot(PTE_IDENT_ATTR |
27769 _PAGE_PSE);
27770
27771 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
27772 - PAGE_OFFSET + PAGE_SIZE-1;
27773 -
27774 - if (is_kernel_text(addr) ||
27775 - is_kernel_text(addr2))
27776 + if (is_kernel_text(address, address + PMD_SIZE))
27777 prot = PAGE_KERNEL_LARGE_EXEC;
27778
27779 pages_2m++;
27780 @@ -331,7 +332,7 @@ repeat:
27781 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27782 pte += pte_ofs;
27783 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
27784 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
27785 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
27786 pgprot_t prot = PAGE_KERNEL;
27787 /*
27788 * first pass will use the same initial
27789 @@ -339,7 +340,7 @@ repeat:
27790 */
27791 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
27792
27793 - if (is_kernel_text(addr))
27794 + if (is_kernel_text(address, address + PAGE_SIZE))
27795 prot = PAGE_KERNEL_EXEC;
27796
27797 pages_4k++;
27798 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
27799
27800 pud = pud_offset(pgd, va);
27801 pmd = pmd_offset(pud, va);
27802 - if (!pmd_present(*pmd))
27803 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
27804 break;
27805
27806 pte = pte_offset_kernel(pmd, va);
27807 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
27808
27809 static void __init pagetable_init(void)
27810 {
27811 - pgd_t *pgd_base = swapper_pg_dir;
27812 -
27813 - permanent_kmaps_init(pgd_base);
27814 + permanent_kmaps_init(swapper_pg_dir);
27815 }
27816
27817 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27818 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27819 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27820
27821 /* user-defined highmem size */
27822 @@ -728,6 +727,12 @@ void __init mem_init(void)
27823
27824 pci_iommu_alloc();
27825
27826 +#ifdef CONFIG_PAX_PER_CPU_PGD
27827 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27828 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27829 + KERNEL_PGD_PTRS);
27830 +#endif
27831 +
27832 #ifdef CONFIG_FLATMEM
27833 BUG_ON(!mem_map);
27834 #endif
27835 @@ -754,7 +759,7 @@ void __init mem_init(void)
27836 reservedpages++;
27837
27838 codesize = (unsigned long) &_etext - (unsigned long) &_text;
27839 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
27840 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
27841 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
27842
27843 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
27844 @@ -795,10 +800,10 @@ void __init mem_init(void)
27845 ((unsigned long)&__init_end -
27846 (unsigned long)&__init_begin) >> 10,
27847
27848 - (unsigned long)&_etext, (unsigned long)&_edata,
27849 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
27850 + (unsigned long)&_sdata, (unsigned long)&_edata,
27851 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
27852
27853 - (unsigned long)&_text, (unsigned long)&_etext,
27854 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
27855 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
27856
27857 /*
27858 @@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
27859 if (!kernel_set_to_readonly)
27860 return;
27861
27862 + start = ktla_ktva(start);
27863 pr_debug("Set kernel text: %lx - %lx for read write\n",
27864 start, start+size);
27865
27866 @@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
27867 if (!kernel_set_to_readonly)
27868 return;
27869
27870 + start = ktla_ktva(start);
27871 pr_debug("Set kernel text: %lx - %lx for read only\n",
27872 start, start+size);
27873
27874 @@ -918,6 +925,7 @@ void mark_rodata_ro(void)
27875 unsigned long start = PFN_ALIGN(_text);
27876 unsigned long size = PFN_ALIGN(_etext) - start;
27877
27878 + start = ktla_ktva(start);
27879 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
27880 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
27881 size >> 10);
27882 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
27883 index 75c9a6a..498d677 100644
27884 --- a/arch/x86/mm/init_64.c
27885 +++ b/arch/x86/mm/init_64.c
27886 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
27887 * around without checking the pgd every time.
27888 */
27889
27890 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
27891 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
27892 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27893
27894 int force_personality32;
27895 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27896
27897 for (address = start; address <= end; address += PGDIR_SIZE) {
27898 const pgd_t *pgd_ref = pgd_offset_k(address);
27899 +
27900 +#ifdef CONFIG_PAX_PER_CPU_PGD
27901 + unsigned long cpu;
27902 +#else
27903 struct page *page;
27904 +#endif
27905
27906 if (pgd_none(*pgd_ref))
27907 continue;
27908
27909 spin_lock(&pgd_lock);
27910 +
27911 +#ifdef CONFIG_PAX_PER_CPU_PGD
27912 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27913 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
27914 +#else
27915 list_for_each_entry(page, &pgd_list, lru) {
27916 pgd_t *pgd;
27917 spinlock_t *pgt_lock;
27918 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27919 /* the pgt_lock only for Xen */
27920 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27921 spin_lock(pgt_lock);
27922 +#endif
27923
27924 if (pgd_none(*pgd))
27925 set_pgd(pgd, *pgd_ref);
27926 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27927 BUG_ON(pgd_page_vaddr(*pgd)
27928 != pgd_page_vaddr(*pgd_ref));
27929
27930 +#ifndef CONFIG_PAX_PER_CPU_PGD
27931 spin_unlock(pgt_lock);
27932 +#endif
27933 +
27934 }
27935 spin_unlock(&pgd_lock);
27936 }
27937 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
27938 {
27939 if (pgd_none(*pgd)) {
27940 pud_t *pud = (pud_t *)spp_getpage();
27941 - pgd_populate(&init_mm, pgd, pud);
27942 + pgd_populate_kernel(&init_mm, pgd, pud);
27943 if (pud != pud_offset(pgd, 0))
27944 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
27945 pud, pud_offset(pgd, 0));
27946 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
27947 {
27948 if (pud_none(*pud)) {
27949 pmd_t *pmd = (pmd_t *) spp_getpage();
27950 - pud_populate(&init_mm, pud, pmd);
27951 + pud_populate_kernel(&init_mm, pud, pmd);
27952 if (pmd != pmd_offset(pud, 0))
27953 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
27954 pmd, pmd_offset(pud, 0));
27955 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
27956 pmd = fill_pmd(pud, vaddr);
27957 pte = fill_pte(pmd, vaddr);
27958
27959 + pax_open_kernel();
27960 set_pte(pte, new_pte);
27961 + pax_close_kernel();
27962
27963 /*
27964 * It's enough to flush this one mapping.
27965 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
27966 pgd = pgd_offset_k((unsigned long)__va(phys));
27967 if (pgd_none(*pgd)) {
27968 pud = (pud_t *) spp_getpage();
27969 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
27970 - _PAGE_USER));
27971 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
27972 }
27973 pud = pud_offset(pgd, (unsigned long)__va(phys));
27974 if (pud_none(*pud)) {
27975 pmd = (pmd_t *) spp_getpage();
27976 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
27977 - _PAGE_USER));
27978 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
27979 }
27980 pmd = pmd_offset(pud, phys);
27981 BUG_ON(!pmd_none(*pmd));
27982 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
27983 if (pfn >= pgt_buf_top)
27984 panic("alloc_low_page: ran out of memory");
27985
27986 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
27987 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
27988 clear_page(adr);
27989 *phys = pfn * PAGE_SIZE;
27990 return adr;
27991 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
27992
27993 phys = __pa(virt);
27994 left = phys & (PAGE_SIZE - 1);
27995 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
27996 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
27997 adr = (void *)(((unsigned long)adr) | left);
27998
27999 return adr;
28000 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28001 unmap_low_page(pmd);
28002
28003 spin_lock(&init_mm.page_table_lock);
28004 - pud_populate(&init_mm, pud, __va(pmd_phys));
28005 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
28006 spin_unlock(&init_mm.page_table_lock);
28007 }
28008 __flush_tlb_all();
28009 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
28010 unmap_low_page(pud);
28011
28012 spin_lock(&init_mm.page_table_lock);
28013 - pgd_populate(&init_mm, pgd, __va(pud_phys));
28014 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
28015 spin_unlock(&init_mm.page_table_lock);
28016 pgd_changed = true;
28017 }
28018 @@ -693,6 +707,12 @@ void __init mem_init(void)
28019
28020 pci_iommu_alloc();
28021
28022 +#ifdef CONFIG_PAX_PER_CPU_PGD
28023 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28024 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28025 + KERNEL_PGD_PTRS);
28026 +#endif
28027 +
28028 /* clear_bss() already clear the empty_zero_page */
28029
28030 reservedpages = 0;
28031 @@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
28032 static struct vm_area_struct gate_vma = {
28033 .vm_start = VSYSCALL_START,
28034 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28035 - .vm_page_prot = PAGE_READONLY_EXEC,
28036 - .vm_flags = VM_READ | VM_EXEC
28037 + .vm_page_prot = PAGE_READONLY,
28038 + .vm_flags = VM_READ
28039 };
28040
28041 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28042 @@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
28043
28044 const char *arch_vma_name(struct vm_area_struct *vma)
28045 {
28046 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28047 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28048 return "[vdso]";
28049 if (vma == &gate_vma)
28050 return "[vsyscall]";
28051 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28052 index 7b179b4..6bd1777 100644
28053 --- a/arch/x86/mm/iomap_32.c
28054 +++ b/arch/x86/mm/iomap_32.c
28055 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28056 type = kmap_atomic_idx_push();
28057 idx = type + KM_TYPE_NR * smp_processor_id();
28058 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28059 +
28060 + pax_open_kernel();
28061 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28062 + pax_close_kernel();
28063 +
28064 arch_flush_lazy_mmu_mode();
28065
28066 return (void *)vaddr;
28067 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28068 index 78fe3f1..2f9433c 100644
28069 --- a/arch/x86/mm/ioremap.c
28070 +++ b/arch/x86/mm/ioremap.c
28071 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28072 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28073 int is_ram = page_is_ram(pfn);
28074
28075 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28076 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28077 return NULL;
28078 WARN_ON_ONCE(is_ram);
28079 }
28080 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28081 *
28082 * Caller must ensure there is only one unmapping for the same pointer.
28083 */
28084 -void iounmap(volatile void __iomem *addr)
28085 +void iounmap(const volatile void __iomem *addr)
28086 {
28087 struct vm_struct *p, *o;
28088
28089 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28090
28091 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28092 if (page_is_ram(start >> PAGE_SHIFT))
28093 +#ifdef CONFIG_HIGHMEM
28094 + if ((start >> PAGE_SHIFT) < max_low_pfn)
28095 +#endif
28096 return __va(phys);
28097
28098 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28099 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
28100 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28101
28102 static __initdata int after_paging_init;
28103 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28104 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28105
28106 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28107 {
28108 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
28109 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28110
28111 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28112 - memset(bm_pte, 0, sizeof(bm_pte));
28113 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
28114 + pmd_populate_user(&init_mm, pmd, bm_pte);
28115
28116 /*
28117 * The boot-ioremap range spans multiple pmds, for which
28118 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28119 index d87dd6d..bf3fa66 100644
28120 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
28121 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28122 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28123 * memory (e.g. tracked pages)? For now, we need this to avoid
28124 * invoking kmemcheck for PnP BIOS calls.
28125 */
28126 - if (regs->flags & X86_VM_MASK)
28127 + if (v8086_mode(regs))
28128 return false;
28129 - if (regs->cs != __KERNEL_CS)
28130 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28131 return false;
28132
28133 pte = kmemcheck_pte_lookup(address);
28134 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28135 index 845df68..1d8d29f 100644
28136 --- a/arch/x86/mm/mmap.c
28137 +++ b/arch/x86/mm/mmap.c
28138 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28139 * Leave an at least ~128 MB hole with possible stack randomization.
28140 */
28141 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28142 -#define MAX_GAP (TASK_SIZE/6*5)
28143 +#define MAX_GAP (pax_task_size/6*5)
28144
28145 static int mmap_is_legacy(void)
28146 {
28147 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28148 return rnd << PAGE_SHIFT;
28149 }
28150
28151 -static unsigned long mmap_base(void)
28152 +static unsigned long mmap_base(struct mm_struct *mm)
28153 {
28154 unsigned long gap = rlimit(RLIMIT_STACK);
28155 + unsigned long pax_task_size = TASK_SIZE;
28156 +
28157 +#ifdef CONFIG_PAX_SEGMEXEC
28158 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28159 + pax_task_size = SEGMEXEC_TASK_SIZE;
28160 +#endif
28161
28162 if (gap < MIN_GAP)
28163 gap = MIN_GAP;
28164 else if (gap > MAX_GAP)
28165 gap = MAX_GAP;
28166
28167 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28168 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28169 }
28170
28171 /*
28172 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28173 * does, but not when emulating X86_32
28174 */
28175 -static unsigned long mmap_legacy_base(void)
28176 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
28177 {
28178 - if (mmap_is_ia32())
28179 + if (mmap_is_ia32()) {
28180 +
28181 +#ifdef CONFIG_PAX_SEGMEXEC
28182 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28183 + return SEGMEXEC_TASK_UNMAPPED_BASE;
28184 + else
28185 +#endif
28186 +
28187 return TASK_UNMAPPED_BASE;
28188 - else
28189 + } else
28190 return TASK_UNMAPPED_BASE + mmap_rnd();
28191 }
28192
28193 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28194 void arch_pick_mmap_layout(struct mm_struct *mm)
28195 {
28196 if (mmap_is_legacy()) {
28197 - mm->mmap_base = mmap_legacy_base();
28198 + mm->mmap_base = mmap_legacy_base(mm);
28199 +
28200 +#ifdef CONFIG_PAX_RANDMMAP
28201 + if (mm->pax_flags & MF_PAX_RANDMMAP)
28202 + mm->mmap_base += mm->delta_mmap;
28203 +#endif
28204 +
28205 mm->get_unmapped_area = arch_get_unmapped_area;
28206 mm->unmap_area = arch_unmap_area;
28207 } else {
28208 - mm->mmap_base = mmap_base();
28209 + mm->mmap_base = mmap_base(mm);
28210 +
28211 +#ifdef CONFIG_PAX_RANDMMAP
28212 + if (mm->pax_flags & MF_PAX_RANDMMAP)
28213 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28214 +#endif
28215 +
28216 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28217 mm->unmap_area = arch_unmap_area_topdown;
28218 }
28219 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28220 index dc0b727..f612039 100644
28221 --- a/arch/x86/mm/mmio-mod.c
28222 +++ b/arch/x86/mm/mmio-mod.c
28223 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28224 break;
28225 default:
28226 {
28227 - unsigned char *ip = (unsigned char *)instptr;
28228 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28229 my_trace->opcode = MMIO_UNKNOWN_OP;
28230 my_trace->width = 0;
28231 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28232 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28233 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28234 void __iomem *addr)
28235 {
28236 - static atomic_t next_id;
28237 + static atomic_unchecked_t next_id;
28238 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28239 /* These are page-unaligned. */
28240 struct mmiotrace_map map = {
28241 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28242 .private = trace
28243 },
28244 .phys = offset,
28245 - .id = atomic_inc_return(&next_id)
28246 + .id = atomic_inc_return_unchecked(&next_id)
28247 };
28248 map.map_id = trace->id;
28249
28250 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28251 ioremap_trace_core(offset, size, addr);
28252 }
28253
28254 -static void iounmap_trace_core(volatile void __iomem *addr)
28255 +static void iounmap_trace_core(const volatile void __iomem *addr)
28256 {
28257 struct mmiotrace_map map = {
28258 .phys = 0,
28259 @@ -328,7 +328,7 @@ not_enabled:
28260 }
28261 }
28262
28263 -void mmiotrace_iounmap(volatile void __iomem *addr)
28264 +void mmiotrace_iounmap(const volatile void __iomem *addr)
28265 {
28266 might_sleep();
28267 if (is_enabled()) /* recheck and proper locking in *_core() */
28268 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28269 index b008656..773eac2 100644
28270 --- a/arch/x86/mm/pageattr-test.c
28271 +++ b/arch/x86/mm/pageattr-test.c
28272 @@ -36,7 +36,7 @@ enum {
28273
28274 static int pte_testbit(pte_t pte)
28275 {
28276 - return pte_flags(pte) & _PAGE_UNUSED1;
28277 + return pte_flags(pte) & _PAGE_CPA_TEST;
28278 }
28279
28280 struct split_state {
28281 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28282 index a718e0d..77419bc 100644
28283 --- a/arch/x86/mm/pageattr.c
28284 +++ b/arch/x86/mm/pageattr.c
28285 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28286 */
28287 #ifdef CONFIG_PCI_BIOS
28288 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28289 - pgprot_val(forbidden) |= _PAGE_NX;
28290 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28291 #endif
28292
28293 /*
28294 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28295 * Does not cover __inittext since that is gone later on. On
28296 * 64bit we do not enforce !NX on the low mapping
28297 */
28298 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
28299 - pgprot_val(forbidden) |= _PAGE_NX;
28300 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28301 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28302
28303 +#ifdef CONFIG_DEBUG_RODATA
28304 /*
28305 * The .rodata section needs to be read-only. Using the pfn
28306 * catches all aliases.
28307 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28308 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
28309 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
28310 pgprot_val(forbidden) |= _PAGE_RW;
28311 +#endif
28312
28313 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28314 /*
28315 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28316 }
28317 #endif
28318
28319 +#ifdef CONFIG_PAX_KERNEXEC
28320 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28321 + pgprot_val(forbidden) |= _PAGE_RW;
28322 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28323 + }
28324 +#endif
28325 +
28326 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28327
28328 return prot;
28329 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
28330 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28331 {
28332 /* change init_mm */
28333 + pax_open_kernel();
28334 set_pte_atomic(kpte, pte);
28335 +
28336 #ifdef CONFIG_X86_32
28337 if (!SHARED_KERNEL_PMD) {
28338 +
28339 +#ifdef CONFIG_PAX_PER_CPU_PGD
28340 + unsigned long cpu;
28341 +#else
28342 struct page *page;
28343 +#endif
28344
28345 +#ifdef CONFIG_PAX_PER_CPU_PGD
28346 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28347 + pgd_t *pgd = get_cpu_pgd(cpu);
28348 +#else
28349 list_for_each_entry(page, &pgd_list, lru) {
28350 - pgd_t *pgd;
28351 + pgd_t *pgd = (pgd_t *)page_address(page);
28352 +#endif
28353 +
28354 pud_t *pud;
28355 pmd_t *pmd;
28356
28357 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
28358 + pgd += pgd_index(address);
28359 pud = pud_offset(pgd, address);
28360 pmd = pmd_offset(pud, address);
28361 set_pte_atomic((pte_t *)pmd, pte);
28362 }
28363 }
28364 #endif
28365 + pax_close_kernel();
28366 }
28367
28368 static int
28369 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
28370 index 0eb572e..92f5c1e 100644
28371 --- a/arch/x86/mm/pat.c
28372 +++ b/arch/x86/mm/pat.c
28373 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
28374
28375 if (!entry) {
28376 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
28377 - current->comm, current->pid, start, end - 1);
28378 + current->comm, task_pid_nr(current), start, end - 1);
28379 return -EINVAL;
28380 }
28381
28382 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28383
28384 while (cursor < to) {
28385 if (!devmem_is_allowed(pfn)) {
28386 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
28387 - current->comm, from, to - 1);
28388 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
28389 + current->comm, from, to - 1, cursor);
28390 return 0;
28391 }
28392 cursor += PAGE_SIZE;
28393 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
28394 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
28395 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
28396 "for [mem %#010Lx-%#010Lx]\n",
28397 - current->comm, current->pid,
28398 + current->comm, task_pid_nr(current),
28399 cattr_name(flags),
28400 base, (unsigned long long)(base + size-1));
28401 return -EINVAL;
28402 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28403 flags = lookup_memtype(paddr);
28404 if (want_flags != flags) {
28405 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
28406 - current->comm, current->pid,
28407 + current->comm, task_pid_nr(current),
28408 cattr_name(want_flags),
28409 (unsigned long long)paddr,
28410 (unsigned long long)(paddr + size - 1),
28411 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28412 free_memtype(paddr, paddr + size);
28413 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
28414 " for [mem %#010Lx-%#010Lx], got %s\n",
28415 - current->comm, current->pid,
28416 + current->comm, task_pid_nr(current),
28417 cattr_name(want_flags),
28418 (unsigned long long)paddr,
28419 (unsigned long long)(paddr + size - 1),
28420 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
28421 index 9f0614d..92ae64a 100644
28422 --- a/arch/x86/mm/pf_in.c
28423 +++ b/arch/x86/mm/pf_in.c
28424 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
28425 int i;
28426 enum reason_type rv = OTHERS;
28427
28428 - p = (unsigned char *)ins_addr;
28429 + p = (unsigned char *)ktla_ktva(ins_addr);
28430 p += skip_prefix(p, &prf);
28431 p += get_opcode(p, &opcode);
28432
28433 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
28434 struct prefix_bits prf;
28435 int i;
28436
28437 - p = (unsigned char *)ins_addr;
28438 + p = (unsigned char *)ktla_ktva(ins_addr);
28439 p += skip_prefix(p, &prf);
28440 p += get_opcode(p, &opcode);
28441
28442 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
28443 struct prefix_bits prf;
28444 int i;
28445
28446 - p = (unsigned char *)ins_addr;
28447 + p = (unsigned char *)ktla_ktva(ins_addr);
28448 p += skip_prefix(p, &prf);
28449 p += get_opcode(p, &opcode);
28450
28451 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
28452 struct prefix_bits prf;
28453 int i;
28454
28455 - p = (unsigned char *)ins_addr;
28456 + p = (unsigned char *)ktla_ktva(ins_addr);
28457 p += skip_prefix(p, &prf);
28458 p += get_opcode(p, &opcode);
28459 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
28460 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
28461 struct prefix_bits prf;
28462 int i;
28463
28464 - p = (unsigned char *)ins_addr;
28465 + p = (unsigned char *)ktla_ktva(ins_addr);
28466 p += skip_prefix(p, &prf);
28467 p += get_opcode(p, &opcode);
28468 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
28469 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
28470 index e27fbf8..8b56dc9 100644
28471 --- a/arch/x86/mm/pgtable.c
28472 +++ b/arch/x86/mm/pgtable.c
28473 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
28474 list_del(&page->lru);
28475 }
28476
28477 -#define UNSHARED_PTRS_PER_PGD \
28478 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28479 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28480 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
28481
28482 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
28483 +{
28484 + unsigned int count = USER_PGD_PTRS;
28485
28486 + while (count--)
28487 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
28488 +}
28489 +#endif
28490 +
28491 +#ifdef CONFIG_PAX_PER_CPU_PGD
28492 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
28493 +{
28494 + unsigned int count = USER_PGD_PTRS;
28495 +
28496 + while (count--) {
28497 + pgd_t pgd;
28498 +
28499 +#ifdef CONFIG_X86_64
28500 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
28501 +#else
28502 + pgd = *src++;
28503 +#endif
28504 +
28505 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28506 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
28507 +#endif
28508 +
28509 + *dst++ = pgd;
28510 + }
28511 +
28512 +}
28513 +#endif
28514 +
28515 +#ifdef CONFIG_X86_64
28516 +#define pxd_t pud_t
28517 +#define pyd_t pgd_t
28518 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
28519 +#define pxd_free(mm, pud) pud_free((mm), (pud))
28520 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
28521 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
28522 +#define PYD_SIZE PGDIR_SIZE
28523 +#else
28524 +#define pxd_t pmd_t
28525 +#define pyd_t pud_t
28526 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
28527 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
28528 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
28529 +#define pyd_offset(mm, address) pud_offset((mm), (address))
28530 +#define PYD_SIZE PUD_SIZE
28531 +#endif
28532 +
28533 +#ifdef CONFIG_PAX_PER_CPU_PGD
28534 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
28535 +static inline void pgd_dtor(pgd_t *pgd) {}
28536 +#else
28537 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
28538 {
28539 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
28540 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
28541 pgd_list_del(pgd);
28542 spin_unlock(&pgd_lock);
28543 }
28544 +#endif
28545
28546 /*
28547 * List of all pgd's needed for non-PAE so it can invalidate entries
28548 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
28549 * -- nyc
28550 */
28551
28552 -#ifdef CONFIG_X86_PAE
28553 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
28554 /*
28555 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
28556 * updating the top-level pagetable entries to guarantee the
28557 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
28558 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
28559 * and initialize the kernel pmds here.
28560 */
28561 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
28562 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28563
28564 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28565 {
28566 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28567 */
28568 flush_tlb_mm(mm);
28569 }
28570 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
28571 +#define PREALLOCATED_PXDS USER_PGD_PTRS
28572 #else /* !CONFIG_X86_PAE */
28573
28574 /* No need to prepopulate any pagetable entries in non-PAE modes. */
28575 -#define PREALLOCATED_PMDS 0
28576 +#define PREALLOCATED_PXDS 0
28577
28578 #endif /* CONFIG_X86_PAE */
28579
28580 -static void free_pmds(pmd_t *pmds[])
28581 +static void free_pxds(pxd_t *pxds[])
28582 {
28583 int i;
28584
28585 - for(i = 0; i < PREALLOCATED_PMDS; i++)
28586 - if (pmds[i])
28587 - free_page((unsigned long)pmds[i]);
28588 + for(i = 0; i < PREALLOCATED_PXDS; i++)
28589 + if (pxds[i])
28590 + free_page((unsigned long)pxds[i]);
28591 }
28592
28593 -static int preallocate_pmds(pmd_t *pmds[])
28594 +static int preallocate_pxds(pxd_t *pxds[])
28595 {
28596 int i;
28597 bool failed = false;
28598
28599 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
28600 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
28601 - if (pmd == NULL)
28602 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
28603 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
28604 + if (pxd == NULL)
28605 failed = true;
28606 - pmds[i] = pmd;
28607 + pxds[i] = pxd;
28608 }
28609
28610 if (failed) {
28611 - free_pmds(pmds);
28612 + free_pxds(pxds);
28613 return -ENOMEM;
28614 }
28615
28616 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
28617 * preallocate which never got a corresponding vma will need to be
28618 * freed manually.
28619 */
28620 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
28621 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
28622 {
28623 int i;
28624
28625 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
28626 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
28627 pgd_t pgd = pgdp[i];
28628
28629 if (pgd_val(pgd) != 0) {
28630 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
28631 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
28632
28633 - pgdp[i] = native_make_pgd(0);
28634 + set_pgd(pgdp + i, native_make_pgd(0));
28635
28636 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
28637 - pmd_free(mm, pmd);
28638 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
28639 + pxd_free(mm, pxd);
28640 }
28641 }
28642 }
28643
28644 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
28645 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
28646 {
28647 - pud_t *pud;
28648 + pyd_t *pyd;
28649 unsigned long addr;
28650 int i;
28651
28652 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
28653 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
28654 return;
28655
28656 - pud = pud_offset(pgd, 0);
28657 +#ifdef CONFIG_X86_64
28658 + pyd = pyd_offset(mm, 0L);
28659 +#else
28660 + pyd = pyd_offset(pgd, 0L);
28661 +#endif
28662
28663 - for (addr = i = 0; i < PREALLOCATED_PMDS;
28664 - i++, pud++, addr += PUD_SIZE) {
28665 - pmd_t *pmd = pmds[i];
28666 + for (addr = i = 0; i < PREALLOCATED_PXDS;
28667 + i++, pyd++, addr += PYD_SIZE) {
28668 + pxd_t *pxd = pxds[i];
28669
28670 if (i >= KERNEL_PGD_BOUNDARY)
28671 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28672 - sizeof(pmd_t) * PTRS_PER_PMD);
28673 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28674 + sizeof(pxd_t) * PTRS_PER_PMD);
28675
28676 - pud_populate(mm, pud, pmd);
28677 + pyd_populate(mm, pyd, pxd);
28678 }
28679 }
28680
28681 pgd_t *pgd_alloc(struct mm_struct *mm)
28682 {
28683 pgd_t *pgd;
28684 - pmd_t *pmds[PREALLOCATED_PMDS];
28685 + pxd_t *pxds[PREALLOCATED_PXDS];
28686
28687 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
28688
28689 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28690
28691 mm->pgd = pgd;
28692
28693 - if (preallocate_pmds(pmds) != 0)
28694 + if (preallocate_pxds(pxds) != 0)
28695 goto out_free_pgd;
28696
28697 if (paravirt_pgd_alloc(mm) != 0)
28698 - goto out_free_pmds;
28699 + goto out_free_pxds;
28700
28701 /*
28702 * Make sure that pre-populating the pmds is atomic with
28703 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28704 spin_lock(&pgd_lock);
28705
28706 pgd_ctor(mm, pgd);
28707 - pgd_prepopulate_pmd(mm, pgd, pmds);
28708 + pgd_prepopulate_pxd(mm, pgd, pxds);
28709
28710 spin_unlock(&pgd_lock);
28711
28712 return pgd;
28713
28714 -out_free_pmds:
28715 - free_pmds(pmds);
28716 +out_free_pxds:
28717 + free_pxds(pxds);
28718 out_free_pgd:
28719 free_page((unsigned long)pgd);
28720 out:
28721 @@ -295,7 +356,7 @@ out:
28722
28723 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
28724 {
28725 - pgd_mop_up_pmds(mm, pgd);
28726 + pgd_mop_up_pxds(mm, pgd);
28727 pgd_dtor(pgd);
28728 paravirt_pgd_free(mm, pgd);
28729 free_page((unsigned long)pgd);
28730 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
28731 index a69bcb8..19068ab 100644
28732 --- a/arch/x86/mm/pgtable_32.c
28733 +++ b/arch/x86/mm/pgtable_32.c
28734 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
28735 return;
28736 }
28737 pte = pte_offset_kernel(pmd, vaddr);
28738 +
28739 + pax_open_kernel();
28740 if (pte_val(pteval))
28741 set_pte_at(&init_mm, vaddr, pte, pteval);
28742 else
28743 pte_clear(&init_mm, vaddr, pte);
28744 + pax_close_kernel();
28745
28746 /*
28747 * It's enough to flush this one mapping.
28748 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
28749 index 410531d..0f16030 100644
28750 --- a/arch/x86/mm/setup_nx.c
28751 +++ b/arch/x86/mm/setup_nx.c
28752 @@ -5,8 +5,10 @@
28753 #include <asm/pgtable.h>
28754 #include <asm/proto.h>
28755
28756 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28757 static int disable_nx __cpuinitdata;
28758
28759 +#ifndef CONFIG_PAX_PAGEEXEC
28760 /*
28761 * noexec = on|off
28762 *
28763 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
28764 return 0;
28765 }
28766 early_param("noexec", noexec_setup);
28767 +#endif
28768 +
28769 +#endif
28770
28771 void __cpuinit x86_configure_nx(void)
28772 {
28773 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28774 if (cpu_has_nx && !disable_nx)
28775 __supported_pte_mask |= _PAGE_NX;
28776 else
28777 +#endif
28778 __supported_pte_mask &= ~_PAGE_NX;
28779 }
28780
28781 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
28782 index 13a6b29..c2fff23 100644
28783 --- a/arch/x86/mm/tlb.c
28784 +++ b/arch/x86/mm/tlb.c
28785 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
28786 BUG();
28787 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
28788 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
28789 +
28790 +#ifndef CONFIG_PAX_PER_CPU_PGD
28791 load_cr3(swapper_pg_dir);
28792 +#endif
28793 +
28794 }
28795 }
28796 EXPORT_SYMBOL_GPL(leave_mm);
28797 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
28798 index 877b9a1..a8ecf42 100644
28799 --- a/arch/x86/net/bpf_jit.S
28800 +++ b/arch/x86/net/bpf_jit.S
28801 @@ -9,6 +9,7 @@
28802 */
28803 #include <linux/linkage.h>
28804 #include <asm/dwarf2.h>
28805 +#include <asm/alternative-asm.h>
28806
28807 /*
28808 * Calling convention :
28809 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
28810 jle bpf_slow_path_word
28811 mov (SKBDATA,%rsi),%eax
28812 bswap %eax /* ntohl() */
28813 + pax_force_retaddr
28814 ret
28815
28816 sk_load_half:
28817 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
28818 jle bpf_slow_path_half
28819 movzwl (SKBDATA,%rsi),%eax
28820 rol $8,%ax # ntohs()
28821 + pax_force_retaddr
28822 ret
28823
28824 sk_load_byte:
28825 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
28826 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
28827 jle bpf_slow_path_byte
28828 movzbl (SKBDATA,%rsi),%eax
28829 + pax_force_retaddr
28830 ret
28831
28832 /**
28833 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
28834 movzbl (SKBDATA,%rsi),%ebx
28835 and $15,%bl
28836 shl $2,%bl
28837 + pax_force_retaddr
28838 ret
28839
28840 /* rsi contains offset and can be scratched */
28841 @@ -109,6 +114,7 @@ bpf_slow_path_word:
28842 js bpf_error
28843 mov -12(%rbp),%eax
28844 bswap %eax
28845 + pax_force_retaddr
28846 ret
28847
28848 bpf_slow_path_half:
28849 @@ -117,12 +123,14 @@ bpf_slow_path_half:
28850 mov -12(%rbp),%ax
28851 rol $8,%ax
28852 movzwl %ax,%eax
28853 + pax_force_retaddr
28854 ret
28855
28856 bpf_slow_path_byte:
28857 bpf_slow_path_common(1)
28858 js bpf_error
28859 movzbl -12(%rbp),%eax
28860 + pax_force_retaddr
28861 ret
28862
28863 bpf_slow_path_byte_msh:
28864 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
28865 and $15,%al
28866 shl $2,%al
28867 xchg %eax,%ebx
28868 + pax_force_retaddr
28869 ret
28870
28871 #define sk_negative_common(SIZE) \
28872 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
28873 sk_negative_common(4)
28874 mov (%rax), %eax
28875 bswap %eax
28876 + pax_force_retaddr
28877 ret
28878
28879 bpf_slow_path_half_neg:
28880 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
28881 mov (%rax),%ax
28882 rol $8,%ax
28883 movzwl %ax,%eax
28884 + pax_force_retaddr
28885 ret
28886
28887 bpf_slow_path_byte_neg:
28888 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
28889 .globl sk_load_byte_negative_offset
28890 sk_negative_common(1)
28891 movzbl (%rax), %eax
28892 + pax_force_retaddr
28893 ret
28894
28895 bpf_slow_path_byte_msh_neg:
28896 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
28897 and $15,%al
28898 shl $2,%al
28899 xchg %eax,%ebx
28900 + pax_force_retaddr
28901 ret
28902
28903 bpf_error:
28904 @@ -197,4 +210,5 @@ bpf_error:
28905 xor %eax,%eax
28906 mov -8(%rbp),%rbx
28907 leaveq
28908 + pax_force_retaddr
28909 ret
28910 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
28911 index d11a470..3f9adff3 100644
28912 --- a/arch/x86/net/bpf_jit_comp.c
28913 +++ b/arch/x86/net/bpf_jit_comp.c
28914 @@ -12,6 +12,7 @@
28915 #include <linux/netdevice.h>
28916 #include <linux/filter.h>
28917 #include <linux/if_vlan.h>
28918 +#include <linux/random.h>
28919
28920 /*
28921 * Conventions :
28922 @@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
28923 return ptr + len;
28924 }
28925
28926 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28927 +#define MAX_INSTR_CODE_SIZE 96
28928 +#else
28929 +#define MAX_INSTR_CODE_SIZE 64
28930 +#endif
28931 +
28932 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
28933
28934 #define EMIT1(b1) EMIT(b1, 1)
28935 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
28936 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
28937 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
28938 +
28939 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28940 +/* original constant will appear in ecx */
28941 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
28942 +do { \
28943 + /* mov ecx, randkey */ \
28944 + EMIT1(0xb9); \
28945 + EMIT(_key, 4); \
28946 + /* xor ecx, randkey ^ off */ \
28947 + EMIT2(0x81, 0xf1); \
28948 + EMIT((_key) ^ (_off), 4); \
28949 +} while (0)
28950 +
28951 +#define EMIT1_off32(b1, _off) \
28952 +do { \
28953 + switch (b1) { \
28954 + case 0x05: /* add eax, imm32 */ \
28955 + case 0x2d: /* sub eax, imm32 */ \
28956 + case 0x25: /* and eax, imm32 */ \
28957 + case 0x0d: /* or eax, imm32 */ \
28958 + case 0xb8: /* mov eax, imm32 */ \
28959 + case 0x3d: /* cmp eax, imm32 */ \
28960 + case 0xa9: /* test eax, imm32 */ \
28961 + DILUTE_CONST_SEQUENCE(_off, randkey); \
28962 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
28963 + break; \
28964 + case 0xbb: /* mov ebx, imm32 */ \
28965 + DILUTE_CONST_SEQUENCE(_off, randkey); \
28966 + /* mov ebx, ecx */ \
28967 + EMIT2(0x89, 0xcb); \
28968 + break; \
28969 + case 0xbe: /* mov esi, imm32 */ \
28970 + DILUTE_CONST_SEQUENCE(_off, randkey); \
28971 + /* mov esi, ecx */ \
28972 + EMIT2(0x89, 0xce); \
28973 + break; \
28974 + case 0xe9: /* jmp rel imm32 */ \
28975 + EMIT1(b1); \
28976 + EMIT(_off, 4); \
28977 + /* prevent fall-through, we're not called if off = 0 */ \
28978 + EMIT(0xcccccccc, 4); \
28979 + EMIT(0xcccccccc, 4); \
28980 + break; \
28981 + default: \
28982 + EMIT1(b1); \
28983 + EMIT(_off, 4); \
28984 + } \
28985 +} while (0)
28986 +
28987 +#define EMIT2_off32(b1, b2, _off) \
28988 +do { \
28989 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
28990 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
28991 + EMIT(randkey, 4); \
28992 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
28993 + EMIT((_off) - randkey, 4); \
28994 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
28995 + DILUTE_CONST_SEQUENCE(_off, randkey); \
28996 + /* imul eax, ecx */ \
28997 + EMIT3(0x0f, 0xaf, 0xc1); \
28998 + } else { \
28999 + EMIT2(b1, b2); \
29000 + EMIT(_off, 4); \
29001 + } \
29002 +} while (0)
29003 +#else
29004 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29005 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29006 +#endif
29007
29008 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29009 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29010 @@ -90,6 +165,24 @@ do { \
29011 #define X86_JBE 0x76
29012 #define X86_JA 0x77
29013
29014 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29015 +#define APPEND_FLOW_VERIFY() \
29016 +do { \
29017 + /* mov ecx, randkey */ \
29018 + EMIT1(0xb9); \
29019 + EMIT(randkey, 4); \
29020 + /* cmp ecx, randkey */ \
29021 + EMIT2(0x81, 0xf9); \
29022 + EMIT(randkey, 4); \
29023 + /* jz after 8 int 3s */ \
29024 + EMIT2(0x74, 0x08); \
29025 + EMIT(0xcccccccc, 4); \
29026 + EMIT(0xcccccccc, 4); \
29027 +} while (0)
29028 +#else
29029 +#define APPEND_FLOW_VERIFY() do { } while (0)
29030 +#endif
29031 +
29032 #define EMIT_COND_JMP(op, offset) \
29033 do { \
29034 if (is_near(offset)) \
29035 @@ -97,6 +190,7 @@ do { \
29036 else { \
29037 EMIT2(0x0f, op + 0x10); \
29038 EMIT(offset, 4); /* jxx .+off32 */ \
29039 + APPEND_FLOW_VERIFY(); \
29040 } \
29041 } while (0)
29042
29043 @@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
29044 set_fs(old_fs);
29045 }
29046
29047 +struct bpf_jit_work {
29048 + struct work_struct work;
29049 + void *image;
29050 +};
29051 +
29052 #define CHOOSE_LOAD_FUNC(K, func) \
29053 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29054
29055 void bpf_jit_compile(struct sk_filter *fp)
29056 {
29057 - u8 temp[64];
29058 + u8 temp[MAX_INSTR_CODE_SIZE];
29059 u8 *prog;
29060 unsigned int proglen, oldproglen = 0;
29061 int ilen, i;
29062 @@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29063 unsigned int *addrs;
29064 const struct sock_filter *filter = fp->insns;
29065 int flen = fp->len;
29066 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29067 + unsigned int randkey;
29068 +#endif
29069
29070 if (!bpf_jit_enable)
29071 return;
29072 @@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29073 if (addrs == NULL)
29074 return;
29075
29076 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29077 + if (!fp->work)
29078 + goto out;
29079 +
29080 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29081 + randkey = get_random_int();
29082 +#endif
29083 +
29084 /* Before first pass, make a rough estimation of addrs[]
29085 - * each bpf instruction is translated to less than 64 bytes
29086 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29087 */
29088 for (proglen = 0, i = 0; i < flen; i++) {
29089 - proglen += 64;
29090 + proglen += MAX_INSTR_CODE_SIZE;
29091 addrs[i] = proglen;
29092 }
29093 cleanup_addr = proglen; /* epilogue address */
29094 @@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29095 case BPF_S_ALU_MUL_K: /* A *= K */
29096 if (is_imm8(K))
29097 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29098 - else {
29099 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29100 - EMIT(K, 4);
29101 - }
29102 + else
29103 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29104 break;
29105 case BPF_S_ALU_DIV_X: /* A /= X; */
29106 seen |= SEEN_XREG;
29107 @@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29108 break;
29109 case BPF_S_ALU_MOD_K: /* A %= K; */
29110 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29111 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29112 + DILUTE_CONST_SEQUENCE(K, randkey);
29113 +#else
29114 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29115 +#endif
29116 EMIT2(0xf7, 0xf1); /* div %ecx */
29117 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29118 break;
29119 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29120 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29121 + DILUTE_CONST_SEQUENCE(K, randkey);
29122 + // imul rax, rcx
29123 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29124 +#else
29125 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29126 EMIT(K, 4);
29127 +#endif
29128 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29129 break;
29130 case BPF_S_ALU_AND_X:
29131 @@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29132 if (is_imm8(K)) {
29133 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29134 } else {
29135 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29136 - EMIT(K, 4);
29137 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29138 }
29139 } else {
29140 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29141 @@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29142 break;
29143 default:
29144 /* hmm, too complex filter, give up with jit compiler */
29145 - goto out;
29146 + goto error;
29147 }
29148 ilen = prog - temp;
29149 if (image) {
29150 if (unlikely(proglen + ilen > oldproglen)) {
29151 pr_err("bpb_jit_compile fatal error\n");
29152 - kfree(addrs);
29153 - module_free(NULL, image);
29154 - return;
29155 + module_free_exec(NULL, image);
29156 + goto error;
29157 }
29158 + pax_open_kernel();
29159 memcpy(image + proglen, temp, ilen);
29160 + pax_close_kernel();
29161 }
29162 proglen += ilen;
29163 addrs[i] = proglen;
29164 @@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29165 break;
29166 }
29167 if (proglen == oldproglen) {
29168 - image = module_alloc(max_t(unsigned int,
29169 - proglen,
29170 - sizeof(struct work_struct)));
29171 + image = module_alloc_exec(proglen);
29172 if (!image)
29173 - goto out;
29174 + goto error;
29175 }
29176 oldproglen = proglen;
29177 }
29178 @@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29179 bpf_flush_icache(image, image + proglen);
29180
29181 fp->bpf_func = (void *)image;
29182 - }
29183 + } else
29184 +error:
29185 + kfree(fp->work);
29186 +
29187 out:
29188 kfree(addrs);
29189 return;
29190 @@ -707,18 +826,20 @@ out:
29191
29192 static void jit_free_defer(struct work_struct *arg)
29193 {
29194 - module_free(NULL, arg);
29195 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29196 + kfree(arg);
29197 }
29198
29199 /* run from softirq, we must use a work_struct to call
29200 - * module_free() from process context
29201 + * module_free_exec() from process context
29202 */
29203 void bpf_jit_free(struct sk_filter *fp)
29204 {
29205 if (fp->bpf_func != sk_run_filter) {
29206 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
29207 + struct work_struct *work = &fp->work->work;
29208
29209 INIT_WORK(work, jit_free_defer);
29210 + fp->work->image = fp->bpf_func;
29211 schedule_work(work);
29212 }
29213 }
29214 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29215 index d6aa6e8..266395a 100644
29216 --- a/arch/x86/oprofile/backtrace.c
29217 +++ b/arch/x86/oprofile/backtrace.c
29218 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29219 struct stack_frame_ia32 *fp;
29220 unsigned long bytes;
29221
29222 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29223 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29224 if (bytes != sizeof(bufhead))
29225 return NULL;
29226
29227 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29228 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29229
29230 oprofile_add_trace(bufhead[0].return_address);
29231
29232 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29233 struct stack_frame bufhead[2];
29234 unsigned long bytes;
29235
29236 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29237 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29238 if (bytes != sizeof(bufhead))
29239 return NULL;
29240
29241 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29242 {
29243 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29244
29245 - if (!user_mode_vm(regs)) {
29246 + if (!user_mode(regs)) {
29247 unsigned long stack = kernel_stack_pointer(regs);
29248 if (depth)
29249 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29250 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29251 index 48768df..ba9143c 100644
29252 --- a/arch/x86/oprofile/nmi_int.c
29253 +++ b/arch/x86/oprofile/nmi_int.c
29254 @@ -23,6 +23,7 @@
29255 #include <asm/nmi.h>
29256 #include <asm/msr.h>
29257 #include <asm/apic.h>
29258 +#include <asm/pgtable.h>
29259
29260 #include "op_counter.h"
29261 #include "op_x86_model.h"
29262 @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
29263 if (ret)
29264 return ret;
29265
29266 - if (!model->num_virt_counters)
29267 - model->num_virt_counters = model->num_counters;
29268 + if (!model->num_virt_counters) {
29269 + pax_open_kernel();
29270 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
29271 + pax_close_kernel();
29272 + }
29273
29274 mux_init(ops);
29275
29276 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
29277 index b2b9443..be58856 100644
29278 --- a/arch/x86/oprofile/op_model_amd.c
29279 +++ b/arch/x86/oprofile/op_model_amd.c
29280 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
29281 num_counters = AMD64_NUM_COUNTERS;
29282 }
29283
29284 - op_amd_spec.num_counters = num_counters;
29285 - op_amd_spec.num_controls = num_counters;
29286 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29287 + pax_open_kernel();
29288 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
29289 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
29290 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29291 + pax_close_kernel();
29292
29293 return 0;
29294 }
29295 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
29296 index d90528e..0127e2b 100644
29297 --- a/arch/x86/oprofile/op_model_ppro.c
29298 +++ b/arch/x86/oprofile/op_model_ppro.c
29299 @@ -19,6 +19,7 @@
29300 #include <asm/msr.h>
29301 #include <asm/apic.h>
29302 #include <asm/nmi.h>
29303 +#include <asm/pgtable.h>
29304
29305 #include "op_x86_model.h"
29306 #include "op_counter.h"
29307 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
29308
29309 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
29310
29311 - op_arch_perfmon_spec.num_counters = num_counters;
29312 - op_arch_perfmon_spec.num_controls = num_counters;
29313 + pax_open_kernel();
29314 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
29315 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
29316 + pax_close_kernel();
29317 }
29318
29319 static int arch_perfmon_init(struct oprofile_operations *ignore)
29320 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
29321 index 71e8a67..6a313bb 100644
29322 --- a/arch/x86/oprofile/op_x86_model.h
29323 +++ b/arch/x86/oprofile/op_x86_model.h
29324 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
29325 void (*switch_ctrl)(struct op_x86_model_spec const *model,
29326 struct op_msrs const * const msrs);
29327 #endif
29328 -};
29329 +} __do_const;
29330
29331 struct op_counter_config;
29332
29333 diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
29334 index e9e6ed5..e47ae67 100644
29335 --- a/arch/x86/pci/amd_bus.c
29336 +++ b/arch/x86/pci/amd_bus.c
29337 @@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
29338 return NOTIFY_OK;
29339 }
29340
29341 -static struct notifier_block __cpuinitdata amd_cpu_notifier = {
29342 +static struct notifier_block amd_cpu_notifier = {
29343 .notifier_call = amd_cpu_notify,
29344 };
29345
29346 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
29347 index 372e9b8..524dafd 100644
29348 --- a/arch/x86/pci/irq.c
29349 +++ b/arch/x86/pci/irq.c
29350 @@ -50,7 +50,7 @@ struct irq_router {
29351 struct irq_router_handler {
29352 u16 vendor;
29353 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
29354 -};
29355 +} __do_const;
29356
29357 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
29358 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
29359 @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
29360 return 0;
29361 }
29362
29363 -static __initdata struct irq_router_handler pirq_routers[] = {
29364 +static __initconst const struct irq_router_handler pirq_routers[] = {
29365 { PCI_VENDOR_ID_INTEL, intel_router_probe },
29366 { PCI_VENDOR_ID_AL, ali_router_probe },
29367 { PCI_VENDOR_ID_ITE, ite_router_probe },
29368 @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
29369 return 0;
29370 }
29371
29372 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
29373 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
29374 {
29375 .callback = fix_broken_hp_bios_irq9,
29376 .ident = "HP Pavilion N5400 Series Laptop",
29377 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
29378 index 6eb18c4..20d83de 100644
29379 --- a/arch/x86/pci/mrst.c
29380 +++ b/arch/x86/pci/mrst.c
29381 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
29382 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
29383 pci_mmcfg_late_init();
29384 pcibios_enable_irq = mrst_pci_irq_enable;
29385 - pci_root_ops = pci_mrst_ops;
29386 + pax_open_kernel();
29387 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
29388 + pax_close_kernel();
29389 pci_soc_mode = 1;
29390 /* Continue with standard init */
29391 return 1;
29392 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
29393 index c77b24a..c979855 100644
29394 --- a/arch/x86/pci/pcbios.c
29395 +++ b/arch/x86/pci/pcbios.c
29396 @@ -79,7 +79,7 @@ union bios32 {
29397 static struct {
29398 unsigned long address;
29399 unsigned short segment;
29400 -} bios32_indirect = { 0, __KERNEL_CS };
29401 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
29402
29403 /*
29404 * Returns the entry point for the given service, NULL on error
29405 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
29406 unsigned long length; /* %ecx */
29407 unsigned long entry; /* %edx */
29408 unsigned long flags;
29409 + struct desc_struct d, *gdt;
29410
29411 local_irq_save(flags);
29412 - __asm__("lcall *(%%edi); cld"
29413 +
29414 + gdt = get_cpu_gdt_table(smp_processor_id());
29415 +
29416 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
29417 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29418 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
29419 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29420 +
29421 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
29422 : "=a" (return_code),
29423 "=b" (address),
29424 "=c" (length),
29425 "=d" (entry)
29426 : "0" (service),
29427 "1" (0),
29428 - "D" (&bios32_indirect));
29429 + "D" (&bios32_indirect),
29430 + "r"(__PCIBIOS_DS)
29431 + : "memory");
29432 +
29433 + pax_open_kernel();
29434 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
29435 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
29436 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
29437 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
29438 + pax_close_kernel();
29439 +
29440 local_irq_restore(flags);
29441
29442 switch (return_code) {
29443 - case 0:
29444 - return address + entry;
29445 - case 0x80: /* Not present */
29446 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29447 - return 0;
29448 - default: /* Shouldn't happen */
29449 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29450 - service, return_code);
29451 + case 0: {
29452 + int cpu;
29453 + unsigned char flags;
29454 +
29455 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
29456 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
29457 + printk(KERN_WARNING "bios32_service: not valid\n");
29458 return 0;
29459 + }
29460 + address = address + PAGE_OFFSET;
29461 + length += 16UL; /* some BIOSs underreport this... */
29462 + flags = 4;
29463 + if (length >= 64*1024*1024) {
29464 + length >>= PAGE_SHIFT;
29465 + flags |= 8;
29466 + }
29467 +
29468 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
29469 + gdt = get_cpu_gdt_table(cpu);
29470 + pack_descriptor(&d, address, length, 0x9b, flags);
29471 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29472 + pack_descriptor(&d, address, length, 0x93, flags);
29473 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29474 + }
29475 + return entry;
29476 + }
29477 + case 0x80: /* Not present */
29478 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29479 + return 0;
29480 + default: /* Shouldn't happen */
29481 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29482 + service, return_code);
29483 + return 0;
29484 }
29485 }
29486
29487 static struct {
29488 unsigned long address;
29489 unsigned short segment;
29490 -} pci_indirect = { 0, __KERNEL_CS };
29491 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
29492
29493 -static int pci_bios_present;
29494 +static int pci_bios_present __read_only;
29495
29496 static int check_pcibios(void)
29497 {
29498 @@ -131,11 +174,13 @@ static int check_pcibios(void)
29499 unsigned long flags, pcibios_entry;
29500
29501 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
29502 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
29503 + pci_indirect.address = pcibios_entry;
29504
29505 local_irq_save(flags);
29506 - __asm__(
29507 - "lcall *(%%edi); cld\n\t"
29508 + __asm__("movw %w6, %%ds\n\t"
29509 + "lcall *%%ss:(%%edi); cld\n\t"
29510 + "push %%ss\n\t"
29511 + "pop %%ds\n\t"
29512 "jc 1f\n\t"
29513 "xor %%ah, %%ah\n"
29514 "1:"
29515 @@ -144,7 +189,8 @@ static int check_pcibios(void)
29516 "=b" (ebx),
29517 "=c" (ecx)
29518 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
29519 - "D" (&pci_indirect)
29520 + "D" (&pci_indirect),
29521 + "r" (__PCIBIOS_DS)
29522 : "memory");
29523 local_irq_restore(flags);
29524
29525 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29526
29527 switch (len) {
29528 case 1:
29529 - __asm__("lcall *(%%esi); cld\n\t"
29530 + __asm__("movw %w6, %%ds\n\t"
29531 + "lcall *%%ss:(%%esi); cld\n\t"
29532 + "push %%ss\n\t"
29533 + "pop %%ds\n\t"
29534 "jc 1f\n\t"
29535 "xor %%ah, %%ah\n"
29536 "1:"
29537 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29538 : "1" (PCIBIOS_READ_CONFIG_BYTE),
29539 "b" (bx),
29540 "D" ((long)reg),
29541 - "S" (&pci_indirect));
29542 + "S" (&pci_indirect),
29543 + "r" (__PCIBIOS_DS));
29544 /*
29545 * Zero-extend the result beyond 8 bits, do not trust the
29546 * BIOS having done it:
29547 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29548 *value &= 0xff;
29549 break;
29550 case 2:
29551 - __asm__("lcall *(%%esi); cld\n\t"
29552 + __asm__("movw %w6, %%ds\n\t"
29553 + "lcall *%%ss:(%%esi); cld\n\t"
29554 + "push %%ss\n\t"
29555 + "pop %%ds\n\t"
29556 "jc 1f\n\t"
29557 "xor %%ah, %%ah\n"
29558 "1:"
29559 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29560 : "1" (PCIBIOS_READ_CONFIG_WORD),
29561 "b" (bx),
29562 "D" ((long)reg),
29563 - "S" (&pci_indirect));
29564 + "S" (&pci_indirect),
29565 + "r" (__PCIBIOS_DS));
29566 /*
29567 * Zero-extend the result beyond 16 bits, do not trust the
29568 * BIOS having done it:
29569 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29570 *value &= 0xffff;
29571 break;
29572 case 4:
29573 - __asm__("lcall *(%%esi); cld\n\t"
29574 + __asm__("movw %w6, %%ds\n\t"
29575 + "lcall *%%ss:(%%esi); cld\n\t"
29576 + "push %%ss\n\t"
29577 + "pop %%ds\n\t"
29578 "jc 1f\n\t"
29579 "xor %%ah, %%ah\n"
29580 "1:"
29581 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29582 : "1" (PCIBIOS_READ_CONFIG_DWORD),
29583 "b" (bx),
29584 "D" ((long)reg),
29585 - "S" (&pci_indirect));
29586 + "S" (&pci_indirect),
29587 + "r" (__PCIBIOS_DS));
29588 break;
29589 }
29590
29591 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29592
29593 switch (len) {
29594 case 1:
29595 - __asm__("lcall *(%%esi); cld\n\t"
29596 + __asm__("movw %w6, %%ds\n\t"
29597 + "lcall *%%ss:(%%esi); cld\n\t"
29598 + "push %%ss\n\t"
29599 + "pop %%ds\n\t"
29600 "jc 1f\n\t"
29601 "xor %%ah, %%ah\n"
29602 "1:"
29603 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29604 "c" (value),
29605 "b" (bx),
29606 "D" ((long)reg),
29607 - "S" (&pci_indirect));
29608 + "S" (&pci_indirect),
29609 + "r" (__PCIBIOS_DS));
29610 break;
29611 case 2:
29612 - __asm__("lcall *(%%esi); cld\n\t"
29613 + __asm__("movw %w6, %%ds\n\t"
29614 + "lcall *%%ss:(%%esi); cld\n\t"
29615 + "push %%ss\n\t"
29616 + "pop %%ds\n\t"
29617 "jc 1f\n\t"
29618 "xor %%ah, %%ah\n"
29619 "1:"
29620 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29621 "c" (value),
29622 "b" (bx),
29623 "D" ((long)reg),
29624 - "S" (&pci_indirect));
29625 + "S" (&pci_indirect),
29626 + "r" (__PCIBIOS_DS));
29627 break;
29628 case 4:
29629 - __asm__("lcall *(%%esi); cld\n\t"
29630 + __asm__("movw %w6, %%ds\n\t"
29631 + "lcall *%%ss:(%%esi); cld\n\t"
29632 + "push %%ss\n\t"
29633 + "pop %%ds\n\t"
29634 "jc 1f\n\t"
29635 "xor %%ah, %%ah\n"
29636 "1:"
29637 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29638 "c" (value),
29639 "b" (bx),
29640 "D" ((long)reg),
29641 - "S" (&pci_indirect));
29642 + "S" (&pci_indirect),
29643 + "r" (__PCIBIOS_DS));
29644 break;
29645 }
29646
29647 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29648
29649 DBG("PCI: Fetching IRQ routing table... ");
29650 __asm__("push %%es\n\t"
29651 + "movw %w8, %%ds\n\t"
29652 "push %%ds\n\t"
29653 "pop %%es\n\t"
29654 - "lcall *(%%esi); cld\n\t"
29655 + "lcall *%%ss:(%%esi); cld\n\t"
29656 "pop %%es\n\t"
29657 + "push %%ss\n\t"
29658 + "pop %%ds\n"
29659 "jc 1f\n\t"
29660 "xor %%ah, %%ah\n"
29661 "1:"
29662 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29663 "1" (0),
29664 "D" ((long) &opt),
29665 "S" (&pci_indirect),
29666 - "m" (opt)
29667 + "m" (opt),
29668 + "r" (__PCIBIOS_DS)
29669 : "memory");
29670 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
29671 if (ret & 0xff00)
29672 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29673 {
29674 int ret;
29675
29676 - __asm__("lcall *(%%esi); cld\n\t"
29677 + __asm__("movw %w5, %%ds\n\t"
29678 + "lcall *%%ss:(%%esi); cld\n\t"
29679 + "push %%ss\n\t"
29680 + "pop %%ds\n"
29681 "jc 1f\n\t"
29682 "xor %%ah, %%ah\n"
29683 "1:"
29684 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29685 : "0" (PCIBIOS_SET_PCI_HW_INT),
29686 "b" ((dev->bus->number << 8) | dev->devfn),
29687 "c" ((irq << 8) | (pin + 10)),
29688 - "S" (&pci_indirect));
29689 + "S" (&pci_indirect),
29690 + "r" (__PCIBIOS_DS));
29691 return !(ret & 0xff00);
29692 }
29693 EXPORT_SYMBOL(pcibios_set_irq_routing);
29694 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
29695 index 40e4469..1ab536e 100644
29696 --- a/arch/x86/platform/efi/efi_32.c
29697 +++ b/arch/x86/platform/efi/efi_32.c
29698 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
29699 {
29700 struct desc_ptr gdt_descr;
29701
29702 +#ifdef CONFIG_PAX_KERNEXEC
29703 + struct desc_struct d;
29704 +#endif
29705 +
29706 local_irq_save(efi_rt_eflags);
29707
29708 load_cr3(initial_page_table);
29709 __flush_tlb_all();
29710
29711 +#ifdef CONFIG_PAX_KERNEXEC
29712 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
29713 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29714 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
29715 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29716 +#endif
29717 +
29718 gdt_descr.address = __pa(get_cpu_gdt_table(0));
29719 gdt_descr.size = GDT_SIZE - 1;
29720 load_gdt(&gdt_descr);
29721 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
29722 {
29723 struct desc_ptr gdt_descr;
29724
29725 +#ifdef CONFIG_PAX_KERNEXEC
29726 + struct desc_struct d;
29727 +
29728 + memset(&d, 0, sizeof d);
29729 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29730 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29731 +#endif
29732 +
29733 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
29734 gdt_descr.size = GDT_SIZE - 1;
29735 load_gdt(&gdt_descr);
29736 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
29737 index fbe66e6..eae5e38 100644
29738 --- a/arch/x86/platform/efi/efi_stub_32.S
29739 +++ b/arch/x86/platform/efi/efi_stub_32.S
29740 @@ -6,7 +6,9 @@
29741 */
29742
29743 #include <linux/linkage.h>
29744 +#include <linux/init.h>
29745 #include <asm/page_types.h>
29746 +#include <asm/segment.h>
29747
29748 /*
29749 * efi_call_phys(void *, ...) is a function with variable parameters.
29750 @@ -20,7 +22,7 @@
29751 * service functions will comply with gcc calling convention, too.
29752 */
29753
29754 -.text
29755 +__INIT
29756 ENTRY(efi_call_phys)
29757 /*
29758 * 0. The function can only be called in Linux kernel. So CS has been
29759 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
29760 * The mapping of lower virtual memory has been created in prelog and
29761 * epilog.
29762 */
29763 - movl $1f, %edx
29764 - subl $__PAGE_OFFSET, %edx
29765 - jmp *%edx
29766 +#ifdef CONFIG_PAX_KERNEXEC
29767 + movl $(__KERNEXEC_EFI_DS), %edx
29768 + mov %edx, %ds
29769 + mov %edx, %es
29770 + mov %edx, %ss
29771 + addl $2f,(1f)
29772 + ljmp *(1f)
29773 +
29774 +__INITDATA
29775 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
29776 +.previous
29777 +
29778 +2:
29779 + subl $2b,(1b)
29780 +#else
29781 + jmp 1f-__PAGE_OFFSET
29782 1:
29783 +#endif
29784
29785 /*
29786 * 2. Now on the top of stack is the return
29787 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
29788 * parameter 2, ..., param n. To make things easy, we save the return
29789 * address of efi_call_phys in a global variable.
29790 */
29791 - popl %edx
29792 - movl %edx, saved_return_addr
29793 - /* get the function pointer into ECX*/
29794 - popl %ecx
29795 - movl %ecx, efi_rt_function_ptr
29796 - movl $2f, %edx
29797 - subl $__PAGE_OFFSET, %edx
29798 - pushl %edx
29799 + popl (saved_return_addr)
29800 + popl (efi_rt_function_ptr)
29801
29802 /*
29803 * 3. Clear PG bit in %CR0.
29804 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
29805 /*
29806 * 5. Call the physical function.
29807 */
29808 - jmp *%ecx
29809 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
29810
29811 -2:
29812 /*
29813 * 6. After EFI runtime service returns, control will return to
29814 * following instruction. We'd better readjust stack pointer first.
29815 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
29816 movl %cr0, %edx
29817 orl $0x80000000, %edx
29818 movl %edx, %cr0
29819 - jmp 1f
29820 -1:
29821 +
29822 /*
29823 * 8. Now restore the virtual mode from flat mode by
29824 * adding EIP with PAGE_OFFSET.
29825 */
29826 - movl $1f, %edx
29827 - jmp *%edx
29828 +#ifdef CONFIG_PAX_KERNEXEC
29829 + movl $(__KERNEL_DS), %edx
29830 + mov %edx, %ds
29831 + mov %edx, %es
29832 + mov %edx, %ss
29833 + ljmp $(__KERNEL_CS),$1f
29834 +#else
29835 + jmp 1f+__PAGE_OFFSET
29836 +#endif
29837 1:
29838
29839 /*
29840 * 9. Balance the stack. And because EAX contain the return value,
29841 * we'd better not clobber it.
29842 */
29843 - leal efi_rt_function_ptr, %edx
29844 - movl (%edx), %ecx
29845 - pushl %ecx
29846 + pushl (efi_rt_function_ptr)
29847
29848 /*
29849 - * 10. Push the saved return address onto the stack and return.
29850 + * 10. Return to the saved return address.
29851 */
29852 - leal saved_return_addr, %edx
29853 - movl (%edx), %ecx
29854 - pushl %ecx
29855 - ret
29856 + jmpl *(saved_return_addr)
29857 ENDPROC(efi_call_phys)
29858 .previous
29859
29860 -.data
29861 +__INITDATA
29862 saved_return_addr:
29863 .long 0
29864 efi_rt_function_ptr:
29865 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
29866 index 4c07cca..2c8427d 100644
29867 --- a/arch/x86/platform/efi/efi_stub_64.S
29868 +++ b/arch/x86/platform/efi/efi_stub_64.S
29869 @@ -7,6 +7,7 @@
29870 */
29871
29872 #include <linux/linkage.h>
29873 +#include <asm/alternative-asm.h>
29874
29875 #define SAVE_XMM \
29876 mov %rsp, %rax; \
29877 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
29878 call *%rdi
29879 addq $32, %rsp
29880 RESTORE_XMM
29881 + pax_force_retaddr 0, 1
29882 ret
29883 ENDPROC(efi_call0)
29884
29885 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
29886 call *%rdi
29887 addq $32, %rsp
29888 RESTORE_XMM
29889 + pax_force_retaddr 0, 1
29890 ret
29891 ENDPROC(efi_call1)
29892
29893 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
29894 call *%rdi
29895 addq $32, %rsp
29896 RESTORE_XMM
29897 + pax_force_retaddr 0, 1
29898 ret
29899 ENDPROC(efi_call2)
29900
29901 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
29902 call *%rdi
29903 addq $32, %rsp
29904 RESTORE_XMM
29905 + pax_force_retaddr 0, 1
29906 ret
29907 ENDPROC(efi_call3)
29908
29909 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
29910 call *%rdi
29911 addq $32, %rsp
29912 RESTORE_XMM
29913 + pax_force_retaddr 0, 1
29914 ret
29915 ENDPROC(efi_call4)
29916
29917 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
29918 call *%rdi
29919 addq $48, %rsp
29920 RESTORE_XMM
29921 + pax_force_retaddr 0, 1
29922 ret
29923 ENDPROC(efi_call5)
29924
29925 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
29926 call *%rdi
29927 addq $48, %rsp
29928 RESTORE_XMM
29929 + pax_force_retaddr 0, 1
29930 ret
29931 ENDPROC(efi_call6)
29932 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
29933 index e31bcd8..f12dc46 100644
29934 --- a/arch/x86/platform/mrst/mrst.c
29935 +++ b/arch/x86/platform/mrst/mrst.c
29936 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
29937 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
29938 int sfi_mrtc_num;
29939
29940 -static void mrst_power_off(void)
29941 +static __noreturn void mrst_power_off(void)
29942 {
29943 + BUG();
29944 }
29945
29946 -static void mrst_reboot(void)
29947 +static __noreturn void mrst_reboot(void)
29948 {
29949 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
29950 + BUG();
29951 }
29952
29953 /* parse all the mtimer info to a static mtimer array */
29954 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
29955 index d6ee929..3637cb5 100644
29956 --- a/arch/x86/platform/olpc/olpc_dt.c
29957 +++ b/arch/x86/platform/olpc/olpc_dt.c
29958 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
29959 return res;
29960 }
29961
29962 -static struct of_pdt_ops prom_olpc_ops __initdata = {
29963 +static struct of_pdt_ops prom_olpc_ops __initconst = {
29964 .nextprop = olpc_dt_nextprop,
29965 .getproplen = olpc_dt_getproplen,
29966 .getproperty = olpc_dt_getproperty,
29967 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
29968 index 120cee1..b2db75a 100644
29969 --- a/arch/x86/power/cpu.c
29970 +++ b/arch/x86/power/cpu.c
29971 @@ -133,7 +133,7 @@ static void do_fpu_end(void)
29972 static void fix_processor_context(void)
29973 {
29974 int cpu = smp_processor_id();
29975 - struct tss_struct *t = &per_cpu(init_tss, cpu);
29976 + struct tss_struct *t = init_tss + cpu;
29977
29978 set_tss_desc(cpu, t); /*
29979 * This just modifies memory; should not be
29980 @@ -143,8 +143,6 @@ static void fix_processor_context(void)
29981 */
29982
29983 #ifdef CONFIG_X86_64
29984 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
29985 -
29986 syscall_init(); /* This sets MSR_*STAR and related */
29987 #endif
29988 load_TR_desc(); /* This does ltr */
29989 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
29990 index cbca565..bae7133 100644
29991 --- a/arch/x86/realmode/init.c
29992 +++ b/arch/x86/realmode/init.c
29993 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
29994 __va(real_mode_header->trampoline_header);
29995
29996 #ifdef CONFIG_X86_32
29997 - trampoline_header->start = __pa(startup_32_smp);
29998 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
29999 +
30000 +#ifdef CONFIG_PAX_KERNEXEC
30001 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30002 +#endif
30003 +
30004 + trampoline_header->boot_cs = __BOOT_CS;
30005 trampoline_header->gdt_limit = __BOOT_DS + 7;
30006 trampoline_header->gdt_base = __pa(boot_gdt);
30007 #else
30008 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30009 index 8869287..d577672 100644
30010 --- a/arch/x86/realmode/rm/Makefile
30011 +++ b/arch/x86/realmode/rm/Makefile
30012 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30013 $(call cc-option, -fno-unit-at-a-time)) \
30014 $(call cc-option, -fno-stack-protector) \
30015 $(call cc-option, -mpreferred-stack-boundary=2)
30016 +ifdef CONSTIFY_PLUGIN
30017 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30018 +endif
30019 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30020 GCOV_PROFILE := n
30021 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30022 index a28221d..93c40f1 100644
30023 --- a/arch/x86/realmode/rm/header.S
30024 +++ b/arch/x86/realmode/rm/header.S
30025 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30026 #endif
30027 /* APM/BIOS reboot */
30028 .long pa_machine_real_restart_asm
30029 -#ifdef CONFIG_X86_64
30030 +#ifdef CONFIG_X86_32
30031 + .long __KERNEL_CS
30032 +#else
30033 .long __KERNEL32_CS
30034 #endif
30035 END(real_mode_header)
30036 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30037 index c1b2791..f9e31c7 100644
30038 --- a/arch/x86/realmode/rm/trampoline_32.S
30039 +++ b/arch/x86/realmode/rm/trampoline_32.S
30040 @@ -25,6 +25,12 @@
30041 #include <asm/page_types.h>
30042 #include "realmode.h"
30043
30044 +#ifdef CONFIG_PAX_KERNEXEC
30045 +#define ta(X) (X)
30046 +#else
30047 +#define ta(X) (pa_ ## X)
30048 +#endif
30049 +
30050 .text
30051 .code16
30052
30053 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30054
30055 cli # We should be safe anyway
30056
30057 - movl tr_start, %eax # where we need to go
30058 -
30059 movl $0xA5A5A5A5, trampoline_status
30060 # write marker for master knows we're running
30061
30062 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30063 movw $1, %dx # protected mode (PE) bit
30064 lmsw %dx # into protected mode
30065
30066 - ljmpl $__BOOT_CS, $pa_startup_32
30067 + ljmpl *(trampoline_header)
30068
30069 .section ".text32","ax"
30070 .code32
30071 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30072 .balign 8
30073 GLOBAL(trampoline_header)
30074 tr_start: .space 4
30075 - tr_gdt_pad: .space 2
30076 + tr_boot_cs: .space 2
30077 tr_gdt: .space 6
30078 END(trampoline_header)
30079
30080 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30081 index bb360dc..3e5945f 100644
30082 --- a/arch/x86/realmode/rm/trampoline_64.S
30083 +++ b/arch/x86/realmode/rm/trampoline_64.S
30084 @@ -107,7 +107,7 @@ ENTRY(startup_32)
30085 wrmsr
30086
30087 # Enable paging and in turn activate Long Mode
30088 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30089 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
30090 movl %eax, %cr0
30091
30092 /*
30093 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30094 index 79d67bd..c7e1b90 100644
30095 --- a/arch/x86/tools/relocs.c
30096 +++ b/arch/x86/tools/relocs.c
30097 @@ -12,10 +12,13 @@
30098 #include <regex.h>
30099 #include <tools/le_byteshift.h>
30100
30101 +#include "../../../include/generated/autoconf.h"
30102 +
30103 static void die(char *fmt, ...);
30104
30105 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
30106 static Elf32_Ehdr ehdr;
30107 +static Elf32_Phdr *phdr;
30108 static unsigned long reloc_count, reloc_idx;
30109 static unsigned long *relocs;
30110 static unsigned long reloc16_count, reloc16_idx;
30111 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
30112 }
30113 }
30114
30115 +static void read_phdrs(FILE *fp)
30116 +{
30117 + unsigned int i;
30118 +
30119 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
30120 + if (!phdr) {
30121 + die("Unable to allocate %d program headers\n",
30122 + ehdr.e_phnum);
30123 + }
30124 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30125 + die("Seek to %d failed: %s\n",
30126 + ehdr.e_phoff, strerror(errno));
30127 + }
30128 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30129 + die("Cannot read ELF program headers: %s\n",
30130 + strerror(errno));
30131 + }
30132 + for(i = 0; i < ehdr.e_phnum; i++) {
30133 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
30134 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
30135 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
30136 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
30137 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
30138 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
30139 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
30140 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
30141 + }
30142 +
30143 +}
30144 +
30145 static void read_shdrs(FILE *fp)
30146 {
30147 - int i;
30148 + unsigned int i;
30149 Elf32_Shdr shdr;
30150
30151 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30152 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
30153
30154 static void read_strtabs(FILE *fp)
30155 {
30156 - int i;
30157 + unsigned int i;
30158 for (i = 0; i < ehdr.e_shnum; i++) {
30159 struct section *sec = &secs[i];
30160 if (sec->shdr.sh_type != SHT_STRTAB) {
30161 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
30162
30163 static void read_symtabs(FILE *fp)
30164 {
30165 - int i,j;
30166 + unsigned int i,j;
30167 for (i = 0; i < ehdr.e_shnum; i++) {
30168 struct section *sec = &secs[i];
30169 if (sec->shdr.sh_type != SHT_SYMTAB) {
30170 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
30171 }
30172
30173
30174 -static void read_relocs(FILE *fp)
30175 +static void read_relocs(FILE *fp, int use_real_mode)
30176 {
30177 - int i,j;
30178 + unsigned int i,j;
30179 + uint32_t base;
30180 +
30181 for (i = 0; i < ehdr.e_shnum; i++) {
30182 struct section *sec = &secs[i];
30183 if (sec->shdr.sh_type != SHT_REL) {
30184 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
30185 die("Cannot read symbol table: %s\n",
30186 strerror(errno));
30187 }
30188 + base = 0;
30189 +
30190 +#ifdef CONFIG_X86_32
30191 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
30192 + if (phdr[j].p_type != PT_LOAD )
30193 + continue;
30194 + 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)
30195 + continue;
30196 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
30197 + break;
30198 + }
30199 +#endif
30200 +
30201 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
30202 Elf32_Rel *rel = &sec->reltab[j];
30203 - rel->r_offset = elf32_to_cpu(rel->r_offset);
30204 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
30205 rel->r_info = elf32_to_cpu(rel->r_info);
30206 }
30207 }
30208 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
30209
30210 static void print_absolute_symbols(void)
30211 {
30212 - int i;
30213 + unsigned int i;
30214 printf("Absolute symbols\n");
30215 printf(" Num: Value Size Type Bind Visibility Name\n");
30216 for (i = 0; i < ehdr.e_shnum; i++) {
30217 struct section *sec = &secs[i];
30218 char *sym_strtab;
30219 - int j;
30220 + unsigned int j;
30221
30222 if (sec->shdr.sh_type != SHT_SYMTAB) {
30223 continue;
30224 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
30225
30226 static void print_absolute_relocs(void)
30227 {
30228 - int i, printed = 0;
30229 + unsigned int i, printed = 0;
30230
30231 for (i = 0; i < ehdr.e_shnum; i++) {
30232 struct section *sec = &secs[i];
30233 struct section *sec_applies, *sec_symtab;
30234 char *sym_strtab;
30235 Elf32_Sym *sh_symtab;
30236 - int j;
30237 + unsigned int j;
30238 if (sec->shdr.sh_type != SHT_REL) {
30239 continue;
30240 }
30241 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
30242 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30243 int use_real_mode)
30244 {
30245 - int i;
30246 + unsigned int i;
30247 /* Walk through the relocations */
30248 for (i = 0; i < ehdr.e_shnum; i++) {
30249 char *sym_strtab;
30250 Elf32_Sym *sh_symtab;
30251 struct section *sec_applies, *sec_symtab;
30252 - int j;
30253 + unsigned int j;
30254 struct section *sec = &secs[i];
30255
30256 if (sec->shdr.sh_type != SHT_REL) {
30257 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30258 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
30259 r_type = ELF32_R_TYPE(rel->r_info);
30260
30261 + if (!use_real_mode) {
30262 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
30263 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
30264 + continue;
30265 +
30266 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
30267 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
30268 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
30269 + continue;
30270 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
30271 + continue;
30272 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
30273 + continue;
30274 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
30275 + continue;
30276 +#endif
30277 + }
30278 +
30279 shn_abs = sym->st_shndx == SHN_ABS;
30280
30281 switch (r_type) {
30282 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
30283
30284 static void emit_relocs(int as_text, int use_real_mode)
30285 {
30286 - int i;
30287 + unsigned int i;
30288 /* Count how many relocations I have and allocate space for them. */
30289 reloc_count = 0;
30290 walk_relocs(count_reloc, use_real_mode);
30291 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
30292 fname, strerror(errno));
30293 }
30294 read_ehdr(fp);
30295 + read_phdrs(fp);
30296 read_shdrs(fp);
30297 read_strtabs(fp);
30298 read_symtabs(fp);
30299 - read_relocs(fp);
30300 + read_relocs(fp, use_real_mode);
30301 if (show_absolute_syms) {
30302 print_absolute_symbols();
30303 goto out;
30304 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
30305 index fd14be1..e3c79c0 100644
30306 --- a/arch/x86/vdso/Makefile
30307 +++ b/arch/x86/vdso/Makefile
30308 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
30309 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
30310 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
30311
30312 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30313 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30314 GCOV_PROFILE := n
30315
30316 #
30317 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
30318 index 0faad64..39ef157 100644
30319 --- a/arch/x86/vdso/vdso32-setup.c
30320 +++ b/arch/x86/vdso/vdso32-setup.c
30321 @@ -25,6 +25,7 @@
30322 #include <asm/tlbflush.h>
30323 #include <asm/vdso.h>
30324 #include <asm/proto.h>
30325 +#include <asm/mman.h>
30326
30327 enum {
30328 VDSO_DISABLED = 0,
30329 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
30330 void enable_sep_cpu(void)
30331 {
30332 int cpu = get_cpu();
30333 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
30334 + struct tss_struct *tss = init_tss + cpu;
30335
30336 if (!boot_cpu_has(X86_FEATURE_SEP)) {
30337 put_cpu();
30338 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
30339 gate_vma.vm_start = FIXADDR_USER_START;
30340 gate_vma.vm_end = FIXADDR_USER_END;
30341 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
30342 - gate_vma.vm_page_prot = __P101;
30343 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
30344
30345 return 0;
30346 }
30347 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30348 if (compat)
30349 addr = VDSO_HIGH_BASE;
30350 else {
30351 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
30352 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
30353 if (IS_ERR_VALUE(addr)) {
30354 ret = addr;
30355 goto up_fail;
30356 }
30357 }
30358
30359 - current->mm->context.vdso = (void *)addr;
30360 + current->mm->context.vdso = addr;
30361
30362 if (compat_uses_vma || !compat) {
30363 /*
30364 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30365 }
30366
30367 current_thread_info()->sysenter_return =
30368 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30369 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30370
30371 up_fail:
30372 if (ret)
30373 - current->mm->context.vdso = NULL;
30374 + current->mm->context.vdso = 0;
30375
30376 up_write(&mm->mmap_sem);
30377
30378 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
30379
30380 const char *arch_vma_name(struct vm_area_struct *vma)
30381 {
30382 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30383 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30384 return "[vdso]";
30385 +
30386 +#ifdef CONFIG_PAX_SEGMEXEC
30387 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
30388 + return "[vdso]";
30389 +#endif
30390 +
30391 return NULL;
30392 }
30393
30394 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30395 * Check to see if the corresponding task was created in compat vdso
30396 * mode.
30397 */
30398 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
30399 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
30400 return &gate_vma;
30401 return NULL;
30402 }
30403 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
30404 index 431e875..cbb23f3 100644
30405 --- a/arch/x86/vdso/vma.c
30406 +++ b/arch/x86/vdso/vma.c
30407 @@ -16,8 +16,6 @@
30408 #include <asm/vdso.h>
30409 #include <asm/page.h>
30410
30411 -unsigned int __read_mostly vdso_enabled = 1;
30412 -
30413 extern char vdso_start[], vdso_end[];
30414 extern unsigned short vdso_sync_cpuid;
30415
30416 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
30417 * unaligned here as a result of stack start randomization.
30418 */
30419 addr = PAGE_ALIGN(addr);
30420 - addr = align_vdso_addr(addr);
30421
30422 return addr;
30423 }
30424 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
30425 unsigned size)
30426 {
30427 struct mm_struct *mm = current->mm;
30428 - unsigned long addr;
30429 + unsigned long addr = 0;
30430 int ret;
30431
30432 - if (!vdso_enabled)
30433 - return 0;
30434 -
30435 down_write(&mm->mmap_sem);
30436 +
30437 +#ifdef CONFIG_PAX_RANDMMAP
30438 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30439 +#endif
30440 +
30441 addr = vdso_addr(mm->start_stack, size);
30442 + addr = align_vdso_addr(addr);
30443 addr = get_unmapped_area(NULL, addr, size, 0, 0);
30444 if (IS_ERR_VALUE(addr)) {
30445 ret = addr;
30446 goto up_fail;
30447 }
30448
30449 - current->mm->context.vdso = (void *)addr;
30450 + mm->context.vdso = addr;
30451
30452 ret = install_special_mapping(mm, addr, size,
30453 VM_READ|VM_EXEC|
30454 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
30455 pages);
30456 - if (ret) {
30457 - current->mm->context.vdso = NULL;
30458 - goto up_fail;
30459 - }
30460 + if (ret)
30461 + mm->context.vdso = 0;
30462
30463 up_fail:
30464 up_write(&mm->mmap_sem);
30465 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30466 vdsox32_size);
30467 }
30468 #endif
30469 -
30470 -static __init int vdso_setup(char *s)
30471 -{
30472 - vdso_enabled = simple_strtoul(s, NULL, 0);
30473 - return 0;
30474 -}
30475 -__setup("vdso=", vdso_setup);
30476 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
30477 index e014092..c76ab69 100644
30478 --- a/arch/x86/xen/enlighten.c
30479 +++ b/arch/x86/xen/enlighten.c
30480 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
30481
30482 struct shared_info xen_dummy_shared_info;
30483
30484 -void *xen_initial_gdt;
30485 -
30486 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
30487 __read_mostly int xen_have_vector_callback;
30488 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
30489 @@ -495,8 +493,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
30490 {
30491 unsigned long va = dtr->address;
30492 unsigned int size = dtr->size + 1;
30493 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30494 - unsigned long frames[pages];
30495 + unsigned long frames[65536 / PAGE_SIZE];
30496 int f;
30497
30498 /*
30499 @@ -544,8 +541,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
30500 {
30501 unsigned long va = dtr->address;
30502 unsigned int size = dtr->size + 1;
30503 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30504 - unsigned long frames[pages];
30505 + unsigned long frames[65536 / PAGE_SIZE];
30506 int f;
30507
30508 /*
30509 @@ -938,7 +934,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
30510 return 0;
30511 }
30512
30513 -static void set_xen_basic_apic_ops(void)
30514 +static void __init set_xen_basic_apic_ops(void)
30515 {
30516 apic->read = xen_apic_read;
30517 apic->write = xen_apic_write;
30518 @@ -1244,30 +1240,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
30519 #endif
30520 };
30521
30522 -static void xen_reboot(int reason)
30523 +static __noreturn void xen_reboot(int reason)
30524 {
30525 struct sched_shutdown r = { .reason = reason };
30526
30527 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
30528 - BUG();
30529 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
30530 + BUG();
30531 }
30532
30533 -static void xen_restart(char *msg)
30534 +static __noreturn void xen_restart(char *msg)
30535 {
30536 xen_reboot(SHUTDOWN_reboot);
30537 }
30538
30539 -static void xen_emergency_restart(void)
30540 +static __noreturn void xen_emergency_restart(void)
30541 {
30542 xen_reboot(SHUTDOWN_reboot);
30543 }
30544
30545 -static void xen_machine_halt(void)
30546 +static __noreturn void xen_machine_halt(void)
30547 {
30548 xen_reboot(SHUTDOWN_poweroff);
30549 }
30550
30551 -static void xen_machine_power_off(void)
30552 +static __noreturn void xen_machine_power_off(void)
30553 {
30554 if (pm_power_off)
30555 pm_power_off();
30556 @@ -1369,7 +1365,17 @@ asmlinkage void __init xen_start_kernel(void)
30557 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
30558
30559 /* Work out if we support NX */
30560 - x86_configure_nx();
30561 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
30562 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
30563 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
30564 + unsigned l, h;
30565 +
30566 + __supported_pte_mask |= _PAGE_NX;
30567 + rdmsr(MSR_EFER, l, h);
30568 + l |= EFER_NX;
30569 + wrmsr(MSR_EFER, l, h);
30570 + }
30571 +#endif
30572
30573 xen_setup_features();
30574
30575 @@ -1398,14 +1404,7 @@ asmlinkage void __init xen_start_kernel(void)
30576 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
30577 }
30578
30579 - machine_ops = xen_machine_ops;
30580 -
30581 - /*
30582 - * The only reliable way to retain the initial address of the
30583 - * percpu gdt_page is to remember it here, so we can go and
30584 - * mark it RW later, when the initial percpu area is freed.
30585 - */
30586 - xen_initial_gdt = &per_cpu(gdt_page, 0);
30587 + memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
30588
30589 xen_smp_init();
30590
30591 @@ -1590,7 +1589,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
30592 return NOTIFY_OK;
30593 }
30594
30595 -static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
30596 +static struct notifier_block xen_hvm_cpu_notifier = {
30597 .notifier_call = xen_hvm_cpu_notify,
30598 };
30599
30600 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
30601 index 01de35c..0bda07b 100644
30602 --- a/arch/x86/xen/mmu.c
30603 +++ b/arch/x86/xen/mmu.c
30604 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30605 /* L3_k[510] -> level2_kernel_pgt
30606 * L3_i[511] -> level2_fixmap_pgt */
30607 convert_pfn_mfn(level3_kernel_pgt);
30608 + convert_pfn_mfn(level3_vmalloc_start_pgt);
30609 + convert_pfn_mfn(level3_vmalloc_end_pgt);
30610 + convert_pfn_mfn(level3_vmemmap_pgt);
30611
30612 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
30613 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
30614 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30615 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
30616 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
30617 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
30618 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
30619 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
30620 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
30621 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
30622 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
30623 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
30624 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
30625 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
30626
30627 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
30628 pv_mmu_ops.set_pud = xen_set_pud;
30629 #if PAGETABLE_LEVELS == 4
30630 pv_mmu_ops.set_pgd = xen_set_pgd;
30631 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
30632 #endif
30633
30634 /* This will work as long as patching hasn't happened yet
30635 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
30636 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
30637 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
30638 .set_pgd = xen_set_pgd_hyper,
30639 + .set_pgd_batched = xen_set_pgd_hyper,
30640
30641 .alloc_pud = xen_alloc_pmd_init,
30642 .release_pud = xen_release_pmd_init,
30643 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
30644 index 34bc4ce..c34aa24 100644
30645 --- a/arch/x86/xen/smp.c
30646 +++ b/arch/x86/xen/smp.c
30647 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
30648 {
30649 BUG_ON(smp_processor_id() != 0);
30650 native_smp_prepare_boot_cpu();
30651 -
30652 - /* We've switched to the "real" per-cpu gdt, so make sure the
30653 - old memory can be recycled */
30654 - make_lowmem_page_readwrite(xen_initial_gdt);
30655 -
30656 xen_filter_cpu_maps();
30657 xen_setup_vcpu_info_placement();
30658 }
30659 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
30660 gdt = get_cpu_gdt_table(cpu);
30661
30662 ctxt->flags = VGCF_IN_KERNEL;
30663 - ctxt->user_regs.ds = __USER_DS;
30664 - ctxt->user_regs.es = __USER_DS;
30665 + ctxt->user_regs.ds = __KERNEL_DS;
30666 + ctxt->user_regs.es = __KERNEL_DS;
30667 ctxt->user_regs.ss = __KERNEL_DS;
30668 #ifdef CONFIG_X86_32
30669 ctxt->user_regs.fs = __KERNEL_PERCPU;
30670 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
30671 + savesegment(gs, ctxt->user_regs.gs);
30672 #else
30673 ctxt->gs_base_kernel = per_cpu_offset(cpu);
30674 #endif
30675 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
30676 int rc;
30677
30678 per_cpu(current_task, cpu) = idle;
30679 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
30680 #ifdef CONFIG_X86_32
30681 irq_ctx_init(cpu);
30682 #else
30683 clear_tsk_thread_flag(idle, TIF_FORK);
30684 - per_cpu(kernel_stack, cpu) =
30685 - (unsigned long)task_stack_page(idle) -
30686 - KERNEL_STACK_OFFSET + THREAD_SIZE;
30687 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
30688 #endif
30689 xen_setup_runstate_info(cpu);
30690 xen_setup_timer(cpu);
30691 @@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
30692
30693 void __init xen_smp_init(void)
30694 {
30695 - smp_ops = xen_smp_ops;
30696 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
30697 xen_fill_possible_map();
30698 xen_init_spinlocks();
30699 }
30700 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
30701 index 33ca6e4..0ded929 100644
30702 --- a/arch/x86/xen/xen-asm_32.S
30703 +++ b/arch/x86/xen/xen-asm_32.S
30704 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
30705 ESP_OFFSET=4 # bytes pushed onto stack
30706
30707 /*
30708 - * Store vcpu_info pointer for easy access. Do it this way to
30709 - * avoid having to reload %fs
30710 + * Store vcpu_info pointer for easy access.
30711 */
30712 #ifdef CONFIG_SMP
30713 - GET_THREAD_INFO(%eax)
30714 - movl %ss:TI_cpu(%eax), %eax
30715 - movl %ss:__per_cpu_offset(,%eax,4), %eax
30716 - mov %ss:xen_vcpu(%eax), %eax
30717 + push %fs
30718 + mov $(__KERNEL_PERCPU), %eax
30719 + mov %eax, %fs
30720 + mov PER_CPU_VAR(xen_vcpu), %eax
30721 + pop %fs
30722 #else
30723 movl %ss:xen_vcpu, %eax
30724 #endif
30725 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
30726 index 7faed58..ba4427c 100644
30727 --- a/arch/x86/xen/xen-head.S
30728 +++ b/arch/x86/xen/xen-head.S
30729 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
30730 #ifdef CONFIG_X86_32
30731 mov %esi,xen_start_info
30732 mov $init_thread_union+THREAD_SIZE,%esp
30733 +#ifdef CONFIG_SMP
30734 + movl $cpu_gdt_table,%edi
30735 + movl $__per_cpu_load,%eax
30736 + movw %ax,__KERNEL_PERCPU + 2(%edi)
30737 + rorl $16,%eax
30738 + movb %al,__KERNEL_PERCPU + 4(%edi)
30739 + movb %ah,__KERNEL_PERCPU + 7(%edi)
30740 + movl $__per_cpu_end - 1,%eax
30741 + subl $__per_cpu_start,%eax
30742 + movw %ax,__KERNEL_PERCPU + 0(%edi)
30743 +#endif
30744 #else
30745 mov %rsi,xen_start_info
30746 mov $init_thread_union+THREAD_SIZE,%rsp
30747 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
30748 index a95b417..b6dbd0b 100644
30749 --- a/arch/x86/xen/xen-ops.h
30750 +++ b/arch/x86/xen/xen-ops.h
30751 @@ -10,8 +10,6 @@
30752 extern const char xen_hypervisor_callback[];
30753 extern const char xen_failsafe_callback[];
30754
30755 -extern void *xen_initial_gdt;
30756 -
30757 struct trap_info;
30758 void xen_copy_trap_info(struct trap_info *traps);
30759
30760 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
30761 index 525bd3d..ef888b1 100644
30762 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
30763 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
30764 @@ -119,9 +119,9 @@
30765 ----------------------------------------------------------------------*/
30766
30767 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
30768 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
30769 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
30770 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
30771 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30772
30773 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
30774 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
30775 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
30776 index 2f33760..835e50a 100644
30777 --- a/arch/xtensa/variants/fsf/include/variant/core.h
30778 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
30779 @@ -11,6 +11,7 @@
30780 #ifndef _XTENSA_CORE_H
30781 #define _XTENSA_CORE_H
30782
30783 +#include <linux/const.h>
30784
30785 /****************************************************************************
30786 Parameters Useful for Any Code, USER or PRIVILEGED
30787 @@ -112,9 +113,9 @@
30788 ----------------------------------------------------------------------*/
30789
30790 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30791 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30792 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30793 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30794 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30795
30796 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
30797 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
30798 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
30799 index af00795..2bb8105 100644
30800 --- a/arch/xtensa/variants/s6000/include/variant/core.h
30801 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
30802 @@ -11,6 +11,7 @@
30803 #ifndef _XTENSA_CORE_CONFIGURATION_H
30804 #define _XTENSA_CORE_CONFIGURATION_H
30805
30806 +#include <linux/const.h>
30807
30808 /****************************************************************************
30809 Parameters Useful for Any Code, USER or PRIVILEGED
30810 @@ -118,9 +119,9 @@
30811 ----------------------------------------------------------------------*/
30812
30813 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30814 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30815 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30816 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30817 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30818
30819 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
30820 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
30821 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
30822 index 58916af..eb9dbcf6 100644
30823 --- a/block/blk-iopoll.c
30824 +++ b/block/blk-iopoll.c
30825 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
30826 }
30827 EXPORT_SYMBOL(blk_iopoll_complete);
30828
30829 -static void blk_iopoll_softirq(struct softirq_action *h)
30830 +static void blk_iopoll_softirq(void)
30831 {
30832 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
30833 int rearm = 0, budget = blk_iopoll_budget;
30834 @@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
30835 return NOTIFY_OK;
30836 }
30837
30838 -static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
30839 +static struct notifier_block blk_iopoll_cpu_notifier = {
30840 .notifier_call = blk_iopoll_cpu_notify,
30841 };
30842
30843 diff --git a/block/blk-map.c b/block/blk-map.c
30844 index 623e1cd..ca1e109 100644
30845 --- a/block/blk-map.c
30846 +++ b/block/blk-map.c
30847 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
30848 if (!len || !kbuf)
30849 return -EINVAL;
30850
30851 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
30852 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
30853 if (do_copy)
30854 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
30855 else
30856 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
30857 index 467c8de..f3628c5 100644
30858 --- a/block/blk-softirq.c
30859 +++ b/block/blk-softirq.c
30860 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
30861 * Softirq action handler - move entries to local list and loop over them
30862 * while passing them to the queue registered handler.
30863 */
30864 -static void blk_done_softirq(struct softirq_action *h)
30865 +static void blk_done_softirq(void)
30866 {
30867 struct list_head *cpu_list, local_list;
30868
30869 @@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
30870 return NOTIFY_OK;
30871 }
30872
30873 -static struct notifier_block __cpuinitdata blk_cpu_notifier = {
30874 +static struct notifier_block blk_cpu_notifier = {
30875 .notifier_call = blk_cpu_notify,
30876 };
30877
30878 diff --git a/block/bsg.c b/block/bsg.c
30879 index ff64ae3..593560c 100644
30880 --- a/block/bsg.c
30881 +++ b/block/bsg.c
30882 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
30883 struct sg_io_v4 *hdr, struct bsg_device *bd,
30884 fmode_t has_write_perm)
30885 {
30886 + unsigned char tmpcmd[sizeof(rq->__cmd)];
30887 + unsigned char *cmdptr;
30888 +
30889 if (hdr->request_len > BLK_MAX_CDB) {
30890 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
30891 if (!rq->cmd)
30892 return -ENOMEM;
30893 - }
30894 + cmdptr = rq->cmd;
30895 + } else
30896 + cmdptr = tmpcmd;
30897
30898 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
30899 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
30900 hdr->request_len))
30901 return -EFAULT;
30902
30903 + if (cmdptr != rq->cmd)
30904 + memcpy(rq->cmd, cmdptr, hdr->request_len);
30905 +
30906 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
30907 if (blk_verify_command(rq->cmd, has_write_perm))
30908 return -EPERM;
30909 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
30910 index 7c668c8..db3521c 100644
30911 --- a/block/compat_ioctl.c
30912 +++ b/block/compat_ioctl.c
30913 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
30914 err |= __get_user(f->spec1, &uf->spec1);
30915 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
30916 err |= __get_user(name, &uf->name);
30917 - f->name = compat_ptr(name);
30918 + f->name = (void __force_kernel *)compat_ptr(name);
30919 if (err) {
30920 err = -EFAULT;
30921 goto out;
30922 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
30923 index b62fb88..bdab4c4 100644
30924 --- a/block/partitions/efi.c
30925 +++ b/block/partitions/efi.c
30926 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
30927 if (!gpt)
30928 return NULL;
30929
30930 + if (!le32_to_cpu(gpt->num_partition_entries))
30931 + return NULL;
30932 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
30933 + if (!pte)
30934 + return NULL;
30935 +
30936 count = le32_to_cpu(gpt->num_partition_entries) *
30937 le32_to_cpu(gpt->sizeof_partition_entry);
30938 - if (!count)
30939 - return NULL;
30940 - pte = kzalloc(count, GFP_KERNEL);
30941 - if (!pte)
30942 - return NULL;
30943 -
30944 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
30945 (u8 *) pte,
30946 count) < count) {
30947 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
30948 index 9a87daa..fb17486 100644
30949 --- a/block/scsi_ioctl.c
30950 +++ b/block/scsi_ioctl.c
30951 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
30952 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
30953 struct sg_io_hdr *hdr, fmode_t mode)
30954 {
30955 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
30956 + unsigned char tmpcmd[sizeof(rq->__cmd)];
30957 + unsigned char *cmdptr;
30958 +
30959 + if (rq->cmd != rq->__cmd)
30960 + cmdptr = rq->cmd;
30961 + else
30962 + cmdptr = tmpcmd;
30963 +
30964 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
30965 return -EFAULT;
30966 +
30967 + if (cmdptr != rq->cmd)
30968 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
30969 +
30970 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
30971 return -EPERM;
30972
30973 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
30974 int err;
30975 unsigned int in_len, out_len, bytes, opcode, cmdlen;
30976 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
30977 + unsigned char tmpcmd[sizeof(rq->__cmd)];
30978 + unsigned char *cmdptr;
30979
30980 if (!sic)
30981 return -EINVAL;
30982 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
30983 */
30984 err = -EFAULT;
30985 rq->cmd_len = cmdlen;
30986 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
30987 +
30988 + if (rq->cmd != rq->__cmd)
30989 + cmdptr = rq->cmd;
30990 + else
30991 + cmdptr = tmpcmd;
30992 +
30993 + if (copy_from_user(cmdptr, sic->data, cmdlen))
30994 goto error;
30995
30996 + if (rq->cmd != cmdptr)
30997 + memcpy(rq->cmd, cmdptr, cmdlen);
30998 +
30999 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31000 goto error;
31001
31002 diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
31003 index 533de95..7d4a8d2 100644
31004 --- a/crypto/ablkcipher.c
31005 +++ b/crypto/ablkcipher.c
31006 @@ -388,9 +388,9 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
31007 {
31008 struct crypto_report_blkcipher rblkcipher;
31009
31010 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "ablkcipher");
31011 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
31012 - alg->cra_ablkcipher.geniv ?: "<default>");
31013 + strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
31014 + strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>",
31015 + sizeof(rblkcipher.geniv));
31016
31017 rblkcipher.blocksize = alg->cra_blocksize;
31018 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
31019 @@ -469,9 +469,9 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
31020 {
31021 struct crypto_report_blkcipher rblkcipher;
31022
31023 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "givcipher");
31024 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
31025 - alg->cra_ablkcipher.geniv ?: "<built-in>");
31026 + strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type));
31027 + strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>",
31028 + sizeof(rblkcipher.geniv));
31029
31030 rblkcipher.blocksize = alg->cra_blocksize;
31031 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
31032 diff --git a/crypto/aead.c b/crypto/aead.c
31033 index 0b8121e..27bc487 100644
31034 --- a/crypto/aead.c
31035 +++ b/crypto/aead.c
31036 @@ -117,9 +117,8 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
31037 struct crypto_report_aead raead;
31038 struct aead_alg *aead = &alg->cra_aead;
31039
31040 - snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "aead");
31041 - snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s",
31042 - aead->geniv ?: "<built-in>");
31043 + strncpy(raead.type, "aead", sizeof(raead.type));
31044 + strncpy(raead.geniv, aead->geniv ?: "<built-in>", sizeof(raead.geniv));
31045
31046 raead.blocksize = alg->cra_blocksize;
31047 raead.maxauthsize = aead->maxauthsize;
31048 @@ -203,8 +202,8 @@ static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
31049 struct crypto_report_aead raead;
31050 struct aead_alg *aead = &alg->cra_aead;
31051
31052 - snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "nivaead");
31053 - snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s", aead->geniv);
31054 + strncpy(raead.type, "nivaead", sizeof(raead.type));
31055 + strncpy(raead.geniv, aead->geniv, sizeof(raead.geniv));
31056
31057 raead.blocksize = alg->cra_blocksize;
31058 raead.maxauthsize = aead->maxauthsize;
31059 diff --git a/crypto/ahash.c b/crypto/ahash.c
31060 index 3887856..793a27f 100644
31061 --- a/crypto/ahash.c
31062 +++ b/crypto/ahash.c
31063 @@ -404,7 +404,7 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
31064 {
31065 struct crypto_report_hash rhash;
31066
31067 - snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "ahash");
31068 + strncpy(rhash.type, "ahash", sizeof(rhash.type));
31069
31070 rhash.blocksize = alg->cra_blocksize;
31071 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
31072 diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
31073 index a8d85a1..c44e014 100644
31074 --- a/crypto/blkcipher.c
31075 +++ b/crypto/blkcipher.c
31076 @@ -499,9 +499,9 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
31077 {
31078 struct crypto_report_blkcipher rblkcipher;
31079
31080 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "blkcipher");
31081 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
31082 - alg->cra_blkcipher.geniv ?: "<default>");
31083 + strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type));
31084 + strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>",
31085 + sizeof(rblkcipher.geniv));
31086
31087 rblkcipher.blocksize = alg->cra_blocksize;
31088 rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
31089 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31090 index 7bdd61b..afec999 100644
31091 --- a/crypto/cryptd.c
31092 +++ b/crypto/cryptd.c
31093 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31094
31095 struct cryptd_blkcipher_request_ctx {
31096 crypto_completion_t complete;
31097 -};
31098 +} __no_const;
31099
31100 struct cryptd_hash_ctx {
31101 struct crypto_shash *child;
31102 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31103
31104 struct cryptd_aead_request_ctx {
31105 crypto_completion_t complete;
31106 -};
31107 +} __no_const;
31108
31109 static void cryptd_queue_worker(struct work_struct *work);
31110
31111 diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
31112 index 35d700a..dfd511f 100644
31113 --- a/crypto/crypto_user.c
31114 +++ b/crypto/crypto_user.c
31115 @@ -30,6 +30,8 @@
31116
31117 #include "internal.h"
31118
31119 +#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
31120 +
31121 static DEFINE_MUTEX(crypto_cfg_mutex);
31122
31123 /* The crypto netlink socket */
31124 @@ -75,7 +77,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
31125 {
31126 struct crypto_report_cipher rcipher;
31127
31128 - snprintf(rcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "cipher");
31129 + strncpy(rcipher.type, "cipher", sizeof(rcipher.type));
31130
31131 rcipher.blocksize = alg->cra_blocksize;
31132 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
31133 @@ -94,8 +96,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
31134 {
31135 struct crypto_report_comp rcomp;
31136
31137 - snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression");
31138 -
31139 + strncpy(rcomp.type, "compression", sizeof(rcomp.type));
31140 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
31141 sizeof(struct crypto_report_comp), &rcomp))
31142 goto nla_put_failure;
31143 @@ -108,12 +109,14 @@ nla_put_failure:
31144 static int crypto_report_one(struct crypto_alg *alg,
31145 struct crypto_user_alg *ualg, struct sk_buff *skb)
31146 {
31147 - memcpy(&ualg->cru_name, &alg->cra_name, sizeof(ualg->cru_name));
31148 - memcpy(&ualg->cru_driver_name, &alg->cra_driver_name,
31149 - sizeof(ualg->cru_driver_name));
31150 - memcpy(&ualg->cru_module_name, module_name(alg->cra_module),
31151 - CRYPTO_MAX_ALG_NAME);
31152 + strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
31153 + strncpy(ualg->cru_driver_name, alg->cra_driver_name,
31154 + sizeof(ualg->cru_driver_name));
31155 + strncpy(ualg->cru_module_name, module_name(alg->cra_module),
31156 + sizeof(ualg->cru_module_name));
31157
31158 + ualg->cru_type = 0;
31159 + ualg->cru_mask = 0;
31160 ualg->cru_flags = alg->cra_flags;
31161 ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
31162
31163 @@ -122,8 +125,7 @@ static int crypto_report_one(struct crypto_alg *alg,
31164 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
31165 struct crypto_report_larval rl;
31166
31167 - snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval");
31168 -
31169 + strncpy(rl.type, "larval", sizeof(rl.type));
31170 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
31171 sizeof(struct crypto_report_larval), &rl))
31172 goto nla_put_failure;
31173 @@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
31174 struct crypto_dump_info info;
31175 int err;
31176
31177 - if (!p->cru_driver_name)
31178 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31179 + return -EINVAL;
31180 +
31181 + if (!p->cru_driver_name[0])
31182 return -EINVAL;
31183
31184 alg = crypto_alg_match(p, 1);
31185 @@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31186 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31187 LIST_HEAD(list);
31188
31189 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31190 + return -EINVAL;
31191 +
31192 if (priority && !strlen(p->cru_driver_name))
31193 return -EINVAL;
31194
31195 @@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31196 struct crypto_alg *alg;
31197 struct crypto_user_alg *p = nlmsg_data(nlh);
31198
31199 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31200 + return -EINVAL;
31201 +
31202 alg = crypto_alg_match(p, 1);
31203 if (!alg)
31204 return -ENOENT;
31205 @@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31206 struct crypto_user_alg *p = nlmsg_data(nlh);
31207 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31208
31209 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31210 + return -EINVAL;
31211 +
31212 if (strlen(p->cru_driver_name))
31213 exact = 1;
31214
31215 diff --git a/crypto/pcompress.c b/crypto/pcompress.c
31216 index 04e083f..7140fe7 100644
31217 --- a/crypto/pcompress.c
31218 +++ b/crypto/pcompress.c
31219 @@ -53,8 +53,7 @@ static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
31220 {
31221 struct crypto_report_comp rpcomp;
31222
31223 - snprintf(rpcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "pcomp");
31224 -
31225 + strncpy(rpcomp.type, "pcomp", sizeof(rpcomp.type));
31226 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
31227 sizeof(struct crypto_report_comp), &rpcomp))
31228 goto nla_put_failure;
31229 diff --git a/crypto/rng.c b/crypto/rng.c
31230 index f3b7894..e0a25c2 100644
31231 --- a/crypto/rng.c
31232 +++ b/crypto/rng.c
31233 @@ -65,7 +65,7 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
31234 {
31235 struct crypto_report_rng rrng;
31236
31237 - snprintf(rrng.type, CRYPTO_MAX_ALG_NAME, "%s", "rng");
31238 + strncpy(rrng.type, "rng", sizeof(rrng.type));
31239
31240 rrng.seedsize = alg->cra_rng.seedsize;
31241
31242 diff --git a/crypto/shash.c b/crypto/shash.c
31243 index f426330f..929058a 100644
31244 --- a/crypto/shash.c
31245 +++ b/crypto/shash.c
31246 @@ -530,7 +530,8 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
31247 struct crypto_report_hash rhash;
31248 struct shash_alg *salg = __crypto_shash_alg(alg);
31249
31250 - snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "shash");
31251 + strncpy(rhash.type, "shash", sizeof(rhash.type));
31252 +
31253 rhash.blocksize = alg->cra_blocksize;
31254 rhash.digestsize = salg->digestsize;
31255
31256 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31257 index f220d64..d359ad6 100644
31258 --- a/drivers/acpi/apei/apei-internal.h
31259 +++ b/drivers/acpi/apei/apei-internal.h
31260 @@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31261 struct apei_exec_ins_type {
31262 u32 flags;
31263 apei_exec_ins_func_t run;
31264 -};
31265 +} __do_const;
31266
31267 struct apei_exec_context {
31268 u32 ip;
31269 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31270 index e6defd8..c26a225 100644
31271 --- a/drivers/acpi/apei/cper.c
31272 +++ b/drivers/acpi/apei/cper.c
31273 @@ -38,12 +38,12 @@
31274 */
31275 u64 cper_next_record_id(void)
31276 {
31277 - static atomic64_t seq;
31278 + static atomic64_unchecked_t seq;
31279
31280 - if (!atomic64_read(&seq))
31281 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
31282 + if (!atomic64_read_unchecked(&seq))
31283 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31284
31285 - return atomic64_inc_return(&seq);
31286 + return atomic64_inc_return_unchecked(&seq);
31287 }
31288 EXPORT_SYMBOL_GPL(cper_next_record_id);
31289
31290 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31291 index be60399..778b33e8 100644
31292 --- a/drivers/acpi/bgrt.c
31293 +++ b/drivers/acpi/bgrt.c
31294 @@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31295 return -ENODEV;
31296
31297 sysfs_bin_attr_init(&image_attr);
31298 - image_attr.private = bgrt_image;
31299 - image_attr.size = bgrt_image_size;
31300 + pax_open_kernel();
31301 + *(void **)&image_attr.private = bgrt_image;
31302 + *(size_t *)&image_attr.size = bgrt_image_size;
31303 + pax_close_kernel();
31304
31305 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31306 if (!bgrt_kobj)
31307 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31308 index cb96296..2d6082b 100644
31309 --- a/drivers/acpi/blacklist.c
31310 +++ b/drivers/acpi/blacklist.c
31311 @@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31312 return 0;
31313 }
31314
31315 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
31316 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
31317 {
31318 .callback = dmi_disable_osi_vista,
31319 .ident = "Fujitsu Siemens",
31320 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31321 index 7586544..636a2f0 100644
31322 --- a/drivers/acpi/ec_sys.c
31323 +++ b/drivers/acpi/ec_sys.c
31324 @@ -12,6 +12,7 @@
31325 #include <linux/acpi.h>
31326 #include <linux/debugfs.h>
31327 #include <linux/module.h>
31328 +#include <linux/uaccess.h>
31329 #include "internal.h"
31330
31331 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31332 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31333 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31334 */
31335 unsigned int size = EC_SPACE_SIZE;
31336 - u8 *data = (u8 *) buf;
31337 + u8 data;
31338 loff_t init_off = *off;
31339 int err = 0;
31340
31341 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31342 size = count;
31343
31344 while (size) {
31345 - err = ec_read(*off, &data[*off - init_off]);
31346 + err = ec_read(*off, &data);
31347 if (err)
31348 return err;
31349 + if (put_user(data, &buf[*off - init_off]))
31350 + return -EFAULT;
31351 *off += 1;
31352 size--;
31353 }
31354 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31355
31356 unsigned int size = count;
31357 loff_t init_off = *off;
31358 - u8 *data = (u8 *) buf;
31359 int err = 0;
31360
31361 if (*off >= EC_SPACE_SIZE)
31362 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31363 }
31364
31365 while (size) {
31366 - u8 byte_write = data[*off - init_off];
31367 + u8 byte_write;
31368 + if (get_user(byte_write, &buf[*off - init_off]))
31369 + return -EFAULT;
31370 err = ec_write(*off, byte_write);
31371 if (err)
31372 return err;
31373 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
31374 index e83311b..142b5cc 100644
31375 --- a/drivers/acpi/processor_driver.c
31376 +++ b/drivers/acpi/processor_driver.c
31377 @@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
31378 return 0;
31379 #endif
31380
31381 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
31382 + BUG_ON(pr->id >= nr_cpu_ids);
31383
31384 /*
31385 * Buggy BIOS check
31386 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
31387 index ed9a1cc..f4a354c 100644
31388 --- a/drivers/acpi/processor_idle.c
31389 +++ b/drivers/acpi/processor_idle.c
31390 @@ -1005,7 +1005,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
31391 {
31392 int i, count = CPUIDLE_DRIVER_STATE_START;
31393 struct acpi_processor_cx *cx;
31394 - struct cpuidle_state *state;
31395 + cpuidle_state_no_const *state;
31396 struct cpuidle_driver *drv = &acpi_idle_driver;
31397
31398 if (!pr->flags.power_setup_done)
31399 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
31400 index ea61ca9..3fdd70d 100644
31401 --- a/drivers/acpi/sysfs.c
31402 +++ b/drivers/acpi/sysfs.c
31403 @@ -420,11 +420,11 @@ static u32 num_counters;
31404 static struct attribute **all_attrs;
31405 static u32 acpi_gpe_count;
31406
31407 -static struct attribute_group interrupt_stats_attr_group = {
31408 +static attribute_group_no_const interrupt_stats_attr_group = {
31409 .name = "interrupts",
31410 };
31411
31412 -static struct kobj_attribute *counter_attrs;
31413 +static kobj_attribute_no_const *counter_attrs;
31414
31415 static void delete_gpe_attr_array(void)
31416 {
31417 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
31418 index 46cd3f4..0871ad0 100644
31419 --- a/drivers/ata/libata-core.c
31420 +++ b/drivers/ata/libata-core.c
31421 @@ -4780,7 +4780,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
31422 struct ata_port *ap;
31423 unsigned int tag;
31424
31425 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31426 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31427 ap = qc->ap;
31428
31429 qc->flags = 0;
31430 @@ -4796,7 +4796,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
31431 struct ata_port *ap;
31432 struct ata_link *link;
31433
31434 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31435 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31436 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31437 ap = qc->ap;
31438 link = qc->dev->link;
31439 @@ -5892,6 +5892,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31440 return;
31441
31442 spin_lock(&lock);
31443 + pax_open_kernel();
31444
31445 for (cur = ops->inherits; cur; cur = cur->inherits) {
31446 void **inherit = (void **)cur;
31447 @@ -5905,8 +5906,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31448 if (IS_ERR(*pp))
31449 *pp = NULL;
31450
31451 - ops->inherits = NULL;
31452 + *(struct ata_port_operations **)&ops->inherits = NULL;
31453
31454 + pax_close_kernel();
31455 spin_unlock(&lock);
31456 }
31457
31458 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31459 index 405022d..fb70e53 100644
31460 --- a/drivers/ata/pata_arasan_cf.c
31461 +++ b/drivers/ata/pata_arasan_cf.c
31462 @@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31463 /* Handle platform specific quirks */
31464 if (pdata->quirk) {
31465 if (pdata->quirk & CF_BROKEN_PIO) {
31466 - ap->ops->set_piomode = NULL;
31467 + pax_open_kernel();
31468 + *(void **)&ap->ops->set_piomode = NULL;
31469 + pax_close_kernel();
31470 ap->pio_mask = 0;
31471 }
31472 if (pdata->quirk & CF_BROKEN_MWDMA)
31473 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31474 index f9b983a..887b9d8 100644
31475 --- a/drivers/atm/adummy.c
31476 +++ b/drivers/atm/adummy.c
31477 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31478 vcc->pop(vcc, skb);
31479 else
31480 dev_kfree_skb_any(skb);
31481 - atomic_inc(&vcc->stats->tx);
31482 + atomic_inc_unchecked(&vcc->stats->tx);
31483
31484 return 0;
31485 }
31486 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31487 index 77a7480..05cde58 100644
31488 --- a/drivers/atm/ambassador.c
31489 +++ b/drivers/atm/ambassador.c
31490 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31491 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31492
31493 // VC layer stats
31494 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31495 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31496
31497 // free the descriptor
31498 kfree (tx_descr);
31499 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31500 dump_skb ("<<<", vc, skb);
31501
31502 // VC layer stats
31503 - atomic_inc(&atm_vcc->stats->rx);
31504 + atomic_inc_unchecked(&atm_vcc->stats->rx);
31505 __net_timestamp(skb);
31506 // end of our responsibility
31507 atm_vcc->push (atm_vcc, skb);
31508 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31509 } else {
31510 PRINTK (KERN_INFO, "dropped over-size frame");
31511 // should we count this?
31512 - atomic_inc(&atm_vcc->stats->rx_drop);
31513 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31514 }
31515
31516 } else {
31517 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
31518 }
31519
31520 if (check_area (skb->data, skb->len)) {
31521 - atomic_inc(&atm_vcc->stats->tx_err);
31522 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
31523 return -ENOMEM; // ?
31524 }
31525
31526 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
31527 index b22d71c..d6e1049 100644
31528 --- a/drivers/atm/atmtcp.c
31529 +++ b/drivers/atm/atmtcp.c
31530 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31531 if (vcc->pop) vcc->pop(vcc,skb);
31532 else dev_kfree_skb(skb);
31533 if (dev_data) return 0;
31534 - atomic_inc(&vcc->stats->tx_err);
31535 + atomic_inc_unchecked(&vcc->stats->tx_err);
31536 return -ENOLINK;
31537 }
31538 size = skb->len+sizeof(struct atmtcp_hdr);
31539 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31540 if (!new_skb) {
31541 if (vcc->pop) vcc->pop(vcc,skb);
31542 else dev_kfree_skb(skb);
31543 - atomic_inc(&vcc->stats->tx_err);
31544 + atomic_inc_unchecked(&vcc->stats->tx_err);
31545 return -ENOBUFS;
31546 }
31547 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
31548 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31549 if (vcc->pop) vcc->pop(vcc,skb);
31550 else dev_kfree_skb(skb);
31551 out_vcc->push(out_vcc,new_skb);
31552 - atomic_inc(&vcc->stats->tx);
31553 - atomic_inc(&out_vcc->stats->rx);
31554 + atomic_inc_unchecked(&vcc->stats->tx);
31555 + atomic_inc_unchecked(&out_vcc->stats->rx);
31556 return 0;
31557 }
31558
31559 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31560 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
31561 read_unlock(&vcc_sklist_lock);
31562 if (!out_vcc) {
31563 - atomic_inc(&vcc->stats->tx_err);
31564 + atomic_inc_unchecked(&vcc->stats->tx_err);
31565 goto done;
31566 }
31567 skb_pull(skb,sizeof(struct atmtcp_hdr));
31568 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31569 __net_timestamp(new_skb);
31570 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
31571 out_vcc->push(out_vcc,new_skb);
31572 - atomic_inc(&vcc->stats->tx);
31573 - atomic_inc(&out_vcc->stats->rx);
31574 + atomic_inc_unchecked(&vcc->stats->tx);
31575 + atomic_inc_unchecked(&out_vcc->stats->rx);
31576 done:
31577 if (vcc->pop) vcc->pop(vcc,skb);
31578 else dev_kfree_skb(skb);
31579 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
31580 index c1eb6fa..4c71be9 100644
31581 --- a/drivers/atm/eni.c
31582 +++ b/drivers/atm/eni.c
31583 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
31584 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
31585 vcc->dev->number);
31586 length = 0;
31587 - atomic_inc(&vcc->stats->rx_err);
31588 + atomic_inc_unchecked(&vcc->stats->rx_err);
31589 }
31590 else {
31591 length = ATM_CELL_SIZE-1; /* no HEC */
31592 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31593 size);
31594 }
31595 eff = length = 0;
31596 - atomic_inc(&vcc->stats->rx_err);
31597 + atomic_inc_unchecked(&vcc->stats->rx_err);
31598 }
31599 else {
31600 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
31601 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31602 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
31603 vcc->dev->number,vcc->vci,length,size << 2,descr);
31604 length = eff = 0;
31605 - atomic_inc(&vcc->stats->rx_err);
31606 + atomic_inc_unchecked(&vcc->stats->rx_err);
31607 }
31608 }
31609 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
31610 @@ -767,7 +767,7 @@ rx_dequeued++;
31611 vcc->push(vcc,skb);
31612 pushed++;
31613 }
31614 - atomic_inc(&vcc->stats->rx);
31615 + atomic_inc_unchecked(&vcc->stats->rx);
31616 }
31617 wake_up(&eni_dev->rx_wait);
31618 }
31619 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
31620 PCI_DMA_TODEVICE);
31621 if (vcc->pop) vcc->pop(vcc,skb);
31622 else dev_kfree_skb_irq(skb);
31623 - atomic_inc(&vcc->stats->tx);
31624 + atomic_inc_unchecked(&vcc->stats->tx);
31625 wake_up(&eni_dev->tx_wait);
31626 dma_complete++;
31627 }
31628 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
31629 index b41c948..a002b17 100644
31630 --- a/drivers/atm/firestream.c
31631 +++ b/drivers/atm/firestream.c
31632 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
31633 }
31634 }
31635
31636 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31637 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31638
31639 fs_dprintk (FS_DEBUG_TXMEM, "i");
31640 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
31641 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31642 #endif
31643 skb_put (skb, qe->p1 & 0xffff);
31644 ATM_SKB(skb)->vcc = atm_vcc;
31645 - atomic_inc(&atm_vcc->stats->rx);
31646 + atomic_inc_unchecked(&atm_vcc->stats->rx);
31647 __net_timestamp(skb);
31648 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
31649 atm_vcc->push (atm_vcc, skb);
31650 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31651 kfree (pe);
31652 }
31653 if (atm_vcc)
31654 - atomic_inc(&atm_vcc->stats->rx_drop);
31655 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31656 break;
31657 case 0x1f: /* Reassembly abort: no buffers. */
31658 /* Silently increment error counter. */
31659 if (atm_vcc)
31660 - atomic_inc(&atm_vcc->stats->rx_drop);
31661 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31662 break;
31663 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
31664 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
31665 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
31666 index 204814e..cede831 100644
31667 --- a/drivers/atm/fore200e.c
31668 +++ b/drivers/atm/fore200e.c
31669 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
31670 #endif
31671 /* check error condition */
31672 if (*entry->status & STATUS_ERROR)
31673 - atomic_inc(&vcc->stats->tx_err);
31674 + atomic_inc_unchecked(&vcc->stats->tx_err);
31675 else
31676 - atomic_inc(&vcc->stats->tx);
31677 + atomic_inc_unchecked(&vcc->stats->tx);
31678 }
31679 }
31680
31681 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31682 if (skb == NULL) {
31683 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
31684
31685 - atomic_inc(&vcc->stats->rx_drop);
31686 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31687 return -ENOMEM;
31688 }
31689
31690 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31691
31692 dev_kfree_skb_any(skb);
31693
31694 - atomic_inc(&vcc->stats->rx_drop);
31695 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31696 return -ENOMEM;
31697 }
31698
31699 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31700
31701 vcc->push(vcc, skb);
31702 - atomic_inc(&vcc->stats->rx);
31703 + atomic_inc_unchecked(&vcc->stats->rx);
31704
31705 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31706
31707 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
31708 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
31709 fore200e->atm_dev->number,
31710 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
31711 - atomic_inc(&vcc->stats->rx_err);
31712 + atomic_inc_unchecked(&vcc->stats->rx_err);
31713 }
31714 }
31715
31716 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
31717 goto retry_here;
31718 }
31719
31720 - atomic_inc(&vcc->stats->tx_err);
31721 + atomic_inc_unchecked(&vcc->stats->tx_err);
31722
31723 fore200e->tx_sat++;
31724 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
31725 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
31726 index 72b6960..cf9167a 100644
31727 --- a/drivers/atm/he.c
31728 +++ b/drivers/atm/he.c
31729 @@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31730
31731 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
31732 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
31733 - atomic_inc(&vcc->stats->rx_drop);
31734 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31735 goto return_host_buffers;
31736 }
31737
31738 @@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31739 RBRQ_LEN_ERR(he_dev->rbrq_head)
31740 ? "LEN_ERR" : "",
31741 vcc->vpi, vcc->vci);
31742 - atomic_inc(&vcc->stats->rx_err);
31743 + atomic_inc_unchecked(&vcc->stats->rx_err);
31744 goto return_host_buffers;
31745 }
31746
31747 @@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31748 vcc->push(vcc, skb);
31749 spin_lock(&he_dev->global_lock);
31750
31751 - atomic_inc(&vcc->stats->rx);
31752 + atomic_inc_unchecked(&vcc->stats->rx);
31753
31754 return_host_buffers:
31755 ++pdus_assembled;
31756 @@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
31757 tpd->vcc->pop(tpd->vcc, tpd->skb);
31758 else
31759 dev_kfree_skb_any(tpd->skb);
31760 - atomic_inc(&tpd->vcc->stats->tx_err);
31761 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
31762 }
31763 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
31764 return;
31765 @@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31766 vcc->pop(vcc, skb);
31767 else
31768 dev_kfree_skb_any(skb);
31769 - atomic_inc(&vcc->stats->tx_err);
31770 + atomic_inc_unchecked(&vcc->stats->tx_err);
31771 return -EINVAL;
31772 }
31773
31774 @@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31775 vcc->pop(vcc, skb);
31776 else
31777 dev_kfree_skb_any(skb);
31778 - atomic_inc(&vcc->stats->tx_err);
31779 + atomic_inc_unchecked(&vcc->stats->tx_err);
31780 return -EINVAL;
31781 }
31782 #endif
31783 @@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31784 vcc->pop(vcc, skb);
31785 else
31786 dev_kfree_skb_any(skb);
31787 - atomic_inc(&vcc->stats->tx_err);
31788 + atomic_inc_unchecked(&vcc->stats->tx_err);
31789 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31790 return -ENOMEM;
31791 }
31792 @@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31793 vcc->pop(vcc, skb);
31794 else
31795 dev_kfree_skb_any(skb);
31796 - atomic_inc(&vcc->stats->tx_err);
31797 + atomic_inc_unchecked(&vcc->stats->tx_err);
31798 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31799 return -ENOMEM;
31800 }
31801 @@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31802 __enqueue_tpd(he_dev, tpd, cid);
31803 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31804
31805 - atomic_inc(&vcc->stats->tx);
31806 + atomic_inc_unchecked(&vcc->stats->tx);
31807
31808 return 0;
31809 }
31810 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
31811 index 1dc0519..1aadaf7 100644
31812 --- a/drivers/atm/horizon.c
31813 +++ b/drivers/atm/horizon.c
31814 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
31815 {
31816 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
31817 // VC layer stats
31818 - atomic_inc(&vcc->stats->rx);
31819 + atomic_inc_unchecked(&vcc->stats->rx);
31820 __net_timestamp(skb);
31821 // end of our responsibility
31822 vcc->push (vcc, skb);
31823 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
31824 dev->tx_iovec = NULL;
31825
31826 // VC layer stats
31827 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31828 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31829
31830 // free the skb
31831 hrz_kfree_skb (skb);
31832 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
31833 index 272f009..a18ba55 100644
31834 --- a/drivers/atm/idt77252.c
31835 +++ b/drivers/atm/idt77252.c
31836 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
31837 else
31838 dev_kfree_skb(skb);
31839
31840 - atomic_inc(&vcc->stats->tx);
31841 + atomic_inc_unchecked(&vcc->stats->tx);
31842 }
31843
31844 atomic_dec(&scq->used);
31845 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31846 if ((sb = dev_alloc_skb(64)) == NULL) {
31847 printk("%s: Can't allocate buffers for aal0.\n",
31848 card->name);
31849 - atomic_add(i, &vcc->stats->rx_drop);
31850 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
31851 break;
31852 }
31853 if (!atm_charge(vcc, sb->truesize)) {
31854 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
31855 card->name);
31856 - atomic_add(i - 1, &vcc->stats->rx_drop);
31857 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
31858 dev_kfree_skb(sb);
31859 break;
31860 }
31861 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31862 ATM_SKB(sb)->vcc = vcc;
31863 __net_timestamp(sb);
31864 vcc->push(vcc, sb);
31865 - atomic_inc(&vcc->stats->rx);
31866 + atomic_inc_unchecked(&vcc->stats->rx);
31867
31868 cell += ATM_CELL_PAYLOAD;
31869 }
31870 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31871 "(CDC: %08x)\n",
31872 card->name, len, rpp->len, readl(SAR_REG_CDC));
31873 recycle_rx_pool_skb(card, rpp);
31874 - atomic_inc(&vcc->stats->rx_err);
31875 + atomic_inc_unchecked(&vcc->stats->rx_err);
31876 return;
31877 }
31878 if (stat & SAR_RSQE_CRC) {
31879 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
31880 recycle_rx_pool_skb(card, rpp);
31881 - atomic_inc(&vcc->stats->rx_err);
31882 + atomic_inc_unchecked(&vcc->stats->rx_err);
31883 return;
31884 }
31885 if (skb_queue_len(&rpp->queue) > 1) {
31886 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31887 RXPRINTK("%s: Can't alloc RX skb.\n",
31888 card->name);
31889 recycle_rx_pool_skb(card, rpp);
31890 - atomic_inc(&vcc->stats->rx_err);
31891 + atomic_inc_unchecked(&vcc->stats->rx_err);
31892 return;
31893 }
31894 if (!atm_charge(vcc, skb->truesize)) {
31895 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31896 __net_timestamp(skb);
31897
31898 vcc->push(vcc, skb);
31899 - atomic_inc(&vcc->stats->rx);
31900 + atomic_inc_unchecked(&vcc->stats->rx);
31901
31902 return;
31903 }
31904 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31905 __net_timestamp(skb);
31906
31907 vcc->push(vcc, skb);
31908 - atomic_inc(&vcc->stats->rx);
31909 + atomic_inc_unchecked(&vcc->stats->rx);
31910
31911 if (skb->truesize > SAR_FB_SIZE_3)
31912 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
31913 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
31914 if (vcc->qos.aal != ATM_AAL0) {
31915 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
31916 card->name, vpi, vci);
31917 - atomic_inc(&vcc->stats->rx_drop);
31918 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31919 goto drop;
31920 }
31921
31922 if ((sb = dev_alloc_skb(64)) == NULL) {
31923 printk("%s: Can't allocate buffers for AAL0.\n",
31924 card->name);
31925 - atomic_inc(&vcc->stats->rx_err);
31926 + atomic_inc_unchecked(&vcc->stats->rx_err);
31927 goto drop;
31928 }
31929
31930 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
31931 ATM_SKB(sb)->vcc = vcc;
31932 __net_timestamp(sb);
31933 vcc->push(vcc, sb);
31934 - atomic_inc(&vcc->stats->rx);
31935 + atomic_inc_unchecked(&vcc->stats->rx);
31936
31937 drop:
31938 skb_pull(queue, 64);
31939 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31940
31941 if (vc == NULL) {
31942 printk("%s: NULL connection in send().\n", card->name);
31943 - atomic_inc(&vcc->stats->tx_err);
31944 + atomic_inc_unchecked(&vcc->stats->tx_err);
31945 dev_kfree_skb(skb);
31946 return -EINVAL;
31947 }
31948 if (!test_bit(VCF_TX, &vc->flags)) {
31949 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
31950 - atomic_inc(&vcc->stats->tx_err);
31951 + atomic_inc_unchecked(&vcc->stats->tx_err);
31952 dev_kfree_skb(skb);
31953 return -EINVAL;
31954 }
31955 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31956 break;
31957 default:
31958 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
31959 - atomic_inc(&vcc->stats->tx_err);
31960 + atomic_inc_unchecked(&vcc->stats->tx_err);
31961 dev_kfree_skb(skb);
31962 return -EINVAL;
31963 }
31964
31965 if (skb_shinfo(skb)->nr_frags != 0) {
31966 printk("%s: No scatter-gather yet.\n", card->name);
31967 - atomic_inc(&vcc->stats->tx_err);
31968 + atomic_inc_unchecked(&vcc->stats->tx_err);
31969 dev_kfree_skb(skb);
31970 return -EINVAL;
31971 }
31972 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31973
31974 err = queue_skb(card, vc, skb, oam);
31975 if (err) {
31976 - atomic_inc(&vcc->stats->tx_err);
31977 + atomic_inc_unchecked(&vcc->stats->tx_err);
31978 dev_kfree_skb(skb);
31979 return err;
31980 }
31981 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
31982 skb = dev_alloc_skb(64);
31983 if (!skb) {
31984 printk("%s: Out of memory in send_oam().\n", card->name);
31985 - atomic_inc(&vcc->stats->tx_err);
31986 + atomic_inc_unchecked(&vcc->stats->tx_err);
31987 return -ENOMEM;
31988 }
31989 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
31990 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
31991 index 4217f29..88f547a 100644
31992 --- a/drivers/atm/iphase.c
31993 +++ b/drivers/atm/iphase.c
31994 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
31995 status = (u_short) (buf_desc_ptr->desc_mode);
31996 if (status & (RX_CER | RX_PTE | RX_OFL))
31997 {
31998 - atomic_inc(&vcc->stats->rx_err);
31999 + atomic_inc_unchecked(&vcc->stats->rx_err);
32000 IF_ERR(printk("IA: bad packet, dropping it");)
32001 if (status & RX_CER) {
32002 IF_ERR(printk(" cause: packet CRC error\n");)
32003 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32004 len = dma_addr - buf_addr;
32005 if (len > iadev->rx_buf_sz) {
32006 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32007 - atomic_inc(&vcc->stats->rx_err);
32008 + atomic_inc_unchecked(&vcc->stats->rx_err);
32009 goto out_free_desc;
32010 }
32011
32012 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32013 ia_vcc = INPH_IA_VCC(vcc);
32014 if (ia_vcc == NULL)
32015 {
32016 - atomic_inc(&vcc->stats->rx_err);
32017 + atomic_inc_unchecked(&vcc->stats->rx_err);
32018 atm_return(vcc, skb->truesize);
32019 dev_kfree_skb_any(skb);
32020 goto INCR_DLE;
32021 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32022 if ((length > iadev->rx_buf_sz) || (length >
32023 (skb->len - sizeof(struct cpcs_trailer))))
32024 {
32025 - atomic_inc(&vcc->stats->rx_err);
32026 + atomic_inc_unchecked(&vcc->stats->rx_err);
32027 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32028 length, skb->len);)
32029 atm_return(vcc, skb->truesize);
32030 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32031
32032 IF_RX(printk("rx_dle_intr: skb push");)
32033 vcc->push(vcc,skb);
32034 - atomic_inc(&vcc->stats->rx);
32035 + atomic_inc_unchecked(&vcc->stats->rx);
32036 iadev->rx_pkt_cnt++;
32037 }
32038 INCR_DLE:
32039 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32040 {
32041 struct k_sonet_stats *stats;
32042 stats = &PRIV(_ia_dev[board])->sonet_stats;
32043 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32044 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32045 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32046 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32047 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32048 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32049 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32050 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32051 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32052 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32053 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32054 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32055 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32056 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32057 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32058 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32059 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32060 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32061 }
32062 ia_cmds.status = 0;
32063 break;
32064 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32065 if ((desc == 0) || (desc > iadev->num_tx_desc))
32066 {
32067 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32068 - atomic_inc(&vcc->stats->tx);
32069 + atomic_inc_unchecked(&vcc->stats->tx);
32070 if (vcc->pop)
32071 vcc->pop(vcc, skb);
32072 else
32073 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32074 ATM_DESC(skb) = vcc->vci;
32075 skb_queue_tail(&iadev->tx_dma_q, skb);
32076
32077 - atomic_inc(&vcc->stats->tx);
32078 + atomic_inc_unchecked(&vcc->stats->tx);
32079 iadev->tx_pkt_cnt++;
32080 /* Increment transaction counter */
32081 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32082
32083 #if 0
32084 /* add flow control logic */
32085 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32086 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32087 if (iavcc->vc_desc_cnt > 10) {
32088 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32089 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32090 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32091 index fa7d701..1e404c7 100644
32092 --- a/drivers/atm/lanai.c
32093 +++ b/drivers/atm/lanai.c
32094 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32095 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32096 lanai_endtx(lanai, lvcc);
32097 lanai_free_skb(lvcc->tx.atmvcc, skb);
32098 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32099 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32100 }
32101
32102 /* Try to fill the buffer - don't call unless there is backlog */
32103 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32104 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32105 __net_timestamp(skb);
32106 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32107 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32108 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32109 out:
32110 lvcc->rx.buf.ptr = end;
32111 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32112 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32113 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32114 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32115 lanai->stats.service_rxnotaal5++;
32116 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32117 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32118 return 0;
32119 }
32120 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32121 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32122 int bytes;
32123 read_unlock(&vcc_sklist_lock);
32124 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32125 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32126 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32127 lvcc->stats.x.aal5.service_trash++;
32128 bytes = (SERVICE_GET_END(s) * 16) -
32129 (((unsigned long) lvcc->rx.buf.ptr) -
32130 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32131 }
32132 if (s & SERVICE_STREAM) {
32133 read_unlock(&vcc_sklist_lock);
32134 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32135 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32136 lvcc->stats.x.aal5.service_stream++;
32137 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32138 "PDU on VCI %d!\n", lanai->number, vci);
32139 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32140 return 0;
32141 }
32142 DPRINTK("got rx crc error on vci %d\n", vci);
32143 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32144 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32145 lvcc->stats.x.aal5.service_rxcrc++;
32146 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32147 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32148 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32149 index ed1d2b7..8cffc1f 100644
32150 --- a/drivers/atm/nicstar.c
32151 +++ b/drivers/atm/nicstar.c
32152 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32153 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32154 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32155 card->index);
32156 - atomic_inc(&vcc->stats->tx_err);
32157 + atomic_inc_unchecked(&vcc->stats->tx_err);
32158 dev_kfree_skb_any(skb);
32159 return -EINVAL;
32160 }
32161 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32162 if (!vc->tx) {
32163 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32164 card->index);
32165 - atomic_inc(&vcc->stats->tx_err);
32166 + atomic_inc_unchecked(&vcc->stats->tx_err);
32167 dev_kfree_skb_any(skb);
32168 return -EINVAL;
32169 }
32170 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32171 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32172 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32173 card->index);
32174 - atomic_inc(&vcc->stats->tx_err);
32175 + atomic_inc_unchecked(&vcc->stats->tx_err);
32176 dev_kfree_skb_any(skb);
32177 return -EINVAL;
32178 }
32179
32180 if (skb_shinfo(skb)->nr_frags != 0) {
32181 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32182 - atomic_inc(&vcc->stats->tx_err);
32183 + atomic_inc_unchecked(&vcc->stats->tx_err);
32184 dev_kfree_skb_any(skb);
32185 return -EINVAL;
32186 }
32187 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32188 }
32189
32190 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32191 - atomic_inc(&vcc->stats->tx_err);
32192 + atomic_inc_unchecked(&vcc->stats->tx_err);
32193 dev_kfree_skb_any(skb);
32194 return -EIO;
32195 }
32196 - atomic_inc(&vcc->stats->tx);
32197 + atomic_inc_unchecked(&vcc->stats->tx);
32198
32199 return 0;
32200 }
32201 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32202 printk
32203 ("nicstar%d: Can't allocate buffers for aal0.\n",
32204 card->index);
32205 - atomic_add(i, &vcc->stats->rx_drop);
32206 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
32207 break;
32208 }
32209 if (!atm_charge(vcc, sb->truesize)) {
32210 RXPRINTK
32211 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32212 card->index);
32213 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32214 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32215 dev_kfree_skb_any(sb);
32216 break;
32217 }
32218 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32219 ATM_SKB(sb)->vcc = vcc;
32220 __net_timestamp(sb);
32221 vcc->push(vcc, sb);
32222 - atomic_inc(&vcc->stats->rx);
32223 + atomic_inc_unchecked(&vcc->stats->rx);
32224 cell += ATM_CELL_PAYLOAD;
32225 }
32226
32227 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32228 if (iovb == NULL) {
32229 printk("nicstar%d: Out of iovec buffers.\n",
32230 card->index);
32231 - atomic_inc(&vcc->stats->rx_drop);
32232 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32233 recycle_rx_buf(card, skb);
32234 return;
32235 }
32236 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32237 small or large buffer itself. */
32238 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32239 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32240 - atomic_inc(&vcc->stats->rx_err);
32241 + atomic_inc_unchecked(&vcc->stats->rx_err);
32242 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32243 NS_MAX_IOVECS);
32244 NS_PRV_IOVCNT(iovb) = 0;
32245 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32246 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32247 card->index);
32248 which_list(card, skb);
32249 - atomic_inc(&vcc->stats->rx_err);
32250 + atomic_inc_unchecked(&vcc->stats->rx_err);
32251 recycle_rx_buf(card, skb);
32252 vc->rx_iov = NULL;
32253 recycle_iov_buf(card, iovb);
32254 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32255 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32256 card->index);
32257 which_list(card, skb);
32258 - atomic_inc(&vcc->stats->rx_err);
32259 + atomic_inc_unchecked(&vcc->stats->rx_err);
32260 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32261 NS_PRV_IOVCNT(iovb));
32262 vc->rx_iov = NULL;
32263 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32264 printk(" - PDU size mismatch.\n");
32265 else
32266 printk(".\n");
32267 - atomic_inc(&vcc->stats->rx_err);
32268 + atomic_inc_unchecked(&vcc->stats->rx_err);
32269 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32270 NS_PRV_IOVCNT(iovb));
32271 vc->rx_iov = NULL;
32272 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32273 /* skb points to a small buffer */
32274 if (!atm_charge(vcc, skb->truesize)) {
32275 push_rxbufs(card, skb);
32276 - atomic_inc(&vcc->stats->rx_drop);
32277 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32278 } else {
32279 skb_put(skb, len);
32280 dequeue_sm_buf(card, skb);
32281 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32282 ATM_SKB(skb)->vcc = vcc;
32283 __net_timestamp(skb);
32284 vcc->push(vcc, skb);
32285 - atomic_inc(&vcc->stats->rx);
32286 + atomic_inc_unchecked(&vcc->stats->rx);
32287 }
32288 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32289 struct sk_buff *sb;
32290 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32291 if (len <= NS_SMBUFSIZE) {
32292 if (!atm_charge(vcc, sb->truesize)) {
32293 push_rxbufs(card, sb);
32294 - atomic_inc(&vcc->stats->rx_drop);
32295 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32296 } else {
32297 skb_put(sb, len);
32298 dequeue_sm_buf(card, sb);
32299 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32300 ATM_SKB(sb)->vcc = vcc;
32301 __net_timestamp(sb);
32302 vcc->push(vcc, sb);
32303 - atomic_inc(&vcc->stats->rx);
32304 + atomic_inc_unchecked(&vcc->stats->rx);
32305 }
32306
32307 push_rxbufs(card, skb);
32308 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32309
32310 if (!atm_charge(vcc, skb->truesize)) {
32311 push_rxbufs(card, skb);
32312 - atomic_inc(&vcc->stats->rx_drop);
32313 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32314 } else {
32315 dequeue_lg_buf(card, skb);
32316 #ifdef NS_USE_DESTRUCTORS
32317 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32318 ATM_SKB(skb)->vcc = vcc;
32319 __net_timestamp(skb);
32320 vcc->push(vcc, skb);
32321 - atomic_inc(&vcc->stats->rx);
32322 + atomic_inc_unchecked(&vcc->stats->rx);
32323 }
32324
32325 push_rxbufs(card, sb);
32326 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32327 printk
32328 ("nicstar%d: Out of huge buffers.\n",
32329 card->index);
32330 - atomic_inc(&vcc->stats->rx_drop);
32331 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32332 recycle_iovec_rx_bufs(card,
32333 (struct iovec *)
32334 iovb->data,
32335 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32336 card->hbpool.count++;
32337 } else
32338 dev_kfree_skb_any(hb);
32339 - atomic_inc(&vcc->stats->rx_drop);
32340 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32341 } else {
32342 /* Copy the small buffer to the huge buffer */
32343 sb = (struct sk_buff *)iov->iov_base;
32344 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32345 #endif /* NS_USE_DESTRUCTORS */
32346 __net_timestamp(hb);
32347 vcc->push(vcc, hb);
32348 - atomic_inc(&vcc->stats->rx);
32349 + atomic_inc_unchecked(&vcc->stats->rx);
32350 }
32351 }
32352
32353 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32354 index 0474a89..06ea4a1 100644
32355 --- a/drivers/atm/solos-pci.c
32356 +++ b/drivers/atm/solos-pci.c
32357 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32358 }
32359 atm_charge(vcc, skb->truesize);
32360 vcc->push(vcc, skb);
32361 - atomic_inc(&vcc->stats->rx);
32362 + atomic_inc_unchecked(&vcc->stats->rx);
32363 break;
32364
32365 case PKT_STATUS:
32366 @@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
32367 vcc = SKB_CB(oldskb)->vcc;
32368
32369 if (vcc) {
32370 - atomic_inc(&vcc->stats->tx);
32371 + atomic_inc_unchecked(&vcc->stats->tx);
32372 solos_pop(vcc, oldskb);
32373 } else {
32374 dev_kfree_skb_irq(oldskb);
32375 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
32376 index 0215934..ce9f5b1 100644
32377 --- a/drivers/atm/suni.c
32378 +++ b/drivers/atm/suni.c
32379 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
32380
32381
32382 #define ADD_LIMITED(s,v) \
32383 - atomic_add((v),&stats->s); \
32384 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
32385 + atomic_add_unchecked((v),&stats->s); \
32386 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
32387
32388
32389 static void suni_hz(unsigned long from_timer)
32390 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
32391 index 5120a96..e2572bd 100644
32392 --- a/drivers/atm/uPD98402.c
32393 +++ b/drivers/atm/uPD98402.c
32394 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
32395 struct sonet_stats tmp;
32396 int error = 0;
32397
32398 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32399 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32400 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
32401 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
32402 if (zero && !error) {
32403 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
32404
32405
32406 #define ADD_LIMITED(s,v) \
32407 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
32408 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
32409 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32410 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
32411 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
32412 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32413
32414
32415 static void stat_event(struct atm_dev *dev)
32416 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
32417 if (reason & uPD98402_INT_PFM) stat_event(dev);
32418 if (reason & uPD98402_INT_PCO) {
32419 (void) GET(PCOCR); /* clear interrupt cause */
32420 - atomic_add(GET(HECCT),
32421 + atomic_add_unchecked(GET(HECCT),
32422 &PRIV(dev)->sonet_stats.uncorr_hcs);
32423 }
32424 if ((reason & uPD98402_INT_RFO) &&
32425 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
32426 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
32427 uPD98402_INT_LOS),PIMR); /* enable them */
32428 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
32429 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32430 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
32431 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
32432 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32433 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
32434 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
32435 return 0;
32436 }
32437
32438 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32439 index 969c3c2..9b72956 100644
32440 --- a/drivers/atm/zatm.c
32441 +++ b/drivers/atm/zatm.c
32442 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32443 }
32444 if (!size) {
32445 dev_kfree_skb_irq(skb);
32446 - if (vcc) atomic_inc(&vcc->stats->rx_err);
32447 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32448 continue;
32449 }
32450 if (!atm_charge(vcc,skb->truesize)) {
32451 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32452 skb->len = size;
32453 ATM_SKB(skb)->vcc = vcc;
32454 vcc->push(vcc,skb);
32455 - atomic_inc(&vcc->stats->rx);
32456 + atomic_inc_unchecked(&vcc->stats->rx);
32457 }
32458 zout(pos & 0xffff,MTA(mbx));
32459 #if 0 /* probably a stupid idea */
32460 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32461 skb_queue_head(&zatm_vcc->backlog,skb);
32462 break;
32463 }
32464 - atomic_inc(&vcc->stats->tx);
32465 + atomic_inc_unchecked(&vcc->stats->tx);
32466 wake_up(&zatm_vcc->tx_wait);
32467 }
32468
32469 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
32470 index 6856303..0602d70 100644
32471 --- a/drivers/base/bus.c
32472 +++ b/drivers/base/bus.c
32473 @@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
32474 return -EINVAL;
32475
32476 mutex_lock(&subsys->p->mutex);
32477 - list_add_tail(&sif->node, &subsys->p->interfaces);
32478 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
32479 if (sif->add_dev) {
32480 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32481 while ((dev = subsys_dev_iter_next(&iter)))
32482 @@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
32483 subsys = sif->subsys;
32484
32485 mutex_lock(&subsys->p->mutex);
32486 - list_del_init(&sif->node);
32487 + pax_list_del_init((struct list_head *)&sif->node);
32488 if (sif->remove_dev) {
32489 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32490 while ((dev = subsys_dev_iter_next(&iter)))
32491 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32492 index 17cf7ca..7e553e1 100644
32493 --- a/drivers/base/devtmpfs.c
32494 +++ b/drivers/base/devtmpfs.c
32495 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
32496 if (!thread)
32497 return 0;
32498
32499 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
32500 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
32501 if (err)
32502 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
32503 else
32504 diff --git a/drivers/base/node.c b/drivers/base/node.c
32505 index fac124a..66bd4ab 100644
32506 --- a/drivers/base/node.c
32507 +++ b/drivers/base/node.c
32508 @@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
32509 struct node_attr {
32510 struct device_attribute attr;
32511 enum node_states state;
32512 -};
32513 +} __do_const;
32514
32515 static ssize_t show_node_state(struct device *dev,
32516 struct device_attribute *attr, char *buf)
32517 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
32518 index e6ee5e8..98ad7fc 100644
32519 --- a/drivers/base/power/wakeup.c
32520 +++ b/drivers/base/power/wakeup.c
32521 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
32522 * They need to be modified together atomically, so it's better to use one
32523 * atomic variable to hold them both.
32524 */
32525 -static atomic_t combined_event_count = ATOMIC_INIT(0);
32526 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
32527
32528 #define IN_PROGRESS_BITS (sizeof(int) * 4)
32529 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
32530
32531 static void split_counters(unsigned int *cnt, unsigned int *inpr)
32532 {
32533 - unsigned int comb = atomic_read(&combined_event_count);
32534 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
32535
32536 *cnt = (comb >> IN_PROGRESS_BITS);
32537 *inpr = comb & MAX_IN_PROGRESS;
32538 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
32539 ws->start_prevent_time = ws->last_time;
32540
32541 /* Increment the counter of events in progress. */
32542 - cec = atomic_inc_return(&combined_event_count);
32543 + cec = atomic_inc_return_unchecked(&combined_event_count);
32544
32545 trace_wakeup_source_activate(ws->name, cec);
32546 }
32547 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
32548 * Increment the counter of registered wakeup events and decrement the
32549 * couter of wakeup events in progress simultaneously.
32550 */
32551 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
32552 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
32553 trace_wakeup_source_deactivate(ws->name, cec);
32554
32555 split_counters(&cnt, &inpr);
32556 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
32557 index e8d11b6..7b1b36f 100644
32558 --- a/drivers/base/syscore.c
32559 +++ b/drivers/base/syscore.c
32560 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
32561 void register_syscore_ops(struct syscore_ops *ops)
32562 {
32563 mutex_lock(&syscore_ops_lock);
32564 - list_add_tail(&ops->node, &syscore_ops_list);
32565 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
32566 mutex_unlock(&syscore_ops_lock);
32567 }
32568 EXPORT_SYMBOL_GPL(register_syscore_ops);
32569 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
32570 void unregister_syscore_ops(struct syscore_ops *ops)
32571 {
32572 mutex_lock(&syscore_ops_lock);
32573 - list_del(&ops->node);
32574 + pax_list_del((struct list_head *)&ops->node);
32575 mutex_unlock(&syscore_ops_lock);
32576 }
32577 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
32578 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
32579 index ade58bc..867143d 100644
32580 --- a/drivers/block/cciss.c
32581 +++ b/drivers/block/cciss.c
32582 @@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
32583 int err;
32584 u32 cp;
32585
32586 + memset(&arg64, 0, sizeof(arg64));
32587 +
32588 err = 0;
32589 err |=
32590 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
32591 @@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
32592 while (!list_empty(&h->reqQ)) {
32593 c = list_entry(h->reqQ.next, CommandList_struct, list);
32594 /* can't do anything if fifo is full */
32595 - if ((h->access.fifo_full(h))) {
32596 + if ((h->access->fifo_full(h))) {
32597 dev_warn(&h->pdev->dev, "fifo full\n");
32598 break;
32599 }
32600 @@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
32601 h->Qdepth--;
32602
32603 /* Tell the controller execute command */
32604 - h->access.submit_command(h, c);
32605 + h->access->submit_command(h, c);
32606
32607 /* Put job onto the completed Q */
32608 addQ(&h->cmpQ, c);
32609 @@ -3441,17 +3443,17 @@ startio:
32610
32611 static inline unsigned long get_next_completion(ctlr_info_t *h)
32612 {
32613 - return h->access.command_completed(h);
32614 + return h->access->command_completed(h);
32615 }
32616
32617 static inline int interrupt_pending(ctlr_info_t *h)
32618 {
32619 - return h->access.intr_pending(h);
32620 + return h->access->intr_pending(h);
32621 }
32622
32623 static inline long interrupt_not_for_us(ctlr_info_t *h)
32624 {
32625 - return ((h->access.intr_pending(h) == 0) ||
32626 + return ((h->access->intr_pending(h) == 0) ||
32627 (h->interrupts_enabled == 0));
32628 }
32629
32630 @@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
32631 u32 a;
32632
32633 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
32634 - return h->access.command_completed(h);
32635 + return h->access->command_completed(h);
32636
32637 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
32638 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
32639 @@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
32640 trans_support & CFGTBL_Trans_use_short_tags);
32641
32642 /* Change the access methods to the performant access methods */
32643 - h->access = SA5_performant_access;
32644 + h->access = &SA5_performant_access;
32645 h->transMethod = CFGTBL_Trans_Performant;
32646
32647 return;
32648 @@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
32649 if (prod_index < 0)
32650 return -ENODEV;
32651 h->product_name = products[prod_index].product_name;
32652 - h->access = *(products[prod_index].access);
32653 + h->access = products[prod_index].access;
32654
32655 if (cciss_board_disabled(h)) {
32656 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
32657 @@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
32658 }
32659
32660 /* make sure the board interrupts are off */
32661 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32662 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32663 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
32664 if (rc)
32665 goto clean2;
32666 @@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
32667 * fake ones to scoop up any residual completions.
32668 */
32669 spin_lock_irqsave(&h->lock, flags);
32670 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32671 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32672 spin_unlock_irqrestore(&h->lock, flags);
32673 free_irq(h->intr[h->intr_mode], h);
32674 rc = cciss_request_irq(h, cciss_msix_discard_completions,
32675 @@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
32676 dev_info(&h->pdev->dev, "Board READY.\n");
32677 dev_info(&h->pdev->dev,
32678 "Waiting for stale completions to drain.\n");
32679 - h->access.set_intr_mask(h, CCISS_INTR_ON);
32680 + h->access->set_intr_mask(h, CCISS_INTR_ON);
32681 msleep(10000);
32682 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32683 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32684
32685 rc = controller_reset_failed(h->cfgtable);
32686 if (rc)
32687 @@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
32688 cciss_scsi_setup(h);
32689
32690 /* Turn the interrupts on so we can service requests */
32691 - h->access.set_intr_mask(h, CCISS_INTR_ON);
32692 + h->access->set_intr_mask(h, CCISS_INTR_ON);
32693
32694 /* Get the firmware version */
32695 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
32696 @@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
32697 kfree(flush_buf);
32698 if (return_code != IO_OK)
32699 dev_warn(&h->pdev->dev, "Error flushing cache\n");
32700 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32701 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32702 free_irq(h->intr[h->intr_mode], h);
32703 }
32704
32705 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
32706 index 7fda30e..eb5dfe0 100644
32707 --- a/drivers/block/cciss.h
32708 +++ b/drivers/block/cciss.h
32709 @@ -101,7 +101,7 @@ struct ctlr_info
32710 /* information about each logical volume */
32711 drive_info_struct *drv[CISS_MAX_LUN];
32712
32713 - struct access_method access;
32714 + struct access_method *access;
32715
32716 /* queue and queue Info */
32717 struct list_head reqQ;
32718 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
32719 index 3f08713..56a586a 100644
32720 --- a/drivers/block/cpqarray.c
32721 +++ b/drivers/block/cpqarray.c
32722 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32723 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
32724 goto Enomem4;
32725 }
32726 - hba[i]->access.set_intr_mask(hba[i], 0);
32727 + hba[i]->access->set_intr_mask(hba[i], 0);
32728 if (request_irq(hba[i]->intr, do_ida_intr,
32729 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
32730 {
32731 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32732 add_timer(&hba[i]->timer);
32733
32734 /* Enable IRQ now that spinlock and rate limit timer are set up */
32735 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32736 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32737
32738 for(j=0; j<NWD; j++) {
32739 struct gendisk *disk = ida_gendisk[i][j];
32740 @@ -694,7 +694,7 @@ DBGINFO(
32741 for(i=0; i<NR_PRODUCTS; i++) {
32742 if (board_id == products[i].board_id) {
32743 c->product_name = products[i].product_name;
32744 - c->access = *(products[i].access);
32745 + c->access = products[i].access;
32746 break;
32747 }
32748 }
32749 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
32750 hba[ctlr]->intr = intr;
32751 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
32752 hba[ctlr]->product_name = products[j].product_name;
32753 - hba[ctlr]->access = *(products[j].access);
32754 + hba[ctlr]->access = products[j].access;
32755 hba[ctlr]->ctlr = ctlr;
32756 hba[ctlr]->board_id = board_id;
32757 hba[ctlr]->pci_dev = NULL; /* not PCI */
32758 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
32759
32760 while((c = h->reqQ) != NULL) {
32761 /* Can't do anything if we're busy */
32762 - if (h->access.fifo_full(h) == 0)
32763 + if (h->access->fifo_full(h) == 0)
32764 return;
32765
32766 /* Get the first entry from the request Q */
32767 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
32768 h->Qdepth--;
32769
32770 /* Tell the controller to do our bidding */
32771 - h->access.submit_command(h, c);
32772 + h->access->submit_command(h, c);
32773
32774 /* Get onto the completion Q */
32775 addQ(&h->cmpQ, c);
32776 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32777 unsigned long flags;
32778 __u32 a,a1;
32779
32780 - istat = h->access.intr_pending(h);
32781 + istat = h->access->intr_pending(h);
32782 /* Is this interrupt for us? */
32783 if (istat == 0)
32784 return IRQ_NONE;
32785 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32786 */
32787 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
32788 if (istat & FIFO_NOT_EMPTY) {
32789 - while((a = h->access.command_completed(h))) {
32790 + while((a = h->access->command_completed(h))) {
32791 a1 = a; a &= ~3;
32792 if ((c = h->cmpQ) == NULL)
32793 {
32794 @@ -1449,11 +1449,11 @@ static int sendcmd(
32795 /*
32796 * Disable interrupt
32797 */
32798 - info_p->access.set_intr_mask(info_p, 0);
32799 + info_p->access->set_intr_mask(info_p, 0);
32800 /* Make sure there is room in the command FIFO */
32801 /* Actually it should be completely empty at this time. */
32802 for (i = 200000; i > 0; i--) {
32803 - temp = info_p->access.fifo_full(info_p);
32804 + temp = info_p->access->fifo_full(info_p);
32805 if (temp != 0) {
32806 break;
32807 }
32808 @@ -1466,7 +1466,7 @@ DBG(
32809 /*
32810 * Send the cmd
32811 */
32812 - info_p->access.submit_command(info_p, c);
32813 + info_p->access->submit_command(info_p, c);
32814 complete = pollcomplete(ctlr);
32815
32816 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
32817 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
32818 * we check the new geometry. Then turn interrupts back on when
32819 * we're done.
32820 */
32821 - host->access.set_intr_mask(host, 0);
32822 + host->access->set_intr_mask(host, 0);
32823 getgeometry(ctlr);
32824 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
32825 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
32826
32827 for(i=0; i<NWD; i++) {
32828 struct gendisk *disk = ida_gendisk[ctlr][i];
32829 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
32830 /* Wait (up to 2 seconds) for a command to complete */
32831
32832 for (i = 200000; i > 0; i--) {
32833 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
32834 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
32835 if (done == 0) {
32836 udelay(10); /* a short fixed delay */
32837 } else
32838 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
32839 index be73e9d..7fbf140 100644
32840 --- a/drivers/block/cpqarray.h
32841 +++ b/drivers/block/cpqarray.h
32842 @@ -99,7 +99,7 @@ struct ctlr_info {
32843 drv_info_t drv[NWD];
32844 struct proc_dir_entry *proc;
32845
32846 - struct access_method access;
32847 + struct access_method *access;
32848
32849 cmdlist_t *reqQ;
32850 cmdlist_t *cmpQ;
32851 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
32852 index 6b51afa..17e1191 100644
32853 --- a/drivers/block/drbd/drbd_int.h
32854 +++ b/drivers/block/drbd/drbd_int.h
32855 @@ -582,7 +582,7 @@ struct drbd_epoch {
32856 struct drbd_tconn *tconn;
32857 struct list_head list;
32858 unsigned int barrier_nr;
32859 - atomic_t epoch_size; /* increased on every request added. */
32860 + atomic_unchecked_t epoch_size; /* increased on every request added. */
32861 atomic_t active; /* increased on every req. added, and dec on every finished. */
32862 unsigned long flags;
32863 };
32864 @@ -1011,7 +1011,7 @@ struct drbd_conf {
32865 int al_tr_cycle;
32866 int al_tr_pos; /* position of the next transaction in the journal */
32867 wait_queue_head_t seq_wait;
32868 - atomic_t packet_seq;
32869 + atomic_unchecked_t packet_seq;
32870 unsigned int peer_seq;
32871 spinlock_t peer_seq_lock;
32872 unsigned int minor;
32873 @@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
32874 char __user *uoptval;
32875 int err;
32876
32877 - uoptval = (char __user __force *)optval;
32878 + uoptval = (char __force_user *)optval;
32879
32880 set_fs(KERNEL_DS);
32881 if (level == SOL_SOCKET)
32882 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
32883 index 8c13eeb..217adee 100644
32884 --- a/drivers/block/drbd/drbd_main.c
32885 +++ b/drivers/block/drbd/drbd_main.c
32886 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
32887 p->sector = sector;
32888 p->block_id = block_id;
32889 p->blksize = blksize;
32890 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32891 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32892 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
32893 }
32894
32895 @@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
32896 return -EIO;
32897 p->sector = cpu_to_be64(req->i.sector);
32898 p->block_id = (unsigned long)req;
32899 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32900 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32901 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
32902 if (mdev->state.conn >= C_SYNC_SOURCE &&
32903 mdev->state.conn <= C_PAUSED_SYNC_T)
32904 @@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
32905 {
32906 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
32907
32908 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
32909 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
32910 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
32911 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
32912 kfree(tconn->current_epoch);
32913
32914 idr_destroy(&tconn->volumes);
32915 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
32916 index a9eccfc..f5efe87 100644
32917 --- a/drivers/block/drbd/drbd_receiver.c
32918 +++ b/drivers/block/drbd/drbd_receiver.c
32919 @@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
32920 {
32921 int err;
32922
32923 - atomic_set(&mdev->packet_seq, 0);
32924 + atomic_set_unchecked(&mdev->packet_seq, 0);
32925 mdev->peer_seq = 0;
32926
32927 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
32928 @@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32929 do {
32930 next_epoch = NULL;
32931
32932 - epoch_size = atomic_read(&epoch->epoch_size);
32933 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
32934
32935 switch (ev & ~EV_CLEANUP) {
32936 case EV_PUT:
32937 @@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32938 rv = FE_DESTROYED;
32939 } else {
32940 epoch->flags = 0;
32941 - atomic_set(&epoch->epoch_size, 0);
32942 + atomic_set_unchecked(&epoch->epoch_size, 0);
32943 /* atomic_set(&epoch->active, 0); is already zero */
32944 if (rv == FE_STILL_LIVE)
32945 rv = FE_RECYCLED;
32946 @@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32947 conn_wait_active_ee_empty(tconn);
32948 drbd_flush(tconn);
32949
32950 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
32951 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32952 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
32953 if (epoch)
32954 break;
32955 @@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32956 }
32957
32958 epoch->flags = 0;
32959 - atomic_set(&epoch->epoch_size, 0);
32960 + atomic_set_unchecked(&epoch->epoch_size, 0);
32961 atomic_set(&epoch->active, 0);
32962
32963 spin_lock(&tconn->epoch_lock);
32964 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
32965 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32966 list_add(&epoch->list, &tconn->current_epoch->list);
32967 tconn->current_epoch = epoch;
32968 tconn->epochs++;
32969 @@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
32970
32971 err = wait_for_and_update_peer_seq(mdev, peer_seq);
32972 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
32973 - atomic_inc(&tconn->current_epoch->epoch_size);
32974 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
32975 err2 = drbd_drain_block(mdev, pi->size);
32976 if (!err)
32977 err = err2;
32978 @@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
32979
32980 spin_lock(&tconn->epoch_lock);
32981 peer_req->epoch = tconn->current_epoch;
32982 - atomic_inc(&peer_req->epoch->epoch_size);
32983 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
32984 atomic_inc(&peer_req->epoch->active);
32985 spin_unlock(&tconn->epoch_lock);
32986
32987 @@ -4346,7 +4346,7 @@ struct data_cmd {
32988 int expect_payload;
32989 size_t pkt_size;
32990 int (*fn)(struct drbd_tconn *, struct packet_info *);
32991 -};
32992 +} __do_const;
32993
32994 static struct data_cmd drbd_cmd_handler[] = {
32995 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
32996 @@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
32997 if (!list_empty(&tconn->current_epoch->list))
32998 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
32999 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33000 - atomic_set(&tconn->current_epoch->epoch_size, 0);
33001 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33002 tconn->send.seen_any_write_yet = false;
33003
33004 conn_info(tconn, "Connection closed\n");
33005 @@ -5222,7 +5222,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33006 struct asender_cmd {
33007 size_t pkt_size;
33008 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33009 -};
33010 +} __do_const;
33011
33012 static struct asender_cmd asender_tbl[] = {
33013 [P_PING] = { 0, got_Ping },
33014 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33015 index ae12512..37fa397 100644
33016 --- a/drivers/block/loop.c
33017 +++ b/drivers/block/loop.c
33018 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
33019 mm_segment_t old_fs = get_fs();
33020
33021 set_fs(get_ds());
33022 - bw = file->f_op->write(file, buf, len, &pos);
33023 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33024 set_fs(old_fs);
33025 if (likely(bw == len))
33026 return 0;
33027 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33028 index d620b44..587561e 100644
33029 --- a/drivers/cdrom/cdrom.c
33030 +++ b/drivers/cdrom/cdrom.c
33031 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33032 ENSURE(reset, CDC_RESET);
33033 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33034 cdi->mc_flags = 0;
33035 - cdo->n_minors = 0;
33036 cdi->options = CDO_USE_FFLAGS;
33037
33038 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33039 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33040 else
33041 cdi->cdda_method = CDDA_OLD;
33042
33043 - if (!cdo->generic_packet)
33044 - cdo->generic_packet = cdrom_dummy_generic_packet;
33045 + if (!cdo->generic_packet) {
33046 + pax_open_kernel();
33047 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33048 + pax_close_kernel();
33049 + }
33050
33051 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33052 mutex_lock(&cdrom_mutex);
33053 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33054 if (cdi->exit)
33055 cdi->exit(cdi);
33056
33057 - cdi->ops->n_minors--;
33058 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33059 }
33060
33061 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33062 index d59cdcb..11afddf 100644
33063 --- a/drivers/cdrom/gdrom.c
33064 +++ b/drivers/cdrom/gdrom.c
33065 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33066 .audio_ioctl = gdrom_audio_ioctl,
33067 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33068 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33069 - .n_minors = 1,
33070 };
33071
33072 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33073 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33074 index 72bedad..8181ce1 100644
33075 --- a/drivers/char/Kconfig
33076 +++ b/drivers/char/Kconfig
33077 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33078
33079 config DEVKMEM
33080 bool "/dev/kmem virtual device support"
33081 - default y
33082 + default n
33083 + depends on !GRKERNSEC_KMEM
33084 help
33085 Say Y here if you want to support the /dev/kmem device. The
33086 /dev/kmem device is rarely used, but can be used for certain
33087 @@ -581,6 +582,7 @@ config DEVPORT
33088 bool
33089 depends on !M68K
33090 depends on ISA || PCI
33091 + depends on !GRKERNSEC_KMEM
33092 default y
33093
33094 source "drivers/s390/char/Kconfig"
33095 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33096 index 2e04433..22afc64 100644
33097 --- a/drivers/char/agp/frontend.c
33098 +++ b/drivers/char/agp/frontend.c
33099 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33100 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33101 return -EFAULT;
33102
33103 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33104 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33105 return -EFAULT;
33106
33107 client = agp_find_client_by_pid(reserve.pid);
33108 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33109 index 21cb980..f15107c 100644
33110 --- a/drivers/char/genrtc.c
33111 +++ b/drivers/char/genrtc.c
33112 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
33113 switch (cmd) {
33114
33115 case RTC_PLL_GET:
33116 + memset(&pll, 0, sizeof(pll));
33117 if (get_rtc_pll(&pll))
33118 return -EINVAL;
33119 else
33120 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33121 index fe6d4be..89f32100 100644
33122 --- a/drivers/char/hpet.c
33123 +++ b/drivers/char/hpet.c
33124 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33125 }
33126
33127 static int
33128 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33129 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33130 struct hpet_info *info)
33131 {
33132 struct hpet_timer __iomem *timer;
33133 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33134 index 053201b0..8335cce 100644
33135 --- a/drivers/char/ipmi/ipmi_msghandler.c
33136 +++ b/drivers/char/ipmi/ipmi_msghandler.c
33137 @@ -420,7 +420,7 @@ struct ipmi_smi {
33138 struct proc_dir_entry *proc_dir;
33139 char proc_dir_name[10];
33140
33141 - atomic_t stats[IPMI_NUM_STATS];
33142 + atomic_unchecked_t stats[IPMI_NUM_STATS];
33143
33144 /*
33145 * run_to_completion duplicate of smb_info, smi_info
33146 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33147
33148
33149 #define ipmi_inc_stat(intf, stat) \
33150 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33151 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33152 #define ipmi_get_stat(intf, stat) \
33153 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33154 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33155
33156 static int is_lan_addr(struct ipmi_addr *addr)
33157 {
33158 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33159 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33160 init_waitqueue_head(&intf->waitq);
33161 for (i = 0; i < IPMI_NUM_STATS; i++)
33162 - atomic_set(&intf->stats[i], 0);
33163 + atomic_set_unchecked(&intf->stats[i], 0);
33164
33165 intf->proc_dir = NULL;
33166
33167 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33168 index 1c7fdcd..4899100 100644
33169 --- a/drivers/char/ipmi/ipmi_si_intf.c
33170 +++ b/drivers/char/ipmi/ipmi_si_intf.c
33171 @@ -275,7 +275,7 @@ struct smi_info {
33172 unsigned char slave_addr;
33173
33174 /* Counters and things for the proc filesystem. */
33175 - atomic_t stats[SI_NUM_STATS];
33176 + atomic_unchecked_t stats[SI_NUM_STATS];
33177
33178 struct task_struct *thread;
33179
33180 @@ -284,9 +284,9 @@ struct smi_info {
33181 };
33182
33183 #define smi_inc_stat(smi, stat) \
33184 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
33185 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
33186 #define smi_get_stat(smi, stat) \
33187 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
33188 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
33189
33190 #define SI_MAX_PARMS 4
33191
33192 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
33193 atomic_set(&new_smi->req_events, 0);
33194 new_smi->run_to_completion = 0;
33195 for (i = 0; i < SI_NUM_STATS; i++)
33196 - atomic_set(&new_smi->stats[i], 0);
33197 + atomic_set_unchecked(&new_smi->stats[i], 0);
33198
33199 new_smi->interrupt_disabled = 1;
33200 atomic_set(&new_smi->stop_operation, 0);
33201 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
33202 index c6fa3bc..4ca3e42 100644
33203 --- a/drivers/char/mem.c
33204 +++ b/drivers/char/mem.c
33205 @@ -18,6 +18,7 @@
33206 #include <linux/raw.h>
33207 #include <linux/tty.h>
33208 #include <linux/capability.h>
33209 +#include <linux/security.h>
33210 #include <linux/ptrace.h>
33211 #include <linux/device.h>
33212 #include <linux/highmem.h>
33213 @@ -37,6 +38,10 @@
33214
33215 #define DEVPORT_MINOR 4
33216
33217 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33218 +extern const struct file_operations grsec_fops;
33219 +#endif
33220 +
33221 static inline unsigned long size_inside_page(unsigned long start,
33222 unsigned long size)
33223 {
33224 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33225
33226 while (cursor < to) {
33227 if (!devmem_is_allowed(pfn)) {
33228 +#ifdef CONFIG_GRKERNSEC_KMEM
33229 + gr_handle_mem_readwrite(from, to);
33230 +#else
33231 printk(KERN_INFO
33232 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
33233 current->comm, from, to);
33234 +#endif
33235 return 0;
33236 }
33237 cursor += PAGE_SIZE;
33238 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33239 }
33240 return 1;
33241 }
33242 +#elif defined(CONFIG_GRKERNSEC_KMEM)
33243 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33244 +{
33245 + return 0;
33246 +}
33247 #else
33248 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33249 {
33250 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33251
33252 while (count > 0) {
33253 unsigned long remaining;
33254 + char *temp;
33255
33256 sz = size_inside_page(p, count);
33257
33258 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33259 if (!ptr)
33260 return -EFAULT;
33261
33262 - remaining = copy_to_user(buf, ptr, sz);
33263 +#ifdef CONFIG_PAX_USERCOPY
33264 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33265 + if (!temp) {
33266 + unxlate_dev_mem_ptr(p, ptr);
33267 + return -ENOMEM;
33268 + }
33269 + memcpy(temp, ptr, sz);
33270 +#else
33271 + temp = ptr;
33272 +#endif
33273 +
33274 + remaining = copy_to_user(buf, temp, sz);
33275 +
33276 +#ifdef CONFIG_PAX_USERCOPY
33277 + kfree(temp);
33278 +#endif
33279 +
33280 unxlate_dev_mem_ptr(p, ptr);
33281 if (remaining)
33282 return -EFAULT;
33283 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33284 size_t count, loff_t *ppos)
33285 {
33286 unsigned long p = *ppos;
33287 - ssize_t low_count, read, sz;
33288 + ssize_t low_count, read, sz, err = 0;
33289 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
33290 - int err = 0;
33291
33292 read = 0;
33293 if (p < (unsigned long) high_memory) {
33294 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33295 }
33296 #endif
33297 while (low_count > 0) {
33298 + char *temp;
33299 +
33300 sz = size_inside_page(p, low_count);
33301
33302 /*
33303 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33304 */
33305 kbuf = xlate_dev_kmem_ptr((char *)p);
33306
33307 - if (copy_to_user(buf, kbuf, sz))
33308 +#ifdef CONFIG_PAX_USERCOPY
33309 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33310 + if (!temp)
33311 + return -ENOMEM;
33312 + memcpy(temp, kbuf, sz);
33313 +#else
33314 + temp = kbuf;
33315 +#endif
33316 +
33317 + err = copy_to_user(buf, temp, sz);
33318 +
33319 +#ifdef CONFIG_PAX_USERCOPY
33320 + kfree(temp);
33321 +#endif
33322 +
33323 + if (err)
33324 return -EFAULT;
33325 buf += sz;
33326 p += sz;
33327 @@ -833,6 +880,9 @@ static const struct memdev {
33328 #ifdef CONFIG_CRASH_DUMP
33329 [12] = { "oldmem", 0, &oldmem_fops, NULL },
33330 #endif
33331 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33332 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
33333 +#endif
33334 };
33335
33336 static int memory_open(struct inode *inode, struct file *filp)
33337 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
33338 index 9df78e2..01ba9ae 100644
33339 --- a/drivers/char/nvram.c
33340 +++ b/drivers/char/nvram.c
33341 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
33342
33343 spin_unlock_irq(&rtc_lock);
33344
33345 - if (copy_to_user(buf, contents, tmp - contents))
33346 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
33347 return -EFAULT;
33348
33349 *ppos = i;
33350 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
33351 index b66eaa0..2619d1b 100644
33352 --- a/drivers/char/pcmcia/synclink_cs.c
33353 +++ b/drivers/char/pcmcia/synclink_cs.c
33354 @@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33355
33356 if (debug_level >= DEBUG_LEVEL_INFO)
33357 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
33358 - __FILE__,__LINE__, info->device_name, port->count);
33359 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
33360
33361 - WARN_ON(!port->count);
33362 + WARN_ON(!atomic_read(&port->count));
33363
33364 if (tty_port_close_start(port, tty, filp) == 0)
33365 goto cleanup;
33366 @@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33367 cleanup:
33368 if (debug_level >= DEBUG_LEVEL_INFO)
33369 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
33370 - tty->driver->name, port->count);
33371 + tty->driver->name, atomic_read(&port->count));
33372 }
33373
33374 /* Wait until the transmitter is empty.
33375 @@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33376
33377 if (debug_level >= DEBUG_LEVEL_INFO)
33378 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
33379 - __FILE__,__LINE__,tty->driver->name, port->count);
33380 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
33381
33382 /* If port is closing, signal caller to try again */
33383 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
33384 @@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33385 goto cleanup;
33386 }
33387 spin_lock(&port->lock);
33388 - port->count++;
33389 + atomic_inc(&port->count);
33390 spin_unlock(&port->lock);
33391 spin_unlock_irqrestore(&info->netlock, flags);
33392
33393 - if (port->count == 1) {
33394 + if (atomic_read(&port->count) == 1) {
33395 /* 1st open on this device, init hardware */
33396 retval = startup(info, tty);
33397 if (retval < 0)
33398 @@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
33399 unsigned short new_crctype;
33400
33401 /* return error if TTY interface open */
33402 - if (info->port.count)
33403 + if (atomic_read(&info->port.count))
33404 return -EBUSY;
33405
33406 switch (encoding)
33407 @@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
33408
33409 /* arbitrate between network and tty opens */
33410 spin_lock_irqsave(&info->netlock, flags);
33411 - if (info->port.count != 0 || info->netcount != 0) {
33412 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
33413 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
33414 spin_unlock_irqrestore(&info->netlock, flags);
33415 return -EBUSY;
33416 @@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
33417 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
33418
33419 /* return error if TTY interface open */
33420 - if (info->port.count)
33421 + if (atomic_read(&info->port.count))
33422 return -EBUSY;
33423
33424 if (cmd != SIOCWANDEV)
33425 diff --git a/drivers/char/random.c b/drivers/char/random.c
33426 index 85e81ec..a129a39 100644
33427 --- a/drivers/char/random.c
33428 +++ b/drivers/char/random.c
33429 @@ -272,8 +272,13 @@
33430 /*
33431 * Configuration information
33432 */
33433 +#ifdef CONFIG_GRKERNSEC_RANDNET
33434 +#define INPUT_POOL_WORDS 512
33435 +#define OUTPUT_POOL_WORDS 128
33436 +#else
33437 #define INPUT_POOL_WORDS 128
33438 #define OUTPUT_POOL_WORDS 32
33439 +#endif
33440 #define SEC_XFER_SIZE 512
33441 #define EXTRACT_SIZE 10
33442
33443 @@ -313,10 +318,17 @@ static struct poolinfo {
33444 int poolwords;
33445 int tap1, tap2, tap3, tap4, tap5;
33446 } poolinfo_table[] = {
33447 +#ifdef CONFIG_GRKERNSEC_RANDNET
33448 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
33449 + { 512, 411, 308, 208, 104, 1 },
33450 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
33451 + { 128, 103, 76, 51, 25, 1 },
33452 +#else
33453 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
33454 { 128, 103, 76, 51, 25, 1 },
33455 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
33456 { 32, 26, 20, 14, 7, 1 },
33457 +#endif
33458 #if 0
33459 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
33460 { 2048, 1638, 1231, 819, 411, 1 },
33461 @@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
33462 input_rotate += i ? 7 : 14;
33463 }
33464
33465 - ACCESS_ONCE(r->input_rotate) = input_rotate;
33466 - ACCESS_ONCE(r->add_ptr) = i;
33467 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
33468 + ACCESS_ONCE_RW(r->add_ptr) = i;
33469 smp_wmb();
33470
33471 if (out)
33472 @@ -1020,7 +1032,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
33473
33474 extract_buf(r, tmp);
33475 i = min_t(int, nbytes, EXTRACT_SIZE);
33476 - if (copy_to_user(buf, tmp, i)) {
33477 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
33478 ret = -EFAULT;
33479 break;
33480 }
33481 @@ -1356,7 +1368,7 @@ EXPORT_SYMBOL(generate_random_uuid);
33482 #include <linux/sysctl.h>
33483
33484 static int min_read_thresh = 8, min_write_thresh;
33485 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
33486 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
33487 static int max_write_thresh = INPUT_POOL_WORDS * 32;
33488 static char sysctl_bootid[16];
33489
33490 @@ -1372,7 +1384,7 @@ static char sysctl_bootid[16];
33491 static int proc_do_uuid(ctl_table *table, int write,
33492 void __user *buffer, size_t *lenp, loff_t *ppos)
33493 {
33494 - ctl_table fake_table;
33495 + ctl_table_no_const fake_table;
33496 unsigned char buf[64], tmp_uuid[16], *uuid;
33497
33498 uuid = table->data;
33499 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
33500 index d780295..b29f3a8 100644
33501 --- a/drivers/char/sonypi.c
33502 +++ b/drivers/char/sonypi.c
33503 @@ -54,6 +54,7 @@
33504
33505 #include <asm/uaccess.h>
33506 #include <asm/io.h>
33507 +#include <asm/local.h>
33508
33509 #include <linux/sonypi.h>
33510
33511 @@ -490,7 +491,7 @@ static struct sonypi_device {
33512 spinlock_t fifo_lock;
33513 wait_queue_head_t fifo_proc_list;
33514 struct fasync_struct *fifo_async;
33515 - int open_count;
33516 + local_t open_count;
33517 int model;
33518 struct input_dev *input_jog_dev;
33519 struct input_dev *input_key_dev;
33520 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
33521 static int sonypi_misc_release(struct inode *inode, struct file *file)
33522 {
33523 mutex_lock(&sonypi_device.lock);
33524 - sonypi_device.open_count--;
33525 + local_dec(&sonypi_device.open_count);
33526 mutex_unlock(&sonypi_device.lock);
33527 return 0;
33528 }
33529 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
33530 {
33531 mutex_lock(&sonypi_device.lock);
33532 /* Flush input queue on first open */
33533 - if (!sonypi_device.open_count)
33534 + if (!local_read(&sonypi_device.open_count))
33535 kfifo_reset(&sonypi_device.fifo);
33536 - sonypi_device.open_count++;
33537 + local_inc(&sonypi_device.open_count);
33538 mutex_unlock(&sonypi_device.lock);
33539
33540 return 0;
33541 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
33542 index 93211df..c7805f7 100644
33543 --- a/drivers/char/tpm/tpm.c
33544 +++ b/drivers/char/tpm/tpm.c
33545 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
33546 chip->vendor.req_complete_val)
33547 goto out_recv;
33548
33549 - if ((status == chip->vendor.req_canceled)) {
33550 + if (status == chip->vendor.req_canceled) {
33551 dev_err(chip->dev, "Operation Canceled\n");
33552 rc = -ECANCELED;
33553 goto out;
33554 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
33555 index 56051d0..11cf3b7 100644
33556 --- a/drivers/char/tpm/tpm_acpi.c
33557 +++ b/drivers/char/tpm/tpm_acpi.c
33558 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
33559 virt = acpi_os_map_memory(start, len);
33560 if (!virt) {
33561 kfree(log->bios_event_log);
33562 + log->bios_event_log = NULL;
33563 printk("%s: ERROR - Unable to map memory\n", __func__);
33564 return -EIO;
33565 }
33566
33567 - memcpy_fromio(log->bios_event_log, virt, len);
33568 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
33569
33570 acpi_os_unmap_memory(virt, len);
33571 return 0;
33572 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
33573 index 84ddc55..1d32f1e 100644
33574 --- a/drivers/char/tpm/tpm_eventlog.c
33575 +++ b/drivers/char/tpm/tpm_eventlog.c
33576 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
33577 event = addr;
33578
33579 if ((event->event_type == 0 && event->event_size == 0) ||
33580 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
33581 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
33582 return NULL;
33583
33584 return addr;
33585 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
33586 return NULL;
33587
33588 if ((event->event_type == 0 && event->event_size == 0) ||
33589 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
33590 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
33591 return NULL;
33592
33593 (*pos)++;
33594 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
33595 int i;
33596
33597 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
33598 - seq_putc(m, data[i]);
33599 + if (!seq_putc(m, data[i]))
33600 + return -EFAULT;
33601
33602 return 0;
33603 }
33604 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
33605 index ee4dbea..69c817b 100644
33606 --- a/drivers/char/virtio_console.c
33607 +++ b/drivers/char/virtio_console.c
33608 @@ -681,7 +681,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
33609 if (to_user) {
33610 ssize_t ret;
33611
33612 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
33613 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
33614 if (ret)
33615 return -EFAULT;
33616 } else {
33617 @@ -780,7 +780,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
33618 if (!port_has_data(port) && !port->host_connected)
33619 return 0;
33620
33621 - return fill_readbuf(port, ubuf, count, true);
33622 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
33623 }
33624
33625 static int wait_port_writable(struct port *port, bool nonblock)
33626 diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
33627 index 8ae1a61..9c00613 100644
33628 --- a/drivers/clocksource/arm_generic.c
33629 +++ b/drivers/clocksource/arm_generic.c
33630 @@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
33631 return NOTIFY_OK;
33632 }
33633
33634 -static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
33635 +static struct notifier_block arch_timer_cpu_nb = {
33636 .notifier_call = arch_timer_cpu_notify,
33637 };
33638
33639 diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
33640 index fce2000..1110478 100644
33641 --- a/drivers/connector/cn_proc.c
33642 +++ b/drivers/connector/cn_proc.c
33643 @@ -313,6 +313,12 @@ static void cn_proc_mcast_ctl(struct cn_msg *msg,
33644 (task_active_pid_ns(current) != &init_pid_ns))
33645 return;
33646
33647 + /* Can only change if privileged. */
33648 + if (!capable(CAP_NET_ADMIN)) {
33649 + err = EPERM;
33650 + goto out;
33651 + }
33652 +
33653 mc_op = (enum proc_cn_mcast_op *)msg->data;
33654 switch (*mc_op) {
33655 case PROC_CN_MCAST_LISTEN:
33656 @@ -325,6 +331,8 @@ static void cn_proc_mcast_ctl(struct cn_msg *msg,
33657 err = EINVAL;
33658 break;
33659 }
33660 +
33661 +out:
33662 cn_proc_ack(err, msg->seq, msg->ack);
33663 }
33664
33665 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
33666 index 7b0d49d..134fac9 100644
33667 --- a/drivers/cpufreq/acpi-cpufreq.c
33668 +++ b/drivers/cpufreq/acpi-cpufreq.c
33669 @@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
33670 return sprintf(buf, "%u\n", boost_enabled);
33671 }
33672
33673 -static struct global_attr global_boost = __ATTR(boost, 0644,
33674 +static global_attr_no_const global_boost = __ATTR(boost, 0644,
33675 show_global_boost,
33676 store_global_boost);
33677
33678 @@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33679 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
33680 per_cpu(acfreq_data, cpu) = data;
33681
33682 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
33683 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
33684 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
33685 + pax_open_kernel();
33686 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
33687 + pax_close_kernel();
33688 + }
33689
33690 result = acpi_processor_register_performance(data->acpi_data, cpu);
33691 if (result)
33692 @@ -835,7 +838,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33693 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
33694 break;
33695 case ACPI_ADR_SPACE_FIXED_HARDWARE:
33696 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
33697 + pax_open_kernel();
33698 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
33699 + pax_close_kernel();
33700 policy->cur = get_cur_freq_on_cpu(cpu);
33701 break;
33702 default:
33703 @@ -846,8 +851,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33704 acpi_processor_notify_smm(THIS_MODULE);
33705
33706 /* Check for APERF/MPERF support in hardware */
33707 - if (boot_cpu_has(X86_FEATURE_APERFMPERF))
33708 - acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
33709 + if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
33710 + pax_open_kernel();
33711 + *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
33712 + pax_close_kernel();
33713 + }
33714
33715 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
33716 for (i = 0; i < perf->state_count; i++)
33717 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
33718 index 1f93dbd..305cef1 100644
33719 --- a/drivers/cpufreq/cpufreq.c
33720 +++ b/drivers/cpufreq/cpufreq.c
33721 @@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
33722 return NOTIFY_OK;
33723 }
33724
33725 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
33726 +static struct notifier_block cpufreq_cpu_notifier = {
33727 .notifier_call = cpufreq_cpu_callback,
33728 };
33729
33730 @@ -1875,8 +1875,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
33731
33732 pr_debug("trying to register driver %s\n", driver_data->name);
33733
33734 - if (driver_data->setpolicy)
33735 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
33736 + if (driver_data->setpolicy) {
33737 + pax_open_kernel();
33738 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
33739 + pax_close_kernel();
33740 + }
33741
33742 spin_lock_irqsave(&cpufreq_driver_lock, flags);
33743 if (cpufreq_driver) {
33744 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
33745 index 6c5f1d3..9c76f07 100644
33746 --- a/drivers/cpufreq/cpufreq_governor.c
33747 +++ b/drivers/cpufreq/cpufreq_governor.c
33748 @@ -243,7 +243,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
33749 * governor, thus we are bound to jiffes/HZ
33750 */
33751 if (dbs_data->governor == GOV_CONSERVATIVE) {
33752 - struct cs_ops *ops = dbs_data->gov_ops;
33753 + const struct cs_ops *ops = dbs_data->gov_ops;
33754
33755 cpufreq_register_notifier(ops->notifier_block,
33756 CPUFREQ_TRANSITION_NOTIFIER);
33757 @@ -289,7 +289,7 @@ second_time:
33758 mutex_destroy(&cpu_cdbs->timer_mutex);
33759 dbs_data->enable--;
33760 if (!dbs_data->enable) {
33761 - struct cs_ops *ops = dbs_data->gov_ops;
33762 + const struct cs_ops *ops = dbs_data->gov_ops;
33763
33764 sysfs_remove_group(cpufreq_global_kobject,
33765 dbs_data->attr_group);
33766 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
33767 index f661654..6c8e638 100644
33768 --- a/drivers/cpufreq/cpufreq_governor.h
33769 +++ b/drivers/cpufreq/cpufreq_governor.h
33770 @@ -142,7 +142,7 @@ struct dbs_data {
33771 void (*gov_check_cpu)(int cpu, unsigned int load);
33772
33773 /* Governor specific ops, see below */
33774 - void *gov_ops;
33775 + const void *gov_ops;
33776 };
33777
33778 /* Governor specific ops, will be passed to dbs_data->gov_ops */
33779 diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
33780 index 9d7732b..0b1a793 100644
33781 --- a/drivers/cpufreq/cpufreq_stats.c
33782 +++ b/drivers/cpufreq/cpufreq_stats.c
33783 @@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
33784 }
33785
33786 /* priority=1 so this will get called before cpufreq_remove_dev */
33787 -static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
33788 +static struct notifier_block cpufreq_stat_cpu_notifier = {
33789 .notifier_call = cpufreq_stat_cpu_callback,
33790 .priority = 1,
33791 };
33792 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
33793 index 827629c9..0bc6a03 100644
33794 --- a/drivers/cpufreq/p4-clockmod.c
33795 +++ b/drivers/cpufreq/p4-clockmod.c
33796 @@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
33797 case 0x0F: /* Core Duo */
33798 case 0x16: /* Celeron Core */
33799 case 0x1C: /* Atom */
33800 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33801 + pax_open_kernel();
33802 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33803 + pax_close_kernel();
33804 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
33805 case 0x0D: /* Pentium M (Dothan) */
33806 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33807 + pax_open_kernel();
33808 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33809 + pax_close_kernel();
33810 /* fall through */
33811 case 0x09: /* Pentium M (Banias) */
33812 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
33813 @@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
33814
33815 /* on P-4s, the TSC runs with constant frequency independent whether
33816 * throttling is active or not. */
33817 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33818 + pax_open_kernel();
33819 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33820 + pax_close_kernel();
33821
33822 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
33823 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
33824 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
33825 index 3a953d5..f5993f6 100644
33826 --- a/drivers/cpufreq/speedstep-centrino.c
33827 +++ b/drivers/cpufreq/speedstep-centrino.c
33828 @@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
33829 !cpu_has(cpu, X86_FEATURE_EST))
33830 return -ENODEV;
33831
33832 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
33833 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
33834 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
33835 + pax_open_kernel();
33836 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
33837 + pax_close_kernel();
33838 + }
33839
33840 if (policy->cpu != 0)
33841 return -ENODEV;
33842 diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
33843 index e1f6860..f8de20b 100644
33844 --- a/drivers/cpuidle/cpuidle.c
33845 +++ b/drivers/cpuidle/cpuidle.c
33846 @@ -279,7 +279,7 @@ static int poll_idle(struct cpuidle_device *dev,
33847
33848 static void poll_idle_init(struct cpuidle_driver *drv)
33849 {
33850 - struct cpuidle_state *state = &drv->states[0];
33851 + cpuidle_state_no_const *state = &drv->states[0];
33852
33853 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
33854 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
33855 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
33856 index ea2f8e7..70ac501 100644
33857 --- a/drivers/cpuidle/governor.c
33858 +++ b/drivers/cpuidle/governor.c
33859 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
33860 mutex_lock(&cpuidle_lock);
33861 if (__cpuidle_find_governor(gov->name) == NULL) {
33862 ret = 0;
33863 - list_add_tail(&gov->governor_list, &cpuidle_governors);
33864 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
33865 if (!cpuidle_curr_governor ||
33866 cpuidle_curr_governor->rating < gov->rating)
33867 cpuidle_switch_governor(gov);
33868 @@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
33869 new_gov = cpuidle_replace_governor(gov->rating);
33870 cpuidle_switch_governor(new_gov);
33871 }
33872 - list_del(&gov->governor_list);
33873 + pax_list_del((struct list_head *)&gov->governor_list);
33874 mutex_unlock(&cpuidle_lock);
33875 }
33876
33877 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
33878 index 428754a..8bdf9cc 100644
33879 --- a/drivers/cpuidle/sysfs.c
33880 +++ b/drivers/cpuidle/sysfs.c
33881 @@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
33882 NULL
33883 };
33884
33885 -static struct attribute_group cpuidle_attr_group = {
33886 +static attribute_group_no_const cpuidle_attr_group = {
33887 .attrs = cpuidle_default_attrs,
33888 .name = "cpuidle",
33889 };
33890 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
33891 index 3b36797..289c16a 100644
33892 --- a/drivers/devfreq/devfreq.c
33893 +++ b/drivers/devfreq/devfreq.c
33894 @@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
33895 goto err_out;
33896 }
33897
33898 - list_add(&governor->node, &devfreq_governor_list);
33899 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
33900
33901 list_for_each_entry(devfreq, &devfreq_list, node) {
33902 int ret = 0;
33903 @@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
33904 }
33905 }
33906
33907 - list_del(&governor->node);
33908 + pax_list_del((struct list_head *)&governor->node);
33909 err_out:
33910 mutex_unlock(&devfreq_list_lock);
33911
33912 diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
33913 index b70709b..1d8d02a 100644
33914 --- a/drivers/dma/sh/shdma.c
33915 +++ b/drivers/dma/sh/shdma.c
33916 @@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
33917 return ret;
33918 }
33919
33920 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
33921 +static struct notifier_block sh_dmae_nmi_notifier = {
33922 .notifier_call = sh_dmae_nmi_handler,
33923
33924 /* Run before NMI debug handler and KGDB */
33925 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
33926 index 0ca1ca7..6e6f454 100644
33927 --- a/drivers/edac/edac_mc_sysfs.c
33928 +++ b/drivers/edac/edac_mc_sysfs.c
33929 @@ -148,7 +148,7 @@ static const char *edac_caps[] = {
33930 struct dev_ch_attribute {
33931 struct device_attribute attr;
33932 int channel;
33933 -};
33934 +} __do_const;
33935
33936 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
33937 struct dev_ch_attribute dev_attr_legacy_##_name = \
33938 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
33939 index 0056c4d..23b54d9 100644
33940 --- a/drivers/edac/edac_pci_sysfs.c
33941 +++ b/drivers/edac/edac_pci_sysfs.c
33942 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
33943 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
33944 static int edac_pci_poll_msec = 1000; /* one second workq period */
33945
33946 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
33947 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
33948 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
33949 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
33950
33951 static struct kobject *edac_pci_top_main_kobj;
33952 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
33953 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
33954 void *value;
33955 ssize_t(*show) (void *, char *);
33956 ssize_t(*store) (void *, const char *, size_t);
33957 -};
33958 +} __do_const;
33959
33960 /* Set of show/store abstract level functions for PCI Parity object */
33961 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
33962 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33963 edac_printk(KERN_CRIT, EDAC_PCI,
33964 "Signaled System Error on %s\n",
33965 pci_name(dev));
33966 - atomic_inc(&pci_nonparity_count);
33967 + atomic_inc_unchecked(&pci_nonparity_count);
33968 }
33969
33970 if (status & (PCI_STATUS_PARITY)) {
33971 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33972 "Master Data Parity Error on %s\n",
33973 pci_name(dev));
33974
33975 - atomic_inc(&pci_parity_count);
33976 + atomic_inc_unchecked(&pci_parity_count);
33977 }
33978
33979 if (status & (PCI_STATUS_DETECTED_PARITY)) {
33980 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33981 "Detected Parity Error on %s\n",
33982 pci_name(dev));
33983
33984 - atomic_inc(&pci_parity_count);
33985 + atomic_inc_unchecked(&pci_parity_count);
33986 }
33987 }
33988
33989 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33990 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
33991 "Signaled System Error on %s\n",
33992 pci_name(dev));
33993 - atomic_inc(&pci_nonparity_count);
33994 + atomic_inc_unchecked(&pci_nonparity_count);
33995 }
33996
33997 if (status & (PCI_STATUS_PARITY)) {
33998 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33999 "Master Data Parity Error on "
34000 "%s\n", pci_name(dev));
34001
34002 - atomic_inc(&pci_parity_count);
34003 + atomic_inc_unchecked(&pci_parity_count);
34004 }
34005
34006 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34007 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34008 "Detected Parity Error on %s\n",
34009 pci_name(dev));
34010
34011 - atomic_inc(&pci_parity_count);
34012 + atomic_inc_unchecked(&pci_parity_count);
34013 }
34014 }
34015 }
34016 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34017 if (!check_pci_errors)
34018 return;
34019
34020 - before_count = atomic_read(&pci_parity_count);
34021 + before_count = atomic_read_unchecked(&pci_parity_count);
34022
34023 /* scan all PCI devices looking for a Parity Error on devices and
34024 * bridges.
34025 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34026 /* Only if operator has selected panic on PCI Error */
34027 if (edac_pci_get_panic_on_pe()) {
34028 /* If the count is different 'after' from 'before' */
34029 - if (before_count != atomic_read(&pci_parity_count))
34030 + if (before_count != atomic_read_unchecked(&pci_parity_count))
34031 panic("EDAC: PCI Parity Error");
34032 }
34033 }
34034 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34035 index 6796799..99e8377 100644
34036 --- a/drivers/edac/mce_amd.h
34037 +++ b/drivers/edac/mce_amd.h
34038 @@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
34039 struct amd_decoder_ops {
34040 bool (*mc0_mce)(u16, u8);
34041 bool (*mc1_mce)(u16, u8);
34042 -};
34043 +} __no_const;
34044
34045 void amd_report_gart_errors(bool);
34046 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34047 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34048 index 57ea7f4..789e3c3 100644
34049 --- a/drivers/firewire/core-card.c
34050 +++ b/drivers/firewire/core-card.c
34051 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34052
34053 void fw_core_remove_card(struct fw_card *card)
34054 {
34055 - struct fw_card_driver dummy_driver = dummy_driver_template;
34056 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
34057
34058 card->driver->update_phy_reg(card, 4,
34059 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34060 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34061 index f8d2287..5aaf4db 100644
34062 --- a/drivers/firewire/core-cdev.c
34063 +++ b/drivers/firewire/core-cdev.c
34064 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
34065 int ret;
34066
34067 if ((request->channels == 0 && request->bandwidth == 0) ||
34068 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34069 - request->bandwidth < 0)
34070 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34071 return -EINVAL;
34072
34073 r = kmalloc(sizeof(*r), GFP_KERNEL);
34074 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34075 index af3e8aa..eb2f227 100644
34076 --- a/drivers/firewire/core-device.c
34077 +++ b/drivers/firewire/core-device.c
34078 @@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
34079 struct config_rom_attribute {
34080 struct device_attribute attr;
34081 u32 key;
34082 -};
34083 +} __do_const;
34084
34085 static ssize_t show_immediate(struct device *dev,
34086 struct device_attribute *dattr, char *buf)
34087 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
34088 index 28a94c7..58da63a 100644
34089 --- a/drivers/firewire/core-transaction.c
34090 +++ b/drivers/firewire/core-transaction.c
34091 @@ -38,6 +38,7 @@
34092 #include <linux/timer.h>
34093 #include <linux/types.h>
34094 #include <linux/workqueue.h>
34095 +#include <linux/sched.h>
34096
34097 #include <asm/byteorder.h>
34098
34099 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
34100 index 515a42c..5ecf3ba 100644
34101 --- a/drivers/firewire/core.h
34102 +++ b/drivers/firewire/core.h
34103 @@ -111,6 +111,7 @@ struct fw_card_driver {
34104
34105 int (*stop_iso)(struct fw_iso_context *ctx);
34106 };
34107 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
34108
34109 void fw_card_initialize(struct fw_card *card,
34110 const struct fw_card_driver *driver, struct device *device);
34111 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
34112 index 94a58a0..f5eba42 100644
34113 --- a/drivers/firmware/dmi-id.c
34114 +++ b/drivers/firmware/dmi-id.c
34115 @@ -16,7 +16,7 @@
34116 struct dmi_device_attribute{
34117 struct device_attribute dev_attr;
34118 int field;
34119 -};
34120 +} __do_const;
34121 #define to_dmi_dev_attr(_dev_attr) \
34122 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
34123
34124 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
34125 index 982f1f5..d21e5da 100644
34126 --- a/drivers/firmware/dmi_scan.c
34127 +++ b/drivers/firmware/dmi_scan.c
34128 @@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
34129 }
34130 }
34131 else {
34132 - /*
34133 - * no iounmap() for that ioremap(); it would be a no-op, but
34134 - * it's so early in setup that sucker gets confused into doing
34135 - * what it shouldn't if we actually call it.
34136 - */
34137 p = dmi_ioremap(0xF0000, 0x10000);
34138 if (p == NULL)
34139 goto error;
34140 @@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
34141 if (buf == NULL)
34142 return -1;
34143
34144 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
34145 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
34146
34147 iounmap(buf);
34148 return 0;
34149 diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
34150 index bcb201c..4fd34dd 100644
34151 --- a/drivers/firmware/efivars.c
34152 +++ b/drivers/firmware/efivars.c
34153 @@ -133,7 +133,7 @@ struct efivar_attribute {
34154 };
34155
34156 static struct efivars __efivars;
34157 -static struct efivar_operations ops;
34158 +static efivar_operations_no_const ops __read_only;
34159
34160 #define PSTORE_EFI_ATTRIBUTES \
34161 (EFI_VARIABLE_NON_VOLATILE | \
34162 @@ -1734,7 +1734,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
34163 static int
34164 create_efivars_bin_attributes(struct efivars *efivars)
34165 {
34166 - struct bin_attribute *attr;
34167 + bin_attribute_no_const *attr;
34168 int error;
34169
34170 /* new_var */
34171 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
34172 index 2a90ba6..07f3733 100644
34173 --- a/drivers/firmware/google/memconsole.c
34174 +++ b/drivers/firmware/google/memconsole.c
34175 @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
34176 if (!found_memconsole())
34177 return -ENODEV;
34178
34179 - memconsole_bin_attr.size = memconsole_length;
34180 + pax_open_kernel();
34181 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
34182 + pax_close_kernel();
34183
34184 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
34185
34186 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
34187 index 6f2306d..af9476a 100644
34188 --- a/drivers/gpio/gpio-ich.c
34189 +++ b/drivers/gpio/gpio-ich.c
34190 @@ -69,7 +69,7 @@ struct ichx_desc {
34191 /* Some chipsets have quirks, let these use their own request/get */
34192 int (*request)(struct gpio_chip *chip, unsigned offset);
34193 int (*get)(struct gpio_chip *chip, unsigned offset);
34194 -};
34195 +} __do_const;
34196
34197 static struct {
34198 spinlock_t lock;
34199 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
34200 index 9902732..64b62dd 100644
34201 --- a/drivers/gpio/gpio-vr41xx.c
34202 +++ b/drivers/gpio/gpio-vr41xx.c
34203 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
34204 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
34205 maskl, pendl, maskh, pendh);
34206
34207 - atomic_inc(&irq_err_count);
34208 + atomic_inc_unchecked(&irq_err_count);
34209
34210 return -EINVAL;
34211 }
34212 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
34213 index 7b2d378..cc947ea 100644
34214 --- a/drivers/gpu/drm/drm_crtc_helper.c
34215 +++ b/drivers/gpu/drm/drm_crtc_helper.c
34216 @@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
34217 struct drm_crtc *tmp;
34218 int crtc_mask = 1;
34219
34220 - WARN(!crtc, "checking null crtc?\n");
34221 + BUG_ON(!crtc);
34222
34223 dev = crtc->dev;
34224
34225 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
34226 index be174ca..7f38143 100644
34227 --- a/drivers/gpu/drm/drm_drv.c
34228 +++ b/drivers/gpu/drm/drm_drv.c
34229 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
34230 /**
34231 * Copy and IOCTL return string to user space
34232 */
34233 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
34234 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
34235 {
34236 int len;
34237
34238 @@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
34239 struct drm_file *file_priv = filp->private_data;
34240 struct drm_device *dev;
34241 struct drm_ioctl_desc *ioctl;
34242 - drm_ioctl_t *func;
34243 + drm_ioctl_no_const_t func;
34244 unsigned int nr = DRM_IOCTL_NR(cmd);
34245 int retcode = -EINVAL;
34246 char stack_kdata[128];
34247 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
34248 return -ENODEV;
34249
34250 atomic_inc(&dev->ioctl_count);
34251 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
34252 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
34253 ++file_priv->ioctl_count;
34254
34255 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
34256 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
34257 index 133b413..fd68225 100644
34258 --- a/drivers/gpu/drm/drm_fops.c
34259 +++ b/drivers/gpu/drm/drm_fops.c
34260 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
34261 }
34262
34263 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
34264 - atomic_set(&dev->counts[i], 0);
34265 + atomic_set_unchecked(&dev->counts[i], 0);
34266
34267 dev->sigdata.lock = NULL;
34268
34269 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
34270 if (drm_device_is_unplugged(dev))
34271 return -ENODEV;
34272
34273 - if (!dev->open_count++)
34274 + if (local_inc_return(&dev->open_count) == 1)
34275 need_setup = 1;
34276 mutex_lock(&dev->struct_mutex);
34277 old_mapping = dev->dev_mapping;
34278 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
34279 retcode = drm_open_helper(inode, filp, dev);
34280 if (retcode)
34281 goto err_undo;
34282 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
34283 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
34284 if (need_setup) {
34285 retcode = drm_setup(dev);
34286 if (retcode)
34287 @@ -164,7 +164,7 @@ err_undo:
34288 iput(container_of(dev->dev_mapping, struct inode, i_data));
34289 dev->dev_mapping = old_mapping;
34290 mutex_unlock(&dev->struct_mutex);
34291 - dev->open_count--;
34292 + local_dec(&dev->open_count);
34293 return retcode;
34294 }
34295 EXPORT_SYMBOL(drm_open);
34296 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
34297
34298 mutex_lock(&drm_global_mutex);
34299
34300 - DRM_DEBUG("open_count = %d\n", dev->open_count);
34301 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
34302
34303 if (dev->driver->preclose)
34304 dev->driver->preclose(dev, file_priv);
34305 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
34306 * Begin inline drm_release
34307 */
34308
34309 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
34310 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
34311 task_pid_nr(current),
34312 (long)old_encode_dev(file_priv->minor->device),
34313 - dev->open_count);
34314 + local_read(&dev->open_count));
34315
34316 /* Release any auth tokens that might point to this file_priv,
34317 (do that under the drm_global_mutex) */
34318 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
34319 * End inline drm_release
34320 */
34321
34322 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
34323 - if (!--dev->open_count) {
34324 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
34325 + if (local_dec_and_test(&dev->open_count)) {
34326 if (atomic_read(&dev->ioctl_count)) {
34327 DRM_ERROR("Device busy: %d\n",
34328 atomic_read(&dev->ioctl_count));
34329 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
34330 index f731116..629842c 100644
34331 --- a/drivers/gpu/drm/drm_global.c
34332 +++ b/drivers/gpu/drm/drm_global.c
34333 @@ -36,7 +36,7 @@
34334 struct drm_global_item {
34335 struct mutex mutex;
34336 void *object;
34337 - int refcount;
34338 + atomic_t refcount;
34339 };
34340
34341 static struct drm_global_item glob[DRM_GLOBAL_NUM];
34342 @@ -49,7 +49,7 @@ void drm_global_init(void)
34343 struct drm_global_item *item = &glob[i];
34344 mutex_init(&item->mutex);
34345 item->object = NULL;
34346 - item->refcount = 0;
34347 + atomic_set(&item->refcount, 0);
34348 }
34349 }
34350
34351 @@ -59,7 +59,7 @@ void drm_global_release(void)
34352 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
34353 struct drm_global_item *item = &glob[i];
34354 BUG_ON(item->object != NULL);
34355 - BUG_ON(item->refcount != 0);
34356 + BUG_ON(atomic_read(&item->refcount) != 0);
34357 }
34358 }
34359
34360 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34361 void *object;
34362
34363 mutex_lock(&item->mutex);
34364 - if (item->refcount == 0) {
34365 + if (atomic_read(&item->refcount) == 0) {
34366 item->object = kzalloc(ref->size, GFP_KERNEL);
34367 if (unlikely(item->object == NULL)) {
34368 ret = -ENOMEM;
34369 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34370 goto out_err;
34371
34372 }
34373 - ++item->refcount;
34374 + atomic_inc(&item->refcount);
34375 ref->object = item->object;
34376 object = item->object;
34377 mutex_unlock(&item->mutex);
34378 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
34379 struct drm_global_item *item = &glob[ref->global_type];
34380
34381 mutex_lock(&item->mutex);
34382 - BUG_ON(item->refcount == 0);
34383 + BUG_ON(atomic_read(&item->refcount) == 0);
34384 BUG_ON(ref->object != item->object);
34385 - if (--item->refcount == 0) {
34386 + if (atomic_dec_and_test(&item->refcount)) {
34387 ref->release(ref);
34388 item->object = NULL;
34389 }
34390 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
34391 index d4b20ce..77a8d41 100644
34392 --- a/drivers/gpu/drm/drm_info.c
34393 +++ b/drivers/gpu/drm/drm_info.c
34394 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
34395 struct drm_local_map *map;
34396 struct drm_map_list *r_list;
34397
34398 - /* Hardcoded from _DRM_FRAME_BUFFER,
34399 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
34400 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
34401 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
34402 + static const char * const types[] = {
34403 + [_DRM_FRAME_BUFFER] = "FB",
34404 + [_DRM_REGISTERS] = "REG",
34405 + [_DRM_SHM] = "SHM",
34406 + [_DRM_AGP] = "AGP",
34407 + [_DRM_SCATTER_GATHER] = "SG",
34408 + [_DRM_CONSISTENT] = "PCI",
34409 + [_DRM_GEM] = "GEM" };
34410 const char *type;
34411 int i;
34412
34413 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
34414 map = r_list->map;
34415 if (!map)
34416 continue;
34417 - if (map->type < 0 || map->type > 5)
34418 + if (map->type >= ARRAY_SIZE(types))
34419 type = "??";
34420 else
34421 type = types[map->type];
34422 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
34423 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
34424 vma->vm_flags & VM_LOCKED ? 'l' : '-',
34425 vma->vm_flags & VM_IO ? 'i' : '-',
34426 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34427 + 0);
34428 +#else
34429 vma->vm_pgoff);
34430 +#endif
34431
34432 #if defined(__i386__)
34433 pgprot = pgprot_val(vma->vm_page_prot);
34434 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
34435 index 2f4c434..dd12cd2 100644
34436 --- a/drivers/gpu/drm/drm_ioc32.c
34437 +++ b/drivers/gpu/drm/drm_ioc32.c
34438 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
34439 request = compat_alloc_user_space(nbytes);
34440 if (!access_ok(VERIFY_WRITE, request, nbytes))
34441 return -EFAULT;
34442 - list = (struct drm_buf_desc *) (request + 1);
34443 + list = (struct drm_buf_desc __user *) (request + 1);
34444
34445 if (__put_user(count, &request->count)
34446 || __put_user(list, &request->list))
34447 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
34448 request = compat_alloc_user_space(nbytes);
34449 if (!access_ok(VERIFY_WRITE, request, nbytes))
34450 return -EFAULT;
34451 - list = (struct drm_buf_pub *) (request + 1);
34452 + list = (struct drm_buf_pub __user *) (request + 1);
34453
34454 if (__put_user(count, &request->count)
34455 || __put_user(list, &request->list))
34456 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
34457 return 0;
34458 }
34459
34460 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
34461 +drm_ioctl_compat_t drm_compat_ioctls[] = {
34462 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
34463 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
34464 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
34465 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
34466 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34467 {
34468 unsigned int nr = DRM_IOCTL_NR(cmd);
34469 - drm_ioctl_compat_t *fn;
34470 int ret;
34471
34472 /* Assume that ioctls without an explicit compat routine will just
34473 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34474 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
34475 return drm_ioctl(filp, cmd, arg);
34476
34477 - fn = drm_compat_ioctls[nr];
34478 -
34479 - if (fn != NULL)
34480 - ret = (*fn) (filp, cmd, arg);
34481 + if (drm_compat_ioctls[nr] != NULL)
34482 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
34483 else
34484 ret = drm_ioctl(filp, cmd, arg);
34485
34486 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
34487 index e77bd8b..1571b85 100644
34488 --- a/drivers/gpu/drm/drm_ioctl.c
34489 +++ b/drivers/gpu/drm/drm_ioctl.c
34490 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
34491 stats->data[i].value =
34492 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
34493 else
34494 - stats->data[i].value = atomic_read(&dev->counts[i]);
34495 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
34496 stats->data[i].type = dev->types[i];
34497 }
34498
34499 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
34500 index d752c96..fe08455 100644
34501 --- a/drivers/gpu/drm/drm_lock.c
34502 +++ b/drivers/gpu/drm/drm_lock.c
34503 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34504 if (drm_lock_take(&master->lock, lock->context)) {
34505 master->lock.file_priv = file_priv;
34506 master->lock.lock_time = jiffies;
34507 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
34508 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
34509 break; /* Got lock */
34510 }
34511
34512 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34513 return -EINVAL;
34514 }
34515
34516 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
34517 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
34518
34519 if (drm_lock_free(&master->lock, lock->context)) {
34520 /* FIXME: Should really bail out here. */
34521 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
34522 index 200e104..59facda 100644
34523 --- a/drivers/gpu/drm/drm_stub.c
34524 +++ b/drivers/gpu/drm/drm_stub.c
34525 @@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
34526
34527 drm_device_set_unplugged(dev);
34528
34529 - if (dev->open_count == 0) {
34530 + if (local_read(&dev->open_count) == 0) {
34531 drm_put_dev(dev);
34532 }
34533 mutex_unlock(&drm_global_mutex);
34534 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
34535 index 004ecdf..db1f6e0 100644
34536 --- a/drivers/gpu/drm/i810/i810_dma.c
34537 +++ b/drivers/gpu/drm/i810/i810_dma.c
34538 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
34539 dma->buflist[vertex->idx],
34540 vertex->discard, vertex->used);
34541
34542 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34543 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34544 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34545 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34546 sarea_priv->last_enqueue = dev_priv->counter - 1;
34547 sarea_priv->last_dispatch = (int)hw_status[5];
34548
34549 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
34550 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
34551 mc->last_render);
34552
34553 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34554 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34555 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34556 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34557 sarea_priv->last_enqueue = dev_priv->counter - 1;
34558 sarea_priv->last_dispatch = (int)hw_status[5];
34559
34560 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
34561 index 6e0acad..93c8289 100644
34562 --- a/drivers/gpu/drm/i810/i810_drv.h
34563 +++ b/drivers/gpu/drm/i810/i810_drv.h
34564 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
34565 int page_flipping;
34566
34567 wait_queue_head_t irq_queue;
34568 - atomic_t irq_received;
34569 - atomic_t irq_emitted;
34570 + atomic_unchecked_t irq_received;
34571 + atomic_unchecked_t irq_emitted;
34572
34573 int front_offset;
34574 } drm_i810_private_t;
34575 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
34576 index 8a7c48b..72effc2 100644
34577 --- a/drivers/gpu/drm/i915/i915_debugfs.c
34578 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
34579 @@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
34580 I915_READ(GTIMR));
34581 }
34582 seq_printf(m, "Interrupts received: %d\n",
34583 - atomic_read(&dev_priv->irq_received));
34584 + atomic_read_unchecked(&dev_priv->irq_received));
34585 for_each_ring(ring, dev_priv, i) {
34586 if (IS_GEN6(dev) || IS_GEN7(dev)) {
34587 seq_printf(m,
34588 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
34589 index 99daa89..84ebd44 100644
34590 --- a/drivers/gpu/drm/i915/i915_dma.c
34591 +++ b/drivers/gpu/drm/i915/i915_dma.c
34592 @@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
34593 bool can_switch;
34594
34595 spin_lock(&dev->count_lock);
34596 - can_switch = (dev->open_count == 0);
34597 + can_switch = (local_read(&dev->open_count) == 0);
34598 spin_unlock(&dev->count_lock);
34599 return can_switch;
34600 }
34601 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
34602 index 7339a4b..445aaba 100644
34603 --- a/drivers/gpu/drm/i915/i915_drv.h
34604 +++ b/drivers/gpu/drm/i915/i915_drv.h
34605 @@ -656,7 +656,7 @@ typedef struct drm_i915_private {
34606 drm_dma_handle_t *status_page_dmah;
34607 struct resource mch_res;
34608
34609 - atomic_t irq_received;
34610 + atomic_unchecked_t irq_received;
34611
34612 /* protects the irq masks */
34613 spinlock_t irq_lock;
34614 @@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
34615 * will be page flipped away on the next vblank. When it
34616 * reaches 0, dev_priv->pending_flip_queue will be woken up.
34617 */
34618 - atomic_t pending_flip;
34619 + atomic_unchecked_t pending_flip;
34620 };
34621 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
34622
34623 @@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
34624 struct drm_i915_private *dev_priv, unsigned port);
34625 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
34626 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
34627 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
34628 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
34629 {
34630 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
34631 }
34632 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34633 index 26d08bb..fccb984 100644
34634 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34635 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34636 @@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
34637 i915_gem_clflush_object(obj);
34638
34639 if (obj->base.pending_write_domain)
34640 - flips |= atomic_read(&obj->pending_flip);
34641 + flips |= atomic_read_unchecked(&obj->pending_flip);
34642
34643 flush_domains |= obj->base.write_domain;
34644 }
34645 @@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
34646
34647 static int
34648 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
34649 - int count)
34650 + unsigned int count)
34651 {
34652 - int i;
34653 + unsigned int i;
34654
34655 for (i = 0; i < count; i++) {
34656 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
34657 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
34658 index 3c59584..500f2e9 100644
34659 --- a/drivers/gpu/drm/i915/i915_ioc32.c
34660 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
34661 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
34662 (unsigned long)request);
34663 }
34664
34665 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
34666 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
34667 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
34668 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
34669 [DRM_I915_GETPARAM] = compat_i915_getparam,
34670 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
34671 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34672 {
34673 unsigned int nr = DRM_IOCTL_NR(cmd);
34674 - drm_ioctl_compat_t *fn = NULL;
34675 int ret;
34676
34677 if (nr < DRM_COMMAND_BASE)
34678 return drm_compat_ioctl(filp, cmd, arg);
34679
34680 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
34681 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
34682 -
34683 - if (fn != NULL)
34684 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
34685 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
34686 ret = (*fn) (filp, cmd, arg);
34687 - else
34688 + } else
34689 ret = drm_ioctl(filp, cmd, arg);
34690
34691 return ret;
34692 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
34693 index fe84338..a863190 100644
34694 --- a/drivers/gpu/drm/i915/i915_irq.c
34695 +++ b/drivers/gpu/drm/i915/i915_irq.c
34696 @@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
34697 u32 pipe_stats[I915_MAX_PIPES];
34698 bool blc_event;
34699
34700 - atomic_inc(&dev_priv->irq_received);
34701 + atomic_inc_unchecked(&dev_priv->irq_received);
34702
34703 while (true) {
34704 iir = I915_READ(VLV_IIR);
34705 @@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
34706 irqreturn_t ret = IRQ_NONE;
34707 int i;
34708
34709 - atomic_inc(&dev_priv->irq_received);
34710 + atomic_inc_unchecked(&dev_priv->irq_received);
34711
34712 /* disable master interrupt before clearing iir */
34713 de_ier = I915_READ(DEIER);
34714 @@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
34715 int ret = IRQ_NONE;
34716 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
34717
34718 - atomic_inc(&dev_priv->irq_received);
34719 + atomic_inc_unchecked(&dev_priv->irq_received);
34720
34721 /* disable master interrupt before clearing iir */
34722 de_ier = I915_READ(DEIER);
34723 @@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
34724 {
34725 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34726
34727 - atomic_set(&dev_priv->irq_received, 0);
34728 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34729
34730 I915_WRITE(HWSTAM, 0xeffe);
34731
34732 @@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
34733 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34734 int pipe;
34735
34736 - atomic_set(&dev_priv->irq_received, 0);
34737 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34738
34739 /* VLV magic */
34740 I915_WRITE(VLV_IMR, 0);
34741 @@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
34742 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34743 int pipe;
34744
34745 - atomic_set(&dev_priv->irq_received, 0);
34746 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34747
34748 for_each_pipe(pipe)
34749 I915_WRITE(PIPESTAT(pipe), 0);
34750 @@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
34751 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
34752 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
34753
34754 - atomic_inc(&dev_priv->irq_received);
34755 + atomic_inc_unchecked(&dev_priv->irq_received);
34756
34757 iir = I915_READ16(IIR);
34758 if (iir == 0)
34759 @@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
34760 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34761 int pipe;
34762
34763 - atomic_set(&dev_priv->irq_received, 0);
34764 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34765
34766 if (I915_HAS_HOTPLUG(dev)) {
34767 I915_WRITE(PORT_HOTPLUG_EN, 0);
34768 @@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
34769 };
34770 int pipe, ret = IRQ_NONE;
34771
34772 - atomic_inc(&dev_priv->irq_received);
34773 + atomic_inc_unchecked(&dev_priv->irq_received);
34774
34775 iir = I915_READ(IIR);
34776 do {
34777 @@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
34778 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34779 int pipe;
34780
34781 - atomic_set(&dev_priv->irq_received, 0);
34782 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34783
34784 I915_WRITE(PORT_HOTPLUG_EN, 0);
34785 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
34786 @@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
34787 int irq_received;
34788 int ret = IRQ_NONE, pipe;
34789
34790 - atomic_inc(&dev_priv->irq_received);
34791 + atomic_inc_unchecked(&dev_priv->irq_received);
34792
34793 iir = I915_READ(IIR);
34794
34795 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
34796 index 80aa1fc..85cfce3 100644
34797 --- a/drivers/gpu/drm/i915/intel_display.c
34798 +++ b/drivers/gpu/drm/i915/intel_display.c
34799 @@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
34800
34801 wait_event(dev_priv->pending_flip_queue,
34802 atomic_read(&dev_priv->mm.wedged) ||
34803 - atomic_read(&obj->pending_flip) == 0);
34804 + atomic_read_unchecked(&obj->pending_flip) == 0);
34805
34806 /* Big Hammer, we also need to ensure that any pending
34807 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
34808 @@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
34809
34810 obj = work->old_fb_obj;
34811
34812 - atomic_clear_mask(1 << intel_crtc->plane,
34813 - &obj->pending_flip.counter);
34814 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
34815 wake_up(&dev_priv->pending_flip_queue);
34816
34817 queue_work(dev_priv->wq, &work->work);
34818 @@ -7490,7 +7489,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
34819 /* Block clients from rendering to the new back buffer until
34820 * the flip occurs and the object is no longer visible.
34821 */
34822 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34823 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34824 atomic_inc(&intel_crtc->unpin_work_count);
34825
34826 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
34827 @@ -7507,7 +7506,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
34828
34829 cleanup_pending:
34830 atomic_dec(&intel_crtc->unpin_work_count);
34831 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34832 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34833 drm_gem_object_unreference(&work->old_fb_obj->base);
34834 drm_gem_object_unreference(&obj->base);
34835 mutex_unlock(&dev->struct_mutex);
34836 @@ -8849,13 +8848,13 @@ struct intel_quirk {
34837 int subsystem_vendor;
34838 int subsystem_device;
34839 void (*hook)(struct drm_device *dev);
34840 -};
34841 +} __do_const;
34842
34843 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
34844 struct intel_dmi_quirk {
34845 void (*hook)(struct drm_device *dev);
34846 const struct dmi_system_id (*dmi_id_list)[];
34847 -};
34848 +} __do_const;
34849
34850 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
34851 {
34852 @@ -8863,18 +8862,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
34853 return 1;
34854 }
34855
34856 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
34857 + {
34858 + .callback = intel_dmi_reverse_brightness,
34859 + .ident = "NCR Corporation",
34860 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
34861 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
34862 + },
34863 + },
34864 + { } /* terminating entry */
34865 +};
34866 +
34867 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
34868 {
34869 - .dmi_id_list = &(const struct dmi_system_id[]) {
34870 - {
34871 - .callback = intel_dmi_reverse_brightness,
34872 - .ident = "NCR Corporation",
34873 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
34874 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
34875 - },
34876 - },
34877 - { } /* terminating entry */
34878 - },
34879 + .dmi_id_list = &intel_dmi_quirks_table,
34880 .hook = quirk_invert_brightness,
34881 },
34882 };
34883 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
34884 index 54558a0..2d97005 100644
34885 --- a/drivers/gpu/drm/mga/mga_drv.h
34886 +++ b/drivers/gpu/drm/mga/mga_drv.h
34887 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
34888 u32 clear_cmd;
34889 u32 maccess;
34890
34891 - atomic_t vbl_received; /**< Number of vblanks received. */
34892 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
34893 wait_queue_head_t fence_queue;
34894 - atomic_t last_fence_retired;
34895 + atomic_unchecked_t last_fence_retired;
34896 u32 next_fence_to_post;
34897
34898 unsigned int fb_cpp;
34899 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
34900 index 709e90d..89a1c0d 100644
34901 --- a/drivers/gpu/drm/mga/mga_ioc32.c
34902 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
34903 @@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
34904 return 0;
34905 }
34906
34907 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
34908 +drm_ioctl_compat_t mga_compat_ioctls[] = {
34909 [DRM_MGA_INIT] = compat_mga_init,
34910 [DRM_MGA_GETPARAM] = compat_mga_getparam,
34911 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
34912 @@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
34913 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34914 {
34915 unsigned int nr = DRM_IOCTL_NR(cmd);
34916 - drm_ioctl_compat_t *fn = NULL;
34917 int ret;
34918
34919 if (nr < DRM_COMMAND_BASE)
34920 return drm_compat_ioctl(filp, cmd, arg);
34921
34922 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
34923 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
34924 -
34925 - if (fn != NULL)
34926 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
34927 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
34928 ret = (*fn) (filp, cmd, arg);
34929 - else
34930 + } else
34931 ret = drm_ioctl(filp, cmd, arg);
34932
34933 return ret;
34934 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
34935 index 598c281..60d590e 100644
34936 --- a/drivers/gpu/drm/mga/mga_irq.c
34937 +++ b/drivers/gpu/drm/mga/mga_irq.c
34938 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
34939 if (crtc != 0)
34940 return 0;
34941
34942 - return atomic_read(&dev_priv->vbl_received);
34943 + return atomic_read_unchecked(&dev_priv->vbl_received);
34944 }
34945
34946
34947 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
34948 /* VBLANK interrupt */
34949 if (status & MGA_VLINEPEN) {
34950 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
34951 - atomic_inc(&dev_priv->vbl_received);
34952 + atomic_inc_unchecked(&dev_priv->vbl_received);
34953 drm_handle_vblank(dev, 0);
34954 handled = 1;
34955 }
34956 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
34957 if ((prim_start & ~0x03) != (prim_end & ~0x03))
34958 MGA_WRITE(MGA_PRIMEND, prim_end);
34959
34960 - atomic_inc(&dev_priv->last_fence_retired);
34961 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
34962 DRM_WAKEUP(&dev_priv->fence_queue);
34963 handled = 1;
34964 }
34965 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
34966 * using fences.
34967 */
34968 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
34969 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
34970 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
34971 - *sequence) <= (1 << 23)));
34972
34973 *sequence = cur_fence;
34974 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
34975 index 865eddf..62c4cc3 100644
34976 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
34977 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
34978 @@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
34979 struct bit_table {
34980 const char id;
34981 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
34982 -};
34983 +} __no_const;
34984
34985 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
34986
34987 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
34988 index aa89eb9..d45d38b 100644
34989 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
34990 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
34991 @@ -80,7 +80,7 @@ struct nouveau_drm {
34992 struct drm_global_reference mem_global_ref;
34993 struct ttm_bo_global_ref bo_global_ref;
34994 struct ttm_bo_device bdev;
34995 - atomic_t validate_sequence;
34996 + atomic_unchecked_t validate_sequence;
34997 int (*move)(struct nouveau_channel *,
34998 struct ttm_buffer_object *,
34999 struct ttm_mem_reg *, struct ttm_mem_reg *);
35000 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
35001 index cdb83ac..27f0a16 100644
35002 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
35003 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
35004 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
35005 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
35006 struct nouveau_channel *);
35007 u32 (*read)(struct nouveau_channel *);
35008 -};
35009 +} __no_const;
35010
35011 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
35012
35013 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35014 index 8bf695c..9fbc90a 100644
35015 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35016 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35017 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35018 int trycnt = 0;
35019 int ret, i;
35020
35021 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35022 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35023 retry:
35024 if (++trycnt > 100000) {
35025 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
35026 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35027 index 08214bc..9208577 100644
35028 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35029 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35030 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35031 unsigned long arg)
35032 {
35033 unsigned int nr = DRM_IOCTL_NR(cmd);
35034 - drm_ioctl_compat_t *fn = NULL;
35035 + drm_ioctl_compat_t fn = NULL;
35036 int ret;
35037
35038 if (nr < DRM_COMMAND_BASE)
35039 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35040 index 25d3495..d81aaf6 100644
35041 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35042 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35043 @@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35044 bool can_switch;
35045
35046 spin_lock(&dev->count_lock);
35047 - can_switch = (dev->open_count == 0);
35048 + can_switch = (local_read(&dev->open_count) == 0);
35049 spin_unlock(&dev->count_lock);
35050 return can_switch;
35051 }
35052 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35053 index d4660cf..70dbe65 100644
35054 --- a/drivers/gpu/drm/r128/r128_cce.c
35055 +++ b/drivers/gpu/drm/r128/r128_cce.c
35056 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35057
35058 /* GH: Simple idle check.
35059 */
35060 - atomic_set(&dev_priv->idle_count, 0);
35061 + atomic_set_unchecked(&dev_priv->idle_count, 0);
35062
35063 /* We don't support anything other than bus-mastering ring mode,
35064 * but the ring can be in either AGP or PCI space for the ring
35065 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35066 index 930c71b..499aded 100644
35067 --- a/drivers/gpu/drm/r128/r128_drv.h
35068 +++ b/drivers/gpu/drm/r128/r128_drv.h
35069 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35070 int is_pci;
35071 unsigned long cce_buffers_offset;
35072
35073 - atomic_t idle_count;
35074 + atomic_unchecked_t idle_count;
35075
35076 int page_flipping;
35077 int current_page;
35078 u32 crtc_offset;
35079 u32 crtc_offset_cntl;
35080
35081 - atomic_t vbl_received;
35082 + atomic_unchecked_t vbl_received;
35083
35084 u32 color_fmt;
35085 unsigned int front_offset;
35086 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35087 index a954c54..9cc595c 100644
35088 --- a/drivers/gpu/drm/r128/r128_ioc32.c
35089 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
35090 @@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35091 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
35092 }
35093
35094 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
35095 +drm_ioctl_compat_t r128_compat_ioctls[] = {
35096 [DRM_R128_INIT] = compat_r128_init,
35097 [DRM_R128_DEPTH] = compat_r128_depth,
35098 [DRM_R128_STIPPLE] = compat_r128_stipple,
35099 @@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
35100 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35101 {
35102 unsigned int nr = DRM_IOCTL_NR(cmd);
35103 - drm_ioctl_compat_t *fn = NULL;
35104 int ret;
35105
35106 if (nr < DRM_COMMAND_BASE)
35107 return drm_compat_ioctl(filp, cmd, arg);
35108
35109 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
35110 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35111 -
35112 - if (fn != NULL)
35113 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
35114 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35115 ret = (*fn) (filp, cmd, arg);
35116 - else
35117 + } else
35118 ret = drm_ioctl(filp, cmd, arg);
35119
35120 return ret;
35121 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
35122 index 2ea4f09..d391371 100644
35123 --- a/drivers/gpu/drm/r128/r128_irq.c
35124 +++ b/drivers/gpu/drm/r128/r128_irq.c
35125 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
35126 if (crtc != 0)
35127 return 0;
35128
35129 - return atomic_read(&dev_priv->vbl_received);
35130 + return atomic_read_unchecked(&dev_priv->vbl_received);
35131 }
35132
35133 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35134 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35135 /* VBLANK interrupt */
35136 if (status & R128_CRTC_VBLANK_INT) {
35137 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
35138 - atomic_inc(&dev_priv->vbl_received);
35139 + atomic_inc_unchecked(&dev_priv->vbl_received);
35140 drm_handle_vblank(dev, 0);
35141 return IRQ_HANDLED;
35142 }
35143 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
35144 index 19bb7e6..de7e2a2 100644
35145 --- a/drivers/gpu/drm/r128/r128_state.c
35146 +++ b/drivers/gpu/drm/r128/r128_state.c
35147 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
35148
35149 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
35150 {
35151 - if (atomic_read(&dev_priv->idle_count) == 0)
35152 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
35153 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
35154 else
35155 - atomic_set(&dev_priv->idle_count, 0);
35156 + atomic_set_unchecked(&dev_priv->idle_count, 0);
35157 }
35158
35159 #endif
35160 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
35161 index 5a82b6b..9e69c73 100644
35162 --- a/drivers/gpu/drm/radeon/mkregtable.c
35163 +++ b/drivers/gpu/drm/radeon/mkregtable.c
35164 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
35165 regex_t mask_rex;
35166 regmatch_t match[4];
35167 char buf[1024];
35168 - size_t end;
35169 + long end;
35170 int len;
35171 int done = 0;
35172 int r;
35173 unsigned o;
35174 struct offset *offset;
35175 char last_reg_s[10];
35176 - int last_reg;
35177 + unsigned long last_reg;
35178
35179 if (regcomp
35180 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
35181 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
35182 index 0d6562b..a154330 100644
35183 --- a/drivers/gpu/drm/radeon/radeon_device.c
35184 +++ b/drivers/gpu/drm/radeon/radeon_device.c
35185 @@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
35186 bool can_switch;
35187
35188 spin_lock(&dev->count_lock);
35189 - can_switch = (dev->open_count == 0);
35190 + can_switch = (local_read(&dev->open_count) == 0);
35191 spin_unlock(&dev->count_lock);
35192 return can_switch;
35193 }
35194 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
35195 index e7fdf16..f4f6490 100644
35196 --- a/drivers/gpu/drm/radeon/radeon_drv.h
35197 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
35198 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
35199
35200 /* SW interrupt */
35201 wait_queue_head_t swi_queue;
35202 - atomic_t swi_emitted;
35203 + atomic_unchecked_t swi_emitted;
35204 int vblank_crtc;
35205 uint32_t irq_enable_reg;
35206 uint32_t r500_disp_irq_reg;
35207 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
35208 index c180df8..5fd8186 100644
35209 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
35210 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
35211 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35212 request = compat_alloc_user_space(sizeof(*request));
35213 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
35214 || __put_user(req32.param, &request->param)
35215 - || __put_user((void __user *)(unsigned long)req32.value,
35216 + || __put_user((unsigned long)req32.value,
35217 &request->value))
35218 return -EFAULT;
35219
35220 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35221 #define compat_radeon_cp_setparam NULL
35222 #endif /* X86_64 || IA64 */
35223
35224 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35225 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
35226 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
35227 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
35228 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
35229 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35230 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35231 {
35232 unsigned int nr = DRM_IOCTL_NR(cmd);
35233 - drm_ioctl_compat_t *fn = NULL;
35234 int ret;
35235
35236 if (nr < DRM_COMMAND_BASE)
35237 return drm_compat_ioctl(filp, cmd, arg);
35238
35239 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
35240 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35241 -
35242 - if (fn != NULL)
35243 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
35244 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35245 ret = (*fn) (filp, cmd, arg);
35246 - else
35247 + } else
35248 ret = drm_ioctl(filp, cmd, arg);
35249
35250 return ret;
35251 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
35252 index e771033..a0bc6b3 100644
35253 --- a/drivers/gpu/drm/radeon/radeon_irq.c
35254 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
35255 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
35256 unsigned int ret;
35257 RING_LOCALS;
35258
35259 - atomic_inc(&dev_priv->swi_emitted);
35260 - ret = atomic_read(&dev_priv->swi_emitted);
35261 + atomic_inc_unchecked(&dev_priv->swi_emitted);
35262 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
35263
35264 BEGIN_RING(4);
35265 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
35266 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
35267 drm_radeon_private_t *dev_priv =
35268 (drm_radeon_private_t *) dev->dev_private;
35269
35270 - atomic_set(&dev_priv->swi_emitted, 0);
35271 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
35272 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
35273
35274 dev->max_vblank_count = 0x001fffff;
35275 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
35276 index 8e9057b..af6dacb 100644
35277 --- a/drivers/gpu/drm/radeon/radeon_state.c
35278 +++ b/drivers/gpu/drm/radeon/radeon_state.c
35279 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
35280 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
35281 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
35282
35283 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35284 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35285 sarea_priv->nbox * sizeof(depth_boxes[0])))
35286 return -EFAULT;
35287
35288 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
35289 {
35290 drm_radeon_private_t *dev_priv = dev->dev_private;
35291 drm_radeon_getparam_t *param = data;
35292 - int value;
35293 + int value = 0;
35294
35295 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
35296
35297 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
35298 index 93f760e..8088227 100644
35299 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
35300 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
35301 @@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
35302 man->size = size >> PAGE_SHIFT;
35303 }
35304
35305 -static struct vm_operations_struct radeon_ttm_vm_ops;
35306 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
35307 static const struct vm_operations_struct *ttm_vm_ops = NULL;
35308
35309 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
35310 @@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
35311 }
35312 if (unlikely(ttm_vm_ops == NULL)) {
35313 ttm_vm_ops = vma->vm_ops;
35314 + pax_open_kernel();
35315 radeon_ttm_vm_ops = *ttm_vm_ops;
35316 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
35317 + pax_close_kernel();
35318 }
35319 vma->vm_ops = &radeon_ttm_vm_ops;
35320 return 0;
35321 @@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
35322 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
35323 else
35324 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
35325 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35326 - radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35327 - radeon_mem_types_list[i].driver_features = 0;
35328 + pax_open_kernel();
35329 + *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35330 + *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35331 + *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35332 if (i == 0)
35333 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35334 + *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35335 else
35336 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35337 -
35338 + *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35339 + pax_close_kernel();
35340 }
35341 /* Add ttm page pool to debugfs */
35342 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
35343 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35344 - radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35345 - radeon_mem_types_list[i].driver_features = 0;
35346 - radeon_mem_types_list[i++].data = NULL;
35347 + pax_open_kernel();
35348 + *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35349 + *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35350 + *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35351 + *(void **)&radeon_mem_types_list[i++].data = NULL;
35352 + pax_close_kernel();
35353 #ifdef CONFIG_SWIOTLB
35354 if (swiotlb_nr_tbl()) {
35355 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
35356 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35357 - radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35358 - radeon_mem_types_list[i].driver_features = 0;
35359 - radeon_mem_types_list[i++].data = NULL;
35360 + pax_open_kernel();
35361 + *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35362 + *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35363 + *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35364 + *(void **)&radeon_mem_types_list[i++].data = NULL;
35365 + pax_close_kernel();
35366 }
35367 #endif
35368 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
35369 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
35370 index 5706d2a..17aedaa 100644
35371 --- a/drivers/gpu/drm/radeon/rs690.c
35372 +++ b/drivers/gpu/drm/radeon/rs690.c
35373 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
35374 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
35375 rdev->pm.sideport_bandwidth.full)
35376 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
35377 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
35378 + read_delay_latency.full = dfixed_const(800 * 1000);
35379 read_delay_latency.full = dfixed_div(read_delay_latency,
35380 rdev->pm.igp_sideport_mclk);
35381 + a.full = dfixed_const(370);
35382 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
35383 } else {
35384 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
35385 rdev->pm.k8_bandwidth.full)
35386 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35387 index bd2a3b4..122d9ad 100644
35388 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
35389 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35390 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
35391 static int ttm_pool_mm_shrink(struct shrinker *shrink,
35392 struct shrink_control *sc)
35393 {
35394 - static atomic_t start_pool = ATOMIC_INIT(0);
35395 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
35396 unsigned i;
35397 - unsigned pool_offset = atomic_add_return(1, &start_pool);
35398 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
35399 struct ttm_page_pool *pool;
35400 int shrink_pages = sc->nr_to_scan;
35401
35402 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
35403 index 1eb060c..188b1fc 100644
35404 --- a/drivers/gpu/drm/udl/udl_fb.c
35405 +++ b/drivers/gpu/drm/udl/udl_fb.c
35406 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
35407 fb_deferred_io_cleanup(info);
35408 kfree(info->fbdefio);
35409 info->fbdefio = NULL;
35410 - info->fbops->fb_mmap = udl_fb_mmap;
35411 }
35412
35413 pr_warn("released /dev/fb%d user=%d count=%d\n",
35414 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
35415 index 893a650..6190d3b 100644
35416 --- a/drivers/gpu/drm/via/via_drv.h
35417 +++ b/drivers/gpu/drm/via/via_drv.h
35418 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
35419 typedef uint32_t maskarray_t[5];
35420
35421 typedef struct drm_via_irq {
35422 - atomic_t irq_received;
35423 + atomic_unchecked_t irq_received;
35424 uint32_t pending_mask;
35425 uint32_t enable_mask;
35426 wait_queue_head_t irq_queue;
35427 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
35428 struct timeval last_vblank;
35429 int last_vblank_valid;
35430 unsigned usec_per_vblank;
35431 - atomic_t vbl_received;
35432 + atomic_unchecked_t vbl_received;
35433 drm_via_state_t hc_state;
35434 char pci_buf[VIA_PCI_BUF_SIZE];
35435 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
35436 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
35437 index ac98964..5dbf512 100644
35438 --- a/drivers/gpu/drm/via/via_irq.c
35439 +++ b/drivers/gpu/drm/via/via_irq.c
35440 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
35441 if (crtc != 0)
35442 return 0;
35443
35444 - return atomic_read(&dev_priv->vbl_received);
35445 + return atomic_read_unchecked(&dev_priv->vbl_received);
35446 }
35447
35448 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35449 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35450
35451 status = VIA_READ(VIA_REG_INTERRUPT);
35452 if (status & VIA_IRQ_VBLANK_PENDING) {
35453 - atomic_inc(&dev_priv->vbl_received);
35454 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
35455 + atomic_inc_unchecked(&dev_priv->vbl_received);
35456 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
35457 do_gettimeofday(&cur_vblank);
35458 if (dev_priv->last_vblank_valid) {
35459 dev_priv->usec_per_vblank =
35460 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35461 dev_priv->last_vblank = cur_vblank;
35462 dev_priv->last_vblank_valid = 1;
35463 }
35464 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
35465 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
35466 DRM_DEBUG("US per vblank is: %u\n",
35467 dev_priv->usec_per_vblank);
35468 }
35469 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35470
35471 for (i = 0; i < dev_priv->num_irqs; ++i) {
35472 if (status & cur_irq->pending_mask) {
35473 - atomic_inc(&cur_irq->irq_received);
35474 + atomic_inc_unchecked(&cur_irq->irq_received);
35475 DRM_WAKEUP(&cur_irq->irq_queue);
35476 handled = 1;
35477 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
35478 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
35479 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35480 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
35481 masks[irq][4]));
35482 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
35483 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
35484 } else {
35485 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35486 (((cur_irq_sequence =
35487 - atomic_read(&cur_irq->irq_received)) -
35488 + atomic_read_unchecked(&cur_irq->irq_received)) -
35489 *sequence) <= (1 << 23)));
35490 }
35491 *sequence = cur_irq_sequence;
35492 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
35493 }
35494
35495 for (i = 0; i < dev_priv->num_irqs; ++i) {
35496 - atomic_set(&cur_irq->irq_received, 0);
35497 + atomic_set_unchecked(&cur_irq->irq_received, 0);
35498 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
35499 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
35500 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
35501 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
35502 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
35503 case VIA_IRQ_RELATIVE:
35504 irqwait->request.sequence +=
35505 - atomic_read(&cur_irq->irq_received);
35506 + atomic_read_unchecked(&cur_irq->irq_received);
35507 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
35508 case VIA_IRQ_ABSOLUTE:
35509 break;
35510 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35511 index 13aeda7..4a952d1 100644
35512 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35513 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35514 @@ -290,7 +290,7 @@ struct vmw_private {
35515 * Fencing and IRQs.
35516 */
35517
35518 - atomic_t marker_seq;
35519 + atomic_unchecked_t marker_seq;
35520 wait_queue_head_t fence_queue;
35521 wait_queue_head_t fifo_queue;
35522 int fence_queue_waiters; /* Protected by hw_mutex */
35523 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35524 index 3eb1486..0a47ee9 100644
35525 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35526 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35527 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
35528 (unsigned int) min,
35529 (unsigned int) fifo->capabilities);
35530
35531 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35532 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35533 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
35534 vmw_marker_queue_init(&fifo->marker_queue);
35535 return vmw_fifo_send_fence(dev_priv, &dummy);
35536 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
35537 if (reserveable)
35538 iowrite32(bytes, fifo_mem +
35539 SVGA_FIFO_RESERVED);
35540 - return fifo_mem + (next_cmd >> 2);
35541 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
35542 } else {
35543 need_bounce = true;
35544 }
35545 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
35546
35547 fm = vmw_fifo_reserve(dev_priv, bytes);
35548 if (unlikely(fm == NULL)) {
35549 - *seqno = atomic_read(&dev_priv->marker_seq);
35550 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
35551 ret = -ENOMEM;
35552 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
35553 false, 3*HZ);
35554 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
35555 }
35556
35557 do {
35558 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
35559 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
35560 } while (*seqno == 0);
35561
35562 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
35563 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35564 index 4640adb..e1384ed 100644
35565 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35566 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35567 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
35568 * emitted. Then the fence is stale and signaled.
35569 */
35570
35571 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
35572 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
35573 > VMW_FENCE_WRAP);
35574
35575 return ret;
35576 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
35577
35578 if (fifo_idle)
35579 down_read(&fifo_state->rwsem);
35580 - signal_seq = atomic_read(&dev_priv->marker_seq);
35581 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
35582 ret = 0;
35583
35584 for (;;) {
35585 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35586 index 8a8725c..afed796 100644
35587 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35588 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35589 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
35590 while (!vmw_lag_lt(queue, us)) {
35591 spin_lock(&queue->lock);
35592 if (list_empty(&queue->head))
35593 - seqno = atomic_read(&dev_priv->marker_seq);
35594 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
35595 else {
35596 marker = list_first_entry(&queue->head,
35597 struct vmw_marker, head);
35598 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
35599 index ceb3040..6160c5c 100644
35600 --- a/drivers/hid/hid-core.c
35601 +++ b/drivers/hid/hid-core.c
35602 @@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
35603
35604 int hid_add_device(struct hid_device *hdev)
35605 {
35606 - static atomic_t id = ATOMIC_INIT(0);
35607 + static atomic_unchecked_t id = ATOMIC_INIT(0);
35608 int ret;
35609
35610 if (WARN_ON(hdev->status & HID_STAT_ADDED))
35611 @@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
35612 /* XXX hack, any other cleaner solution after the driver core
35613 * is converted to allow more than 20 bytes as the device name? */
35614 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
35615 - hdev->vendor, hdev->product, atomic_inc_return(&id));
35616 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
35617
35618 hid_debug_register(hdev, dev_name(&hdev->dev));
35619 ret = device_add(&hdev->dev);
35620 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
35621 index eec3291..8ed706b 100644
35622 --- a/drivers/hid/hid-wiimote-debug.c
35623 +++ b/drivers/hid/hid-wiimote-debug.c
35624 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
35625 else if (size == 0)
35626 return -EIO;
35627
35628 - if (copy_to_user(u, buf, size))
35629 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
35630 return -EFAULT;
35631
35632 *off += size;
35633 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
35634 index 773a2f2..7ce08bc 100644
35635 --- a/drivers/hv/channel.c
35636 +++ b/drivers/hv/channel.c
35637 @@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
35638 int ret = 0;
35639 int t;
35640
35641 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
35642 - atomic_inc(&vmbus_connection.next_gpadl_handle);
35643 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
35644 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
35645
35646 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
35647 if (ret)
35648 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
35649 index 3648f8f..30ef30d 100644
35650 --- a/drivers/hv/hv.c
35651 +++ b/drivers/hv/hv.c
35652 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
35653 u64 output_address = (output) ? virt_to_phys(output) : 0;
35654 u32 output_address_hi = output_address >> 32;
35655 u32 output_address_lo = output_address & 0xFFFFFFFF;
35656 - void *hypercall_page = hv_context.hypercall_page;
35657 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
35658
35659 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
35660 "=a"(hv_status_lo) : "d" (control_hi),
35661 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
35662 index d8d1fad..b91caf7 100644
35663 --- a/drivers/hv/hyperv_vmbus.h
35664 +++ b/drivers/hv/hyperv_vmbus.h
35665 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
35666 struct vmbus_connection {
35667 enum vmbus_connect_state conn_state;
35668
35669 - atomic_t next_gpadl_handle;
35670 + atomic_unchecked_t next_gpadl_handle;
35671
35672 /*
35673 * Represents channel interrupts. Each bit position represents a
35674 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
35675 index 8e1a9ec..4687821 100644
35676 --- a/drivers/hv/vmbus_drv.c
35677 +++ b/drivers/hv/vmbus_drv.c
35678 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
35679 {
35680 int ret = 0;
35681
35682 - static atomic_t device_num = ATOMIC_INIT(0);
35683 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
35684
35685 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
35686 - atomic_inc_return(&device_num));
35687 + atomic_inc_return_unchecked(&device_num));
35688
35689 child_device_obj->device.bus = &hv_bus;
35690 child_device_obj->device.parent = &hv_acpi_dev->dev;
35691 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
35692 index 1672e2a..4a6297c 100644
35693 --- a/drivers/hwmon/acpi_power_meter.c
35694 +++ b/drivers/hwmon/acpi_power_meter.c
35695 @@ -117,7 +117,7 @@ struct sensor_template {
35696 struct device_attribute *devattr,
35697 const char *buf, size_t count);
35698 int index;
35699 -};
35700 +} __do_const;
35701
35702 /* Averaging interval */
35703 static int update_avg_interval(struct acpi_power_meter_resource *resource)
35704 @@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
35705 struct sensor_template *attrs)
35706 {
35707 struct device *dev = &resource->acpi_dev->dev;
35708 - struct sensor_device_attribute *sensors =
35709 + sensor_device_attribute_no_const *sensors =
35710 &resource->sensors[resource->num_sensors];
35711 int res = 0;
35712
35713 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
35714 index b41baff..4953e4d 100644
35715 --- a/drivers/hwmon/applesmc.c
35716 +++ b/drivers/hwmon/applesmc.c
35717 @@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
35718 {
35719 struct applesmc_node_group *grp;
35720 struct applesmc_dev_attr *node;
35721 - struct attribute *attr;
35722 + attribute_no_const *attr;
35723 int ret, i;
35724
35725 for (grp = groups; grp->format; grp++) {
35726 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
35727 index 56dbcfb..9874bf1 100644
35728 --- a/drivers/hwmon/asus_atk0110.c
35729 +++ b/drivers/hwmon/asus_atk0110.c
35730 @@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
35731 struct atk_sensor_data {
35732 struct list_head list;
35733 struct atk_data *data;
35734 - struct device_attribute label_attr;
35735 - struct device_attribute input_attr;
35736 - struct device_attribute limit1_attr;
35737 - struct device_attribute limit2_attr;
35738 + device_attribute_no_const label_attr;
35739 + device_attribute_no_const input_attr;
35740 + device_attribute_no_const limit1_attr;
35741 + device_attribute_no_const limit2_attr;
35742 char label_attr_name[ATTR_NAME_SIZE];
35743 char input_attr_name[ATTR_NAME_SIZE];
35744 char limit1_attr_name[ATTR_NAME_SIZE];
35745 @@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
35746 static struct device_attribute atk_name_attr =
35747 __ATTR(name, 0444, atk_name_show, NULL);
35748
35749 -static void atk_init_attribute(struct device_attribute *attr, char *name,
35750 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
35751 sysfs_show_func show)
35752 {
35753 sysfs_attr_init(&attr->attr);
35754 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
35755 index d64923d..72591e8 100644
35756 --- a/drivers/hwmon/coretemp.c
35757 +++ b/drivers/hwmon/coretemp.c
35758 @@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
35759 return NOTIFY_OK;
35760 }
35761
35762 -static struct notifier_block coretemp_cpu_notifier __refdata = {
35763 +static struct notifier_block coretemp_cpu_notifier = {
35764 .notifier_call = coretemp_cpu_callback,
35765 };
35766
35767 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
35768 index a14f634..2916ee2 100644
35769 --- a/drivers/hwmon/ibmaem.c
35770 +++ b/drivers/hwmon/ibmaem.c
35771 @@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
35772 struct aem_rw_sensor_template *rw)
35773 {
35774 struct device *dev = &data->pdev->dev;
35775 - struct sensor_device_attribute *sensors = data->sensors;
35776 + sensor_device_attribute_no_const *sensors = data->sensors;
35777 int err;
35778
35779 /* Set up read-only sensors */
35780 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
35781 index 7d19b1b..8fdaaac 100644
35782 --- a/drivers/hwmon/pmbus/pmbus_core.c
35783 +++ b/drivers/hwmon/pmbus/pmbus_core.c
35784 @@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
35785
35786 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
35787 do { \
35788 - struct sensor_device_attribute *a \
35789 + sensor_device_attribute_no_const *a \
35790 = &data->_type##s[data->num_##_type##s].attribute; \
35791 BUG_ON(data->num_attributes >= data->max_attributes); \
35792 sysfs_attr_init(&a->dev_attr.attr); \
35793 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
35794 index 1c85d39..55ed3cf 100644
35795 --- a/drivers/hwmon/sht15.c
35796 +++ b/drivers/hwmon/sht15.c
35797 @@ -169,7 +169,7 @@ struct sht15_data {
35798 int supply_uV;
35799 bool supply_uV_valid;
35800 struct work_struct update_supply_work;
35801 - atomic_t interrupt_handled;
35802 + atomic_unchecked_t interrupt_handled;
35803 };
35804
35805 /**
35806 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
35807 return ret;
35808
35809 gpio_direction_input(data->pdata->gpio_data);
35810 - atomic_set(&data->interrupt_handled, 0);
35811 + atomic_set_unchecked(&data->interrupt_handled, 0);
35812
35813 enable_irq(gpio_to_irq(data->pdata->gpio_data));
35814 if (gpio_get_value(data->pdata->gpio_data) == 0) {
35815 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
35816 /* Only relevant if the interrupt hasn't occurred. */
35817 - if (!atomic_read(&data->interrupt_handled))
35818 + if (!atomic_read_unchecked(&data->interrupt_handled))
35819 schedule_work(&data->read_work);
35820 }
35821 ret = wait_event_timeout(data->wait_queue,
35822 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
35823
35824 /* First disable the interrupt */
35825 disable_irq_nosync(irq);
35826 - atomic_inc(&data->interrupt_handled);
35827 + atomic_inc_unchecked(&data->interrupt_handled);
35828 /* Then schedule a reading work struct */
35829 if (data->state != SHT15_READING_NOTHING)
35830 schedule_work(&data->read_work);
35831 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
35832 * If not, then start the interrupt again - care here as could
35833 * have gone low in meantime so verify it hasn't!
35834 */
35835 - atomic_set(&data->interrupt_handled, 0);
35836 + atomic_set_unchecked(&data->interrupt_handled, 0);
35837 enable_irq(gpio_to_irq(data->pdata->gpio_data));
35838 /* If still not occurred or another handler was scheduled */
35839 if (gpio_get_value(data->pdata->gpio_data)
35840 - || atomic_read(&data->interrupt_handled))
35841 + || atomic_read_unchecked(&data->interrupt_handled))
35842 return;
35843 }
35844
35845 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
35846 index 76f157b..9c0db1b 100644
35847 --- a/drivers/hwmon/via-cputemp.c
35848 +++ b/drivers/hwmon/via-cputemp.c
35849 @@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
35850 return NOTIFY_OK;
35851 }
35852
35853 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
35854 +static struct notifier_block via_cputemp_cpu_notifier = {
35855 .notifier_call = via_cputemp_cpu_callback,
35856 };
35857
35858 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
35859 index 378fcb5..5e91fa8 100644
35860 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
35861 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
35862 @@ -43,7 +43,7 @@
35863 extern struct i2c_adapter amd756_smbus;
35864
35865 static struct i2c_adapter *s4882_adapter;
35866 -static struct i2c_algorithm *s4882_algo;
35867 +static i2c_algorithm_no_const *s4882_algo;
35868
35869 /* Wrapper access functions for multiplexed SMBus */
35870 static DEFINE_MUTEX(amd756_lock);
35871 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
35872 index 29015eb..af2d8e9 100644
35873 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
35874 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
35875 @@ -41,7 +41,7 @@
35876 extern struct i2c_adapter *nforce2_smbus;
35877
35878 static struct i2c_adapter *s4985_adapter;
35879 -static struct i2c_algorithm *s4985_algo;
35880 +static i2c_algorithm_no_const *s4985_algo;
35881
35882 /* Wrapper access functions for multiplexed SMBus */
35883 static DEFINE_MUTEX(nforce2_lock);
35884 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
35885 index 8126824..55a2798 100644
35886 --- a/drivers/ide/ide-cd.c
35887 +++ b/drivers/ide/ide-cd.c
35888 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
35889 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
35890 if ((unsigned long)buf & alignment
35891 || blk_rq_bytes(rq) & q->dma_pad_mask
35892 - || object_is_on_stack(buf))
35893 + || object_starts_on_stack(buf))
35894 drive->dma = 0;
35895 }
35896 }
35897 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
35898 index 8848f16..f8e6dd8 100644
35899 --- a/drivers/iio/industrialio-core.c
35900 +++ b/drivers/iio/industrialio-core.c
35901 @@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
35902 }
35903
35904 static
35905 -int __iio_device_attr_init(struct device_attribute *dev_attr,
35906 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
35907 const char *postfix,
35908 struct iio_chan_spec const *chan,
35909 ssize_t (*readfunc)(struct device *dev,
35910 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
35911 index 394fea2..c833880 100644
35912 --- a/drivers/infiniband/core/cm.c
35913 +++ b/drivers/infiniband/core/cm.c
35914 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
35915
35916 struct cm_counter_group {
35917 struct kobject obj;
35918 - atomic_long_t counter[CM_ATTR_COUNT];
35919 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
35920 };
35921
35922 struct cm_counter_attribute {
35923 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
35924 struct ib_mad_send_buf *msg = NULL;
35925 int ret;
35926
35927 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
35928 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
35929 counter[CM_REQ_COUNTER]);
35930
35931 /* Quick state check to discard duplicate REQs. */
35932 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
35933 if (!cm_id_priv)
35934 return;
35935
35936 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
35937 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
35938 counter[CM_REP_COUNTER]);
35939 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
35940 if (ret)
35941 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
35942 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
35943 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
35944 spin_unlock_irq(&cm_id_priv->lock);
35945 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
35946 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
35947 counter[CM_RTU_COUNTER]);
35948 goto out;
35949 }
35950 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
35951 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
35952 dreq_msg->local_comm_id);
35953 if (!cm_id_priv) {
35954 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
35955 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
35956 counter[CM_DREQ_COUNTER]);
35957 cm_issue_drep(work->port, work->mad_recv_wc);
35958 return -EINVAL;
35959 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
35960 case IB_CM_MRA_REP_RCVD:
35961 break;
35962 case IB_CM_TIMEWAIT:
35963 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
35964 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
35965 counter[CM_DREQ_COUNTER]);
35966 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
35967 goto unlock;
35968 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
35969 cm_free_msg(msg);
35970 goto deref;
35971 case IB_CM_DREQ_RCVD:
35972 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
35973 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
35974 counter[CM_DREQ_COUNTER]);
35975 goto unlock;
35976 default:
35977 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
35978 ib_modify_mad(cm_id_priv->av.port->mad_agent,
35979 cm_id_priv->msg, timeout)) {
35980 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
35981 - atomic_long_inc(&work->port->
35982 + atomic_long_inc_unchecked(&work->port->
35983 counter_group[CM_RECV_DUPLICATES].
35984 counter[CM_MRA_COUNTER]);
35985 goto out;
35986 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
35987 break;
35988 case IB_CM_MRA_REQ_RCVD:
35989 case IB_CM_MRA_REP_RCVD:
35990 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
35991 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
35992 counter[CM_MRA_COUNTER]);
35993 /* fall through */
35994 default:
35995 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
35996 case IB_CM_LAP_IDLE:
35997 break;
35998 case IB_CM_MRA_LAP_SENT:
35999 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36000 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36001 counter[CM_LAP_COUNTER]);
36002 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36003 goto unlock;
36004 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
36005 cm_free_msg(msg);
36006 goto deref;
36007 case IB_CM_LAP_RCVD:
36008 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36009 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36010 counter[CM_LAP_COUNTER]);
36011 goto unlock;
36012 default:
36013 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36014 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36015 if (cur_cm_id_priv) {
36016 spin_unlock_irq(&cm.lock);
36017 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36018 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36019 counter[CM_SIDR_REQ_COUNTER]);
36020 goto out; /* Duplicate message. */
36021 }
36022 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36023 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36024 msg->retries = 1;
36025
36026 - atomic_long_add(1 + msg->retries,
36027 + atomic_long_add_unchecked(1 + msg->retries,
36028 &port->counter_group[CM_XMIT].counter[attr_index]);
36029 if (msg->retries)
36030 - atomic_long_add(msg->retries,
36031 + atomic_long_add_unchecked(msg->retries,
36032 &port->counter_group[CM_XMIT_RETRIES].
36033 counter[attr_index]);
36034
36035 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36036 }
36037
36038 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36039 - atomic_long_inc(&port->counter_group[CM_RECV].
36040 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36041 counter[attr_id - CM_ATTR_ID_OFFSET]);
36042
36043 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36044 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36045 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36046
36047 return sprintf(buf, "%ld\n",
36048 - atomic_long_read(&group->counter[cm_attr->index]));
36049 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36050 }
36051
36052 static const struct sysfs_ops cm_counter_ops = {
36053 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36054 index 176c8f9..2627b62 100644
36055 --- a/drivers/infiniband/core/fmr_pool.c
36056 +++ b/drivers/infiniband/core/fmr_pool.c
36057 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
36058
36059 struct task_struct *thread;
36060
36061 - atomic_t req_ser;
36062 - atomic_t flush_ser;
36063 + atomic_unchecked_t req_ser;
36064 + atomic_unchecked_t flush_ser;
36065
36066 wait_queue_head_t force_wait;
36067 };
36068 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36069 struct ib_fmr_pool *pool = pool_ptr;
36070
36071 do {
36072 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
36073 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
36074 ib_fmr_batch_release(pool);
36075
36076 - atomic_inc(&pool->flush_ser);
36077 + atomic_inc_unchecked(&pool->flush_ser);
36078 wake_up_interruptible(&pool->force_wait);
36079
36080 if (pool->flush_function)
36081 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36082 }
36083
36084 set_current_state(TASK_INTERRUPTIBLE);
36085 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
36086 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
36087 !kthread_should_stop())
36088 schedule();
36089 __set_current_state(TASK_RUNNING);
36090 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
36091 pool->dirty_watermark = params->dirty_watermark;
36092 pool->dirty_len = 0;
36093 spin_lock_init(&pool->pool_lock);
36094 - atomic_set(&pool->req_ser, 0);
36095 - atomic_set(&pool->flush_ser, 0);
36096 + atomic_set_unchecked(&pool->req_ser, 0);
36097 + atomic_set_unchecked(&pool->flush_ser, 0);
36098 init_waitqueue_head(&pool->force_wait);
36099
36100 pool->thread = kthread_run(ib_fmr_cleanup_thread,
36101 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
36102 }
36103 spin_unlock_irq(&pool->pool_lock);
36104
36105 - serial = atomic_inc_return(&pool->req_ser);
36106 + serial = atomic_inc_return_unchecked(&pool->req_ser);
36107 wake_up_process(pool->thread);
36108
36109 if (wait_event_interruptible(pool->force_wait,
36110 - atomic_read(&pool->flush_ser) - serial >= 0))
36111 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
36112 return -EINTR;
36113
36114 return 0;
36115 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
36116 } else {
36117 list_add_tail(&fmr->list, &pool->dirty_list);
36118 if (++pool->dirty_len >= pool->dirty_watermark) {
36119 - atomic_inc(&pool->req_ser);
36120 + atomic_inc_unchecked(&pool->req_ser);
36121 wake_up_process(pool->thread);
36122 }
36123 }
36124 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
36125 index afd8179..598063f 100644
36126 --- a/drivers/infiniband/hw/cxgb4/mem.c
36127 +++ b/drivers/infiniband/hw/cxgb4/mem.c
36128 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36129 int err;
36130 struct fw_ri_tpte tpt;
36131 u32 stag_idx;
36132 - static atomic_t key;
36133 + static atomic_unchecked_t key;
36134
36135 if (c4iw_fatal_error(rdev))
36136 return -EIO;
36137 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36138 if (rdev->stats.stag.cur > rdev->stats.stag.max)
36139 rdev->stats.stag.max = rdev->stats.stag.cur;
36140 mutex_unlock(&rdev->stats.lock);
36141 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
36142 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
36143 }
36144 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
36145 __func__, stag_state, type, pdid, stag_idx);
36146 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
36147 index 79b3dbc..96e5fcc 100644
36148 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
36149 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
36150 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36151 struct ib_atomic_eth *ateth;
36152 struct ipath_ack_entry *e;
36153 u64 vaddr;
36154 - atomic64_t *maddr;
36155 + atomic64_unchecked_t *maddr;
36156 u64 sdata;
36157 u32 rkey;
36158 u8 next;
36159 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36160 IB_ACCESS_REMOTE_ATOMIC)))
36161 goto nack_acc_unlck;
36162 /* Perform atomic OP and save result. */
36163 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36164 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36165 sdata = be64_to_cpu(ateth->swap_data);
36166 e = &qp->s_ack_queue[qp->r_head_ack_queue];
36167 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
36168 - (u64) atomic64_add_return(sdata, maddr) - sdata :
36169 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36170 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36171 be64_to_cpu(ateth->compare_data),
36172 sdata);
36173 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
36174 index 1f95bba..9530f87 100644
36175 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
36176 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
36177 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
36178 unsigned long flags;
36179 struct ib_wc wc;
36180 u64 sdata;
36181 - atomic64_t *maddr;
36182 + atomic64_unchecked_t *maddr;
36183 enum ib_wc_status send_status;
36184
36185 /*
36186 @@ -382,11 +382,11 @@ again:
36187 IB_ACCESS_REMOTE_ATOMIC)))
36188 goto acc_err;
36189 /* Perform atomic OP and save result. */
36190 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36191 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36192 sdata = wqe->wr.wr.atomic.compare_add;
36193 *(u64 *) sqp->s_sge.sge.vaddr =
36194 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
36195 - (u64) atomic64_add_return(sdata, maddr) - sdata :
36196 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36197 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36198 sdata, wqe->wr.wr.atomic.swap);
36199 goto send_comp;
36200 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
36201 index 5b152a3..c1f3e83 100644
36202 --- a/drivers/infiniband/hw/nes/nes.c
36203 +++ b/drivers/infiniband/hw/nes/nes.c
36204 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
36205 LIST_HEAD(nes_adapter_list);
36206 static LIST_HEAD(nes_dev_list);
36207
36208 -atomic_t qps_destroyed;
36209 +atomic_unchecked_t qps_destroyed;
36210
36211 static unsigned int ee_flsh_adapter;
36212 static unsigned int sysfs_nonidx_addr;
36213 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
36214 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
36215 struct nes_adapter *nesadapter = nesdev->nesadapter;
36216
36217 - atomic_inc(&qps_destroyed);
36218 + atomic_inc_unchecked(&qps_destroyed);
36219
36220 /* Free the control structures */
36221
36222 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
36223 index 33cc589..3bd6538 100644
36224 --- a/drivers/infiniband/hw/nes/nes.h
36225 +++ b/drivers/infiniband/hw/nes/nes.h
36226 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
36227 extern unsigned int wqm_quanta;
36228 extern struct list_head nes_adapter_list;
36229
36230 -extern atomic_t cm_connects;
36231 -extern atomic_t cm_accepts;
36232 -extern atomic_t cm_disconnects;
36233 -extern atomic_t cm_closes;
36234 -extern atomic_t cm_connecteds;
36235 -extern atomic_t cm_connect_reqs;
36236 -extern atomic_t cm_rejects;
36237 -extern atomic_t mod_qp_timouts;
36238 -extern atomic_t qps_created;
36239 -extern atomic_t qps_destroyed;
36240 -extern atomic_t sw_qps_destroyed;
36241 +extern atomic_unchecked_t cm_connects;
36242 +extern atomic_unchecked_t cm_accepts;
36243 +extern atomic_unchecked_t cm_disconnects;
36244 +extern atomic_unchecked_t cm_closes;
36245 +extern atomic_unchecked_t cm_connecteds;
36246 +extern atomic_unchecked_t cm_connect_reqs;
36247 +extern atomic_unchecked_t cm_rejects;
36248 +extern atomic_unchecked_t mod_qp_timouts;
36249 +extern atomic_unchecked_t qps_created;
36250 +extern atomic_unchecked_t qps_destroyed;
36251 +extern atomic_unchecked_t sw_qps_destroyed;
36252 extern u32 mh_detected;
36253 extern u32 mh_pauses_sent;
36254 extern u32 cm_packets_sent;
36255 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
36256 extern u32 cm_packets_received;
36257 extern u32 cm_packets_dropped;
36258 extern u32 cm_packets_retrans;
36259 -extern atomic_t cm_listens_created;
36260 -extern atomic_t cm_listens_destroyed;
36261 +extern atomic_unchecked_t cm_listens_created;
36262 +extern atomic_unchecked_t cm_listens_destroyed;
36263 extern u32 cm_backlog_drops;
36264 -extern atomic_t cm_loopbacks;
36265 -extern atomic_t cm_nodes_created;
36266 -extern atomic_t cm_nodes_destroyed;
36267 -extern atomic_t cm_accel_dropped_pkts;
36268 -extern atomic_t cm_resets_recvd;
36269 -extern atomic_t pau_qps_created;
36270 -extern atomic_t pau_qps_destroyed;
36271 +extern atomic_unchecked_t cm_loopbacks;
36272 +extern atomic_unchecked_t cm_nodes_created;
36273 +extern atomic_unchecked_t cm_nodes_destroyed;
36274 +extern atomic_unchecked_t cm_accel_dropped_pkts;
36275 +extern atomic_unchecked_t cm_resets_recvd;
36276 +extern atomic_unchecked_t pau_qps_created;
36277 +extern atomic_unchecked_t pau_qps_destroyed;
36278
36279 extern u32 int_mod_timer_init;
36280 extern u32 int_mod_cq_depth_256;
36281 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
36282 index 22ea67e..dcbe3bc 100644
36283 --- a/drivers/infiniband/hw/nes/nes_cm.c
36284 +++ b/drivers/infiniband/hw/nes/nes_cm.c
36285 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
36286 u32 cm_packets_retrans;
36287 u32 cm_packets_created;
36288 u32 cm_packets_received;
36289 -atomic_t cm_listens_created;
36290 -atomic_t cm_listens_destroyed;
36291 +atomic_unchecked_t cm_listens_created;
36292 +atomic_unchecked_t cm_listens_destroyed;
36293 u32 cm_backlog_drops;
36294 -atomic_t cm_loopbacks;
36295 -atomic_t cm_nodes_created;
36296 -atomic_t cm_nodes_destroyed;
36297 -atomic_t cm_accel_dropped_pkts;
36298 -atomic_t cm_resets_recvd;
36299 +atomic_unchecked_t cm_loopbacks;
36300 +atomic_unchecked_t cm_nodes_created;
36301 +atomic_unchecked_t cm_nodes_destroyed;
36302 +atomic_unchecked_t cm_accel_dropped_pkts;
36303 +atomic_unchecked_t cm_resets_recvd;
36304
36305 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
36306 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
36307 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
36308
36309 static struct nes_cm_core *g_cm_core;
36310
36311 -atomic_t cm_connects;
36312 -atomic_t cm_accepts;
36313 -atomic_t cm_disconnects;
36314 -atomic_t cm_closes;
36315 -atomic_t cm_connecteds;
36316 -atomic_t cm_connect_reqs;
36317 -atomic_t cm_rejects;
36318 +atomic_unchecked_t cm_connects;
36319 +atomic_unchecked_t cm_accepts;
36320 +atomic_unchecked_t cm_disconnects;
36321 +atomic_unchecked_t cm_closes;
36322 +atomic_unchecked_t cm_connecteds;
36323 +atomic_unchecked_t cm_connect_reqs;
36324 +atomic_unchecked_t cm_rejects;
36325
36326 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
36327 {
36328 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
36329 kfree(listener);
36330 listener = NULL;
36331 ret = 0;
36332 - atomic_inc(&cm_listens_destroyed);
36333 + atomic_inc_unchecked(&cm_listens_destroyed);
36334 } else {
36335 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
36336 }
36337 @@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
36338 cm_node->rem_mac);
36339
36340 add_hte_node(cm_core, cm_node);
36341 - atomic_inc(&cm_nodes_created);
36342 + atomic_inc_unchecked(&cm_nodes_created);
36343
36344 return cm_node;
36345 }
36346 @@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
36347 }
36348
36349 atomic_dec(&cm_core->node_cnt);
36350 - atomic_inc(&cm_nodes_destroyed);
36351 + atomic_inc_unchecked(&cm_nodes_destroyed);
36352 nesqp = cm_node->nesqp;
36353 if (nesqp) {
36354 nesqp->cm_node = NULL;
36355 @@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
36356
36357 static void drop_packet(struct sk_buff *skb)
36358 {
36359 - atomic_inc(&cm_accel_dropped_pkts);
36360 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
36361 dev_kfree_skb_any(skb);
36362 }
36363
36364 @@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
36365 {
36366
36367 int reset = 0; /* whether to send reset in case of err.. */
36368 - atomic_inc(&cm_resets_recvd);
36369 + atomic_inc_unchecked(&cm_resets_recvd);
36370 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
36371 " refcnt=%d\n", cm_node, cm_node->state,
36372 atomic_read(&cm_node->ref_count));
36373 @@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
36374 rem_ref_cm_node(cm_node->cm_core, cm_node);
36375 return NULL;
36376 }
36377 - atomic_inc(&cm_loopbacks);
36378 + atomic_inc_unchecked(&cm_loopbacks);
36379 loopbackremotenode->loopbackpartner = cm_node;
36380 loopbackremotenode->tcp_cntxt.rcv_wscale =
36381 NES_CM_DEFAULT_RCV_WND_SCALE;
36382 @@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
36383 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
36384 else {
36385 rem_ref_cm_node(cm_core, cm_node);
36386 - atomic_inc(&cm_accel_dropped_pkts);
36387 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
36388 dev_kfree_skb_any(skb);
36389 }
36390 break;
36391 @@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36392
36393 if ((cm_id) && (cm_id->event_handler)) {
36394 if (issue_disconn) {
36395 - atomic_inc(&cm_disconnects);
36396 + atomic_inc_unchecked(&cm_disconnects);
36397 cm_event.event = IW_CM_EVENT_DISCONNECT;
36398 cm_event.status = disconn_status;
36399 cm_event.local_addr = cm_id->local_addr;
36400 @@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36401 }
36402
36403 if (issue_close) {
36404 - atomic_inc(&cm_closes);
36405 + atomic_inc_unchecked(&cm_closes);
36406 nes_disconnect(nesqp, 1);
36407
36408 cm_id->provider_data = nesqp;
36409 @@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36410
36411 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
36412 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
36413 - atomic_inc(&cm_accepts);
36414 + atomic_inc_unchecked(&cm_accepts);
36415
36416 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
36417 netdev_refcnt_read(nesvnic->netdev));
36418 @@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
36419 struct nes_cm_core *cm_core;
36420 u8 *start_buff;
36421
36422 - atomic_inc(&cm_rejects);
36423 + atomic_inc_unchecked(&cm_rejects);
36424 cm_node = (struct nes_cm_node *)cm_id->provider_data;
36425 loopback = cm_node->loopbackpartner;
36426 cm_core = cm_node->cm_core;
36427 @@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36428 ntohl(cm_id->local_addr.sin_addr.s_addr),
36429 ntohs(cm_id->local_addr.sin_port));
36430
36431 - atomic_inc(&cm_connects);
36432 + atomic_inc_unchecked(&cm_connects);
36433 nesqp->active_conn = 1;
36434
36435 /* cache the cm_id in the qp */
36436 @@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
36437 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
36438 return err;
36439 }
36440 - atomic_inc(&cm_listens_created);
36441 + atomic_inc_unchecked(&cm_listens_created);
36442 }
36443
36444 cm_id->add_ref(cm_id);
36445 @@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
36446
36447 if (nesqp->destroyed)
36448 return;
36449 - atomic_inc(&cm_connecteds);
36450 + atomic_inc_unchecked(&cm_connecteds);
36451 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
36452 " local port 0x%04X. jiffies = %lu.\n",
36453 nesqp->hwqp.qp_id,
36454 @@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
36455
36456 cm_id->add_ref(cm_id);
36457 ret = cm_id->event_handler(cm_id, &cm_event);
36458 - atomic_inc(&cm_closes);
36459 + atomic_inc_unchecked(&cm_closes);
36460 cm_event.event = IW_CM_EVENT_CLOSE;
36461 cm_event.status = 0;
36462 cm_event.provider_data = cm_id->provider_data;
36463 @@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
36464 return;
36465 cm_id = cm_node->cm_id;
36466
36467 - atomic_inc(&cm_connect_reqs);
36468 + atomic_inc_unchecked(&cm_connect_reqs);
36469 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36470 cm_node, cm_id, jiffies);
36471
36472 @@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
36473 return;
36474 cm_id = cm_node->cm_id;
36475
36476 - atomic_inc(&cm_connect_reqs);
36477 + atomic_inc_unchecked(&cm_connect_reqs);
36478 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36479 cm_node, cm_id, jiffies);
36480
36481 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
36482 index 4166452..fc952c3 100644
36483 --- a/drivers/infiniband/hw/nes/nes_mgt.c
36484 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
36485 @@ -40,8 +40,8 @@
36486 #include "nes.h"
36487 #include "nes_mgt.h"
36488
36489 -atomic_t pau_qps_created;
36490 -atomic_t pau_qps_destroyed;
36491 +atomic_unchecked_t pau_qps_created;
36492 +atomic_unchecked_t pau_qps_destroyed;
36493
36494 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
36495 {
36496 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
36497 {
36498 struct sk_buff *skb;
36499 unsigned long flags;
36500 - atomic_inc(&pau_qps_destroyed);
36501 + atomic_inc_unchecked(&pau_qps_destroyed);
36502
36503 /* Free packets that have not yet been forwarded */
36504 /* Lock is acquired by skb_dequeue when removing the skb */
36505 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
36506 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
36507 skb_queue_head_init(&nesqp->pau_list);
36508 spin_lock_init(&nesqp->pau_lock);
36509 - atomic_inc(&pau_qps_created);
36510 + atomic_inc_unchecked(&pau_qps_created);
36511 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
36512 }
36513
36514 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
36515 index 9542e16..a008c40 100644
36516 --- a/drivers/infiniband/hw/nes/nes_nic.c
36517 +++ b/drivers/infiniband/hw/nes/nes_nic.c
36518 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
36519 target_stat_values[++index] = mh_detected;
36520 target_stat_values[++index] = mh_pauses_sent;
36521 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
36522 - target_stat_values[++index] = atomic_read(&cm_connects);
36523 - target_stat_values[++index] = atomic_read(&cm_accepts);
36524 - target_stat_values[++index] = atomic_read(&cm_disconnects);
36525 - target_stat_values[++index] = atomic_read(&cm_connecteds);
36526 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
36527 - target_stat_values[++index] = atomic_read(&cm_rejects);
36528 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
36529 - target_stat_values[++index] = atomic_read(&qps_created);
36530 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
36531 - target_stat_values[++index] = atomic_read(&qps_destroyed);
36532 - target_stat_values[++index] = atomic_read(&cm_closes);
36533 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
36534 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
36535 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
36536 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
36537 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
36538 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
36539 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
36540 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
36541 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
36542 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
36543 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
36544 target_stat_values[++index] = cm_packets_sent;
36545 target_stat_values[++index] = cm_packets_bounced;
36546 target_stat_values[++index] = cm_packets_created;
36547 target_stat_values[++index] = cm_packets_received;
36548 target_stat_values[++index] = cm_packets_dropped;
36549 target_stat_values[++index] = cm_packets_retrans;
36550 - target_stat_values[++index] = atomic_read(&cm_listens_created);
36551 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
36552 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
36553 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
36554 target_stat_values[++index] = cm_backlog_drops;
36555 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
36556 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
36557 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
36558 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
36559 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
36560 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
36561 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
36562 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
36563 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
36564 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
36565 target_stat_values[++index] = nesadapter->free_4kpbl;
36566 target_stat_values[++index] = nesadapter->free_256pbl;
36567 target_stat_values[++index] = int_mod_timer_init;
36568 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
36569 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
36570 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
36571 - target_stat_values[++index] = atomic_read(&pau_qps_created);
36572 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
36573 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
36574 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
36575 }
36576
36577 /**
36578 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
36579 index 07e4fba..685f041 100644
36580 --- a/drivers/infiniband/hw/nes/nes_verbs.c
36581 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
36582 @@ -46,9 +46,9 @@
36583
36584 #include <rdma/ib_umem.h>
36585
36586 -atomic_t mod_qp_timouts;
36587 -atomic_t qps_created;
36588 -atomic_t sw_qps_destroyed;
36589 +atomic_unchecked_t mod_qp_timouts;
36590 +atomic_unchecked_t qps_created;
36591 +atomic_unchecked_t sw_qps_destroyed;
36592
36593 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
36594
36595 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
36596 if (init_attr->create_flags)
36597 return ERR_PTR(-EINVAL);
36598
36599 - atomic_inc(&qps_created);
36600 + atomic_inc_unchecked(&qps_created);
36601 switch (init_attr->qp_type) {
36602 case IB_QPT_RC:
36603 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
36604 @@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
36605 struct iw_cm_event cm_event;
36606 int ret = 0;
36607
36608 - atomic_inc(&sw_qps_destroyed);
36609 + atomic_inc_unchecked(&sw_qps_destroyed);
36610 nesqp->destroyed = 1;
36611
36612 /* Blow away the connection if it exists. */
36613 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
36614 index 4d11575..3e890e5 100644
36615 --- a/drivers/infiniband/hw/qib/qib.h
36616 +++ b/drivers/infiniband/hw/qib/qib.h
36617 @@ -51,6 +51,7 @@
36618 #include <linux/completion.h>
36619 #include <linux/kref.h>
36620 #include <linux/sched.h>
36621 +#include <linux/slab.h>
36622
36623 #include "qib_common.h"
36624 #include "qib_verbs.h"
36625 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
36626 index da739d9..da1c7f4 100644
36627 --- a/drivers/input/gameport/gameport.c
36628 +++ b/drivers/input/gameport/gameport.c
36629 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
36630 */
36631 static void gameport_init_port(struct gameport *gameport)
36632 {
36633 - static atomic_t gameport_no = ATOMIC_INIT(0);
36634 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
36635
36636 __module_get(THIS_MODULE);
36637
36638 mutex_init(&gameport->drv_mutex);
36639 device_initialize(&gameport->dev);
36640 dev_set_name(&gameport->dev, "gameport%lu",
36641 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
36642 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
36643 gameport->dev.bus = &gameport_bus;
36644 gameport->dev.release = gameport_release_port;
36645 if (gameport->parent)
36646 diff --git a/drivers/input/input.c b/drivers/input/input.c
36647 index c044699..174d71a 100644
36648 --- a/drivers/input/input.c
36649 +++ b/drivers/input/input.c
36650 @@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
36651 */
36652 int input_register_device(struct input_dev *dev)
36653 {
36654 - static atomic_t input_no = ATOMIC_INIT(0);
36655 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
36656 struct input_devres *devres = NULL;
36657 struct input_handler *handler;
36658 unsigned int packet_size;
36659 @@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
36660 dev->setkeycode = input_default_setkeycode;
36661
36662 dev_set_name(&dev->dev, "input%ld",
36663 - (unsigned long) atomic_inc_return(&input_no) - 1);
36664 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
36665
36666 error = device_add(&dev->dev);
36667 if (error)
36668 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
36669 index 04c69af..5f92d00 100644
36670 --- a/drivers/input/joystick/sidewinder.c
36671 +++ b/drivers/input/joystick/sidewinder.c
36672 @@ -30,6 +30,7 @@
36673 #include <linux/kernel.h>
36674 #include <linux/module.h>
36675 #include <linux/slab.h>
36676 +#include <linux/sched.h>
36677 #include <linux/init.h>
36678 #include <linux/input.h>
36679 #include <linux/gameport.h>
36680 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
36681 index d6cbfe9..6225402 100644
36682 --- a/drivers/input/joystick/xpad.c
36683 +++ b/drivers/input/joystick/xpad.c
36684 @@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
36685
36686 static int xpad_led_probe(struct usb_xpad *xpad)
36687 {
36688 - static atomic_t led_seq = ATOMIC_INIT(0);
36689 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
36690 long led_no;
36691 struct xpad_led *led;
36692 struct led_classdev *led_cdev;
36693 @@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
36694 if (!led)
36695 return -ENOMEM;
36696
36697 - led_no = (long)atomic_inc_return(&led_seq) - 1;
36698 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
36699
36700 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
36701 led->xpad = xpad;
36702 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
36703 index fe1df23..5b710f3 100644
36704 --- a/drivers/input/mouse/psmouse.h
36705 +++ b/drivers/input/mouse/psmouse.h
36706 @@ -115,7 +115,7 @@ struct psmouse_attribute {
36707 ssize_t (*set)(struct psmouse *psmouse, void *data,
36708 const char *buf, size_t count);
36709 bool protect;
36710 -};
36711 +} __do_const;
36712 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
36713
36714 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
36715 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
36716 index 4c842c3..590b0bf 100644
36717 --- a/drivers/input/mousedev.c
36718 +++ b/drivers/input/mousedev.c
36719 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
36720
36721 spin_unlock_irq(&client->packet_lock);
36722
36723 - if (copy_to_user(buffer, data, count))
36724 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
36725 return -EFAULT;
36726
36727 return count;
36728 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
36729 index 25fc597..558bf3b 100644
36730 --- a/drivers/input/serio/serio.c
36731 +++ b/drivers/input/serio/serio.c
36732 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
36733 */
36734 static void serio_init_port(struct serio *serio)
36735 {
36736 - static atomic_t serio_no = ATOMIC_INIT(0);
36737 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
36738
36739 __module_get(THIS_MODULE);
36740
36741 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
36742 mutex_init(&serio->drv_mutex);
36743 device_initialize(&serio->dev);
36744 dev_set_name(&serio->dev, "serio%ld",
36745 - (long)atomic_inc_return(&serio_no) - 1);
36746 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
36747 serio->dev.bus = &serio_bus;
36748 serio->dev.release = serio_release_port;
36749 serio->dev.groups = serio_device_attr_groups;
36750 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
36751 index ddbdaca..be18a78 100644
36752 --- a/drivers/iommu/iommu.c
36753 +++ b/drivers/iommu/iommu.c
36754 @@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
36755 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
36756 {
36757 bus_register_notifier(bus, &iommu_bus_nb);
36758 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
36759 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
36760 }
36761
36762 /**
36763 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
36764 index 89562a8..218999b 100644
36765 --- a/drivers/isdn/capi/capi.c
36766 +++ b/drivers/isdn/capi/capi.c
36767 @@ -81,8 +81,8 @@ struct capiminor {
36768
36769 struct capi20_appl *ap;
36770 u32 ncci;
36771 - atomic_t datahandle;
36772 - atomic_t msgid;
36773 + atomic_unchecked_t datahandle;
36774 + atomic_unchecked_t msgid;
36775
36776 struct tty_port port;
36777 int ttyinstop;
36778 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
36779 capimsg_setu16(s, 2, mp->ap->applid);
36780 capimsg_setu8 (s, 4, CAPI_DATA_B3);
36781 capimsg_setu8 (s, 5, CAPI_RESP);
36782 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
36783 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
36784 capimsg_setu32(s, 8, mp->ncci);
36785 capimsg_setu16(s, 12, datahandle);
36786 }
36787 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
36788 mp->outbytes -= len;
36789 spin_unlock_bh(&mp->outlock);
36790
36791 - datahandle = atomic_inc_return(&mp->datahandle);
36792 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
36793 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
36794 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
36795 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
36796 capimsg_setu16(skb->data, 2, mp->ap->applid);
36797 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
36798 capimsg_setu8 (skb->data, 5, CAPI_REQ);
36799 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
36800 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
36801 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
36802 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
36803 capimsg_setu16(skb->data, 16, len); /* Data length */
36804 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
36805 index 67abf3f..076b3a6 100644
36806 --- a/drivers/isdn/gigaset/interface.c
36807 +++ b/drivers/isdn/gigaset/interface.c
36808 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
36809 }
36810 tty->driver_data = cs;
36811
36812 - ++cs->port.count;
36813 + atomic_inc(&cs->port.count);
36814
36815 - if (cs->port.count == 1) {
36816 + if (atomic_read(&cs->port.count) == 1) {
36817 tty_port_tty_set(&cs->port, tty);
36818 tty->low_latency = 1;
36819 }
36820 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
36821
36822 if (!cs->connected)
36823 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
36824 - else if (!cs->port.count)
36825 + else if (!atomic_read(&cs->port.count))
36826 dev_warn(cs->dev, "%s: device not opened\n", __func__);
36827 - else if (!--cs->port.count)
36828 + else if (!atomic_dec_return(&cs->port.count))
36829 tty_port_tty_set(&cs->port, NULL);
36830
36831 mutex_unlock(&cs->mutex);
36832 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
36833 index 821f7ac..28d4030 100644
36834 --- a/drivers/isdn/hardware/avm/b1.c
36835 +++ b/drivers/isdn/hardware/avm/b1.c
36836 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
36837 }
36838 if (left) {
36839 if (t4file->user) {
36840 - if (copy_from_user(buf, dp, left))
36841 + if (left > sizeof buf || copy_from_user(buf, dp, left))
36842 return -EFAULT;
36843 } else {
36844 memcpy(buf, dp, left);
36845 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
36846 }
36847 if (left) {
36848 if (config->user) {
36849 - if (copy_from_user(buf, dp, left))
36850 + if (left > sizeof buf || copy_from_user(buf, dp, left))
36851 return -EFAULT;
36852 } else {
36853 memcpy(buf, dp, left);
36854 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
36855 index e09dc8a..15e2efb 100644
36856 --- a/drivers/isdn/i4l/isdn_tty.c
36857 +++ b/drivers/isdn/i4l/isdn_tty.c
36858 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
36859
36860 #ifdef ISDN_DEBUG_MODEM_OPEN
36861 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
36862 - port->count);
36863 + atomic_read(&port->count));
36864 #endif
36865 - port->count++;
36866 + atomic_inc(&port->count);
36867 port->tty = tty;
36868 /*
36869 * Start up serial port
36870 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
36871 #endif
36872 return;
36873 }
36874 - if ((tty->count == 1) && (port->count != 1)) {
36875 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
36876 /*
36877 * Uh, oh. tty->count is 1, which means that the tty
36878 * structure will be freed. Info->count should always
36879 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
36880 * serial port won't be shutdown.
36881 */
36882 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
36883 - "info->count is %d\n", port->count);
36884 - port->count = 1;
36885 + "info->count is %d\n", atomic_read(&port->count));
36886 + atomic_set(&port->count, 1);
36887 }
36888 - if (--port->count < 0) {
36889 + if (atomic_dec_return(&port->count) < 0) {
36890 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
36891 - info->line, port->count);
36892 - port->count = 0;
36893 + info->line, atomic_read(&port->count));
36894 + atomic_set(&port->count, 0);
36895 }
36896 - if (port->count) {
36897 + if (atomic_read(&port->count)) {
36898 #ifdef ISDN_DEBUG_MODEM_OPEN
36899 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
36900 #endif
36901 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
36902 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
36903 return;
36904 isdn_tty_shutdown(info);
36905 - port->count = 0;
36906 + atomic_set(&port->count, 0);
36907 port->flags &= ~ASYNC_NORMAL_ACTIVE;
36908 port->tty = NULL;
36909 wake_up_interruptible(&port->open_wait);
36910 @@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
36911 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
36912 modem_info *info = &dev->mdm.info[i];
36913
36914 - if (info->port.count == 0)
36915 + if (atomic_read(&info->port.count) == 0)
36916 continue;
36917 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
36918 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
36919 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
36920 index e74df7c..03a03ba 100644
36921 --- a/drivers/isdn/icn/icn.c
36922 +++ b/drivers/isdn/icn/icn.c
36923 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
36924 if (count > len)
36925 count = len;
36926 if (user) {
36927 - if (copy_from_user(msg, buf, count))
36928 + if (count > sizeof msg || copy_from_user(msg, buf, count))
36929 return -EFAULT;
36930 } else
36931 memcpy(msg, buf, count);
36932 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
36933 index 6a8405d..0bd1c7e 100644
36934 --- a/drivers/leds/leds-clevo-mail.c
36935 +++ b/drivers/leds/leds-clevo-mail.c
36936 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
36937 * detected as working, but in reality it is not) as low as
36938 * possible.
36939 */
36940 -static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
36941 +static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
36942 {
36943 .callback = clevo_mail_led_dmi_callback,
36944 .ident = "Clevo D410J",
36945 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
36946 index ec9b287..65c9bf4 100644
36947 --- a/drivers/leds/leds-ss4200.c
36948 +++ b/drivers/leds/leds-ss4200.c
36949 @@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
36950 * detected as working, but in reality it is not) as low as
36951 * possible.
36952 */
36953 -static struct dmi_system_id __initdata nas_led_whitelist[] = {
36954 +static const struct dmi_system_id __initconst nas_led_whitelist[] = {
36955 {
36956 .callback = ss4200_led_dmi_callback,
36957 .ident = "Intel SS4200-E",
36958 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
36959 index a5ebc00..982886f 100644
36960 --- a/drivers/lguest/core.c
36961 +++ b/drivers/lguest/core.c
36962 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
36963 * it's worked so far. The end address needs +1 because __get_vm_area
36964 * allocates an extra guard page, so we need space for that.
36965 */
36966 +
36967 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
36968 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
36969 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
36970 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
36971 +#else
36972 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
36973 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
36974 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
36975 +#endif
36976 +
36977 if (!switcher_vma) {
36978 err = -ENOMEM;
36979 printk("lguest: could not map switcher pages high\n");
36980 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
36981 * Now the Switcher is mapped at the right address, we can't fail!
36982 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
36983 */
36984 - memcpy(switcher_vma->addr, start_switcher_text,
36985 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
36986 end_switcher_text - start_switcher_text);
36987
36988 printk(KERN_INFO "lguest: mapped switcher at %p\n",
36989 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
36990 index 4af12e1..0e89afe 100644
36991 --- a/drivers/lguest/x86/core.c
36992 +++ b/drivers/lguest/x86/core.c
36993 @@ -59,7 +59,7 @@ static struct {
36994 /* Offset from where switcher.S was compiled to where we've copied it */
36995 static unsigned long switcher_offset(void)
36996 {
36997 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
36998 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
36999 }
37000
37001 /* This cpu's struct lguest_pages. */
37002 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37003 * These copies are pretty cheap, so we do them unconditionally: */
37004 /* Save the current Host top-level page directory.
37005 */
37006 +
37007 +#ifdef CONFIG_PAX_PER_CPU_PGD
37008 + pages->state.host_cr3 = read_cr3();
37009 +#else
37010 pages->state.host_cr3 = __pa(current->mm->pgd);
37011 +#endif
37012 +
37013 /*
37014 * Set up the Guest's page tables to see this CPU's pages (and no
37015 * other CPU's pages).
37016 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37017 * compiled-in switcher code and the high-mapped copy we just made.
37018 */
37019 for (i = 0; i < IDT_ENTRIES; i++)
37020 - default_idt_entries[i] += switcher_offset();
37021 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37022
37023 /*
37024 * Set up the Switcher's per-cpu areas.
37025 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37026 * it will be undisturbed when we switch. To change %cs and jump we
37027 * need this structure to feed to Intel's "lcall" instruction.
37028 */
37029 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
37030 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
37031 lguest_entry.segment = LGUEST_CS;
37032
37033 /*
37034 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
37035 index 40634b0..4f5855e 100644
37036 --- a/drivers/lguest/x86/switcher_32.S
37037 +++ b/drivers/lguest/x86/switcher_32.S
37038 @@ -87,6 +87,7 @@
37039 #include <asm/page.h>
37040 #include <asm/segment.h>
37041 #include <asm/lguest.h>
37042 +#include <asm/processor-flags.h>
37043
37044 // We mark the start of the code to copy
37045 // It's placed in .text tho it's never run here
37046 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
37047 // Changes type when we load it: damn Intel!
37048 // For after we switch over our page tables
37049 // That entry will be read-only: we'd crash.
37050 +
37051 +#ifdef CONFIG_PAX_KERNEXEC
37052 + mov %cr0, %edx
37053 + xor $X86_CR0_WP, %edx
37054 + mov %edx, %cr0
37055 +#endif
37056 +
37057 movl $(GDT_ENTRY_TSS*8), %edx
37058 ltr %dx
37059
37060 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
37061 // Let's clear it again for our return.
37062 // The GDT descriptor of the Host
37063 // Points to the table after two "size" bytes
37064 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
37065 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
37066 // Clear "used" from type field (byte 5, bit 2)
37067 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
37068 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
37069 +
37070 +#ifdef CONFIG_PAX_KERNEXEC
37071 + mov %cr0, %eax
37072 + xor $X86_CR0_WP, %eax
37073 + mov %eax, %cr0
37074 +#endif
37075
37076 // Once our page table's switched, the Guest is live!
37077 // The Host fades as we run this final step.
37078 @@ -295,13 +309,12 @@ deliver_to_host:
37079 // I consulted gcc, and it gave
37080 // These instructions, which I gladly credit:
37081 leal (%edx,%ebx,8), %eax
37082 - movzwl (%eax),%edx
37083 - movl 4(%eax), %eax
37084 - xorw %ax, %ax
37085 - orl %eax, %edx
37086 + movl 4(%eax), %edx
37087 + movw (%eax), %dx
37088 // Now the address of the handler's in %edx
37089 // We call it now: its "iret" drops us home.
37090 - jmp *%edx
37091 + ljmp $__KERNEL_CS, $1f
37092 +1: jmp *%edx
37093
37094 // Every interrupt can come to us here
37095 // But we must truly tell each apart.
37096 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
37097 index 7155945..4bcc562 100644
37098 --- a/drivers/md/bitmap.c
37099 +++ b/drivers/md/bitmap.c
37100 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
37101 chunk_kb ? "KB" : "B");
37102 if (bitmap->storage.file) {
37103 seq_printf(seq, ", file: ");
37104 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
37105 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
37106 }
37107
37108 seq_printf(seq, "\n");
37109 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
37110 index 0666b5d..ed82cb4 100644
37111 --- a/drivers/md/dm-ioctl.c
37112 +++ b/drivers/md/dm-ioctl.c
37113 @@ -1628,7 +1628,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
37114 cmd == DM_LIST_VERSIONS_CMD)
37115 return 0;
37116
37117 - if ((cmd == DM_DEV_CREATE_CMD)) {
37118 + if (cmd == DM_DEV_CREATE_CMD) {
37119 if (!*param->name) {
37120 DMWARN("name not supplied when creating device");
37121 return -EINVAL;
37122 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
37123 index fa51918..c26253c 100644
37124 --- a/drivers/md/dm-raid1.c
37125 +++ b/drivers/md/dm-raid1.c
37126 @@ -40,7 +40,7 @@ enum dm_raid1_error {
37127
37128 struct mirror {
37129 struct mirror_set *ms;
37130 - atomic_t error_count;
37131 + atomic_unchecked_t error_count;
37132 unsigned long error_type;
37133 struct dm_dev *dev;
37134 sector_t offset;
37135 @@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
37136 struct mirror *m;
37137
37138 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
37139 - if (!atomic_read(&m->error_count))
37140 + if (!atomic_read_unchecked(&m->error_count))
37141 return m;
37142
37143 return NULL;
37144 @@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
37145 * simple way to tell if a device has encountered
37146 * errors.
37147 */
37148 - atomic_inc(&m->error_count);
37149 + atomic_inc_unchecked(&m->error_count);
37150
37151 if (test_and_set_bit(error_type, &m->error_type))
37152 return;
37153 @@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
37154 struct mirror *m = get_default_mirror(ms);
37155
37156 do {
37157 - if (likely(!atomic_read(&m->error_count)))
37158 + if (likely(!atomic_read_unchecked(&m->error_count)))
37159 return m;
37160
37161 if (m-- == ms->mirror)
37162 @@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
37163 {
37164 struct mirror *default_mirror = get_default_mirror(m->ms);
37165
37166 - return !atomic_read(&default_mirror->error_count);
37167 + return !atomic_read_unchecked(&default_mirror->error_count);
37168 }
37169
37170 static int mirror_available(struct mirror_set *ms, struct bio *bio)
37171 @@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
37172 */
37173 if (likely(region_in_sync(ms, region, 1)))
37174 m = choose_mirror(ms, bio->bi_sector);
37175 - else if (m && atomic_read(&m->error_count))
37176 + else if (m && atomic_read_unchecked(&m->error_count))
37177 m = NULL;
37178
37179 if (likely(m))
37180 @@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
37181 }
37182
37183 ms->mirror[mirror].ms = ms;
37184 - atomic_set(&(ms->mirror[mirror].error_count), 0);
37185 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
37186 ms->mirror[mirror].error_type = 0;
37187 ms->mirror[mirror].offset = offset;
37188
37189 @@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
37190 */
37191 static char device_status_char(struct mirror *m)
37192 {
37193 - if (!atomic_read(&(m->error_count)))
37194 + if (!atomic_read_unchecked(&(m->error_count)))
37195 return 'A';
37196
37197 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
37198 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
37199 index c89cde8..9d184cf 100644
37200 --- a/drivers/md/dm-stripe.c
37201 +++ b/drivers/md/dm-stripe.c
37202 @@ -20,7 +20,7 @@ struct stripe {
37203 struct dm_dev *dev;
37204 sector_t physical_start;
37205
37206 - atomic_t error_count;
37207 + atomic_unchecked_t error_count;
37208 };
37209
37210 struct stripe_c {
37211 @@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
37212 kfree(sc);
37213 return r;
37214 }
37215 - atomic_set(&(sc->stripe[i].error_count), 0);
37216 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
37217 }
37218
37219 ti->private = sc;
37220 @@ -325,7 +325,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
37221 DMEMIT("%d ", sc->stripes);
37222 for (i = 0; i < sc->stripes; i++) {
37223 DMEMIT("%s ", sc->stripe[i].dev->name);
37224 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
37225 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
37226 'D' : 'A';
37227 }
37228 buffer[i] = '\0';
37229 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
37230 */
37231 for (i = 0; i < sc->stripes; i++)
37232 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
37233 - atomic_inc(&(sc->stripe[i].error_count));
37234 - if (atomic_read(&(sc->stripe[i].error_count)) <
37235 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
37236 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
37237 DM_IO_ERROR_THRESHOLD)
37238 schedule_work(&sc->trigger_event);
37239 }
37240 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
37241 index daf25d0..d74f49f 100644
37242 --- a/drivers/md/dm-table.c
37243 +++ b/drivers/md/dm-table.c
37244 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
37245 if (!dev_size)
37246 return 0;
37247
37248 - if ((start >= dev_size) || (start + len > dev_size)) {
37249 + if ((start >= dev_size) || (len > dev_size - start)) {
37250 DMWARN("%s: %s too small for target: "
37251 "start=%llu, len=%llu, dev_size=%llu",
37252 dm_device_name(ti->table->md), bdevname(bdev, b),
37253 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
37254 index 4d6e853..a234157 100644
37255 --- a/drivers/md/dm-thin-metadata.c
37256 +++ b/drivers/md/dm-thin-metadata.c
37257 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37258 {
37259 pmd->info.tm = pmd->tm;
37260 pmd->info.levels = 2;
37261 - pmd->info.value_type.context = pmd->data_sm;
37262 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37263 pmd->info.value_type.size = sizeof(__le64);
37264 pmd->info.value_type.inc = data_block_inc;
37265 pmd->info.value_type.dec = data_block_dec;
37266 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37267
37268 pmd->bl_info.tm = pmd->tm;
37269 pmd->bl_info.levels = 1;
37270 - pmd->bl_info.value_type.context = pmd->data_sm;
37271 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37272 pmd->bl_info.value_type.size = sizeof(__le64);
37273 pmd->bl_info.value_type.inc = data_block_inc;
37274 pmd->bl_info.value_type.dec = data_block_dec;
37275 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
37276 index 314a0e2..1376406 100644
37277 --- a/drivers/md/dm.c
37278 +++ b/drivers/md/dm.c
37279 @@ -170,9 +170,9 @@ struct mapped_device {
37280 /*
37281 * Event handling.
37282 */
37283 - atomic_t event_nr;
37284 + atomic_unchecked_t event_nr;
37285 wait_queue_head_t eventq;
37286 - atomic_t uevent_seq;
37287 + atomic_unchecked_t uevent_seq;
37288 struct list_head uevent_list;
37289 spinlock_t uevent_lock; /* Protect access to uevent_list */
37290
37291 @@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
37292 rwlock_init(&md->map_lock);
37293 atomic_set(&md->holders, 1);
37294 atomic_set(&md->open_count, 0);
37295 - atomic_set(&md->event_nr, 0);
37296 - atomic_set(&md->uevent_seq, 0);
37297 + atomic_set_unchecked(&md->event_nr, 0);
37298 + atomic_set_unchecked(&md->uevent_seq, 0);
37299 INIT_LIST_HEAD(&md->uevent_list);
37300 spin_lock_init(&md->uevent_lock);
37301
37302 @@ -2014,7 +2014,7 @@ static void event_callback(void *context)
37303
37304 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
37305
37306 - atomic_inc(&md->event_nr);
37307 + atomic_inc_unchecked(&md->event_nr);
37308 wake_up(&md->eventq);
37309 }
37310
37311 @@ -2669,18 +2669,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
37312
37313 uint32_t dm_next_uevent_seq(struct mapped_device *md)
37314 {
37315 - return atomic_add_return(1, &md->uevent_seq);
37316 + return atomic_add_return_unchecked(1, &md->uevent_seq);
37317 }
37318
37319 uint32_t dm_get_event_nr(struct mapped_device *md)
37320 {
37321 - return atomic_read(&md->event_nr);
37322 + return atomic_read_unchecked(&md->event_nr);
37323 }
37324
37325 int dm_wait_event(struct mapped_device *md, int event_nr)
37326 {
37327 return wait_event_interruptible(md->eventq,
37328 - (event_nr != atomic_read(&md->event_nr)));
37329 + (event_nr != atomic_read_unchecked(&md->event_nr)));
37330 }
37331
37332 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
37333 diff --git a/drivers/md/md.c b/drivers/md/md.c
37334 index 3db3d1b..9487468 100644
37335 --- a/drivers/md/md.c
37336 +++ b/drivers/md/md.c
37337 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
37338 * start build, activate spare
37339 */
37340 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
37341 -static atomic_t md_event_count;
37342 +static atomic_unchecked_t md_event_count;
37343 void md_new_event(struct mddev *mddev)
37344 {
37345 - atomic_inc(&md_event_count);
37346 + atomic_inc_unchecked(&md_event_count);
37347 wake_up(&md_event_waiters);
37348 }
37349 EXPORT_SYMBOL_GPL(md_new_event);
37350 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
37351 */
37352 static void md_new_event_inintr(struct mddev *mddev)
37353 {
37354 - atomic_inc(&md_event_count);
37355 + atomic_inc_unchecked(&md_event_count);
37356 wake_up(&md_event_waiters);
37357 }
37358
37359 @@ -1503,7 +1503,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
37360 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
37361 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
37362 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
37363 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37364 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37365
37366 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
37367 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
37368 @@ -1747,7 +1747,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
37369 else
37370 sb->resync_offset = cpu_to_le64(0);
37371
37372 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
37373 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
37374
37375 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
37376 sb->size = cpu_to_le64(mddev->dev_sectors);
37377 @@ -2747,7 +2747,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
37378 static ssize_t
37379 errors_show(struct md_rdev *rdev, char *page)
37380 {
37381 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
37382 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
37383 }
37384
37385 static ssize_t
37386 @@ -2756,7 +2756,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
37387 char *e;
37388 unsigned long n = simple_strtoul(buf, &e, 10);
37389 if (*buf && (*e == 0 || *e == '\n')) {
37390 - atomic_set(&rdev->corrected_errors, n);
37391 + atomic_set_unchecked(&rdev->corrected_errors, n);
37392 return len;
37393 }
37394 return -EINVAL;
37395 @@ -3203,8 +3203,8 @@ int md_rdev_init(struct md_rdev *rdev)
37396 rdev->sb_loaded = 0;
37397 rdev->bb_page = NULL;
37398 atomic_set(&rdev->nr_pending, 0);
37399 - atomic_set(&rdev->read_errors, 0);
37400 - atomic_set(&rdev->corrected_errors, 0);
37401 + atomic_set_unchecked(&rdev->read_errors, 0);
37402 + atomic_set_unchecked(&rdev->corrected_errors, 0);
37403
37404 INIT_LIST_HEAD(&rdev->same_set);
37405 init_waitqueue_head(&rdev->blocked_wait);
37406 @@ -6980,7 +6980,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
37407
37408 spin_unlock(&pers_lock);
37409 seq_printf(seq, "\n");
37410 - seq->poll_event = atomic_read(&md_event_count);
37411 + seq->poll_event = atomic_read_unchecked(&md_event_count);
37412 return 0;
37413 }
37414 if (v == (void*)2) {
37415 @@ -7083,7 +7083,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
37416 return error;
37417
37418 seq = file->private_data;
37419 - seq->poll_event = atomic_read(&md_event_count);
37420 + seq->poll_event = atomic_read_unchecked(&md_event_count);
37421 return error;
37422 }
37423
37424 @@ -7097,7 +7097,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
37425 /* always allow read */
37426 mask = POLLIN | POLLRDNORM;
37427
37428 - if (seq->poll_event != atomic_read(&md_event_count))
37429 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
37430 mask |= POLLERR | POLLPRI;
37431 return mask;
37432 }
37433 @@ -7141,7 +7141,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
37434 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
37435 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
37436 (int)part_stat_read(&disk->part0, sectors[1]) -
37437 - atomic_read(&disk->sync_io);
37438 + atomic_read_unchecked(&disk->sync_io);
37439 /* sync IO will cause sync_io to increase before the disk_stats
37440 * as sync_io is counted when a request starts, and
37441 * disk_stats is counted when it completes.
37442 diff --git a/drivers/md/md.h b/drivers/md/md.h
37443 index eca59c3..7c42285 100644
37444 --- a/drivers/md/md.h
37445 +++ b/drivers/md/md.h
37446 @@ -94,13 +94,13 @@ struct md_rdev {
37447 * only maintained for arrays that
37448 * support hot removal
37449 */
37450 - atomic_t read_errors; /* number of consecutive read errors that
37451 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
37452 * we have tried to ignore.
37453 */
37454 struct timespec last_read_error; /* monotonic time since our
37455 * last read error
37456 */
37457 - atomic_t corrected_errors; /* number of corrected read errors,
37458 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
37459 * for reporting to userspace and storing
37460 * in superblock.
37461 */
37462 @@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
37463
37464 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
37465 {
37466 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37467 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37468 }
37469
37470 struct md_personality
37471 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
37472 index 1cbfc6b..56e1dbb 100644
37473 --- a/drivers/md/persistent-data/dm-space-map.h
37474 +++ b/drivers/md/persistent-data/dm-space-map.h
37475 @@ -60,6 +60,7 @@ struct dm_space_map {
37476 int (*root_size)(struct dm_space_map *sm, size_t *result);
37477 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
37478 };
37479 +typedef struct dm_space_map __no_const dm_space_map_no_const;
37480
37481 /*----------------------------------------------------------------*/
37482
37483 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
37484 index d5bddfc..b079b4b 100644
37485 --- a/drivers/md/raid1.c
37486 +++ b/drivers/md/raid1.c
37487 @@ -1818,7 +1818,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
37488 if (r1_sync_page_io(rdev, sect, s,
37489 bio->bi_io_vec[idx].bv_page,
37490 READ) != 0)
37491 - atomic_add(s, &rdev->corrected_errors);
37492 + atomic_add_unchecked(s, &rdev->corrected_errors);
37493 }
37494 sectors -= s;
37495 sect += s;
37496 @@ -2040,7 +2040,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
37497 test_bit(In_sync, &rdev->flags)) {
37498 if (r1_sync_page_io(rdev, sect, s,
37499 conf->tmppage, READ)) {
37500 - atomic_add(s, &rdev->corrected_errors);
37501 + atomic_add_unchecked(s, &rdev->corrected_errors);
37502 printk(KERN_INFO
37503 "md/raid1:%s: read error corrected "
37504 "(%d sectors at %llu on %s)\n",
37505 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
37506 index 64d4824..8b9ea57 100644
37507 --- a/drivers/md/raid10.c
37508 +++ b/drivers/md/raid10.c
37509 @@ -1877,7 +1877,7 @@ static void end_sync_read(struct bio *bio, int error)
37510 /* The write handler will notice the lack of
37511 * R10BIO_Uptodate and record any errors etc
37512 */
37513 - atomic_add(r10_bio->sectors,
37514 + atomic_add_unchecked(r10_bio->sectors,
37515 &conf->mirrors[d].rdev->corrected_errors);
37516
37517 /* for reconstruct, we always reschedule after a read.
37518 @@ -2226,7 +2226,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
37519 {
37520 struct timespec cur_time_mon;
37521 unsigned long hours_since_last;
37522 - unsigned int read_errors = atomic_read(&rdev->read_errors);
37523 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
37524
37525 ktime_get_ts(&cur_time_mon);
37526
37527 @@ -2248,9 +2248,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
37528 * overflowing the shift of read_errors by hours_since_last.
37529 */
37530 if (hours_since_last >= 8 * sizeof(read_errors))
37531 - atomic_set(&rdev->read_errors, 0);
37532 + atomic_set_unchecked(&rdev->read_errors, 0);
37533 else
37534 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
37535 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
37536 }
37537
37538 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
37539 @@ -2304,8 +2304,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37540 return;
37541
37542 check_decay_read_errors(mddev, rdev);
37543 - atomic_inc(&rdev->read_errors);
37544 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
37545 + atomic_inc_unchecked(&rdev->read_errors);
37546 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
37547 char b[BDEVNAME_SIZE];
37548 bdevname(rdev->bdev, b);
37549
37550 @@ -2313,7 +2313,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37551 "md/raid10:%s: %s: Raid device exceeded "
37552 "read_error threshold [cur %d:max %d]\n",
37553 mdname(mddev), b,
37554 - atomic_read(&rdev->read_errors), max_read_errors);
37555 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
37556 printk(KERN_NOTICE
37557 "md/raid10:%s: %s: Failing raid device\n",
37558 mdname(mddev), b);
37559 @@ -2468,7 +2468,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37560 sect +
37561 choose_data_offset(r10_bio, rdev)),
37562 bdevname(rdev->bdev, b));
37563 - atomic_add(s, &rdev->corrected_errors);
37564 + atomic_add_unchecked(s, &rdev->corrected_errors);
37565 }
37566
37567 rdev_dec_pending(rdev, mddev);
37568 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
37569 index 19d77a0..56051b92 100644
37570 --- a/drivers/md/raid5.c
37571 +++ b/drivers/md/raid5.c
37572 @@ -1797,21 +1797,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
37573 mdname(conf->mddev), STRIPE_SECTORS,
37574 (unsigned long long)s,
37575 bdevname(rdev->bdev, b));
37576 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
37577 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
37578 clear_bit(R5_ReadError, &sh->dev[i].flags);
37579 clear_bit(R5_ReWrite, &sh->dev[i].flags);
37580 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
37581 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
37582
37583 - if (atomic_read(&rdev->read_errors))
37584 - atomic_set(&rdev->read_errors, 0);
37585 + if (atomic_read_unchecked(&rdev->read_errors))
37586 + atomic_set_unchecked(&rdev->read_errors, 0);
37587 } else {
37588 const char *bdn = bdevname(rdev->bdev, b);
37589 int retry = 0;
37590 int set_bad = 0;
37591
37592 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
37593 - atomic_inc(&rdev->read_errors);
37594 + atomic_inc_unchecked(&rdev->read_errors);
37595 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
37596 printk_ratelimited(
37597 KERN_WARNING
37598 @@ -1839,7 +1839,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
37599 mdname(conf->mddev),
37600 (unsigned long long)s,
37601 bdn);
37602 - } else if (atomic_read(&rdev->read_errors)
37603 + } else if (atomic_read_unchecked(&rdev->read_errors)
37604 > conf->max_nr_stripes)
37605 printk(KERN_WARNING
37606 "md/raid:%s: Too many read errors, failing device %s.\n",
37607 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
37608 index d33101a..6b13069 100644
37609 --- a/drivers/media/dvb-core/dvbdev.c
37610 +++ b/drivers/media/dvb-core/dvbdev.c
37611 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
37612 const struct dvb_device *template, void *priv, int type)
37613 {
37614 struct dvb_device *dvbdev;
37615 - struct file_operations *dvbdevfops;
37616 + file_operations_no_const *dvbdevfops;
37617 struct device *clsdev;
37618 int minor;
37619 int id;
37620 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
37621 index 404f63a..4796533 100644
37622 --- a/drivers/media/dvb-frontends/dib3000.h
37623 +++ b/drivers/media/dvb-frontends/dib3000.h
37624 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
37625 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
37626 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
37627 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
37628 -};
37629 +} __no_const;
37630
37631 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
37632 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
37633 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
37634 index 8e9a668..78d6310 100644
37635 --- a/drivers/media/platform/omap/omap_vout.c
37636 +++ b/drivers/media/platform/omap/omap_vout.c
37637 @@ -63,7 +63,6 @@ enum omap_vout_channels {
37638 OMAP_VIDEO2,
37639 };
37640
37641 -static struct videobuf_queue_ops video_vbq_ops;
37642 /* Variables configurable through module params*/
37643 static u32 video1_numbuffers = 3;
37644 static u32 video2_numbuffers = 3;
37645 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
37646 {
37647 struct videobuf_queue *q;
37648 struct omap_vout_device *vout = NULL;
37649 + static struct videobuf_queue_ops video_vbq_ops = {
37650 + .buf_setup = omap_vout_buffer_setup,
37651 + .buf_prepare = omap_vout_buffer_prepare,
37652 + .buf_release = omap_vout_buffer_release,
37653 + .buf_queue = omap_vout_buffer_queue,
37654 + };
37655
37656 vout = video_drvdata(file);
37657 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
37658 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
37659 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
37660
37661 q = &vout->vbq;
37662 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
37663 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
37664 - video_vbq_ops.buf_release = omap_vout_buffer_release;
37665 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
37666 spin_lock_init(&vout->vbq_lock);
37667
37668 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
37669 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
37670 index b671e20..34088b7 100644
37671 --- a/drivers/media/platform/s5p-tv/mixer.h
37672 +++ b/drivers/media/platform/s5p-tv/mixer.h
37673 @@ -155,7 +155,7 @@ struct mxr_layer {
37674 /** layer index (unique identifier) */
37675 int idx;
37676 /** callbacks for layer methods */
37677 - struct mxr_layer_ops ops;
37678 + struct mxr_layer_ops *ops;
37679 /** format array */
37680 const struct mxr_format **fmt_array;
37681 /** size of format array */
37682 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
37683 index b93a21f..2535195 100644
37684 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
37685 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
37686 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
37687 {
37688 struct mxr_layer *layer;
37689 int ret;
37690 - struct mxr_layer_ops ops = {
37691 + static struct mxr_layer_ops ops = {
37692 .release = mxr_graph_layer_release,
37693 .buffer_set = mxr_graph_buffer_set,
37694 .stream_set = mxr_graph_stream_set,
37695 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
37696 index 3b1670a..595c939 100644
37697 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
37698 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
37699 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
37700 layer->update_buf = next;
37701 }
37702
37703 - layer->ops.buffer_set(layer, layer->update_buf);
37704 + layer->ops->buffer_set(layer, layer->update_buf);
37705
37706 if (done && done != layer->shadow_buf)
37707 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
37708 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
37709 index 1f3b743..e839271 100644
37710 --- a/drivers/media/platform/s5p-tv/mixer_video.c
37711 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
37712 @@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
37713 layer->geo.src.height = layer->geo.src.full_height;
37714
37715 mxr_geometry_dump(mdev, &layer->geo);
37716 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37717 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37718 mxr_geometry_dump(mdev, &layer->geo);
37719 }
37720
37721 @@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
37722 layer->geo.dst.full_width = mbus_fmt.width;
37723 layer->geo.dst.full_height = mbus_fmt.height;
37724 layer->geo.dst.field = mbus_fmt.field;
37725 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37726 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37727
37728 mxr_geometry_dump(mdev, &layer->geo);
37729 }
37730 @@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
37731 /* set source size to highest accepted value */
37732 geo->src.full_width = max(geo->dst.full_width, pix->width);
37733 geo->src.full_height = max(geo->dst.full_height, pix->height);
37734 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37735 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37736 mxr_geometry_dump(mdev, &layer->geo);
37737 /* set cropping to total visible screen */
37738 geo->src.width = pix->width;
37739 @@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
37740 geo->src.x_offset = 0;
37741 geo->src.y_offset = 0;
37742 /* assure consistency of geometry */
37743 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
37744 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
37745 mxr_geometry_dump(mdev, &layer->geo);
37746 /* set full size to lowest possible value */
37747 geo->src.full_width = 0;
37748 geo->src.full_height = 0;
37749 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37750 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37751 mxr_geometry_dump(mdev, &layer->geo);
37752
37753 /* returning results */
37754 @@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
37755 target->width = s->r.width;
37756 target->height = s->r.height;
37757
37758 - layer->ops.fix_geometry(layer, stage, s->flags);
37759 + layer->ops->fix_geometry(layer, stage, s->flags);
37760
37761 /* retrieve update selection rectangle */
37762 res.left = target->x_offset;
37763 @@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
37764 mxr_output_get(mdev);
37765
37766 mxr_layer_update_output(layer);
37767 - layer->ops.format_set(layer);
37768 + layer->ops->format_set(layer);
37769 /* enabling layer in hardware */
37770 spin_lock_irqsave(&layer->enq_slock, flags);
37771 layer->state = MXR_LAYER_STREAMING;
37772 spin_unlock_irqrestore(&layer->enq_slock, flags);
37773
37774 - layer->ops.stream_set(layer, MXR_ENABLE);
37775 + layer->ops->stream_set(layer, MXR_ENABLE);
37776 mxr_streamer_get(mdev);
37777
37778 return 0;
37779 @@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
37780 spin_unlock_irqrestore(&layer->enq_slock, flags);
37781
37782 /* disabling layer in hardware */
37783 - layer->ops.stream_set(layer, MXR_DISABLE);
37784 + layer->ops->stream_set(layer, MXR_DISABLE);
37785 /* remove one streamer */
37786 mxr_streamer_put(mdev);
37787 /* allow changes in output configuration */
37788 @@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
37789
37790 void mxr_layer_release(struct mxr_layer *layer)
37791 {
37792 - if (layer->ops.release)
37793 - layer->ops.release(layer);
37794 + if (layer->ops->release)
37795 + layer->ops->release(layer);
37796 }
37797
37798 void mxr_base_layer_release(struct mxr_layer *layer)
37799 @@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
37800
37801 layer->mdev = mdev;
37802 layer->idx = idx;
37803 - layer->ops = *ops;
37804 + layer->ops = ops;
37805
37806 spin_lock_init(&layer->enq_slock);
37807 INIT_LIST_HEAD(&layer->enq_list);
37808 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
37809 index 3d13a63..da31bf1 100644
37810 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
37811 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
37812 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
37813 {
37814 struct mxr_layer *layer;
37815 int ret;
37816 - struct mxr_layer_ops ops = {
37817 + static struct mxr_layer_ops ops = {
37818 .release = mxr_vp_layer_release,
37819 .buffer_set = mxr_vp_buffer_set,
37820 .stream_set = mxr_vp_stream_set,
37821 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
37822 index 643d80a..56bb96b 100644
37823 --- a/drivers/media/radio/radio-cadet.c
37824 +++ b/drivers/media/radio/radio-cadet.c
37825 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
37826 unsigned char readbuf[RDS_BUFFER];
37827 int i = 0;
37828
37829 + if (count > RDS_BUFFER)
37830 + return -EFAULT;
37831 mutex_lock(&dev->lock);
37832 if (dev->rdsstat == 0)
37833 cadet_start_rds(dev);
37834 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
37835 while (i < count && dev->rdsin != dev->rdsout)
37836 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
37837
37838 - if (i && copy_to_user(data, readbuf, i))
37839 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
37840 i = -EFAULT;
37841 unlock:
37842 mutex_unlock(&dev->lock);
37843 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
37844 index 3940bb0..fb3952a 100644
37845 --- a/drivers/media/usb/dvb-usb/cxusb.c
37846 +++ b/drivers/media/usb/dvb-usb/cxusb.c
37847 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
37848
37849 struct dib0700_adapter_state {
37850 int (*set_param_save) (struct dvb_frontend *);
37851 -};
37852 +} __no_const;
37853
37854 static int dib7070_set_param_override(struct dvb_frontend *fe)
37855 {
37856 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
37857 index 9382895..ac8093c 100644
37858 --- a/drivers/media/usb/dvb-usb/dw2102.c
37859 +++ b/drivers/media/usb/dvb-usb/dw2102.c
37860 @@ -95,7 +95,7 @@ struct su3000_state {
37861
37862 struct s6x0_state {
37863 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
37864 -};
37865 +} __no_const;
37866
37867 /* debug */
37868 static int dvb_usb_dw2102_debug;
37869 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
37870 index aa6e7c7..4cd8061 100644
37871 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
37872 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
37873 @@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
37874 struct file *file, void *fh, void *p);
37875 } u;
37876 void (*debug)(const void *arg, bool write_only);
37877 -};
37878 +} __do_const;
37879 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
37880
37881 /* This control needs a priority check */
37882 #define INFO_FL_PRIO (1 << 0)
37883 @@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
37884 struct video_device *vfd = video_devdata(file);
37885 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
37886 bool write_only = false;
37887 - struct v4l2_ioctl_info default_info;
37888 + v4l2_ioctl_info_no_const default_info;
37889 const struct v4l2_ioctl_info *info;
37890 void *fh = file->private_data;
37891 struct v4l2_fh *vfh = NULL;
37892 diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
37893 index 29b2172..a7c5b31 100644
37894 --- a/drivers/memstick/host/r592.c
37895 +++ b/drivers/memstick/host/r592.c
37896 @@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
37897 /* Executes one TPC (data is read/written from small or large fifo) */
37898 static void r592_execute_tpc(struct r592_device *dev)
37899 {
37900 - bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
37901 + bool is_write;
37902 int len, error;
37903 u32 status, reg;
37904
37905 @@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
37906 return;
37907 }
37908
37909 + is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
37910 len = dev->req->long_data ?
37911 dev->req->sg.length : dev->req->data_len;
37912
37913 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
37914 index fb69baa..cf7ad22 100644
37915 --- a/drivers/message/fusion/mptbase.c
37916 +++ b/drivers/message/fusion/mptbase.c
37917 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
37918 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
37919 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
37920
37921 +#ifdef CONFIG_GRKERNSEC_HIDESYM
37922 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
37923 +#else
37924 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
37925 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
37926 +#endif
37927 +
37928 /*
37929 * Rounding UP to nearest 4-kB boundary here...
37930 */
37931 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
37932 index fa43c39..daeb158 100644
37933 --- a/drivers/message/fusion/mptsas.c
37934 +++ b/drivers/message/fusion/mptsas.c
37935 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
37936 return 0;
37937 }
37938
37939 +static inline void
37940 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
37941 +{
37942 + if (phy_info->port_details) {
37943 + phy_info->port_details->rphy = rphy;
37944 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
37945 + ioc->name, rphy));
37946 + }
37947 +
37948 + if (rphy) {
37949 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
37950 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
37951 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
37952 + ioc->name, rphy, rphy->dev.release));
37953 + }
37954 +}
37955 +
37956 /* no mutex */
37957 static void
37958 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
37959 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
37960 return NULL;
37961 }
37962
37963 -static inline void
37964 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
37965 -{
37966 - if (phy_info->port_details) {
37967 - phy_info->port_details->rphy = rphy;
37968 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
37969 - ioc->name, rphy));
37970 - }
37971 -
37972 - if (rphy) {
37973 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
37974 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
37975 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
37976 - ioc->name, rphy, rphy->dev.release));
37977 - }
37978 -}
37979 -
37980 static inline struct sas_port *
37981 mptsas_get_port(struct mptsas_phyinfo *phy_info)
37982 {
37983 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
37984 index 164afa7..b6b2e74 100644
37985 --- a/drivers/message/fusion/mptscsih.c
37986 +++ b/drivers/message/fusion/mptscsih.c
37987 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
37988
37989 h = shost_priv(SChost);
37990
37991 - if (h) {
37992 - if (h->info_kbuf == NULL)
37993 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
37994 - return h->info_kbuf;
37995 - h->info_kbuf[0] = '\0';
37996 + if (!h)
37997 + return NULL;
37998
37999 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38000 - h->info_kbuf[size-1] = '\0';
38001 - }
38002 + if (h->info_kbuf == NULL)
38003 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38004 + return h->info_kbuf;
38005 + h->info_kbuf[0] = '\0';
38006 +
38007 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38008 + h->info_kbuf[size-1] = '\0';
38009
38010 return h->info_kbuf;
38011 }
38012 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
38013 index 8001aa6..b137580 100644
38014 --- a/drivers/message/i2o/i2o_proc.c
38015 +++ b/drivers/message/i2o/i2o_proc.c
38016 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
38017 "Array Controller Device"
38018 };
38019
38020 -static char *chtostr(char *tmp, u8 *chars, int n)
38021 -{
38022 - tmp[0] = 0;
38023 - return strncat(tmp, (char *)chars, n);
38024 -}
38025 -
38026 static int i2o_report_query_status(struct seq_file *seq, int block_status,
38027 char *group)
38028 {
38029 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38030 } *result;
38031
38032 i2o_exec_execute_ddm_table ddm_table;
38033 - char tmp[28 + 1];
38034
38035 result = kmalloc(sizeof(*result), GFP_KERNEL);
38036 if (!result)
38037 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38038
38039 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
38040 seq_printf(seq, "%-#8x", ddm_table.module_id);
38041 - seq_printf(seq, "%-29s",
38042 - chtostr(tmp, ddm_table.module_name_version, 28));
38043 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
38044 seq_printf(seq, "%9d ", ddm_table.data_size);
38045 seq_printf(seq, "%8d", ddm_table.code_size);
38046
38047 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38048
38049 i2o_driver_result_table *result;
38050 i2o_driver_store_table *dst;
38051 - char tmp[28 + 1];
38052
38053 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
38054 if (result == NULL)
38055 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38056
38057 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
38058 seq_printf(seq, "%-#8x", dst->module_id);
38059 - seq_printf(seq, "%-29s",
38060 - chtostr(tmp, dst->module_name_version, 28));
38061 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
38062 + seq_printf(seq, "%-.28s", dst->module_name_version);
38063 + seq_printf(seq, "%-.8s", dst->date);
38064 seq_printf(seq, "%8d ", dst->module_size);
38065 seq_printf(seq, "%8d ", dst->mpb_size);
38066 seq_printf(seq, "0x%04x", dst->module_flags);
38067 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38068 // == (allow) 512d bytes (max)
38069 static u16 *work16 = (u16 *) work32;
38070 int token;
38071 - char tmp[16 + 1];
38072
38073 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
38074
38075 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38076 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
38077 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
38078 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
38079 - seq_printf(seq, "Vendor info : %s\n",
38080 - chtostr(tmp, (u8 *) (work32 + 2), 16));
38081 - seq_printf(seq, "Product info : %s\n",
38082 - chtostr(tmp, (u8 *) (work32 + 6), 16));
38083 - seq_printf(seq, "Description : %s\n",
38084 - chtostr(tmp, (u8 *) (work32 + 10), 16));
38085 - seq_printf(seq, "Product rev. : %s\n",
38086 - chtostr(tmp, (u8 *) (work32 + 14), 8));
38087 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
38088 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
38089 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
38090 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
38091
38092 seq_printf(seq, "Serial number : ");
38093 print_serial_number(seq, (u8 *) (work32 + 16),
38094 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38095 u8 pad[256]; // allow up to 256 byte (max) serial number
38096 } result;
38097
38098 - char tmp[24 + 1];
38099 -
38100 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
38101
38102 if (token < 0) {
38103 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38104 }
38105
38106 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
38107 - seq_printf(seq, "Module name : %s\n",
38108 - chtostr(tmp, result.module_name, 24));
38109 - seq_printf(seq, "Module revision : %s\n",
38110 - chtostr(tmp, result.module_rev, 8));
38111 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
38112 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
38113
38114 seq_printf(seq, "Serial number : ");
38115 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
38116 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38117 u8 instance_number[4];
38118 } result;
38119
38120 - char tmp[64 + 1];
38121 -
38122 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
38123
38124 if (token < 0) {
38125 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38126 return 0;
38127 }
38128
38129 - seq_printf(seq, "Device name : %s\n",
38130 - chtostr(tmp, result.device_name, 64));
38131 - seq_printf(seq, "Service name : %s\n",
38132 - chtostr(tmp, result.service_name, 64));
38133 - seq_printf(seq, "Physical name : %s\n",
38134 - chtostr(tmp, result.physical_location, 64));
38135 - seq_printf(seq, "Instance number : %s\n",
38136 - chtostr(tmp, result.instance_number, 4));
38137 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
38138 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
38139 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
38140 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
38141
38142 return 0;
38143 }
38144 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
38145 index a8c08f3..155fe3d 100644
38146 --- a/drivers/message/i2o/iop.c
38147 +++ b/drivers/message/i2o/iop.c
38148 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
38149
38150 spin_lock_irqsave(&c->context_list_lock, flags);
38151
38152 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
38153 - atomic_inc(&c->context_list_counter);
38154 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
38155 + atomic_inc_unchecked(&c->context_list_counter);
38156
38157 - entry->context = atomic_read(&c->context_list_counter);
38158 + entry->context = atomic_read_unchecked(&c->context_list_counter);
38159
38160 list_add(&entry->list, &c->context_list);
38161
38162 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
38163
38164 #if BITS_PER_LONG == 64
38165 spin_lock_init(&c->context_list_lock);
38166 - atomic_set(&c->context_list_counter, 0);
38167 + atomic_set_unchecked(&c->context_list_counter, 0);
38168 INIT_LIST_HEAD(&c->context_list);
38169 #endif
38170
38171 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
38172 index 45ece11..8efa218 100644
38173 --- a/drivers/mfd/janz-cmodio.c
38174 +++ b/drivers/mfd/janz-cmodio.c
38175 @@ -13,6 +13,7 @@
38176
38177 #include <linux/kernel.h>
38178 #include <linux/module.h>
38179 +#include <linux/slab.h>
38180 #include <linux/init.h>
38181 #include <linux/pci.h>
38182 #include <linux/interrupt.h>
38183 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
38184 index a5f9888..9a77921 100644
38185 --- a/drivers/mfd/twl4030-irq.c
38186 +++ b/drivers/mfd/twl4030-irq.c
38187 @@ -728,10 +728,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
38188 * Install an irq handler for each of the SIH modules;
38189 * clone dummy irq_chip since PIH can't *do* anything
38190 */
38191 - twl4030_irq_chip = dummy_irq_chip;
38192 - twl4030_irq_chip.name = "twl4030";
38193 + pax_open_kernel();
38194 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
38195 + *(const char **)&twl4030_irq_chip.name = "twl4030";
38196
38197 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38198 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38199 + pax_close_kernel();
38200
38201 for (i = irq_base; i < irq_end; i++) {
38202 irq_set_chip_and_handler(i, &twl4030_irq_chip,
38203 diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
38204 index 277a8db..0e0b754 100644
38205 --- a/drivers/mfd/twl6030-irq.c
38206 +++ b/drivers/mfd/twl6030-irq.c
38207 @@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
38208 * install an irq handler for each of the modules;
38209 * clone dummy irq_chip since PIH can't *do* anything
38210 */
38211 - twl6030_irq_chip = dummy_irq_chip;
38212 - twl6030_irq_chip.name = "twl6030";
38213 - twl6030_irq_chip.irq_set_type = NULL;
38214 - twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38215 + pax_open_kernel();
38216 + memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
38217 + *(const char **)&twl6030_irq_chip.name = "twl6030";
38218 + *(void **)&twl6030_irq_chip.irq_set_type = NULL;
38219 + *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38220 + pax_close_kernel();
38221
38222 for (i = irq_base; i < irq_end; i++) {
38223 irq_set_chip_and_handler(i, &twl6030_irq_chip,
38224 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
38225 index f428d86..274c368 100644
38226 --- a/drivers/misc/c2port/core.c
38227 +++ b/drivers/misc/c2port/core.c
38228 @@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
38229 mutex_init(&c2dev->mutex);
38230
38231 /* Create binary file */
38232 - c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38233 + pax_open_kernel();
38234 + *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38235 + pax_close_kernel();
38236 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
38237 if (unlikely(ret))
38238 goto error_device_create_bin_file;
38239 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
38240 index 3aa9a96..59cf685 100644
38241 --- a/drivers/misc/kgdbts.c
38242 +++ b/drivers/misc/kgdbts.c
38243 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
38244 char before[BREAK_INSTR_SIZE];
38245 char after[BREAK_INSTR_SIZE];
38246
38247 - probe_kernel_read(before, (char *)kgdbts_break_test,
38248 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
38249 BREAK_INSTR_SIZE);
38250 init_simple_test();
38251 ts.tst = plant_and_detach_test;
38252 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
38253 /* Activate test with initial breakpoint */
38254 if (!is_early)
38255 kgdb_breakpoint();
38256 - probe_kernel_read(after, (char *)kgdbts_break_test,
38257 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
38258 BREAK_INSTR_SIZE);
38259 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
38260 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
38261 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
38262 index 4a87e5c..76bdf5c 100644
38263 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
38264 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
38265 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
38266 * the lid is closed. This leads to interrupts as soon as a little move
38267 * is done.
38268 */
38269 - atomic_inc(&lis3->count);
38270 + atomic_inc_unchecked(&lis3->count);
38271
38272 wake_up_interruptible(&lis3->misc_wait);
38273 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
38274 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
38275 if (lis3->pm_dev)
38276 pm_runtime_get_sync(lis3->pm_dev);
38277
38278 - atomic_set(&lis3->count, 0);
38279 + atomic_set_unchecked(&lis3->count, 0);
38280 return 0;
38281 }
38282
38283 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
38284 add_wait_queue(&lis3->misc_wait, &wait);
38285 while (true) {
38286 set_current_state(TASK_INTERRUPTIBLE);
38287 - data = atomic_xchg(&lis3->count, 0);
38288 + data = atomic_xchg_unchecked(&lis3->count, 0);
38289 if (data)
38290 break;
38291
38292 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
38293 struct lis3lv02d, miscdev);
38294
38295 poll_wait(file, &lis3->misc_wait, wait);
38296 - if (atomic_read(&lis3->count))
38297 + if (atomic_read_unchecked(&lis3->count))
38298 return POLLIN | POLLRDNORM;
38299 return 0;
38300 }
38301 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
38302 index c439c82..1f20f57 100644
38303 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
38304 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
38305 @@ -297,7 +297,7 @@ struct lis3lv02d {
38306 struct input_polled_dev *idev; /* input device */
38307 struct platform_device *pdev; /* platform device */
38308 struct regulator_bulk_data regulators[2];
38309 - atomic_t count; /* interrupt count after last read */
38310 + atomic_unchecked_t count; /* interrupt count after last read */
38311 union axis_conversion ac; /* hw -> logical axis */
38312 int mapped_btns[3];
38313
38314 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
38315 index 2f30bad..c4c13d0 100644
38316 --- a/drivers/misc/sgi-gru/gruhandles.c
38317 +++ b/drivers/misc/sgi-gru/gruhandles.c
38318 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
38319 unsigned long nsec;
38320
38321 nsec = CLKS2NSEC(clks);
38322 - atomic_long_inc(&mcs_op_statistics[op].count);
38323 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
38324 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
38325 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
38326 if (mcs_op_statistics[op].max < nsec)
38327 mcs_op_statistics[op].max = nsec;
38328 }
38329 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
38330 index 950dbe9..eeef0f8 100644
38331 --- a/drivers/misc/sgi-gru/gruprocfs.c
38332 +++ b/drivers/misc/sgi-gru/gruprocfs.c
38333 @@ -32,9 +32,9 @@
38334
38335 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
38336
38337 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
38338 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
38339 {
38340 - unsigned long val = atomic_long_read(v);
38341 + unsigned long val = atomic_long_read_unchecked(v);
38342
38343 seq_printf(s, "%16lu %s\n", val, id);
38344 }
38345 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
38346
38347 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
38348 for (op = 0; op < mcsop_last; op++) {
38349 - count = atomic_long_read(&mcs_op_statistics[op].count);
38350 - total = atomic_long_read(&mcs_op_statistics[op].total);
38351 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
38352 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
38353 max = mcs_op_statistics[op].max;
38354 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
38355 count ? total / count : 0, max);
38356 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
38357 index 5c3ce24..4915ccb 100644
38358 --- a/drivers/misc/sgi-gru/grutables.h
38359 +++ b/drivers/misc/sgi-gru/grutables.h
38360 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
38361 * GRU statistics.
38362 */
38363 struct gru_stats_s {
38364 - atomic_long_t vdata_alloc;
38365 - atomic_long_t vdata_free;
38366 - atomic_long_t gts_alloc;
38367 - atomic_long_t gts_free;
38368 - atomic_long_t gms_alloc;
38369 - atomic_long_t gms_free;
38370 - atomic_long_t gts_double_allocate;
38371 - atomic_long_t assign_context;
38372 - atomic_long_t assign_context_failed;
38373 - atomic_long_t free_context;
38374 - atomic_long_t load_user_context;
38375 - atomic_long_t load_kernel_context;
38376 - atomic_long_t lock_kernel_context;
38377 - atomic_long_t unlock_kernel_context;
38378 - atomic_long_t steal_user_context;
38379 - atomic_long_t steal_kernel_context;
38380 - atomic_long_t steal_context_failed;
38381 - atomic_long_t nopfn;
38382 - atomic_long_t asid_new;
38383 - atomic_long_t asid_next;
38384 - atomic_long_t asid_wrap;
38385 - atomic_long_t asid_reuse;
38386 - atomic_long_t intr;
38387 - atomic_long_t intr_cbr;
38388 - atomic_long_t intr_tfh;
38389 - atomic_long_t intr_spurious;
38390 - atomic_long_t intr_mm_lock_failed;
38391 - atomic_long_t call_os;
38392 - atomic_long_t call_os_wait_queue;
38393 - atomic_long_t user_flush_tlb;
38394 - atomic_long_t user_unload_context;
38395 - atomic_long_t user_exception;
38396 - atomic_long_t set_context_option;
38397 - atomic_long_t check_context_retarget_intr;
38398 - atomic_long_t check_context_unload;
38399 - atomic_long_t tlb_dropin;
38400 - atomic_long_t tlb_preload_page;
38401 - atomic_long_t tlb_dropin_fail_no_asid;
38402 - atomic_long_t tlb_dropin_fail_upm;
38403 - atomic_long_t tlb_dropin_fail_invalid;
38404 - atomic_long_t tlb_dropin_fail_range_active;
38405 - atomic_long_t tlb_dropin_fail_idle;
38406 - atomic_long_t tlb_dropin_fail_fmm;
38407 - atomic_long_t tlb_dropin_fail_no_exception;
38408 - atomic_long_t tfh_stale_on_fault;
38409 - atomic_long_t mmu_invalidate_range;
38410 - atomic_long_t mmu_invalidate_page;
38411 - atomic_long_t flush_tlb;
38412 - atomic_long_t flush_tlb_gru;
38413 - atomic_long_t flush_tlb_gru_tgh;
38414 - atomic_long_t flush_tlb_gru_zero_asid;
38415 + atomic_long_unchecked_t vdata_alloc;
38416 + atomic_long_unchecked_t vdata_free;
38417 + atomic_long_unchecked_t gts_alloc;
38418 + atomic_long_unchecked_t gts_free;
38419 + atomic_long_unchecked_t gms_alloc;
38420 + atomic_long_unchecked_t gms_free;
38421 + atomic_long_unchecked_t gts_double_allocate;
38422 + atomic_long_unchecked_t assign_context;
38423 + atomic_long_unchecked_t assign_context_failed;
38424 + atomic_long_unchecked_t free_context;
38425 + atomic_long_unchecked_t load_user_context;
38426 + atomic_long_unchecked_t load_kernel_context;
38427 + atomic_long_unchecked_t lock_kernel_context;
38428 + atomic_long_unchecked_t unlock_kernel_context;
38429 + atomic_long_unchecked_t steal_user_context;
38430 + atomic_long_unchecked_t steal_kernel_context;
38431 + atomic_long_unchecked_t steal_context_failed;
38432 + atomic_long_unchecked_t nopfn;
38433 + atomic_long_unchecked_t asid_new;
38434 + atomic_long_unchecked_t asid_next;
38435 + atomic_long_unchecked_t asid_wrap;
38436 + atomic_long_unchecked_t asid_reuse;
38437 + atomic_long_unchecked_t intr;
38438 + atomic_long_unchecked_t intr_cbr;
38439 + atomic_long_unchecked_t intr_tfh;
38440 + atomic_long_unchecked_t intr_spurious;
38441 + atomic_long_unchecked_t intr_mm_lock_failed;
38442 + atomic_long_unchecked_t call_os;
38443 + atomic_long_unchecked_t call_os_wait_queue;
38444 + atomic_long_unchecked_t user_flush_tlb;
38445 + atomic_long_unchecked_t user_unload_context;
38446 + atomic_long_unchecked_t user_exception;
38447 + atomic_long_unchecked_t set_context_option;
38448 + atomic_long_unchecked_t check_context_retarget_intr;
38449 + atomic_long_unchecked_t check_context_unload;
38450 + atomic_long_unchecked_t tlb_dropin;
38451 + atomic_long_unchecked_t tlb_preload_page;
38452 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
38453 + atomic_long_unchecked_t tlb_dropin_fail_upm;
38454 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
38455 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
38456 + atomic_long_unchecked_t tlb_dropin_fail_idle;
38457 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
38458 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
38459 + atomic_long_unchecked_t tfh_stale_on_fault;
38460 + atomic_long_unchecked_t mmu_invalidate_range;
38461 + atomic_long_unchecked_t mmu_invalidate_page;
38462 + atomic_long_unchecked_t flush_tlb;
38463 + atomic_long_unchecked_t flush_tlb_gru;
38464 + atomic_long_unchecked_t flush_tlb_gru_tgh;
38465 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
38466
38467 - atomic_long_t copy_gpa;
38468 - atomic_long_t read_gpa;
38469 + atomic_long_unchecked_t copy_gpa;
38470 + atomic_long_unchecked_t read_gpa;
38471
38472 - atomic_long_t mesq_receive;
38473 - atomic_long_t mesq_receive_none;
38474 - atomic_long_t mesq_send;
38475 - atomic_long_t mesq_send_failed;
38476 - atomic_long_t mesq_noop;
38477 - atomic_long_t mesq_send_unexpected_error;
38478 - atomic_long_t mesq_send_lb_overflow;
38479 - atomic_long_t mesq_send_qlimit_reached;
38480 - atomic_long_t mesq_send_amo_nacked;
38481 - atomic_long_t mesq_send_put_nacked;
38482 - atomic_long_t mesq_page_overflow;
38483 - atomic_long_t mesq_qf_locked;
38484 - atomic_long_t mesq_qf_noop_not_full;
38485 - atomic_long_t mesq_qf_switch_head_failed;
38486 - atomic_long_t mesq_qf_unexpected_error;
38487 - atomic_long_t mesq_noop_unexpected_error;
38488 - atomic_long_t mesq_noop_lb_overflow;
38489 - atomic_long_t mesq_noop_qlimit_reached;
38490 - atomic_long_t mesq_noop_amo_nacked;
38491 - atomic_long_t mesq_noop_put_nacked;
38492 - atomic_long_t mesq_noop_page_overflow;
38493 + atomic_long_unchecked_t mesq_receive;
38494 + atomic_long_unchecked_t mesq_receive_none;
38495 + atomic_long_unchecked_t mesq_send;
38496 + atomic_long_unchecked_t mesq_send_failed;
38497 + atomic_long_unchecked_t mesq_noop;
38498 + atomic_long_unchecked_t mesq_send_unexpected_error;
38499 + atomic_long_unchecked_t mesq_send_lb_overflow;
38500 + atomic_long_unchecked_t mesq_send_qlimit_reached;
38501 + atomic_long_unchecked_t mesq_send_amo_nacked;
38502 + atomic_long_unchecked_t mesq_send_put_nacked;
38503 + atomic_long_unchecked_t mesq_page_overflow;
38504 + atomic_long_unchecked_t mesq_qf_locked;
38505 + atomic_long_unchecked_t mesq_qf_noop_not_full;
38506 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
38507 + atomic_long_unchecked_t mesq_qf_unexpected_error;
38508 + atomic_long_unchecked_t mesq_noop_unexpected_error;
38509 + atomic_long_unchecked_t mesq_noop_lb_overflow;
38510 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
38511 + atomic_long_unchecked_t mesq_noop_amo_nacked;
38512 + atomic_long_unchecked_t mesq_noop_put_nacked;
38513 + atomic_long_unchecked_t mesq_noop_page_overflow;
38514
38515 };
38516
38517 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
38518 tghop_invalidate, mcsop_last};
38519
38520 struct mcs_op_statistic {
38521 - atomic_long_t count;
38522 - atomic_long_t total;
38523 + atomic_long_unchecked_t count;
38524 + atomic_long_unchecked_t total;
38525 unsigned long max;
38526 };
38527
38528 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
38529
38530 #define STAT(id) do { \
38531 if (gru_options & OPT_STATS) \
38532 - atomic_long_inc(&gru_stats.id); \
38533 + atomic_long_inc_unchecked(&gru_stats.id); \
38534 } while (0)
38535
38536 #ifdef CONFIG_SGI_GRU_DEBUG
38537 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
38538 index c862cd4..0d176fe 100644
38539 --- a/drivers/misc/sgi-xp/xp.h
38540 +++ b/drivers/misc/sgi-xp/xp.h
38541 @@ -288,7 +288,7 @@ struct xpc_interface {
38542 xpc_notify_func, void *);
38543 void (*received) (short, int, void *);
38544 enum xp_retval (*partid_to_nasids) (short, void *);
38545 -};
38546 +} __no_const;
38547
38548 extern struct xpc_interface xpc_interface;
38549
38550 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
38551 index b94d5f7..7f494c5 100644
38552 --- a/drivers/misc/sgi-xp/xpc.h
38553 +++ b/drivers/misc/sgi-xp/xpc.h
38554 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
38555 void (*received_payload) (struct xpc_channel *, void *);
38556 void (*notify_senders_of_disconnect) (struct xpc_channel *);
38557 };
38558 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
38559
38560 /* struct xpc_partition act_state values (for XPC HB) */
38561
38562 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
38563 /* found in xpc_main.c */
38564 extern struct device *xpc_part;
38565 extern struct device *xpc_chan;
38566 -extern struct xpc_arch_operations xpc_arch_ops;
38567 +extern xpc_arch_operations_no_const xpc_arch_ops;
38568 extern int xpc_disengage_timelimit;
38569 extern int xpc_disengage_timedout;
38570 extern int xpc_activate_IRQ_rcvd;
38571 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
38572 index d971817..33bdca5 100644
38573 --- a/drivers/misc/sgi-xp/xpc_main.c
38574 +++ b/drivers/misc/sgi-xp/xpc_main.c
38575 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
38576 .notifier_call = xpc_system_die,
38577 };
38578
38579 -struct xpc_arch_operations xpc_arch_ops;
38580 +xpc_arch_operations_no_const xpc_arch_ops;
38581
38582 /*
38583 * Timer function to enforce the timelimit on the partition disengage.
38584 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
38585
38586 if (((die_args->trapnr == X86_TRAP_MF) ||
38587 (die_args->trapnr == X86_TRAP_XF)) &&
38588 - !user_mode_vm(die_args->regs))
38589 + !user_mode(die_args->regs))
38590 xpc_die_deactivate();
38591
38592 break;
38593 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
38594 index 6d8f701..35b6369 100644
38595 --- a/drivers/mmc/core/mmc_ops.c
38596 +++ b/drivers/mmc/core/mmc_ops.c
38597 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
38598 void *data_buf;
38599 int is_on_stack;
38600
38601 - is_on_stack = object_is_on_stack(buf);
38602 + is_on_stack = object_starts_on_stack(buf);
38603 if (is_on_stack) {
38604 /*
38605 * dma onto stack is unsafe/nonportable, but callers to this
38606 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
38607 index 53b8fd9..615b462 100644
38608 --- a/drivers/mmc/host/dw_mmc.h
38609 +++ b/drivers/mmc/host/dw_mmc.h
38610 @@ -205,5 +205,5 @@ struct dw_mci_drv_data {
38611 int (*parse_dt)(struct dw_mci *host);
38612 int (*setup_bus)(struct dw_mci *host,
38613 struct device_node *slot_np, u8 bus_width);
38614 -};
38615 +} __do_const;
38616 #endif /* _DW_MMC_H_ */
38617 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
38618 index 82a8de1..3c56ccb 100644
38619 --- a/drivers/mmc/host/sdhci-s3c.c
38620 +++ b/drivers/mmc/host/sdhci-s3c.c
38621 @@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
38622 * we can use overriding functions instead of default.
38623 */
38624 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
38625 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
38626 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
38627 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
38628 + pax_open_kernel();
38629 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
38630 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
38631 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
38632 + pax_close_kernel();
38633 }
38634
38635 /* It supports additional host capabilities if needed */
38636 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
38637 index a4eb8b5..8c0628f 100644
38638 --- a/drivers/mtd/devices/doc2000.c
38639 +++ b/drivers/mtd/devices/doc2000.c
38640 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
38641
38642 /* The ECC will not be calculated correctly if less than 512 is written */
38643 /* DBB-
38644 - if (len != 0x200 && eccbuf)
38645 + if (len != 0x200)
38646 printk(KERN_WARNING
38647 "ECC needs a full sector write (adr: %lx size %lx)\n",
38648 (long) to, (long) len);
38649 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
38650 index 0c8bb6b..6f35deb 100644
38651 --- a/drivers/mtd/nand/denali.c
38652 +++ b/drivers/mtd/nand/denali.c
38653 @@ -24,6 +24,7 @@
38654 #include <linux/slab.h>
38655 #include <linux/mtd/mtd.h>
38656 #include <linux/module.h>
38657 +#include <linux/slab.h>
38658
38659 #include "denali.h"
38660
38661 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
38662 index 51b9d6a..52af9a7 100644
38663 --- a/drivers/mtd/nftlmount.c
38664 +++ b/drivers/mtd/nftlmount.c
38665 @@ -24,6 +24,7 @@
38666 #include <asm/errno.h>
38667 #include <linux/delay.h>
38668 #include <linux/slab.h>
38669 +#include <linux/sched.h>
38670 #include <linux/mtd/mtd.h>
38671 #include <linux/mtd/nand.h>
38672 #include <linux/mtd/nftl.h>
38673 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
38674 index 8dd6ba5..419cc1d 100644
38675 --- a/drivers/mtd/sm_ftl.c
38676 +++ b/drivers/mtd/sm_ftl.c
38677 @@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
38678 #define SM_CIS_VENDOR_OFFSET 0x59
38679 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
38680 {
38681 - struct attribute_group *attr_group;
38682 + attribute_group_no_const *attr_group;
38683 struct attribute **attributes;
38684 struct sm_sysfs_attribute *vendor_attribute;
38685
38686 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
38687 index b7d45f3..b5c89d9 100644
38688 --- a/drivers/net/bonding/bond_main.c
38689 +++ b/drivers/net/bonding/bond_main.c
38690 @@ -4861,7 +4861,7 @@ static unsigned int bond_get_num_tx_queues(void)
38691 return tx_queues;
38692 }
38693
38694 -static struct rtnl_link_ops bond_link_ops __read_mostly = {
38695 +static struct rtnl_link_ops bond_link_ops = {
38696 .kind = "bond",
38697 .priv_size = sizeof(struct bonding),
38698 .setup = bond_setup,
38699 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
38700 index 70dba5d..11a0919 100644
38701 --- a/drivers/net/ethernet/8390/ax88796.c
38702 +++ b/drivers/net/ethernet/8390/ax88796.c
38703 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
38704 if (ax->plat->reg_offsets)
38705 ei_local->reg_offset = ax->plat->reg_offsets;
38706 else {
38707 + resource_size_t _mem_size = mem_size;
38708 + do_div(_mem_size, 0x18);
38709 ei_local->reg_offset = ax->reg_offsets;
38710 for (ret = 0; ret < 0x18; ret++)
38711 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
38712 + ax->reg_offsets[ret] = _mem_size * ret;
38713 }
38714
38715 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
38716 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
38717 index 0991534..8098e92 100644
38718 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
38719 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
38720 @@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
38721 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
38722 {
38723 /* RX_MODE controlling object */
38724 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
38725 + bnx2x_init_rx_mode_obj(bp);
38726
38727 /* multicast configuration controlling object */
38728 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
38729 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
38730 index 09b625e..15b16fe 100644
38731 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
38732 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
38733 @@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
38734 return rc;
38735 }
38736
38737 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
38738 - struct bnx2x_rx_mode_obj *o)
38739 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
38740 {
38741 if (CHIP_IS_E1x(bp)) {
38742 - o->wait_comp = bnx2x_empty_rx_mode_wait;
38743 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
38744 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
38745 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
38746 } else {
38747 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
38748 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
38749 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
38750 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
38751 }
38752 }
38753
38754 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
38755 index adbd91b..58ec94a 100644
38756 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
38757 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
38758 @@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
38759
38760 /********************* RX MODE ****************/
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 /**
38767 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
38768 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
38769 index d330e81..ce1fb9a 100644
38770 --- a/drivers/net/ethernet/broadcom/tg3.h
38771 +++ b/drivers/net/ethernet/broadcom/tg3.h
38772 @@ -146,6 +146,7 @@
38773 #define CHIPREV_ID_5750_A0 0x4000
38774 #define CHIPREV_ID_5750_A1 0x4001
38775 #define CHIPREV_ID_5750_A3 0x4003
38776 +#define CHIPREV_ID_5750_C1 0x4201
38777 #define CHIPREV_ID_5750_C2 0x4202
38778 #define CHIPREV_ID_5752_A0_HW 0x5000
38779 #define CHIPREV_ID_5752_A0 0x6000
38780 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
38781 index 8cffcdf..aadf043 100644
38782 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
38783 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
38784 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
38785 */
38786 struct l2t_skb_cb {
38787 arp_failure_handler_func arp_failure_handler;
38788 -};
38789 +} __no_const;
38790
38791 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
38792
38793 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
38794 index 4c83003..2a2a5b9 100644
38795 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
38796 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
38797 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38798 for (i=0; i<ETH_ALEN; i++) {
38799 tmp.addr[i] = dev->dev_addr[i];
38800 }
38801 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38802 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38803 break;
38804
38805 case DE4X5_SET_HWADDR: /* Set the hardware address */
38806 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38807 spin_lock_irqsave(&lp->lock, flags);
38808 memcpy(&statbuf, &lp->pktStats, ioc->len);
38809 spin_unlock_irqrestore(&lp->lock, flags);
38810 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
38811 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
38812 return -EFAULT;
38813 break;
38814 }
38815 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
38816 index 4d6f3c5..6169e60 100644
38817 --- a/drivers/net/ethernet/emulex/benet/be_main.c
38818 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
38819 @@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
38820
38821 if (wrapped)
38822 newacc += 65536;
38823 - ACCESS_ONCE(*acc) = newacc;
38824 + ACCESS_ONCE_RW(*acc) = newacc;
38825 }
38826
38827 void be_parse_stats(struct be_adapter *adapter)
38828 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
38829 index 74d749e..eefb1bd 100644
38830 --- a/drivers/net/ethernet/faraday/ftgmac100.c
38831 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
38832 @@ -31,6 +31,8 @@
38833 #include <linux/netdevice.h>
38834 #include <linux/phy.h>
38835 #include <linux/platform_device.h>
38836 +#include <linux/interrupt.h>
38837 +#include <linux/irqreturn.h>
38838 #include <net/ip.h>
38839
38840 #include "ftgmac100.h"
38841 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
38842 index b901a01..1ff32ee 100644
38843 --- a/drivers/net/ethernet/faraday/ftmac100.c
38844 +++ b/drivers/net/ethernet/faraday/ftmac100.c
38845 @@ -31,6 +31,8 @@
38846 #include <linux/module.h>
38847 #include <linux/netdevice.h>
38848 #include <linux/platform_device.h>
38849 +#include <linux/interrupt.h>
38850 +#include <linux/irqreturn.h>
38851
38852 #include "ftmac100.h"
38853
38854 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
38855 index bb9256a..56d8752 100644
38856 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
38857 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
38858 @@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
38859 }
38860
38861 /* update the base incval used to calculate frequency adjustment */
38862 - ACCESS_ONCE(adapter->base_incval) = incval;
38863 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
38864 smp_mb();
38865
38866 /* need lock to prevent incorrect read while modifying cyclecounter */
38867 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
38868 index fbe5363..266b4e3 100644
38869 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
38870 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
38871 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
38872 struct __vxge_hw_fifo *fifo;
38873 struct vxge_hw_fifo_config *config;
38874 u32 txdl_size, txdl_per_memblock;
38875 - struct vxge_hw_mempool_cbs fifo_mp_callback;
38876 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
38877 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
38878 + };
38879 +
38880 struct __vxge_hw_virtualpath *vpath;
38881
38882 if ((vp == NULL) || (attr == NULL)) {
38883 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
38884 goto exit;
38885 }
38886
38887 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
38888 -
38889 fifo->mempool =
38890 __vxge_hw_mempool_create(vpath->hldev,
38891 fifo->config->memblock_size,
38892 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
38893 index 998974f..ecd26db 100644
38894 --- a/drivers/net/ethernet/realtek/r8169.c
38895 +++ b/drivers/net/ethernet/realtek/r8169.c
38896 @@ -741,22 +741,22 @@ struct rtl8169_private {
38897 struct mdio_ops {
38898 void (*write)(struct rtl8169_private *, int, int);
38899 int (*read)(struct rtl8169_private *, int);
38900 - } mdio_ops;
38901 + } __no_const mdio_ops;
38902
38903 struct pll_power_ops {
38904 void (*down)(struct rtl8169_private *);
38905 void (*up)(struct rtl8169_private *);
38906 - } pll_power_ops;
38907 + } __no_const pll_power_ops;
38908
38909 struct jumbo_ops {
38910 void (*enable)(struct rtl8169_private *);
38911 void (*disable)(struct rtl8169_private *);
38912 - } jumbo_ops;
38913 + } __no_const jumbo_ops;
38914
38915 struct csi_ops {
38916 void (*write)(struct rtl8169_private *, int, int);
38917 u32 (*read)(struct rtl8169_private *, int);
38918 - } csi_ops;
38919 + } __no_const csi_ops;
38920
38921 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
38922 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
38923 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
38924 index 0767043f..08c2553 100644
38925 --- a/drivers/net/ethernet/sfc/ptp.c
38926 +++ b/drivers/net/ethernet/sfc/ptp.c
38927 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
38928 (u32)((u64)ptp->start.dma_addr >> 32));
38929
38930 /* Clear flag that signals MC ready */
38931 - ACCESS_ONCE(*start) = 0;
38932 + ACCESS_ONCE_RW(*start) = 0;
38933 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
38934 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
38935
38936 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
38937 index 0c74a70..3bc6f68 100644
38938 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
38939 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
38940 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
38941
38942 writel(value, ioaddr + MMC_CNTRL);
38943
38944 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
38945 - MMC_CNTRL, value);
38946 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
38947 +// MMC_CNTRL, value);
38948 }
38949
38950 /* To mask all all interrupts.*/
38951 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
38952 index e6fe0d8..2b7d752 100644
38953 --- a/drivers/net/hyperv/hyperv_net.h
38954 +++ b/drivers/net/hyperv/hyperv_net.h
38955 @@ -101,7 +101,7 @@ struct rndis_device {
38956
38957 enum rndis_device_state state;
38958 bool link_state;
38959 - atomic_t new_req_id;
38960 + atomic_unchecked_t new_req_id;
38961
38962 spinlock_t request_lock;
38963 struct list_head req_list;
38964 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
38965 index 2b657d4..9903bc0 100644
38966 --- a/drivers/net/hyperv/rndis_filter.c
38967 +++ b/drivers/net/hyperv/rndis_filter.c
38968 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
38969 * template
38970 */
38971 set = &rndis_msg->msg.set_req;
38972 - set->req_id = atomic_inc_return(&dev->new_req_id);
38973 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
38974
38975 /* Add to the request list */
38976 spin_lock_irqsave(&dev->request_lock, flags);
38977 @@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
38978
38979 /* Setup the rndis set */
38980 halt = &request->request_msg.msg.halt_req;
38981 - halt->req_id = atomic_inc_return(&dev->new_req_id);
38982 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
38983
38984 /* Ignore return since this msg is optional. */
38985 rndis_filter_send_request(dev, request);
38986 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
38987 index 1e9cb0b..7839125 100644
38988 --- a/drivers/net/ieee802154/fakehard.c
38989 +++ b/drivers/net/ieee802154/fakehard.c
38990 @@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
38991 phy->transmit_power = 0xbf;
38992
38993 dev->netdev_ops = &fake_ops;
38994 - dev->ml_priv = &fake_mlme;
38995 + dev->ml_priv = (void *)&fake_mlme;
38996
38997 priv = netdev_priv(dev);
38998 priv->phy = phy;
38999 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
39000 index d3fb97d..19520c7 100644
39001 --- a/drivers/net/macvlan.c
39002 +++ b/drivers/net/macvlan.c
39003 @@ -851,13 +851,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
39004 int macvlan_link_register(struct rtnl_link_ops *ops)
39005 {
39006 /* common fields */
39007 - ops->priv_size = sizeof(struct macvlan_dev);
39008 - ops->validate = macvlan_validate;
39009 - ops->maxtype = IFLA_MACVLAN_MAX;
39010 - ops->policy = macvlan_policy;
39011 - ops->changelink = macvlan_changelink;
39012 - ops->get_size = macvlan_get_size;
39013 - ops->fill_info = macvlan_fill_info;
39014 + pax_open_kernel();
39015 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
39016 + *(void **)&ops->validate = macvlan_validate;
39017 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
39018 + *(const void **)&ops->policy = macvlan_policy;
39019 + *(void **)&ops->changelink = macvlan_changelink;
39020 + *(void **)&ops->get_size = macvlan_get_size;
39021 + *(void **)&ops->fill_info = macvlan_fill_info;
39022 + pax_close_kernel();
39023
39024 return rtnl_link_register(ops);
39025 };
39026 @@ -913,7 +915,7 @@ static int macvlan_device_event(struct notifier_block *unused,
39027 return NOTIFY_DONE;
39028 }
39029
39030 -static struct notifier_block macvlan_notifier_block __read_mostly = {
39031 +static struct notifier_block macvlan_notifier_block = {
39032 .notifier_call = macvlan_device_event,
39033 };
39034
39035 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
39036 index 0f0f9ce..0ca5819 100644
39037 --- a/drivers/net/macvtap.c
39038 +++ b/drivers/net/macvtap.c
39039 @@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
39040 return NOTIFY_DONE;
39041 }
39042
39043 -static struct notifier_block macvtap_notifier_block __read_mostly = {
39044 +static struct notifier_block macvtap_notifier_block = {
39045 .notifier_call = macvtap_device_event,
39046 };
39047
39048 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
39049 index daec9b0..6428fcb 100644
39050 --- a/drivers/net/phy/mdio-bitbang.c
39051 +++ b/drivers/net/phy/mdio-bitbang.c
39052 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
39053 struct mdiobb_ctrl *ctrl = bus->priv;
39054
39055 module_put(ctrl->ops->owner);
39056 + mdiobus_unregister(bus);
39057 mdiobus_free(bus);
39058 }
39059 EXPORT_SYMBOL(free_mdio_bitbang);
39060 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
39061 index 508570e..f706dc7 100644
39062 --- a/drivers/net/ppp/ppp_generic.c
39063 +++ b/drivers/net/ppp/ppp_generic.c
39064 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39065 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
39066 struct ppp_stats stats;
39067 struct ppp_comp_stats cstats;
39068 - char *vers;
39069
39070 switch (cmd) {
39071 case SIOCGPPPSTATS:
39072 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39073 break;
39074
39075 case SIOCGPPPVER:
39076 - vers = PPP_VERSION;
39077 - if (copy_to_user(addr, vers, strlen(vers) + 1))
39078 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
39079 break;
39080 err = 0;
39081 break;
39082 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
39083 index ad86660..9fd0884 100644
39084 --- a/drivers/net/team/team.c
39085 +++ b/drivers/net/team/team.c
39086 @@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
39087 return NOTIFY_DONE;
39088 }
39089
39090 -static struct notifier_block team_notifier_block __read_mostly = {
39091 +static struct notifier_block team_notifier_block = {
39092 .notifier_call = team_device_event,
39093 };
39094
39095 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
39096 index 2917a86..edd463f 100644
39097 --- a/drivers/net/tun.c
39098 +++ b/drivers/net/tun.c
39099 @@ -1836,7 +1836,7 @@ unlock:
39100 }
39101
39102 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39103 - unsigned long arg, int ifreq_len)
39104 + unsigned long arg, size_t ifreq_len)
39105 {
39106 struct tun_file *tfile = file->private_data;
39107 struct tun_struct *tun;
39108 @@ -1848,6 +1848,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39109 int vnet_hdr_sz;
39110 int ret;
39111
39112 + if (ifreq_len > sizeof ifr)
39113 + return -EFAULT;
39114 +
39115 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
39116 if (copy_from_user(&ifr, argp, ifreq_len))
39117 return -EFAULT;
39118 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39119 index cd8ccb2..cff5144 100644
39120 --- a/drivers/net/usb/hso.c
39121 +++ b/drivers/net/usb/hso.c
39122 @@ -71,7 +71,7 @@
39123 #include <asm/byteorder.h>
39124 #include <linux/serial_core.h>
39125 #include <linux/serial.h>
39126 -
39127 +#include <asm/local.h>
39128
39129 #define MOD_AUTHOR "Option Wireless"
39130 #define MOD_DESCRIPTION "USB High Speed Option driver"
39131 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39132 struct urb *urb;
39133
39134 urb = serial->rx_urb[0];
39135 - if (serial->port.count > 0) {
39136 + if (atomic_read(&serial->port.count) > 0) {
39137 count = put_rxbuf_data(urb, serial);
39138 if (count == -1)
39139 return;
39140 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39141 DUMP1(urb->transfer_buffer, urb->actual_length);
39142
39143 /* Anyone listening? */
39144 - if (serial->port.count == 0)
39145 + if (atomic_read(&serial->port.count) == 0)
39146 return;
39147
39148 if (status == 0) {
39149 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39150 tty_port_tty_set(&serial->port, tty);
39151
39152 /* check for port already opened, if not set the termios */
39153 - serial->port.count++;
39154 - if (serial->port.count == 1) {
39155 + if (atomic_inc_return(&serial->port.count) == 1) {
39156 serial->rx_state = RX_IDLE;
39157 /* Force default termio settings */
39158 _hso_serial_set_termios(tty, NULL);
39159 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39160 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39161 if (result) {
39162 hso_stop_serial_device(serial->parent);
39163 - serial->port.count--;
39164 + atomic_dec(&serial->port.count);
39165 kref_put(&serial->parent->ref, hso_serial_ref_free);
39166 }
39167 } else {
39168 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39169
39170 /* reset the rts and dtr */
39171 /* do the actual close */
39172 - serial->port.count--;
39173 + atomic_dec(&serial->port.count);
39174
39175 - if (serial->port.count <= 0) {
39176 - serial->port.count = 0;
39177 + if (atomic_read(&serial->port.count) <= 0) {
39178 + atomic_set(&serial->port.count, 0);
39179 tty_port_tty_set(&serial->port, NULL);
39180 if (!usb_gone)
39181 hso_stop_serial_device(serial->parent);
39182 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39183
39184 /* the actual setup */
39185 spin_lock_irqsave(&serial->serial_lock, flags);
39186 - if (serial->port.count)
39187 + if (atomic_read(&serial->port.count))
39188 _hso_serial_set_termios(tty, old);
39189 else
39190 tty->termios = *old;
39191 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
39192 D1("Pending read interrupt on port %d\n", i);
39193 spin_lock(&serial->serial_lock);
39194 if (serial->rx_state == RX_IDLE &&
39195 - serial->port.count > 0) {
39196 + atomic_read(&serial->port.count) > 0) {
39197 /* Setup and send a ctrl req read on
39198 * port i */
39199 if (!serial->rx_urb_filled[0]) {
39200 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
39201 /* Start all serial ports */
39202 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39203 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39204 - if (dev2ser(serial_table[i])->port.count) {
39205 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
39206 result =
39207 hso_start_serial_device(serial_table[i], GFP_NOIO);
39208 hso_kick_transmit(dev2ser(serial_table[i]));
39209 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
39210 index 656230e..15525a8 100644
39211 --- a/drivers/net/vxlan.c
39212 +++ b/drivers/net/vxlan.c
39213 @@ -1428,7 +1428,7 @@ nla_put_failure:
39214 return -EMSGSIZE;
39215 }
39216
39217 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
39218 +static struct rtnl_link_ops vxlan_link_ops = {
39219 .kind = "vxlan",
39220 .maxtype = IFLA_VXLAN_MAX,
39221 .policy = vxlan_policy,
39222 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39223 index 8d78253..bebbb68 100644
39224 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39225 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39226 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39227 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
39228 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
39229
39230 - ACCESS_ONCE(ads->ds_link) = i->link;
39231 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
39232 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
39233 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
39234
39235 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
39236 ctl6 = SM(i->keytype, AR_EncrType);
39237 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39238
39239 if ((i->is_first || i->is_last) &&
39240 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
39241 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
39242 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
39243 | set11nTries(i->rates, 1)
39244 | set11nTries(i->rates, 2)
39245 | set11nTries(i->rates, 3)
39246 | (i->dur_update ? AR_DurUpdateEna : 0)
39247 | SM(0, AR_BurstDur);
39248
39249 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
39250 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
39251 | set11nRate(i->rates, 1)
39252 | set11nRate(i->rates, 2)
39253 | set11nRate(i->rates, 3);
39254 } else {
39255 - ACCESS_ONCE(ads->ds_ctl2) = 0;
39256 - ACCESS_ONCE(ads->ds_ctl3) = 0;
39257 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
39258 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
39259 }
39260
39261 if (!i->is_first) {
39262 - ACCESS_ONCE(ads->ds_ctl0) = 0;
39263 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39264 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39265 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
39266 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39267 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39268 return;
39269 }
39270
39271 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39272 break;
39273 }
39274
39275 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39276 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39277 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39278 | SM(i->txpower, AR_XmitPower)
39279 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39280 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39281 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
39282 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
39283
39284 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39285 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39286 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39287 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39288
39289 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
39290 return;
39291
39292 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39293 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39294 | set11nPktDurRTSCTS(i->rates, 1);
39295
39296 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39297 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39298 | set11nPktDurRTSCTS(i->rates, 3);
39299
39300 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39301 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39302 | set11nRateFlags(i->rates, 1)
39303 | set11nRateFlags(i->rates, 2)
39304 | set11nRateFlags(i->rates, 3)
39305 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39306 index 301bf72..3f5654f 100644
39307 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39308 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39309 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39310 (i->qcu << AR_TxQcuNum_S) | desc_len;
39311
39312 checksum += val;
39313 - ACCESS_ONCE(ads->info) = val;
39314 + ACCESS_ONCE_RW(ads->info) = val;
39315
39316 checksum += i->link;
39317 - ACCESS_ONCE(ads->link) = i->link;
39318 + ACCESS_ONCE_RW(ads->link) = i->link;
39319
39320 checksum += i->buf_addr[0];
39321 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
39322 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
39323 checksum += i->buf_addr[1];
39324 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
39325 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
39326 checksum += i->buf_addr[2];
39327 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
39328 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
39329 checksum += i->buf_addr[3];
39330 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
39331 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
39332
39333 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
39334 - ACCESS_ONCE(ads->ctl3) = val;
39335 + ACCESS_ONCE_RW(ads->ctl3) = val;
39336 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
39337 - ACCESS_ONCE(ads->ctl5) = val;
39338 + ACCESS_ONCE_RW(ads->ctl5) = val;
39339 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
39340 - ACCESS_ONCE(ads->ctl7) = val;
39341 + ACCESS_ONCE_RW(ads->ctl7) = val;
39342 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
39343 - ACCESS_ONCE(ads->ctl9) = val;
39344 + ACCESS_ONCE_RW(ads->ctl9) = val;
39345
39346 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
39347 - ACCESS_ONCE(ads->ctl10) = checksum;
39348 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
39349
39350 if (i->is_first || i->is_last) {
39351 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
39352 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
39353 | set11nTries(i->rates, 1)
39354 | set11nTries(i->rates, 2)
39355 | set11nTries(i->rates, 3)
39356 | (i->dur_update ? AR_DurUpdateEna : 0)
39357 | SM(0, AR_BurstDur);
39358
39359 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
39360 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
39361 | set11nRate(i->rates, 1)
39362 | set11nRate(i->rates, 2)
39363 | set11nRate(i->rates, 3);
39364 } else {
39365 - ACCESS_ONCE(ads->ctl13) = 0;
39366 - ACCESS_ONCE(ads->ctl14) = 0;
39367 + ACCESS_ONCE_RW(ads->ctl13) = 0;
39368 + ACCESS_ONCE_RW(ads->ctl14) = 0;
39369 }
39370
39371 ads->ctl20 = 0;
39372 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39373
39374 ctl17 = SM(i->keytype, AR_EncrType);
39375 if (!i->is_first) {
39376 - ACCESS_ONCE(ads->ctl11) = 0;
39377 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39378 - ACCESS_ONCE(ads->ctl15) = 0;
39379 - ACCESS_ONCE(ads->ctl16) = 0;
39380 - ACCESS_ONCE(ads->ctl17) = ctl17;
39381 - ACCESS_ONCE(ads->ctl18) = 0;
39382 - ACCESS_ONCE(ads->ctl19) = 0;
39383 + ACCESS_ONCE_RW(ads->ctl11) = 0;
39384 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39385 + ACCESS_ONCE_RW(ads->ctl15) = 0;
39386 + ACCESS_ONCE_RW(ads->ctl16) = 0;
39387 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39388 + ACCESS_ONCE_RW(ads->ctl18) = 0;
39389 + ACCESS_ONCE_RW(ads->ctl19) = 0;
39390 return;
39391 }
39392
39393 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39394 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39395 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39396 | SM(i->txpower, AR_XmitPower)
39397 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39398 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39399 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
39400 ctl12 |= SM(val, AR_PAPRDChainMask);
39401
39402 - ACCESS_ONCE(ads->ctl12) = ctl12;
39403 - ACCESS_ONCE(ads->ctl17) = ctl17;
39404 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
39405 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39406
39407 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39408 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39409 | set11nPktDurRTSCTS(i->rates, 1);
39410
39411 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39412 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39413 | set11nPktDurRTSCTS(i->rates, 3);
39414
39415 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
39416 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
39417 | set11nRateFlags(i->rates, 1)
39418 | set11nRateFlags(i->rates, 2)
39419 | set11nRateFlags(i->rates, 3)
39420 | SM(i->rtscts_rate, AR_RTSCTSRate);
39421
39422 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
39423 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
39424 }
39425
39426 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
39427 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
39428 index 9d26fc5..60d9f14 100644
39429 --- a/drivers/net/wireless/ath/ath9k/hw.h
39430 +++ b/drivers/net/wireless/ath/ath9k/hw.h
39431 @@ -658,7 +658,7 @@ struct ath_hw_private_ops {
39432
39433 /* ANI */
39434 void (*ani_cache_ini_regs)(struct ath_hw *ah);
39435 -};
39436 +} __no_const;
39437
39438 /**
39439 * struct ath_hw_ops - callbacks used by hardware code and driver code
39440 @@ -688,7 +688,7 @@ struct ath_hw_ops {
39441 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
39442 struct ath_hw_antcomb_conf *antconf);
39443 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
39444 -};
39445 +} __no_const;
39446
39447 struct ath_nf_limits {
39448 s16 max;
39449 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
39450 index 3726cd6..b655808 100644
39451 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
39452 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
39453 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39454 */
39455 if (il3945_mod_params.disable_hw_scan) {
39456 D_INFO("Disabling hw_scan\n");
39457 - il3945_mac_ops.hw_scan = NULL;
39458 + pax_open_kernel();
39459 + *(void **)&il3945_mac_ops.hw_scan = NULL;
39460 + pax_close_kernel();
39461 }
39462
39463 D_INFO("*** LOAD DRIVER ***\n");
39464 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39465 index 5b9533e..7733880 100644
39466 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39467 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39468 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
39469 {
39470 struct iwl_priv *priv = file->private_data;
39471 char buf[64];
39472 - int buf_size;
39473 + size_t buf_size;
39474 u32 offset, len;
39475
39476 memset(buf, 0, sizeof(buf));
39477 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
39478 struct iwl_priv *priv = file->private_data;
39479
39480 char buf[8];
39481 - int buf_size;
39482 + size_t buf_size;
39483 u32 reset_flag;
39484
39485 memset(buf, 0, sizeof(buf));
39486 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
39487 {
39488 struct iwl_priv *priv = file->private_data;
39489 char buf[8];
39490 - int buf_size;
39491 + size_t buf_size;
39492 int ht40;
39493
39494 memset(buf, 0, sizeof(buf));
39495 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
39496 {
39497 struct iwl_priv *priv = file->private_data;
39498 char buf[8];
39499 - int buf_size;
39500 + size_t buf_size;
39501 int value;
39502
39503 memset(buf, 0, sizeof(buf));
39504 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
39505 {
39506 struct iwl_priv *priv = file->private_data;
39507 char buf[8];
39508 - int buf_size;
39509 + size_t buf_size;
39510 int clear;
39511
39512 memset(buf, 0, sizeof(buf));
39513 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
39514 {
39515 struct iwl_priv *priv = file->private_data;
39516 char buf[8];
39517 - int buf_size;
39518 + size_t buf_size;
39519 int trace;
39520
39521 memset(buf, 0, sizeof(buf));
39522 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
39523 {
39524 struct iwl_priv *priv = file->private_data;
39525 char buf[8];
39526 - int buf_size;
39527 + size_t buf_size;
39528 int missed;
39529
39530 memset(buf, 0, sizeof(buf));
39531 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
39532
39533 struct iwl_priv *priv = file->private_data;
39534 char buf[8];
39535 - int buf_size;
39536 + size_t buf_size;
39537 int plcp;
39538
39539 memset(buf, 0, sizeof(buf));
39540 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
39541
39542 struct iwl_priv *priv = file->private_data;
39543 char buf[8];
39544 - int buf_size;
39545 + size_t buf_size;
39546 int flush;
39547
39548 memset(buf, 0, sizeof(buf));
39549 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
39550
39551 struct iwl_priv *priv = file->private_data;
39552 char buf[8];
39553 - int buf_size;
39554 + size_t buf_size;
39555 int rts;
39556
39557 if (!priv->cfg->ht_params)
39558 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
39559 {
39560 struct iwl_priv *priv = file->private_data;
39561 char buf[8];
39562 - int buf_size;
39563 + size_t buf_size;
39564
39565 memset(buf, 0, sizeof(buf));
39566 buf_size = min(count, sizeof(buf) - 1);
39567 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
39568 struct iwl_priv *priv = file->private_data;
39569 u32 event_log_flag;
39570 char buf[8];
39571 - int buf_size;
39572 + size_t buf_size;
39573
39574 /* check that the interface is up */
39575 if (!iwl_is_ready(priv))
39576 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
39577 struct iwl_priv *priv = file->private_data;
39578 char buf[8];
39579 u32 calib_disabled;
39580 - int buf_size;
39581 + size_t buf_size;
39582
39583 memset(buf, 0, sizeof(buf));
39584 buf_size = min(count, sizeof(buf) - 1);
39585 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
39586 index 35708b9..31f7754 100644
39587 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
39588 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
39589 @@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
39590 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
39591
39592 char buf[8];
39593 - int buf_size;
39594 + size_t buf_size;
39595 u32 reset_flag;
39596
39597 memset(buf, 0, sizeof(buf));
39598 @@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
39599 {
39600 struct iwl_trans *trans = file->private_data;
39601 char buf[8];
39602 - int buf_size;
39603 + size_t buf_size;
39604 int csr;
39605
39606 memset(buf, 0, sizeof(buf));
39607 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
39608 index ff90855..e46d223 100644
39609 --- a/drivers/net/wireless/mac80211_hwsim.c
39610 +++ b/drivers/net/wireless/mac80211_hwsim.c
39611 @@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
39612
39613 if (channels > 1) {
39614 hwsim_if_comb.num_different_channels = channels;
39615 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
39616 - mac80211_hwsim_ops.cancel_hw_scan =
39617 - mac80211_hwsim_cancel_hw_scan;
39618 - mac80211_hwsim_ops.sw_scan_start = NULL;
39619 - mac80211_hwsim_ops.sw_scan_complete = NULL;
39620 - mac80211_hwsim_ops.remain_on_channel =
39621 - mac80211_hwsim_roc;
39622 - mac80211_hwsim_ops.cancel_remain_on_channel =
39623 - mac80211_hwsim_croc;
39624 - mac80211_hwsim_ops.add_chanctx =
39625 - mac80211_hwsim_add_chanctx;
39626 - mac80211_hwsim_ops.remove_chanctx =
39627 - mac80211_hwsim_remove_chanctx;
39628 - mac80211_hwsim_ops.change_chanctx =
39629 - mac80211_hwsim_change_chanctx;
39630 - mac80211_hwsim_ops.assign_vif_chanctx =
39631 - mac80211_hwsim_assign_vif_chanctx;
39632 - mac80211_hwsim_ops.unassign_vif_chanctx =
39633 - mac80211_hwsim_unassign_vif_chanctx;
39634 + pax_open_kernel();
39635 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
39636 + *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
39637 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
39638 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
39639 + *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
39640 + *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
39641 + *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
39642 + *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
39643 + *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
39644 + *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
39645 + *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
39646 + pax_close_kernel();
39647 }
39648
39649 spin_lock_init(&hwsim_radio_lock);
39650 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
39651 index abe1d03..fb02c22 100644
39652 --- a/drivers/net/wireless/rndis_wlan.c
39653 +++ b/drivers/net/wireless/rndis_wlan.c
39654 @@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
39655
39656 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
39657
39658 - if (rts_threshold < 0 || rts_threshold > 2347)
39659 + if (rts_threshold > 2347)
39660 rts_threshold = 2347;
39661
39662 tmp = cpu_to_le32(rts_threshold);
39663 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
39664 index 0751b35..246ba3e 100644
39665 --- a/drivers/net/wireless/rt2x00/rt2x00.h
39666 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
39667 @@ -398,7 +398,7 @@ struct rt2x00_intf {
39668 * for hardware which doesn't support hardware
39669 * sequence counting.
39670 */
39671 - atomic_t seqno;
39672 + atomic_unchecked_t seqno;
39673 };
39674
39675 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
39676 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
39677 index e488b94..14b6a0c 100644
39678 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
39679 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
39680 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
39681 * sequence counter given by mac80211.
39682 */
39683 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
39684 - seqno = atomic_add_return(0x10, &intf->seqno);
39685 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
39686 else
39687 - seqno = atomic_read(&intf->seqno);
39688 + seqno = atomic_read_unchecked(&intf->seqno);
39689
39690 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
39691 hdr->seq_ctrl |= cpu_to_le16(seqno);
39692 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
39693 index e57ee48..541cf6c 100644
39694 --- a/drivers/net/wireless/ti/wl1251/sdio.c
39695 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
39696 @@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
39697
39698 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
39699
39700 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
39701 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
39702 + pax_open_kernel();
39703 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
39704 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
39705 + pax_close_kernel();
39706
39707 wl1251_info("using dedicated interrupt line");
39708 } else {
39709 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
39710 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
39711 + pax_open_kernel();
39712 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
39713 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
39714 + pax_close_kernel();
39715
39716 wl1251_info("using SDIO interrupt");
39717 }
39718 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
39719 index e5f5f8f..fdf15b7 100644
39720 --- a/drivers/net/wireless/ti/wl12xx/main.c
39721 +++ b/drivers/net/wireless/ti/wl12xx/main.c
39722 @@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
39723 sizeof(wl->conf.mem));
39724
39725 /* read data preparation is only needed by wl127x */
39726 - wl->ops->prepare_read = wl127x_prepare_read;
39727 + pax_open_kernel();
39728 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
39729 + pax_close_kernel();
39730
39731 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
39732 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
39733 @@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
39734 sizeof(wl->conf.mem));
39735
39736 /* read data preparation is only needed by wl127x */
39737 - wl->ops->prepare_read = wl127x_prepare_read;
39738 + pax_open_kernel();
39739 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
39740 + pax_close_kernel();
39741
39742 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
39743 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
39744 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
39745 index 8d8c1f8..e754844 100644
39746 --- a/drivers/net/wireless/ti/wl18xx/main.c
39747 +++ b/drivers/net/wireless/ti/wl18xx/main.c
39748 @@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
39749 }
39750
39751 if (!checksum_param) {
39752 - wl18xx_ops.set_rx_csum = NULL;
39753 - wl18xx_ops.init_vif = NULL;
39754 + pax_open_kernel();
39755 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
39756 + *(void **)&wl18xx_ops.init_vif = NULL;
39757 + pax_close_kernel();
39758 }
39759
39760 /* Enable 11a Band only if we have 5G antennas */
39761 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
39762 index d93b2b6..ae50401 100644
39763 --- a/drivers/oprofile/buffer_sync.c
39764 +++ b/drivers/oprofile/buffer_sync.c
39765 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
39766 if (cookie == NO_COOKIE)
39767 offset = pc;
39768 if (cookie == INVALID_COOKIE) {
39769 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39770 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39771 offset = pc;
39772 }
39773 if (cookie != last_cookie) {
39774 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
39775 /* add userspace sample */
39776
39777 if (!mm) {
39778 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
39779 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
39780 return 0;
39781 }
39782
39783 cookie = lookup_dcookie(mm, s->eip, &offset);
39784
39785 if (cookie == INVALID_COOKIE) {
39786 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39787 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39788 return 0;
39789 }
39790
39791 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
39792 /* ignore backtraces if failed to add a sample */
39793 if (state == sb_bt_start) {
39794 state = sb_bt_ignore;
39795 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
39796 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
39797 }
39798 }
39799 release_mm(mm);
39800 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
39801 index c0cc4e7..44d4e54 100644
39802 --- a/drivers/oprofile/event_buffer.c
39803 +++ b/drivers/oprofile/event_buffer.c
39804 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
39805 }
39806
39807 if (buffer_pos == buffer_size) {
39808 - atomic_inc(&oprofile_stats.event_lost_overflow);
39809 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
39810 return;
39811 }
39812
39813 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
39814 index ed2c3ec..deda85a 100644
39815 --- a/drivers/oprofile/oprof.c
39816 +++ b/drivers/oprofile/oprof.c
39817 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
39818 if (oprofile_ops.switch_events())
39819 return;
39820
39821 - atomic_inc(&oprofile_stats.multiplex_counter);
39822 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
39823 start_switch_worker();
39824 }
39825
39826 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
39827 index 917d28e..d62d981 100644
39828 --- a/drivers/oprofile/oprofile_stats.c
39829 +++ b/drivers/oprofile/oprofile_stats.c
39830 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
39831 cpu_buf->sample_invalid_eip = 0;
39832 }
39833
39834 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
39835 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
39836 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
39837 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
39838 - atomic_set(&oprofile_stats.multiplex_counter, 0);
39839 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
39840 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
39841 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
39842 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
39843 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
39844 }
39845
39846
39847 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
39848 index 38b6fc0..b5cbfce 100644
39849 --- a/drivers/oprofile/oprofile_stats.h
39850 +++ b/drivers/oprofile/oprofile_stats.h
39851 @@ -13,11 +13,11 @@
39852 #include <linux/atomic.h>
39853
39854 struct oprofile_stat_struct {
39855 - atomic_t sample_lost_no_mm;
39856 - atomic_t sample_lost_no_mapping;
39857 - atomic_t bt_lost_no_mapping;
39858 - atomic_t event_lost_overflow;
39859 - atomic_t multiplex_counter;
39860 + atomic_unchecked_t sample_lost_no_mm;
39861 + atomic_unchecked_t sample_lost_no_mapping;
39862 + atomic_unchecked_t bt_lost_no_mapping;
39863 + atomic_unchecked_t event_lost_overflow;
39864 + atomic_unchecked_t multiplex_counter;
39865 };
39866
39867 extern struct oprofile_stat_struct oprofile_stats;
39868 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
39869 index 849357c..b83c1e0 100644
39870 --- a/drivers/oprofile/oprofilefs.c
39871 +++ b/drivers/oprofile/oprofilefs.c
39872 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
39873
39874
39875 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
39876 - char const *name, atomic_t *val)
39877 + char const *name, atomic_unchecked_t *val)
39878 {
39879 return __oprofilefs_create_file(sb, root, name,
39880 &atomic_ro_fops, 0444, val);
39881 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
39882 index 93404f7..4a313d8 100644
39883 --- a/drivers/oprofile/timer_int.c
39884 +++ b/drivers/oprofile/timer_int.c
39885 @@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
39886 return NOTIFY_OK;
39887 }
39888
39889 -static struct notifier_block __refdata oprofile_cpu_notifier = {
39890 +static struct notifier_block oprofile_cpu_notifier = {
39891 .notifier_call = oprofile_cpu_notify,
39892 };
39893
39894 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
39895 index 3f56bc0..707d642 100644
39896 --- a/drivers/parport/procfs.c
39897 +++ b/drivers/parport/procfs.c
39898 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
39899
39900 *ppos += len;
39901
39902 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
39903 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
39904 }
39905
39906 #ifdef CONFIG_PARPORT_1284
39907 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
39908
39909 *ppos += len;
39910
39911 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
39912 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
39913 }
39914 #endif /* IEEE1284.3 support. */
39915
39916 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
39917 index c35e8ad..fc33beb 100644
39918 --- a/drivers/pci/hotplug/acpiphp_ibm.c
39919 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
39920 @@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
39921 goto init_cleanup;
39922 }
39923
39924 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
39925 + pax_open_kernel();
39926 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
39927 + pax_close_kernel();
39928 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
39929
39930 return retval;
39931 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
39932 index a6a71c4..c91097b 100644
39933 --- a/drivers/pci/hotplug/cpcihp_generic.c
39934 +++ b/drivers/pci/hotplug/cpcihp_generic.c
39935 @@ -73,7 +73,6 @@ static u16 port;
39936 static unsigned int enum_bit;
39937 static u8 enum_mask;
39938
39939 -static struct cpci_hp_controller_ops generic_hpc_ops;
39940 static struct cpci_hp_controller generic_hpc;
39941
39942 static int __init validate_parameters(void)
39943 @@ -139,6 +138,10 @@ static int query_enum(void)
39944 return ((value & enum_mask) == enum_mask);
39945 }
39946
39947 +static struct cpci_hp_controller_ops generic_hpc_ops = {
39948 + .query_enum = query_enum,
39949 +};
39950 +
39951 static int __init cpcihp_generic_init(void)
39952 {
39953 int status;
39954 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
39955 pci_dev_put(dev);
39956
39957 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
39958 - generic_hpc_ops.query_enum = query_enum;
39959 generic_hpc.ops = &generic_hpc_ops;
39960
39961 status = cpci_hp_register_controller(&generic_hpc);
39962 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
39963 index 449b4bb..257e2e8 100644
39964 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
39965 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
39966 @@ -59,7 +59,6 @@
39967 /* local variables */
39968 static bool debug;
39969 static bool poll;
39970 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
39971 static struct cpci_hp_controller zt5550_hpc;
39972
39973 /* Primary cPCI bus bridge device */
39974 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
39975 return 0;
39976 }
39977
39978 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
39979 + .query_enum = zt5550_hc_query_enum,
39980 +};
39981 +
39982 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
39983 {
39984 int status;
39985 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
39986 dbg("returned from zt5550_hc_config");
39987
39988 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
39989 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
39990 zt5550_hpc.ops = &zt5550_hpc_ops;
39991 if(!poll) {
39992 zt5550_hpc.irq = hc_dev->irq;
39993 zt5550_hpc.irq_flags = IRQF_SHARED;
39994 zt5550_hpc.dev_id = hc_dev;
39995
39996 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
39997 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
39998 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
39999 + pax_open_kernel();
40000 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40001 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40002 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40003 + pax_open_kernel();
40004 } else {
40005 info("using ENUM# polling mode");
40006 }
40007 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
40008 index 76ba8a1..20ca857 100644
40009 --- a/drivers/pci/hotplug/cpqphp_nvram.c
40010 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
40011 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
40012
40013 void compaq_nvram_init (void __iomem *rom_start)
40014 {
40015 +
40016 +#ifndef CONFIG_PAX_KERNEXEC
40017 if (rom_start) {
40018 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
40019 }
40020 +#endif
40021 +
40022 dbg("int15 entry = %p\n", compaq_int15_entry_point);
40023
40024 /* initialize our int15 lock */
40025 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
40026 index 202f4a9..8ee47d0 100644
40027 --- a/drivers/pci/hotplug/pci_hotplug_core.c
40028 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
40029 @@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
40030 return -EINVAL;
40031 }
40032
40033 - slot->ops->owner = owner;
40034 - slot->ops->mod_name = mod_name;
40035 + pax_open_kernel();
40036 + *(struct module **)&slot->ops->owner = owner;
40037 + *(const char **)&slot->ops->mod_name = mod_name;
40038 + pax_close_kernel();
40039
40040 mutex_lock(&pci_hp_mutex);
40041 /*
40042 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
40043 index 939bd1d..a1459c9 100644
40044 --- a/drivers/pci/hotplug/pciehp_core.c
40045 +++ b/drivers/pci/hotplug/pciehp_core.c
40046 @@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
40047 struct slot *slot = ctrl->slot;
40048 struct hotplug_slot *hotplug = NULL;
40049 struct hotplug_slot_info *info = NULL;
40050 - struct hotplug_slot_ops *ops = NULL;
40051 + hotplug_slot_ops_no_const *ops = NULL;
40052 char name[SLOT_NAME_SIZE];
40053 int retval = -ENOMEM;
40054
40055 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
40056 index 9c6e9bb..2916736 100644
40057 --- a/drivers/pci/pci-sysfs.c
40058 +++ b/drivers/pci/pci-sysfs.c
40059 @@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
40060 {
40061 /* allocate attribute structure, piggyback attribute name */
40062 int name_len = write_combine ? 13 : 10;
40063 - struct bin_attribute *res_attr;
40064 + bin_attribute_no_const *res_attr;
40065 int retval;
40066
40067 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
40068 @@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
40069 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
40070 {
40071 int retval;
40072 - struct bin_attribute *attr;
40073 + bin_attribute_no_const *attr;
40074
40075 /* If the device has VPD, try to expose it in sysfs. */
40076 if (dev->vpd) {
40077 @@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
40078 {
40079 int retval;
40080 int rom_size = 0;
40081 - struct bin_attribute *attr;
40082 + bin_attribute_no_const *attr;
40083
40084 if (!sysfs_initialized)
40085 return -EACCES;
40086 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
40087 index e851829..a1a7196 100644
40088 --- a/drivers/pci/pci.h
40089 +++ b/drivers/pci/pci.h
40090 @@ -98,7 +98,7 @@ struct pci_vpd_ops {
40091 struct pci_vpd {
40092 unsigned int len;
40093 const struct pci_vpd_ops *ops;
40094 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
40095 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
40096 };
40097
40098 extern int pci_vpd_pci22_init(struct pci_dev *dev);
40099 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
40100 index 8474b6a..ee81993 100644
40101 --- a/drivers/pci/pcie/aspm.c
40102 +++ b/drivers/pci/pcie/aspm.c
40103 @@ -27,9 +27,9 @@
40104 #define MODULE_PARAM_PREFIX "pcie_aspm."
40105
40106 /* Note: those are not register definitions */
40107 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
40108 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
40109 -#define ASPM_STATE_L1 (4) /* L1 state */
40110 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
40111 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
40112 +#define ASPM_STATE_L1 (4U) /* L1 state */
40113 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
40114 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
40115
40116 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
40117 index 6186f03..1a78714 100644
40118 --- a/drivers/pci/probe.c
40119 +++ b/drivers/pci/probe.c
40120 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
40121 struct pci_bus_region region;
40122 bool bar_too_big = false, bar_disabled = false;
40123
40124 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
40125 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
40126
40127 /* No printks while decoding is disabled! */
40128 if (!dev->mmio_always_on) {
40129 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
40130 index 9b8505c..f00870a 100644
40131 --- a/drivers/pci/proc.c
40132 +++ b/drivers/pci/proc.c
40133 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
40134 static int __init pci_proc_init(void)
40135 {
40136 struct pci_dev *dev = NULL;
40137 +
40138 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
40139 +#ifdef CONFIG_GRKERNSEC_PROC_USER
40140 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
40141 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
40142 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
40143 +#endif
40144 +#else
40145 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
40146 +#endif
40147 proc_create("devices", 0, proc_bus_pci_dir,
40148 &proc_bus_pci_dev_operations);
40149 proc_initialized = 1;
40150 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40151 index 2111dbb..79e434b 100644
40152 --- a/drivers/platform/x86/msi-laptop.c
40153 +++ b/drivers/platform/x86/msi-laptop.c
40154 @@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
40155 int result;
40156
40157 /* allow userland write sysfs file */
40158 - dev_attr_bluetooth.store = store_bluetooth;
40159 - dev_attr_wlan.store = store_wlan;
40160 - dev_attr_threeg.store = store_threeg;
40161 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
40162 - dev_attr_wlan.attr.mode |= S_IWUSR;
40163 - dev_attr_threeg.attr.mode |= S_IWUSR;
40164 + pax_open_kernel();
40165 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
40166 + *(void **)&dev_attr_wlan.store = store_wlan;
40167 + *(void **)&dev_attr_threeg.store = store_threeg;
40168 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
40169 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
40170 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
40171 + pax_close_kernel();
40172
40173 /* disable hardware control by fn key */
40174 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
40175 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40176 index b8ad71f..3ec9bb4 100644
40177 --- a/drivers/platform/x86/sony-laptop.c
40178 +++ b/drivers/platform/x86/sony-laptop.c
40179 @@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
40180 }
40181
40182 /* High speed charging function */
40183 -static struct device_attribute *hsc_handle;
40184 +static device_attribute_no_const *hsc_handle;
40185
40186 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
40187 struct device_attribute *attr,
40188 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40189 index f946ca7..f25c833 100644
40190 --- a/drivers/platform/x86/thinkpad_acpi.c
40191 +++ b/drivers/platform/x86/thinkpad_acpi.c
40192 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
40193 return 0;
40194 }
40195
40196 -void static hotkey_mask_warn_incomplete_mask(void)
40197 +static void hotkey_mask_warn_incomplete_mask(void)
40198 {
40199 /* log only what the user can fix... */
40200 const u32 wantedmask = hotkey_driver_mask &
40201 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
40202 }
40203 }
40204
40205 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40206 - struct tp_nvram_state *newn,
40207 - const u32 event_mask)
40208 -{
40209 -
40210 #define TPACPI_COMPARE_KEY(__scancode, __member) \
40211 do { \
40212 if ((event_mask & (1 << __scancode)) && \
40213 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40214 tpacpi_hotkey_send_key(__scancode); \
40215 } while (0)
40216
40217 - void issue_volchange(const unsigned int oldvol,
40218 - const unsigned int newvol)
40219 - {
40220 - unsigned int i = oldvol;
40221 +static void issue_volchange(const unsigned int oldvol,
40222 + const unsigned int newvol,
40223 + const u32 event_mask)
40224 +{
40225 + unsigned int i = oldvol;
40226
40227 - while (i > newvol) {
40228 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40229 - i--;
40230 - }
40231 - while (i < newvol) {
40232 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40233 - i++;
40234 - }
40235 + while (i > newvol) {
40236 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40237 + i--;
40238 }
40239 + while (i < newvol) {
40240 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40241 + i++;
40242 + }
40243 +}
40244
40245 - void issue_brightnesschange(const unsigned int oldbrt,
40246 - const unsigned int newbrt)
40247 - {
40248 - unsigned int i = oldbrt;
40249 +static void issue_brightnesschange(const unsigned int oldbrt,
40250 + const unsigned int newbrt,
40251 + const u32 event_mask)
40252 +{
40253 + unsigned int i = oldbrt;
40254
40255 - while (i > newbrt) {
40256 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40257 - i--;
40258 - }
40259 - while (i < newbrt) {
40260 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40261 - i++;
40262 - }
40263 + while (i > newbrt) {
40264 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40265 + i--;
40266 + }
40267 + while (i < newbrt) {
40268 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40269 + i++;
40270 }
40271 +}
40272
40273 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40274 + struct tp_nvram_state *newn,
40275 + const u32 event_mask)
40276 +{
40277 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
40278 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
40279 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
40280 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40281 oldn->volume_level != newn->volume_level) {
40282 /* recently muted, or repeated mute keypress, or
40283 * multiple presses ending in mute */
40284 - issue_volchange(oldn->volume_level, newn->volume_level);
40285 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40286 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
40287 }
40288 } else {
40289 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40290 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40291 }
40292 if (oldn->volume_level != newn->volume_level) {
40293 - issue_volchange(oldn->volume_level, newn->volume_level);
40294 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40295 } else if (oldn->volume_toggle != newn->volume_toggle) {
40296 /* repeated vol up/down keypress at end of scale ? */
40297 if (newn->volume_level == 0)
40298 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40299 /* handle brightness */
40300 if (oldn->brightness_level != newn->brightness_level) {
40301 issue_brightnesschange(oldn->brightness_level,
40302 - newn->brightness_level);
40303 + newn->brightness_level,
40304 + event_mask);
40305 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
40306 /* repeated key presses that didn't change state */
40307 if (newn->brightness_level == 0)
40308 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40309 && !tp_features.bright_unkfw)
40310 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40311 }
40312 +}
40313
40314 #undef TPACPI_COMPARE_KEY
40315 #undef TPACPI_MAY_SEND_KEY
40316 -}
40317
40318 /*
40319 * Polling driver
40320 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40321 index 769d265..a3a05ca 100644
40322 --- a/drivers/pnp/pnpbios/bioscalls.c
40323 +++ b/drivers/pnp/pnpbios/bioscalls.c
40324 @@ -58,7 +58,7 @@ do { \
40325 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40326 } while(0)
40327
40328 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40329 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40330 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40331
40332 /*
40333 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40334
40335 cpu = get_cpu();
40336 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40337 +
40338 + pax_open_kernel();
40339 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40340 + pax_close_kernel();
40341
40342 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40343 spin_lock_irqsave(&pnp_bios_lock, flags);
40344 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40345 :"memory");
40346 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40347
40348 + pax_open_kernel();
40349 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40350 + pax_close_kernel();
40351 +
40352 put_cpu();
40353
40354 /* If we get here and this is set then the PnP BIOS faulted on us. */
40355 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40356 return status;
40357 }
40358
40359 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
40360 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40361 {
40362 int i;
40363
40364 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40365 pnp_bios_callpoint.offset = header->fields.pm16offset;
40366 pnp_bios_callpoint.segment = PNP_CS16;
40367
40368 + pax_open_kernel();
40369 +
40370 for_each_possible_cpu(i) {
40371 struct desc_struct *gdt = get_cpu_gdt_table(i);
40372 if (!gdt)
40373 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40374 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40375 (unsigned long)__va(header->fields.pm16dseg));
40376 }
40377 +
40378 + pax_close_kernel();
40379 }
40380 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40381 index 3e6db1c..1fbbdae 100644
40382 --- a/drivers/pnp/resource.c
40383 +++ b/drivers/pnp/resource.c
40384 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40385 return 1;
40386
40387 /* check if the resource is valid */
40388 - if (*irq < 0 || *irq > 15)
40389 + if (*irq > 15)
40390 return 0;
40391
40392 /* check if the resource is reserved */
40393 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40394 return 1;
40395
40396 /* check if the resource is valid */
40397 - if (*dma < 0 || *dma == 4 || *dma > 7)
40398 + if (*dma == 4 || *dma > 7)
40399 return 0;
40400
40401 /* check if the resource is reserved */
40402 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
40403 index 7df7c5f..bd48c47 100644
40404 --- a/drivers/power/pda_power.c
40405 +++ b/drivers/power/pda_power.c
40406 @@ -37,7 +37,11 @@ static int polling;
40407
40408 #ifdef CONFIG_USB_OTG_UTILS
40409 static struct usb_phy *transceiver;
40410 -static struct notifier_block otg_nb;
40411 +static int otg_handle_notification(struct notifier_block *nb,
40412 + unsigned long event, void *unused);
40413 +static struct notifier_block otg_nb = {
40414 + .notifier_call = otg_handle_notification
40415 +};
40416 #endif
40417
40418 static struct regulator *ac_draw;
40419 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
40420
40421 #ifdef CONFIG_USB_OTG_UTILS
40422 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
40423 - otg_nb.notifier_call = otg_handle_notification;
40424 ret = usb_register_notifier(transceiver, &otg_nb);
40425 if (ret) {
40426 dev_err(dev, "failure to register otg notifier\n");
40427 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
40428 index cc439fd..8fa30df 100644
40429 --- a/drivers/power/power_supply.h
40430 +++ b/drivers/power/power_supply.h
40431 @@ -16,12 +16,12 @@ struct power_supply;
40432
40433 #ifdef CONFIG_SYSFS
40434
40435 -extern void power_supply_init_attrs(struct device_type *dev_type);
40436 +extern void power_supply_init_attrs(void);
40437 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
40438
40439 #else
40440
40441 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
40442 +static inline void power_supply_init_attrs(void) {}
40443 #define power_supply_uevent NULL
40444
40445 #endif /* CONFIG_SYSFS */
40446 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
40447 index 8a7cfb3..493e0a2 100644
40448 --- a/drivers/power/power_supply_core.c
40449 +++ b/drivers/power/power_supply_core.c
40450 @@ -24,7 +24,10 @@
40451 struct class *power_supply_class;
40452 EXPORT_SYMBOL_GPL(power_supply_class);
40453
40454 -static struct device_type power_supply_dev_type;
40455 +extern const struct attribute_group *power_supply_attr_groups[];
40456 +static struct device_type power_supply_dev_type = {
40457 + .groups = power_supply_attr_groups,
40458 +};
40459
40460 static int __power_supply_changed_work(struct device *dev, void *data)
40461 {
40462 @@ -393,7 +396,6 @@ static int __init power_supply_class_init(void)
40463 return PTR_ERR(power_supply_class);
40464
40465 power_supply_class->dev_uevent = power_supply_uevent;
40466 - power_supply_init_attrs(&power_supply_dev_type);
40467
40468 return 0;
40469 }
40470 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
40471 index 40fa3b7..d9c2e0e 100644
40472 --- a/drivers/power/power_supply_sysfs.c
40473 +++ b/drivers/power/power_supply_sysfs.c
40474 @@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
40475 .is_visible = power_supply_attr_is_visible,
40476 };
40477
40478 -static const struct attribute_group *power_supply_attr_groups[] = {
40479 +const struct attribute_group *power_supply_attr_groups[] = {
40480 &power_supply_attr_group,
40481 NULL,
40482 };
40483
40484 -void power_supply_init_attrs(struct device_type *dev_type)
40485 +void power_supply_init_attrs(void)
40486 {
40487 int i;
40488
40489 - dev_type->groups = power_supply_attr_groups;
40490 -
40491 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
40492 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
40493 }
40494 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
40495 index 4d7c635..9860196 100644
40496 --- a/drivers/regulator/max8660.c
40497 +++ b/drivers/regulator/max8660.c
40498 @@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
40499 max8660->shadow_regs[MAX8660_OVER1] = 5;
40500 } else {
40501 /* Otherwise devices can be toggled via software */
40502 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
40503 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
40504 + pax_open_kernel();
40505 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
40506 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
40507 + pax_close_kernel();
40508 }
40509
40510 /*
40511 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
40512 index 9a8ea91..c483dd9 100644
40513 --- a/drivers/regulator/max8973-regulator.c
40514 +++ b/drivers/regulator/max8973-regulator.c
40515 @@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
40516 if (!pdata->enable_ext_control) {
40517 max->desc.enable_reg = MAX8973_VOUT;
40518 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
40519 - max8973_dcdc_ops.enable = regulator_enable_regmap;
40520 - max8973_dcdc_ops.disable = regulator_disable_regmap;
40521 - max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
40522 + pax_open_kernel();
40523 + *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
40524 + *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
40525 + *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
40526 + pax_close_kernel();
40527 }
40528
40529 max->enable_external_control = pdata->enable_ext_control;
40530 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
40531 index 0d84b1f..c2da6ac 100644
40532 --- a/drivers/regulator/mc13892-regulator.c
40533 +++ b/drivers/regulator/mc13892-regulator.c
40534 @@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
40535 }
40536 mc13xxx_unlock(mc13892);
40537
40538 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
40539 + pax_open_kernel();
40540 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
40541 = mc13892_vcam_set_mode;
40542 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
40543 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
40544 = mc13892_vcam_get_mode;
40545 + pax_close_kernel();
40546
40547 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
40548 ARRAY_SIZE(mc13892_regulators));
40549 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
40550 index 16630aa..6afc992 100644
40551 --- a/drivers/rtc/rtc-cmos.c
40552 +++ b/drivers/rtc/rtc-cmos.c
40553 @@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
40554 hpet_rtc_timer_init();
40555
40556 /* export at least the first block of NVRAM */
40557 - nvram.size = address_space - NVRAM_OFFSET;
40558 + pax_open_kernel();
40559 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
40560 + pax_close_kernel();
40561 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
40562 if (retval < 0) {
40563 dev_dbg(dev, "can't create nvram file? %d\n", retval);
40564 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
40565 index 9a86b4b..3a383dc 100644
40566 --- a/drivers/rtc/rtc-dev.c
40567 +++ b/drivers/rtc/rtc-dev.c
40568 @@ -14,6 +14,7 @@
40569 #include <linux/module.h>
40570 #include <linux/rtc.h>
40571 #include <linux/sched.h>
40572 +#include <linux/grsecurity.h>
40573 #include "rtc-core.h"
40574
40575 static dev_t rtc_devt;
40576 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
40577 if (copy_from_user(&tm, uarg, sizeof(tm)))
40578 return -EFAULT;
40579
40580 + gr_log_timechange();
40581 +
40582 return rtc_set_time(rtc, &tm);
40583
40584 case RTC_PIE_ON:
40585 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
40586 index e0d0ba4..3c65868 100644
40587 --- a/drivers/rtc/rtc-ds1307.c
40588 +++ b/drivers/rtc/rtc-ds1307.c
40589 @@ -106,7 +106,7 @@ struct ds1307 {
40590 u8 offset; /* register's offset */
40591 u8 regs[11];
40592 u16 nvram_offset;
40593 - struct bin_attribute *nvram;
40594 + bin_attribute_no_const *nvram;
40595 enum ds_type type;
40596 unsigned long flags;
40597 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
40598 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
40599 index 130f29a..6179d03 100644
40600 --- a/drivers/rtc/rtc-m48t59.c
40601 +++ b/drivers/rtc/rtc-m48t59.c
40602 @@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
40603 goto out;
40604 }
40605
40606 - m48t59_nvram_attr.size = pdata->offset;
40607 + pax_open_kernel();
40608 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
40609 + pax_close_kernel();
40610
40611 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
40612 if (ret) {
40613 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
40614 index e693af6..2e525b6 100644
40615 --- a/drivers/scsi/bfa/bfa_fcpim.h
40616 +++ b/drivers/scsi/bfa/bfa_fcpim.h
40617 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
40618
40619 struct bfa_itn_s {
40620 bfa_isr_func_t isr;
40621 -};
40622 +} __no_const;
40623
40624 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
40625 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
40626 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
40627 index 23a90e7..9cf04ee 100644
40628 --- a/drivers/scsi/bfa/bfa_ioc.h
40629 +++ b/drivers/scsi/bfa/bfa_ioc.h
40630 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
40631 bfa_ioc_disable_cbfn_t disable_cbfn;
40632 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
40633 bfa_ioc_reset_cbfn_t reset_cbfn;
40634 -};
40635 +} __no_const;
40636
40637 /*
40638 * IOC event notification mechanism.
40639 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
40640 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
40641 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
40642 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
40643 -};
40644 +} __no_const;
40645
40646 /*
40647 * Queue element to wait for room in request queue. FIFO order is
40648 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
40649 index 593085a..47aa999 100644
40650 --- a/drivers/scsi/hosts.c
40651 +++ b/drivers/scsi/hosts.c
40652 @@ -42,7 +42,7 @@
40653 #include "scsi_logging.h"
40654
40655
40656 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
40657 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
40658
40659
40660 static void scsi_host_cls_release(struct device *dev)
40661 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
40662 * subtract one because we increment first then return, but we need to
40663 * know what the next host number was before increment
40664 */
40665 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
40666 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
40667 shost->dma_channel = 0xff;
40668
40669 /* These three are default values which can be overridden */
40670 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
40671 index 4f33806..afd6f60 100644
40672 --- a/drivers/scsi/hpsa.c
40673 +++ b/drivers/scsi/hpsa.c
40674 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
40675 unsigned long flags;
40676
40677 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
40678 - return h->access.command_completed(h, q);
40679 + return h->access->command_completed(h, q);
40680
40681 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
40682 a = rq->head[rq->current_entry];
40683 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
40684 while (!list_empty(&h->reqQ)) {
40685 c = list_entry(h->reqQ.next, struct CommandList, list);
40686 /* can't do anything if fifo is full */
40687 - if ((h->access.fifo_full(h))) {
40688 + if ((h->access->fifo_full(h))) {
40689 dev_warn(&h->pdev->dev, "fifo full\n");
40690 break;
40691 }
40692 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
40693
40694 /* Tell the controller execute command */
40695 spin_unlock_irqrestore(&h->lock, flags);
40696 - h->access.submit_command(h, c);
40697 + h->access->submit_command(h, c);
40698 spin_lock_irqsave(&h->lock, flags);
40699 }
40700 spin_unlock_irqrestore(&h->lock, flags);
40701 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
40702
40703 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
40704 {
40705 - return h->access.command_completed(h, q);
40706 + return h->access->command_completed(h, q);
40707 }
40708
40709 static inline bool interrupt_pending(struct ctlr_info *h)
40710 {
40711 - return h->access.intr_pending(h);
40712 + return h->access->intr_pending(h);
40713 }
40714
40715 static inline long interrupt_not_for_us(struct ctlr_info *h)
40716 {
40717 - return (h->access.intr_pending(h) == 0) ||
40718 + return (h->access->intr_pending(h) == 0) ||
40719 (h->interrupts_enabled == 0);
40720 }
40721
40722 @@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
40723 if (prod_index < 0)
40724 return -ENODEV;
40725 h->product_name = products[prod_index].product_name;
40726 - h->access = *(products[prod_index].access);
40727 + h->access = products[prod_index].access;
40728
40729 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
40730 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
40731 @@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
40732
40733 assert_spin_locked(&lockup_detector_lock);
40734 remove_ctlr_from_lockup_detector_list(h);
40735 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40736 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40737 spin_lock_irqsave(&h->lock, flags);
40738 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
40739 spin_unlock_irqrestore(&h->lock, flags);
40740 @@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
40741 }
40742
40743 /* make sure the board interrupts are off */
40744 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40745 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40746
40747 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
40748 goto clean2;
40749 @@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
40750 * fake ones to scoop up any residual completions.
40751 */
40752 spin_lock_irqsave(&h->lock, flags);
40753 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40754 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40755 spin_unlock_irqrestore(&h->lock, flags);
40756 free_irqs(h);
40757 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
40758 @@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
40759 dev_info(&h->pdev->dev, "Board READY.\n");
40760 dev_info(&h->pdev->dev,
40761 "Waiting for stale completions to drain.\n");
40762 - h->access.set_intr_mask(h, HPSA_INTR_ON);
40763 + h->access->set_intr_mask(h, HPSA_INTR_ON);
40764 msleep(10000);
40765 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40766 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40767
40768 rc = controller_reset_failed(h->cfgtable);
40769 if (rc)
40770 @@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
40771 }
40772
40773 /* Turn the interrupts on so we can service requests */
40774 - h->access.set_intr_mask(h, HPSA_INTR_ON);
40775 + h->access->set_intr_mask(h, HPSA_INTR_ON);
40776
40777 hpsa_hba_inquiry(h);
40778 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
40779 @@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
40780 * To write all data in the battery backed cache to disks
40781 */
40782 hpsa_flush_cache(h);
40783 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40784 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40785 hpsa_free_irqs_and_disable_msix(h);
40786 }
40787
40788 @@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
40789 return;
40790 }
40791 /* Change the access methods to the performant access methods */
40792 - h->access = SA5_performant_access;
40793 + h->access = &SA5_performant_access;
40794 h->transMethod = CFGTBL_Trans_Performant;
40795 }
40796
40797 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
40798 index 9816479..c5d4e97 100644
40799 --- a/drivers/scsi/hpsa.h
40800 +++ b/drivers/scsi/hpsa.h
40801 @@ -79,7 +79,7 @@ struct ctlr_info {
40802 unsigned int msix_vector;
40803 unsigned int msi_vector;
40804 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
40805 - struct access_method access;
40806 + struct access_method *access;
40807
40808 /* queue and queue Info */
40809 struct list_head reqQ;
40810 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
40811 index c772d8d..35c362c 100644
40812 --- a/drivers/scsi/libfc/fc_exch.c
40813 +++ b/drivers/scsi/libfc/fc_exch.c
40814 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
40815 u16 pool_max_index;
40816
40817 struct {
40818 - atomic_t no_free_exch;
40819 - atomic_t no_free_exch_xid;
40820 - atomic_t xid_not_found;
40821 - atomic_t xid_busy;
40822 - atomic_t seq_not_found;
40823 - atomic_t non_bls_resp;
40824 + atomic_unchecked_t no_free_exch;
40825 + atomic_unchecked_t no_free_exch_xid;
40826 + atomic_unchecked_t xid_not_found;
40827 + atomic_unchecked_t xid_busy;
40828 + atomic_unchecked_t seq_not_found;
40829 + atomic_unchecked_t non_bls_resp;
40830 } stats;
40831 };
40832
40833 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
40834 /* allocate memory for exchange */
40835 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
40836 if (!ep) {
40837 - atomic_inc(&mp->stats.no_free_exch);
40838 + atomic_inc_unchecked(&mp->stats.no_free_exch);
40839 goto out;
40840 }
40841 memset(ep, 0, sizeof(*ep));
40842 @@ -786,7 +786,7 @@ out:
40843 return ep;
40844 err:
40845 spin_unlock_bh(&pool->lock);
40846 - atomic_inc(&mp->stats.no_free_exch_xid);
40847 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
40848 mempool_free(ep, mp->ep_pool);
40849 return NULL;
40850 }
40851 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40852 xid = ntohs(fh->fh_ox_id); /* we originated exch */
40853 ep = fc_exch_find(mp, xid);
40854 if (!ep) {
40855 - atomic_inc(&mp->stats.xid_not_found);
40856 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40857 reject = FC_RJT_OX_ID;
40858 goto out;
40859 }
40860 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40861 ep = fc_exch_find(mp, xid);
40862 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
40863 if (ep) {
40864 - atomic_inc(&mp->stats.xid_busy);
40865 + atomic_inc_unchecked(&mp->stats.xid_busy);
40866 reject = FC_RJT_RX_ID;
40867 goto rel;
40868 }
40869 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40870 }
40871 xid = ep->xid; /* get our XID */
40872 } else if (!ep) {
40873 - atomic_inc(&mp->stats.xid_not_found);
40874 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40875 reject = FC_RJT_RX_ID; /* XID not found */
40876 goto out;
40877 }
40878 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40879 } else {
40880 sp = &ep->seq;
40881 if (sp->id != fh->fh_seq_id) {
40882 - atomic_inc(&mp->stats.seq_not_found);
40883 + atomic_inc_unchecked(&mp->stats.seq_not_found);
40884 if (f_ctl & FC_FC_END_SEQ) {
40885 /*
40886 * Update sequence_id based on incoming last
40887 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40888
40889 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
40890 if (!ep) {
40891 - atomic_inc(&mp->stats.xid_not_found);
40892 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40893 goto out;
40894 }
40895 if (ep->esb_stat & ESB_ST_COMPLETE) {
40896 - atomic_inc(&mp->stats.xid_not_found);
40897 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40898 goto rel;
40899 }
40900 if (ep->rxid == FC_XID_UNKNOWN)
40901 ep->rxid = ntohs(fh->fh_rx_id);
40902 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
40903 - atomic_inc(&mp->stats.xid_not_found);
40904 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40905 goto rel;
40906 }
40907 if (ep->did != ntoh24(fh->fh_s_id) &&
40908 ep->did != FC_FID_FLOGI) {
40909 - atomic_inc(&mp->stats.xid_not_found);
40910 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40911 goto rel;
40912 }
40913 sof = fr_sof(fp);
40914 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40915 sp->ssb_stat |= SSB_ST_RESP;
40916 sp->id = fh->fh_seq_id;
40917 } else if (sp->id != fh->fh_seq_id) {
40918 - atomic_inc(&mp->stats.seq_not_found);
40919 + atomic_inc_unchecked(&mp->stats.seq_not_found);
40920 goto rel;
40921 }
40922
40923 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40924 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
40925
40926 if (!sp)
40927 - atomic_inc(&mp->stats.xid_not_found);
40928 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40929 else
40930 - atomic_inc(&mp->stats.non_bls_resp);
40931 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
40932
40933 fc_frame_free(fp);
40934 }
40935 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
40936
40937 list_for_each_entry(ema, &lport->ema_list, ema_list) {
40938 mp = ema->mp;
40939 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
40940 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
40941 st->fc_no_free_exch_xid +=
40942 - atomic_read(&mp->stats.no_free_exch_xid);
40943 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
40944 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
40945 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
40946 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
40947 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
40948 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
40949 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
40950 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
40951 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
40952 }
40953 }
40954 EXPORT_SYMBOL(fc_exch_update_stats);
40955 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
40956 index bdb81cd..d3c7c2c 100644
40957 --- a/drivers/scsi/libsas/sas_ata.c
40958 +++ b/drivers/scsi/libsas/sas_ata.c
40959 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
40960 .postreset = ata_std_postreset,
40961 .error_handler = ata_std_error_handler,
40962 .post_internal_cmd = sas_ata_post_internal,
40963 - .qc_defer = ata_std_qc_defer,
40964 + .qc_defer = ata_std_qc_defer,
40965 .qc_prep = ata_noop_qc_prep,
40966 .qc_issue = sas_ata_qc_issue,
40967 .qc_fill_rtf = sas_ata_qc_fill_rtf,
40968 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
40969 index df4c13a..a51e90c 100644
40970 --- a/drivers/scsi/lpfc/lpfc.h
40971 +++ b/drivers/scsi/lpfc/lpfc.h
40972 @@ -424,7 +424,7 @@ struct lpfc_vport {
40973 struct dentry *debug_nodelist;
40974 struct dentry *vport_debugfs_root;
40975 struct lpfc_debugfs_trc *disc_trc;
40976 - atomic_t disc_trc_cnt;
40977 + atomic_unchecked_t disc_trc_cnt;
40978 #endif
40979 uint8_t stat_data_enabled;
40980 uint8_t stat_data_blocked;
40981 @@ -842,8 +842,8 @@ struct lpfc_hba {
40982 struct timer_list fabric_block_timer;
40983 unsigned long bit_flags;
40984 #define FABRIC_COMANDS_BLOCKED 0
40985 - atomic_t num_rsrc_err;
40986 - atomic_t num_cmd_success;
40987 + atomic_unchecked_t num_rsrc_err;
40988 + atomic_unchecked_t num_cmd_success;
40989 unsigned long last_rsrc_error_time;
40990 unsigned long last_ramp_down_time;
40991 unsigned long last_ramp_up_time;
40992 @@ -879,7 +879,7 @@ struct lpfc_hba {
40993
40994 struct dentry *debug_slow_ring_trc;
40995 struct lpfc_debugfs_trc *slow_ring_trc;
40996 - atomic_t slow_ring_trc_cnt;
40997 + atomic_unchecked_t slow_ring_trc_cnt;
40998 /* iDiag debugfs sub-directory */
40999 struct dentry *idiag_root;
41000 struct dentry *idiag_pci_cfg;
41001 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
41002 index f63f5ff..de29189 100644
41003 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
41004 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
41005 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
41006
41007 #include <linux/debugfs.h>
41008
41009 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41010 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41011 static unsigned long lpfc_debugfs_start_time = 0L;
41012
41013 /* iDiag */
41014 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
41015 lpfc_debugfs_enable = 0;
41016
41017 len = 0;
41018 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
41019 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
41020 (lpfc_debugfs_max_disc_trc - 1);
41021 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
41022 dtp = vport->disc_trc + i;
41023 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
41024 lpfc_debugfs_enable = 0;
41025
41026 len = 0;
41027 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
41028 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
41029 (lpfc_debugfs_max_slow_ring_trc - 1);
41030 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
41031 dtp = phba->slow_ring_trc + i;
41032 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
41033 !vport || !vport->disc_trc)
41034 return;
41035
41036 - index = atomic_inc_return(&vport->disc_trc_cnt) &
41037 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
41038 (lpfc_debugfs_max_disc_trc - 1);
41039 dtp = vport->disc_trc + index;
41040 dtp->fmt = fmt;
41041 dtp->data1 = data1;
41042 dtp->data2 = data2;
41043 dtp->data3 = data3;
41044 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41045 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41046 dtp->jif = jiffies;
41047 #endif
41048 return;
41049 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
41050 !phba || !phba->slow_ring_trc)
41051 return;
41052
41053 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
41054 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
41055 (lpfc_debugfs_max_slow_ring_trc - 1);
41056 dtp = phba->slow_ring_trc + index;
41057 dtp->fmt = fmt;
41058 dtp->data1 = data1;
41059 dtp->data2 = data2;
41060 dtp->data3 = data3;
41061 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41062 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41063 dtp->jif = jiffies;
41064 #endif
41065 return;
41066 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41067 "slow_ring buffer\n");
41068 goto debug_failed;
41069 }
41070 - atomic_set(&phba->slow_ring_trc_cnt, 0);
41071 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
41072 memset(phba->slow_ring_trc, 0,
41073 (sizeof(struct lpfc_debugfs_trc) *
41074 lpfc_debugfs_max_slow_ring_trc));
41075 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41076 "buffer\n");
41077 goto debug_failed;
41078 }
41079 - atomic_set(&vport->disc_trc_cnt, 0);
41080 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
41081
41082 snprintf(name, sizeof(name), "discovery_trace");
41083 vport->debug_disc_trc =
41084 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
41085 index 89ad558..76956c4 100644
41086 --- a/drivers/scsi/lpfc/lpfc_init.c
41087 +++ b/drivers/scsi/lpfc/lpfc_init.c
41088 @@ -10618,8 +10618,10 @@ lpfc_init(void)
41089 "misc_register returned with status %d", error);
41090
41091 if (lpfc_enable_npiv) {
41092 - lpfc_transport_functions.vport_create = lpfc_vport_create;
41093 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41094 + pax_open_kernel();
41095 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
41096 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41097 + pax_close_kernel();
41098 }
41099 lpfc_transport_template =
41100 fc_attach_transport(&lpfc_transport_functions);
41101 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
41102 index 60e5a17..ff7a793 100644
41103 --- a/drivers/scsi/lpfc/lpfc_scsi.c
41104 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
41105 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
41106 uint32_t evt_posted;
41107
41108 spin_lock_irqsave(&phba->hbalock, flags);
41109 - atomic_inc(&phba->num_rsrc_err);
41110 + atomic_inc_unchecked(&phba->num_rsrc_err);
41111 phba->last_rsrc_error_time = jiffies;
41112
41113 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
41114 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
41115 unsigned long flags;
41116 struct lpfc_hba *phba = vport->phba;
41117 uint32_t evt_posted;
41118 - atomic_inc(&phba->num_cmd_success);
41119 + atomic_inc_unchecked(&phba->num_cmd_success);
41120
41121 if (vport->cfg_lun_queue_depth <= queue_depth)
41122 return;
41123 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41124 unsigned long num_rsrc_err, num_cmd_success;
41125 int i;
41126
41127 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
41128 - num_cmd_success = atomic_read(&phba->num_cmd_success);
41129 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
41130 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
41131
41132 /*
41133 * The error and success command counters are global per
41134 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41135 }
41136 }
41137 lpfc_destroy_vport_work_array(phba, vports);
41138 - atomic_set(&phba->num_rsrc_err, 0);
41139 - atomic_set(&phba->num_cmd_success, 0);
41140 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
41141 + atomic_set_unchecked(&phba->num_cmd_success, 0);
41142 }
41143
41144 /**
41145 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
41146 }
41147 }
41148 lpfc_destroy_vport_work_array(phba, vports);
41149 - atomic_set(&phba->num_rsrc_err, 0);
41150 - atomic_set(&phba->num_cmd_success, 0);
41151 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
41152 + atomic_set_unchecked(&phba->num_cmd_success, 0);
41153 }
41154
41155 /**
41156 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41157 index b46f5e9..c4c4ccb 100644
41158 --- a/drivers/scsi/pmcraid.c
41159 +++ b/drivers/scsi/pmcraid.c
41160 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41161 res->scsi_dev = scsi_dev;
41162 scsi_dev->hostdata = res;
41163 res->change_detected = 0;
41164 - atomic_set(&res->read_failures, 0);
41165 - atomic_set(&res->write_failures, 0);
41166 + atomic_set_unchecked(&res->read_failures, 0);
41167 + atomic_set_unchecked(&res->write_failures, 0);
41168 rc = 0;
41169 }
41170 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41171 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41172
41173 /* If this was a SCSI read/write command keep count of errors */
41174 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41175 - atomic_inc(&res->read_failures);
41176 + atomic_inc_unchecked(&res->read_failures);
41177 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41178 - atomic_inc(&res->write_failures);
41179 + atomic_inc_unchecked(&res->write_failures);
41180
41181 if (!RES_IS_GSCSI(res->cfg_entry) &&
41182 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41183 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
41184 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41185 * hrrq_id assigned here in queuecommand
41186 */
41187 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41188 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41189 pinstance->num_hrrq;
41190 cmd->cmd_done = pmcraid_io_done;
41191
41192 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
41193 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41194 * hrrq_id assigned here in queuecommand
41195 */
41196 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41197 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41198 pinstance->num_hrrq;
41199
41200 if (request_size) {
41201 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41202
41203 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41204 /* add resources only after host is added into system */
41205 - if (!atomic_read(&pinstance->expose_resources))
41206 + if (!atomic_read_unchecked(&pinstance->expose_resources))
41207 return;
41208
41209 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
41210 @@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
41211 init_waitqueue_head(&pinstance->reset_wait_q);
41212
41213 atomic_set(&pinstance->outstanding_cmds, 0);
41214 - atomic_set(&pinstance->last_message_id, 0);
41215 - atomic_set(&pinstance->expose_resources, 0);
41216 + atomic_set_unchecked(&pinstance->last_message_id, 0);
41217 + atomic_set_unchecked(&pinstance->expose_resources, 0);
41218
41219 INIT_LIST_HEAD(&pinstance->free_res_q);
41220 INIT_LIST_HEAD(&pinstance->used_res_q);
41221 @@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
41222 /* Schedule worker thread to handle CCN and take care of adding and
41223 * removing devices to OS
41224 */
41225 - atomic_set(&pinstance->expose_resources, 1);
41226 + atomic_set_unchecked(&pinstance->expose_resources, 1);
41227 schedule_work(&pinstance->worker_q);
41228 return rc;
41229
41230 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41231 index e1d150f..6c6df44 100644
41232 --- a/drivers/scsi/pmcraid.h
41233 +++ b/drivers/scsi/pmcraid.h
41234 @@ -748,7 +748,7 @@ struct pmcraid_instance {
41235 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
41236
41237 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
41238 - atomic_t last_message_id;
41239 + atomic_unchecked_t last_message_id;
41240
41241 /* configuration table */
41242 struct pmcraid_config_table *cfg_table;
41243 @@ -777,7 +777,7 @@ struct pmcraid_instance {
41244 atomic_t outstanding_cmds;
41245
41246 /* should add/delete resources to mid-layer now ?*/
41247 - atomic_t expose_resources;
41248 + atomic_unchecked_t expose_resources;
41249
41250
41251
41252 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
41253 struct pmcraid_config_table_entry_ext cfg_entry_ext;
41254 };
41255 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41256 - atomic_t read_failures; /* count of failed READ commands */
41257 - atomic_t write_failures; /* count of failed WRITE commands */
41258 + atomic_unchecked_t read_failures; /* count of failed READ commands */
41259 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41260
41261 /* To indicate add/delete/modify during CCN */
41262 u8 change_detected;
41263 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
41264 index 83d7984..a27d947 100644
41265 --- a/drivers/scsi/qla2xxx/qla_attr.c
41266 +++ b/drivers/scsi/qla2xxx/qla_attr.c
41267 @@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
41268 return 0;
41269 }
41270
41271 -struct fc_function_template qla2xxx_transport_functions = {
41272 +fc_function_template_no_const qla2xxx_transport_functions = {
41273
41274 .show_host_node_name = 1,
41275 .show_host_port_name = 1,
41276 @@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
41277 .bsg_timeout = qla24xx_bsg_timeout,
41278 };
41279
41280 -struct fc_function_template qla2xxx_transport_vport_functions = {
41281 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
41282
41283 .show_host_node_name = 1,
41284 .show_host_port_name = 1,
41285 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
41286 index 2411d1a..4673766 100644
41287 --- a/drivers/scsi/qla2xxx/qla_gbl.h
41288 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
41289 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
41290 struct device_attribute;
41291 extern struct device_attribute *qla2x00_host_attrs[];
41292 struct fc_function_template;
41293 -extern struct fc_function_template qla2xxx_transport_functions;
41294 -extern struct fc_function_template qla2xxx_transport_vport_functions;
41295 +extern fc_function_template_no_const qla2xxx_transport_functions;
41296 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
41297 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
41298 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
41299 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
41300 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
41301 index 10d23f8..a7d5d4c 100644
41302 --- a/drivers/scsi/qla2xxx/qla_os.c
41303 +++ b/drivers/scsi/qla2xxx/qla_os.c
41304 @@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
41305 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
41306 /* Ok, a 64bit DMA mask is applicable. */
41307 ha->flags.enable_64bit_addressing = 1;
41308 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41309 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41310 + pax_open_kernel();
41311 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41312 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41313 + pax_close_kernel();
41314 return;
41315 }
41316 }
41317 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41318 index 329d553..f20d31d 100644
41319 --- a/drivers/scsi/qla4xxx/ql4_def.h
41320 +++ b/drivers/scsi/qla4xxx/ql4_def.h
41321 @@ -273,7 +273,7 @@ struct ddb_entry {
41322 * (4000 only) */
41323 atomic_t relogin_timer; /* Max Time to wait for
41324 * relogin to complete */
41325 - atomic_t relogin_retry_count; /* Num of times relogin has been
41326 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41327 * retried */
41328 uint32_t default_time2wait; /* Default Min time between
41329 * relogins (+aens) */
41330 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41331 index 4cec123..7c1329f 100644
41332 --- a/drivers/scsi/qla4xxx/ql4_os.c
41333 +++ b/drivers/scsi/qla4xxx/ql4_os.c
41334 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
41335 */
41336 if (!iscsi_is_session_online(cls_sess)) {
41337 /* Reset retry relogin timer */
41338 - atomic_inc(&ddb_entry->relogin_retry_count);
41339 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41340 DEBUG2(ql4_printk(KERN_INFO, ha,
41341 "%s: index[%d] relogin timed out-retrying"
41342 " relogin (%d), retry (%d)\n", __func__,
41343 ddb_entry->fw_ddb_index,
41344 - atomic_read(&ddb_entry->relogin_retry_count),
41345 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
41346 ddb_entry->default_time2wait + 4));
41347 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
41348 atomic_set(&ddb_entry->retry_relogin_timer,
41349 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
41350
41351 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41352 atomic_set(&ddb_entry->relogin_timer, 0);
41353 - atomic_set(&ddb_entry->relogin_retry_count, 0);
41354 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41355 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
41356 ddb_entry->default_relogin_timeout =
41357 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
41358 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41359 index 2c0d0ec..4e8681a 100644
41360 --- a/drivers/scsi/scsi.c
41361 +++ b/drivers/scsi/scsi.c
41362 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41363 unsigned long timeout;
41364 int rtn = 0;
41365
41366 - atomic_inc(&cmd->device->iorequest_cnt);
41367 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41368
41369 /* check if the device is still usable */
41370 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41371 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41372 index f1bf5af..f67e943 100644
41373 --- a/drivers/scsi/scsi_lib.c
41374 +++ b/drivers/scsi/scsi_lib.c
41375 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41376 shost = sdev->host;
41377 scsi_init_cmd_errh(cmd);
41378 cmd->result = DID_NO_CONNECT << 16;
41379 - atomic_inc(&cmd->device->iorequest_cnt);
41380 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41381
41382 /*
41383 * SCSI request completion path will do scsi_device_unbusy(),
41384 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
41385
41386 INIT_LIST_HEAD(&cmd->eh_entry);
41387
41388 - atomic_inc(&cmd->device->iodone_cnt);
41389 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
41390 if (cmd->result)
41391 - atomic_inc(&cmd->device->ioerr_cnt);
41392 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41393
41394 disposition = scsi_decide_disposition(cmd);
41395 if (disposition != SUCCESS &&
41396 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41397 index 931a7d9..0c2a754 100644
41398 --- a/drivers/scsi/scsi_sysfs.c
41399 +++ b/drivers/scsi/scsi_sysfs.c
41400 @@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41401 char *buf) \
41402 { \
41403 struct scsi_device *sdev = to_scsi_device(dev); \
41404 - unsigned long long count = atomic_read(&sdev->field); \
41405 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
41406 return snprintf(buf, 20, "0x%llx\n", count); \
41407 } \
41408 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41409 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41410 index 84a1fdf..693b0d6 100644
41411 --- a/drivers/scsi/scsi_tgt_lib.c
41412 +++ b/drivers/scsi/scsi_tgt_lib.c
41413 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41414 int err;
41415
41416 dprintk("%lx %u\n", uaddr, len);
41417 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41418 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41419 if (err) {
41420 /*
41421 * TODO: need to fixup sg_tablesize, max_segment_size,
41422 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
41423 index e894ca7..de9d7660 100644
41424 --- a/drivers/scsi/scsi_transport_fc.c
41425 +++ b/drivers/scsi/scsi_transport_fc.c
41426 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
41427 * Netlink Infrastructure
41428 */
41429
41430 -static atomic_t fc_event_seq;
41431 +static atomic_unchecked_t fc_event_seq;
41432
41433 /**
41434 * fc_get_event_number - Obtain the next sequential FC event number
41435 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
41436 u32
41437 fc_get_event_number(void)
41438 {
41439 - return atomic_add_return(1, &fc_event_seq);
41440 + return atomic_add_return_unchecked(1, &fc_event_seq);
41441 }
41442 EXPORT_SYMBOL(fc_get_event_number);
41443
41444 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
41445 {
41446 int error;
41447
41448 - atomic_set(&fc_event_seq, 0);
41449 + atomic_set_unchecked(&fc_event_seq, 0);
41450
41451 error = transport_class_register(&fc_host_class);
41452 if (error)
41453 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
41454 char *cp;
41455
41456 *val = simple_strtoul(buf, &cp, 0);
41457 - if ((*cp && (*cp != '\n')) || (*val < 0))
41458 + if (*cp && (*cp != '\n'))
41459 return -EINVAL;
41460 /*
41461 * Check for overflow; dev_loss_tmo is u32
41462 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
41463 index 31969f2..2b348f0 100644
41464 --- a/drivers/scsi/scsi_transport_iscsi.c
41465 +++ b/drivers/scsi/scsi_transport_iscsi.c
41466 @@ -79,7 +79,7 @@ struct iscsi_internal {
41467 struct transport_container session_cont;
41468 };
41469
41470 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
41471 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
41472 static struct workqueue_struct *iscsi_eh_timer_workq;
41473
41474 static DEFINE_IDA(iscsi_sess_ida);
41475 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
41476 int err;
41477
41478 ihost = shost->shost_data;
41479 - session->sid = atomic_add_return(1, &iscsi_session_nr);
41480 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
41481
41482 if (target_id == ISCSI_MAX_TARGET) {
41483 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
41484 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
41485 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
41486 ISCSI_TRANSPORT_VERSION);
41487
41488 - atomic_set(&iscsi_session_nr, 0);
41489 + atomic_set_unchecked(&iscsi_session_nr, 0);
41490
41491 err = class_register(&iscsi_transport_class);
41492 if (err)
41493 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
41494 index f379c7f..e8fc69c 100644
41495 --- a/drivers/scsi/scsi_transport_srp.c
41496 +++ b/drivers/scsi/scsi_transport_srp.c
41497 @@ -33,7 +33,7 @@
41498 #include "scsi_transport_srp_internal.h"
41499
41500 struct srp_host_attrs {
41501 - atomic_t next_port_id;
41502 + atomic_unchecked_t next_port_id;
41503 };
41504 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
41505
41506 @@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
41507 struct Scsi_Host *shost = dev_to_shost(dev);
41508 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
41509
41510 - atomic_set(&srp_host->next_port_id, 0);
41511 + atomic_set_unchecked(&srp_host->next_port_id, 0);
41512 return 0;
41513 }
41514
41515 @@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
41516 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
41517 rport->roles = ids->roles;
41518
41519 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
41520 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
41521 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
41522
41523 transport_setup_device(&rport->dev);
41524 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
41525 index 7992635..609faf8 100644
41526 --- a/drivers/scsi/sd.c
41527 +++ b/drivers/scsi/sd.c
41528 @@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
41529 sdkp->disk = gd;
41530 sdkp->index = index;
41531 atomic_set(&sdkp->openers, 0);
41532 - atomic_set(&sdkp->device->ioerr_cnt, 0);
41533 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
41534
41535 if (!sdp->request_queue->rq_timeout) {
41536 if (sdp->type != TYPE_MOD)
41537 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
41538 index be2c9a6..275525c 100644
41539 --- a/drivers/scsi/sg.c
41540 +++ b/drivers/scsi/sg.c
41541 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
41542 sdp->disk->disk_name,
41543 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
41544 NULL,
41545 - (char *)arg);
41546 + (char __user *)arg);
41547 case BLKTRACESTART:
41548 return blk_trace_startstop(sdp->device->request_queue, 1);
41549 case BLKTRACESTOP:
41550 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
41551 index 19ee901..6e8c2ef 100644
41552 --- a/drivers/spi/spi.c
41553 +++ b/drivers/spi/spi.c
41554 @@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
41555 EXPORT_SYMBOL_GPL(spi_bus_unlock);
41556
41557 /* portable code must never pass more than 32 bytes */
41558 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
41559 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
41560
41561 static u8 *buf;
41562
41563 diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
41564 index c7a5f97..71ecd35 100644
41565 --- a/drivers/staging/iio/iio_hwmon.c
41566 +++ b/drivers/staging/iio/iio_hwmon.c
41567 @@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
41568 static int iio_hwmon_probe(struct platform_device *pdev)
41569 {
41570 struct iio_hwmon_state *st;
41571 - struct sensor_device_attribute *a;
41572 + sensor_device_attribute_no_const *a;
41573 int ret, i;
41574 int in_i = 1, temp_i = 1, curr_i = 1;
41575 enum iio_chan_type type;
41576 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
41577 index 34afc16..ffe44dd 100644
41578 --- a/drivers/staging/octeon/ethernet-rx.c
41579 +++ b/drivers/staging/octeon/ethernet-rx.c
41580 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
41581 /* Increment RX stats for virtual ports */
41582 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
41583 #ifdef CONFIG_64BIT
41584 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
41585 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
41586 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
41587 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
41588 #else
41589 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
41590 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
41591 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
41592 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
41593 #endif
41594 }
41595 netif_receive_skb(skb);
41596 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
41597 dev->name);
41598 */
41599 #ifdef CONFIG_64BIT
41600 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
41601 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
41602 #else
41603 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
41604 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
41605 #endif
41606 dev_kfree_skb_irq(skb);
41607 }
41608 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
41609 index ef32dc1..a159d68 100644
41610 --- a/drivers/staging/octeon/ethernet.c
41611 +++ b/drivers/staging/octeon/ethernet.c
41612 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
41613 * since the RX tasklet also increments it.
41614 */
41615 #ifdef CONFIG_64BIT
41616 - atomic64_add(rx_status.dropped_packets,
41617 - (atomic64_t *)&priv->stats.rx_dropped);
41618 + atomic64_add_unchecked(rx_status.dropped_packets,
41619 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
41620 #else
41621 - atomic_add(rx_status.dropped_packets,
41622 - (atomic_t *)&priv->stats.rx_dropped);
41623 + atomic_add_unchecked(rx_status.dropped_packets,
41624 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
41625 #endif
41626 }
41627
41628 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
41629 index a2b7e03..aaf3630 100644
41630 --- a/drivers/staging/ramster/tmem.c
41631 +++ b/drivers/staging/ramster/tmem.c
41632 @@ -50,25 +50,25 @@
41633 * A tmem host implementation must use this function to register callbacks
41634 * for memory allocation.
41635 */
41636 -static struct tmem_hostops tmem_hostops;
41637 +static struct tmem_hostops *tmem_hostops;
41638
41639 static void tmem_objnode_tree_init(void);
41640
41641 void tmem_register_hostops(struct tmem_hostops *m)
41642 {
41643 tmem_objnode_tree_init();
41644 - tmem_hostops = *m;
41645 + tmem_hostops = m;
41646 }
41647
41648 /*
41649 * A tmem host implementation must use this function to register
41650 * callbacks for a page-accessible memory (PAM) implementation.
41651 */
41652 -static struct tmem_pamops tmem_pamops;
41653 +static struct tmem_pamops *tmem_pamops;
41654
41655 void tmem_register_pamops(struct tmem_pamops *m)
41656 {
41657 - tmem_pamops = *m;
41658 + tmem_pamops = m;
41659 }
41660
41661 /*
41662 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
41663 obj->pampd_count = 0;
41664 #ifdef CONFIG_RAMSTER
41665 if (tmem_pamops.new_obj != NULL)
41666 - (*tmem_pamops.new_obj)(obj);
41667 + (tmem_pamops->new_obj)(obj);
41668 #endif
41669 SET_SENTINEL(obj, OBJ);
41670
41671 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
41672 rbnode = rb_next(rbnode);
41673 tmem_pampd_destroy_all_in_obj(obj, true);
41674 tmem_obj_free(obj, hb);
41675 - (*tmem_hostops.obj_free)(obj, pool);
41676 + (tmem_hostops->obj_free)(obj, pool);
41677 }
41678 spin_unlock(&hb->lock);
41679 }
41680 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
41681 ASSERT_SENTINEL(obj, OBJ);
41682 BUG_ON(obj->pool == NULL);
41683 ASSERT_SENTINEL(obj->pool, POOL);
41684 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
41685 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
41686 if (unlikely(objnode == NULL))
41687 goto out;
41688 objnode->obj = obj;
41689 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
41690 ASSERT_SENTINEL(pool, POOL);
41691 objnode->obj->objnode_count--;
41692 objnode->obj = NULL;
41693 - (*tmem_hostops.objnode_free)(objnode, pool);
41694 + (tmem_hostops->objnode_free)(objnode, pool);
41695 }
41696
41697 /*
41698 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
41699 void *old_pampd = *(void **)slot;
41700 *(void **)slot = new_pampd;
41701 if (!no_free)
41702 - (*tmem_pamops.free)(old_pampd, obj->pool,
41703 + (tmem_pamops->free)(old_pampd, obj->pool,
41704 NULL, 0, false);
41705 ret = new_pampd;
41706 }
41707 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
41708 if (objnode->slots[i]) {
41709 if (ht == 1) {
41710 obj->pampd_count--;
41711 - (*tmem_pamops.free)(objnode->slots[i],
41712 + (tmem_pamops->free)(objnode->slots[i],
41713 obj->pool, NULL, 0, true);
41714 objnode->slots[i] = NULL;
41715 continue;
41716 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
41717 return;
41718 if (obj->objnode_tree_height == 0) {
41719 obj->pampd_count--;
41720 - (*tmem_pamops.free)(obj->objnode_tree_root,
41721 + (tmem_pamops->free)(obj->objnode_tree_root,
41722 obj->pool, NULL, 0, true);
41723 } else {
41724 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
41725 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
41726 obj->objnode_tree_root = NULL;
41727 #ifdef CONFIG_RAMSTER
41728 if (tmem_pamops.free_obj != NULL)
41729 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
41730 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
41731 #endif
41732 }
41733
41734 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41735 /* if found, is a dup put, flush the old one */
41736 pampd_del = tmem_pampd_delete_from_obj(obj, index);
41737 BUG_ON(pampd_del != pampd);
41738 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
41739 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
41740 if (obj->pampd_count == 0) {
41741 objnew = obj;
41742 objfound = NULL;
41743 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41744 pampd = NULL;
41745 }
41746 } else {
41747 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
41748 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
41749 if (unlikely(obj == NULL)) {
41750 ret = -ENOMEM;
41751 goto out;
41752 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41753 if (unlikely(ret == -ENOMEM))
41754 /* may have partially built objnode tree ("stump") */
41755 goto delete_and_free;
41756 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
41757 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
41758 goto out;
41759
41760 delete_and_free:
41761 (void)tmem_pampd_delete_from_obj(obj, index);
41762 if (pampd)
41763 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
41764 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
41765 if (objnew) {
41766 tmem_obj_free(objnew, hb);
41767 - (*tmem_hostops.obj_free)(objnew, pool);
41768 + (tmem_hostops->obj_free)(objnew, pool);
41769 }
41770 out:
41771 spin_unlock(&hb->lock);
41772 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
41773 if (pampd != NULL) {
41774 BUG_ON(obj == NULL);
41775 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
41776 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
41777 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
41778 } else if (delete) {
41779 BUG_ON(obj == NULL);
41780 (void)tmem_pampd_delete_from_obj(obj, index);
41781 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
41782 int ret = 0;
41783
41784 if (!is_ephemeral(pool))
41785 - new_pampd = (*tmem_pamops.repatriate_preload)(
41786 + new_pampd = (tmem_pamops->repatriate_preload)(
41787 old_pampd, pool, oidp, index, &intransit);
41788 if (intransit)
41789 ret = -EAGAIN;
41790 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
41791 /* must release the hb->lock else repatriate can't sleep */
41792 spin_unlock(&hb->lock);
41793 if (!intransit)
41794 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
41795 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
41796 oidp, index, free, data);
41797 if (ret == -EAGAIN) {
41798 /* rare I think, but should cond_resched()??? */
41799 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
41800 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
41801 /* if we bug here, pamops wasn't properly set up for ramster */
41802 BUG_ON(tmem_pamops.replace_in_obj == NULL);
41803 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
41804 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
41805 out:
41806 spin_unlock(&hb->lock);
41807 return ret;
41808 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41809 if (free) {
41810 if (obj->pampd_count == 0) {
41811 tmem_obj_free(obj, hb);
41812 - (*tmem_hostops.obj_free)(obj, pool);
41813 + (tmem_hostops->obj_free)(obj, pool);
41814 obj = NULL;
41815 }
41816 }
41817 if (free)
41818 - ret = (*tmem_pamops.get_data_and_free)(
41819 + ret = (tmem_pamops->get_data_and_free)(
41820 data, sizep, raw, pampd, pool, oidp, index);
41821 else
41822 - ret = (*tmem_pamops.get_data)(
41823 + ret = (tmem_pamops->get_data)(
41824 data, sizep, raw, pampd, pool, oidp, index);
41825 if (ret < 0)
41826 goto out;
41827 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
41828 pampd = tmem_pampd_delete_from_obj(obj, index);
41829 if (pampd == NULL)
41830 goto out;
41831 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
41832 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
41833 if (obj->pampd_count == 0) {
41834 tmem_obj_free(obj, hb);
41835 - (*tmem_hostops.obj_free)(obj, pool);
41836 + (tmem_hostops->obj_free)(obj, pool);
41837 }
41838 ret = 0;
41839
41840 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
41841 goto out;
41842 tmem_pampd_destroy_all_in_obj(obj, false);
41843 tmem_obj_free(obj, hb);
41844 - (*tmem_hostops.obj_free)(obj, pool);
41845 + (tmem_hostops->obj_free)(obj, pool);
41846 ret = 0;
41847
41848 out:
41849 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
41850 index dc23395..cf7e9b1 100644
41851 --- a/drivers/staging/rtl8712/rtl871x_io.h
41852 +++ b/drivers/staging/rtl8712/rtl871x_io.h
41853 @@ -108,7 +108,7 @@ struct _io_ops {
41854 u8 *pmem);
41855 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
41856 u8 *pmem);
41857 -};
41858 +} __no_const;
41859
41860 struct io_req {
41861 struct list_head list;
41862 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
41863 index 1f5088b..0e59820 100644
41864 --- a/drivers/staging/sbe-2t3e3/netdev.c
41865 +++ b/drivers/staging/sbe-2t3e3/netdev.c
41866 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41867 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
41868
41869 if (rlen)
41870 - if (copy_to_user(data, &resp, rlen))
41871 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
41872 return -EFAULT;
41873
41874 return 0;
41875 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
41876 index 5dddc4d..34fcb2f 100644
41877 --- a/drivers/staging/usbip/vhci.h
41878 +++ b/drivers/staging/usbip/vhci.h
41879 @@ -83,7 +83,7 @@ struct vhci_hcd {
41880 unsigned resuming:1;
41881 unsigned long re_timeout;
41882
41883 - atomic_t seqnum;
41884 + atomic_unchecked_t seqnum;
41885
41886 /*
41887 * NOTE:
41888 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
41889 index c3aa219..bf8b3de 100644
41890 --- a/drivers/staging/usbip/vhci_hcd.c
41891 +++ b/drivers/staging/usbip/vhci_hcd.c
41892 @@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
41893 return;
41894 }
41895
41896 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
41897 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
41898 if (priv->seqnum == 0xffff)
41899 dev_info(&urb->dev->dev, "seqnum max\n");
41900
41901 @@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
41902 return -ENOMEM;
41903 }
41904
41905 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
41906 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
41907 if (unlink->seqnum == 0xffff)
41908 pr_info("seqnum max\n");
41909
41910 @@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
41911 vdev->rhport = rhport;
41912 }
41913
41914 - atomic_set(&vhci->seqnum, 0);
41915 + atomic_set_unchecked(&vhci->seqnum, 0);
41916 spin_lock_init(&vhci->lock);
41917
41918 hcd->power_budget = 0; /* no limit */
41919 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
41920 index ba5f1c0..11d8122 100644
41921 --- a/drivers/staging/usbip/vhci_rx.c
41922 +++ b/drivers/staging/usbip/vhci_rx.c
41923 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
41924 if (!urb) {
41925 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
41926 pr_info("max seqnum %d\n",
41927 - atomic_read(&the_controller->seqnum));
41928 + atomic_read_unchecked(&the_controller->seqnum));
41929 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
41930 return;
41931 }
41932 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
41933 index 5f13890..36a044b 100644
41934 --- a/drivers/staging/vt6655/hostap.c
41935 +++ b/drivers/staging/vt6655/hostap.c
41936 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
41937 *
41938 */
41939
41940 +static net_device_ops_no_const apdev_netdev_ops;
41941 +
41942 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
41943 {
41944 PSDevice apdev_priv;
41945 struct net_device *dev = pDevice->dev;
41946 int ret;
41947 - const struct net_device_ops apdev_netdev_ops = {
41948 - .ndo_start_xmit = pDevice->tx_80211,
41949 - };
41950
41951 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
41952
41953 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
41954 *apdev_priv = *pDevice;
41955 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
41956
41957 + /* only half broken now */
41958 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
41959 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
41960
41961 pDevice->apdev->type = ARPHRD_IEEE80211;
41962 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
41963 index 26a7d0e..897b083 100644
41964 --- a/drivers/staging/vt6656/hostap.c
41965 +++ b/drivers/staging/vt6656/hostap.c
41966 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
41967 *
41968 */
41969
41970 +static net_device_ops_no_const apdev_netdev_ops;
41971 +
41972 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
41973 {
41974 PSDevice apdev_priv;
41975 struct net_device *dev = pDevice->dev;
41976 int ret;
41977 - const struct net_device_ops apdev_netdev_ops = {
41978 - .ndo_start_xmit = pDevice->tx_80211,
41979 - };
41980
41981 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
41982
41983 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
41984 *apdev_priv = *pDevice;
41985 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
41986
41987 + /* only half broken now */
41988 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
41989 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
41990
41991 pDevice->apdev->type = ARPHRD_IEEE80211;
41992 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
41993 index 56c8e60..1920c63 100644
41994 --- a/drivers/staging/zcache/tmem.c
41995 +++ b/drivers/staging/zcache/tmem.c
41996 @@ -39,7 +39,7 @@
41997 * A tmem host implementation must use this function to register callbacks
41998 * for memory allocation.
41999 */
42000 -static struct tmem_hostops tmem_hostops;
42001 +static tmem_hostops_no_const tmem_hostops;
42002
42003 static void tmem_objnode_tree_init(void);
42004
42005 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
42006 * A tmem host implementation must use this function to register
42007 * callbacks for a page-accessible memory (PAM) implementation
42008 */
42009 -static struct tmem_pamops tmem_pamops;
42010 +static tmem_pamops_no_const tmem_pamops;
42011
42012 void tmem_register_pamops(struct tmem_pamops *m)
42013 {
42014 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
42015 index 0d4aa82..f7832d4 100644
42016 --- a/drivers/staging/zcache/tmem.h
42017 +++ b/drivers/staging/zcache/tmem.h
42018 @@ -180,6 +180,7 @@ struct tmem_pamops {
42019 void (*new_obj)(struct tmem_obj *);
42020 int (*replace_in_obj)(void *, struct tmem_obj *);
42021 };
42022 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
42023 extern void tmem_register_pamops(struct tmem_pamops *m);
42024
42025 /* memory allocation methods provided by the host implementation */
42026 @@ -189,6 +190,7 @@ struct tmem_hostops {
42027 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
42028 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
42029 };
42030 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
42031 extern void tmem_register_hostops(struct tmem_hostops *m);
42032
42033 /* core tmem accessor functions */
42034 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
42035 index 96f4981..4daaa7e 100644
42036 --- a/drivers/target/target_core_device.c
42037 +++ b/drivers/target/target_core_device.c
42038 @@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
42039 spin_lock_init(&dev->se_port_lock);
42040 spin_lock_init(&dev->se_tmr_lock);
42041 spin_lock_init(&dev->qf_cmd_lock);
42042 - atomic_set(&dev->dev_ordered_id, 0);
42043 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
42044 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
42045 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
42046 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
42047 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
42048 index bd587b7..173daf3 100644
42049 --- a/drivers/target/target_core_transport.c
42050 +++ b/drivers/target/target_core_transport.c
42051 @@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
42052 * Used to determine when ORDERED commands should go from
42053 * Dormant to Active status.
42054 */
42055 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
42056 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
42057 smp_mb__after_atomic_inc();
42058 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
42059 cmd->se_ordered_id, cmd->sam_task_attr,
42060 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
42061 index b09c8d1f..c4225c0 100644
42062 --- a/drivers/tty/cyclades.c
42063 +++ b/drivers/tty/cyclades.c
42064 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
42065 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
42066 info->port.count);
42067 #endif
42068 - info->port.count++;
42069 + atomic_inc(&info->port.count);
42070 #ifdef CY_DEBUG_COUNT
42071 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
42072 - current->pid, info->port.count);
42073 + current->pid, atomic_read(&info->port.count));
42074 #endif
42075
42076 /*
42077 @@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
42078 for (j = 0; j < cy_card[i].nports; j++) {
42079 info = &cy_card[i].ports[j];
42080
42081 - if (info->port.count) {
42082 + if (atomic_read(&info->port.count)) {
42083 /* XXX is the ldisc num worth this? */
42084 struct tty_struct *tty;
42085 struct tty_ldisc *ld;
42086 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
42087 index 13ee53b..418d164 100644
42088 --- a/drivers/tty/hvc/hvc_console.c
42089 +++ b/drivers/tty/hvc/hvc_console.c
42090 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
42091
42092 spin_lock_irqsave(&hp->port.lock, flags);
42093 /* Check and then increment for fast path open. */
42094 - if (hp->port.count++ > 0) {
42095 + if (atomic_inc_return(&hp->port.count) > 1) {
42096 spin_unlock_irqrestore(&hp->port.lock, flags);
42097 hvc_kick();
42098 return 0;
42099 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42100
42101 spin_lock_irqsave(&hp->port.lock, flags);
42102
42103 - if (--hp->port.count == 0) {
42104 + if (atomic_dec_return(&hp->port.count) == 0) {
42105 spin_unlock_irqrestore(&hp->port.lock, flags);
42106 /* We are done with the tty pointer now. */
42107 tty_port_tty_set(&hp->port, NULL);
42108 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42109 */
42110 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
42111 } else {
42112 - if (hp->port.count < 0)
42113 + if (atomic_read(&hp->port.count) < 0)
42114 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
42115 - hp->vtermno, hp->port.count);
42116 + hp->vtermno, atomic_read(&hp->port.count));
42117 spin_unlock_irqrestore(&hp->port.lock, flags);
42118 }
42119 }
42120 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
42121 * open->hangup case this can be called after the final close so prevent
42122 * that from happening for now.
42123 */
42124 - if (hp->port.count <= 0) {
42125 + if (atomic_read(&hp->port.count) <= 0) {
42126 spin_unlock_irqrestore(&hp->port.lock, flags);
42127 return;
42128 }
42129
42130 - hp->port.count = 0;
42131 + atomic_set(&hp->port.count, 0);
42132 spin_unlock_irqrestore(&hp->port.lock, flags);
42133 tty_port_tty_set(&hp->port, NULL);
42134
42135 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
42136 return -EPIPE;
42137
42138 /* FIXME what's this (unprotected) check for? */
42139 - if (hp->port.count <= 0)
42140 + if (atomic_read(&hp->port.count) <= 0)
42141 return -EIO;
42142
42143 spin_lock_irqsave(&hp->lock, flags);
42144 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
42145 index 8776357..b2d4afd 100644
42146 --- a/drivers/tty/hvc/hvcs.c
42147 +++ b/drivers/tty/hvc/hvcs.c
42148 @@ -83,6 +83,7 @@
42149 #include <asm/hvcserver.h>
42150 #include <asm/uaccess.h>
42151 #include <asm/vio.h>
42152 +#include <asm/local.h>
42153
42154 /*
42155 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
42156 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
42157
42158 spin_lock_irqsave(&hvcsd->lock, flags);
42159
42160 - if (hvcsd->port.count > 0) {
42161 + if (atomic_read(&hvcsd->port.count) > 0) {
42162 spin_unlock_irqrestore(&hvcsd->lock, flags);
42163 printk(KERN_INFO "HVCS: vterm state unchanged. "
42164 "The hvcs device node is still in use.\n");
42165 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
42166 }
42167 }
42168
42169 - hvcsd->port.count = 0;
42170 + atomic_set(&hvcsd->port.count, 0);
42171 hvcsd->port.tty = tty;
42172 tty->driver_data = hvcsd;
42173
42174 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
42175 unsigned long flags;
42176
42177 spin_lock_irqsave(&hvcsd->lock, flags);
42178 - hvcsd->port.count++;
42179 + atomic_inc(&hvcsd->port.count);
42180 hvcsd->todo_mask |= HVCS_SCHED_READ;
42181 spin_unlock_irqrestore(&hvcsd->lock, flags);
42182
42183 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42184 hvcsd = tty->driver_data;
42185
42186 spin_lock_irqsave(&hvcsd->lock, flags);
42187 - if (--hvcsd->port.count == 0) {
42188 + if (atomic_dec_and_test(&hvcsd->port.count)) {
42189
42190 vio_disable_interrupts(hvcsd->vdev);
42191
42192 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42193
42194 free_irq(irq, hvcsd);
42195 return;
42196 - } else if (hvcsd->port.count < 0) {
42197 + } else if (atomic_read(&hvcsd->port.count) < 0) {
42198 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
42199 " is missmanaged.\n",
42200 - hvcsd->vdev->unit_address, hvcsd->port.count);
42201 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
42202 }
42203
42204 spin_unlock_irqrestore(&hvcsd->lock, flags);
42205 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42206
42207 spin_lock_irqsave(&hvcsd->lock, flags);
42208 /* Preserve this so that we know how many kref refs to put */
42209 - temp_open_count = hvcsd->port.count;
42210 + temp_open_count = atomic_read(&hvcsd->port.count);
42211
42212 /*
42213 * Don't kref put inside the spinlock because the destruction
42214 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42215 tty->driver_data = NULL;
42216 hvcsd->port.tty = NULL;
42217
42218 - hvcsd->port.count = 0;
42219 + atomic_set(&hvcsd->port.count, 0);
42220
42221 /* This will drop any buffered data on the floor which is OK in a hangup
42222 * scenario. */
42223 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
42224 * the middle of a write operation? This is a crummy place to do this
42225 * but we want to keep it all in the spinlock.
42226 */
42227 - if (hvcsd->port.count <= 0) {
42228 + if (atomic_read(&hvcsd->port.count) <= 0) {
42229 spin_unlock_irqrestore(&hvcsd->lock, flags);
42230 return -ENODEV;
42231 }
42232 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
42233 {
42234 struct hvcs_struct *hvcsd = tty->driver_data;
42235
42236 - if (!hvcsd || hvcsd->port.count <= 0)
42237 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
42238 return 0;
42239
42240 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
42241 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
42242 index 2cde13d..645d78f 100644
42243 --- a/drivers/tty/ipwireless/tty.c
42244 +++ b/drivers/tty/ipwireless/tty.c
42245 @@ -29,6 +29,7 @@
42246 #include <linux/tty_driver.h>
42247 #include <linux/tty_flip.h>
42248 #include <linux/uaccess.h>
42249 +#include <asm/local.h>
42250
42251 #include "tty.h"
42252 #include "network.h"
42253 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42254 mutex_unlock(&tty->ipw_tty_mutex);
42255 return -ENODEV;
42256 }
42257 - if (tty->port.count == 0)
42258 + if (atomic_read(&tty->port.count) == 0)
42259 tty->tx_bytes_queued = 0;
42260
42261 - tty->port.count++;
42262 + atomic_inc(&tty->port.count);
42263
42264 tty->port.tty = linux_tty;
42265 linux_tty->driver_data = tty;
42266 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42267
42268 static void do_ipw_close(struct ipw_tty *tty)
42269 {
42270 - tty->port.count--;
42271 -
42272 - if (tty->port.count == 0) {
42273 + if (atomic_dec_return(&tty->port.count) == 0) {
42274 struct tty_struct *linux_tty = tty->port.tty;
42275
42276 if (linux_tty != NULL) {
42277 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
42278 return;
42279
42280 mutex_lock(&tty->ipw_tty_mutex);
42281 - if (tty->port.count == 0) {
42282 + if (atomic_read(&tty->port.count) == 0) {
42283 mutex_unlock(&tty->ipw_tty_mutex);
42284 return;
42285 }
42286 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
42287 return;
42288 }
42289
42290 - if (!tty->port.count) {
42291 + if (!atomic_read(&tty->port.count)) {
42292 mutex_unlock(&tty->ipw_tty_mutex);
42293 return;
42294 }
42295 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
42296 return -ENODEV;
42297
42298 mutex_lock(&tty->ipw_tty_mutex);
42299 - if (!tty->port.count) {
42300 + if (!atomic_read(&tty->port.count)) {
42301 mutex_unlock(&tty->ipw_tty_mutex);
42302 return -EINVAL;
42303 }
42304 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
42305 if (!tty)
42306 return -ENODEV;
42307
42308 - if (!tty->port.count)
42309 + if (!atomic_read(&tty->port.count))
42310 return -EINVAL;
42311
42312 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
42313 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
42314 if (!tty)
42315 return 0;
42316
42317 - if (!tty->port.count)
42318 + if (!atomic_read(&tty->port.count))
42319 return 0;
42320
42321 return tty->tx_bytes_queued;
42322 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
42323 if (!tty)
42324 return -ENODEV;
42325
42326 - if (!tty->port.count)
42327 + if (!atomic_read(&tty->port.count))
42328 return -EINVAL;
42329
42330 return get_control_lines(tty);
42331 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
42332 if (!tty)
42333 return -ENODEV;
42334
42335 - if (!tty->port.count)
42336 + if (!atomic_read(&tty->port.count))
42337 return -EINVAL;
42338
42339 return set_control_lines(tty, set, clear);
42340 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
42341 if (!tty)
42342 return -ENODEV;
42343
42344 - if (!tty->port.count)
42345 + if (!atomic_read(&tty->port.count))
42346 return -EINVAL;
42347
42348 /* FIXME: Exactly how is the tty object locked here .. */
42349 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
42350 * are gone */
42351 mutex_lock(&ttyj->ipw_tty_mutex);
42352 }
42353 - while (ttyj->port.count)
42354 + while (atomic_read(&ttyj->port.count))
42355 do_ipw_close(ttyj);
42356 ipwireless_disassociate_network_ttys(network,
42357 ttyj->channel_idx);
42358 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
42359 index f9d2850..b006f04 100644
42360 --- a/drivers/tty/moxa.c
42361 +++ b/drivers/tty/moxa.c
42362 @@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
42363 }
42364
42365 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
42366 - ch->port.count++;
42367 + atomic_inc(&ch->port.count);
42368 tty->driver_data = ch;
42369 tty_port_tty_set(&ch->port, tty);
42370 mutex_lock(&ch->port.mutex);
42371 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
42372 index bfd6771..e0d93c4 100644
42373 --- a/drivers/tty/n_gsm.c
42374 +++ b/drivers/tty/n_gsm.c
42375 @@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
42376 spin_lock_init(&dlci->lock);
42377 mutex_init(&dlci->mutex);
42378 dlci->fifo = &dlci->_fifo;
42379 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
42380 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
42381 kfree(dlci);
42382 return NULL;
42383 }
42384 @@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
42385 struct gsm_dlci *dlci = tty->driver_data;
42386 struct tty_port *port = &dlci->port;
42387
42388 - port->count++;
42389 + atomic_inc(&port->count);
42390 dlci_get(dlci);
42391 dlci_get(dlci->gsm->dlci[0]);
42392 mux_get(dlci->gsm);
42393 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
42394 index 19083ef..6e34e97 100644
42395 --- a/drivers/tty/n_tty.c
42396 +++ b/drivers/tty/n_tty.c
42397 @@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
42398 {
42399 *ops = tty_ldisc_N_TTY;
42400 ops->owner = NULL;
42401 - ops->refcount = ops->flags = 0;
42402 + atomic_set(&ops->refcount, 0);
42403 + ops->flags = 0;
42404 }
42405 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
42406 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
42407 index 79ff3a5..1fe9399 100644
42408 --- a/drivers/tty/pty.c
42409 +++ b/drivers/tty/pty.c
42410 @@ -791,8 +791,10 @@ static void __init unix98_pty_init(void)
42411 panic("Couldn't register Unix98 pts driver");
42412
42413 /* Now create the /dev/ptmx special device */
42414 + pax_open_kernel();
42415 tty_default_fops(&ptmx_fops);
42416 - ptmx_fops.open = ptmx_open;
42417 + *(void **)&ptmx_fops.open = ptmx_open;
42418 + pax_close_kernel();
42419
42420 cdev_init(&ptmx_cdev, &ptmx_fops);
42421 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
42422 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
42423 index e42009a..566a036 100644
42424 --- a/drivers/tty/rocket.c
42425 +++ b/drivers/tty/rocket.c
42426 @@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42427 tty->driver_data = info;
42428 tty_port_tty_set(port, tty);
42429
42430 - if (port->count++ == 0) {
42431 + if (atomic_inc_return(&port->count) == 1) {
42432 atomic_inc(&rp_num_ports_open);
42433
42434 #ifdef ROCKET_DEBUG_OPEN
42435 @@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42436 #endif
42437 }
42438 #ifdef ROCKET_DEBUG_OPEN
42439 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
42440 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
42441 #endif
42442
42443 /*
42444 @@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
42445 spin_unlock_irqrestore(&info->port.lock, flags);
42446 return;
42447 }
42448 - if (info->port.count)
42449 + if (atomic_read(&info->port.count))
42450 atomic_dec(&rp_num_ports_open);
42451 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
42452 spin_unlock_irqrestore(&info->port.lock, flags);
42453 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
42454 index 1002054..dd644a8 100644
42455 --- a/drivers/tty/serial/kgdboc.c
42456 +++ b/drivers/tty/serial/kgdboc.c
42457 @@ -24,8 +24,9 @@
42458 #define MAX_CONFIG_LEN 40
42459
42460 static struct kgdb_io kgdboc_io_ops;
42461 +static struct kgdb_io kgdboc_io_ops_console;
42462
42463 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
42464 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
42465 static int configured = -1;
42466
42467 static char config[MAX_CONFIG_LEN];
42468 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
42469 kgdboc_unregister_kbd();
42470 if (configured == 1)
42471 kgdb_unregister_io_module(&kgdboc_io_ops);
42472 + else if (configured == 2)
42473 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
42474 }
42475
42476 static int configure_kgdboc(void)
42477 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
42478 int err;
42479 char *cptr = config;
42480 struct console *cons;
42481 + int is_console = 0;
42482
42483 err = kgdboc_option_setup(config);
42484 if (err || !strlen(config) || isspace(config[0]))
42485 goto noconfig;
42486
42487 err = -ENODEV;
42488 - kgdboc_io_ops.is_console = 0;
42489 kgdb_tty_driver = NULL;
42490
42491 kgdboc_use_kms = 0;
42492 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
42493 int idx;
42494 if (cons->device && cons->device(cons, &idx) == p &&
42495 idx == tty_line) {
42496 - kgdboc_io_ops.is_console = 1;
42497 + is_console = 1;
42498 break;
42499 }
42500 cons = cons->next;
42501 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
42502 kgdb_tty_line = tty_line;
42503
42504 do_register:
42505 - err = kgdb_register_io_module(&kgdboc_io_ops);
42506 + if (is_console) {
42507 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
42508 + configured = 2;
42509 + } else {
42510 + err = kgdb_register_io_module(&kgdboc_io_ops);
42511 + configured = 1;
42512 + }
42513 if (err)
42514 goto noconfig;
42515
42516 @@ -205,8 +214,6 @@ do_register:
42517 if (err)
42518 goto nmi_con_failed;
42519
42520 - configured = 1;
42521 -
42522 return 0;
42523
42524 nmi_con_failed:
42525 @@ -223,7 +230,7 @@ noconfig:
42526 static int __init init_kgdboc(void)
42527 {
42528 /* Already configured? */
42529 - if (configured == 1)
42530 + if (configured >= 1)
42531 return 0;
42532
42533 return configure_kgdboc();
42534 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
42535 if (config[len - 1] == '\n')
42536 config[len - 1] = '\0';
42537
42538 - if (configured == 1)
42539 + if (configured >= 1)
42540 cleanup_kgdboc();
42541
42542 /* Go and configure with the new params. */
42543 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
42544 .post_exception = kgdboc_post_exp_handler,
42545 };
42546
42547 +static struct kgdb_io kgdboc_io_ops_console = {
42548 + .name = "kgdboc",
42549 + .read_char = kgdboc_get_char,
42550 + .write_char = kgdboc_put_char,
42551 + .pre_exception = kgdboc_pre_exp_handler,
42552 + .post_exception = kgdboc_post_exp_handler,
42553 + .is_console = 1
42554 +};
42555 +
42556 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
42557 /* This is only available if kgdboc is a built in for early debugging */
42558 static int __init kgdboc_early_init(char *opt)
42559 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
42560 index e514b3a..c73d614 100644
42561 --- a/drivers/tty/serial/samsung.c
42562 +++ b/drivers/tty/serial/samsung.c
42563 @@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
42564 }
42565 }
42566
42567 +static int s3c64xx_serial_startup(struct uart_port *port);
42568 static int s3c24xx_serial_startup(struct uart_port *port)
42569 {
42570 struct s3c24xx_uart_port *ourport = to_ourport(port);
42571 int ret;
42572
42573 + /* Startup sequence is different for s3c64xx and higher SoC's */
42574 + if (s3c24xx_serial_has_interrupt_mask(port))
42575 + return s3c64xx_serial_startup(port);
42576 +
42577 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
42578 port->mapbase, port->membase);
42579
42580 @@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
42581 /* setup info for port */
42582 port->dev = &platdev->dev;
42583
42584 - /* Startup sequence is different for s3c64xx and higher SoC's */
42585 - if (s3c24xx_serial_has_interrupt_mask(port))
42586 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
42587 -
42588 port->uartclk = 1;
42589
42590 if (cfg->uart_flags & UPF_CONS_FLOW) {
42591 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
42592 index 2c7230a..2104f16 100644
42593 --- a/drivers/tty/serial/serial_core.c
42594 +++ b/drivers/tty/serial/serial_core.c
42595 @@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
42596 uart_flush_buffer(tty);
42597 uart_shutdown(tty, state);
42598 spin_lock_irqsave(&port->lock, flags);
42599 - port->count = 0;
42600 + atomic_set(&port->count, 0);
42601 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
42602 spin_unlock_irqrestore(&port->lock, flags);
42603 tty_port_tty_set(port, NULL);
42604 @@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
42605 goto end;
42606 }
42607
42608 - port->count++;
42609 + atomic_inc(&port->count);
42610 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
42611 retval = -ENXIO;
42612 goto err_dec_count;
42613 @@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
42614 /*
42615 * Make sure the device is in D0 state.
42616 */
42617 - if (port->count == 1)
42618 + if (atomic_read(&port->count) == 1)
42619 uart_change_pm(state, 0);
42620
42621 /*
42622 @@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
42623 end:
42624 return retval;
42625 err_dec_count:
42626 - port->count--;
42627 + atomic_inc(&port->count);
42628 mutex_unlock(&port->mutex);
42629 goto end;
42630 }
42631 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
42632 index 9e071f6..f30ae69 100644
42633 --- a/drivers/tty/synclink.c
42634 +++ b/drivers/tty/synclink.c
42635 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
42636
42637 if (debug_level >= DEBUG_LEVEL_INFO)
42638 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
42639 - __FILE__,__LINE__, info->device_name, info->port.count);
42640 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
42641
42642 if (tty_port_close_start(&info->port, tty, filp) == 0)
42643 goto cleanup;
42644 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
42645 cleanup:
42646 if (debug_level >= DEBUG_LEVEL_INFO)
42647 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
42648 - tty->driver->name, info->port.count);
42649 + tty->driver->name, atomic_read(&info->port.count));
42650
42651 } /* end of mgsl_close() */
42652
42653 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
42654
42655 mgsl_flush_buffer(tty);
42656 shutdown(info);
42657 -
42658 - info->port.count = 0;
42659 +
42660 + atomic_set(&info->port.count, 0);
42661 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
42662 info->port.tty = NULL;
42663
42664 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
42665
42666 if (debug_level >= DEBUG_LEVEL_INFO)
42667 printk("%s(%d):block_til_ready before block on %s count=%d\n",
42668 - __FILE__,__LINE__, tty->driver->name, port->count );
42669 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
42670
42671 spin_lock_irqsave(&info->irq_spinlock, flags);
42672 if (!tty_hung_up_p(filp)) {
42673 extra_count = true;
42674 - port->count--;
42675 + atomic_dec(&port->count);
42676 }
42677 spin_unlock_irqrestore(&info->irq_spinlock, flags);
42678 port->blocked_open++;
42679 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
42680
42681 if (debug_level >= DEBUG_LEVEL_INFO)
42682 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
42683 - __FILE__,__LINE__, tty->driver->name, port->count );
42684 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
42685
42686 tty_unlock(tty);
42687 schedule();
42688 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
42689
42690 /* FIXME: Racy on hangup during close wait */
42691 if (extra_count)
42692 - port->count++;
42693 + atomic_inc(&port->count);
42694 port->blocked_open--;
42695
42696 if (debug_level >= DEBUG_LEVEL_INFO)
42697 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
42698 - __FILE__,__LINE__, tty->driver->name, port->count );
42699 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
42700
42701 if (!retval)
42702 port->flags |= ASYNC_NORMAL_ACTIVE;
42703 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
42704
42705 if (debug_level >= DEBUG_LEVEL_INFO)
42706 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
42707 - __FILE__,__LINE__,tty->driver->name, info->port.count);
42708 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
42709
42710 /* If port is closing, signal caller to try again */
42711 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
42712 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
42713 spin_unlock_irqrestore(&info->netlock, flags);
42714 goto cleanup;
42715 }
42716 - info->port.count++;
42717 + atomic_inc(&info->port.count);
42718 spin_unlock_irqrestore(&info->netlock, flags);
42719
42720 - if (info->port.count == 1) {
42721 + if (atomic_read(&info->port.count) == 1) {
42722 /* 1st open on this device, init hardware */
42723 retval = startup(info);
42724 if (retval < 0)
42725 @@ -3451,8 +3451,8 @@ cleanup:
42726 if (retval) {
42727 if (tty->count == 1)
42728 info->port.tty = NULL; /* tty layer will release tty struct */
42729 - if(info->port.count)
42730 - info->port.count--;
42731 + if (atomic_read(&info->port.count))
42732 + atomic_dec(&info->port.count);
42733 }
42734
42735 return retval;
42736 @@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
42737 unsigned short new_crctype;
42738
42739 /* return error if TTY interface open */
42740 - if (info->port.count)
42741 + if (atomic_read(&info->port.count))
42742 return -EBUSY;
42743
42744 switch (encoding)
42745 @@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
42746
42747 /* arbitrate between network and tty opens */
42748 spin_lock_irqsave(&info->netlock, flags);
42749 - if (info->port.count != 0 || info->netcount != 0) {
42750 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
42751 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
42752 spin_unlock_irqrestore(&info->netlock, flags);
42753 return -EBUSY;
42754 @@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42755 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
42756
42757 /* return error if TTY interface open */
42758 - if (info->port.count)
42759 + if (atomic_read(&info->port.count))
42760 return -EBUSY;
42761
42762 if (cmd != SIOCWANDEV)
42763 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
42764 index aba1e59..877ac33 100644
42765 --- a/drivers/tty/synclink_gt.c
42766 +++ b/drivers/tty/synclink_gt.c
42767 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
42768 tty->driver_data = info;
42769 info->port.tty = tty;
42770
42771 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
42772 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
42773
42774 /* If port is closing, signal caller to try again */
42775 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
42776 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
42777 mutex_unlock(&info->port.mutex);
42778 goto cleanup;
42779 }
42780 - info->port.count++;
42781 + atomic_inc(&info->port.count);
42782 spin_unlock_irqrestore(&info->netlock, flags);
42783
42784 - if (info->port.count == 1) {
42785 + if (atomic_read(&info->port.count) == 1) {
42786 /* 1st open on this device, init hardware */
42787 retval = startup(info);
42788 if (retval < 0) {
42789 @@ -716,8 +716,8 @@ cleanup:
42790 if (retval) {
42791 if (tty->count == 1)
42792 info->port.tty = NULL; /* tty layer will release tty struct */
42793 - if(info->port.count)
42794 - info->port.count--;
42795 + if(atomic_read(&info->port.count))
42796 + atomic_dec(&info->port.count);
42797 }
42798
42799 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
42800 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
42801
42802 if (sanity_check(info, tty->name, "close"))
42803 return;
42804 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
42805 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
42806
42807 if (tty_port_close_start(&info->port, tty, filp) == 0)
42808 goto cleanup;
42809 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
42810 tty_port_close_end(&info->port, tty);
42811 info->port.tty = NULL;
42812 cleanup:
42813 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
42814 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
42815 }
42816
42817 static void hangup(struct tty_struct *tty)
42818 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
42819 shutdown(info);
42820
42821 spin_lock_irqsave(&info->port.lock, flags);
42822 - info->port.count = 0;
42823 + atomic_set(&info->port.count, 0);
42824 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
42825 info->port.tty = NULL;
42826 spin_unlock_irqrestore(&info->port.lock, flags);
42827 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
42828 unsigned short new_crctype;
42829
42830 /* return error if TTY interface open */
42831 - if (info->port.count)
42832 + if (atomic_read(&info->port.count))
42833 return -EBUSY;
42834
42835 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
42836 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
42837
42838 /* arbitrate between network and tty opens */
42839 spin_lock_irqsave(&info->netlock, flags);
42840 - if (info->port.count != 0 || info->netcount != 0) {
42841 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
42842 DBGINFO(("%s hdlc_open busy\n", dev->name));
42843 spin_unlock_irqrestore(&info->netlock, flags);
42844 return -EBUSY;
42845 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42846 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
42847
42848 /* return error if TTY interface open */
42849 - if (info->port.count)
42850 + if (atomic_read(&info->port.count))
42851 return -EBUSY;
42852
42853 if (cmd != SIOCWANDEV)
42854 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
42855 if (port == NULL)
42856 continue;
42857 spin_lock(&port->lock);
42858 - if ((port->port.count || port->netcount) &&
42859 + if ((atomic_read(&port->port.count) || port->netcount) &&
42860 port->pending_bh && !port->bh_running &&
42861 !port->bh_requested) {
42862 DBGISR(("%s bh queued\n", port->device_name));
42863 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
42864 spin_lock_irqsave(&info->lock, flags);
42865 if (!tty_hung_up_p(filp)) {
42866 extra_count = true;
42867 - port->count--;
42868 + atomic_dec(&port->count);
42869 }
42870 spin_unlock_irqrestore(&info->lock, flags);
42871 port->blocked_open++;
42872 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
42873 remove_wait_queue(&port->open_wait, &wait);
42874
42875 if (extra_count)
42876 - port->count++;
42877 + atomic_inc(&port->count);
42878 port->blocked_open--;
42879
42880 if (!retval)
42881 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
42882 index fd43fb6..34704ad 100644
42883 --- a/drivers/tty/synclinkmp.c
42884 +++ b/drivers/tty/synclinkmp.c
42885 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
42886
42887 if (debug_level >= DEBUG_LEVEL_INFO)
42888 printk("%s(%d):%s open(), old ref count = %d\n",
42889 - __FILE__,__LINE__,tty->driver->name, info->port.count);
42890 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
42891
42892 /* If port is closing, signal caller to try again */
42893 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
42894 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
42895 spin_unlock_irqrestore(&info->netlock, flags);
42896 goto cleanup;
42897 }
42898 - info->port.count++;
42899 + atomic_inc(&info->port.count);
42900 spin_unlock_irqrestore(&info->netlock, flags);
42901
42902 - if (info->port.count == 1) {
42903 + if (atomic_read(&info->port.count) == 1) {
42904 /* 1st open on this device, init hardware */
42905 retval = startup(info);
42906 if (retval < 0)
42907 @@ -797,8 +797,8 @@ cleanup:
42908 if (retval) {
42909 if (tty->count == 1)
42910 info->port.tty = NULL; /* tty layer will release tty struct */
42911 - if(info->port.count)
42912 - info->port.count--;
42913 + if(atomic_read(&info->port.count))
42914 + atomic_dec(&info->port.count);
42915 }
42916
42917 return retval;
42918 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
42919
42920 if (debug_level >= DEBUG_LEVEL_INFO)
42921 printk("%s(%d):%s close() entry, count=%d\n",
42922 - __FILE__,__LINE__, info->device_name, info->port.count);
42923 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
42924
42925 if (tty_port_close_start(&info->port, tty, filp) == 0)
42926 goto cleanup;
42927 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
42928 cleanup:
42929 if (debug_level >= DEBUG_LEVEL_INFO)
42930 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
42931 - tty->driver->name, info->port.count);
42932 + tty->driver->name, atomic_read(&info->port.count));
42933 }
42934
42935 /* Called by tty_hangup() when a hangup is signaled.
42936 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
42937 shutdown(info);
42938
42939 spin_lock_irqsave(&info->port.lock, flags);
42940 - info->port.count = 0;
42941 + atomic_set(&info->port.count, 0);
42942 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
42943 info->port.tty = NULL;
42944 spin_unlock_irqrestore(&info->port.lock, flags);
42945 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
42946 unsigned short new_crctype;
42947
42948 /* return error if TTY interface open */
42949 - if (info->port.count)
42950 + if (atomic_read(&info->port.count))
42951 return -EBUSY;
42952
42953 switch (encoding)
42954 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
42955
42956 /* arbitrate between network and tty opens */
42957 spin_lock_irqsave(&info->netlock, flags);
42958 - if (info->port.count != 0 || info->netcount != 0) {
42959 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
42960 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
42961 spin_unlock_irqrestore(&info->netlock, flags);
42962 return -EBUSY;
42963 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42964 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
42965
42966 /* return error if TTY interface open */
42967 - if (info->port.count)
42968 + if (atomic_read(&info->port.count))
42969 return -EBUSY;
42970
42971 if (cmd != SIOCWANDEV)
42972 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
42973 * do not request bottom half processing if the
42974 * device is not open in a normal mode.
42975 */
42976 - if ( port && (port->port.count || port->netcount) &&
42977 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
42978 port->pending_bh && !port->bh_running &&
42979 !port->bh_requested ) {
42980 if ( debug_level >= DEBUG_LEVEL_ISR )
42981 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
42982
42983 if (debug_level >= DEBUG_LEVEL_INFO)
42984 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
42985 - __FILE__,__LINE__, tty->driver->name, port->count );
42986 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
42987
42988 spin_lock_irqsave(&info->lock, flags);
42989 if (!tty_hung_up_p(filp)) {
42990 extra_count = true;
42991 - port->count--;
42992 + atomic_dec(&port->count);
42993 }
42994 spin_unlock_irqrestore(&info->lock, flags);
42995 port->blocked_open++;
42996 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
42997
42998 if (debug_level >= DEBUG_LEVEL_INFO)
42999 printk("%s(%d):%s block_til_ready() count=%d\n",
43000 - __FILE__,__LINE__, tty->driver->name, port->count );
43001 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43002
43003 tty_unlock(tty);
43004 schedule();
43005 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43006 remove_wait_queue(&port->open_wait, &wait);
43007
43008 if (extra_count)
43009 - port->count++;
43010 + atomic_inc(&port->count);
43011 port->blocked_open--;
43012
43013 if (debug_level >= DEBUG_LEVEL_INFO)
43014 printk("%s(%d):%s block_til_ready() after, count=%d\n",
43015 - __FILE__,__LINE__, tty->driver->name, port->count );
43016 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43017
43018 if (!retval)
43019 port->flags |= ASYNC_NORMAL_ACTIVE;
43020 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
43021 index b3c4a25..723916f 100644
43022 --- a/drivers/tty/sysrq.c
43023 +++ b/drivers/tty/sysrq.c
43024 @@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
43025 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
43026 size_t count, loff_t *ppos)
43027 {
43028 - if (count) {
43029 + if (count && capable(CAP_SYS_ADMIN)) {
43030 char c;
43031
43032 if (get_user(c, buf))
43033 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
43034 index da9fde8..c07975f 100644
43035 --- a/drivers/tty/tty_io.c
43036 +++ b/drivers/tty/tty_io.c
43037 @@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
43038
43039 void tty_default_fops(struct file_operations *fops)
43040 {
43041 - *fops = tty_fops;
43042 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
43043 }
43044
43045 /*
43046 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
43047 index c578229..45aa9ee 100644
43048 --- a/drivers/tty/tty_ldisc.c
43049 +++ b/drivers/tty/tty_ldisc.c
43050 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
43051 if (atomic_dec_and_test(&ld->users)) {
43052 struct tty_ldisc_ops *ldo = ld->ops;
43053
43054 - ldo->refcount--;
43055 + atomic_dec(&ldo->refcount);
43056 module_put(ldo->owner);
43057 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43058
43059 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
43060 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43061 tty_ldiscs[disc] = new_ldisc;
43062 new_ldisc->num = disc;
43063 - new_ldisc->refcount = 0;
43064 + atomic_set(&new_ldisc->refcount, 0);
43065 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43066
43067 return ret;
43068 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
43069 return -EINVAL;
43070
43071 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43072 - if (tty_ldiscs[disc]->refcount)
43073 + if (atomic_read(&tty_ldiscs[disc]->refcount))
43074 ret = -EBUSY;
43075 else
43076 tty_ldiscs[disc] = NULL;
43077 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
43078 if (ldops) {
43079 ret = ERR_PTR(-EAGAIN);
43080 if (try_module_get(ldops->owner)) {
43081 - ldops->refcount++;
43082 + atomic_inc(&ldops->refcount);
43083 ret = ldops;
43084 }
43085 }
43086 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
43087 unsigned long flags;
43088
43089 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43090 - ldops->refcount--;
43091 + atomic_dec(&ldops->refcount);
43092 module_put(ldops->owner);
43093 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43094 }
43095 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
43096 index b7ff59d..7c6105e 100644
43097 --- a/drivers/tty/tty_port.c
43098 +++ b/drivers/tty/tty_port.c
43099 @@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
43100 unsigned long flags;
43101
43102 spin_lock_irqsave(&port->lock, flags);
43103 - port->count = 0;
43104 + atomic_set(&port->count, 0);
43105 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43106 if (port->tty) {
43107 set_bit(TTY_IO_ERROR, &port->tty->flags);
43108 @@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43109 /* The port lock protects the port counts */
43110 spin_lock_irqsave(&port->lock, flags);
43111 if (!tty_hung_up_p(filp))
43112 - port->count--;
43113 + atomic_dec(&port->count);
43114 port->blocked_open++;
43115 spin_unlock_irqrestore(&port->lock, flags);
43116
43117 @@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43118 we must not mess that up further */
43119 spin_lock_irqsave(&port->lock, flags);
43120 if (!tty_hung_up_p(filp))
43121 - port->count++;
43122 + atomic_inc(&port->count);
43123 port->blocked_open--;
43124 if (retval == 0)
43125 port->flags |= ASYNC_NORMAL_ACTIVE;
43126 @@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
43127 return 0;
43128 }
43129
43130 - if (tty->count == 1 && port->count != 1) {
43131 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
43132 printk(KERN_WARNING
43133 "tty_port_close_start: tty->count = 1 port count = %d.\n",
43134 - port->count);
43135 - port->count = 1;
43136 + atomic_read(&port->count));
43137 + atomic_set(&port->count, 1);
43138 }
43139 - if (--port->count < 0) {
43140 + if (atomic_dec_return(&port->count) < 0) {
43141 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
43142 - port->count);
43143 - port->count = 0;
43144 + atomic_read(&port->count));
43145 + atomic_set(&port->count, 0);
43146 }
43147
43148 - if (port->count) {
43149 + if (atomic_read(&port->count)) {
43150 spin_unlock_irqrestore(&port->lock, flags);
43151 if (port->ops->drop)
43152 port->ops->drop(port);
43153 @@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
43154 {
43155 spin_lock_irq(&port->lock);
43156 if (!tty_hung_up_p(filp))
43157 - ++port->count;
43158 + atomic_inc(&port->count);
43159 spin_unlock_irq(&port->lock);
43160 tty_port_tty_set(port, tty);
43161
43162 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
43163 index 681765b..d3ccdf2 100644
43164 --- a/drivers/tty/vt/keyboard.c
43165 +++ b/drivers/tty/vt/keyboard.c
43166 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
43167 kbd->kbdmode == VC_OFF) &&
43168 value != KVAL(K_SAK))
43169 return; /* SAK is allowed even in raw mode */
43170 +
43171 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
43172 + {
43173 + void *func = fn_handler[value];
43174 + if (func == fn_show_state || func == fn_show_ptregs ||
43175 + func == fn_show_mem)
43176 + return;
43177 + }
43178 +#endif
43179 +
43180 fn_handler[value](vc);
43181 }
43182
43183 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43184 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
43185 return -EFAULT;
43186
43187 - if (!capable(CAP_SYS_TTY_CONFIG))
43188 - perm = 0;
43189 -
43190 switch (cmd) {
43191 case KDGKBENT:
43192 /* Ensure another thread doesn't free it under us */
43193 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43194 spin_unlock_irqrestore(&kbd_event_lock, flags);
43195 return put_user(val, &user_kbe->kb_value);
43196 case KDSKBENT:
43197 + if (!capable(CAP_SYS_TTY_CONFIG))
43198 + perm = 0;
43199 +
43200 if (!perm)
43201 return -EPERM;
43202 if (!i && v == K_NOSUCHMAP) {
43203 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43204 int i, j, k;
43205 int ret;
43206
43207 - if (!capable(CAP_SYS_TTY_CONFIG))
43208 - perm = 0;
43209 -
43210 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
43211 if (!kbs) {
43212 ret = -ENOMEM;
43213 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43214 kfree(kbs);
43215 return ((p && *p) ? -EOVERFLOW : 0);
43216 case KDSKBSENT:
43217 + if (!capable(CAP_SYS_TTY_CONFIG))
43218 + perm = 0;
43219 +
43220 if (!perm) {
43221 ret = -EPERM;
43222 goto reterr;
43223 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
43224 index 5110f36..8dc0a74 100644
43225 --- a/drivers/uio/uio.c
43226 +++ b/drivers/uio/uio.c
43227 @@ -25,6 +25,7 @@
43228 #include <linux/kobject.h>
43229 #include <linux/cdev.h>
43230 #include <linux/uio_driver.h>
43231 +#include <asm/local.h>
43232
43233 #define UIO_MAX_DEVICES (1U << MINORBITS)
43234
43235 @@ -32,10 +33,10 @@ struct uio_device {
43236 struct module *owner;
43237 struct device *dev;
43238 int minor;
43239 - atomic_t event;
43240 + atomic_unchecked_t event;
43241 struct fasync_struct *async_queue;
43242 wait_queue_head_t wait;
43243 - int vma_count;
43244 + local_t vma_count;
43245 struct uio_info *info;
43246 struct kobject *map_dir;
43247 struct kobject *portio_dir;
43248 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
43249 struct device_attribute *attr, char *buf)
43250 {
43251 struct uio_device *idev = dev_get_drvdata(dev);
43252 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
43253 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
43254 }
43255
43256 static struct device_attribute uio_class_attributes[] = {
43257 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
43258 {
43259 struct uio_device *idev = info->uio_dev;
43260
43261 - atomic_inc(&idev->event);
43262 + atomic_inc_unchecked(&idev->event);
43263 wake_up_interruptible(&idev->wait);
43264 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
43265 }
43266 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
43267 }
43268
43269 listener->dev = idev;
43270 - listener->event_count = atomic_read(&idev->event);
43271 + listener->event_count = atomic_read_unchecked(&idev->event);
43272 filep->private_data = listener;
43273
43274 if (idev->info->open) {
43275 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
43276 return -EIO;
43277
43278 poll_wait(filep, &idev->wait, wait);
43279 - if (listener->event_count != atomic_read(&idev->event))
43280 + if (listener->event_count != atomic_read_unchecked(&idev->event))
43281 return POLLIN | POLLRDNORM;
43282 return 0;
43283 }
43284 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
43285 do {
43286 set_current_state(TASK_INTERRUPTIBLE);
43287
43288 - event_count = atomic_read(&idev->event);
43289 + event_count = atomic_read_unchecked(&idev->event);
43290 if (event_count != listener->event_count) {
43291 if (copy_to_user(buf, &event_count, count))
43292 retval = -EFAULT;
43293 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
43294 static void uio_vma_open(struct vm_area_struct *vma)
43295 {
43296 struct uio_device *idev = vma->vm_private_data;
43297 - idev->vma_count++;
43298 + local_inc(&idev->vma_count);
43299 }
43300
43301 static void uio_vma_close(struct vm_area_struct *vma)
43302 {
43303 struct uio_device *idev = vma->vm_private_data;
43304 - idev->vma_count--;
43305 + local_dec(&idev->vma_count);
43306 }
43307
43308 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
43309 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
43310 idev->owner = owner;
43311 idev->info = info;
43312 init_waitqueue_head(&idev->wait);
43313 - atomic_set(&idev->event, 0);
43314 + atomic_set_unchecked(&idev->event, 0);
43315
43316 ret = uio_get_minor(idev);
43317 if (ret)
43318 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
43319 index b7eb86a..36d28af 100644
43320 --- a/drivers/usb/atm/cxacru.c
43321 +++ b/drivers/usb/atm/cxacru.c
43322 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
43323 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
43324 if (ret < 2)
43325 return -EINVAL;
43326 - if (index < 0 || index > 0x7f)
43327 + if (index > 0x7f)
43328 return -EINVAL;
43329 pos += tmp;
43330
43331 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
43332 index 35f10bf..6a38a0b 100644
43333 --- a/drivers/usb/atm/usbatm.c
43334 +++ b/drivers/usb/atm/usbatm.c
43335 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43336 if (printk_ratelimit())
43337 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
43338 __func__, vpi, vci);
43339 - atomic_inc(&vcc->stats->rx_err);
43340 + atomic_inc_unchecked(&vcc->stats->rx_err);
43341 return;
43342 }
43343
43344 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43345 if (length > ATM_MAX_AAL5_PDU) {
43346 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
43347 __func__, length, vcc);
43348 - atomic_inc(&vcc->stats->rx_err);
43349 + atomic_inc_unchecked(&vcc->stats->rx_err);
43350 goto out;
43351 }
43352
43353 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43354 if (sarb->len < pdu_length) {
43355 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
43356 __func__, pdu_length, sarb->len, vcc);
43357 - atomic_inc(&vcc->stats->rx_err);
43358 + atomic_inc_unchecked(&vcc->stats->rx_err);
43359 goto out;
43360 }
43361
43362 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
43363 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
43364 __func__, vcc);
43365 - atomic_inc(&vcc->stats->rx_err);
43366 + atomic_inc_unchecked(&vcc->stats->rx_err);
43367 goto out;
43368 }
43369
43370 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43371 if (printk_ratelimit())
43372 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
43373 __func__, length);
43374 - atomic_inc(&vcc->stats->rx_drop);
43375 + atomic_inc_unchecked(&vcc->stats->rx_drop);
43376 goto out;
43377 }
43378
43379 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43380
43381 vcc->push(vcc, skb);
43382
43383 - atomic_inc(&vcc->stats->rx);
43384 + atomic_inc_unchecked(&vcc->stats->rx);
43385 out:
43386 skb_trim(sarb, 0);
43387 }
43388 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
43389 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
43390
43391 usbatm_pop(vcc, skb);
43392 - atomic_inc(&vcc->stats->tx);
43393 + atomic_inc_unchecked(&vcc->stats->tx);
43394
43395 skb = skb_dequeue(&instance->sndqueue);
43396 }
43397 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
43398 if (!left--)
43399 return sprintf(page,
43400 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
43401 - atomic_read(&atm_dev->stats.aal5.tx),
43402 - atomic_read(&atm_dev->stats.aal5.tx_err),
43403 - atomic_read(&atm_dev->stats.aal5.rx),
43404 - atomic_read(&atm_dev->stats.aal5.rx_err),
43405 - atomic_read(&atm_dev->stats.aal5.rx_drop));
43406 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
43407 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
43408 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
43409 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
43410 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
43411
43412 if (!left--) {
43413 if (instance->disconnected)
43414 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
43415 index cbacea9..246cccd 100644
43416 --- a/drivers/usb/core/devices.c
43417 +++ b/drivers/usb/core/devices.c
43418 @@ -126,7 +126,7 @@ static const char format_endpt[] =
43419 * time it gets called.
43420 */
43421 static struct device_connect_event {
43422 - atomic_t count;
43423 + atomic_unchecked_t count;
43424 wait_queue_head_t wait;
43425 } device_event = {
43426 .count = ATOMIC_INIT(1),
43427 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
43428
43429 void usbfs_conn_disc_event(void)
43430 {
43431 - atomic_add(2, &device_event.count);
43432 + atomic_add_unchecked(2, &device_event.count);
43433 wake_up(&device_event.wait);
43434 }
43435
43436 @@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
43437
43438 poll_wait(file, &device_event.wait, wait);
43439
43440 - event_count = atomic_read(&device_event.count);
43441 + event_count = atomic_read_unchecked(&device_event.count);
43442 if (file->f_version != event_count) {
43443 file->f_version = event_count;
43444 return POLLIN | POLLRDNORM;
43445 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
43446 index 8e64adf..9a33a3c 100644
43447 --- a/drivers/usb/core/hcd.c
43448 +++ b/drivers/usb/core/hcd.c
43449 @@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43450 */
43451 usb_get_urb(urb);
43452 atomic_inc(&urb->use_count);
43453 - atomic_inc(&urb->dev->urbnum);
43454 + atomic_inc_unchecked(&urb->dev->urbnum);
43455 usbmon_urb_submit(&hcd->self, urb);
43456
43457 /* NOTE requirements on root-hub callers (usbfs and the hub
43458 @@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43459 urb->hcpriv = NULL;
43460 INIT_LIST_HEAD(&urb->urb_list);
43461 atomic_dec(&urb->use_count);
43462 - atomic_dec(&urb->dev->urbnum);
43463 + atomic_dec_unchecked(&urb->dev->urbnum);
43464 if (atomic_read(&urb->reject))
43465 wake_up(&usb_kill_urb_queue);
43466 usb_put_urb(urb);
43467 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
43468 index 818e4a0..0fc9589 100644
43469 --- a/drivers/usb/core/sysfs.c
43470 +++ b/drivers/usb/core/sysfs.c
43471 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
43472 struct usb_device *udev;
43473
43474 udev = to_usb_device(dev);
43475 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
43476 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
43477 }
43478 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
43479
43480 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
43481 index f81b925..78d22ec 100644
43482 --- a/drivers/usb/core/usb.c
43483 +++ b/drivers/usb/core/usb.c
43484 @@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
43485 set_dev_node(&dev->dev, dev_to_node(bus->controller));
43486 dev->state = USB_STATE_ATTACHED;
43487 dev->lpm_disable_count = 1;
43488 - atomic_set(&dev->urbnum, 0);
43489 + atomic_set_unchecked(&dev->urbnum, 0);
43490
43491 INIT_LIST_HEAD(&dev->ep0.urb_list);
43492 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
43493 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
43494 index 5e29dde..eca992f 100644
43495 --- a/drivers/usb/early/ehci-dbgp.c
43496 +++ b/drivers/usb/early/ehci-dbgp.c
43497 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
43498
43499 #ifdef CONFIG_KGDB
43500 static struct kgdb_io kgdbdbgp_io_ops;
43501 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
43502 +static struct kgdb_io kgdbdbgp_io_ops_console;
43503 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
43504 #else
43505 #define dbgp_kgdb_mode (0)
43506 #endif
43507 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
43508 .write_char = kgdbdbgp_write_char,
43509 };
43510
43511 +static struct kgdb_io kgdbdbgp_io_ops_console = {
43512 + .name = "kgdbdbgp",
43513 + .read_char = kgdbdbgp_read_char,
43514 + .write_char = kgdbdbgp_write_char,
43515 + .is_console = 1
43516 +};
43517 +
43518 static int kgdbdbgp_wait_time;
43519
43520 static int __init kgdbdbgp_parse_config(char *str)
43521 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
43522 ptr++;
43523 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
43524 }
43525 - kgdb_register_io_module(&kgdbdbgp_io_ops);
43526 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
43527 + if (early_dbgp_console.index != -1)
43528 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
43529 + else
43530 + kgdb_register_io_module(&kgdbdbgp_io_ops);
43531
43532 return 0;
43533 }
43534 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
43535 index 598dcc1..032dd4f 100644
43536 --- a/drivers/usb/gadget/u_serial.c
43537 +++ b/drivers/usb/gadget/u_serial.c
43538 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
43539 spin_lock_irq(&port->port_lock);
43540
43541 /* already open? Great. */
43542 - if (port->port.count) {
43543 + if (atomic_read(&port->port.count)) {
43544 status = 0;
43545 - port->port.count++;
43546 + atomic_inc(&port->port.count);
43547
43548 /* currently opening/closing? wait ... */
43549 } else if (port->openclose) {
43550 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
43551 tty->driver_data = port;
43552 port->port.tty = tty;
43553
43554 - port->port.count = 1;
43555 + atomic_set(&port->port.count, 1);
43556 port->openclose = false;
43557
43558 /* if connected, start the I/O stream */
43559 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
43560
43561 spin_lock_irq(&port->port_lock);
43562
43563 - if (port->port.count != 1) {
43564 - if (port->port.count == 0)
43565 + if (atomic_read(&port->port.count) != 1) {
43566 + if (atomic_read(&port->port.count) == 0)
43567 WARN_ON(1);
43568 else
43569 - --port->port.count;
43570 + atomic_dec(&port->port.count);
43571 goto exit;
43572 }
43573
43574 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
43575 * and sleep if necessary
43576 */
43577 port->openclose = true;
43578 - port->port.count = 0;
43579 + atomic_set(&port->port.count, 0);
43580
43581 gser = port->port_usb;
43582 if (gser && gser->disconnect)
43583 @@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
43584 int cond;
43585
43586 spin_lock_irq(&port->port_lock);
43587 - cond = (port->port.count == 0) && !port->openclose;
43588 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
43589 spin_unlock_irq(&port->port_lock);
43590 return cond;
43591 }
43592 @@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
43593 /* if it's already open, start I/O ... and notify the serial
43594 * protocol about open/close status (connect/disconnect).
43595 */
43596 - if (port->port.count) {
43597 + if (atomic_read(&port->port.count)) {
43598 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
43599 gs_start_io(port);
43600 if (gser->connect)
43601 @@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
43602
43603 port->port_usb = NULL;
43604 gser->ioport = NULL;
43605 - if (port->port.count > 0 || port->openclose) {
43606 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
43607 wake_up_interruptible(&port->drain_wait);
43608 if (port->port.tty)
43609 tty_hangup(port->port.tty);
43610 @@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
43611
43612 /* finally, free any unused/unusable I/O buffers */
43613 spin_lock_irqsave(&port->port_lock, flags);
43614 - if (port->port.count == 0 && !port->openclose)
43615 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
43616 gs_buf_free(&port->port_write_buf);
43617 gs_free_requests(gser->out, &port->read_pool, NULL);
43618 gs_free_requests(gser->out, &port->read_queue, NULL);
43619 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
43620 index 5f3bcd3..bfca43f 100644
43621 --- a/drivers/usb/serial/console.c
43622 +++ b/drivers/usb/serial/console.c
43623 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
43624
43625 info->port = port;
43626
43627 - ++port->port.count;
43628 + atomic_inc(&port->port.count);
43629 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
43630 if (serial->type->set_termios) {
43631 /*
43632 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
43633 }
43634 /* Now that any required fake tty operations are completed restore
43635 * the tty port count */
43636 - --port->port.count;
43637 + atomic_dec(&port->port.count);
43638 /* The console is special in terms of closing the device so
43639 * indicate this port is now acting as a system console. */
43640 port->port.console = 1;
43641 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
43642 free_tty:
43643 kfree(tty);
43644 reset_open_count:
43645 - port->port.count = 0;
43646 + atomic_set(&port->port.count, 0);
43647 usb_autopm_put_interface(serial->interface);
43648 error_get_interface:
43649 usb_serial_put(serial);
43650 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
43651 index 75f70f0..d467e1a 100644
43652 --- a/drivers/usb/storage/usb.h
43653 +++ b/drivers/usb/storage/usb.h
43654 @@ -63,7 +63,7 @@ struct us_unusual_dev {
43655 __u8 useProtocol;
43656 __u8 useTransport;
43657 int (*initFunction)(struct us_data *);
43658 -};
43659 +} __do_const;
43660
43661
43662 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
43663 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
43664 index d6bea3e..60b250e 100644
43665 --- a/drivers/usb/wusbcore/wa-hc.h
43666 +++ b/drivers/usb/wusbcore/wa-hc.h
43667 @@ -192,7 +192,7 @@ struct wahc {
43668 struct list_head xfer_delayed_list;
43669 spinlock_t xfer_list_lock;
43670 struct work_struct xfer_work;
43671 - atomic_t xfer_id_count;
43672 + atomic_unchecked_t xfer_id_count;
43673 };
43674
43675
43676 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
43677 INIT_LIST_HEAD(&wa->xfer_delayed_list);
43678 spin_lock_init(&wa->xfer_list_lock);
43679 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
43680 - atomic_set(&wa->xfer_id_count, 1);
43681 + atomic_set_unchecked(&wa->xfer_id_count, 1);
43682 }
43683
43684 /**
43685 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
43686 index 57c01ab..8a05959 100644
43687 --- a/drivers/usb/wusbcore/wa-xfer.c
43688 +++ b/drivers/usb/wusbcore/wa-xfer.c
43689 @@ -296,7 +296,7 @@ out:
43690 */
43691 static void wa_xfer_id_init(struct wa_xfer *xfer)
43692 {
43693 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
43694 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
43695 }
43696
43697 /*
43698 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
43699 index 8c55011..eed4ae1a 100644
43700 --- a/drivers/video/aty/aty128fb.c
43701 +++ b/drivers/video/aty/aty128fb.c
43702 @@ -149,7 +149,7 @@ enum {
43703 };
43704
43705 /* Must match above enum */
43706 -static char * const r128_family[] = {
43707 +static const char * const r128_family[] = {
43708 "AGP",
43709 "PCI",
43710 "PRO AGP",
43711 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
43712 index 4f27fdc..d3537e6 100644
43713 --- a/drivers/video/aty/atyfb_base.c
43714 +++ b/drivers/video/aty/atyfb_base.c
43715 @@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
43716 par->accel_flags = var->accel_flags; /* hack */
43717
43718 if (var->accel_flags) {
43719 - info->fbops->fb_sync = atyfb_sync;
43720 + pax_open_kernel();
43721 + *(void **)&info->fbops->fb_sync = atyfb_sync;
43722 + pax_close_kernel();
43723 info->flags &= ~FBINFO_HWACCEL_DISABLED;
43724 } else {
43725 - info->fbops->fb_sync = NULL;
43726 + pax_open_kernel();
43727 + *(void **)&info->fbops->fb_sync = NULL;
43728 + pax_close_kernel();
43729 info->flags |= FBINFO_HWACCEL_DISABLED;
43730 }
43731
43732 diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
43733 index 95ec042..ae33e7a 100644
43734 --- a/drivers/video/aty/mach64_cursor.c
43735 +++ b/drivers/video/aty/mach64_cursor.c
43736 @@ -208,7 +208,9 @@ int aty_init_cursor(struct fb_info *info)
43737 info->sprite.buf_align = 16; /* and 64 lines tall. */
43738 info->sprite.flags = FB_PIXMAP_IO;
43739
43740 - info->fbops->fb_cursor = atyfb_cursor;
43741 + pax_open_kernel();
43742 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
43743 + pax_close_kernel();
43744
43745 return 0;
43746 }
43747 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
43748 index 6c5ed6b..b727c88 100644
43749 --- a/drivers/video/backlight/kb3886_bl.c
43750 +++ b/drivers/video/backlight/kb3886_bl.c
43751 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
43752 static unsigned long kb3886bl_flags;
43753 #define KB3886BL_SUSPENDED 0x01
43754
43755 -static struct dmi_system_id __initdata kb3886bl_device_table[] = {
43756 +static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
43757 {
43758 .ident = "Sahara Touch-iT",
43759 .matches = {
43760 diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
43761 index 88cad6b..dd746c7 100644
43762 --- a/drivers/video/fb_defio.c
43763 +++ b/drivers/video/fb_defio.c
43764 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
43765
43766 BUG_ON(!fbdefio);
43767 mutex_init(&fbdefio->lock);
43768 - info->fbops->fb_mmap = fb_deferred_io_mmap;
43769 + pax_open_kernel();
43770 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
43771 + pax_close_kernel();
43772 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
43773 INIT_LIST_HEAD(&fbdefio->pagelist);
43774 if (fbdefio->delay == 0) /* set a default of 1 s */
43775 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
43776 page->mapping = NULL;
43777 }
43778
43779 - info->fbops->fb_mmap = NULL;
43780 + *(void **)&info->fbops->fb_mmap = NULL;
43781 mutex_destroy(&fbdefio->lock);
43782 }
43783 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
43784 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
43785 index 5c3960d..15cf8fc 100644
43786 --- a/drivers/video/fbcmap.c
43787 +++ b/drivers/video/fbcmap.c
43788 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
43789 rc = -ENODEV;
43790 goto out;
43791 }
43792 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
43793 - !info->fbops->fb_setcmap)) {
43794 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
43795 rc = -EINVAL;
43796 goto out1;
43797 }
43798 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
43799 index dc61c12..e29796e 100644
43800 --- a/drivers/video/fbmem.c
43801 +++ b/drivers/video/fbmem.c
43802 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
43803 image->dx += image->width + 8;
43804 }
43805 } else if (rotate == FB_ROTATE_UD) {
43806 - for (x = 0; x < num && image->dx >= 0; x++) {
43807 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
43808 info->fbops->fb_imageblit(info, image);
43809 image->dx -= image->width + 8;
43810 }
43811 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
43812 image->dy += image->height + 8;
43813 }
43814 } else if (rotate == FB_ROTATE_CCW) {
43815 - for (x = 0; x < num && image->dy >= 0; x++) {
43816 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
43817 info->fbops->fb_imageblit(info, image);
43818 image->dy -= image->height + 8;
43819 }
43820 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
43821 return -EFAULT;
43822 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
43823 return -EINVAL;
43824 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
43825 + if (con2fb.framebuffer >= FB_MAX)
43826 return -EINVAL;
43827 if (!registered_fb[con2fb.framebuffer])
43828 request_module("fb%d", con2fb.framebuffer);
43829 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
43830 index 7672d2e..b56437f 100644
43831 --- a/drivers/video/i810/i810_accel.c
43832 +++ b/drivers/video/i810/i810_accel.c
43833 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
43834 }
43835 }
43836 printk("ringbuffer lockup!!!\n");
43837 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
43838 i810_report_error(mmio);
43839 par->dev_flags |= LOCKUP;
43840 info->pixmap.scan_align = 1;
43841 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
43842 index 3c14e43..eafa544 100644
43843 --- a/drivers/video/logo/logo_linux_clut224.ppm
43844 +++ b/drivers/video/logo/logo_linux_clut224.ppm
43845 @@ -1,1604 +1,1123 @@
43846 P3
43847 -# Standard 224-color Linux logo
43848 80 80
43849 255
43850 - 0 0 0 0 0 0 0 0 0 0 0 0
43851 - 0 0 0 0 0 0 0 0 0 0 0 0
43852 - 0 0 0 0 0 0 0 0 0 0 0 0
43853 - 0 0 0 0 0 0 0 0 0 0 0 0
43854 - 0 0 0 0 0 0 0 0 0 0 0 0
43855 - 0 0 0 0 0 0 0 0 0 0 0 0
43856 - 0 0 0 0 0 0 0 0 0 0 0 0
43857 - 0 0 0 0 0 0 0 0 0 0 0 0
43858 - 0 0 0 0 0 0 0 0 0 0 0 0
43859 - 6 6 6 6 6 6 10 10 10 10 10 10
43860 - 10 10 10 6 6 6 6 6 6 6 6 6
43861 - 0 0 0 0 0 0 0 0 0 0 0 0
43862 - 0 0 0 0 0 0 0 0 0 0 0 0
43863 - 0 0 0 0 0 0 0 0 0 0 0 0
43864 - 0 0 0 0 0 0 0 0 0 0 0 0
43865 - 0 0 0 0 0 0 0 0 0 0 0 0
43866 - 0 0 0 0 0 0 0 0 0 0 0 0
43867 - 0 0 0 0 0 0 0 0 0 0 0 0
43868 - 0 0 0 0 0 0 0 0 0 0 0 0
43869 - 0 0 0 0 0 0 0 0 0 0 0 0
43870 - 0 0 0 0 0 0 0 0 0 0 0 0
43871 - 0 0 0 0 0 0 0 0 0 0 0 0
43872 - 0 0 0 0 0 0 0 0 0 0 0 0
43873 - 0 0 0 0 0 0 0 0 0 0 0 0
43874 - 0 0 0 0 0 0 0 0 0 0 0 0
43875 - 0 0 0 0 0 0 0 0 0 0 0 0
43876 - 0 0 0 0 0 0 0 0 0 0 0 0
43877 - 0 0 0 0 0 0 0 0 0 0 0 0
43878 - 0 0 0 6 6 6 10 10 10 14 14 14
43879 - 22 22 22 26 26 26 30 30 30 34 34 34
43880 - 30 30 30 30 30 30 26 26 26 18 18 18
43881 - 14 14 14 10 10 10 6 6 6 0 0 0
43882 - 0 0 0 0 0 0 0 0 0 0 0 0
43883 - 0 0 0 0 0 0 0 0 0 0 0 0
43884 - 0 0 0 0 0 0 0 0 0 0 0 0
43885 - 0 0 0 0 0 0 0 0 0 0 0 0
43886 - 0 0 0 0 0 0 0 0 0 0 0 0
43887 - 0 0 0 0 0 0 0 0 0 0 0 0
43888 - 0 0 0 0 0 0 0 0 0 0 0 0
43889 - 0 0 0 0 0 0 0 0 0 0 0 0
43890 - 0 0 0 0 0 0 0 0 0 0 0 0
43891 - 0 0 0 0 0 1 0 0 1 0 0 0
43892 - 0 0 0 0 0 0 0 0 0 0 0 0
43893 - 0 0 0 0 0 0 0 0 0 0 0 0
43894 - 0 0 0 0 0 0 0 0 0 0 0 0
43895 - 0 0 0 0 0 0 0 0 0 0 0 0
43896 - 0 0 0 0 0 0 0 0 0 0 0 0
43897 - 0 0 0 0 0 0 0 0 0 0 0 0
43898 - 6 6 6 14 14 14 26 26 26 42 42 42
43899 - 54 54 54 66 66 66 78 78 78 78 78 78
43900 - 78 78 78 74 74 74 66 66 66 54 54 54
43901 - 42 42 42 26 26 26 18 18 18 10 10 10
43902 - 6 6 6 0 0 0 0 0 0 0 0 0
43903 - 0 0 0 0 0 0 0 0 0 0 0 0
43904 - 0 0 0 0 0 0 0 0 0 0 0 0
43905 - 0 0 0 0 0 0 0 0 0 0 0 0
43906 - 0 0 0 0 0 0 0 0 0 0 0 0
43907 - 0 0 0 0 0 0 0 0 0 0 0 0
43908 - 0 0 0 0 0 0 0 0 0 0 0 0
43909 - 0 0 0 0 0 0 0 0 0 0 0 0
43910 - 0 0 0 0 0 0 0 0 0 0 0 0
43911 - 0 0 1 0 0 0 0 0 0 0 0 0
43912 - 0 0 0 0 0 0 0 0 0 0 0 0
43913 - 0 0 0 0 0 0 0 0 0 0 0 0
43914 - 0 0 0 0 0 0 0 0 0 0 0 0
43915 - 0 0 0 0 0 0 0 0 0 0 0 0
43916 - 0 0 0 0 0 0 0 0 0 0 0 0
43917 - 0 0 0 0 0 0 0 0 0 10 10 10
43918 - 22 22 22 42 42 42 66 66 66 86 86 86
43919 - 66 66 66 38 38 38 38 38 38 22 22 22
43920 - 26 26 26 34 34 34 54 54 54 66 66 66
43921 - 86 86 86 70 70 70 46 46 46 26 26 26
43922 - 14 14 14 6 6 6 0 0 0 0 0 0
43923 - 0 0 0 0 0 0 0 0 0 0 0 0
43924 - 0 0 0 0 0 0 0 0 0 0 0 0
43925 - 0 0 0 0 0 0 0 0 0 0 0 0
43926 - 0 0 0 0 0 0 0 0 0 0 0 0
43927 - 0 0 0 0 0 0 0 0 0 0 0 0
43928 - 0 0 0 0 0 0 0 0 0 0 0 0
43929 - 0 0 0 0 0 0 0 0 0 0 0 0
43930 - 0 0 0 0 0 0 0 0 0 0 0 0
43931 - 0 0 1 0 0 1 0 0 1 0 0 0
43932 - 0 0 0 0 0 0 0 0 0 0 0 0
43933 - 0 0 0 0 0 0 0 0 0 0 0 0
43934 - 0 0 0 0 0 0 0 0 0 0 0 0
43935 - 0 0 0 0 0 0 0 0 0 0 0 0
43936 - 0 0 0 0 0 0 0 0 0 0 0 0
43937 - 0 0 0 0 0 0 10 10 10 26 26 26
43938 - 50 50 50 82 82 82 58 58 58 6 6 6
43939 - 2 2 6 2 2 6 2 2 6 2 2 6
43940 - 2 2 6 2 2 6 2 2 6 2 2 6
43941 - 6 6 6 54 54 54 86 86 86 66 66 66
43942 - 38 38 38 18 18 18 6 6 6 0 0 0
43943 - 0 0 0 0 0 0 0 0 0 0 0 0
43944 - 0 0 0 0 0 0 0 0 0 0 0 0
43945 - 0 0 0 0 0 0 0 0 0 0 0 0
43946 - 0 0 0 0 0 0 0 0 0 0 0 0
43947 - 0 0 0 0 0 0 0 0 0 0 0 0
43948 - 0 0 0 0 0 0 0 0 0 0 0 0
43949 - 0 0 0 0 0 0 0 0 0 0 0 0
43950 - 0 0 0 0 0 0 0 0 0 0 0 0
43951 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 22 22 22 50 50 50
43958 - 78 78 78 34 34 34 2 2 6 2 2 6
43959 - 2 2 6 2 2 6 2 2 6 2 2 6
43960 - 2 2 6 2 2 6 2 2 6 2 2 6
43961 - 2 2 6 2 2 6 6 6 6 70 70 70
43962 - 78 78 78 46 46 46 22 22 22 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 1 0 0 1 0 0 1 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 - 6 6 6 18 18 18 42 42 42 82 82 82
43978 - 26 26 26 2 2 6 2 2 6 2 2 6
43979 - 2 2 6 2 2 6 2 2 6 2 2 6
43980 - 2 2 6 2 2 6 2 2 6 14 14 14
43981 - 46 46 46 34 34 34 6 6 6 2 2 6
43982 - 42 42 42 78 78 78 42 42 42 18 18 18
43983 - 6 6 6 0 0 0 0 0 0 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 1 0 0 0 0 0 1 0 0 0
43992 - 0 0 0 0 0 0 0 0 0 0 0 0
43993 - 0 0 0 0 0 0 0 0 0 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 - 10 10 10 30 30 30 66 66 66 58 58 58
43998 - 2 2 6 2 2 6 2 2 6 2 2 6
43999 - 2 2 6 2 2 6 2 2 6 2 2 6
44000 - 2 2 6 2 2 6 2 2 6 26 26 26
44001 - 86 86 86 101 101 101 46 46 46 10 10 10
44002 - 2 2 6 58 58 58 70 70 70 34 34 34
44003 - 10 10 10 0 0 0 0 0 0 0 0 0
44004 - 0 0 0 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 1 0 0 1 0 0 1 0 0 0
44012 - 0 0 0 0 0 0 0 0 0 0 0 0
44013 - 0 0 0 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 - 14 14 14 42 42 42 86 86 86 10 10 10
44018 - 2 2 6 2 2 6 2 2 6 2 2 6
44019 - 2 2 6 2 2 6 2 2 6 2 2 6
44020 - 2 2 6 2 2 6 2 2 6 30 30 30
44021 - 94 94 94 94 94 94 58 58 58 26 26 26
44022 - 2 2 6 6 6 6 78 78 78 54 54 54
44023 - 22 22 22 6 6 6 0 0 0 0 0 0
44024 - 0 0 0 0 0 0 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 0 0 0 0 0 0 0 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 6 6 6
44037 - 22 22 22 62 62 62 62 62 62 2 2 6
44038 - 2 2 6 2 2 6 2 2 6 2 2 6
44039 - 2 2 6 2 2 6 2 2 6 2 2 6
44040 - 2 2 6 2 2 6 2 2 6 26 26 26
44041 - 54 54 54 38 38 38 18 18 18 10 10 10
44042 - 2 2 6 2 2 6 34 34 34 82 82 82
44043 - 38 38 38 14 14 14 0 0 0 0 0 0
44044 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 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 6 6 6
44057 - 30 30 30 78 78 78 30 30 30 2 2 6
44058 - 2 2 6 2 2 6 2 2 6 2 2 6
44059 - 2 2 6 2 2 6 2 2 6 2 2 6
44060 - 2 2 6 2 2 6 2 2 6 10 10 10
44061 - 10 10 10 2 2 6 2 2 6 2 2 6
44062 - 2 2 6 2 2 6 2 2 6 78 78 78
44063 - 50 50 50 18 18 18 6 6 6 0 0 0
44064 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 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 0 0 0 0 0 0 0 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 10 10 10
44077 - 38 38 38 86 86 86 14 14 14 2 2 6
44078 - 2 2 6 2 2 6 2 2 6 2 2 6
44079 - 2 2 6 2 2 6 2 2 6 2 2 6
44080 - 2 2 6 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 54 54 54
44083 - 66 66 66 26 26 26 6 6 6 0 0 0
44084 - 0 0 0 0 0 0 0 0 0 0 0 0
44085 - 0 0 0 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 1 0 0 1 0 0 0
44092 - 0 0 0 0 0 0 0 0 0 0 0 0
44093 - 0 0 0 0 0 0 0 0 0 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 14 14 14
44097 - 42 42 42 82 82 82 2 2 6 2 2 6
44098 - 2 2 6 6 6 6 10 10 10 2 2 6
44099 - 2 2 6 2 2 6 2 2 6 2 2 6
44100 - 2 2 6 2 2 6 2 2 6 6 6 6
44101 - 14 14 14 10 10 10 2 2 6 2 2 6
44102 - 2 2 6 2 2 6 2 2 6 18 18 18
44103 - 82 82 82 34 34 34 10 10 10 0 0 0
44104 - 0 0 0 0 0 0 0 0 0 0 0 0
44105 - 0 0 0 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 1 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 0 0 0 0 0 0 0 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 14 14 14
44117 - 46 46 46 86 86 86 2 2 6 2 2 6
44118 - 6 6 6 6 6 6 22 22 22 34 34 34
44119 - 6 6 6 2 2 6 2 2 6 2 2 6
44120 - 2 2 6 2 2 6 18 18 18 34 34 34
44121 - 10 10 10 50 50 50 22 22 22 2 2 6
44122 - 2 2 6 2 2 6 2 2 6 10 10 10
44123 - 86 86 86 42 42 42 14 14 14 0 0 0
44124 - 0 0 0 0 0 0 0 0 0 0 0 0
44125 - 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 14 14 14
44137 - 46 46 46 86 86 86 2 2 6 2 2 6
44138 - 38 38 38 116 116 116 94 94 94 22 22 22
44139 - 22 22 22 2 2 6 2 2 6 2 2 6
44140 - 14 14 14 86 86 86 138 138 138 162 162 162
44141 -154 154 154 38 38 38 26 26 26 6 6 6
44142 - 2 2 6 2 2 6 2 2 6 2 2 6
44143 - 86 86 86 46 46 46 14 14 14 0 0 0
44144 - 0 0 0 0 0 0 0 0 0 0 0 0
44145 - 0 0 0 0 0 0 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 0 0 0 0 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 14 14 14
44157 - 46 46 46 86 86 86 2 2 6 14 14 14
44158 -134 134 134 198 198 198 195 195 195 116 116 116
44159 - 10 10 10 2 2 6 2 2 6 6 6 6
44160 -101 98 89 187 187 187 210 210 210 218 218 218
44161 -214 214 214 134 134 134 14 14 14 6 6 6
44162 - 2 2 6 2 2 6 2 2 6 2 2 6
44163 - 86 86 86 50 50 50 18 18 18 6 6 6
44164 - 0 0 0 0 0 0 0 0 0 0 0 0
44165 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
44171 - 0 0 1 0 0 1 0 0 1 0 0 0
44172 - 0 0 0 0 0 0 0 0 0 0 0 0
44173 - 0 0 0 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 14 14 14
44177 - 46 46 46 86 86 86 2 2 6 54 54 54
44178 -218 218 218 195 195 195 226 226 226 246 246 246
44179 - 58 58 58 2 2 6 2 2 6 30 30 30
44180 -210 210 210 253 253 253 174 174 174 123 123 123
44181 -221 221 221 234 234 234 74 74 74 2 2 6
44182 - 2 2 6 2 2 6 2 2 6 2 2 6
44183 - 70 70 70 58 58 58 22 22 22 6 6 6
44184 - 0 0 0 0 0 0 0 0 0 0 0 0
44185 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 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 14 14 14
44197 - 46 46 46 82 82 82 2 2 6 106 106 106
44198 -170 170 170 26 26 26 86 86 86 226 226 226
44199 -123 123 123 10 10 10 14 14 14 46 46 46
44200 -231 231 231 190 190 190 6 6 6 70 70 70
44201 - 90 90 90 238 238 238 158 158 158 2 2 6
44202 - 2 2 6 2 2 6 2 2 6 2 2 6
44203 - 70 70 70 58 58 58 22 22 22 6 6 6
44204 - 0 0 0 0 0 0 0 0 0 0 0 0
44205 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
44211 - 0 0 1 0 0 1 0 0 1 0 0 0
44212 - 0 0 0 0 0 0 0 0 0 0 0 0
44213 - 0 0 0 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 14 14 14
44217 - 42 42 42 86 86 86 6 6 6 116 116 116
44218 -106 106 106 6 6 6 70 70 70 149 149 149
44219 -128 128 128 18 18 18 38 38 38 54 54 54
44220 -221 221 221 106 106 106 2 2 6 14 14 14
44221 - 46 46 46 190 190 190 198 198 198 2 2 6
44222 - 2 2 6 2 2 6 2 2 6 2 2 6
44223 - 74 74 74 62 62 62 22 22 22 6 6 6
44224 - 0 0 0 0 0 0 0 0 0 0 0 0
44225 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
44231 - 0 0 1 0 0 0 0 0 1 0 0 0
44232 - 0 0 0 0 0 0 0 0 0 0 0 0
44233 - 0 0 0 0 0 0 0 0 0 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 14 14 14
44237 - 42 42 42 94 94 94 14 14 14 101 101 101
44238 -128 128 128 2 2 6 18 18 18 116 116 116
44239 -118 98 46 121 92 8 121 92 8 98 78 10
44240 -162 162 162 106 106 106 2 2 6 2 2 6
44241 - 2 2 6 195 195 195 195 195 195 6 6 6
44242 - 2 2 6 2 2 6 2 2 6 2 2 6
44243 - 74 74 74 62 62 62 22 22 22 6 6 6
44244 - 0 0 0 0 0 0 0 0 0 0 0 0
44245 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1
44251 - 0 0 1 0 0 0 0 0 1 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 10 10 10
44257 - 38 38 38 90 90 90 14 14 14 58 58 58
44258 -210 210 210 26 26 26 54 38 6 154 114 10
44259 -226 170 11 236 186 11 225 175 15 184 144 12
44260 -215 174 15 175 146 61 37 26 9 2 2 6
44261 - 70 70 70 246 246 246 138 138 138 2 2 6
44262 - 2 2 6 2 2 6 2 2 6 2 2 6
44263 - 70 70 70 66 66 66 26 26 26 6 6 6
44264 - 0 0 0 0 0 0 0 0 0 0 0 0
44265 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
44273 - 0 0 0 0 0 0 0 0 0 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 10 10 10
44277 - 38 38 38 86 86 86 14 14 14 10 10 10
44278 -195 195 195 188 164 115 192 133 9 225 175 15
44279 -239 182 13 234 190 10 232 195 16 232 200 30
44280 -245 207 45 241 208 19 232 195 16 184 144 12
44281 -218 194 134 211 206 186 42 42 42 2 2 6
44282 - 2 2 6 2 2 6 2 2 6 2 2 6
44283 - 50 50 50 74 74 74 30 30 30 6 6 6
44284 - 0 0 0 0 0 0 0 0 0 0 0 0
44285 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
44297 - 34 34 34 86 86 86 14 14 14 2 2 6
44298 -121 87 25 192 133 9 219 162 10 239 182 13
44299 -236 186 11 232 195 16 241 208 19 244 214 54
44300 -246 218 60 246 218 38 246 215 20 241 208 19
44301 -241 208 19 226 184 13 121 87 25 2 2 6
44302 - 2 2 6 2 2 6 2 2 6 2 2 6
44303 - 50 50 50 82 82 82 34 34 34 10 10 10
44304 - 0 0 0 0 0 0 0 0 0 0 0 0
44305 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
44313 - 0 0 0 0 0 0 0 0 0 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 10 10 10
44317 - 34 34 34 82 82 82 30 30 30 61 42 6
44318 -180 123 7 206 145 10 230 174 11 239 182 13
44319 -234 190 10 238 202 15 241 208 19 246 218 74
44320 -246 218 38 246 215 20 246 215 20 246 215 20
44321 -226 184 13 215 174 15 184 144 12 6 6 6
44322 - 2 2 6 2 2 6 2 2 6 2 2 6
44323 - 26 26 26 94 94 94 42 42 42 14 14 14
44324 - 0 0 0 0 0 0 0 0 0 0 0 0
44325 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
44333 - 0 0 0 0 0 0 0 0 0 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 10 10 10
44337 - 30 30 30 78 78 78 50 50 50 104 69 6
44338 -192 133 9 216 158 10 236 178 12 236 186 11
44339 -232 195 16 241 208 19 244 214 54 245 215 43
44340 -246 215 20 246 215 20 241 208 19 198 155 10
44341 -200 144 11 216 158 10 156 118 10 2 2 6
44342 - 2 2 6 2 2 6 2 2 6 2 2 6
44343 - 6 6 6 90 90 90 54 54 54 18 18 18
44344 - 6 6 6 0 0 0 0 0 0 0 0 0
44345 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
44353 - 0 0 0 0 0 0 0 0 0 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 10 10 10
44357 - 30 30 30 78 78 78 46 46 46 22 22 22
44358 -137 92 6 210 162 10 239 182 13 238 190 10
44359 -238 202 15 241 208 19 246 215 20 246 215 20
44360 -241 208 19 203 166 17 185 133 11 210 150 10
44361 -216 158 10 210 150 10 102 78 10 2 2 6
44362 - 6 6 6 54 54 54 14 14 14 2 2 6
44363 - 2 2 6 62 62 62 74 74 74 30 30 30
44364 - 10 10 10 0 0 0 0 0 0 0 0 0
44365 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
44377 - 34 34 34 78 78 78 50 50 50 6 6 6
44378 - 94 70 30 139 102 15 190 146 13 226 184 13
44379 -232 200 30 232 195 16 215 174 15 190 146 13
44380 -168 122 10 192 133 9 210 150 10 213 154 11
44381 -202 150 34 182 157 106 101 98 89 2 2 6
44382 - 2 2 6 78 78 78 116 116 116 58 58 58
44383 - 2 2 6 22 22 22 90 90 90 46 46 46
44384 - 18 18 18 6 6 6 0 0 0 0 0 0
44385 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
44397 - 38 38 38 86 86 86 50 50 50 6 6 6
44398 -128 128 128 174 154 114 156 107 11 168 122 10
44399 -198 155 10 184 144 12 197 138 11 200 144 11
44400 -206 145 10 206 145 10 197 138 11 188 164 115
44401 -195 195 195 198 198 198 174 174 174 14 14 14
44402 - 2 2 6 22 22 22 116 116 116 116 116 116
44403 - 22 22 22 2 2 6 74 74 74 70 70 70
44404 - 30 30 30 10 10 10 0 0 0 0 0 0
44405 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
44417 - 50 50 50 101 101 101 26 26 26 10 10 10
44418 -138 138 138 190 190 190 174 154 114 156 107 11
44419 -197 138 11 200 144 11 197 138 11 192 133 9
44420 -180 123 7 190 142 34 190 178 144 187 187 187
44421 -202 202 202 221 221 221 214 214 214 66 66 66
44422 - 2 2 6 2 2 6 50 50 50 62 62 62
44423 - 6 6 6 2 2 6 10 10 10 90 90 90
44424 - 50 50 50 18 18 18 6 6 6 0 0 0
44425 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 34 34 34
44437 - 74 74 74 74 74 74 2 2 6 6 6 6
44438 -144 144 144 198 198 198 190 190 190 178 166 146
44439 -154 121 60 156 107 11 156 107 11 168 124 44
44440 -174 154 114 187 187 187 190 190 190 210 210 210
44441 -246 246 246 253 253 253 253 253 253 182 182 182
44442 - 6 6 6 2 2 6 2 2 6 2 2 6
44443 - 2 2 6 2 2 6 2 2 6 62 62 62
44444 - 74 74 74 34 34 34 14 14 14 0 0 0
44445 - 0 0 0 0 0 0 0 0 0 0 0 0
44446 - 0 0 0 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 10 10 10 22 22 22 54 54 54
44457 - 94 94 94 18 18 18 2 2 6 46 46 46
44458 -234 234 234 221 221 221 190 190 190 190 190 190
44459 -190 190 190 187 187 187 187 187 187 190 190 190
44460 -190 190 190 195 195 195 214 214 214 242 242 242
44461 -253 253 253 253 253 253 253 253 253 253 253 253
44462 - 82 82 82 2 2 6 2 2 6 2 2 6
44463 - 2 2 6 2 2 6 2 2 6 14 14 14
44464 - 86 86 86 54 54 54 22 22 22 6 6 6
44465 - 0 0 0 0 0 0 0 0 0 0 0 0
44466 - 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
44477 - 46 46 46 18 18 18 6 6 6 182 182 182
44478 -253 253 253 246 246 246 206 206 206 190 190 190
44479 -190 190 190 190 190 190 190 190 190 190 190 190
44480 -206 206 206 231 231 231 250 250 250 253 253 253
44481 -253 253 253 253 253 253 253 253 253 253 253 253
44482 -202 202 202 14 14 14 2 2 6 2 2 6
44483 - 2 2 6 2 2 6 2 2 6 2 2 6
44484 - 42 42 42 86 86 86 42 42 42 18 18 18
44485 - 6 6 6 0 0 0 0 0 0 0 0 0
44486 - 0 0 0 0 0 0 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 6 6 6
44496 - 14 14 14 38 38 38 74 74 74 66 66 66
44497 - 2 2 6 6 6 6 90 90 90 250 250 250
44498 -253 253 253 253 253 253 238 238 238 198 198 198
44499 -190 190 190 190 190 190 195 195 195 221 221 221
44500 -246 246 246 253 253 253 253 253 253 253 253 253
44501 -253 253 253 253 253 253 253 253 253 253 253 253
44502 -253 253 253 82 82 82 2 2 6 2 2 6
44503 - 2 2 6 2 2 6 2 2 6 2 2 6
44504 - 2 2 6 78 78 78 70 70 70 34 34 34
44505 - 14 14 14 6 6 6 0 0 0 0 0 0
44506 - 0 0 0 0 0 0 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 14 14 14
44516 - 34 34 34 66 66 66 78 78 78 6 6 6
44517 - 2 2 6 18 18 18 218 218 218 253 253 253
44518 -253 253 253 253 253 253 253 253 253 246 246 246
44519 -226 226 226 231 231 231 246 246 246 253 253 253
44520 -253 253 253 253 253 253 253 253 253 253 253 253
44521 -253 253 253 253 253 253 253 253 253 253 253 253
44522 -253 253 253 178 178 178 2 2 6 2 2 6
44523 - 2 2 6 2 2 6 2 2 6 2 2 6
44524 - 2 2 6 18 18 18 90 90 90 62 62 62
44525 - 30 30 30 10 10 10 0 0 0 0 0 0
44526 - 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
44536 - 58 58 58 90 90 90 18 18 18 2 2 6
44537 - 2 2 6 110 110 110 253 253 253 253 253 253
44538 -253 253 253 253 253 253 253 253 253 253 253 253
44539 -250 250 250 253 253 253 253 253 253 253 253 253
44540 -253 253 253 253 253 253 253 253 253 253 253 253
44541 -253 253 253 253 253 253 253 253 253 253 253 253
44542 -253 253 253 231 231 231 18 18 18 2 2 6
44543 - 2 2 6 2 2 6 2 2 6 2 2 6
44544 - 2 2 6 2 2 6 18 18 18 94 94 94
44545 - 54 54 54 26 26 26 10 10 10 0 0 0
44546 - 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
44556 - 90 90 90 26 26 26 2 2 6 2 2 6
44557 - 14 14 14 195 195 195 250 250 250 253 253 253
44558 -253 253 253 253 253 253 253 253 253 253 253 253
44559 -253 253 253 253 253 253 253 253 253 253 253 253
44560 -253 253 253 253 253 253 253 253 253 253 253 253
44561 -253 253 253 253 253 253 253 253 253 253 253 253
44562 -250 250 250 242 242 242 54 54 54 2 2 6
44563 - 2 2 6 2 2 6 2 2 6 2 2 6
44564 - 2 2 6 2 2 6 2 2 6 38 38 38
44565 - 86 86 86 50 50 50 22 22 22 6 6 6
44566 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 14 14 14 38 38 38 82 82 82
44576 - 34 34 34 2 2 6 2 2 6 2 2 6
44577 - 42 42 42 195 195 195 246 246 246 253 253 253
44578 -253 253 253 253 253 253 253 253 253 250 250 250
44579 -242 242 242 242 242 242 250 250 250 253 253 253
44580 -253 253 253 253 253 253 253 253 253 253 253 253
44581 -253 253 253 250 250 250 246 246 246 238 238 238
44582 -226 226 226 231 231 231 101 101 101 6 6 6
44583 - 2 2 6 2 2 6 2 2 6 2 2 6
44584 - 2 2 6 2 2 6 2 2 6 2 2 6
44585 - 38 38 38 82 82 82 42 42 42 14 14 14
44586 - 6 6 6 0 0 0 0 0 0 0 0 0
44587 - 0 0 0 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 - 10 10 10 26 26 26 62 62 62 66 66 66
44596 - 2 2 6 2 2 6 2 2 6 6 6 6
44597 - 70 70 70 170 170 170 206 206 206 234 234 234
44598 -246 246 246 250 250 250 250 250 250 238 238 238
44599 -226 226 226 231 231 231 238 238 238 250 250 250
44600 -250 250 250 250 250 250 246 246 246 231 231 231
44601 -214 214 214 206 206 206 202 202 202 202 202 202
44602 -198 198 198 202 202 202 182 182 182 18 18 18
44603 - 2 2 6 2 2 6 2 2 6 2 2 6
44604 - 2 2 6 2 2 6 2 2 6 2 2 6
44605 - 2 2 6 62 62 62 66 66 66 30 30 30
44606 - 10 10 10 0 0 0 0 0 0 0 0 0
44607 - 0 0 0 0 0 0 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 - 14 14 14 42 42 42 82 82 82 18 18 18
44616 - 2 2 6 2 2 6 2 2 6 10 10 10
44617 - 94 94 94 182 182 182 218 218 218 242 242 242
44618 -250 250 250 253 253 253 253 253 253 250 250 250
44619 -234 234 234 253 253 253 253 253 253 253 253 253
44620 -253 253 253 253 253 253 253 253 253 246 246 246
44621 -238 238 238 226 226 226 210 210 210 202 202 202
44622 -195 195 195 195 195 195 210 210 210 158 158 158
44623 - 6 6 6 14 14 14 50 50 50 14 14 14
44624 - 2 2 6 2 2 6 2 2 6 2 2 6
44625 - 2 2 6 6 6 6 86 86 86 46 46 46
44626 - 18 18 18 6 6 6 0 0 0 0 0 0
44627 - 0 0 0 0 0 0 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 6 6 6
44635 - 22 22 22 54 54 54 70 70 70 2 2 6
44636 - 2 2 6 10 10 10 2 2 6 22 22 22
44637 -166 166 166 231 231 231 250 250 250 253 253 253
44638 -253 253 253 253 253 253 253 253 253 250 250 250
44639 -242 242 242 253 253 253 253 253 253 253 253 253
44640 -253 253 253 253 253 253 253 253 253 253 253 253
44641 -253 253 253 253 253 253 253 253 253 246 246 246
44642 -231 231 231 206 206 206 198 198 198 226 226 226
44643 - 94 94 94 2 2 6 6 6 6 38 38 38
44644 - 30 30 30 2 2 6 2 2 6 2 2 6
44645 - 2 2 6 2 2 6 62 62 62 66 66 66
44646 - 26 26 26 10 10 10 0 0 0 0 0 0
44647 - 0 0 0 0 0 0 0 0 0 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 10 10 10
44655 - 30 30 30 74 74 74 50 50 50 2 2 6
44656 - 26 26 26 26 26 26 2 2 6 106 106 106
44657 -238 238 238 253 253 253 253 253 253 253 253 253
44658 -253 253 253 253 253 253 253 253 253 253 253 253
44659 -253 253 253 253 253 253 253 253 253 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 246 246 246 218 218 218 202 202 202
44663 -210 210 210 14 14 14 2 2 6 2 2 6
44664 - 30 30 30 22 22 22 2 2 6 2 2 6
44665 - 2 2 6 2 2 6 18 18 18 86 86 86
44666 - 42 42 42 14 14 14 0 0 0 0 0 0
44667 - 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
44675 - 42 42 42 90 90 90 22 22 22 2 2 6
44676 - 42 42 42 2 2 6 18 18 18 218 218 218
44677 -253 253 253 253 253 253 253 253 253 253 253 253
44678 -253 253 253 253 253 253 253 253 253 253 253 253
44679 -253 253 253 253 253 253 253 253 253 253 253 253
44680 -253 253 253 253 253 253 253 253 253 253 253 253
44681 -253 253 253 253 253 253 253 253 253 253 253 253
44682 -253 253 253 253 253 253 250 250 250 221 221 221
44683 -218 218 218 101 101 101 2 2 6 14 14 14
44684 - 18 18 18 38 38 38 10 10 10 2 2 6
44685 - 2 2 6 2 2 6 2 2 6 78 78 78
44686 - 58 58 58 22 22 22 6 6 6 0 0 0
44687 - 0 0 0 0 0 0 0 0 0 0 0 0
44688 - 0 0 0 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 6 6 6 18 18 18
44695 - 54 54 54 82 82 82 2 2 6 26 26 26
44696 - 22 22 22 2 2 6 123 123 123 253 253 253
44697 -253 253 253 253 253 253 253 253 253 253 253 253
44698 -253 253 253 253 253 253 253 253 253 253 253 253
44699 -253 253 253 253 253 253 253 253 253 253 253 253
44700 -253 253 253 253 253 253 253 253 253 253 253 253
44701 -253 253 253 253 253 253 253 253 253 253 253 253
44702 -253 253 253 253 253 253 253 253 253 250 250 250
44703 -238 238 238 198 198 198 6 6 6 38 38 38
44704 - 58 58 58 26 26 26 38 38 38 2 2 6
44705 - 2 2 6 2 2 6 2 2 6 46 46 46
44706 - 78 78 78 30 30 30 10 10 10 0 0 0
44707 - 0 0 0 0 0 0 0 0 0 0 0 0
44708 - 0 0 0 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 10 10 10 30 30 30
44715 - 74 74 74 58 58 58 2 2 6 42 42 42
44716 - 2 2 6 22 22 22 231 231 231 253 253 253
44717 -253 253 253 253 253 253 253 253 253 253 253 253
44718 -253 253 253 253 253 253 253 253 253 250 250 250
44719 -253 253 253 253 253 253 253 253 253 253 253 253
44720 -253 253 253 253 253 253 253 253 253 253 253 253
44721 -253 253 253 253 253 253 253 253 253 253 253 253
44722 -253 253 253 253 253 253 253 253 253 253 253 253
44723 -253 253 253 246 246 246 46 46 46 38 38 38
44724 - 42 42 42 14 14 14 38 38 38 14 14 14
44725 - 2 2 6 2 2 6 2 2 6 6 6 6
44726 - 86 86 86 46 46 46 14 14 14 0 0 0
44727 - 0 0 0 0 0 0 0 0 0 0 0 0
44728 - 0 0 0 0 0 0 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 6 6 6 14 14 14 42 42 42
44735 - 90 90 90 18 18 18 18 18 18 26 26 26
44736 - 2 2 6 116 116 116 253 253 253 253 253 253
44737 -253 253 253 253 253 253 253 253 253 253 253 253
44738 -253 253 253 253 253 253 250 250 250 238 238 238
44739 -253 253 253 253 253 253 253 253 253 253 253 253
44740 -253 253 253 253 253 253 253 253 253 253 253 253
44741 -253 253 253 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 94 94 94 6 6 6
44744 - 2 2 6 2 2 6 10 10 10 34 34 34
44745 - 2 2 6 2 2 6 2 2 6 2 2 6
44746 - 74 74 74 58 58 58 22 22 22 6 6 6
44747 - 0 0 0 0 0 0 0 0 0 0 0 0
44748 - 0 0 0 0 0 0 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 10 10 10 26 26 26 66 66 66
44755 - 82 82 82 2 2 6 38 38 38 6 6 6
44756 - 14 14 14 210 210 210 253 253 253 253 253 253
44757 -253 253 253 253 253 253 253 253 253 253 253 253
44758 -253 253 253 253 253 253 246 246 246 242 242 242
44759 -253 253 253 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 144 144 144 2 2 6
44764 - 2 2 6 2 2 6 2 2 6 46 46 46
44765 - 2 2 6 2 2 6 2 2 6 2 2 6
44766 - 42 42 42 74 74 74 30 30 30 10 10 10
44767 - 0 0 0 0 0 0 0 0 0 0 0 0
44768 - 0 0 0 0 0 0 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 - 6 6 6 14 14 14 42 42 42 90 90 90
44775 - 26 26 26 6 6 6 42 42 42 2 2 6
44776 - 74 74 74 250 250 250 253 253 253 253 253 253
44777 -253 253 253 253 253 253 253 253 253 253 253 253
44778 -253 253 253 253 253 253 242 242 242 242 242 242
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 182 182 182 2 2 6
44784 - 2 2 6 2 2 6 2 2 6 46 46 46
44785 - 2 2 6 2 2 6 2 2 6 2 2 6
44786 - 10 10 10 86 86 86 38 38 38 10 10 10
44787 - 0 0 0 0 0 0 0 0 0 0 0 0
44788 - 0 0 0 0 0 0 0 0 0 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 - 10 10 10 26 26 26 66 66 66 82 82 82
44795 - 2 2 6 22 22 22 18 18 18 2 2 6
44796 -149 149 149 253 253 253 253 253 253 253 253 253
44797 -253 253 253 253 253 253 253 253 253 253 253 253
44798 -253 253 253 253 253 253 234 234 234 242 242 242
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 206 206 206 2 2 6
44804 - 2 2 6 2 2 6 2 2 6 38 38 38
44805 - 2 2 6 2 2 6 2 2 6 2 2 6
44806 - 6 6 6 86 86 86 46 46 46 14 14 14
44807 - 0 0 0 0 0 0 0 0 0 0 0 0
44808 - 0 0 0 0 0 0 0 0 0 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 6 6 6
44814 - 18 18 18 46 46 46 86 86 86 18 18 18
44815 - 2 2 6 34 34 34 10 10 10 6 6 6
44816 -210 210 210 253 253 253 253 253 253 253 253 253
44817 -253 253 253 253 253 253 253 253 253 253 253 253
44818 -253 253 253 253 253 253 234 234 234 242 242 242
44819 -253 253 253 253 253 253 253 253 253 253 253 253
44820 -253 253 253 253 253 253 253 253 253 253 253 253
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 221 221 221 6 6 6
44824 - 2 2 6 2 2 6 6 6 6 30 30 30
44825 - 2 2 6 2 2 6 2 2 6 2 2 6
44826 - 2 2 6 82 82 82 54 54 54 18 18 18
44827 - 6 6 6 0 0 0 0 0 0 0 0 0
44828 - 0 0 0 0 0 0 0 0 0 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 10 10 10
44834 - 26 26 26 66 66 66 62 62 62 2 2 6
44835 - 2 2 6 38 38 38 10 10 10 26 26 26
44836 -238 238 238 253 253 253 253 253 253 253 253 253
44837 -253 253 253 253 253 253 253 253 253 253 253 253
44838 -253 253 253 253 253 253 231 231 231 238 238 238
44839 -253 253 253 253 253 253 253 253 253 253 253 253
44840 -253 253 253 253 253 253 253 253 253 253 253 253
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 231 231 231 6 6 6
44844 - 2 2 6 2 2 6 10 10 10 30 30 30
44845 - 2 2 6 2 2 6 2 2 6 2 2 6
44846 - 2 2 6 66 66 66 58 58 58 22 22 22
44847 - 6 6 6 0 0 0 0 0 0 0 0 0
44848 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
44854 - 38 38 38 78 78 78 6 6 6 2 2 6
44855 - 2 2 6 46 46 46 14 14 14 42 42 42
44856 -246 246 246 253 253 253 253 253 253 253 253 253
44857 -253 253 253 253 253 253 253 253 253 253 253 253
44858 -253 253 253 253 253 253 231 231 231 242 242 242
44859 -253 253 253 253 253 253 253 253 253 253 253 253
44860 -253 253 253 253 253 253 253 253 253 253 253 253
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 234 234 234 10 10 10
44864 - 2 2 6 2 2 6 22 22 22 14 14 14
44865 - 2 2 6 2 2 6 2 2 6 2 2 6
44866 - 2 2 6 66 66 66 62 62 62 22 22 22
44867 - 6 6 6 0 0 0 0 0 0 0 0 0
44868 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
44874 - 50 50 50 74 74 74 2 2 6 2 2 6
44875 - 14 14 14 70 70 70 34 34 34 62 62 62
44876 -250 250 250 253 253 253 253 253 253 253 253 253
44877 -253 253 253 253 253 253 253 253 253 253 253 253
44878 -253 253 253 253 253 253 231 231 231 246 246 246
44879 -253 253 253 253 253 253 253 253 253 253 253 253
44880 -253 253 253 253 253 253 253 253 253 253 253 253
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 234 234 234 14 14 14
44884 - 2 2 6 2 2 6 30 30 30 2 2 6
44885 - 2 2 6 2 2 6 2 2 6 2 2 6
44886 - 2 2 6 66 66 66 62 62 62 22 22 22
44887 - 6 6 6 0 0 0 0 0 0 0 0 0
44888 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
44894 - 54 54 54 62 62 62 2 2 6 2 2 6
44895 - 2 2 6 30 30 30 46 46 46 70 70 70
44896 -250 250 250 253 253 253 253 253 253 253 253 253
44897 -253 253 253 253 253 253 253 253 253 253 253 253
44898 -253 253 253 253 253 253 231 231 231 246 246 246
44899 -253 253 253 253 253 253 253 253 253 253 253 253
44900 -253 253 253 253 253 253 253 253 253 253 253 253
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 226 226 226 10 10 10
44904 - 2 2 6 6 6 6 30 30 30 2 2 6
44905 - 2 2 6 2 2 6 2 2 6 2 2 6
44906 - 2 2 6 66 66 66 58 58 58 22 22 22
44907 - 6 6 6 0 0 0 0 0 0 0 0 0
44908 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 22 22 22
44914 - 58 58 58 62 62 62 2 2 6 2 2 6
44915 - 2 2 6 2 2 6 30 30 30 78 78 78
44916 -250 250 250 253 253 253 253 253 253 253 253 253
44917 -253 253 253 253 253 253 253 253 253 253 253 253
44918 -253 253 253 253 253 253 231 231 231 246 246 246
44919 -253 253 253 253 253 253 253 253 253 253 253 253
44920 -253 253 253 253 253 253 253 253 253 253 253 253
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 206 206 206 2 2 6
44924 - 22 22 22 34 34 34 18 14 6 22 22 22
44925 - 26 26 26 18 18 18 6 6 6 2 2 6
44926 - 2 2 6 82 82 82 54 54 54 18 18 18
44927 - 6 6 6 0 0 0 0 0 0 0 0 0
44928 - 0 0 0 0 0 0 0 0 0 0 0 0
44929 - 0 0 0 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 6 6 6 26 26 26
44934 - 62 62 62 106 106 106 74 54 14 185 133 11
44935 -210 162 10 121 92 8 6 6 6 62 62 62
44936 -238 238 238 253 253 253 253 253 253 253 253 253
44937 -253 253 253 253 253 253 253 253 253 253 253 253
44938 -253 253 253 253 253 253 231 231 231 246 246 246
44939 -253 253 253 253 253 253 253 253 253 253 253 253
44940 -253 253 253 253 253 253 253 253 253 253 253 253
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 158 158 158 18 18 18
44944 - 14 14 14 2 2 6 2 2 6 2 2 6
44945 - 6 6 6 18 18 18 66 66 66 38 38 38
44946 - 6 6 6 94 94 94 50 50 50 18 18 18
44947 - 6 6 6 0 0 0 0 0 0 0 0 0
44948 - 0 0 0 0 0 0 0 0 0 0 0 0
44949 - 0 0 0 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 6 6 6
44953 - 10 10 10 10 10 10 18 18 18 38 38 38
44954 - 78 78 78 142 134 106 216 158 10 242 186 14
44955 -246 190 14 246 190 14 156 118 10 10 10 10
44956 - 90 90 90 238 238 238 253 253 253 253 253 253
44957 -253 253 253 253 253 253 253 253 253 253 253 253
44958 -253 253 253 253 253 253 231 231 231 250 250 250
44959 -253 253 253 253 253 253 253 253 253 253 253 253
44960 -253 253 253 253 253 253 253 253 253 253 253 253
44961 -253 253 253 253 253 253 253 253 253 253 253 253
44962 -253 253 253 253 253 253 253 253 253 246 230 190
44963 -238 204 91 238 204 91 181 142 44 37 26 9
44964 - 2 2 6 2 2 6 2 2 6 2 2 6
44965 - 2 2 6 2 2 6 38 38 38 46 46 46
44966 - 26 26 26 106 106 106 54 54 54 18 18 18
44967 - 6 6 6 0 0 0 0 0 0 0 0 0
44968 - 0 0 0 0 0 0 0 0 0 0 0 0
44969 - 0 0 0 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 6 6 6 14 14 14 22 22 22
44973 - 30 30 30 38 38 38 50 50 50 70 70 70
44974 -106 106 106 190 142 34 226 170 11 242 186 14
44975 -246 190 14 246 190 14 246 190 14 154 114 10
44976 - 6 6 6 74 74 74 226 226 226 253 253 253
44977 -253 253 253 253 253 253 253 253 253 253 253 253
44978 -253 253 253 253 253 253 231 231 231 250 250 250
44979 -253 253 253 253 253 253 253 253 253 253 253 253
44980 -253 253 253 253 253 253 253 253 253 253 253 253
44981 -253 253 253 253 253 253 253 253 253 253 253 253
44982 -253 253 253 253 253 253 253 253 253 228 184 62
44983 -241 196 14 241 208 19 232 195 16 38 30 10
44984 - 2 2 6 2 2 6 2 2 6 2 2 6
44985 - 2 2 6 6 6 6 30 30 30 26 26 26
44986 -203 166 17 154 142 90 66 66 66 26 26 26
44987 - 6 6 6 0 0 0 0 0 0 0 0 0
44988 - 0 0 0 0 0 0 0 0 0 0 0 0
44989 - 0 0 0 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 - 6 6 6 18 18 18 38 38 38 58 58 58
44993 - 78 78 78 86 86 86 101 101 101 123 123 123
44994 -175 146 61 210 150 10 234 174 13 246 186 14
44995 -246 190 14 246 190 14 246 190 14 238 190 10
44996 -102 78 10 2 2 6 46 46 46 198 198 198
44997 -253 253 253 253 253 253 253 253 253 253 253 253
44998 -253 253 253 253 253 253 234 234 234 242 242 242
44999 -253 253 253 253 253 253 253 253 253 253 253 253
45000 -253 253 253 253 253 253 253 253 253 253 253 253
45001 -253 253 253 253 253 253 253 253 253 253 253 253
45002 -253 253 253 253 253 253 253 253 253 224 178 62
45003 -242 186 14 241 196 14 210 166 10 22 18 6
45004 - 2 2 6 2 2 6 2 2 6 2 2 6
45005 - 2 2 6 2 2 6 6 6 6 121 92 8
45006 -238 202 15 232 195 16 82 82 82 34 34 34
45007 - 10 10 10 0 0 0 0 0 0 0 0 0
45008 - 0 0 0 0 0 0 0 0 0 0 0 0
45009 - 0 0 0 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 - 14 14 14 38 38 38 70 70 70 154 122 46
45013 -190 142 34 200 144 11 197 138 11 197 138 11
45014 -213 154 11 226 170 11 242 186 14 246 190 14
45015 -246 190 14 246 190 14 246 190 14 246 190 14
45016 -225 175 15 46 32 6 2 2 6 22 22 22
45017 -158 158 158 250 250 250 253 253 253 253 253 253
45018 -253 253 253 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 253 253 253 253 253 253
45021 -253 253 253 253 253 253 253 253 253 253 253 253
45022 -253 253 253 250 250 250 242 242 242 224 178 62
45023 -239 182 13 236 186 11 213 154 11 46 32 6
45024 - 2 2 6 2 2 6 2 2 6 2 2 6
45025 - 2 2 6 2 2 6 61 42 6 225 175 15
45026 -238 190 10 236 186 11 112 100 78 42 42 42
45027 - 14 14 14 0 0 0 0 0 0 0 0 0
45028 - 0 0 0 0 0 0 0 0 0 0 0 0
45029 - 0 0 0 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 6 6 6
45032 - 22 22 22 54 54 54 154 122 46 213 154 11
45033 -226 170 11 230 174 11 226 170 11 226 170 11
45034 -236 178 12 242 186 14 246 190 14 246 190 14
45035 -246 190 14 246 190 14 246 190 14 246 190 14
45036 -241 196 14 184 144 12 10 10 10 2 2 6
45037 - 6 6 6 116 116 116 242 242 242 253 253 253
45038 -253 253 253 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 253 253 253 253 253 253
45041 -253 253 253 253 253 253 253 253 253 253 253 253
45042 -253 253 253 231 231 231 198 198 198 214 170 54
45043 -236 178 12 236 178 12 210 150 10 137 92 6
45044 - 18 14 6 2 2 6 2 2 6 2 2 6
45045 - 6 6 6 70 47 6 200 144 11 236 178 12
45046 -239 182 13 239 182 13 124 112 88 58 58 58
45047 - 22 22 22 6 6 6 0 0 0 0 0 0
45048 - 0 0 0 0 0 0 0 0 0 0 0 0
45049 - 0 0 0 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 10 10 10
45052 - 30 30 30 70 70 70 180 133 36 226 170 11
45053 -239 182 13 242 186 14 242 186 14 246 186 14
45054 -246 190 14 246 190 14 246 190 14 246 190 14
45055 -246 190 14 246 190 14 246 190 14 246 190 14
45056 -246 190 14 232 195 16 98 70 6 2 2 6
45057 - 2 2 6 2 2 6 66 66 66 221 221 221
45058 -253 253 253 253 253 253 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 253 253 253 253 253 253
45061 -253 253 253 253 253 253 253 253 253 253 253 253
45062 -253 253 253 206 206 206 198 198 198 214 166 58
45063 -230 174 11 230 174 11 216 158 10 192 133 9
45064 -163 110 8 116 81 8 102 78 10 116 81 8
45065 -167 114 7 197 138 11 226 170 11 239 182 13
45066 -242 186 14 242 186 14 162 146 94 78 78 78
45067 - 34 34 34 14 14 14 6 6 6 0 0 0
45068 - 0 0 0 0 0 0 0 0 0 0 0 0
45069 - 0 0 0 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 6 6 6
45072 - 30 30 30 78 78 78 190 142 34 226 170 11
45073 -239 182 13 246 190 14 246 190 14 246 190 14
45074 -246 190 14 246 190 14 246 190 14 246 190 14
45075 -246 190 14 246 190 14 246 190 14 246 190 14
45076 -246 190 14 241 196 14 203 166 17 22 18 6
45077 - 2 2 6 2 2 6 2 2 6 38 38 38
45078 -218 218 218 253 253 253 253 253 253 253 253 253
45079 -253 253 253 253 253 253 253 253 253 253 253 253
45080 -253 253 253 253 253 253 253 253 253 253 253 253
45081 -253 253 253 253 253 253 253 253 253 253 253 253
45082 -250 250 250 206 206 206 198 198 198 202 162 69
45083 -226 170 11 236 178 12 224 166 10 210 150 10
45084 -200 144 11 197 138 11 192 133 9 197 138 11
45085 -210 150 10 226 170 11 242 186 14 246 190 14
45086 -246 190 14 246 186 14 225 175 15 124 112 88
45087 - 62 62 62 30 30 30 14 14 14 6 6 6
45088 - 0 0 0 0 0 0 0 0 0 0 0 0
45089 - 0 0 0 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 10 10 10
45092 - 30 30 30 78 78 78 174 135 50 224 166 10
45093 -239 182 13 246 190 14 246 190 14 246 190 14
45094 -246 190 14 246 190 14 246 190 14 246 190 14
45095 -246 190 14 246 190 14 246 190 14 246 190 14
45096 -246 190 14 246 190 14 241 196 14 139 102 15
45097 - 2 2 6 2 2 6 2 2 6 2 2 6
45098 - 78 78 78 250 250 250 253 253 253 253 253 253
45099 -253 253 253 253 253 253 253 253 253 253 253 253
45100 -253 253 253 253 253 253 253 253 253 253 253 253
45101 -253 253 253 253 253 253 253 253 253 253 253 253
45102 -250 250 250 214 214 214 198 198 198 190 150 46
45103 -219 162 10 236 178 12 234 174 13 224 166 10
45104 -216 158 10 213 154 11 213 154 11 216 158 10
45105 -226 170 11 239 182 13 246 190 14 246 190 14
45106 -246 190 14 246 190 14 242 186 14 206 162 42
45107 -101 101 101 58 58 58 30 30 30 14 14 14
45108 - 6 6 6 0 0 0 0 0 0 0 0 0
45109 - 0 0 0 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 10 10 10
45112 - 30 30 30 74 74 74 174 135 50 216 158 10
45113 -236 178 12 246 190 14 246 190 14 246 190 14
45114 -246 190 14 246 190 14 246 190 14 246 190 14
45115 -246 190 14 246 190 14 246 190 14 246 190 14
45116 -246 190 14 246 190 14 241 196 14 226 184 13
45117 - 61 42 6 2 2 6 2 2 6 2 2 6
45118 - 22 22 22 238 238 238 253 253 253 253 253 253
45119 -253 253 253 253 253 253 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 226 226 226 187 187 187 180 133 36
45123 -216 158 10 236 178 12 239 182 13 236 178 12
45124 -230 174 11 226 170 11 226 170 11 230 174 11
45125 -236 178 12 242 186 14 246 190 14 246 190 14
45126 -246 190 14 246 190 14 246 186 14 239 182 13
45127 -206 162 42 106 106 106 66 66 66 34 34 34
45128 - 14 14 14 6 6 6 0 0 0 0 0 0
45129 - 0 0 0 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 6 6 6
45132 - 26 26 26 70 70 70 163 133 67 213 154 11
45133 -236 178 12 246 190 14 246 190 14 246 190 14
45134 -246 190 14 246 190 14 246 190 14 246 190 14
45135 -246 190 14 246 190 14 246 190 14 246 190 14
45136 -246 190 14 246 190 14 246 190 14 241 196 14
45137 -190 146 13 18 14 6 2 2 6 2 2 6
45138 - 46 46 46 246 246 246 253 253 253 253 253 253
45139 -253 253 253 253 253 253 253 253 253 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 221 221 221 86 86 86 156 107 11
45143 -216 158 10 236 178 12 242 186 14 246 186 14
45144 -242 186 14 239 182 13 239 182 13 242 186 14
45145 -242 186 14 246 186 14 246 190 14 246 190 14
45146 -246 190 14 246 190 14 246 190 14 246 190 14
45147 -242 186 14 225 175 15 142 122 72 66 66 66
45148 - 30 30 30 10 10 10 0 0 0 0 0 0
45149 - 0 0 0 0 0 0 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 6 6 6
45152 - 26 26 26 70 70 70 163 133 67 210 150 10
45153 -236 178 12 246 190 14 246 190 14 246 190 14
45154 -246 190 14 246 190 14 246 190 14 246 190 14
45155 -246 190 14 246 190 14 246 190 14 246 190 14
45156 -246 190 14 246 190 14 246 190 14 246 190 14
45157 -232 195 16 121 92 8 34 34 34 106 106 106
45158 -221 221 221 253 253 253 253 253 253 253 253 253
45159 -253 253 253 253 253 253 253 253 253 253 253 253
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 -242 242 242 82 82 82 18 14 6 163 110 8
45163 -216 158 10 236 178 12 242 186 14 246 190 14
45164 -246 190 14 246 190 14 246 190 14 246 190 14
45165 -246 190 14 246 190 14 246 190 14 246 190 14
45166 -246 190 14 246 190 14 246 190 14 246 190 14
45167 -246 190 14 246 190 14 242 186 14 163 133 67
45168 - 46 46 46 18 18 18 6 6 6 0 0 0
45169 - 0 0 0 0 0 0 0 0 0 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 10 10 10
45172 - 30 30 30 78 78 78 163 133 67 210 150 10
45173 -236 178 12 246 186 14 246 190 14 246 190 14
45174 -246 190 14 246 190 14 246 190 14 246 190 14
45175 -246 190 14 246 190 14 246 190 14 246 190 14
45176 -246 190 14 246 190 14 246 190 14 246 190 14
45177 -241 196 14 215 174 15 190 178 144 253 253 253
45178 -253 253 253 253 253 253 253 253 253 253 253 253
45179 -253 253 253 253 253 253 253 253 253 253 253 253
45180 -253 253 253 253 253 253 253 253 253 253 253 253
45181 -253 253 253 253 253 253 253 253 253 218 218 218
45182 - 58 58 58 2 2 6 22 18 6 167 114 7
45183 -216 158 10 236 178 12 246 186 14 246 190 14
45184 -246 190 14 246 190 14 246 190 14 246 190 14
45185 -246 190 14 246 190 14 246 190 14 246 190 14
45186 -246 190 14 246 190 14 246 190 14 246 190 14
45187 -246 190 14 246 186 14 242 186 14 190 150 46
45188 - 54 54 54 22 22 22 6 6 6 0 0 0
45189 - 0 0 0 0 0 0 0 0 0 0 0 0
45190 - 0 0 0 0 0 0 0 0 0 0 0 0
45191 - 0 0 0 0 0 0 0 0 0 14 14 14
45192 - 38 38 38 86 86 86 180 133 36 213 154 11
45193 -236 178 12 246 186 14 246 190 14 246 190 14
45194 -246 190 14 246 190 14 246 190 14 246 190 14
45195 -246 190 14 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 232 195 16 190 146 13 214 214 214
45198 -253 253 253 253 253 253 253 253 253 253 253 253
45199 -253 253 253 253 253 253 253 253 253 253 253 253
45200 -253 253 253 253 253 253 253 253 253 253 253 253
45201 -253 253 253 250 250 250 170 170 170 26 26 26
45202 - 2 2 6 2 2 6 37 26 9 163 110 8
45203 -219 162 10 239 182 13 246 186 14 246 190 14
45204 -246 190 14 246 190 14 246 190 14 246 190 14
45205 -246 190 14 246 190 14 246 190 14 246 190 14
45206 -246 190 14 246 190 14 246 190 14 246 190 14
45207 -246 186 14 236 178 12 224 166 10 142 122 72
45208 - 46 46 46 18 18 18 6 6 6 0 0 0
45209 - 0 0 0 0 0 0 0 0 0 0 0 0
45210 - 0 0 0 0 0 0 0 0 0 0 0 0
45211 - 0 0 0 0 0 0 6 6 6 18 18 18
45212 - 50 50 50 109 106 95 192 133 9 224 166 10
45213 -242 186 14 246 190 14 246 190 14 246 190 14
45214 -246 190 14 246 190 14 246 190 14 246 190 14
45215 -246 190 14 246 190 14 246 190 14 246 190 14
45216 -246 190 14 246 190 14 246 190 14 246 190 14
45217 -242 186 14 226 184 13 210 162 10 142 110 46
45218 -226 226 226 253 253 253 253 253 253 253 253 253
45219 -253 253 253 253 253 253 253 253 253 253 253 253
45220 -253 253 253 253 253 253 253 253 253 253 253 253
45221 -198 198 198 66 66 66 2 2 6 2 2 6
45222 - 2 2 6 2 2 6 50 34 6 156 107 11
45223 -219 162 10 239 182 13 246 186 14 246 190 14
45224 -246 190 14 246 190 14 246 190 14 246 190 14
45225 -246 190 14 246 190 14 246 190 14 246 190 14
45226 -246 190 14 246 190 14 246 190 14 242 186 14
45227 -234 174 13 213 154 11 154 122 46 66 66 66
45228 - 30 30 30 10 10 10 0 0 0 0 0 0
45229 - 0 0 0 0 0 0 0 0 0 0 0 0
45230 - 0 0 0 0 0 0 0 0 0 0 0 0
45231 - 0 0 0 0 0 0 6 6 6 22 22 22
45232 - 58 58 58 154 121 60 206 145 10 234 174 13
45233 -242 186 14 246 186 14 246 190 14 246 190 14
45234 -246 190 14 246 190 14 246 190 14 246 190 14
45235 -246 190 14 246 190 14 246 190 14 246 190 14
45236 -246 190 14 246 190 14 246 190 14 246 190 14
45237 -246 186 14 236 178 12 210 162 10 163 110 8
45238 - 61 42 6 138 138 138 218 218 218 250 250 250
45239 -253 253 253 253 253 253 253 253 253 250 250 250
45240 -242 242 242 210 210 210 144 144 144 66 66 66
45241 - 6 6 6 2 2 6 2 2 6 2 2 6
45242 - 2 2 6 2 2 6 61 42 6 163 110 8
45243 -216 158 10 236 178 12 246 190 14 246 190 14
45244 -246 190 14 246 190 14 246 190 14 246 190 14
45245 -246 190 14 246 190 14 246 190 14 246 190 14
45246 -246 190 14 239 182 13 230 174 11 216 158 10
45247 -190 142 34 124 112 88 70 70 70 38 38 38
45248 - 18 18 18 6 6 6 0 0 0 0 0 0
45249 - 0 0 0 0 0 0 0 0 0 0 0 0
45250 - 0 0 0 0 0 0 0 0 0 0 0 0
45251 - 0 0 0 0 0 0 6 6 6 22 22 22
45252 - 62 62 62 168 124 44 206 145 10 224 166 10
45253 -236 178 12 239 182 13 242 186 14 242 186 14
45254 -246 186 14 246 190 14 246 190 14 246 190 14
45255 -246 190 14 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 236 178 12 216 158 10 175 118 6
45258 - 80 54 7 2 2 6 6 6 6 30 30 30
45259 - 54 54 54 62 62 62 50 50 50 38 38 38
45260 - 14 14 14 2 2 6 2 2 6 2 2 6
45261 - 2 2 6 2 2 6 2 2 6 2 2 6
45262 - 2 2 6 6 6 6 80 54 7 167 114 7
45263 -213 154 11 236 178 12 246 190 14 246 190 14
45264 -246 190 14 246 190 14 246 190 14 246 190 14
45265 -246 190 14 242 186 14 239 182 13 239 182 13
45266 -230 174 11 210 150 10 174 135 50 124 112 88
45267 - 82 82 82 54 54 54 34 34 34 18 18 18
45268 - 6 6 6 0 0 0 0 0 0 0 0 0
45269 - 0 0 0 0 0 0 0 0 0 0 0 0
45270 - 0 0 0 0 0 0 0 0 0 0 0 0
45271 - 0 0 0 0 0 0 6 6 6 18 18 18
45272 - 50 50 50 158 118 36 192 133 9 200 144 11
45273 -216 158 10 219 162 10 224 166 10 226 170 11
45274 -230 174 11 236 178 12 239 182 13 239 182 13
45275 -242 186 14 246 186 14 246 190 14 246 190 14
45276 -246 190 14 246 190 14 246 190 14 246 190 14
45277 -246 186 14 230 174 11 210 150 10 163 110 8
45278 -104 69 6 10 10 10 2 2 6 2 2 6
45279 - 2 2 6 2 2 6 2 2 6 2 2 6
45280 - 2 2 6 2 2 6 2 2 6 2 2 6
45281 - 2 2 6 2 2 6 2 2 6 2 2 6
45282 - 2 2 6 6 6 6 91 60 6 167 114 7
45283 -206 145 10 230 174 11 242 186 14 246 190 14
45284 -246 190 14 246 190 14 246 186 14 242 186 14
45285 -239 182 13 230 174 11 224 166 10 213 154 11
45286 -180 133 36 124 112 88 86 86 86 58 58 58
45287 - 38 38 38 22 22 22 10 10 10 6 6 6
45288 - 0 0 0 0 0 0 0 0 0 0 0 0
45289 - 0 0 0 0 0 0 0 0 0 0 0 0
45290 - 0 0 0 0 0 0 0 0 0 0 0 0
45291 - 0 0 0 0 0 0 0 0 0 14 14 14
45292 - 34 34 34 70 70 70 138 110 50 158 118 36
45293 -167 114 7 180 123 7 192 133 9 197 138 11
45294 -200 144 11 206 145 10 213 154 11 219 162 10
45295 -224 166 10 230 174 11 239 182 13 242 186 14
45296 -246 186 14 246 186 14 246 186 14 246 186 14
45297 -239 182 13 216 158 10 185 133 11 152 99 6
45298 -104 69 6 18 14 6 2 2 6 2 2 6
45299 - 2 2 6 2 2 6 2 2 6 2 2 6
45300 - 2 2 6 2 2 6 2 2 6 2 2 6
45301 - 2 2 6 2 2 6 2 2 6 2 2 6
45302 - 2 2 6 6 6 6 80 54 7 152 99 6
45303 -192 133 9 219 162 10 236 178 12 239 182 13
45304 -246 186 14 242 186 14 239 182 13 236 178 12
45305 -224 166 10 206 145 10 192 133 9 154 121 60
45306 - 94 94 94 62 62 62 42 42 42 22 22 22
45307 - 14 14 14 6 6 6 0 0 0 0 0 0
45308 - 0 0 0 0 0 0 0 0 0 0 0 0
45309 - 0 0 0 0 0 0 0 0 0 0 0 0
45310 - 0 0 0 0 0 0 0 0 0 0 0 0
45311 - 0 0 0 0 0 0 0 0 0 6 6 6
45312 - 18 18 18 34 34 34 58 58 58 78 78 78
45313 -101 98 89 124 112 88 142 110 46 156 107 11
45314 -163 110 8 167 114 7 175 118 6 180 123 7
45315 -185 133 11 197 138 11 210 150 10 219 162 10
45316 -226 170 11 236 178 12 236 178 12 234 174 13
45317 -219 162 10 197 138 11 163 110 8 130 83 6
45318 - 91 60 6 10 10 10 2 2 6 2 2 6
45319 - 18 18 18 38 38 38 38 38 38 38 38 38
45320 - 38 38 38 38 38 38 38 38 38 38 38 38
45321 - 38 38 38 38 38 38 26 26 26 2 2 6
45322 - 2 2 6 6 6 6 70 47 6 137 92 6
45323 -175 118 6 200 144 11 219 162 10 230 174 11
45324 -234 174 13 230 174 11 219 162 10 210 150 10
45325 -192 133 9 163 110 8 124 112 88 82 82 82
45326 - 50 50 50 30 30 30 14 14 14 6 6 6
45327 - 0 0 0 0 0 0 0 0 0 0 0 0
45328 - 0 0 0 0 0 0 0 0 0 0 0 0
45329 - 0 0 0 0 0 0 0 0 0 0 0 0
45330 - 0 0 0 0 0 0 0 0 0 0 0 0
45331 - 0 0 0 0 0 0 0 0 0 0 0 0
45332 - 6 6 6 14 14 14 22 22 22 34 34 34
45333 - 42 42 42 58 58 58 74 74 74 86 86 86
45334 -101 98 89 122 102 70 130 98 46 121 87 25
45335 -137 92 6 152 99 6 163 110 8 180 123 7
45336 -185 133 11 197 138 11 206 145 10 200 144 11
45337 -180 123 7 156 107 11 130 83 6 104 69 6
45338 - 50 34 6 54 54 54 110 110 110 101 98 89
45339 - 86 86 86 82 82 82 78 78 78 78 78 78
45340 - 78 78 78 78 78 78 78 78 78 78 78 78
45341 - 78 78 78 82 82 82 86 86 86 94 94 94
45342 -106 106 106 101 101 101 86 66 34 124 80 6
45343 -156 107 11 180 123 7 192 133 9 200 144 11
45344 -206 145 10 200 144 11 192 133 9 175 118 6
45345 -139 102 15 109 106 95 70 70 70 42 42 42
45346 - 22 22 22 10 10 10 0 0 0 0 0 0
45347 - 0 0 0 0 0 0 0 0 0 0 0 0
45348 - 0 0 0 0 0 0 0 0 0 0 0 0
45349 - 0 0 0 0 0 0 0 0 0 0 0 0
45350 - 0 0 0 0 0 0 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 6 6 6 10 10 10
45353 - 14 14 14 22 22 22 30 30 30 38 38 38
45354 - 50 50 50 62 62 62 74 74 74 90 90 90
45355 -101 98 89 112 100 78 121 87 25 124 80 6
45356 -137 92 6 152 99 6 152 99 6 152 99 6
45357 -138 86 6 124 80 6 98 70 6 86 66 30
45358 -101 98 89 82 82 82 58 58 58 46 46 46
45359 - 38 38 38 34 34 34 34 34 34 34 34 34
45360 - 34 34 34 34 34 34 34 34 34 34 34 34
45361 - 34 34 34 34 34 34 38 38 38 42 42 42
45362 - 54 54 54 82 82 82 94 86 76 91 60 6
45363 -134 86 6 156 107 11 167 114 7 175 118 6
45364 -175 118 6 167 114 7 152 99 6 121 87 25
45365 -101 98 89 62 62 62 34 34 34 18 18 18
45366 - 6 6 6 0 0 0 0 0 0 0 0 0
45367 - 0 0 0 0 0 0 0 0 0 0 0 0
45368 - 0 0 0 0 0 0 0 0 0 0 0 0
45369 - 0 0 0 0 0 0 0 0 0 0 0 0
45370 - 0 0 0 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 6 6 6 6 6 6 10 10 10
45374 - 18 18 18 22 22 22 30 30 30 42 42 42
45375 - 50 50 50 66 66 66 86 86 86 101 98 89
45376 -106 86 58 98 70 6 104 69 6 104 69 6
45377 -104 69 6 91 60 6 82 62 34 90 90 90
45378 - 62 62 62 38 38 38 22 22 22 14 14 14
45379 - 10 10 10 10 10 10 10 10 10 10 10 10
45380 - 10 10 10 10 10 10 6 6 6 10 10 10
45381 - 10 10 10 10 10 10 10 10 10 14 14 14
45382 - 22 22 22 42 42 42 70 70 70 89 81 66
45383 - 80 54 7 104 69 6 124 80 6 137 92 6
45384 -134 86 6 116 81 8 100 82 52 86 86 86
45385 - 58 58 58 30 30 30 14 14 14 6 6 6
45386 - 0 0 0 0 0 0 0 0 0 0 0 0
45387 - 0 0 0 0 0 0 0 0 0 0 0 0
45388 - 0 0 0 0 0 0 0 0 0 0 0 0
45389 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
45394 - 0 0 0 6 6 6 10 10 10 14 14 14
45395 - 18 18 18 26 26 26 38 38 38 54 54 54
45396 - 70 70 70 86 86 86 94 86 76 89 81 66
45397 - 89 81 66 86 86 86 74 74 74 50 50 50
45398 - 30 30 30 14 14 14 6 6 6 0 0 0
45399 - 0 0 0 0 0 0 0 0 0 0 0 0
45400 - 0 0 0 0 0 0 0 0 0 0 0 0
45401 - 0 0 0 0 0 0 0 0 0 0 0 0
45402 - 6 6 6 18 18 18 34 34 34 58 58 58
45403 - 82 82 82 89 81 66 89 81 66 89 81 66
45404 - 94 86 66 94 86 76 74 74 74 50 50 50
45405 - 26 26 26 14 14 14 6 6 6 0 0 0
45406 - 0 0 0 0 0 0 0 0 0 0 0 0
45407 - 0 0 0 0 0 0 0 0 0 0 0 0
45408 - 0 0 0 0 0 0 0 0 0 0 0 0
45409 - 0 0 0 0 0 0 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 0 0 0
45414 - 0 0 0 0 0 0 0 0 0 0 0 0
45415 - 6 6 6 6 6 6 14 14 14 18 18 18
45416 - 30 30 30 38 38 38 46 46 46 54 54 54
45417 - 50 50 50 42 42 42 30 30 30 18 18 18
45418 - 10 10 10 0 0 0 0 0 0 0 0 0
45419 - 0 0 0 0 0 0 0 0 0 0 0 0
45420 - 0 0 0 0 0 0 0 0 0 0 0 0
45421 - 0 0 0 0 0 0 0 0 0 0 0 0
45422 - 0 0 0 6 6 6 14 14 14 26 26 26
45423 - 38 38 38 50 50 50 58 58 58 58 58 58
45424 - 54 54 54 42 42 42 30 30 30 18 18 18
45425 - 10 10 10 0 0 0 0 0 0 0 0 0
45426 - 0 0 0 0 0 0 0 0 0 0 0 0
45427 - 0 0 0 0 0 0 0 0 0 0 0 0
45428 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 0 0 0 0 0 0 0 0 0 0 0 0
45435 - 0 0 0 0 0 0 0 0 0 6 6 6
45436 - 6 6 6 10 10 10 14 14 14 18 18 18
45437 - 18 18 18 14 14 14 10 10 10 6 6 6
45438 - 0 0 0 0 0 0 0 0 0 0 0 0
45439 - 0 0 0 0 0 0 0 0 0 0 0 0
45440 - 0 0 0 0 0 0 0 0 0 0 0 0
45441 - 0 0 0 0 0 0 0 0 0 0 0 0
45442 - 0 0 0 0 0 0 0 0 0 6 6 6
45443 - 14 14 14 18 18 18 22 22 22 22 22 22
45444 - 18 18 18 14 14 14 10 10 10 6 6 6
45445 - 0 0 0 0 0 0 0 0 0 0 0 0
45446 - 0 0 0 0 0 0 0 0 0 0 0 0
45447 - 0 0 0 0 0 0 0 0 0 0 0 0
45448 - 0 0 0 0 0 0 0 0 0 0 0 0
45449 - 0 0 0 0 0 0 0 0 0 0 0 0
45450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45463 +4 4 4 4 4 4
45464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45477 +4 4 4 4 4 4
45478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45491 +4 4 4 4 4 4
45492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45505 +4 4 4 4 4 4
45506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45519 +4 4 4 4 4 4
45520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45533 +4 4 4 4 4 4
45534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45538 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
45539 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
45540 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45543 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
45544 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
45545 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
45546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45547 +4 4 4 4 4 4
45548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45552 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
45553 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
45554 +5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
45558 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
45559 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
45560 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45561 +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 4 4 4 4 4 4 4 4 4 4 4 4
45566 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
45567 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
45568 +0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
45572 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
45573 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
45574 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
45575 +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 5 5 5 5 5 5 2 2 2 0 0 0
45580 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
45581 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
45582 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
45585 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
45586 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
45587 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
45588 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
45589 +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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
45594 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
45595 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
45596 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
45597 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45598 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
45599 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
45600 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
45601 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
45602 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
45603 +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 5 5 5
45607 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
45608 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
45609 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
45610 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
45611 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
45612 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
45613 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
45614 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
45615 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
45616 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
45617 +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 5 5 5 3 3 3
45621 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
45622 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
45623 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
45624 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
45625 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
45626 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
45627 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
45628 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
45629 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
45630 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
45631 +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 2 2 2 0 0 0 4 0 0
45635 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
45636 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
45637 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
45638 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
45639 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
45640 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
45641 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
45642 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
45643 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
45644 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
45645 +4 4 4 4 4 4
45646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45648 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
45649 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
45650 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
45651 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
45652 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
45653 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
45654 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
45655 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
45656 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
45657 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
45658 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
45659 +4 4 4 4 4 4
45660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45662 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
45663 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
45664 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
45665 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
45666 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
45667 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
45668 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
45669 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
45670 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
45671 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
45672 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
45673 +4 4 4 4 4 4
45674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45675 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
45676 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
45677 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
45678 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
45679 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
45680 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
45681 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
45682 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
45683 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
45684 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
45685 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
45686 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
45687 +4 4 4 4 4 4
45688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45689 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
45690 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
45691 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
45692 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
45693 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
45694 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
45695 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
45696 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
45697 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
45698 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
45699 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
45700 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
45701 +0 0 0 4 4 4
45702 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
45703 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
45704 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
45705 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
45706 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
45707 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
45708 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
45709 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
45710 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
45711 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
45712 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
45713 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
45714 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
45715 +2 0 0 0 0 0
45716 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
45717 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
45718 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
45719 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
45720 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
45721 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
45722 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
45723 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
45724 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
45725 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
45726 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
45727 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
45728 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
45729 +37 38 37 0 0 0
45730 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
45731 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
45732 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
45733 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
45734 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
45735 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
45736 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
45737 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
45738 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
45739 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
45740 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
45741 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
45742 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
45743 +85 115 134 4 0 0
45744 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
45745 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
45746 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
45747 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
45748 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
45749 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
45750 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
45751 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
45752 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
45753 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
45754 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
45755 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
45756 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
45757 +60 73 81 4 0 0
45758 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
45759 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
45760 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
45761 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
45762 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
45763 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
45764 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
45765 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
45766 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
45767 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
45768 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
45769 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
45770 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
45771 +16 19 21 4 0 0
45772 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
45773 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
45774 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
45775 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
45776 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
45777 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
45778 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
45779 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
45780 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
45781 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
45782 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
45783 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
45784 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
45785 +4 0 0 4 3 3
45786 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
45787 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
45788 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
45789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
45790 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
45791 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
45792 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
45793 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
45794 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
45795 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
45796 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
45797 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
45798 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
45799 +3 2 2 4 4 4
45800 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
45801 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
45802 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
45803 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
45804 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
45805 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
45806 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
45807 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
45808 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
45809 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
45810 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
45811 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
45812 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
45813 +4 4 4 4 4 4
45814 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
45815 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
45816 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
45817 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
45818 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
45819 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
45820 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
45821 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
45822 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
45823 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
45824 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
45825 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
45826 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
45827 +4 4 4 4 4 4
45828 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
45829 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
45830 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
45831 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
45832 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
45833 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
45834 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
45835 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
45836 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
45837 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
45838 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
45839 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
45840 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
45841 +5 5 5 5 5 5
45842 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
45843 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
45844 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
45845 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
45846 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
45847 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45848 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
45849 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
45850 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
45851 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
45852 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
45853 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
45854 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
45855 +5 5 5 4 4 4
45856 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
45857 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
45858 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
45859 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
45860 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45861 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
45862 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
45863 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
45864 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
45865 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
45866 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
45867 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
45868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45869 +4 4 4 4 4 4
45870 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
45871 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
45872 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
45873 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
45874 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
45875 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45876 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45877 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
45878 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
45879 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
45880 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
45881 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
45882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45883 +4 4 4 4 4 4
45884 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
45885 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
45886 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
45887 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
45888 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45889 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
45890 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
45891 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
45892 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
45893 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
45894 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
45895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45897 +4 4 4 4 4 4
45898 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
45899 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
45900 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
45901 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
45902 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45903 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45904 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45905 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
45906 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
45907 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
45908 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
45909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45911 +4 4 4 4 4 4
45912 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
45913 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
45914 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
45915 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
45916 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45917 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
45918 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
45919 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
45920 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
45921 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
45922 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45925 +4 4 4 4 4 4
45926 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
45927 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
45928 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
45929 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
45930 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45931 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
45932 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
45933 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
45934 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
45935 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
45936 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
45937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45939 +4 4 4 4 4 4
45940 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
45941 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
45942 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
45943 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
45944 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45945 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
45946 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
45947 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
45948 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
45949 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
45950 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
45951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45953 +4 4 4 4 4 4
45954 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
45955 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
45956 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
45957 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
45958 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
45959 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
45960 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
45961 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
45962 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
45963 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
45964 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45967 +4 4 4 4 4 4
45968 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
45969 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
45970 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
45971 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
45972 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45973 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
45974 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
45975 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
45976 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
45977 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
45978 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45981 +4 4 4 4 4 4
45982 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
45983 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
45984 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
45985 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
45986 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45987 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
45988 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
45989 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
45990 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
45991 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
45992 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45995 +4 4 4 4 4 4
45996 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
45997 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
45998 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
45999 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46000 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46001 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
46002 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
46003 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
46004 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46005 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46006 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46009 +4 4 4 4 4 4
46010 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46011 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
46012 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46013 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
46014 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
46015 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
46016 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
46017 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
46018 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46019 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46020 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46023 +4 4 4 4 4 4
46024 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46025 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
46026 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46027 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
46028 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46029 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
46030 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
46031 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
46032 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46033 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46034 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46037 +4 4 4 4 4 4
46038 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
46039 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
46040 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46041 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
46042 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
46043 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
46044 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
46045 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
46046 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46047 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46048 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46051 +4 4 4 4 4 4
46052 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
46053 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
46054 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46055 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
46056 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
46057 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
46058 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
46059 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
46060 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46061 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46062 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46065 +4 4 4 4 4 4
46066 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46067 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
46068 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46069 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
46070 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
46071 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
46072 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
46073 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
46074 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46075 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46076 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46079 +4 4 4 4 4 4
46080 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
46081 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
46082 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46083 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
46084 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
46085 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
46086 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
46087 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
46088 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
46089 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46090 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46093 +4 4 4 4 4 4
46094 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46095 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
46096 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
46097 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
46098 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
46099 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
46100 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
46101 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
46102 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46103 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46104 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46107 +4 4 4 4 4 4
46108 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46109 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
46110 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46111 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
46112 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
46113 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
46114 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
46115 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
46116 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46117 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46118 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46121 +4 4 4 4 4 4
46122 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46123 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
46124 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
46125 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
46126 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
46127 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
46128 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46129 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
46130 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46131 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46132 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46135 +4 4 4 4 4 4
46136 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46137 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
46138 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
46139 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46140 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
46141 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
46142 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46143 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
46144 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46145 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46146 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46149 +4 4 4 4 4 4
46150 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46151 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
46152 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
46153 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
46154 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
46155 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
46156 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
46157 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
46158 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
46159 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46160 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46163 +4 4 4 4 4 4
46164 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46165 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
46166 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
46167 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
46168 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
46169 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
46170 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
46171 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
46172 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
46173 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46174 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46177 +4 4 4 4 4 4
46178 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
46179 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
46180 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
46181 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
46182 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46183 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
46184 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
46185 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
46186 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
46187 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46188 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46191 +4 4 4 4 4 4
46192 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46193 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
46194 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
46195 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
46196 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
46197 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
46198 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
46199 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
46200 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
46201 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46202 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46205 +4 4 4 4 4 4
46206 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
46207 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
46208 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
46209 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
46210 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
46211 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
46212 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
46213 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
46214 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
46215 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
46216 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46219 +4 4 4 4 4 4
46220 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
46221 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46222 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
46223 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
46224 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
46225 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
46226 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
46227 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
46228 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
46229 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
46230 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46233 +4 4 4 4 4 4
46234 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
46235 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46236 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
46237 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
46238 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
46239 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
46240 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46241 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
46242 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
46243 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
46244 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46247 +4 4 4 4 4 4
46248 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
46249 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
46250 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
46251 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
46252 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
46253 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
46254 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
46255 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
46256 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
46257 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
46258 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46261 +4 4 4 4 4 4
46262 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
46263 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
46264 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46265 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
46266 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
46267 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
46268 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
46269 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
46270 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
46271 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
46272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46275 +4 4 4 4 4 4
46276 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46277 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
46278 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
46279 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
46280 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
46281 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
46282 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
46283 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
46284 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
46285 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46289 +4 4 4 4 4 4
46290 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
46291 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
46292 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
46293 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
46294 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
46295 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
46296 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
46297 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
46298 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
46299 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46303 +4 4 4 4 4 4
46304 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
46305 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
46306 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
46307 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
46308 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
46309 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
46310 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
46311 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
46312 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46313 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46317 +4 4 4 4 4 4
46318 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
46319 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46320 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
46321 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46322 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
46323 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
46324 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
46325 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
46326 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
46327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46331 +4 4 4 4 4 4
46332 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
46333 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
46334 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
46335 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
46336 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
46337 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
46338 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
46339 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
46340 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
46341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46345 +4 4 4 4 4 4
46346 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
46347 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
46348 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
46349 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
46350 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
46351 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
46352 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
46353 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
46354 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46359 +4 4 4 4 4 4
46360 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
46361 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
46362 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46363 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
46364 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
46365 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
46366 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
46367 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
46368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46373 +4 4 4 4 4 4
46374 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
46375 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
46376 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
46377 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
46378 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
46379 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
46380 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
46381 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46387 +4 4 4 4 4 4
46388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46389 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
46390 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46391 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
46392 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
46393 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
46394 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
46395 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
46396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46401 +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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
46404 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
46405 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
46406 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
46407 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
46408 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
46409 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
46410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46415 +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 5 5 5 5 5 5 5 5 5
46418 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
46419 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
46420 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
46421 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
46422 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
46423 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46429 +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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
46433 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
46434 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
46435 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
46436 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
46437 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46443 +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 5 5 5
46447 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46448 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
46449 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
46450 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
46451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46457 +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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
46462 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46463 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
46464 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
46465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 5 5 5 4 3 3 5 5 5 6 6 6
46476 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46477 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
46478 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
46479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46483 +4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 5 5 5 4 3 3 5 5 5
46490 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
46491 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
46492 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
46493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46497 +4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 5 5 5
46504 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
46505 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46506 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46511 +4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
46518 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
46519 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
46520 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46525 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
46532 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
46533 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
46534 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46538 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46539 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
46546 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
46547 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
46548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46552 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 4 4 4 4 4 4
46560 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
46561 +5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46566 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
46570 diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
46571 index fe92eed..106e085 100644
46572 --- a/drivers/video/mb862xx/mb862xxfb_accel.c
46573 +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
46574 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
46575 struct mb862xxfb_par *par = info->par;
46576
46577 if (info->var.bits_per_pixel == 32) {
46578 - info->fbops->fb_fillrect = cfb_fillrect;
46579 - info->fbops->fb_copyarea = cfb_copyarea;
46580 - info->fbops->fb_imageblit = cfb_imageblit;
46581 + pax_open_kernel();
46582 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
46583 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
46584 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
46585 + pax_close_kernel();
46586 } else {
46587 outreg(disp, GC_L0EM, 3);
46588 - info->fbops->fb_fillrect = mb86290fb_fillrect;
46589 - info->fbops->fb_copyarea = mb86290fb_copyarea;
46590 - info->fbops->fb_imageblit = mb86290fb_imageblit;
46591 + pax_open_kernel();
46592 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
46593 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
46594 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
46595 + pax_close_kernel();
46596 }
46597 outreg(draw, GDC_REG_DRAW_BASE, 0);
46598 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
46599 diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
46600 index ff22871..b129bed 100644
46601 --- a/drivers/video/nvidia/nvidia.c
46602 +++ b/drivers/video/nvidia/nvidia.c
46603 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
46604 info->fix.line_length = (info->var.xres_virtual *
46605 info->var.bits_per_pixel) >> 3;
46606 if (info->var.accel_flags) {
46607 - info->fbops->fb_imageblit = nvidiafb_imageblit;
46608 - info->fbops->fb_fillrect = nvidiafb_fillrect;
46609 - info->fbops->fb_copyarea = nvidiafb_copyarea;
46610 - info->fbops->fb_sync = nvidiafb_sync;
46611 + pax_open_kernel();
46612 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
46613 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
46614 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
46615 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
46616 + pax_close_kernel();
46617 info->pixmap.scan_align = 4;
46618 info->flags &= ~FBINFO_HWACCEL_DISABLED;
46619 info->flags |= FBINFO_READS_FAST;
46620 NVResetGraphics(info);
46621 } else {
46622 - info->fbops->fb_imageblit = cfb_imageblit;
46623 - info->fbops->fb_fillrect = cfb_fillrect;
46624 - info->fbops->fb_copyarea = cfb_copyarea;
46625 - info->fbops->fb_sync = NULL;
46626 + pax_open_kernel();
46627 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
46628 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
46629 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
46630 + *(void **)&info->fbops->fb_sync = NULL;
46631 + pax_close_kernel();
46632 info->pixmap.scan_align = 1;
46633 info->flags |= FBINFO_HWACCEL_DISABLED;
46634 info->flags &= ~FBINFO_READS_FAST;
46635 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
46636 info->pixmap.size = 8 * 1024;
46637 info->pixmap.flags = FB_PIXMAP_SYSTEM;
46638
46639 - if (!hwcur)
46640 - info->fbops->fb_cursor = NULL;
46641 + if (!hwcur) {
46642 + pax_open_kernel();
46643 + *(void **)&info->fbops->fb_cursor = NULL;
46644 + pax_close_kernel();
46645 + }
46646
46647 info->var.accel_flags = (!noaccel);
46648
46649 diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
46650 index 76d9053..dec2bfd 100644
46651 --- a/drivers/video/s1d13xxxfb.c
46652 +++ b/drivers/video/s1d13xxxfb.c
46653 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
46654
46655 switch(prod_id) {
46656 case S1D13506_PROD_ID: /* activate acceleration */
46657 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
46658 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
46659 + pax_open_kernel();
46660 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
46661 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
46662 + pax_close_kernel();
46663 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
46664 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
46665 break;
46666 diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
46667 index 97bd662..39fab85 100644
46668 --- a/drivers/video/smscufx.c
46669 +++ b/drivers/video/smscufx.c
46670 @@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
46671 fb_deferred_io_cleanup(info);
46672 kfree(info->fbdefio);
46673 info->fbdefio = NULL;
46674 - info->fbops->fb_mmap = ufx_ops_mmap;
46675 + pax_open_kernel();
46676 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
46677 + pax_close_kernel();
46678 }
46679
46680 pr_debug("released /dev/fb%d user=%d count=%d",
46681 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
46682 index 86d449e..8e04dc5 100644
46683 --- a/drivers/video/udlfb.c
46684 +++ b/drivers/video/udlfb.c
46685 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
46686 dlfb_urb_completion(urb);
46687
46688 error:
46689 - atomic_add(bytes_sent, &dev->bytes_sent);
46690 - atomic_add(bytes_identical, &dev->bytes_identical);
46691 - atomic_add(width*height*2, &dev->bytes_rendered);
46692 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
46693 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
46694 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
46695 end_cycles = get_cycles();
46696 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
46697 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
46698 >> 10)), /* Kcycles */
46699 &dev->cpu_kcycles_used);
46700
46701 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
46702 dlfb_urb_completion(urb);
46703
46704 error:
46705 - atomic_add(bytes_sent, &dev->bytes_sent);
46706 - atomic_add(bytes_identical, &dev->bytes_identical);
46707 - atomic_add(bytes_rendered, &dev->bytes_rendered);
46708 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
46709 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
46710 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
46711 end_cycles = get_cycles();
46712 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
46713 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
46714 >> 10)), /* Kcycles */
46715 &dev->cpu_kcycles_used);
46716 }
46717 @@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
46718 fb_deferred_io_cleanup(info);
46719 kfree(info->fbdefio);
46720 info->fbdefio = NULL;
46721 - info->fbops->fb_mmap = dlfb_ops_mmap;
46722 + pax_open_kernel();
46723 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
46724 + pax_close_kernel();
46725 }
46726
46727 pr_warn("released /dev/fb%d user=%d count=%d\n",
46728 @@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
46729 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46730 struct dlfb_data *dev = fb_info->par;
46731 return snprintf(buf, PAGE_SIZE, "%u\n",
46732 - atomic_read(&dev->bytes_rendered));
46733 + atomic_read_unchecked(&dev->bytes_rendered));
46734 }
46735
46736 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
46737 @@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
46738 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46739 struct dlfb_data *dev = fb_info->par;
46740 return snprintf(buf, PAGE_SIZE, "%u\n",
46741 - atomic_read(&dev->bytes_identical));
46742 + atomic_read_unchecked(&dev->bytes_identical));
46743 }
46744
46745 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
46746 @@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
46747 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46748 struct dlfb_data *dev = fb_info->par;
46749 return snprintf(buf, PAGE_SIZE, "%u\n",
46750 - atomic_read(&dev->bytes_sent));
46751 + atomic_read_unchecked(&dev->bytes_sent));
46752 }
46753
46754 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
46755 @@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
46756 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46757 struct dlfb_data *dev = fb_info->par;
46758 return snprintf(buf, PAGE_SIZE, "%u\n",
46759 - atomic_read(&dev->cpu_kcycles_used));
46760 + atomic_read_unchecked(&dev->cpu_kcycles_used));
46761 }
46762
46763 static ssize_t edid_show(
46764 @@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
46765 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46766 struct dlfb_data *dev = fb_info->par;
46767
46768 - atomic_set(&dev->bytes_rendered, 0);
46769 - atomic_set(&dev->bytes_identical, 0);
46770 - atomic_set(&dev->bytes_sent, 0);
46771 - atomic_set(&dev->cpu_kcycles_used, 0);
46772 + atomic_set_unchecked(&dev->bytes_rendered, 0);
46773 + atomic_set_unchecked(&dev->bytes_identical, 0);
46774 + atomic_set_unchecked(&dev->bytes_sent, 0);
46775 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
46776
46777 return count;
46778 }
46779 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
46780 index b75db01..ad2f34a 100644
46781 --- a/drivers/video/uvesafb.c
46782 +++ b/drivers/video/uvesafb.c
46783 @@ -19,6 +19,7 @@
46784 #include <linux/io.h>
46785 #include <linux/mutex.h>
46786 #include <linux/slab.h>
46787 +#include <linux/moduleloader.h>
46788 #include <video/edid.h>
46789 #include <video/uvesafb.h>
46790 #ifdef CONFIG_X86
46791 @@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
46792 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
46793 par->pmi_setpal = par->ypan = 0;
46794 } else {
46795 +
46796 +#ifdef CONFIG_PAX_KERNEXEC
46797 +#ifdef CONFIG_MODULES
46798 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
46799 +#endif
46800 + if (!par->pmi_code) {
46801 + par->pmi_setpal = par->ypan = 0;
46802 + return 0;
46803 + }
46804 +#endif
46805 +
46806 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
46807 + task->t.regs.edi);
46808 +
46809 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46810 + pax_open_kernel();
46811 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
46812 + pax_close_kernel();
46813 +
46814 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
46815 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
46816 +#else
46817 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
46818 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
46819 +#endif
46820 +
46821 printk(KERN_INFO "uvesafb: protected mode interface info at "
46822 "%04x:%04x\n",
46823 (u16)task->t.regs.es, (u16)task->t.regs.edi);
46824 @@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
46825 par->ypan = ypan;
46826
46827 if (par->pmi_setpal || par->ypan) {
46828 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
46829 if (__supported_pte_mask & _PAGE_NX) {
46830 par->pmi_setpal = par->ypan = 0;
46831 printk(KERN_WARNING "uvesafb: NX protection is actively."
46832 "We have better not to use the PMI.\n");
46833 - } else {
46834 + } else
46835 +#endif
46836 uvesafb_vbe_getpmi(task, par);
46837 - }
46838 }
46839 #else
46840 /* The protected mode interface is not available on non-x86. */
46841 @@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
46842 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
46843
46844 /* Disable blanking if the user requested so. */
46845 - if (!blank)
46846 - info->fbops->fb_blank = NULL;
46847 + if (!blank) {
46848 + pax_open_kernel();
46849 + *(void **)&info->fbops->fb_blank = NULL;
46850 + pax_close_kernel();
46851 + }
46852
46853 /*
46854 * Find out how much IO memory is required for the mode with
46855 @@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
46856 info->flags = FBINFO_FLAG_DEFAULT |
46857 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
46858
46859 - if (!par->ypan)
46860 - info->fbops->fb_pan_display = NULL;
46861 + if (!par->ypan) {
46862 + pax_open_kernel();
46863 + *(void **)&info->fbops->fb_pan_display = NULL;
46864 + pax_close_kernel();
46865 + }
46866 }
46867
46868 static void uvesafb_init_mtrr(struct fb_info *info)
46869 @@ -1836,6 +1866,11 @@ out:
46870 if (par->vbe_modes)
46871 kfree(par->vbe_modes);
46872
46873 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46874 + if (par->pmi_code)
46875 + module_free_exec(NULL, par->pmi_code);
46876 +#endif
46877 +
46878 framebuffer_release(info);
46879 return err;
46880 }
46881 @@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
46882 kfree(par->vbe_state_orig);
46883 if (par->vbe_state_saved)
46884 kfree(par->vbe_state_saved);
46885 +
46886 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46887 + if (par->pmi_code)
46888 + module_free_exec(NULL, par->pmi_code);
46889 +#endif
46890 +
46891 }
46892
46893 framebuffer_release(info);
46894 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
46895 index 501b340..d80aa17 100644
46896 --- a/drivers/video/vesafb.c
46897 +++ b/drivers/video/vesafb.c
46898 @@ -9,6 +9,7 @@
46899 */
46900
46901 #include <linux/module.h>
46902 +#include <linux/moduleloader.h>
46903 #include <linux/kernel.h>
46904 #include <linux/errno.h>
46905 #include <linux/string.h>
46906 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
46907 static int vram_total __initdata; /* Set total amount of memory */
46908 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
46909 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
46910 -static void (*pmi_start)(void) __read_mostly;
46911 -static void (*pmi_pal) (void) __read_mostly;
46912 +static void (*pmi_start)(void) __read_only;
46913 +static void (*pmi_pal) (void) __read_only;
46914 static int depth __read_mostly;
46915 static int vga_compat __read_mostly;
46916 /* --------------------------------------------------------------------- */
46917 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
46918 unsigned int size_vmode;
46919 unsigned int size_remap;
46920 unsigned int size_total;
46921 + void *pmi_code = NULL;
46922
46923 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
46924 return -ENODEV;
46925 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
46926 size_remap = size_total;
46927 vesafb_fix.smem_len = size_remap;
46928
46929 -#ifndef __i386__
46930 - screen_info.vesapm_seg = 0;
46931 -#endif
46932 -
46933 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
46934 printk(KERN_WARNING
46935 "vesafb: cannot reserve video memory at 0x%lx\n",
46936 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
46937 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
46938 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
46939
46940 +#ifdef __i386__
46941 +
46942 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46943 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
46944 + if (!pmi_code)
46945 +#elif !defined(CONFIG_PAX_KERNEXEC)
46946 + if (0)
46947 +#endif
46948 +
46949 +#endif
46950 + screen_info.vesapm_seg = 0;
46951 +
46952 if (screen_info.vesapm_seg) {
46953 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
46954 - screen_info.vesapm_seg,screen_info.vesapm_off);
46955 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
46956 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
46957 }
46958
46959 if (screen_info.vesapm_seg < 0xc000)
46960 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
46961
46962 if (ypan || pmi_setpal) {
46963 unsigned short *pmi_base;
46964 +
46965 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
46966 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
46967 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
46968 +
46969 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46970 + pax_open_kernel();
46971 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
46972 +#else
46973 + pmi_code = pmi_base;
46974 +#endif
46975 +
46976 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
46977 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
46978 +
46979 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46980 + pmi_start = ktva_ktla(pmi_start);
46981 + pmi_pal = ktva_ktla(pmi_pal);
46982 + pax_close_kernel();
46983 +#endif
46984 +
46985 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
46986 if (pmi_base[3]) {
46987 printk(KERN_INFO "vesafb: pmi: ports = ");
46988 @@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
46989 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
46990 (ypan ? FBINFO_HWACCEL_YPAN : 0);
46991
46992 - if (!ypan)
46993 - info->fbops->fb_pan_display = NULL;
46994 + if (!ypan) {
46995 + pax_open_kernel();
46996 + *(void **)&info->fbops->fb_pan_display = NULL;
46997 + pax_close_kernel();
46998 + }
46999
47000 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
47001 err = -ENOMEM;
47002 @@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47003 info->node, info->fix.id);
47004 return 0;
47005 err:
47006 +
47007 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47008 + module_free_exec(NULL, pmi_code);
47009 +#endif
47010 +
47011 if (info->screen_base)
47012 iounmap(info->screen_base);
47013 framebuffer_release(info);
47014 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
47015 index 88714ae..16c2e11 100644
47016 --- a/drivers/video/via/via_clock.h
47017 +++ b/drivers/video/via/via_clock.h
47018 @@ -56,7 +56,7 @@ struct via_clock {
47019
47020 void (*set_engine_pll_state)(u8 state);
47021 void (*set_engine_pll)(struct via_pll_config config);
47022 -};
47023 +} __no_const;
47024
47025
47026 static inline u32 get_pll_internal_frequency(u32 ref_freq,
47027 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
47028 index fef20db..d28b1ab 100644
47029 --- a/drivers/xen/xenfs/xenstored.c
47030 +++ b/drivers/xen/xenfs/xenstored.c
47031 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
47032 static int xsd_kva_open(struct inode *inode, struct file *file)
47033 {
47034 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
47035 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47036 + NULL);
47037 +#else
47038 xen_store_interface);
47039 +#endif
47040 +
47041 if (!file->private_data)
47042 return -ENOMEM;
47043 return 0;
47044 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
47045 index 890bed5..17ae73e 100644
47046 --- a/fs/9p/vfs_inode.c
47047 +++ b/fs/9p/vfs_inode.c
47048 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47049 void
47050 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47051 {
47052 - char *s = nd_get_link(nd);
47053 + const char *s = nd_get_link(nd);
47054
47055 p9_debug(P9_DEBUG_VFS, " %s %s\n",
47056 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
47057 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
47058 index 0efd152..b5802ad 100644
47059 --- a/fs/Kconfig.binfmt
47060 +++ b/fs/Kconfig.binfmt
47061 @@ -89,7 +89,7 @@ config HAVE_AOUT
47062
47063 config BINFMT_AOUT
47064 tristate "Kernel support for a.out and ECOFF binaries"
47065 - depends on HAVE_AOUT
47066 + depends on HAVE_AOUT && BROKEN
47067 ---help---
47068 A.out (Assembler.OUTput) is a set of formats for libraries and
47069 executables used in the earliest versions of UNIX. Linux used
47070 diff --git a/fs/aio.c b/fs/aio.c
47071 index 71f613c..9d01f1f 100644
47072 --- a/fs/aio.c
47073 +++ b/fs/aio.c
47074 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
47075 size += sizeof(struct io_event) * nr_events;
47076 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
47077
47078 - if (nr_pages < 0)
47079 + if (nr_pages <= 0)
47080 return -EINVAL;
47081
47082 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
47083 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
47084 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47085 {
47086 ssize_t ret;
47087 + struct iovec iovstack;
47088
47089 #ifdef CONFIG_COMPAT
47090 if (compat)
47091 ret = compat_rw_copy_check_uvector(type,
47092 (struct compat_iovec __user *)kiocb->ki_buf,
47093 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47094 + kiocb->ki_nbytes, 1, &iovstack,
47095 &kiocb->ki_iovec);
47096 else
47097 #endif
47098 ret = rw_copy_check_uvector(type,
47099 (struct iovec __user *)kiocb->ki_buf,
47100 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47101 + kiocb->ki_nbytes, 1, &iovstack,
47102 &kiocb->ki_iovec);
47103 if (ret < 0)
47104 goto out;
47105 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47106 if (ret < 0)
47107 goto out;
47108
47109 + if (kiocb->ki_iovec == &iovstack) {
47110 + kiocb->ki_inline_vec = iovstack;
47111 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
47112 + }
47113 kiocb->ki_nr_segs = kiocb->ki_nbytes;
47114 kiocb->ki_cur_seg = 0;
47115 /* ki_nbytes/left now reflect bytes instead of segs */
47116 diff --git a/fs/attr.c b/fs/attr.c
47117 index 1449adb..a2038c2 100644
47118 --- a/fs/attr.c
47119 +++ b/fs/attr.c
47120 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
47121 unsigned long limit;
47122
47123 limit = rlimit(RLIMIT_FSIZE);
47124 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
47125 if (limit != RLIM_INFINITY && offset > limit)
47126 goto out_sig;
47127 if (offset > inode->i_sb->s_maxbytes)
47128 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
47129 index 03bc1d3..6205356 100644
47130 --- a/fs/autofs4/waitq.c
47131 +++ b/fs/autofs4/waitq.c
47132 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
47133 {
47134 unsigned long sigpipe, flags;
47135 mm_segment_t fs;
47136 - const char *data = (const char *)addr;
47137 + const char __user *data = (const char __force_user *)addr;
47138 ssize_t wr = 0;
47139
47140 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
47141 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
47142 return 1;
47143 }
47144
47145 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47146 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
47147 +#endif
47148 +
47149 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47150 enum autofs_notify notify)
47151 {
47152 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47153
47154 /* If this is a direct mount request create a dummy name */
47155 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
47156 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47157 + /* this name does get written to userland via autofs4_write() */
47158 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
47159 +#else
47160 qstr.len = sprintf(name, "%p", dentry);
47161 +#endif
47162 else {
47163 qstr.len = autofs4_getpath(sbi, dentry, &name);
47164 if (!qstr.len) {
47165 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
47166 index 2b3bda8..6a2d4be 100644
47167 --- a/fs/befs/linuxvfs.c
47168 +++ b/fs/befs/linuxvfs.c
47169 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47170 {
47171 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
47172 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
47173 - char *link = nd_get_link(nd);
47174 + const char *link = nd_get_link(nd);
47175 if (!IS_ERR(link))
47176 kfree(link);
47177 }
47178 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
47179 index 6043567..16a9239 100644
47180 --- a/fs/binfmt_aout.c
47181 +++ b/fs/binfmt_aout.c
47182 @@ -16,6 +16,7 @@
47183 #include <linux/string.h>
47184 #include <linux/fs.h>
47185 #include <linux/file.h>
47186 +#include <linux/security.h>
47187 #include <linux/stat.h>
47188 #include <linux/fcntl.h>
47189 #include <linux/ptrace.h>
47190 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
47191 #endif
47192 # define START_STACK(u) ((void __user *)u.start_stack)
47193
47194 + memset(&dump, 0, sizeof(dump));
47195 +
47196 fs = get_fs();
47197 set_fs(KERNEL_DS);
47198 has_dumped = 1;
47199 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
47200
47201 /* If the size of the dump file exceeds the rlimit, then see what would happen
47202 if we wrote the stack, but not the data area. */
47203 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
47204 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
47205 dump.u_dsize = 0;
47206
47207 /* Make sure we have enough room to write the stack and data areas. */
47208 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
47209 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
47210 dump.u_ssize = 0;
47211
47212 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
47213 rlim = rlimit(RLIMIT_DATA);
47214 if (rlim >= RLIM_INFINITY)
47215 rlim = ~0;
47216 +
47217 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
47218 if (ex.a_data + ex.a_bss > rlim)
47219 return -ENOMEM;
47220
47221 @@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
47222
47223 install_exec_creds(bprm);
47224
47225 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47226 + current->mm->pax_flags = 0UL;
47227 +#endif
47228 +
47229 +#ifdef CONFIG_PAX_PAGEEXEC
47230 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
47231 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
47232 +
47233 +#ifdef CONFIG_PAX_EMUTRAMP
47234 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
47235 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
47236 +#endif
47237 +
47238 +#ifdef CONFIG_PAX_MPROTECT
47239 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
47240 + current->mm->pax_flags |= MF_PAX_MPROTECT;
47241 +#endif
47242 +
47243 + }
47244 +#endif
47245 +
47246 if (N_MAGIC(ex) == OMAGIC) {
47247 unsigned long text_addr, map_size;
47248 loff_t pos;
47249 @@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
47250 }
47251
47252 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
47253 - PROT_READ | PROT_WRITE | PROT_EXEC,
47254 + PROT_READ | PROT_WRITE,
47255 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
47256 fd_offset + ex.a_text);
47257 if (error != N_DATADDR(ex)) {
47258 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
47259 index 0c42cdb..f4be023 100644
47260 --- a/fs/binfmt_elf.c
47261 +++ b/fs/binfmt_elf.c
47262 @@ -33,6 +33,7 @@
47263 #include <linux/elf.h>
47264 #include <linux/utsname.h>
47265 #include <linux/coredump.h>
47266 +#include <linux/xattr.h>
47267 #include <asm/uaccess.h>
47268 #include <asm/param.h>
47269 #include <asm/page.h>
47270 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
47271 #define elf_core_dump NULL
47272 #endif
47273
47274 +#ifdef CONFIG_PAX_MPROTECT
47275 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
47276 +#endif
47277 +
47278 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
47279 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
47280 #else
47281 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
47282 .load_binary = load_elf_binary,
47283 .load_shlib = load_elf_library,
47284 .core_dump = elf_core_dump,
47285 +
47286 +#ifdef CONFIG_PAX_MPROTECT
47287 + .handle_mprotect= elf_handle_mprotect,
47288 +#endif
47289 +
47290 .min_coredump = ELF_EXEC_PAGESIZE,
47291 };
47292
47293 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
47294
47295 static int set_brk(unsigned long start, unsigned long end)
47296 {
47297 + unsigned long e = end;
47298 +
47299 start = ELF_PAGEALIGN(start);
47300 end = ELF_PAGEALIGN(end);
47301 if (end > start) {
47302 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
47303 if (BAD_ADDR(addr))
47304 return addr;
47305 }
47306 - current->mm->start_brk = current->mm->brk = end;
47307 + current->mm->start_brk = current->mm->brk = e;
47308 return 0;
47309 }
47310
47311 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47312 elf_addr_t __user *u_rand_bytes;
47313 const char *k_platform = ELF_PLATFORM;
47314 const char *k_base_platform = ELF_BASE_PLATFORM;
47315 - unsigned char k_rand_bytes[16];
47316 + u32 k_rand_bytes[4];
47317 int items;
47318 elf_addr_t *elf_info;
47319 int ei_index = 0;
47320 const struct cred *cred = current_cred();
47321 struct vm_area_struct *vma;
47322 + unsigned long saved_auxv[AT_VECTOR_SIZE];
47323
47324 /*
47325 * In some cases (e.g. Hyper-Threading), we want to avoid L1
47326 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47327 * Generate 16 random bytes for userspace PRNG seeding.
47328 */
47329 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
47330 - u_rand_bytes = (elf_addr_t __user *)
47331 - STACK_ALLOC(p, sizeof(k_rand_bytes));
47332 + srandom32(k_rand_bytes[0] ^ random32());
47333 + srandom32(k_rand_bytes[1] ^ random32());
47334 + srandom32(k_rand_bytes[2] ^ random32());
47335 + srandom32(k_rand_bytes[3] ^ random32());
47336 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
47337 + u_rand_bytes = (elf_addr_t __user *) p;
47338 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
47339 return -EFAULT;
47340
47341 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47342 return -EFAULT;
47343 current->mm->env_end = p;
47344
47345 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
47346 +
47347 /* Put the elf_info on the stack in the right place. */
47348 sp = (elf_addr_t __user *)envp + 1;
47349 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
47350 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
47351 return -EFAULT;
47352 return 0;
47353 }
47354 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
47355 an ELF header */
47356
47357 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47358 - struct file *interpreter, unsigned long *interp_map_addr,
47359 - unsigned long no_base)
47360 + struct file *interpreter, unsigned long no_base)
47361 {
47362 struct elf_phdr *elf_phdata;
47363 struct elf_phdr *eppnt;
47364 - unsigned long load_addr = 0;
47365 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
47366 int load_addr_set = 0;
47367 unsigned long last_bss = 0, elf_bss = 0;
47368 - unsigned long error = ~0UL;
47369 + unsigned long error = -EINVAL;
47370 unsigned long total_size;
47371 int retval, i, size;
47372
47373 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47374 goto out_close;
47375 }
47376
47377 +#ifdef CONFIG_PAX_SEGMEXEC
47378 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
47379 + pax_task_size = SEGMEXEC_TASK_SIZE;
47380 +#endif
47381 +
47382 eppnt = elf_phdata;
47383 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
47384 if (eppnt->p_type == PT_LOAD) {
47385 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47386 map_addr = elf_map(interpreter, load_addr + vaddr,
47387 eppnt, elf_prot, elf_type, total_size);
47388 total_size = 0;
47389 - if (!*interp_map_addr)
47390 - *interp_map_addr = map_addr;
47391 error = map_addr;
47392 if (BAD_ADDR(map_addr))
47393 goto out_close;
47394 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47395 k = load_addr + eppnt->p_vaddr;
47396 if (BAD_ADDR(k) ||
47397 eppnt->p_filesz > eppnt->p_memsz ||
47398 - eppnt->p_memsz > TASK_SIZE ||
47399 - TASK_SIZE - eppnt->p_memsz < k) {
47400 + eppnt->p_memsz > pax_task_size ||
47401 + pax_task_size - eppnt->p_memsz < k) {
47402 error = -ENOMEM;
47403 goto out_close;
47404 }
47405 @@ -530,6 +551,315 @@ out:
47406 return error;
47407 }
47408
47409 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
47410 +#ifdef CONFIG_PAX_SOFTMODE
47411 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
47412 +{
47413 + unsigned long pax_flags = 0UL;
47414 +
47415 +#ifdef CONFIG_PAX_PAGEEXEC
47416 + if (elf_phdata->p_flags & PF_PAGEEXEC)
47417 + pax_flags |= MF_PAX_PAGEEXEC;
47418 +#endif
47419 +
47420 +#ifdef CONFIG_PAX_SEGMEXEC
47421 + if (elf_phdata->p_flags & PF_SEGMEXEC)
47422 + pax_flags |= MF_PAX_SEGMEXEC;
47423 +#endif
47424 +
47425 +#ifdef CONFIG_PAX_EMUTRAMP
47426 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
47427 + pax_flags |= MF_PAX_EMUTRAMP;
47428 +#endif
47429 +
47430 +#ifdef CONFIG_PAX_MPROTECT
47431 + if (elf_phdata->p_flags & PF_MPROTECT)
47432 + pax_flags |= MF_PAX_MPROTECT;
47433 +#endif
47434 +
47435 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47436 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
47437 + pax_flags |= MF_PAX_RANDMMAP;
47438 +#endif
47439 +
47440 + return pax_flags;
47441 +}
47442 +#endif
47443 +
47444 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
47445 +{
47446 + unsigned long pax_flags = 0UL;
47447 +
47448 +#ifdef CONFIG_PAX_PAGEEXEC
47449 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
47450 + pax_flags |= MF_PAX_PAGEEXEC;
47451 +#endif
47452 +
47453 +#ifdef CONFIG_PAX_SEGMEXEC
47454 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
47455 + pax_flags |= MF_PAX_SEGMEXEC;
47456 +#endif
47457 +
47458 +#ifdef CONFIG_PAX_EMUTRAMP
47459 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
47460 + pax_flags |= MF_PAX_EMUTRAMP;
47461 +#endif
47462 +
47463 +#ifdef CONFIG_PAX_MPROTECT
47464 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
47465 + pax_flags |= MF_PAX_MPROTECT;
47466 +#endif
47467 +
47468 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47469 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
47470 + pax_flags |= MF_PAX_RANDMMAP;
47471 +#endif
47472 +
47473 + return pax_flags;
47474 +}
47475 +#endif
47476 +
47477 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
47478 +#ifdef CONFIG_PAX_SOFTMODE
47479 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
47480 +{
47481 + unsigned long pax_flags = 0UL;
47482 +
47483 +#ifdef CONFIG_PAX_PAGEEXEC
47484 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
47485 + pax_flags |= MF_PAX_PAGEEXEC;
47486 +#endif
47487 +
47488 +#ifdef CONFIG_PAX_SEGMEXEC
47489 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
47490 + pax_flags |= MF_PAX_SEGMEXEC;
47491 +#endif
47492 +
47493 +#ifdef CONFIG_PAX_EMUTRAMP
47494 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
47495 + pax_flags |= MF_PAX_EMUTRAMP;
47496 +#endif
47497 +
47498 +#ifdef CONFIG_PAX_MPROTECT
47499 + if (pax_flags_softmode & MF_PAX_MPROTECT)
47500 + pax_flags |= MF_PAX_MPROTECT;
47501 +#endif
47502 +
47503 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47504 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
47505 + pax_flags |= MF_PAX_RANDMMAP;
47506 +#endif
47507 +
47508 + return pax_flags;
47509 +}
47510 +#endif
47511 +
47512 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
47513 +{
47514 + unsigned long pax_flags = 0UL;
47515 +
47516 +#ifdef CONFIG_PAX_PAGEEXEC
47517 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
47518 + pax_flags |= MF_PAX_PAGEEXEC;
47519 +#endif
47520 +
47521 +#ifdef CONFIG_PAX_SEGMEXEC
47522 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
47523 + pax_flags |= MF_PAX_SEGMEXEC;
47524 +#endif
47525 +
47526 +#ifdef CONFIG_PAX_EMUTRAMP
47527 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
47528 + pax_flags |= MF_PAX_EMUTRAMP;
47529 +#endif
47530 +
47531 +#ifdef CONFIG_PAX_MPROTECT
47532 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
47533 + pax_flags |= MF_PAX_MPROTECT;
47534 +#endif
47535 +
47536 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47537 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
47538 + pax_flags |= MF_PAX_RANDMMAP;
47539 +#endif
47540 +
47541 + return pax_flags;
47542 +}
47543 +#endif
47544 +
47545 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47546 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
47547 +{
47548 + unsigned long pax_flags = 0UL;
47549 +
47550 +#ifdef CONFIG_PAX_EI_PAX
47551 +
47552 +#ifdef CONFIG_PAX_PAGEEXEC
47553 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
47554 + pax_flags |= MF_PAX_PAGEEXEC;
47555 +#endif
47556 +
47557 +#ifdef CONFIG_PAX_SEGMEXEC
47558 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
47559 + pax_flags |= MF_PAX_SEGMEXEC;
47560 +#endif
47561 +
47562 +#ifdef CONFIG_PAX_EMUTRAMP
47563 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
47564 + pax_flags |= MF_PAX_EMUTRAMP;
47565 +#endif
47566 +
47567 +#ifdef CONFIG_PAX_MPROTECT
47568 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
47569 + pax_flags |= MF_PAX_MPROTECT;
47570 +#endif
47571 +
47572 +#ifdef CONFIG_PAX_ASLR
47573 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
47574 + pax_flags |= MF_PAX_RANDMMAP;
47575 +#endif
47576 +
47577 +#else
47578 +
47579 +#ifdef CONFIG_PAX_PAGEEXEC
47580 + pax_flags |= MF_PAX_PAGEEXEC;
47581 +#endif
47582 +
47583 +#ifdef CONFIG_PAX_SEGMEXEC
47584 + pax_flags |= MF_PAX_SEGMEXEC;
47585 +#endif
47586 +
47587 +#ifdef CONFIG_PAX_MPROTECT
47588 + pax_flags |= MF_PAX_MPROTECT;
47589 +#endif
47590 +
47591 +#ifdef CONFIG_PAX_RANDMMAP
47592 + if (randomize_va_space)
47593 + pax_flags |= MF_PAX_RANDMMAP;
47594 +#endif
47595 +
47596 +#endif
47597 +
47598 + return pax_flags;
47599 +}
47600 +
47601 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
47602 +{
47603 +
47604 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
47605 + unsigned long i;
47606 +
47607 + for (i = 0UL; i < elf_ex->e_phnum; i++)
47608 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
47609 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
47610 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
47611 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
47612 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
47613 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
47614 + return ~0UL;
47615 +
47616 +#ifdef CONFIG_PAX_SOFTMODE
47617 + if (pax_softmode)
47618 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
47619 + else
47620 +#endif
47621 +
47622 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
47623 + break;
47624 + }
47625 +#endif
47626 +
47627 + return ~0UL;
47628 +}
47629 +
47630 +static unsigned long pax_parse_xattr_pax(struct file * const file)
47631 +{
47632 +
47633 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
47634 + ssize_t xattr_size, i;
47635 + unsigned char xattr_value[5];
47636 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
47637 +
47638 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
47639 + if (xattr_size <= 0 || xattr_size > 5)
47640 + return ~0UL;
47641 +
47642 + for (i = 0; i < xattr_size; i++)
47643 + switch (xattr_value[i]) {
47644 + default:
47645 + return ~0UL;
47646 +
47647 +#define parse_flag(option1, option2, flag) \
47648 + case option1: \
47649 + if (pax_flags_hardmode & MF_PAX_##flag) \
47650 + return ~0UL; \
47651 + pax_flags_hardmode |= MF_PAX_##flag; \
47652 + break; \
47653 + case option2: \
47654 + if (pax_flags_softmode & MF_PAX_##flag) \
47655 + return ~0UL; \
47656 + pax_flags_softmode |= MF_PAX_##flag; \
47657 + break;
47658 +
47659 + parse_flag('p', 'P', PAGEEXEC);
47660 + parse_flag('e', 'E', EMUTRAMP);
47661 + parse_flag('m', 'M', MPROTECT);
47662 + parse_flag('r', 'R', RANDMMAP);
47663 + parse_flag('s', 'S', SEGMEXEC);
47664 +
47665 +#undef parse_flag
47666 + }
47667 +
47668 + if (pax_flags_hardmode & pax_flags_softmode)
47669 + return ~0UL;
47670 +
47671 +#ifdef CONFIG_PAX_SOFTMODE
47672 + if (pax_softmode)
47673 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
47674 + else
47675 +#endif
47676 +
47677 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
47678 +#else
47679 + return ~0UL;
47680 +#endif
47681 +
47682 +}
47683 +
47684 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
47685 +{
47686 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
47687 +
47688 + pax_flags = pax_parse_ei_pax(elf_ex);
47689 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
47690 + xattr_pax_flags = pax_parse_xattr_pax(file);
47691 +
47692 + if (pt_pax_flags == ~0UL)
47693 + pt_pax_flags = xattr_pax_flags;
47694 + else if (xattr_pax_flags == ~0UL)
47695 + xattr_pax_flags = pt_pax_flags;
47696 + if (pt_pax_flags != xattr_pax_flags)
47697 + return -EINVAL;
47698 + if (pt_pax_flags != ~0UL)
47699 + pax_flags = pt_pax_flags;
47700 +
47701 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
47702 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47703 + if ((__supported_pte_mask & _PAGE_NX))
47704 + pax_flags &= ~MF_PAX_SEGMEXEC;
47705 + else
47706 + pax_flags &= ~MF_PAX_PAGEEXEC;
47707 + }
47708 +#endif
47709 +
47710 + if (0 > pax_check_flags(&pax_flags))
47711 + return -EINVAL;
47712 +
47713 + current->mm->pax_flags = pax_flags;
47714 + return 0;
47715 +}
47716 +#endif
47717 +
47718 /*
47719 * These are the functions used to load ELF style executables and shared
47720 * libraries. There is no binary dependent code anywhere else.
47721 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
47722 {
47723 unsigned int random_variable = 0;
47724
47725 +#ifdef CONFIG_PAX_RANDUSTACK
47726 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
47727 + return stack_top - current->mm->delta_stack;
47728 +#endif
47729 +
47730 if ((current->flags & PF_RANDOMIZE) &&
47731 !(current->personality & ADDR_NO_RANDOMIZE)) {
47732 random_variable = get_random_int() & STACK_RND_MASK;
47733 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
47734 unsigned long load_addr = 0, load_bias = 0;
47735 int load_addr_set = 0;
47736 char * elf_interpreter = NULL;
47737 - unsigned long error;
47738 + unsigned long error = 0;
47739 struct elf_phdr *elf_ppnt, *elf_phdata;
47740 unsigned long elf_bss, elf_brk;
47741 int retval, i;
47742 @@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
47743 unsigned long start_code, end_code, start_data, end_data;
47744 unsigned long reloc_func_desc __maybe_unused = 0;
47745 int executable_stack = EXSTACK_DEFAULT;
47746 - unsigned long def_flags = 0;
47747 struct pt_regs *regs = current_pt_regs();
47748 struct {
47749 struct elfhdr elf_ex;
47750 struct elfhdr interp_elf_ex;
47751 } *loc;
47752 + unsigned long pax_task_size = TASK_SIZE;
47753
47754 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
47755 if (!loc) {
47756 @@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
47757 goto out_free_dentry;
47758
47759 /* OK, This is the point of no return */
47760 - current->mm->def_flags = def_flags;
47761 +
47762 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47763 + current->mm->pax_flags = 0UL;
47764 +#endif
47765 +
47766 +#ifdef CONFIG_PAX_DLRESOLVE
47767 + current->mm->call_dl_resolve = 0UL;
47768 +#endif
47769 +
47770 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
47771 + current->mm->call_syscall = 0UL;
47772 +#endif
47773 +
47774 +#ifdef CONFIG_PAX_ASLR
47775 + current->mm->delta_mmap = 0UL;
47776 + current->mm->delta_stack = 0UL;
47777 +#endif
47778 +
47779 + current->mm->def_flags = 0;
47780 +
47781 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47782 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
47783 + send_sig(SIGKILL, current, 0);
47784 + goto out_free_dentry;
47785 + }
47786 +#endif
47787 +
47788 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
47789 + pax_set_initial_flags(bprm);
47790 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
47791 + if (pax_set_initial_flags_func)
47792 + (pax_set_initial_flags_func)(bprm);
47793 +#endif
47794 +
47795 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
47796 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
47797 + current->mm->context.user_cs_limit = PAGE_SIZE;
47798 + current->mm->def_flags |= VM_PAGEEXEC;
47799 + }
47800 +#endif
47801 +
47802 +#ifdef CONFIG_PAX_SEGMEXEC
47803 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
47804 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
47805 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
47806 + pax_task_size = SEGMEXEC_TASK_SIZE;
47807 + current->mm->def_flags |= VM_NOHUGEPAGE;
47808 + }
47809 +#endif
47810 +
47811 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
47812 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47813 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
47814 + put_cpu();
47815 + }
47816 +#endif
47817
47818 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
47819 may depend on the personality. */
47820 SET_PERSONALITY(loc->elf_ex);
47821 +
47822 +#ifdef CONFIG_PAX_ASLR
47823 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
47824 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
47825 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
47826 + }
47827 +#endif
47828 +
47829 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47830 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47831 + executable_stack = EXSTACK_DISABLE_X;
47832 + current->personality &= ~READ_IMPLIES_EXEC;
47833 + } else
47834 +#endif
47835 +
47836 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
47837 current->personality |= READ_IMPLIES_EXEC;
47838
47839 @@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
47840 #else
47841 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
47842 #endif
47843 +
47844 +#ifdef CONFIG_PAX_RANDMMAP
47845 + /* PaX: randomize base address at the default exe base if requested */
47846 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
47847 +#ifdef CONFIG_SPARC64
47848 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
47849 +#else
47850 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
47851 +#endif
47852 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
47853 + elf_flags |= MAP_FIXED;
47854 + }
47855 +#endif
47856 +
47857 }
47858
47859 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
47860 @@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
47861 * allowed task size. Note that p_filesz must always be
47862 * <= p_memsz so it is only necessary to check p_memsz.
47863 */
47864 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
47865 - elf_ppnt->p_memsz > TASK_SIZE ||
47866 - TASK_SIZE - elf_ppnt->p_memsz < k) {
47867 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
47868 + elf_ppnt->p_memsz > pax_task_size ||
47869 + pax_task_size - elf_ppnt->p_memsz < k) {
47870 /* set_brk can never work. Avoid overflows. */
47871 send_sig(SIGKILL, current, 0);
47872 retval = -EINVAL;
47873 @@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
47874 goto out_free_dentry;
47875 }
47876 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
47877 - send_sig(SIGSEGV, current, 0);
47878 - retval = -EFAULT; /* Nobody gets to see this, but.. */
47879 - goto out_free_dentry;
47880 + /*
47881 + * This bss-zeroing can fail if the ELF
47882 + * file specifies odd protections. So
47883 + * we don't check the return value
47884 + */
47885 }
47886
47887 +#ifdef CONFIG_PAX_RANDMMAP
47888 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
47889 + unsigned long start, size;
47890 +
47891 + start = ELF_PAGEALIGN(elf_brk);
47892 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
47893 + down_read(&current->mm->mmap_sem);
47894 + retval = -ENOMEM;
47895 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
47896 + unsigned long prot = PROT_NONE;
47897 +
47898 + up_read(&current->mm->mmap_sem);
47899 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
47900 +// if (current->personality & ADDR_NO_RANDOMIZE)
47901 +// prot = PROT_READ;
47902 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
47903 + retval = IS_ERR_VALUE(start) ? start : 0;
47904 + } else
47905 + up_read(&current->mm->mmap_sem);
47906 + if (retval == 0)
47907 + retval = set_brk(start + size, start + size + PAGE_SIZE);
47908 + if (retval < 0) {
47909 + send_sig(SIGKILL, current, 0);
47910 + goto out_free_dentry;
47911 + }
47912 + }
47913 +#endif
47914 +
47915 if (elf_interpreter) {
47916 - unsigned long interp_map_addr = 0;
47917 -
47918 elf_entry = load_elf_interp(&loc->interp_elf_ex,
47919 interpreter,
47920 - &interp_map_addr,
47921 load_bias);
47922 if (!IS_ERR((void *)elf_entry)) {
47923 /*
47924 @@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
47925 * Decide what to dump of a segment, part, all or none.
47926 */
47927 static unsigned long vma_dump_size(struct vm_area_struct *vma,
47928 - unsigned long mm_flags)
47929 + unsigned long mm_flags, long signr)
47930 {
47931 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
47932
47933 @@ -1152,7 +1598,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
47934 if (vma->vm_file == NULL)
47935 return 0;
47936
47937 - if (FILTER(MAPPED_PRIVATE))
47938 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
47939 goto whole;
47940
47941 /*
47942 @@ -1374,9 +1820,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
47943 {
47944 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
47945 int i = 0;
47946 - do
47947 + do {
47948 i += 2;
47949 - while (auxv[i - 2] != AT_NULL);
47950 + } while (auxv[i - 2] != AT_NULL);
47951 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
47952 }
47953
47954 @@ -2006,14 +2452,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
47955 }
47956
47957 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
47958 - unsigned long mm_flags)
47959 + struct coredump_params *cprm)
47960 {
47961 struct vm_area_struct *vma;
47962 size_t size = 0;
47963
47964 for (vma = first_vma(current, gate_vma); vma != NULL;
47965 vma = next_vma(vma, gate_vma))
47966 - size += vma_dump_size(vma, mm_flags);
47967 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
47968 return size;
47969 }
47970
47971 @@ -2107,7 +2553,7 @@ static int elf_core_dump(struct coredump_params *cprm)
47972
47973 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
47974
47975 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
47976 + offset += elf_core_vma_data_size(gate_vma, cprm);
47977 offset += elf_core_extra_data_size();
47978 e_shoff = offset;
47979
47980 @@ -2121,10 +2567,12 @@ static int elf_core_dump(struct coredump_params *cprm)
47981 offset = dataoff;
47982
47983 size += sizeof(*elf);
47984 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
47985 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
47986 goto end_coredump;
47987
47988 size += sizeof(*phdr4note);
47989 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
47990 if (size > cprm->limit
47991 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
47992 goto end_coredump;
47993 @@ -2138,7 +2586,7 @@ static int elf_core_dump(struct coredump_params *cprm)
47994 phdr.p_offset = offset;
47995 phdr.p_vaddr = vma->vm_start;
47996 phdr.p_paddr = 0;
47997 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
47998 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
47999 phdr.p_memsz = vma->vm_end - vma->vm_start;
48000 offset += phdr.p_filesz;
48001 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
48002 @@ -2149,6 +2597,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48003 phdr.p_align = ELF_EXEC_PAGESIZE;
48004
48005 size += sizeof(phdr);
48006 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48007 if (size > cprm->limit
48008 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
48009 goto end_coredump;
48010 @@ -2173,7 +2622,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48011 unsigned long addr;
48012 unsigned long end;
48013
48014 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
48015 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48016
48017 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
48018 struct page *page;
48019 @@ -2182,6 +2631,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48020 page = get_dump_page(addr);
48021 if (page) {
48022 void *kaddr = kmap(page);
48023 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
48024 stop = ((size += PAGE_SIZE) > cprm->limit) ||
48025 !dump_write(cprm->file, kaddr,
48026 PAGE_SIZE);
48027 @@ -2199,6 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48028
48029 if (e_phnum == PN_XNUM) {
48030 size += sizeof(*shdr4extnum);
48031 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48032 if (size > cprm->limit
48033 || !dump_write(cprm->file, shdr4extnum,
48034 sizeof(*shdr4extnum)))
48035 @@ -2219,6 +2670,97 @@ out:
48036
48037 #endif /* CONFIG_ELF_CORE */
48038
48039 +#ifdef CONFIG_PAX_MPROTECT
48040 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
48041 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
48042 + * we'll remove VM_MAYWRITE for good on RELRO segments.
48043 + *
48044 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
48045 + * basis because we want to allow the common case and not the special ones.
48046 + */
48047 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
48048 +{
48049 + struct elfhdr elf_h;
48050 + struct elf_phdr elf_p;
48051 + unsigned long i;
48052 + unsigned long oldflags;
48053 + bool is_textrel_rw, is_textrel_rx, is_relro;
48054 +
48055 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
48056 + return;
48057 +
48058 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
48059 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
48060 +
48061 +#ifdef CONFIG_PAX_ELFRELOCS
48062 + /* possible TEXTREL */
48063 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
48064 + 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);
48065 +#else
48066 + is_textrel_rw = false;
48067 + is_textrel_rx = false;
48068 +#endif
48069 +
48070 + /* possible RELRO */
48071 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
48072 +
48073 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
48074 + return;
48075 +
48076 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
48077 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
48078 +
48079 +#ifdef CONFIG_PAX_ETEXECRELOCS
48080 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48081 +#else
48082 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
48083 +#endif
48084 +
48085 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48086 + !elf_check_arch(&elf_h) ||
48087 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
48088 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
48089 + return;
48090 +
48091 + for (i = 0UL; i < elf_h.e_phnum; i++) {
48092 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
48093 + return;
48094 + switch (elf_p.p_type) {
48095 + case PT_DYNAMIC:
48096 + if (!is_textrel_rw && !is_textrel_rx)
48097 + continue;
48098 + i = 0UL;
48099 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
48100 + elf_dyn dyn;
48101 +
48102 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
48103 + return;
48104 + if (dyn.d_tag == DT_NULL)
48105 + return;
48106 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
48107 + gr_log_textrel(vma);
48108 + if (is_textrel_rw)
48109 + vma->vm_flags |= VM_MAYWRITE;
48110 + else
48111 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
48112 + vma->vm_flags &= ~VM_MAYWRITE;
48113 + return;
48114 + }
48115 + i++;
48116 + }
48117 + return;
48118 +
48119 + case PT_GNU_RELRO:
48120 + if (!is_relro)
48121 + continue;
48122 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
48123 + vma->vm_flags &= ~VM_MAYWRITE;
48124 + return;
48125 + }
48126 + }
48127 +}
48128 +#endif
48129 +
48130 static int __init init_elf_binfmt(void)
48131 {
48132 register_binfmt(&elf_format);
48133 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
48134 index b563719..3868998 100644
48135 --- a/fs/binfmt_flat.c
48136 +++ b/fs/binfmt_flat.c
48137 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
48138 realdatastart = (unsigned long) -ENOMEM;
48139 printk("Unable to allocate RAM for process data, errno %d\n",
48140 (int)-realdatastart);
48141 + down_write(&current->mm->mmap_sem);
48142 vm_munmap(textpos, text_len);
48143 + up_write(&current->mm->mmap_sem);
48144 ret = realdatastart;
48145 goto err;
48146 }
48147 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48148 }
48149 if (IS_ERR_VALUE(result)) {
48150 printk("Unable to read data+bss, errno %d\n", (int)-result);
48151 + down_write(&current->mm->mmap_sem);
48152 vm_munmap(textpos, text_len);
48153 vm_munmap(realdatastart, len);
48154 + up_write(&current->mm->mmap_sem);
48155 ret = result;
48156 goto err;
48157 }
48158 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48159 }
48160 if (IS_ERR_VALUE(result)) {
48161 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
48162 + down_write(&current->mm->mmap_sem);
48163 vm_munmap(textpos, text_len + data_len + extra +
48164 MAX_SHARED_LIBS * sizeof(unsigned long));
48165 + up_write(&current->mm->mmap_sem);
48166 ret = result;
48167 goto err;
48168 }
48169 diff --git a/fs/bio.c b/fs/bio.c
48170 index b96fc6c..431d628 100644
48171 --- a/fs/bio.c
48172 +++ b/fs/bio.c
48173 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
48174 /*
48175 * Overflow, abort
48176 */
48177 - if (end < start)
48178 + if (end < start || end - start > INT_MAX - nr_pages)
48179 return ERR_PTR(-EINVAL);
48180
48181 nr_pages += end - start;
48182 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
48183 /*
48184 * Overflow, abort
48185 */
48186 - if (end < start)
48187 + if (end < start || end - start > INT_MAX - nr_pages)
48188 return ERR_PTR(-EINVAL);
48189
48190 nr_pages += end - start;
48191 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
48192 const int read = bio_data_dir(bio) == READ;
48193 struct bio_map_data *bmd = bio->bi_private;
48194 int i;
48195 - char *p = bmd->sgvecs[0].iov_base;
48196 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
48197
48198 __bio_for_each_segment(bvec, bio, i, 0) {
48199 char *addr = page_address(bvec->bv_page);
48200 diff --git a/fs/block_dev.c b/fs/block_dev.c
48201 index 78333a3..23dcb4d 100644
48202 --- a/fs/block_dev.c
48203 +++ b/fs/block_dev.c
48204 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
48205 else if (bdev->bd_contains == bdev)
48206 return true; /* is a whole device which isn't held */
48207
48208 - else if (whole->bd_holder == bd_may_claim)
48209 + else if (whole->bd_holder == (void *)bd_may_claim)
48210 return true; /* is a partition of a device that is being partitioned */
48211 else if (whole->bd_holder != NULL)
48212 return false; /* is a partition of a held device */
48213 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
48214 index eea5da7..88fead70 100644
48215 --- a/fs/btrfs/ctree.c
48216 +++ b/fs/btrfs/ctree.c
48217 @@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
48218 free_extent_buffer(buf);
48219 add_root_to_dirty_list(root);
48220 } else {
48221 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
48222 - parent_start = parent->start;
48223 - else
48224 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
48225 + if (parent)
48226 + parent_start = parent->start;
48227 + else
48228 + parent_start = 0;
48229 + } else
48230 parent_start = 0;
48231
48232 WARN_ON(trans->transid != btrfs_header_generation(parent));
48233 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
48234 index cc93b23..f3c42bf 100644
48235 --- a/fs/btrfs/inode.c
48236 +++ b/fs/btrfs/inode.c
48237 @@ -7296,7 +7296,7 @@ fail:
48238 return -ENOMEM;
48239 }
48240
48241 -static int btrfs_getattr(struct vfsmount *mnt,
48242 +int btrfs_getattr(struct vfsmount *mnt,
48243 struct dentry *dentry, struct kstat *stat)
48244 {
48245 struct inode *inode = dentry->d_inode;
48246 @@ -7310,6 +7310,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
48247 return 0;
48248 }
48249
48250 +EXPORT_SYMBOL(btrfs_getattr);
48251 +
48252 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
48253 +{
48254 + return BTRFS_I(inode)->root->anon_dev;
48255 +}
48256 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
48257 +
48258 /*
48259 * If a file is moved, it will inherit the cow and compression flags of the new
48260 * directory.
48261 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
48262 index 338f259..b657640 100644
48263 --- a/fs/btrfs/ioctl.c
48264 +++ b/fs/btrfs/ioctl.c
48265 @@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48266 for (i = 0; i < num_types; i++) {
48267 struct btrfs_space_info *tmp;
48268
48269 + /* Don't copy in more than we allocated */
48270 if (!slot_count)
48271 break;
48272
48273 + slot_count--;
48274 +
48275 info = NULL;
48276 rcu_read_lock();
48277 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
48278 @@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48279 memcpy(dest, &space, sizeof(space));
48280 dest++;
48281 space_args.total_spaces++;
48282 - slot_count--;
48283 }
48284 - if (!slot_count)
48285 - break;
48286 }
48287 up_read(&info->groups_sem);
48288 }
48289 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
48290 index 300e09a..9fe4539 100644
48291 --- a/fs/btrfs/relocation.c
48292 +++ b/fs/btrfs/relocation.c
48293 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
48294 }
48295 spin_unlock(&rc->reloc_root_tree.lock);
48296
48297 - BUG_ON((struct btrfs_root *)node->data != root);
48298 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
48299
48300 if (!del) {
48301 spin_lock(&rc->reloc_root_tree.lock);
48302 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
48303 index d8982e9..29a85fa 100644
48304 --- a/fs/btrfs/super.c
48305 +++ b/fs/btrfs/super.c
48306 @@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
48307 function, line, errstr);
48308 return;
48309 }
48310 - ACCESS_ONCE(trans->transaction->aborted) = errno;
48311 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
48312 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
48313 }
48314 /*
48315 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
48316 index 622f469..e8d2d55 100644
48317 --- a/fs/cachefiles/bind.c
48318 +++ b/fs/cachefiles/bind.c
48319 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
48320 args);
48321
48322 /* start by checking things over */
48323 - ASSERT(cache->fstop_percent >= 0 &&
48324 - cache->fstop_percent < cache->fcull_percent &&
48325 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
48326 cache->fcull_percent < cache->frun_percent &&
48327 cache->frun_percent < 100);
48328
48329 - ASSERT(cache->bstop_percent >= 0 &&
48330 - cache->bstop_percent < cache->bcull_percent &&
48331 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
48332 cache->bcull_percent < cache->brun_percent &&
48333 cache->brun_percent < 100);
48334
48335 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
48336 index 0a1467b..6a53245 100644
48337 --- a/fs/cachefiles/daemon.c
48338 +++ b/fs/cachefiles/daemon.c
48339 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
48340 if (n > buflen)
48341 return -EMSGSIZE;
48342
48343 - if (copy_to_user(_buffer, buffer, n) != 0)
48344 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
48345 return -EFAULT;
48346
48347 return n;
48348 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
48349 if (test_bit(CACHEFILES_DEAD, &cache->flags))
48350 return -EIO;
48351
48352 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
48353 + if (datalen > PAGE_SIZE - 1)
48354 return -EOPNOTSUPP;
48355
48356 /* drag the command string into the kernel so we can parse it */
48357 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
48358 if (args[0] != '%' || args[1] != '\0')
48359 return -EINVAL;
48360
48361 - if (fstop < 0 || fstop >= cache->fcull_percent)
48362 + if (fstop >= cache->fcull_percent)
48363 return cachefiles_daemon_range_error(cache, args);
48364
48365 cache->fstop_percent = fstop;
48366 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
48367 if (args[0] != '%' || args[1] != '\0')
48368 return -EINVAL;
48369
48370 - if (bstop < 0 || bstop >= cache->bcull_percent)
48371 + if (bstop >= cache->bcull_percent)
48372 return cachefiles_daemon_range_error(cache, args);
48373
48374 cache->bstop_percent = bstop;
48375 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
48376 index 4938251..7e01445 100644
48377 --- a/fs/cachefiles/internal.h
48378 +++ b/fs/cachefiles/internal.h
48379 @@ -59,7 +59,7 @@ struct cachefiles_cache {
48380 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
48381 struct rb_root active_nodes; /* active nodes (can't be culled) */
48382 rwlock_t active_lock; /* lock for active_nodes */
48383 - atomic_t gravecounter; /* graveyard uniquifier */
48384 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
48385 unsigned frun_percent; /* when to stop culling (% files) */
48386 unsigned fcull_percent; /* when to start culling (% files) */
48387 unsigned fstop_percent; /* when to stop allocating (% files) */
48388 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
48389 * proc.c
48390 */
48391 #ifdef CONFIG_CACHEFILES_HISTOGRAM
48392 -extern atomic_t cachefiles_lookup_histogram[HZ];
48393 -extern atomic_t cachefiles_mkdir_histogram[HZ];
48394 -extern atomic_t cachefiles_create_histogram[HZ];
48395 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48396 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48397 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
48398
48399 extern int __init cachefiles_proc_init(void);
48400 extern void cachefiles_proc_cleanup(void);
48401 static inline
48402 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
48403 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
48404 {
48405 unsigned long jif = jiffies - start_jif;
48406 if (jif >= HZ)
48407 jif = HZ - 1;
48408 - atomic_inc(&histogram[jif]);
48409 + atomic_inc_unchecked(&histogram[jif]);
48410 }
48411
48412 #else
48413 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
48414 index 8c01c5fc..15f982e 100644
48415 --- a/fs/cachefiles/namei.c
48416 +++ b/fs/cachefiles/namei.c
48417 @@ -317,7 +317,7 @@ try_again:
48418 /* first step is to make up a grave dentry in the graveyard */
48419 sprintf(nbuffer, "%08x%08x",
48420 (uint32_t) get_seconds(),
48421 - (uint32_t) atomic_inc_return(&cache->gravecounter));
48422 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
48423
48424 /* do the multiway lock magic */
48425 trap = lock_rename(cache->graveyard, dir);
48426 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
48427 index eccd339..4c1d995 100644
48428 --- a/fs/cachefiles/proc.c
48429 +++ b/fs/cachefiles/proc.c
48430 @@ -14,9 +14,9 @@
48431 #include <linux/seq_file.h>
48432 #include "internal.h"
48433
48434 -atomic_t cachefiles_lookup_histogram[HZ];
48435 -atomic_t cachefiles_mkdir_histogram[HZ];
48436 -atomic_t cachefiles_create_histogram[HZ];
48437 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48438 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48439 +atomic_unchecked_t cachefiles_create_histogram[HZ];
48440
48441 /*
48442 * display the latency histogram
48443 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
48444 return 0;
48445 default:
48446 index = (unsigned long) v - 3;
48447 - x = atomic_read(&cachefiles_lookup_histogram[index]);
48448 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
48449 - z = atomic_read(&cachefiles_create_histogram[index]);
48450 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
48451 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
48452 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
48453 if (x == 0 && y == 0 && z == 0)
48454 return 0;
48455
48456 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
48457 index 4809922..aab2c39 100644
48458 --- a/fs/cachefiles/rdwr.c
48459 +++ b/fs/cachefiles/rdwr.c
48460 @@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
48461 old_fs = get_fs();
48462 set_fs(KERNEL_DS);
48463 ret = file->f_op->write(
48464 - file, (const void __user *) data, len, &pos);
48465 + file, (const void __force_user *) data, len, &pos);
48466 set_fs(old_fs);
48467 kunmap(page);
48468 if (ret != len)
48469 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
48470 index 8c1aabe..bbf856a 100644
48471 --- a/fs/ceph/dir.c
48472 +++ b/fs/ceph/dir.c
48473 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
48474 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
48475 struct ceph_mds_client *mdsc = fsc->mdsc;
48476 unsigned frag = fpos_frag(filp->f_pos);
48477 - int off = fpos_off(filp->f_pos);
48478 + unsigned int off = fpos_off(filp->f_pos);
48479 int err;
48480 u32 ftype;
48481 struct ceph_mds_reply_info_parsed *rinfo;
48482 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
48483 index d9ea6ed..1e6c8ac 100644
48484 --- a/fs/cifs/cifs_debug.c
48485 +++ b/fs/cifs/cifs_debug.c
48486 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
48487
48488 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
48489 #ifdef CONFIG_CIFS_STATS2
48490 - atomic_set(&totBufAllocCount, 0);
48491 - atomic_set(&totSmBufAllocCount, 0);
48492 + atomic_set_unchecked(&totBufAllocCount, 0);
48493 + atomic_set_unchecked(&totSmBufAllocCount, 0);
48494 #endif /* CONFIG_CIFS_STATS2 */
48495 spin_lock(&cifs_tcp_ses_lock);
48496 list_for_each(tmp1, &cifs_tcp_ses_list) {
48497 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
48498 tcon = list_entry(tmp3,
48499 struct cifs_tcon,
48500 tcon_list);
48501 - atomic_set(&tcon->num_smbs_sent, 0);
48502 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
48503 if (server->ops->clear_stats)
48504 server->ops->clear_stats(tcon);
48505 }
48506 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
48507 smBufAllocCount.counter, cifs_min_small);
48508 #ifdef CONFIG_CIFS_STATS2
48509 seq_printf(m, "Total Large %d Small %d Allocations\n",
48510 - atomic_read(&totBufAllocCount),
48511 - atomic_read(&totSmBufAllocCount));
48512 + atomic_read_unchecked(&totBufAllocCount),
48513 + atomic_read_unchecked(&totSmBufAllocCount));
48514 #endif /* CONFIG_CIFS_STATS2 */
48515
48516 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
48517 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
48518 if (tcon->need_reconnect)
48519 seq_puts(m, "\tDISCONNECTED ");
48520 seq_printf(m, "\nSMBs: %d",
48521 - atomic_read(&tcon->num_smbs_sent));
48522 + atomic_read_unchecked(&tcon->num_smbs_sent));
48523 if (server->ops->print_stats)
48524 server->ops->print_stats(m, tcon);
48525 }
48526 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
48527 index de7f916..6cb22a9 100644
48528 --- a/fs/cifs/cifsfs.c
48529 +++ b/fs/cifs/cifsfs.c
48530 @@ -997,7 +997,7 @@ cifs_init_request_bufs(void)
48531 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
48532 cifs_req_cachep = kmem_cache_create("cifs_request",
48533 CIFSMaxBufSize + max_hdr_size, 0,
48534 - SLAB_HWCACHE_ALIGN, NULL);
48535 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
48536 if (cifs_req_cachep == NULL)
48537 return -ENOMEM;
48538
48539 @@ -1024,7 +1024,7 @@ cifs_init_request_bufs(void)
48540 efficient to alloc 1 per page off the slab compared to 17K (5page)
48541 alloc of large cifs buffers even when page debugging is on */
48542 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
48543 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
48544 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
48545 NULL);
48546 if (cifs_sm_req_cachep == NULL) {
48547 mempool_destroy(cifs_req_poolp);
48548 @@ -1109,8 +1109,8 @@ init_cifs(void)
48549 atomic_set(&bufAllocCount, 0);
48550 atomic_set(&smBufAllocCount, 0);
48551 #ifdef CONFIG_CIFS_STATS2
48552 - atomic_set(&totBufAllocCount, 0);
48553 - atomic_set(&totSmBufAllocCount, 0);
48554 + atomic_set_unchecked(&totBufAllocCount, 0);
48555 + atomic_set_unchecked(&totSmBufAllocCount, 0);
48556 #endif /* CONFIG_CIFS_STATS2 */
48557
48558 atomic_set(&midCount, 0);
48559 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
48560 index e6899ce..d6b2920 100644
48561 --- a/fs/cifs/cifsglob.h
48562 +++ b/fs/cifs/cifsglob.h
48563 @@ -751,35 +751,35 @@ struct cifs_tcon {
48564 __u16 Flags; /* optional support bits */
48565 enum statusEnum tidStatus;
48566 #ifdef CONFIG_CIFS_STATS
48567 - atomic_t num_smbs_sent;
48568 + atomic_unchecked_t num_smbs_sent;
48569 union {
48570 struct {
48571 - atomic_t num_writes;
48572 - atomic_t num_reads;
48573 - atomic_t num_flushes;
48574 - atomic_t num_oplock_brks;
48575 - atomic_t num_opens;
48576 - atomic_t num_closes;
48577 - atomic_t num_deletes;
48578 - atomic_t num_mkdirs;
48579 - atomic_t num_posixopens;
48580 - atomic_t num_posixmkdirs;
48581 - atomic_t num_rmdirs;
48582 - atomic_t num_renames;
48583 - atomic_t num_t2renames;
48584 - atomic_t num_ffirst;
48585 - atomic_t num_fnext;
48586 - atomic_t num_fclose;
48587 - atomic_t num_hardlinks;
48588 - atomic_t num_symlinks;
48589 - atomic_t num_locks;
48590 - atomic_t num_acl_get;
48591 - atomic_t num_acl_set;
48592 + atomic_unchecked_t num_writes;
48593 + atomic_unchecked_t num_reads;
48594 + atomic_unchecked_t num_flushes;
48595 + atomic_unchecked_t num_oplock_brks;
48596 + atomic_unchecked_t num_opens;
48597 + atomic_unchecked_t num_closes;
48598 + atomic_unchecked_t num_deletes;
48599 + atomic_unchecked_t num_mkdirs;
48600 + atomic_unchecked_t num_posixopens;
48601 + atomic_unchecked_t num_posixmkdirs;
48602 + atomic_unchecked_t num_rmdirs;
48603 + atomic_unchecked_t num_renames;
48604 + atomic_unchecked_t num_t2renames;
48605 + atomic_unchecked_t num_ffirst;
48606 + atomic_unchecked_t num_fnext;
48607 + atomic_unchecked_t num_fclose;
48608 + atomic_unchecked_t num_hardlinks;
48609 + atomic_unchecked_t num_symlinks;
48610 + atomic_unchecked_t num_locks;
48611 + atomic_unchecked_t num_acl_get;
48612 + atomic_unchecked_t num_acl_set;
48613 } cifs_stats;
48614 #ifdef CONFIG_CIFS_SMB2
48615 struct {
48616 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
48617 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
48618 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
48619 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
48620 } smb2_stats;
48621 #endif /* CONFIG_CIFS_SMB2 */
48622 } stats;
48623 @@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
48624 }
48625
48626 #ifdef CONFIG_CIFS_STATS
48627 -#define cifs_stats_inc atomic_inc
48628 +#define cifs_stats_inc atomic_inc_unchecked
48629
48630 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
48631 unsigned int bytes)
48632 @@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
48633 /* Various Debug counters */
48634 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
48635 #ifdef CONFIG_CIFS_STATS2
48636 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
48637 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
48638 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
48639 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
48640 #endif
48641 GLOBAL_EXTERN atomic_t smBufAllocCount;
48642 GLOBAL_EXTERN atomic_t midCount;
48643 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
48644 index 51dc2fb..1e12a33 100644
48645 --- a/fs/cifs/link.c
48646 +++ b/fs/cifs/link.c
48647 @@ -616,7 +616,7 @@ symlink_exit:
48648
48649 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
48650 {
48651 - char *p = nd_get_link(nd);
48652 + const char *p = nd_get_link(nd);
48653 if (!IS_ERR(p))
48654 kfree(p);
48655 }
48656 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
48657 index 3a00c0d..42d901c 100644
48658 --- a/fs/cifs/misc.c
48659 +++ b/fs/cifs/misc.c
48660 @@ -169,7 +169,7 @@ cifs_buf_get(void)
48661 memset(ret_buf, 0, buf_size + 3);
48662 atomic_inc(&bufAllocCount);
48663 #ifdef CONFIG_CIFS_STATS2
48664 - atomic_inc(&totBufAllocCount);
48665 + atomic_inc_unchecked(&totBufAllocCount);
48666 #endif /* CONFIG_CIFS_STATS2 */
48667 }
48668
48669 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
48670 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
48671 atomic_inc(&smBufAllocCount);
48672 #ifdef CONFIG_CIFS_STATS2
48673 - atomic_inc(&totSmBufAllocCount);
48674 + atomic_inc_unchecked(&totSmBufAllocCount);
48675 #endif /* CONFIG_CIFS_STATS2 */
48676
48677 }
48678 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
48679 index 47bc5a8..10decbe 100644
48680 --- a/fs/cifs/smb1ops.c
48681 +++ b/fs/cifs/smb1ops.c
48682 @@ -586,27 +586,27 @@ static void
48683 cifs_clear_stats(struct cifs_tcon *tcon)
48684 {
48685 #ifdef CONFIG_CIFS_STATS
48686 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
48687 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
48688 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
48689 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
48690 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
48691 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
48692 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
48693 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
48694 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
48695 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
48696 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
48697 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
48698 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
48699 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
48700 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
48701 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
48702 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
48703 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
48704 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
48705 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
48706 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
48707 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
48708 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
48709 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
48710 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
48711 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
48712 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
48713 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
48714 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
48715 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
48716 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
48717 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
48718 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
48719 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
48720 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
48721 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
48722 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
48723 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
48724 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
48725 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
48726 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
48727 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
48728 #endif
48729 }
48730
48731 @@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
48732 {
48733 #ifdef CONFIG_CIFS_STATS
48734 seq_printf(m, " Oplocks breaks: %d",
48735 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
48736 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
48737 seq_printf(m, "\nReads: %d Bytes: %llu",
48738 - atomic_read(&tcon->stats.cifs_stats.num_reads),
48739 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
48740 (long long)(tcon->bytes_read));
48741 seq_printf(m, "\nWrites: %d Bytes: %llu",
48742 - atomic_read(&tcon->stats.cifs_stats.num_writes),
48743 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
48744 (long long)(tcon->bytes_written));
48745 seq_printf(m, "\nFlushes: %d",
48746 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
48747 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
48748 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
48749 - atomic_read(&tcon->stats.cifs_stats.num_locks),
48750 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
48751 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
48752 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
48753 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
48754 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
48755 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
48756 - atomic_read(&tcon->stats.cifs_stats.num_opens),
48757 - atomic_read(&tcon->stats.cifs_stats.num_closes),
48758 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
48759 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
48760 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
48761 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
48762 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
48763 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
48764 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
48765 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
48766 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
48767 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
48768 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
48769 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
48770 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
48771 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
48772 seq_printf(m, "\nRenames: %d T2 Renames %d",
48773 - atomic_read(&tcon->stats.cifs_stats.num_renames),
48774 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
48775 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
48776 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
48777 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
48778 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
48779 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
48780 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
48781 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
48782 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
48783 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
48784 #endif
48785 }
48786
48787 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
48788 index c9c7aa7..065056a 100644
48789 --- a/fs/cifs/smb2ops.c
48790 +++ b/fs/cifs/smb2ops.c
48791 @@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
48792 #ifdef CONFIG_CIFS_STATS
48793 int i;
48794 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
48795 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
48796 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
48797 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
48798 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
48799 }
48800 #endif
48801 }
48802 @@ -284,66 +284,66 @@ static void
48803 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
48804 {
48805 #ifdef CONFIG_CIFS_STATS
48806 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
48807 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
48808 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
48809 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
48810 seq_printf(m, "\nNegotiates: %d sent %d failed",
48811 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
48812 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
48813 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
48814 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
48815 seq_printf(m, "\nSessionSetups: %d sent %d failed",
48816 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
48817 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
48818 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
48819 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
48820 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
48821 seq_printf(m, "\nLogoffs: %d sent %d failed",
48822 - atomic_read(&sent[SMB2_LOGOFF_HE]),
48823 - atomic_read(&failed[SMB2_LOGOFF_HE]));
48824 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
48825 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
48826 seq_printf(m, "\nTreeConnects: %d sent %d failed",
48827 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
48828 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
48829 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
48830 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
48831 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
48832 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
48833 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
48834 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
48835 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
48836 seq_printf(m, "\nCreates: %d sent %d failed",
48837 - atomic_read(&sent[SMB2_CREATE_HE]),
48838 - atomic_read(&failed[SMB2_CREATE_HE]));
48839 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
48840 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
48841 seq_printf(m, "\nCloses: %d sent %d failed",
48842 - atomic_read(&sent[SMB2_CLOSE_HE]),
48843 - atomic_read(&failed[SMB2_CLOSE_HE]));
48844 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
48845 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
48846 seq_printf(m, "\nFlushes: %d sent %d failed",
48847 - atomic_read(&sent[SMB2_FLUSH_HE]),
48848 - atomic_read(&failed[SMB2_FLUSH_HE]));
48849 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
48850 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
48851 seq_printf(m, "\nReads: %d sent %d failed",
48852 - atomic_read(&sent[SMB2_READ_HE]),
48853 - atomic_read(&failed[SMB2_READ_HE]));
48854 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
48855 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
48856 seq_printf(m, "\nWrites: %d sent %d failed",
48857 - atomic_read(&sent[SMB2_WRITE_HE]),
48858 - atomic_read(&failed[SMB2_WRITE_HE]));
48859 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
48860 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
48861 seq_printf(m, "\nLocks: %d sent %d failed",
48862 - atomic_read(&sent[SMB2_LOCK_HE]),
48863 - atomic_read(&failed[SMB2_LOCK_HE]));
48864 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
48865 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
48866 seq_printf(m, "\nIOCTLs: %d sent %d failed",
48867 - atomic_read(&sent[SMB2_IOCTL_HE]),
48868 - atomic_read(&failed[SMB2_IOCTL_HE]));
48869 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
48870 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
48871 seq_printf(m, "\nCancels: %d sent %d failed",
48872 - atomic_read(&sent[SMB2_CANCEL_HE]),
48873 - atomic_read(&failed[SMB2_CANCEL_HE]));
48874 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
48875 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
48876 seq_printf(m, "\nEchos: %d sent %d failed",
48877 - atomic_read(&sent[SMB2_ECHO_HE]),
48878 - atomic_read(&failed[SMB2_ECHO_HE]));
48879 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
48880 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
48881 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
48882 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
48883 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
48884 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
48885 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
48886 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
48887 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
48888 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
48889 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
48890 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
48891 seq_printf(m, "\nQueryInfos: %d sent %d failed",
48892 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
48893 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
48894 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
48895 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
48896 seq_printf(m, "\nSetInfos: %d sent %d failed",
48897 - atomic_read(&sent[SMB2_SET_INFO_HE]),
48898 - atomic_read(&failed[SMB2_SET_INFO_HE]));
48899 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
48900 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
48901 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
48902 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
48903 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
48904 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
48905 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
48906 #endif
48907 }
48908
48909 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
48910 index 41d9d07..dbb4772 100644
48911 --- a/fs/cifs/smb2pdu.c
48912 +++ b/fs/cifs/smb2pdu.c
48913 @@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
48914 default:
48915 cERROR(1, "info level %u isn't supported",
48916 srch_inf->info_level);
48917 - rc = -EINVAL;
48918 - goto qdir_exit;
48919 + return -EINVAL;
48920 }
48921
48922 req->FileIndex = cpu_to_le32(index);
48923 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
48924 index 958ae0e..505c9d0 100644
48925 --- a/fs/coda/cache.c
48926 +++ b/fs/coda/cache.c
48927 @@ -24,7 +24,7 @@
48928 #include "coda_linux.h"
48929 #include "coda_cache.h"
48930
48931 -static atomic_t permission_epoch = ATOMIC_INIT(0);
48932 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
48933
48934 /* replace or extend an acl cache hit */
48935 void coda_cache_enter(struct inode *inode, int mask)
48936 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
48937 struct coda_inode_info *cii = ITOC(inode);
48938
48939 spin_lock(&cii->c_lock);
48940 - cii->c_cached_epoch = atomic_read(&permission_epoch);
48941 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
48942 if (cii->c_uid != current_fsuid()) {
48943 cii->c_uid = current_fsuid();
48944 cii->c_cached_perm = mask;
48945 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
48946 {
48947 struct coda_inode_info *cii = ITOC(inode);
48948 spin_lock(&cii->c_lock);
48949 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
48950 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
48951 spin_unlock(&cii->c_lock);
48952 }
48953
48954 /* remove all acl caches */
48955 void coda_cache_clear_all(struct super_block *sb)
48956 {
48957 - atomic_inc(&permission_epoch);
48958 + atomic_inc_unchecked(&permission_epoch);
48959 }
48960
48961
48962 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
48963 spin_lock(&cii->c_lock);
48964 hit = (mask & cii->c_cached_perm) == mask &&
48965 cii->c_uid == current_fsuid() &&
48966 - cii->c_cached_epoch == atomic_read(&permission_epoch);
48967 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
48968 spin_unlock(&cii->c_lock);
48969
48970 return hit;
48971 diff --git a/fs/compat.c b/fs/compat.c
48972 index 015e1e1..b8966ac 100644
48973 --- a/fs/compat.c
48974 +++ b/fs/compat.c
48975 @@ -54,7 +54,7 @@
48976 #include <asm/ioctls.h>
48977 #include "internal.h"
48978
48979 -int compat_log = 1;
48980 +int compat_log = 0;
48981
48982 int compat_printk(const char *fmt, ...)
48983 {
48984 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
48985
48986 set_fs(KERNEL_DS);
48987 /* The __user pointer cast is valid because of the set_fs() */
48988 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
48989 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
48990 set_fs(oldfs);
48991 /* truncating is ok because it's a user address */
48992 if (!ret)
48993 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
48994 goto out;
48995
48996 ret = -EINVAL;
48997 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
48998 + if (nr_segs > UIO_MAXIOV)
48999 goto out;
49000 if (nr_segs > fast_segs) {
49001 ret = -ENOMEM;
49002 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
49003
49004 struct compat_readdir_callback {
49005 struct compat_old_linux_dirent __user *dirent;
49006 + struct file * file;
49007 int result;
49008 };
49009
49010 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
49011 buf->result = -EOVERFLOW;
49012 return -EOVERFLOW;
49013 }
49014 +
49015 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49016 + return 0;
49017 +
49018 buf->result++;
49019 dirent = buf->dirent;
49020 if (!access_ok(VERIFY_WRITE, dirent,
49021 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
49022
49023 buf.result = 0;
49024 buf.dirent = dirent;
49025 + buf.file = f.file;
49026
49027 error = vfs_readdir(f.file, compat_fillonedir, &buf);
49028 if (buf.result)
49029 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
49030 struct compat_getdents_callback {
49031 struct compat_linux_dirent __user *current_dir;
49032 struct compat_linux_dirent __user *previous;
49033 + struct file * file;
49034 int count;
49035 int error;
49036 };
49037 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
49038 buf->error = -EOVERFLOW;
49039 return -EOVERFLOW;
49040 }
49041 +
49042 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49043 + return 0;
49044 +
49045 dirent = buf->previous;
49046 if (dirent) {
49047 if (__put_user(offset, &dirent->d_off))
49048 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49049 buf.previous = NULL;
49050 buf.count = count;
49051 buf.error = 0;
49052 + buf.file = f.file;
49053
49054 error = vfs_readdir(f.file, compat_filldir, &buf);
49055 if (error >= 0)
49056 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49057 struct compat_getdents_callback64 {
49058 struct linux_dirent64 __user *current_dir;
49059 struct linux_dirent64 __user *previous;
49060 + struct file * file;
49061 int count;
49062 int error;
49063 };
49064 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
49065 buf->error = -EINVAL; /* only used if we fail.. */
49066 if (reclen > buf->count)
49067 return -EINVAL;
49068 +
49069 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49070 + return 0;
49071 +
49072 dirent = buf->previous;
49073
49074 if (dirent) {
49075 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
49076 buf.previous = NULL;
49077 buf.count = count;
49078 buf.error = 0;
49079 + buf.file = f.file;
49080
49081 error = vfs_readdir(f.file, compat_filldir64, &buf);
49082 if (error >= 0)
49083 error = buf.error;
49084 lastdirent = buf.previous;
49085 if (lastdirent) {
49086 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
49087 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
49088 if (__put_user_unaligned(d_off, &lastdirent->d_off))
49089 error = -EFAULT;
49090 else
49091 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
49092 index a81147e..20bf2b5 100644
49093 --- a/fs/compat_binfmt_elf.c
49094 +++ b/fs/compat_binfmt_elf.c
49095 @@ -30,11 +30,13 @@
49096 #undef elf_phdr
49097 #undef elf_shdr
49098 #undef elf_note
49099 +#undef elf_dyn
49100 #undef elf_addr_t
49101 #define elfhdr elf32_hdr
49102 #define elf_phdr elf32_phdr
49103 #define elf_shdr elf32_shdr
49104 #define elf_note elf32_note
49105 +#define elf_dyn Elf32_Dyn
49106 #define elf_addr_t Elf32_Addr
49107
49108 /*
49109 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
49110 index e2f57a0..3c78771 100644
49111 --- a/fs/compat_ioctl.c
49112 +++ b/fs/compat_ioctl.c
49113 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
49114 return -EFAULT;
49115 if (__get_user(udata, &ss32->iomem_base))
49116 return -EFAULT;
49117 - ss.iomem_base = compat_ptr(udata);
49118 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
49119 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
49120 __get_user(ss.port_high, &ss32->port_high))
49121 return -EFAULT;
49122 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
49123 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
49124 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
49125 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
49126 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49127 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49128 return -EFAULT;
49129
49130 return ioctl_preallocate(file, p);
49131 @@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
49132 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
49133 {
49134 unsigned int a, b;
49135 - a = *(unsigned int *)p;
49136 - b = *(unsigned int *)q;
49137 + a = *(const unsigned int *)p;
49138 + b = *(const unsigned int *)q;
49139 if (a > b)
49140 return 1;
49141 if (a < b)
49142 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
49143 index 712b10f..c33c4ca 100644
49144 --- a/fs/configfs/dir.c
49145 +++ b/fs/configfs/dir.c
49146 @@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
49147 static int configfs_depend_prep(struct dentry *origin,
49148 struct config_item *target)
49149 {
49150 - struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
49151 + struct configfs_dirent *child_sd, *sd;
49152 int ret = 0;
49153
49154 - BUG_ON(!origin || !sd);
49155 + BUG_ON(!origin || !origin->d_fsdata);
49156 + sd = origin->d_fsdata;
49157
49158 if (sd->s_element == target) /* Boo-yah */
49159 goto out;
49160 @@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49161 }
49162 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
49163 struct configfs_dirent *next;
49164 - const char * name;
49165 + const unsigned char * name;
49166 + char d_name[sizeof(next->s_dentry->d_iname)];
49167 int len;
49168 struct inode *inode = NULL;
49169
49170 @@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49171 continue;
49172
49173 name = configfs_get_name(next);
49174 - len = strlen(name);
49175 + if (next->s_dentry && name == next->s_dentry->d_iname) {
49176 + len = next->s_dentry->d_name.len;
49177 + memcpy(d_name, name, len);
49178 + name = d_name;
49179 + } else
49180 + len = strlen(name);
49181
49182 /*
49183 * We'll have a dentry and an inode for
49184 diff --git a/fs/coredump.c b/fs/coredump.c
49185 index 1774932..5812106 100644
49186 --- a/fs/coredump.c
49187 +++ b/fs/coredump.c
49188 @@ -52,7 +52,7 @@ struct core_name {
49189 char *corename;
49190 int used, size;
49191 };
49192 -static atomic_t call_count = ATOMIC_INIT(1);
49193 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
49194
49195 /* The maximal length of core_pattern is also specified in sysctl.c */
49196
49197 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
49198 {
49199 char *old_corename = cn->corename;
49200
49201 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
49202 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
49203 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
49204
49205 if (!cn->corename) {
49206 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
49207 int pid_in_pattern = 0;
49208 int err = 0;
49209
49210 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
49211 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
49212 cn->corename = kmalloc(cn->size, GFP_KERNEL);
49213 cn->used = 0;
49214
49215 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
49216 pipe = file->f_path.dentry->d_inode->i_pipe;
49217
49218 pipe_lock(pipe);
49219 - pipe->readers++;
49220 - pipe->writers--;
49221 + atomic_inc(&pipe->readers);
49222 + atomic_dec(&pipe->writers);
49223
49224 - while ((pipe->readers > 1) && (!signal_pending(current))) {
49225 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
49226 wake_up_interruptible_sync(&pipe->wait);
49227 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49228 pipe_wait(pipe);
49229 }
49230
49231 - pipe->readers--;
49232 - pipe->writers++;
49233 + atomic_dec(&pipe->readers);
49234 + atomic_inc(&pipe->writers);
49235 pipe_unlock(pipe);
49236
49237 }
49238 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
49239 int ispipe;
49240 struct files_struct *displaced;
49241 bool need_nonrelative = false;
49242 - static atomic_t core_dump_count = ATOMIC_INIT(0);
49243 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
49244 + long signr = siginfo->si_signo;
49245 struct coredump_params cprm = {
49246 .siginfo = siginfo,
49247 .regs = signal_pt_regs(),
49248 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
49249 .mm_flags = mm->flags,
49250 };
49251
49252 - audit_core_dumps(siginfo->si_signo);
49253 + audit_core_dumps(signr);
49254 +
49255 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
49256 + gr_handle_brute_attach(cprm.mm_flags);
49257
49258 binfmt = mm->binfmt;
49259 if (!binfmt || !binfmt->core_dump)
49260 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
49261 need_nonrelative = true;
49262 }
49263
49264 - retval = coredump_wait(siginfo->si_signo, &core_state);
49265 + retval = coredump_wait(signr, &core_state);
49266 if (retval < 0)
49267 goto fail_creds;
49268
49269 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
49270 }
49271 cprm.limit = RLIM_INFINITY;
49272
49273 - dump_count = atomic_inc_return(&core_dump_count);
49274 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
49275 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
49276 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
49277 task_tgid_vnr(current), current->comm);
49278 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
49279 } else {
49280 struct inode *inode;
49281
49282 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
49283 +
49284 if (cprm.limit < binfmt->min_coredump)
49285 goto fail_unlock;
49286
49287 @@ -640,7 +646,7 @@ close_fail:
49288 filp_close(cprm.file, NULL);
49289 fail_dropcount:
49290 if (ispipe)
49291 - atomic_dec(&core_dump_count);
49292 + atomic_dec_unchecked(&core_dump_count);
49293 fail_unlock:
49294 kfree(cn.corename);
49295 fail_corename:
49296 @@ -659,7 +665,7 @@ fail:
49297 */
49298 int dump_write(struct file *file, const void *addr, int nr)
49299 {
49300 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
49301 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
49302 }
49303 EXPORT_SYMBOL(dump_write);
49304
49305 diff --git a/fs/dcache.c b/fs/dcache.c
49306 index 19153a0..428c2f5 100644
49307 --- a/fs/dcache.c
49308 +++ b/fs/dcache.c
49309 @@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
49310 mempages -= reserve;
49311
49312 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
49313 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
49314 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
49315
49316 dcache_init();
49317 inode_init();
49318 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
49319 index a5f12b7..4ee8a6f 100644
49320 --- a/fs/debugfs/inode.c
49321 +++ b/fs/debugfs/inode.c
49322 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
49323 */
49324 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
49325 {
49326 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49327 + return __create_file(name, S_IFDIR | S_IRWXU,
49328 +#else
49329 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
49330 +#endif
49331 parent, NULL, NULL);
49332 }
49333 EXPORT_SYMBOL_GPL(debugfs_create_dir);
49334 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
49335 index cc7709e..7e7211f 100644
49336 --- a/fs/ecryptfs/inode.c
49337 +++ b/fs/ecryptfs/inode.c
49338 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
49339 old_fs = get_fs();
49340 set_fs(get_ds());
49341 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
49342 - (char __user *)lower_buf,
49343 + (char __force_user *)lower_buf,
49344 PATH_MAX);
49345 set_fs(old_fs);
49346 if (rc < 0)
49347 @@ -706,7 +706,7 @@ out:
49348 static void
49349 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
49350 {
49351 - char *buf = nd_get_link(nd);
49352 + const char *buf = nd_get_link(nd);
49353 if (!IS_ERR(buf)) {
49354 /* Free the char* */
49355 kfree(buf);
49356 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
49357 index 412e6ed..4292d22 100644
49358 --- a/fs/ecryptfs/miscdev.c
49359 +++ b/fs/ecryptfs/miscdev.c
49360 @@ -315,7 +315,7 @@ check_list:
49361 goto out_unlock_msg_ctx;
49362 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
49363 if (msg_ctx->msg) {
49364 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
49365 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
49366 goto out_unlock_msg_ctx;
49367 i += packet_length_size;
49368 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
49369 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
49370 index b2a34a1..162fa69 100644
49371 --- a/fs/ecryptfs/read_write.c
49372 +++ b/fs/ecryptfs/read_write.c
49373 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
49374 return -EIO;
49375 fs_save = get_fs();
49376 set_fs(get_ds());
49377 - rc = vfs_write(lower_file, data, size, &offset);
49378 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
49379 set_fs(fs_save);
49380 mark_inode_dirty_sync(ecryptfs_inode);
49381 return rc;
49382 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
49383 return -EIO;
49384 fs_save = get_fs();
49385 set_fs(get_ds());
49386 - rc = vfs_read(lower_file, data, size, &offset);
49387 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
49388 set_fs(fs_save);
49389 return rc;
49390 }
49391 diff --git a/fs/exec.c b/fs/exec.c
49392 index 20df02c..9b8f78d 100644
49393 --- a/fs/exec.c
49394 +++ b/fs/exec.c
49395 @@ -55,6 +55,17 @@
49396 #include <linux/pipe_fs_i.h>
49397 #include <linux/oom.h>
49398 #include <linux/compat.h>
49399 +#include <linux/random.h>
49400 +#include <linux/seq_file.h>
49401 +#include <linux/coredump.h>
49402 +#include <linux/mman.h>
49403 +
49404 +#ifdef CONFIG_PAX_REFCOUNT
49405 +#include <linux/kallsyms.h>
49406 +#include <linux/kdebug.h>
49407 +#endif
49408 +
49409 +#include <trace/events/fs.h>
49410
49411 #include <asm/uaccess.h>
49412 #include <asm/mmu_context.h>
49413 @@ -66,6 +77,18 @@
49414
49415 #include <trace/events/sched.h>
49416
49417 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49418 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
49419 +{
49420 + 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");
49421 +}
49422 +#endif
49423 +
49424 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
49425 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
49426 +EXPORT_SYMBOL(pax_set_initial_flags_func);
49427 +#endif
49428 +
49429 int suid_dumpable = 0;
49430
49431 static LIST_HEAD(formats);
49432 @@ -75,8 +98,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
49433 {
49434 BUG_ON(!fmt);
49435 write_lock(&binfmt_lock);
49436 - insert ? list_add(&fmt->lh, &formats) :
49437 - list_add_tail(&fmt->lh, &formats);
49438 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
49439 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
49440 write_unlock(&binfmt_lock);
49441 }
49442
49443 @@ -85,7 +108,7 @@ EXPORT_SYMBOL(__register_binfmt);
49444 void unregister_binfmt(struct linux_binfmt * fmt)
49445 {
49446 write_lock(&binfmt_lock);
49447 - list_del(&fmt->lh);
49448 + pax_list_del((struct list_head *)&fmt->lh);
49449 write_unlock(&binfmt_lock);
49450 }
49451
49452 @@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
49453 int write)
49454 {
49455 struct page *page;
49456 - int ret;
49457
49458 -#ifdef CONFIG_STACK_GROWSUP
49459 - if (write) {
49460 - ret = expand_downwards(bprm->vma, pos);
49461 - if (ret < 0)
49462 - return NULL;
49463 - }
49464 -#endif
49465 - ret = get_user_pages(current, bprm->mm, pos,
49466 - 1, write, 1, &page, NULL);
49467 - if (ret <= 0)
49468 + if (0 > expand_downwards(bprm->vma, pos))
49469 + return NULL;
49470 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
49471 return NULL;
49472
49473 if (write) {
49474 @@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
49475 if (size <= ARG_MAX)
49476 return page;
49477
49478 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49479 + // only allow 512KB for argv+env on suid/sgid binaries
49480 + // to prevent easy ASLR exhaustion
49481 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
49482 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
49483 + (size > (512 * 1024))) {
49484 + put_page(page);
49485 + return NULL;
49486 + }
49487 +#endif
49488 +
49489 /*
49490 * Limit to 1/4-th the stack size for the argv+env strings.
49491 * This ensures that:
49492 @@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
49493 vma->vm_end = STACK_TOP_MAX;
49494 vma->vm_start = vma->vm_end - PAGE_SIZE;
49495 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
49496 +
49497 +#ifdef CONFIG_PAX_SEGMEXEC
49498 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
49499 +#endif
49500 +
49501 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
49502 INIT_LIST_HEAD(&vma->anon_vma_chain);
49503
49504 @@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
49505 mm->stack_vm = mm->total_vm = 1;
49506 up_write(&mm->mmap_sem);
49507 bprm->p = vma->vm_end - sizeof(void *);
49508 +
49509 +#ifdef CONFIG_PAX_RANDUSTACK
49510 + if (randomize_va_space)
49511 + bprm->p ^= random32() & ~PAGE_MASK;
49512 +#endif
49513 +
49514 return 0;
49515 err:
49516 up_write(&mm->mmap_sem);
49517 @@ -384,19 +421,7 @@ err:
49518 return err;
49519 }
49520
49521 -struct user_arg_ptr {
49522 -#ifdef CONFIG_COMPAT
49523 - bool is_compat;
49524 -#endif
49525 - union {
49526 - const char __user *const __user *native;
49527 -#ifdef CONFIG_COMPAT
49528 - const compat_uptr_t __user *compat;
49529 -#endif
49530 - } ptr;
49531 -};
49532 -
49533 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49534 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49535 {
49536 const char __user *native;
49537
49538 @@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49539 compat_uptr_t compat;
49540
49541 if (get_user(compat, argv.ptr.compat + nr))
49542 - return ERR_PTR(-EFAULT);
49543 + return (const char __force_user *)ERR_PTR(-EFAULT);
49544
49545 return compat_ptr(compat);
49546 }
49547 #endif
49548
49549 if (get_user(native, argv.ptr.native + nr))
49550 - return ERR_PTR(-EFAULT);
49551 + return (const char __force_user *)ERR_PTR(-EFAULT);
49552
49553 return native;
49554 }
49555 @@ -431,7 +456,7 @@ static int count(struct user_arg_ptr argv, int max)
49556 if (!p)
49557 break;
49558
49559 - if (IS_ERR(p))
49560 + if (IS_ERR((const char __force_kernel *)p))
49561 return -EFAULT;
49562
49563 if (i >= max)
49564 @@ -466,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
49565
49566 ret = -EFAULT;
49567 str = get_user_arg_ptr(argv, argc);
49568 - if (IS_ERR(str))
49569 + if (IS_ERR((const char __force_kernel *)str))
49570 goto out;
49571
49572 len = strnlen_user(str, MAX_ARG_STRLEN);
49573 @@ -548,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
49574 int r;
49575 mm_segment_t oldfs = get_fs();
49576 struct user_arg_ptr argv = {
49577 - .ptr.native = (const char __user *const __user *)__argv,
49578 + .ptr.native = (const char __force_user *const __force_user *)__argv,
49579 };
49580
49581 set_fs(KERNEL_DS);
49582 @@ -583,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
49583 unsigned long new_end = old_end - shift;
49584 struct mmu_gather tlb;
49585
49586 - BUG_ON(new_start > new_end);
49587 + if (new_start >= new_end || new_start < mmap_min_addr)
49588 + return -ENOMEM;
49589
49590 /*
49591 * ensure there are no vmas between where we want to go
49592 @@ -592,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
49593 if (vma != find_vma(mm, new_start))
49594 return -EFAULT;
49595
49596 +#ifdef CONFIG_PAX_SEGMEXEC
49597 + BUG_ON(pax_find_mirror_vma(vma));
49598 +#endif
49599 +
49600 /*
49601 * cover the whole range: [new_start, old_end)
49602 */
49603 @@ -672,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
49604 stack_top = arch_align_stack(stack_top);
49605 stack_top = PAGE_ALIGN(stack_top);
49606
49607 - if (unlikely(stack_top < mmap_min_addr) ||
49608 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
49609 - return -ENOMEM;
49610 -
49611 stack_shift = vma->vm_end - stack_top;
49612
49613 bprm->p -= stack_shift;
49614 @@ -687,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
49615 bprm->exec -= stack_shift;
49616
49617 down_write(&mm->mmap_sem);
49618 +
49619 + /* Move stack pages down in memory. */
49620 + if (stack_shift) {
49621 + ret = shift_arg_pages(vma, stack_shift);
49622 + if (ret)
49623 + goto out_unlock;
49624 + }
49625 +
49626 vm_flags = VM_STACK_FLAGS;
49627
49628 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49629 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49630 + vm_flags &= ~VM_EXEC;
49631 +
49632 +#ifdef CONFIG_PAX_MPROTECT
49633 + if (mm->pax_flags & MF_PAX_MPROTECT)
49634 + vm_flags &= ~VM_MAYEXEC;
49635 +#endif
49636 +
49637 + }
49638 +#endif
49639 +
49640 /*
49641 * Adjust stack execute permissions; explicitly enable for
49642 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
49643 @@ -707,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
49644 goto out_unlock;
49645 BUG_ON(prev != vma);
49646
49647 - /* Move stack pages down in memory. */
49648 - if (stack_shift) {
49649 - ret = shift_arg_pages(vma, stack_shift);
49650 - if (ret)
49651 - goto out_unlock;
49652 - }
49653 -
49654 /* mprotect_fixup is overkill to remove the temporary stack flags */
49655 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
49656
49657 @@ -737,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
49658 #endif
49659 current->mm->start_stack = bprm->p;
49660 ret = expand_stack(vma, stack_base);
49661 +
49662 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
49663 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
49664 + unsigned long size, flags, vm_flags;
49665 +
49666 + size = STACK_TOP - vma->vm_end;
49667 + flags = MAP_FIXED | MAP_PRIVATE;
49668 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
49669 +
49670 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
49671 +
49672 +#ifdef CONFIG_X86
49673 + if (!ret) {
49674 + size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
49675 + ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
49676 + }
49677 +#endif
49678 +
49679 + }
49680 +#endif
49681 +
49682 if (ret)
49683 ret = -EFAULT;
49684
49685 @@ -772,6 +832,8 @@ struct file *open_exec(const char *name)
49686
49687 fsnotify_open(file);
49688
49689 + trace_open_exec(name);
49690 +
49691 err = deny_write_access(file);
49692 if (err)
49693 goto exit;
49694 @@ -795,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
49695 old_fs = get_fs();
49696 set_fs(get_ds());
49697 /* The cast to a user pointer is valid due to the set_fs() */
49698 - result = vfs_read(file, (void __user *)addr, count, &pos);
49699 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
49700 set_fs(old_fs);
49701 return result;
49702 }
49703 @@ -1247,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
49704 }
49705 rcu_read_unlock();
49706
49707 - if (p->fs->users > n_fs) {
49708 + if (atomic_read(&p->fs->users) > n_fs) {
49709 bprm->unsafe |= LSM_UNSAFE_SHARE;
49710 } else {
49711 res = -EAGAIN;
49712 @@ -1447,6 +1509,28 @@ int search_binary_handler(struct linux_binprm *bprm)
49713
49714 EXPORT_SYMBOL(search_binary_handler);
49715
49716 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49717 +static DEFINE_PER_CPU(u64, exec_counter);
49718 +static int __init init_exec_counters(void)
49719 +{
49720 + unsigned int cpu;
49721 +
49722 + for_each_possible_cpu(cpu) {
49723 + per_cpu(exec_counter, cpu) = (u64)cpu;
49724 + }
49725 +
49726 + return 0;
49727 +}
49728 +early_initcall(init_exec_counters);
49729 +static inline void increment_exec_counter(void)
49730 +{
49731 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
49732 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
49733 +}
49734 +#else
49735 +static inline void increment_exec_counter(void) {}
49736 +#endif
49737 +
49738 /*
49739 * sys_execve() executes a new program.
49740 */
49741 @@ -1454,6 +1538,11 @@ static int do_execve_common(const char *filename,
49742 struct user_arg_ptr argv,
49743 struct user_arg_ptr envp)
49744 {
49745 +#ifdef CONFIG_GRKERNSEC
49746 + struct file *old_exec_file;
49747 + struct acl_subject_label *old_acl;
49748 + struct rlimit old_rlim[RLIM_NLIMITS];
49749 +#endif
49750 struct linux_binprm *bprm;
49751 struct file *file;
49752 struct files_struct *displaced;
49753 @@ -1461,6 +1550,8 @@ static int do_execve_common(const char *filename,
49754 int retval;
49755 const struct cred *cred = current_cred();
49756
49757 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
49758 +
49759 /*
49760 * We move the actual failure in case of RLIMIT_NPROC excess from
49761 * set*uid() to execve() because too many poorly written programs
49762 @@ -1501,12 +1592,27 @@ static int do_execve_common(const char *filename,
49763 if (IS_ERR(file))
49764 goto out_unmark;
49765
49766 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
49767 + retval = -EPERM;
49768 + goto out_file;
49769 + }
49770 +
49771 sched_exec();
49772
49773 bprm->file = file;
49774 bprm->filename = filename;
49775 bprm->interp = filename;
49776
49777 + if (gr_process_user_ban()) {
49778 + retval = -EPERM;
49779 + goto out_file;
49780 + }
49781 +
49782 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
49783 + retval = -EACCES;
49784 + goto out_file;
49785 + }
49786 +
49787 retval = bprm_mm_init(bprm);
49788 if (retval)
49789 goto out_file;
49790 @@ -1523,24 +1629,65 @@ static int do_execve_common(const char *filename,
49791 if (retval < 0)
49792 goto out;
49793
49794 +#ifdef CONFIG_GRKERNSEC
49795 + old_acl = current->acl;
49796 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
49797 + old_exec_file = current->exec_file;
49798 + get_file(file);
49799 + current->exec_file = file;
49800 +#endif
49801 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49802 + /* limit suid stack to 8MB
49803 + * we saved the old limits above and will restore them if this exec fails
49804 + */
49805 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
49806 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
49807 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
49808 +#endif
49809 +
49810 + if (!gr_tpe_allow(file)) {
49811 + retval = -EACCES;
49812 + goto out_fail;
49813 + }
49814 +
49815 + if (gr_check_crash_exec(file)) {
49816 + retval = -EACCES;
49817 + goto out_fail;
49818 + }
49819 +
49820 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
49821 + bprm->unsafe);
49822 + if (retval < 0)
49823 + goto out_fail;
49824 +
49825 retval = copy_strings_kernel(1, &bprm->filename, bprm);
49826 if (retval < 0)
49827 - goto out;
49828 + goto out_fail;
49829
49830 bprm->exec = bprm->p;
49831 retval = copy_strings(bprm->envc, envp, bprm);
49832 if (retval < 0)
49833 - goto out;
49834 + goto out_fail;
49835
49836 retval = copy_strings(bprm->argc, argv, bprm);
49837 if (retval < 0)
49838 - goto out;
49839 + goto out_fail;
49840 +
49841 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
49842 +
49843 + gr_handle_exec_args(bprm, argv);
49844
49845 retval = search_binary_handler(bprm);
49846 if (retval < 0)
49847 - goto out;
49848 + goto out_fail;
49849 +#ifdef CONFIG_GRKERNSEC
49850 + if (old_exec_file)
49851 + fput(old_exec_file);
49852 +#endif
49853
49854 /* execve succeeded */
49855 +
49856 + increment_exec_counter();
49857 current->fs->in_exec = 0;
49858 current->in_execve = 0;
49859 acct_update_integrals(current);
49860 @@ -1549,6 +1696,14 @@ static int do_execve_common(const char *filename,
49861 put_files_struct(displaced);
49862 return retval;
49863
49864 +out_fail:
49865 +#ifdef CONFIG_GRKERNSEC
49866 + current->acl = old_acl;
49867 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
49868 + fput(current->exec_file);
49869 + current->exec_file = old_exec_file;
49870 +#endif
49871 +
49872 out:
49873 if (bprm->mm) {
49874 acct_arg_size(bprm, 0);
49875 @@ -1697,3 +1852,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
49876 return error;
49877 }
49878 #endif
49879 +
49880 +int pax_check_flags(unsigned long *flags)
49881 +{
49882 + int retval = 0;
49883 +
49884 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
49885 + if (*flags & MF_PAX_SEGMEXEC)
49886 + {
49887 + *flags &= ~MF_PAX_SEGMEXEC;
49888 + retval = -EINVAL;
49889 + }
49890 +#endif
49891 +
49892 + if ((*flags & MF_PAX_PAGEEXEC)
49893 +
49894 +#ifdef CONFIG_PAX_PAGEEXEC
49895 + && (*flags & MF_PAX_SEGMEXEC)
49896 +#endif
49897 +
49898 + )
49899 + {
49900 + *flags &= ~MF_PAX_PAGEEXEC;
49901 + retval = -EINVAL;
49902 + }
49903 +
49904 + if ((*flags & MF_PAX_MPROTECT)
49905 +
49906 +#ifdef CONFIG_PAX_MPROTECT
49907 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
49908 +#endif
49909 +
49910 + )
49911 + {
49912 + *flags &= ~MF_PAX_MPROTECT;
49913 + retval = -EINVAL;
49914 + }
49915 +
49916 + if ((*flags & MF_PAX_EMUTRAMP)
49917 +
49918 +#ifdef CONFIG_PAX_EMUTRAMP
49919 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
49920 +#endif
49921 +
49922 + )
49923 + {
49924 + *flags &= ~MF_PAX_EMUTRAMP;
49925 + retval = -EINVAL;
49926 + }
49927 +
49928 + return retval;
49929 +}
49930 +
49931 +EXPORT_SYMBOL(pax_check_flags);
49932 +
49933 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49934 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
49935 +{
49936 + struct task_struct *tsk = current;
49937 + struct mm_struct *mm = current->mm;
49938 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
49939 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
49940 + char *path_exec = NULL;
49941 + char *path_fault = NULL;
49942 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
49943 + siginfo_t info = { };
49944 +
49945 + if (buffer_exec && buffer_fault) {
49946 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
49947 +
49948 + down_read(&mm->mmap_sem);
49949 + vma = mm->mmap;
49950 + while (vma && (!vma_exec || !vma_fault)) {
49951 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
49952 + vma_exec = vma;
49953 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
49954 + vma_fault = vma;
49955 + vma = vma->vm_next;
49956 + }
49957 + if (vma_exec) {
49958 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
49959 + if (IS_ERR(path_exec))
49960 + path_exec = "<path too long>";
49961 + else {
49962 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
49963 + if (path_exec) {
49964 + *path_exec = 0;
49965 + path_exec = buffer_exec;
49966 + } else
49967 + path_exec = "<path too long>";
49968 + }
49969 + }
49970 + if (vma_fault) {
49971 + start = vma_fault->vm_start;
49972 + end = vma_fault->vm_end;
49973 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
49974 + if (vma_fault->vm_file) {
49975 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
49976 + if (IS_ERR(path_fault))
49977 + path_fault = "<path too long>";
49978 + else {
49979 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
49980 + if (path_fault) {
49981 + *path_fault = 0;
49982 + path_fault = buffer_fault;
49983 + } else
49984 + path_fault = "<path too long>";
49985 + }
49986 + } else
49987 + path_fault = "<anonymous mapping>";
49988 + }
49989 + up_read(&mm->mmap_sem);
49990 + }
49991 + if (tsk->signal->curr_ip)
49992 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
49993 + else
49994 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
49995 + 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),
49996 + from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
49997 + free_page((unsigned long)buffer_exec);
49998 + free_page((unsigned long)buffer_fault);
49999 + pax_report_insns(regs, pc, sp);
50000 + info.si_signo = SIGKILL;
50001 + info.si_errno = 0;
50002 + info.si_code = SI_KERNEL;
50003 + info.si_pid = 0;
50004 + info.si_uid = 0;
50005 + do_coredump(&info);
50006 +}
50007 +#endif
50008 +
50009 +#ifdef CONFIG_PAX_REFCOUNT
50010 +void pax_report_refcount_overflow(struct pt_regs *regs)
50011 +{
50012 + if (current->signal->curr_ip)
50013 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
50014 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
50015 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
50016 + else
50017 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
50018 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
50019 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
50020 + show_regs(regs);
50021 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
50022 +}
50023 +#endif
50024 +
50025 +#ifdef CONFIG_PAX_USERCOPY
50026 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
50027 +static noinline int check_stack_object(const void *obj, unsigned long len)
50028 +{
50029 + const void * const stack = task_stack_page(current);
50030 + const void * const stackend = stack + THREAD_SIZE;
50031 +
50032 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50033 + const void *frame = NULL;
50034 + const void *oldframe;
50035 +#endif
50036 +
50037 + if (obj + len < obj)
50038 + return -1;
50039 +
50040 + if (obj + len <= stack || stackend <= obj)
50041 + return 0;
50042 +
50043 + if (obj < stack || stackend < obj + len)
50044 + return -1;
50045 +
50046 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50047 + oldframe = __builtin_frame_address(1);
50048 + if (oldframe)
50049 + frame = __builtin_frame_address(2);
50050 + /*
50051 + low ----------------------------------------------> high
50052 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
50053 + ^----------------^
50054 + allow copies only within here
50055 + */
50056 + while (stack <= frame && frame < stackend) {
50057 + /* if obj + len extends past the last frame, this
50058 + check won't pass and the next frame will be 0,
50059 + causing us to bail out and correctly report
50060 + the copy as invalid
50061 + */
50062 + if (obj + len <= frame)
50063 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
50064 + oldframe = frame;
50065 + frame = *(const void * const *)frame;
50066 + }
50067 + return -1;
50068 +#else
50069 + return 1;
50070 +#endif
50071 +}
50072 +
50073 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
50074 +{
50075 + if (current->signal->curr_ip)
50076 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50077 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50078 + else
50079 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50080 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50081 + dump_stack();
50082 + gr_handle_kernel_exploit();
50083 + do_group_exit(SIGKILL);
50084 +}
50085 +#endif
50086 +
50087 +void __check_object_size(const void *ptr, unsigned long n, bool to)
50088 +{
50089 +
50090 +#ifdef CONFIG_PAX_USERCOPY
50091 + const char *type;
50092 +
50093 + if (!n)
50094 + return;
50095 +
50096 + type = check_heap_object(ptr, n);
50097 + if (!type) {
50098 + if (check_stack_object(ptr, n) != -1)
50099 + return;
50100 + type = "<process stack>";
50101 + }
50102 +
50103 + pax_report_usercopy(ptr, n, to, type);
50104 +#endif
50105 +
50106 +}
50107 +EXPORT_SYMBOL(__check_object_size);
50108 +
50109 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
50110 +void pax_track_stack(void)
50111 +{
50112 + unsigned long sp = (unsigned long)&sp;
50113 + if (sp < current_thread_info()->lowest_stack &&
50114 + sp > (unsigned long)task_stack_page(current))
50115 + current_thread_info()->lowest_stack = sp;
50116 +}
50117 +EXPORT_SYMBOL(pax_track_stack);
50118 +#endif
50119 +
50120 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
50121 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
50122 +{
50123 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
50124 + dump_stack();
50125 + do_group_exit(SIGKILL);
50126 +}
50127 +EXPORT_SYMBOL(report_size_overflow);
50128 +#endif
50129 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
50130 index 2616d0e..2ffdec9 100644
50131 --- a/fs/ext2/balloc.c
50132 +++ b/fs/ext2/balloc.c
50133 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
50134
50135 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50136 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50137 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50138 + if (free_blocks < root_blocks + 1 &&
50139 !uid_eq(sbi->s_resuid, current_fsuid()) &&
50140 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50141 - !in_group_p (sbi->s_resgid))) {
50142 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50143 return 0;
50144 }
50145 return 1;
50146 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
50147 index 22548f5..41521d8 100644
50148 --- a/fs/ext3/balloc.c
50149 +++ b/fs/ext3/balloc.c
50150 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
50151
50152 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50153 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50154 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50155 + if (free_blocks < root_blocks + 1 &&
50156 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
50157 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50158 - !in_group_p (sbi->s_resgid))) {
50159 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50160 return 0;
50161 }
50162 return 1;
50163 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
50164 index 2f2e0da..89b113a 100644
50165 --- a/fs/ext4/balloc.c
50166 +++ b/fs/ext4/balloc.c
50167 @@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
50168 /* Hm, nope. Are (enough) root reserved clusters available? */
50169 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
50170 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
50171 - capable(CAP_SYS_RESOURCE) ||
50172 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
50173 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
50174 + capable_nolog(CAP_SYS_RESOURCE)) {
50175
50176 if (free_clusters >= (nclusters + dirty_clusters))
50177 return 1;
50178 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
50179 index 8462eb3..4a71af6 100644
50180 --- a/fs/ext4/ext4.h
50181 +++ b/fs/ext4/ext4.h
50182 @@ -1265,19 +1265,19 @@ struct ext4_sb_info {
50183 unsigned long s_mb_last_start;
50184
50185 /* stats for buddy allocator */
50186 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
50187 - atomic_t s_bal_success; /* we found long enough chunks */
50188 - atomic_t s_bal_allocated; /* in blocks */
50189 - atomic_t s_bal_ex_scanned; /* total extents scanned */
50190 - atomic_t s_bal_goals; /* goal hits */
50191 - atomic_t s_bal_breaks; /* too long searches */
50192 - atomic_t s_bal_2orders; /* 2^order hits */
50193 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
50194 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
50195 + atomic_unchecked_t s_bal_allocated; /* in blocks */
50196 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
50197 + atomic_unchecked_t s_bal_goals; /* goal hits */
50198 + atomic_unchecked_t s_bal_breaks; /* too long searches */
50199 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
50200 spinlock_t s_bal_lock;
50201 unsigned long s_mb_buddies_generated;
50202 unsigned long long s_mb_generation_time;
50203 - atomic_t s_mb_lost_chunks;
50204 - atomic_t s_mb_preallocated;
50205 - atomic_t s_mb_discarded;
50206 + atomic_unchecked_t s_mb_lost_chunks;
50207 + atomic_unchecked_t s_mb_preallocated;
50208 + atomic_unchecked_t s_mb_discarded;
50209 atomic_t s_lock_busy;
50210
50211 /* locality groups */
50212 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
50213 index 061727a..7622abf 100644
50214 --- a/fs/ext4/mballoc.c
50215 +++ b/fs/ext4/mballoc.c
50216 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
50217 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
50218
50219 if (EXT4_SB(sb)->s_mb_stats)
50220 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
50221 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
50222
50223 break;
50224 }
50225 @@ -2044,7 +2044,7 @@ repeat:
50226 ac->ac_status = AC_STATUS_CONTINUE;
50227 ac->ac_flags |= EXT4_MB_HINT_FIRST;
50228 cr = 3;
50229 - atomic_inc(&sbi->s_mb_lost_chunks);
50230 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
50231 goto repeat;
50232 }
50233 }
50234 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
50235 if (sbi->s_mb_stats) {
50236 ext4_msg(sb, KERN_INFO,
50237 "mballoc: %u blocks %u reqs (%u success)",
50238 - atomic_read(&sbi->s_bal_allocated),
50239 - atomic_read(&sbi->s_bal_reqs),
50240 - atomic_read(&sbi->s_bal_success));
50241 + atomic_read_unchecked(&sbi->s_bal_allocated),
50242 + atomic_read_unchecked(&sbi->s_bal_reqs),
50243 + atomic_read_unchecked(&sbi->s_bal_success));
50244 ext4_msg(sb, KERN_INFO,
50245 "mballoc: %u extents scanned, %u goal hits, "
50246 "%u 2^N hits, %u breaks, %u lost",
50247 - atomic_read(&sbi->s_bal_ex_scanned),
50248 - atomic_read(&sbi->s_bal_goals),
50249 - atomic_read(&sbi->s_bal_2orders),
50250 - atomic_read(&sbi->s_bal_breaks),
50251 - atomic_read(&sbi->s_mb_lost_chunks));
50252 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
50253 + atomic_read_unchecked(&sbi->s_bal_goals),
50254 + atomic_read_unchecked(&sbi->s_bal_2orders),
50255 + atomic_read_unchecked(&sbi->s_bal_breaks),
50256 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
50257 ext4_msg(sb, KERN_INFO,
50258 "mballoc: %lu generated and it took %Lu",
50259 sbi->s_mb_buddies_generated,
50260 sbi->s_mb_generation_time);
50261 ext4_msg(sb, KERN_INFO,
50262 "mballoc: %u preallocated, %u discarded",
50263 - atomic_read(&sbi->s_mb_preallocated),
50264 - atomic_read(&sbi->s_mb_discarded));
50265 + atomic_read_unchecked(&sbi->s_mb_preallocated),
50266 + atomic_read_unchecked(&sbi->s_mb_discarded));
50267 }
50268
50269 free_percpu(sbi->s_locality_groups);
50270 @@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
50271 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
50272
50273 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
50274 - atomic_inc(&sbi->s_bal_reqs);
50275 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50276 + atomic_inc_unchecked(&sbi->s_bal_reqs);
50277 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50278 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
50279 - atomic_inc(&sbi->s_bal_success);
50280 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
50281 + atomic_inc_unchecked(&sbi->s_bal_success);
50282 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
50283 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
50284 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
50285 - atomic_inc(&sbi->s_bal_goals);
50286 + atomic_inc_unchecked(&sbi->s_bal_goals);
50287 if (ac->ac_found > sbi->s_mb_max_to_scan)
50288 - atomic_inc(&sbi->s_bal_breaks);
50289 + atomic_inc_unchecked(&sbi->s_bal_breaks);
50290 }
50291
50292 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
50293 @@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
50294 trace_ext4_mb_new_inode_pa(ac, pa);
50295
50296 ext4_mb_use_inode_pa(ac, pa);
50297 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
50298 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
50299
50300 ei = EXT4_I(ac->ac_inode);
50301 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50302 @@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
50303 trace_ext4_mb_new_group_pa(ac, pa);
50304
50305 ext4_mb_use_group_pa(ac, pa);
50306 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50307 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50308
50309 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50310 lg = ac->ac_lg;
50311 @@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
50312 * from the bitmap and continue.
50313 */
50314 }
50315 - atomic_add(free, &sbi->s_mb_discarded);
50316 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
50317
50318 return err;
50319 }
50320 @@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
50321 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
50322 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
50323 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
50324 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50325 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50326 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
50327
50328 return 0;
50329 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
50330 index 0465f36..99a003a 100644
50331 --- a/fs/ext4/super.c
50332 +++ b/fs/ext4/super.c
50333 @@ -2429,7 +2429,7 @@ struct ext4_attr {
50334 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
50335 const char *, size_t);
50336 int offset;
50337 -};
50338 +} __do_const;
50339
50340 static int parse_strtoul(const char *buf,
50341 unsigned long max, unsigned long *value)
50342 diff --git a/fs/fcntl.c b/fs/fcntl.c
50343 index 71a600a..20d87b1 100644
50344 --- a/fs/fcntl.c
50345 +++ b/fs/fcntl.c
50346 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
50347 if (err)
50348 return err;
50349
50350 + if (gr_handle_chroot_fowner(pid, type))
50351 + return -ENOENT;
50352 + if (gr_check_protected_task_fowner(pid, type))
50353 + return -EACCES;
50354 +
50355 f_modown(filp, pid, type, force);
50356 return 0;
50357 }
50358 diff --git a/fs/fhandle.c b/fs/fhandle.c
50359 index 999ff5c..41f4109 100644
50360 --- a/fs/fhandle.c
50361 +++ b/fs/fhandle.c
50362 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
50363 } else
50364 retval = 0;
50365 /* copy the mount id */
50366 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
50367 - sizeof(*mnt_id)) ||
50368 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
50369 copy_to_user(ufh, handle,
50370 sizeof(struct file_handle) + handle_bytes))
50371 retval = -EFAULT;
50372 diff --git a/fs/fifo.c b/fs/fifo.c
50373 index cf6f434..3d7942c 100644
50374 --- a/fs/fifo.c
50375 +++ b/fs/fifo.c
50376 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
50377 */
50378 filp->f_op = &read_pipefifo_fops;
50379 pipe->r_counter++;
50380 - if (pipe->readers++ == 0)
50381 + if (atomic_inc_return(&pipe->readers) == 1)
50382 wake_up_partner(inode);
50383
50384 - if (!pipe->writers) {
50385 + if (!atomic_read(&pipe->writers)) {
50386 if ((filp->f_flags & O_NONBLOCK)) {
50387 /* suppress POLLHUP until we have
50388 * seen a writer */
50389 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
50390 * errno=ENXIO when there is no process reading the FIFO.
50391 */
50392 ret = -ENXIO;
50393 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
50394 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
50395 goto err;
50396
50397 filp->f_op = &write_pipefifo_fops;
50398 pipe->w_counter++;
50399 - if (!pipe->writers++)
50400 + if (atomic_inc_return(&pipe->writers) == 1)
50401 wake_up_partner(inode);
50402
50403 - if (!pipe->readers) {
50404 + if (!atomic_read(&pipe->readers)) {
50405 if (wait_for_partner(inode, &pipe->r_counter))
50406 goto err_wr;
50407 }
50408 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
50409 */
50410 filp->f_op = &rdwr_pipefifo_fops;
50411
50412 - pipe->readers++;
50413 - pipe->writers++;
50414 + atomic_inc(&pipe->readers);
50415 + atomic_inc(&pipe->writers);
50416 pipe->r_counter++;
50417 pipe->w_counter++;
50418 - if (pipe->readers == 1 || pipe->writers == 1)
50419 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
50420 wake_up_partner(inode);
50421 break;
50422
50423 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
50424 return 0;
50425
50426 err_rd:
50427 - if (!--pipe->readers)
50428 + if (atomic_dec_and_test(&pipe->readers))
50429 wake_up_interruptible(&pipe->wait);
50430 ret = -ERESTARTSYS;
50431 goto err;
50432
50433 err_wr:
50434 - if (!--pipe->writers)
50435 + if (atomic_dec_and_test(&pipe->writers))
50436 wake_up_interruptible(&pipe->wait);
50437 ret = -ERESTARTSYS;
50438 goto err;
50439
50440 err:
50441 - if (!pipe->readers && !pipe->writers)
50442 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
50443 free_pipe_info(inode);
50444
50445 err_nocleanup:
50446 diff --git a/fs/file.c b/fs/file.c
50447 index 2b3570b..c57924b 100644
50448 --- a/fs/file.c
50449 +++ b/fs/file.c
50450 @@ -16,6 +16,7 @@
50451 #include <linux/slab.h>
50452 #include <linux/vmalloc.h>
50453 #include <linux/file.h>
50454 +#include <linux/security.h>
50455 #include <linux/fdtable.h>
50456 #include <linux/bitops.h>
50457 #include <linux/interrupt.h>
50458 @@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
50459 if (!file)
50460 return __close_fd(files, fd);
50461
50462 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
50463 if (fd >= rlimit(RLIMIT_NOFILE))
50464 return -EBADF;
50465
50466 @@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
50467 if (unlikely(oldfd == newfd))
50468 return -EINVAL;
50469
50470 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
50471 if (newfd >= rlimit(RLIMIT_NOFILE))
50472 return -EBADF;
50473
50474 @@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
50475 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
50476 {
50477 int err;
50478 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
50479 if (from >= rlimit(RLIMIT_NOFILE))
50480 return -EINVAL;
50481 err = alloc_fd(from, flags);
50482 diff --git a/fs/filesystems.c b/fs/filesystems.c
50483 index da165f6..3671bdb 100644
50484 --- a/fs/filesystems.c
50485 +++ b/fs/filesystems.c
50486 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
50487 int len = dot ? dot - name : strlen(name);
50488
50489 fs = __get_fs_type(name, len);
50490 +
50491 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
50492 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
50493 +#else
50494 if (!fs && (request_module("%.*s", len, name) == 0))
50495 +#endif
50496 fs = __get_fs_type(name, len);
50497
50498 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
50499 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
50500 index fe6ca58..65318cf 100644
50501 --- a/fs/fs_struct.c
50502 +++ b/fs/fs_struct.c
50503 @@ -4,6 +4,7 @@
50504 #include <linux/path.h>
50505 #include <linux/slab.h>
50506 #include <linux/fs_struct.h>
50507 +#include <linux/grsecurity.h>
50508 #include "internal.h"
50509
50510 /*
50511 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
50512 write_seqcount_begin(&fs->seq);
50513 old_root = fs->root;
50514 fs->root = *path;
50515 + gr_set_chroot_entries(current, path);
50516 write_seqcount_end(&fs->seq);
50517 spin_unlock(&fs->lock);
50518 if (old_root.dentry)
50519 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
50520 return 1;
50521 }
50522
50523 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
50524 +{
50525 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
50526 + return 0;
50527 + *p = *new;
50528 +
50529 + /* This function is only called from pivot_root(). Leave our
50530 + gr_chroot_dentry and is_chrooted flags as-is, so that a
50531 + pivoted root isn't treated as a chroot
50532 + */
50533 + //gr_set_chroot_entries(task, new);
50534 +
50535 + return 1;
50536 +}
50537 +
50538 void chroot_fs_refs(struct path *old_root, struct path *new_root)
50539 {
50540 struct task_struct *g, *p;
50541 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
50542 int hits = 0;
50543 spin_lock(&fs->lock);
50544 write_seqcount_begin(&fs->seq);
50545 - hits += replace_path(&fs->root, old_root, new_root);
50546 + hits += replace_root_path(p, &fs->root, old_root, new_root);
50547 hits += replace_path(&fs->pwd, old_root, new_root);
50548 write_seqcount_end(&fs->seq);
50549 while (hits--) {
50550 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
50551 task_lock(tsk);
50552 spin_lock(&fs->lock);
50553 tsk->fs = NULL;
50554 - kill = !--fs->users;
50555 + gr_clear_chroot_entries(tsk);
50556 + kill = !atomic_dec_return(&fs->users);
50557 spin_unlock(&fs->lock);
50558 task_unlock(tsk);
50559 if (kill)
50560 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
50561 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
50562 /* We don't need to lock fs - think why ;-) */
50563 if (fs) {
50564 - fs->users = 1;
50565 + atomic_set(&fs->users, 1);
50566 fs->in_exec = 0;
50567 spin_lock_init(&fs->lock);
50568 seqcount_init(&fs->seq);
50569 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
50570 spin_lock(&old->lock);
50571 fs->root = old->root;
50572 path_get(&fs->root);
50573 + /* instead of calling gr_set_chroot_entries here,
50574 + we call it from every caller of this function
50575 + */
50576 fs->pwd = old->pwd;
50577 path_get(&fs->pwd);
50578 spin_unlock(&old->lock);
50579 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
50580
50581 task_lock(current);
50582 spin_lock(&fs->lock);
50583 - kill = !--fs->users;
50584 + kill = !atomic_dec_return(&fs->users);
50585 current->fs = new_fs;
50586 + gr_set_chroot_entries(current, &new_fs->root);
50587 spin_unlock(&fs->lock);
50588 task_unlock(current);
50589
50590 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
50591
50592 int current_umask(void)
50593 {
50594 - return current->fs->umask;
50595 + return current->fs->umask | gr_acl_umask();
50596 }
50597 EXPORT_SYMBOL(current_umask);
50598
50599 /* to be mentioned only in INIT_TASK */
50600 struct fs_struct init_fs = {
50601 - .users = 1,
50602 + .users = ATOMIC_INIT(1),
50603 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
50604 .seq = SEQCNT_ZERO,
50605 .umask = 0022,
50606 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
50607 index 8dcb114..b1072e2 100644
50608 --- a/fs/fscache/cookie.c
50609 +++ b/fs/fscache/cookie.c
50610 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
50611 parent ? (char *) parent->def->name : "<no-parent>",
50612 def->name, netfs_data);
50613
50614 - fscache_stat(&fscache_n_acquires);
50615 + fscache_stat_unchecked(&fscache_n_acquires);
50616
50617 /* if there's no parent cookie, then we don't create one here either */
50618 if (!parent) {
50619 - fscache_stat(&fscache_n_acquires_null);
50620 + fscache_stat_unchecked(&fscache_n_acquires_null);
50621 _leave(" [no parent]");
50622 return NULL;
50623 }
50624 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
50625 /* allocate and initialise a cookie */
50626 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
50627 if (!cookie) {
50628 - fscache_stat(&fscache_n_acquires_oom);
50629 + fscache_stat_unchecked(&fscache_n_acquires_oom);
50630 _leave(" [ENOMEM]");
50631 return NULL;
50632 }
50633 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
50634
50635 switch (cookie->def->type) {
50636 case FSCACHE_COOKIE_TYPE_INDEX:
50637 - fscache_stat(&fscache_n_cookie_index);
50638 + fscache_stat_unchecked(&fscache_n_cookie_index);
50639 break;
50640 case FSCACHE_COOKIE_TYPE_DATAFILE:
50641 - fscache_stat(&fscache_n_cookie_data);
50642 + fscache_stat_unchecked(&fscache_n_cookie_data);
50643 break;
50644 default:
50645 - fscache_stat(&fscache_n_cookie_special);
50646 + fscache_stat_unchecked(&fscache_n_cookie_special);
50647 break;
50648 }
50649
50650 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
50651 if (fscache_acquire_non_index_cookie(cookie) < 0) {
50652 atomic_dec(&parent->n_children);
50653 __fscache_cookie_put(cookie);
50654 - fscache_stat(&fscache_n_acquires_nobufs);
50655 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
50656 _leave(" = NULL");
50657 return NULL;
50658 }
50659 }
50660
50661 - fscache_stat(&fscache_n_acquires_ok);
50662 + fscache_stat_unchecked(&fscache_n_acquires_ok);
50663 _leave(" = %p", cookie);
50664 return cookie;
50665 }
50666 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
50667 cache = fscache_select_cache_for_object(cookie->parent);
50668 if (!cache) {
50669 up_read(&fscache_addremove_sem);
50670 - fscache_stat(&fscache_n_acquires_no_cache);
50671 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
50672 _leave(" = -ENOMEDIUM [no cache]");
50673 return -ENOMEDIUM;
50674 }
50675 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
50676 object = cache->ops->alloc_object(cache, cookie);
50677 fscache_stat_d(&fscache_n_cop_alloc_object);
50678 if (IS_ERR(object)) {
50679 - fscache_stat(&fscache_n_object_no_alloc);
50680 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
50681 ret = PTR_ERR(object);
50682 goto error;
50683 }
50684
50685 - fscache_stat(&fscache_n_object_alloc);
50686 + fscache_stat_unchecked(&fscache_n_object_alloc);
50687
50688 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
50689
50690 @@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
50691
50692 _enter("{%s}", cookie->def->name);
50693
50694 - fscache_stat(&fscache_n_invalidates);
50695 + fscache_stat_unchecked(&fscache_n_invalidates);
50696
50697 /* Only permit invalidation of data files. Invalidating an index will
50698 * require the caller to release all its attachments to the tree rooted
50699 @@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
50700 struct fscache_object *object;
50701 struct hlist_node *_p;
50702
50703 - fscache_stat(&fscache_n_updates);
50704 + fscache_stat_unchecked(&fscache_n_updates);
50705
50706 if (!cookie) {
50707 - fscache_stat(&fscache_n_updates_null);
50708 + fscache_stat_unchecked(&fscache_n_updates_null);
50709 _leave(" [no cookie]");
50710 return;
50711 }
50712 @@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
50713 struct fscache_object *object;
50714 unsigned long event;
50715
50716 - fscache_stat(&fscache_n_relinquishes);
50717 + fscache_stat_unchecked(&fscache_n_relinquishes);
50718 if (retire)
50719 - fscache_stat(&fscache_n_relinquishes_retire);
50720 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
50721
50722 if (!cookie) {
50723 - fscache_stat(&fscache_n_relinquishes_null);
50724 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
50725 _leave(" [no cookie]");
50726 return;
50727 }
50728 @@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
50729
50730 /* wait for the cookie to finish being instantiated (or to fail) */
50731 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
50732 - fscache_stat(&fscache_n_relinquishes_waitcrt);
50733 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
50734 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
50735 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
50736 }
50737 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
50738 index ee38fef..0a326d4 100644
50739 --- a/fs/fscache/internal.h
50740 +++ b/fs/fscache/internal.h
50741 @@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
50742 * stats.c
50743 */
50744 #ifdef CONFIG_FSCACHE_STATS
50745 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
50746 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
50747 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
50748 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
50749
50750 -extern atomic_t fscache_n_op_pend;
50751 -extern atomic_t fscache_n_op_run;
50752 -extern atomic_t fscache_n_op_enqueue;
50753 -extern atomic_t fscache_n_op_deferred_release;
50754 -extern atomic_t fscache_n_op_release;
50755 -extern atomic_t fscache_n_op_gc;
50756 -extern atomic_t fscache_n_op_cancelled;
50757 -extern atomic_t fscache_n_op_rejected;
50758 +extern atomic_unchecked_t fscache_n_op_pend;
50759 +extern atomic_unchecked_t fscache_n_op_run;
50760 +extern atomic_unchecked_t fscache_n_op_enqueue;
50761 +extern atomic_unchecked_t fscache_n_op_deferred_release;
50762 +extern atomic_unchecked_t fscache_n_op_release;
50763 +extern atomic_unchecked_t fscache_n_op_gc;
50764 +extern atomic_unchecked_t fscache_n_op_cancelled;
50765 +extern atomic_unchecked_t fscache_n_op_rejected;
50766
50767 -extern atomic_t fscache_n_attr_changed;
50768 -extern atomic_t fscache_n_attr_changed_ok;
50769 -extern atomic_t fscache_n_attr_changed_nobufs;
50770 -extern atomic_t fscache_n_attr_changed_nomem;
50771 -extern atomic_t fscache_n_attr_changed_calls;
50772 +extern atomic_unchecked_t fscache_n_attr_changed;
50773 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
50774 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
50775 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
50776 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
50777
50778 -extern atomic_t fscache_n_allocs;
50779 -extern atomic_t fscache_n_allocs_ok;
50780 -extern atomic_t fscache_n_allocs_wait;
50781 -extern atomic_t fscache_n_allocs_nobufs;
50782 -extern atomic_t fscache_n_allocs_intr;
50783 -extern atomic_t fscache_n_allocs_object_dead;
50784 -extern atomic_t fscache_n_alloc_ops;
50785 -extern atomic_t fscache_n_alloc_op_waits;
50786 +extern atomic_unchecked_t fscache_n_allocs;
50787 +extern atomic_unchecked_t fscache_n_allocs_ok;
50788 +extern atomic_unchecked_t fscache_n_allocs_wait;
50789 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
50790 +extern atomic_unchecked_t fscache_n_allocs_intr;
50791 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
50792 +extern atomic_unchecked_t fscache_n_alloc_ops;
50793 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
50794
50795 -extern atomic_t fscache_n_retrievals;
50796 -extern atomic_t fscache_n_retrievals_ok;
50797 -extern atomic_t fscache_n_retrievals_wait;
50798 -extern atomic_t fscache_n_retrievals_nodata;
50799 -extern atomic_t fscache_n_retrievals_nobufs;
50800 -extern atomic_t fscache_n_retrievals_intr;
50801 -extern atomic_t fscache_n_retrievals_nomem;
50802 -extern atomic_t fscache_n_retrievals_object_dead;
50803 -extern atomic_t fscache_n_retrieval_ops;
50804 -extern atomic_t fscache_n_retrieval_op_waits;
50805 +extern atomic_unchecked_t fscache_n_retrievals;
50806 +extern atomic_unchecked_t fscache_n_retrievals_ok;
50807 +extern atomic_unchecked_t fscache_n_retrievals_wait;
50808 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
50809 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
50810 +extern atomic_unchecked_t fscache_n_retrievals_intr;
50811 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
50812 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
50813 +extern atomic_unchecked_t fscache_n_retrieval_ops;
50814 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
50815
50816 -extern atomic_t fscache_n_stores;
50817 -extern atomic_t fscache_n_stores_ok;
50818 -extern atomic_t fscache_n_stores_again;
50819 -extern atomic_t fscache_n_stores_nobufs;
50820 -extern atomic_t fscache_n_stores_oom;
50821 -extern atomic_t fscache_n_store_ops;
50822 -extern atomic_t fscache_n_store_calls;
50823 -extern atomic_t fscache_n_store_pages;
50824 -extern atomic_t fscache_n_store_radix_deletes;
50825 -extern atomic_t fscache_n_store_pages_over_limit;
50826 +extern atomic_unchecked_t fscache_n_stores;
50827 +extern atomic_unchecked_t fscache_n_stores_ok;
50828 +extern atomic_unchecked_t fscache_n_stores_again;
50829 +extern atomic_unchecked_t fscache_n_stores_nobufs;
50830 +extern atomic_unchecked_t fscache_n_stores_oom;
50831 +extern atomic_unchecked_t fscache_n_store_ops;
50832 +extern atomic_unchecked_t fscache_n_store_calls;
50833 +extern atomic_unchecked_t fscache_n_store_pages;
50834 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
50835 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
50836
50837 -extern atomic_t fscache_n_store_vmscan_not_storing;
50838 -extern atomic_t fscache_n_store_vmscan_gone;
50839 -extern atomic_t fscache_n_store_vmscan_busy;
50840 -extern atomic_t fscache_n_store_vmscan_cancelled;
50841 -extern atomic_t fscache_n_store_vmscan_wait;
50842 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
50843 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
50844 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
50845 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
50846 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
50847
50848 -extern atomic_t fscache_n_marks;
50849 -extern atomic_t fscache_n_uncaches;
50850 +extern atomic_unchecked_t fscache_n_marks;
50851 +extern atomic_unchecked_t fscache_n_uncaches;
50852
50853 -extern atomic_t fscache_n_acquires;
50854 -extern atomic_t fscache_n_acquires_null;
50855 -extern atomic_t fscache_n_acquires_no_cache;
50856 -extern atomic_t fscache_n_acquires_ok;
50857 -extern atomic_t fscache_n_acquires_nobufs;
50858 -extern atomic_t fscache_n_acquires_oom;
50859 +extern atomic_unchecked_t fscache_n_acquires;
50860 +extern atomic_unchecked_t fscache_n_acquires_null;
50861 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
50862 +extern atomic_unchecked_t fscache_n_acquires_ok;
50863 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
50864 +extern atomic_unchecked_t fscache_n_acquires_oom;
50865
50866 -extern atomic_t fscache_n_invalidates;
50867 -extern atomic_t fscache_n_invalidates_run;
50868 +extern atomic_unchecked_t fscache_n_invalidates;
50869 +extern atomic_unchecked_t fscache_n_invalidates_run;
50870
50871 -extern atomic_t fscache_n_updates;
50872 -extern atomic_t fscache_n_updates_null;
50873 -extern atomic_t fscache_n_updates_run;
50874 +extern atomic_unchecked_t fscache_n_updates;
50875 +extern atomic_unchecked_t fscache_n_updates_null;
50876 +extern atomic_unchecked_t fscache_n_updates_run;
50877
50878 -extern atomic_t fscache_n_relinquishes;
50879 -extern atomic_t fscache_n_relinquishes_null;
50880 -extern atomic_t fscache_n_relinquishes_waitcrt;
50881 -extern atomic_t fscache_n_relinquishes_retire;
50882 +extern atomic_unchecked_t fscache_n_relinquishes;
50883 +extern atomic_unchecked_t fscache_n_relinquishes_null;
50884 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
50885 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
50886
50887 -extern atomic_t fscache_n_cookie_index;
50888 -extern atomic_t fscache_n_cookie_data;
50889 -extern atomic_t fscache_n_cookie_special;
50890 +extern atomic_unchecked_t fscache_n_cookie_index;
50891 +extern atomic_unchecked_t fscache_n_cookie_data;
50892 +extern atomic_unchecked_t fscache_n_cookie_special;
50893
50894 -extern atomic_t fscache_n_object_alloc;
50895 -extern atomic_t fscache_n_object_no_alloc;
50896 -extern atomic_t fscache_n_object_lookups;
50897 -extern atomic_t fscache_n_object_lookups_negative;
50898 -extern atomic_t fscache_n_object_lookups_positive;
50899 -extern atomic_t fscache_n_object_lookups_timed_out;
50900 -extern atomic_t fscache_n_object_created;
50901 -extern atomic_t fscache_n_object_avail;
50902 -extern atomic_t fscache_n_object_dead;
50903 +extern atomic_unchecked_t fscache_n_object_alloc;
50904 +extern atomic_unchecked_t fscache_n_object_no_alloc;
50905 +extern atomic_unchecked_t fscache_n_object_lookups;
50906 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
50907 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
50908 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
50909 +extern atomic_unchecked_t fscache_n_object_created;
50910 +extern atomic_unchecked_t fscache_n_object_avail;
50911 +extern atomic_unchecked_t fscache_n_object_dead;
50912
50913 -extern atomic_t fscache_n_checkaux_none;
50914 -extern atomic_t fscache_n_checkaux_okay;
50915 -extern atomic_t fscache_n_checkaux_update;
50916 -extern atomic_t fscache_n_checkaux_obsolete;
50917 +extern atomic_unchecked_t fscache_n_checkaux_none;
50918 +extern atomic_unchecked_t fscache_n_checkaux_okay;
50919 +extern atomic_unchecked_t fscache_n_checkaux_update;
50920 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
50921
50922 extern atomic_t fscache_n_cop_alloc_object;
50923 extern atomic_t fscache_n_cop_lookup_object;
50924 @@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
50925 atomic_inc(stat);
50926 }
50927
50928 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
50929 +{
50930 + atomic_inc_unchecked(stat);
50931 +}
50932 +
50933 static inline void fscache_stat_d(atomic_t *stat)
50934 {
50935 atomic_dec(stat);
50936 @@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
50937
50938 #define __fscache_stat(stat) (NULL)
50939 #define fscache_stat(stat) do {} while (0)
50940 +#define fscache_stat_unchecked(stat) do {} while (0)
50941 #define fscache_stat_d(stat) do {} while (0)
50942 #endif
50943
50944 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
50945 index 50d41c1..10ee117 100644
50946 --- a/fs/fscache/object.c
50947 +++ b/fs/fscache/object.c
50948 @@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
50949 /* Invalidate an object on disk */
50950 case FSCACHE_OBJECT_INVALIDATING:
50951 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
50952 - fscache_stat(&fscache_n_invalidates_run);
50953 + fscache_stat_unchecked(&fscache_n_invalidates_run);
50954 fscache_stat(&fscache_n_cop_invalidate_object);
50955 fscache_invalidate_object(object);
50956 fscache_stat_d(&fscache_n_cop_invalidate_object);
50957 @@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
50958 /* update the object metadata on disk */
50959 case FSCACHE_OBJECT_UPDATING:
50960 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
50961 - fscache_stat(&fscache_n_updates_run);
50962 + fscache_stat_unchecked(&fscache_n_updates_run);
50963 fscache_stat(&fscache_n_cop_update_object);
50964 object->cache->ops->update_object(object);
50965 fscache_stat_d(&fscache_n_cop_update_object);
50966 @@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
50967 spin_lock(&object->lock);
50968 object->state = FSCACHE_OBJECT_DEAD;
50969 spin_unlock(&object->lock);
50970 - fscache_stat(&fscache_n_object_dead);
50971 + fscache_stat_unchecked(&fscache_n_object_dead);
50972 goto terminal_transit;
50973
50974 /* handle the parent cache of this object being withdrawn from
50975 @@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
50976 spin_lock(&object->lock);
50977 object->state = FSCACHE_OBJECT_DEAD;
50978 spin_unlock(&object->lock);
50979 - fscache_stat(&fscache_n_object_dead);
50980 + fscache_stat_unchecked(&fscache_n_object_dead);
50981 goto terminal_transit;
50982
50983 /* complain about the object being woken up once it is
50984 @@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
50985 parent->cookie->def->name, cookie->def->name,
50986 object->cache->tag->name);
50987
50988 - fscache_stat(&fscache_n_object_lookups);
50989 + fscache_stat_unchecked(&fscache_n_object_lookups);
50990 fscache_stat(&fscache_n_cop_lookup_object);
50991 ret = object->cache->ops->lookup_object(object);
50992 fscache_stat_d(&fscache_n_cop_lookup_object);
50993 @@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
50994 if (ret == -ETIMEDOUT) {
50995 /* probably stuck behind another object, so move this one to
50996 * the back of the queue */
50997 - fscache_stat(&fscache_n_object_lookups_timed_out);
50998 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
50999 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51000 }
51001
51002 @@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
51003
51004 spin_lock(&object->lock);
51005 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51006 - fscache_stat(&fscache_n_object_lookups_negative);
51007 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
51008
51009 /* transit here to allow write requests to begin stacking up
51010 * and read requests to begin returning ENODATA */
51011 @@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
51012 * result, in which case there may be data available */
51013 spin_lock(&object->lock);
51014 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51015 - fscache_stat(&fscache_n_object_lookups_positive);
51016 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
51017
51018 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
51019
51020 @@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
51021 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51022 } else {
51023 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
51024 - fscache_stat(&fscache_n_object_created);
51025 + fscache_stat_unchecked(&fscache_n_object_created);
51026
51027 object->state = FSCACHE_OBJECT_AVAILABLE;
51028 spin_unlock(&object->lock);
51029 @@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
51030 fscache_enqueue_dependents(object);
51031
51032 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
51033 - fscache_stat(&fscache_n_object_avail);
51034 + fscache_stat_unchecked(&fscache_n_object_avail);
51035
51036 _leave("");
51037 }
51038 @@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51039 enum fscache_checkaux result;
51040
51041 if (!object->cookie->def->check_aux) {
51042 - fscache_stat(&fscache_n_checkaux_none);
51043 + fscache_stat_unchecked(&fscache_n_checkaux_none);
51044 return FSCACHE_CHECKAUX_OKAY;
51045 }
51046
51047 @@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51048 switch (result) {
51049 /* entry okay as is */
51050 case FSCACHE_CHECKAUX_OKAY:
51051 - fscache_stat(&fscache_n_checkaux_okay);
51052 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
51053 break;
51054
51055 /* entry requires update */
51056 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
51057 - fscache_stat(&fscache_n_checkaux_update);
51058 + fscache_stat_unchecked(&fscache_n_checkaux_update);
51059 break;
51060
51061 /* entry requires deletion */
51062 case FSCACHE_CHECKAUX_OBSOLETE:
51063 - fscache_stat(&fscache_n_checkaux_obsolete);
51064 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
51065 break;
51066
51067 default:
51068 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
51069 index 762a9ec..2023284 100644
51070 --- a/fs/fscache/operation.c
51071 +++ b/fs/fscache/operation.c
51072 @@ -17,7 +17,7 @@
51073 #include <linux/slab.h>
51074 #include "internal.h"
51075
51076 -atomic_t fscache_op_debug_id;
51077 +atomic_unchecked_t fscache_op_debug_id;
51078 EXPORT_SYMBOL(fscache_op_debug_id);
51079
51080 /**
51081 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
51082 ASSERTCMP(atomic_read(&op->usage), >, 0);
51083 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
51084
51085 - fscache_stat(&fscache_n_op_enqueue);
51086 + fscache_stat_unchecked(&fscache_n_op_enqueue);
51087 switch (op->flags & FSCACHE_OP_TYPE) {
51088 case FSCACHE_OP_ASYNC:
51089 _debug("queue async");
51090 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
51091 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
51092 if (op->processor)
51093 fscache_enqueue_operation(op);
51094 - fscache_stat(&fscache_n_op_run);
51095 + fscache_stat_unchecked(&fscache_n_op_run);
51096 }
51097
51098 /*
51099 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51100 if (object->n_in_progress > 0) {
51101 atomic_inc(&op->usage);
51102 list_add_tail(&op->pend_link, &object->pending_ops);
51103 - fscache_stat(&fscache_n_op_pend);
51104 + fscache_stat_unchecked(&fscache_n_op_pend);
51105 } else if (!list_empty(&object->pending_ops)) {
51106 atomic_inc(&op->usage);
51107 list_add_tail(&op->pend_link, &object->pending_ops);
51108 - fscache_stat(&fscache_n_op_pend);
51109 + fscache_stat_unchecked(&fscache_n_op_pend);
51110 fscache_start_operations(object);
51111 } else {
51112 ASSERTCMP(object->n_in_progress, ==, 0);
51113 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51114 object->n_exclusive++; /* reads and writes must wait */
51115 atomic_inc(&op->usage);
51116 list_add_tail(&op->pend_link, &object->pending_ops);
51117 - fscache_stat(&fscache_n_op_pend);
51118 + fscache_stat_unchecked(&fscache_n_op_pend);
51119 ret = 0;
51120 } else {
51121 /* If we're in any other state, there must have been an I/O
51122 @@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
51123 if (object->n_exclusive > 0) {
51124 atomic_inc(&op->usage);
51125 list_add_tail(&op->pend_link, &object->pending_ops);
51126 - fscache_stat(&fscache_n_op_pend);
51127 + fscache_stat_unchecked(&fscache_n_op_pend);
51128 } else if (!list_empty(&object->pending_ops)) {
51129 atomic_inc(&op->usage);
51130 list_add_tail(&op->pend_link, &object->pending_ops);
51131 - fscache_stat(&fscache_n_op_pend);
51132 + fscache_stat_unchecked(&fscache_n_op_pend);
51133 fscache_start_operations(object);
51134 } else {
51135 ASSERTCMP(object->n_exclusive, ==, 0);
51136 @@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
51137 object->n_ops++;
51138 atomic_inc(&op->usage);
51139 list_add_tail(&op->pend_link, &object->pending_ops);
51140 - fscache_stat(&fscache_n_op_pend);
51141 + fscache_stat_unchecked(&fscache_n_op_pend);
51142 ret = 0;
51143 } else if (object->state == FSCACHE_OBJECT_DYING ||
51144 object->state == FSCACHE_OBJECT_LC_DYING ||
51145 object->state == FSCACHE_OBJECT_WITHDRAWING) {
51146 - fscache_stat(&fscache_n_op_rejected);
51147 + fscache_stat_unchecked(&fscache_n_op_rejected);
51148 op->state = FSCACHE_OP_ST_CANCELLED;
51149 ret = -ENOBUFS;
51150 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
51151 @@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
51152 ret = -EBUSY;
51153 if (op->state == FSCACHE_OP_ST_PENDING) {
51154 ASSERT(!list_empty(&op->pend_link));
51155 - fscache_stat(&fscache_n_op_cancelled);
51156 + fscache_stat_unchecked(&fscache_n_op_cancelled);
51157 list_del_init(&op->pend_link);
51158 if (do_cancel)
51159 do_cancel(op);
51160 @@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
51161 while (!list_empty(&object->pending_ops)) {
51162 op = list_entry(object->pending_ops.next,
51163 struct fscache_operation, pend_link);
51164 - fscache_stat(&fscache_n_op_cancelled);
51165 + fscache_stat_unchecked(&fscache_n_op_cancelled);
51166 list_del_init(&op->pend_link);
51167
51168 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
51169 @@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
51170 op->state, ==, FSCACHE_OP_ST_CANCELLED);
51171 op->state = FSCACHE_OP_ST_DEAD;
51172
51173 - fscache_stat(&fscache_n_op_release);
51174 + fscache_stat_unchecked(&fscache_n_op_release);
51175
51176 if (op->release) {
51177 op->release(op);
51178 @@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
51179 * lock, and defer it otherwise */
51180 if (!spin_trylock(&object->lock)) {
51181 _debug("defer put");
51182 - fscache_stat(&fscache_n_op_deferred_release);
51183 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
51184
51185 cache = object->cache;
51186 spin_lock(&cache->op_gc_list_lock);
51187 @@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
51188
51189 _debug("GC DEFERRED REL OBJ%x OP%x",
51190 object->debug_id, op->debug_id);
51191 - fscache_stat(&fscache_n_op_gc);
51192 + fscache_stat_unchecked(&fscache_n_op_gc);
51193
51194 ASSERTCMP(atomic_read(&op->usage), ==, 0);
51195 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
51196 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
51197 index ff000e5..c44ec6d 100644
51198 --- a/fs/fscache/page.c
51199 +++ b/fs/fscache/page.c
51200 @@ -61,7 +61,7 @@ try_again:
51201 val = radix_tree_lookup(&cookie->stores, page->index);
51202 if (!val) {
51203 rcu_read_unlock();
51204 - fscache_stat(&fscache_n_store_vmscan_not_storing);
51205 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
51206 __fscache_uncache_page(cookie, page);
51207 return true;
51208 }
51209 @@ -91,11 +91,11 @@ try_again:
51210 spin_unlock(&cookie->stores_lock);
51211
51212 if (xpage) {
51213 - fscache_stat(&fscache_n_store_vmscan_cancelled);
51214 - fscache_stat(&fscache_n_store_radix_deletes);
51215 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
51216 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51217 ASSERTCMP(xpage, ==, page);
51218 } else {
51219 - fscache_stat(&fscache_n_store_vmscan_gone);
51220 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
51221 }
51222
51223 wake_up_bit(&cookie->flags, 0);
51224 @@ -110,11 +110,11 @@ page_busy:
51225 * sleeping on memory allocation, so we may need to impose a timeout
51226 * too. */
51227 if (!(gfp & __GFP_WAIT)) {
51228 - fscache_stat(&fscache_n_store_vmscan_busy);
51229 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
51230 return false;
51231 }
51232
51233 - fscache_stat(&fscache_n_store_vmscan_wait);
51234 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
51235 __fscache_wait_on_page_write(cookie, page);
51236 gfp &= ~__GFP_WAIT;
51237 goto try_again;
51238 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
51239 FSCACHE_COOKIE_STORING_TAG);
51240 if (!radix_tree_tag_get(&cookie->stores, page->index,
51241 FSCACHE_COOKIE_PENDING_TAG)) {
51242 - fscache_stat(&fscache_n_store_radix_deletes);
51243 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51244 xpage = radix_tree_delete(&cookie->stores, page->index);
51245 }
51246 spin_unlock(&cookie->stores_lock);
51247 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
51248
51249 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
51250
51251 - fscache_stat(&fscache_n_attr_changed_calls);
51252 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
51253
51254 if (fscache_object_is_active(object)) {
51255 fscache_stat(&fscache_n_cop_attr_changed);
51256 @@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51257
51258 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51259
51260 - fscache_stat(&fscache_n_attr_changed);
51261 + fscache_stat_unchecked(&fscache_n_attr_changed);
51262
51263 op = kzalloc(sizeof(*op), GFP_KERNEL);
51264 if (!op) {
51265 - fscache_stat(&fscache_n_attr_changed_nomem);
51266 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
51267 _leave(" = -ENOMEM");
51268 return -ENOMEM;
51269 }
51270 @@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51271 if (fscache_submit_exclusive_op(object, op) < 0)
51272 goto nobufs;
51273 spin_unlock(&cookie->lock);
51274 - fscache_stat(&fscache_n_attr_changed_ok);
51275 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
51276 fscache_put_operation(op);
51277 _leave(" = 0");
51278 return 0;
51279 @@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51280 nobufs:
51281 spin_unlock(&cookie->lock);
51282 kfree(op);
51283 - fscache_stat(&fscache_n_attr_changed_nobufs);
51284 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
51285 _leave(" = %d", -ENOBUFS);
51286 return -ENOBUFS;
51287 }
51288 @@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
51289 /* allocate a retrieval operation and attempt to submit it */
51290 op = kzalloc(sizeof(*op), GFP_NOIO);
51291 if (!op) {
51292 - fscache_stat(&fscache_n_retrievals_nomem);
51293 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51294 return NULL;
51295 }
51296
51297 @@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
51298 return 0;
51299 }
51300
51301 - fscache_stat(&fscache_n_retrievals_wait);
51302 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
51303
51304 jif = jiffies;
51305 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
51306 fscache_wait_bit_interruptible,
51307 TASK_INTERRUPTIBLE) != 0) {
51308 - fscache_stat(&fscache_n_retrievals_intr);
51309 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
51310 _leave(" = -ERESTARTSYS");
51311 return -ERESTARTSYS;
51312 }
51313 @@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
51314 */
51315 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51316 struct fscache_retrieval *op,
51317 - atomic_t *stat_op_waits,
51318 - atomic_t *stat_object_dead)
51319 + atomic_unchecked_t *stat_op_waits,
51320 + atomic_unchecked_t *stat_object_dead)
51321 {
51322 int ret;
51323
51324 @@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51325 goto check_if_dead;
51326
51327 _debug(">>> WT");
51328 - fscache_stat(stat_op_waits);
51329 + fscache_stat_unchecked(stat_op_waits);
51330 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
51331 fscache_wait_bit_interruptible,
51332 TASK_INTERRUPTIBLE) != 0) {
51333 @@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51334
51335 check_if_dead:
51336 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
51337 - fscache_stat(stat_object_dead);
51338 + fscache_stat_unchecked(stat_object_dead);
51339 _leave(" = -ENOBUFS [cancelled]");
51340 return -ENOBUFS;
51341 }
51342 if (unlikely(fscache_object_is_dead(object))) {
51343 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
51344 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
51345 - fscache_stat(stat_object_dead);
51346 + fscache_stat_unchecked(stat_object_dead);
51347 return -ENOBUFS;
51348 }
51349 return 0;
51350 @@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51351
51352 _enter("%p,%p,,,", cookie, page);
51353
51354 - fscache_stat(&fscache_n_retrievals);
51355 + fscache_stat_unchecked(&fscache_n_retrievals);
51356
51357 if (hlist_empty(&cookie->backing_objects))
51358 goto nobufs;
51359 @@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51360 goto nobufs_unlock_dec;
51361 spin_unlock(&cookie->lock);
51362
51363 - fscache_stat(&fscache_n_retrieval_ops);
51364 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
51365
51366 /* pin the netfs read context in case we need to do the actual netfs
51367 * read because we've encountered a cache read failure */
51368 @@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51369
51370 error:
51371 if (ret == -ENOMEM)
51372 - fscache_stat(&fscache_n_retrievals_nomem);
51373 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51374 else if (ret == -ERESTARTSYS)
51375 - fscache_stat(&fscache_n_retrievals_intr);
51376 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
51377 else if (ret == -ENODATA)
51378 - fscache_stat(&fscache_n_retrievals_nodata);
51379 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51380 else if (ret < 0)
51381 - fscache_stat(&fscache_n_retrievals_nobufs);
51382 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51383 else
51384 - fscache_stat(&fscache_n_retrievals_ok);
51385 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
51386
51387 fscache_put_retrieval(op);
51388 _leave(" = %d", ret);
51389 @@ -467,7 +467,7 @@ nobufs_unlock:
51390 spin_unlock(&cookie->lock);
51391 kfree(op);
51392 nobufs:
51393 - fscache_stat(&fscache_n_retrievals_nobufs);
51394 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51395 _leave(" = -ENOBUFS");
51396 return -ENOBUFS;
51397 }
51398 @@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51399
51400 _enter("%p,,%d,,,", cookie, *nr_pages);
51401
51402 - fscache_stat(&fscache_n_retrievals);
51403 + fscache_stat_unchecked(&fscache_n_retrievals);
51404
51405 if (hlist_empty(&cookie->backing_objects))
51406 goto nobufs;
51407 @@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51408 goto nobufs_unlock_dec;
51409 spin_unlock(&cookie->lock);
51410
51411 - fscache_stat(&fscache_n_retrieval_ops);
51412 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
51413
51414 /* pin the netfs read context in case we need to do the actual netfs
51415 * read because we've encountered a cache read failure */
51416 @@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51417
51418 error:
51419 if (ret == -ENOMEM)
51420 - fscache_stat(&fscache_n_retrievals_nomem);
51421 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51422 else if (ret == -ERESTARTSYS)
51423 - fscache_stat(&fscache_n_retrievals_intr);
51424 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
51425 else if (ret == -ENODATA)
51426 - fscache_stat(&fscache_n_retrievals_nodata);
51427 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51428 else if (ret < 0)
51429 - fscache_stat(&fscache_n_retrievals_nobufs);
51430 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51431 else
51432 - fscache_stat(&fscache_n_retrievals_ok);
51433 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
51434
51435 fscache_put_retrieval(op);
51436 _leave(" = %d", ret);
51437 @@ -591,7 +591,7 @@ nobufs_unlock:
51438 spin_unlock(&cookie->lock);
51439 kfree(op);
51440 nobufs:
51441 - fscache_stat(&fscache_n_retrievals_nobufs);
51442 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51443 _leave(" = -ENOBUFS");
51444 return -ENOBUFS;
51445 }
51446 @@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51447
51448 _enter("%p,%p,,,", cookie, page);
51449
51450 - fscache_stat(&fscache_n_allocs);
51451 + fscache_stat_unchecked(&fscache_n_allocs);
51452
51453 if (hlist_empty(&cookie->backing_objects))
51454 goto nobufs;
51455 @@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51456 goto nobufs_unlock;
51457 spin_unlock(&cookie->lock);
51458
51459 - fscache_stat(&fscache_n_alloc_ops);
51460 + fscache_stat_unchecked(&fscache_n_alloc_ops);
51461
51462 ret = fscache_wait_for_retrieval_activation(
51463 object, op,
51464 @@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51465
51466 error:
51467 if (ret == -ERESTARTSYS)
51468 - fscache_stat(&fscache_n_allocs_intr);
51469 + fscache_stat_unchecked(&fscache_n_allocs_intr);
51470 else if (ret < 0)
51471 - fscache_stat(&fscache_n_allocs_nobufs);
51472 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
51473 else
51474 - fscache_stat(&fscache_n_allocs_ok);
51475 + fscache_stat_unchecked(&fscache_n_allocs_ok);
51476
51477 fscache_put_retrieval(op);
51478 _leave(" = %d", ret);
51479 @@ -677,7 +677,7 @@ nobufs_unlock:
51480 spin_unlock(&cookie->lock);
51481 kfree(op);
51482 nobufs:
51483 - fscache_stat(&fscache_n_allocs_nobufs);
51484 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
51485 _leave(" = -ENOBUFS");
51486 return -ENOBUFS;
51487 }
51488 @@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51489
51490 spin_lock(&cookie->stores_lock);
51491
51492 - fscache_stat(&fscache_n_store_calls);
51493 + fscache_stat_unchecked(&fscache_n_store_calls);
51494
51495 /* find a page to store */
51496 page = NULL;
51497 @@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51498 page = results[0];
51499 _debug("gang %d [%lx]", n, page->index);
51500 if (page->index > op->store_limit) {
51501 - fscache_stat(&fscache_n_store_pages_over_limit);
51502 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
51503 goto superseded;
51504 }
51505
51506 @@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51507 spin_unlock(&cookie->stores_lock);
51508 spin_unlock(&object->lock);
51509
51510 - fscache_stat(&fscache_n_store_pages);
51511 + fscache_stat_unchecked(&fscache_n_store_pages);
51512 fscache_stat(&fscache_n_cop_write_page);
51513 ret = object->cache->ops->write_page(op, page);
51514 fscache_stat_d(&fscache_n_cop_write_page);
51515 @@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51516 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51517 ASSERT(PageFsCache(page));
51518
51519 - fscache_stat(&fscache_n_stores);
51520 + fscache_stat_unchecked(&fscache_n_stores);
51521
51522 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
51523 _leave(" = -ENOBUFS [invalidating]");
51524 @@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51525 spin_unlock(&cookie->stores_lock);
51526 spin_unlock(&object->lock);
51527
51528 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
51529 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
51530 op->store_limit = object->store_limit;
51531
51532 if (fscache_submit_op(object, &op->op) < 0)
51533 @@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51534
51535 spin_unlock(&cookie->lock);
51536 radix_tree_preload_end();
51537 - fscache_stat(&fscache_n_store_ops);
51538 - fscache_stat(&fscache_n_stores_ok);
51539 + fscache_stat_unchecked(&fscache_n_store_ops);
51540 + fscache_stat_unchecked(&fscache_n_stores_ok);
51541
51542 /* the work queue now carries its own ref on the object */
51543 fscache_put_operation(&op->op);
51544 @@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51545 return 0;
51546
51547 already_queued:
51548 - fscache_stat(&fscache_n_stores_again);
51549 + fscache_stat_unchecked(&fscache_n_stores_again);
51550 already_pending:
51551 spin_unlock(&cookie->stores_lock);
51552 spin_unlock(&object->lock);
51553 spin_unlock(&cookie->lock);
51554 radix_tree_preload_end();
51555 kfree(op);
51556 - fscache_stat(&fscache_n_stores_ok);
51557 + fscache_stat_unchecked(&fscache_n_stores_ok);
51558 _leave(" = 0");
51559 return 0;
51560
51561 @@ -959,14 +959,14 @@ nobufs:
51562 spin_unlock(&cookie->lock);
51563 radix_tree_preload_end();
51564 kfree(op);
51565 - fscache_stat(&fscache_n_stores_nobufs);
51566 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
51567 _leave(" = -ENOBUFS");
51568 return -ENOBUFS;
51569
51570 nomem_free:
51571 kfree(op);
51572 nomem:
51573 - fscache_stat(&fscache_n_stores_oom);
51574 + fscache_stat_unchecked(&fscache_n_stores_oom);
51575 _leave(" = -ENOMEM");
51576 return -ENOMEM;
51577 }
51578 @@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
51579 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51580 ASSERTCMP(page, !=, NULL);
51581
51582 - fscache_stat(&fscache_n_uncaches);
51583 + fscache_stat_unchecked(&fscache_n_uncaches);
51584
51585 /* cache withdrawal may beat us to it */
51586 if (!PageFsCache(page))
51587 @@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
51588 struct fscache_cookie *cookie = op->op.object->cookie;
51589
51590 #ifdef CONFIG_FSCACHE_STATS
51591 - atomic_inc(&fscache_n_marks);
51592 + atomic_inc_unchecked(&fscache_n_marks);
51593 #endif
51594
51595 _debug("- mark %p{%lx}", page, page->index);
51596 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
51597 index 8179e8b..5072cc7 100644
51598 --- a/fs/fscache/stats.c
51599 +++ b/fs/fscache/stats.c
51600 @@ -18,99 +18,99 @@
51601 /*
51602 * operation counters
51603 */
51604 -atomic_t fscache_n_op_pend;
51605 -atomic_t fscache_n_op_run;
51606 -atomic_t fscache_n_op_enqueue;
51607 -atomic_t fscache_n_op_requeue;
51608 -atomic_t fscache_n_op_deferred_release;
51609 -atomic_t fscache_n_op_release;
51610 -atomic_t fscache_n_op_gc;
51611 -atomic_t fscache_n_op_cancelled;
51612 -atomic_t fscache_n_op_rejected;
51613 +atomic_unchecked_t fscache_n_op_pend;
51614 +atomic_unchecked_t fscache_n_op_run;
51615 +atomic_unchecked_t fscache_n_op_enqueue;
51616 +atomic_unchecked_t fscache_n_op_requeue;
51617 +atomic_unchecked_t fscache_n_op_deferred_release;
51618 +atomic_unchecked_t fscache_n_op_release;
51619 +atomic_unchecked_t fscache_n_op_gc;
51620 +atomic_unchecked_t fscache_n_op_cancelled;
51621 +atomic_unchecked_t fscache_n_op_rejected;
51622
51623 -atomic_t fscache_n_attr_changed;
51624 -atomic_t fscache_n_attr_changed_ok;
51625 -atomic_t fscache_n_attr_changed_nobufs;
51626 -atomic_t fscache_n_attr_changed_nomem;
51627 -atomic_t fscache_n_attr_changed_calls;
51628 +atomic_unchecked_t fscache_n_attr_changed;
51629 +atomic_unchecked_t fscache_n_attr_changed_ok;
51630 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
51631 +atomic_unchecked_t fscache_n_attr_changed_nomem;
51632 +atomic_unchecked_t fscache_n_attr_changed_calls;
51633
51634 -atomic_t fscache_n_allocs;
51635 -atomic_t fscache_n_allocs_ok;
51636 -atomic_t fscache_n_allocs_wait;
51637 -atomic_t fscache_n_allocs_nobufs;
51638 -atomic_t fscache_n_allocs_intr;
51639 -atomic_t fscache_n_allocs_object_dead;
51640 -atomic_t fscache_n_alloc_ops;
51641 -atomic_t fscache_n_alloc_op_waits;
51642 +atomic_unchecked_t fscache_n_allocs;
51643 +atomic_unchecked_t fscache_n_allocs_ok;
51644 +atomic_unchecked_t fscache_n_allocs_wait;
51645 +atomic_unchecked_t fscache_n_allocs_nobufs;
51646 +atomic_unchecked_t fscache_n_allocs_intr;
51647 +atomic_unchecked_t fscache_n_allocs_object_dead;
51648 +atomic_unchecked_t fscache_n_alloc_ops;
51649 +atomic_unchecked_t fscache_n_alloc_op_waits;
51650
51651 -atomic_t fscache_n_retrievals;
51652 -atomic_t fscache_n_retrievals_ok;
51653 -atomic_t fscache_n_retrievals_wait;
51654 -atomic_t fscache_n_retrievals_nodata;
51655 -atomic_t fscache_n_retrievals_nobufs;
51656 -atomic_t fscache_n_retrievals_intr;
51657 -atomic_t fscache_n_retrievals_nomem;
51658 -atomic_t fscache_n_retrievals_object_dead;
51659 -atomic_t fscache_n_retrieval_ops;
51660 -atomic_t fscache_n_retrieval_op_waits;
51661 +atomic_unchecked_t fscache_n_retrievals;
51662 +atomic_unchecked_t fscache_n_retrievals_ok;
51663 +atomic_unchecked_t fscache_n_retrievals_wait;
51664 +atomic_unchecked_t fscache_n_retrievals_nodata;
51665 +atomic_unchecked_t fscache_n_retrievals_nobufs;
51666 +atomic_unchecked_t fscache_n_retrievals_intr;
51667 +atomic_unchecked_t fscache_n_retrievals_nomem;
51668 +atomic_unchecked_t fscache_n_retrievals_object_dead;
51669 +atomic_unchecked_t fscache_n_retrieval_ops;
51670 +atomic_unchecked_t fscache_n_retrieval_op_waits;
51671
51672 -atomic_t fscache_n_stores;
51673 -atomic_t fscache_n_stores_ok;
51674 -atomic_t fscache_n_stores_again;
51675 -atomic_t fscache_n_stores_nobufs;
51676 -atomic_t fscache_n_stores_oom;
51677 -atomic_t fscache_n_store_ops;
51678 -atomic_t fscache_n_store_calls;
51679 -atomic_t fscache_n_store_pages;
51680 -atomic_t fscache_n_store_radix_deletes;
51681 -atomic_t fscache_n_store_pages_over_limit;
51682 +atomic_unchecked_t fscache_n_stores;
51683 +atomic_unchecked_t fscache_n_stores_ok;
51684 +atomic_unchecked_t fscache_n_stores_again;
51685 +atomic_unchecked_t fscache_n_stores_nobufs;
51686 +atomic_unchecked_t fscache_n_stores_oom;
51687 +atomic_unchecked_t fscache_n_store_ops;
51688 +atomic_unchecked_t fscache_n_store_calls;
51689 +atomic_unchecked_t fscache_n_store_pages;
51690 +atomic_unchecked_t fscache_n_store_radix_deletes;
51691 +atomic_unchecked_t fscache_n_store_pages_over_limit;
51692
51693 -atomic_t fscache_n_store_vmscan_not_storing;
51694 -atomic_t fscache_n_store_vmscan_gone;
51695 -atomic_t fscache_n_store_vmscan_busy;
51696 -atomic_t fscache_n_store_vmscan_cancelled;
51697 -atomic_t fscache_n_store_vmscan_wait;
51698 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51699 +atomic_unchecked_t fscache_n_store_vmscan_gone;
51700 +atomic_unchecked_t fscache_n_store_vmscan_busy;
51701 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51702 +atomic_unchecked_t fscache_n_store_vmscan_wait;
51703
51704 -atomic_t fscache_n_marks;
51705 -atomic_t fscache_n_uncaches;
51706 +atomic_unchecked_t fscache_n_marks;
51707 +atomic_unchecked_t fscache_n_uncaches;
51708
51709 -atomic_t fscache_n_acquires;
51710 -atomic_t fscache_n_acquires_null;
51711 -atomic_t fscache_n_acquires_no_cache;
51712 -atomic_t fscache_n_acquires_ok;
51713 -atomic_t fscache_n_acquires_nobufs;
51714 -atomic_t fscache_n_acquires_oom;
51715 +atomic_unchecked_t fscache_n_acquires;
51716 +atomic_unchecked_t fscache_n_acquires_null;
51717 +atomic_unchecked_t fscache_n_acquires_no_cache;
51718 +atomic_unchecked_t fscache_n_acquires_ok;
51719 +atomic_unchecked_t fscache_n_acquires_nobufs;
51720 +atomic_unchecked_t fscache_n_acquires_oom;
51721
51722 -atomic_t fscache_n_invalidates;
51723 -atomic_t fscache_n_invalidates_run;
51724 +atomic_unchecked_t fscache_n_invalidates;
51725 +atomic_unchecked_t fscache_n_invalidates_run;
51726
51727 -atomic_t fscache_n_updates;
51728 -atomic_t fscache_n_updates_null;
51729 -atomic_t fscache_n_updates_run;
51730 +atomic_unchecked_t fscache_n_updates;
51731 +atomic_unchecked_t fscache_n_updates_null;
51732 +atomic_unchecked_t fscache_n_updates_run;
51733
51734 -atomic_t fscache_n_relinquishes;
51735 -atomic_t fscache_n_relinquishes_null;
51736 -atomic_t fscache_n_relinquishes_waitcrt;
51737 -atomic_t fscache_n_relinquishes_retire;
51738 +atomic_unchecked_t fscache_n_relinquishes;
51739 +atomic_unchecked_t fscache_n_relinquishes_null;
51740 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51741 +atomic_unchecked_t fscache_n_relinquishes_retire;
51742
51743 -atomic_t fscache_n_cookie_index;
51744 -atomic_t fscache_n_cookie_data;
51745 -atomic_t fscache_n_cookie_special;
51746 +atomic_unchecked_t fscache_n_cookie_index;
51747 +atomic_unchecked_t fscache_n_cookie_data;
51748 +atomic_unchecked_t fscache_n_cookie_special;
51749
51750 -atomic_t fscache_n_object_alloc;
51751 -atomic_t fscache_n_object_no_alloc;
51752 -atomic_t fscache_n_object_lookups;
51753 -atomic_t fscache_n_object_lookups_negative;
51754 -atomic_t fscache_n_object_lookups_positive;
51755 -atomic_t fscache_n_object_lookups_timed_out;
51756 -atomic_t fscache_n_object_created;
51757 -atomic_t fscache_n_object_avail;
51758 -atomic_t fscache_n_object_dead;
51759 +atomic_unchecked_t fscache_n_object_alloc;
51760 +atomic_unchecked_t fscache_n_object_no_alloc;
51761 +atomic_unchecked_t fscache_n_object_lookups;
51762 +atomic_unchecked_t fscache_n_object_lookups_negative;
51763 +atomic_unchecked_t fscache_n_object_lookups_positive;
51764 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
51765 +atomic_unchecked_t fscache_n_object_created;
51766 +atomic_unchecked_t fscache_n_object_avail;
51767 +atomic_unchecked_t fscache_n_object_dead;
51768
51769 -atomic_t fscache_n_checkaux_none;
51770 -atomic_t fscache_n_checkaux_okay;
51771 -atomic_t fscache_n_checkaux_update;
51772 -atomic_t fscache_n_checkaux_obsolete;
51773 +atomic_unchecked_t fscache_n_checkaux_none;
51774 +atomic_unchecked_t fscache_n_checkaux_okay;
51775 +atomic_unchecked_t fscache_n_checkaux_update;
51776 +atomic_unchecked_t fscache_n_checkaux_obsolete;
51777
51778 atomic_t fscache_n_cop_alloc_object;
51779 atomic_t fscache_n_cop_lookup_object;
51780 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
51781 seq_puts(m, "FS-Cache statistics\n");
51782
51783 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
51784 - atomic_read(&fscache_n_cookie_index),
51785 - atomic_read(&fscache_n_cookie_data),
51786 - atomic_read(&fscache_n_cookie_special));
51787 + atomic_read_unchecked(&fscache_n_cookie_index),
51788 + atomic_read_unchecked(&fscache_n_cookie_data),
51789 + atomic_read_unchecked(&fscache_n_cookie_special));
51790
51791 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
51792 - atomic_read(&fscache_n_object_alloc),
51793 - atomic_read(&fscache_n_object_no_alloc),
51794 - atomic_read(&fscache_n_object_avail),
51795 - atomic_read(&fscache_n_object_dead));
51796 + atomic_read_unchecked(&fscache_n_object_alloc),
51797 + atomic_read_unchecked(&fscache_n_object_no_alloc),
51798 + atomic_read_unchecked(&fscache_n_object_avail),
51799 + atomic_read_unchecked(&fscache_n_object_dead));
51800 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
51801 - atomic_read(&fscache_n_checkaux_none),
51802 - atomic_read(&fscache_n_checkaux_okay),
51803 - atomic_read(&fscache_n_checkaux_update),
51804 - atomic_read(&fscache_n_checkaux_obsolete));
51805 + atomic_read_unchecked(&fscache_n_checkaux_none),
51806 + atomic_read_unchecked(&fscache_n_checkaux_okay),
51807 + atomic_read_unchecked(&fscache_n_checkaux_update),
51808 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
51809
51810 seq_printf(m, "Pages : mrk=%u unc=%u\n",
51811 - atomic_read(&fscache_n_marks),
51812 - atomic_read(&fscache_n_uncaches));
51813 + atomic_read_unchecked(&fscache_n_marks),
51814 + atomic_read_unchecked(&fscache_n_uncaches));
51815
51816 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
51817 " oom=%u\n",
51818 - atomic_read(&fscache_n_acquires),
51819 - atomic_read(&fscache_n_acquires_null),
51820 - atomic_read(&fscache_n_acquires_no_cache),
51821 - atomic_read(&fscache_n_acquires_ok),
51822 - atomic_read(&fscache_n_acquires_nobufs),
51823 - atomic_read(&fscache_n_acquires_oom));
51824 + atomic_read_unchecked(&fscache_n_acquires),
51825 + atomic_read_unchecked(&fscache_n_acquires_null),
51826 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
51827 + atomic_read_unchecked(&fscache_n_acquires_ok),
51828 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
51829 + atomic_read_unchecked(&fscache_n_acquires_oom));
51830
51831 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
51832 - atomic_read(&fscache_n_object_lookups),
51833 - atomic_read(&fscache_n_object_lookups_negative),
51834 - atomic_read(&fscache_n_object_lookups_positive),
51835 - atomic_read(&fscache_n_object_created),
51836 - atomic_read(&fscache_n_object_lookups_timed_out));
51837 + atomic_read_unchecked(&fscache_n_object_lookups),
51838 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
51839 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
51840 + atomic_read_unchecked(&fscache_n_object_created),
51841 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
51842
51843 seq_printf(m, "Invals : n=%u run=%u\n",
51844 - atomic_read(&fscache_n_invalidates),
51845 - atomic_read(&fscache_n_invalidates_run));
51846 + atomic_read_unchecked(&fscache_n_invalidates),
51847 + atomic_read_unchecked(&fscache_n_invalidates_run));
51848
51849 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
51850 - atomic_read(&fscache_n_updates),
51851 - atomic_read(&fscache_n_updates_null),
51852 - atomic_read(&fscache_n_updates_run));
51853 + atomic_read_unchecked(&fscache_n_updates),
51854 + atomic_read_unchecked(&fscache_n_updates_null),
51855 + atomic_read_unchecked(&fscache_n_updates_run));
51856
51857 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
51858 - atomic_read(&fscache_n_relinquishes),
51859 - atomic_read(&fscache_n_relinquishes_null),
51860 - atomic_read(&fscache_n_relinquishes_waitcrt),
51861 - atomic_read(&fscache_n_relinquishes_retire));
51862 + atomic_read_unchecked(&fscache_n_relinquishes),
51863 + atomic_read_unchecked(&fscache_n_relinquishes_null),
51864 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
51865 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
51866
51867 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
51868 - atomic_read(&fscache_n_attr_changed),
51869 - atomic_read(&fscache_n_attr_changed_ok),
51870 - atomic_read(&fscache_n_attr_changed_nobufs),
51871 - atomic_read(&fscache_n_attr_changed_nomem),
51872 - atomic_read(&fscache_n_attr_changed_calls));
51873 + atomic_read_unchecked(&fscache_n_attr_changed),
51874 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
51875 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
51876 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
51877 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
51878
51879 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
51880 - atomic_read(&fscache_n_allocs),
51881 - atomic_read(&fscache_n_allocs_ok),
51882 - atomic_read(&fscache_n_allocs_wait),
51883 - atomic_read(&fscache_n_allocs_nobufs),
51884 - atomic_read(&fscache_n_allocs_intr));
51885 + atomic_read_unchecked(&fscache_n_allocs),
51886 + atomic_read_unchecked(&fscache_n_allocs_ok),
51887 + atomic_read_unchecked(&fscache_n_allocs_wait),
51888 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
51889 + atomic_read_unchecked(&fscache_n_allocs_intr));
51890 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
51891 - atomic_read(&fscache_n_alloc_ops),
51892 - atomic_read(&fscache_n_alloc_op_waits),
51893 - atomic_read(&fscache_n_allocs_object_dead));
51894 + atomic_read_unchecked(&fscache_n_alloc_ops),
51895 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
51896 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
51897
51898 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
51899 " int=%u oom=%u\n",
51900 - atomic_read(&fscache_n_retrievals),
51901 - atomic_read(&fscache_n_retrievals_ok),
51902 - atomic_read(&fscache_n_retrievals_wait),
51903 - atomic_read(&fscache_n_retrievals_nodata),
51904 - atomic_read(&fscache_n_retrievals_nobufs),
51905 - atomic_read(&fscache_n_retrievals_intr),
51906 - atomic_read(&fscache_n_retrievals_nomem));
51907 + atomic_read_unchecked(&fscache_n_retrievals),
51908 + atomic_read_unchecked(&fscache_n_retrievals_ok),
51909 + atomic_read_unchecked(&fscache_n_retrievals_wait),
51910 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
51911 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
51912 + atomic_read_unchecked(&fscache_n_retrievals_intr),
51913 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
51914 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
51915 - atomic_read(&fscache_n_retrieval_ops),
51916 - atomic_read(&fscache_n_retrieval_op_waits),
51917 - atomic_read(&fscache_n_retrievals_object_dead));
51918 + atomic_read_unchecked(&fscache_n_retrieval_ops),
51919 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
51920 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
51921
51922 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
51923 - atomic_read(&fscache_n_stores),
51924 - atomic_read(&fscache_n_stores_ok),
51925 - atomic_read(&fscache_n_stores_again),
51926 - atomic_read(&fscache_n_stores_nobufs),
51927 - atomic_read(&fscache_n_stores_oom));
51928 + atomic_read_unchecked(&fscache_n_stores),
51929 + atomic_read_unchecked(&fscache_n_stores_ok),
51930 + atomic_read_unchecked(&fscache_n_stores_again),
51931 + atomic_read_unchecked(&fscache_n_stores_nobufs),
51932 + atomic_read_unchecked(&fscache_n_stores_oom));
51933 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
51934 - atomic_read(&fscache_n_store_ops),
51935 - atomic_read(&fscache_n_store_calls),
51936 - atomic_read(&fscache_n_store_pages),
51937 - atomic_read(&fscache_n_store_radix_deletes),
51938 - atomic_read(&fscache_n_store_pages_over_limit));
51939 + atomic_read_unchecked(&fscache_n_store_ops),
51940 + atomic_read_unchecked(&fscache_n_store_calls),
51941 + atomic_read_unchecked(&fscache_n_store_pages),
51942 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
51943 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
51944
51945 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
51946 - atomic_read(&fscache_n_store_vmscan_not_storing),
51947 - atomic_read(&fscache_n_store_vmscan_gone),
51948 - atomic_read(&fscache_n_store_vmscan_busy),
51949 - atomic_read(&fscache_n_store_vmscan_cancelled),
51950 - atomic_read(&fscache_n_store_vmscan_wait));
51951 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
51952 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
51953 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
51954 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
51955 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
51956
51957 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
51958 - atomic_read(&fscache_n_op_pend),
51959 - atomic_read(&fscache_n_op_run),
51960 - atomic_read(&fscache_n_op_enqueue),
51961 - atomic_read(&fscache_n_op_cancelled),
51962 - atomic_read(&fscache_n_op_rejected));
51963 + atomic_read_unchecked(&fscache_n_op_pend),
51964 + atomic_read_unchecked(&fscache_n_op_run),
51965 + atomic_read_unchecked(&fscache_n_op_enqueue),
51966 + atomic_read_unchecked(&fscache_n_op_cancelled),
51967 + atomic_read_unchecked(&fscache_n_op_rejected));
51968 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
51969 - atomic_read(&fscache_n_op_deferred_release),
51970 - atomic_read(&fscache_n_op_release),
51971 - atomic_read(&fscache_n_op_gc));
51972 + atomic_read_unchecked(&fscache_n_op_deferred_release),
51973 + atomic_read_unchecked(&fscache_n_op_release),
51974 + atomic_read_unchecked(&fscache_n_op_gc));
51975
51976 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
51977 atomic_read(&fscache_n_cop_alloc_object),
51978 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
51979 index e397b67..b0d8709 100644
51980 --- a/fs/fuse/cuse.c
51981 +++ b/fs/fuse/cuse.c
51982 @@ -593,10 +593,12 @@ static int __init cuse_init(void)
51983 INIT_LIST_HEAD(&cuse_conntbl[i]);
51984
51985 /* inherit and extend fuse_dev_operations */
51986 - cuse_channel_fops = fuse_dev_operations;
51987 - cuse_channel_fops.owner = THIS_MODULE;
51988 - cuse_channel_fops.open = cuse_channel_open;
51989 - cuse_channel_fops.release = cuse_channel_release;
51990 + pax_open_kernel();
51991 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
51992 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
51993 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
51994 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
51995 + pax_close_kernel();
51996
51997 cuse_class = class_create(THIS_MODULE, "cuse");
51998 if (IS_ERR(cuse_class))
51999 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
52000 index e83351a..41e3c9c 100644
52001 --- a/fs/fuse/dev.c
52002 +++ b/fs/fuse/dev.c
52003 @@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
52004 ret = 0;
52005 pipe_lock(pipe);
52006
52007 - if (!pipe->readers) {
52008 + if (!atomic_read(&pipe->readers)) {
52009 send_sig(SIGPIPE, current, 0);
52010 if (!ret)
52011 ret = -EPIPE;
52012 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
52013 index 315e1f8..91f890c 100644
52014 --- a/fs/fuse/dir.c
52015 +++ b/fs/fuse/dir.c
52016 @@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
52017 return link;
52018 }
52019
52020 -static void free_link(char *link)
52021 +static void free_link(const char *link)
52022 {
52023 if (!IS_ERR(link))
52024 free_page((unsigned long) link);
52025 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
52026 index 2b6f569..fcb4d1f 100644
52027 --- a/fs/gfs2/inode.c
52028 +++ b/fs/gfs2/inode.c
52029 @@ -1499,7 +1499,7 @@ out:
52030
52031 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52032 {
52033 - char *s = nd_get_link(nd);
52034 + const char *s = nd_get_link(nd);
52035 if (!IS_ERR(s))
52036 kfree(s);
52037 }
52038 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
52039 index 78bde32..767e906 100644
52040 --- a/fs/hugetlbfs/inode.c
52041 +++ b/fs/hugetlbfs/inode.c
52042 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52043 struct mm_struct *mm = current->mm;
52044 struct vm_area_struct *vma;
52045 struct hstate *h = hstate_file(file);
52046 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
52047 struct vm_unmapped_area_info info;
52048
52049 if (len & ~huge_page_mask(h))
52050 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52051 return addr;
52052 }
52053
52054 +#ifdef CONFIG_PAX_RANDMMAP
52055 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
52056 +#endif
52057 +
52058 if (addr) {
52059 addr = ALIGN(addr, huge_page_size(h));
52060 vma = find_vma(mm, addr);
52061 - if (TASK_SIZE - len >= addr &&
52062 - (!vma || addr + len <= vma->vm_start))
52063 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
52064 return addr;
52065 }
52066
52067 info.flags = 0;
52068 info.length = len;
52069 info.low_limit = TASK_UNMAPPED_BASE;
52070 +
52071 +#ifdef CONFIG_PAX_RANDMMAP
52072 + if (mm->pax_flags & MF_PAX_RANDMMAP)
52073 + info.low_limit += mm->delta_mmap;
52074 +#endif
52075 +
52076 info.high_limit = TASK_SIZE;
52077 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
52078 info.align_offset = 0;
52079 @@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
52080 .kill_sb = kill_litter_super,
52081 };
52082
52083 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52084 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52085
52086 static int can_do_hugetlb_shm(void)
52087 {
52088 diff --git a/fs/inode.c b/fs/inode.c
52089 index 14084b7..29af1d9 100644
52090 --- a/fs/inode.c
52091 +++ b/fs/inode.c
52092 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
52093
52094 #ifdef CONFIG_SMP
52095 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
52096 - static atomic_t shared_last_ino;
52097 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
52098 + static atomic_unchecked_t shared_last_ino;
52099 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
52100
52101 res = next - LAST_INO_BATCH;
52102 }
52103 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
52104 index 4a6cf28..d3a29d3 100644
52105 --- a/fs/jffs2/erase.c
52106 +++ b/fs/jffs2/erase.c
52107 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
52108 struct jffs2_unknown_node marker = {
52109 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
52110 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52111 - .totlen = cpu_to_je32(c->cleanmarker_size)
52112 + .totlen = cpu_to_je32(c->cleanmarker_size),
52113 + .hdr_crc = cpu_to_je32(0)
52114 };
52115
52116 jffs2_prealloc_raw_node_refs(c, jeb, 1);
52117 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
52118 index a6597d6..41b30ec 100644
52119 --- a/fs/jffs2/wbuf.c
52120 +++ b/fs/jffs2/wbuf.c
52121 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
52122 {
52123 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
52124 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52125 - .totlen = constant_cpu_to_je32(8)
52126 + .totlen = constant_cpu_to_je32(8),
52127 + .hdr_crc = constant_cpu_to_je32(0)
52128 };
52129
52130 /*
52131 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
52132 index 1a543be..a4e1363 100644
52133 --- a/fs/jfs/super.c
52134 +++ b/fs/jfs/super.c
52135 @@ -225,7 +225,7 @@ static const match_table_t tokens = {
52136 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52137 int *flag)
52138 {
52139 - void *nls_map = (void *)-1; /* -1: no change; NULL: none */
52140 + const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
52141 char *p;
52142 struct jfs_sb_info *sbi = JFS_SBI(sb);
52143
52144 @@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52145 /* Don't do anything ;-) */
52146 break;
52147 case Opt_iocharset:
52148 - if (nls_map && nls_map != (void *) -1)
52149 + if (nls_map && nls_map != (const void *) -1)
52150 unload_nls(nls_map);
52151 if (!strcmp(args[0].from, "none"))
52152 nls_map = NULL;
52153 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
52154
52155 jfs_inode_cachep =
52156 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
52157 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
52158 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
52159 init_once);
52160 if (jfs_inode_cachep == NULL)
52161 return -ENOMEM;
52162 diff --git a/fs/libfs.c b/fs/libfs.c
52163 index 916da8c..1588998 100644
52164 --- a/fs/libfs.c
52165 +++ b/fs/libfs.c
52166 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52167
52168 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
52169 struct dentry *next;
52170 + char d_name[sizeof(next->d_iname)];
52171 + const unsigned char *name;
52172 +
52173 next = list_entry(p, struct dentry, d_u.d_child);
52174 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
52175 if (!simple_positive(next)) {
52176 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52177
52178 spin_unlock(&next->d_lock);
52179 spin_unlock(&dentry->d_lock);
52180 - if (filldir(dirent, next->d_name.name,
52181 + name = next->d_name.name;
52182 + if (name == next->d_iname) {
52183 + memcpy(d_name, name, next->d_name.len);
52184 + name = d_name;
52185 + }
52186 + if (filldir(dirent, name,
52187 next->d_name.len, filp->f_pos,
52188 next->d_inode->i_ino,
52189 dt_type(next->d_inode)) < 0)
52190 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
52191 index 52e5120..808936e 100644
52192 --- a/fs/lockd/clntproc.c
52193 +++ b/fs/lockd/clntproc.c
52194 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
52195 /*
52196 * Cookie counter for NLM requests
52197 */
52198 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
52199 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
52200
52201 void nlmclnt_next_cookie(struct nlm_cookie *c)
52202 {
52203 - u32 cookie = atomic_inc_return(&nlm_cookie);
52204 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
52205
52206 memcpy(c->data, &cookie, 4);
52207 c->len=4;
52208 diff --git a/fs/locks.c b/fs/locks.c
52209 index a94e331..060bce3 100644
52210 --- a/fs/locks.c
52211 +++ b/fs/locks.c
52212 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
52213 return;
52214
52215 if (filp->f_op && filp->f_op->flock) {
52216 - struct file_lock fl = {
52217 + struct file_lock flock = {
52218 .fl_pid = current->tgid,
52219 .fl_file = filp,
52220 .fl_flags = FL_FLOCK,
52221 .fl_type = F_UNLCK,
52222 .fl_end = OFFSET_MAX,
52223 };
52224 - filp->f_op->flock(filp, F_SETLKW, &fl);
52225 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
52226 - fl.fl_ops->fl_release_private(&fl);
52227 + filp->f_op->flock(filp, F_SETLKW, &flock);
52228 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
52229 + flock.fl_ops->fl_release_private(&flock);
52230 }
52231
52232 lock_flocks();
52233 diff --git a/fs/namei.c b/fs/namei.c
52234 index 43a97ee..4e585fd 100644
52235 --- a/fs/namei.c
52236 +++ b/fs/namei.c
52237 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
52238 if (ret != -EACCES)
52239 return ret;
52240
52241 +#ifdef CONFIG_GRKERNSEC
52242 + /* we'll block if we have to log due to a denied capability use */
52243 + if (mask & MAY_NOT_BLOCK)
52244 + return -ECHILD;
52245 +#endif
52246 +
52247 if (S_ISDIR(inode->i_mode)) {
52248 /* DACs are overridable for directories */
52249 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
52250 - return 0;
52251 if (!(mask & MAY_WRITE))
52252 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52253 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52254 + inode_capable(inode, CAP_DAC_READ_SEARCH))
52255 return 0;
52256 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
52257 + return 0;
52258 return -EACCES;
52259 }
52260 /*
52261 + * Searching includes executable on directories, else just read.
52262 + */
52263 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52264 + if (mask == MAY_READ)
52265 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52266 + inode_capable(inode, CAP_DAC_READ_SEARCH))
52267 + return 0;
52268 +
52269 + /*
52270 * Read/write DACs are always overridable.
52271 * Executable DACs are overridable when there is
52272 * at least one exec bit set.
52273 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
52274 if (inode_capable(inode, CAP_DAC_OVERRIDE))
52275 return 0;
52276
52277 - /*
52278 - * Searching includes executable on directories, else just read.
52279 - */
52280 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52281 - if (mask == MAY_READ)
52282 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52283 - return 0;
52284 -
52285 return -EACCES;
52286 }
52287
52288 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52289 {
52290 struct dentry *dentry = link->dentry;
52291 int error;
52292 - char *s;
52293 + const char *s;
52294
52295 BUG_ON(nd->flags & LOOKUP_RCU);
52296
52297 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52298 if (error)
52299 goto out_put_nd_path;
52300
52301 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
52302 + dentry->d_inode, dentry, nd->path.mnt)) {
52303 + error = -EACCES;
52304 + goto out_put_nd_path;
52305 + }
52306 +
52307 nd->last_type = LAST_BIND;
52308 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
52309 error = PTR_ERR(*p);
52310 @@ -1596,6 +1610,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
52311 break;
52312 res = walk_component(nd, path, &nd->last,
52313 nd->last_type, LOOKUP_FOLLOW);
52314 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
52315 + res = -EACCES;
52316 put_link(nd, &link, cookie);
52317 } while (res > 0);
52318
52319 @@ -1694,7 +1710,7 @@ EXPORT_SYMBOL(full_name_hash);
52320 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
52321 {
52322 unsigned long a, b, adata, bdata, mask, hash, len;
52323 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52324 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52325
52326 hash = a = 0;
52327 len = -sizeof(unsigned long);
52328 @@ -1979,6 +1995,8 @@ static int path_lookupat(int dfd, const char *name,
52329 if (err)
52330 break;
52331 err = lookup_last(nd, &path);
52332 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
52333 + err = -EACCES;
52334 put_link(nd, &link, cookie);
52335 }
52336 }
52337 @@ -1986,6 +2004,19 @@ static int path_lookupat(int dfd, const char *name,
52338 if (!err)
52339 err = complete_walk(nd);
52340
52341 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
52342 +#ifdef CONFIG_GRKERNSEC
52343 + if (flags & LOOKUP_RCU) {
52344 + path_put(&nd->path);
52345 + err = -ECHILD;
52346 + } else
52347 +#endif
52348 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52349 + path_put(&nd->path);
52350 + err = -ENOENT;
52351 + }
52352 + }
52353 +
52354 if (!err && nd->flags & LOOKUP_DIRECTORY) {
52355 if (!nd->inode->i_op->lookup) {
52356 path_put(&nd->path);
52357 @@ -2013,8 +2044,17 @@ static int filename_lookup(int dfd, struct filename *name,
52358 retval = path_lookupat(dfd, name->name,
52359 flags | LOOKUP_REVAL, nd);
52360
52361 - if (likely(!retval))
52362 + if (likely(!retval)) {
52363 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
52364 +#ifdef CONFIG_GRKERNSEC
52365 + if (flags & LOOKUP_RCU)
52366 + return -ECHILD;
52367 +#endif
52368 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
52369 + return -ENOENT;
52370 + }
52371 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
52372 + }
52373 return retval;
52374 }
52375
52376 @@ -2392,6 +2432,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
52377 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
52378 return -EPERM;
52379
52380 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
52381 + return -EPERM;
52382 + if (gr_handle_rawio(inode))
52383 + return -EPERM;
52384 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
52385 + return -EACCES;
52386 +
52387 return 0;
52388 }
52389
52390 @@ -2613,7 +2660,7 @@ looked_up:
52391 * cleared otherwise prior to returning.
52392 */
52393 static int lookup_open(struct nameidata *nd, struct path *path,
52394 - struct file *file,
52395 + struct path *link, struct file *file,
52396 const struct open_flags *op,
52397 bool got_write, int *opened)
52398 {
52399 @@ -2648,6 +2695,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52400 /* Negative dentry, just create the file */
52401 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
52402 umode_t mode = op->mode;
52403 +
52404 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
52405 + error = -EACCES;
52406 + goto out_dput;
52407 + }
52408 +
52409 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
52410 + error = -EACCES;
52411 + goto out_dput;
52412 + }
52413 +
52414 if (!IS_POSIXACL(dir->d_inode))
52415 mode &= ~current_umask();
52416 /*
52417 @@ -2669,6 +2727,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52418 nd->flags & LOOKUP_EXCL);
52419 if (error)
52420 goto out_dput;
52421 + else
52422 + gr_handle_create(dentry, nd->path.mnt);
52423 }
52424 out_no_open:
52425 path->dentry = dentry;
52426 @@ -2683,7 +2743,7 @@ out_dput:
52427 /*
52428 * Handle the last step of open()
52429 */
52430 -static int do_last(struct nameidata *nd, struct path *path,
52431 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
52432 struct file *file, const struct open_flags *op,
52433 int *opened, struct filename *name)
52434 {
52435 @@ -2712,16 +2772,44 @@ static int do_last(struct nameidata *nd, struct path *path,
52436 error = complete_walk(nd);
52437 if (error)
52438 return error;
52439 +#ifdef CONFIG_GRKERNSEC
52440 + if (nd->flags & LOOKUP_RCU) {
52441 + error = -ECHILD;
52442 + goto out;
52443 + }
52444 +#endif
52445 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52446 + error = -ENOENT;
52447 + goto out;
52448 + }
52449 audit_inode(name, nd->path.dentry, 0);
52450 if (open_flag & O_CREAT) {
52451 error = -EISDIR;
52452 goto out;
52453 }
52454 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
52455 + error = -EACCES;
52456 + goto out;
52457 + }
52458 goto finish_open;
52459 case LAST_BIND:
52460 error = complete_walk(nd);
52461 if (error)
52462 return error;
52463 +#ifdef CONFIG_GRKERNSEC
52464 + if (nd->flags & LOOKUP_RCU) {
52465 + error = -ECHILD;
52466 + goto out;
52467 + }
52468 +#endif
52469 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
52470 + error = -ENOENT;
52471 + goto out;
52472 + }
52473 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
52474 + error = -EACCES;
52475 + goto out;
52476 + }
52477 audit_inode(name, dir, 0);
52478 goto finish_open;
52479 }
52480 @@ -2770,7 +2858,7 @@ retry_lookup:
52481 */
52482 }
52483 mutex_lock(&dir->d_inode->i_mutex);
52484 - error = lookup_open(nd, path, file, op, got_write, opened);
52485 + error = lookup_open(nd, path, link, file, op, got_write, opened);
52486 mutex_unlock(&dir->d_inode->i_mutex);
52487
52488 if (error <= 0) {
52489 @@ -2794,11 +2882,28 @@ retry_lookup:
52490 goto finish_open_created;
52491 }
52492
52493 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
52494 + error = -ENOENT;
52495 + goto exit_dput;
52496 + }
52497 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
52498 + error = -EACCES;
52499 + goto exit_dput;
52500 + }
52501 +
52502 /*
52503 * create/update audit record if it already exists.
52504 */
52505 - if (path->dentry->d_inode)
52506 + if (path->dentry->d_inode) {
52507 + /* only check if O_CREAT is specified, all other checks need to go
52508 + into may_open */
52509 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
52510 + error = -EACCES;
52511 + goto exit_dput;
52512 + }
52513 +
52514 audit_inode(name, path->dentry, 0);
52515 + }
52516
52517 /*
52518 * If atomic_open() acquired write access it is dropped now due to
52519 @@ -2839,6 +2944,11 @@ finish_lookup:
52520 }
52521 }
52522 BUG_ON(inode != path->dentry->d_inode);
52523 + /* if we're resolving a symlink to another symlink */
52524 + if (link && gr_handle_symlink_owner(link, inode)) {
52525 + error = -EACCES;
52526 + goto out;
52527 + }
52528 return 1;
52529 }
52530
52531 @@ -2848,7 +2958,6 @@ finish_lookup:
52532 save_parent.dentry = nd->path.dentry;
52533 save_parent.mnt = mntget(path->mnt);
52534 nd->path.dentry = path->dentry;
52535 -
52536 }
52537 nd->inode = inode;
52538 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
52539 @@ -2857,6 +2966,22 @@ finish_lookup:
52540 path_put(&save_parent);
52541 return error;
52542 }
52543 +
52544 +#ifdef CONFIG_GRKERNSEC
52545 + if (nd->flags & LOOKUP_RCU) {
52546 + error = -ECHILD;
52547 + goto out;
52548 + }
52549 +#endif
52550 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52551 + error = -ENOENT;
52552 + goto out;
52553 + }
52554 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
52555 + error = -EACCES;
52556 + goto out;
52557 + }
52558 +
52559 error = -EISDIR;
52560 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
52561 goto out;
52562 @@ -2955,7 +3080,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
52563 if (unlikely(error))
52564 goto out;
52565
52566 - error = do_last(nd, &path, file, op, &opened, pathname);
52567 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
52568 while (unlikely(error > 0)) { /* trailing symlink */
52569 struct path link = path;
52570 void *cookie;
52571 @@ -2973,7 +3098,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
52572 error = follow_link(&link, nd, &cookie);
52573 if (unlikely(error))
52574 break;
52575 - error = do_last(nd, &path, file, op, &opened, pathname);
52576 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
52577 put_link(nd, &link, cookie);
52578 }
52579 out:
52580 @@ -3073,8 +3198,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
52581 goto unlock;
52582
52583 error = -EEXIST;
52584 - if (dentry->d_inode)
52585 + if (dentry->d_inode) {
52586 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
52587 + error = -ENOENT;
52588 + }
52589 goto fail;
52590 + }
52591 /*
52592 * Special case - lookup gave negative, but... we had foo/bar/
52593 * From the vfs_mknod() POV we just have a negative dentry -
52594 @@ -3126,6 +3255,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
52595 }
52596 EXPORT_SYMBOL(user_path_create);
52597
52598 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
52599 +{
52600 + struct filename *tmp = getname(pathname);
52601 + struct dentry *res;
52602 + if (IS_ERR(tmp))
52603 + return ERR_CAST(tmp);
52604 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
52605 + if (IS_ERR(res))
52606 + putname(tmp);
52607 + else
52608 + *to = tmp;
52609 + return res;
52610 +}
52611 +
52612 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
52613 {
52614 int error = may_create(dir, dentry);
52615 @@ -3188,6 +3331,17 @@ retry:
52616
52617 if (!IS_POSIXACL(path.dentry->d_inode))
52618 mode &= ~current_umask();
52619 +
52620 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
52621 + error = -EPERM;
52622 + goto out;
52623 + }
52624 +
52625 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
52626 + error = -EACCES;
52627 + goto out;
52628 + }
52629 +
52630 error = security_path_mknod(&path, dentry, mode, dev);
52631 if (error)
52632 goto out;
52633 @@ -3204,6 +3358,8 @@ retry:
52634 break;
52635 }
52636 out:
52637 + if (!error)
52638 + gr_handle_create(dentry, path.mnt);
52639 done_path_create(&path, dentry);
52640 if (retry_estale(error, lookup_flags)) {
52641 lookup_flags |= LOOKUP_REVAL;
52642 @@ -3256,9 +3412,16 @@ retry:
52643
52644 if (!IS_POSIXACL(path.dentry->d_inode))
52645 mode &= ~current_umask();
52646 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
52647 + error = -EACCES;
52648 + goto out;
52649 + }
52650 error = security_path_mkdir(&path, dentry, mode);
52651 if (!error)
52652 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
52653 + if (!error)
52654 + gr_handle_create(dentry, path.mnt);
52655 +out:
52656 done_path_create(&path, dentry);
52657 if (retry_estale(error, lookup_flags)) {
52658 lookup_flags |= LOOKUP_REVAL;
52659 @@ -3339,6 +3502,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
52660 struct filename *name;
52661 struct dentry *dentry;
52662 struct nameidata nd;
52663 + ino_t saved_ino = 0;
52664 + dev_t saved_dev = 0;
52665 unsigned int lookup_flags = 0;
52666 retry:
52667 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
52668 @@ -3371,10 +3536,21 @@ retry:
52669 error = -ENOENT;
52670 goto exit3;
52671 }
52672 +
52673 + saved_ino = dentry->d_inode->i_ino;
52674 + saved_dev = gr_get_dev_from_dentry(dentry);
52675 +
52676 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
52677 + error = -EACCES;
52678 + goto exit3;
52679 + }
52680 +
52681 error = security_path_rmdir(&nd.path, dentry);
52682 if (error)
52683 goto exit3;
52684 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
52685 + if (!error && (saved_dev || saved_ino))
52686 + gr_handle_delete(saved_ino, saved_dev);
52687 exit3:
52688 dput(dentry);
52689 exit2:
52690 @@ -3440,6 +3616,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
52691 struct dentry *dentry;
52692 struct nameidata nd;
52693 struct inode *inode = NULL;
52694 + ino_t saved_ino = 0;
52695 + dev_t saved_dev = 0;
52696 unsigned int lookup_flags = 0;
52697 retry:
52698 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
52699 @@ -3466,10 +3644,22 @@ retry:
52700 if (!inode)
52701 goto slashes;
52702 ihold(inode);
52703 +
52704 + if (inode->i_nlink <= 1) {
52705 + saved_ino = inode->i_ino;
52706 + saved_dev = gr_get_dev_from_dentry(dentry);
52707 + }
52708 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
52709 + error = -EACCES;
52710 + goto exit2;
52711 + }
52712 +
52713 error = security_path_unlink(&nd.path, dentry);
52714 if (error)
52715 goto exit2;
52716 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
52717 + if (!error && (saved_ino || saved_dev))
52718 + gr_handle_delete(saved_ino, saved_dev);
52719 exit2:
52720 dput(dentry);
52721 }
52722 @@ -3547,9 +3737,17 @@ retry:
52723 if (IS_ERR(dentry))
52724 goto out_putname;
52725
52726 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
52727 + error = -EACCES;
52728 + goto out;
52729 + }
52730 +
52731 error = security_path_symlink(&path, dentry, from->name);
52732 if (!error)
52733 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
52734 + if (!error)
52735 + gr_handle_create(dentry, path.mnt);
52736 +out:
52737 done_path_create(&path, dentry);
52738 if (retry_estale(error, lookup_flags)) {
52739 lookup_flags |= LOOKUP_REVAL;
52740 @@ -3623,6 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
52741 {
52742 struct dentry *new_dentry;
52743 struct path old_path, new_path;
52744 + struct filename *to = NULL;
52745 int how = 0;
52746 int error;
52747
52748 @@ -3646,7 +3845,7 @@ retry:
52749 if (error)
52750 return error;
52751
52752 - new_dentry = user_path_create(newdfd, newname, &new_path,
52753 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
52754 (how & LOOKUP_REVAL));
52755 error = PTR_ERR(new_dentry);
52756 if (IS_ERR(new_dentry))
52757 @@ -3658,11 +3857,28 @@ retry:
52758 error = may_linkat(&old_path);
52759 if (unlikely(error))
52760 goto out_dput;
52761 +
52762 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
52763 + old_path.dentry->d_inode,
52764 + old_path.dentry->d_inode->i_mode, to)) {
52765 + error = -EACCES;
52766 + goto out_dput;
52767 + }
52768 +
52769 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
52770 + old_path.dentry, old_path.mnt, to)) {
52771 + error = -EACCES;
52772 + goto out_dput;
52773 + }
52774 +
52775 error = security_path_link(old_path.dentry, &new_path, new_dentry);
52776 if (error)
52777 goto out_dput;
52778 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
52779 + if (!error)
52780 + gr_handle_create(new_dentry, new_path.mnt);
52781 out_dput:
52782 + putname(to);
52783 done_path_create(&new_path, new_dentry);
52784 if (retry_estale(error, how)) {
52785 how |= LOOKUP_REVAL;
52786 @@ -3908,12 +4124,21 @@ retry:
52787 if (new_dentry == trap)
52788 goto exit5;
52789
52790 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
52791 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
52792 + to);
52793 + if (error)
52794 + goto exit5;
52795 +
52796 error = security_path_rename(&oldnd.path, old_dentry,
52797 &newnd.path, new_dentry);
52798 if (error)
52799 goto exit5;
52800 error = vfs_rename(old_dir->d_inode, old_dentry,
52801 new_dir->d_inode, new_dentry);
52802 + if (!error)
52803 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
52804 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
52805 exit5:
52806 dput(new_dentry);
52807 exit4:
52808 @@ -3945,6 +4170,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
52809
52810 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
52811 {
52812 + char tmpbuf[64];
52813 + const char *newlink;
52814 int len;
52815
52816 len = PTR_ERR(link);
52817 @@ -3954,7 +4181,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
52818 len = strlen(link);
52819 if (len > (unsigned) buflen)
52820 len = buflen;
52821 - if (copy_to_user(buffer, link, len))
52822 +
52823 + if (len < sizeof(tmpbuf)) {
52824 + memcpy(tmpbuf, link, len);
52825 + newlink = tmpbuf;
52826 + } else
52827 + newlink = link;
52828 +
52829 + if (copy_to_user(buffer, newlink, len))
52830 len = -EFAULT;
52831 out:
52832 return len;
52833 diff --git a/fs/namespace.c b/fs/namespace.c
52834 index a51054f..f9b53e5 100644
52835 --- a/fs/namespace.c
52836 +++ b/fs/namespace.c
52837 @@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
52838 if (!(sb->s_flags & MS_RDONLY))
52839 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
52840 up_write(&sb->s_umount);
52841 +
52842 + gr_log_remount(mnt->mnt_devname, retval);
52843 +
52844 return retval;
52845 }
52846
52847 @@ -1234,6 +1237,9 @@ static int do_umount(struct mount *mnt, int flags)
52848 br_write_unlock(&vfsmount_lock);
52849 up_write(&namespace_sem);
52850 release_mounts(&umount_list);
52851 +
52852 + gr_log_unmount(mnt->mnt_devname, retval);
52853 +
52854 return retval;
52855 }
52856
52857 @@ -2287,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
52858 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
52859 MS_STRICTATIME);
52860
52861 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
52862 + retval = -EPERM;
52863 + goto dput_out;
52864 + }
52865 +
52866 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
52867 + retval = -EPERM;
52868 + goto dput_out;
52869 + }
52870 +
52871 if (flags & MS_REMOUNT)
52872 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
52873 data_page);
52874 @@ -2301,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
52875 dev_name, data_page);
52876 dput_out:
52877 path_put(&path);
52878 +
52879 + gr_log_mount(dev_name, dir_name, retval);
52880 +
52881 return retval;
52882 }
52883
52884 @@ -2587,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
52885 if (error)
52886 goto out2;
52887
52888 + if (gr_handle_chroot_pivot()) {
52889 + error = -EPERM;
52890 + goto out2;
52891 + }
52892 +
52893 get_fs_root(current->fs, &root);
52894 error = lock_mount(&old);
52895 if (error)
52896 @@ -2790,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
52897 !nsown_capable(CAP_SYS_ADMIN))
52898 return -EPERM;
52899
52900 - if (fs->users != 1)
52901 + if (atomic_read(&fs->users) != 1)
52902 return -EINVAL;
52903
52904 get_mnt_ns(mnt_ns);
52905 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
52906 index 59461c9..b17c57e 100644
52907 --- a/fs/nfs/callback_xdr.c
52908 +++ b/fs/nfs/callback_xdr.c
52909 @@ -51,7 +51,7 @@ struct callback_op {
52910 callback_decode_arg_t decode_args;
52911 callback_encode_res_t encode_res;
52912 long res_maxsize;
52913 -};
52914 +} __do_const;
52915
52916 static struct callback_op callback_ops[];
52917
52918 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
52919 index ebeb94c..ff35337 100644
52920 --- a/fs/nfs/inode.c
52921 +++ b/fs/nfs/inode.c
52922 @@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
52923 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
52924 }
52925
52926 -static atomic_long_t nfs_attr_generation_counter;
52927 +static atomic_long_unchecked_t nfs_attr_generation_counter;
52928
52929 static unsigned long nfs_read_attr_generation_counter(void)
52930 {
52931 - return atomic_long_read(&nfs_attr_generation_counter);
52932 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
52933 }
52934
52935 unsigned long nfs_inc_attr_generation_counter(void)
52936 {
52937 - return atomic_long_inc_return(&nfs_attr_generation_counter);
52938 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
52939 }
52940
52941 void nfs_fattr_init(struct nfs_fattr *fattr)
52942 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
52943 index 9d1c5db..1e13db8 100644
52944 --- a/fs/nfsd/nfs4proc.c
52945 +++ b/fs/nfsd/nfs4proc.c
52946 @@ -1097,7 +1097,7 @@ struct nfsd4_operation {
52947 nfsd4op_rsize op_rsize_bop;
52948 stateid_getter op_get_currentstateid;
52949 stateid_setter op_set_currentstateid;
52950 -};
52951 +} __do_const;
52952
52953 static struct nfsd4_operation nfsd4_ops[];
52954
52955 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
52956 index 0dc1158..ccf0338 100644
52957 --- a/fs/nfsd/nfs4xdr.c
52958 +++ b/fs/nfsd/nfs4xdr.c
52959 @@ -1456,7 +1456,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
52960
52961 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
52962
52963 -static nfsd4_dec nfsd4_dec_ops[] = {
52964 +static const nfsd4_dec nfsd4_dec_ops[] = {
52965 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
52966 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
52967 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
52968 @@ -1496,7 +1496,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
52969 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
52970 };
52971
52972 -static nfsd4_dec nfsd41_dec_ops[] = {
52973 +static const nfsd4_dec nfsd41_dec_ops[] = {
52974 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
52975 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
52976 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
52977 @@ -1558,7 +1558,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
52978 };
52979
52980 struct nfsd4_minorversion_ops {
52981 - nfsd4_dec *decoders;
52982 + const nfsd4_dec *decoders;
52983 int nops;
52984 };
52985
52986 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
52987 index d586117..143d568 100644
52988 --- a/fs/nfsd/vfs.c
52989 +++ b/fs/nfsd/vfs.c
52990 @@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
52991 } else {
52992 oldfs = get_fs();
52993 set_fs(KERNEL_DS);
52994 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
52995 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
52996 set_fs(oldfs);
52997 }
52998
52999 @@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53000
53001 /* Write the data. */
53002 oldfs = get_fs(); set_fs(KERNEL_DS);
53003 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
53004 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
53005 set_fs(oldfs);
53006 if (host_err < 0)
53007 goto out_nfserr;
53008 @@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
53009 */
53010
53011 oldfs = get_fs(); set_fs(KERNEL_DS);
53012 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
53013 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
53014 set_fs(oldfs);
53015
53016 if (host_err < 0)
53017 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
53018 index fea6bd5..8ee9d81 100644
53019 --- a/fs/nls/nls_base.c
53020 +++ b/fs/nls/nls_base.c
53021 @@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
53022
53023 int register_nls(struct nls_table * nls)
53024 {
53025 - struct nls_table ** tmp = &tables;
53026 + struct nls_table *tmp = tables;
53027
53028 if (nls->next)
53029 return -EBUSY;
53030
53031 spin_lock(&nls_lock);
53032 - while (*tmp) {
53033 - if (nls == *tmp) {
53034 + while (tmp) {
53035 + if (nls == tmp) {
53036 spin_unlock(&nls_lock);
53037 return -EBUSY;
53038 }
53039 - tmp = &(*tmp)->next;
53040 + tmp = tmp->next;
53041 }
53042 - nls->next = tables;
53043 + pax_open_kernel();
53044 + *(struct nls_table **)&nls->next = tables;
53045 + pax_close_kernel();
53046 tables = nls;
53047 spin_unlock(&nls_lock);
53048 return 0;
53049 @@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
53050
53051 int unregister_nls(struct nls_table * nls)
53052 {
53053 - struct nls_table ** tmp = &tables;
53054 + struct nls_table * const * tmp = &tables;
53055
53056 spin_lock(&nls_lock);
53057 while (*tmp) {
53058 if (nls == *tmp) {
53059 - *tmp = nls->next;
53060 + pax_open_kernel();
53061 + *(struct nls_table **)tmp = nls->next;
53062 + pax_close_kernel();
53063 spin_unlock(&nls_lock);
53064 return 0;
53065 }
53066 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
53067 index 7424929..35f6be5 100644
53068 --- a/fs/nls/nls_euc-jp.c
53069 +++ b/fs/nls/nls_euc-jp.c
53070 @@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
53071 p_nls = load_nls("cp932");
53072
53073 if (p_nls) {
53074 - table.charset2upper = p_nls->charset2upper;
53075 - table.charset2lower = p_nls->charset2lower;
53076 + pax_open_kernel();
53077 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53078 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53079 + pax_close_kernel();
53080 return register_nls(&table);
53081 }
53082
53083 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
53084 index e7bc1d7..06bd4bb 100644
53085 --- a/fs/nls/nls_koi8-ru.c
53086 +++ b/fs/nls/nls_koi8-ru.c
53087 @@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
53088 p_nls = load_nls("koi8-u");
53089
53090 if (p_nls) {
53091 - table.charset2upper = p_nls->charset2upper;
53092 - table.charset2lower = p_nls->charset2lower;
53093 + pax_open_kernel();
53094 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53095 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53096 + pax_close_kernel();
53097 return register_nls(&table);
53098 }
53099
53100 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
53101 index 9ff4a5e..deb1f0f 100644
53102 --- a/fs/notify/fanotify/fanotify_user.c
53103 +++ b/fs/notify/fanotify/fanotify_user.c
53104 @@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
53105
53106 fd = fanotify_event_metadata.fd;
53107 ret = -EFAULT;
53108 - if (copy_to_user(buf, &fanotify_event_metadata,
53109 - fanotify_event_metadata.event_len))
53110 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
53111 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
53112 goto out_close_fd;
53113
53114 ret = prepare_for_access_response(group, event, fd);
53115 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
53116 index 7b51b05..5ea5ef6 100644
53117 --- a/fs/notify/notification.c
53118 +++ b/fs/notify/notification.c
53119 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
53120 * get set to 0 so it will never get 'freed'
53121 */
53122 static struct fsnotify_event *q_overflow_event;
53123 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53124 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53125
53126 /**
53127 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
53128 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53129 */
53130 u32 fsnotify_get_cookie(void)
53131 {
53132 - return atomic_inc_return(&fsnotify_sync_cookie);
53133 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
53134 }
53135 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
53136
53137 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
53138 index 99e3610..02c1068 100644
53139 --- a/fs/ntfs/dir.c
53140 +++ b/fs/ntfs/dir.c
53141 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
53142 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
53143 ~(s64)(ndir->itype.index.block_size - 1)));
53144 /* Bounds checks. */
53145 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53146 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53147 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
53148 "inode 0x%lx or driver bug.", vdir->i_ino);
53149 goto err_out;
53150 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
53151 index 5b2d4f0..c6de396 100644
53152 --- a/fs/ntfs/file.c
53153 +++ b/fs/ntfs/file.c
53154 @@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
53155 #endif /* NTFS_RW */
53156 };
53157
53158 -const struct file_operations ntfs_empty_file_ops = {};
53159 +const struct file_operations ntfs_empty_file_ops __read_only;
53160
53161 -const struct inode_operations ntfs_empty_inode_ops = {};
53162 +const struct inode_operations ntfs_empty_inode_ops __read_only;
53163 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
53164 index a9f78c7..ed8a381 100644
53165 --- a/fs/ocfs2/localalloc.c
53166 +++ b/fs/ocfs2/localalloc.c
53167 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
53168 goto bail;
53169 }
53170
53171 - atomic_inc(&osb->alloc_stats.moves);
53172 + atomic_inc_unchecked(&osb->alloc_stats.moves);
53173
53174 bail:
53175 if (handle)
53176 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
53177 index d355e6e..578d905 100644
53178 --- a/fs/ocfs2/ocfs2.h
53179 +++ b/fs/ocfs2/ocfs2.h
53180 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
53181
53182 struct ocfs2_alloc_stats
53183 {
53184 - atomic_t moves;
53185 - atomic_t local_data;
53186 - atomic_t bitmap_data;
53187 - atomic_t bg_allocs;
53188 - atomic_t bg_extends;
53189 + atomic_unchecked_t moves;
53190 + atomic_unchecked_t local_data;
53191 + atomic_unchecked_t bitmap_data;
53192 + atomic_unchecked_t bg_allocs;
53193 + atomic_unchecked_t bg_extends;
53194 };
53195
53196 enum ocfs2_local_alloc_state
53197 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
53198 index b7e74b5..19c6536 100644
53199 --- a/fs/ocfs2/suballoc.c
53200 +++ b/fs/ocfs2/suballoc.c
53201 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
53202 mlog_errno(status);
53203 goto bail;
53204 }
53205 - atomic_inc(&osb->alloc_stats.bg_extends);
53206 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
53207
53208 /* You should never ask for this much metadata */
53209 BUG_ON(bits_wanted >
53210 @@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
53211 mlog_errno(status);
53212 goto bail;
53213 }
53214 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53215 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53216
53217 *suballoc_loc = res.sr_bg_blkno;
53218 *suballoc_bit_start = res.sr_bit_offset;
53219 @@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
53220 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
53221 res->sr_bits);
53222
53223 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53224 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53225
53226 BUG_ON(res->sr_bits != 1);
53227
53228 @@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
53229 mlog_errno(status);
53230 goto bail;
53231 }
53232 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53233 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53234
53235 BUG_ON(res.sr_bits != 1);
53236
53237 @@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53238 cluster_start,
53239 num_clusters);
53240 if (!status)
53241 - atomic_inc(&osb->alloc_stats.local_data);
53242 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
53243 } else {
53244 if (min_clusters > (osb->bitmap_cpg - 1)) {
53245 /* The only paths asking for contiguousness
53246 @@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53247 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
53248 res.sr_bg_blkno,
53249 res.sr_bit_offset);
53250 - atomic_inc(&osb->alloc_stats.bitmap_data);
53251 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
53252 *num_clusters = res.sr_bits;
53253 }
53254 }
53255 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
53256 index 0e91ec2..f4b3fc6 100644
53257 --- a/fs/ocfs2/super.c
53258 +++ b/fs/ocfs2/super.c
53259 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
53260 "%10s => GlobalAllocs: %d LocalAllocs: %d "
53261 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
53262 "Stats",
53263 - atomic_read(&osb->alloc_stats.bitmap_data),
53264 - atomic_read(&osb->alloc_stats.local_data),
53265 - atomic_read(&osb->alloc_stats.bg_allocs),
53266 - atomic_read(&osb->alloc_stats.moves),
53267 - atomic_read(&osb->alloc_stats.bg_extends));
53268 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
53269 + atomic_read_unchecked(&osb->alloc_stats.local_data),
53270 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
53271 + atomic_read_unchecked(&osb->alloc_stats.moves),
53272 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
53273
53274 out += snprintf(buf + out, len - out,
53275 "%10s => State: %u Descriptor: %llu Size: %u bits "
53276 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
53277 spin_lock_init(&osb->osb_xattr_lock);
53278 ocfs2_init_steal_slots(osb);
53279
53280 - atomic_set(&osb->alloc_stats.moves, 0);
53281 - atomic_set(&osb->alloc_stats.local_data, 0);
53282 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
53283 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
53284 - atomic_set(&osb->alloc_stats.bg_extends, 0);
53285 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
53286 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
53287 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
53288 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
53289 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
53290
53291 /* Copy the blockcheck stats from the superblock probe */
53292 osb->osb_ecc_stats = *stats;
53293 diff --git a/fs/open.c b/fs/open.c
53294 index 9b33c0c..2ffcca2 100644
53295 --- a/fs/open.c
53296 +++ b/fs/open.c
53297 @@ -31,6 +31,8 @@
53298 #include <linux/ima.h>
53299 #include <linux/dnotify.h>
53300
53301 +#define CREATE_TRACE_POINTS
53302 +#include <trace/events/fs.h>
53303 #include "internal.h"
53304
53305 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
53306 @@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
53307 error = locks_verify_truncate(inode, NULL, length);
53308 if (!error)
53309 error = security_path_truncate(path);
53310 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
53311 + error = -EACCES;
53312 if (!error)
53313 error = do_truncate(path->dentry, length, 0, NULL);
53314
53315 @@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
53316 error = locks_verify_truncate(inode, f.file, length);
53317 if (!error)
53318 error = security_path_truncate(&f.file->f_path);
53319 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
53320 + error = -EACCES;
53321 if (!error)
53322 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
53323 sb_end_write(inode->i_sb);
53324 @@ -373,6 +379,9 @@ retry:
53325 if (__mnt_is_readonly(path.mnt))
53326 res = -EROFS;
53327
53328 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
53329 + res = -EACCES;
53330 +
53331 out_path_release:
53332 path_put(&path);
53333 if (retry_estale(res, lookup_flags)) {
53334 @@ -404,6 +413,8 @@ retry:
53335 if (error)
53336 goto dput_and_out;
53337
53338 + gr_log_chdir(path.dentry, path.mnt);
53339 +
53340 set_fs_pwd(current->fs, &path);
53341
53342 dput_and_out:
53343 @@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
53344 goto out_putf;
53345
53346 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
53347 +
53348 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
53349 + error = -EPERM;
53350 +
53351 + if (!error)
53352 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
53353 +
53354 if (!error)
53355 set_fs_pwd(current->fs, &f.file->f_path);
53356 out_putf:
53357 @@ -462,7 +480,13 @@ retry:
53358 if (error)
53359 goto dput_and_out;
53360
53361 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
53362 + goto dput_and_out;
53363 +
53364 set_fs_root(current->fs, &path);
53365 +
53366 + gr_handle_chroot_chdir(&path);
53367 +
53368 error = 0;
53369 dput_and_out:
53370 path_put(&path);
53371 @@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
53372 if (error)
53373 return error;
53374 mutex_lock(&inode->i_mutex);
53375 +
53376 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
53377 + error = -EACCES;
53378 + goto out_unlock;
53379 + }
53380 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
53381 + error = -EACCES;
53382 + goto out_unlock;
53383 + }
53384 +
53385 error = security_path_chmod(path, mode);
53386 if (error)
53387 goto out_unlock;
53388 @@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
53389 uid = make_kuid(current_user_ns(), user);
53390 gid = make_kgid(current_user_ns(), group);
53391
53392 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
53393 + return -EACCES;
53394 +
53395 newattrs.ia_valid = ATTR_CTIME;
53396 if (user != (uid_t) -1) {
53397 if (!uid_valid(uid))
53398 @@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
53399 } else {
53400 fsnotify_open(f);
53401 fd_install(fd, f);
53402 + trace_do_sys_open(tmp->name, flags, mode);
53403 }
53404 }
53405 putname(tmp);
53406 diff --git a/fs/pipe.c b/fs/pipe.c
53407 index bd3479d..fb92c4d 100644
53408 --- a/fs/pipe.c
53409 +++ b/fs/pipe.c
53410 @@ -438,9 +438,9 @@ redo:
53411 }
53412 if (bufs) /* More to do? */
53413 continue;
53414 - if (!pipe->writers)
53415 + if (!atomic_read(&pipe->writers))
53416 break;
53417 - if (!pipe->waiting_writers) {
53418 + if (!atomic_read(&pipe->waiting_writers)) {
53419 /* syscall merging: Usually we must not sleep
53420 * if O_NONBLOCK is set, or if we got some data.
53421 * But if a writer sleeps in kernel space, then
53422 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
53423 mutex_lock(&inode->i_mutex);
53424 pipe = inode->i_pipe;
53425
53426 - if (!pipe->readers) {
53427 + if (!atomic_read(&pipe->readers)) {
53428 send_sig(SIGPIPE, current, 0);
53429 ret = -EPIPE;
53430 goto out;
53431 @@ -553,7 +553,7 @@ redo1:
53432 for (;;) {
53433 int bufs;
53434
53435 - if (!pipe->readers) {
53436 + if (!atomic_read(&pipe->readers)) {
53437 send_sig(SIGPIPE, current, 0);
53438 if (!ret)
53439 ret = -EPIPE;
53440 @@ -644,9 +644,9 @@ redo2:
53441 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
53442 do_wakeup = 0;
53443 }
53444 - pipe->waiting_writers++;
53445 + atomic_inc(&pipe->waiting_writers);
53446 pipe_wait(pipe);
53447 - pipe->waiting_writers--;
53448 + atomic_dec(&pipe->waiting_writers);
53449 }
53450 out:
53451 mutex_unlock(&inode->i_mutex);
53452 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
53453 mask = 0;
53454 if (filp->f_mode & FMODE_READ) {
53455 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
53456 - if (!pipe->writers && filp->f_version != pipe->w_counter)
53457 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
53458 mask |= POLLHUP;
53459 }
53460
53461 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
53462 * Most Unices do not set POLLERR for FIFOs but on Linux they
53463 * behave exactly like pipes for poll().
53464 */
53465 - if (!pipe->readers)
53466 + if (!atomic_read(&pipe->readers))
53467 mask |= POLLERR;
53468 }
53469
53470 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
53471
53472 mutex_lock(&inode->i_mutex);
53473 pipe = inode->i_pipe;
53474 - pipe->readers -= decr;
53475 - pipe->writers -= decw;
53476 + atomic_sub(decr, &pipe->readers);
53477 + atomic_sub(decw, &pipe->writers);
53478
53479 - if (!pipe->readers && !pipe->writers) {
53480 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
53481 free_pipe_info(inode);
53482 } else {
53483 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
53484 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
53485
53486 if (inode->i_pipe) {
53487 ret = 0;
53488 - inode->i_pipe->readers++;
53489 + atomic_inc(&inode->i_pipe->readers);
53490 }
53491
53492 mutex_unlock(&inode->i_mutex);
53493 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
53494
53495 if (inode->i_pipe) {
53496 ret = 0;
53497 - inode->i_pipe->writers++;
53498 + atomic_inc(&inode->i_pipe->writers);
53499 }
53500
53501 mutex_unlock(&inode->i_mutex);
53502 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
53503 if (inode->i_pipe) {
53504 ret = 0;
53505 if (filp->f_mode & FMODE_READ)
53506 - inode->i_pipe->readers++;
53507 + atomic_inc(&inode->i_pipe->readers);
53508 if (filp->f_mode & FMODE_WRITE)
53509 - inode->i_pipe->writers++;
53510 + atomic_inc(&inode->i_pipe->writers);
53511 }
53512
53513 mutex_unlock(&inode->i_mutex);
53514 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
53515 inode->i_pipe = NULL;
53516 }
53517
53518 -static struct vfsmount *pipe_mnt __read_mostly;
53519 +struct vfsmount *pipe_mnt __read_mostly;
53520
53521 /*
53522 * pipefs_dname() is called from d_path().
53523 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
53524 goto fail_iput;
53525 inode->i_pipe = pipe;
53526
53527 - pipe->readers = pipe->writers = 1;
53528 + atomic_set(&pipe->readers, 1);
53529 + atomic_set(&pipe->writers, 1);
53530 inode->i_fop = &rdwr_pipefifo_fops;
53531
53532 /*
53533 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
53534 index 15af622..0e9f4467 100644
53535 --- a/fs/proc/Kconfig
53536 +++ b/fs/proc/Kconfig
53537 @@ -30,12 +30,12 @@ config PROC_FS
53538
53539 config PROC_KCORE
53540 bool "/proc/kcore support" if !ARM
53541 - depends on PROC_FS && MMU
53542 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
53543
53544 config PROC_VMCORE
53545 bool "/proc/vmcore support"
53546 - depends on PROC_FS && CRASH_DUMP
53547 - default y
53548 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
53549 + default n
53550 help
53551 Exports the dump image of crashed kernel in ELF format.
53552
53553 @@ -59,8 +59,8 @@ config PROC_SYSCTL
53554 limited in memory.
53555
53556 config PROC_PAGE_MONITOR
53557 - default y
53558 - depends on PROC_FS && MMU
53559 + default n
53560 + depends on PROC_FS && MMU && !GRKERNSEC
53561 bool "Enable /proc page monitoring" if EXPERT
53562 help
53563 Various /proc files exist to monitor process memory utilization:
53564 diff --git a/fs/proc/array.c b/fs/proc/array.c
53565 index 6a91e6f..e54dbc14 100644
53566 --- a/fs/proc/array.c
53567 +++ b/fs/proc/array.c
53568 @@ -60,6 +60,7 @@
53569 #include <linux/tty.h>
53570 #include <linux/string.h>
53571 #include <linux/mman.h>
53572 +#include <linux/grsecurity.h>
53573 #include <linux/proc_fs.h>
53574 #include <linux/ioport.h>
53575 #include <linux/uaccess.h>
53576 @@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
53577 seq_putc(m, '\n');
53578 }
53579
53580 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53581 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
53582 +{
53583 + if (p->mm)
53584 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
53585 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
53586 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
53587 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
53588 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
53589 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
53590 + else
53591 + seq_printf(m, "PaX:\t-----\n");
53592 +}
53593 +#endif
53594 +
53595 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
53596 struct pid *pid, struct task_struct *task)
53597 {
53598 @@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
53599 task_cpus_allowed(m, task);
53600 cpuset_task_status_allowed(m, task);
53601 task_context_switch_counts(m, task);
53602 +
53603 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53604 + task_pax(m, task);
53605 +#endif
53606 +
53607 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
53608 + task_grsec_rbac(m, task);
53609 +#endif
53610 +
53611 return 0;
53612 }
53613
53614 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53615 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53616 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
53617 + _mm->pax_flags & MF_PAX_SEGMEXEC))
53618 +#endif
53619 +
53620 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53621 struct pid *pid, struct task_struct *task, int whole)
53622 {
53623 @@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53624 char tcomm[sizeof(task->comm)];
53625 unsigned long flags;
53626
53627 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53628 + if (current->exec_id != m->exec_id) {
53629 + gr_log_badprocpid("stat");
53630 + return 0;
53631 + }
53632 +#endif
53633 +
53634 state = *get_task_state(task);
53635 vsize = eip = esp = 0;
53636 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
53637 @@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53638 gtime = task->gtime;
53639 }
53640
53641 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53642 + if (PAX_RAND_FLAGS(mm)) {
53643 + eip = 0;
53644 + esp = 0;
53645 + wchan = 0;
53646 + }
53647 +#endif
53648 +#ifdef CONFIG_GRKERNSEC_HIDESYM
53649 + wchan = 0;
53650 + eip =0;
53651 + esp =0;
53652 +#endif
53653 +
53654 /* scale priority and nice values from timeslices to -20..20 */
53655 /* to make it look like a "normal" Unix priority/nice value */
53656 priority = task_prio(task);
53657 @@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53658 seq_put_decimal_ull(m, ' ', vsize);
53659 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
53660 seq_put_decimal_ull(m, ' ', rsslim);
53661 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53662 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
53663 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
53664 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
53665 +#else
53666 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
53667 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
53668 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
53669 +#endif
53670 seq_put_decimal_ull(m, ' ', esp);
53671 seq_put_decimal_ull(m, ' ', eip);
53672 /* The signal information here is obsolete.
53673 @@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53674 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
53675 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
53676
53677 - if (mm && permitted) {
53678 + if (mm && permitted
53679 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53680 + && !PAX_RAND_FLAGS(mm)
53681 +#endif
53682 + ) {
53683 seq_put_decimal_ull(m, ' ', mm->start_data);
53684 seq_put_decimal_ull(m, ' ', mm->end_data);
53685 seq_put_decimal_ull(m, ' ', mm->start_brk);
53686 @@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
53687 struct pid *pid, struct task_struct *task)
53688 {
53689 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
53690 - struct mm_struct *mm = get_task_mm(task);
53691 + struct mm_struct *mm;
53692
53693 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53694 + if (current->exec_id != m->exec_id) {
53695 + gr_log_badprocpid("statm");
53696 + return 0;
53697 + }
53698 +#endif
53699 + mm = get_task_mm(task);
53700 if (mm) {
53701 size = task_statm(mm, &shared, &text, &data, &resident);
53702 mmput(mm);
53703 @@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
53704 return 0;
53705 }
53706
53707 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
53708 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
53709 +{
53710 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
53711 +}
53712 +#endif
53713 +
53714 #ifdef CONFIG_CHECKPOINT_RESTORE
53715 static struct pid *
53716 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
53717 diff --git a/fs/proc/base.c b/fs/proc/base.c
53718 index 9b43ff77..ba3e990 100644
53719 --- a/fs/proc/base.c
53720 +++ b/fs/proc/base.c
53721 @@ -111,6 +111,14 @@ struct pid_entry {
53722 union proc_op op;
53723 };
53724
53725 +struct getdents_callback {
53726 + struct linux_dirent __user * current_dir;
53727 + struct linux_dirent __user * previous;
53728 + struct file * file;
53729 + int count;
53730 + int error;
53731 +};
53732 +
53733 #define NOD(NAME, MODE, IOP, FOP, OP) { \
53734 .name = (NAME), \
53735 .len = sizeof(NAME) - 1, \
53736 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
53737 if (!mm->arg_end)
53738 goto out_mm; /* Shh! No looking before we're done */
53739
53740 + if (gr_acl_handle_procpidmem(task))
53741 + goto out_mm;
53742 +
53743 len = mm->arg_end - mm->arg_start;
53744
53745 if (len > PAGE_SIZE)
53746 @@ -235,12 +246,28 @@ out:
53747 return res;
53748 }
53749
53750 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53751 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53752 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
53753 + _mm->pax_flags & MF_PAX_SEGMEXEC))
53754 +#endif
53755 +
53756 static int proc_pid_auxv(struct task_struct *task, char *buffer)
53757 {
53758 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
53759 int res = PTR_ERR(mm);
53760 if (mm && !IS_ERR(mm)) {
53761 unsigned int nwords = 0;
53762 +
53763 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53764 + /* allow if we're currently ptracing this task */
53765 + if (PAX_RAND_FLAGS(mm) &&
53766 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
53767 + mmput(mm);
53768 + return 0;
53769 + }
53770 +#endif
53771 +
53772 do {
53773 nwords += 2;
53774 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
53775 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
53776 }
53777
53778
53779 -#ifdef CONFIG_KALLSYMS
53780 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53781 /*
53782 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
53783 * Returns the resolved symbol. If that fails, simply return the address.
53784 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
53785 mutex_unlock(&task->signal->cred_guard_mutex);
53786 }
53787
53788 -#ifdef CONFIG_STACKTRACE
53789 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53790
53791 #define MAX_STACK_TRACE_DEPTH 64
53792
53793 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
53794 return count;
53795 }
53796
53797 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
53798 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
53799 static int proc_pid_syscall(struct task_struct *task, char *buffer)
53800 {
53801 long nr;
53802 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
53803 /************************************************************************/
53804
53805 /* permission checks */
53806 -static int proc_fd_access_allowed(struct inode *inode)
53807 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
53808 {
53809 struct task_struct *task;
53810 int allowed = 0;
53811 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
53812 */
53813 task = get_proc_task(inode);
53814 if (task) {
53815 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
53816 + if (log)
53817 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
53818 + else
53819 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
53820 put_task_struct(task);
53821 }
53822 return allowed;
53823 @@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
53824 struct task_struct *task,
53825 int hide_pid_min)
53826 {
53827 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
53828 + return false;
53829 +
53830 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53831 + rcu_read_lock();
53832 + {
53833 + const struct cred *tmpcred = current_cred();
53834 + const struct cred *cred = __task_cred(task);
53835 +
53836 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
53837 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
53838 + || in_group_p(grsec_proc_gid)
53839 +#endif
53840 + ) {
53841 + rcu_read_unlock();
53842 + return true;
53843 + }
53844 + }
53845 + rcu_read_unlock();
53846 +
53847 + if (!pid->hide_pid)
53848 + return false;
53849 +#endif
53850 +
53851 if (pid->hide_pid < hide_pid_min)
53852 return true;
53853 if (in_group_p(pid->pid_gid))
53854 return true;
53855 +
53856 return ptrace_may_access(task, PTRACE_MODE_READ);
53857 }
53858
53859 @@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
53860 put_task_struct(task);
53861
53862 if (!has_perms) {
53863 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53864 + {
53865 +#else
53866 if (pid->hide_pid == 2) {
53867 +#endif
53868 /*
53869 * Let's make getdents(), stat(), and open()
53870 * consistent with each other. If a process
53871 @@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
53872 if (!task)
53873 return -ESRCH;
53874
53875 + if (gr_acl_handle_procpidmem(task)) {
53876 + put_task_struct(task);
53877 + return -EPERM;
53878 + }
53879 +
53880 mm = mm_access(task, mode);
53881 put_task_struct(task);
53882
53883 @@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
53884
53885 file->private_data = mm;
53886
53887 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53888 + file->f_version = current->exec_id;
53889 +#endif
53890 +
53891 return 0;
53892 }
53893
53894 @@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
53895 ssize_t copied;
53896 char *page;
53897
53898 +#ifdef CONFIG_GRKERNSEC
53899 + if (write)
53900 + return -EPERM;
53901 +#endif
53902 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53903 + if (file->f_version != current->exec_id) {
53904 + gr_log_badprocpid("mem");
53905 + return 0;
53906 + }
53907 +#endif
53908 +
53909 if (!mm)
53910 return 0;
53911
53912 @@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
53913 if (!mm)
53914 return 0;
53915
53916 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53917 + if (file->f_version != current->exec_id) {
53918 + gr_log_badprocpid("environ");
53919 + return 0;
53920 + }
53921 +#endif
53922 +
53923 page = (char *)__get_free_page(GFP_TEMPORARY);
53924 if (!page)
53925 return -ENOMEM;
53926 @@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
53927 int error = -EACCES;
53928
53929 /* Are we allowed to snoop on the tasks file descriptors? */
53930 - if (!proc_fd_access_allowed(inode))
53931 + if (!proc_fd_access_allowed(inode, 0))
53932 goto out;
53933
53934 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
53935 @@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
53936 struct path path;
53937
53938 /* Are we allowed to snoop on the tasks file descriptors? */
53939 - if (!proc_fd_access_allowed(inode))
53940 - goto out;
53941 + /* logging this is needed for learning on chromium to work properly,
53942 + but we don't want to flood the logs from 'ps' which does a readlink
53943 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
53944 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
53945 + */
53946 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
53947 + if (!proc_fd_access_allowed(inode,0))
53948 + goto out;
53949 + } else {
53950 + if (!proc_fd_access_allowed(inode,1))
53951 + goto out;
53952 + }
53953
53954 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
53955 if (error)
53956 @@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
53957 rcu_read_lock();
53958 cred = __task_cred(task);
53959 inode->i_uid = cred->euid;
53960 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
53961 + inode->i_gid = grsec_proc_gid;
53962 +#else
53963 inode->i_gid = cred->egid;
53964 +#endif
53965 rcu_read_unlock();
53966 }
53967 security_task_to_inode(task, inode);
53968 @@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
53969 return -ENOENT;
53970 }
53971 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
53972 +#ifdef CONFIG_GRKERNSEC_PROC_USER
53973 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
53974 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53975 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
53976 +#endif
53977 task_dumpable(task)) {
53978 cred = __task_cred(task);
53979 stat->uid = cred->euid;
53980 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
53981 + stat->gid = grsec_proc_gid;
53982 +#else
53983 stat->gid = cred->egid;
53984 +#endif
53985 }
53986 }
53987 rcu_read_unlock();
53988 @@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
53989
53990 if (task) {
53991 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
53992 +#ifdef CONFIG_GRKERNSEC_PROC_USER
53993 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
53994 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53995 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
53996 +#endif
53997 task_dumpable(task)) {
53998 rcu_read_lock();
53999 cred = __task_cred(task);
54000 inode->i_uid = cred->euid;
54001 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54002 + inode->i_gid = grsec_proc_gid;
54003 +#else
54004 inode->i_gid = cred->egid;
54005 +#endif
54006 rcu_read_unlock();
54007 } else {
54008 inode->i_uid = GLOBAL_ROOT_UID;
54009 @@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
54010 if (!task)
54011 goto out_no_task;
54012
54013 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54014 + goto out;
54015 +
54016 /*
54017 * Yes, it does not scale. And it should not. Don't add
54018 * new entries into /proc/<tgid>/ without very good reasons.
54019 @@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
54020 if (!task)
54021 goto out_no_task;
54022
54023 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54024 + goto out;
54025 +
54026 ret = 0;
54027 i = filp->f_pos;
54028 switch (i) {
54029 @@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
54030 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
54031 #endif
54032 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54033 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54034 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54035 INF("syscall", S_IRUGO, proc_pid_syscall),
54036 #endif
54037 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54038 @@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
54039 #ifdef CONFIG_SECURITY
54040 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54041 #endif
54042 -#ifdef CONFIG_KALLSYMS
54043 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54044 INF("wchan", S_IRUGO, proc_pid_wchan),
54045 #endif
54046 -#ifdef CONFIG_STACKTRACE
54047 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54048 ONE("stack", S_IRUGO, proc_pid_stack),
54049 #endif
54050 #ifdef CONFIG_SCHEDSTATS
54051 @@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
54052 #ifdef CONFIG_HARDWALL
54053 INF("hardwall", S_IRUGO, proc_pid_hardwall),
54054 #endif
54055 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54056 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
54057 +#endif
54058 #ifdef CONFIG_USER_NS
54059 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
54060 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
54061 @@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
54062 if (!inode)
54063 goto out;
54064
54065 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54066 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
54067 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54068 + inode->i_gid = grsec_proc_gid;
54069 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
54070 +#else
54071 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
54072 +#endif
54073 inode->i_op = &proc_tgid_base_inode_operations;
54074 inode->i_fop = &proc_tgid_base_operations;
54075 inode->i_flags|=S_IMMUTABLE;
54076 @@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
54077 if (!task)
54078 goto out;
54079
54080 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54081 + goto out_put_task;
54082 +
54083 result = proc_pid_instantiate(dir, dentry, task, NULL);
54084 +out_put_task:
54085 put_task_struct(task);
54086 out:
54087 return result;
54088 @@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
54089 static int fake_filldir(void *buf, const char *name, int namelen,
54090 loff_t offset, u64 ino, unsigned d_type)
54091 {
54092 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
54093 + __buf->error = -EINVAL;
54094 return 0;
54095 }
54096
54097 @@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
54098 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
54099 #endif
54100 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54101 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54102 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54103 INF("syscall", S_IRUGO, proc_pid_syscall),
54104 #endif
54105 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54106 @@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
54107 #ifdef CONFIG_SECURITY
54108 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54109 #endif
54110 -#ifdef CONFIG_KALLSYMS
54111 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54112 INF("wchan", S_IRUGO, proc_pid_wchan),
54113 #endif
54114 -#ifdef CONFIG_STACKTRACE
54115 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54116 ONE("stack", S_IRUGO, proc_pid_stack),
54117 #endif
54118 #ifdef CONFIG_SCHEDSTATS
54119 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
54120 index 82676e3..5f8518a 100644
54121 --- a/fs/proc/cmdline.c
54122 +++ b/fs/proc/cmdline.c
54123 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
54124
54125 static int __init proc_cmdline_init(void)
54126 {
54127 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54128 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
54129 +#else
54130 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
54131 +#endif
54132 return 0;
54133 }
54134 module_init(proc_cmdline_init);
54135 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
54136 index b143471..bb105e5 100644
54137 --- a/fs/proc/devices.c
54138 +++ b/fs/proc/devices.c
54139 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
54140
54141 static int __init proc_devices_init(void)
54142 {
54143 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54144 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
54145 +#else
54146 proc_create("devices", 0, NULL, &proc_devinfo_operations);
54147 +#endif
54148 return 0;
54149 }
54150 module_init(proc_devices_init);
54151 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
54152 index d7a4a28..0201742 100644
54153 --- a/fs/proc/fd.c
54154 +++ b/fs/proc/fd.c
54155 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
54156 if (!task)
54157 return -ENOENT;
54158
54159 - files = get_files_struct(task);
54160 + if (!gr_acl_handle_procpidmem(task))
54161 + files = get_files_struct(task);
54162 put_task_struct(task);
54163
54164 if (files) {
54165 @@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
54166 */
54167 int proc_fd_permission(struct inode *inode, int mask)
54168 {
54169 + struct task_struct *task;
54170 int rv = generic_permission(inode, mask);
54171 - if (rv == 0)
54172 - return 0;
54173 +
54174 if (task_pid(current) == proc_pid(inode))
54175 rv = 0;
54176 +
54177 + task = get_proc_task(inode);
54178 + if (task == NULL)
54179 + return rv;
54180 +
54181 + if (gr_acl_handle_procpidmem(task))
54182 + rv = -EACCES;
54183 +
54184 + put_task_struct(task);
54185 +
54186 return rv;
54187 }
54188
54189 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
54190 index 439ae688..c21ac36 100644
54191 --- a/fs/proc/inode.c
54192 +++ b/fs/proc/inode.c
54193 @@ -21,11 +21,17 @@
54194 #include <linux/seq_file.h>
54195 #include <linux/slab.h>
54196 #include <linux/mount.h>
54197 +#include <linux/grsecurity.h>
54198
54199 #include <asm/uaccess.h>
54200
54201 #include "internal.h"
54202
54203 +#ifdef CONFIG_PROC_SYSCTL
54204 +extern const struct inode_operations proc_sys_inode_operations;
54205 +extern const struct inode_operations proc_sys_dir_operations;
54206 +#endif
54207 +
54208 static void proc_evict_inode(struct inode *inode)
54209 {
54210 struct proc_dir_entry *de;
54211 @@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
54212 ns = PROC_I(inode)->ns;
54213 if (ns_ops && ns)
54214 ns_ops->put(ns);
54215 +
54216 +#ifdef CONFIG_PROC_SYSCTL
54217 + if (inode->i_op == &proc_sys_inode_operations ||
54218 + inode->i_op == &proc_sys_dir_operations)
54219 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
54220 +#endif
54221 +
54222 }
54223
54224 static struct kmem_cache * proc_inode_cachep;
54225 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
54226 if (de->mode) {
54227 inode->i_mode = de->mode;
54228 inode->i_uid = de->uid;
54229 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54230 + inode->i_gid = grsec_proc_gid;
54231 +#else
54232 inode->i_gid = de->gid;
54233 +#endif
54234 }
54235 if (de->size)
54236 inode->i_size = de->size;
54237 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
54238 index 252544c..04395b9 100644
54239 --- a/fs/proc/internal.h
54240 +++ b/fs/proc/internal.h
54241 @@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54242 struct pid *pid, struct task_struct *task);
54243 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54244 struct pid *pid, struct task_struct *task);
54245 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54246 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
54247 +#endif
54248 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
54249
54250 extern const struct file_operations proc_tid_children_operations;
54251 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
54252 index e96d4f1..8b116ed 100644
54253 --- a/fs/proc/kcore.c
54254 +++ b/fs/proc/kcore.c
54255 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54256 * the addresses in the elf_phdr on our list.
54257 */
54258 start = kc_offset_to_vaddr(*fpos - elf_buflen);
54259 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
54260 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
54261 + if (tsz > buflen)
54262 tsz = buflen;
54263 -
54264 +
54265 while (buflen) {
54266 struct kcore_list *m;
54267
54268 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54269 kfree(elf_buf);
54270 } else {
54271 if (kern_addr_valid(start)) {
54272 - unsigned long n;
54273 + char *elf_buf;
54274 + mm_segment_t oldfs;
54275
54276 - n = copy_to_user(buffer, (char *)start, tsz);
54277 - /*
54278 - * We cannot distinguish between fault on source
54279 - * and fault on destination. When this happens
54280 - * we clear too and hope it will trigger the
54281 - * EFAULT again.
54282 - */
54283 - if (n) {
54284 - if (clear_user(buffer + tsz - n,
54285 - n))
54286 + elf_buf = kmalloc(tsz, GFP_KERNEL);
54287 + if (!elf_buf)
54288 + return -ENOMEM;
54289 + oldfs = get_fs();
54290 + set_fs(KERNEL_DS);
54291 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
54292 + set_fs(oldfs);
54293 + if (copy_to_user(buffer, elf_buf, tsz)) {
54294 + kfree(elf_buf);
54295 return -EFAULT;
54296 + }
54297 }
54298 + set_fs(oldfs);
54299 + kfree(elf_buf);
54300 } else {
54301 if (clear_user(buffer, tsz))
54302 return -EFAULT;
54303 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54304
54305 static int open_kcore(struct inode *inode, struct file *filp)
54306 {
54307 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
54308 + return -EPERM;
54309 +#endif
54310 if (!capable(CAP_SYS_RAWIO))
54311 return -EPERM;
54312 if (kcore_need_update)
54313 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
54314 index 80e4645..53e5fcf 100644
54315 --- a/fs/proc/meminfo.c
54316 +++ b/fs/proc/meminfo.c
54317 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
54318 vmi.used >> 10,
54319 vmi.largest_chunk >> 10
54320 #ifdef CONFIG_MEMORY_FAILURE
54321 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
54322 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
54323 #endif
54324 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
54325 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
54326 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
54327 index b1822dd..df622cb 100644
54328 --- a/fs/proc/nommu.c
54329 +++ b/fs/proc/nommu.c
54330 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
54331 if (len < 1)
54332 len = 1;
54333 seq_printf(m, "%*c", len, ' ');
54334 - seq_path(m, &file->f_path, "");
54335 + seq_path(m, &file->f_path, "\n\\");
54336 }
54337
54338 seq_putc(m, '\n');
54339 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
54340 index fe72cd0..21b52ff 100644
54341 --- a/fs/proc/proc_net.c
54342 +++ b/fs/proc/proc_net.c
54343 @@ -23,6 +23,7 @@
54344 #include <linux/nsproxy.h>
54345 #include <net/net_namespace.h>
54346 #include <linux/seq_file.h>
54347 +#include <linux/grsecurity.h>
54348
54349 #include "internal.h"
54350
54351 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
54352 struct task_struct *task;
54353 struct nsproxy *ns;
54354 struct net *net = NULL;
54355 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54356 + const struct cred *cred = current_cred();
54357 +#endif
54358 +
54359 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54360 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
54361 + return net;
54362 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54363 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
54364 + return net;
54365 +#endif
54366
54367 rcu_read_lock();
54368 task = pid_task(proc_pid(dir), PIDTYPE_PID);
54369 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
54370 index 1827d88..43b0279 100644
54371 --- a/fs/proc/proc_sysctl.c
54372 +++ b/fs/proc/proc_sysctl.c
54373 @@ -12,11 +12,15 @@
54374 #include <linux/module.h>
54375 #include "internal.h"
54376
54377 +extern int gr_handle_chroot_sysctl(const int op);
54378 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
54379 + const int op);
54380 +
54381 static const struct dentry_operations proc_sys_dentry_operations;
54382 static const struct file_operations proc_sys_file_operations;
54383 -static const struct inode_operations proc_sys_inode_operations;
54384 +const struct inode_operations proc_sys_inode_operations;
54385 static const struct file_operations proc_sys_dir_file_operations;
54386 -static const struct inode_operations proc_sys_dir_operations;
54387 +const struct inode_operations proc_sys_dir_operations;
54388
54389 void proc_sys_poll_notify(struct ctl_table_poll *poll)
54390 {
54391 @@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
54392
54393 err = NULL;
54394 d_set_d_op(dentry, &proc_sys_dentry_operations);
54395 +
54396 + gr_handle_proc_create(dentry, inode);
54397 +
54398 d_add(dentry, inode);
54399
54400 out:
54401 @@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54402 struct inode *inode = filp->f_path.dentry->d_inode;
54403 struct ctl_table_header *head = grab_header(inode);
54404 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
54405 + int op = write ? MAY_WRITE : MAY_READ;
54406 ssize_t error;
54407 size_t res;
54408
54409 @@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54410 * and won't be until we finish.
54411 */
54412 error = -EPERM;
54413 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
54414 + if (sysctl_perm(head, table, op))
54415 goto out;
54416
54417 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
54418 @@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54419 if (!table->proc_handler)
54420 goto out;
54421
54422 +#ifdef CONFIG_GRKERNSEC
54423 + error = -EPERM;
54424 + if (gr_handle_chroot_sysctl(op))
54425 + goto out;
54426 + dget(filp->f_path.dentry);
54427 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
54428 + dput(filp->f_path.dentry);
54429 + goto out;
54430 + }
54431 + dput(filp->f_path.dentry);
54432 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
54433 + goto out;
54434 + if (write && !capable(CAP_SYS_ADMIN))
54435 + goto out;
54436 +#endif
54437 +
54438 /* careful: calling conventions are nasty here */
54439 res = count;
54440 error = table->proc_handler(table, write, buf, &res, ppos);
54441 @@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
54442 return -ENOMEM;
54443 } else {
54444 d_set_d_op(child, &proc_sys_dentry_operations);
54445 +
54446 + gr_handle_proc_create(child, inode);
54447 +
54448 d_add(child, inode);
54449 }
54450 } else {
54451 @@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
54452 if ((*pos)++ < file->f_pos)
54453 return 0;
54454
54455 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
54456 + return 0;
54457 +
54458 if (unlikely(S_ISLNK(table->mode)))
54459 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
54460 else
54461 @@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
54462 if (IS_ERR(head))
54463 return PTR_ERR(head);
54464
54465 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
54466 + return -ENOENT;
54467 +
54468 generic_fillattr(inode, stat);
54469 if (table)
54470 stat->mode = (stat->mode & S_IFMT) | table->mode;
54471 @@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
54472 .llseek = generic_file_llseek,
54473 };
54474
54475 -static const struct inode_operations proc_sys_inode_operations = {
54476 +const struct inode_operations proc_sys_inode_operations = {
54477 .permission = proc_sys_permission,
54478 .setattr = proc_sys_setattr,
54479 .getattr = proc_sys_getattr,
54480 };
54481
54482 -static const struct inode_operations proc_sys_dir_operations = {
54483 +const struct inode_operations proc_sys_dir_operations = {
54484 .lookup = proc_sys_lookup,
54485 .permission = proc_sys_permission,
54486 .setattr = proc_sys_setattr,
54487 @@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
54488 static struct ctl_dir *new_dir(struct ctl_table_set *set,
54489 const char *name, int namelen)
54490 {
54491 - struct ctl_table *table;
54492 + ctl_table_no_const *table;
54493 struct ctl_dir *new;
54494 struct ctl_node *node;
54495 char *new_name;
54496 @@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
54497 return NULL;
54498
54499 node = (struct ctl_node *)(new + 1);
54500 - table = (struct ctl_table *)(node + 1);
54501 + table = (ctl_table_no_const *)(node + 1);
54502 new_name = (char *)(table + 2);
54503 memcpy(new_name, name, namelen);
54504 new_name[namelen] = '\0';
54505 @@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
54506 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
54507 struct ctl_table_root *link_root)
54508 {
54509 - struct ctl_table *link_table, *entry, *link;
54510 + ctl_table_no_const *link_table, *link;
54511 + struct ctl_table *entry;
54512 struct ctl_table_header *links;
54513 struct ctl_node *node;
54514 char *link_name;
54515 @@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
54516 return NULL;
54517
54518 node = (struct ctl_node *)(links + 1);
54519 - link_table = (struct ctl_table *)(node + nr_entries);
54520 + link_table = (ctl_table_no_const *)(node + nr_entries);
54521 link_name = (char *)&link_table[nr_entries + 1];
54522
54523 for (link = link_table, entry = table; entry->procname; link++, entry++) {
54524 @@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54525 struct ctl_table_header ***subheader, struct ctl_table_set *set,
54526 struct ctl_table *table)
54527 {
54528 - struct ctl_table *ctl_table_arg = NULL;
54529 - struct ctl_table *entry, *files;
54530 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
54531 + struct ctl_table *entry;
54532 int nr_files = 0;
54533 int nr_dirs = 0;
54534 int err = -ENOMEM;
54535 @@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54536 nr_files++;
54537 }
54538
54539 - files = table;
54540 /* If there are mixed files and directories we need a new table */
54541 if (nr_dirs && nr_files) {
54542 - struct ctl_table *new;
54543 + ctl_table_no_const *new;
54544 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
54545 GFP_KERNEL);
54546 if (!files)
54547 @@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54548 /* Register everything except a directory full of subdirectories */
54549 if (nr_files || !nr_dirs) {
54550 struct ctl_table_header *header;
54551 - header = __register_sysctl_table(set, path, files);
54552 + header = __register_sysctl_table(set, path, files ? files : table);
54553 if (!header) {
54554 kfree(ctl_table_arg);
54555 goto out;
54556 diff --git a/fs/proc/root.c b/fs/proc/root.c
54557 index c6e9fac..a740964 100644
54558 --- a/fs/proc/root.c
54559 +++ b/fs/proc/root.c
54560 @@ -176,7 +176,15 @@ void __init proc_root_init(void)
54561 #ifdef CONFIG_PROC_DEVICETREE
54562 proc_device_tree_init();
54563 #endif
54564 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54565 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54566 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
54567 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54568 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
54569 +#endif
54570 +#else
54571 proc_mkdir("bus", NULL);
54572 +#endif
54573 proc_sys_init();
54574 }
54575
54576 diff --git a/fs/proc/self.c b/fs/proc/self.c
54577 index aa5cc3b..c91a5d0 100644
54578 --- a/fs/proc/self.c
54579 +++ b/fs/proc/self.c
54580 @@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
54581 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
54582 void *cookie)
54583 {
54584 - char *s = nd_get_link(nd);
54585 + const char *s = nd_get_link(nd);
54586 if (!IS_ERR(s))
54587 kfree(s);
54588 }
54589 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
54590 index ca5ce7f..02c1cf0 100644
54591 --- a/fs/proc/task_mmu.c
54592 +++ b/fs/proc/task_mmu.c
54593 @@ -11,12 +11,19 @@
54594 #include <linux/rmap.h>
54595 #include <linux/swap.h>
54596 #include <linux/swapops.h>
54597 +#include <linux/grsecurity.h>
54598
54599 #include <asm/elf.h>
54600 #include <asm/uaccess.h>
54601 #include <asm/tlbflush.h>
54602 #include "internal.h"
54603
54604 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54605 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54606 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
54607 + _mm->pax_flags & MF_PAX_SEGMEXEC))
54608 +#endif
54609 +
54610 void task_mem(struct seq_file *m, struct mm_struct *mm)
54611 {
54612 unsigned long data, text, lib, swap;
54613 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54614 "VmExe:\t%8lu kB\n"
54615 "VmLib:\t%8lu kB\n"
54616 "VmPTE:\t%8lu kB\n"
54617 - "VmSwap:\t%8lu kB\n",
54618 - hiwater_vm << (PAGE_SHIFT-10),
54619 + "VmSwap:\t%8lu kB\n"
54620 +
54621 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54622 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
54623 +#endif
54624 +
54625 + ,hiwater_vm << (PAGE_SHIFT-10),
54626 total_vm << (PAGE_SHIFT-10),
54627 mm->locked_vm << (PAGE_SHIFT-10),
54628 mm->pinned_vm << (PAGE_SHIFT-10),
54629 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54630 data << (PAGE_SHIFT-10),
54631 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
54632 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
54633 - swap << (PAGE_SHIFT-10));
54634 + swap << (PAGE_SHIFT-10)
54635 +
54636 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54637 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54638 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
54639 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
54640 +#else
54641 + , mm->context.user_cs_base
54642 + , mm->context.user_cs_limit
54643 +#endif
54644 +#endif
54645 +
54646 + );
54647 }
54648
54649 unsigned long task_vsize(struct mm_struct *mm)
54650 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54651 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
54652 }
54653
54654 - /* We don't show the stack guard page in /proc/maps */
54655 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54656 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
54657 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
54658 +#else
54659 start = vma->vm_start;
54660 - if (stack_guard_page_start(vma, start))
54661 - start += PAGE_SIZE;
54662 end = vma->vm_end;
54663 - if (stack_guard_page_end(vma, end))
54664 - end -= PAGE_SIZE;
54665 +#endif
54666
54667 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
54668 start,
54669 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54670 flags & VM_WRITE ? 'w' : '-',
54671 flags & VM_EXEC ? 'x' : '-',
54672 flags & VM_MAYSHARE ? 's' : 'p',
54673 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54674 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
54675 +#else
54676 pgoff,
54677 +#endif
54678 MAJOR(dev), MINOR(dev), ino, &len);
54679
54680 /*
54681 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54682 */
54683 if (file) {
54684 pad_len_spaces(m, len);
54685 - seq_path(m, &file->f_path, "\n");
54686 + seq_path(m, &file->f_path, "\n\\");
54687 goto done;
54688 }
54689
54690 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54691 * Thread stack in /proc/PID/task/TID/maps or
54692 * the main process stack.
54693 */
54694 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
54695 - vma->vm_end >= mm->start_stack)) {
54696 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
54697 + (vma->vm_start <= mm->start_stack &&
54698 + vma->vm_end >= mm->start_stack)) {
54699 name = "[stack]";
54700 } else {
54701 /* Thread stack in /proc/PID/maps */
54702 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
54703 struct proc_maps_private *priv = m->private;
54704 struct task_struct *task = priv->task;
54705
54706 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54707 + if (current->exec_id != m->exec_id) {
54708 + gr_log_badprocpid("maps");
54709 + return 0;
54710 + }
54711 +#endif
54712 +
54713 show_map_vma(m, vma, is_pid);
54714
54715 if (m->count < m->size) /* vma is copied successfully */
54716 @@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
54717 .private = &mss,
54718 };
54719
54720 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54721 + if (current->exec_id != m->exec_id) {
54722 + gr_log_badprocpid("smaps");
54723 + return 0;
54724 + }
54725 +#endif
54726 memset(&mss, 0, sizeof mss);
54727 - mss.vma = vma;
54728 - /* mmap_sem is held in m_start */
54729 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
54730 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
54731 -
54732 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54733 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
54734 +#endif
54735 + mss.vma = vma;
54736 + /* mmap_sem is held in m_start */
54737 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
54738 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
54739 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54740 + }
54741 +#endif
54742 show_map_vma(m, vma, is_pid);
54743
54744 seq_printf(m,
54745 @@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
54746 "KernelPageSize: %8lu kB\n"
54747 "MMUPageSize: %8lu kB\n"
54748 "Locked: %8lu kB\n",
54749 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54750 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
54751 +#else
54752 (vma->vm_end - vma->vm_start) >> 10,
54753 +#endif
54754 mss.resident >> 10,
54755 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
54756 mss.shared_clean >> 10,
54757 @@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
54758 int n;
54759 char buffer[50];
54760
54761 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54762 + if (current->exec_id != m->exec_id) {
54763 + gr_log_badprocpid("numa_maps");
54764 + return 0;
54765 + }
54766 +#endif
54767 +
54768 if (!mm)
54769 return 0;
54770
54771 @@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
54772 mpol_to_str(buffer, sizeof(buffer), pol);
54773 mpol_cond_put(pol);
54774
54775 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54776 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
54777 +#else
54778 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
54779 +#endif
54780
54781 if (file) {
54782 seq_printf(m, " file=");
54783 - seq_path(m, &file->f_path, "\n\t= ");
54784 + seq_path(m, &file->f_path, "\n\t\\= ");
54785 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
54786 seq_printf(m, " heap");
54787 } else {
54788 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
54789 index 1ccfa53..0848f95 100644
54790 --- a/fs/proc/task_nommu.c
54791 +++ b/fs/proc/task_nommu.c
54792 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54793 else
54794 bytes += kobjsize(mm);
54795
54796 - if (current->fs && current->fs->users > 1)
54797 + if (current->fs && atomic_read(&current->fs->users) > 1)
54798 sbytes += kobjsize(current->fs);
54799 else
54800 bytes += kobjsize(current->fs);
54801 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
54802
54803 if (file) {
54804 pad_len_spaces(m, len);
54805 - seq_path(m, &file->f_path, "");
54806 + seq_path(m, &file->f_path, "\n\\");
54807 } else if (mm) {
54808 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
54809
54810 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
54811 index 16e8abb..2dcf914 100644
54812 --- a/fs/quota/netlink.c
54813 +++ b/fs/quota/netlink.c
54814 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
54815 void quota_send_warning(struct kqid qid, dev_t dev,
54816 const char warntype)
54817 {
54818 - static atomic_t seq;
54819 + static atomic_unchecked_t seq;
54820 struct sk_buff *skb;
54821 void *msg_head;
54822 int ret;
54823 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
54824 "VFS: Not enough memory to send quota warning.\n");
54825 return;
54826 }
54827 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
54828 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
54829 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
54830 if (!msg_head) {
54831 printk(KERN_ERR
54832 diff --git a/fs/readdir.c b/fs/readdir.c
54833 index 5e69ef5..e5d9099 100644
54834 --- a/fs/readdir.c
54835 +++ b/fs/readdir.c
54836 @@ -17,6 +17,7 @@
54837 #include <linux/security.h>
54838 #include <linux/syscalls.h>
54839 #include <linux/unistd.h>
54840 +#include <linux/namei.h>
54841
54842 #include <asm/uaccess.h>
54843
54844 @@ -67,6 +68,7 @@ struct old_linux_dirent {
54845
54846 struct readdir_callback {
54847 struct old_linux_dirent __user * dirent;
54848 + struct file * file;
54849 int result;
54850 };
54851
54852 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
54853 buf->result = -EOVERFLOW;
54854 return -EOVERFLOW;
54855 }
54856 +
54857 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54858 + return 0;
54859 +
54860 buf->result++;
54861 dirent = buf->dirent;
54862 if (!access_ok(VERIFY_WRITE, dirent,
54863 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
54864
54865 buf.result = 0;
54866 buf.dirent = dirent;
54867 + buf.file = f.file;
54868
54869 error = vfs_readdir(f.file, fillonedir, &buf);
54870 if (buf.result)
54871 @@ -139,6 +146,7 @@ struct linux_dirent {
54872 struct getdents_callback {
54873 struct linux_dirent __user * current_dir;
54874 struct linux_dirent __user * previous;
54875 + struct file * file;
54876 int count;
54877 int error;
54878 };
54879 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
54880 buf->error = -EOVERFLOW;
54881 return -EOVERFLOW;
54882 }
54883 +
54884 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54885 + return 0;
54886 +
54887 dirent = buf->previous;
54888 if (dirent) {
54889 if (__put_user(offset, &dirent->d_off))
54890 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
54891 buf.previous = NULL;
54892 buf.count = count;
54893 buf.error = 0;
54894 + buf.file = f.file;
54895
54896 error = vfs_readdir(f.file, filldir, &buf);
54897 if (error >= 0)
54898 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
54899 struct getdents_callback64 {
54900 struct linux_dirent64 __user * current_dir;
54901 struct linux_dirent64 __user * previous;
54902 + struct file *file;
54903 int count;
54904 int error;
54905 };
54906 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
54907 buf->error = -EINVAL; /* only used if we fail.. */
54908 if (reclen > buf->count)
54909 return -EINVAL;
54910 +
54911 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54912 + return 0;
54913 +
54914 dirent = buf->previous;
54915 if (dirent) {
54916 if (__put_user(offset, &dirent->d_off))
54917 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
54918
54919 buf.current_dir = dirent;
54920 buf.previous = NULL;
54921 + buf.file = f.file;
54922 buf.count = count;
54923 buf.error = 0;
54924
54925 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
54926 error = buf.error;
54927 lastdirent = buf.previous;
54928 if (lastdirent) {
54929 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
54930 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
54931 if (__put_user(d_off, &lastdirent->d_off))
54932 error = -EFAULT;
54933 else
54934 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
54935 index 2b7882b..1c5ef48 100644
54936 --- a/fs/reiserfs/do_balan.c
54937 +++ b/fs/reiserfs/do_balan.c
54938 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
54939 return;
54940 }
54941
54942 - atomic_inc(&(fs_generation(tb->tb_sb)));
54943 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
54944 do_balance_starts(tb);
54945
54946 /* balance leaf returns 0 except if combining L R and S into
54947 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
54948 index e60e870..f40ac16 100644
54949 --- a/fs/reiserfs/procfs.c
54950 +++ b/fs/reiserfs/procfs.c
54951 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
54952 "SMALL_TAILS " : "NO_TAILS ",
54953 replay_only(sb) ? "REPLAY_ONLY " : "",
54954 convert_reiserfs(sb) ? "CONV " : "",
54955 - atomic_read(&r->s_generation_counter),
54956 + atomic_read_unchecked(&r->s_generation_counter),
54957 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
54958 SF(s_do_balance), SF(s_unneeded_left_neighbor),
54959 SF(s_good_search_by_key_reada), SF(s_bmaps),
54960 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
54961 index 157e474..65a6114 100644
54962 --- a/fs/reiserfs/reiserfs.h
54963 +++ b/fs/reiserfs/reiserfs.h
54964 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
54965 /* Comment? -Hans */
54966 wait_queue_head_t s_wait;
54967 /* To be obsoleted soon by per buffer seals.. -Hans */
54968 - atomic_t s_generation_counter; // increased by one every time the
54969 + atomic_unchecked_t s_generation_counter; // increased by one every time the
54970 // tree gets re-balanced
54971 unsigned long s_properties; /* File system properties. Currently holds
54972 on-disk FS format */
54973 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
54974 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
54975
54976 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
54977 -#define get_generation(s) atomic_read (&fs_generation(s))
54978 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
54979 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
54980 #define __fs_changed(gen,s) (gen != get_generation (s))
54981 #define fs_changed(gen,s) \
54982 diff --git a/fs/select.c b/fs/select.c
54983 index 2ef72d9..f213b17 100644
54984 --- a/fs/select.c
54985 +++ b/fs/select.c
54986 @@ -20,6 +20,7 @@
54987 #include <linux/export.h>
54988 #include <linux/slab.h>
54989 #include <linux/poll.h>
54990 +#include <linux/security.h>
54991 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
54992 #include <linux/file.h>
54993 #include <linux/fdtable.h>
54994 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
54995 struct poll_list *walk = head;
54996 unsigned long todo = nfds;
54997
54998 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
54999 if (nfds > rlimit(RLIMIT_NOFILE))
55000 return -EINVAL;
55001
55002 diff --git a/fs/seq_file.c b/fs/seq_file.c
55003 index f2bc3df..239d4f6 100644
55004 --- a/fs/seq_file.c
55005 +++ b/fs/seq_file.c
55006 @@ -10,6 +10,7 @@
55007 #include <linux/seq_file.h>
55008 #include <linux/slab.h>
55009 #include <linux/cred.h>
55010 +#include <linux/sched.h>
55011
55012 #include <asm/uaccess.h>
55013 #include <asm/page.h>
55014 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
55015 #ifdef CONFIG_USER_NS
55016 p->user_ns = file->f_cred->user_ns;
55017 #endif
55018 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55019 + p->exec_id = current->exec_id;
55020 +#endif
55021
55022 /*
55023 * Wrappers around seq_open(e.g. swaps_open) need to be
55024 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55025 return 0;
55026 }
55027 if (!m->buf) {
55028 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55029 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55030 if (!m->buf)
55031 return -ENOMEM;
55032 }
55033 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55034 Eoverflow:
55035 m->op->stop(m, p);
55036 kfree(m->buf);
55037 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55038 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55039 return !m->buf ? -ENOMEM : -EAGAIN;
55040 }
55041
55042 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55043
55044 /* grab buffer if we didn't have one */
55045 if (!m->buf) {
55046 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55047 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55048 if (!m->buf)
55049 goto Enomem;
55050 }
55051 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55052 goto Fill;
55053 m->op->stop(m, p);
55054 kfree(m->buf);
55055 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55056 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55057 if (!m->buf)
55058 goto Enomem;
55059 m->count = 0;
55060 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
55061 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
55062 void *data)
55063 {
55064 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
55065 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
55066 int res = -ENOMEM;
55067
55068 if (op) {
55069 diff --git a/fs/splice.c b/fs/splice.c
55070 index 6909d89..5b2e8f9 100644
55071 --- a/fs/splice.c
55072 +++ b/fs/splice.c
55073 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55074 pipe_lock(pipe);
55075
55076 for (;;) {
55077 - if (!pipe->readers) {
55078 + if (!atomic_read(&pipe->readers)) {
55079 send_sig(SIGPIPE, current, 0);
55080 if (!ret)
55081 ret = -EPIPE;
55082 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55083 do_wakeup = 0;
55084 }
55085
55086 - pipe->waiting_writers++;
55087 + atomic_inc(&pipe->waiting_writers);
55088 pipe_wait(pipe);
55089 - pipe->waiting_writers--;
55090 + atomic_dec(&pipe->waiting_writers);
55091 }
55092
55093 pipe_unlock(pipe);
55094 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
55095 old_fs = get_fs();
55096 set_fs(get_ds());
55097 /* The cast to a user pointer is valid due to the set_fs() */
55098 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
55099 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
55100 set_fs(old_fs);
55101
55102 return res;
55103 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
55104 old_fs = get_fs();
55105 set_fs(get_ds());
55106 /* The cast to a user pointer is valid due to the set_fs() */
55107 - res = vfs_write(file, (const char __user *)buf, count, &pos);
55108 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
55109 set_fs(old_fs);
55110
55111 return res;
55112 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
55113 goto err;
55114
55115 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
55116 - vec[i].iov_base = (void __user *) page_address(page);
55117 + vec[i].iov_base = (void __force_user *) page_address(page);
55118 vec[i].iov_len = this_len;
55119 spd.pages[i] = page;
55120 spd.nr_pages++;
55121 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
55122 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
55123 {
55124 while (!pipe->nrbufs) {
55125 - if (!pipe->writers)
55126 + if (!atomic_read(&pipe->writers))
55127 return 0;
55128
55129 - if (!pipe->waiting_writers && sd->num_spliced)
55130 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
55131 return 0;
55132
55133 if (sd->flags & SPLICE_F_NONBLOCK)
55134 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
55135 * out of the pipe right after the splice_to_pipe(). So set
55136 * PIPE_READERS appropriately.
55137 */
55138 - pipe->readers = 1;
55139 + atomic_set(&pipe->readers, 1);
55140
55141 current->splice_pipe = pipe;
55142 }
55143 @@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55144 ret = -ERESTARTSYS;
55145 break;
55146 }
55147 - if (!pipe->writers)
55148 + if (!atomic_read(&pipe->writers))
55149 break;
55150 - if (!pipe->waiting_writers) {
55151 + if (!atomic_read(&pipe->waiting_writers)) {
55152 if (flags & SPLICE_F_NONBLOCK) {
55153 ret = -EAGAIN;
55154 break;
55155 @@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55156 pipe_lock(pipe);
55157
55158 while (pipe->nrbufs >= pipe->buffers) {
55159 - if (!pipe->readers) {
55160 + if (!atomic_read(&pipe->readers)) {
55161 send_sig(SIGPIPE, current, 0);
55162 ret = -EPIPE;
55163 break;
55164 @@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55165 ret = -ERESTARTSYS;
55166 break;
55167 }
55168 - pipe->waiting_writers++;
55169 + atomic_inc(&pipe->waiting_writers);
55170 pipe_wait(pipe);
55171 - pipe->waiting_writers--;
55172 + atomic_dec(&pipe->waiting_writers);
55173 }
55174
55175 pipe_unlock(pipe);
55176 @@ -1823,14 +1823,14 @@ retry:
55177 pipe_double_lock(ipipe, opipe);
55178
55179 do {
55180 - if (!opipe->readers) {
55181 + if (!atomic_read(&opipe->readers)) {
55182 send_sig(SIGPIPE, current, 0);
55183 if (!ret)
55184 ret = -EPIPE;
55185 break;
55186 }
55187
55188 - if (!ipipe->nrbufs && !ipipe->writers)
55189 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
55190 break;
55191
55192 /*
55193 @@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55194 pipe_double_lock(ipipe, opipe);
55195
55196 do {
55197 - if (!opipe->readers) {
55198 + if (!atomic_read(&opipe->readers)) {
55199 send_sig(SIGPIPE, current, 0);
55200 if (!ret)
55201 ret = -EPIPE;
55202 @@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55203 * return EAGAIN if we have the potential of some data in the
55204 * future, otherwise just return 0
55205 */
55206 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
55207 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
55208 ret = -EAGAIN;
55209
55210 pipe_unlock(ipipe);
55211 diff --git a/fs/stat.c b/fs/stat.c
55212 index 14f4545..9b7f55b 100644
55213 --- a/fs/stat.c
55214 +++ b/fs/stat.c
55215 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
55216 stat->gid = inode->i_gid;
55217 stat->rdev = inode->i_rdev;
55218 stat->size = i_size_read(inode);
55219 - stat->atime = inode->i_atime;
55220 - stat->mtime = inode->i_mtime;
55221 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55222 + stat->atime = inode->i_ctime;
55223 + stat->mtime = inode->i_ctime;
55224 + } else {
55225 + stat->atime = inode->i_atime;
55226 + stat->mtime = inode->i_mtime;
55227 + }
55228 stat->ctime = inode->i_ctime;
55229 stat->blksize = (1 << inode->i_blkbits);
55230 stat->blocks = inode->i_blocks;
55231 @@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55232 if (retval)
55233 return retval;
55234
55235 - if (inode->i_op->getattr)
55236 - return inode->i_op->getattr(mnt, dentry, stat);
55237 + if (inode->i_op->getattr) {
55238 + retval = inode->i_op->getattr(mnt, dentry, stat);
55239 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55240 + stat->atime = stat->ctime;
55241 + stat->mtime = stat->ctime;
55242 + }
55243 + return retval;
55244 + }
55245
55246 generic_fillattr(inode, stat);
55247 return 0;
55248 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
55249 index 2fbdff6..5530a61 100644
55250 --- a/fs/sysfs/dir.c
55251 +++ b/fs/sysfs/dir.c
55252 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
55253 struct sysfs_dirent *sd;
55254 int rc;
55255
55256 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55257 + const char *parent_name = parent_sd->s_name;
55258 +
55259 + mode = S_IFDIR | S_IRWXU;
55260 +
55261 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
55262 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
55263 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
55264 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
55265 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
55266 +#endif
55267 +
55268 /* allocate */
55269 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
55270 if (!sd)
55271 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
55272 index 602f56d..6853db8 100644
55273 --- a/fs/sysfs/file.c
55274 +++ b/fs/sysfs/file.c
55275 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
55276
55277 struct sysfs_open_dirent {
55278 atomic_t refcnt;
55279 - atomic_t event;
55280 + atomic_unchecked_t event;
55281 wait_queue_head_t poll;
55282 struct list_head buffers; /* goes through sysfs_buffer.list */
55283 };
55284 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
55285 if (!sysfs_get_active(attr_sd))
55286 return -ENODEV;
55287
55288 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
55289 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
55290 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
55291
55292 sysfs_put_active(attr_sd);
55293 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
55294 return -ENOMEM;
55295
55296 atomic_set(&new_od->refcnt, 0);
55297 - atomic_set(&new_od->event, 1);
55298 + atomic_set_unchecked(&new_od->event, 1);
55299 init_waitqueue_head(&new_od->poll);
55300 INIT_LIST_HEAD(&new_od->buffers);
55301 goto retry;
55302 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
55303
55304 sysfs_put_active(attr_sd);
55305
55306 - if (buffer->event != atomic_read(&od->event))
55307 + if (buffer->event != atomic_read_unchecked(&od->event))
55308 goto trigger;
55309
55310 return DEFAULT_POLLMASK;
55311 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
55312
55313 od = sd->s_attr.open;
55314 if (od) {
55315 - atomic_inc(&od->event);
55316 + atomic_inc_unchecked(&od->event);
55317 wake_up_interruptible(&od->poll);
55318 }
55319
55320 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
55321 index 3c9eb56..9dea5be 100644
55322 --- a/fs/sysfs/symlink.c
55323 +++ b/fs/sysfs/symlink.c
55324 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55325
55326 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
55327 {
55328 - char *page = nd_get_link(nd);
55329 + const char *page = nd_get_link(nd);
55330 if (!IS_ERR(page))
55331 free_page((unsigned long)page);
55332 }
55333 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
55334 index c175b4d..8f36a16 100644
55335 --- a/fs/udf/misc.c
55336 +++ b/fs/udf/misc.c
55337 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
55338
55339 u8 udf_tag_checksum(const struct tag *t)
55340 {
55341 - u8 *data = (u8 *)t;
55342 + const u8 *data = (const u8 *)t;
55343 u8 checksum = 0;
55344 int i;
55345 for (i = 0; i < sizeof(struct tag); ++i)
55346 diff --git a/fs/utimes.c b/fs/utimes.c
55347 index f4fb7ec..3fe03c0 100644
55348 --- a/fs/utimes.c
55349 +++ b/fs/utimes.c
55350 @@ -1,6 +1,7 @@
55351 #include <linux/compiler.h>
55352 #include <linux/file.h>
55353 #include <linux/fs.h>
55354 +#include <linux/security.h>
55355 #include <linux/linkage.h>
55356 #include <linux/mount.h>
55357 #include <linux/namei.h>
55358 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
55359 goto mnt_drop_write_and_out;
55360 }
55361 }
55362 +
55363 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
55364 + error = -EACCES;
55365 + goto mnt_drop_write_and_out;
55366 + }
55367 +
55368 mutex_lock(&inode->i_mutex);
55369 error = notify_change(path->dentry, &newattrs);
55370 mutex_unlock(&inode->i_mutex);
55371 diff --git a/fs/xattr.c b/fs/xattr.c
55372 index 3377dff..4feded6 100644
55373 --- a/fs/xattr.c
55374 +++ b/fs/xattr.c
55375 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
55376 * Extended attribute SET operations
55377 */
55378 static long
55379 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
55380 +setxattr(struct path *path, const char __user *name, const void __user *value,
55381 size_t size, int flags)
55382 {
55383 int error;
55384 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
55385 posix_acl_fix_xattr_from_user(kvalue, size);
55386 }
55387
55388 - error = vfs_setxattr(d, kname, kvalue, size, flags);
55389 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
55390 + error = -EACCES;
55391 + goto out;
55392 + }
55393 +
55394 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
55395 out:
55396 if (vvalue)
55397 vfree(vvalue);
55398 @@ -377,7 +382,7 @@ retry:
55399 return error;
55400 error = mnt_want_write(path.mnt);
55401 if (!error) {
55402 - error = setxattr(path.dentry, name, value, size, flags);
55403 + error = setxattr(&path, name, value, size, flags);
55404 mnt_drop_write(path.mnt);
55405 }
55406 path_put(&path);
55407 @@ -401,7 +406,7 @@ retry:
55408 return error;
55409 error = mnt_want_write(path.mnt);
55410 if (!error) {
55411 - error = setxattr(path.dentry, name, value, size, flags);
55412 + error = setxattr(&path, name, value, size, flags);
55413 mnt_drop_write(path.mnt);
55414 }
55415 path_put(&path);
55416 @@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
55417 const void __user *,value, size_t, size, int, flags)
55418 {
55419 struct fd f = fdget(fd);
55420 - struct dentry *dentry;
55421 int error = -EBADF;
55422
55423 if (!f.file)
55424 return error;
55425 - dentry = f.file->f_path.dentry;
55426 - audit_inode(NULL, dentry, 0);
55427 + audit_inode(NULL, f.file->f_path.dentry, 0);
55428 error = mnt_want_write_file(f.file);
55429 if (!error) {
55430 - error = setxattr(dentry, name, value, size, flags);
55431 + error = setxattr(&f.file->f_path, name, value, size, flags);
55432 mnt_drop_write_file(f.file);
55433 }
55434 fdput(f);
55435 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
55436 index 9fbea87..6b19972 100644
55437 --- a/fs/xattr_acl.c
55438 +++ b/fs/xattr_acl.c
55439 @@ -76,8 +76,8 @@ struct posix_acl *
55440 posix_acl_from_xattr(struct user_namespace *user_ns,
55441 const void *value, size_t size)
55442 {
55443 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
55444 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
55445 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
55446 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
55447 int count;
55448 struct posix_acl *acl;
55449 struct posix_acl_entry *acl_e;
55450 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
55451 index 572a858..12a9b0d 100644
55452 --- a/fs/xfs/xfs_bmap.c
55453 +++ b/fs/xfs/xfs_bmap.c
55454 @@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
55455 int nmap,
55456 int ret_nmap);
55457 #else
55458 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
55459 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
55460 #endif /* DEBUG */
55461
55462 STATIC int
55463 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
55464 index 1b9fc3e..e1bdde0 100644
55465 --- a/fs/xfs/xfs_dir2_sf.c
55466 +++ b/fs/xfs/xfs_dir2_sf.c
55467 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
55468 }
55469
55470 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
55471 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
55472 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
55473 + char name[sfep->namelen];
55474 + memcpy(name, sfep->name, sfep->namelen);
55475 + if (filldir(dirent, name, sfep->namelen,
55476 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
55477 + *offset = off & 0x7fffffff;
55478 + return 0;
55479 + }
55480 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
55481 off & 0x7fffffff, ino, DT_UNKNOWN)) {
55482 *offset = off & 0x7fffffff;
55483 return 0;
55484 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
55485 index c1c3ef8..0952438 100644
55486 --- a/fs/xfs/xfs_ioctl.c
55487 +++ b/fs/xfs/xfs_ioctl.c
55488 @@ -127,7 +127,7 @@ xfs_find_handle(
55489 }
55490
55491 error = -EFAULT;
55492 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
55493 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
55494 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
55495 goto out_put;
55496
55497 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
55498 index d82efaa..0904a8e 100644
55499 --- a/fs/xfs/xfs_iops.c
55500 +++ b/fs/xfs/xfs_iops.c
55501 @@ -395,7 +395,7 @@ xfs_vn_put_link(
55502 struct nameidata *nd,
55503 void *p)
55504 {
55505 - char *s = nd_get_link(nd);
55506 + const char *s = nd_get_link(nd);
55507
55508 if (!IS_ERR(s))
55509 kfree(s);
55510 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
55511 new file mode 100644
55512 index 0000000..92247e4
55513 --- /dev/null
55514 +++ b/grsecurity/Kconfig
55515 @@ -0,0 +1,1021 @@
55516 +#
55517 +# grecurity configuration
55518 +#
55519 +menu "Memory Protections"
55520 +depends on GRKERNSEC
55521 +
55522 +config GRKERNSEC_KMEM
55523 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
55524 + default y if GRKERNSEC_CONFIG_AUTO
55525 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
55526 + help
55527 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
55528 + be written to or read from to modify or leak the contents of the running
55529 + kernel. /dev/port will also not be allowed to be opened and support
55530 + for /dev/cpu/*/msr will be removed. If you have module
55531 + support disabled, enabling this will close up five ways that are
55532 + currently used to insert malicious code into the running kernel.
55533 +
55534 + Even with all these features enabled, we still highly recommend that
55535 + you use the RBAC system, as it is still possible for an attacker to
55536 + modify the running kernel through privileged I/O granted by ioperm/iopl.
55537 +
55538 + If you are not using XFree86, you may be able to stop this additional
55539 + case by enabling the 'Disable privileged I/O' option. Though nothing
55540 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
55541 + but only to video memory, which is the only writing we allow in this
55542 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
55543 + not be allowed to mprotect it with PROT_WRITE later.
55544 + Enabling this feature will prevent the "cpupower" and "powertop" tools
55545 + from working.
55546 +
55547 + It is highly recommended that you say Y here if you meet all the
55548 + conditions above.
55549 +
55550 +config GRKERNSEC_VM86
55551 + bool "Restrict VM86 mode"
55552 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
55553 + depends on X86_32
55554 +
55555 + help
55556 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
55557 + make use of a special execution mode on 32bit x86 processors called
55558 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
55559 + video cards and will still work with this option enabled. The purpose
55560 + of the option is to prevent exploitation of emulation errors in
55561 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
55562 + Nearly all users should be able to enable this option.
55563 +
55564 +config GRKERNSEC_IO
55565 + bool "Disable privileged I/O"
55566 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
55567 + depends on X86
55568 + select RTC_CLASS
55569 + select RTC_INTF_DEV
55570 + select RTC_DRV_CMOS
55571 +
55572 + help
55573 + If you say Y here, all ioperm and iopl calls will return an error.
55574 + Ioperm and iopl can be used to modify the running kernel.
55575 + Unfortunately, some programs need this access to operate properly,
55576 + the most notable of which are XFree86 and hwclock. hwclock can be
55577 + remedied by having RTC support in the kernel, so real-time
55578 + clock support is enabled if this option is enabled, to ensure
55579 + that hwclock operates correctly. XFree86 still will not
55580 + operate correctly with this option enabled, so DO NOT CHOOSE Y
55581 + IF YOU USE XFree86. If you use XFree86 and you still want to
55582 + protect your kernel against modification, use the RBAC system.
55583 +
55584 +config GRKERNSEC_JIT_HARDEN
55585 + bool "Harden BPF JIT against spray attacks"
55586 + default y if GRKERNSEC_CONFIG_AUTO
55587 + depends on BPF_JIT
55588 + help
55589 + If you say Y here, the native code generated by the kernel's Berkeley
55590 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
55591 + attacks that attempt to fit attacker-beneficial instructions in
55592 + 32bit immediate fields of JIT-generated native instructions. The
55593 + attacker will generally aim to cause an unintended instruction sequence
55594 + of JIT-generated native code to execute by jumping into the middle of
55595 + a generated instruction. This feature effectively randomizes the 32bit
55596 + immediate constants present in the generated code to thwart such attacks.
55597 +
55598 + If you're using KERNEXEC, it's recommended that you enable this option
55599 + to supplement the hardening of the kernel.
55600 +
55601 +config GRKERNSEC_RAND_THREADSTACK
55602 + bool "Insert random gaps between thread stacks"
55603 + default y if GRKERNSEC_CONFIG_AUTO
55604 + depends on PAX_RANDMMAP && !PPC
55605 + help
55606 + If you say Y here, a random-sized gap will be enforced between allocated
55607 + thread stacks. Glibc's NPTL and other threading libraries that
55608 + pass MAP_STACK to the kernel for thread stack allocation are supported.
55609 + The implementation currently provides 8 bits of entropy for the gap.
55610 +
55611 + Many distributions do not compile threaded remote services with the
55612 + -fstack-check argument to GCC, causing the variable-sized stack-based
55613 + allocator, alloca(), to not probe the stack on allocation. This
55614 + permits an unbounded alloca() to skip over any guard page and potentially
55615 + modify another thread's stack reliably. An enforced random gap
55616 + reduces the reliability of such an attack and increases the chance
55617 + that such a read/write to another thread's stack instead lands in
55618 + an unmapped area, causing a crash and triggering grsecurity's
55619 + anti-bruteforcing logic.
55620 +
55621 +config GRKERNSEC_PROC_MEMMAP
55622 + bool "Harden ASLR against information leaks and entropy reduction"
55623 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
55624 + depends on PAX_NOEXEC || PAX_ASLR
55625 + help
55626 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
55627 + give no information about the addresses of its mappings if
55628 + PaX features that rely on random addresses are enabled on the task.
55629 + In addition to sanitizing this information and disabling other
55630 + dangerous sources of information, this option causes reads of sensitive
55631 + /proc/<pid> entries where the file descriptor was opened in a different
55632 + task than the one performing the read. Such attempts are logged.
55633 + This option also limits argv/env strings for suid/sgid binaries
55634 + to 512KB to prevent a complete exhaustion of the stack entropy provided
55635 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
55636 + binaries to prevent alternative mmap layouts from being abused.
55637 +
55638 + If you use PaX it is essential that you say Y here as it closes up
55639 + several holes that make full ASLR useless locally.
55640 +
55641 +config GRKERNSEC_BRUTE
55642 + bool "Deter exploit bruteforcing"
55643 + default y if GRKERNSEC_CONFIG_AUTO
55644 + help
55645 + If you say Y here, attempts to bruteforce exploits against forking
55646 + daemons such as apache or sshd, as well as against suid/sgid binaries
55647 + will be deterred. When a child of a forking daemon is killed by PaX
55648 + or crashes due to an illegal instruction or other suspicious signal,
55649 + the parent process will be delayed 30 seconds upon every subsequent
55650 + fork until the administrator is able to assess the situation and
55651 + restart the daemon.
55652 + In the suid/sgid case, the attempt is logged, the user has all their
55653 + processes terminated, and they are prevented from executing any further
55654 + processes for 15 minutes.
55655 + It is recommended that you also enable signal logging in the auditing
55656 + section so that logs are generated when a process triggers a suspicious
55657 + signal.
55658 + If the sysctl option is enabled, a sysctl option with name
55659 + "deter_bruteforce" is created.
55660 +
55661 +
55662 +config GRKERNSEC_MODHARDEN
55663 + bool "Harden module auto-loading"
55664 + default y if GRKERNSEC_CONFIG_AUTO
55665 + depends on MODULES
55666 + help
55667 + If you say Y here, module auto-loading in response to use of some
55668 + feature implemented by an unloaded module will be restricted to
55669 + root users. Enabling this option helps defend against attacks
55670 + by unprivileged users who abuse the auto-loading behavior to
55671 + cause a vulnerable module to load that is then exploited.
55672 +
55673 + If this option prevents a legitimate use of auto-loading for a
55674 + non-root user, the administrator can execute modprobe manually
55675 + with the exact name of the module mentioned in the alert log.
55676 + Alternatively, the administrator can add the module to the list
55677 + of modules loaded at boot by modifying init scripts.
55678 +
55679 + Modification of init scripts will most likely be needed on
55680 + Ubuntu servers with encrypted home directory support enabled,
55681 + as the first non-root user logging in will cause the ecb(aes),
55682 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
55683 +
55684 +config GRKERNSEC_HIDESYM
55685 + bool "Hide kernel symbols"
55686 + default y if GRKERNSEC_CONFIG_AUTO
55687 + select PAX_USERCOPY_SLABS
55688 + help
55689 + If you say Y here, getting information on loaded modules, and
55690 + displaying all kernel symbols through a syscall will be restricted
55691 + to users with CAP_SYS_MODULE. For software compatibility reasons,
55692 + /proc/kallsyms will be restricted to the root user. The RBAC
55693 + system can hide that entry even from root.
55694 +
55695 + This option also prevents leaking of kernel addresses through
55696 + several /proc entries.
55697 +
55698 + Note that this option is only effective provided the following
55699 + conditions are met:
55700 + 1) The kernel using grsecurity is not precompiled by some distribution
55701 + 2) You have also enabled GRKERNSEC_DMESG
55702 + 3) You are using the RBAC system and hiding other files such as your
55703 + kernel image and System.map. Alternatively, enabling this option
55704 + causes the permissions on /boot, /lib/modules, and the kernel
55705 + source directory to change at compile time to prevent
55706 + reading by non-root users.
55707 + If the above conditions are met, this option will aid in providing a
55708 + useful protection against local kernel exploitation of overflows
55709 + and arbitrary read/write vulnerabilities.
55710 +
55711 +config GRKERNSEC_KERN_LOCKOUT
55712 + bool "Active kernel exploit response"
55713 + default y if GRKERNSEC_CONFIG_AUTO
55714 + depends on X86 || ARM || PPC || SPARC
55715 + help
55716 + If you say Y here, when a PaX alert is triggered due to suspicious
55717 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
55718 + or an OOPS occurs due to bad memory accesses, instead of just
55719 + terminating the offending process (and potentially allowing
55720 + a subsequent exploit from the same user), we will take one of two
55721 + actions:
55722 + If the user was root, we will panic the system
55723 + If the user was non-root, we will log the attempt, terminate
55724 + all processes owned by the user, then prevent them from creating
55725 + any new processes until the system is restarted
55726 + This deters repeated kernel exploitation/bruteforcing attempts
55727 + and is useful for later forensics.
55728 +
55729 +endmenu
55730 +menu "Role Based Access Control Options"
55731 +depends on GRKERNSEC
55732 +
55733 +config GRKERNSEC_RBAC_DEBUG
55734 + bool
55735 +
55736 +config GRKERNSEC_NO_RBAC
55737 + bool "Disable RBAC system"
55738 + help
55739 + If you say Y here, the /dev/grsec device will be removed from the kernel,
55740 + preventing the RBAC system from being enabled. You should only say Y
55741 + here if you have no intention of using the RBAC system, so as to prevent
55742 + an attacker with root access from misusing the RBAC system to hide files
55743 + and processes when loadable module support and /dev/[k]mem have been
55744 + locked down.
55745 +
55746 +config GRKERNSEC_ACL_HIDEKERN
55747 + bool "Hide kernel processes"
55748 + help
55749 + If you say Y here, all kernel threads will be hidden to all
55750 + processes but those whose subject has the "view hidden processes"
55751 + flag.
55752 +
55753 +config GRKERNSEC_ACL_MAXTRIES
55754 + int "Maximum tries before password lockout"
55755 + default 3
55756 + help
55757 + This option enforces the maximum number of times a user can attempt
55758 + to authorize themselves with the grsecurity RBAC system before being
55759 + denied the ability to attempt authorization again for a specified time.
55760 + The lower the number, the harder it will be to brute-force a password.
55761 +
55762 +config GRKERNSEC_ACL_TIMEOUT
55763 + int "Time to wait after max password tries, in seconds"
55764 + default 30
55765 + help
55766 + This option specifies the time the user must wait after attempting to
55767 + authorize to the RBAC system with the maximum number of invalid
55768 + passwords. The higher the number, the harder it will be to brute-force
55769 + a password.
55770 +
55771 +endmenu
55772 +menu "Filesystem Protections"
55773 +depends on GRKERNSEC
55774 +
55775 +config GRKERNSEC_PROC
55776 + bool "Proc restrictions"
55777 + default y if GRKERNSEC_CONFIG_AUTO
55778 + help
55779 + If you say Y here, the permissions of the /proc filesystem
55780 + will be altered to enhance system security and privacy. You MUST
55781 + choose either a user only restriction or a user and group restriction.
55782 + Depending upon the option you choose, you can either restrict users to
55783 + see only the processes they themselves run, or choose a group that can
55784 + view all processes and files normally restricted to root if you choose
55785 + the "restrict to user only" option. NOTE: If you're running identd or
55786 + ntpd as a non-root user, you will have to run it as the group you
55787 + specify here.
55788 +
55789 +config GRKERNSEC_PROC_USER
55790 + bool "Restrict /proc to user only"
55791 + depends on GRKERNSEC_PROC
55792 + help
55793 + If you say Y here, non-root users will only be able to view their own
55794 + processes, and restricts them from viewing network-related information,
55795 + and viewing kernel symbol and module information.
55796 +
55797 +config GRKERNSEC_PROC_USERGROUP
55798 + bool "Allow special group"
55799 + default y if GRKERNSEC_CONFIG_AUTO
55800 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
55801 + help
55802 + If you say Y here, you will be able to select a group that will be
55803 + able to view all processes and network-related information. If you've
55804 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
55805 + remain hidden. This option is useful if you want to run identd as
55806 + a non-root user. The group you select may also be chosen at boot time
55807 + via "grsec_proc_gid=" on the kernel commandline.
55808 +
55809 +config GRKERNSEC_PROC_GID
55810 + int "GID for special group"
55811 + depends on GRKERNSEC_PROC_USERGROUP
55812 + default 1001
55813 +
55814 +config GRKERNSEC_PROC_ADD
55815 + bool "Additional restrictions"
55816 + default y if GRKERNSEC_CONFIG_AUTO
55817 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
55818 + help
55819 + If you say Y here, additional restrictions will be placed on
55820 + /proc that keep normal users from viewing device information and
55821 + slabinfo information that could be useful for exploits.
55822 +
55823 +config GRKERNSEC_LINK
55824 + bool "Linking restrictions"
55825 + default y if GRKERNSEC_CONFIG_AUTO
55826 + help
55827 + If you say Y here, /tmp race exploits will be prevented, since users
55828 + will no longer be able to follow symlinks owned by other users in
55829 + world-writable +t directories (e.g. /tmp), unless the owner of the
55830 + symlink is the owner of the directory. users will also not be
55831 + able to hardlink to files they do not own. If the sysctl option is
55832 + enabled, a sysctl option with name "linking_restrictions" is created.
55833 +
55834 +config GRKERNSEC_SYMLINKOWN
55835 + bool "Kernel-enforced SymlinksIfOwnerMatch"
55836 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
55837 + help
55838 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
55839 + that prevents it from being used as a security feature. As Apache
55840 + verifies the symlink by performing a stat() against the target of
55841 + the symlink before it is followed, an attacker can setup a symlink
55842 + to point to a same-owned file, then replace the symlink with one
55843 + that targets another user's file just after Apache "validates" the
55844 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
55845 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
55846 + will be in place for the group you specify. If the sysctl option
55847 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
55848 + created.
55849 +
55850 +config GRKERNSEC_SYMLINKOWN_GID
55851 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
55852 + depends on GRKERNSEC_SYMLINKOWN
55853 + default 1006
55854 + help
55855 + Setting this GID determines what group kernel-enforced
55856 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
55857 + is enabled, a sysctl option with name "symlinkown_gid" is created.
55858 +
55859 +config GRKERNSEC_FIFO
55860 + bool "FIFO restrictions"
55861 + default y if GRKERNSEC_CONFIG_AUTO
55862 + help
55863 + If you say Y here, users will not be able to write to FIFOs they don't
55864 + own in world-writable +t directories (e.g. /tmp), unless the owner of
55865 + the FIFO is the same owner of the directory it's held in. If the sysctl
55866 + option is enabled, a sysctl option with name "fifo_restrictions" is
55867 + created.
55868 +
55869 +config GRKERNSEC_SYSFS_RESTRICT
55870 + bool "Sysfs/debugfs restriction"
55871 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
55872 + depends on SYSFS
55873 + help
55874 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
55875 + any filesystem normally mounted under it (e.g. debugfs) will be
55876 + mostly accessible only by root. These filesystems generally provide access
55877 + to hardware and debug information that isn't appropriate for unprivileged
55878 + users of the system. Sysfs and debugfs have also become a large source
55879 + of new vulnerabilities, ranging from infoleaks to local compromise.
55880 + There has been very little oversight with an eye toward security involved
55881 + in adding new exporters of information to these filesystems, so their
55882 + use is discouraged.
55883 + For reasons of compatibility, a few directories have been whitelisted
55884 + for access by non-root users:
55885 + /sys/fs/selinux
55886 + /sys/fs/fuse
55887 + /sys/devices/system/cpu
55888 +
55889 +config GRKERNSEC_ROFS
55890 + bool "Runtime read-only mount protection"
55891 + help
55892 + If you say Y here, a sysctl option with name "romount_protect" will
55893 + be created. By setting this option to 1 at runtime, filesystems
55894 + will be protected in the following ways:
55895 + * No new writable mounts will be allowed
55896 + * Existing read-only mounts won't be able to be remounted read/write
55897 + * Write operations will be denied on all block devices
55898 + This option acts independently of grsec_lock: once it is set to 1,
55899 + it cannot be turned off. Therefore, please be mindful of the resulting
55900 + behavior if this option is enabled in an init script on a read-only
55901 + filesystem. This feature is mainly intended for secure embedded systems.
55902 +
55903 +config GRKERNSEC_DEVICE_SIDECHANNEL
55904 + bool "Eliminate stat/notify-based device sidechannels"
55905 + default y if GRKERNSEC_CONFIG_AUTO
55906 + help
55907 + If you say Y here, timing analyses on block or character
55908 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
55909 + will be thwarted for unprivileged users. If a process without
55910 + CAP_MKNOD stats such a device, the last access and last modify times
55911 + will match the device's create time. No access or modify events
55912 + will be triggered through inotify/dnotify/fanotify for such devices.
55913 + This feature will prevent attacks that may at a minimum
55914 + allow an attacker to determine the administrator's password length.
55915 +
55916 +config GRKERNSEC_CHROOT
55917 + bool "Chroot jail restrictions"
55918 + default y if GRKERNSEC_CONFIG_AUTO
55919 + help
55920 + If you say Y here, you will be able to choose several options that will
55921 + make breaking out of a chrooted jail much more difficult. If you
55922 + encounter no software incompatibilities with the following options, it
55923 + is recommended that you enable each one.
55924 +
55925 +config GRKERNSEC_CHROOT_MOUNT
55926 + bool "Deny mounts"
55927 + default y if GRKERNSEC_CONFIG_AUTO
55928 + depends on GRKERNSEC_CHROOT
55929 + help
55930 + If you say Y here, processes inside a chroot will not be able to
55931 + mount or remount filesystems. If the sysctl option is enabled, a
55932 + sysctl option with name "chroot_deny_mount" is created.
55933 +
55934 +config GRKERNSEC_CHROOT_DOUBLE
55935 + bool "Deny double-chroots"
55936 + default y if GRKERNSEC_CONFIG_AUTO
55937 + depends on GRKERNSEC_CHROOT
55938 + help
55939 + If you say Y here, processes inside a chroot will not be able to chroot
55940 + again outside the chroot. This is a widely used method of breaking
55941 + out of a chroot jail and should not be allowed. If the sysctl
55942 + option is enabled, a sysctl option with name
55943 + "chroot_deny_chroot" is created.
55944 +
55945 +config GRKERNSEC_CHROOT_PIVOT
55946 + bool "Deny pivot_root in chroot"
55947 + default y if GRKERNSEC_CONFIG_AUTO
55948 + depends on GRKERNSEC_CHROOT
55949 + help
55950 + If you say Y here, processes inside a chroot will not be able to use
55951 + a function called pivot_root() that was introduced in Linux 2.3.41. It
55952 + works similar to chroot in that it changes the root filesystem. This
55953 + function could be misused in a chrooted process to attempt to break out
55954 + of the chroot, and therefore should not be allowed. If the sysctl
55955 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
55956 + created.
55957 +
55958 +config GRKERNSEC_CHROOT_CHDIR
55959 + bool "Enforce chdir(\"/\") on all chroots"
55960 + default y if GRKERNSEC_CONFIG_AUTO
55961 + depends on GRKERNSEC_CHROOT
55962 + help
55963 + If you say Y here, the current working directory of all newly-chrooted
55964 + applications will be set to the the root directory of the chroot.
55965 + The man page on chroot(2) states:
55966 + Note that this call does not change the current working
55967 + directory, so that `.' can be outside the tree rooted at
55968 + `/'. In particular, the super-user can escape from a
55969 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
55970 +
55971 + It is recommended that you say Y here, since it's not known to break
55972 + any software. If the sysctl option is enabled, a sysctl option with
55973 + name "chroot_enforce_chdir" is created.
55974 +
55975 +config GRKERNSEC_CHROOT_CHMOD
55976 + bool "Deny (f)chmod +s"
55977 + default y if GRKERNSEC_CONFIG_AUTO
55978 + depends on GRKERNSEC_CHROOT
55979 + help
55980 + If you say Y here, processes inside a chroot will not be able to chmod
55981 + or fchmod files to make them have suid or sgid bits. This protects
55982 + against another published method of breaking a chroot. If the sysctl
55983 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
55984 + created.
55985 +
55986 +config GRKERNSEC_CHROOT_FCHDIR
55987 + bool "Deny fchdir out of chroot"
55988 + default y if GRKERNSEC_CONFIG_AUTO
55989 + depends on GRKERNSEC_CHROOT
55990 + help
55991 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
55992 + to a file descriptor of the chrooting process that points to a directory
55993 + outside the filesystem will be stopped. If the sysctl option
55994 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
55995 +
55996 +config GRKERNSEC_CHROOT_MKNOD
55997 + bool "Deny mknod"
55998 + default y if GRKERNSEC_CONFIG_AUTO
55999 + depends on GRKERNSEC_CHROOT
56000 + help
56001 + If you say Y here, processes inside a chroot will not be allowed to
56002 + mknod. The problem with using mknod inside a chroot is that it
56003 + would allow an attacker to create a device entry that is the same
56004 + as one on the physical root of your system, which could range from
56005 + anything from the console device to a device for your harddrive (which
56006 + they could then use to wipe the drive or steal data). It is recommended
56007 + that you say Y here, unless you run into software incompatibilities.
56008 + If the sysctl option is enabled, a sysctl option with name
56009 + "chroot_deny_mknod" is created.
56010 +
56011 +config GRKERNSEC_CHROOT_SHMAT
56012 + bool "Deny shmat() out of chroot"
56013 + default y if GRKERNSEC_CONFIG_AUTO
56014 + depends on GRKERNSEC_CHROOT
56015 + help
56016 + If you say Y here, processes inside a chroot will not be able to attach
56017 + to shared memory segments that were created outside of the chroot jail.
56018 + It is recommended that you say Y here. If the sysctl option is enabled,
56019 + a sysctl option with name "chroot_deny_shmat" is created.
56020 +
56021 +config GRKERNSEC_CHROOT_UNIX
56022 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
56023 + default y if GRKERNSEC_CONFIG_AUTO
56024 + depends on GRKERNSEC_CHROOT
56025 + help
56026 + If you say Y here, processes inside a chroot will not be able to
56027 + connect to abstract (meaning not belonging to a filesystem) Unix
56028 + domain sockets that were bound outside of a chroot. It is recommended
56029 + that you say Y here. If the sysctl option is enabled, a sysctl option
56030 + with name "chroot_deny_unix" is created.
56031 +
56032 +config GRKERNSEC_CHROOT_FINDTASK
56033 + bool "Protect outside processes"
56034 + default y if GRKERNSEC_CONFIG_AUTO
56035 + depends on GRKERNSEC_CHROOT
56036 + help
56037 + If you say Y here, processes inside a chroot will not be able to
56038 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
56039 + getsid, or view any process outside of the chroot. If the sysctl
56040 + option is enabled, a sysctl option with name "chroot_findtask" is
56041 + created.
56042 +
56043 +config GRKERNSEC_CHROOT_NICE
56044 + bool "Restrict priority changes"
56045 + default y if GRKERNSEC_CONFIG_AUTO
56046 + depends on GRKERNSEC_CHROOT
56047 + help
56048 + If you say Y here, processes inside a chroot will not be able to raise
56049 + the priority of processes in the chroot, or alter the priority of
56050 + processes outside the chroot. This provides more security than simply
56051 + removing CAP_SYS_NICE from the process' capability set. If the
56052 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
56053 + is created.
56054 +
56055 +config GRKERNSEC_CHROOT_SYSCTL
56056 + bool "Deny sysctl writes"
56057 + default y if GRKERNSEC_CONFIG_AUTO
56058 + depends on GRKERNSEC_CHROOT
56059 + help
56060 + If you say Y here, an attacker in a chroot will not be able to
56061 + write to sysctl entries, either by sysctl(2) or through a /proc
56062 + interface. It is strongly recommended that you say Y here. If the
56063 + sysctl option is enabled, a sysctl option with name
56064 + "chroot_deny_sysctl" is created.
56065 +
56066 +config GRKERNSEC_CHROOT_CAPS
56067 + bool "Capability restrictions"
56068 + default y if GRKERNSEC_CONFIG_AUTO
56069 + depends on GRKERNSEC_CHROOT
56070 + help
56071 + If you say Y here, the capabilities on all processes within a
56072 + chroot jail will be lowered to stop module insertion, raw i/o,
56073 + system and net admin tasks, rebooting the system, modifying immutable
56074 + files, modifying IPC owned by another, and changing the system time.
56075 + This is left an option because it can break some apps. Disable this
56076 + if your chrooted apps are having problems performing those kinds of
56077 + tasks. If the sysctl option is enabled, a sysctl option with
56078 + name "chroot_caps" is created.
56079 +
56080 +endmenu
56081 +menu "Kernel Auditing"
56082 +depends on GRKERNSEC
56083 +
56084 +config GRKERNSEC_AUDIT_GROUP
56085 + bool "Single group for auditing"
56086 + help
56087 + If you say Y here, the exec and chdir logging features will only operate
56088 + on a group you specify. This option is recommended if you only want to
56089 + watch certain users instead of having a large amount of logs from the
56090 + entire system. If the sysctl option is enabled, a sysctl option with
56091 + name "audit_group" is created.
56092 +
56093 +config GRKERNSEC_AUDIT_GID
56094 + int "GID for auditing"
56095 + depends on GRKERNSEC_AUDIT_GROUP
56096 + default 1007
56097 +
56098 +config GRKERNSEC_EXECLOG
56099 + bool "Exec logging"
56100 + help
56101 + If you say Y here, all execve() calls will be logged (since the
56102 + other exec*() calls are frontends to execve(), all execution
56103 + will be logged). Useful for shell-servers that like to keep track
56104 + of their users. If the sysctl option is enabled, a sysctl option with
56105 + name "exec_logging" is created.
56106 + WARNING: This option when enabled will produce a LOT of logs, especially
56107 + on an active system.
56108 +
56109 +config GRKERNSEC_RESLOG
56110 + bool "Resource logging"
56111 + default y if GRKERNSEC_CONFIG_AUTO
56112 + help
56113 + If you say Y here, all attempts to overstep resource limits will
56114 + be logged with the resource name, the requested size, and the current
56115 + limit. It is highly recommended that you say Y here. If the sysctl
56116 + option is enabled, a sysctl option with name "resource_logging" is
56117 + created. If the RBAC system is enabled, the sysctl value is ignored.
56118 +
56119 +config GRKERNSEC_CHROOT_EXECLOG
56120 + bool "Log execs within chroot"
56121 + help
56122 + If you say Y here, all executions inside a chroot jail will be logged
56123 + to syslog. This can cause a large amount of logs if certain
56124 + applications (eg. djb's daemontools) are installed on the system, and
56125 + is therefore left as an option. If the sysctl option is enabled, a
56126 + sysctl option with name "chroot_execlog" is created.
56127 +
56128 +config GRKERNSEC_AUDIT_PTRACE
56129 + bool "Ptrace logging"
56130 + help
56131 + If you say Y here, all attempts to attach to a process via ptrace
56132 + will be logged. If the sysctl option is enabled, a sysctl option
56133 + with name "audit_ptrace" is created.
56134 +
56135 +config GRKERNSEC_AUDIT_CHDIR
56136 + bool "Chdir logging"
56137 + help
56138 + If you say Y here, all chdir() calls will be logged. If the sysctl
56139 + option is enabled, a sysctl option with name "audit_chdir" is created.
56140 +
56141 +config GRKERNSEC_AUDIT_MOUNT
56142 + bool "(Un)Mount logging"
56143 + help
56144 + If you say Y here, all mounts and unmounts will be logged. If the
56145 + sysctl option is enabled, a sysctl option with name "audit_mount" is
56146 + created.
56147 +
56148 +config GRKERNSEC_SIGNAL
56149 + bool "Signal logging"
56150 + default y if GRKERNSEC_CONFIG_AUTO
56151 + help
56152 + If you say Y here, certain important signals will be logged, such as
56153 + SIGSEGV, which will as a result inform you of when a error in a program
56154 + occurred, which in some cases could mean a possible exploit attempt.
56155 + If the sysctl option is enabled, a sysctl option with name
56156 + "signal_logging" is created.
56157 +
56158 +config GRKERNSEC_FORKFAIL
56159 + bool "Fork failure logging"
56160 + help
56161 + If you say Y here, all failed fork() attempts will be logged.
56162 + This could suggest a fork bomb, or someone attempting to overstep
56163 + their process limit. If the sysctl option is enabled, a sysctl option
56164 + with name "forkfail_logging" is created.
56165 +
56166 +config GRKERNSEC_TIME
56167 + bool "Time change logging"
56168 + default y if GRKERNSEC_CONFIG_AUTO
56169 + help
56170 + If you say Y here, any changes of the system clock will be logged.
56171 + If the sysctl option is enabled, a sysctl option with name
56172 + "timechange_logging" is created.
56173 +
56174 +config GRKERNSEC_PROC_IPADDR
56175 + bool "/proc/<pid>/ipaddr support"
56176 + default y if GRKERNSEC_CONFIG_AUTO
56177 + help
56178 + If you say Y here, a new entry will be added to each /proc/<pid>
56179 + directory that contains the IP address of the person using the task.
56180 + The IP is carried across local TCP and AF_UNIX stream sockets.
56181 + This information can be useful for IDS/IPSes to perform remote response
56182 + to a local attack. The entry is readable by only the owner of the
56183 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
56184 + the RBAC system), and thus does not create privacy concerns.
56185 +
56186 +config GRKERNSEC_RWXMAP_LOG
56187 + bool 'Denied RWX mmap/mprotect logging'
56188 + default y if GRKERNSEC_CONFIG_AUTO
56189 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
56190 + help
56191 + If you say Y here, calls to mmap() and mprotect() with explicit
56192 + usage of PROT_WRITE and PROT_EXEC together will be logged when
56193 + denied by the PAX_MPROTECT feature. If the sysctl option is
56194 + enabled, a sysctl option with name "rwxmap_logging" is created.
56195 +
56196 +config GRKERNSEC_AUDIT_TEXTREL
56197 + bool 'ELF text relocations logging (READ HELP)'
56198 + depends on PAX_MPROTECT
56199 + help
56200 + If you say Y here, text relocations will be logged with the filename
56201 + of the offending library or binary. The purpose of the feature is
56202 + to help Linux distribution developers get rid of libraries and
56203 + binaries that need text relocations which hinder the future progress
56204 + of PaX. Only Linux distribution developers should say Y here, and
56205 + never on a production machine, as this option creates an information
56206 + leak that could aid an attacker in defeating the randomization of
56207 + a single memory region. If the sysctl option is enabled, a sysctl
56208 + option with name "audit_textrel" is created.
56209 +
56210 +endmenu
56211 +
56212 +menu "Executable Protections"
56213 +depends on GRKERNSEC
56214 +
56215 +config GRKERNSEC_DMESG
56216 + bool "Dmesg(8) restriction"
56217 + default y if GRKERNSEC_CONFIG_AUTO
56218 + help
56219 + If you say Y here, non-root users will not be able to use dmesg(8)
56220 + to view the contents of the kernel's circular log buffer.
56221 + The kernel's log buffer often contains kernel addresses and other
56222 + identifying information useful to an attacker in fingerprinting a
56223 + system for a targeted exploit.
56224 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
56225 + created.
56226 +
56227 +config GRKERNSEC_HARDEN_PTRACE
56228 + bool "Deter ptrace-based process snooping"
56229 + default y if GRKERNSEC_CONFIG_AUTO
56230 + help
56231 + If you say Y here, TTY sniffers and other malicious monitoring
56232 + programs implemented through ptrace will be defeated. If you
56233 + have been using the RBAC system, this option has already been
56234 + enabled for several years for all users, with the ability to make
56235 + fine-grained exceptions.
56236 +
56237 + This option only affects the ability of non-root users to ptrace
56238 + processes that are not a descendent of the ptracing process.
56239 + This means that strace ./binary and gdb ./binary will still work,
56240 + but attaching to arbitrary processes will not. If the sysctl
56241 + option is enabled, a sysctl option with name "harden_ptrace" is
56242 + created.
56243 +
56244 +config GRKERNSEC_PTRACE_READEXEC
56245 + bool "Require read access to ptrace sensitive binaries"
56246 + default y if GRKERNSEC_CONFIG_AUTO
56247 + help
56248 + If you say Y here, unprivileged users will not be able to ptrace unreadable
56249 + binaries. This option is useful in environments that
56250 + remove the read bits (e.g. file mode 4711) from suid binaries to
56251 + prevent infoleaking of their contents. This option adds
56252 + consistency to the use of that file mode, as the binary could normally
56253 + be read out when run without privileges while ptracing.
56254 +
56255 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
56256 + is created.
56257 +
56258 +config GRKERNSEC_SETXID
56259 + bool "Enforce consistent multithreaded privileges"
56260 + default y if GRKERNSEC_CONFIG_AUTO
56261 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
56262 + help
56263 + If you say Y here, a change from a root uid to a non-root uid
56264 + in a multithreaded application will cause the resulting uids,
56265 + gids, supplementary groups, and capabilities in that thread
56266 + to be propagated to the other threads of the process. In most
56267 + cases this is unnecessary, as glibc will emulate this behavior
56268 + on behalf of the application. Other libcs do not act in the
56269 + same way, allowing the other threads of the process to continue
56270 + running with root privileges. If the sysctl option is enabled,
56271 + a sysctl option with name "consistent_setxid" is created.
56272 +
56273 +config GRKERNSEC_TPE
56274 + bool "Trusted Path Execution (TPE)"
56275 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56276 + help
56277 + If you say Y here, you will be able to choose a gid to add to the
56278 + supplementary groups of users you want to mark as "untrusted."
56279 + These users will not be able to execute any files that are not in
56280 + root-owned directories writable only by root. If the sysctl option
56281 + is enabled, a sysctl option with name "tpe" is created.
56282 +
56283 +config GRKERNSEC_TPE_ALL
56284 + bool "Partially restrict all non-root users"
56285 + depends on GRKERNSEC_TPE
56286 + help
56287 + If you say Y here, all non-root users will be covered under
56288 + a weaker TPE restriction. This is separate from, and in addition to,
56289 + the main TPE options that you have selected elsewhere. Thus, if a
56290 + "trusted" GID is chosen, this restriction applies to even that GID.
56291 + Under this restriction, all non-root users will only be allowed to
56292 + execute files in directories they own that are not group or
56293 + world-writable, or in directories owned by root and writable only by
56294 + root. If the sysctl option is enabled, a sysctl option with name
56295 + "tpe_restrict_all" is created.
56296 +
56297 +config GRKERNSEC_TPE_INVERT
56298 + bool "Invert GID option"
56299 + depends on GRKERNSEC_TPE
56300 + help
56301 + If you say Y here, the group you specify in the TPE configuration will
56302 + decide what group TPE restrictions will be *disabled* for. This
56303 + option is useful if you want TPE restrictions to be applied to most
56304 + users on the system. If the sysctl option is enabled, a sysctl option
56305 + with name "tpe_invert" is created. Unlike other sysctl options, this
56306 + entry will default to on for backward-compatibility.
56307 +
56308 +config GRKERNSEC_TPE_GID
56309 + int
56310 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
56311 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
56312 +
56313 +config GRKERNSEC_TPE_UNTRUSTED_GID
56314 + int "GID for TPE-untrusted users"
56315 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
56316 + default 1005
56317 + help
56318 + Setting this GID determines what group TPE restrictions will be
56319 + *enabled* for. If the sysctl option is enabled, a sysctl option
56320 + with name "tpe_gid" is created.
56321 +
56322 +config GRKERNSEC_TPE_TRUSTED_GID
56323 + int "GID for TPE-trusted users"
56324 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
56325 + default 1005
56326 + help
56327 + Setting this GID determines what group TPE restrictions will be
56328 + *disabled* for. If the sysctl option is enabled, a sysctl option
56329 + with name "tpe_gid" is created.
56330 +
56331 +endmenu
56332 +menu "Network Protections"
56333 +depends on GRKERNSEC
56334 +
56335 +config GRKERNSEC_RANDNET
56336 + bool "Larger entropy pools"
56337 + default y if GRKERNSEC_CONFIG_AUTO
56338 + help
56339 + If you say Y here, the entropy pools used for many features of Linux
56340 + and grsecurity will be doubled in size. Since several grsecurity
56341 + features use additional randomness, it is recommended that you say Y
56342 + here. Saying Y here has a similar effect as modifying
56343 + /proc/sys/kernel/random/poolsize.
56344 +
56345 +config GRKERNSEC_BLACKHOLE
56346 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
56347 + default y if GRKERNSEC_CONFIG_AUTO
56348 + depends on NET
56349 + help
56350 + If you say Y here, neither TCP resets nor ICMP
56351 + destination-unreachable packets will be sent in response to packets
56352 + sent to ports for which no associated listening process exists.
56353 + This feature supports both IPV4 and IPV6 and exempts the
56354 + loopback interface from blackholing. Enabling this feature
56355 + makes a host more resilient to DoS attacks and reduces network
56356 + visibility against scanners.
56357 +
56358 + The blackhole feature as-implemented is equivalent to the FreeBSD
56359 + blackhole feature, as it prevents RST responses to all packets, not
56360 + just SYNs. Under most application behavior this causes no
56361 + problems, but applications (like haproxy) may not close certain
56362 + connections in a way that cleanly terminates them on the remote
56363 + end, leaving the remote host in LAST_ACK state. Because of this
56364 + side-effect and to prevent intentional LAST_ACK DoSes, this
56365 + feature also adds automatic mitigation against such attacks.
56366 + The mitigation drastically reduces the amount of time a socket
56367 + can spend in LAST_ACK state. If you're using haproxy and not
56368 + all servers it connects to have this option enabled, consider
56369 + disabling this feature on the haproxy host.
56370 +
56371 + If the sysctl option is enabled, two sysctl options with names
56372 + "ip_blackhole" and "lastack_retries" will be created.
56373 + While "ip_blackhole" takes the standard zero/non-zero on/off
56374 + toggle, "lastack_retries" uses the same kinds of values as
56375 + "tcp_retries1" and "tcp_retries2". The default value of 4
56376 + prevents a socket from lasting more than 45 seconds in LAST_ACK
56377 + state.
56378 +
56379 +config GRKERNSEC_NO_SIMULT_CONNECT
56380 + bool "Disable TCP Simultaneous Connect"
56381 + default y if GRKERNSEC_CONFIG_AUTO
56382 + depends on NET
56383 + help
56384 + If you say Y here, a feature by Willy Tarreau will be enabled that
56385 + removes a weakness in Linux's strict implementation of TCP that
56386 + allows two clients to connect to each other without either entering
56387 + a listening state. The weakness allows an attacker to easily prevent
56388 + a client from connecting to a known server provided the source port
56389 + for the connection is guessed correctly.
56390 +
56391 + As the weakness could be used to prevent an antivirus or IPS from
56392 + fetching updates, or prevent an SSL gateway from fetching a CRL,
56393 + it should be eliminated by enabling this option. Though Linux is
56394 + one of few operating systems supporting simultaneous connect, it
56395 + has no legitimate use in practice and is rarely supported by firewalls.
56396 +
56397 +config GRKERNSEC_SOCKET
56398 + bool "Socket restrictions"
56399 + depends on NET
56400 + help
56401 + If you say Y here, you will be able to choose from several options.
56402 + If you assign a GID on your system and add it to the supplementary
56403 + groups of users you want to restrict socket access to, this patch
56404 + will perform up to three things, based on the option(s) you choose.
56405 +
56406 +config GRKERNSEC_SOCKET_ALL
56407 + bool "Deny any sockets to group"
56408 + depends on GRKERNSEC_SOCKET
56409 + help
56410 + If you say Y here, you will be able to choose a GID of whose users will
56411 + be unable to connect to other hosts from your machine or run server
56412 + applications from your machine. If the sysctl option is enabled, a
56413 + sysctl option with name "socket_all" is created.
56414 +
56415 +config GRKERNSEC_SOCKET_ALL_GID
56416 + int "GID to deny all sockets for"
56417 + depends on GRKERNSEC_SOCKET_ALL
56418 + default 1004
56419 + help
56420 + Here you can choose the GID to disable socket access for. Remember to
56421 + add the users you want socket access disabled for to the GID
56422 + specified here. If the sysctl option is enabled, a sysctl option
56423 + with name "socket_all_gid" is created.
56424 +
56425 +config GRKERNSEC_SOCKET_CLIENT
56426 + bool "Deny client sockets to group"
56427 + depends on GRKERNSEC_SOCKET
56428 + help
56429 + If you say Y here, you will be able to choose a GID of whose users will
56430 + be unable to connect to other hosts from your machine, but will be
56431 + able to run servers. If this option is enabled, all users in the group
56432 + you specify will have to use passive mode when initiating ftp transfers
56433 + from the shell on your machine. If the sysctl option is enabled, a
56434 + sysctl option with name "socket_client" is created.
56435 +
56436 +config GRKERNSEC_SOCKET_CLIENT_GID
56437 + int "GID to deny client sockets for"
56438 + depends on GRKERNSEC_SOCKET_CLIENT
56439 + default 1003
56440 + help
56441 + Here you can choose the GID to disable client socket access for.
56442 + Remember to add the users you want client socket access disabled for to
56443 + the GID specified here. If the sysctl option is enabled, a sysctl
56444 + option with name "socket_client_gid" is created.
56445 +
56446 +config GRKERNSEC_SOCKET_SERVER
56447 + bool "Deny server sockets to group"
56448 + depends on GRKERNSEC_SOCKET
56449 + help
56450 + If you say Y here, you will be able to choose a GID of whose users will
56451 + be unable to run server applications from your machine. If the sysctl
56452 + option is enabled, a sysctl option with name "socket_server" is created.
56453 +
56454 +config GRKERNSEC_SOCKET_SERVER_GID
56455 + int "GID to deny server sockets for"
56456 + depends on GRKERNSEC_SOCKET_SERVER
56457 + default 1002
56458 + help
56459 + Here you can choose the GID to disable server socket access for.
56460 + Remember to add the users you want server socket access disabled for to
56461 + the GID specified here. If the sysctl option is enabled, a sysctl
56462 + option with name "socket_server_gid" is created.
56463 +
56464 +endmenu
56465 +menu "Sysctl Support"
56466 +depends on GRKERNSEC && SYSCTL
56467 +
56468 +config GRKERNSEC_SYSCTL
56469 + bool "Sysctl support"
56470 + default y if GRKERNSEC_CONFIG_AUTO
56471 + help
56472 + If you say Y here, you will be able to change the options that
56473 + grsecurity runs with at bootup, without having to recompile your
56474 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
56475 + to enable (1) or disable (0) various features. All the sysctl entries
56476 + are mutable until the "grsec_lock" entry is set to a non-zero value.
56477 + All features enabled in the kernel configuration are disabled at boot
56478 + if you do not say Y to the "Turn on features by default" option.
56479 + All options should be set at startup, and the grsec_lock entry should
56480 + be set to a non-zero value after all the options are set.
56481 + *THIS IS EXTREMELY IMPORTANT*
56482 +
56483 +config GRKERNSEC_SYSCTL_DISTRO
56484 + bool "Extra sysctl support for distro makers (READ HELP)"
56485 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
56486 + help
56487 + If you say Y here, additional sysctl options will be created
56488 + for features that affect processes running as root. Therefore,
56489 + it is critical when using this option that the grsec_lock entry be
56490 + enabled after boot. Only distros with prebuilt kernel packages
56491 + with this option enabled that can ensure grsec_lock is enabled
56492 + after boot should use this option.
56493 + *Failure to set grsec_lock after boot makes all grsec features
56494 + this option covers useless*
56495 +
56496 + Currently this option creates the following sysctl entries:
56497 + "Disable Privileged I/O": "disable_priv_io"
56498 +
56499 +config GRKERNSEC_SYSCTL_ON
56500 + bool "Turn on features by default"
56501 + default y if GRKERNSEC_CONFIG_AUTO
56502 + depends on GRKERNSEC_SYSCTL
56503 + help
56504 + If you say Y here, instead of having all features enabled in the
56505 + kernel configuration disabled at boot time, the features will be
56506 + enabled at boot time. It is recommended you say Y here unless
56507 + there is some reason you would want all sysctl-tunable features to
56508 + be disabled by default. As mentioned elsewhere, it is important
56509 + to enable the grsec_lock entry once you have finished modifying
56510 + the sysctl entries.
56511 +
56512 +endmenu
56513 +menu "Logging Options"
56514 +depends on GRKERNSEC
56515 +
56516 +config GRKERNSEC_FLOODTIME
56517 + int "Seconds in between log messages (minimum)"
56518 + default 10
56519 + help
56520 + This option allows you to enforce the number of seconds between
56521 + grsecurity log messages. The default should be suitable for most
56522 + people, however, if you choose to change it, choose a value small enough
56523 + to allow informative logs to be produced, but large enough to
56524 + prevent flooding.
56525 +
56526 +config GRKERNSEC_FLOODBURST
56527 + int "Number of messages in a burst (maximum)"
56528 + default 6
56529 + help
56530 + This option allows you to choose the maximum number of messages allowed
56531 + within the flood time interval you chose in a separate option. The
56532 + default should be suitable for most people, however if you find that
56533 + many of your logs are being interpreted as flooding, you may want to
56534 + raise this value.
56535 +
56536 +endmenu
56537 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
56538 new file mode 100644
56539 index 0000000..1b9afa9
56540 --- /dev/null
56541 +++ b/grsecurity/Makefile
56542 @@ -0,0 +1,38 @@
56543 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
56544 +# during 2001-2009 it has been completely redesigned by Brad Spengler
56545 +# into an RBAC system
56546 +#
56547 +# All code in this directory and various hooks inserted throughout the kernel
56548 +# are copyright Brad Spengler - Open Source Security, Inc., and released
56549 +# under the GPL v2 or higher
56550 +
56551 +KBUILD_CFLAGS += -Werror
56552 +
56553 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
56554 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
56555 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
56556 +
56557 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
56558 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
56559 + gracl_learn.o grsec_log.o
56560 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
56561 +
56562 +ifdef CONFIG_NET
56563 +obj-y += grsec_sock.o
56564 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
56565 +endif
56566 +
56567 +ifndef CONFIG_GRKERNSEC
56568 +obj-y += grsec_disabled.o
56569 +endif
56570 +
56571 +ifdef CONFIG_GRKERNSEC_HIDESYM
56572 +extra-y := grsec_hidesym.o
56573 +$(obj)/grsec_hidesym.o:
56574 + @-chmod -f 500 /boot
56575 + @-chmod -f 500 /lib/modules
56576 + @-chmod -f 500 /lib64/modules
56577 + @-chmod -f 500 /lib32/modules
56578 + @-chmod -f 700 .
56579 + @echo ' grsec: protected kernel image paths'
56580 +endif
56581 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
56582 new file mode 100644
56583 index 0000000..0767b2e
56584 --- /dev/null
56585 +++ b/grsecurity/gracl.c
56586 @@ -0,0 +1,4067 @@
56587 +#include <linux/kernel.h>
56588 +#include <linux/module.h>
56589 +#include <linux/sched.h>
56590 +#include <linux/mm.h>
56591 +#include <linux/file.h>
56592 +#include <linux/fs.h>
56593 +#include <linux/namei.h>
56594 +#include <linux/mount.h>
56595 +#include <linux/tty.h>
56596 +#include <linux/proc_fs.h>
56597 +#include <linux/lglock.h>
56598 +#include <linux/slab.h>
56599 +#include <linux/vmalloc.h>
56600 +#include <linux/types.h>
56601 +#include <linux/sysctl.h>
56602 +#include <linux/netdevice.h>
56603 +#include <linux/ptrace.h>
56604 +#include <linux/gracl.h>
56605 +#include <linux/gralloc.h>
56606 +#include <linux/security.h>
56607 +#include <linux/grinternal.h>
56608 +#include <linux/pid_namespace.h>
56609 +#include <linux/stop_machine.h>
56610 +#include <linux/fdtable.h>
56611 +#include <linux/percpu.h>
56612 +#include <linux/lglock.h>
56613 +#include <linux/hugetlb.h>
56614 +#include "../fs/mount.h"
56615 +
56616 +#include <asm/uaccess.h>
56617 +#include <asm/errno.h>
56618 +#include <asm/mman.h>
56619 +
56620 +extern struct lglock vfsmount_lock;
56621 +
56622 +static struct acl_role_db acl_role_set;
56623 +static struct name_db name_set;
56624 +static struct inodev_db inodev_set;
56625 +
56626 +/* for keeping track of userspace pointers used for subjects, so we
56627 + can share references in the kernel as well
56628 +*/
56629 +
56630 +static struct path real_root;
56631 +
56632 +static struct acl_subj_map_db subj_map_set;
56633 +
56634 +static struct acl_role_label *default_role;
56635 +
56636 +static struct acl_role_label *role_list;
56637 +
56638 +static u16 acl_sp_role_value;
56639 +
56640 +extern char *gr_shared_page[4];
56641 +static DEFINE_MUTEX(gr_dev_mutex);
56642 +DEFINE_RWLOCK(gr_inode_lock);
56643 +
56644 +struct gr_arg *gr_usermode;
56645 +
56646 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
56647 +
56648 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
56649 +extern void gr_clear_learn_entries(void);
56650 +
56651 +unsigned char *gr_system_salt;
56652 +unsigned char *gr_system_sum;
56653 +
56654 +static struct sprole_pw **acl_special_roles = NULL;
56655 +static __u16 num_sprole_pws = 0;
56656 +
56657 +static struct acl_role_label *kernel_role = NULL;
56658 +
56659 +static unsigned int gr_auth_attempts = 0;
56660 +static unsigned long gr_auth_expires = 0UL;
56661 +
56662 +#ifdef CONFIG_NET
56663 +extern struct vfsmount *sock_mnt;
56664 +#endif
56665 +
56666 +extern struct vfsmount *pipe_mnt;
56667 +extern struct vfsmount *shm_mnt;
56668 +
56669 +#ifdef CONFIG_HUGETLBFS
56670 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
56671 +#endif
56672 +
56673 +static struct acl_object_label *fakefs_obj_rw;
56674 +static struct acl_object_label *fakefs_obj_rwx;
56675 +
56676 +extern int gr_init_uidset(void);
56677 +extern void gr_free_uidset(void);
56678 +extern void gr_remove_uid(uid_t uid);
56679 +extern int gr_find_uid(uid_t uid);
56680 +
56681 +__inline__ int
56682 +gr_acl_is_enabled(void)
56683 +{
56684 + return (gr_status & GR_READY);
56685 +}
56686 +
56687 +#ifdef CONFIG_BTRFS_FS
56688 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56689 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56690 +#endif
56691 +
56692 +static inline dev_t __get_dev(const struct dentry *dentry)
56693 +{
56694 +#ifdef CONFIG_BTRFS_FS
56695 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56696 + return get_btrfs_dev_from_inode(dentry->d_inode);
56697 + else
56698 +#endif
56699 + return dentry->d_inode->i_sb->s_dev;
56700 +}
56701 +
56702 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56703 +{
56704 + return __get_dev(dentry);
56705 +}
56706 +
56707 +static char gr_task_roletype_to_char(struct task_struct *task)
56708 +{
56709 + switch (task->role->roletype &
56710 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
56711 + GR_ROLE_SPECIAL)) {
56712 + case GR_ROLE_DEFAULT:
56713 + return 'D';
56714 + case GR_ROLE_USER:
56715 + return 'U';
56716 + case GR_ROLE_GROUP:
56717 + return 'G';
56718 + case GR_ROLE_SPECIAL:
56719 + return 'S';
56720 + }
56721 +
56722 + return 'X';
56723 +}
56724 +
56725 +char gr_roletype_to_char(void)
56726 +{
56727 + return gr_task_roletype_to_char(current);
56728 +}
56729 +
56730 +__inline__ int
56731 +gr_acl_tpe_check(void)
56732 +{
56733 + if (unlikely(!(gr_status & GR_READY)))
56734 + return 0;
56735 + if (current->role->roletype & GR_ROLE_TPE)
56736 + return 1;
56737 + else
56738 + return 0;
56739 +}
56740 +
56741 +int
56742 +gr_handle_rawio(const struct inode *inode)
56743 +{
56744 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56745 + if (inode && S_ISBLK(inode->i_mode) &&
56746 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56747 + !capable(CAP_SYS_RAWIO))
56748 + return 1;
56749 +#endif
56750 + return 0;
56751 +}
56752 +
56753 +static int
56754 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
56755 +{
56756 + if (likely(lena != lenb))
56757 + return 0;
56758 +
56759 + return !memcmp(a, b, lena);
56760 +}
56761 +
56762 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
56763 +{
56764 + *buflen -= namelen;
56765 + if (*buflen < 0)
56766 + return -ENAMETOOLONG;
56767 + *buffer -= namelen;
56768 + memcpy(*buffer, str, namelen);
56769 + return 0;
56770 +}
56771 +
56772 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
56773 +{
56774 + return prepend(buffer, buflen, name->name, name->len);
56775 +}
56776 +
56777 +static int prepend_path(const struct path *path, struct path *root,
56778 + char **buffer, int *buflen)
56779 +{
56780 + struct dentry *dentry = path->dentry;
56781 + struct vfsmount *vfsmnt = path->mnt;
56782 + struct mount *mnt = real_mount(vfsmnt);
56783 + bool slash = false;
56784 + int error = 0;
56785 +
56786 + while (dentry != root->dentry || vfsmnt != root->mnt) {
56787 + struct dentry * parent;
56788 +
56789 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
56790 + /* Global root? */
56791 + if (!mnt_has_parent(mnt)) {
56792 + goto out;
56793 + }
56794 + dentry = mnt->mnt_mountpoint;
56795 + mnt = mnt->mnt_parent;
56796 + vfsmnt = &mnt->mnt;
56797 + continue;
56798 + }
56799 + parent = dentry->d_parent;
56800 + prefetch(parent);
56801 + spin_lock(&dentry->d_lock);
56802 + error = prepend_name(buffer, buflen, &dentry->d_name);
56803 + spin_unlock(&dentry->d_lock);
56804 + if (!error)
56805 + error = prepend(buffer, buflen, "/", 1);
56806 + if (error)
56807 + break;
56808 +
56809 + slash = true;
56810 + dentry = parent;
56811 + }
56812 +
56813 +out:
56814 + if (!error && !slash)
56815 + error = prepend(buffer, buflen, "/", 1);
56816 +
56817 + return error;
56818 +}
56819 +
56820 +/* this must be called with vfsmount_lock and rename_lock held */
56821 +
56822 +static char *__our_d_path(const struct path *path, struct path *root,
56823 + char *buf, int buflen)
56824 +{
56825 + char *res = buf + buflen;
56826 + int error;
56827 +
56828 + prepend(&res, &buflen, "\0", 1);
56829 + error = prepend_path(path, root, &res, &buflen);
56830 + if (error)
56831 + return ERR_PTR(error);
56832 +
56833 + return res;
56834 +}
56835 +
56836 +static char *
56837 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
56838 +{
56839 + char *retval;
56840 +
56841 + retval = __our_d_path(path, root, buf, buflen);
56842 + if (unlikely(IS_ERR(retval)))
56843 + retval = strcpy(buf, "<path too long>");
56844 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
56845 + retval[1] = '\0';
56846 +
56847 + return retval;
56848 +}
56849 +
56850 +static char *
56851 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
56852 + char *buf, int buflen)
56853 +{
56854 + struct path path;
56855 + char *res;
56856 +
56857 + path.dentry = (struct dentry *)dentry;
56858 + path.mnt = (struct vfsmount *)vfsmnt;
56859 +
56860 + /* we can use real_root.dentry, real_root.mnt, because this is only called
56861 + by the RBAC system */
56862 + res = gen_full_path(&path, &real_root, buf, buflen);
56863 +
56864 + return res;
56865 +}
56866 +
56867 +static char *
56868 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
56869 + char *buf, int buflen)
56870 +{
56871 + char *res;
56872 + struct path path;
56873 + struct path root;
56874 + struct task_struct *reaper = init_pid_ns.child_reaper;
56875 +
56876 + path.dentry = (struct dentry *)dentry;
56877 + path.mnt = (struct vfsmount *)vfsmnt;
56878 +
56879 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
56880 + get_fs_root(reaper->fs, &root);
56881 +
56882 + write_seqlock(&rename_lock);
56883 + br_read_lock(&vfsmount_lock);
56884 + res = gen_full_path(&path, &root, buf, buflen);
56885 + br_read_unlock(&vfsmount_lock);
56886 + write_sequnlock(&rename_lock);
56887 +
56888 + path_put(&root);
56889 + return res;
56890 +}
56891 +
56892 +static char *
56893 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
56894 +{
56895 + char *ret;
56896 + write_seqlock(&rename_lock);
56897 + br_read_lock(&vfsmount_lock);
56898 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
56899 + PAGE_SIZE);
56900 + br_read_unlock(&vfsmount_lock);
56901 + write_sequnlock(&rename_lock);
56902 + return ret;
56903 +}
56904 +
56905 +static char *
56906 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
56907 +{
56908 + char *ret;
56909 + char *buf;
56910 + int buflen;
56911 +
56912 + write_seqlock(&rename_lock);
56913 + br_read_lock(&vfsmount_lock);
56914 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
56915 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
56916 + buflen = (int)(ret - buf);
56917 + if (buflen >= 5)
56918 + prepend(&ret, &buflen, "/proc", 5);
56919 + else
56920 + ret = strcpy(buf, "<path too long>");
56921 + br_read_unlock(&vfsmount_lock);
56922 + write_sequnlock(&rename_lock);
56923 + return ret;
56924 +}
56925 +
56926 +char *
56927 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
56928 +{
56929 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
56930 + PAGE_SIZE);
56931 +}
56932 +
56933 +char *
56934 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
56935 +{
56936 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
56937 + PAGE_SIZE);
56938 +}
56939 +
56940 +char *
56941 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
56942 +{
56943 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
56944 + PAGE_SIZE);
56945 +}
56946 +
56947 +char *
56948 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
56949 +{
56950 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
56951 + PAGE_SIZE);
56952 +}
56953 +
56954 +char *
56955 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
56956 +{
56957 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
56958 + PAGE_SIZE);
56959 +}
56960 +
56961 +__inline__ __u32
56962 +to_gr_audit(const __u32 reqmode)
56963 +{
56964 + /* masks off auditable permission flags, then shifts them to create
56965 + auditing flags, and adds the special case of append auditing if
56966 + we're requesting write */
56967 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
56968 +}
56969 +
56970 +struct acl_subject_label *
56971 +lookup_subject_map(const struct acl_subject_label *userp)
56972 +{
56973 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
56974 + struct subject_map *match;
56975 +
56976 + match = subj_map_set.s_hash[index];
56977 +
56978 + while (match && match->user != userp)
56979 + match = match->next;
56980 +
56981 + if (match != NULL)
56982 + return match->kernel;
56983 + else
56984 + return NULL;
56985 +}
56986 +
56987 +static void
56988 +insert_subj_map_entry(struct subject_map *subjmap)
56989 +{
56990 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
56991 + struct subject_map **curr;
56992 +
56993 + subjmap->prev = NULL;
56994 +
56995 + curr = &subj_map_set.s_hash[index];
56996 + if (*curr != NULL)
56997 + (*curr)->prev = subjmap;
56998 +
56999 + subjmap->next = *curr;
57000 + *curr = subjmap;
57001 +
57002 + return;
57003 +}
57004 +
57005 +static struct acl_role_label *
57006 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
57007 + const gid_t gid)
57008 +{
57009 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
57010 + struct acl_role_label *match;
57011 + struct role_allowed_ip *ipp;
57012 + unsigned int x;
57013 + u32 curr_ip = task->signal->curr_ip;
57014 +
57015 + task->signal->saved_ip = curr_ip;
57016 +
57017 + match = acl_role_set.r_hash[index];
57018 +
57019 + while (match) {
57020 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
57021 + for (x = 0; x < match->domain_child_num; x++) {
57022 + if (match->domain_children[x] == uid)
57023 + goto found;
57024 + }
57025 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
57026 + break;
57027 + match = match->next;
57028 + }
57029 +found:
57030 + if (match == NULL) {
57031 + try_group:
57032 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
57033 + match = acl_role_set.r_hash[index];
57034 +
57035 + while (match) {
57036 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
57037 + for (x = 0; x < match->domain_child_num; x++) {
57038 + if (match->domain_children[x] == gid)
57039 + goto found2;
57040 + }
57041 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
57042 + break;
57043 + match = match->next;
57044 + }
57045 +found2:
57046 + if (match == NULL)
57047 + match = default_role;
57048 + if (match->allowed_ips == NULL)
57049 + return match;
57050 + else {
57051 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57052 + if (likely
57053 + ((ntohl(curr_ip) & ipp->netmask) ==
57054 + (ntohl(ipp->addr) & ipp->netmask)))
57055 + return match;
57056 + }
57057 + match = default_role;
57058 + }
57059 + } else if (match->allowed_ips == NULL) {
57060 + return match;
57061 + } else {
57062 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57063 + if (likely
57064 + ((ntohl(curr_ip) & ipp->netmask) ==
57065 + (ntohl(ipp->addr) & ipp->netmask)))
57066 + return match;
57067 + }
57068 + goto try_group;
57069 + }
57070 +
57071 + return match;
57072 +}
57073 +
57074 +struct acl_subject_label *
57075 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
57076 + const struct acl_role_label *role)
57077 +{
57078 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57079 + struct acl_subject_label *match;
57080 +
57081 + match = role->subj_hash[index];
57082 +
57083 + while (match && (match->inode != ino || match->device != dev ||
57084 + (match->mode & GR_DELETED))) {
57085 + match = match->next;
57086 + }
57087 +
57088 + if (match && !(match->mode & GR_DELETED))
57089 + return match;
57090 + else
57091 + return NULL;
57092 +}
57093 +
57094 +struct acl_subject_label *
57095 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
57096 + const struct acl_role_label *role)
57097 +{
57098 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57099 + struct acl_subject_label *match;
57100 +
57101 + match = role->subj_hash[index];
57102 +
57103 + while (match && (match->inode != ino || match->device != dev ||
57104 + !(match->mode & GR_DELETED))) {
57105 + match = match->next;
57106 + }
57107 +
57108 + if (match && (match->mode & GR_DELETED))
57109 + return match;
57110 + else
57111 + return NULL;
57112 +}
57113 +
57114 +static struct acl_object_label *
57115 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
57116 + const struct acl_subject_label *subj)
57117 +{
57118 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57119 + struct acl_object_label *match;
57120 +
57121 + match = subj->obj_hash[index];
57122 +
57123 + while (match && (match->inode != ino || match->device != dev ||
57124 + (match->mode & GR_DELETED))) {
57125 + match = match->next;
57126 + }
57127 +
57128 + if (match && !(match->mode & GR_DELETED))
57129 + return match;
57130 + else
57131 + return NULL;
57132 +}
57133 +
57134 +static struct acl_object_label *
57135 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
57136 + const struct acl_subject_label *subj)
57137 +{
57138 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57139 + struct acl_object_label *match;
57140 +
57141 + match = subj->obj_hash[index];
57142 +
57143 + while (match && (match->inode != ino || match->device != dev ||
57144 + !(match->mode & GR_DELETED))) {
57145 + match = match->next;
57146 + }
57147 +
57148 + if (match && (match->mode & GR_DELETED))
57149 + return match;
57150 +
57151 + match = subj->obj_hash[index];
57152 +
57153 + while (match && (match->inode != ino || match->device != dev ||
57154 + (match->mode & GR_DELETED))) {
57155 + match = match->next;
57156 + }
57157 +
57158 + if (match && !(match->mode & GR_DELETED))
57159 + return match;
57160 + else
57161 + return NULL;
57162 +}
57163 +
57164 +static struct name_entry *
57165 +lookup_name_entry(const char *name)
57166 +{
57167 + unsigned int len = strlen(name);
57168 + unsigned int key = full_name_hash(name, len);
57169 + unsigned int index = key % name_set.n_size;
57170 + struct name_entry *match;
57171 +
57172 + match = name_set.n_hash[index];
57173 +
57174 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
57175 + match = match->next;
57176 +
57177 + return match;
57178 +}
57179 +
57180 +static struct name_entry *
57181 +lookup_name_entry_create(const char *name)
57182 +{
57183 + unsigned int len = strlen(name);
57184 + unsigned int key = full_name_hash(name, len);
57185 + unsigned int index = key % name_set.n_size;
57186 + struct name_entry *match;
57187 +
57188 + match = name_set.n_hash[index];
57189 +
57190 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57191 + !match->deleted))
57192 + match = match->next;
57193 +
57194 + if (match && match->deleted)
57195 + return match;
57196 +
57197 + match = name_set.n_hash[index];
57198 +
57199 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57200 + match->deleted))
57201 + match = match->next;
57202 +
57203 + if (match && !match->deleted)
57204 + return match;
57205 + else
57206 + return NULL;
57207 +}
57208 +
57209 +static struct inodev_entry *
57210 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
57211 +{
57212 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
57213 + struct inodev_entry *match;
57214 +
57215 + match = inodev_set.i_hash[index];
57216 +
57217 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
57218 + match = match->next;
57219 +
57220 + return match;
57221 +}
57222 +
57223 +static void
57224 +insert_inodev_entry(struct inodev_entry *entry)
57225 +{
57226 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
57227 + inodev_set.i_size);
57228 + struct inodev_entry **curr;
57229 +
57230 + entry->prev = NULL;
57231 +
57232 + curr = &inodev_set.i_hash[index];
57233 + if (*curr != NULL)
57234 + (*curr)->prev = entry;
57235 +
57236 + entry->next = *curr;
57237 + *curr = entry;
57238 +
57239 + return;
57240 +}
57241 +
57242 +static void
57243 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
57244 +{
57245 + unsigned int index =
57246 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
57247 + struct acl_role_label **curr;
57248 + struct acl_role_label *tmp, *tmp2;
57249 +
57250 + curr = &acl_role_set.r_hash[index];
57251 +
57252 + /* simple case, slot is empty, just set it to our role */
57253 + if (*curr == NULL) {
57254 + *curr = role;
57255 + } else {
57256 + /* example:
57257 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
57258 + 2 -> 3
57259 + */
57260 + /* first check to see if we can already be reached via this slot */
57261 + tmp = *curr;
57262 + while (tmp && tmp != role)
57263 + tmp = tmp->next;
57264 + if (tmp == role) {
57265 + /* we don't need to add ourselves to this slot's chain */
57266 + return;
57267 + }
57268 + /* we need to add ourselves to this chain, two cases */
57269 + if (role->next == NULL) {
57270 + /* simple case, append the current chain to our role */
57271 + role->next = *curr;
57272 + *curr = role;
57273 + } else {
57274 + /* 1 -> 2 -> 3 -> 4
57275 + 2 -> 3 -> 4
57276 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
57277 + */
57278 + /* trickier case: walk our role's chain until we find
57279 + the role for the start of the current slot's chain */
57280 + tmp = role;
57281 + tmp2 = *curr;
57282 + while (tmp->next && tmp->next != tmp2)
57283 + tmp = tmp->next;
57284 + if (tmp->next == tmp2) {
57285 + /* from example above, we found 3, so just
57286 + replace this slot's chain with ours */
57287 + *curr = role;
57288 + } else {
57289 + /* we didn't find a subset of our role's chain
57290 + in the current slot's chain, so append their
57291 + chain to ours, and set us as the first role in
57292 + the slot's chain
57293 +
57294 + we could fold this case with the case above,
57295 + but making it explicit for clarity
57296 + */
57297 + tmp->next = tmp2;
57298 + *curr = role;
57299 + }
57300 + }
57301 + }
57302 +
57303 + return;
57304 +}
57305 +
57306 +static void
57307 +insert_acl_role_label(struct acl_role_label *role)
57308 +{
57309 + int i;
57310 +
57311 + if (role_list == NULL) {
57312 + role_list = role;
57313 + role->prev = NULL;
57314 + } else {
57315 + role->prev = role_list;
57316 + role_list = role;
57317 + }
57318 +
57319 + /* used for hash chains */
57320 + role->next = NULL;
57321 +
57322 + if (role->roletype & GR_ROLE_DOMAIN) {
57323 + for (i = 0; i < role->domain_child_num; i++)
57324 + __insert_acl_role_label(role, role->domain_children[i]);
57325 + } else
57326 + __insert_acl_role_label(role, role->uidgid);
57327 +}
57328 +
57329 +static int
57330 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
57331 +{
57332 + struct name_entry **curr, *nentry;
57333 + struct inodev_entry *ientry;
57334 + unsigned int len = strlen(name);
57335 + unsigned int key = full_name_hash(name, len);
57336 + unsigned int index = key % name_set.n_size;
57337 +
57338 + curr = &name_set.n_hash[index];
57339 +
57340 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
57341 + curr = &((*curr)->next);
57342 +
57343 + if (*curr != NULL)
57344 + return 1;
57345 +
57346 + nentry = acl_alloc(sizeof (struct name_entry));
57347 + if (nentry == NULL)
57348 + return 0;
57349 + ientry = acl_alloc(sizeof (struct inodev_entry));
57350 + if (ientry == NULL)
57351 + return 0;
57352 + ientry->nentry = nentry;
57353 +
57354 + nentry->key = key;
57355 + nentry->name = name;
57356 + nentry->inode = inode;
57357 + nentry->device = device;
57358 + nentry->len = len;
57359 + nentry->deleted = deleted;
57360 +
57361 + nentry->prev = NULL;
57362 + curr = &name_set.n_hash[index];
57363 + if (*curr != NULL)
57364 + (*curr)->prev = nentry;
57365 + nentry->next = *curr;
57366 + *curr = nentry;
57367 +
57368 + /* insert us into the table searchable by inode/dev */
57369 + insert_inodev_entry(ientry);
57370 +
57371 + return 1;
57372 +}
57373 +
57374 +static void
57375 +insert_acl_obj_label(struct acl_object_label *obj,
57376 + struct acl_subject_label *subj)
57377 +{
57378 + unsigned int index =
57379 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
57380 + struct acl_object_label **curr;
57381 +
57382 +
57383 + obj->prev = NULL;
57384 +
57385 + curr = &subj->obj_hash[index];
57386 + if (*curr != NULL)
57387 + (*curr)->prev = obj;
57388 +
57389 + obj->next = *curr;
57390 + *curr = obj;
57391 +
57392 + return;
57393 +}
57394 +
57395 +static void
57396 +insert_acl_subj_label(struct acl_subject_label *obj,
57397 + struct acl_role_label *role)
57398 +{
57399 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
57400 + struct acl_subject_label **curr;
57401 +
57402 + obj->prev = NULL;
57403 +
57404 + curr = &role->subj_hash[index];
57405 + if (*curr != NULL)
57406 + (*curr)->prev = obj;
57407 +
57408 + obj->next = *curr;
57409 + *curr = obj;
57410 +
57411 + return;
57412 +}
57413 +
57414 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
57415 +
57416 +static void *
57417 +create_table(__u32 * len, int elementsize)
57418 +{
57419 + unsigned int table_sizes[] = {
57420 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
57421 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
57422 + 4194301, 8388593, 16777213, 33554393, 67108859
57423 + };
57424 + void *newtable = NULL;
57425 + unsigned int pwr = 0;
57426 +
57427 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
57428 + table_sizes[pwr] <= *len)
57429 + pwr++;
57430 +
57431 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
57432 + return newtable;
57433 +
57434 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
57435 + newtable =
57436 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
57437 + else
57438 + newtable = vmalloc(table_sizes[pwr] * elementsize);
57439 +
57440 + *len = table_sizes[pwr];
57441 +
57442 + return newtable;
57443 +}
57444 +
57445 +static int
57446 +init_variables(const struct gr_arg *arg)
57447 +{
57448 + struct task_struct *reaper = init_pid_ns.child_reaper;
57449 + unsigned int stacksize;
57450 +
57451 + subj_map_set.s_size = arg->role_db.num_subjects;
57452 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
57453 + name_set.n_size = arg->role_db.num_objects;
57454 + inodev_set.i_size = arg->role_db.num_objects;
57455 +
57456 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
57457 + !name_set.n_size || !inodev_set.i_size)
57458 + return 1;
57459 +
57460 + if (!gr_init_uidset())
57461 + return 1;
57462 +
57463 + /* set up the stack that holds allocation info */
57464 +
57465 + stacksize = arg->role_db.num_pointers + 5;
57466 +
57467 + if (!acl_alloc_stack_init(stacksize))
57468 + return 1;
57469 +
57470 + /* grab reference for the real root dentry and vfsmount */
57471 + get_fs_root(reaper->fs, &real_root);
57472 +
57473 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57474 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
57475 +#endif
57476 +
57477 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
57478 + if (fakefs_obj_rw == NULL)
57479 + return 1;
57480 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
57481 +
57482 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
57483 + if (fakefs_obj_rwx == NULL)
57484 + return 1;
57485 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
57486 +
57487 + subj_map_set.s_hash =
57488 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
57489 + acl_role_set.r_hash =
57490 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
57491 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
57492 + inodev_set.i_hash =
57493 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
57494 +
57495 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
57496 + !name_set.n_hash || !inodev_set.i_hash)
57497 + return 1;
57498 +
57499 + memset(subj_map_set.s_hash, 0,
57500 + sizeof(struct subject_map *) * subj_map_set.s_size);
57501 + memset(acl_role_set.r_hash, 0,
57502 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
57503 + memset(name_set.n_hash, 0,
57504 + sizeof (struct name_entry *) * name_set.n_size);
57505 + memset(inodev_set.i_hash, 0,
57506 + sizeof (struct inodev_entry *) * inodev_set.i_size);
57507 +
57508 + return 0;
57509 +}
57510 +
57511 +/* free information not needed after startup
57512 + currently contains user->kernel pointer mappings for subjects
57513 +*/
57514 +
57515 +static void
57516 +free_init_variables(void)
57517 +{
57518 + __u32 i;
57519 +
57520 + if (subj_map_set.s_hash) {
57521 + for (i = 0; i < subj_map_set.s_size; i++) {
57522 + if (subj_map_set.s_hash[i]) {
57523 + kfree(subj_map_set.s_hash[i]);
57524 + subj_map_set.s_hash[i] = NULL;
57525 + }
57526 + }
57527 +
57528 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
57529 + PAGE_SIZE)
57530 + kfree(subj_map_set.s_hash);
57531 + else
57532 + vfree(subj_map_set.s_hash);
57533 + }
57534 +
57535 + return;
57536 +}
57537 +
57538 +static void
57539 +free_variables(void)
57540 +{
57541 + struct acl_subject_label *s;
57542 + struct acl_role_label *r;
57543 + struct task_struct *task, *task2;
57544 + unsigned int x;
57545 +
57546 + gr_clear_learn_entries();
57547 +
57548 + read_lock(&tasklist_lock);
57549 + do_each_thread(task2, task) {
57550 + task->acl_sp_role = 0;
57551 + task->acl_role_id = 0;
57552 + task->acl = NULL;
57553 + task->role = NULL;
57554 + } while_each_thread(task2, task);
57555 + read_unlock(&tasklist_lock);
57556 +
57557 + /* release the reference to the real root dentry and vfsmount */
57558 + path_put(&real_root);
57559 + memset(&real_root, 0, sizeof(real_root));
57560 +
57561 + /* free all object hash tables */
57562 +
57563 + FOR_EACH_ROLE_START(r)
57564 + if (r->subj_hash == NULL)
57565 + goto next_role;
57566 + FOR_EACH_SUBJECT_START(r, s, x)
57567 + if (s->obj_hash == NULL)
57568 + break;
57569 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
57570 + kfree(s->obj_hash);
57571 + else
57572 + vfree(s->obj_hash);
57573 + FOR_EACH_SUBJECT_END(s, x)
57574 + FOR_EACH_NESTED_SUBJECT_START(r, s)
57575 + if (s->obj_hash == NULL)
57576 + break;
57577 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
57578 + kfree(s->obj_hash);
57579 + else
57580 + vfree(s->obj_hash);
57581 + FOR_EACH_NESTED_SUBJECT_END(s)
57582 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
57583 + kfree(r->subj_hash);
57584 + else
57585 + vfree(r->subj_hash);
57586 + r->subj_hash = NULL;
57587 +next_role:
57588 + FOR_EACH_ROLE_END(r)
57589 +
57590 + acl_free_all();
57591 +
57592 + if (acl_role_set.r_hash) {
57593 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
57594 + PAGE_SIZE)
57595 + kfree(acl_role_set.r_hash);
57596 + else
57597 + vfree(acl_role_set.r_hash);
57598 + }
57599 + if (name_set.n_hash) {
57600 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
57601 + PAGE_SIZE)
57602 + kfree(name_set.n_hash);
57603 + else
57604 + vfree(name_set.n_hash);
57605 + }
57606 +
57607 + if (inodev_set.i_hash) {
57608 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
57609 + PAGE_SIZE)
57610 + kfree(inodev_set.i_hash);
57611 + else
57612 + vfree(inodev_set.i_hash);
57613 + }
57614 +
57615 + gr_free_uidset();
57616 +
57617 + memset(&name_set, 0, sizeof (struct name_db));
57618 + memset(&inodev_set, 0, sizeof (struct inodev_db));
57619 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
57620 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
57621 +
57622 + default_role = NULL;
57623 + kernel_role = NULL;
57624 + role_list = NULL;
57625 +
57626 + return;
57627 +}
57628 +
57629 +static __u32
57630 +count_user_objs(struct acl_object_label *userp)
57631 +{
57632 + struct acl_object_label o_tmp;
57633 + __u32 num = 0;
57634 +
57635 + while (userp) {
57636 + if (copy_from_user(&o_tmp, userp,
57637 + sizeof (struct acl_object_label)))
57638 + break;
57639 +
57640 + userp = o_tmp.prev;
57641 + num++;
57642 + }
57643 +
57644 + return num;
57645 +}
57646 +
57647 +static struct acl_subject_label *
57648 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
57649 +
57650 +static int
57651 +copy_user_glob(struct acl_object_label *obj)
57652 +{
57653 + struct acl_object_label *g_tmp, **guser;
57654 + unsigned int len;
57655 + char *tmp;
57656 +
57657 + if (obj->globbed == NULL)
57658 + return 0;
57659 +
57660 + guser = &obj->globbed;
57661 + while (*guser) {
57662 + g_tmp = (struct acl_object_label *)
57663 + acl_alloc(sizeof (struct acl_object_label));
57664 + if (g_tmp == NULL)
57665 + return -ENOMEM;
57666 +
57667 + if (copy_from_user(g_tmp, *guser,
57668 + sizeof (struct acl_object_label)))
57669 + return -EFAULT;
57670 +
57671 + len = strnlen_user(g_tmp->filename, PATH_MAX);
57672 +
57673 + if (!len || len >= PATH_MAX)
57674 + return -EINVAL;
57675 +
57676 + if ((tmp = (char *) acl_alloc(len)) == NULL)
57677 + return -ENOMEM;
57678 +
57679 + if (copy_from_user(tmp, g_tmp->filename, len))
57680 + return -EFAULT;
57681 + tmp[len-1] = '\0';
57682 + g_tmp->filename = tmp;
57683 +
57684 + *guser = g_tmp;
57685 + guser = &(g_tmp->next);
57686 + }
57687 +
57688 + return 0;
57689 +}
57690 +
57691 +static int
57692 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
57693 + struct acl_role_label *role)
57694 +{
57695 + struct acl_object_label *o_tmp;
57696 + unsigned int len;
57697 + int ret;
57698 + char *tmp;
57699 +
57700 + while (userp) {
57701 + if ((o_tmp = (struct acl_object_label *)
57702 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
57703 + return -ENOMEM;
57704 +
57705 + if (copy_from_user(o_tmp, userp,
57706 + sizeof (struct acl_object_label)))
57707 + return -EFAULT;
57708 +
57709 + userp = o_tmp->prev;
57710 +
57711 + len = strnlen_user(o_tmp->filename, PATH_MAX);
57712 +
57713 + if (!len || len >= PATH_MAX)
57714 + return -EINVAL;
57715 +
57716 + if ((tmp = (char *) acl_alloc(len)) == NULL)
57717 + return -ENOMEM;
57718 +
57719 + if (copy_from_user(tmp, o_tmp->filename, len))
57720 + return -EFAULT;
57721 + tmp[len-1] = '\0';
57722 + o_tmp->filename = tmp;
57723 +
57724 + insert_acl_obj_label(o_tmp, subj);
57725 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
57726 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
57727 + return -ENOMEM;
57728 +
57729 + ret = copy_user_glob(o_tmp);
57730 + if (ret)
57731 + return ret;
57732 +
57733 + if (o_tmp->nested) {
57734 + int already_copied;
57735 +
57736 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
57737 + if (IS_ERR(o_tmp->nested))
57738 + return PTR_ERR(o_tmp->nested);
57739 +
57740 + /* insert into nested subject list if we haven't copied this one yet
57741 + to prevent duplicate entries */
57742 + if (!already_copied) {
57743 + o_tmp->nested->next = role->hash->first;
57744 + role->hash->first = o_tmp->nested;
57745 + }
57746 + }
57747 + }
57748 +
57749 + return 0;
57750 +}
57751 +
57752 +static __u32
57753 +count_user_subjs(struct acl_subject_label *userp)
57754 +{
57755 + struct acl_subject_label s_tmp;
57756 + __u32 num = 0;
57757 +
57758 + while (userp) {
57759 + if (copy_from_user(&s_tmp, userp,
57760 + sizeof (struct acl_subject_label)))
57761 + break;
57762 +
57763 + userp = s_tmp.prev;
57764 + }
57765 +
57766 + return num;
57767 +}
57768 +
57769 +static int
57770 +copy_user_allowedips(struct acl_role_label *rolep)
57771 +{
57772 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
57773 +
57774 + ruserip = rolep->allowed_ips;
57775 +
57776 + while (ruserip) {
57777 + rlast = rtmp;
57778 +
57779 + if ((rtmp = (struct role_allowed_ip *)
57780 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
57781 + return -ENOMEM;
57782 +
57783 + if (copy_from_user(rtmp, ruserip,
57784 + sizeof (struct role_allowed_ip)))
57785 + return -EFAULT;
57786 +
57787 + ruserip = rtmp->prev;
57788 +
57789 + if (!rlast) {
57790 + rtmp->prev = NULL;
57791 + rolep->allowed_ips = rtmp;
57792 + } else {
57793 + rlast->next = rtmp;
57794 + rtmp->prev = rlast;
57795 + }
57796 +
57797 + if (!ruserip)
57798 + rtmp->next = NULL;
57799 + }
57800 +
57801 + return 0;
57802 +}
57803 +
57804 +static int
57805 +copy_user_transitions(struct acl_role_label *rolep)
57806 +{
57807 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
57808 +
57809 + unsigned int len;
57810 + char *tmp;
57811 +
57812 + rusertp = rolep->transitions;
57813 +
57814 + while (rusertp) {
57815 + rlast = rtmp;
57816 +
57817 + if ((rtmp = (struct role_transition *)
57818 + acl_alloc(sizeof (struct role_transition))) == NULL)
57819 + return -ENOMEM;
57820 +
57821 + if (copy_from_user(rtmp, rusertp,
57822 + sizeof (struct role_transition)))
57823 + return -EFAULT;
57824 +
57825 + rusertp = rtmp->prev;
57826 +
57827 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
57828 +
57829 + if (!len || len >= GR_SPROLE_LEN)
57830 + return -EINVAL;
57831 +
57832 + if ((tmp = (char *) acl_alloc(len)) == NULL)
57833 + return -ENOMEM;
57834 +
57835 + if (copy_from_user(tmp, rtmp->rolename, len))
57836 + return -EFAULT;
57837 + tmp[len-1] = '\0';
57838 + rtmp->rolename = tmp;
57839 +
57840 + if (!rlast) {
57841 + rtmp->prev = NULL;
57842 + rolep->transitions = rtmp;
57843 + } else {
57844 + rlast->next = rtmp;
57845 + rtmp->prev = rlast;
57846 + }
57847 +
57848 + if (!rusertp)
57849 + rtmp->next = NULL;
57850 + }
57851 +
57852 + return 0;
57853 +}
57854 +
57855 +static struct acl_subject_label *
57856 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
57857 +{
57858 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
57859 + unsigned int len;
57860 + char *tmp;
57861 + __u32 num_objs;
57862 + struct acl_ip_label **i_tmp, *i_utmp2;
57863 + struct gr_hash_struct ghash;
57864 + struct subject_map *subjmap;
57865 + unsigned int i_num;
57866 + int err;
57867 +
57868 + if (already_copied != NULL)
57869 + *already_copied = 0;
57870 +
57871 + s_tmp = lookup_subject_map(userp);
57872 +
57873 + /* we've already copied this subject into the kernel, just return
57874 + the reference to it, and don't copy it over again
57875 + */
57876 + if (s_tmp) {
57877 + if (already_copied != NULL)
57878 + *already_copied = 1;
57879 + return(s_tmp);
57880 + }
57881 +
57882 + if ((s_tmp = (struct acl_subject_label *)
57883 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
57884 + return ERR_PTR(-ENOMEM);
57885 +
57886 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
57887 + if (subjmap == NULL)
57888 + return ERR_PTR(-ENOMEM);
57889 +
57890 + subjmap->user = userp;
57891 + subjmap->kernel = s_tmp;
57892 + insert_subj_map_entry(subjmap);
57893 +
57894 + if (copy_from_user(s_tmp, userp,
57895 + sizeof (struct acl_subject_label)))
57896 + return ERR_PTR(-EFAULT);
57897 +
57898 + len = strnlen_user(s_tmp->filename, PATH_MAX);
57899 +
57900 + if (!len || len >= PATH_MAX)
57901 + return ERR_PTR(-EINVAL);
57902 +
57903 + if ((tmp = (char *) acl_alloc(len)) == NULL)
57904 + return ERR_PTR(-ENOMEM);
57905 +
57906 + if (copy_from_user(tmp, s_tmp->filename, len))
57907 + return ERR_PTR(-EFAULT);
57908 + tmp[len-1] = '\0';
57909 + s_tmp->filename = tmp;
57910 +
57911 + if (!strcmp(s_tmp->filename, "/"))
57912 + role->root_label = s_tmp;
57913 +
57914 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
57915 + return ERR_PTR(-EFAULT);
57916 +
57917 + /* copy user and group transition tables */
57918 +
57919 + if (s_tmp->user_trans_num) {
57920 + uid_t *uidlist;
57921 +
57922 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
57923 + if (uidlist == NULL)
57924 + return ERR_PTR(-ENOMEM);
57925 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
57926 + return ERR_PTR(-EFAULT);
57927 +
57928 + s_tmp->user_transitions = uidlist;
57929 + }
57930 +
57931 + if (s_tmp->group_trans_num) {
57932 + gid_t *gidlist;
57933 +
57934 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
57935 + if (gidlist == NULL)
57936 + return ERR_PTR(-ENOMEM);
57937 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
57938 + return ERR_PTR(-EFAULT);
57939 +
57940 + s_tmp->group_transitions = gidlist;
57941 + }
57942 +
57943 + /* set up object hash table */
57944 + num_objs = count_user_objs(ghash.first);
57945 +
57946 + s_tmp->obj_hash_size = num_objs;
57947 + s_tmp->obj_hash =
57948 + (struct acl_object_label **)
57949 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
57950 +
57951 + if (!s_tmp->obj_hash)
57952 + return ERR_PTR(-ENOMEM);
57953 +
57954 + memset(s_tmp->obj_hash, 0,
57955 + s_tmp->obj_hash_size *
57956 + sizeof (struct acl_object_label *));
57957 +
57958 + /* add in objects */
57959 + err = copy_user_objs(ghash.first, s_tmp, role);
57960 +
57961 + if (err)
57962 + return ERR_PTR(err);
57963 +
57964 + /* set pointer for parent subject */
57965 + if (s_tmp->parent_subject) {
57966 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
57967 +
57968 + if (IS_ERR(s_tmp2))
57969 + return s_tmp2;
57970 +
57971 + s_tmp->parent_subject = s_tmp2;
57972 + }
57973 +
57974 + /* add in ip acls */
57975 +
57976 + if (!s_tmp->ip_num) {
57977 + s_tmp->ips = NULL;
57978 + goto insert;
57979 + }
57980 +
57981 + i_tmp =
57982 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
57983 + sizeof (struct acl_ip_label *));
57984 +
57985 + if (!i_tmp)
57986 + return ERR_PTR(-ENOMEM);
57987 +
57988 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
57989 + *(i_tmp + i_num) =
57990 + (struct acl_ip_label *)
57991 + acl_alloc(sizeof (struct acl_ip_label));
57992 + if (!*(i_tmp + i_num))
57993 + return ERR_PTR(-ENOMEM);
57994 +
57995 + if (copy_from_user
57996 + (&i_utmp2, s_tmp->ips + i_num,
57997 + sizeof (struct acl_ip_label *)))
57998 + return ERR_PTR(-EFAULT);
57999 +
58000 + if (copy_from_user
58001 + (*(i_tmp + i_num), i_utmp2,
58002 + sizeof (struct acl_ip_label)))
58003 + return ERR_PTR(-EFAULT);
58004 +
58005 + if ((*(i_tmp + i_num))->iface == NULL)
58006 + continue;
58007 +
58008 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
58009 + if (!len || len >= IFNAMSIZ)
58010 + return ERR_PTR(-EINVAL);
58011 + tmp = acl_alloc(len);
58012 + if (tmp == NULL)
58013 + return ERR_PTR(-ENOMEM);
58014 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
58015 + return ERR_PTR(-EFAULT);
58016 + (*(i_tmp + i_num))->iface = tmp;
58017 + }
58018 +
58019 + s_tmp->ips = i_tmp;
58020 +
58021 +insert:
58022 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
58023 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
58024 + return ERR_PTR(-ENOMEM);
58025 +
58026 + return s_tmp;
58027 +}
58028 +
58029 +static int
58030 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
58031 +{
58032 + struct acl_subject_label s_pre;
58033 + struct acl_subject_label * ret;
58034 + int err;
58035 +
58036 + while (userp) {
58037 + if (copy_from_user(&s_pre, userp,
58038 + sizeof (struct acl_subject_label)))
58039 + return -EFAULT;
58040 +
58041 + ret = do_copy_user_subj(userp, role, NULL);
58042 +
58043 + err = PTR_ERR(ret);
58044 + if (IS_ERR(ret))
58045 + return err;
58046 +
58047 + insert_acl_subj_label(ret, role);
58048 +
58049 + userp = s_pre.prev;
58050 + }
58051 +
58052 + return 0;
58053 +}
58054 +
58055 +static int
58056 +copy_user_acl(struct gr_arg *arg)
58057 +{
58058 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
58059 + struct acl_subject_label *subj_list;
58060 + struct sprole_pw *sptmp;
58061 + struct gr_hash_struct *ghash;
58062 + uid_t *domainlist;
58063 + unsigned int r_num;
58064 + unsigned int len;
58065 + char *tmp;
58066 + int err = 0;
58067 + __u16 i;
58068 + __u32 num_subjs;
58069 +
58070 + /* we need a default and kernel role */
58071 + if (arg->role_db.num_roles < 2)
58072 + return -EINVAL;
58073 +
58074 + /* copy special role authentication info from userspace */
58075 +
58076 + num_sprole_pws = arg->num_sprole_pws;
58077 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
58078 +
58079 + if (!acl_special_roles && num_sprole_pws)
58080 + return -ENOMEM;
58081 +
58082 + for (i = 0; i < num_sprole_pws; i++) {
58083 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
58084 + if (!sptmp)
58085 + return -ENOMEM;
58086 + if (copy_from_user(sptmp, arg->sprole_pws + i,
58087 + sizeof (struct sprole_pw)))
58088 + return -EFAULT;
58089 +
58090 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
58091 +
58092 + if (!len || len >= GR_SPROLE_LEN)
58093 + return -EINVAL;
58094 +
58095 + if ((tmp = (char *) acl_alloc(len)) == NULL)
58096 + return -ENOMEM;
58097 +
58098 + if (copy_from_user(tmp, sptmp->rolename, len))
58099 + return -EFAULT;
58100 +
58101 + tmp[len-1] = '\0';
58102 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58103 + printk(KERN_ALERT "Copying special role %s\n", tmp);
58104 +#endif
58105 + sptmp->rolename = tmp;
58106 + acl_special_roles[i] = sptmp;
58107 + }
58108 +
58109 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
58110 +
58111 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
58112 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
58113 +
58114 + if (!r_tmp)
58115 + return -ENOMEM;
58116 +
58117 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
58118 + sizeof (struct acl_role_label *)))
58119 + return -EFAULT;
58120 +
58121 + if (copy_from_user(r_tmp, r_utmp2,
58122 + sizeof (struct acl_role_label)))
58123 + return -EFAULT;
58124 +
58125 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
58126 +
58127 + if (!len || len >= PATH_MAX)
58128 + return -EINVAL;
58129 +
58130 + if ((tmp = (char *) acl_alloc(len)) == NULL)
58131 + return -ENOMEM;
58132 +
58133 + if (copy_from_user(tmp, r_tmp->rolename, len))
58134 + return -EFAULT;
58135 +
58136 + tmp[len-1] = '\0';
58137 + r_tmp->rolename = tmp;
58138 +
58139 + if (!strcmp(r_tmp->rolename, "default")
58140 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
58141 + default_role = r_tmp;
58142 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
58143 + kernel_role = r_tmp;
58144 + }
58145 +
58146 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
58147 + return -ENOMEM;
58148 +
58149 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
58150 + return -EFAULT;
58151 +
58152 + r_tmp->hash = ghash;
58153 +
58154 + num_subjs = count_user_subjs(r_tmp->hash->first);
58155 +
58156 + r_tmp->subj_hash_size = num_subjs;
58157 + r_tmp->subj_hash =
58158 + (struct acl_subject_label **)
58159 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
58160 +
58161 + if (!r_tmp->subj_hash)
58162 + return -ENOMEM;
58163 +
58164 + err = copy_user_allowedips(r_tmp);
58165 + if (err)
58166 + return err;
58167 +
58168 + /* copy domain info */
58169 + if (r_tmp->domain_children != NULL) {
58170 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
58171 + if (domainlist == NULL)
58172 + return -ENOMEM;
58173 +
58174 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
58175 + return -EFAULT;
58176 +
58177 + r_tmp->domain_children = domainlist;
58178 + }
58179 +
58180 + err = copy_user_transitions(r_tmp);
58181 + if (err)
58182 + return err;
58183 +
58184 + memset(r_tmp->subj_hash, 0,
58185 + r_tmp->subj_hash_size *
58186 + sizeof (struct acl_subject_label *));
58187 +
58188 + /* acquire the list of subjects, then NULL out
58189 + the list prior to parsing the subjects for this role,
58190 + as during this parsing the list is replaced with a list
58191 + of *nested* subjects for the role
58192 + */
58193 + subj_list = r_tmp->hash->first;
58194 +
58195 + /* set nested subject list to null */
58196 + r_tmp->hash->first = NULL;
58197 +
58198 + err = copy_user_subjs(subj_list, r_tmp);
58199 +
58200 + if (err)
58201 + return err;
58202 +
58203 + insert_acl_role_label(r_tmp);
58204 + }
58205 +
58206 + if (default_role == NULL || kernel_role == NULL)
58207 + return -EINVAL;
58208 +
58209 + return err;
58210 +}
58211 +
58212 +static int
58213 +gracl_init(struct gr_arg *args)
58214 +{
58215 + int error = 0;
58216 +
58217 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
58218 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
58219 +
58220 + if (init_variables(args)) {
58221 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
58222 + error = -ENOMEM;
58223 + free_variables();
58224 + goto out;
58225 + }
58226 +
58227 + error = copy_user_acl(args);
58228 + free_init_variables();
58229 + if (error) {
58230 + free_variables();
58231 + goto out;
58232 + }
58233 +
58234 + if ((error = gr_set_acls(0))) {
58235 + free_variables();
58236 + goto out;
58237 + }
58238 +
58239 + pax_open_kernel();
58240 + gr_status |= GR_READY;
58241 + pax_close_kernel();
58242 +
58243 + out:
58244 + return error;
58245 +}
58246 +
58247 +/* derived from glibc fnmatch() 0: match, 1: no match*/
58248 +
58249 +static int
58250 +glob_match(const char *p, const char *n)
58251 +{
58252 + char c;
58253 +
58254 + while ((c = *p++) != '\0') {
58255 + switch (c) {
58256 + case '?':
58257 + if (*n == '\0')
58258 + return 1;
58259 + else if (*n == '/')
58260 + return 1;
58261 + break;
58262 + case '\\':
58263 + if (*n != c)
58264 + return 1;
58265 + break;
58266 + case '*':
58267 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
58268 + if (*n == '/')
58269 + return 1;
58270 + else if (c == '?') {
58271 + if (*n == '\0')
58272 + return 1;
58273 + else
58274 + ++n;
58275 + }
58276 + }
58277 + if (c == '\0') {
58278 + return 0;
58279 + } else {
58280 + const char *endp;
58281 +
58282 + if ((endp = strchr(n, '/')) == NULL)
58283 + endp = n + strlen(n);
58284 +
58285 + if (c == '[') {
58286 + for (--p; n < endp; ++n)
58287 + if (!glob_match(p, n))
58288 + return 0;
58289 + } else if (c == '/') {
58290 + while (*n != '\0' && *n != '/')
58291 + ++n;
58292 + if (*n == '/' && !glob_match(p, n + 1))
58293 + return 0;
58294 + } else {
58295 + for (--p; n < endp; ++n)
58296 + if (*n == c && !glob_match(p, n))
58297 + return 0;
58298 + }
58299 +
58300 + return 1;
58301 + }
58302 + case '[':
58303 + {
58304 + int not;
58305 + char cold;
58306 +
58307 + if (*n == '\0' || *n == '/')
58308 + return 1;
58309 +
58310 + not = (*p == '!' || *p == '^');
58311 + if (not)
58312 + ++p;
58313 +
58314 + c = *p++;
58315 + for (;;) {
58316 + unsigned char fn = (unsigned char)*n;
58317 +
58318 + if (c == '\0')
58319 + return 1;
58320 + else {
58321 + if (c == fn)
58322 + goto matched;
58323 + cold = c;
58324 + c = *p++;
58325 +
58326 + if (c == '-' && *p != ']') {
58327 + unsigned char cend = *p++;
58328 +
58329 + if (cend == '\0')
58330 + return 1;
58331 +
58332 + if (cold <= fn && fn <= cend)
58333 + goto matched;
58334 +
58335 + c = *p++;
58336 + }
58337 + }
58338 +
58339 + if (c == ']')
58340 + break;
58341 + }
58342 + if (!not)
58343 + return 1;
58344 + break;
58345 + matched:
58346 + while (c != ']') {
58347 + if (c == '\0')
58348 + return 1;
58349 +
58350 + c = *p++;
58351 + }
58352 + if (not)
58353 + return 1;
58354 + }
58355 + break;
58356 + default:
58357 + if (c != *n)
58358 + return 1;
58359 + }
58360 +
58361 + ++n;
58362 + }
58363 +
58364 + if (*n == '\0')
58365 + return 0;
58366 +
58367 + if (*n == '/')
58368 + return 0;
58369 +
58370 + return 1;
58371 +}
58372 +
58373 +static struct acl_object_label *
58374 +chk_glob_label(struct acl_object_label *globbed,
58375 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
58376 +{
58377 + struct acl_object_label *tmp;
58378 +
58379 + if (*path == NULL)
58380 + *path = gr_to_filename_nolock(dentry, mnt);
58381 +
58382 + tmp = globbed;
58383 +
58384 + while (tmp) {
58385 + if (!glob_match(tmp->filename, *path))
58386 + return tmp;
58387 + tmp = tmp->next;
58388 + }
58389 +
58390 + return NULL;
58391 +}
58392 +
58393 +static struct acl_object_label *
58394 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
58395 + const ino_t curr_ino, const dev_t curr_dev,
58396 + const struct acl_subject_label *subj, char **path, const int checkglob)
58397 +{
58398 + struct acl_subject_label *tmpsubj;
58399 + struct acl_object_label *retval;
58400 + struct acl_object_label *retval2;
58401 +
58402 + tmpsubj = (struct acl_subject_label *) subj;
58403 + read_lock(&gr_inode_lock);
58404 + do {
58405 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
58406 + if (retval) {
58407 + if (checkglob && retval->globbed) {
58408 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
58409 + if (retval2)
58410 + retval = retval2;
58411 + }
58412 + break;
58413 + }
58414 + } while ((tmpsubj = tmpsubj->parent_subject));
58415 + read_unlock(&gr_inode_lock);
58416 +
58417 + return retval;
58418 +}
58419 +
58420 +static __inline__ struct acl_object_label *
58421 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
58422 + struct dentry *curr_dentry,
58423 + const struct acl_subject_label *subj, char **path, const int checkglob)
58424 +{
58425 + int newglob = checkglob;
58426 + ino_t inode;
58427 + dev_t device;
58428 +
58429 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
58430 + as we don't want a / * rule to match instead of the / object
58431 + don't do this for create lookups that call this function though, since they're looking up
58432 + on the parent and thus need globbing checks on all paths
58433 + */
58434 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
58435 + newglob = GR_NO_GLOB;
58436 +
58437 + spin_lock(&curr_dentry->d_lock);
58438 + inode = curr_dentry->d_inode->i_ino;
58439 + device = __get_dev(curr_dentry);
58440 + spin_unlock(&curr_dentry->d_lock);
58441 +
58442 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
58443 +}
58444 +
58445 +#ifdef CONFIG_HUGETLBFS
58446 +static inline bool
58447 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
58448 +{
58449 + int i;
58450 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
58451 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
58452 + return true;
58453 + }
58454 +
58455 + return false;
58456 +}
58457 +#endif
58458 +
58459 +static struct acl_object_label *
58460 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58461 + const struct acl_subject_label *subj, char *path, const int checkglob)
58462 +{
58463 + struct dentry *dentry = (struct dentry *) l_dentry;
58464 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
58465 + struct mount *real_mnt = real_mount(mnt);
58466 + struct acl_object_label *retval;
58467 + struct dentry *parent;
58468 +
58469 + write_seqlock(&rename_lock);
58470 + br_read_lock(&vfsmount_lock);
58471 +
58472 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
58473 +#ifdef CONFIG_NET
58474 + mnt == sock_mnt ||
58475 +#endif
58476 +#ifdef CONFIG_HUGETLBFS
58477 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
58478 +#endif
58479 + /* ignore Eric Biederman */
58480 + IS_PRIVATE(l_dentry->d_inode))) {
58481 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
58482 + goto out;
58483 + }
58484 +
58485 + for (;;) {
58486 + if (dentry == real_root.dentry && mnt == real_root.mnt)
58487 + break;
58488 +
58489 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
58490 + if (!mnt_has_parent(real_mnt))
58491 + break;
58492 +
58493 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58494 + if (retval != NULL)
58495 + goto out;
58496 +
58497 + dentry = real_mnt->mnt_mountpoint;
58498 + real_mnt = real_mnt->mnt_parent;
58499 + mnt = &real_mnt->mnt;
58500 + continue;
58501 + }
58502 +
58503 + parent = dentry->d_parent;
58504 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58505 + if (retval != NULL)
58506 + goto out;
58507 +
58508 + dentry = parent;
58509 + }
58510 +
58511 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58512 +
58513 + /* real_root is pinned so we don't have to hold a reference */
58514 + if (retval == NULL)
58515 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
58516 +out:
58517 + br_read_unlock(&vfsmount_lock);
58518 + write_sequnlock(&rename_lock);
58519 +
58520 + BUG_ON(retval == NULL);
58521 +
58522 + return retval;
58523 +}
58524 +
58525 +static __inline__ struct acl_object_label *
58526 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58527 + const struct acl_subject_label *subj)
58528 +{
58529 + char *path = NULL;
58530 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
58531 +}
58532 +
58533 +static __inline__ struct acl_object_label *
58534 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58535 + const struct acl_subject_label *subj)
58536 +{
58537 + char *path = NULL;
58538 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
58539 +}
58540 +
58541 +static __inline__ struct acl_object_label *
58542 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58543 + const struct acl_subject_label *subj, char *path)
58544 +{
58545 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
58546 +}
58547 +
58548 +static struct acl_subject_label *
58549 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58550 + const struct acl_role_label *role)
58551 +{
58552 + struct dentry *dentry = (struct dentry *) l_dentry;
58553 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
58554 + struct mount *real_mnt = real_mount(mnt);
58555 + struct acl_subject_label *retval;
58556 + struct dentry *parent;
58557 +
58558 + write_seqlock(&rename_lock);
58559 + br_read_lock(&vfsmount_lock);
58560 +
58561 + for (;;) {
58562 + if (dentry == real_root.dentry && mnt == real_root.mnt)
58563 + break;
58564 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
58565 + if (!mnt_has_parent(real_mnt))
58566 + break;
58567 +
58568 + spin_lock(&dentry->d_lock);
58569 + read_lock(&gr_inode_lock);
58570 + retval =
58571 + lookup_acl_subj_label(dentry->d_inode->i_ino,
58572 + __get_dev(dentry), role);
58573 + read_unlock(&gr_inode_lock);
58574 + spin_unlock(&dentry->d_lock);
58575 + if (retval != NULL)
58576 + goto out;
58577 +
58578 + dentry = real_mnt->mnt_mountpoint;
58579 + real_mnt = real_mnt->mnt_parent;
58580 + mnt = &real_mnt->mnt;
58581 + continue;
58582 + }
58583 +
58584 + spin_lock(&dentry->d_lock);
58585 + read_lock(&gr_inode_lock);
58586 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
58587 + __get_dev(dentry), role);
58588 + read_unlock(&gr_inode_lock);
58589 + parent = dentry->d_parent;
58590 + spin_unlock(&dentry->d_lock);
58591 +
58592 + if (retval != NULL)
58593 + goto out;
58594 +
58595 + dentry = parent;
58596 + }
58597 +
58598 + spin_lock(&dentry->d_lock);
58599 + read_lock(&gr_inode_lock);
58600 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
58601 + __get_dev(dentry), role);
58602 + read_unlock(&gr_inode_lock);
58603 + spin_unlock(&dentry->d_lock);
58604 +
58605 + if (unlikely(retval == NULL)) {
58606 + /* real_root is pinned, we don't need to hold a reference */
58607 + read_lock(&gr_inode_lock);
58608 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
58609 + __get_dev(real_root.dentry), role);
58610 + read_unlock(&gr_inode_lock);
58611 + }
58612 +out:
58613 + br_read_unlock(&vfsmount_lock);
58614 + write_sequnlock(&rename_lock);
58615 +
58616 + BUG_ON(retval == NULL);
58617 +
58618 + return retval;
58619 +}
58620 +
58621 +static void
58622 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
58623 +{
58624 + struct task_struct *task = current;
58625 + const struct cred *cred = current_cred();
58626 +
58627 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
58628 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58629 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58630 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
58631 +
58632 + return;
58633 +}
58634 +
58635 +static void
58636 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
58637 +{
58638 + struct task_struct *task = current;
58639 + const struct cred *cred = current_cred();
58640 +
58641 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
58642 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58643 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58644 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
58645 +
58646 + return;
58647 +}
58648 +
58649 +static void
58650 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
58651 +{
58652 + struct task_struct *task = current;
58653 + const struct cred *cred = current_cred();
58654 +
58655 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
58656 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58657 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58658 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
58659 +
58660 + return;
58661 +}
58662 +
58663 +__u32
58664 +gr_search_file(const struct dentry * dentry, const __u32 mode,
58665 + const struct vfsmount * mnt)
58666 +{
58667 + __u32 retval = mode;
58668 + struct acl_subject_label *curracl;
58669 + struct acl_object_label *currobj;
58670 +
58671 + if (unlikely(!(gr_status & GR_READY)))
58672 + return (mode & ~GR_AUDITS);
58673 +
58674 + curracl = current->acl;
58675 +
58676 + currobj = chk_obj_label(dentry, mnt, curracl);
58677 + retval = currobj->mode & mode;
58678 +
58679 + /* if we're opening a specified transfer file for writing
58680 + (e.g. /dev/initctl), then transfer our role to init
58681 + */
58682 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
58683 + current->role->roletype & GR_ROLE_PERSIST)) {
58684 + struct task_struct *task = init_pid_ns.child_reaper;
58685 +
58686 + if (task->role != current->role) {
58687 + task->acl_sp_role = 0;
58688 + task->acl_role_id = current->acl_role_id;
58689 + task->role = current->role;
58690 + rcu_read_lock();
58691 + read_lock(&grsec_exec_file_lock);
58692 + gr_apply_subject_to_task(task);
58693 + read_unlock(&grsec_exec_file_lock);
58694 + rcu_read_unlock();
58695 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
58696 + }
58697 + }
58698 +
58699 + if (unlikely
58700 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
58701 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
58702 + __u32 new_mode = mode;
58703 +
58704 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
58705 +
58706 + retval = new_mode;
58707 +
58708 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
58709 + new_mode |= GR_INHERIT;
58710 +
58711 + if (!(mode & GR_NOLEARN))
58712 + gr_log_learn(dentry, mnt, new_mode);
58713 + }
58714 +
58715 + return retval;
58716 +}
58717 +
58718 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
58719 + const struct dentry *parent,
58720 + const struct vfsmount *mnt)
58721 +{
58722 + struct name_entry *match;
58723 + struct acl_object_label *matchpo;
58724 + struct acl_subject_label *curracl;
58725 + char *path;
58726 +
58727 + if (unlikely(!(gr_status & GR_READY)))
58728 + return NULL;
58729 +
58730 + preempt_disable();
58731 + path = gr_to_filename_rbac(new_dentry, mnt);
58732 + match = lookup_name_entry_create(path);
58733 +
58734 + curracl = current->acl;
58735 +
58736 + if (match) {
58737 + read_lock(&gr_inode_lock);
58738 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
58739 + read_unlock(&gr_inode_lock);
58740 +
58741 + if (matchpo) {
58742 + preempt_enable();
58743 + return matchpo;
58744 + }
58745 + }
58746 +
58747 + // lookup parent
58748 +
58749 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
58750 +
58751 + preempt_enable();
58752 + return matchpo;
58753 +}
58754 +
58755 +__u32
58756 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
58757 + const struct vfsmount * mnt, const __u32 mode)
58758 +{
58759 + struct acl_object_label *matchpo;
58760 + __u32 retval;
58761 +
58762 + if (unlikely(!(gr_status & GR_READY)))
58763 + return (mode & ~GR_AUDITS);
58764 +
58765 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
58766 +
58767 + retval = matchpo->mode & mode;
58768 +
58769 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
58770 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
58771 + __u32 new_mode = mode;
58772 +
58773 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
58774 +
58775 + gr_log_learn(new_dentry, mnt, new_mode);
58776 + return new_mode;
58777 + }
58778 +
58779 + return retval;
58780 +}
58781 +
58782 +__u32
58783 +gr_check_link(const struct dentry * new_dentry,
58784 + const struct dentry * parent_dentry,
58785 + const struct vfsmount * parent_mnt,
58786 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
58787 +{
58788 + struct acl_object_label *obj;
58789 + __u32 oldmode, newmode;
58790 + __u32 needmode;
58791 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
58792 + GR_DELETE | GR_INHERIT;
58793 +
58794 + if (unlikely(!(gr_status & GR_READY)))
58795 + return (GR_CREATE | GR_LINK);
58796 +
58797 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
58798 + oldmode = obj->mode;
58799 +
58800 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
58801 + newmode = obj->mode;
58802 +
58803 + needmode = newmode & checkmodes;
58804 +
58805 + // old name for hardlink must have at least the permissions of the new name
58806 + if ((oldmode & needmode) != needmode)
58807 + goto bad;
58808 +
58809 + // if old name had restrictions/auditing, make sure the new name does as well
58810 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
58811 +
58812 + // don't allow hardlinking of suid/sgid/fcapped files without permission
58813 + if (is_privileged_binary(old_dentry))
58814 + needmode |= GR_SETID;
58815 +
58816 + if ((newmode & needmode) != needmode)
58817 + goto bad;
58818 +
58819 + // enforce minimum permissions
58820 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
58821 + return newmode;
58822 +bad:
58823 + needmode = oldmode;
58824 + if (is_privileged_binary(old_dentry))
58825 + needmode |= GR_SETID;
58826 +
58827 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
58828 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
58829 + return (GR_CREATE | GR_LINK);
58830 + } else if (newmode & GR_SUPPRESS)
58831 + return GR_SUPPRESS;
58832 + else
58833 + return 0;
58834 +}
58835 +
58836 +int
58837 +gr_check_hidden_task(const struct task_struct *task)
58838 +{
58839 + if (unlikely(!(gr_status & GR_READY)))
58840 + return 0;
58841 +
58842 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
58843 + return 1;
58844 +
58845 + return 0;
58846 +}
58847 +
58848 +int
58849 +gr_check_protected_task(const struct task_struct *task)
58850 +{
58851 + if (unlikely(!(gr_status & GR_READY) || !task))
58852 + return 0;
58853 +
58854 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
58855 + task->acl != current->acl)
58856 + return 1;
58857 +
58858 + return 0;
58859 +}
58860 +
58861 +int
58862 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
58863 +{
58864 + struct task_struct *p;
58865 + int ret = 0;
58866 +
58867 + if (unlikely(!(gr_status & GR_READY) || !pid))
58868 + return ret;
58869 +
58870 + read_lock(&tasklist_lock);
58871 + do_each_pid_task(pid, type, p) {
58872 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
58873 + p->acl != current->acl) {
58874 + ret = 1;
58875 + goto out;
58876 + }
58877 + } while_each_pid_task(pid, type, p);
58878 +out:
58879 + read_unlock(&tasklist_lock);
58880 +
58881 + return ret;
58882 +}
58883 +
58884 +void
58885 +gr_copy_label(struct task_struct *tsk)
58886 +{
58887 + tsk->signal->used_accept = 0;
58888 + tsk->acl_sp_role = 0;
58889 + tsk->acl_role_id = current->acl_role_id;
58890 + tsk->acl = current->acl;
58891 + tsk->role = current->role;
58892 + tsk->signal->curr_ip = current->signal->curr_ip;
58893 + tsk->signal->saved_ip = current->signal->saved_ip;
58894 + if (current->exec_file)
58895 + get_file(current->exec_file);
58896 + tsk->exec_file = current->exec_file;
58897 + tsk->is_writable = current->is_writable;
58898 + if (unlikely(current->signal->used_accept)) {
58899 + current->signal->curr_ip = 0;
58900 + current->signal->saved_ip = 0;
58901 + }
58902 +
58903 + return;
58904 +}
58905 +
58906 +static void
58907 +gr_set_proc_res(struct task_struct *task)
58908 +{
58909 + struct acl_subject_label *proc;
58910 + unsigned short i;
58911 +
58912 + proc = task->acl;
58913 +
58914 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
58915 + return;
58916 +
58917 + for (i = 0; i < RLIM_NLIMITS; i++) {
58918 + if (!(proc->resmask & (1 << i)))
58919 + continue;
58920 +
58921 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
58922 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
58923 + }
58924 +
58925 + return;
58926 +}
58927 +
58928 +extern int __gr_process_user_ban(struct user_struct *user);
58929 +
58930 +int
58931 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
58932 +{
58933 + unsigned int i;
58934 + __u16 num;
58935 + uid_t *uidlist;
58936 + uid_t curuid;
58937 + int realok = 0;
58938 + int effectiveok = 0;
58939 + int fsok = 0;
58940 + uid_t globalreal, globaleffective, globalfs;
58941 +
58942 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58943 + struct user_struct *user;
58944 +
58945 + if (!uid_valid(real))
58946 + goto skipit;
58947 +
58948 + /* find user based on global namespace */
58949 +
58950 + globalreal = GR_GLOBAL_UID(real);
58951 +
58952 + user = find_user(make_kuid(&init_user_ns, globalreal));
58953 + if (user == NULL)
58954 + goto skipit;
58955 +
58956 + if (__gr_process_user_ban(user)) {
58957 + /* for find_user */
58958 + free_uid(user);
58959 + return 1;
58960 + }
58961 +
58962 + /* for find_user */
58963 + free_uid(user);
58964 +
58965 +skipit:
58966 +#endif
58967 +
58968 + if (unlikely(!(gr_status & GR_READY)))
58969 + return 0;
58970 +
58971 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
58972 + gr_log_learn_uid_change(real, effective, fs);
58973 +
58974 + num = current->acl->user_trans_num;
58975 + uidlist = current->acl->user_transitions;
58976 +
58977 + if (uidlist == NULL)
58978 + return 0;
58979 +
58980 + if (!uid_valid(real)) {
58981 + realok = 1;
58982 + globalreal = (uid_t)-1;
58983 + } else {
58984 + globalreal = GR_GLOBAL_UID(real);
58985 + }
58986 + if (!uid_valid(effective)) {
58987 + effectiveok = 1;
58988 + globaleffective = (uid_t)-1;
58989 + } else {
58990 + globaleffective = GR_GLOBAL_UID(effective);
58991 + }
58992 + if (!uid_valid(fs)) {
58993 + fsok = 1;
58994 + globalfs = (uid_t)-1;
58995 + } else {
58996 + globalfs = GR_GLOBAL_UID(fs);
58997 + }
58998 +
58999 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
59000 + for (i = 0; i < num; i++) {
59001 + curuid = uidlist[i];
59002 + if (globalreal == curuid)
59003 + realok = 1;
59004 + if (globaleffective == curuid)
59005 + effectiveok = 1;
59006 + if (globalfs == curuid)
59007 + fsok = 1;
59008 + }
59009 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
59010 + for (i = 0; i < num; i++) {
59011 + curuid = uidlist[i];
59012 + if (globalreal == curuid)
59013 + break;
59014 + if (globaleffective == curuid)
59015 + break;
59016 + if (globalfs == curuid)
59017 + break;
59018 + }
59019 + /* not in deny list */
59020 + if (i == num) {
59021 + realok = 1;
59022 + effectiveok = 1;
59023 + fsok = 1;
59024 + }
59025 + }
59026 +
59027 + if (realok && effectiveok && fsok)
59028 + return 0;
59029 + else {
59030 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59031 + return 1;
59032 + }
59033 +}
59034 +
59035 +int
59036 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
59037 +{
59038 + unsigned int i;
59039 + __u16 num;
59040 + gid_t *gidlist;
59041 + gid_t curgid;
59042 + int realok = 0;
59043 + int effectiveok = 0;
59044 + int fsok = 0;
59045 + gid_t globalreal, globaleffective, globalfs;
59046 +
59047 + if (unlikely(!(gr_status & GR_READY)))
59048 + return 0;
59049 +
59050 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59051 + gr_log_learn_gid_change(real, effective, fs);
59052 +
59053 + num = current->acl->group_trans_num;
59054 + gidlist = current->acl->group_transitions;
59055 +
59056 + if (gidlist == NULL)
59057 + return 0;
59058 +
59059 + if (!gid_valid(real)) {
59060 + realok = 1;
59061 + globalreal = (gid_t)-1;
59062 + } else {
59063 + globalreal = GR_GLOBAL_GID(real);
59064 + }
59065 + if (!gid_valid(effective)) {
59066 + effectiveok = 1;
59067 + globaleffective = (gid_t)-1;
59068 + } else {
59069 + globaleffective = GR_GLOBAL_GID(effective);
59070 + }
59071 + if (!gid_valid(fs)) {
59072 + fsok = 1;
59073 + globalfs = (gid_t)-1;
59074 + } else {
59075 + globalfs = GR_GLOBAL_GID(fs);
59076 + }
59077 +
59078 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
59079 + for (i = 0; i < num; i++) {
59080 + curgid = gidlist[i];
59081 + if (globalreal == curgid)
59082 + realok = 1;
59083 + if (globaleffective == curgid)
59084 + effectiveok = 1;
59085 + if (globalfs == curgid)
59086 + fsok = 1;
59087 + }
59088 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
59089 + for (i = 0; i < num; i++) {
59090 + curgid = gidlist[i];
59091 + if (globalreal == curgid)
59092 + break;
59093 + if (globaleffective == curgid)
59094 + break;
59095 + if (globalfs == curgid)
59096 + break;
59097 + }
59098 + /* not in deny list */
59099 + if (i == num) {
59100 + realok = 1;
59101 + effectiveok = 1;
59102 + fsok = 1;
59103 + }
59104 + }
59105 +
59106 + if (realok && effectiveok && fsok)
59107 + return 0;
59108 + else {
59109 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59110 + return 1;
59111 + }
59112 +}
59113 +
59114 +extern int gr_acl_is_capable(const int cap);
59115 +
59116 +void
59117 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
59118 +{
59119 + struct acl_role_label *role = task->role;
59120 + struct acl_subject_label *subj = NULL;
59121 + struct acl_object_label *obj;
59122 + struct file *filp;
59123 + uid_t uid;
59124 + gid_t gid;
59125 +
59126 + if (unlikely(!(gr_status & GR_READY)))
59127 + return;
59128 +
59129 + uid = GR_GLOBAL_UID(kuid);
59130 + gid = GR_GLOBAL_GID(kgid);
59131 +
59132 + filp = task->exec_file;
59133 +
59134 + /* kernel process, we'll give them the kernel role */
59135 + if (unlikely(!filp)) {
59136 + task->role = kernel_role;
59137 + task->acl = kernel_role->root_label;
59138 + return;
59139 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
59140 + role = lookup_acl_role_label(task, uid, gid);
59141 +
59142 + /* don't change the role if we're not a privileged process */
59143 + if (role && task->role != role &&
59144 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
59145 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
59146 + return;
59147 +
59148 + /* perform subject lookup in possibly new role
59149 + we can use this result below in the case where role == task->role
59150 + */
59151 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
59152 +
59153 + /* if we changed uid/gid, but result in the same role
59154 + and are using inheritance, don't lose the inherited subject
59155 + if current subject is other than what normal lookup
59156 + would result in, we arrived via inheritance, don't
59157 + lose subject
59158 + */
59159 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
59160 + (subj == task->acl)))
59161 + task->acl = subj;
59162 +
59163 + task->role = role;
59164 +
59165 + task->is_writable = 0;
59166 +
59167 + /* ignore additional mmap checks for processes that are writable
59168 + by the default ACL */
59169 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59170 + if (unlikely(obj->mode & GR_WRITE))
59171 + task->is_writable = 1;
59172 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
59173 + if (unlikely(obj->mode & GR_WRITE))
59174 + task->is_writable = 1;
59175 +
59176 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59177 + 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);
59178 +#endif
59179 +
59180 + gr_set_proc_res(task);
59181 +
59182 + return;
59183 +}
59184 +
59185 +int
59186 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59187 + const int unsafe_flags)
59188 +{
59189 + struct task_struct *task = current;
59190 + struct acl_subject_label *newacl;
59191 + struct acl_object_label *obj;
59192 + __u32 retmode;
59193 +
59194 + if (unlikely(!(gr_status & GR_READY)))
59195 + return 0;
59196 +
59197 + newacl = chk_subj_label(dentry, mnt, task->role);
59198 +
59199 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
59200 + did an exec
59201 + */
59202 + rcu_read_lock();
59203 + read_lock(&tasklist_lock);
59204 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
59205 + (task->parent->acl->mode & GR_POVERRIDE))) {
59206 + read_unlock(&tasklist_lock);
59207 + rcu_read_unlock();
59208 + goto skip_check;
59209 + }
59210 + read_unlock(&tasklist_lock);
59211 + rcu_read_unlock();
59212 +
59213 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
59214 + !(task->role->roletype & GR_ROLE_GOD) &&
59215 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
59216 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59217 + if (unsafe_flags & LSM_UNSAFE_SHARE)
59218 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
59219 + else
59220 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
59221 + return -EACCES;
59222 + }
59223 +
59224 +skip_check:
59225 +
59226 + obj = chk_obj_label(dentry, mnt, task->acl);
59227 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
59228 +
59229 + if (!(task->acl->mode & GR_INHERITLEARN) &&
59230 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
59231 + if (obj->nested)
59232 + task->acl = obj->nested;
59233 + else
59234 + task->acl = newacl;
59235 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
59236 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
59237 +
59238 + task->is_writable = 0;
59239 +
59240 + /* ignore additional mmap checks for processes that are writable
59241 + by the default ACL */
59242 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
59243 + if (unlikely(obj->mode & GR_WRITE))
59244 + task->is_writable = 1;
59245 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
59246 + if (unlikely(obj->mode & GR_WRITE))
59247 + task->is_writable = 1;
59248 +
59249 + gr_set_proc_res(task);
59250 +
59251 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59252 + 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);
59253 +#endif
59254 + return 0;
59255 +}
59256 +
59257 +/* always called with valid inodev ptr */
59258 +static void
59259 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
59260 +{
59261 + struct acl_object_label *matchpo;
59262 + struct acl_subject_label *matchps;
59263 + struct acl_subject_label *subj;
59264 + struct acl_role_label *role;
59265 + unsigned int x;
59266 +
59267 + FOR_EACH_ROLE_START(role)
59268 + FOR_EACH_SUBJECT_START(role, subj, x)
59269 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59270 + matchpo->mode |= GR_DELETED;
59271 + FOR_EACH_SUBJECT_END(subj,x)
59272 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
59273 + /* nested subjects aren't in the role's subj_hash table */
59274 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59275 + matchpo->mode |= GR_DELETED;
59276 + FOR_EACH_NESTED_SUBJECT_END(subj)
59277 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
59278 + matchps->mode |= GR_DELETED;
59279 + FOR_EACH_ROLE_END(role)
59280 +
59281 + inodev->nentry->deleted = 1;
59282 +
59283 + return;
59284 +}
59285 +
59286 +void
59287 +gr_handle_delete(const ino_t ino, const dev_t dev)
59288 +{
59289 + struct inodev_entry *inodev;
59290 +
59291 + if (unlikely(!(gr_status & GR_READY)))
59292 + return;
59293 +
59294 + write_lock(&gr_inode_lock);
59295 + inodev = lookup_inodev_entry(ino, dev);
59296 + if (inodev != NULL)
59297 + do_handle_delete(inodev, ino, dev);
59298 + write_unlock(&gr_inode_lock);
59299 +
59300 + return;
59301 +}
59302 +
59303 +static void
59304 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
59305 + const ino_t newinode, const dev_t newdevice,
59306 + struct acl_subject_label *subj)
59307 +{
59308 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
59309 + struct acl_object_label *match;
59310 +
59311 + match = subj->obj_hash[index];
59312 +
59313 + while (match && (match->inode != oldinode ||
59314 + match->device != olddevice ||
59315 + !(match->mode & GR_DELETED)))
59316 + match = match->next;
59317 +
59318 + if (match && (match->inode == oldinode)
59319 + && (match->device == olddevice)
59320 + && (match->mode & GR_DELETED)) {
59321 + if (match->prev == NULL) {
59322 + subj->obj_hash[index] = match->next;
59323 + if (match->next != NULL)
59324 + match->next->prev = NULL;
59325 + } else {
59326 + match->prev->next = match->next;
59327 + if (match->next != NULL)
59328 + match->next->prev = match->prev;
59329 + }
59330 + match->prev = NULL;
59331 + match->next = NULL;
59332 + match->inode = newinode;
59333 + match->device = newdevice;
59334 + match->mode &= ~GR_DELETED;
59335 +
59336 + insert_acl_obj_label(match, subj);
59337 + }
59338 +
59339 + return;
59340 +}
59341 +
59342 +static void
59343 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
59344 + const ino_t newinode, const dev_t newdevice,
59345 + struct acl_role_label *role)
59346 +{
59347 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
59348 + struct acl_subject_label *match;
59349 +
59350 + match = role->subj_hash[index];
59351 +
59352 + while (match && (match->inode != oldinode ||
59353 + match->device != olddevice ||
59354 + !(match->mode & GR_DELETED)))
59355 + match = match->next;
59356 +
59357 + if (match && (match->inode == oldinode)
59358 + && (match->device == olddevice)
59359 + && (match->mode & GR_DELETED)) {
59360 + if (match->prev == NULL) {
59361 + role->subj_hash[index] = match->next;
59362 + if (match->next != NULL)
59363 + match->next->prev = NULL;
59364 + } else {
59365 + match->prev->next = match->next;
59366 + if (match->next != NULL)
59367 + match->next->prev = match->prev;
59368 + }
59369 + match->prev = NULL;
59370 + match->next = NULL;
59371 + match->inode = newinode;
59372 + match->device = newdevice;
59373 + match->mode &= ~GR_DELETED;
59374 +
59375 + insert_acl_subj_label(match, role);
59376 + }
59377 +
59378 + return;
59379 +}
59380 +
59381 +static void
59382 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
59383 + const ino_t newinode, const dev_t newdevice)
59384 +{
59385 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
59386 + struct inodev_entry *match;
59387 +
59388 + match = inodev_set.i_hash[index];
59389 +
59390 + while (match && (match->nentry->inode != oldinode ||
59391 + match->nentry->device != olddevice || !match->nentry->deleted))
59392 + match = match->next;
59393 +
59394 + if (match && (match->nentry->inode == oldinode)
59395 + && (match->nentry->device == olddevice) &&
59396 + match->nentry->deleted) {
59397 + if (match->prev == NULL) {
59398 + inodev_set.i_hash[index] = match->next;
59399 + if (match->next != NULL)
59400 + match->next->prev = NULL;
59401 + } else {
59402 + match->prev->next = match->next;
59403 + if (match->next != NULL)
59404 + match->next->prev = match->prev;
59405 + }
59406 + match->prev = NULL;
59407 + match->next = NULL;
59408 + match->nentry->inode = newinode;
59409 + match->nentry->device = newdevice;
59410 + match->nentry->deleted = 0;
59411 +
59412 + insert_inodev_entry(match);
59413 + }
59414 +
59415 + return;
59416 +}
59417 +
59418 +static void
59419 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
59420 +{
59421 + struct acl_subject_label *subj;
59422 + struct acl_role_label *role;
59423 + unsigned int x;
59424 +
59425 + FOR_EACH_ROLE_START(role)
59426 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
59427 +
59428 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
59429 + if ((subj->inode == ino) && (subj->device == dev)) {
59430 + subj->inode = ino;
59431 + subj->device = dev;
59432 + }
59433 + /* nested subjects aren't in the role's subj_hash table */
59434 + update_acl_obj_label(matchn->inode, matchn->device,
59435 + ino, dev, subj);
59436 + FOR_EACH_NESTED_SUBJECT_END(subj)
59437 + FOR_EACH_SUBJECT_START(role, subj, x)
59438 + update_acl_obj_label(matchn->inode, matchn->device,
59439 + ino, dev, subj);
59440 + FOR_EACH_SUBJECT_END(subj,x)
59441 + FOR_EACH_ROLE_END(role)
59442 +
59443 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
59444 +
59445 + return;
59446 +}
59447 +
59448 +static void
59449 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
59450 + const struct vfsmount *mnt)
59451 +{
59452 + ino_t ino = dentry->d_inode->i_ino;
59453 + dev_t dev = __get_dev(dentry);
59454 +
59455 + __do_handle_create(matchn, ino, dev);
59456 +
59457 + return;
59458 +}
59459 +
59460 +void
59461 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59462 +{
59463 + struct name_entry *matchn;
59464 +
59465 + if (unlikely(!(gr_status & GR_READY)))
59466 + return;
59467 +
59468 + preempt_disable();
59469 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
59470 +
59471 + if (unlikely((unsigned long)matchn)) {
59472 + write_lock(&gr_inode_lock);
59473 + do_handle_create(matchn, dentry, mnt);
59474 + write_unlock(&gr_inode_lock);
59475 + }
59476 + preempt_enable();
59477 +
59478 + return;
59479 +}
59480 +
59481 +void
59482 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59483 +{
59484 + struct name_entry *matchn;
59485 +
59486 + if (unlikely(!(gr_status & GR_READY)))
59487 + return;
59488 +
59489 + preempt_disable();
59490 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
59491 +
59492 + if (unlikely((unsigned long)matchn)) {
59493 + write_lock(&gr_inode_lock);
59494 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
59495 + write_unlock(&gr_inode_lock);
59496 + }
59497 + preempt_enable();
59498 +
59499 + return;
59500 +}
59501 +
59502 +void
59503 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59504 + struct dentry *old_dentry,
59505 + struct dentry *new_dentry,
59506 + struct vfsmount *mnt, const __u8 replace)
59507 +{
59508 + struct name_entry *matchn;
59509 + struct inodev_entry *inodev;
59510 + struct inode *inode = new_dentry->d_inode;
59511 + ino_t old_ino = old_dentry->d_inode->i_ino;
59512 + dev_t old_dev = __get_dev(old_dentry);
59513 +
59514 + /* vfs_rename swaps the name and parent link for old_dentry and
59515 + new_dentry
59516 + at this point, old_dentry has the new name, parent link, and inode
59517 + for the renamed file
59518 + if a file is being replaced by a rename, new_dentry has the inode
59519 + and name for the replaced file
59520 + */
59521 +
59522 + if (unlikely(!(gr_status & GR_READY)))
59523 + return;
59524 +
59525 + preempt_disable();
59526 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
59527 +
59528 + /* we wouldn't have to check d_inode if it weren't for
59529 + NFS silly-renaming
59530 + */
59531 +
59532 + write_lock(&gr_inode_lock);
59533 + if (unlikely(replace && inode)) {
59534 + ino_t new_ino = inode->i_ino;
59535 + dev_t new_dev = __get_dev(new_dentry);
59536 +
59537 + inodev = lookup_inodev_entry(new_ino, new_dev);
59538 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
59539 + do_handle_delete(inodev, new_ino, new_dev);
59540 + }
59541 +
59542 + inodev = lookup_inodev_entry(old_ino, old_dev);
59543 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
59544 + do_handle_delete(inodev, old_ino, old_dev);
59545 +
59546 + if (unlikely((unsigned long)matchn))
59547 + do_handle_create(matchn, old_dentry, mnt);
59548 +
59549 + write_unlock(&gr_inode_lock);
59550 + preempt_enable();
59551 +
59552 + return;
59553 +}
59554 +
59555 +static int
59556 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
59557 + unsigned char **sum)
59558 +{
59559 + struct acl_role_label *r;
59560 + struct role_allowed_ip *ipp;
59561 + struct role_transition *trans;
59562 + unsigned int i;
59563 + int found = 0;
59564 + u32 curr_ip = current->signal->curr_ip;
59565 +
59566 + current->signal->saved_ip = curr_ip;
59567 +
59568 + /* check transition table */
59569 +
59570 + for (trans = current->role->transitions; trans; trans = trans->next) {
59571 + if (!strcmp(rolename, trans->rolename)) {
59572 + found = 1;
59573 + break;
59574 + }
59575 + }
59576 +
59577 + if (!found)
59578 + return 0;
59579 +
59580 + /* handle special roles that do not require authentication
59581 + and check ip */
59582 +
59583 + FOR_EACH_ROLE_START(r)
59584 + if (!strcmp(rolename, r->rolename) &&
59585 + (r->roletype & GR_ROLE_SPECIAL)) {
59586 + found = 0;
59587 + if (r->allowed_ips != NULL) {
59588 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
59589 + if ((ntohl(curr_ip) & ipp->netmask) ==
59590 + (ntohl(ipp->addr) & ipp->netmask))
59591 + found = 1;
59592 + }
59593 + } else
59594 + found = 2;
59595 + if (!found)
59596 + return 0;
59597 +
59598 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
59599 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
59600 + *salt = NULL;
59601 + *sum = NULL;
59602 + return 1;
59603 + }
59604 + }
59605 + FOR_EACH_ROLE_END(r)
59606 +
59607 + for (i = 0; i < num_sprole_pws; i++) {
59608 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
59609 + *salt = acl_special_roles[i]->salt;
59610 + *sum = acl_special_roles[i]->sum;
59611 + return 1;
59612 + }
59613 + }
59614 +
59615 + return 0;
59616 +}
59617 +
59618 +static void
59619 +assign_special_role(char *rolename)
59620 +{
59621 + struct acl_object_label *obj;
59622 + struct acl_role_label *r;
59623 + struct acl_role_label *assigned = NULL;
59624 + struct task_struct *tsk;
59625 + struct file *filp;
59626 +
59627 + FOR_EACH_ROLE_START(r)
59628 + if (!strcmp(rolename, r->rolename) &&
59629 + (r->roletype & GR_ROLE_SPECIAL)) {
59630 + assigned = r;
59631 + break;
59632 + }
59633 + FOR_EACH_ROLE_END(r)
59634 +
59635 + if (!assigned)
59636 + return;
59637 +
59638 + read_lock(&tasklist_lock);
59639 + read_lock(&grsec_exec_file_lock);
59640 +
59641 + tsk = current->real_parent;
59642 + if (tsk == NULL)
59643 + goto out_unlock;
59644 +
59645 + filp = tsk->exec_file;
59646 + if (filp == NULL)
59647 + goto out_unlock;
59648 +
59649 + tsk->is_writable = 0;
59650 +
59651 + tsk->acl_sp_role = 1;
59652 + tsk->acl_role_id = ++acl_sp_role_value;
59653 + tsk->role = assigned;
59654 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
59655 +
59656 + /* ignore additional mmap checks for processes that are writable
59657 + by the default ACL */
59658 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59659 + if (unlikely(obj->mode & GR_WRITE))
59660 + tsk->is_writable = 1;
59661 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
59662 + if (unlikely(obj->mode & GR_WRITE))
59663 + tsk->is_writable = 1;
59664 +
59665 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59666 + 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));
59667 +#endif
59668 +
59669 +out_unlock:
59670 + read_unlock(&grsec_exec_file_lock);
59671 + read_unlock(&tasklist_lock);
59672 + return;
59673 +}
59674 +
59675 +int gr_check_secure_terminal(struct task_struct *task)
59676 +{
59677 + struct task_struct *p, *p2, *p3;
59678 + struct files_struct *files;
59679 + struct fdtable *fdt;
59680 + struct file *our_file = NULL, *file;
59681 + int i;
59682 +
59683 + if (task->signal->tty == NULL)
59684 + return 1;
59685 +
59686 + files = get_files_struct(task);
59687 + if (files != NULL) {
59688 + rcu_read_lock();
59689 + fdt = files_fdtable(files);
59690 + for (i=0; i < fdt->max_fds; i++) {
59691 + file = fcheck_files(files, i);
59692 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
59693 + get_file(file);
59694 + our_file = file;
59695 + }
59696 + }
59697 + rcu_read_unlock();
59698 + put_files_struct(files);
59699 + }
59700 +
59701 + if (our_file == NULL)
59702 + return 1;
59703 +
59704 + read_lock(&tasklist_lock);
59705 + do_each_thread(p2, p) {
59706 + files = get_files_struct(p);
59707 + if (files == NULL ||
59708 + (p->signal && p->signal->tty == task->signal->tty)) {
59709 + if (files != NULL)
59710 + put_files_struct(files);
59711 + continue;
59712 + }
59713 + rcu_read_lock();
59714 + fdt = files_fdtable(files);
59715 + for (i=0; i < fdt->max_fds; i++) {
59716 + file = fcheck_files(files, i);
59717 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
59718 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
59719 + p3 = task;
59720 + while (task_pid_nr(p3) > 0) {
59721 + if (p3 == p)
59722 + break;
59723 + p3 = p3->real_parent;
59724 + }
59725 + if (p3 == p)
59726 + break;
59727 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
59728 + gr_handle_alertkill(p);
59729 + rcu_read_unlock();
59730 + put_files_struct(files);
59731 + read_unlock(&tasklist_lock);
59732 + fput(our_file);
59733 + return 0;
59734 + }
59735 + }
59736 + rcu_read_unlock();
59737 + put_files_struct(files);
59738 + } while_each_thread(p2, p);
59739 + read_unlock(&tasklist_lock);
59740 +
59741 + fput(our_file);
59742 + return 1;
59743 +}
59744 +
59745 +static int gr_rbac_disable(void *unused)
59746 +{
59747 + pax_open_kernel();
59748 + gr_status &= ~GR_READY;
59749 + pax_close_kernel();
59750 +
59751 + return 0;
59752 +}
59753 +
59754 +ssize_t
59755 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
59756 +{
59757 + struct gr_arg_wrapper uwrap;
59758 + unsigned char *sprole_salt = NULL;
59759 + unsigned char *sprole_sum = NULL;
59760 + int error = sizeof (struct gr_arg_wrapper);
59761 + int error2 = 0;
59762 +
59763 + mutex_lock(&gr_dev_mutex);
59764 +
59765 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
59766 + error = -EPERM;
59767 + goto out;
59768 + }
59769 +
59770 + if (count != sizeof (struct gr_arg_wrapper)) {
59771 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
59772 + error = -EINVAL;
59773 + goto out;
59774 + }
59775 +
59776 +
59777 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
59778 + gr_auth_expires = 0;
59779 + gr_auth_attempts = 0;
59780 + }
59781 +
59782 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
59783 + error = -EFAULT;
59784 + goto out;
59785 + }
59786 +
59787 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
59788 + error = -EINVAL;
59789 + goto out;
59790 + }
59791 +
59792 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
59793 + error = -EFAULT;
59794 + goto out;
59795 + }
59796 +
59797 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
59798 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
59799 + time_after(gr_auth_expires, get_seconds())) {
59800 + error = -EBUSY;
59801 + goto out;
59802 + }
59803 +
59804 + /* if non-root trying to do anything other than use a special role,
59805 + do not attempt authentication, do not count towards authentication
59806 + locking
59807 + */
59808 +
59809 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
59810 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
59811 + gr_is_global_nonroot(current_uid())) {
59812 + error = -EPERM;
59813 + goto out;
59814 + }
59815 +
59816 + /* ensure pw and special role name are null terminated */
59817 +
59818 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
59819 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
59820 +
59821 + /* Okay.
59822 + * We have our enough of the argument structure..(we have yet
59823 + * to copy_from_user the tables themselves) . Copy the tables
59824 + * only if we need them, i.e. for loading operations. */
59825 +
59826 + switch (gr_usermode->mode) {
59827 + case GR_STATUS:
59828 + if (gr_status & GR_READY) {
59829 + error = 1;
59830 + if (!gr_check_secure_terminal(current))
59831 + error = 3;
59832 + } else
59833 + error = 2;
59834 + goto out;
59835 + case GR_SHUTDOWN:
59836 + if ((gr_status & GR_READY)
59837 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
59838 + stop_machine(gr_rbac_disable, NULL, NULL);
59839 + free_variables();
59840 + memset(gr_usermode, 0, sizeof (struct gr_arg));
59841 + memset(gr_system_salt, 0, GR_SALT_LEN);
59842 + memset(gr_system_sum, 0, GR_SHA_LEN);
59843 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
59844 + } else if (gr_status & GR_READY) {
59845 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
59846 + error = -EPERM;
59847 + } else {
59848 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
59849 + error = -EAGAIN;
59850 + }
59851 + break;
59852 + case GR_ENABLE:
59853 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
59854 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
59855 + else {
59856 + if (gr_status & GR_READY)
59857 + error = -EAGAIN;
59858 + else
59859 + error = error2;
59860 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
59861 + }
59862 + break;
59863 + case GR_RELOAD:
59864 + if (!(gr_status & GR_READY)) {
59865 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
59866 + error = -EAGAIN;
59867 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
59868 + stop_machine(gr_rbac_disable, NULL, NULL);
59869 + free_variables();
59870 + error2 = gracl_init(gr_usermode);
59871 + if (!error2)
59872 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
59873 + else {
59874 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
59875 + error = error2;
59876 + }
59877 + } else {
59878 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
59879 + error = -EPERM;
59880 + }
59881 + break;
59882 + case GR_SEGVMOD:
59883 + if (unlikely(!(gr_status & GR_READY))) {
59884 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
59885 + error = -EAGAIN;
59886 + break;
59887 + }
59888 +
59889 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
59890 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
59891 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
59892 + struct acl_subject_label *segvacl;
59893 + segvacl =
59894 + lookup_acl_subj_label(gr_usermode->segv_inode,
59895 + gr_usermode->segv_device,
59896 + current->role);
59897 + if (segvacl) {
59898 + segvacl->crashes = 0;
59899 + segvacl->expires = 0;
59900 + }
59901 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
59902 + gr_remove_uid(gr_usermode->segv_uid);
59903 + }
59904 + } else {
59905 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
59906 + error = -EPERM;
59907 + }
59908 + break;
59909 + case GR_SPROLE:
59910 + case GR_SPROLEPAM:
59911 + if (unlikely(!(gr_status & GR_READY))) {
59912 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
59913 + error = -EAGAIN;
59914 + break;
59915 + }
59916 +
59917 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
59918 + current->role->expires = 0;
59919 + current->role->auth_attempts = 0;
59920 + }
59921 +
59922 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
59923 + time_after(current->role->expires, get_seconds())) {
59924 + error = -EBUSY;
59925 + goto out;
59926 + }
59927 +
59928 + if (lookup_special_role_auth
59929 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
59930 + && ((!sprole_salt && !sprole_sum)
59931 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
59932 + char *p = "";
59933 + assign_special_role(gr_usermode->sp_role);
59934 + read_lock(&tasklist_lock);
59935 + if (current->real_parent)
59936 + p = current->real_parent->role->rolename;
59937 + read_unlock(&tasklist_lock);
59938 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
59939 + p, acl_sp_role_value);
59940 + } else {
59941 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
59942 + error = -EPERM;
59943 + if(!(current->role->auth_attempts++))
59944 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
59945 +
59946 + goto out;
59947 + }
59948 + break;
59949 + case GR_UNSPROLE:
59950 + if (unlikely(!(gr_status & GR_READY))) {
59951 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
59952 + error = -EAGAIN;
59953 + break;
59954 + }
59955 +
59956 + if (current->role->roletype & GR_ROLE_SPECIAL) {
59957 + char *p = "";
59958 + int i = 0;
59959 +
59960 + read_lock(&tasklist_lock);
59961 + if (current->real_parent) {
59962 + p = current->real_parent->role->rolename;
59963 + i = current->real_parent->acl_role_id;
59964 + }
59965 + read_unlock(&tasklist_lock);
59966 +
59967 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
59968 + gr_set_acls(1);
59969 + } else {
59970 + error = -EPERM;
59971 + goto out;
59972 + }
59973 + break;
59974 + default:
59975 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
59976 + error = -EINVAL;
59977 + break;
59978 + }
59979 +
59980 + if (error != -EPERM)
59981 + goto out;
59982 +
59983 + if(!(gr_auth_attempts++))
59984 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
59985 +
59986 + out:
59987 + mutex_unlock(&gr_dev_mutex);
59988 + return error;
59989 +}
59990 +
59991 +/* must be called with
59992 + rcu_read_lock();
59993 + read_lock(&tasklist_lock);
59994 + read_lock(&grsec_exec_file_lock);
59995 +*/
59996 +int gr_apply_subject_to_task(struct task_struct *task)
59997 +{
59998 + struct acl_object_label *obj;
59999 + char *tmpname;
60000 + struct acl_subject_label *tmpsubj;
60001 + struct file *filp;
60002 + struct name_entry *nmatch;
60003 +
60004 + filp = task->exec_file;
60005 + if (filp == NULL)
60006 + return 0;
60007 +
60008 + /* the following is to apply the correct subject
60009 + on binaries running when the RBAC system
60010 + is enabled, when the binaries have been
60011 + replaced or deleted since their execution
60012 + -----
60013 + when the RBAC system starts, the inode/dev
60014 + from exec_file will be one the RBAC system
60015 + is unaware of. It only knows the inode/dev
60016 + of the present file on disk, or the absence
60017 + of it.
60018 + */
60019 + preempt_disable();
60020 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
60021 +
60022 + nmatch = lookup_name_entry(tmpname);
60023 + preempt_enable();
60024 + tmpsubj = NULL;
60025 + if (nmatch) {
60026 + if (nmatch->deleted)
60027 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
60028 + else
60029 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
60030 + if (tmpsubj != NULL)
60031 + task->acl = tmpsubj;
60032 + }
60033 + if (tmpsubj == NULL)
60034 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
60035 + task->role);
60036 + if (task->acl) {
60037 + task->is_writable = 0;
60038 + /* ignore additional mmap checks for processes that are writable
60039 + by the default ACL */
60040 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60041 + if (unlikely(obj->mode & GR_WRITE))
60042 + task->is_writable = 1;
60043 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60044 + if (unlikely(obj->mode & GR_WRITE))
60045 + task->is_writable = 1;
60046 +
60047 + gr_set_proc_res(task);
60048 +
60049 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60050 + 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);
60051 +#endif
60052 + } else {
60053 + return 1;
60054 + }
60055 +
60056 + return 0;
60057 +}
60058 +
60059 +int
60060 +gr_set_acls(const int type)
60061 +{
60062 + struct task_struct *task, *task2;
60063 + struct acl_role_label *role = current->role;
60064 + __u16 acl_role_id = current->acl_role_id;
60065 + const struct cred *cred;
60066 + int ret;
60067 +
60068 + rcu_read_lock();
60069 + read_lock(&tasklist_lock);
60070 + read_lock(&grsec_exec_file_lock);
60071 + do_each_thread(task2, task) {
60072 + /* check to see if we're called from the exit handler,
60073 + if so, only replace ACLs that have inherited the admin
60074 + ACL */
60075 +
60076 + if (type && (task->role != role ||
60077 + task->acl_role_id != acl_role_id))
60078 + continue;
60079 +
60080 + task->acl_role_id = 0;
60081 + task->acl_sp_role = 0;
60082 +
60083 + if (task->exec_file) {
60084 + cred = __task_cred(task);
60085 + task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
60086 + ret = gr_apply_subject_to_task(task);
60087 + if (ret) {
60088 + read_unlock(&grsec_exec_file_lock);
60089 + read_unlock(&tasklist_lock);
60090 + rcu_read_unlock();
60091 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
60092 + return ret;
60093 + }
60094 + } else {
60095 + // it's a kernel process
60096 + task->role = kernel_role;
60097 + task->acl = kernel_role->root_label;
60098 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
60099 + task->acl->mode &= ~GR_PROCFIND;
60100 +#endif
60101 + }
60102 + } while_each_thread(task2, task);
60103 + read_unlock(&grsec_exec_file_lock);
60104 + read_unlock(&tasklist_lock);
60105 + rcu_read_unlock();
60106 +
60107 + return 0;
60108 +}
60109 +
60110 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
60111 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
60112 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
60113 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
60114 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
60115 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
60116 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
60117 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
60118 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
60119 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
60120 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
60121 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
60122 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
60123 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
60124 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
60125 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
60126 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
60127 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
60128 +};
60129 +
60130 +void
60131 +gr_learn_resource(const struct task_struct *task,
60132 + const int res, const unsigned long wanted, const int gt)
60133 +{
60134 + struct acl_subject_label *acl;
60135 + const struct cred *cred;
60136 +
60137 + if (unlikely((gr_status & GR_READY) &&
60138 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
60139 + goto skip_reslog;
60140 +
60141 + gr_log_resource(task, res, wanted, gt);
60142 +skip_reslog:
60143 +
60144 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
60145 + return;
60146 +
60147 + acl = task->acl;
60148 +
60149 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
60150 + !(acl->resmask & (1 << (unsigned short) res))))
60151 + return;
60152 +
60153 + if (wanted >= acl->res[res].rlim_cur) {
60154 + unsigned long res_add;
60155 +
60156 + res_add = wanted + res_learn_bumps[res];
60157 +
60158 + acl->res[res].rlim_cur = res_add;
60159 +
60160 + if (wanted > acl->res[res].rlim_max)
60161 + acl->res[res].rlim_max = res_add;
60162 +
60163 + /* only log the subject filename, since resource logging is supported for
60164 + single-subject learning only */
60165 + rcu_read_lock();
60166 + cred = __task_cred(task);
60167 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60168 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
60169 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
60170 + "", (unsigned long) res, &task->signal->saved_ip);
60171 + rcu_read_unlock();
60172 + }
60173 +
60174 + return;
60175 +}
60176 +EXPORT_SYMBOL(gr_learn_resource);
60177 +#endif
60178 +
60179 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
60180 +void
60181 +pax_set_initial_flags(struct linux_binprm *bprm)
60182 +{
60183 + struct task_struct *task = current;
60184 + struct acl_subject_label *proc;
60185 + unsigned long flags;
60186 +
60187 + if (unlikely(!(gr_status & GR_READY)))
60188 + return;
60189 +
60190 + flags = pax_get_flags(task);
60191 +
60192 + proc = task->acl;
60193 +
60194 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
60195 + flags &= ~MF_PAX_PAGEEXEC;
60196 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
60197 + flags &= ~MF_PAX_SEGMEXEC;
60198 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
60199 + flags &= ~MF_PAX_RANDMMAP;
60200 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
60201 + flags &= ~MF_PAX_EMUTRAMP;
60202 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
60203 + flags &= ~MF_PAX_MPROTECT;
60204 +
60205 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
60206 + flags |= MF_PAX_PAGEEXEC;
60207 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
60208 + flags |= MF_PAX_SEGMEXEC;
60209 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
60210 + flags |= MF_PAX_RANDMMAP;
60211 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
60212 + flags |= MF_PAX_EMUTRAMP;
60213 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
60214 + flags |= MF_PAX_MPROTECT;
60215 +
60216 + pax_set_flags(task, flags);
60217 +
60218 + return;
60219 +}
60220 +#endif
60221 +
60222 +int
60223 +gr_handle_proc_ptrace(struct task_struct *task)
60224 +{
60225 + struct file *filp;
60226 + struct task_struct *tmp = task;
60227 + struct task_struct *curtemp = current;
60228 + __u32 retmode;
60229 +
60230 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60231 + if (unlikely(!(gr_status & GR_READY)))
60232 + return 0;
60233 +#endif
60234 +
60235 + read_lock(&tasklist_lock);
60236 + read_lock(&grsec_exec_file_lock);
60237 + filp = task->exec_file;
60238 +
60239 + while (task_pid_nr(tmp) > 0) {
60240 + if (tmp == curtemp)
60241 + break;
60242 + tmp = tmp->real_parent;
60243 + }
60244 +
60245 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60246 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
60247 + read_unlock(&grsec_exec_file_lock);
60248 + read_unlock(&tasklist_lock);
60249 + return 1;
60250 + }
60251 +
60252 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60253 + if (!(gr_status & GR_READY)) {
60254 + read_unlock(&grsec_exec_file_lock);
60255 + read_unlock(&tasklist_lock);
60256 + return 0;
60257 + }
60258 +#endif
60259 +
60260 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
60261 + read_unlock(&grsec_exec_file_lock);
60262 + read_unlock(&tasklist_lock);
60263 +
60264 + if (retmode & GR_NOPTRACE)
60265 + return 1;
60266 +
60267 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
60268 + && (current->acl != task->acl || (current->acl != current->role->root_label
60269 + && task_pid_nr(current) != task_pid_nr(task))))
60270 + return 1;
60271 +
60272 + return 0;
60273 +}
60274 +
60275 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
60276 +{
60277 + if (unlikely(!(gr_status & GR_READY)))
60278 + return;
60279 +
60280 + if (!(current->role->roletype & GR_ROLE_GOD))
60281 + return;
60282 +
60283 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
60284 + p->role->rolename, gr_task_roletype_to_char(p),
60285 + p->acl->filename);
60286 +}
60287 +
60288 +int
60289 +gr_handle_ptrace(struct task_struct *task, const long request)
60290 +{
60291 + struct task_struct *tmp = task;
60292 + struct task_struct *curtemp = current;
60293 + __u32 retmode;
60294 +
60295 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60296 + if (unlikely(!(gr_status & GR_READY)))
60297 + return 0;
60298 +#endif
60299 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
60300 + read_lock(&tasklist_lock);
60301 + while (task_pid_nr(tmp) > 0) {
60302 + if (tmp == curtemp)
60303 + break;
60304 + tmp = tmp->real_parent;
60305 + }
60306 +
60307 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60308 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
60309 + read_unlock(&tasklist_lock);
60310 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60311 + return 1;
60312 + }
60313 + read_unlock(&tasklist_lock);
60314 + }
60315 +
60316 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60317 + if (!(gr_status & GR_READY))
60318 + return 0;
60319 +#endif
60320 +
60321 + read_lock(&grsec_exec_file_lock);
60322 + if (unlikely(!task->exec_file)) {
60323 + read_unlock(&grsec_exec_file_lock);
60324 + return 0;
60325 + }
60326 +
60327 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
60328 + read_unlock(&grsec_exec_file_lock);
60329 +
60330 + if (retmode & GR_NOPTRACE) {
60331 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60332 + return 1;
60333 + }
60334 +
60335 + if (retmode & GR_PTRACERD) {
60336 + switch (request) {
60337 + case PTRACE_SEIZE:
60338 + case PTRACE_POKETEXT:
60339 + case PTRACE_POKEDATA:
60340 + case PTRACE_POKEUSR:
60341 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
60342 + case PTRACE_SETREGS:
60343 + case PTRACE_SETFPREGS:
60344 +#endif
60345 +#ifdef CONFIG_X86
60346 + case PTRACE_SETFPXREGS:
60347 +#endif
60348 +#ifdef CONFIG_ALTIVEC
60349 + case PTRACE_SETVRREGS:
60350 +#endif
60351 + return 1;
60352 + default:
60353 + return 0;
60354 + }
60355 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
60356 + !(current->role->roletype & GR_ROLE_GOD) &&
60357 + (current->acl != task->acl)) {
60358 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60359 + return 1;
60360 + }
60361 +
60362 + return 0;
60363 +}
60364 +
60365 +static int is_writable_mmap(const struct file *filp)
60366 +{
60367 + struct task_struct *task = current;
60368 + struct acl_object_label *obj, *obj2;
60369 +
60370 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
60371 + !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))) {
60372 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60373 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
60374 + task->role->root_label);
60375 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
60376 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
60377 + return 1;
60378 + }
60379 + }
60380 + return 0;
60381 +}
60382 +
60383 +int
60384 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
60385 +{
60386 + __u32 mode;
60387 +
60388 + if (unlikely(!file || !(prot & PROT_EXEC)))
60389 + return 1;
60390 +
60391 + if (is_writable_mmap(file))
60392 + return 0;
60393 +
60394 + mode =
60395 + gr_search_file(file->f_path.dentry,
60396 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
60397 + file->f_path.mnt);
60398 +
60399 + if (!gr_tpe_allow(file))
60400 + return 0;
60401 +
60402 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
60403 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60404 + return 0;
60405 + } else if (unlikely(!(mode & GR_EXEC))) {
60406 + return 0;
60407 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
60408 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60409 + return 1;
60410 + }
60411 +
60412 + return 1;
60413 +}
60414 +
60415 +int
60416 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60417 +{
60418 + __u32 mode;
60419 +
60420 + if (unlikely(!file || !(prot & PROT_EXEC)))
60421 + return 1;
60422 +
60423 + if (is_writable_mmap(file))
60424 + return 0;
60425 +
60426 + mode =
60427 + gr_search_file(file->f_path.dentry,
60428 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
60429 + file->f_path.mnt);
60430 +
60431 + if (!gr_tpe_allow(file))
60432 + return 0;
60433 +
60434 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
60435 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60436 + return 0;
60437 + } else if (unlikely(!(mode & GR_EXEC))) {
60438 + return 0;
60439 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
60440 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60441 + return 1;
60442 + }
60443 +
60444 + return 1;
60445 +}
60446 +
60447 +void
60448 +gr_acl_handle_psacct(struct task_struct *task, const long code)
60449 +{
60450 + unsigned long runtime;
60451 + unsigned long cputime;
60452 + unsigned int wday, cday;
60453 + __u8 whr, chr;
60454 + __u8 wmin, cmin;
60455 + __u8 wsec, csec;
60456 + struct timespec timeval;
60457 +
60458 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
60459 + !(task->acl->mode & GR_PROCACCT)))
60460 + return;
60461 +
60462 + do_posix_clock_monotonic_gettime(&timeval);
60463 + runtime = timeval.tv_sec - task->start_time.tv_sec;
60464 + wday = runtime / (3600 * 24);
60465 + runtime -= wday * (3600 * 24);
60466 + whr = runtime / 3600;
60467 + runtime -= whr * 3600;
60468 + wmin = runtime / 60;
60469 + runtime -= wmin * 60;
60470 + wsec = runtime;
60471 +
60472 + cputime = (task->utime + task->stime) / HZ;
60473 + cday = cputime / (3600 * 24);
60474 + cputime -= cday * (3600 * 24);
60475 + chr = cputime / 3600;
60476 + cputime -= chr * 3600;
60477 + cmin = cputime / 60;
60478 + cputime -= cmin * 60;
60479 + csec = cputime;
60480 +
60481 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
60482 +
60483 + return;
60484 +}
60485 +
60486 +void gr_set_kernel_label(struct task_struct *task)
60487 +{
60488 + if (gr_status & GR_READY) {
60489 + task->role = kernel_role;
60490 + task->acl = kernel_role->root_label;
60491 + }
60492 + return;
60493 +}
60494 +
60495 +#ifdef CONFIG_TASKSTATS
60496 +int gr_is_taskstats_denied(int pid)
60497 +{
60498 + struct task_struct *task;
60499 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60500 + const struct cred *cred;
60501 +#endif
60502 + int ret = 0;
60503 +
60504 + /* restrict taskstats viewing to un-chrooted root users
60505 + who have the 'view' subject flag if the RBAC system is enabled
60506 + */
60507 +
60508 + rcu_read_lock();
60509 + read_lock(&tasklist_lock);
60510 + task = find_task_by_vpid(pid);
60511 + if (task) {
60512 +#ifdef CONFIG_GRKERNSEC_CHROOT
60513 + if (proc_is_chrooted(task))
60514 + ret = -EACCES;
60515 +#endif
60516 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60517 + cred = __task_cred(task);
60518 +#ifdef CONFIG_GRKERNSEC_PROC_USER
60519 + if (gr_is_global_nonroot(cred->uid))
60520 + ret = -EACCES;
60521 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60522 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
60523 + ret = -EACCES;
60524 +#endif
60525 +#endif
60526 + if (gr_status & GR_READY) {
60527 + if (!(task->acl->mode & GR_VIEW))
60528 + ret = -EACCES;
60529 + }
60530 + } else
60531 + ret = -ENOENT;
60532 +
60533 + read_unlock(&tasklist_lock);
60534 + rcu_read_unlock();
60535 +
60536 + return ret;
60537 +}
60538 +#endif
60539 +
60540 +/* AUXV entries are filled via a descendant of search_binary_handler
60541 + after we've already applied the subject for the target
60542 +*/
60543 +int gr_acl_enable_at_secure(void)
60544 +{
60545 + if (unlikely(!(gr_status & GR_READY)))
60546 + return 0;
60547 +
60548 + if (current->acl->mode & GR_ATSECURE)
60549 + return 1;
60550 +
60551 + return 0;
60552 +}
60553 +
60554 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
60555 +{
60556 + struct task_struct *task = current;
60557 + struct dentry *dentry = file->f_path.dentry;
60558 + struct vfsmount *mnt = file->f_path.mnt;
60559 + struct acl_object_label *obj, *tmp;
60560 + struct acl_subject_label *subj;
60561 + unsigned int bufsize;
60562 + int is_not_root;
60563 + char *path;
60564 + dev_t dev = __get_dev(dentry);
60565 +
60566 + if (unlikely(!(gr_status & GR_READY)))
60567 + return 1;
60568 +
60569 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60570 + return 1;
60571 +
60572 + /* ignore Eric Biederman */
60573 + if (IS_PRIVATE(dentry->d_inode))
60574 + return 1;
60575 +
60576 + subj = task->acl;
60577 + read_lock(&gr_inode_lock);
60578 + do {
60579 + obj = lookup_acl_obj_label(ino, dev, subj);
60580 + if (obj != NULL) {
60581 + read_unlock(&gr_inode_lock);
60582 + return (obj->mode & GR_FIND) ? 1 : 0;
60583 + }
60584 + } while ((subj = subj->parent_subject));
60585 + read_unlock(&gr_inode_lock);
60586 +
60587 + /* this is purely an optimization since we're looking for an object
60588 + for the directory we're doing a readdir on
60589 + if it's possible for any globbed object to match the entry we're
60590 + filling into the directory, then the object we find here will be
60591 + an anchor point with attached globbed objects
60592 + */
60593 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
60594 + if (obj->globbed == NULL)
60595 + return (obj->mode & GR_FIND) ? 1 : 0;
60596 +
60597 + is_not_root = ((obj->filename[0] == '/') &&
60598 + (obj->filename[1] == '\0')) ? 0 : 1;
60599 + bufsize = PAGE_SIZE - namelen - is_not_root;
60600 +
60601 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
60602 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
60603 + return 1;
60604 +
60605 + preempt_disable();
60606 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
60607 + bufsize);
60608 +
60609 + bufsize = strlen(path);
60610 +
60611 + /* if base is "/", don't append an additional slash */
60612 + if (is_not_root)
60613 + *(path + bufsize) = '/';
60614 + memcpy(path + bufsize + is_not_root, name, namelen);
60615 + *(path + bufsize + namelen + is_not_root) = '\0';
60616 +
60617 + tmp = obj->globbed;
60618 + while (tmp) {
60619 + if (!glob_match(tmp->filename, path)) {
60620 + preempt_enable();
60621 + return (tmp->mode & GR_FIND) ? 1 : 0;
60622 + }
60623 + tmp = tmp->next;
60624 + }
60625 + preempt_enable();
60626 + return (obj->mode & GR_FIND) ? 1 : 0;
60627 +}
60628 +
60629 +void gr_put_exec_file(struct task_struct *task)
60630 +{
60631 + struct file *filp;
60632 +
60633 + write_lock(&grsec_exec_file_lock);
60634 + filp = task->exec_file;
60635 + task->exec_file = NULL;
60636 + write_unlock(&grsec_exec_file_lock);
60637 +
60638 + if (filp)
60639 + fput(filp);
60640 +
60641 + return;
60642 +}
60643 +
60644 +
60645 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
60646 +EXPORT_SYMBOL(gr_acl_is_enabled);
60647 +#endif
60648 +EXPORT_SYMBOL(gr_set_kernel_label);
60649 +#ifdef CONFIG_SECURITY
60650 +EXPORT_SYMBOL(gr_check_user_change);
60651 +EXPORT_SYMBOL(gr_check_group_change);
60652 +#endif
60653 +
60654 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
60655 new file mode 100644
60656 index 0000000..34fefda
60657 --- /dev/null
60658 +++ b/grsecurity/gracl_alloc.c
60659 @@ -0,0 +1,105 @@
60660 +#include <linux/kernel.h>
60661 +#include <linux/mm.h>
60662 +#include <linux/slab.h>
60663 +#include <linux/vmalloc.h>
60664 +#include <linux/gracl.h>
60665 +#include <linux/grsecurity.h>
60666 +
60667 +static unsigned long alloc_stack_next = 1;
60668 +static unsigned long alloc_stack_size = 1;
60669 +static void **alloc_stack;
60670 +
60671 +static __inline__ int
60672 +alloc_pop(void)
60673 +{
60674 + if (alloc_stack_next == 1)
60675 + return 0;
60676 +
60677 + kfree(alloc_stack[alloc_stack_next - 2]);
60678 +
60679 + alloc_stack_next--;
60680 +
60681 + return 1;
60682 +}
60683 +
60684 +static __inline__ int
60685 +alloc_push(void *buf)
60686 +{
60687 + if (alloc_stack_next >= alloc_stack_size)
60688 + return 1;
60689 +
60690 + alloc_stack[alloc_stack_next - 1] = buf;
60691 +
60692 + alloc_stack_next++;
60693 +
60694 + return 0;
60695 +}
60696 +
60697 +void *
60698 +acl_alloc(unsigned long len)
60699 +{
60700 + void *ret = NULL;
60701 +
60702 + if (!len || len > PAGE_SIZE)
60703 + goto out;
60704 +
60705 + ret = kmalloc(len, GFP_KERNEL);
60706 +
60707 + if (ret) {
60708 + if (alloc_push(ret)) {
60709 + kfree(ret);
60710 + ret = NULL;
60711 + }
60712 + }
60713 +
60714 +out:
60715 + return ret;
60716 +}
60717 +
60718 +void *
60719 +acl_alloc_num(unsigned long num, unsigned long len)
60720 +{
60721 + if (!len || (num > (PAGE_SIZE / len)))
60722 + return NULL;
60723 +
60724 + return acl_alloc(num * len);
60725 +}
60726 +
60727 +void
60728 +acl_free_all(void)
60729 +{
60730 + if (gr_acl_is_enabled() || !alloc_stack)
60731 + return;
60732 +
60733 + while (alloc_pop()) ;
60734 +
60735 + if (alloc_stack) {
60736 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
60737 + kfree(alloc_stack);
60738 + else
60739 + vfree(alloc_stack);
60740 + }
60741 +
60742 + alloc_stack = NULL;
60743 + alloc_stack_size = 1;
60744 + alloc_stack_next = 1;
60745 +
60746 + return;
60747 +}
60748 +
60749 +int
60750 +acl_alloc_stack_init(unsigned long size)
60751 +{
60752 + if ((size * sizeof (void *)) <= PAGE_SIZE)
60753 + alloc_stack =
60754 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
60755 + else
60756 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
60757 +
60758 + alloc_stack_size = size;
60759 +
60760 + if (!alloc_stack)
60761 + return 0;
60762 + else
60763 + return 1;
60764 +}
60765 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
60766 new file mode 100644
60767 index 0000000..bdd51ea
60768 --- /dev/null
60769 +++ b/grsecurity/gracl_cap.c
60770 @@ -0,0 +1,110 @@
60771 +#include <linux/kernel.h>
60772 +#include <linux/module.h>
60773 +#include <linux/sched.h>
60774 +#include <linux/gracl.h>
60775 +#include <linux/grsecurity.h>
60776 +#include <linux/grinternal.h>
60777 +
60778 +extern const char *captab_log[];
60779 +extern int captab_log_entries;
60780 +
60781 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60782 +{
60783 + struct acl_subject_label *curracl;
60784 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
60785 + kernel_cap_t cap_audit = __cap_empty_set;
60786 +
60787 + if (!gr_acl_is_enabled())
60788 + return 1;
60789 +
60790 + curracl = task->acl;
60791 +
60792 + cap_drop = curracl->cap_lower;
60793 + cap_mask = curracl->cap_mask;
60794 + cap_audit = curracl->cap_invert_audit;
60795 +
60796 + while ((curracl = curracl->parent_subject)) {
60797 + /* if the cap isn't specified in the current computed mask but is specified in the
60798 + current level subject, and is lowered in the current level subject, then add
60799 + it to the set of dropped capabilities
60800 + otherwise, add the current level subject's mask to the current computed mask
60801 + */
60802 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
60803 + cap_raise(cap_mask, cap);
60804 + if (cap_raised(curracl->cap_lower, cap))
60805 + cap_raise(cap_drop, cap);
60806 + if (cap_raised(curracl->cap_invert_audit, cap))
60807 + cap_raise(cap_audit, cap);
60808 + }
60809 + }
60810 +
60811 + if (!cap_raised(cap_drop, cap)) {
60812 + if (cap_raised(cap_audit, cap))
60813 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
60814 + return 1;
60815 + }
60816 +
60817 + curracl = task->acl;
60818 +
60819 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
60820 + && cap_raised(cred->cap_effective, cap)) {
60821 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60822 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
60823 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
60824 + gr_to_filename(task->exec_file->f_path.dentry,
60825 + task->exec_file->f_path.mnt) : curracl->filename,
60826 + curracl->filename, 0UL,
60827 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
60828 + return 1;
60829 + }
60830 +
60831 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
60832 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
60833 +
60834 + return 0;
60835 +}
60836 +
60837 +int
60838 +gr_acl_is_capable(const int cap)
60839 +{
60840 + return gr_task_acl_is_capable(current, current_cred(), cap);
60841 +}
60842 +
60843 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
60844 +{
60845 + struct acl_subject_label *curracl;
60846 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
60847 +
60848 + if (!gr_acl_is_enabled())
60849 + return 1;
60850 +
60851 + curracl = task->acl;
60852 +
60853 + cap_drop = curracl->cap_lower;
60854 + cap_mask = curracl->cap_mask;
60855 +
60856 + while ((curracl = curracl->parent_subject)) {
60857 + /* if the cap isn't specified in the current computed mask but is specified in the
60858 + current level subject, and is lowered in the current level subject, then add
60859 + it to the set of dropped capabilities
60860 + otherwise, add the current level subject's mask to the current computed mask
60861 + */
60862 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
60863 + cap_raise(cap_mask, cap);
60864 + if (cap_raised(curracl->cap_lower, cap))
60865 + cap_raise(cap_drop, cap);
60866 + }
60867 + }
60868 +
60869 + if (!cap_raised(cap_drop, cap))
60870 + return 1;
60871 +
60872 + return 0;
60873 +}
60874 +
60875 +int
60876 +gr_acl_is_capable_nolog(const int cap)
60877 +{
60878 + return gr_task_acl_is_capable_nolog(current, cap);
60879 +}
60880 +
60881 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
60882 new file mode 100644
60883 index 0000000..a340c17
60884 --- /dev/null
60885 +++ b/grsecurity/gracl_fs.c
60886 @@ -0,0 +1,431 @@
60887 +#include <linux/kernel.h>
60888 +#include <linux/sched.h>
60889 +#include <linux/types.h>
60890 +#include <linux/fs.h>
60891 +#include <linux/file.h>
60892 +#include <linux/stat.h>
60893 +#include <linux/grsecurity.h>
60894 +#include <linux/grinternal.h>
60895 +#include <linux/gracl.h>
60896 +
60897 +umode_t
60898 +gr_acl_umask(void)
60899 +{
60900 + if (unlikely(!gr_acl_is_enabled()))
60901 + return 0;
60902 +
60903 + return current->role->umask;
60904 +}
60905 +
60906 +__u32
60907 +gr_acl_handle_hidden_file(const struct dentry * dentry,
60908 + const struct vfsmount * mnt)
60909 +{
60910 + __u32 mode;
60911 +
60912 + if (unlikely(!dentry->d_inode))
60913 + return GR_FIND;
60914 +
60915 + mode =
60916 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
60917 +
60918 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
60919 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
60920 + return mode;
60921 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
60922 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
60923 + return 0;
60924 + } else if (unlikely(!(mode & GR_FIND)))
60925 + return 0;
60926 +
60927 + return GR_FIND;
60928 +}
60929 +
60930 +__u32
60931 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
60932 + int acc_mode)
60933 +{
60934 + __u32 reqmode = GR_FIND;
60935 + __u32 mode;
60936 +
60937 + if (unlikely(!dentry->d_inode))
60938 + return reqmode;
60939 +
60940 + if (acc_mode & MAY_APPEND)
60941 + reqmode |= GR_APPEND;
60942 + else if (acc_mode & MAY_WRITE)
60943 + reqmode |= GR_WRITE;
60944 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
60945 + reqmode |= GR_READ;
60946 +
60947 + mode =
60948 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
60949 + mnt);
60950 +
60951 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
60952 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
60953 + reqmode & GR_READ ? " reading" : "",
60954 + reqmode & GR_WRITE ? " writing" : reqmode &
60955 + GR_APPEND ? " appending" : "");
60956 + return reqmode;
60957 + } else
60958 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
60959 + {
60960 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
60961 + reqmode & GR_READ ? " reading" : "",
60962 + reqmode & GR_WRITE ? " writing" : reqmode &
60963 + GR_APPEND ? " appending" : "");
60964 + return 0;
60965 + } else if (unlikely((mode & reqmode) != reqmode))
60966 + return 0;
60967 +
60968 + return reqmode;
60969 +}
60970 +
60971 +__u32
60972 +gr_acl_handle_creat(const struct dentry * dentry,
60973 + const struct dentry * p_dentry,
60974 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60975 + const int imode)
60976 +{
60977 + __u32 reqmode = GR_WRITE | GR_CREATE;
60978 + __u32 mode;
60979 +
60980 + if (acc_mode & MAY_APPEND)
60981 + reqmode |= GR_APPEND;
60982 + // if a directory was required or the directory already exists, then
60983 + // don't count this open as a read
60984 + if ((acc_mode & MAY_READ) &&
60985 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
60986 + reqmode |= GR_READ;
60987 + if ((open_flags & O_CREAT) &&
60988 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
60989 + reqmode |= GR_SETID;
60990 +
60991 + mode =
60992 + gr_check_create(dentry, p_dentry, p_mnt,
60993 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
60994 +
60995 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
60996 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
60997 + reqmode & GR_READ ? " reading" : "",
60998 + reqmode & GR_WRITE ? " writing" : reqmode &
60999 + GR_APPEND ? " appending" : "");
61000 + return reqmode;
61001 + } else
61002 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61003 + {
61004 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61005 + reqmode & GR_READ ? " reading" : "",
61006 + reqmode & GR_WRITE ? " writing" : reqmode &
61007 + GR_APPEND ? " appending" : "");
61008 + return 0;
61009 + } else if (unlikely((mode & reqmode) != reqmode))
61010 + return 0;
61011 +
61012 + return reqmode;
61013 +}
61014 +
61015 +__u32
61016 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
61017 + const int fmode)
61018 +{
61019 + __u32 mode, reqmode = GR_FIND;
61020 +
61021 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
61022 + reqmode |= GR_EXEC;
61023 + if (fmode & S_IWOTH)
61024 + reqmode |= GR_WRITE;
61025 + if (fmode & S_IROTH)
61026 + reqmode |= GR_READ;
61027 +
61028 + mode =
61029 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61030 + mnt);
61031 +
61032 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61033 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61034 + reqmode & GR_READ ? " reading" : "",
61035 + reqmode & GR_WRITE ? " writing" : "",
61036 + reqmode & GR_EXEC ? " executing" : "");
61037 + return reqmode;
61038 + } else
61039 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61040 + {
61041 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61042 + reqmode & GR_READ ? " reading" : "",
61043 + reqmode & GR_WRITE ? " writing" : "",
61044 + reqmode & GR_EXEC ? " executing" : "");
61045 + return 0;
61046 + } else if (unlikely((mode & reqmode) != reqmode))
61047 + return 0;
61048 +
61049 + return reqmode;
61050 +}
61051 +
61052 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
61053 +{
61054 + __u32 mode;
61055 +
61056 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
61057 +
61058 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61059 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
61060 + return mode;
61061 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61062 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
61063 + return 0;
61064 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
61065 + return 0;
61066 +
61067 + return (reqmode);
61068 +}
61069 +
61070 +__u32
61071 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
61072 +{
61073 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
61074 +}
61075 +
61076 +__u32
61077 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
61078 +{
61079 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
61080 +}
61081 +
61082 +__u32
61083 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
61084 +{
61085 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
61086 +}
61087 +
61088 +__u32
61089 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
61090 +{
61091 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
61092 +}
61093 +
61094 +__u32
61095 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
61096 + umode_t *modeptr)
61097 +{
61098 + umode_t mode;
61099 +
61100 + *modeptr &= ~gr_acl_umask();
61101 + mode = *modeptr;
61102 +
61103 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
61104 + return 1;
61105 +
61106 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
61107 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
61108 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
61109 + GR_CHMOD_ACL_MSG);
61110 + } else {
61111 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
61112 + }
61113 +}
61114 +
61115 +__u32
61116 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
61117 +{
61118 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
61119 +}
61120 +
61121 +__u32
61122 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
61123 +{
61124 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
61125 +}
61126 +
61127 +__u32
61128 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
61129 +{
61130 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
61131 +}
61132 +
61133 +__u32
61134 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
61135 +{
61136 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
61137 + GR_UNIXCONNECT_ACL_MSG);
61138 +}
61139 +
61140 +/* hardlinks require at minimum create and link permission,
61141 + any additional privilege required is based on the
61142 + privilege of the file being linked to
61143 +*/
61144 +__u32
61145 +gr_acl_handle_link(const struct dentry * new_dentry,
61146 + const struct dentry * parent_dentry,
61147 + const struct vfsmount * parent_mnt,
61148 + const struct dentry * old_dentry,
61149 + const struct vfsmount * old_mnt, const struct filename *to)
61150 +{
61151 + __u32 mode;
61152 + __u32 needmode = GR_CREATE | GR_LINK;
61153 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
61154 +
61155 + mode =
61156 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
61157 + old_mnt);
61158 +
61159 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
61160 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61161 + return mode;
61162 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61163 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61164 + return 0;
61165 + } else if (unlikely((mode & needmode) != needmode))
61166 + return 0;
61167 +
61168 + return 1;
61169 +}
61170 +
61171 +__u32
61172 +gr_acl_handle_symlink(const struct dentry * new_dentry,
61173 + const struct dentry * parent_dentry,
61174 + const struct vfsmount * parent_mnt, const struct filename *from)
61175 +{
61176 + __u32 needmode = GR_WRITE | GR_CREATE;
61177 + __u32 mode;
61178 +
61179 + mode =
61180 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
61181 + GR_CREATE | GR_AUDIT_CREATE |
61182 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
61183 +
61184 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
61185 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61186 + return mode;
61187 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61188 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61189 + return 0;
61190 + } else if (unlikely((mode & needmode) != needmode))
61191 + return 0;
61192 +
61193 + return (GR_WRITE | GR_CREATE);
61194 +}
61195 +
61196 +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)
61197 +{
61198 + __u32 mode;
61199 +
61200 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61201 +
61202 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61203 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
61204 + return mode;
61205 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61206 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
61207 + return 0;
61208 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
61209 + return 0;
61210 +
61211 + return (reqmode);
61212 +}
61213 +
61214 +__u32
61215 +gr_acl_handle_mknod(const struct dentry * new_dentry,
61216 + const struct dentry * parent_dentry,
61217 + const struct vfsmount * parent_mnt,
61218 + const int mode)
61219 +{
61220 + __u32 reqmode = GR_WRITE | GR_CREATE;
61221 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61222 + reqmode |= GR_SETID;
61223 +
61224 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61225 + reqmode, GR_MKNOD_ACL_MSG);
61226 +}
61227 +
61228 +__u32
61229 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
61230 + const struct dentry *parent_dentry,
61231 + const struct vfsmount *parent_mnt)
61232 +{
61233 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61234 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
61235 +}
61236 +
61237 +#define RENAME_CHECK_SUCCESS(old, new) \
61238 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
61239 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
61240 +
61241 +int
61242 +gr_acl_handle_rename(struct dentry *new_dentry,
61243 + struct dentry *parent_dentry,
61244 + const struct vfsmount *parent_mnt,
61245 + struct dentry *old_dentry,
61246 + struct inode *old_parent_inode,
61247 + struct vfsmount *old_mnt, const struct filename *newname)
61248 +{
61249 + __u32 comp1, comp2;
61250 + int error = 0;
61251 +
61252 + if (unlikely(!gr_acl_is_enabled()))
61253 + return 0;
61254 +
61255 + if (!new_dentry->d_inode) {
61256 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
61257 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
61258 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
61259 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
61260 + GR_DELETE | GR_AUDIT_DELETE |
61261 + GR_AUDIT_READ | GR_AUDIT_WRITE |
61262 + GR_SUPPRESS, old_mnt);
61263 + } else {
61264 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
61265 + GR_CREATE | GR_DELETE |
61266 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
61267 + GR_AUDIT_READ | GR_AUDIT_WRITE |
61268 + GR_SUPPRESS, parent_mnt);
61269 + comp2 =
61270 + gr_search_file(old_dentry,
61271 + GR_READ | GR_WRITE | GR_AUDIT_READ |
61272 + GR_DELETE | GR_AUDIT_DELETE |
61273 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
61274 + }
61275 +
61276 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
61277 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
61278 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61279 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
61280 + && !(comp2 & GR_SUPPRESS)) {
61281 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61282 + error = -EACCES;
61283 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
61284 + error = -EACCES;
61285 +
61286 + return error;
61287 +}
61288 +
61289 +void
61290 +gr_acl_handle_exit(void)
61291 +{
61292 + u16 id;
61293 + char *rolename;
61294 +
61295 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
61296 + !(current->role->roletype & GR_ROLE_PERSIST))) {
61297 + id = current->acl_role_id;
61298 + rolename = current->role->rolename;
61299 + gr_set_acls(1);
61300 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
61301 + }
61302 +
61303 + gr_put_exec_file(current);
61304 + return;
61305 +}
61306 +
61307 +int
61308 +gr_acl_handle_procpidmem(const struct task_struct *task)
61309 +{
61310 + if (unlikely(!gr_acl_is_enabled()))
61311 + return 0;
61312 +
61313 + if (task != current && task->acl->mode & GR_PROTPROCFD)
61314 + return -EACCES;
61315 +
61316 + return 0;
61317 +}
61318 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
61319 new file mode 100644
61320 index 0000000..4699807
61321 --- /dev/null
61322 +++ b/grsecurity/gracl_ip.c
61323 @@ -0,0 +1,384 @@
61324 +#include <linux/kernel.h>
61325 +#include <asm/uaccess.h>
61326 +#include <asm/errno.h>
61327 +#include <net/sock.h>
61328 +#include <linux/file.h>
61329 +#include <linux/fs.h>
61330 +#include <linux/net.h>
61331 +#include <linux/in.h>
61332 +#include <linux/skbuff.h>
61333 +#include <linux/ip.h>
61334 +#include <linux/udp.h>
61335 +#include <linux/types.h>
61336 +#include <linux/sched.h>
61337 +#include <linux/netdevice.h>
61338 +#include <linux/inetdevice.h>
61339 +#include <linux/gracl.h>
61340 +#include <linux/grsecurity.h>
61341 +#include <linux/grinternal.h>
61342 +
61343 +#define GR_BIND 0x01
61344 +#define GR_CONNECT 0x02
61345 +#define GR_INVERT 0x04
61346 +#define GR_BINDOVERRIDE 0x08
61347 +#define GR_CONNECTOVERRIDE 0x10
61348 +#define GR_SOCK_FAMILY 0x20
61349 +
61350 +static const char * gr_protocols[IPPROTO_MAX] = {
61351 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
61352 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
61353 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
61354 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
61355 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
61356 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
61357 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
61358 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
61359 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
61360 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
61361 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
61362 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
61363 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
61364 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
61365 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
61366 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
61367 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
61368 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
61369 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
61370 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
61371 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
61372 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
61373 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
61374 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
61375 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
61376 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
61377 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
61378 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
61379 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
61380 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
61381 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
61382 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
61383 + };
61384 +
61385 +static const char * gr_socktypes[SOCK_MAX] = {
61386 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
61387 + "unknown:7", "unknown:8", "unknown:9", "packet"
61388 + };
61389 +
61390 +static const char * gr_sockfamilies[AF_MAX+1] = {
61391 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
61392 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
61393 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
61394 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
61395 + };
61396 +
61397 +const char *
61398 +gr_proto_to_name(unsigned char proto)
61399 +{
61400 + return gr_protocols[proto];
61401 +}
61402 +
61403 +const char *
61404 +gr_socktype_to_name(unsigned char type)
61405 +{
61406 + return gr_socktypes[type];
61407 +}
61408 +
61409 +const char *
61410 +gr_sockfamily_to_name(unsigned char family)
61411 +{
61412 + return gr_sockfamilies[family];
61413 +}
61414 +
61415 +int
61416 +gr_search_socket(const int domain, const int type, const int protocol)
61417 +{
61418 + struct acl_subject_label *curr;
61419 + const struct cred *cred = current_cred();
61420 +
61421 + if (unlikely(!gr_acl_is_enabled()))
61422 + goto exit;
61423 +
61424 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
61425 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
61426 + goto exit; // let the kernel handle it
61427 +
61428 + curr = current->acl;
61429 +
61430 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
61431 + /* the family is allowed, if this is PF_INET allow it only if
61432 + the extra sock type/protocol checks pass */
61433 + if (domain == PF_INET)
61434 + goto inet_check;
61435 + goto exit;
61436 + } else {
61437 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61438 + __u32 fakeip = 0;
61439 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61440 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61441 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61442 + gr_to_filename(current->exec_file->f_path.dentry,
61443 + current->exec_file->f_path.mnt) :
61444 + curr->filename, curr->filename,
61445 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
61446 + &current->signal->saved_ip);
61447 + goto exit;
61448 + }
61449 + goto exit_fail;
61450 + }
61451 +
61452 +inet_check:
61453 + /* the rest of this checking is for IPv4 only */
61454 + if (!curr->ips)
61455 + goto exit;
61456 +
61457 + if ((curr->ip_type & (1 << type)) &&
61458 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
61459 + goto exit;
61460 +
61461 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61462 + /* we don't place acls on raw sockets , and sometimes
61463 + dgram/ip sockets are opened for ioctl and not
61464 + bind/connect, so we'll fake a bind learn log */
61465 + if (type == SOCK_RAW || type == SOCK_PACKET) {
61466 + __u32 fakeip = 0;
61467 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61468 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61469 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61470 + gr_to_filename(current->exec_file->f_path.dentry,
61471 + current->exec_file->f_path.mnt) :
61472 + curr->filename, curr->filename,
61473 + &fakeip, 0, type,
61474 + protocol, GR_CONNECT, &current->signal->saved_ip);
61475 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
61476 + __u32 fakeip = 0;
61477 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61478 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61479 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61480 + gr_to_filename(current->exec_file->f_path.dentry,
61481 + current->exec_file->f_path.mnt) :
61482 + curr->filename, curr->filename,
61483 + &fakeip, 0, type,
61484 + protocol, GR_BIND, &current->signal->saved_ip);
61485 + }
61486 + /* we'll log when they use connect or bind */
61487 + goto exit;
61488 + }
61489 +
61490 +exit_fail:
61491 + if (domain == PF_INET)
61492 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
61493 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
61494 + else
61495 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
61496 + gr_socktype_to_name(type), protocol);
61497 +
61498 + return 0;
61499 +exit:
61500 + return 1;
61501 +}
61502 +
61503 +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)
61504 +{
61505 + if ((ip->mode & mode) &&
61506 + (ip_port >= ip->low) &&
61507 + (ip_port <= ip->high) &&
61508 + ((ntohl(ip_addr) & our_netmask) ==
61509 + (ntohl(our_addr) & our_netmask))
61510 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
61511 + && (ip->type & (1 << type))) {
61512 + if (ip->mode & GR_INVERT)
61513 + return 2; // specifically denied
61514 + else
61515 + return 1; // allowed
61516 + }
61517 +
61518 + return 0; // not specifically allowed, may continue parsing
61519 +}
61520 +
61521 +static int
61522 +gr_search_connectbind(const int full_mode, struct sock *sk,
61523 + struct sockaddr_in *addr, const int type)
61524 +{
61525 + char iface[IFNAMSIZ] = {0};
61526 + struct acl_subject_label *curr;
61527 + struct acl_ip_label *ip;
61528 + struct inet_sock *isk;
61529 + struct net_device *dev;
61530 + struct in_device *idev;
61531 + unsigned long i;
61532 + int ret;
61533 + int mode = full_mode & (GR_BIND | GR_CONNECT);
61534 + __u32 ip_addr = 0;
61535 + __u32 our_addr;
61536 + __u32 our_netmask;
61537 + char *p;
61538 + __u16 ip_port = 0;
61539 + const struct cred *cred = current_cred();
61540 +
61541 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
61542 + return 0;
61543 +
61544 + curr = current->acl;
61545 + isk = inet_sk(sk);
61546 +
61547 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
61548 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
61549 + addr->sin_addr.s_addr = curr->inaddr_any_override;
61550 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
61551 + struct sockaddr_in saddr;
61552 + int err;
61553 +
61554 + saddr.sin_family = AF_INET;
61555 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
61556 + saddr.sin_port = isk->inet_sport;
61557 +
61558 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
61559 + if (err)
61560 + return err;
61561 +
61562 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
61563 + if (err)
61564 + return err;
61565 + }
61566 +
61567 + if (!curr->ips)
61568 + return 0;
61569 +
61570 + ip_addr = addr->sin_addr.s_addr;
61571 + ip_port = ntohs(addr->sin_port);
61572 +
61573 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61574 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61575 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61576 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61577 + gr_to_filename(current->exec_file->f_path.dentry,
61578 + current->exec_file->f_path.mnt) :
61579 + curr->filename, curr->filename,
61580 + &ip_addr, ip_port, type,
61581 + sk->sk_protocol, mode, &current->signal->saved_ip);
61582 + return 0;
61583 + }
61584 +
61585 + for (i = 0; i < curr->ip_num; i++) {
61586 + ip = *(curr->ips + i);
61587 + if (ip->iface != NULL) {
61588 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
61589 + p = strchr(iface, ':');
61590 + if (p != NULL)
61591 + *p = '\0';
61592 + dev = dev_get_by_name(sock_net(sk), iface);
61593 + if (dev == NULL)
61594 + continue;
61595 + idev = in_dev_get(dev);
61596 + if (idev == NULL) {
61597 + dev_put(dev);
61598 + continue;
61599 + }
61600 + rcu_read_lock();
61601 + for_ifa(idev) {
61602 + if (!strcmp(ip->iface, ifa->ifa_label)) {
61603 + our_addr = ifa->ifa_address;
61604 + our_netmask = 0xffffffff;
61605 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
61606 + if (ret == 1) {
61607 + rcu_read_unlock();
61608 + in_dev_put(idev);
61609 + dev_put(dev);
61610 + return 0;
61611 + } else if (ret == 2) {
61612 + rcu_read_unlock();
61613 + in_dev_put(idev);
61614 + dev_put(dev);
61615 + goto denied;
61616 + }
61617 + }
61618 + } endfor_ifa(idev);
61619 + rcu_read_unlock();
61620 + in_dev_put(idev);
61621 + dev_put(dev);
61622 + } else {
61623 + our_addr = ip->addr;
61624 + our_netmask = ip->netmask;
61625 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
61626 + if (ret == 1)
61627 + return 0;
61628 + else if (ret == 2)
61629 + goto denied;
61630 + }
61631 + }
61632 +
61633 +denied:
61634 + if (mode == GR_BIND)
61635 + 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));
61636 + else if (mode == GR_CONNECT)
61637 + 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));
61638 +
61639 + return -EACCES;
61640 +}
61641 +
61642 +int
61643 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
61644 +{
61645 + /* always allow disconnection of dgram sockets with connect */
61646 + if (addr->sin_family == AF_UNSPEC)
61647 + return 0;
61648 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
61649 +}
61650 +
61651 +int
61652 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
61653 +{
61654 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
61655 +}
61656 +
61657 +int gr_search_listen(struct socket *sock)
61658 +{
61659 + struct sock *sk = sock->sk;
61660 + struct sockaddr_in addr;
61661 +
61662 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
61663 + addr.sin_port = inet_sk(sk)->inet_sport;
61664 +
61665 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
61666 +}
61667 +
61668 +int gr_search_accept(struct socket *sock)
61669 +{
61670 + struct sock *sk = sock->sk;
61671 + struct sockaddr_in addr;
61672 +
61673 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
61674 + addr.sin_port = inet_sk(sk)->inet_sport;
61675 +
61676 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
61677 +}
61678 +
61679 +int
61680 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
61681 +{
61682 + if (addr)
61683 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
61684 + else {
61685 + struct sockaddr_in sin;
61686 + const struct inet_sock *inet = inet_sk(sk);
61687 +
61688 + sin.sin_addr.s_addr = inet->inet_daddr;
61689 + sin.sin_port = inet->inet_dport;
61690 +
61691 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
61692 + }
61693 +}
61694 +
61695 +int
61696 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
61697 +{
61698 + struct sockaddr_in sin;
61699 +
61700 + if (unlikely(skb->len < sizeof (struct udphdr)))
61701 + return 0; // skip this packet
61702 +
61703 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
61704 + sin.sin_port = udp_hdr(skb)->source;
61705 +
61706 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
61707 +}
61708 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
61709 new file mode 100644
61710 index 0000000..25f54ef
61711 --- /dev/null
61712 +++ b/grsecurity/gracl_learn.c
61713 @@ -0,0 +1,207 @@
61714 +#include <linux/kernel.h>
61715 +#include <linux/mm.h>
61716 +#include <linux/sched.h>
61717 +#include <linux/poll.h>
61718 +#include <linux/string.h>
61719 +#include <linux/file.h>
61720 +#include <linux/types.h>
61721 +#include <linux/vmalloc.h>
61722 +#include <linux/grinternal.h>
61723 +
61724 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
61725 + size_t count, loff_t *ppos);
61726 +extern int gr_acl_is_enabled(void);
61727 +
61728 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
61729 +static int gr_learn_attached;
61730 +
61731 +/* use a 512k buffer */
61732 +#define LEARN_BUFFER_SIZE (512 * 1024)
61733 +
61734 +static DEFINE_SPINLOCK(gr_learn_lock);
61735 +static DEFINE_MUTEX(gr_learn_user_mutex);
61736 +
61737 +/* we need to maintain two buffers, so that the kernel context of grlearn
61738 + uses a semaphore around the userspace copying, and the other kernel contexts
61739 + use a spinlock when copying into the buffer, since they cannot sleep
61740 +*/
61741 +static char *learn_buffer;
61742 +static char *learn_buffer_user;
61743 +static int learn_buffer_len;
61744 +static int learn_buffer_user_len;
61745 +
61746 +static ssize_t
61747 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
61748 +{
61749 + DECLARE_WAITQUEUE(wait, current);
61750 + ssize_t retval = 0;
61751 +
61752 + add_wait_queue(&learn_wait, &wait);
61753 + set_current_state(TASK_INTERRUPTIBLE);
61754 + do {
61755 + mutex_lock(&gr_learn_user_mutex);
61756 + spin_lock(&gr_learn_lock);
61757 + if (learn_buffer_len)
61758 + break;
61759 + spin_unlock(&gr_learn_lock);
61760 + mutex_unlock(&gr_learn_user_mutex);
61761 + if (file->f_flags & O_NONBLOCK) {
61762 + retval = -EAGAIN;
61763 + goto out;
61764 + }
61765 + if (signal_pending(current)) {
61766 + retval = -ERESTARTSYS;
61767 + goto out;
61768 + }
61769 +
61770 + schedule();
61771 + } while (1);
61772 +
61773 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
61774 + learn_buffer_user_len = learn_buffer_len;
61775 + retval = learn_buffer_len;
61776 + learn_buffer_len = 0;
61777 +
61778 + spin_unlock(&gr_learn_lock);
61779 +
61780 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
61781 + retval = -EFAULT;
61782 +
61783 + mutex_unlock(&gr_learn_user_mutex);
61784 +out:
61785 + set_current_state(TASK_RUNNING);
61786 + remove_wait_queue(&learn_wait, &wait);
61787 + return retval;
61788 +}
61789 +
61790 +static unsigned int
61791 +poll_learn(struct file * file, poll_table * wait)
61792 +{
61793 + poll_wait(file, &learn_wait, wait);
61794 +
61795 + if (learn_buffer_len)
61796 + return (POLLIN | POLLRDNORM);
61797 +
61798 + return 0;
61799 +}
61800 +
61801 +void
61802 +gr_clear_learn_entries(void)
61803 +{
61804 + char *tmp;
61805 +
61806 + mutex_lock(&gr_learn_user_mutex);
61807 + spin_lock(&gr_learn_lock);
61808 + tmp = learn_buffer;
61809 + learn_buffer = NULL;
61810 + spin_unlock(&gr_learn_lock);
61811 + if (tmp)
61812 + vfree(tmp);
61813 + if (learn_buffer_user != NULL) {
61814 + vfree(learn_buffer_user);
61815 + learn_buffer_user = NULL;
61816 + }
61817 + learn_buffer_len = 0;
61818 + mutex_unlock(&gr_learn_user_mutex);
61819 +
61820 + return;
61821 +}
61822 +
61823 +void
61824 +gr_add_learn_entry(const char *fmt, ...)
61825 +{
61826 + va_list args;
61827 + unsigned int len;
61828 +
61829 + if (!gr_learn_attached)
61830 + return;
61831 +
61832 + spin_lock(&gr_learn_lock);
61833 +
61834 + /* leave a gap at the end so we know when it's "full" but don't have to
61835 + compute the exact length of the string we're trying to append
61836 + */
61837 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
61838 + spin_unlock(&gr_learn_lock);
61839 + wake_up_interruptible(&learn_wait);
61840 + return;
61841 + }
61842 + if (learn_buffer == NULL) {
61843 + spin_unlock(&gr_learn_lock);
61844 + return;
61845 + }
61846 +
61847 + va_start(args, fmt);
61848 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
61849 + va_end(args);
61850 +
61851 + learn_buffer_len += len + 1;
61852 +
61853 + spin_unlock(&gr_learn_lock);
61854 + wake_up_interruptible(&learn_wait);
61855 +
61856 + return;
61857 +}
61858 +
61859 +static int
61860 +open_learn(struct inode *inode, struct file *file)
61861 +{
61862 + if (file->f_mode & FMODE_READ && gr_learn_attached)
61863 + return -EBUSY;
61864 + if (file->f_mode & FMODE_READ) {
61865 + int retval = 0;
61866 + mutex_lock(&gr_learn_user_mutex);
61867 + if (learn_buffer == NULL)
61868 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
61869 + if (learn_buffer_user == NULL)
61870 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
61871 + if (learn_buffer == NULL) {
61872 + retval = -ENOMEM;
61873 + goto out_error;
61874 + }
61875 + if (learn_buffer_user == NULL) {
61876 + retval = -ENOMEM;
61877 + goto out_error;
61878 + }
61879 + learn_buffer_len = 0;
61880 + learn_buffer_user_len = 0;
61881 + gr_learn_attached = 1;
61882 +out_error:
61883 + mutex_unlock(&gr_learn_user_mutex);
61884 + return retval;
61885 + }
61886 + return 0;
61887 +}
61888 +
61889 +static int
61890 +close_learn(struct inode *inode, struct file *file)
61891 +{
61892 + if (file->f_mode & FMODE_READ) {
61893 + char *tmp = NULL;
61894 + mutex_lock(&gr_learn_user_mutex);
61895 + spin_lock(&gr_learn_lock);
61896 + tmp = learn_buffer;
61897 + learn_buffer = NULL;
61898 + spin_unlock(&gr_learn_lock);
61899 + if (tmp)
61900 + vfree(tmp);
61901 + if (learn_buffer_user != NULL) {
61902 + vfree(learn_buffer_user);
61903 + learn_buffer_user = NULL;
61904 + }
61905 + learn_buffer_len = 0;
61906 + learn_buffer_user_len = 0;
61907 + gr_learn_attached = 0;
61908 + mutex_unlock(&gr_learn_user_mutex);
61909 + }
61910 +
61911 + return 0;
61912 +}
61913 +
61914 +const struct file_operations grsec_fops = {
61915 + .read = read_learn,
61916 + .write = write_grsec_handler,
61917 + .open = open_learn,
61918 + .release = close_learn,
61919 + .poll = poll_learn,
61920 +};
61921 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
61922 new file mode 100644
61923 index 0000000..39645c9
61924 --- /dev/null
61925 +++ b/grsecurity/gracl_res.c
61926 @@ -0,0 +1,68 @@
61927 +#include <linux/kernel.h>
61928 +#include <linux/sched.h>
61929 +#include <linux/gracl.h>
61930 +#include <linux/grinternal.h>
61931 +
61932 +static const char *restab_log[] = {
61933 + [RLIMIT_CPU] = "RLIMIT_CPU",
61934 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
61935 + [RLIMIT_DATA] = "RLIMIT_DATA",
61936 + [RLIMIT_STACK] = "RLIMIT_STACK",
61937 + [RLIMIT_CORE] = "RLIMIT_CORE",
61938 + [RLIMIT_RSS] = "RLIMIT_RSS",
61939 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
61940 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
61941 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
61942 + [RLIMIT_AS] = "RLIMIT_AS",
61943 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
61944 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
61945 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
61946 + [RLIMIT_NICE] = "RLIMIT_NICE",
61947 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
61948 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
61949 + [GR_CRASH_RES] = "RLIMIT_CRASH"
61950 +};
61951 +
61952 +void
61953 +gr_log_resource(const struct task_struct *task,
61954 + const int res, const unsigned long wanted, const int gt)
61955 +{
61956 + const struct cred *cred;
61957 + unsigned long rlim;
61958 +
61959 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
61960 + return;
61961 +
61962 + // not yet supported resource
61963 + if (unlikely(!restab_log[res]))
61964 + return;
61965 +
61966 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
61967 + rlim = task_rlimit_max(task, res);
61968 + else
61969 + rlim = task_rlimit(task, res);
61970 +
61971 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
61972 + return;
61973 +
61974 + rcu_read_lock();
61975 + cred = __task_cred(task);
61976 +
61977 + if (res == RLIMIT_NPROC &&
61978 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
61979 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
61980 + goto out_rcu_unlock;
61981 + else if (res == RLIMIT_MEMLOCK &&
61982 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
61983 + goto out_rcu_unlock;
61984 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
61985 + goto out_rcu_unlock;
61986 + rcu_read_unlock();
61987 +
61988 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
61989 +
61990 + return;
61991 +out_rcu_unlock:
61992 + rcu_read_unlock();
61993 + return;
61994 +}
61995 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
61996 new file mode 100644
61997 index 0000000..8c8fc9d
61998 --- /dev/null
61999 +++ b/grsecurity/gracl_segv.c
62000 @@ -0,0 +1,303 @@
62001 +#include <linux/kernel.h>
62002 +#include <linux/mm.h>
62003 +#include <asm/uaccess.h>
62004 +#include <asm/errno.h>
62005 +#include <asm/mman.h>
62006 +#include <net/sock.h>
62007 +#include <linux/file.h>
62008 +#include <linux/fs.h>
62009 +#include <linux/net.h>
62010 +#include <linux/in.h>
62011 +#include <linux/slab.h>
62012 +#include <linux/types.h>
62013 +#include <linux/sched.h>
62014 +#include <linux/timer.h>
62015 +#include <linux/gracl.h>
62016 +#include <linux/grsecurity.h>
62017 +#include <linux/grinternal.h>
62018 +
62019 +static struct crash_uid *uid_set;
62020 +static unsigned short uid_used;
62021 +static DEFINE_SPINLOCK(gr_uid_lock);
62022 +extern rwlock_t gr_inode_lock;
62023 +extern struct acl_subject_label *
62024 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
62025 + struct acl_role_label *role);
62026 +
62027 +#ifdef CONFIG_BTRFS_FS
62028 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
62029 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
62030 +#endif
62031 +
62032 +static inline dev_t __get_dev(const struct dentry *dentry)
62033 +{
62034 +#ifdef CONFIG_BTRFS_FS
62035 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
62036 + return get_btrfs_dev_from_inode(dentry->d_inode);
62037 + else
62038 +#endif
62039 + return dentry->d_inode->i_sb->s_dev;
62040 +}
62041 +
62042 +int
62043 +gr_init_uidset(void)
62044 +{
62045 + uid_set =
62046 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
62047 + uid_used = 0;
62048 +
62049 + return uid_set ? 1 : 0;
62050 +}
62051 +
62052 +void
62053 +gr_free_uidset(void)
62054 +{
62055 + if (uid_set)
62056 + kfree(uid_set);
62057 +
62058 + return;
62059 +}
62060 +
62061 +int
62062 +gr_find_uid(const uid_t uid)
62063 +{
62064 + struct crash_uid *tmp = uid_set;
62065 + uid_t buid;
62066 + int low = 0, high = uid_used - 1, mid;
62067 +
62068 + while (high >= low) {
62069 + mid = (low + high) >> 1;
62070 + buid = tmp[mid].uid;
62071 + if (buid == uid)
62072 + return mid;
62073 + if (buid > uid)
62074 + high = mid - 1;
62075 + if (buid < uid)
62076 + low = mid + 1;
62077 + }
62078 +
62079 + return -1;
62080 +}
62081 +
62082 +static __inline__ void
62083 +gr_insertsort(void)
62084 +{
62085 + unsigned short i, j;
62086 + struct crash_uid index;
62087 +
62088 + for (i = 1; i < uid_used; i++) {
62089 + index = uid_set[i];
62090 + j = i;
62091 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
62092 + uid_set[j] = uid_set[j - 1];
62093 + j--;
62094 + }
62095 + uid_set[j] = index;
62096 + }
62097 +
62098 + return;
62099 +}
62100 +
62101 +static __inline__ void
62102 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
62103 +{
62104 + int loc;
62105 + uid_t uid = GR_GLOBAL_UID(kuid);
62106 +
62107 + if (uid_used == GR_UIDTABLE_MAX)
62108 + return;
62109 +
62110 + loc = gr_find_uid(uid);
62111 +
62112 + if (loc >= 0) {
62113 + uid_set[loc].expires = expires;
62114 + return;
62115 + }
62116 +
62117 + uid_set[uid_used].uid = uid;
62118 + uid_set[uid_used].expires = expires;
62119 + uid_used++;
62120 +
62121 + gr_insertsort();
62122 +
62123 + return;
62124 +}
62125 +
62126 +void
62127 +gr_remove_uid(const unsigned short loc)
62128 +{
62129 + unsigned short i;
62130 +
62131 + for (i = loc + 1; i < uid_used; i++)
62132 + uid_set[i - 1] = uid_set[i];
62133 +
62134 + uid_used--;
62135 +
62136 + return;
62137 +}
62138 +
62139 +int
62140 +gr_check_crash_uid(const kuid_t kuid)
62141 +{
62142 + int loc;
62143 + int ret = 0;
62144 + uid_t uid;
62145 +
62146 + if (unlikely(!gr_acl_is_enabled()))
62147 + return 0;
62148 +
62149 + uid = GR_GLOBAL_UID(kuid);
62150 +
62151 + spin_lock(&gr_uid_lock);
62152 + loc = gr_find_uid(uid);
62153 +
62154 + if (loc < 0)
62155 + goto out_unlock;
62156 +
62157 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
62158 + gr_remove_uid(loc);
62159 + else
62160 + ret = 1;
62161 +
62162 +out_unlock:
62163 + spin_unlock(&gr_uid_lock);
62164 + return ret;
62165 +}
62166 +
62167 +static __inline__ int
62168 +proc_is_setxid(const struct cred *cred)
62169 +{
62170 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
62171 + !uid_eq(cred->uid, cred->fsuid))
62172 + return 1;
62173 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
62174 + !gid_eq(cred->gid, cred->fsgid))
62175 + return 1;
62176 +
62177 + return 0;
62178 +}
62179 +
62180 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
62181 +
62182 +void
62183 +gr_handle_crash(struct task_struct *task, const int sig)
62184 +{
62185 + struct acl_subject_label *curr;
62186 + struct task_struct *tsk, *tsk2;
62187 + const struct cred *cred;
62188 + const struct cred *cred2;
62189 +
62190 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
62191 + return;
62192 +
62193 + if (unlikely(!gr_acl_is_enabled()))
62194 + return;
62195 +
62196 + curr = task->acl;
62197 +
62198 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
62199 + return;
62200 +
62201 + if (time_before_eq(curr->expires, get_seconds())) {
62202 + curr->expires = 0;
62203 + curr->crashes = 0;
62204 + }
62205 +
62206 + curr->crashes++;
62207 +
62208 + if (!curr->expires)
62209 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
62210 +
62211 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62212 + time_after(curr->expires, get_seconds())) {
62213 + rcu_read_lock();
62214 + cred = __task_cred(task);
62215 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
62216 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62217 + spin_lock(&gr_uid_lock);
62218 + gr_insert_uid(cred->uid, curr->expires);
62219 + spin_unlock(&gr_uid_lock);
62220 + curr->expires = 0;
62221 + curr->crashes = 0;
62222 + read_lock(&tasklist_lock);
62223 + do_each_thread(tsk2, tsk) {
62224 + cred2 = __task_cred(tsk);
62225 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
62226 + gr_fake_force_sig(SIGKILL, tsk);
62227 + } while_each_thread(tsk2, tsk);
62228 + read_unlock(&tasklist_lock);
62229 + } else {
62230 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62231 + read_lock(&tasklist_lock);
62232 + read_lock(&grsec_exec_file_lock);
62233 + do_each_thread(tsk2, tsk) {
62234 + if (likely(tsk != task)) {
62235 + // if this thread has the same subject as the one that triggered
62236 + // RES_CRASH and it's the same binary, kill it
62237 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
62238 + gr_fake_force_sig(SIGKILL, tsk);
62239 + }
62240 + } while_each_thread(tsk2, tsk);
62241 + read_unlock(&grsec_exec_file_lock);
62242 + read_unlock(&tasklist_lock);
62243 + }
62244 + rcu_read_unlock();
62245 + }
62246 +
62247 + return;
62248 +}
62249 +
62250 +int
62251 +gr_check_crash_exec(const struct file *filp)
62252 +{
62253 + struct acl_subject_label *curr;
62254 +
62255 + if (unlikely(!gr_acl_is_enabled()))
62256 + return 0;
62257 +
62258 + read_lock(&gr_inode_lock);
62259 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
62260 + __get_dev(filp->f_path.dentry),
62261 + current->role);
62262 + read_unlock(&gr_inode_lock);
62263 +
62264 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
62265 + (!curr->crashes && !curr->expires))
62266 + return 0;
62267 +
62268 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62269 + time_after(curr->expires, get_seconds()))
62270 + return 1;
62271 + else if (time_before_eq(curr->expires, get_seconds())) {
62272 + curr->crashes = 0;
62273 + curr->expires = 0;
62274 + }
62275 +
62276 + return 0;
62277 +}
62278 +
62279 +void
62280 +gr_handle_alertkill(struct task_struct *task)
62281 +{
62282 + struct acl_subject_label *curracl;
62283 + __u32 curr_ip;
62284 + struct task_struct *p, *p2;
62285 +
62286 + if (unlikely(!gr_acl_is_enabled()))
62287 + return;
62288 +
62289 + curracl = task->acl;
62290 + curr_ip = task->signal->curr_ip;
62291 +
62292 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
62293 + read_lock(&tasklist_lock);
62294 + do_each_thread(p2, p) {
62295 + if (p->signal->curr_ip == curr_ip)
62296 + gr_fake_force_sig(SIGKILL, p);
62297 + } while_each_thread(p2, p);
62298 + read_unlock(&tasklist_lock);
62299 + } else if (curracl->mode & GR_KILLPROC)
62300 + gr_fake_force_sig(SIGKILL, task);
62301 +
62302 + return;
62303 +}
62304 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
62305 new file mode 100644
62306 index 0000000..98011b0
62307 --- /dev/null
62308 +++ b/grsecurity/gracl_shm.c
62309 @@ -0,0 +1,40 @@
62310 +#include <linux/kernel.h>
62311 +#include <linux/mm.h>
62312 +#include <linux/sched.h>
62313 +#include <linux/file.h>
62314 +#include <linux/ipc.h>
62315 +#include <linux/gracl.h>
62316 +#include <linux/grsecurity.h>
62317 +#include <linux/grinternal.h>
62318 +
62319 +int
62320 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62321 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
62322 +{
62323 + struct task_struct *task;
62324 +
62325 + if (!gr_acl_is_enabled())
62326 + return 1;
62327 +
62328 + rcu_read_lock();
62329 + read_lock(&tasklist_lock);
62330 +
62331 + task = find_task_by_vpid(shm_cprid);
62332 +
62333 + if (unlikely(!task))
62334 + task = find_task_by_vpid(shm_lapid);
62335 +
62336 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
62337 + (task_pid_nr(task) == shm_lapid)) &&
62338 + (task->acl->mode & GR_PROTSHM) &&
62339 + (task->acl != current->acl))) {
62340 + read_unlock(&tasklist_lock);
62341 + rcu_read_unlock();
62342 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
62343 + return 0;
62344 + }
62345 + read_unlock(&tasklist_lock);
62346 + rcu_read_unlock();
62347 +
62348 + return 1;
62349 +}
62350 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
62351 new file mode 100644
62352 index 0000000..bc0be01
62353 --- /dev/null
62354 +++ b/grsecurity/grsec_chdir.c
62355 @@ -0,0 +1,19 @@
62356 +#include <linux/kernel.h>
62357 +#include <linux/sched.h>
62358 +#include <linux/fs.h>
62359 +#include <linux/file.h>
62360 +#include <linux/grsecurity.h>
62361 +#include <linux/grinternal.h>
62362 +
62363 +void
62364 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
62365 +{
62366 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62367 + if ((grsec_enable_chdir && grsec_enable_group &&
62368 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
62369 + !grsec_enable_group)) {
62370 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
62371 + }
62372 +#endif
62373 + return;
62374 +}
62375 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
62376 new file mode 100644
62377 index 0000000..6d2de57
62378 --- /dev/null
62379 +++ b/grsecurity/grsec_chroot.c
62380 @@ -0,0 +1,357 @@
62381 +#include <linux/kernel.h>
62382 +#include <linux/module.h>
62383 +#include <linux/sched.h>
62384 +#include <linux/file.h>
62385 +#include <linux/fs.h>
62386 +#include <linux/mount.h>
62387 +#include <linux/types.h>
62388 +#include "../fs/mount.h"
62389 +#include <linux/grsecurity.h>
62390 +#include <linux/grinternal.h>
62391 +
62392 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
62393 +{
62394 +#ifdef CONFIG_GRKERNSEC
62395 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
62396 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
62397 + task->gr_is_chrooted = 1;
62398 + else
62399 + task->gr_is_chrooted = 0;
62400 +
62401 + task->gr_chroot_dentry = path->dentry;
62402 +#endif
62403 + return;
62404 +}
62405 +
62406 +void gr_clear_chroot_entries(struct task_struct *task)
62407 +{
62408 +#ifdef CONFIG_GRKERNSEC
62409 + task->gr_is_chrooted = 0;
62410 + task->gr_chroot_dentry = NULL;
62411 +#endif
62412 + return;
62413 +}
62414 +
62415 +int
62416 +gr_handle_chroot_unix(const pid_t pid)
62417 +{
62418 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62419 + struct task_struct *p;
62420 +
62421 + if (unlikely(!grsec_enable_chroot_unix))
62422 + return 1;
62423 +
62424 + if (likely(!proc_is_chrooted(current)))
62425 + return 1;
62426 +
62427 + rcu_read_lock();
62428 + read_lock(&tasklist_lock);
62429 + p = find_task_by_vpid_unrestricted(pid);
62430 + if (unlikely(p && !have_same_root(current, p))) {
62431 + read_unlock(&tasklist_lock);
62432 + rcu_read_unlock();
62433 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
62434 + return 0;
62435 + }
62436 + read_unlock(&tasklist_lock);
62437 + rcu_read_unlock();
62438 +#endif
62439 + return 1;
62440 +}
62441 +
62442 +int
62443 +gr_handle_chroot_nice(void)
62444 +{
62445 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62446 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
62447 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
62448 + return -EPERM;
62449 + }
62450 +#endif
62451 + return 0;
62452 +}
62453 +
62454 +int
62455 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
62456 +{
62457 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62458 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
62459 + && proc_is_chrooted(current)) {
62460 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
62461 + return -EACCES;
62462 + }
62463 +#endif
62464 + return 0;
62465 +}
62466 +
62467 +int
62468 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
62469 +{
62470 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62471 + struct task_struct *p;
62472 + int ret = 0;
62473 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
62474 + return ret;
62475 +
62476 + read_lock(&tasklist_lock);
62477 + do_each_pid_task(pid, type, p) {
62478 + if (!have_same_root(current, p)) {
62479 + ret = 1;
62480 + goto out;
62481 + }
62482 + } while_each_pid_task(pid, type, p);
62483 +out:
62484 + read_unlock(&tasklist_lock);
62485 + return ret;
62486 +#endif
62487 + return 0;
62488 +}
62489 +
62490 +int
62491 +gr_pid_is_chrooted(struct task_struct *p)
62492 +{
62493 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62494 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
62495 + return 0;
62496 +
62497 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
62498 + !have_same_root(current, p)) {
62499 + return 1;
62500 + }
62501 +#endif
62502 + return 0;
62503 +}
62504 +
62505 +EXPORT_SYMBOL(gr_pid_is_chrooted);
62506 +
62507 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
62508 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
62509 +{
62510 + struct path path, currentroot;
62511 + int ret = 0;
62512 +
62513 + path.dentry = (struct dentry *)u_dentry;
62514 + path.mnt = (struct vfsmount *)u_mnt;
62515 + get_fs_root(current->fs, &currentroot);
62516 + if (path_is_under(&path, &currentroot))
62517 + ret = 1;
62518 + path_put(&currentroot);
62519 +
62520 + return ret;
62521 +}
62522 +#endif
62523 +
62524 +int
62525 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
62526 +{
62527 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62528 + if (!grsec_enable_chroot_fchdir)
62529 + return 1;
62530 +
62531 + if (!proc_is_chrooted(current))
62532 + return 1;
62533 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
62534 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
62535 + return 0;
62536 + }
62537 +#endif
62538 + return 1;
62539 +}
62540 +
62541 +int
62542 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62543 + const time_t shm_createtime)
62544 +{
62545 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62546 + struct task_struct *p;
62547 + time_t starttime;
62548 +
62549 + if (unlikely(!grsec_enable_chroot_shmat))
62550 + return 1;
62551 +
62552 + if (likely(!proc_is_chrooted(current)))
62553 + return 1;
62554 +
62555 + rcu_read_lock();
62556 + read_lock(&tasklist_lock);
62557 +
62558 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
62559 + starttime = p->start_time.tv_sec;
62560 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
62561 + if (have_same_root(current, p)) {
62562 + goto allow;
62563 + } else {
62564 + read_unlock(&tasklist_lock);
62565 + rcu_read_unlock();
62566 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
62567 + return 0;
62568 + }
62569 + }
62570 + /* creator exited, pid reuse, fall through to next check */
62571 + }
62572 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
62573 + if (unlikely(!have_same_root(current, p))) {
62574 + read_unlock(&tasklist_lock);
62575 + rcu_read_unlock();
62576 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
62577 + return 0;
62578 + }
62579 + }
62580 +
62581 +allow:
62582 + read_unlock(&tasklist_lock);
62583 + rcu_read_unlock();
62584 +#endif
62585 + return 1;
62586 +}
62587 +
62588 +void
62589 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
62590 +{
62591 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62592 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
62593 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
62594 +#endif
62595 + return;
62596 +}
62597 +
62598 +int
62599 +gr_handle_chroot_mknod(const struct dentry *dentry,
62600 + const struct vfsmount *mnt, const int mode)
62601 +{
62602 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62603 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
62604 + proc_is_chrooted(current)) {
62605 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
62606 + return -EPERM;
62607 + }
62608 +#endif
62609 + return 0;
62610 +}
62611 +
62612 +int
62613 +gr_handle_chroot_mount(const struct dentry *dentry,
62614 + const struct vfsmount *mnt, const char *dev_name)
62615 +{
62616 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62617 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
62618 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
62619 + return -EPERM;
62620 + }
62621 +#endif
62622 + return 0;
62623 +}
62624 +
62625 +int
62626 +gr_handle_chroot_pivot(void)
62627 +{
62628 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62629 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
62630 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
62631 + return -EPERM;
62632 + }
62633 +#endif
62634 + return 0;
62635 +}
62636 +
62637 +int
62638 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
62639 +{
62640 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62641 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
62642 + !gr_is_outside_chroot(dentry, mnt)) {
62643 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
62644 + return -EPERM;
62645 + }
62646 +#endif
62647 + return 0;
62648 +}
62649 +
62650 +extern const char *captab_log[];
62651 +extern int captab_log_entries;
62652 +
62653 +int
62654 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62655 +{
62656 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62657 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
62658 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
62659 + if (cap_raised(chroot_caps, cap)) {
62660 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
62661 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
62662 + }
62663 + return 0;
62664 + }
62665 + }
62666 +#endif
62667 + return 1;
62668 +}
62669 +
62670 +int
62671 +gr_chroot_is_capable(const int cap)
62672 +{
62673 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62674 + return gr_task_chroot_is_capable(current, current_cred(), cap);
62675 +#endif
62676 + return 1;
62677 +}
62678 +
62679 +int
62680 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
62681 +{
62682 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62683 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
62684 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
62685 + if (cap_raised(chroot_caps, cap)) {
62686 + return 0;
62687 + }
62688 + }
62689 +#endif
62690 + return 1;
62691 +}
62692 +
62693 +int
62694 +gr_chroot_is_capable_nolog(const int cap)
62695 +{
62696 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62697 + return gr_task_chroot_is_capable_nolog(current, cap);
62698 +#endif
62699 + return 1;
62700 +}
62701 +
62702 +int
62703 +gr_handle_chroot_sysctl(const int op)
62704 +{
62705 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62706 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
62707 + proc_is_chrooted(current))
62708 + return -EACCES;
62709 +#endif
62710 + return 0;
62711 +}
62712 +
62713 +void
62714 +gr_handle_chroot_chdir(struct path *path)
62715 +{
62716 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62717 + if (grsec_enable_chroot_chdir)
62718 + set_fs_pwd(current->fs, path);
62719 +#endif
62720 + return;
62721 +}
62722 +
62723 +int
62724 +gr_handle_chroot_chmod(const struct dentry *dentry,
62725 + const struct vfsmount *mnt, const int mode)
62726 +{
62727 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62728 + /* allow chmod +s on directories, but not files */
62729 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
62730 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
62731 + proc_is_chrooted(current)) {
62732 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
62733 + return -EPERM;
62734 + }
62735 +#endif
62736 + return 0;
62737 +}
62738 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
62739 new file mode 100644
62740 index 0000000..207d409
62741 --- /dev/null
62742 +++ b/grsecurity/grsec_disabled.c
62743 @@ -0,0 +1,434 @@
62744 +#include <linux/kernel.h>
62745 +#include <linux/module.h>
62746 +#include <linux/sched.h>
62747 +#include <linux/file.h>
62748 +#include <linux/fs.h>
62749 +#include <linux/kdev_t.h>
62750 +#include <linux/net.h>
62751 +#include <linux/in.h>
62752 +#include <linux/ip.h>
62753 +#include <linux/skbuff.h>
62754 +#include <linux/sysctl.h>
62755 +
62756 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62757 +void
62758 +pax_set_initial_flags(struct linux_binprm *bprm)
62759 +{
62760 + return;
62761 +}
62762 +#endif
62763 +
62764 +#ifdef CONFIG_SYSCTL
62765 +__u32
62766 +gr_handle_sysctl(const struct ctl_table * table, const int op)
62767 +{
62768 + return 0;
62769 +}
62770 +#endif
62771 +
62772 +#ifdef CONFIG_TASKSTATS
62773 +int gr_is_taskstats_denied(int pid)
62774 +{
62775 + return 0;
62776 +}
62777 +#endif
62778 +
62779 +int
62780 +gr_acl_is_enabled(void)
62781 +{
62782 + return 0;
62783 +}
62784 +
62785 +void
62786 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
62787 +{
62788 + return;
62789 +}
62790 +
62791 +int
62792 +gr_handle_rawio(const struct inode *inode)
62793 +{
62794 + return 0;
62795 +}
62796 +
62797 +void
62798 +gr_acl_handle_psacct(struct task_struct *task, const long code)
62799 +{
62800 + return;
62801 +}
62802 +
62803 +int
62804 +gr_handle_ptrace(struct task_struct *task, const long request)
62805 +{
62806 + return 0;
62807 +}
62808 +
62809 +int
62810 +gr_handle_proc_ptrace(struct task_struct *task)
62811 +{
62812 + return 0;
62813 +}
62814 +
62815 +int
62816 +gr_set_acls(const int type)
62817 +{
62818 + return 0;
62819 +}
62820 +
62821 +int
62822 +gr_check_hidden_task(const struct task_struct *tsk)
62823 +{
62824 + return 0;
62825 +}
62826 +
62827 +int
62828 +gr_check_protected_task(const struct task_struct *task)
62829 +{
62830 + return 0;
62831 +}
62832 +
62833 +int
62834 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
62835 +{
62836 + return 0;
62837 +}
62838 +
62839 +void
62840 +gr_copy_label(struct task_struct *tsk)
62841 +{
62842 + return;
62843 +}
62844 +
62845 +void
62846 +gr_set_pax_flags(struct task_struct *task)
62847 +{
62848 + return;
62849 +}
62850 +
62851 +int
62852 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
62853 + const int unsafe_share)
62854 +{
62855 + return 0;
62856 +}
62857 +
62858 +void
62859 +gr_handle_delete(const ino_t ino, const dev_t dev)
62860 +{
62861 + return;
62862 +}
62863 +
62864 +void
62865 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
62866 +{
62867 + return;
62868 +}
62869 +
62870 +void
62871 +gr_handle_crash(struct task_struct *task, const int sig)
62872 +{
62873 + return;
62874 +}
62875 +
62876 +int
62877 +gr_check_crash_exec(const struct file *filp)
62878 +{
62879 + return 0;
62880 +}
62881 +
62882 +int
62883 +gr_check_crash_uid(const kuid_t uid)
62884 +{
62885 + return 0;
62886 +}
62887 +
62888 +void
62889 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62890 + struct dentry *old_dentry,
62891 + struct dentry *new_dentry,
62892 + struct vfsmount *mnt, const __u8 replace)
62893 +{
62894 + return;
62895 +}
62896 +
62897 +int
62898 +gr_search_socket(const int family, const int type, const int protocol)
62899 +{
62900 + return 1;
62901 +}
62902 +
62903 +int
62904 +gr_search_connectbind(const int mode, const struct socket *sock,
62905 + const struct sockaddr_in *addr)
62906 +{
62907 + return 0;
62908 +}
62909 +
62910 +void
62911 +gr_handle_alertkill(struct task_struct *task)
62912 +{
62913 + return;
62914 +}
62915 +
62916 +__u32
62917 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
62918 +{
62919 + return 1;
62920 +}
62921 +
62922 +__u32
62923 +gr_acl_handle_hidden_file(const struct dentry * dentry,
62924 + const struct vfsmount * mnt)
62925 +{
62926 + return 1;
62927 +}
62928 +
62929 +__u32
62930 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
62931 + int acc_mode)
62932 +{
62933 + return 1;
62934 +}
62935 +
62936 +__u32
62937 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62938 +{
62939 + return 1;
62940 +}
62941 +
62942 +__u32
62943 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
62944 +{
62945 + return 1;
62946 +}
62947 +
62948 +int
62949 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
62950 + unsigned int *vm_flags)
62951 +{
62952 + return 1;
62953 +}
62954 +
62955 +__u32
62956 +gr_acl_handle_truncate(const struct dentry * dentry,
62957 + const struct vfsmount * mnt)
62958 +{
62959 + return 1;
62960 +}
62961 +
62962 +__u32
62963 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
62964 +{
62965 + return 1;
62966 +}
62967 +
62968 +__u32
62969 +gr_acl_handle_access(const struct dentry * dentry,
62970 + const struct vfsmount * mnt, const int fmode)
62971 +{
62972 + return 1;
62973 +}
62974 +
62975 +__u32
62976 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
62977 + umode_t *mode)
62978 +{
62979 + return 1;
62980 +}
62981 +
62982 +__u32
62983 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
62984 +{
62985 + return 1;
62986 +}
62987 +
62988 +__u32
62989 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
62990 +{
62991 + return 1;
62992 +}
62993 +
62994 +void
62995 +grsecurity_init(void)
62996 +{
62997 + return;
62998 +}
62999 +
63000 +umode_t gr_acl_umask(void)
63001 +{
63002 + return 0;
63003 +}
63004 +
63005 +__u32
63006 +gr_acl_handle_mknod(const struct dentry * new_dentry,
63007 + const struct dentry * parent_dentry,
63008 + const struct vfsmount * parent_mnt,
63009 + const int mode)
63010 +{
63011 + return 1;
63012 +}
63013 +
63014 +__u32
63015 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
63016 + const struct dentry * parent_dentry,
63017 + const struct vfsmount * parent_mnt)
63018 +{
63019 + return 1;
63020 +}
63021 +
63022 +__u32
63023 +gr_acl_handle_symlink(const struct dentry * new_dentry,
63024 + const struct dentry * parent_dentry,
63025 + const struct vfsmount * parent_mnt, const struct filename *from)
63026 +{
63027 + return 1;
63028 +}
63029 +
63030 +__u32
63031 +gr_acl_handle_link(const struct dentry * new_dentry,
63032 + const struct dentry * parent_dentry,
63033 + const struct vfsmount * parent_mnt,
63034 + const struct dentry * old_dentry,
63035 + const struct vfsmount * old_mnt, const struct filename *to)
63036 +{
63037 + return 1;
63038 +}
63039 +
63040 +int
63041 +gr_acl_handle_rename(const struct dentry *new_dentry,
63042 + const struct dentry *parent_dentry,
63043 + const struct vfsmount *parent_mnt,
63044 + const struct dentry *old_dentry,
63045 + const struct inode *old_parent_inode,
63046 + const struct vfsmount *old_mnt, const struct filename *newname)
63047 +{
63048 + return 0;
63049 +}
63050 +
63051 +int
63052 +gr_acl_handle_filldir(const struct file *file, const char *name,
63053 + const int namelen, const ino_t ino)
63054 +{
63055 + return 1;
63056 +}
63057 +
63058 +int
63059 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63060 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
63061 +{
63062 + return 1;
63063 +}
63064 +
63065 +int
63066 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
63067 +{
63068 + return 0;
63069 +}
63070 +
63071 +int
63072 +gr_search_accept(const struct socket *sock)
63073 +{
63074 + return 0;
63075 +}
63076 +
63077 +int
63078 +gr_search_listen(const struct socket *sock)
63079 +{
63080 + return 0;
63081 +}
63082 +
63083 +int
63084 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
63085 +{
63086 + return 0;
63087 +}
63088 +
63089 +__u32
63090 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
63091 +{
63092 + return 1;
63093 +}
63094 +
63095 +__u32
63096 +gr_acl_handle_creat(const struct dentry * dentry,
63097 + const struct dentry * p_dentry,
63098 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
63099 + const int imode)
63100 +{
63101 + return 1;
63102 +}
63103 +
63104 +void
63105 +gr_acl_handle_exit(void)
63106 +{
63107 + return;
63108 +}
63109 +
63110 +int
63111 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
63112 +{
63113 + return 1;
63114 +}
63115 +
63116 +void
63117 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
63118 +{
63119 + return;
63120 +}
63121 +
63122 +int
63123 +gr_acl_handle_procpidmem(const struct task_struct *task)
63124 +{
63125 + return 0;
63126 +}
63127 +
63128 +int
63129 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
63130 +{
63131 + return 0;
63132 +}
63133 +
63134 +int
63135 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
63136 +{
63137 + return 0;
63138 +}
63139 +
63140 +void
63141 +gr_set_kernel_label(struct task_struct *task)
63142 +{
63143 + return;
63144 +}
63145 +
63146 +int
63147 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
63148 +{
63149 + return 0;
63150 +}
63151 +
63152 +int
63153 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
63154 +{
63155 + return 0;
63156 +}
63157 +
63158 +int gr_acl_enable_at_secure(void)
63159 +{
63160 + return 0;
63161 +}
63162 +
63163 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63164 +{
63165 + return dentry->d_inode->i_sb->s_dev;
63166 +}
63167 +
63168 +void gr_put_exec_file(struct task_struct *task)
63169 +{
63170 + return;
63171 +}
63172 +
63173 +EXPORT_SYMBOL(gr_set_kernel_label);
63174 +#ifdef CONFIG_SECURITY
63175 +EXPORT_SYMBOL(gr_check_user_change);
63176 +EXPORT_SYMBOL(gr_check_group_change);
63177 +#endif
63178 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
63179 new file mode 100644
63180 index 0000000..abfa971
63181 --- /dev/null
63182 +++ b/grsecurity/grsec_exec.c
63183 @@ -0,0 +1,174 @@
63184 +#include <linux/kernel.h>
63185 +#include <linux/sched.h>
63186 +#include <linux/file.h>
63187 +#include <linux/binfmts.h>
63188 +#include <linux/fs.h>
63189 +#include <linux/types.h>
63190 +#include <linux/grdefs.h>
63191 +#include <linux/grsecurity.h>
63192 +#include <linux/grinternal.h>
63193 +#include <linux/capability.h>
63194 +#include <linux/module.h>
63195 +
63196 +#include <asm/uaccess.h>
63197 +
63198 +#ifdef CONFIG_GRKERNSEC_EXECLOG
63199 +static char gr_exec_arg_buf[132];
63200 +static DEFINE_MUTEX(gr_exec_arg_mutex);
63201 +#endif
63202 +
63203 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
63204 +
63205 +void
63206 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
63207 +{
63208 +#ifdef CONFIG_GRKERNSEC_EXECLOG
63209 + char *grarg = gr_exec_arg_buf;
63210 + unsigned int i, x, execlen = 0;
63211 + char c;
63212 +
63213 + if (!((grsec_enable_execlog && grsec_enable_group &&
63214 + in_group_p(grsec_audit_gid))
63215 + || (grsec_enable_execlog && !grsec_enable_group)))
63216 + return;
63217 +
63218 + mutex_lock(&gr_exec_arg_mutex);
63219 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
63220 +
63221 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
63222 + const char __user *p;
63223 + unsigned int len;
63224 +
63225 + p = get_user_arg_ptr(argv, i);
63226 + if (IS_ERR(p))
63227 + goto log;
63228 +
63229 + len = strnlen_user(p, 128 - execlen);
63230 + if (len > 128 - execlen)
63231 + len = 128 - execlen;
63232 + else if (len > 0)
63233 + len--;
63234 + if (copy_from_user(grarg + execlen, p, len))
63235 + goto log;
63236 +
63237 + /* rewrite unprintable characters */
63238 + for (x = 0; x < len; x++) {
63239 + c = *(grarg + execlen + x);
63240 + if (c < 32 || c > 126)
63241 + *(grarg + execlen + x) = ' ';
63242 + }
63243 +
63244 + execlen += len;
63245 + *(grarg + execlen) = ' ';
63246 + *(grarg + execlen + 1) = '\0';
63247 + execlen++;
63248 + }
63249 +
63250 + log:
63251 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
63252 + bprm->file->f_path.mnt, grarg);
63253 + mutex_unlock(&gr_exec_arg_mutex);
63254 +#endif
63255 + return;
63256 +}
63257 +
63258 +#ifdef CONFIG_GRKERNSEC
63259 +extern int gr_acl_is_capable(const int cap);
63260 +extern int gr_acl_is_capable_nolog(const int cap);
63261 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63262 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
63263 +extern int gr_chroot_is_capable(const int cap);
63264 +extern int gr_chroot_is_capable_nolog(const int cap);
63265 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63266 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
63267 +#endif
63268 +
63269 +const char *captab_log[] = {
63270 + "CAP_CHOWN",
63271 + "CAP_DAC_OVERRIDE",
63272 + "CAP_DAC_READ_SEARCH",
63273 + "CAP_FOWNER",
63274 + "CAP_FSETID",
63275 + "CAP_KILL",
63276 + "CAP_SETGID",
63277 + "CAP_SETUID",
63278 + "CAP_SETPCAP",
63279 + "CAP_LINUX_IMMUTABLE",
63280 + "CAP_NET_BIND_SERVICE",
63281 + "CAP_NET_BROADCAST",
63282 + "CAP_NET_ADMIN",
63283 + "CAP_NET_RAW",
63284 + "CAP_IPC_LOCK",
63285 + "CAP_IPC_OWNER",
63286 + "CAP_SYS_MODULE",
63287 + "CAP_SYS_RAWIO",
63288 + "CAP_SYS_CHROOT",
63289 + "CAP_SYS_PTRACE",
63290 + "CAP_SYS_PACCT",
63291 + "CAP_SYS_ADMIN",
63292 + "CAP_SYS_BOOT",
63293 + "CAP_SYS_NICE",
63294 + "CAP_SYS_RESOURCE",
63295 + "CAP_SYS_TIME",
63296 + "CAP_SYS_TTY_CONFIG",
63297 + "CAP_MKNOD",
63298 + "CAP_LEASE",
63299 + "CAP_AUDIT_WRITE",
63300 + "CAP_AUDIT_CONTROL",
63301 + "CAP_SETFCAP",
63302 + "CAP_MAC_OVERRIDE",
63303 + "CAP_MAC_ADMIN",
63304 + "CAP_SYSLOG",
63305 + "CAP_WAKE_ALARM"
63306 +};
63307 +
63308 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
63309 +
63310 +int gr_is_capable(const int cap)
63311 +{
63312 +#ifdef CONFIG_GRKERNSEC
63313 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
63314 + return 1;
63315 + return 0;
63316 +#else
63317 + return 1;
63318 +#endif
63319 +}
63320 +
63321 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63322 +{
63323 +#ifdef CONFIG_GRKERNSEC
63324 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
63325 + return 1;
63326 + return 0;
63327 +#else
63328 + return 1;
63329 +#endif
63330 +}
63331 +
63332 +int gr_is_capable_nolog(const int cap)
63333 +{
63334 +#ifdef CONFIG_GRKERNSEC
63335 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
63336 + return 1;
63337 + return 0;
63338 +#else
63339 + return 1;
63340 +#endif
63341 +}
63342 +
63343 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
63344 +{
63345 +#ifdef CONFIG_GRKERNSEC
63346 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
63347 + return 1;
63348 + return 0;
63349 +#else
63350 + return 1;
63351 +#endif
63352 +}
63353 +
63354 +EXPORT_SYMBOL(gr_is_capable);
63355 +EXPORT_SYMBOL(gr_is_capable_nolog);
63356 +EXPORT_SYMBOL(gr_task_is_capable);
63357 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
63358 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
63359 new file mode 100644
63360 index 0000000..06cc6ea
63361 --- /dev/null
63362 +++ b/grsecurity/grsec_fifo.c
63363 @@ -0,0 +1,24 @@
63364 +#include <linux/kernel.h>
63365 +#include <linux/sched.h>
63366 +#include <linux/fs.h>
63367 +#include <linux/file.h>
63368 +#include <linux/grinternal.h>
63369 +
63370 +int
63371 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
63372 + const struct dentry *dir, const int flag, const int acc_mode)
63373 +{
63374 +#ifdef CONFIG_GRKERNSEC_FIFO
63375 + const struct cred *cred = current_cred();
63376 +
63377 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
63378 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
63379 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
63380 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
63381 + if (!inode_permission(dentry->d_inode, acc_mode))
63382 + 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));
63383 + return -EACCES;
63384 + }
63385 +#endif
63386 + return 0;
63387 +}
63388 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
63389 new file mode 100644
63390 index 0000000..8ca18bf
63391 --- /dev/null
63392 +++ b/grsecurity/grsec_fork.c
63393 @@ -0,0 +1,23 @@
63394 +#include <linux/kernel.h>
63395 +#include <linux/sched.h>
63396 +#include <linux/grsecurity.h>
63397 +#include <linux/grinternal.h>
63398 +#include <linux/errno.h>
63399 +
63400 +void
63401 +gr_log_forkfail(const int retval)
63402 +{
63403 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
63404 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
63405 + switch (retval) {
63406 + case -EAGAIN:
63407 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
63408 + break;
63409 + case -ENOMEM:
63410 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
63411 + break;
63412 + }
63413 + }
63414 +#endif
63415 + return;
63416 +}
63417 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
63418 new file mode 100644
63419 index 0000000..a862e9f
63420 --- /dev/null
63421 +++ b/grsecurity/grsec_init.c
63422 @@ -0,0 +1,283 @@
63423 +#include <linux/kernel.h>
63424 +#include <linux/sched.h>
63425 +#include <linux/mm.h>
63426 +#include <linux/gracl.h>
63427 +#include <linux/slab.h>
63428 +#include <linux/vmalloc.h>
63429 +#include <linux/percpu.h>
63430 +#include <linux/module.h>
63431 +
63432 +int grsec_enable_ptrace_readexec;
63433 +int grsec_enable_setxid;
63434 +int grsec_enable_symlinkown;
63435 +kgid_t grsec_symlinkown_gid;
63436 +int grsec_enable_brute;
63437 +int grsec_enable_link;
63438 +int grsec_enable_dmesg;
63439 +int grsec_enable_harden_ptrace;
63440 +int grsec_enable_fifo;
63441 +int grsec_enable_execlog;
63442 +int grsec_enable_signal;
63443 +int grsec_enable_forkfail;
63444 +int grsec_enable_audit_ptrace;
63445 +int grsec_enable_time;
63446 +int grsec_enable_audit_textrel;
63447 +int grsec_enable_group;
63448 +kgid_t grsec_audit_gid;
63449 +int grsec_enable_chdir;
63450 +int grsec_enable_mount;
63451 +int grsec_enable_rofs;
63452 +int grsec_enable_chroot_findtask;
63453 +int grsec_enable_chroot_mount;
63454 +int grsec_enable_chroot_shmat;
63455 +int grsec_enable_chroot_fchdir;
63456 +int grsec_enable_chroot_double;
63457 +int grsec_enable_chroot_pivot;
63458 +int grsec_enable_chroot_chdir;
63459 +int grsec_enable_chroot_chmod;
63460 +int grsec_enable_chroot_mknod;
63461 +int grsec_enable_chroot_nice;
63462 +int grsec_enable_chroot_execlog;
63463 +int grsec_enable_chroot_caps;
63464 +int grsec_enable_chroot_sysctl;
63465 +int grsec_enable_chroot_unix;
63466 +int grsec_enable_tpe;
63467 +kgid_t grsec_tpe_gid;
63468 +int grsec_enable_blackhole;
63469 +#ifdef CONFIG_IPV6_MODULE
63470 +EXPORT_SYMBOL(grsec_enable_blackhole);
63471 +#endif
63472 +int grsec_lastack_retries;
63473 +int grsec_enable_tpe_all;
63474 +int grsec_enable_tpe_invert;
63475 +int grsec_enable_socket_all;
63476 +kgid_t grsec_socket_all_gid;
63477 +int grsec_enable_socket_client;
63478 +kgid_t grsec_socket_client_gid;
63479 +int grsec_enable_socket_server;
63480 +kgid_t grsec_socket_server_gid;
63481 +int grsec_resource_logging;
63482 +int grsec_disable_privio;
63483 +int grsec_enable_log_rwxmaps;
63484 +int grsec_lock;
63485 +
63486 +DEFINE_SPINLOCK(grsec_alert_lock);
63487 +unsigned long grsec_alert_wtime = 0;
63488 +unsigned long grsec_alert_fyet = 0;
63489 +
63490 +DEFINE_SPINLOCK(grsec_audit_lock);
63491 +
63492 +DEFINE_RWLOCK(grsec_exec_file_lock);
63493 +
63494 +char *gr_shared_page[4];
63495 +
63496 +char *gr_alert_log_fmt;
63497 +char *gr_audit_log_fmt;
63498 +char *gr_alert_log_buf;
63499 +char *gr_audit_log_buf;
63500 +
63501 +extern struct gr_arg *gr_usermode;
63502 +extern unsigned char *gr_system_salt;
63503 +extern unsigned char *gr_system_sum;
63504 +
63505 +void __init
63506 +grsecurity_init(void)
63507 +{
63508 + int j;
63509 + /* create the per-cpu shared pages */
63510 +
63511 +#ifdef CONFIG_X86
63512 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
63513 +#endif
63514 +
63515 + for (j = 0; j < 4; j++) {
63516 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
63517 + if (gr_shared_page[j] == NULL) {
63518 + panic("Unable to allocate grsecurity shared page");
63519 + return;
63520 + }
63521 + }
63522 +
63523 + /* allocate log buffers */
63524 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
63525 + if (!gr_alert_log_fmt) {
63526 + panic("Unable to allocate grsecurity alert log format buffer");
63527 + return;
63528 + }
63529 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
63530 + if (!gr_audit_log_fmt) {
63531 + panic("Unable to allocate grsecurity audit log format buffer");
63532 + return;
63533 + }
63534 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
63535 + if (!gr_alert_log_buf) {
63536 + panic("Unable to allocate grsecurity alert log buffer");
63537 + return;
63538 + }
63539 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
63540 + if (!gr_audit_log_buf) {
63541 + panic("Unable to allocate grsecurity audit log buffer");
63542 + return;
63543 + }
63544 +
63545 + /* allocate memory for authentication structure */
63546 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
63547 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
63548 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
63549 +
63550 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
63551 + panic("Unable to allocate grsecurity authentication structure");
63552 + return;
63553 + }
63554 +
63555 +
63556 +#ifdef CONFIG_GRKERNSEC_IO
63557 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
63558 + grsec_disable_privio = 1;
63559 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
63560 + grsec_disable_privio = 1;
63561 +#else
63562 + grsec_disable_privio = 0;
63563 +#endif
63564 +#endif
63565 +
63566 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63567 + /* for backward compatibility, tpe_invert always defaults to on if
63568 + enabled in the kernel
63569 + */
63570 + grsec_enable_tpe_invert = 1;
63571 +#endif
63572 +
63573 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
63574 +#ifndef CONFIG_GRKERNSEC_SYSCTL
63575 + grsec_lock = 1;
63576 +#endif
63577 +
63578 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
63579 + grsec_enable_audit_textrel = 1;
63580 +#endif
63581 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63582 + grsec_enable_log_rwxmaps = 1;
63583 +#endif
63584 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
63585 + grsec_enable_group = 1;
63586 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
63587 +#endif
63588 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
63589 + grsec_enable_ptrace_readexec = 1;
63590 +#endif
63591 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63592 + grsec_enable_chdir = 1;
63593 +#endif
63594 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
63595 + grsec_enable_harden_ptrace = 1;
63596 +#endif
63597 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63598 + grsec_enable_mount = 1;
63599 +#endif
63600 +#ifdef CONFIG_GRKERNSEC_LINK
63601 + grsec_enable_link = 1;
63602 +#endif
63603 +#ifdef CONFIG_GRKERNSEC_BRUTE
63604 + grsec_enable_brute = 1;
63605 +#endif
63606 +#ifdef CONFIG_GRKERNSEC_DMESG
63607 + grsec_enable_dmesg = 1;
63608 +#endif
63609 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
63610 + grsec_enable_blackhole = 1;
63611 + grsec_lastack_retries = 4;
63612 +#endif
63613 +#ifdef CONFIG_GRKERNSEC_FIFO
63614 + grsec_enable_fifo = 1;
63615 +#endif
63616 +#ifdef CONFIG_GRKERNSEC_EXECLOG
63617 + grsec_enable_execlog = 1;
63618 +#endif
63619 +#ifdef CONFIG_GRKERNSEC_SETXID
63620 + grsec_enable_setxid = 1;
63621 +#endif
63622 +#ifdef CONFIG_GRKERNSEC_SIGNAL
63623 + grsec_enable_signal = 1;
63624 +#endif
63625 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
63626 + grsec_enable_forkfail = 1;
63627 +#endif
63628 +#ifdef CONFIG_GRKERNSEC_TIME
63629 + grsec_enable_time = 1;
63630 +#endif
63631 +#ifdef CONFIG_GRKERNSEC_RESLOG
63632 + grsec_resource_logging = 1;
63633 +#endif
63634 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63635 + grsec_enable_chroot_findtask = 1;
63636 +#endif
63637 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63638 + grsec_enable_chroot_unix = 1;
63639 +#endif
63640 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63641 + grsec_enable_chroot_mount = 1;
63642 +#endif
63643 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63644 + grsec_enable_chroot_fchdir = 1;
63645 +#endif
63646 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63647 + grsec_enable_chroot_shmat = 1;
63648 +#endif
63649 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63650 + grsec_enable_audit_ptrace = 1;
63651 +#endif
63652 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63653 + grsec_enable_chroot_double = 1;
63654 +#endif
63655 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63656 + grsec_enable_chroot_pivot = 1;
63657 +#endif
63658 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63659 + grsec_enable_chroot_chdir = 1;
63660 +#endif
63661 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63662 + grsec_enable_chroot_chmod = 1;
63663 +#endif
63664 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63665 + grsec_enable_chroot_mknod = 1;
63666 +#endif
63667 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63668 + grsec_enable_chroot_nice = 1;
63669 +#endif
63670 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63671 + grsec_enable_chroot_execlog = 1;
63672 +#endif
63673 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63674 + grsec_enable_chroot_caps = 1;
63675 +#endif
63676 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63677 + grsec_enable_chroot_sysctl = 1;
63678 +#endif
63679 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
63680 + grsec_enable_symlinkown = 1;
63681 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
63682 +#endif
63683 +#ifdef CONFIG_GRKERNSEC_TPE
63684 + grsec_enable_tpe = 1;
63685 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
63686 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
63687 + grsec_enable_tpe_all = 1;
63688 +#endif
63689 +#endif
63690 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
63691 + grsec_enable_socket_all = 1;
63692 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
63693 +#endif
63694 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
63695 + grsec_enable_socket_client = 1;
63696 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
63697 +#endif
63698 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63699 + grsec_enable_socket_server = 1;
63700 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
63701 +#endif
63702 +#endif
63703 +
63704 + return;
63705 +}
63706 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
63707 new file mode 100644
63708 index 0000000..5e05e20
63709 --- /dev/null
63710 +++ b/grsecurity/grsec_link.c
63711 @@ -0,0 +1,58 @@
63712 +#include <linux/kernel.h>
63713 +#include <linux/sched.h>
63714 +#include <linux/fs.h>
63715 +#include <linux/file.h>
63716 +#include <linux/grinternal.h>
63717 +
63718 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
63719 +{
63720 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
63721 + const struct inode *link_inode = link->dentry->d_inode;
63722 +
63723 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
63724 + /* ignore root-owned links, e.g. /proc/self */
63725 + gr_is_global_nonroot(link_inode->i_uid) && target &&
63726 + !uid_eq(link_inode->i_uid, target->i_uid)) {
63727 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
63728 + return 1;
63729 + }
63730 +#endif
63731 + return 0;
63732 +}
63733 +
63734 +int
63735 +gr_handle_follow_link(const struct inode *parent,
63736 + const struct inode *inode,
63737 + const struct dentry *dentry, const struct vfsmount *mnt)
63738 +{
63739 +#ifdef CONFIG_GRKERNSEC_LINK
63740 + const struct cred *cred = current_cred();
63741 +
63742 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
63743 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
63744 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
63745 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
63746 + return -EACCES;
63747 + }
63748 +#endif
63749 + return 0;
63750 +}
63751 +
63752 +int
63753 +gr_handle_hardlink(const struct dentry *dentry,
63754 + const struct vfsmount *mnt,
63755 + struct inode *inode, const int mode, const struct filename *to)
63756 +{
63757 +#ifdef CONFIG_GRKERNSEC_LINK
63758 + const struct cred *cred = current_cred();
63759 +
63760 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
63761 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
63762 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
63763 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
63764 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
63765 + return -EPERM;
63766 + }
63767 +#endif
63768 + return 0;
63769 +}
63770 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
63771 new file mode 100644
63772 index 0000000..7c06085
63773 --- /dev/null
63774 +++ b/grsecurity/grsec_log.c
63775 @@ -0,0 +1,326 @@
63776 +#include <linux/kernel.h>
63777 +#include <linux/sched.h>
63778 +#include <linux/file.h>
63779 +#include <linux/tty.h>
63780 +#include <linux/fs.h>
63781 +#include <linux/grinternal.h>
63782 +
63783 +#ifdef CONFIG_TREE_PREEMPT_RCU
63784 +#define DISABLE_PREEMPT() preempt_disable()
63785 +#define ENABLE_PREEMPT() preempt_enable()
63786 +#else
63787 +#define DISABLE_PREEMPT()
63788 +#define ENABLE_PREEMPT()
63789 +#endif
63790 +
63791 +#define BEGIN_LOCKS(x) \
63792 + DISABLE_PREEMPT(); \
63793 + rcu_read_lock(); \
63794 + read_lock(&tasklist_lock); \
63795 + read_lock(&grsec_exec_file_lock); \
63796 + if (x != GR_DO_AUDIT) \
63797 + spin_lock(&grsec_alert_lock); \
63798 + else \
63799 + spin_lock(&grsec_audit_lock)
63800 +
63801 +#define END_LOCKS(x) \
63802 + if (x != GR_DO_AUDIT) \
63803 + spin_unlock(&grsec_alert_lock); \
63804 + else \
63805 + spin_unlock(&grsec_audit_lock); \
63806 + read_unlock(&grsec_exec_file_lock); \
63807 + read_unlock(&tasklist_lock); \
63808 + rcu_read_unlock(); \
63809 + ENABLE_PREEMPT(); \
63810 + if (x == GR_DONT_AUDIT) \
63811 + gr_handle_alertkill(current)
63812 +
63813 +enum {
63814 + FLOODING,
63815 + NO_FLOODING
63816 +};
63817 +
63818 +extern char *gr_alert_log_fmt;
63819 +extern char *gr_audit_log_fmt;
63820 +extern char *gr_alert_log_buf;
63821 +extern char *gr_audit_log_buf;
63822 +
63823 +static int gr_log_start(int audit)
63824 +{
63825 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
63826 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
63827 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63828 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
63829 + unsigned long curr_secs = get_seconds();
63830 +
63831 + if (audit == GR_DO_AUDIT)
63832 + goto set_fmt;
63833 +
63834 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
63835 + grsec_alert_wtime = curr_secs;
63836 + grsec_alert_fyet = 0;
63837 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
63838 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
63839 + grsec_alert_fyet++;
63840 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
63841 + grsec_alert_wtime = curr_secs;
63842 + grsec_alert_fyet++;
63843 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
63844 + return FLOODING;
63845 + }
63846 + else return FLOODING;
63847 +
63848 +set_fmt:
63849 +#endif
63850 + memset(buf, 0, PAGE_SIZE);
63851 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
63852 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
63853 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
63854 + } else if (current->signal->curr_ip) {
63855 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
63856 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
63857 + } else if (gr_acl_is_enabled()) {
63858 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
63859 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
63860 + } else {
63861 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
63862 + strcpy(buf, fmt);
63863 + }
63864 +
63865 + return NO_FLOODING;
63866 +}
63867 +
63868 +static void gr_log_middle(int audit, const char *msg, va_list ap)
63869 + __attribute__ ((format (printf, 2, 0)));
63870 +
63871 +static void gr_log_middle(int audit, const char *msg, va_list ap)
63872 +{
63873 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63874 + unsigned int len = strlen(buf);
63875 +
63876 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
63877 +
63878 + return;
63879 +}
63880 +
63881 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
63882 + __attribute__ ((format (printf, 2, 3)));
63883 +
63884 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
63885 +{
63886 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63887 + unsigned int len = strlen(buf);
63888 + va_list ap;
63889 +
63890 + va_start(ap, msg);
63891 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
63892 + va_end(ap);
63893 +
63894 + return;
63895 +}
63896 +
63897 +static void gr_log_end(int audit, int append_default)
63898 +{
63899 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63900 + if (append_default) {
63901 + struct task_struct *task = current;
63902 + struct task_struct *parent = task->real_parent;
63903 + const struct cred *cred = __task_cred(task);
63904 + const struct cred *pcred = __task_cred(parent);
63905 + unsigned int len = strlen(buf);
63906 +
63907 + 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));
63908 + }
63909 +
63910 + printk("%s\n", buf);
63911 +
63912 + return;
63913 +}
63914 +
63915 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
63916 +{
63917 + int logtype;
63918 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
63919 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
63920 + void *voidptr = NULL;
63921 + int num1 = 0, num2 = 0;
63922 + unsigned long ulong1 = 0, ulong2 = 0;
63923 + struct dentry *dentry = NULL;
63924 + struct vfsmount *mnt = NULL;
63925 + struct file *file = NULL;
63926 + struct task_struct *task = NULL;
63927 + const struct cred *cred, *pcred;
63928 + va_list ap;
63929 +
63930 + BEGIN_LOCKS(audit);
63931 + logtype = gr_log_start(audit);
63932 + if (logtype == FLOODING) {
63933 + END_LOCKS(audit);
63934 + return;
63935 + }
63936 + va_start(ap, argtypes);
63937 + switch (argtypes) {
63938 + case GR_TTYSNIFF:
63939 + task = va_arg(ap, struct task_struct *);
63940 + 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));
63941 + break;
63942 + case GR_SYSCTL_HIDDEN:
63943 + str1 = va_arg(ap, char *);
63944 + gr_log_middle_varargs(audit, msg, result, str1);
63945 + break;
63946 + case GR_RBAC:
63947 + dentry = va_arg(ap, struct dentry *);
63948 + mnt = va_arg(ap, struct vfsmount *);
63949 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
63950 + break;
63951 + case GR_RBAC_STR:
63952 + dentry = va_arg(ap, struct dentry *);
63953 + mnt = va_arg(ap, struct vfsmount *);
63954 + str1 = va_arg(ap, char *);
63955 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
63956 + break;
63957 + case GR_STR_RBAC:
63958 + str1 = va_arg(ap, char *);
63959 + dentry = va_arg(ap, struct dentry *);
63960 + mnt = va_arg(ap, struct vfsmount *);
63961 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
63962 + break;
63963 + case GR_RBAC_MODE2:
63964 + dentry = va_arg(ap, struct dentry *);
63965 + mnt = va_arg(ap, struct vfsmount *);
63966 + str1 = va_arg(ap, char *);
63967 + str2 = va_arg(ap, char *);
63968 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
63969 + break;
63970 + case GR_RBAC_MODE3:
63971 + dentry = va_arg(ap, struct dentry *);
63972 + mnt = va_arg(ap, struct vfsmount *);
63973 + str1 = va_arg(ap, char *);
63974 + str2 = va_arg(ap, char *);
63975 + str3 = va_arg(ap, char *);
63976 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
63977 + break;
63978 + case GR_FILENAME:
63979 + dentry = va_arg(ap, struct dentry *);
63980 + mnt = va_arg(ap, struct vfsmount *);
63981 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
63982 + break;
63983 + case GR_STR_FILENAME:
63984 + str1 = va_arg(ap, char *);
63985 + dentry = va_arg(ap, struct dentry *);
63986 + mnt = va_arg(ap, struct vfsmount *);
63987 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
63988 + break;
63989 + case GR_FILENAME_STR:
63990 + dentry = va_arg(ap, struct dentry *);
63991 + mnt = va_arg(ap, struct vfsmount *);
63992 + str1 = va_arg(ap, char *);
63993 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
63994 + break;
63995 + case GR_FILENAME_TWO_INT:
63996 + dentry = va_arg(ap, struct dentry *);
63997 + mnt = va_arg(ap, struct vfsmount *);
63998 + num1 = va_arg(ap, int);
63999 + num2 = va_arg(ap, int);
64000 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
64001 + break;
64002 + case GR_FILENAME_TWO_INT_STR:
64003 + dentry = va_arg(ap, struct dentry *);
64004 + mnt = va_arg(ap, struct vfsmount *);
64005 + num1 = va_arg(ap, int);
64006 + num2 = va_arg(ap, int);
64007 + str1 = va_arg(ap, char *);
64008 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
64009 + break;
64010 + case GR_TEXTREL:
64011 + file = va_arg(ap, struct file *);
64012 + ulong1 = va_arg(ap, unsigned long);
64013 + ulong2 = va_arg(ap, unsigned long);
64014 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
64015 + break;
64016 + case GR_PTRACE:
64017 + task = va_arg(ap, struct task_struct *);
64018 + 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));
64019 + break;
64020 + case GR_RESOURCE:
64021 + task = va_arg(ap, struct task_struct *);
64022 + cred = __task_cred(task);
64023 + pcred = __task_cred(task->real_parent);
64024 + ulong1 = va_arg(ap, unsigned long);
64025 + str1 = va_arg(ap, char *);
64026 + ulong2 = va_arg(ap, unsigned long);
64027 + 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));
64028 + break;
64029 + case GR_CAP:
64030 + task = va_arg(ap, struct task_struct *);
64031 + cred = __task_cred(task);
64032 + pcred = __task_cred(task->real_parent);
64033 + str1 = va_arg(ap, char *);
64034 + 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));
64035 + break;
64036 + case GR_SIG:
64037 + str1 = va_arg(ap, char *);
64038 + voidptr = va_arg(ap, void *);
64039 + gr_log_middle_varargs(audit, msg, str1, voidptr);
64040 + break;
64041 + case GR_SIG2:
64042 + task = va_arg(ap, struct task_struct *);
64043 + cred = __task_cred(task);
64044 + pcred = __task_cred(task->real_parent);
64045 + num1 = va_arg(ap, int);
64046 + 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));
64047 + break;
64048 + case GR_CRASH1:
64049 + task = va_arg(ap, struct task_struct *);
64050 + cred = __task_cred(task);
64051 + pcred = __task_cred(task->real_parent);
64052 + ulong1 = va_arg(ap, unsigned long);
64053 + 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);
64054 + break;
64055 + case GR_CRASH2:
64056 + task = va_arg(ap, struct task_struct *);
64057 + cred = __task_cred(task);
64058 + pcred = __task_cred(task->real_parent);
64059 + ulong1 = va_arg(ap, unsigned long);
64060 + 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);
64061 + break;
64062 + case GR_RWXMAP:
64063 + file = va_arg(ap, struct file *);
64064 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
64065 + break;
64066 + case GR_PSACCT:
64067 + {
64068 + unsigned int wday, cday;
64069 + __u8 whr, chr;
64070 + __u8 wmin, cmin;
64071 + __u8 wsec, csec;
64072 + char cur_tty[64] = { 0 };
64073 + char parent_tty[64] = { 0 };
64074 +
64075 + task = va_arg(ap, struct task_struct *);
64076 + wday = va_arg(ap, unsigned int);
64077 + cday = va_arg(ap, unsigned int);
64078 + whr = va_arg(ap, int);
64079 + chr = va_arg(ap, int);
64080 + wmin = va_arg(ap, int);
64081 + cmin = va_arg(ap, int);
64082 + wsec = va_arg(ap, int);
64083 + csec = va_arg(ap, int);
64084 + ulong1 = va_arg(ap, unsigned long);
64085 + cred = __task_cred(task);
64086 + pcred = __task_cred(task->real_parent);
64087 +
64088 + 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));
64089 + }
64090 + break;
64091 + default:
64092 + gr_log_middle(audit, msg, ap);
64093 + }
64094 + va_end(ap);
64095 + // these don't need DEFAULTSECARGS printed on the end
64096 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
64097 + gr_log_end(audit, 0);
64098 + else
64099 + gr_log_end(audit, 1);
64100 + END_LOCKS(audit);
64101 +}
64102 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
64103 new file mode 100644
64104 index 0000000..f536303
64105 --- /dev/null
64106 +++ b/grsecurity/grsec_mem.c
64107 @@ -0,0 +1,40 @@
64108 +#include <linux/kernel.h>
64109 +#include <linux/sched.h>
64110 +#include <linux/mm.h>
64111 +#include <linux/mman.h>
64112 +#include <linux/grinternal.h>
64113 +
64114 +void
64115 +gr_handle_ioperm(void)
64116 +{
64117 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
64118 + return;
64119 +}
64120 +
64121 +void
64122 +gr_handle_iopl(void)
64123 +{
64124 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
64125 + return;
64126 +}
64127 +
64128 +void
64129 +gr_handle_mem_readwrite(u64 from, u64 to)
64130 +{
64131 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
64132 + return;
64133 +}
64134 +
64135 +void
64136 +gr_handle_vm86(void)
64137 +{
64138 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
64139 + return;
64140 +}
64141 +
64142 +void
64143 +gr_log_badprocpid(const char *entry)
64144 +{
64145 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
64146 + return;
64147 +}
64148 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
64149 new file mode 100644
64150 index 0000000..2131422
64151 --- /dev/null
64152 +++ b/grsecurity/grsec_mount.c
64153 @@ -0,0 +1,62 @@
64154 +#include <linux/kernel.h>
64155 +#include <linux/sched.h>
64156 +#include <linux/mount.h>
64157 +#include <linux/grsecurity.h>
64158 +#include <linux/grinternal.h>
64159 +
64160 +void
64161 +gr_log_remount(const char *devname, const int retval)
64162 +{
64163 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64164 + if (grsec_enable_mount && (retval >= 0))
64165 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
64166 +#endif
64167 + return;
64168 +}
64169 +
64170 +void
64171 +gr_log_unmount(const char *devname, const int retval)
64172 +{
64173 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64174 + if (grsec_enable_mount && (retval >= 0))
64175 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
64176 +#endif
64177 + return;
64178 +}
64179 +
64180 +void
64181 +gr_log_mount(const char *from, const char *to, const int retval)
64182 +{
64183 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64184 + if (grsec_enable_mount && (retval >= 0))
64185 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
64186 +#endif
64187 + return;
64188 +}
64189 +
64190 +int
64191 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
64192 +{
64193 +#ifdef CONFIG_GRKERNSEC_ROFS
64194 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
64195 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
64196 + return -EPERM;
64197 + } else
64198 + return 0;
64199 +#endif
64200 + return 0;
64201 +}
64202 +
64203 +int
64204 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
64205 +{
64206 +#ifdef CONFIG_GRKERNSEC_ROFS
64207 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
64208 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
64209 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
64210 + return -EPERM;
64211 + } else
64212 + return 0;
64213 +#endif
64214 + return 0;
64215 +}
64216 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
64217 new file mode 100644
64218 index 0000000..a3b12a0
64219 --- /dev/null
64220 +++ b/grsecurity/grsec_pax.c
64221 @@ -0,0 +1,36 @@
64222 +#include <linux/kernel.h>
64223 +#include <linux/sched.h>
64224 +#include <linux/mm.h>
64225 +#include <linux/file.h>
64226 +#include <linux/grinternal.h>
64227 +#include <linux/grsecurity.h>
64228 +
64229 +void
64230 +gr_log_textrel(struct vm_area_struct * vma)
64231 +{
64232 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64233 + if (grsec_enable_audit_textrel)
64234 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
64235 +#endif
64236 + return;
64237 +}
64238 +
64239 +void
64240 +gr_log_rwxmmap(struct file *file)
64241 +{
64242 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64243 + if (grsec_enable_log_rwxmaps)
64244 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
64245 +#endif
64246 + return;
64247 +}
64248 +
64249 +void
64250 +gr_log_rwxmprotect(struct file *file)
64251 +{
64252 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64253 + if (grsec_enable_log_rwxmaps)
64254 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
64255 +#endif
64256 + return;
64257 +}
64258 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
64259 new file mode 100644
64260 index 0000000..f7f29aa
64261 --- /dev/null
64262 +++ b/grsecurity/grsec_ptrace.c
64263 @@ -0,0 +1,30 @@
64264 +#include <linux/kernel.h>
64265 +#include <linux/sched.h>
64266 +#include <linux/grinternal.h>
64267 +#include <linux/security.h>
64268 +
64269 +void
64270 +gr_audit_ptrace(struct task_struct *task)
64271 +{
64272 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64273 + if (grsec_enable_audit_ptrace)
64274 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
64275 +#endif
64276 + return;
64277 +}
64278 +
64279 +int
64280 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
64281 +{
64282 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64283 + const struct dentry *dentry = file->f_path.dentry;
64284 + const struct vfsmount *mnt = file->f_path.mnt;
64285 +
64286 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
64287 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
64288 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
64289 + return -EACCES;
64290 + }
64291 +#endif
64292 + return 0;
64293 +}
64294 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
64295 new file mode 100644
64296 index 0000000..e09715a
64297 --- /dev/null
64298 +++ b/grsecurity/grsec_sig.c
64299 @@ -0,0 +1,222 @@
64300 +#include <linux/kernel.h>
64301 +#include <linux/sched.h>
64302 +#include <linux/delay.h>
64303 +#include <linux/grsecurity.h>
64304 +#include <linux/grinternal.h>
64305 +#include <linux/hardirq.h>
64306 +
64307 +char *signames[] = {
64308 + [SIGSEGV] = "Segmentation fault",
64309 + [SIGILL] = "Illegal instruction",
64310 + [SIGABRT] = "Abort",
64311 + [SIGBUS] = "Invalid alignment/Bus error"
64312 +};
64313 +
64314 +void
64315 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
64316 +{
64317 +#ifdef CONFIG_GRKERNSEC_SIGNAL
64318 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
64319 + (sig == SIGABRT) || (sig == SIGBUS))) {
64320 + if (task_pid_nr(t) == task_pid_nr(current)) {
64321 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
64322 + } else {
64323 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
64324 + }
64325 + }
64326 +#endif
64327 + return;
64328 +}
64329 +
64330 +int
64331 +gr_handle_signal(const struct task_struct *p, const int sig)
64332 +{
64333 +#ifdef CONFIG_GRKERNSEC
64334 + /* ignore the 0 signal for protected task checks */
64335 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
64336 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
64337 + return -EPERM;
64338 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
64339 + return -EPERM;
64340 + }
64341 +#endif
64342 + return 0;
64343 +}
64344 +
64345 +#ifdef CONFIG_GRKERNSEC
64346 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
64347 +
64348 +int gr_fake_force_sig(int sig, struct task_struct *t)
64349 +{
64350 + unsigned long int flags;
64351 + int ret, blocked, ignored;
64352 + struct k_sigaction *action;
64353 +
64354 + spin_lock_irqsave(&t->sighand->siglock, flags);
64355 + action = &t->sighand->action[sig-1];
64356 + ignored = action->sa.sa_handler == SIG_IGN;
64357 + blocked = sigismember(&t->blocked, sig);
64358 + if (blocked || ignored) {
64359 + action->sa.sa_handler = SIG_DFL;
64360 + if (blocked) {
64361 + sigdelset(&t->blocked, sig);
64362 + recalc_sigpending_and_wake(t);
64363 + }
64364 + }
64365 + if (action->sa.sa_handler == SIG_DFL)
64366 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
64367 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
64368 +
64369 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
64370 +
64371 + return ret;
64372 +}
64373 +#endif
64374 +
64375 +#ifdef CONFIG_GRKERNSEC_BRUTE
64376 +#define GR_USER_BAN_TIME (15 * 60)
64377 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
64378 +
64379 +static int __get_dumpable(unsigned long mm_flags)
64380 +{
64381 + int ret;
64382 +
64383 + ret = mm_flags & MMF_DUMPABLE_MASK;
64384 + return (ret >= 2) ? 2 : ret;
64385 +}
64386 +#endif
64387 +
64388 +void gr_handle_brute_attach(unsigned long mm_flags)
64389 +{
64390 +#ifdef CONFIG_GRKERNSEC_BRUTE
64391 + struct task_struct *p = current;
64392 + kuid_t uid = GLOBAL_ROOT_UID;
64393 + int daemon = 0;
64394 +
64395 + if (!grsec_enable_brute)
64396 + return;
64397 +
64398 + rcu_read_lock();
64399 + read_lock(&tasklist_lock);
64400 + read_lock(&grsec_exec_file_lock);
64401 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
64402 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
64403 + p->real_parent->brute = 1;
64404 + daemon = 1;
64405 + } else {
64406 + const struct cred *cred = __task_cred(p), *cred2;
64407 + struct task_struct *tsk, *tsk2;
64408 +
64409 + if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
64410 + struct user_struct *user;
64411 +
64412 + uid = cred->uid;
64413 +
64414 + /* this is put upon execution past expiration */
64415 + user = find_user(uid);
64416 + if (user == NULL)
64417 + goto unlock;
64418 + user->banned = 1;
64419 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
64420 + if (user->ban_expires == ~0UL)
64421 + user->ban_expires--;
64422 +
64423 + do_each_thread(tsk2, tsk) {
64424 + cred2 = __task_cred(tsk);
64425 + if (tsk != p && uid_eq(cred2->uid, uid))
64426 + gr_fake_force_sig(SIGKILL, tsk);
64427 + } while_each_thread(tsk2, tsk);
64428 + }
64429 + }
64430 +unlock:
64431 + read_unlock(&grsec_exec_file_lock);
64432 + read_unlock(&tasklist_lock);
64433 + rcu_read_unlock();
64434 +
64435 + if (gr_is_global_nonroot(uid))
64436 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
64437 + GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
64438 + else if (daemon)
64439 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
64440 +
64441 +#endif
64442 + return;
64443 +}
64444 +
64445 +void gr_handle_brute_check(void)
64446 +{
64447 +#ifdef CONFIG_GRKERNSEC_BRUTE
64448 + struct task_struct *p = current;
64449 +
64450 + if (unlikely(p->brute)) {
64451 + if (!grsec_enable_brute)
64452 + p->brute = 0;
64453 + else if (time_before(get_seconds(), p->brute_expires))
64454 + msleep(30 * 1000);
64455 + }
64456 +#endif
64457 + return;
64458 +}
64459 +
64460 +void gr_handle_kernel_exploit(void)
64461 +{
64462 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
64463 + const struct cred *cred;
64464 + struct task_struct *tsk, *tsk2;
64465 + struct user_struct *user;
64466 + kuid_t uid;
64467 +
64468 + if (in_irq() || in_serving_softirq() || in_nmi())
64469 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
64470 +
64471 + uid = current_uid();
64472 +
64473 + if (gr_is_global_root(uid))
64474 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
64475 + else {
64476 + /* kill all the processes of this user, hold a reference
64477 + to their creds struct, and prevent them from creating
64478 + another process until system reset
64479 + */
64480 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
64481 + GR_GLOBAL_UID(uid));
64482 + /* we intentionally leak this ref */
64483 + user = get_uid(current->cred->user);
64484 + if (user) {
64485 + user->banned = 1;
64486 + user->ban_expires = ~0UL;
64487 + }
64488 +
64489 + read_lock(&tasklist_lock);
64490 + do_each_thread(tsk2, tsk) {
64491 + cred = __task_cred(tsk);
64492 + if (uid_eq(cred->uid, uid))
64493 + gr_fake_force_sig(SIGKILL, tsk);
64494 + } while_each_thread(tsk2, tsk);
64495 + read_unlock(&tasklist_lock);
64496 + }
64497 +#endif
64498 +}
64499 +
64500 +int __gr_process_user_ban(struct user_struct *user)
64501 +{
64502 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64503 + if (unlikely(user->banned)) {
64504 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
64505 + user->banned = 0;
64506 + user->ban_expires = 0;
64507 + free_uid(user);
64508 + } else
64509 + return -EPERM;
64510 + }
64511 +#endif
64512 + return 0;
64513 +}
64514 +
64515 +int gr_process_user_ban(void)
64516 +{
64517 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64518 + return __gr_process_user_ban(current->cred->user);
64519 +#endif
64520 + return 0;
64521 +}
64522 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
64523 new file mode 100644
64524 index 0000000..4030d57
64525 --- /dev/null
64526 +++ b/grsecurity/grsec_sock.c
64527 @@ -0,0 +1,244 @@
64528 +#include <linux/kernel.h>
64529 +#include <linux/module.h>
64530 +#include <linux/sched.h>
64531 +#include <linux/file.h>
64532 +#include <linux/net.h>
64533 +#include <linux/in.h>
64534 +#include <linux/ip.h>
64535 +#include <net/sock.h>
64536 +#include <net/inet_sock.h>
64537 +#include <linux/grsecurity.h>
64538 +#include <linux/grinternal.h>
64539 +#include <linux/gracl.h>
64540 +
64541 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
64542 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
64543 +
64544 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
64545 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
64546 +
64547 +#ifdef CONFIG_UNIX_MODULE
64548 +EXPORT_SYMBOL(gr_acl_handle_unix);
64549 +EXPORT_SYMBOL(gr_acl_handle_mknod);
64550 +EXPORT_SYMBOL(gr_handle_chroot_unix);
64551 +EXPORT_SYMBOL(gr_handle_create);
64552 +#endif
64553 +
64554 +#ifdef CONFIG_GRKERNSEC
64555 +#define gr_conn_table_size 32749
64556 +struct conn_table_entry {
64557 + struct conn_table_entry *next;
64558 + struct signal_struct *sig;
64559 +};
64560 +
64561 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
64562 +DEFINE_SPINLOCK(gr_conn_table_lock);
64563 +
64564 +extern const char * gr_socktype_to_name(unsigned char type);
64565 +extern const char * gr_proto_to_name(unsigned char proto);
64566 +extern const char * gr_sockfamily_to_name(unsigned char family);
64567 +
64568 +static __inline__ int
64569 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
64570 +{
64571 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
64572 +}
64573 +
64574 +static __inline__ int
64575 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
64576 + __u16 sport, __u16 dport)
64577 +{
64578 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
64579 + sig->gr_sport == sport && sig->gr_dport == dport))
64580 + return 1;
64581 + else
64582 + return 0;
64583 +}
64584 +
64585 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
64586 +{
64587 + struct conn_table_entry **match;
64588 + unsigned int index;
64589 +
64590 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
64591 + sig->gr_sport, sig->gr_dport,
64592 + gr_conn_table_size);
64593 +
64594 + newent->sig = sig;
64595 +
64596 + match = &gr_conn_table[index];
64597 + newent->next = *match;
64598 + *match = newent;
64599 +
64600 + return;
64601 +}
64602 +
64603 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
64604 +{
64605 + struct conn_table_entry *match, *last = NULL;
64606 + unsigned int index;
64607 +
64608 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
64609 + sig->gr_sport, sig->gr_dport,
64610 + gr_conn_table_size);
64611 +
64612 + match = gr_conn_table[index];
64613 + while (match && !conn_match(match->sig,
64614 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
64615 + sig->gr_dport)) {
64616 + last = match;
64617 + match = match->next;
64618 + }
64619 +
64620 + if (match) {
64621 + if (last)
64622 + last->next = match->next;
64623 + else
64624 + gr_conn_table[index] = NULL;
64625 + kfree(match);
64626 + }
64627 +
64628 + return;
64629 +}
64630 +
64631 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
64632 + __u16 sport, __u16 dport)
64633 +{
64634 + struct conn_table_entry *match;
64635 + unsigned int index;
64636 +
64637 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
64638 +
64639 + match = gr_conn_table[index];
64640 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
64641 + match = match->next;
64642 +
64643 + if (match)
64644 + return match->sig;
64645 + else
64646 + return NULL;
64647 +}
64648 +
64649 +#endif
64650 +
64651 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
64652 +{
64653 +#ifdef CONFIG_GRKERNSEC
64654 + struct signal_struct *sig = task->signal;
64655 + struct conn_table_entry *newent;
64656 +
64657 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
64658 + if (newent == NULL)
64659 + return;
64660 + /* no bh lock needed since we are called with bh disabled */
64661 + spin_lock(&gr_conn_table_lock);
64662 + gr_del_task_from_ip_table_nolock(sig);
64663 + sig->gr_saddr = inet->inet_rcv_saddr;
64664 + sig->gr_daddr = inet->inet_daddr;
64665 + sig->gr_sport = inet->inet_sport;
64666 + sig->gr_dport = inet->inet_dport;
64667 + gr_add_to_task_ip_table_nolock(sig, newent);
64668 + spin_unlock(&gr_conn_table_lock);
64669 +#endif
64670 + return;
64671 +}
64672 +
64673 +void gr_del_task_from_ip_table(struct task_struct *task)
64674 +{
64675 +#ifdef CONFIG_GRKERNSEC
64676 + spin_lock_bh(&gr_conn_table_lock);
64677 + gr_del_task_from_ip_table_nolock(task->signal);
64678 + spin_unlock_bh(&gr_conn_table_lock);
64679 +#endif
64680 + return;
64681 +}
64682 +
64683 +void
64684 +gr_attach_curr_ip(const struct sock *sk)
64685 +{
64686 +#ifdef CONFIG_GRKERNSEC
64687 + struct signal_struct *p, *set;
64688 + const struct inet_sock *inet = inet_sk(sk);
64689 +
64690 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
64691 + return;
64692 +
64693 + set = current->signal;
64694 +
64695 + spin_lock_bh(&gr_conn_table_lock);
64696 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
64697 + inet->inet_dport, inet->inet_sport);
64698 + if (unlikely(p != NULL)) {
64699 + set->curr_ip = p->curr_ip;
64700 + set->used_accept = 1;
64701 + gr_del_task_from_ip_table_nolock(p);
64702 + spin_unlock_bh(&gr_conn_table_lock);
64703 + return;
64704 + }
64705 + spin_unlock_bh(&gr_conn_table_lock);
64706 +
64707 + set->curr_ip = inet->inet_daddr;
64708 + set->used_accept = 1;
64709 +#endif
64710 + return;
64711 +}
64712 +
64713 +int
64714 +gr_handle_sock_all(const int family, const int type, const int protocol)
64715 +{
64716 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64717 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
64718 + (family != AF_UNIX)) {
64719 + if (family == AF_INET)
64720 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
64721 + else
64722 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
64723 + return -EACCES;
64724 + }
64725 +#endif
64726 + return 0;
64727 +}
64728 +
64729 +int
64730 +gr_handle_sock_server(const struct sockaddr *sck)
64731 +{
64732 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64733 + if (grsec_enable_socket_server &&
64734 + in_group_p(grsec_socket_server_gid) &&
64735 + sck && (sck->sa_family != AF_UNIX) &&
64736 + (sck->sa_family != AF_LOCAL)) {
64737 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
64738 + return -EACCES;
64739 + }
64740 +#endif
64741 + return 0;
64742 +}
64743 +
64744 +int
64745 +gr_handle_sock_server_other(const struct sock *sck)
64746 +{
64747 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64748 + if (grsec_enable_socket_server &&
64749 + in_group_p(grsec_socket_server_gid) &&
64750 + sck && (sck->sk_family != AF_UNIX) &&
64751 + (sck->sk_family != AF_LOCAL)) {
64752 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
64753 + return -EACCES;
64754 + }
64755 +#endif
64756 + return 0;
64757 +}
64758 +
64759 +int
64760 +gr_handle_sock_client(const struct sockaddr *sck)
64761 +{
64762 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64763 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
64764 + sck && (sck->sa_family != AF_UNIX) &&
64765 + (sck->sa_family != AF_LOCAL)) {
64766 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
64767 + return -EACCES;
64768 + }
64769 +#endif
64770 + return 0;
64771 +}
64772 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
64773 new file mode 100644
64774 index 0000000..f55ef0f
64775 --- /dev/null
64776 +++ b/grsecurity/grsec_sysctl.c
64777 @@ -0,0 +1,469 @@
64778 +#include <linux/kernel.h>
64779 +#include <linux/sched.h>
64780 +#include <linux/sysctl.h>
64781 +#include <linux/grsecurity.h>
64782 +#include <linux/grinternal.h>
64783 +
64784 +int
64785 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
64786 +{
64787 +#ifdef CONFIG_GRKERNSEC_SYSCTL
64788 + if (dirname == NULL || name == NULL)
64789 + return 0;
64790 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
64791 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
64792 + return -EACCES;
64793 + }
64794 +#endif
64795 + return 0;
64796 +}
64797 +
64798 +#ifdef CONFIG_GRKERNSEC_ROFS
64799 +static int __maybe_unused one = 1;
64800 +#endif
64801 +
64802 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
64803 +struct ctl_table grsecurity_table[] = {
64804 +#ifdef CONFIG_GRKERNSEC_SYSCTL
64805 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
64806 +#ifdef CONFIG_GRKERNSEC_IO
64807 + {
64808 + .procname = "disable_priv_io",
64809 + .data = &grsec_disable_privio,
64810 + .maxlen = sizeof(int),
64811 + .mode = 0600,
64812 + .proc_handler = &proc_dointvec,
64813 + },
64814 +#endif
64815 +#endif
64816 +#ifdef CONFIG_GRKERNSEC_LINK
64817 + {
64818 + .procname = "linking_restrictions",
64819 + .data = &grsec_enable_link,
64820 + .maxlen = sizeof(int),
64821 + .mode = 0600,
64822 + .proc_handler = &proc_dointvec,
64823 + },
64824 +#endif
64825 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64826 + {
64827 + .procname = "enforce_symlinksifowner",
64828 + .data = &grsec_enable_symlinkown,
64829 + .maxlen = sizeof(int),
64830 + .mode = 0600,
64831 + .proc_handler = &proc_dointvec,
64832 + },
64833 + {
64834 + .procname = "symlinkown_gid",
64835 + .data = &grsec_symlinkown_gid,
64836 + .maxlen = sizeof(int),
64837 + .mode = 0600,
64838 + .proc_handler = &proc_dointvec,
64839 + },
64840 +#endif
64841 +#ifdef CONFIG_GRKERNSEC_BRUTE
64842 + {
64843 + .procname = "deter_bruteforce",
64844 + .data = &grsec_enable_brute,
64845 + .maxlen = sizeof(int),
64846 + .mode = 0600,
64847 + .proc_handler = &proc_dointvec,
64848 + },
64849 +#endif
64850 +#ifdef CONFIG_GRKERNSEC_FIFO
64851 + {
64852 + .procname = "fifo_restrictions",
64853 + .data = &grsec_enable_fifo,
64854 + .maxlen = sizeof(int),
64855 + .mode = 0600,
64856 + .proc_handler = &proc_dointvec,
64857 + },
64858 +#endif
64859 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64860 + {
64861 + .procname = "ptrace_readexec",
64862 + .data = &grsec_enable_ptrace_readexec,
64863 + .maxlen = sizeof(int),
64864 + .mode = 0600,
64865 + .proc_handler = &proc_dointvec,
64866 + },
64867 +#endif
64868 +#ifdef CONFIG_GRKERNSEC_SETXID
64869 + {
64870 + .procname = "consistent_setxid",
64871 + .data = &grsec_enable_setxid,
64872 + .maxlen = sizeof(int),
64873 + .mode = 0600,
64874 + .proc_handler = &proc_dointvec,
64875 + },
64876 +#endif
64877 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
64878 + {
64879 + .procname = "ip_blackhole",
64880 + .data = &grsec_enable_blackhole,
64881 + .maxlen = sizeof(int),
64882 + .mode = 0600,
64883 + .proc_handler = &proc_dointvec,
64884 + },
64885 + {
64886 + .procname = "lastack_retries",
64887 + .data = &grsec_lastack_retries,
64888 + .maxlen = sizeof(int),
64889 + .mode = 0600,
64890 + .proc_handler = &proc_dointvec,
64891 + },
64892 +#endif
64893 +#ifdef CONFIG_GRKERNSEC_EXECLOG
64894 + {
64895 + .procname = "exec_logging",
64896 + .data = &grsec_enable_execlog,
64897 + .maxlen = sizeof(int),
64898 + .mode = 0600,
64899 + .proc_handler = &proc_dointvec,
64900 + },
64901 +#endif
64902 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64903 + {
64904 + .procname = "rwxmap_logging",
64905 + .data = &grsec_enable_log_rwxmaps,
64906 + .maxlen = sizeof(int),
64907 + .mode = 0600,
64908 + .proc_handler = &proc_dointvec,
64909 + },
64910 +#endif
64911 +#ifdef CONFIG_GRKERNSEC_SIGNAL
64912 + {
64913 + .procname = "signal_logging",
64914 + .data = &grsec_enable_signal,
64915 + .maxlen = sizeof(int),
64916 + .mode = 0600,
64917 + .proc_handler = &proc_dointvec,
64918 + },
64919 +#endif
64920 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
64921 + {
64922 + .procname = "forkfail_logging",
64923 + .data = &grsec_enable_forkfail,
64924 + .maxlen = sizeof(int),
64925 + .mode = 0600,
64926 + .proc_handler = &proc_dointvec,
64927 + },
64928 +#endif
64929 +#ifdef CONFIG_GRKERNSEC_TIME
64930 + {
64931 + .procname = "timechange_logging",
64932 + .data = &grsec_enable_time,
64933 + .maxlen = sizeof(int),
64934 + .mode = 0600,
64935 + .proc_handler = &proc_dointvec,
64936 + },
64937 +#endif
64938 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64939 + {
64940 + .procname = "chroot_deny_shmat",
64941 + .data = &grsec_enable_chroot_shmat,
64942 + .maxlen = sizeof(int),
64943 + .mode = 0600,
64944 + .proc_handler = &proc_dointvec,
64945 + },
64946 +#endif
64947 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64948 + {
64949 + .procname = "chroot_deny_unix",
64950 + .data = &grsec_enable_chroot_unix,
64951 + .maxlen = sizeof(int),
64952 + .mode = 0600,
64953 + .proc_handler = &proc_dointvec,
64954 + },
64955 +#endif
64956 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64957 + {
64958 + .procname = "chroot_deny_mount",
64959 + .data = &grsec_enable_chroot_mount,
64960 + .maxlen = sizeof(int),
64961 + .mode = 0600,
64962 + .proc_handler = &proc_dointvec,
64963 + },
64964 +#endif
64965 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64966 + {
64967 + .procname = "chroot_deny_fchdir",
64968 + .data = &grsec_enable_chroot_fchdir,
64969 + .maxlen = sizeof(int),
64970 + .mode = 0600,
64971 + .proc_handler = &proc_dointvec,
64972 + },
64973 +#endif
64974 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64975 + {
64976 + .procname = "chroot_deny_chroot",
64977 + .data = &grsec_enable_chroot_double,
64978 + .maxlen = sizeof(int),
64979 + .mode = 0600,
64980 + .proc_handler = &proc_dointvec,
64981 + },
64982 +#endif
64983 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64984 + {
64985 + .procname = "chroot_deny_pivot",
64986 + .data = &grsec_enable_chroot_pivot,
64987 + .maxlen = sizeof(int),
64988 + .mode = 0600,
64989 + .proc_handler = &proc_dointvec,
64990 + },
64991 +#endif
64992 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64993 + {
64994 + .procname = "chroot_enforce_chdir",
64995 + .data = &grsec_enable_chroot_chdir,
64996 + .maxlen = sizeof(int),
64997 + .mode = 0600,
64998 + .proc_handler = &proc_dointvec,
64999 + },
65000 +#endif
65001 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65002 + {
65003 + .procname = "chroot_deny_chmod",
65004 + .data = &grsec_enable_chroot_chmod,
65005 + .maxlen = sizeof(int),
65006 + .mode = 0600,
65007 + .proc_handler = &proc_dointvec,
65008 + },
65009 +#endif
65010 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65011 + {
65012 + .procname = "chroot_deny_mknod",
65013 + .data = &grsec_enable_chroot_mknod,
65014 + .maxlen = sizeof(int),
65015 + .mode = 0600,
65016 + .proc_handler = &proc_dointvec,
65017 + },
65018 +#endif
65019 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65020 + {
65021 + .procname = "chroot_restrict_nice",
65022 + .data = &grsec_enable_chroot_nice,
65023 + .maxlen = sizeof(int),
65024 + .mode = 0600,
65025 + .proc_handler = &proc_dointvec,
65026 + },
65027 +#endif
65028 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65029 + {
65030 + .procname = "chroot_execlog",
65031 + .data = &grsec_enable_chroot_execlog,
65032 + .maxlen = sizeof(int),
65033 + .mode = 0600,
65034 + .proc_handler = &proc_dointvec,
65035 + },
65036 +#endif
65037 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65038 + {
65039 + .procname = "chroot_caps",
65040 + .data = &grsec_enable_chroot_caps,
65041 + .maxlen = sizeof(int),
65042 + .mode = 0600,
65043 + .proc_handler = &proc_dointvec,
65044 + },
65045 +#endif
65046 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65047 + {
65048 + .procname = "chroot_deny_sysctl",
65049 + .data = &grsec_enable_chroot_sysctl,
65050 + .maxlen = sizeof(int),
65051 + .mode = 0600,
65052 + .proc_handler = &proc_dointvec,
65053 + },
65054 +#endif
65055 +#ifdef CONFIG_GRKERNSEC_TPE
65056 + {
65057 + .procname = "tpe",
65058 + .data = &grsec_enable_tpe,
65059 + .maxlen = sizeof(int),
65060 + .mode = 0600,
65061 + .proc_handler = &proc_dointvec,
65062 + },
65063 + {
65064 + .procname = "tpe_gid",
65065 + .data = &grsec_tpe_gid,
65066 + .maxlen = sizeof(int),
65067 + .mode = 0600,
65068 + .proc_handler = &proc_dointvec,
65069 + },
65070 +#endif
65071 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65072 + {
65073 + .procname = "tpe_invert",
65074 + .data = &grsec_enable_tpe_invert,
65075 + .maxlen = sizeof(int),
65076 + .mode = 0600,
65077 + .proc_handler = &proc_dointvec,
65078 + },
65079 +#endif
65080 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
65081 + {
65082 + .procname = "tpe_restrict_all",
65083 + .data = &grsec_enable_tpe_all,
65084 + .maxlen = sizeof(int),
65085 + .mode = 0600,
65086 + .proc_handler = &proc_dointvec,
65087 + },
65088 +#endif
65089 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65090 + {
65091 + .procname = "socket_all",
65092 + .data = &grsec_enable_socket_all,
65093 + .maxlen = sizeof(int),
65094 + .mode = 0600,
65095 + .proc_handler = &proc_dointvec,
65096 + },
65097 + {
65098 + .procname = "socket_all_gid",
65099 + .data = &grsec_socket_all_gid,
65100 + .maxlen = sizeof(int),
65101 + .mode = 0600,
65102 + .proc_handler = &proc_dointvec,
65103 + },
65104 +#endif
65105 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65106 + {
65107 + .procname = "socket_client",
65108 + .data = &grsec_enable_socket_client,
65109 + .maxlen = sizeof(int),
65110 + .mode = 0600,
65111 + .proc_handler = &proc_dointvec,
65112 + },
65113 + {
65114 + .procname = "socket_client_gid",
65115 + .data = &grsec_socket_client_gid,
65116 + .maxlen = sizeof(int),
65117 + .mode = 0600,
65118 + .proc_handler = &proc_dointvec,
65119 + },
65120 +#endif
65121 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65122 + {
65123 + .procname = "socket_server",
65124 + .data = &grsec_enable_socket_server,
65125 + .maxlen = sizeof(int),
65126 + .mode = 0600,
65127 + .proc_handler = &proc_dointvec,
65128 + },
65129 + {
65130 + .procname = "socket_server_gid",
65131 + .data = &grsec_socket_server_gid,
65132 + .maxlen = sizeof(int),
65133 + .mode = 0600,
65134 + .proc_handler = &proc_dointvec,
65135 + },
65136 +#endif
65137 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65138 + {
65139 + .procname = "audit_group",
65140 + .data = &grsec_enable_group,
65141 + .maxlen = sizeof(int),
65142 + .mode = 0600,
65143 + .proc_handler = &proc_dointvec,
65144 + },
65145 + {
65146 + .procname = "audit_gid",
65147 + .data = &grsec_audit_gid,
65148 + .maxlen = sizeof(int),
65149 + .mode = 0600,
65150 + .proc_handler = &proc_dointvec,
65151 + },
65152 +#endif
65153 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65154 + {
65155 + .procname = "audit_chdir",
65156 + .data = &grsec_enable_chdir,
65157 + .maxlen = sizeof(int),
65158 + .mode = 0600,
65159 + .proc_handler = &proc_dointvec,
65160 + },
65161 +#endif
65162 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65163 + {
65164 + .procname = "audit_mount",
65165 + .data = &grsec_enable_mount,
65166 + .maxlen = sizeof(int),
65167 + .mode = 0600,
65168 + .proc_handler = &proc_dointvec,
65169 + },
65170 +#endif
65171 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65172 + {
65173 + .procname = "audit_textrel",
65174 + .data = &grsec_enable_audit_textrel,
65175 + .maxlen = sizeof(int),
65176 + .mode = 0600,
65177 + .proc_handler = &proc_dointvec,
65178 + },
65179 +#endif
65180 +#ifdef CONFIG_GRKERNSEC_DMESG
65181 + {
65182 + .procname = "dmesg",
65183 + .data = &grsec_enable_dmesg,
65184 + .maxlen = sizeof(int),
65185 + .mode = 0600,
65186 + .proc_handler = &proc_dointvec,
65187 + },
65188 +#endif
65189 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65190 + {
65191 + .procname = "chroot_findtask",
65192 + .data = &grsec_enable_chroot_findtask,
65193 + .maxlen = sizeof(int),
65194 + .mode = 0600,
65195 + .proc_handler = &proc_dointvec,
65196 + },
65197 +#endif
65198 +#ifdef CONFIG_GRKERNSEC_RESLOG
65199 + {
65200 + .procname = "resource_logging",
65201 + .data = &grsec_resource_logging,
65202 + .maxlen = sizeof(int),
65203 + .mode = 0600,
65204 + .proc_handler = &proc_dointvec,
65205 + },
65206 +#endif
65207 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65208 + {
65209 + .procname = "audit_ptrace",
65210 + .data = &grsec_enable_audit_ptrace,
65211 + .maxlen = sizeof(int),
65212 + .mode = 0600,
65213 + .proc_handler = &proc_dointvec,
65214 + },
65215 +#endif
65216 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65217 + {
65218 + .procname = "harden_ptrace",
65219 + .data = &grsec_enable_harden_ptrace,
65220 + .maxlen = sizeof(int),
65221 + .mode = 0600,
65222 + .proc_handler = &proc_dointvec,
65223 + },
65224 +#endif
65225 + {
65226 + .procname = "grsec_lock",
65227 + .data = &grsec_lock,
65228 + .maxlen = sizeof(int),
65229 + .mode = 0600,
65230 + .proc_handler = &proc_dointvec,
65231 + },
65232 +#endif
65233 +#ifdef CONFIG_GRKERNSEC_ROFS
65234 + {
65235 + .procname = "romount_protect",
65236 + .data = &grsec_enable_rofs,
65237 + .maxlen = sizeof(int),
65238 + .mode = 0600,
65239 + .proc_handler = &proc_dointvec_minmax,
65240 + .extra1 = &one,
65241 + .extra2 = &one,
65242 + },
65243 +#endif
65244 + { }
65245 +};
65246 +#endif
65247 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
65248 new file mode 100644
65249 index 0000000..0dc13c3
65250 --- /dev/null
65251 +++ b/grsecurity/grsec_time.c
65252 @@ -0,0 +1,16 @@
65253 +#include <linux/kernel.h>
65254 +#include <linux/sched.h>
65255 +#include <linux/grinternal.h>
65256 +#include <linux/module.h>
65257 +
65258 +void
65259 +gr_log_timechange(void)
65260 +{
65261 +#ifdef CONFIG_GRKERNSEC_TIME
65262 + if (grsec_enable_time)
65263 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
65264 +#endif
65265 + return;
65266 +}
65267 +
65268 +EXPORT_SYMBOL(gr_log_timechange);
65269 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
65270 new file mode 100644
65271 index 0000000..ee57dcf
65272 --- /dev/null
65273 +++ b/grsecurity/grsec_tpe.c
65274 @@ -0,0 +1,73 @@
65275 +#include <linux/kernel.h>
65276 +#include <linux/sched.h>
65277 +#include <linux/file.h>
65278 +#include <linux/fs.h>
65279 +#include <linux/grinternal.h>
65280 +
65281 +extern int gr_acl_tpe_check(void);
65282 +
65283 +int
65284 +gr_tpe_allow(const struct file *file)
65285 +{
65286 +#ifdef CONFIG_GRKERNSEC
65287 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
65288 + const struct cred *cred = current_cred();
65289 + char *msg = NULL;
65290 + char *msg2 = NULL;
65291 +
65292 + // never restrict root
65293 + if (gr_is_global_root(cred->uid))
65294 + return 1;
65295 +
65296 + if (grsec_enable_tpe) {
65297 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65298 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
65299 + msg = "not being in trusted group";
65300 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
65301 + msg = "being in untrusted group";
65302 +#else
65303 + if (in_group_p(grsec_tpe_gid))
65304 + msg = "being in untrusted group";
65305 +#endif
65306 + }
65307 + if (!msg && gr_acl_tpe_check())
65308 + msg = "being in untrusted role";
65309 +
65310 + // not in any affected group/role
65311 + if (!msg)
65312 + goto next_check;
65313 +
65314 + if (gr_is_global_nonroot(inode->i_uid))
65315 + msg2 = "file in non-root-owned directory";
65316 + else if (inode->i_mode & S_IWOTH)
65317 + msg2 = "file in world-writable directory";
65318 + else if (inode->i_mode & S_IWGRP)
65319 + msg2 = "file in group-writable directory";
65320 +
65321 + if (msg && msg2) {
65322 + char fullmsg[70] = {0};
65323 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
65324 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
65325 + return 0;
65326 + }
65327 + msg = NULL;
65328 +next_check:
65329 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
65330 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
65331 + return 1;
65332 +
65333 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
65334 + msg = "directory not owned by user";
65335 + else if (inode->i_mode & S_IWOTH)
65336 + msg = "file in world-writable directory";
65337 + else if (inode->i_mode & S_IWGRP)
65338 + msg = "file in group-writable directory";
65339 +
65340 + if (msg) {
65341 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
65342 + return 0;
65343 + }
65344 +#endif
65345 +#endif
65346 + return 1;
65347 +}
65348 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
65349 new file mode 100644
65350 index 0000000..9f7b1ac
65351 --- /dev/null
65352 +++ b/grsecurity/grsum.c
65353 @@ -0,0 +1,61 @@
65354 +#include <linux/err.h>
65355 +#include <linux/kernel.h>
65356 +#include <linux/sched.h>
65357 +#include <linux/mm.h>
65358 +#include <linux/scatterlist.h>
65359 +#include <linux/crypto.h>
65360 +#include <linux/gracl.h>
65361 +
65362 +
65363 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
65364 +#error "crypto and sha256 must be built into the kernel"
65365 +#endif
65366 +
65367 +int
65368 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
65369 +{
65370 + char *p;
65371 + struct crypto_hash *tfm;
65372 + struct hash_desc desc;
65373 + struct scatterlist sg;
65374 + unsigned char temp_sum[GR_SHA_LEN];
65375 + volatile int retval = 0;
65376 + volatile int dummy = 0;
65377 + unsigned int i;
65378 +
65379 + sg_init_table(&sg, 1);
65380 +
65381 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
65382 + if (IS_ERR(tfm)) {
65383 + /* should never happen, since sha256 should be built in */
65384 + return 1;
65385 + }
65386 +
65387 + desc.tfm = tfm;
65388 + desc.flags = 0;
65389 +
65390 + crypto_hash_init(&desc);
65391 +
65392 + p = salt;
65393 + sg_set_buf(&sg, p, GR_SALT_LEN);
65394 + crypto_hash_update(&desc, &sg, sg.length);
65395 +
65396 + p = entry->pw;
65397 + sg_set_buf(&sg, p, strlen(p));
65398 +
65399 + crypto_hash_update(&desc, &sg, sg.length);
65400 +
65401 + crypto_hash_final(&desc, temp_sum);
65402 +
65403 + memset(entry->pw, 0, GR_PW_LEN);
65404 +
65405 + for (i = 0; i < GR_SHA_LEN; i++)
65406 + if (sum[i] != temp_sum[i])
65407 + retval = 1;
65408 + else
65409 + dummy = 1; // waste a cycle
65410 +
65411 + crypto_free_hash(tfm);
65412 +
65413 + return retval;
65414 +}
65415 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
65416 index 77ff547..181834f 100644
65417 --- a/include/asm-generic/4level-fixup.h
65418 +++ b/include/asm-generic/4level-fixup.h
65419 @@ -13,8 +13,10 @@
65420 #define pmd_alloc(mm, pud, address) \
65421 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
65422 NULL: pmd_offset(pud, address))
65423 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
65424
65425 #define pud_alloc(mm, pgd, address) (pgd)
65426 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
65427 #define pud_offset(pgd, start) (pgd)
65428 #define pud_none(pud) 0
65429 #define pud_bad(pud) 0
65430 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
65431 index b7babf0..04ad282 100644
65432 --- a/include/asm-generic/atomic-long.h
65433 +++ b/include/asm-generic/atomic-long.h
65434 @@ -22,6 +22,12 @@
65435
65436 typedef atomic64_t atomic_long_t;
65437
65438 +#ifdef CONFIG_PAX_REFCOUNT
65439 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
65440 +#else
65441 +typedef atomic64_t atomic_long_unchecked_t;
65442 +#endif
65443 +
65444 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
65445
65446 static inline long atomic_long_read(atomic_long_t *l)
65447 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
65448 return (long)atomic64_read(v);
65449 }
65450
65451 +#ifdef CONFIG_PAX_REFCOUNT
65452 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
65453 +{
65454 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65455 +
65456 + return (long)atomic64_read_unchecked(v);
65457 +}
65458 +#endif
65459 +
65460 static inline void atomic_long_set(atomic_long_t *l, long i)
65461 {
65462 atomic64_t *v = (atomic64_t *)l;
65463 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
65464 atomic64_set(v, i);
65465 }
65466
65467 +#ifdef CONFIG_PAX_REFCOUNT
65468 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
65469 +{
65470 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65471 +
65472 + atomic64_set_unchecked(v, i);
65473 +}
65474 +#endif
65475 +
65476 static inline void atomic_long_inc(atomic_long_t *l)
65477 {
65478 atomic64_t *v = (atomic64_t *)l;
65479 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
65480 atomic64_inc(v);
65481 }
65482
65483 +#ifdef CONFIG_PAX_REFCOUNT
65484 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
65485 +{
65486 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65487 +
65488 + atomic64_inc_unchecked(v);
65489 +}
65490 +#endif
65491 +
65492 static inline void atomic_long_dec(atomic_long_t *l)
65493 {
65494 atomic64_t *v = (atomic64_t *)l;
65495 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
65496 atomic64_dec(v);
65497 }
65498
65499 +#ifdef CONFIG_PAX_REFCOUNT
65500 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
65501 +{
65502 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65503 +
65504 + atomic64_dec_unchecked(v);
65505 +}
65506 +#endif
65507 +
65508 static inline void atomic_long_add(long i, atomic_long_t *l)
65509 {
65510 atomic64_t *v = (atomic64_t *)l;
65511 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
65512 atomic64_add(i, v);
65513 }
65514
65515 +#ifdef CONFIG_PAX_REFCOUNT
65516 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
65517 +{
65518 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65519 +
65520 + atomic64_add_unchecked(i, v);
65521 +}
65522 +#endif
65523 +
65524 static inline void atomic_long_sub(long i, atomic_long_t *l)
65525 {
65526 atomic64_t *v = (atomic64_t *)l;
65527 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
65528 atomic64_sub(i, v);
65529 }
65530
65531 +#ifdef CONFIG_PAX_REFCOUNT
65532 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
65533 +{
65534 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65535 +
65536 + atomic64_sub_unchecked(i, v);
65537 +}
65538 +#endif
65539 +
65540 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
65541 {
65542 atomic64_t *v = (atomic64_t *)l;
65543 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
65544 return (long)atomic64_add_return(i, v);
65545 }
65546
65547 +#ifdef CONFIG_PAX_REFCOUNT
65548 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
65549 +{
65550 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65551 +
65552 + return (long)atomic64_add_return_unchecked(i, v);
65553 +}
65554 +#endif
65555 +
65556 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
65557 {
65558 atomic64_t *v = (atomic64_t *)l;
65559 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
65560 return (long)atomic64_inc_return(v);
65561 }
65562
65563 +#ifdef CONFIG_PAX_REFCOUNT
65564 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
65565 +{
65566 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65567 +
65568 + return (long)atomic64_inc_return_unchecked(v);
65569 +}
65570 +#endif
65571 +
65572 static inline long atomic_long_dec_return(atomic_long_t *l)
65573 {
65574 atomic64_t *v = (atomic64_t *)l;
65575 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
65576
65577 typedef atomic_t atomic_long_t;
65578
65579 +#ifdef CONFIG_PAX_REFCOUNT
65580 +typedef atomic_unchecked_t atomic_long_unchecked_t;
65581 +#else
65582 +typedef atomic_t atomic_long_unchecked_t;
65583 +#endif
65584 +
65585 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
65586 static inline long atomic_long_read(atomic_long_t *l)
65587 {
65588 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
65589 return (long)atomic_read(v);
65590 }
65591
65592 +#ifdef CONFIG_PAX_REFCOUNT
65593 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
65594 +{
65595 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65596 +
65597 + return (long)atomic_read_unchecked(v);
65598 +}
65599 +#endif
65600 +
65601 static inline void atomic_long_set(atomic_long_t *l, long i)
65602 {
65603 atomic_t *v = (atomic_t *)l;
65604 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
65605 atomic_set(v, i);
65606 }
65607
65608 +#ifdef CONFIG_PAX_REFCOUNT
65609 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
65610 +{
65611 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65612 +
65613 + atomic_set_unchecked(v, i);
65614 +}
65615 +#endif
65616 +
65617 static inline void atomic_long_inc(atomic_long_t *l)
65618 {
65619 atomic_t *v = (atomic_t *)l;
65620 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
65621 atomic_inc(v);
65622 }
65623
65624 +#ifdef CONFIG_PAX_REFCOUNT
65625 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
65626 +{
65627 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65628 +
65629 + atomic_inc_unchecked(v);
65630 +}
65631 +#endif
65632 +
65633 static inline void atomic_long_dec(atomic_long_t *l)
65634 {
65635 atomic_t *v = (atomic_t *)l;
65636 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
65637 atomic_dec(v);
65638 }
65639
65640 +#ifdef CONFIG_PAX_REFCOUNT
65641 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
65642 +{
65643 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65644 +
65645 + atomic_dec_unchecked(v);
65646 +}
65647 +#endif
65648 +
65649 static inline void atomic_long_add(long i, atomic_long_t *l)
65650 {
65651 atomic_t *v = (atomic_t *)l;
65652 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
65653 atomic_add(i, v);
65654 }
65655
65656 +#ifdef CONFIG_PAX_REFCOUNT
65657 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
65658 +{
65659 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65660 +
65661 + atomic_add_unchecked(i, v);
65662 +}
65663 +#endif
65664 +
65665 static inline void atomic_long_sub(long i, atomic_long_t *l)
65666 {
65667 atomic_t *v = (atomic_t *)l;
65668 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
65669 atomic_sub(i, v);
65670 }
65671
65672 +#ifdef CONFIG_PAX_REFCOUNT
65673 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
65674 +{
65675 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65676 +
65677 + atomic_sub_unchecked(i, v);
65678 +}
65679 +#endif
65680 +
65681 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
65682 {
65683 atomic_t *v = (atomic_t *)l;
65684 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
65685 return (long)atomic_add_return(i, v);
65686 }
65687
65688 +#ifdef CONFIG_PAX_REFCOUNT
65689 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
65690 +{
65691 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65692 +
65693 + return (long)atomic_add_return_unchecked(i, v);
65694 +}
65695 +
65696 +#endif
65697 +
65698 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
65699 {
65700 atomic_t *v = (atomic_t *)l;
65701 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
65702 return (long)atomic_inc_return(v);
65703 }
65704
65705 +#ifdef CONFIG_PAX_REFCOUNT
65706 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
65707 +{
65708 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65709 +
65710 + return (long)atomic_inc_return_unchecked(v);
65711 +}
65712 +#endif
65713 +
65714 static inline long atomic_long_dec_return(atomic_long_t *l)
65715 {
65716 atomic_t *v = (atomic_t *)l;
65717 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
65718
65719 #endif /* BITS_PER_LONG == 64 */
65720
65721 +#ifdef CONFIG_PAX_REFCOUNT
65722 +static inline void pax_refcount_needs_these_functions(void)
65723 +{
65724 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
65725 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
65726 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
65727 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
65728 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
65729 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
65730 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
65731 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
65732 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
65733 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
65734 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
65735 +#ifdef CONFIG_X86
65736 + atomic_clear_mask_unchecked(0, NULL);
65737 + atomic_set_mask_unchecked(0, NULL);
65738 +#endif
65739 +
65740 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
65741 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
65742 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
65743 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
65744 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
65745 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
65746 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
65747 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
65748 +}
65749 +#else
65750 +#define atomic_read_unchecked(v) atomic_read(v)
65751 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
65752 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
65753 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
65754 +#define atomic_inc_unchecked(v) atomic_inc(v)
65755 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
65756 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
65757 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
65758 +#define atomic_dec_unchecked(v) atomic_dec(v)
65759 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
65760 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
65761 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
65762 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
65763 +
65764 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
65765 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
65766 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
65767 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
65768 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
65769 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
65770 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
65771 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
65772 +#endif
65773 +
65774 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
65775 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
65776 index 1ced641..c896ee8 100644
65777 --- a/include/asm-generic/atomic.h
65778 +++ b/include/asm-generic/atomic.h
65779 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
65780 * Atomically clears the bits set in @mask from @v
65781 */
65782 #ifndef atomic_clear_mask
65783 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
65784 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
65785 {
65786 unsigned long flags;
65787
65788 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
65789 index b18ce4f..2ee2843 100644
65790 --- a/include/asm-generic/atomic64.h
65791 +++ b/include/asm-generic/atomic64.h
65792 @@ -16,6 +16,8 @@ typedef struct {
65793 long long counter;
65794 } atomic64_t;
65795
65796 +typedef atomic64_t atomic64_unchecked_t;
65797 +
65798 #define ATOMIC64_INIT(i) { (i) }
65799
65800 extern long long atomic64_read(const atomic64_t *v);
65801 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
65802 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
65803 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
65804
65805 +#define atomic64_read_unchecked(v) atomic64_read(v)
65806 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
65807 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
65808 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
65809 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
65810 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
65811 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
65812 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
65813 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
65814 +
65815 #endif /* _ASM_GENERIC_ATOMIC64_H */
65816 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
65817 index 1bfcfe5..e04c5c9 100644
65818 --- a/include/asm-generic/cache.h
65819 +++ b/include/asm-generic/cache.h
65820 @@ -6,7 +6,7 @@
65821 * cache lines need to provide their own cache.h.
65822 */
65823
65824 -#define L1_CACHE_SHIFT 5
65825 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
65826 +#define L1_CACHE_SHIFT 5UL
65827 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
65828
65829 #endif /* __ASM_GENERIC_CACHE_H */
65830 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
65831 index 0d68a1e..b74a761 100644
65832 --- a/include/asm-generic/emergency-restart.h
65833 +++ b/include/asm-generic/emergency-restart.h
65834 @@ -1,7 +1,7 @@
65835 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
65836 #define _ASM_GENERIC_EMERGENCY_RESTART_H
65837
65838 -static inline void machine_emergency_restart(void)
65839 +static inline __noreturn void machine_emergency_restart(void)
65840 {
65841 machine_restart(NULL);
65842 }
65843 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
65844 index 90f99c7..00ce236 100644
65845 --- a/include/asm-generic/kmap_types.h
65846 +++ b/include/asm-generic/kmap_types.h
65847 @@ -2,9 +2,9 @@
65848 #define _ASM_GENERIC_KMAP_TYPES_H
65849
65850 #ifdef __WITH_KM_FENCE
65851 -# define KM_TYPE_NR 41
65852 +# define KM_TYPE_NR 42
65853 #else
65854 -# define KM_TYPE_NR 20
65855 +# define KM_TYPE_NR 21
65856 #endif
65857
65858 #endif
65859 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
65860 index 9ceb03b..62b0b8f 100644
65861 --- a/include/asm-generic/local.h
65862 +++ b/include/asm-generic/local.h
65863 @@ -23,24 +23,37 @@ typedef struct
65864 atomic_long_t a;
65865 } local_t;
65866
65867 +typedef struct {
65868 + atomic_long_unchecked_t a;
65869 +} local_unchecked_t;
65870 +
65871 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
65872
65873 #define local_read(l) atomic_long_read(&(l)->a)
65874 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
65875 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
65876 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
65877 #define local_inc(l) atomic_long_inc(&(l)->a)
65878 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
65879 #define local_dec(l) atomic_long_dec(&(l)->a)
65880 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
65881 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
65882 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
65883 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
65884 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
65885
65886 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
65887 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
65888 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
65889 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
65890 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
65891 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
65892 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
65893 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
65894 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
65895
65896 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
65897 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
65898 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
65899 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
65900 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
65901 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
65902 index 725612b..9cc513a 100644
65903 --- a/include/asm-generic/pgtable-nopmd.h
65904 +++ b/include/asm-generic/pgtable-nopmd.h
65905 @@ -1,14 +1,19 @@
65906 #ifndef _PGTABLE_NOPMD_H
65907 #define _PGTABLE_NOPMD_H
65908
65909 -#ifndef __ASSEMBLY__
65910 -
65911 #include <asm-generic/pgtable-nopud.h>
65912
65913 -struct mm_struct;
65914 -
65915 #define __PAGETABLE_PMD_FOLDED
65916
65917 +#define PMD_SHIFT PUD_SHIFT
65918 +#define PTRS_PER_PMD 1
65919 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
65920 +#define PMD_MASK (~(PMD_SIZE-1))
65921 +
65922 +#ifndef __ASSEMBLY__
65923 +
65924 +struct mm_struct;
65925 +
65926 /*
65927 * Having the pmd type consist of a pud gets the size right, and allows
65928 * us to conceptually access the pud entry that this pmd is folded into
65929 @@ -16,11 +21,6 @@ struct mm_struct;
65930 */
65931 typedef struct { pud_t pud; } pmd_t;
65932
65933 -#define PMD_SHIFT PUD_SHIFT
65934 -#define PTRS_PER_PMD 1
65935 -#define PMD_SIZE (1UL << PMD_SHIFT)
65936 -#define PMD_MASK (~(PMD_SIZE-1))
65937 -
65938 /*
65939 * The "pud_xxx()" functions here are trivial for a folded two-level
65940 * setup: the pmd is never bad, and a pmd always exists (as it's folded
65941 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
65942 index 810431d..0ec4804f 100644
65943 --- a/include/asm-generic/pgtable-nopud.h
65944 +++ b/include/asm-generic/pgtable-nopud.h
65945 @@ -1,10 +1,15 @@
65946 #ifndef _PGTABLE_NOPUD_H
65947 #define _PGTABLE_NOPUD_H
65948
65949 -#ifndef __ASSEMBLY__
65950 -
65951 #define __PAGETABLE_PUD_FOLDED
65952
65953 +#define PUD_SHIFT PGDIR_SHIFT
65954 +#define PTRS_PER_PUD 1
65955 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
65956 +#define PUD_MASK (~(PUD_SIZE-1))
65957 +
65958 +#ifndef __ASSEMBLY__
65959 +
65960 /*
65961 * Having the pud type consist of a pgd gets the size right, and allows
65962 * us to conceptually access the pgd entry that this pud is folded into
65963 @@ -12,11 +17,6 @@
65964 */
65965 typedef struct { pgd_t pgd; } pud_t;
65966
65967 -#define PUD_SHIFT PGDIR_SHIFT
65968 -#define PTRS_PER_PUD 1
65969 -#define PUD_SIZE (1UL << PUD_SHIFT)
65970 -#define PUD_MASK (~(PUD_SIZE-1))
65971 -
65972 /*
65973 * The "pgd_xxx()" functions here are trivial for a folded two-level
65974 * setup: the pud is never bad, and a pud always exists (as it's folded
65975 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
65976 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
65977
65978 #define pgd_populate(mm, pgd, pud) do { } while (0)
65979 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
65980 /*
65981 * (puds are folded into pgds so this doesn't get actually called,
65982 * but the define is needed for a generic inline function.)
65983 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
65984 index 5cf680a..4b74d62 100644
65985 --- a/include/asm-generic/pgtable.h
65986 +++ b/include/asm-generic/pgtable.h
65987 @@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
65988 }
65989 #endif /* CONFIG_NUMA_BALANCING */
65990
65991 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
65992 +static inline unsigned long pax_open_kernel(void) { return 0; }
65993 +#endif
65994 +
65995 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
65996 +static inline unsigned long pax_close_kernel(void) { return 0; }
65997 +#endif
65998 +
65999 #endif /* CONFIG_MMU */
66000
66001 #endif /* !__ASSEMBLY__ */
66002 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
66003 index d1ea7ce..b1ebf2a 100644
66004 --- a/include/asm-generic/vmlinux.lds.h
66005 +++ b/include/asm-generic/vmlinux.lds.h
66006 @@ -218,6 +218,7 @@
66007 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
66008 VMLINUX_SYMBOL(__start_rodata) = .; \
66009 *(.rodata) *(.rodata.*) \
66010 + *(.data..read_only) \
66011 *(__vermagic) /* Kernel version magic */ \
66012 . = ALIGN(8); \
66013 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
66014 @@ -725,17 +726,18 @@
66015 * section in the linker script will go there too. @phdr should have
66016 * a leading colon.
66017 *
66018 - * Note that this macros defines __per_cpu_load as an absolute symbol.
66019 + * Note that this macros defines per_cpu_load as an absolute symbol.
66020 * If there is no need to put the percpu section at a predetermined
66021 * address, use PERCPU_SECTION.
66022 */
66023 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
66024 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
66025 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
66026 + per_cpu_load = .; \
66027 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
66028 - LOAD_OFFSET) { \
66029 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
66030 PERCPU_INPUT(cacheline) \
66031 } phdr \
66032 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
66033 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
66034
66035 /**
66036 * PERCPU_SECTION - define output section for percpu area, simple version
66037 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
66038 index 418d270..bfd2794 100644
66039 --- a/include/crypto/algapi.h
66040 +++ b/include/crypto/algapi.h
66041 @@ -34,7 +34,7 @@ struct crypto_type {
66042 unsigned int maskclear;
66043 unsigned int maskset;
66044 unsigned int tfmsize;
66045 -};
66046 +} __do_const;
66047
66048 struct crypto_instance {
66049 struct crypto_alg alg;
66050 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
66051 index fad21c9..ab858bc 100644
66052 --- a/include/drm/drmP.h
66053 +++ b/include/drm/drmP.h
66054 @@ -72,6 +72,7 @@
66055 #include <linux/workqueue.h>
66056 #include <linux/poll.h>
66057 #include <asm/pgalloc.h>
66058 +#include <asm/local.h>
66059 #include <drm/drm.h>
66060 #include <drm/drm_sarea.h>
66061
66062 @@ -293,10 +294,12 @@ do { \
66063 * \param cmd command.
66064 * \param arg argument.
66065 */
66066 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
66067 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
66068 + struct drm_file *file_priv);
66069 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
66070 struct drm_file *file_priv);
66071
66072 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66073 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
66074 unsigned long arg);
66075
66076 #define DRM_IOCTL_NR(n) _IOC_NR(n)
66077 @@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66078 struct drm_ioctl_desc {
66079 unsigned int cmd;
66080 int flags;
66081 - drm_ioctl_t *func;
66082 + drm_ioctl_t func;
66083 unsigned int cmd_drv;
66084 -};
66085 +} __do_const;
66086
66087 /**
66088 * Creates a driver or general drm_ioctl_desc array entry for the given
66089 @@ -995,7 +998,7 @@ struct drm_info_list {
66090 int (*show)(struct seq_file*, void*); /** show callback */
66091 u32 driver_features; /**< Required driver features for this entry */
66092 void *data;
66093 -};
66094 +} __do_const;
66095
66096 /**
66097 * debugfs node structure. This structure represents a debugfs file.
66098 @@ -1068,7 +1071,7 @@ struct drm_device {
66099
66100 /** \name Usage Counters */
66101 /*@{ */
66102 - int open_count; /**< Outstanding files open */
66103 + local_t open_count; /**< Outstanding files open */
66104 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
66105 atomic_t vma_count; /**< Outstanding vma areas open */
66106 int buf_use; /**< Buffers in use -- cannot alloc */
66107 @@ -1079,7 +1082,7 @@ struct drm_device {
66108 /*@{ */
66109 unsigned long counters;
66110 enum drm_stat_type types[15];
66111 - atomic_t counts[15];
66112 + atomic_unchecked_t counts[15];
66113 /*@} */
66114
66115 struct list_head filelist;
66116 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
66117 index f43d556..94d9343 100644
66118 --- a/include/drm/drm_crtc_helper.h
66119 +++ b/include/drm/drm_crtc_helper.h
66120 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
66121 struct drm_connector *connector);
66122 /* disable encoder when not in use - more explicit than dpms off */
66123 void (*disable)(struct drm_encoder *encoder);
66124 -};
66125 +} __no_const;
66126
66127 /**
66128 * drm_connector_helper_funcs - helper operations for connectors
66129 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
66130 index 72dcbe8..8db58d7 100644
66131 --- a/include/drm/ttm/ttm_memory.h
66132 +++ b/include/drm/ttm/ttm_memory.h
66133 @@ -48,7 +48,7 @@
66134
66135 struct ttm_mem_shrink {
66136 int (*do_shrink) (struct ttm_mem_shrink *);
66137 -};
66138 +} __no_const;
66139
66140 /**
66141 * struct ttm_mem_global - Global memory accounting structure.
66142 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
66143 index 4b840e8..155d235 100644
66144 --- a/include/keys/asymmetric-subtype.h
66145 +++ b/include/keys/asymmetric-subtype.h
66146 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
66147 /* Verify the signature on a key of this subtype (optional) */
66148 int (*verify_signature)(const struct key *key,
66149 const struct public_key_signature *sig);
66150 -};
66151 +} __do_const;
66152
66153 /**
66154 * asymmetric_key_subtype - Get the subtype from an asymmetric key
66155 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
66156 index c1da539..1dcec55 100644
66157 --- a/include/linux/atmdev.h
66158 +++ b/include/linux/atmdev.h
66159 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
66160 #endif
66161
66162 struct k_atm_aal_stats {
66163 -#define __HANDLE_ITEM(i) atomic_t i
66164 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
66165 __AAL_STAT_ITEMS
66166 #undef __HANDLE_ITEM
66167 };
66168 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
66169 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
66170 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
66171 struct module *owner;
66172 -};
66173 +} __do_const ;
66174
66175 struct atmphy_ops {
66176 int (*start)(struct atm_dev *dev);
66177 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
66178 index 0530b98..96a8ac0 100644
66179 --- a/include/linux/binfmts.h
66180 +++ b/include/linux/binfmts.h
66181 @@ -73,8 +73,9 @@ struct linux_binfmt {
66182 int (*load_binary)(struct linux_binprm *);
66183 int (*load_shlib)(struct file *);
66184 int (*core_dump)(struct coredump_params *cprm);
66185 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
66186 unsigned long min_coredump; /* minimal dump size */
66187 -};
66188 +} __do_const;
66189
66190 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
66191
66192 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
66193 index f94bc83..62b9cfe 100644
66194 --- a/include/linux/blkdev.h
66195 +++ b/include/linux/blkdev.h
66196 @@ -1498,7 +1498,7 @@ struct block_device_operations {
66197 /* this callback is with swap_lock and sometimes page table lock held */
66198 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
66199 struct module *owner;
66200 -};
66201 +} __do_const;
66202
66203 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
66204 unsigned long);
66205 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
66206 index 7c2e030..b72475d 100644
66207 --- a/include/linux/blktrace_api.h
66208 +++ b/include/linux/blktrace_api.h
66209 @@ -23,7 +23,7 @@ struct blk_trace {
66210 struct dentry *dir;
66211 struct dentry *dropped_file;
66212 struct dentry *msg_file;
66213 - atomic_t dropped;
66214 + atomic_unchecked_t dropped;
66215 };
66216
66217 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
66218 diff --git a/include/linux/cache.h b/include/linux/cache.h
66219 index 4c57065..4307975 100644
66220 --- a/include/linux/cache.h
66221 +++ b/include/linux/cache.h
66222 @@ -16,6 +16,10 @@
66223 #define __read_mostly
66224 #endif
66225
66226 +#ifndef __read_only
66227 +#define __read_only __read_mostly
66228 +#endif
66229 +
66230 #ifndef ____cacheline_aligned
66231 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
66232 #endif
66233 diff --git a/include/linux/capability.h b/include/linux/capability.h
66234 index 98503b7..cc36d18 100644
66235 --- a/include/linux/capability.h
66236 +++ b/include/linux/capability.h
66237 @@ -211,8 +211,13 @@ extern bool capable(int cap);
66238 extern bool ns_capable(struct user_namespace *ns, int cap);
66239 extern bool nsown_capable(int cap);
66240 extern bool inode_capable(const struct inode *inode, int cap);
66241 +extern bool capable_nolog(int cap);
66242 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
66243 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
66244
66245 /* audit system wants to get cap info from files as well */
66246 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
66247
66248 +extern int is_privileged_binary(const struct dentry *dentry);
66249 +
66250 #endif /* !_LINUX_CAPABILITY_H */
66251 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
66252 index 8609d57..86e4d79 100644
66253 --- a/include/linux/cdrom.h
66254 +++ b/include/linux/cdrom.h
66255 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
66256
66257 /* driver specifications */
66258 const int capability; /* capability flags */
66259 - int n_minors; /* number of active minor devices */
66260 /* handle uniform packets for scsi type devices (scsi,atapi) */
66261 int (*generic_packet) (struct cdrom_device_info *,
66262 struct packet_command *);
66263 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
66264 index 42e55de..1cd0e66 100644
66265 --- a/include/linux/cleancache.h
66266 +++ b/include/linux/cleancache.h
66267 @@ -31,7 +31,7 @@ struct cleancache_ops {
66268 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
66269 void (*invalidate_inode)(int, struct cleancache_filekey);
66270 void (*invalidate_fs)(int);
66271 -};
66272 +} __no_const;
66273
66274 extern struct cleancache_ops
66275 cleancache_register_ops(struct cleancache_ops *ops);
66276 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
66277 index 662fd1b..e801992 100644
66278 --- a/include/linux/compiler-gcc4.h
66279 +++ b/include/linux/compiler-gcc4.h
66280 @@ -34,6 +34,21 @@
66281 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
66282
66283 #if __GNUC_MINOR__ >= 5
66284 +
66285 +#ifdef CONSTIFY_PLUGIN
66286 +#define __no_const __attribute__((no_const))
66287 +#define __do_const __attribute__((do_const))
66288 +#endif
66289 +
66290 +#ifdef SIZE_OVERFLOW_PLUGIN
66291 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
66292 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
66293 +#endif
66294 +
66295 +#ifdef LATENT_ENTROPY_PLUGIN
66296 +#define __latent_entropy __attribute__((latent_entropy))
66297 +#endif
66298 +
66299 /*
66300 * Mark a position in code as unreachable. This can be used to
66301 * suppress control flow warnings after asm blocks that transfer
66302 @@ -49,6 +64,11 @@
66303 #define __noclone __attribute__((__noclone__))
66304
66305 #endif
66306 +
66307 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
66308 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
66309 +#define __bos0(ptr) __bos((ptr), 0)
66310 +#define __bos1(ptr) __bos((ptr), 1)
66311 #endif
66312
66313 #if __GNUC_MINOR__ >= 6
66314 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
66315 index dd852b7..72924c0 100644
66316 --- a/include/linux/compiler.h
66317 +++ b/include/linux/compiler.h
66318 @@ -5,11 +5,14 @@
66319
66320 #ifdef __CHECKER__
66321 # define __user __attribute__((noderef, address_space(1)))
66322 +# define __force_user __force __user
66323 # define __kernel __attribute__((address_space(0)))
66324 +# define __force_kernel __force __kernel
66325 # define __safe __attribute__((safe))
66326 # define __force __attribute__((force))
66327 # define __nocast __attribute__((nocast))
66328 # define __iomem __attribute__((noderef, address_space(2)))
66329 +# define __force_iomem __force __iomem
66330 # define __must_hold(x) __attribute__((context(x,1,1)))
66331 # define __acquires(x) __attribute__((context(x,0,1)))
66332 # define __releases(x) __attribute__((context(x,1,0)))
66333 @@ -17,20 +20,48 @@
66334 # define __release(x) __context__(x,-1)
66335 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
66336 # define __percpu __attribute__((noderef, address_space(3)))
66337 +# define __force_percpu __force __percpu
66338 #ifdef CONFIG_SPARSE_RCU_POINTER
66339 # define __rcu __attribute__((noderef, address_space(4)))
66340 +# define __force_rcu __force __rcu
66341 #else
66342 # define __rcu
66343 +# define __force_rcu
66344 #endif
66345 extern void __chk_user_ptr(const volatile void __user *);
66346 extern void __chk_io_ptr(const volatile void __iomem *);
66347 +#elif defined(CHECKER_PLUGIN)
66348 +//# define __user
66349 +//# define __force_user
66350 +//# define __kernel
66351 +//# define __force_kernel
66352 +# define __safe
66353 +# define __force
66354 +# define __nocast
66355 +# define __iomem
66356 +# define __force_iomem
66357 +# define __chk_user_ptr(x) (void)0
66358 +# define __chk_io_ptr(x) (void)0
66359 +# define __builtin_warning(x, y...) (1)
66360 +# define __acquires(x)
66361 +# define __releases(x)
66362 +# define __acquire(x) (void)0
66363 +# define __release(x) (void)0
66364 +# define __cond_lock(x,c) (c)
66365 +# define __percpu
66366 +# define __force_percpu
66367 +# define __rcu
66368 +# define __force_rcu
66369 #else
66370 # define __user
66371 +# define __force_user
66372 # define __kernel
66373 +# define __force_kernel
66374 # define __safe
66375 # define __force
66376 # define __nocast
66377 # define __iomem
66378 +# define __force_iomem
66379 # define __chk_user_ptr(x) (void)0
66380 # define __chk_io_ptr(x) (void)0
66381 # define __builtin_warning(x, y...) (1)
66382 @@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
66383 # define __release(x) (void)0
66384 # define __cond_lock(x,c) (c)
66385 # define __percpu
66386 +# define __force_percpu
66387 # define __rcu
66388 +# define __force_rcu
66389 #endif
66390
66391 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
66392 @@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66393 # define __attribute_const__ /* unimplemented */
66394 #endif
66395
66396 +#ifndef __no_const
66397 +# define __no_const
66398 +#endif
66399 +
66400 +#ifndef __do_const
66401 +# define __do_const
66402 +#endif
66403 +
66404 +#ifndef __size_overflow
66405 +# define __size_overflow(...)
66406 +#endif
66407 +
66408 +#ifndef __intentional_overflow
66409 +# define __intentional_overflow(...)
66410 +#endif
66411 +
66412 +#ifndef __latent_entropy
66413 +# define __latent_entropy
66414 +#endif
66415 +
66416 /*
66417 * Tell gcc if a function is cold. The compiler will assume any path
66418 * directly leading to the call is unlikely.
66419 @@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66420 #define __cold
66421 #endif
66422
66423 +#ifndef __alloc_size
66424 +#define __alloc_size(...)
66425 +#endif
66426 +
66427 +#ifndef __bos
66428 +#define __bos(ptr, arg)
66429 +#endif
66430 +
66431 +#ifndef __bos0
66432 +#define __bos0(ptr)
66433 +#endif
66434 +
66435 +#ifndef __bos1
66436 +#define __bos1(ptr)
66437 +#endif
66438 +
66439 /* Simple shorthand for a section definition */
66440 #ifndef __section
66441 # define __section(S) __attribute__ ((__section__(#S)))
66442 @@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66443 * use is to mediate communication between process-level code and irq/NMI
66444 * handlers, all running on the same CPU.
66445 */
66446 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
66447 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
66448 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
66449
66450 #endif /* __LINUX_COMPILER_H */
66451 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
66452 index 34025df..d94bbbc 100644
66453 --- a/include/linux/configfs.h
66454 +++ b/include/linux/configfs.h
66455 @@ -125,7 +125,7 @@ struct configfs_attribute {
66456 const char *ca_name;
66457 struct module *ca_owner;
66458 umode_t ca_mode;
66459 -};
66460 +} __do_const;
66461
66462 /*
66463 * Users often need to create attribute structures for their configurable
66464 diff --git a/include/linux/cpu.h b/include/linux/cpu.h
66465 index ce7a074..01ab8ac 100644
66466 --- a/include/linux/cpu.h
66467 +++ b/include/linux/cpu.h
66468 @@ -115,7 +115,7 @@ enum {
66469 /* Need to know about CPUs going up/down? */
66470 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
66471 #define cpu_notifier(fn, pri) { \
66472 - static struct notifier_block fn##_nb __cpuinitdata = \
66473 + static struct notifier_block fn##_nb = \
66474 { .notifier_call = fn, .priority = pri }; \
66475 register_cpu_notifier(&fn##_nb); \
66476 }
66477 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
66478 index a55b88e..fba90c5 100644
66479 --- a/include/linux/cpufreq.h
66480 +++ b/include/linux/cpufreq.h
66481 @@ -240,7 +240,7 @@ struct cpufreq_driver {
66482 int (*suspend) (struct cpufreq_policy *policy);
66483 int (*resume) (struct cpufreq_policy *policy);
66484 struct freq_attr **attr;
66485 -};
66486 +} __do_const;
66487
66488 /* flags */
66489
66490 @@ -299,6 +299,7 @@ struct global_attr {
66491 ssize_t (*store)(struct kobject *a, struct attribute *b,
66492 const char *c, size_t count);
66493 };
66494 +typedef struct global_attr __no_const global_attr_no_const;
66495
66496 #define define_one_global_ro(_name) \
66497 static struct global_attr _name = \
66498 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
66499 index 24cd1037..20a63aae 100644
66500 --- a/include/linux/cpuidle.h
66501 +++ b/include/linux/cpuidle.h
66502 @@ -54,7 +54,8 @@ struct cpuidle_state {
66503 int index);
66504
66505 int (*enter_dead) (struct cpuidle_device *dev, int index);
66506 -};
66507 +} __do_const;
66508 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
66509
66510 /* Idle State Flags */
66511 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
66512 @@ -216,7 +217,7 @@ struct cpuidle_governor {
66513 void (*reflect) (struct cpuidle_device *dev, int index);
66514
66515 struct module *owner;
66516 -};
66517 +} __do_const;
66518
66519 #ifdef CONFIG_CPU_IDLE
66520
66521 diff --git a/include/linux/cred.h b/include/linux/cred.h
66522 index 04421e8..6bce4ef 100644
66523 --- a/include/linux/cred.h
66524 +++ b/include/linux/cred.h
66525 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
66526 static inline void validate_process_creds(void)
66527 {
66528 }
66529 +static inline void validate_task_creds(struct task_struct *task)
66530 +{
66531 +}
66532 #endif
66533
66534 /**
66535 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
66536 index b92eadf..b4ecdc1 100644
66537 --- a/include/linux/crypto.h
66538 +++ b/include/linux/crypto.h
66539 @@ -373,7 +373,7 @@ struct cipher_tfm {
66540 const u8 *key, unsigned int keylen);
66541 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
66542 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
66543 -};
66544 +} __no_const;
66545
66546 struct hash_tfm {
66547 int (*init)(struct hash_desc *desc);
66548 @@ -394,13 +394,13 @@ struct compress_tfm {
66549 int (*cot_decompress)(struct crypto_tfm *tfm,
66550 const u8 *src, unsigned int slen,
66551 u8 *dst, unsigned int *dlen);
66552 -};
66553 +} __no_const;
66554
66555 struct rng_tfm {
66556 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
66557 unsigned int dlen);
66558 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
66559 -};
66560 +} __no_const;
66561
66562 #define crt_ablkcipher crt_u.ablkcipher
66563 #define crt_aead crt_u.aead
66564 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
66565 index 7925bf0..d5143d2 100644
66566 --- a/include/linux/decompress/mm.h
66567 +++ b/include/linux/decompress/mm.h
66568 @@ -77,7 +77,7 @@ static void free(void *where)
66569 * warnings when not needed (indeed large_malloc / large_free are not
66570 * needed by inflate */
66571
66572 -#define malloc(a) kmalloc(a, GFP_KERNEL)
66573 +#define malloc(a) kmalloc((a), GFP_KERNEL)
66574 #define free(a) kfree(a)
66575
66576 #define large_malloc(a) vmalloc(a)
66577 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
66578 index e83ef39..33e0eb3 100644
66579 --- a/include/linux/devfreq.h
66580 +++ b/include/linux/devfreq.h
66581 @@ -114,7 +114,7 @@ struct devfreq_governor {
66582 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
66583 int (*event_handler)(struct devfreq *devfreq,
66584 unsigned int event, void *data);
66585 -};
66586 +} __do_const;
66587
66588 /**
66589 * struct devfreq - Device devfreq structure
66590 diff --git a/include/linux/device.h b/include/linux/device.h
66591 index 43dcda9..7a1fb65 100644
66592 --- a/include/linux/device.h
66593 +++ b/include/linux/device.h
66594 @@ -294,7 +294,7 @@ struct subsys_interface {
66595 struct list_head node;
66596 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
66597 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
66598 -};
66599 +} __do_const;
66600
66601 int subsys_interface_register(struct subsys_interface *sif);
66602 void subsys_interface_unregister(struct subsys_interface *sif);
66603 @@ -474,7 +474,7 @@ struct device_type {
66604 void (*release)(struct device *dev);
66605
66606 const struct dev_pm_ops *pm;
66607 -};
66608 +} __do_const;
66609
66610 /* interface for exporting device attributes */
66611 struct device_attribute {
66612 @@ -484,11 +484,12 @@ struct device_attribute {
66613 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
66614 const char *buf, size_t count);
66615 };
66616 +typedef struct device_attribute __no_const device_attribute_no_const;
66617
66618 struct dev_ext_attribute {
66619 struct device_attribute attr;
66620 void *var;
66621 -};
66622 +} __do_const;
66623
66624 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
66625 char *buf);
66626 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
66627 index 94af418..b1ca7a2 100644
66628 --- a/include/linux/dma-mapping.h
66629 +++ b/include/linux/dma-mapping.h
66630 @@ -54,7 +54,7 @@ struct dma_map_ops {
66631 u64 (*get_required_mask)(struct device *dev);
66632 #endif
66633 int is_phys;
66634 -};
66635 +} __do_const;
66636
66637 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
66638
66639 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
66640 index d3201e4..8281e63 100644
66641 --- a/include/linux/dmaengine.h
66642 +++ b/include/linux/dmaengine.h
66643 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
66644 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
66645 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
66646
66647 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
66648 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
66649 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
66650 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
66651 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
66652 struct dma_pinned_list *pinned_list, struct page *page,
66653 unsigned int offset, size_t len);
66654
66655 diff --git a/include/linux/efi.h b/include/linux/efi.h
66656 index 7a9498a..155713d 100644
66657 --- a/include/linux/efi.h
66658 +++ b/include/linux/efi.h
66659 @@ -733,6 +733,7 @@ struct efivar_operations {
66660 efi_set_variable_t *set_variable;
66661 efi_query_variable_info_t *query_variable_info;
66662 };
66663 +typedef struct efivar_operations __no_const efivar_operations_no_const;
66664
66665 struct efivars {
66666 /*
66667 diff --git a/include/linux/elf.h b/include/linux/elf.h
66668 index 8c9048e..16a4665 100644
66669 --- a/include/linux/elf.h
66670 +++ b/include/linux/elf.h
66671 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
66672 #define elf_note elf32_note
66673 #define elf_addr_t Elf32_Off
66674 #define Elf_Half Elf32_Half
66675 +#define elf_dyn Elf32_Dyn
66676
66677 #else
66678
66679 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
66680 #define elf_note elf64_note
66681 #define elf_addr_t Elf64_Off
66682 #define Elf_Half Elf64_Half
66683 +#define elf_dyn Elf64_Dyn
66684
66685 #endif
66686
66687 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
66688 index fcb51c8..bdafcf6 100644
66689 --- a/include/linux/extcon.h
66690 +++ b/include/linux/extcon.h
66691 @@ -134,7 +134,7 @@ struct extcon_dev {
66692 /* /sys/class/extcon/.../mutually_exclusive/... */
66693 struct attribute_group attr_g_muex;
66694 struct attribute **attrs_muex;
66695 - struct device_attribute *d_attrs_muex;
66696 + device_attribute_no_const *d_attrs_muex;
66697 };
66698
66699 /**
66700 diff --git a/include/linux/fb.h b/include/linux/fb.h
66701 index c7a9571..02eeffe 100644
66702 --- a/include/linux/fb.h
66703 +++ b/include/linux/fb.h
66704 @@ -302,7 +302,7 @@ struct fb_ops {
66705 /* called at KDB enter and leave time to prepare the console */
66706 int (*fb_debug_enter)(struct fb_info *info);
66707 int (*fb_debug_leave)(struct fb_info *info);
66708 -};
66709 +} __do_const;
66710
66711 #ifdef CONFIG_FB_TILEBLITTING
66712 #define FB_TILE_CURSOR_NONE 0
66713 diff --git a/include/linux/filter.h b/include/linux/filter.h
66714 index c45eabc..baa0be5 100644
66715 --- a/include/linux/filter.h
66716 +++ b/include/linux/filter.h
66717 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
66718
66719 struct sk_buff;
66720 struct sock;
66721 +struct bpf_jit_work;
66722
66723 struct sk_filter
66724 {
66725 @@ -27,6 +28,9 @@ struct sk_filter
66726 unsigned int len; /* Number of filter blocks */
66727 unsigned int (*bpf_func)(const struct sk_buff *skb,
66728 const struct sock_filter *filter);
66729 +#ifdef CONFIG_BPF_JIT
66730 + struct bpf_jit_work *work;
66731 +#endif
66732 struct rcu_head rcu;
66733 struct sock_filter insns[0];
66734 };
66735 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
66736 index 3044254..9767f41 100644
66737 --- a/include/linux/frontswap.h
66738 +++ b/include/linux/frontswap.h
66739 @@ -11,7 +11,7 @@ struct frontswap_ops {
66740 int (*load)(unsigned, pgoff_t, struct page *);
66741 void (*invalidate_page)(unsigned, pgoff_t);
66742 void (*invalidate_area)(unsigned);
66743 -};
66744 +} __no_const;
66745
66746 extern bool frontswap_enabled;
66747 extern struct frontswap_ops
66748 diff --git a/include/linux/fs.h b/include/linux/fs.h
66749 index 7617ee0..b575199 100644
66750 --- a/include/linux/fs.h
66751 +++ b/include/linux/fs.h
66752 @@ -1541,7 +1541,8 @@ struct file_operations {
66753 long (*fallocate)(struct file *file, int mode, loff_t offset,
66754 loff_t len);
66755 int (*show_fdinfo)(struct seq_file *m, struct file *f);
66756 -};
66757 +} __do_const;
66758 +typedef struct file_operations __no_const file_operations_no_const;
66759
66760 struct inode_operations {
66761 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
66762 @@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
66763 inode->i_flags |= S_NOSEC;
66764 }
66765
66766 +static inline bool is_sidechannel_device(const struct inode *inode)
66767 +{
66768 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
66769 + umode_t mode = inode->i_mode;
66770 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
66771 +#else
66772 + return false;
66773 +#endif
66774 +}
66775 +
66776 #endif /* _LINUX_FS_H */
66777 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
66778 index d0ae3a8..0244b34 100644
66779 --- a/include/linux/fs_struct.h
66780 +++ b/include/linux/fs_struct.h
66781 @@ -6,7 +6,7 @@
66782 #include <linux/seqlock.h>
66783
66784 struct fs_struct {
66785 - int users;
66786 + atomic_t users;
66787 spinlock_t lock;
66788 seqcount_t seq;
66789 int umask;
66790 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
66791 index 5dfa0aa..6acf322 100644
66792 --- a/include/linux/fscache-cache.h
66793 +++ b/include/linux/fscache-cache.h
66794 @@ -112,7 +112,7 @@ struct fscache_operation {
66795 fscache_operation_release_t release;
66796 };
66797
66798 -extern atomic_t fscache_op_debug_id;
66799 +extern atomic_unchecked_t fscache_op_debug_id;
66800 extern void fscache_op_work_func(struct work_struct *work);
66801
66802 extern void fscache_enqueue_operation(struct fscache_operation *);
66803 @@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
66804 INIT_WORK(&op->work, fscache_op_work_func);
66805 atomic_set(&op->usage, 1);
66806 op->state = FSCACHE_OP_ST_INITIALISED;
66807 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
66808 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
66809 op->processor = processor;
66810 op->release = release;
66811 INIT_LIST_HEAD(&op->pend_link);
66812 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
66813 index 7a08623..4c07b0f 100644
66814 --- a/include/linux/fscache.h
66815 +++ b/include/linux/fscache.h
66816 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
66817 * - this is mandatory for any object that may have data
66818 */
66819 void (*now_uncached)(void *cookie_netfs_data);
66820 -};
66821 +} __do_const;
66822
66823 /*
66824 * fscache cached network filesystem type
66825 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
66826 index 0fbfb46..508eb0d 100644
66827 --- a/include/linux/fsnotify.h
66828 +++ b/include/linux/fsnotify.h
66829 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
66830 struct inode *inode = path->dentry->d_inode;
66831 __u32 mask = FS_ACCESS;
66832
66833 + if (is_sidechannel_device(inode))
66834 + return;
66835 +
66836 if (S_ISDIR(inode->i_mode))
66837 mask |= FS_ISDIR;
66838
66839 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
66840 struct inode *inode = path->dentry->d_inode;
66841 __u32 mask = FS_MODIFY;
66842
66843 + if (is_sidechannel_device(inode))
66844 + return;
66845 +
66846 if (S_ISDIR(inode->i_mode))
66847 mask |= FS_ISDIR;
66848
66849 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
66850 */
66851 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
66852 {
66853 - return kstrdup(name, GFP_KERNEL);
66854 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
66855 }
66856
66857 /*
66858 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
66859 index a3d4895..ddd2a50 100644
66860 --- a/include/linux/ftrace_event.h
66861 +++ b/include/linux/ftrace_event.h
66862 @@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
66863 extern int trace_add_event_call(struct ftrace_event_call *call);
66864 extern void trace_remove_event_call(struct ftrace_event_call *call);
66865
66866 -#define is_signed_type(type) (((type)(-1)) < 0)
66867 +#define is_signed_type(type) (((type)(-1)) < (type)1)
66868
66869 int trace_set_clr_event(const char *system, const char *event, int set);
66870
66871 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
66872 index 79b8bba..86b539e 100644
66873 --- a/include/linux/genhd.h
66874 +++ b/include/linux/genhd.h
66875 @@ -194,7 +194,7 @@ struct gendisk {
66876 struct kobject *slave_dir;
66877
66878 struct timer_rand_state *random;
66879 - atomic_t sync_io; /* RAID */
66880 + atomic_unchecked_t sync_io; /* RAID */
66881 struct disk_events *ev;
66882 #ifdef CONFIG_BLK_DEV_INTEGRITY
66883 struct blk_integrity *integrity;
66884 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
66885 index 023bc34..b02b46a 100644
66886 --- a/include/linux/genl_magic_func.h
66887 +++ b/include/linux/genl_magic_func.h
66888 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
66889 },
66890
66891 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
66892 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
66893 +static struct genl_ops ZZZ_genl_ops[] = {
66894 #include GENL_MAGIC_INCLUDE_FILE
66895 };
66896
66897 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
66898 index 0f615eb..5c3832f 100644
66899 --- a/include/linux/gfp.h
66900 +++ b/include/linux/gfp.h
66901 @@ -35,6 +35,13 @@ struct vm_area_struct;
66902 #define ___GFP_NO_KSWAPD 0x400000u
66903 #define ___GFP_OTHER_NODE 0x800000u
66904 #define ___GFP_WRITE 0x1000000u
66905 +
66906 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66907 +#define ___GFP_USERCOPY 0x2000000u
66908 +#else
66909 +#define ___GFP_USERCOPY 0
66910 +#endif
66911 +
66912 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
66913
66914 /*
66915 @@ -92,6 +99,7 @@ struct vm_area_struct;
66916 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
66917 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
66918 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
66919 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
66920
66921 /*
66922 * This may seem redundant, but it's a way of annotating false positives vs.
66923 @@ -99,7 +107,7 @@ struct vm_area_struct;
66924 */
66925 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
66926
66927 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
66928 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
66929 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
66930
66931 /* This equals 0, but use constants in case they ever change */
66932 @@ -153,6 +161,8 @@ struct vm_area_struct;
66933 /* 4GB DMA on some platforms */
66934 #define GFP_DMA32 __GFP_DMA32
66935
66936 +#define GFP_USERCOPY __GFP_USERCOPY
66937 +
66938 /* Convert GFP flags to their corresponding migrate type */
66939 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
66940 {
66941 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
66942 new file mode 100644
66943 index 0000000..ebe6d72
66944 --- /dev/null
66945 +++ b/include/linux/gracl.h
66946 @@ -0,0 +1,319 @@
66947 +#ifndef GR_ACL_H
66948 +#define GR_ACL_H
66949 +
66950 +#include <linux/grdefs.h>
66951 +#include <linux/resource.h>
66952 +#include <linux/capability.h>
66953 +#include <linux/dcache.h>
66954 +#include <asm/resource.h>
66955 +
66956 +/* Major status information */
66957 +
66958 +#define GR_VERSION "grsecurity 2.9.1"
66959 +#define GRSECURITY_VERSION 0x2901
66960 +
66961 +enum {
66962 + GR_SHUTDOWN = 0,
66963 + GR_ENABLE = 1,
66964 + GR_SPROLE = 2,
66965 + GR_RELOAD = 3,
66966 + GR_SEGVMOD = 4,
66967 + GR_STATUS = 5,
66968 + GR_UNSPROLE = 6,
66969 + GR_PASSSET = 7,
66970 + GR_SPROLEPAM = 8,
66971 +};
66972 +
66973 +/* Password setup definitions
66974 + * kernel/grhash.c */
66975 +enum {
66976 + GR_PW_LEN = 128,
66977 + GR_SALT_LEN = 16,
66978 + GR_SHA_LEN = 32,
66979 +};
66980 +
66981 +enum {
66982 + GR_SPROLE_LEN = 64,
66983 +};
66984 +
66985 +enum {
66986 + GR_NO_GLOB = 0,
66987 + GR_REG_GLOB,
66988 + GR_CREATE_GLOB
66989 +};
66990 +
66991 +#define GR_NLIMITS 32
66992 +
66993 +/* Begin Data Structures */
66994 +
66995 +struct sprole_pw {
66996 + unsigned char *rolename;
66997 + unsigned char salt[GR_SALT_LEN];
66998 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
66999 +};
67000 +
67001 +struct name_entry {
67002 + __u32 key;
67003 + ino_t inode;
67004 + dev_t device;
67005 + char *name;
67006 + __u16 len;
67007 + __u8 deleted;
67008 + struct name_entry *prev;
67009 + struct name_entry *next;
67010 +};
67011 +
67012 +struct inodev_entry {
67013 + struct name_entry *nentry;
67014 + struct inodev_entry *prev;
67015 + struct inodev_entry *next;
67016 +};
67017 +
67018 +struct acl_role_db {
67019 + struct acl_role_label **r_hash;
67020 + __u32 r_size;
67021 +};
67022 +
67023 +struct inodev_db {
67024 + struct inodev_entry **i_hash;
67025 + __u32 i_size;
67026 +};
67027 +
67028 +struct name_db {
67029 + struct name_entry **n_hash;
67030 + __u32 n_size;
67031 +};
67032 +
67033 +struct crash_uid {
67034 + uid_t uid;
67035 + unsigned long expires;
67036 +};
67037 +
67038 +struct gr_hash_struct {
67039 + void **table;
67040 + void **nametable;
67041 + void *first;
67042 + __u32 table_size;
67043 + __u32 used_size;
67044 + int type;
67045 +};
67046 +
67047 +/* Userspace Grsecurity ACL data structures */
67048 +
67049 +struct acl_subject_label {
67050 + char *filename;
67051 + ino_t inode;
67052 + dev_t device;
67053 + __u32 mode;
67054 + kernel_cap_t cap_mask;
67055 + kernel_cap_t cap_lower;
67056 + kernel_cap_t cap_invert_audit;
67057 +
67058 + struct rlimit res[GR_NLIMITS];
67059 + __u32 resmask;
67060 +
67061 + __u8 user_trans_type;
67062 + __u8 group_trans_type;
67063 + uid_t *user_transitions;
67064 + gid_t *group_transitions;
67065 + __u16 user_trans_num;
67066 + __u16 group_trans_num;
67067 +
67068 + __u32 sock_families[2];
67069 + __u32 ip_proto[8];
67070 + __u32 ip_type;
67071 + struct acl_ip_label **ips;
67072 + __u32 ip_num;
67073 + __u32 inaddr_any_override;
67074 +
67075 + __u32 crashes;
67076 + unsigned long expires;
67077 +
67078 + struct acl_subject_label *parent_subject;
67079 + struct gr_hash_struct *hash;
67080 + struct acl_subject_label *prev;
67081 + struct acl_subject_label *next;
67082 +
67083 + struct acl_object_label **obj_hash;
67084 + __u32 obj_hash_size;
67085 + __u16 pax_flags;
67086 +};
67087 +
67088 +struct role_allowed_ip {
67089 + __u32 addr;
67090 + __u32 netmask;
67091 +
67092 + struct role_allowed_ip *prev;
67093 + struct role_allowed_ip *next;
67094 +};
67095 +
67096 +struct role_transition {
67097 + char *rolename;
67098 +
67099 + struct role_transition *prev;
67100 + struct role_transition *next;
67101 +};
67102 +
67103 +struct acl_role_label {
67104 + char *rolename;
67105 + uid_t uidgid;
67106 + __u16 roletype;
67107 +
67108 + __u16 auth_attempts;
67109 + unsigned long expires;
67110 +
67111 + struct acl_subject_label *root_label;
67112 + struct gr_hash_struct *hash;
67113 +
67114 + struct acl_role_label *prev;
67115 + struct acl_role_label *next;
67116 +
67117 + struct role_transition *transitions;
67118 + struct role_allowed_ip *allowed_ips;
67119 + uid_t *domain_children;
67120 + __u16 domain_child_num;
67121 +
67122 + umode_t umask;
67123 +
67124 + struct acl_subject_label **subj_hash;
67125 + __u32 subj_hash_size;
67126 +};
67127 +
67128 +struct user_acl_role_db {
67129 + struct acl_role_label **r_table;
67130 + __u32 num_pointers; /* Number of allocations to track */
67131 + __u32 num_roles; /* Number of roles */
67132 + __u32 num_domain_children; /* Number of domain children */
67133 + __u32 num_subjects; /* Number of subjects */
67134 + __u32 num_objects; /* Number of objects */
67135 +};
67136 +
67137 +struct acl_object_label {
67138 + char *filename;
67139 + ino_t inode;
67140 + dev_t device;
67141 + __u32 mode;
67142 +
67143 + struct acl_subject_label *nested;
67144 + struct acl_object_label *globbed;
67145 +
67146 + /* next two structures not used */
67147 +
67148 + struct acl_object_label *prev;
67149 + struct acl_object_label *next;
67150 +};
67151 +
67152 +struct acl_ip_label {
67153 + char *iface;
67154 + __u32 addr;
67155 + __u32 netmask;
67156 + __u16 low, high;
67157 + __u8 mode;
67158 + __u32 type;
67159 + __u32 proto[8];
67160 +
67161 + /* next two structures not used */
67162 +
67163 + struct acl_ip_label *prev;
67164 + struct acl_ip_label *next;
67165 +};
67166 +
67167 +struct gr_arg {
67168 + struct user_acl_role_db role_db;
67169 + unsigned char pw[GR_PW_LEN];
67170 + unsigned char salt[GR_SALT_LEN];
67171 + unsigned char sum[GR_SHA_LEN];
67172 + unsigned char sp_role[GR_SPROLE_LEN];
67173 + struct sprole_pw *sprole_pws;
67174 + dev_t segv_device;
67175 + ino_t segv_inode;
67176 + uid_t segv_uid;
67177 + __u16 num_sprole_pws;
67178 + __u16 mode;
67179 +};
67180 +
67181 +struct gr_arg_wrapper {
67182 + struct gr_arg *arg;
67183 + __u32 version;
67184 + __u32 size;
67185 +};
67186 +
67187 +struct subject_map {
67188 + struct acl_subject_label *user;
67189 + struct acl_subject_label *kernel;
67190 + struct subject_map *prev;
67191 + struct subject_map *next;
67192 +};
67193 +
67194 +struct acl_subj_map_db {
67195 + struct subject_map **s_hash;
67196 + __u32 s_size;
67197 +};
67198 +
67199 +/* End Data Structures Section */
67200 +
67201 +/* Hash functions generated by empirical testing by Brad Spengler
67202 + Makes good use of the low bits of the inode. Generally 0-1 times
67203 + in loop for successful match. 0-3 for unsuccessful match.
67204 + Shift/add algorithm with modulus of table size and an XOR*/
67205 +
67206 +static __inline__ unsigned int
67207 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
67208 +{
67209 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
67210 +}
67211 +
67212 + static __inline__ unsigned int
67213 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
67214 +{
67215 + return ((const unsigned long)userp % sz);
67216 +}
67217 +
67218 +static __inline__ unsigned int
67219 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
67220 +{
67221 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
67222 +}
67223 +
67224 +static __inline__ unsigned int
67225 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
67226 +{
67227 + return full_name_hash((const unsigned char *)name, len) % sz;
67228 +}
67229 +
67230 +#define FOR_EACH_ROLE_START(role) \
67231 + role = role_list; \
67232 + while (role) {
67233 +
67234 +#define FOR_EACH_ROLE_END(role) \
67235 + role = role->prev; \
67236 + }
67237 +
67238 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
67239 + subj = NULL; \
67240 + iter = 0; \
67241 + while (iter < role->subj_hash_size) { \
67242 + if (subj == NULL) \
67243 + subj = role->subj_hash[iter]; \
67244 + if (subj == NULL) { \
67245 + iter++; \
67246 + continue; \
67247 + }
67248 +
67249 +#define FOR_EACH_SUBJECT_END(subj,iter) \
67250 + subj = subj->next; \
67251 + if (subj == NULL) \
67252 + iter++; \
67253 + }
67254 +
67255 +
67256 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
67257 + subj = role->hash->first; \
67258 + while (subj != NULL) {
67259 +
67260 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
67261 + subj = subj->next; \
67262 + }
67263 +
67264 +#endif
67265 +
67266 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
67267 new file mode 100644
67268 index 0000000..323ecf2
67269 --- /dev/null
67270 +++ b/include/linux/gralloc.h
67271 @@ -0,0 +1,9 @@
67272 +#ifndef __GRALLOC_H
67273 +#define __GRALLOC_H
67274 +
67275 +void acl_free_all(void);
67276 +int acl_alloc_stack_init(unsigned long size);
67277 +void *acl_alloc(unsigned long len);
67278 +void *acl_alloc_num(unsigned long num, unsigned long len);
67279 +
67280 +#endif
67281 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
67282 new file mode 100644
67283 index 0000000..be66033
67284 --- /dev/null
67285 +++ b/include/linux/grdefs.h
67286 @@ -0,0 +1,140 @@
67287 +#ifndef GRDEFS_H
67288 +#define GRDEFS_H
67289 +
67290 +/* Begin grsecurity status declarations */
67291 +
67292 +enum {
67293 + GR_READY = 0x01,
67294 + GR_STATUS_INIT = 0x00 // disabled state
67295 +};
67296 +
67297 +/* Begin ACL declarations */
67298 +
67299 +/* Role flags */
67300 +
67301 +enum {
67302 + GR_ROLE_USER = 0x0001,
67303 + GR_ROLE_GROUP = 0x0002,
67304 + GR_ROLE_DEFAULT = 0x0004,
67305 + GR_ROLE_SPECIAL = 0x0008,
67306 + GR_ROLE_AUTH = 0x0010,
67307 + GR_ROLE_NOPW = 0x0020,
67308 + GR_ROLE_GOD = 0x0040,
67309 + GR_ROLE_LEARN = 0x0080,
67310 + GR_ROLE_TPE = 0x0100,
67311 + GR_ROLE_DOMAIN = 0x0200,
67312 + GR_ROLE_PAM = 0x0400,
67313 + GR_ROLE_PERSIST = 0x0800
67314 +};
67315 +
67316 +/* ACL Subject and Object mode flags */
67317 +enum {
67318 + GR_DELETED = 0x80000000
67319 +};
67320 +
67321 +/* ACL Object-only mode flags */
67322 +enum {
67323 + GR_READ = 0x00000001,
67324 + GR_APPEND = 0x00000002,
67325 + GR_WRITE = 0x00000004,
67326 + GR_EXEC = 0x00000008,
67327 + GR_FIND = 0x00000010,
67328 + GR_INHERIT = 0x00000020,
67329 + GR_SETID = 0x00000040,
67330 + GR_CREATE = 0x00000080,
67331 + GR_DELETE = 0x00000100,
67332 + GR_LINK = 0x00000200,
67333 + GR_AUDIT_READ = 0x00000400,
67334 + GR_AUDIT_APPEND = 0x00000800,
67335 + GR_AUDIT_WRITE = 0x00001000,
67336 + GR_AUDIT_EXEC = 0x00002000,
67337 + GR_AUDIT_FIND = 0x00004000,
67338 + GR_AUDIT_INHERIT= 0x00008000,
67339 + GR_AUDIT_SETID = 0x00010000,
67340 + GR_AUDIT_CREATE = 0x00020000,
67341 + GR_AUDIT_DELETE = 0x00040000,
67342 + GR_AUDIT_LINK = 0x00080000,
67343 + GR_PTRACERD = 0x00100000,
67344 + GR_NOPTRACE = 0x00200000,
67345 + GR_SUPPRESS = 0x00400000,
67346 + GR_NOLEARN = 0x00800000,
67347 + GR_INIT_TRANSFER= 0x01000000
67348 +};
67349 +
67350 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
67351 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
67352 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
67353 +
67354 +/* ACL subject-only mode flags */
67355 +enum {
67356 + GR_KILL = 0x00000001,
67357 + GR_VIEW = 0x00000002,
67358 + GR_PROTECTED = 0x00000004,
67359 + GR_LEARN = 0x00000008,
67360 + GR_OVERRIDE = 0x00000010,
67361 + /* just a placeholder, this mode is only used in userspace */
67362 + GR_DUMMY = 0x00000020,
67363 + GR_PROTSHM = 0x00000040,
67364 + GR_KILLPROC = 0x00000080,
67365 + GR_KILLIPPROC = 0x00000100,
67366 + /* just a placeholder, this mode is only used in userspace */
67367 + GR_NOTROJAN = 0x00000200,
67368 + GR_PROTPROCFD = 0x00000400,
67369 + GR_PROCACCT = 0x00000800,
67370 + GR_RELAXPTRACE = 0x00001000,
67371 + //GR_NESTED = 0x00002000,
67372 + GR_INHERITLEARN = 0x00004000,
67373 + GR_PROCFIND = 0x00008000,
67374 + GR_POVERRIDE = 0x00010000,
67375 + GR_KERNELAUTH = 0x00020000,
67376 + GR_ATSECURE = 0x00040000,
67377 + GR_SHMEXEC = 0x00080000
67378 +};
67379 +
67380 +enum {
67381 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
67382 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
67383 + GR_PAX_ENABLE_MPROTECT = 0x0004,
67384 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
67385 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
67386 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
67387 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
67388 + GR_PAX_DISABLE_MPROTECT = 0x0400,
67389 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
67390 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
67391 +};
67392 +
67393 +enum {
67394 + GR_ID_USER = 0x01,
67395 + GR_ID_GROUP = 0x02,
67396 +};
67397 +
67398 +enum {
67399 + GR_ID_ALLOW = 0x01,
67400 + GR_ID_DENY = 0x02,
67401 +};
67402 +
67403 +#define GR_CRASH_RES 31
67404 +#define GR_UIDTABLE_MAX 500
67405 +
67406 +/* begin resource learning section */
67407 +enum {
67408 + GR_RLIM_CPU_BUMP = 60,
67409 + GR_RLIM_FSIZE_BUMP = 50000,
67410 + GR_RLIM_DATA_BUMP = 10000,
67411 + GR_RLIM_STACK_BUMP = 1000,
67412 + GR_RLIM_CORE_BUMP = 10000,
67413 + GR_RLIM_RSS_BUMP = 500000,
67414 + GR_RLIM_NPROC_BUMP = 1,
67415 + GR_RLIM_NOFILE_BUMP = 5,
67416 + GR_RLIM_MEMLOCK_BUMP = 50000,
67417 + GR_RLIM_AS_BUMP = 500000,
67418 + GR_RLIM_LOCKS_BUMP = 2,
67419 + GR_RLIM_SIGPENDING_BUMP = 5,
67420 + GR_RLIM_MSGQUEUE_BUMP = 10000,
67421 + GR_RLIM_NICE_BUMP = 1,
67422 + GR_RLIM_RTPRIO_BUMP = 1,
67423 + GR_RLIM_RTTIME_BUMP = 1000000
67424 +};
67425 +
67426 +#endif
67427 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
67428 new file mode 100644
67429 index 0000000..9bb6662
67430 --- /dev/null
67431 +++ b/include/linux/grinternal.h
67432 @@ -0,0 +1,215 @@
67433 +#ifndef __GRINTERNAL_H
67434 +#define __GRINTERNAL_H
67435 +
67436 +#ifdef CONFIG_GRKERNSEC
67437 +
67438 +#include <linux/fs.h>
67439 +#include <linux/mnt_namespace.h>
67440 +#include <linux/nsproxy.h>
67441 +#include <linux/gracl.h>
67442 +#include <linux/grdefs.h>
67443 +#include <linux/grmsg.h>
67444 +
67445 +void gr_add_learn_entry(const char *fmt, ...)
67446 + __attribute__ ((format (printf, 1, 2)));
67447 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
67448 + const struct vfsmount *mnt);
67449 +__u32 gr_check_create(const struct dentry *new_dentry,
67450 + const struct dentry *parent,
67451 + const struct vfsmount *mnt, const __u32 mode);
67452 +int gr_check_protected_task(const struct task_struct *task);
67453 +__u32 to_gr_audit(const __u32 reqmode);
67454 +int gr_set_acls(const int type);
67455 +int gr_apply_subject_to_task(struct task_struct *task);
67456 +int gr_acl_is_enabled(void);
67457 +char gr_roletype_to_char(void);
67458 +
67459 +void gr_handle_alertkill(struct task_struct *task);
67460 +char *gr_to_filename(const struct dentry *dentry,
67461 + const struct vfsmount *mnt);
67462 +char *gr_to_filename1(const struct dentry *dentry,
67463 + const struct vfsmount *mnt);
67464 +char *gr_to_filename2(const struct dentry *dentry,
67465 + const struct vfsmount *mnt);
67466 +char *gr_to_filename3(const struct dentry *dentry,
67467 + const struct vfsmount *mnt);
67468 +
67469 +extern int grsec_enable_ptrace_readexec;
67470 +extern int grsec_enable_harden_ptrace;
67471 +extern int grsec_enable_link;
67472 +extern int grsec_enable_fifo;
67473 +extern int grsec_enable_execve;
67474 +extern int grsec_enable_shm;
67475 +extern int grsec_enable_execlog;
67476 +extern int grsec_enable_signal;
67477 +extern int grsec_enable_audit_ptrace;
67478 +extern int grsec_enable_forkfail;
67479 +extern int grsec_enable_time;
67480 +extern int grsec_enable_rofs;
67481 +extern int grsec_enable_chroot_shmat;
67482 +extern int grsec_enable_chroot_mount;
67483 +extern int grsec_enable_chroot_double;
67484 +extern int grsec_enable_chroot_pivot;
67485 +extern int grsec_enable_chroot_chdir;
67486 +extern int grsec_enable_chroot_chmod;
67487 +extern int grsec_enable_chroot_mknod;
67488 +extern int grsec_enable_chroot_fchdir;
67489 +extern int grsec_enable_chroot_nice;
67490 +extern int grsec_enable_chroot_execlog;
67491 +extern int grsec_enable_chroot_caps;
67492 +extern int grsec_enable_chroot_sysctl;
67493 +extern int grsec_enable_chroot_unix;
67494 +extern int grsec_enable_symlinkown;
67495 +extern kgid_t grsec_symlinkown_gid;
67496 +extern int grsec_enable_tpe;
67497 +extern kgid_t grsec_tpe_gid;
67498 +extern int grsec_enable_tpe_all;
67499 +extern int grsec_enable_tpe_invert;
67500 +extern int grsec_enable_socket_all;
67501 +extern kgid_t grsec_socket_all_gid;
67502 +extern int grsec_enable_socket_client;
67503 +extern kgid_t grsec_socket_client_gid;
67504 +extern int grsec_enable_socket_server;
67505 +extern kgid_t grsec_socket_server_gid;
67506 +extern kgid_t grsec_audit_gid;
67507 +extern int grsec_enable_group;
67508 +extern int grsec_enable_audit_textrel;
67509 +extern int grsec_enable_log_rwxmaps;
67510 +extern int grsec_enable_mount;
67511 +extern int grsec_enable_chdir;
67512 +extern int grsec_resource_logging;
67513 +extern int grsec_enable_blackhole;
67514 +extern int grsec_lastack_retries;
67515 +extern int grsec_enable_brute;
67516 +extern int grsec_lock;
67517 +
67518 +extern spinlock_t grsec_alert_lock;
67519 +extern unsigned long grsec_alert_wtime;
67520 +extern unsigned long grsec_alert_fyet;
67521 +
67522 +extern spinlock_t grsec_audit_lock;
67523 +
67524 +extern rwlock_t grsec_exec_file_lock;
67525 +
67526 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
67527 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
67528 + (tsk)->exec_file->f_vfsmnt) : "/")
67529 +
67530 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
67531 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
67532 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
67533 +
67534 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
67535 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
67536 + (tsk)->exec_file->f_vfsmnt) : "/")
67537 +
67538 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
67539 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
67540 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
67541 +
67542 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
67543 +
67544 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
67545 +
67546 +#define GR_CHROOT_CAPS {{ \
67547 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
67548 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
67549 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
67550 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
67551 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
67552 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
67553 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
67554 +
67555 +#define security_learn(normal_msg,args...) \
67556 +({ \
67557 + read_lock(&grsec_exec_file_lock); \
67558 + gr_add_learn_entry(normal_msg "\n", ## args); \
67559 + read_unlock(&grsec_exec_file_lock); \
67560 +})
67561 +
67562 +enum {
67563 + GR_DO_AUDIT,
67564 + GR_DONT_AUDIT,
67565 + /* used for non-audit messages that we shouldn't kill the task on */
67566 + GR_DONT_AUDIT_GOOD
67567 +};
67568 +
67569 +enum {
67570 + GR_TTYSNIFF,
67571 + GR_RBAC,
67572 + GR_RBAC_STR,
67573 + GR_STR_RBAC,
67574 + GR_RBAC_MODE2,
67575 + GR_RBAC_MODE3,
67576 + GR_FILENAME,
67577 + GR_SYSCTL_HIDDEN,
67578 + GR_NOARGS,
67579 + GR_ONE_INT,
67580 + GR_ONE_INT_TWO_STR,
67581 + GR_ONE_STR,
67582 + GR_STR_INT,
67583 + GR_TWO_STR_INT,
67584 + GR_TWO_INT,
67585 + GR_TWO_U64,
67586 + GR_THREE_INT,
67587 + GR_FIVE_INT_TWO_STR,
67588 + GR_TWO_STR,
67589 + GR_THREE_STR,
67590 + GR_FOUR_STR,
67591 + GR_STR_FILENAME,
67592 + GR_FILENAME_STR,
67593 + GR_FILENAME_TWO_INT,
67594 + GR_FILENAME_TWO_INT_STR,
67595 + GR_TEXTREL,
67596 + GR_PTRACE,
67597 + GR_RESOURCE,
67598 + GR_CAP,
67599 + GR_SIG,
67600 + GR_SIG2,
67601 + GR_CRASH1,
67602 + GR_CRASH2,
67603 + GR_PSACCT,
67604 + GR_RWXMAP
67605 +};
67606 +
67607 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
67608 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
67609 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
67610 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
67611 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
67612 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
67613 +#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)
67614 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
67615 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
67616 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
67617 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
67618 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
67619 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
67620 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
67621 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
67622 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
67623 +#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)
67624 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
67625 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
67626 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
67627 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
67628 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
67629 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
67630 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
67631 +#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)
67632 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
67633 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
67634 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
67635 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
67636 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
67637 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
67638 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
67639 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
67640 +#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)
67641 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
67642 +
67643 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
67644 +
67645 +#endif
67646 +
67647 +#endif
67648 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
67649 new file mode 100644
67650 index 0000000..2bd4c8d
67651 --- /dev/null
67652 +++ b/include/linux/grmsg.h
67653 @@ -0,0 +1,111 @@
67654 +#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"
67655 +#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"
67656 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
67657 +#define GR_STOPMOD_MSG "denied modification of module state by "
67658 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
67659 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
67660 +#define GR_IOPERM_MSG "denied use of ioperm() by "
67661 +#define GR_IOPL_MSG "denied use of iopl() by "
67662 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
67663 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
67664 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
67665 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
67666 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
67667 +#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"
67668 +#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"
67669 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
67670 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
67671 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
67672 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
67673 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
67674 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
67675 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
67676 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
67677 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
67678 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
67679 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
67680 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
67681 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
67682 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
67683 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
67684 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
67685 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
67686 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
67687 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
67688 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
67689 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
67690 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
67691 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
67692 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
67693 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
67694 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
67695 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
67696 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
67697 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
67698 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
67699 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
67700 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
67701 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
67702 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
67703 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
67704 +#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"
67705 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
67706 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
67707 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
67708 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
67709 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
67710 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
67711 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
67712 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
67713 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
67714 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
67715 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
67716 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
67717 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
67718 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
67719 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
67720 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
67721 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
67722 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
67723 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
67724 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
67725 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
67726 +#define GR_NICE_CHROOT_MSG "denied priority change by "
67727 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
67728 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
67729 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
67730 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
67731 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
67732 +#define GR_TIME_MSG "time set by "
67733 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
67734 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
67735 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
67736 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
67737 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
67738 +#define GR_BIND_MSG "denied bind() by "
67739 +#define GR_CONNECT_MSG "denied connect() by "
67740 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
67741 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
67742 +#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"
67743 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
67744 +#define GR_CAP_ACL_MSG "use of %s denied for "
67745 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
67746 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
67747 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
67748 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
67749 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
67750 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
67751 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
67752 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
67753 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
67754 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
67755 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
67756 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
67757 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
67758 +#define GR_VM86_MSG "denied use of vm86 by "
67759 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
67760 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
67761 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
67762 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
67763 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
67764 +#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 "
67765 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
67766 new file mode 100644
67767 index 0000000..1ae241a
67768 --- /dev/null
67769 +++ b/include/linux/grsecurity.h
67770 @@ -0,0 +1,257 @@
67771 +#ifndef GR_SECURITY_H
67772 +#define GR_SECURITY_H
67773 +#include <linux/fs.h>
67774 +#include <linux/fs_struct.h>
67775 +#include <linux/binfmts.h>
67776 +#include <linux/gracl.h>
67777 +
67778 +/* notify of brain-dead configs */
67779 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67780 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
67781 +#endif
67782 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
67783 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
67784 +#endif
67785 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
67786 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
67787 +#endif
67788 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
67789 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
67790 +#endif
67791 +
67792 +#include <linux/compat.h>
67793 +
67794 +struct user_arg_ptr {
67795 +#ifdef CONFIG_COMPAT
67796 + bool is_compat;
67797 +#endif
67798 + union {
67799 + const char __user *const __user *native;
67800 +#ifdef CONFIG_COMPAT
67801 + const compat_uptr_t __user *compat;
67802 +#endif
67803 + } ptr;
67804 +};
67805 +
67806 +void gr_handle_brute_attach(unsigned long mm_flags);
67807 +void gr_handle_brute_check(void);
67808 +void gr_handle_kernel_exploit(void);
67809 +int gr_process_user_ban(void);
67810 +
67811 +char gr_roletype_to_char(void);
67812 +
67813 +int gr_acl_enable_at_secure(void);
67814 +
67815 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
67816 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
67817 +
67818 +void gr_del_task_from_ip_table(struct task_struct *p);
67819 +
67820 +int gr_pid_is_chrooted(struct task_struct *p);
67821 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
67822 +int gr_handle_chroot_nice(void);
67823 +int gr_handle_chroot_sysctl(const int op);
67824 +int gr_handle_chroot_setpriority(struct task_struct *p,
67825 + const int niceval);
67826 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
67827 +int gr_handle_chroot_chroot(const struct dentry *dentry,
67828 + const struct vfsmount *mnt);
67829 +void gr_handle_chroot_chdir(struct path *path);
67830 +int gr_handle_chroot_chmod(const struct dentry *dentry,
67831 + const struct vfsmount *mnt, const int mode);
67832 +int gr_handle_chroot_mknod(const struct dentry *dentry,
67833 + const struct vfsmount *mnt, const int mode);
67834 +int gr_handle_chroot_mount(const struct dentry *dentry,
67835 + const struct vfsmount *mnt,
67836 + const char *dev_name);
67837 +int gr_handle_chroot_pivot(void);
67838 +int gr_handle_chroot_unix(const pid_t pid);
67839 +
67840 +int gr_handle_rawio(const struct inode *inode);
67841 +
67842 +void gr_handle_ioperm(void);
67843 +void gr_handle_iopl(void);
67844 +
67845 +umode_t gr_acl_umask(void);
67846 +
67847 +int gr_tpe_allow(const struct file *file);
67848 +
67849 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
67850 +void gr_clear_chroot_entries(struct task_struct *task);
67851 +
67852 +void gr_log_forkfail(const int retval);
67853 +void gr_log_timechange(void);
67854 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
67855 +void gr_log_chdir(const struct dentry *dentry,
67856 + const struct vfsmount *mnt);
67857 +void gr_log_chroot_exec(const struct dentry *dentry,
67858 + const struct vfsmount *mnt);
67859 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
67860 +void gr_log_remount(const char *devname, const int retval);
67861 +void gr_log_unmount(const char *devname, const int retval);
67862 +void gr_log_mount(const char *from, const char *to, const int retval);
67863 +void gr_log_textrel(struct vm_area_struct *vma);
67864 +void gr_log_rwxmmap(struct file *file);
67865 +void gr_log_rwxmprotect(struct file *file);
67866 +
67867 +int gr_handle_follow_link(const struct inode *parent,
67868 + const struct inode *inode,
67869 + const struct dentry *dentry,
67870 + const struct vfsmount *mnt);
67871 +int gr_handle_fifo(const struct dentry *dentry,
67872 + const struct vfsmount *mnt,
67873 + const struct dentry *dir, const int flag,
67874 + const int acc_mode);
67875 +int gr_handle_hardlink(const struct dentry *dentry,
67876 + const struct vfsmount *mnt,
67877 + struct inode *inode,
67878 + const int mode, const struct filename *to);
67879 +
67880 +int gr_is_capable(const int cap);
67881 +int gr_is_capable_nolog(const int cap);
67882 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
67883 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
67884 +
67885 +void gr_copy_label(struct task_struct *tsk);
67886 +void gr_handle_crash(struct task_struct *task, const int sig);
67887 +int gr_handle_signal(const struct task_struct *p, const int sig);
67888 +int gr_check_crash_uid(const kuid_t uid);
67889 +int gr_check_protected_task(const struct task_struct *task);
67890 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
67891 +int gr_acl_handle_mmap(const struct file *file,
67892 + const unsigned long prot);
67893 +int gr_acl_handle_mprotect(const struct file *file,
67894 + const unsigned long prot);
67895 +int gr_check_hidden_task(const struct task_struct *tsk);
67896 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
67897 + const struct vfsmount *mnt);
67898 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
67899 + const struct vfsmount *mnt);
67900 +__u32 gr_acl_handle_access(const struct dentry *dentry,
67901 + const struct vfsmount *mnt, const int fmode);
67902 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
67903 + const struct vfsmount *mnt, umode_t *mode);
67904 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
67905 + const struct vfsmount *mnt);
67906 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
67907 + const struct vfsmount *mnt);
67908 +int gr_handle_ptrace(struct task_struct *task, const long request);
67909 +int gr_handle_proc_ptrace(struct task_struct *task);
67910 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
67911 + const struct vfsmount *mnt);
67912 +int gr_check_crash_exec(const struct file *filp);
67913 +int gr_acl_is_enabled(void);
67914 +void gr_set_kernel_label(struct task_struct *task);
67915 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
67916 + const kgid_t gid);
67917 +int gr_set_proc_label(const struct dentry *dentry,
67918 + const struct vfsmount *mnt,
67919 + const int unsafe_flags);
67920 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
67921 + const struct vfsmount *mnt);
67922 +__u32 gr_acl_handle_open(const struct dentry *dentry,
67923 + const struct vfsmount *mnt, int acc_mode);
67924 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
67925 + const struct dentry *p_dentry,
67926 + const struct vfsmount *p_mnt,
67927 + int open_flags, int acc_mode, const int imode);
67928 +void gr_handle_create(const struct dentry *dentry,
67929 + const struct vfsmount *mnt);
67930 +void gr_handle_proc_create(const struct dentry *dentry,
67931 + const struct inode *inode);
67932 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
67933 + const struct dentry *parent_dentry,
67934 + const struct vfsmount *parent_mnt,
67935 + const int mode);
67936 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
67937 + const struct dentry *parent_dentry,
67938 + const struct vfsmount *parent_mnt);
67939 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
67940 + const struct vfsmount *mnt);
67941 +void gr_handle_delete(const ino_t ino, const dev_t dev);
67942 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
67943 + const struct vfsmount *mnt);
67944 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
67945 + const struct dentry *parent_dentry,
67946 + const struct vfsmount *parent_mnt,
67947 + const struct filename *from);
67948 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
67949 + const struct dentry *parent_dentry,
67950 + const struct vfsmount *parent_mnt,
67951 + const struct dentry *old_dentry,
67952 + const struct vfsmount *old_mnt, const struct filename *to);
67953 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
67954 +int gr_acl_handle_rename(struct dentry *new_dentry,
67955 + struct dentry *parent_dentry,
67956 + const struct vfsmount *parent_mnt,
67957 + struct dentry *old_dentry,
67958 + struct inode *old_parent_inode,
67959 + struct vfsmount *old_mnt, const struct filename *newname);
67960 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
67961 + struct dentry *old_dentry,
67962 + struct dentry *new_dentry,
67963 + struct vfsmount *mnt, const __u8 replace);
67964 +__u32 gr_check_link(const struct dentry *new_dentry,
67965 + const struct dentry *parent_dentry,
67966 + const struct vfsmount *parent_mnt,
67967 + const struct dentry *old_dentry,
67968 + const struct vfsmount *old_mnt);
67969 +int gr_acl_handle_filldir(const struct file *file, const char *name,
67970 + const unsigned int namelen, const ino_t ino);
67971 +
67972 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
67973 + const struct vfsmount *mnt);
67974 +void gr_acl_handle_exit(void);
67975 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
67976 +int gr_acl_handle_procpidmem(const struct task_struct *task);
67977 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
67978 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
67979 +void gr_audit_ptrace(struct task_struct *task);
67980 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
67981 +void gr_put_exec_file(struct task_struct *task);
67982 +
67983 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
67984 +
67985 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
67986 +extern void gr_learn_resource(const struct task_struct *task, const int res,
67987 + const unsigned long wanted, const int gt);
67988 +#else
67989 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
67990 + const unsigned long wanted, const int gt)
67991 +{
67992 +}
67993 +#endif
67994 +
67995 +#ifdef CONFIG_GRKERNSEC_RESLOG
67996 +extern void gr_log_resource(const struct task_struct *task, const int res,
67997 + const unsigned long wanted, const int gt);
67998 +#else
67999 +static inline void gr_log_resource(const struct task_struct *task, const int res,
68000 + const unsigned long wanted, const int gt)
68001 +{
68002 +}
68003 +#endif
68004 +
68005 +#ifdef CONFIG_GRKERNSEC
68006 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
68007 +void gr_handle_vm86(void);
68008 +void gr_handle_mem_readwrite(u64 from, u64 to);
68009 +
68010 +void gr_log_badprocpid(const char *entry);
68011 +
68012 +extern int grsec_enable_dmesg;
68013 +extern int grsec_disable_privio;
68014 +
68015 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68016 +extern kgid_t grsec_proc_gid;
68017 +#endif
68018 +
68019 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68020 +extern int grsec_enable_chroot_findtask;
68021 +#endif
68022 +#ifdef CONFIG_GRKERNSEC_SETXID
68023 +extern int grsec_enable_setxid;
68024 +#endif
68025 +#endif
68026 +
68027 +#endif
68028 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
68029 new file mode 100644
68030 index 0000000..e7ffaaf
68031 --- /dev/null
68032 +++ b/include/linux/grsock.h
68033 @@ -0,0 +1,19 @@
68034 +#ifndef __GRSOCK_H
68035 +#define __GRSOCK_H
68036 +
68037 +extern void gr_attach_curr_ip(const struct sock *sk);
68038 +extern int gr_handle_sock_all(const int family, const int type,
68039 + const int protocol);
68040 +extern int gr_handle_sock_server(const struct sockaddr *sck);
68041 +extern int gr_handle_sock_server_other(const struct sock *sck);
68042 +extern int gr_handle_sock_client(const struct sockaddr *sck);
68043 +extern int gr_search_connect(struct socket * sock,
68044 + struct sockaddr_in * addr);
68045 +extern int gr_search_bind(struct socket * sock,
68046 + struct sockaddr_in * addr);
68047 +extern int gr_search_listen(struct socket * sock);
68048 +extern int gr_search_accept(struct socket * sock);
68049 +extern int gr_search_socket(const int domain, const int type,
68050 + const int protocol);
68051 +
68052 +#endif
68053 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
68054 index ef788b5..ac41b7b 100644
68055 --- a/include/linux/highmem.h
68056 +++ b/include/linux/highmem.h
68057 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
68058 kunmap_atomic(kaddr);
68059 }
68060
68061 +static inline void sanitize_highpage(struct page *page)
68062 +{
68063 + void *kaddr;
68064 + unsigned long flags;
68065 +
68066 + local_irq_save(flags);
68067 + kaddr = kmap_atomic(page);
68068 + clear_page(kaddr);
68069 + kunmap_atomic(kaddr);
68070 + local_irq_restore(flags);
68071 +}
68072 +
68073 static inline void zero_user_segments(struct page *page,
68074 unsigned start1, unsigned end1,
68075 unsigned start2, unsigned end2)
68076 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
68077 index 1c7b89a..7f52502 100644
68078 --- a/include/linux/hwmon-sysfs.h
68079 +++ b/include/linux/hwmon-sysfs.h
68080 @@ -25,7 +25,8 @@
68081 struct sensor_device_attribute{
68082 struct device_attribute dev_attr;
68083 int index;
68084 -};
68085 +} __do_const;
68086 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
68087 #define to_sensor_dev_attr(_dev_attr) \
68088 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
68089
68090 @@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
68091 struct device_attribute dev_attr;
68092 u8 index;
68093 u8 nr;
68094 -};
68095 +} __do_const;
68096 #define to_sensor_dev_attr_2(_dev_attr) \
68097 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
68098
68099 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
68100 index d0c4db7..61b3577 100644
68101 --- a/include/linux/i2c.h
68102 +++ b/include/linux/i2c.h
68103 @@ -369,6 +369,7 @@ struct i2c_algorithm {
68104 /* To determine what the adapter supports */
68105 u32 (*functionality) (struct i2c_adapter *);
68106 };
68107 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
68108
68109 /*
68110 * i2c_adapter is the structure used to identify a physical i2c bus along
68111 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
68112 index d23c3c2..eb63c81 100644
68113 --- a/include/linux/i2o.h
68114 +++ b/include/linux/i2o.h
68115 @@ -565,7 +565,7 @@ struct i2o_controller {
68116 struct i2o_device *exec; /* Executive */
68117 #if BITS_PER_LONG == 64
68118 spinlock_t context_list_lock; /* lock for context_list */
68119 - atomic_t context_list_counter; /* needed for unique contexts */
68120 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
68121 struct list_head context_list; /* list of context id's
68122 and pointers */
68123 #endif
68124 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
68125 index aff7ad8..3942bbd 100644
68126 --- a/include/linux/if_pppox.h
68127 +++ b/include/linux/if_pppox.h
68128 @@ -76,7 +76,7 @@ struct pppox_proto {
68129 int (*ioctl)(struct socket *sock, unsigned int cmd,
68130 unsigned long arg);
68131 struct module *owner;
68132 -};
68133 +} __do_const;
68134
68135 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
68136 extern void unregister_pppox_proto(int proto_num);
68137 diff --git a/include/linux/init.h b/include/linux/init.h
68138 index 10ed4f4..8e8490d 100644
68139 --- a/include/linux/init.h
68140 +++ b/include/linux/init.h
68141 @@ -39,9 +39,36 @@
68142 * Also note, that this data cannot be "const".
68143 */
68144
68145 +#ifdef MODULE
68146 +#define add_init_latent_entropy
68147 +#define add_devinit_latent_entropy
68148 +#define add_cpuinit_latent_entropy
68149 +#define add_meminit_latent_entropy
68150 +#else
68151 +#define add_init_latent_entropy __latent_entropy
68152 +
68153 +#ifdef CONFIG_HOTPLUG
68154 +#define add_devinit_latent_entropy
68155 +#else
68156 +#define add_devinit_latent_entropy __latent_entropy
68157 +#endif
68158 +
68159 +#ifdef CONFIG_HOTPLUG_CPU
68160 +#define add_cpuinit_latent_entropy
68161 +#else
68162 +#define add_cpuinit_latent_entropy __latent_entropy
68163 +#endif
68164 +
68165 +#ifdef CONFIG_MEMORY_HOTPLUG
68166 +#define add_meminit_latent_entropy
68167 +#else
68168 +#define add_meminit_latent_entropy __latent_entropy
68169 +#endif
68170 +#endif
68171 +
68172 /* These are for everybody (although not all archs will actually
68173 discard it in modules) */
68174 -#define __init __section(.init.text) __cold notrace
68175 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
68176 #define __initdata __section(.init.data)
68177 #define __initconst __constsection(.init.rodata)
68178 #define __exitdata __section(.exit.data)
68179 @@ -94,7 +121,7 @@
68180 #define __exit __section(.exit.text) __exitused __cold notrace
68181
68182 /* Used for HOTPLUG_CPU */
68183 -#define __cpuinit __section(.cpuinit.text) __cold notrace
68184 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
68185 #define __cpuinitdata __section(.cpuinit.data)
68186 #define __cpuinitconst __constsection(.cpuinit.rodata)
68187 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
68188 @@ -102,7 +129,7 @@
68189 #define __cpuexitconst __constsection(.cpuexit.rodata)
68190
68191 /* Used for MEMORY_HOTPLUG */
68192 -#define __meminit __section(.meminit.text) __cold notrace
68193 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
68194 #define __meminitdata __section(.meminit.data)
68195 #define __meminitconst __constsection(.meminit.rodata)
68196 #define __memexit __section(.memexit.text) __exitused __cold notrace
68197 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
68198 index 6d087c5..401cab8 100644
68199 --- a/include/linux/init_task.h
68200 +++ b/include/linux/init_task.h
68201 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
68202
68203 #define INIT_TASK_COMM "swapper"
68204
68205 +#ifdef CONFIG_X86
68206 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
68207 +#else
68208 +#define INIT_TASK_THREAD_INFO
68209 +#endif
68210 +
68211 /*
68212 * INIT_TASK is used to set up the first task table, touch at
68213 * your own risk!. Base=0, limit=0x1fffff (=2MB)
68214 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
68215 RCU_POINTER_INITIALIZER(cred, &init_cred), \
68216 .comm = INIT_TASK_COMM, \
68217 .thread = INIT_THREAD, \
68218 + INIT_TASK_THREAD_INFO \
68219 .fs = &init_fs, \
68220 .files = &init_files, \
68221 .signal = &init_signals, \
68222 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
68223 index 5fa5afe..ac55b25 100644
68224 --- a/include/linux/interrupt.h
68225 +++ b/include/linux/interrupt.h
68226 @@ -430,7 +430,7 @@ enum
68227 /* map softirq index to softirq name. update 'softirq_to_name' in
68228 * kernel/softirq.c when adding a new softirq.
68229 */
68230 -extern char *softirq_to_name[NR_SOFTIRQS];
68231 +extern const char * const softirq_to_name[NR_SOFTIRQS];
68232
68233 /* softirq mask and active fields moved to irq_cpustat_t in
68234 * asm/hardirq.h to get better cache usage. KAO
68235 @@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
68236
68237 struct softirq_action
68238 {
68239 - void (*action)(struct softirq_action *);
68240 -};
68241 + void (*action)(void);
68242 +} __no_const;
68243
68244 asmlinkage void do_softirq(void);
68245 asmlinkage void __do_softirq(void);
68246 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
68247 +extern void open_softirq(int nr, void (*action)(void));
68248 extern void softirq_init(void);
68249 extern void __raise_softirq_irqoff(unsigned int nr);
68250
68251 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
68252 index f3b99e1..9b73cee 100644
68253 --- a/include/linux/iommu.h
68254 +++ b/include/linux/iommu.h
68255 @@ -101,7 +101,7 @@ struct iommu_ops {
68256 int (*domain_set_attr)(struct iommu_domain *domain,
68257 enum iommu_attr attr, void *data);
68258 unsigned long pgsize_bitmap;
68259 -};
68260 +} __do_const;
68261
68262 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
68263 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
68264 diff --git a/include/linux/irq.h b/include/linux/irq.h
68265 index fdf2c4a..c06b031 100644
68266 --- a/include/linux/irq.h
68267 +++ b/include/linux/irq.h
68268 @@ -328,7 +328,7 @@ struct irq_chip {
68269 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
68270
68271 unsigned long flags;
68272 -};
68273 +} __do_const;
68274
68275 /*
68276 * irq_chip specific flags
68277 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
68278 index 6883e19..06992b1 100644
68279 --- a/include/linux/kallsyms.h
68280 +++ b/include/linux/kallsyms.h
68281 @@ -15,7 +15,8 @@
68282
68283 struct module;
68284
68285 -#ifdef CONFIG_KALLSYMS
68286 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
68287 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68288 /* Lookup the address for a symbol. Returns 0 if not found. */
68289 unsigned long kallsyms_lookup_name(const char *name);
68290
68291 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
68292 /* Stupid that this does nothing, but I didn't create this mess. */
68293 #define __print_symbol(fmt, addr)
68294 #endif /*CONFIG_KALLSYMS*/
68295 +#else /* when included by kallsyms.c, vsnprintf.c, or
68296 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
68297 +extern void __print_symbol(const char *fmt, unsigned long address);
68298 +extern int sprint_backtrace(char *buffer, unsigned long address);
68299 +extern int sprint_symbol(char *buffer, unsigned long address);
68300 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
68301 +const char *kallsyms_lookup(unsigned long addr,
68302 + unsigned long *symbolsize,
68303 + unsigned long *offset,
68304 + char **modname, char *namebuf);
68305 +#endif
68306
68307 /* This macro allows us to keep printk typechecking */
68308 static __printf(1, 2)
68309 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
68310 index 518a53a..5e28358 100644
68311 --- a/include/linux/key-type.h
68312 +++ b/include/linux/key-type.h
68313 @@ -125,7 +125,7 @@ struct key_type {
68314 /* internal fields */
68315 struct list_head link; /* link in types list */
68316 struct lock_class_key lock_class; /* key->sem lock class */
68317 -};
68318 +} __do_const;
68319
68320 extern struct key_type key_type_keyring;
68321
68322 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
68323 index 4dff0c6..1ca9b72 100644
68324 --- a/include/linux/kgdb.h
68325 +++ b/include/linux/kgdb.h
68326 @@ -53,7 +53,7 @@ extern int kgdb_connected;
68327 extern int kgdb_io_module_registered;
68328
68329 extern atomic_t kgdb_setting_breakpoint;
68330 -extern atomic_t kgdb_cpu_doing_single_step;
68331 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
68332
68333 extern struct task_struct *kgdb_usethread;
68334 extern struct task_struct *kgdb_contthread;
68335 @@ -255,7 +255,7 @@ struct kgdb_arch {
68336 void (*correct_hw_break)(void);
68337
68338 void (*enable_nmi)(bool on);
68339 -};
68340 +} __do_const;
68341
68342 /**
68343 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
68344 @@ -280,7 +280,7 @@ struct kgdb_io {
68345 void (*pre_exception) (void);
68346 void (*post_exception) (void);
68347 int is_console;
68348 -};
68349 +} __do_const;
68350
68351 extern struct kgdb_arch arch_kgdb_ops;
68352
68353 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
68354 index 5398d58..5883a34 100644
68355 --- a/include/linux/kmod.h
68356 +++ b/include/linux/kmod.h
68357 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
68358 * usually useless though. */
68359 extern __printf(2, 3)
68360 int __request_module(bool wait, const char *name, ...);
68361 +extern __printf(3, 4)
68362 +int ___request_module(bool wait, char *param_name, const char *name, ...);
68363 #define request_module(mod...) __request_module(true, mod)
68364 #define request_module_nowait(mod...) __request_module(false, mod)
68365 #define try_then_request_module(x, mod...) \
68366 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
68367 index 939b112..ed6ed51 100644
68368 --- a/include/linux/kobject.h
68369 +++ b/include/linux/kobject.h
68370 @@ -111,7 +111,7 @@ struct kobj_type {
68371 struct attribute **default_attrs;
68372 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
68373 const void *(*namespace)(struct kobject *kobj);
68374 -};
68375 +} __do_const;
68376
68377 struct kobj_uevent_env {
68378 char *envp[UEVENT_NUM_ENVP];
68379 @@ -134,6 +134,7 @@ struct kobj_attribute {
68380 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
68381 const char *buf, size_t count);
68382 };
68383 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
68384
68385 extern const struct sysfs_ops kobj_sysfs_ops;
68386
68387 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
68388 index f66b065..c2c29b4 100644
68389 --- a/include/linux/kobject_ns.h
68390 +++ b/include/linux/kobject_ns.h
68391 @@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
68392 const void *(*netlink_ns)(struct sock *sk);
68393 const void *(*initial_ns)(void);
68394 void (*drop_ns)(void *);
68395 -};
68396 +} __do_const;
68397
68398 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
68399 int kobj_ns_type_registered(enum kobj_ns_type type);
68400 diff --git a/include/linux/kref.h b/include/linux/kref.h
68401 index 4972e6e..de4d19b 100644
68402 --- a/include/linux/kref.h
68403 +++ b/include/linux/kref.h
68404 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
68405 static inline int kref_sub(struct kref *kref, unsigned int count,
68406 void (*release)(struct kref *kref))
68407 {
68408 - WARN_ON(release == NULL);
68409 + BUG_ON(release == NULL);
68410
68411 if (atomic_sub_and_test((int) count, &kref->refcount)) {
68412 release(kref);
68413 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
68414 index 2c497ab..afe32f5 100644
68415 --- a/include/linux/kvm_host.h
68416 +++ b/include/linux/kvm_host.h
68417 @@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
68418 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
68419 void vcpu_put(struct kvm_vcpu *vcpu);
68420
68421 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
68422 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
68423 struct module *module);
68424 void kvm_exit(void);
68425
68426 @@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
68427 struct kvm_guest_debug *dbg);
68428 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
68429
68430 -int kvm_arch_init(void *opaque);
68431 +int kvm_arch_init(const void *opaque);
68432 void kvm_arch_exit(void);
68433
68434 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
68435 diff --git a/include/linux/libata.h b/include/linux/libata.h
68436 index 649e5f8..ead5194 100644
68437 --- a/include/linux/libata.h
68438 +++ b/include/linux/libata.h
68439 @@ -915,7 +915,7 @@ struct ata_port_operations {
68440 * fields must be pointers.
68441 */
68442 const struct ata_port_operations *inherits;
68443 -};
68444 +} __do_const;
68445
68446 struct ata_port_info {
68447 unsigned long flags;
68448 diff --git a/include/linux/list.h b/include/linux/list.h
68449 index cc6d2aa..c10ee83 100644
68450 --- a/include/linux/list.h
68451 +++ b/include/linux/list.h
68452 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
68453 extern void list_del(struct list_head *entry);
68454 #endif
68455
68456 +extern void __pax_list_add(struct list_head *new,
68457 + struct list_head *prev,
68458 + struct list_head *next);
68459 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
68460 +{
68461 + __pax_list_add(new, head, head->next);
68462 +}
68463 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
68464 +{
68465 + __pax_list_add(new, head->prev, head);
68466 +}
68467 +extern void pax_list_del(struct list_head *entry);
68468 +
68469 /**
68470 * list_replace - replace old entry by new one
68471 * @old : the element to be replaced
68472 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
68473 INIT_LIST_HEAD(entry);
68474 }
68475
68476 +extern void pax_list_del_init(struct list_head *entry);
68477 +
68478 /**
68479 * list_move - delete from one list and add as another's head
68480 * @list: the entry to move
68481 diff --git a/include/linux/mm.h b/include/linux/mm.h
68482 index 66e2f7c..ea88001 100644
68483 --- a/include/linux/mm.h
68484 +++ b/include/linux/mm.h
68485 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
68486 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
68487 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
68488 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
68489 +
68490 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68491 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
68492 +#endif
68493 +
68494 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
68495
68496 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
68497 @@ -231,6 +236,7 @@ struct vm_operations_struct {
68498 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
68499 unsigned long size, pgoff_t pgoff);
68500 };
68501 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
68502
68503 struct mmu_gather;
68504 struct inode;
68505 @@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
68506 int set_page_dirty_lock(struct page *page);
68507 int clear_page_dirty_for_io(struct page *page);
68508
68509 -/* Is the vma a continuation of the stack vma above it? */
68510 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
68511 -{
68512 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
68513 -}
68514 -
68515 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
68516 - unsigned long addr)
68517 -{
68518 - return (vma->vm_flags & VM_GROWSDOWN) &&
68519 - (vma->vm_start == addr) &&
68520 - !vma_growsdown(vma->vm_prev, addr);
68521 -}
68522 -
68523 -/* Is the vma a continuation of the stack vma below it? */
68524 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
68525 -{
68526 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
68527 -}
68528 -
68529 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
68530 - unsigned long addr)
68531 -{
68532 - return (vma->vm_flags & VM_GROWSUP) &&
68533 - (vma->vm_end == addr) &&
68534 - !vma_growsup(vma->vm_next, addr);
68535 -}
68536 -
68537 extern pid_t
68538 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
68539
68540 @@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
68541 }
68542 #endif
68543
68544 +#ifdef CONFIG_MMU
68545 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
68546 +#else
68547 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
68548 +{
68549 + return __pgprot(0);
68550 +}
68551 +#endif
68552 +
68553 int vma_wants_writenotify(struct vm_area_struct *vma);
68554
68555 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
68556 @@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
68557 {
68558 return 0;
68559 }
68560 +
68561 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
68562 + unsigned long address)
68563 +{
68564 + return 0;
68565 +}
68566 #else
68567 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
68568 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
68569 #endif
68570
68571 #ifdef __PAGETABLE_PMD_FOLDED
68572 @@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
68573 {
68574 return 0;
68575 }
68576 +
68577 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
68578 + unsigned long address)
68579 +{
68580 + return 0;
68581 +}
68582 #else
68583 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
68584 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
68585 #endif
68586
68587 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
68588 @@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
68589 NULL: pud_offset(pgd, address);
68590 }
68591
68592 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
68593 +{
68594 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
68595 + NULL: pud_offset(pgd, address);
68596 +}
68597 +
68598 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
68599 {
68600 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
68601 NULL: pmd_offset(pud, address);
68602 }
68603 +
68604 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
68605 +{
68606 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
68607 + NULL: pmd_offset(pud, address);
68608 +}
68609 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
68610
68611 #if USE_SPLIT_PTLOCKS
68612 @@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
68613 unsigned long, unsigned long,
68614 unsigned long, unsigned long);
68615 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
68616 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
68617
68618 /* These take the mm semaphore themselves */
68619 extern unsigned long vm_brk(unsigned long, unsigned long);
68620 @@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
68621 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
68622 struct vm_area_struct **pprev);
68623
68624 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
68625 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
68626 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
68627 +
68628 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
68629 NULL if none. Assume start_addr < end_addr. */
68630 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
68631 @@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
68632 return vma;
68633 }
68634
68635 -#ifdef CONFIG_MMU
68636 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
68637 -#else
68638 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
68639 -{
68640 - return __pgprot(0);
68641 -}
68642 -#endif
68643 -
68644 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
68645 unsigned long change_prot_numa(struct vm_area_struct *vma,
68646 unsigned long start, unsigned long end);
68647 @@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
68648 extern int sysctl_memory_failure_early_kill;
68649 extern int sysctl_memory_failure_recovery;
68650 extern void shake_page(struct page *p, int access);
68651 -extern atomic_long_t mce_bad_pages;
68652 +extern atomic_long_unchecked_t mce_bad_pages;
68653 extern int soft_offline_page(struct page *page, int flags);
68654
68655 extern void dump_page(struct page *page);
68656 @@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
68657 static inline bool page_is_guard(struct page *page) { return false; }
68658 #endif /* CONFIG_DEBUG_PAGEALLOC */
68659
68660 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
68661 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
68662 +#else
68663 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
68664 +#endif
68665 +
68666 #endif /* __KERNEL__ */
68667 #endif /* _LINUX_MM_H */
68668 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
68669 index f8f5162..6276a36 100644
68670 --- a/include/linux/mm_types.h
68671 +++ b/include/linux/mm_types.h
68672 @@ -288,6 +288,8 @@ struct vm_area_struct {
68673 #ifdef CONFIG_NUMA
68674 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
68675 #endif
68676 +
68677 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
68678 };
68679
68680 struct core_thread {
68681 @@ -362,7 +364,7 @@ struct mm_struct {
68682 unsigned long def_flags;
68683 unsigned long nr_ptes; /* Page table pages */
68684 unsigned long start_code, end_code, start_data, end_data;
68685 - unsigned long start_brk, brk, start_stack;
68686 + unsigned long brk_gap, start_brk, brk, start_stack;
68687 unsigned long arg_start, arg_end, env_start, env_end;
68688
68689 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
68690 @@ -436,6 +438,24 @@ struct mm_struct {
68691 int first_nid;
68692 #endif
68693 struct uprobes_state uprobes_state;
68694 +
68695 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
68696 + unsigned long pax_flags;
68697 +#endif
68698 +
68699 +#ifdef CONFIG_PAX_DLRESOLVE
68700 + unsigned long call_dl_resolve;
68701 +#endif
68702 +
68703 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
68704 + unsigned long call_syscall;
68705 +#endif
68706 +
68707 +#ifdef CONFIG_PAX_ASLR
68708 + unsigned long delta_mmap; /* randomized offset */
68709 + unsigned long delta_stack; /* randomized offset */
68710 +#endif
68711 +
68712 };
68713
68714 /* first nid will either be a valid NID or one of these values */
68715 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
68716 index c5d5278..f0b68c8 100644
68717 --- a/include/linux/mmiotrace.h
68718 +++ b/include/linux/mmiotrace.h
68719 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
68720 /* Called from ioremap.c */
68721 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
68722 void __iomem *addr);
68723 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
68724 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
68725
68726 /* For anyone to insert markers. Remember trailing newline. */
68727 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
68728 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
68729 {
68730 }
68731
68732 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
68733 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
68734 {
68735 }
68736
68737 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
68738 index 73b64a3..6562925 100644
68739 --- a/include/linux/mmzone.h
68740 +++ b/include/linux/mmzone.h
68741 @@ -412,7 +412,7 @@ struct zone {
68742 unsigned long flags; /* zone flags, see below */
68743
68744 /* Zone statistics */
68745 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
68746 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
68747
68748 /*
68749 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
68750 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
68751 index fed3def..c933f99 100644
68752 --- a/include/linux/mod_devicetable.h
68753 +++ b/include/linux/mod_devicetable.h
68754 @@ -12,7 +12,7 @@
68755 typedef unsigned long kernel_ulong_t;
68756 #endif
68757
68758 -#define PCI_ANY_ID (~0)
68759 +#define PCI_ANY_ID ((__u16)~0)
68760
68761 struct pci_device_id {
68762 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
68763 @@ -139,7 +139,7 @@ struct usb_device_id {
68764 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
68765 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
68766
68767 -#define HID_ANY_ID (~0)
68768 +#define HID_ANY_ID (~0U)
68769 #define HID_BUS_ANY 0xffff
68770 #define HID_GROUP_ANY 0x0000
68771
68772 @@ -498,7 +498,7 @@ struct dmi_system_id {
68773 const char *ident;
68774 struct dmi_strmatch matches[4];
68775 void *driver_data;
68776 -};
68777 +} __do_const;
68778 /*
68779 * struct dmi_device_id appears during expansion of
68780 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
68781 diff --git a/include/linux/module.h b/include/linux/module.h
68782 index 1375ee3..ced8177 100644
68783 --- a/include/linux/module.h
68784 +++ b/include/linux/module.h
68785 @@ -17,9 +17,11 @@
68786 #include <linux/moduleparam.h>
68787 #include <linux/tracepoint.h>
68788 #include <linux/export.h>
68789 +#include <linux/fs.h>
68790
68791 #include <linux/percpu.h>
68792 #include <asm/module.h>
68793 +#include <asm/pgtable.h>
68794
68795 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
68796 #define MODULE_SIG_STRING "~Module signature appended~\n"
68797 @@ -54,12 +56,13 @@ struct module_attribute {
68798 int (*test)(struct module *);
68799 void (*free)(struct module *);
68800 };
68801 +typedef struct module_attribute __no_const module_attribute_no_const;
68802
68803 struct module_version_attribute {
68804 struct module_attribute mattr;
68805 const char *module_name;
68806 const char *version;
68807 -} __attribute__ ((__aligned__(sizeof(void *))));
68808 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
68809
68810 extern ssize_t __modver_version_show(struct module_attribute *,
68811 struct module_kobject *, char *);
68812 @@ -232,7 +235,7 @@ struct module
68813
68814 /* Sysfs stuff. */
68815 struct module_kobject mkobj;
68816 - struct module_attribute *modinfo_attrs;
68817 + module_attribute_no_const *modinfo_attrs;
68818 const char *version;
68819 const char *srcversion;
68820 struct kobject *holders_dir;
68821 @@ -281,19 +284,16 @@ struct module
68822 int (*init)(void);
68823
68824 /* If this is non-NULL, vfree after init() returns */
68825 - void *module_init;
68826 + void *module_init_rx, *module_init_rw;
68827
68828 /* Here is the actual code + data, vfree'd on unload. */
68829 - void *module_core;
68830 + void *module_core_rx, *module_core_rw;
68831
68832 /* Here are the sizes of the init and core sections */
68833 - unsigned int init_size, core_size;
68834 + unsigned int init_size_rw, core_size_rw;
68835
68836 /* The size of the executable code in each section. */
68837 - unsigned int init_text_size, core_text_size;
68838 -
68839 - /* Size of RO sections of the module (text+rodata) */
68840 - unsigned int init_ro_size, core_ro_size;
68841 + unsigned int init_size_rx, core_size_rx;
68842
68843 /* Arch-specific module values */
68844 struct mod_arch_specific arch;
68845 @@ -349,6 +349,10 @@ struct module
68846 #ifdef CONFIG_EVENT_TRACING
68847 struct ftrace_event_call **trace_events;
68848 unsigned int num_trace_events;
68849 + struct file_operations trace_id;
68850 + struct file_operations trace_enable;
68851 + struct file_operations trace_format;
68852 + struct file_operations trace_filter;
68853 #endif
68854 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
68855 unsigned int num_ftrace_callsites;
68856 @@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
68857 bool is_module_percpu_address(unsigned long addr);
68858 bool is_module_text_address(unsigned long addr);
68859
68860 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
68861 +{
68862 +
68863 +#ifdef CONFIG_PAX_KERNEXEC
68864 + if (ktla_ktva(addr) >= (unsigned long)start &&
68865 + ktla_ktva(addr) < (unsigned long)start + size)
68866 + return 1;
68867 +#endif
68868 +
68869 + return ((void *)addr >= start && (void *)addr < start + size);
68870 +}
68871 +
68872 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
68873 +{
68874 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
68875 +}
68876 +
68877 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
68878 +{
68879 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
68880 +}
68881 +
68882 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
68883 +{
68884 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
68885 +}
68886 +
68887 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
68888 +{
68889 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
68890 +}
68891 +
68892 static inline int within_module_core(unsigned long addr, struct module *mod)
68893 {
68894 - return (unsigned long)mod->module_core <= addr &&
68895 - addr < (unsigned long)mod->module_core + mod->core_size;
68896 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
68897 }
68898
68899 static inline int within_module_init(unsigned long addr, struct module *mod)
68900 {
68901 - return (unsigned long)mod->module_init <= addr &&
68902 - addr < (unsigned long)mod->module_init + mod->init_size;
68903 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
68904 }
68905
68906 /* Search for module by name: must hold module_mutex. */
68907 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
68908 index 560ca53..5ee8d73 100644
68909 --- a/include/linux/moduleloader.h
68910 +++ b/include/linux/moduleloader.h
68911 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
68912
68913 /* Allocator used for allocating struct module, core sections and init
68914 sections. Returns NULL on failure. */
68915 -void *module_alloc(unsigned long size);
68916 +void *module_alloc(unsigned long size) __size_overflow(1);
68917 +
68918 +#ifdef CONFIG_PAX_KERNEXEC
68919 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
68920 +#else
68921 +#define module_alloc_exec(x) module_alloc(x)
68922 +#endif
68923
68924 /* Free memory returned from module_alloc. */
68925 void module_free(struct module *mod, void *module_region);
68926
68927 +#ifdef CONFIG_PAX_KERNEXEC
68928 +void module_free_exec(struct module *mod, void *module_region);
68929 +#else
68930 +#define module_free_exec(x, y) module_free((x), (y))
68931 +#endif
68932 +
68933 /*
68934 * Apply the given relocation to the (simplified) ELF. Return -error
68935 * or 0.
68936 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
68937 unsigned int relsec,
68938 struct module *me)
68939 {
68940 +#ifdef CONFIG_MODULES
68941 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
68942 +#endif
68943 return -ENOEXEC;
68944 }
68945 #endif
68946 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
68947 unsigned int relsec,
68948 struct module *me)
68949 {
68950 +#ifdef CONFIG_MODULES
68951 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
68952 +#endif
68953 return -ENOEXEC;
68954 }
68955 #endif
68956 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
68957 index 137b419..fe663ec 100644
68958 --- a/include/linux/moduleparam.h
68959 +++ b/include/linux/moduleparam.h
68960 @@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
68961 * @len is usually just sizeof(string).
68962 */
68963 #define module_param_string(name, string, len, perm) \
68964 - static const struct kparam_string __param_string_##name \
68965 + static const struct kparam_string __param_string_##name __used \
68966 = { len, string }; \
68967 __module_param_call(MODULE_PARAM_PREFIX, name, \
68968 &param_ops_string, \
68969 @@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
68970 */
68971 #define module_param_array_named(name, array, type, nump, perm) \
68972 param_check_##type(name, &(array)[0]); \
68973 - static const struct kparam_array __param_arr_##name \
68974 + static const struct kparam_array __param_arr_##name __used \
68975 = { .max = ARRAY_SIZE(array), .num = nump, \
68976 .ops = &param_ops_##type, \
68977 .elemsize = sizeof(array[0]), .elem = array }; \
68978 diff --git a/include/linux/namei.h b/include/linux/namei.h
68979 index 5a5ff57..5ae5070 100644
68980 --- a/include/linux/namei.h
68981 +++ b/include/linux/namei.h
68982 @@ -19,7 +19,7 @@ struct nameidata {
68983 unsigned seq;
68984 int last_type;
68985 unsigned depth;
68986 - char *saved_names[MAX_NESTED_LINKS + 1];
68987 + const char *saved_names[MAX_NESTED_LINKS + 1];
68988 };
68989
68990 /*
68991 @@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
68992
68993 extern void nd_jump_link(struct nameidata *nd, struct path *path);
68994
68995 -static inline void nd_set_link(struct nameidata *nd, char *path)
68996 +static inline void nd_set_link(struct nameidata *nd, const char *path)
68997 {
68998 nd->saved_names[nd->depth] = path;
68999 }
69000
69001 -static inline char *nd_get_link(struct nameidata *nd)
69002 +static inline const char *nd_get_link(const struct nameidata *nd)
69003 {
69004 return nd->saved_names[nd->depth];
69005 }
69006 diff --git a/include/linux/net.h b/include/linux/net.h
69007 index aa16731..514b875 100644
69008 --- a/include/linux/net.h
69009 +++ b/include/linux/net.h
69010 @@ -183,7 +183,7 @@ struct net_proto_family {
69011 int (*create)(struct net *net, struct socket *sock,
69012 int protocol, int kern);
69013 struct module *owner;
69014 -};
69015 +} __do_const;
69016
69017 struct iovec;
69018 struct kvec;
69019 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
69020 index 9ef07d0..130a5d9 100644
69021 --- a/include/linux/netdevice.h
69022 +++ b/include/linux/netdevice.h
69023 @@ -1012,6 +1012,7 @@ struct net_device_ops {
69024 u32 pid, u32 seq,
69025 struct net_device *dev);
69026 };
69027 +typedef struct net_device_ops __no_const net_device_ops_no_const;
69028
69029 /*
69030 * The DEVICE structure.
69031 @@ -1078,7 +1079,7 @@ struct net_device {
69032 int iflink;
69033
69034 struct net_device_stats stats;
69035 - atomic_long_t rx_dropped; /* dropped packets by core network
69036 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
69037 * Do not use this in drivers.
69038 */
69039
69040 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
69041 index ee14284..bc65d63 100644
69042 --- a/include/linux/netfilter.h
69043 +++ b/include/linux/netfilter.h
69044 @@ -82,7 +82,7 @@ struct nf_sockopt_ops {
69045 #endif
69046 /* Use the module struct to lock set/get code in place */
69047 struct module *owner;
69048 -};
69049 +} __do_const;
69050
69051 /* Function to register/unregister hook points. */
69052 int nf_register_hook(struct nf_hook_ops *reg);
69053 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
69054 index 7958e84..ed74d7a 100644
69055 --- a/include/linux/netfilter/ipset/ip_set.h
69056 +++ b/include/linux/netfilter/ipset/ip_set.h
69057 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
69058 /* Return true if "b" set is the same as "a"
69059 * according to the create set parameters */
69060 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
69061 -};
69062 +} __do_const;
69063
69064 /* The core set type structure */
69065 struct ip_set_type {
69066 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
69067 index 4966dde..7d8ce06 100644
69068 --- a/include/linux/netfilter/nfnetlink.h
69069 +++ b/include/linux/netfilter/nfnetlink.h
69070 @@ -16,7 +16,7 @@ struct nfnl_callback {
69071 const struct nlattr * const cda[]);
69072 const struct nla_policy *policy; /* netlink attribute policy */
69073 const u_int16_t attr_count; /* number of nlattr's */
69074 -};
69075 +} __do_const;
69076
69077 struct nfnetlink_subsystem {
69078 const char *name;
69079 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
69080 new file mode 100644
69081 index 0000000..33f4af8
69082 --- /dev/null
69083 +++ b/include/linux/netfilter/xt_gradm.h
69084 @@ -0,0 +1,9 @@
69085 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
69086 +#define _LINUX_NETFILTER_XT_GRADM_H 1
69087 +
69088 +struct xt_gradm_mtinfo {
69089 + __u16 flags;
69090 + __u16 invflags;
69091 +};
69092 +
69093 +#endif
69094 diff --git a/include/linux/nls.h b/include/linux/nls.h
69095 index 5dc635f..35f5e11 100644
69096 --- a/include/linux/nls.h
69097 +++ b/include/linux/nls.h
69098 @@ -31,7 +31,7 @@ struct nls_table {
69099 const unsigned char *charset2upper;
69100 struct module *owner;
69101 struct nls_table *next;
69102 -};
69103 +} __do_const;
69104
69105 /* this value hold the maximum octet of charset */
69106 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
69107 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
69108 index d65746e..62e72c2 100644
69109 --- a/include/linux/notifier.h
69110 +++ b/include/linux/notifier.h
69111 @@ -51,7 +51,8 @@ struct notifier_block {
69112 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
69113 struct notifier_block __rcu *next;
69114 int priority;
69115 -};
69116 +} __do_const;
69117 +typedef struct notifier_block __no_const notifier_block_no_const;
69118
69119 struct atomic_notifier_head {
69120 spinlock_t lock;
69121 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
69122 index a4c5624..79d6d88 100644
69123 --- a/include/linux/oprofile.h
69124 +++ b/include/linux/oprofile.h
69125 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
69126 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
69127 char const * name, ulong * val);
69128
69129 -/** Create a file for read-only access to an atomic_t. */
69130 +/** Create a file for read-only access to an atomic_unchecked_t. */
69131 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
69132 - char const * name, atomic_t * val);
69133 + char const * name, atomic_unchecked_t * val);
69134
69135 /** create a directory */
69136 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
69137 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
69138 index 45fc162..01a4068 100644
69139 --- a/include/linux/pci_hotplug.h
69140 +++ b/include/linux/pci_hotplug.h
69141 @@ -80,7 +80,8 @@ struct hotplug_slot_ops {
69142 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
69143 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
69144 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
69145 -};
69146 +} __do_const;
69147 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
69148
69149 /**
69150 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
69151 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
69152 index 6bfb2faa..e5bc5e5 100644
69153 --- a/include/linux/perf_event.h
69154 +++ b/include/linux/perf_event.h
69155 @@ -328,8 +328,8 @@ struct perf_event {
69156
69157 enum perf_event_active_state state;
69158 unsigned int attach_state;
69159 - local64_t count;
69160 - atomic64_t child_count;
69161 + local64_t count; /* PaX: fix it one day */
69162 + atomic64_unchecked_t child_count;
69163
69164 /*
69165 * These are the total time in nanoseconds that the event
69166 @@ -380,8 +380,8 @@ struct perf_event {
69167 * These accumulate total time (in nanoseconds) that children
69168 * events have been enabled and running, respectively.
69169 */
69170 - atomic64_t child_total_time_enabled;
69171 - atomic64_t child_total_time_running;
69172 + atomic64_unchecked_t child_total_time_enabled;
69173 + atomic64_unchecked_t child_total_time_running;
69174
69175 /*
69176 * Protect attach/detach and child_list:
69177 @@ -801,7 +801,7 @@ static inline void perf_event_task_tick(void) { }
69178 */
69179 #define perf_cpu_notifier(fn) \
69180 do { \
69181 - static struct notifier_block fn##_nb __cpuinitdata = \
69182 + static struct notifier_block fn##_nb = \
69183 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
69184 unsigned long cpu = smp_processor_id(); \
69185 unsigned long flags; \
69186 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
69187 index ad1a427..6419649 100644
69188 --- a/include/linux/pipe_fs_i.h
69189 +++ b/include/linux/pipe_fs_i.h
69190 @@ -45,9 +45,9 @@ struct pipe_buffer {
69191 struct pipe_inode_info {
69192 wait_queue_head_t wait;
69193 unsigned int nrbufs, curbuf, buffers;
69194 - unsigned int readers;
69195 - unsigned int writers;
69196 - unsigned int waiting_writers;
69197 + atomic_t readers;
69198 + atomic_t writers;
69199 + atomic_t waiting_writers;
69200 unsigned int r_counter;
69201 unsigned int w_counter;
69202 struct page *tmp_page;
69203 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
69204 index 5f28cae..3d23723 100644
69205 --- a/include/linux/platform_data/usb-ehci-s5p.h
69206 +++ b/include/linux/platform_data/usb-ehci-s5p.h
69207 @@ -14,7 +14,7 @@
69208 struct s5p_ehci_platdata {
69209 int (*phy_init)(struct platform_device *pdev, int type);
69210 int (*phy_exit)(struct platform_device *pdev, int type);
69211 -};
69212 +} __no_const;
69213
69214 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
69215
69216 diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
69217 index c256c59..8ea94c7 100644
69218 --- a/include/linux/platform_data/usb-exynos.h
69219 +++ b/include/linux/platform_data/usb-exynos.h
69220 @@ -14,7 +14,7 @@
69221 struct exynos4_ohci_platdata {
69222 int (*phy_init)(struct platform_device *pdev, int type);
69223 int (*phy_exit)(struct platform_device *pdev, int type);
69224 -};
69225 +} __no_const;
69226
69227 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
69228
69229 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
69230 index f271860..6b3bec5 100644
69231 --- a/include/linux/pm_runtime.h
69232 +++ b/include/linux/pm_runtime.h
69233 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
69234
69235 static inline void pm_runtime_mark_last_busy(struct device *dev)
69236 {
69237 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
69238 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
69239 }
69240
69241 #else /* !CONFIG_PM_RUNTIME */
69242 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
69243 index 195aafc..49a7bc2 100644
69244 --- a/include/linux/pnp.h
69245 +++ b/include/linux/pnp.h
69246 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
69247 struct pnp_fixup {
69248 char id[7];
69249 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
69250 -};
69251 +} __do_const;
69252
69253 /* config parameters */
69254 #define PNP_CONFIG_NORMAL 0x0001
69255 diff --git a/include/linux/poison.h b/include/linux/poison.h
69256 index 2110a81..13a11bb 100644
69257 --- a/include/linux/poison.h
69258 +++ b/include/linux/poison.h
69259 @@ -19,8 +19,8 @@
69260 * under normal circumstances, used to verify that nobody uses
69261 * non-initialized list entries.
69262 */
69263 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
69264 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
69265 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
69266 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
69267
69268 /********** include/linux/timer.h **********/
69269 /*
69270 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
69271 index c0f44c2..1572583 100644
69272 --- a/include/linux/power/smartreflex.h
69273 +++ b/include/linux/power/smartreflex.h
69274 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
69275 int (*notify)(struct omap_sr *sr, u32 status);
69276 u8 notify_flags;
69277 u8 class_type;
69278 -};
69279 +} __do_const;
69280
69281 /**
69282 * struct omap_sr_nvalue_table - Smartreflex n-target value info
69283 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
69284 index 4ea1d37..80f4b33 100644
69285 --- a/include/linux/ppp-comp.h
69286 +++ b/include/linux/ppp-comp.h
69287 @@ -84,7 +84,7 @@ struct compressor {
69288 struct module *owner;
69289 /* Extra skb space needed by the compressor algorithm */
69290 unsigned int comp_extra;
69291 -};
69292 +} __do_const;
69293
69294 /*
69295 * The return value from decompress routine is the length of the
69296 diff --git a/include/linux/printk.h b/include/linux/printk.h
69297 index 9afc01e..92c32e8 100644
69298 --- a/include/linux/printk.h
69299 +++ b/include/linux/printk.h
69300 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
69301 extern int printk_needs_cpu(int cpu);
69302 extern void printk_tick(void);
69303
69304 +extern int kptr_restrict;
69305 +
69306 #ifdef CONFIG_PRINTK
69307 asmlinkage __printf(5, 0)
69308 int vprintk_emit(int facility, int level,
69309 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
69310
69311 extern int printk_delay_msec;
69312 extern int dmesg_restrict;
69313 -extern int kptr_restrict;
69314
69315 void log_buf_kexec_setup(void);
69316 void __init setup_log_buf(int early);
69317 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
69318 index 32676b3..8f7a182 100644
69319 --- a/include/linux/proc_fs.h
69320 +++ b/include/linux/proc_fs.h
69321 @@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
69322 return proc_create_data(name, mode, parent, proc_fops, NULL);
69323 }
69324
69325 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
69326 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
69327 +{
69328 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69329 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
69330 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69331 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
69332 +#else
69333 + return proc_create_data(name, mode, parent, proc_fops, NULL);
69334 +#endif
69335 +}
69336 +
69337 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
69338 umode_t mode, struct proc_dir_entry *base,
69339 read_proc_t *read_proc, void * data)
69340 diff --git a/include/linux/random.h b/include/linux/random.h
69341 index d984608..d6f0042 100644
69342 --- a/include/linux/random.h
69343 +++ b/include/linux/random.h
69344 @@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
69345 u32 prandom_u32_state(struct rnd_state *);
69346 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
69347
69348 +static inline unsigned long pax_get_random_long(void)
69349 +{
69350 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
69351 +}
69352 +
69353 /*
69354 * Handle minimum values for seeds
69355 */
69356 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
69357 index c92dd28..08f4eab 100644
69358 --- a/include/linux/rculist.h
69359 +++ b/include/linux/rculist.h
69360 @@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
69361 struct list_head *prev, struct list_head *next);
69362 #endif
69363
69364 +extern void __pax_list_add_rcu(struct list_head *new,
69365 + struct list_head *prev, struct list_head *next);
69366 +
69367 /**
69368 * list_add_rcu - add a new entry to rcu-protected list
69369 * @new: new entry to be added
69370 @@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
69371 __list_add_rcu(new, head, head->next);
69372 }
69373
69374 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
69375 +{
69376 + __pax_list_add_rcu(new, head, head->next);
69377 +}
69378 +
69379 /**
69380 * list_add_tail_rcu - add a new entry to rcu-protected list
69381 * @new: new entry to be added
69382 @@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
69383 __list_add_rcu(new, head->prev, head);
69384 }
69385
69386 +static inline void pax_list_add_tail_rcu(struct list_head *new,
69387 + struct list_head *head)
69388 +{
69389 + __pax_list_add_rcu(new, head->prev, head);
69390 +}
69391 +
69392 /**
69393 * list_del_rcu - deletes entry from list without re-initialization
69394 * @entry: the element to delete from the list.
69395 @@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
69396 entry->prev = LIST_POISON2;
69397 }
69398
69399 +extern void pax_list_del_rcu(struct list_head *entry);
69400 +
69401 /**
69402 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
69403 * @n: the element to delete from the hash list.
69404 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
69405 index 23b3630..e1bc12b 100644
69406 --- a/include/linux/reboot.h
69407 +++ b/include/linux/reboot.h
69408 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
69409 * Architecture-specific implementations of sys_reboot commands.
69410 */
69411
69412 -extern void machine_restart(char *cmd);
69413 -extern void machine_halt(void);
69414 -extern void machine_power_off(void);
69415 +extern void machine_restart(char *cmd) __noreturn;
69416 +extern void machine_halt(void) __noreturn;
69417 +extern void machine_power_off(void) __noreturn;
69418
69419 extern void machine_shutdown(void);
69420 struct pt_regs;
69421 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
69422 */
69423
69424 extern void kernel_restart_prepare(char *cmd);
69425 -extern void kernel_restart(char *cmd);
69426 -extern void kernel_halt(void);
69427 -extern void kernel_power_off(void);
69428 +extern void kernel_restart(char *cmd) __noreturn;
69429 +extern void kernel_halt(void) __noreturn;
69430 +extern void kernel_power_off(void) __noreturn;
69431
69432 extern int C_A_D; /* for sysctl */
69433 void ctrl_alt_del(void);
69434 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
69435 * Emergency restart, callable from an interrupt handler.
69436 */
69437
69438 -extern void emergency_restart(void);
69439 +extern void emergency_restart(void) __noreturn;
69440 #include <asm/emergency-restart.h>
69441
69442 #endif /* _LINUX_REBOOT_H */
69443 diff --git a/include/linux/regset.h b/include/linux/regset.h
69444 index 8e0c9fe..ac4d221 100644
69445 --- a/include/linux/regset.h
69446 +++ b/include/linux/regset.h
69447 @@ -161,7 +161,8 @@ struct user_regset {
69448 unsigned int align;
69449 unsigned int bias;
69450 unsigned int core_note_type;
69451 -};
69452 +} __do_const;
69453 +typedef struct user_regset __no_const user_regset_no_const;
69454
69455 /**
69456 * struct user_regset_view - available regsets
69457 diff --git a/include/linux/relay.h b/include/linux/relay.h
69458 index 91cacc3..b55ff74 100644
69459 --- a/include/linux/relay.h
69460 +++ b/include/linux/relay.h
69461 @@ -160,7 +160,7 @@ struct rchan_callbacks
69462 * The callback should return 0 if successful, negative if not.
69463 */
69464 int (*remove_buf_file)(struct dentry *dentry);
69465 -};
69466 +} __no_const;
69467
69468 /*
69469 * CONFIG_RELAY kernel API, kernel/relay.c
69470 diff --git a/include/linux/rio.h b/include/linux/rio.h
69471 index a3e7842..d973ca6 100644
69472 --- a/include/linux/rio.h
69473 +++ b/include/linux/rio.h
69474 @@ -339,7 +339,7 @@ struct rio_ops {
69475 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
69476 u64 rstart, u32 size, u32 flags);
69477 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
69478 -};
69479 +} __no_const;
69480
69481 #define RIO_RESOURCE_MEM 0x00000100
69482 #define RIO_RESOURCE_DOORBELL 0x00000200
69483 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
69484 index c20635c..2f5def4 100644
69485 --- a/include/linux/rmap.h
69486 +++ b/include/linux/rmap.h
69487 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
69488 void anon_vma_init(void); /* create anon_vma_cachep */
69489 int anon_vma_prepare(struct vm_area_struct *);
69490 void unlink_anon_vmas(struct vm_area_struct *);
69491 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
69492 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
69493 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
69494 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
69495
69496 static inline void anon_vma_merge(struct vm_area_struct *vma,
69497 struct vm_area_struct *next)
69498 diff --git a/include/linux/sched.h b/include/linux/sched.h
69499 index d211247..a5cbf38b 100644
69500 --- a/include/linux/sched.h
69501 +++ b/include/linux/sched.h
69502 @@ -61,6 +61,7 @@ struct bio_list;
69503 struct fs_struct;
69504 struct perf_event_context;
69505 struct blk_plug;
69506 +struct linux_binprm;
69507
69508 /*
69509 * List of flags we want to share for kernel threads,
69510 @@ -354,10 +355,23 @@ struct user_namespace;
69511 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
69512
69513 extern int sysctl_max_map_count;
69514 +extern unsigned long sysctl_heap_stack_gap;
69515
69516 #include <linux/aio.h>
69517
69518 #ifdef CONFIG_MMU
69519 +
69520 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
69521 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
69522 +#else
69523 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
69524 +{
69525 + return 0;
69526 +}
69527 +#endif
69528 +
69529 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
69530 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
69531 extern void arch_pick_mmap_layout(struct mm_struct *mm);
69532 extern unsigned long
69533 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
69534 @@ -639,6 +653,17 @@ struct signal_struct {
69535 #ifdef CONFIG_TASKSTATS
69536 struct taskstats *stats;
69537 #endif
69538 +
69539 +#ifdef CONFIG_GRKERNSEC
69540 + u32 curr_ip;
69541 + u32 saved_ip;
69542 + u32 gr_saddr;
69543 + u32 gr_daddr;
69544 + u16 gr_sport;
69545 + u16 gr_dport;
69546 + u8 used_accept:1;
69547 +#endif
69548 +
69549 #ifdef CONFIG_AUDIT
69550 unsigned audit_tty;
69551 struct tty_audit_buf *tty_audit_buf;
69552 @@ -717,6 +742,11 @@ struct user_struct {
69553 struct key *session_keyring; /* UID's default session keyring */
69554 #endif
69555
69556 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
69557 + unsigned int banned;
69558 + unsigned long ban_expires;
69559 +#endif
69560 +
69561 /* Hash table maintenance information */
69562 struct hlist_node uidhash_node;
69563 kuid_t uid;
69564 @@ -1116,7 +1146,7 @@ struct sched_class {
69565 #ifdef CONFIG_FAIR_GROUP_SCHED
69566 void (*task_move_group) (struct task_struct *p, int on_rq);
69567 #endif
69568 -};
69569 +} __do_const;
69570
69571 struct load_weight {
69572 unsigned long weight, inv_weight;
69573 @@ -1360,8 +1390,8 @@ struct task_struct {
69574 struct list_head thread_group;
69575
69576 struct completion *vfork_done; /* for vfork() */
69577 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
69578 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
69579 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
69580 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
69581
69582 cputime_t utime, stime, utimescaled, stimescaled;
69583 cputime_t gtime;
69584 @@ -1377,11 +1407,6 @@ struct task_struct {
69585 struct task_cputime cputime_expires;
69586 struct list_head cpu_timers[3];
69587
69588 -/* process credentials */
69589 - const struct cred __rcu *real_cred; /* objective and real subjective task
69590 - * credentials (COW) */
69591 - const struct cred __rcu *cred; /* effective (overridable) subjective task
69592 - * credentials (COW) */
69593 char comm[TASK_COMM_LEN]; /* executable name excluding path
69594 - access with [gs]et_task_comm (which lock
69595 it with task_lock())
69596 @@ -1398,6 +1423,10 @@ struct task_struct {
69597 #endif
69598 /* CPU-specific state of this task */
69599 struct thread_struct thread;
69600 +/* thread_info moved to task_struct */
69601 +#ifdef CONFIG_X86
69602 + struct thread_info tinfo;
69603 +#endif
69604 /* filesystem information */
69605 struct fs_struct *fs;
69606 /* open file information */
69607 @@ -1471,6 +1500,10 @@ struct task_struct {
69608 gfp_t lockdep_reclaim_gfp;
69609 #endif
69610
69611 +/* process credentials */
69612 + const struct cred __rcu *real_cred; /* objective and real subjective task
69613 + * credentials (COW) */
69614 +
69615 /* journalling filesystem info */
69616 void *journal_info;
69617
69618 @@ -1509,6 +1542,10 @@ struct task_struct {
69619 /* cg_list protected by css_set_lock and tsk->alloc_lock */
69620 struct list_head cg_list;
69621 #endif
69622 +
69623 + const struct cred __rcu *cred; /* effective (overridable) subjective task
69624 + * credentials (COW) */
69625 +
69626 #ifdef CONFIG_FUTEX
69627 struct robust_list_head __user *robust_list;
69628 #ifdef CONFIG_COMPAT
69629 @@ -1605,8 +1642,74 @@ struct task_struct {
69630 #ifdef CONFIG_UPROBES
69631 struct uprobe_task *utask;
69632 #endif
69633 +
69634 +#ifdef CONFIG_GRKERNSEC
69635 + /* grsecurity */
69636 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
69637 + u64 exec_id;
69638 +#endif
69639 +#ifdef CONFIG_GRKERNSEC_SETXID
69640 + const struct cred *delayed_cred;
69641 +#endif
69642 + struct dentry *gr_chroot_dentry;
69643 + struct acl_subject_label *acl;
69644 + struct acl_role_label *role;
69645 + struct file *exec_file;
69646 + unsigned long brute_expires;
69647 + u16 acl_role_id;
69648 + /* is this the task that authenticated to the special role */
69649 + u8 acl_sp_role;
69650 + u8 is_writable;
69651 + u8 brute;
69652 + u8 gr_is_chrooted;
69653 +#endif
69654 +
69655 };
69656
69657 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
69658 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
69659 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
69660 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
69661 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
69662 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
69663 +
69664 +#ifdef CONFIG_PAX_SOFTMODE
69665 +extern int pax_softmode;
69666 +#endif
69667 +
69668 +extern int pax_check_flags(unsigned long *);
69669 +
69670 +/* if tsk != current then task_lock must be held on it */
69671 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
69672 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
69673 +{
69674 + if (likely(tsk->mm))
69675 + return tsk->mm->pax_flags;
69676 + else
69677 + return 0UL;
69678 +}
69679 +
69680 +/* if tsk != current then task_lock must be held on it */
69681 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
69682 +{
69683 + if (likely(tsk->mm)) {
69684 + tsk->mm->pax_flags = flags;
69685 + return 0;
69686 + }
69687 + return -EINVAL;
69688 +}
69689 +#endif
69690 +
69691 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
69692 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
69693 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
69694 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
69695 +#endif
69696 +
69697 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
69698 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
69699 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
69700 +
69701 /* Future-safe accessor for struct task_struct's cpus_allowed. */
69702 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
69703
69704 @@ -1696,7 +1799,7 @@ struct pid_namespace;
69705 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
69706 struct pid_namespace *ns);
69707
69708 -static inline pid_t task_pid_nr(struct task_struct *tsk)
69709 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
69710 {
69711 return tsk->pid;
69712 }
69713 @@ -2155,7 +2258,9 @@ void yield(void);
69714 extern struct exec_domain default_exec_domain;
69715
69716 union thread_union {
69717 +#ifndef CONFIG_X86
69718 struct thread_info thread_info;
69719 +#endif
69720 unsigned long stack[THREAD_SIZE/sizeof(long)];
69721 };
69722
69723 @@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
69724 */
69725
69726 extern struct task_struct *find_task_by_vpid(pid_t nr);
69727 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
69728 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
69729 struct pid_namespace *ns);
69730
69731 @@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
69732 extern void exit_itimers(struct signal_struct *);
69733 extern void flush_itimer_signals(void);
69734
69735 -extern void do_group_exit(int);
69736 +extern __noreturn void do_group_exit(int);
69737
69738 extern int allow_signal(int);
69739 extern int disallow_signal(int);
69740 @@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
69741
69742 #endif
69743
69744 -static inline int object_is_on_stack(void *obj)
69745 +static inline int object_starts_on_stack(void *obj)
69746 {
69747 - void *stack = task_stack_page(current);
69748 + const void *stack = task_stack_page(current);
69749
69750 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
69751 }
69752 diff --git a/include/linux/security.h b/include/linux/security.h
69753 index eee7478..290f7ba 100644
69754 --- a/include/linux/security.h
69755 +++ b/include/linux/security.h
69756 @@ -26,6 +26,7 @@
69757 #include <linux/capability.h>
69758 #include <linux/slab.h>
69759 #include <linux/err.h>
69760 +#include <linux/grsecurity.h>
69761
69762 struct linux_binprm;
69763 struct cred;
69764 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
69765 index 68a04a3..866e6a1 100644
69766 --- a/include/linux/seq_file.h
69767 +++ b/include/linux/seq_file.h
69768 @@ -26,6 +26,9 @@ struct seq_file {
69769 struct mutex lock;
69770 const struct seq_operations *op;
69771 int poll_event;
69772 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
69773 + u64 exec_id;
69774 +#endif
69775 #ifdef CONFIG_USER_NS
69776 struct user_namespace *user_ns;
69777 #endif
69778 @@ -38,6 +41,7 @@ struct seq_operations {
69779 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
69780 int (*show) (struct seq_file *m, void *v);
69781 };
69782 +typedef struct seq_operations __no_const seq_operations_no_const;
69783
69784 #define SEQ_SKIP 1
69785
69786 diff --git a/include/linux/shm.h b/include/linux/shm.h
69787 index 429c199..4d42e38 100644
69788 --- a/include/linux/shm.h
69789 +++ b/include/linux/shm.h
69790 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
69791
69792 /* The task created the shm object. NULL if the task is dead. */
69793 struct task_struct *shm_creator;
69794 +#ifdef CONFIG_GRKERNSEC
69795 + time_t shm_createtime;
69796 + pid_t shm_lapid;
69797 +#endif
69798 };
69799
69800 /* shm_mode upper byte flags */
69801 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
69802 index 320e976..fd52553 100644
69803 --- a/include/linux/skbuff.h
69804 +++ b/include/linux/skbuff.h
69805 @@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
69806 extern struct sk_buff *__alloc_skb(unsigned int size,
69807 gfp_t priority, int flags, int node);
69808 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
69809 -static inline struct sk_buff *alloc_skb(unsigned int size,
69810 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
69811 gfp_t priority)
69812 {
69813 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
69814 @@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
69815 */
69816 static inline int skb_queue_empty(const struct sk_buff_head *list)
69817 {
69818 - return list->next == (struct sk_buff *)list;
69819 + return list->next == (const struct sk_buff *)list;
69820 }
69821
69822 /**
69823 @@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
69824 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
69825 const struct sk_buff *skb)
69826 {
69827 - return skb->next == (struct sk_buff *)list;
69828 + return skb->next == (const struct sk_buff *)list;
69829 }
69830
69831 /**
69832 @@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
69833 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
69834 const struct sk_buff *skb)
69835 {
69836 - return skb->prev == (struct sk_buff *)list;
69837 + return skb->prev == (const struct sk_buff *)list;
69838 }
69839
69840 /**
69841 @@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
69842 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
69843 */
69844 #ifndef NET_SKB_PAD
69845 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
69846 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
69847 #endif
69848
69849 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
69850 @@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
69851 int noblock, int *err);
69852 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
69853 struct poll_table_struct *wait);
69854 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
69855 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
69856 int offset, struct iovec *to,
69857 int size);
69858 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
69859 diff --git a/include/linux/slab.h b/include/linux/slab.h
69860 index 5d168d7..720bff3 100644
69861 --- a/include/linux/slab.h
69862 +++ b/include/linux/slab.h
69863 @@ -12,13 +12,20 @@
69864 #include <linux/gfp.h>
69865 #include <linux/types.h>
69866 #include <linux/workqueue.h>
69867 -
69868 +#include <linux/err.h>
69869
69870 /*
69871 * Flags to pass to kmem_cache_create().
69872 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
69873 */
69874 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
69875 +
69876 +#ifdef CONFIG_PAX_USERCOPY_SLABS
69877 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
69878 +#else
69879 +#define SLAB_USERCOPY 0x00000000UL
69880 +#endif
69881 +
69882 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
69883 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
69884 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
69885 @@ -89,10 +96,13 @@
69886 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
69887 * Both make kfree a no-op.
69888 */
69889 -#define ZERO_SIZE_PTR ((void *)16)
69890 +#define ZERO_SIZE_PTR \
69891 +({ \
69892 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
69893 + (void *)(-MAX_ERRNO-1L); \
69894 +})
69895
69896 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
69897 - (unsigned long)ZERO_SIZE_PTR)
69898 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
69899
69900 /*
69901 * Common fields provided in kmem_cache by all slab allocators
69902 @@ -112,7 +122,7 @@ struct kmem_cache {
69903 unsigned int align; /* Alignment as calculated */
69904 unsigned long flags; /* Active flags on the slab */
69905 const char *name; /* Slab name for sysfs */
69906 - int refcount; /* Use counter */
69907 + atomic_t refcount; /* Use counter */
69908 void (*ctor)(void *); /* Called on object slot creation */
69909 struct list_head list; /* List of all slab caches on the system */
69910 };
69911 @@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
69912 void kfree(const void *);
69913 void kzfree(const void *);
69914 size_t ksize(const void *);
69915 +const char *check_heap_object(const void *ptr, unsigned long n);
69916 +bool is_usercopy_object(const void *ptr);
69917
69918 /*
69919 * Allocator specific definitions. These are mainly used to establish optimized
69920 @@ -311,6 +323,7 @@ size_t ksize(const void *);
69921 * for general use, and so are not documented here. For a full list of
69922 * potential flags, always refer to linux/gfp.h.
69923 */
69924 +
69925 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
69926 {
69927 if (size != 0 && n > SIZE_MAX / size)
69928 @@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
69929 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
69930 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
69931 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
69932 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
69933 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
69934 #define kmalloc_track_caller(size, flags) \
69935 __kmalloc_track_caller(size, flags, _RET_IP_)
69936 #else
69937 @@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
69938 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
69939 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
69940 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
69941 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
69942 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
69943 #define kmalloc_node_track_caller(size, flags, node) \
69944 __kmalloc_node_track_caller(size, flags, node, \
69945 _RET_IP_)
69946 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
69947 index 8bb6e0e..8eb0dbe 100644
69948 --- a/include/linux/slab_def.h
69949 +++ b/include/linux/slab_def.h
69950 @@ -52,7 +52,7 @@ struct kmem_cache {
69951 /* 4) cache creation/removal */
69952 const char *name;
69953 struct list_head list;
69954 - int refcount;
69955 + atomic_t refcount;
69956 int object_size;
69957 int align;
69958
69959 @@ -68,10 +68,10 @@ struct kmem_cache {
69960 unsigned long node_allocs;
69961 unsigned long node_frees;
69962 unsigned long node_overflow;
69963 - atomic_t allochit;
69964 - atomic_t allocmiss;
69965 - atomic_t freehit;
69966 - atomic_t freemiss;
69967 + atomic_unchecked_t allochit;
69968 + atomic_unchecked_t allocmiss;
69969 + atomic_unchecked_t freehit;
69970 + atomic_unchecked_t freemiss;
69971
69972 /*
69973 * If debugging is enabled, then the allocator can add additional
69974 @@ -111,11 +111,16 @@ struct cache_sizes {
69975 #ifdef CONFIG_ZONE_DMA
69976 struct kmem_cache *cs_dmacachep;
69977 #endif
69978 +
69979 +#ifdef CONFIG_PAX_USERCOPY_SLABS
69980 + struct kmem_cache *cs_usercopycachep;
69981 +#endif
69982 +
69983 };
69984 extern struct cache_sizes malloc_sizes[];
69985
69986 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
69987 -void *__kmalloc(size_t size, gfp_t flags);
69988 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
69989
69990 #ifdef CONFIG_TRACING
69991 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
69992 @@ -152,6 +157,13 @@ found:
69993 cachep = malloc_sizes[i].cs_dmacachep;
69994 else
69995 #endif
69996 +
69997 +#ifdef CONFIG_PAX_USERCOPY_SLABS
69998 + if (flags & GFP_USERCOPY)
69999 + cachep = malloc_sizes[i].cs_usercopycachep;
70000 + else
70001 +#endif
70002 +
70003 cachep = malloc_sizes[i].cs_cachep;
70004
70005 ret = kmem_cache_alloc_trace(cachep, flags, size);
70006 @@ -162,7 +174,7 @@ found:
70007 }
70008
70009 #ifdef CONFIG_NUMA
70010 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
70011 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70012 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70013
70014 #ifdef CONFIG_TRACING
70015 @@ -205,6 +217,13 @@ found:
70016 cachep = malloc_sizes[i].cs_dmacachep;
70017 else
70018 #endif
70019 +
70020 +#ifdef CONFIG_PAX_USERCOPY_SLABS
70021 + if (flags & GFP_USERCOPY)
70022 + cachep = malloc_sizes[i].cs_usercopycachep;
70023 + else
70024 +#endif
70025 +
70026 cachep = malloc_sizes[i].cs_cachep;
70027
70028 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
70029 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
70030 index f28e14a..7831211 100644
70031 --- a/include/linux/slob_def.h
70032 +++ b/include/linux/slob_def.h
70033 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
70034 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
70035 }
70036
70037 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
70038 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70039
70040 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
70041 {
70042 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70043 return __kmalloc_node(size, flags, NUMA_NO_NODE);
70044 }
70045
70046 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
70047 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
70048 {
70049 return kmalloc(size, flags);
70050 }
70051 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
70052 index 9db4825..ed42fb5 100644
70053 --- a/include/linux/slub_def.h
70054 +++ b/include/linux/slub_def.h
70055 @@ -91,7 +91,7 @@ struct kmem_cache {
70056 struct kmem_cache_order_objects max;
70057 struct kmem_cache_order_objects min;
70058 gfp_t allocflags; /* gfp flags to use on each alloc */
70059 - int refcount; /* Refcount for slab cache destroy */
70060 + atomic_t refcount; /* Refcount for slab cache destroy */
70061 void (*ctor)(void *);
70062 int inuse; /* Offset to metadata */
70063 int align; /* Alignment */
70064 @@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
70065 * Sorry that the following has to be that ugly but some versions of GCC
70066 * have trouble with constant propagation and loops.
70067 */
70068 -static __always_inline int kmalloc_index(size_t size)
70069 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
70070 {
70071 if (!size)
70072 return 0;
70073 @@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
70074 }
70075
70076 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70077 -void *__kmalloc(size_t size, gfp_t flags);
70078 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
70079
70080 static __always_inline void *
70081 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
70082 @@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
70083 }
70084 #endif
70085
70086 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
70087 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
70088 {
70089 unsigned int order = get_order(size);
70090 return kmalloc_order_trace(size, flags, order);
70091 @@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70092 }
70093
70094 #ifdef CONFIG_NUMA
70095 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
70096 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70097 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70098
70099 #ifdef CONFIG_TRACING
70100 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
70101 index e8d702e..0a56eb4 100644
70102 --- a/include/linux/sock_diag.h
70103 +++ b/include/linux/sock_diag.h
70104 @@ -10,7 +10,7 @@ struct sock;
70105 struct sock_diag_handler {
70106 __u8 family;
70107 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
70108 -};
70109 +} __do_const;
70110
70111 int sock_diag_register(const struct sock_diag_handler *h);
70112 void sock_diag_unregister(const struct sock_diag_handler *h);
70113 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
70114 index 680f9a3..f13aeb0 100644
70115 --- a/include/linux/sonet.h
70116 +++ b/include/linux/sonet.h
70117 @@ -7,7 +7,7 @@
70118 #include <uapi/linux/sonet.h>
70119
70120 struct k_sonet_stats {
70121 -#define __HANDLE_ITEM(i) atomic_t i
70122 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
70123 __SONET_ITEMS
70124 #undef __HANDLE_ITEM
70125 };
70126 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
70127 index 34206b8..3db7f1c 100644
70128 --- a/include/linux/sunrpc/clnt.h
70129 +++ b/include/linux/sunrpc/clnt.h
70130 @@ -96,7 +96,7 @@ struct rpc_procinfo {
70131 unsigned int p_timer; /* Which RTT timer to use */
70132 u32 p_statidx; /* Which procedure to account */
70133 const char * p_name; /* name of procedure */
70134 -};
70135 +} __do_const;
70136
70137 #ifdef __KERNEL__
70138
70139 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
70140 {
70141 switch (sap->sa_family) {
70142 case AF_INET:
70143 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
70144 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
70145 case AF_INET6:
70146 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
70147 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
70148 }
70149 return 0;
70150 }
70151 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
70152 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
70153 const struct sockaddr *src)
70154 {
70155 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
70156 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
70157 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
70158
70159 dsin->sin_family = ssin->sin_family;
70160 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
70161 if (sa->sa_family != AF_INET6)
70162 return 0;
70163
70164 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
70165 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
70166 }
70167
70168 #endif /* __KERNEL__ */
70169 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
70170 index 676ddf5..4c519a1 100644
70171 --- a/include/linux/sunrpc/svc.h
70172 +++ b/include/linux/sunrpc/svc.h
70173 @@ -410,7 +410,7 @@ struct svc_procedure {
70174 unsigned int pc_count; /* call count */
70175 unsigned int pc_cachetype; /* cache info (NFS) */
70176 unsigned int pc_xdrressize; /* maximum size of XDR reply */
70177 -};
70178 +} __do_const;
70179
70180 /*
70181 * Function prototypes.
70182 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
70183 index 0b8e3e6..33e0a01 100644
70184 --- a/include/linux/sunrpc/svc_rdma.h
70185 +++ b/include/linux/sunrpc/svc_rdma.h
70186 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
70187 extern unsigned int svcrdma_max_requests;
70188 extern unsigned int svcrdma_max_req_size;
70189
70190 -extern atomic_t rdma_stat_recv;
70191 -extern atomic_t rdma_stat_read;
70192 -extern atomic_t rdma_stat_write;
70193 -extern atomic_t rdma_stat_sq_starve;
70194 -extern atomic_t rdma_stat_rq_starve;
70195 -extern atomic_t rdma_stat_rq_poll;
70196 -extern atomic_t rdma_stat_rq_prod;
70197 -extern atomic_t rdma_stat_sq_poll;
70198 -extern atomic_t rdma_stat_sq_prod;
70199 +extern atomic_unchecked_t rdma_stat_recv;
70200 +extern atomic_unchecked_t rdma_stat_read;
70201 +extern atomic_unchecked_t rdma_stat_write;
70202 +extern atomic_unchecked_t rdma_stat_sq_starve;
70203 +extern atomic_unchecked_t rdma_stat_rq_starve;
70204 +extern atomic_unchecked_t rdma_stat_rq_poll;
70205 +extern atomic_unchecked_t rdma_stat_rq_prod;
70206 +extern atomic_unchecked_t rdma_stat_sq_poll;
70207 +extern atomic_unchecked_t rdma_stat_sq_prod;
70208
70209 #define RPCRDMA_VERSION 1
70210
70211 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
70212 index dd74084a..7f509d5 100644
70213 --- a/include/linux/sunrpc/svcauth.h
70214 +++ b/include/linux/sunrpc/svcauth.h
70215 @@ -109,7 +109,7 @@ struct auth_ops {
70216 int (*release)(struct svc_rqst *rq);
70217 void (*domain_release)(struct auth_domain *);
70218 int (*set_client)(struct svc_rqst *rq);
70219 -};
70220 +} __do_const;
70221
70222 #define SVC_GARBAGE 1
70223 #define SVC_SYSERR 2
70224 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
70225 index 071d62c..4ccc7ac 100644
70226 --- a/include/linux/swiotlb.h
70227 +++ b/include/linux/swiotlb.h
70228 @@ -59,7 +59,8 @@ extern void
70229
70230 extern void
70231 swiotlb_free_coherent(struct device *hwdev, size_t size,
70232 - void *vaddr, dma_addr_t dma_handle);
70233 + void *vaddr, dma_addr_t dma_handle,
70234 + struct dma_attrs *attrs);
70235
70236 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
70237 unsigned long offset, size_t size,
70238 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
70239 index 27b3b0b..e093dd9 100644
70240 --- a/include/linux/syscore_ops.h
70241 +++ b/include/linux/syscore_ops.h
70242 @@ -16,7 +16,7 @@ struct syscore_ops {
70243 int (*suspend)(void);
70244 void (*resume)(void);
70245 void (*shutdown)(void);
70246 -};
70247 +} __do_const;
70248
70249 extern void register_syscore_ops(struct syscore_ops *ops);
70250 extern void unregister_syscore_ops(struct syscore_ops *ops);
70251 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
70252 index 14a8ff2..af52bad 100644
70253 --- a/include/linux/sysctl.h
70254 +++ b/include/linux/sysctl.h
70255 @@ -34,13 +34,13 @@ struct ctl_table_root;
70256 struct ctl_table_header;
70257 struct ctl_dir;
70258
70259 -typedef struct ctl_table ctl_table;
70260 -
70261 typedef int proc_handler (struct ctl_table *ctl, int write,
70262 void __user *buffer, size_t *lenp, loff_t *ppos);
70263
70264 extern int proc_dostring(struct ctl_table *, int,
70265 void __user *, size_t *, loff_t *);
70266 +extern int proc_dostring_modpriv(struct ctl_table *, int,
70267 + void __user *, size_t *, loff_t *);
70268 extern int proc_dointvec(struct ctl_table *, int,
70269 void __user *, size_t *, loff_t *);
70270 extern int proc_dointvec_minmax(struct ctl_table *, int,
70271 @@ -115,7 +115,9 @@ struct ctl_table
70272 struct ctl_table_poll *poll;
70273 void *extra1;
70274 void *extra2;
70275 -};
70276 +} __do_const;
70277 +typedef struct ctl_table __no_const ctl_table_no_const;
70278 +typedef struct ctl_table ctl_table;
70279
70280 struct ctl_node {
70281 struct rb_node node;
70282 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
70283 index 381f06d..dc16cc7 100644
70284 --- a/include/linux/sysfs.h
70285 +++ b/include/linux/sysfs.h
70286 @@ -31,7 +31,8 @@ struct attribute {
70287 struct lock_class_key *key;
70288 struct lock_class_key skey;
70289 #endif
70290 -};
70291 +} __do_const;
70292 +typedef struct attribute __no_const attribute_no_const;
70293
70294 /**
70295 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
70296 @@ -59,8 +60,8 @@ struct attribute_group {
70297 umode_t (*is_visible)(struct kobject *,
70298 struct attribute *, int);
70299 struct attribute **attrs;
70300 -};
70301 -
70302 +} __do_const;
70303 +typedef struct attribute_group __no_const attribute_group_no_const;
70304
70305
70306 /**
70307 @@ -107,7 +108,8 @@ struct bin_attribute {
70308 char *, loff_t, size_t);
70309 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
70310 struct vm_area_struct *vma);
70311 -};
70312 +} __do_const;
70313 +typedef struct bin_attribute __no_const bin_attribute_no_const;
70314
70315 /**
70316 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
70317 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
70318 index 7faf933..4657127 100644
70319 --- a/include/linux/sysrq.h
70320 +++ b/include/linux/sysrq.h
70321 @@ -15,7 +15,9 @@
70322 #define _LINUX_SYSRQ_H
70323
70324 #include <linux/errno.h>
70325 +#include <linux/compiler.h>
70326 #include <linux/types.h>
70327 +#include <linux/compiler.h>
70328
70329 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
70330 #define SYSRQ_DEFAULT_ENABLE 1
70331 @@ -36,7 +38,7 @@ struct sysrq_key_op {
70332 char *help_msg;
70333 char *action_msg;
70334 int enable_mask;
70335 -};
70336 +} __do_const;
70337
70338 #ifdef CONFIG_MAGIC_SYSRQ
70339
70340 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
70341 index e7e0473..39b7b52 100644
70342 --- a/include/linux/thread_info.h
70343 +++ b/include/linux/thread_info.h
70344 @@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
70345 #error "no set_restore_sigmask() provided and default one won't work"
70346 #endif
70347
70348 +extern void __check_object_size(const void *ptr, unsigned long n, bool to);
70349 +static inline void check_object_size(const void *ptr, unsigned long n, bool to)
70350 +{
70351 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
70352 + if (!__builtin_constant_p(n))
70353 +#endif
70354 + __check_object_size(ptr, n, to);
70355 +}
70356 +
70357 #endif /* __KERNEL__ */
70358
70359 #endif /* _LINUX_THREAD_INFO_H */
70360 diff --git a/include/linux/tty.h b/include/linux/tty.h
70361 index 8db1b56..c16a040 100644
70362 --- a/include/linux/tty.h
70363 +++ b/include/linux/tty.h
70364 @@ -194,7 +194,7 @@ struct tty_port {
70365 const struct tty_port_operations *ops; /* Port operations */
70366 spinlock_t lock; /* Lock protecting tty field */
70367 int blocked_open; /* Waiting to open */
70368 - int count; /* Usage count */
70369 + atomic_t count; /* Usage count */
70370 wait_queue_head_t open_wait; /* Open waiters */
70371 wait_queue_head_t close_wait; /* Close waiters */
70372 wait_queue_head_t delta_msr_wait; /* Modem status change */
70373 @@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
70374 struct tty_struct *tty, struct file *filp);
70375 static inline int tty_port_users(struct tty_port *port)
70376 {
70377 - return port->count + port->blocked_open;
70378 + return atomic_read(&port->count) + port->blocked_open;
70379 }
70380
70381 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
70382 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
70383 index dd976cf..e272742 100644
70384 --- a/include/linux/tty_driver.h
70385 +++ b/include/linux/tty_driver.h
70386 @@ -284,7 +284,7 @@ struct tty_operations {
70387 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
70388 #endif
70389 const struct file_operations *proc_fops;
70390 -};
70391 +} __do_const;
70392
70393 struct tty_driver {
70394 int magic; /* magic number for this structure */
70395 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
70396 index fb79dd8d..07d4773 100644
70397 --- a/include/linux/tty_ldisc.h
70398 +++ b/include/linux/tty_ldisc.h
70399 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
70400
70401 struct module *owner;
70402
70403 - int refcount;
70404 + atomic_t refcount;
70405 };
70406
70407 struct tty_ldisc {
70408 diff --git a/include/linux/types.h b/include/linux/types.h
70409 index 4d118ba..c3ee9bf 100644
70410 --- a/include/linux/types.h
70411 +++ b/include/linux/types.h
70412 @@ -176,10 +176,26 @@ typedef struct {
70413 int counter;
70414 } atomic_t;
70415
70416 +#ifdef CONFIG_PAX_REFCOUNT
70417 +typedef struct {
70418 + int counter;
70419 +} atomic_unchecked_t;
70420 +#else
70421 +typedef atomic_t atomic_unchecked_t;
70422 +#endif
70423 +
70424 #ifdef CONFIG_64BIT
70425 typedef struct {
70426 long counter;
70427 } atomic64_t;
70428 +
70429 +#ifdef CONFIG_PAX_REFCOUNT
70430 +typedef struct {
70431 + long counter;
70432 +} atomic64_unchecked_t;
70433 +#else
70434 +typedef atomic64_t atomic64_unchecked_t;
70435 +#endif
70436 #endif
70437
70438 struct list_head {
70439 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
70440 index 5ca0951..ab496a5 100644
70441 --- a/include/linux/uaccess.h
70442 +++ b/include/linux/uaccess.h
70443 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
70444 long ret; \
70445 mm_segment_t old_fs = get_fs(); \
70446 \
70447 - set_fs(KERNEL_DS); \
70448 pagefault_disable(); \
70449 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
70450 - pagefault_enable(); \
70451 + set_fs(KERNEL_DS); \
70452 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
70453 set_fs(old_fs); \
70454 + pagefault_enable(); \
70455 ret; \
70456 })
70457
70458 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
70459 index 8e522cbc..aa8572d 100644
70460 --- a/include/linux/uidgid.h
70461 +++ b/include/linux/uidgid.h
70462 @@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
70463
70464 #endif /* CONFIG_USER_NS */
70465
70466 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
70467 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
70468 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
70469 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
70470 +
70471 #endif /* _LINUX_UIDGID_H */
70472 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
70473 index 99c1b4d..bb94261 100644
70474 --- a/include/linux/unaligned/access_ok.h
70475 +++ b/include/linux/unaligned/access_ok.h
70476 @@ -6,32 +6,32 @@
70477
70478 static inline u16 get_unaligned_le16(const void *p)
70479 {
70480 - return le16_to_cpup((__le16 *)p);
70481 + return le16_to_cpup((const __le16 *)p);
70482 }
70483
70484 static inline u32 get_unaligned_le32(const void *p)
70485 {
70486 - return le32_to_cpup((__le32 *)p);
70487 + return le32_to_cpup((const __le32 *)p);
70488 }
70489
70490 static inline u64 get_unaligned_le64(const void *p)
70491 {
70492 - return le64_to_cpup((__le64 *)p);
70493 + return le64_to_cpup((const __le64 *)p);
70494 }
70495
70496 static inline u16 get_unaligned_be16(const void *p)
70497 {
70498 - return be16_to_cpup((__be16 *)p);
70499 + return be16_to_cpup((const __be16 *)p);
70500 }
70501
70502 static inline u32 get_unaligned_be32(const void *p)
70503 {
70504 - return be32_to_cpup((__be32 *)p);
70505 + return be32_to_cpup((const __be32 *)p);
70506 }
70507
70508 static inline u64 get_unaligned_be64(const void *p)
70509 {
70510 - return be64_to_cpup((__be64 *)p);
70511 + return be64_to_cpup((const __be64 *)p);
70512 }
70513
70514 static inline void put_unaligned_le16(u16 val, void *p)
70515 diff --git a/include/linux/usb.h b/include/linux/usb.h
70516 index 4d22d0f..ac43c2f 100644
70517 --- a/include/linux/usb.h
70518 +++ b/include/linux/usb.h
70519 @@ -554,7 +554,7 @@ struct usb_device {
70520 int maxchild;
70521
70522 u32 quirks;
70523 - atomic_t urbnum;
70524 + atomic_unchecked_t urbnum;
70525
70526 unsigned long active_duration;
70527
70528 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
70529 index c5d36c6..108f4f9 100644
70530 --- a/include/linux/usb/renesas_usbhs.h
70531 +++ b/include/linux/usb/renesas_usbhs.h
70532 @@ -39,7 +39,7 @@ enum {
70533 */
70534 struct renesas_usbhs_driver_callback {
70535 int (*notify_hotplug)(struct platform_device *pdev);
70536 -};
70537 +} __no_const;
70538
70539 /*
70540 * callback functions for platform
70541 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
70542 index b9bd2e6..4ce0093 100644
70543 --- a/include/linux/user_namespace.h
70544 +++ b/include/linux/user_namespace.h
70545 @@ -21,7 +21,7 @@ struct user_namespace {
70546 struct uid_gid_map uid_map;
70547 struct uid_gid_map gid_map;
70548 struct uid_gid_map projid_map;
70549 - struct kref kref;
70550 + atomic_t count;
70551 struct user_namespace *parent;
70552 kuid_t owner;
70553 kgid_t group;
70554 @@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
70555 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
70556 {
70557 if (ns)
70558 - kref_get(&ns->kref);
70559 + atomic_inc(&ns->count);
70560 return ns;
70561 }
70562
70563 extern int create_user_ns(struct cred *new);
70564 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
70565 -extern void free_user_ns(struct kref *kref);
70566 +extern void free_user_ns(struct user_namespace *ns);
70567
70568 static inline void put_user_ns(struct user_namespace *ns)
70569 {
70570 - if (ns)
70571 - kref_put(&ns->kref, free_user_ns);
70572 + if (ns && atomic_dec_and_test(&ns->count))
70573 + free_user_ns(ns);
70574 }
70575
70576 struct seq_operations;
70577 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
70578 index 6f8fbcf..8259001 100644
70579 --- a/include/linux/vermagic.h
70580 +++ b/include/linux/vermagic.h
70581 @@ -25,9 +25,35 @@
70582 #define MODULE_ARCH_VERMAGIC ""
70583 #endif
70584
70585 +#ifdef CONFIG_PAX_REFCOUNT
70586 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
70587 +#else
70588 +#define MODULE_PAX_REFCOUNT ""
70589 +#endif
70590 +
70591 +#ifdef CONSTIFY_PLUGIN
70592 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
70593 +#else
70594 +#define MODULE_CONSTIFY_PLUGIN ""
70595 +#endif
70596 +
70597 +#ifdef STACKLEAK_PLUGIN
70598 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
70599 +#else
70600 +#define MODULE_STACKLEAK_PLUGIN ""
70601 +#endif
70602 +
70603 +#ifdef CONFIG_GRKERNSEC
70604 +#define MODULE_GRSEC "GRSEC "
70605 +#else
70606 +#define MODULE_GRSEC ""
70607 +#endif
70608 +
70609 #define VERMAGIC_STRING \
70610 UTS_RELEASE " " \
70611 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
70612 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
70613 - MODULE_ARCH_VERMAGIC
70614 + MODULE_ARCH_VERMAGIC \
70615 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
70616 + MODULE_GRSEC
70617
70618 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
70619 index 6071e91..ca6a489 100644
70620 --- a/include/linux/vmalloc.h
70621 +++ b/include/linux/vmalloc.h
70622 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
70623 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
70624 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
70625 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
70626 +
70627 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
70628 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
70629 +#endif
70630 +
70631 /* bits [20..32] reserved for arch specific ioremap internals */
70632
70633 /*
70634 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
70635 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
70636 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
70637 unsigned long start, unsigned long end, gfp_t gfp_mask,
70638 - pgprot_t prot, int node, const void *caller);
70639 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
70640 extern void vfree(const void *addr);
70641
70642 extern void *vmap(struct page **pages, unsigned int count,
70643 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
70644 extern void free_vm_area(struct vm_struct *area);
70645
70646 /* for /dev/kmem */
70647 -extern long vread(char *buf, char *addr, unsigned long count);
70648 -extern long vwrite(char *buf, char *addr, unsigned long count);
70649 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
70650 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
70651
70652 /*
70653 * Internals. Dont't use..
70654 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
70655 index a13291f..af51fa3 100644
70656 --- a/include/linux/vmstat.h
70657 +++ b/include/linux/vmstat.h
70658 @@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
70659 /*
70660 * Zone based page accounting with per cpu differentials.
70661 */
70662 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70663 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70664
70665 static inline void zone_page_state_add(long x, struct zone *zone,
70666 enum zone_stat_item item)
70667 {
70668 - atomic_long_add(x, &zone->vm_stat[item]);
70669 - atomic_long_add(x, &vm_stat[item]);
70670 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
70671 + atomic_long_add_unchecked(x, &vm_stat[item]);
70672 }
70673
70674 static inline unsigned long global_page_state(enum zone_stat_item item)
70675 {
70676 - long x = atomic_long_read(&vm_stat[item]);
70677 + long x = atomic_long_read_unchecked(&vm_stat[item]);
70678 #ifdef CONFIG_SMP
70679 if (x < 0)
70680 x = 0;
70681 @@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
70682 static inline unsigned long zone_page_state(struct zone *zone,
70683 enum zone_stat_item item)
70684 {
70685 - long x = atomic_long_read(&zone->vm_stat[item]);
70686 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
70687 #ifdef CONFIG_SMP
70688 if (x < 0)
70689 x = 0;
70690 @@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
70691 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
70692 enum zone_stat_item item)
70693 {
70694 - long x = atomic_long_read(&zone->vm_stat[item]);
70695 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
70696
70697 #ifdef CONFIG_SMP
70698 int cpu;
70699 @@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
70700
70701 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
70702 {
70703 - atomic_long_inc(&zone->vm_stat[item]);
70704 - atomic_long_inc(&vm_stat[item]);
70705 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
70706 + atomic_long_inc_unchecked(&vm_stat[item]);
70707 }
70708
70709 static inline void __inc_zone_page_state(struct page *page,
70710 @@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
70711
70712 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
70713 {
70714 - atomic_long_dec(&zone->vm_stat[item]);
70715 - atomic_long_dec(&vm_stat[item]);
70716 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
70717 + atomic_long_dec_unchecked(&vm_stat[item]);
70718 }
70719
70720 static inline void __dec_zone_page_state(struct page *page,
70721 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
70722 index fdbafc6..b7ffd47 100644
70723 --- a/include/linux/xattr.h
70724 +++ b/include/linux/xattr.h
70725 @@ -28,7 +28,7 @@ struct xattr_handler {
70726 size_t size, int handler_flags);
70727 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
70728 size_t size, int flags, int handler_flags);
70729 -};
70730 +} __do_const;
70731
70732 struct xattr {
70733 char *name;
70734 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
70735 index 95d1c91..6798cca 100644
70736 --- a/include/media/v4l2-dev.h
70737 +++ b/include/media/v4l2-dev.h
70738 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
70739 int (*mmap) (struct file *, struct vm_area_struct *);
70740 int (*open) (struct file *);
70741 int (*release) (struct file *);
70742 -};
70743 +} __do_const;
70744
70745 /*
70746 * Newer version of video_device, handled by videodev2.c
70747 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
70748 index 4118ad1..cb7e25f 100644
70749 --- a/include/media/v4l2-ioctl.h
70750 +++ b/include/media/v4l2-ioctl.h
70751 @@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
70752 bool valid_prio, int cmd, void *arg);
70753 };
70754
70755 -
70756 /* v4l debugging and diagnostics */
70757
70758 /* Debug bitmask flags to be used on V4L2 */
70759 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
70760 index adcbb20..62c2559 100644
70761 --- a/include/net/9p/transport.h
70762 +++ b/include/net/9p/transport.h
70763 @@ -57,7 +57,7 @@ struct p9_trans_module {
70764 int (*cancel) (struct p9_client *, struct p9_req_t *req);
70765 int (*zc_request)(struct p9_client *, struct p9_req_t *,
70766 char *, char *, int , int, int, int);
70767 -};
70768 +} __do_const;
70769
70770 void v9fs_register_trans(struct p9_trans_module *m);
70771 void v9fs_unregister_trans(struct p9_trans_module *m);
70772 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
70773 index 7588ef4..e62d35f 100644
70774 --- a/include/net/bluetooth/l2cap.h
70775 +++ b/include/net/bluetooth/l2cap.h
70776 @@ -552,7 +552,7 @@ struct l2cap_ops {
70777 void (*defer) (struct l2cap_chan *chan);
70778 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
70779 unsigned long len, int nb);
70780 -};
70781 +} __do_const;
70782
70783 struct l2cap_conn {
70784 struct hci_conn *hcon;
70785 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
70786 index 9e5425b..8136ffc 100644
70787 --- a/include/net/caif/cfctrl.h
70788 +++ b/include/net/caif/cfctrl.h
70789 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
70790 void (*radioset_rsp)(void);
70791 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
70792 struct cflayer *client_layer);
70793 -};
70794 +} __no_const;
70795
70796 /* Link Setup Parameters for CAIF-Links. */
70797 struct cfctrl_link_param {
70798 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
70799 struct cfctrl {
70800 struct cfsrvl serv;
70801 struct cfctrl_rsp res;
70802 - atomic_t req_seq_no;
70803 - atomic_t rsp_seq_no;
70804 + atomic_unchecked_t req_seq_no;
70805 + atomic_unchecked_t rsp_seq_no;
70806 struct list_head list;
70807 /* Protects from simultaneous access to first_req list */
70808 spinlock_t info_list_lock;
70809 diff --git a/include/net/flow.h b/include/net/flow.h
70810 index 628e11b..4c475df 100644
70811 --- a/include/net/flow.h
70812 +++ b/include/net/flow.h
70813 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
70814
70815 extern void flow_cache_flush(void);
70816 extern void flow_cache_flush_deferred(void);
70817 -extern atomic_t flow_cache_genid;
70818 +extern atomic_unchecked_t flow_cache_genid;
70819
70820 #endif
70821 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
70822 index bdfbe68..4402ebe 100644
70823 --- a/include/net/genetlink.h
70824 +++ b/include/net/genetlink.h
70825 @@ -118,7 +118,7 @@ struct genl_ops {
70826 struct netlink_callback *cb);
70827 int (*done)(struct netlink_callback *cb);
70828 struct list_head ops_list;
70829 -};
70830 +} __do_const;
70831
70832 extern int genl_register_family(struct genl_family *family);
70833 extern int genl_register_family_with_ops(struct genl_family *family,
70834 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
70835 index e5062c9..48a9a4b 100644
70836 --- a/include/net/gro_cells.h
70837 +++ b/include/net/gro_cells.h
70838 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
70839 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
70840
70841 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
70842 - atomic_long_inc(&dev->rx_dropped);
70843 + atomic_long_inc_unchecked(&dev->rx_dropped);
70844 kfree_skb(skb);
70845 return;
70846 }
70847 @@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
70848 int i;
70849
70850 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
70851 - gcells->cells = kcalloc(sizeof(struct gro_cell),
70852 - gcells->gro_cells_mask + 1,
70853 + gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
70854 + sizeof(struct gro_cell),
70855 GFP_KERNEL);
70856 if (!gcells->cells)
70857 return -ENOMEM;
70858 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
70859 index 1832927..ce39aea 100644
70860 --- a/include/net/inet_connection_sock.h
70861 +++ b/include/net/inet_connection_sock.h
70862 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
70863 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
70864 int (*bind_conflict)(const struct sock *sk,
70865 const struct inet_bind_bucket *tb, bool relax);
70866 -};
70867 +} __do_const;
70868
70869 /** inet_connection_sock - INET connection oriented sock
70870 *
70871 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
70872 index 53f464d..ba76aaa 100644
70873 --- a/include/net/inetpeer.h
70874 +++ b/include/net/inetpeer.h
70875 @@ -47,8 +47,8 @@ struct inet_peer {
70876 */
70877 union {
70878 struct {
70879 - atomic_t rid; /* Frag reception counter */
70880 - atomic_t ip_id_count; /* IP ID for the next packet */
70881 + atomic_unchecked_t rid; /* Frag reception counter */
70882 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
70883 };
70884 struct rcu_head rcu;
70885 struct inet_peer *gc_next;
70886 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
70887 more++;
70888 inet_peer_refcheck(p);
70889 do {
70890 - old = atomic_read(&p->ip_id_count);
70891 + old = atomic_read_unchecked(&p->ip_id_count);
70892 new = old + more;
70893 if (!new)
70894 new = 1;
70895 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
70896 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
70897 return new;
70898 }
70899
70900 diff --git a/include/net/ip.h b/include/net/ip.h
70901 index a68f838..74518ab 100644
70902 --- a/include/net/ip.h
70903 +++ b/include/net/ip.h
70904 @@ -202,7 +202,7 @@ extern struct local_ports {
70905 } sysctl_local_ports;
70906 extern void inet_get_local_port_range(int *low, int *high);
70907
70908 -extern unsigned long *sysctl_local_reserved_ports;
70909 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
70910 static inline int inet_is_reserved_local_port(int port)
70911 {
70912 return test_bit(port, sysctl_local_reserved_ports);
70913 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
70914 index 9497be1..5a4fafe 100644
70915 --- a/include/net/ip_fib.h
70916 +++ b/include/net/ip_fib.h
70917 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
70918
70919 #define FIB_RES_SADDR(net, res) \
70920 ((FIB_RES_NH(res).nh_saddr_genid == \
70921 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
70922 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
70923 FIB_RES_NH(res).nh_saddr : \
70924 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
70925 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
70926 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
70927 index 68c69d5..bdab192 100644
70928 --- a/include/net/ip_vs.h
70929 +++ b/include/net/ip_vs.h
70930 @@ -599,7 +599,7 @@ struct ip_vs_conn {
70931 struct ip_vs_conn *control; /* Master control connection */
70932 atomic_t n_control; /* Number of controlled ones */
70933 struct ip_vs_dest *dest; /* real server */
70934 - atomic_t in_pkts; /* incoming packet counter */
70935 + atomic_unchecked_t in_pkts; /* incoming packet counter */
70936
70937 /* packet transmitter for different forwarding methods. If it
70938 mangles the packet, it must return NF_DROP or better NF_STOLEN,
70939 @@ -737,7 +737,7 @@ struct ip_vs_dest {
70940 __be16 port; /* port number of the server */
70941 union nf_inet_addr addr; /* IP address of the server */
70942 volatile unsigned int flags; /* dest status flags */
70943 - atomic_t conn_flags; /* flags to copy to conn */
70944 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
70945 atomic_t weight; /* server weight */
70946
70947 atomic_t refcnt; /* reference counter */
70948 @@ -980,11 +980,11 @@ struct netns_ipvs {
70949 /* ip_vs_lblc */
70950 int sysctl_lblc_expiration;
70951 struct ctl_table_header *lblc_ctl_header;
70952 - struct ctl_table *lblc_ctl_table;
70953 + ctl_table_no_const *lblc_ctl_table;
70954 /* ip_vs_lblcr */
70955 int sysctl_lblcr_expiration;
70956 struct ctl_table_header *lblcr_ctl_header;
70957 - struct ctl_table *lblcr_ctl_table;
70958 + ctl_table_no_const *lblcr_ctl_table;
70959 /* ip_vs_est */
70960 struct list_head est_list; /* estimator list */
70961 spinlock_t est_lock;
70962 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
70963 index 80ffde3..968b0f4 100644
70964 --- a/include/net/irda/ircomm_tty.h
70965 +++ b/include/net/irda/ircomm_tty.h
70966 @@ -35,6 +35,7 @@
70967 #include <linux/termios.h>
70968 #include <linux/timer.h>
70969 #include <linux/tty.h> /* struct tty_struct */
70970 +#include <asm/local.h>
70971
70972 #include <net/irda/irias_object.h>
70973 #include <net/irda/ircomm_core.h>
70974 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
70975 index cc7c197..9f2da2a 100644
70976 --- a/include/net/iucv/af_iucv.h
70977 +++ b/include/net/iucv/af_iucv.h
70978 @@ -141,7 +141,7 @@ struct iucv_sock {
70979 struct iucv_sock_list {
70980 struct hlist_head head;
70981 rwlock_t lock;
70982 - atomic_t autobind_name;
70983 + atomic_unchecked_t autobind_name;
70984 };
70985
70986 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
70987 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
70988 index df83f69..9b640b8 100644
70989 --- a/include/net/llc_c_ac.h
70990 +++ b/include/net/llc_c_ac.h
70991 @@ -87,7 +87,7 @@
70992 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
70993 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
70994
70995 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
70996 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
70997
70998 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
70999 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
71000 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
71001 index 6ca3113..f8026dd 100644
71002 --- a/include/net/llc_c_ev.h
71003 +++ b/include/net/llc_c_ev.h
71004 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
71005 return (struct llc_conn_state_ev *)skb->cb;
71006 }
71007
71008 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71009 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71010 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71011 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71012
71013 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
71014 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
71015 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
71016 index 0e79cfb..f46db31 100644
71017 --- a/include/net/llc_c_st.h
71018 +++ b/include/net/llc_c_st.h
71019 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
71020 u8 next_state;
71021 llc_conn_ev_qfyr_t *ev_qualifiers;
71022 llc_conn_action_t *ev_actions;
71023 -};
71024 +} __do_const;
71025
71026 struct llc_conn_state {
71027 u8 current_state;
71028 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
71029 index 37a3bbd..55a4241 100644
71030 --- a/include/net/llc_s_ac.h
71031 +++ b/include/net/llc_s_ac.h
71032 @@ -23,7 +23,7 @@
71033 #define SAP_ACT_TEST_IND 9
71034
71035 /* All action functions must look like this */
71036 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71037 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71038
71039 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
71040 struct sk_buff *skb);
71041 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
71042 index 567c681..cd73ac0 100644
71043 --- a/include/net/llc_s_st.h
71044 +++ b/include/net/llc_s_st.h
71045 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
71046 llc_sap_ev_t ev;
71047 u8 next_state;
71048 llc_sap_action_t *ev_actions;
71049 -};
71050 +} __do_const;
71051
71052 struct llc_sap_state {
71053 u8 curr_state;
71054 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
71055 index ee50c5e..1bc3b1a 100644
71056 --- a/include/net/mac80211.h
71057 +++ b/include/net/mac80211.h
71058 @@ -3996,7 +3996,7 @@ struct rate_control_ops {
71059 void (*add_sta_debugfs)(void *priv, void *priv_sta,
71060 struct dentry *dir);
71061 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
71062 -};
71063 +} __do_const;
71064
71065 static inline int rate_supported(struct ieee80211_sta *sta,
71066 enum ieee80211_band band,
71067 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
71068 index 0dab173..1b76af0 100644
71069 --- a/include/net/neighbour.h
71070 +++ b/include/net/neighbour.h
71071 @@ -123,7 +123,7 @@ struct neigh_ops {
71072 void (*error_report)(struct neighbour *, struct sk_buff *);
71073 int (*output)(struct neighbour *, struct sk_buff *);
71074 int (*connected_output)(struct neighbour *, struct sk_buff *);
71075 -};
71076 +} __do_const;
71077
71078 struct pneigh_entry {
71079 struct pneigh_entry *next;
71080 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
71081 index de644bc..351fd4e 100644
71082 --- a/include/net/net_namespace.h
71083 +++ b/include/net/net_namespace.h
71084 @@ -115,7 +115,7 @@ struct net {
71085 #endif
71086 struct netns_ipvs *ipvs;
71087 struct sock *diag_nlsk;
71088 - atomic_t rt_genid;
71089 + atomic_unchecked_t rt_genid;
71090 };
71091
71092 /*
71093 @@ -282,7 +282,7 @@ struct pernet_operations {
71094 void (*exit_batch)(struct list_head *net_exit_list);
71095 int *id;
71096 size_t size;
71097 -};
71098 +} __do_const;
71099
71100 /*
71101 * Use these carefully. If you implement a network device and it
71102 @@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
71103
71104 static inline int rt_genid(struct net *net)
71105 {
71106 - return atomic_read(&net->rt_genid);
71107 + return atomic_read_unchecked(&net->rt_genid);
71108 }
71109
71110 static inline void rt_genid_bump(struct net *net)
71111 {
71112 - atomic_inc(&net->rt_genid);
71113 + atomic_inc_unchecked(&net->rt_genid);
71114 }
71115
71116 #endif /* __NET_NET_NAMESPACE_H */
71117 diff --git a/include/net/netdma.h b/include/net/netdma.h
71118 index 8ba8ce2..99b7fff 100644
71119 --- a/include/net/netdma.h
71120 +++ b/include/net/netdma.h
71121 @@ -24,7 +24,7 @@
71122 #include <linux/dmaengine.h>
71123 #include <linux/skbuff.h>
71124
71125 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71126 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71127 struct sk_buff *skb, int offset, struct iovec *to,
71128 size_t len, struct dma_pinned_list *pinned_list);
71129
71130 diff --git a/include/net/netlink.h b/include/net/netlink.h
71131 index 9690b0f..87aded7 100644
71132 --- a/include/net/netlink.h
71133 +++ b/include/net/netlink.h
71134 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
71135 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
71136 {
71137 if (mark)
71138 - skb_trim(skb, (unsigned char *) mark - skb->data);
71139 + skb_trim(skb, (const unsigned char *) mark - skb->data);
71140 }
71141
71142 /**
71143 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
71144 index 923cb20..deae816 100644
71145 --- a/include/net/netns/conntrack.h
71146 +++ b/include/net/netns/conntrack.h
71147 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
71148 struct nf_proto_net {
71149 #ifdef CONFIG_SYSCTL
71150 struct ctl_table_header *ctl_table_header;
71151 - struct ctl_table *ctl_table;
71152 + ctl_table_no_const *ctl_table;
71153 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
71154 struct ctl_table_header *ctl_compat_header;
71155 - struct ctl_table *ctl_compat_table;
71156 + ctl_table_no_const *ctl_compat_table;
71157 #endif
71158 #endif
71159 unsigned int users;
71160 @@ -58,7 +58,7 @@ struct nf_ip_net {
71161 struct nf_icmp_net icmpv6;
71162 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
71163 struct ctl_table_header *ctl_table_header;
71164 - struct ctl_table *ctl_table;
71165 + ctl_table_no_const *ctl_table;
71166 #endif
71167 };
71168
71169 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
71170 index 2ae2b83..dbdc85e 100644
71171 --- a/include/net/netns/ipv4.h
71172 +++ b/include/net/netns/ipv4.h
71173 @@ -64,7 +64,7 @@ struct netns_ipv4 {
71174 kgid_t sysctl_ping_group_range[2];
71175 long sysctl_tcp_mem[3];
71176
71177 - atomic_t dev_addr_genid;
71178 + atomic_unchecked_t dev_addr_genid;
71179
71180 #ifdef CONFIG_IP_MROUTE
71181 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
71182 diff --git a/include/net/protocol.h b/include/net/protocol.h
71183 index 047c047..b9dad15 100644
71184 --- a/include/net/protocol.h
71185 +++ b/include/net/protocol.h
71186 @@ -44,7 +44,7 @@ struct net_protocol {
71187 void (*err_handler)(struct sk_buff *skb, u32 info);
71188 unsigned int no_policy:1,
71189 netns_ok:1;
71190 -};
71191 +} __do_const;
71192
71193 #if IS_ENABLED(CONFIG_IPV6)
71194 struct inet6_protocol {
71195 @@ -57,7 +57,7 @@ struct inet6_protocol {
71196 u8 type, u8 code, int offset,
71197 __be32 info);
71198 unsigned int flags; /* INET6_PROTO_xxx */
71199 -};
71200 +} __do_const;
71201
71202 #define INET6_PROTO_NOPOLICY 0x1
71203 #define INET6_PROTO_FINAL 0x2
71204 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
71205 index 5a15fab..d799ea7 100644
71206 --- a/include/net/rtnetlink.h
71207 +++ b/include/net/rtnetlink.h
71208 @@ -81,7 +81,7 @@ struct rtnl_link_ops {
71209 const struct net_device *dev);
71210 unsigned int (*get_num_tx_queues)(void);
71211 unsigned int (*get_num_rx_queues)(void);
71212 -};
71213 +} __do_const;
71214
71215 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
71216 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
71217 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
71218 index 7fdf298..197e9f7 100644
71219 --- a/include/net/sctp/sctp.h
71220 +++ b/include/net/sctp/sctp.h
71221 @@ -330,9 +330,9 @@ do { \
71222
71223 #else /* SCTP_DEBUG */
71224
71225 -#define SCTP_DEBUG_PRINTK(whatever...)
71226 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
71227 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
71228 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
71229 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
71230 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
71231 #define SCTP_ENABLE_DEBUG
71232 #define SCTP_DISABLE_DEBUG
71233 #define SCTP_ASSERT(expr, str, func)
71234 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
71235 index 2a82d13..62a31c2 100644
71236 --- a/include/net/sctp/sm.h
71237 +++ b/include/net/sctp/sm.h
71238 @@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
71239 typedef struct {
71240 sctp_state_fn_t *fn;
71241 const char *name;
71242 -} sctp_sm_table_entry_t;
71243 +} __do_const sctp_sm_table_entry_t;
71244
71245 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
71246 * currently in use.
71247 @@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
71248 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
71249
71250 /* Extern declarations for major data structures. */
71251 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
71252 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
71253
71254
71255 /* Get the size of a DATA chunk payload. */
71256 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
71257 index fdeb85a..1329d95 100644
71258 --- a/include/net/sctp/structs.h
71259 +++ b/include/net/sctp/structs.h
71260 @@ -517,7 +517,7 @@ struct sctp_pf {
71261 struct sctp_association *asoc);
71262 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
71263 struct sctp_af *af;
71264 -};
71265 +} __do_const;
71266
71267
71268 /* Structure to track chunk fragments that have been acked, but peer
71269 diff --git a/include/net/sock.h b/include/net/sock.h
71270 index 25afaa0..8bb0070 100644
71271 --- a/include/net/sock.h
71272 +++ b/include/net/sock.h
71273 @@ -322,7 +322,7 @@ struct sock {
71274 #ifdef CONFIG_RPS
71275 __u32 sk_rxhash;
71276 #endif
71277 - atomic_t sk_drops;
71278 + atomic_unchecked_t sk_drops;
71279 int sk_rcvbuf;
71280
71281 struct sk_filter __rcu *sk_filter;
71282 @@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
71283 }
71284
71285 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
71286 - char __user *from, char *to,
71287 + char __user *from, unsigned char *to,
71288 int copy, int offset)
71289 {
71290 if (skb->ip_summed == CHECKSUM_NONE) {
71291 @@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
71292 }
71293 }
71294
71295 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
71296 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
71297
71298 /**
71299 * sk_page_frag - return an appropriate page_frag
71300 diff --git a/include/net/tcp.h b/include/net/tcp.h
71301 index aed42c7..43890c6 100644
71302 --- a/include/net/tcp.h
71303 +++ b/include/net/tcp.h
71304 @@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
71305 extern void tcp_xmit_retransmit_queue(struct sock *);
71306 extern void tcp_simple_retransmit(struct sock *);
71307 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
71308 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
71309 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
71310
71311 extern void tcp_send_probe0(struct sock *);
71312 extern void tcp_send_partial(struct sock *);
71313 @@ -701,8 +701,8 @@ struct tcp_skb_cb {
71314 struct inet6_skb_parm h6;
71315 #endif
71316 } header; /* For incoming frames */
71317 - __u32 seq; /* Starting sequence number */
71318 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
71319 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
71320 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
71321 __u32 when; /* used to compute rtt's */
71322 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
71323
71324 @@ -716,7 +716,7 @@ struct tcp_skb_cb {
71325
71326 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
71327 /* 1 byte hole */
71328 - __u32 ack_seq; /* Sequence number ACK'd */
71329 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
71330 };
71331
71332 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
71333 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
71334 index 63445ed..d6fc34f 100644
71335 --- a/include/net/xfrm.h
71336 +++ b/include/net/xfrm.h
71337 @@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
71338 struct net_device *dev,
71339 const struct flowi *fl);
71340 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
71341 -};
71342 +} __do_const;
71343
71344 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
71345 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
71346 @@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
71347 struct sk_buff *skb);
71348 int (*transport_finish)(struct sk_buff *skb,
71349 int async);
71350 -};
71351 +} __do_const;
71352
71353 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
71354 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
71355 @@ -423,7 +423,7 @@ struct xfrm_mode {
71356 struct module *owner;
71357 unsigned int encap;
71358 int flags;
71359 -};
71360 +} __do_const;
71361
71362 /* Flags for xfrm_mode. */
71363 enum {
71364 @@ -514,7 +514,7 @@ struct xfrm_policy {
71365 struct timer_list timer;
71366
71367 struct flow_cache_object flo;
71368 - atomic_t genid;
71369 + atomic_unchecked_t genid;
71370 u32 priority;
71371 u32 index;
71372 struct xfrm_mark mark;
71373 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
71374 index 1a046b1..ee0bef0 100644
71375 --- a/include/rdma/iw_cm.h
71376 +++ b/include/rdma/iw_cm.h
71377 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
71378 int backlog);
71379
71380 int (*destroy_listen)(struct iw_cm_id *cm_id);
71381 -};
71382 +} __no_const;
71383
71384 /**
71385 * iw_create_cm_id - Create an IW CM identifier.
71386 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
71387 index 399162b..b337f1a 100644
71388 --- a/include/scsi/libfc.h
71389 +++ b/include/scsi/libfc.h
71390 @@ -762,6 +762,7 @@ struct libfc_function_template {
71391 */
71392 void (*disc_stop_final) (struct fc_lport *);
71393 };
71394 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
71395
71396 /**
71397 * struct fc_disc - Discovery context
71398 @@ -866,7 +867,7 @@ struct fc_lport {
71399 struct fc_vport *vport;
71400
71401 /* Operational Information */
71402 - struct libfc_function_template tt;
71403 + libfc_function_template_no_const tt;
71404 u8 link_up;
71405 u8 qfull;
71406 enum fc_lport_state state;
71407 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
71408 index e65c62e..aa2e5a2 100644
71409 --- a/include/scsi/scsi_device.h
71410 +++ b/include/scsi/scsi_device.h
71411 @@ -170,9 +170,9 @@ struct scsi_device {
71412 unsigned int max_device_blocked; /* what device_blocked counts down from */
71413 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
71414
71415 - atomic_t iorequest_cnt;
71416 - atomic_t iodone_cnt;
71417 - atomic_t ioerr_cnt;
71418 + atomic_unchecked_t iorequest_cnt;
71419 + atomic_unchecked_t iodone_cnt;
71420 + atomic_unchecked_t ioerr_cnt;
71421
71422 struct device sdev_gendev,
71423 sdev_dev;
71424 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
71425 index b797e8f..8e2c3aa 100644
71426 --- a/include/scsi/scsi_transport_fc.h
71427 +++ b/include/scsi/scsi_transport_fc.h
71428 @@ -751,7 +751,8 @@ struct fc_function_template {
71429 unsigned long show_host_system_hostname:1;
71430
71431 unsigned long disable_target_scan:1;
71432 -};
71433 +} __do_const;
71434 +typedef struct fc_function_template __no_const fc_function_template_no_const;
71435
71436
71437 /**
71438 diff --git a/include/sound/soc.h b/include/sound/soc.h
71439 index bc56738..a4be132 100644
71440 --- a/include/sound/soc.h
71441 +++ b/include/sound/soc.h
71442 @@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
71443 /* probe ordering - for components with runtime dependencies */
71444 int probe_order;
71445 int remove_order;
71446 -};
71447 +} __do_const;
71448
71449 /* SoC platform interface */
71450 struct snd_soc_platform_driver {
71451 @@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
71452 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
71453 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
71454 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
71455 -};
71456 +} __do_const;
71457
71458 struct snd_soc_platform {
71459 const char *name;
71460 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
71461 index 663e34a..91b306a 100644
71462 --- a/include/target/target_core_base.h
71463 +++ b/include/target/target_core_base.h
71464 @@ -654,7 +654,7 @@ struct se_device {
71465 spinlock_t stats_lock;
71466 /* Active commands on this virtual SE device */
71467 atomic_t simple_cmds;
71468 - atomic_t dev_ordered_id;
71469 + atomic_unchecked_t dev_ordered_id;
71470 atomic_t dev_ordered_sync;
71471 atomic_t dev_qf_count;
71472 int export_count;
71473 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
71474 new file mode 100644
71475 index 0000000..fb634b7
71476 --- /dev/null
71477 +++ b/include/trace/events/fs.h
71478 @@ -0,0 +1,53 @@
71479 +#undef TRACE_SYSTEM
71480 +#define TRACE_SYSTEM fs
71481 +
71482 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
71483 +#define _TRACE_FS_H
71484 +
71485 +#include <linux/fs.h>
71486 +#include <linux/tracepoint.h>
71487 +
71488 +TRACE_EVENT(do_sys_open,
71489 +
71490 + TP_PROTO(const char *filename, int flags, int mode),
71491 +
71492 + TP_ARGS(filename, flags, mode),
71493 +
71494 + TP_STRUCT__entry(
71495 + __string( filename, filename )
71496 + __field( int, flags )
71497 + __field( int, mode )
71498 + ),
71499 +
71500 + TP_fast_assign(
71501 + __assign_str(filename, filename);
71502 + __entry->flags = flags;
71503 + __entry->mode = mode;
71504 + ),
71505 +
71506 + TP_printk("\"%s\" %x %o",
71507 + __get_str(filename), __entry->flags, __entry->mode)
71508 +);
71509 +
71510 +TRACE_EVENT(open_exec,
71511 +
71512 + TP_PROTO(const char *filename),
71513 +
71514 + TP_ARGS(filename),
71515 +
71516 + TP_STRUCT__entry(
71517 + __string( filename, filename )
71518 + ),
71519 +
71520 + TP_fast_assign(
71521 + __assign_str(filename, filename);
71522 + ),
71523 +
71524 + TP_printk("\"%s\"",
71525 + __get_str(filename))
71526 +);
71527 +
71528 +#endif /* _TRACE_FS_H */
71529 +
71530 +/* This part must be outside protection */
71531 +#include <trace/define_trace.h>
71532 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
71533 index 1c09820..7f5ec79 100644
71534 --- a/include/trace/events/irq.h
71535 +++ b/include/trace/events/irq.h
71536 @@ -36,7 +36,7 @@ struct softirq_action;
71537 */
71538 TRACE_EVENT(irq_handler_entry,
71539
71540 - TP_PROTO(int irq, struct irqaction *action),
71541 + TP_PROTO(int irq, const struct irqaction *action),
71542
71543 TP_ARGS(irq, action),
71544
71545 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
71546 */
71547 TRACE_EVENT(irq_handler_exit,
71548
71549 - TP_PROTO(int irq, struct irqaction *action, int ret),
71550 + TP_PROTO(int irq, const struct irqaction *action, int ret),
71551
71552 TP_ARGS(irq, action, ret),
71553
71554 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
71555 index 7caf44c..23c6f27 100644
71556 --- a/include/uapi/linux/a.out.h
71557 +++ b/include/uapi/linux/a.out.h
71558 @@ -39,6 +39,14 @@ enum machine_type {
71559 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
71560 };
71561
71562 +/* Constants for the N_FLAGS field */
71563 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
71564 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
71565 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
71566 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
71567 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
71568 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
71569 +
71570 #if !defined (N_MAGIC)
71571 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
71572 #endif
71573 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
71574 index d876736..b36014e 100644
71575 --- a/include/uapi/linux/byteorder/little_endian.h
71576 +++ b/include/uapi/linux/byteorder/little_endian.h
71577 @@ -42,51 +42,51 @@
71578
71579 static inline __le64 __cpu_to_le64p(const __u64 *p)
71580 {
71581 - return (__force __le64)*p;
71582 + return (__force const __le64)*p;
71583 }
71584 static inline __u64 __le64_to_cpup(const __le64 *p)
71585 {
71586 - return (__force __u64)*p;
71587 + return (__force const __u64)*p;
71588 }
71589 static inline __le32 __cpu_to_le32p(const __u32 *p)
71590 {
71591 - return (__force __le32)*p;
71592 + return (__force const __le32)*p;
71593 }
71594 static inline __u32 __le32_to_cpup(const __le32 *p)
71595 {
71596 - return (__force __u32)*p;
71597 + return (__force const __u32)*p;
71598 }
71599 static inline __le16 __cpu_to_le16p(const __u16 *p)
71600 {
71601 - return (__force __le16)*p;
71602 + return (__force const __le16)*p;
71603 }
71604 static inline __u16 __le16_to_cpup(const __le16 *p)
71605 {
71606 - return (__force __u16)*p;
71607 + return (__force const __u16)*p;
71608 }
71609 static inline __be64 __cpu_to_be64p(const __u64 *p)
71610 {
71611 - return (__force __be64)__swab64p(p);
71612 + return (__force const __be64)__swab64p(p);
71613 }
71614 static inline __u64 __be64_to_cpup(const __be64 *p)
71615 {
71616 - return __swab64p((__u64 *)p);
71617 + return __swab64p((const __u64 *)p);
71618 }
71619 static inline __be32 __cpu_to_be32p(const __u32 *p)
71620 {
71621 - return (__force __be32)__swab32p(p);
71622 + return (__force const __be32)__swab32p(p);
71623 }
71624 static inline __u32 __be32_to_cpup(const __be32 *p)
71625 {
71626 - return __swab32p((__u32 *)p);
71627 + return __swab32p((const __u32 *)p);
71628 }
71629 static inline __be16 __cpu_to_be16p(const __u16 *p)
71630 {
71631 - return (__force __be16)__swab16p(p);
71632 + return (__force const __be16)__swab16p(p);
71633 }
71634 static inline __u16 __be16_to_cpup(const __be16 *p)
71635 {
71636 - return __swab16p((__u16 *)p);
71637 + return __swab16p((const __u16 *)p);
71638 }
71639 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
71640 #define __le64_to_cpus(x) do { (void)(x); } while (0)
71641 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
71642 index 126a817..d522bd1 100644
71643 --- a/include/uapi/linux/elf.h
71644 +++ b/include/uapi/linux/elf.h
71645 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
71646 #define PT_GNU_EH_FRAME 0x6474e550
71647
71648 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
71649 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
71650 +
71651 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
71652 +
71653 +/* Constants for the e_flags field */
71654 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
71655 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
71656 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
71657 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
71658 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
71659 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
71660
71661 /*
71662 * Extended Numbering
71663 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
71664 #define DT_DEBUG 21
71665 #define DT_TEXTREL 22
71666 #define DT_JMPREL 23
71667 +#define DT_FLAGS 30
71668 + #define DF_TEXTREL 0x00000004
71669 #define DT_ENCODING 32
71670 #define OLD_DT_LOOS 0x60000000
71671 #define DT_LOOS 0x6000000d
71672 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
71673 #define PF_W 0x2
71674 #define PF_X 0x1
71675
71676 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
71677 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
71678 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
71679 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
71680 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
71681 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
71682 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
71683 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
71684 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
71685 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
71686 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
71687 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
71688 +
71689 typedef struct elf32_phdr{
71690 Elf32_Word p_type;
71691 Elf32_Off p_offset;
71692 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
71693 #define EI_OSABI 7
71694 #define EI_PAD 8
71695
71696 +#define EI_PAX 14
71697 +
71698 #define ELFMAG0 0x7f /* EI_MAG */
71699 #define ELFMAG1 'E'
71700 #define ELFMAG2 'L'
71701 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
71702 index aa169c4..6a2771d 100644
71703 --- a/include/uapi/linux/personality.h
71704 +++ b/include/uapi/linux/personality.h
71705 @@ -30,6 +30,7 @@ enum {
71706 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
71707 ADDR_NO_RANDOMIZE | \
71708 ADDR_COMPAT_LAYOUT | \
71709 + ADDR_LIMIT_3GB | \
71710 MMAP_PAGE_ZERO)
71711
71712 /*
71713 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
71714 index 7530e74..e714828 100644
71715 --- a/include/uapi/linux/screen_info.h
71716 +++ b/include/uapi/linux/screen_info.h
71717 @@ -43,7 +43,8 @@ struct screen_info {
71718 __u16 pages; /* 0x32 */
71719 __u16 vesa_attributes; /* 0x34 */
71720 __u32 capabilities; /* 0x36 */
71721 - __u8 _reserved[6]; /* 0x3a */
71722 + __u16 vesapm_size; /* 0x3a */
71723 + __u8 _reserved[4]; /* 0x3c */
71724 } __attribute__((packed));
71725
71726 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
71727 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
71728 index 6d67213..8dab561 100644
71729 --- a/include/uapi/linux/sysctl.h
71730 +++ b/include/uapi/linux/sysctl.h
71731 @@ -155,7 +155,11 @@ enum
71732 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
71733 };
71734
71735 -
71736 +#ifdef CONFIG_PAX_SOFTMODE
71737 +enum {
71738 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
71739 +};
71740 +#endif
71741
71742 /* CTL_VM names: */
71743 enum
71744 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
71745 index 26607bd..588b65f 100644
71746 --- a/include/uapi/linux/xattr.h
71747 +++ b/include/uapi/linux/xattr.h
71748 @@ -60,5 +60,9 @@
71749 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
71750 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
71751
71752 +/* User namespace */
71753 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
71754 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
71755 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
71756
71757 #endif /* _UAPI_LINUX_XATTR_H */
71758 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
71759 index f9466fa..f4e2b81 100644
71760 --- a/include/video/udlfb.h
71761 +++ b/include/video/udlfb.h
71762 @@ -53,10 +53,10 @@ struct dlfb_data {
71763 u32 pseudo_palette[256];
71764 int blank_mode; /*one of FB_BLANK_ */
71765 /* blit-only rendering path metrics, exposed through sysfs */
71766 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
71767 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
71768 - atomic_t bytes_sent; /* to usb, after compression including overhead */
71769 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
71770 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
71771 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
71772 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
71773 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
71774 };
71775
71776 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
71777 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
71778 index 0993a22..32ba2fe 100644
71779 --- a/include/video/uvesafb.h
71780 +++ b/include/video/uvesafb.h
71781 @@ -177,6 +177,7 @@ struct uvesafb_par {
71782 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
71783 u8 pmi_setpal; /* PMI for palette changes */
71784 u16 *pmi_base; /* protected mode interface location */
71785 + u8 *pmi_code; /* protected mode code location */
71786 void *pmi_start;
71787 void *pmi_pal;
71788 u8 *vbe_state_orig; /*
71789 diff --git a/init/Kconfig b/init/Kconfig
71790 index be8b7f5..1eeca9b 100644
71791 --- a/init/Kconfig
71792 +++ b/init/Kconfig
71793 @@ -990,6 +990,7 @@ endif # CGROUPS
71794
71795 config CHECKPOINT_RESTORE
71796 bool "Checkpoint/restore support" if EXPERT
71797 + depends on !GRKERNSEC
71798 default n
71799 help
71800 Enables additional kernel features in a sake of checkpoint/restore.
71801 @@ -1468,7 +1469,7 @@ config SLUB_DEBUG
71802
71803 config COMPAT_BRK
71804 bool "Disable heap randomization"
71805 - default y
71806 + default n
71807 help
71808 Randomizing heap placement makes heap exploits harder, but it
71809 also breaks ancient binaries (including anything libc5 based).
71810 @@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
71811 config STOP_MACHINE
71812 bool
71813 default y
71814 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
71815 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
71816 help
71817 Need stop_machine() primitive.
71818
71819 diff --git a/init/Makefile b/init/Makefile
71820 index 7bc47ee..6da2dc7 100644
71821 --- a/init/Makefile
71822 +++ b/init/Makefile
71823 @@ -2,6 +2,9 @@
71824 # Makefile for the linux kernel.
71825 #
71826
71827 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
71828 +asflags-y := $(GCC_PLUGINS_AFLAGS)
71829 +
71830 obj-y := main.o version.o mounts.o
71831 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
71832 obj-y += noinitramfs.o
71833 diff --git a/init/do_mounts.c b/init/do_mounts.c
71834 index 1d1b634..a1c810f 100644
71835 --- a/init/do_mounts.c
71836 +++ b/init/do_mounts.c
71837 @@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
71838 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
71839 {
71840 struct super_block *s;
71841 - int err = sys_mount(name, "/root", fs, flags, data);
71842 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
71843 if (err)
71844 return err;
71845
71846 - sys_chdir("/root");
71847 + sys_chdir((const char __force_user *)"/root");
71848 s = current->fs->pwd.dentry->d_sb;
71849 ROOT_DEV = s->s_dev;
71850 printk(KERN_INFO
71851 @@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
71852 va_start(args, fmt);
71853 vsprintf(buf, fmt, args);
71854 va_end(args);
71855 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
71856 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
71857 if (fd >= 0) {
71858 sys_ioctl(fd, FDEJECT, 0);
71859 sys_close(fd);
71860 }
71861 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
71862 - fd = sys_open("/dev/console", O_RDWR, 0);
71863 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
71864 if (fd >= 0) {
71865 sys_ioctl(fd, TCGETS, (long)&termios);
71866 termios.c_lflag &= ~ICANON;
71867 sys_ioctl(fd, TCSETSF, (long)&termios);
71868 - sys_read(fd, &c, 1);
71869 + sys_read(fd, (char __user *)&c, 1);
71870 termios.c_lflag |= ICANON;
71871 sys_ioctl(fd, TCSETSF, (long)&termios);
71872 sys_close(fd);
71873 @@ -585,6 +585,6 @@ void __init prepare_namespace(void)
71874 mount_root();
71875 out:
71876 devtmpfs_mount("dev");
71877 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
71878 - sys_chroot(".");
71879 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
71880 + sys_chroot((const char __force_user *)".");
71881 }
71882 diff --git a/init/do_mounts.h b/init/do_mounts.h
71883 index f5b978a..69dbfe8 100644
71884 --- a/init/do_mounts.h
71885 +++ b/init/do_mounts.h
71886 @@ -15,15 +15,15 @@ extern int root_mountflags;
71887
71888 static inline int create_dev(char *name, dev_t dev)
71889 {
71890 - sys_unlink(name);
71891 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
71892 + sys_unlink((char __force_user *)name);
71893 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
71894 }
71895
71896 #if BITS_PER_LONG == 32
71897 static inline u32 bstat(char *name)
71898 {
71899 struct stat64 stat;
71900 - if (sys_stat64(name, &stat) != 0)
71901 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
71902 return 0;
71903 if (!S_ISBLK(stat.st_mode))
71904 return 0;
71905 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
71906 static inline u32 bstat(char *name)
71907 {
71908 struct stat stat;
71909 - if (sys_newstat(name, &stat) != 0)
71910 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
71911 return 0;
71912 if (!S_ISBLK(stat.st_mode))
71913 return 0;
71914 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
71915 index f9acf71..1e19144 100644
71916 --- a/init/do_mounts_initrd.c
71917 +++ b/init/do_mounts_initrd.c
71918 @@ -58,8 +58,8 @@ static void __init handle_initrd(void)
71919 create_dev("/dev/root.old", Root_RAM0);
71920 /* mount initrd on rootfs' /root */
71921 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
71922 - sys_mkdir("/old", 0700);
71923 - sys_chdir("/old");
71924 + sys_mkdir((const char __force_user *)"/old", 0700);
71925 + sys_chdir((const char __force_user *)"/old");
71926
71927 /*
71928 * In case that a resume from disk is carried out by linuxrc or one of
71929 @@ -73,31 +73,31 @@ static void __init handle_initrd(void)
71930 current->flags &= ~PF_FREEZER_SKIP;
71931
71932 /* move initrd to rootfs' /old */
71933 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
71934 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
71935 /* switch root and cwd back to / of rootfs */
71936 - sys_chroot("..");
71937 + sys_chroot((const char __force_user *)"..");
71938
71939 if (new_decode_dev(real_root_dev) == Root_RAM0) {
71940 - sys_chdir("/old");
71941 + sys_chdir((const char __force_user *)"/old");
71942 return;
71943 }
71944
71945 - sys_chdir("/");
71946 + sys_chdir((const char __force_user *)"/");
71947 ROOT_DEV = new_decode_dev(real_root_dev);
71948 mount_root();
71949
71950 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
71951 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
71952 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
71953 if (!error)
71954 printk("okay\n");
71955 else {
71956 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
71957 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
71958 if (error == -ENOENT)
71959 printk("/initrd does not exist. Ignored.\n");
71960 else
71961 printk("failed\n");
71962 printk(KERN_NOTICE "Unmounting old root\n");
71963 - sys_umount("/old", MNT_DETACH);
71964 + sys_umount((char __force_user *)"/old", MNT_DETACH);
71965 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
71966 if (fd < 0) {
71967 error = fd;
71968 @@ -120,11 +120,11 @@ int __init initrd_load(void)
71969 * mounted in the normal path.
71970 */
71971 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
71972 - sys_unlink("/initrd.image");
71973 + sys_unlink((const char __force_user *)"/initrd.image");
71974 handle_initrd();
71975 return 1;
71976 }
71977 }
71978 - sys_unlink("/initrd.image");
71979 + sys_unlink((const char __force_user *)"/initrd.image");
71980 return 0;
71981 }
71982 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
71983 index 8cb6db5..d729f50 100644
71984 --- a/init/do_mounts_md.c
71985 +++ b/init/do_mounts_md.c
71986 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
71987 partitioned ? "_d" : "", minor,
71988 md_setup_args[ent].device_names);
71989
71990 - fd = sys_open(name, 0, 0);
71991 + fd = sys_open((char __force_user *)name, 0, 0);
71992 if (fd < 0) {
71993 printk(KERN_ERR "md: open failed - cannot start "
71994 "array %s\n", name);
71995 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
71996 * array without it
71997 */
71998 sys_close(fd);
71999 - fd = sys_open(name, 0, 0);
72000 + fd = sys_open((char __force_user *)name, 0, 0);
72001 sys_ioctl(fd, BLKRRPART, 0);
72002 }
72003 sys_close(fd);
72004 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
72005
72006 wait_for_device_probe();
72007
72008 - fd = sys_open("/dev/md0", 0, 0);
72009 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
72010 if (fd >= 0) {
72011 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
72012 sys_close(fd);
72013 diff --git a/init/init_task.c b/init/init_task.c
72014 index 8b2f399..f0797c9 100644
72015 --- a/init/init_task.c
72016 +++ b/init/init_task.c
72017 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
72018 * Initial thread structure. Alignment of this is handled by a special
72019 * linker map entry.
72020 */
72021 +#ifdef CONFIG_X86
72022 +union thread_union init_thread_union __init_task_data;
72023 +#else
72024 union thread_union init_thread_union __init_task_data =
72025 { INIT_THREAD_INFO(init_task) };
72026 +#endif
72027 diff --git a/init/initramfs.c b/init/initramfs.c
72028 index 84c6bf1..8899338 100644
72029 --- a/init/initramfs.c
72030 +++ b/init/initramfs.c
72031 @@ -84,7 +84,7 @@ static void __init free_hash(void)
72032 }
72033 }
72034
72035 -static long __init do_utime(char *filename, time_t mtime)
72036 +static long __init do_utime(char __force_user *filename, time_t mtime)
72037 {
72038 struct timespec t[2];
72039
72040 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
72041 struct dir_entry *de, *tmp;
72042 list_for_each_entry_safe(de, tmp, &dir_list, list) {
72043 list_del(&de->list);
72044 - do_utime(de->name, de->mtime);
72045 + do_utime((char __force_user *)de->name, de->mtime);
72046 kfree(de->name);
72047 kfree(de);
72048 }
72049 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
72050 if (nlink >= 2) {
72051 char *old = find_link(major, minor, ino, mode, collected);
72052 if (old)
72053 - return (sys_link(old, collected) < 0) ? -1 : 1;
72054 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
72055 }
72056 return 0;
72057 }
72058 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
72059 {
72060 struct stat st;
72061
72062 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
72063 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
72064 if (S_ISDIR(st.st_mode))
72065 - sys_rmdir(path);
72066 + sys_rmdir((char __force_user *)path);
72067 else
72068 - sys_unlink(path);
72069 + sys_unlink((char __force_user *)path);
72070 }
72071 }
72072
72073 @@ -315,7 +315,7 @@ static int __init do_name(void)
72074 int openflags = O_WRONLY|O_CREAT;
72075 if (ml != 1)
72076 openflags |= O_TRUNC;
72077 - wfd = sys_open(collected, openflags, mode);
72078 + wfd = sys_open((char __force_user *)collected, openflags, mode);
72079
72080 if (wfd >= 0) {
72081 sys_fchown(wfd, uid, gid);
72082 @@ -327,17 +327,17 @@ static int __init do_name(void)
72083 }
72084 }
72085 } else if (S_ISDIR(mode)) {
72086 - sys_mkdir(collected, mode);
72087 - sys_chown(collected, uid, gid);
72088 - sys_chmod(collected, mode);
72089 + sys_mkdir((char __force_user *)collected, mode);
72090 + sys_chown((char __force_user *)collected, uid, gid);
72091 + sys_chmod((char __force_user *)collected, mode);
72092 dir_add(collected, mtime);
72093 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
72094 S_ISFIFO(mode) || S_ISSOCK(mode)) {
72095 if (maybe_link() == 0) {
72096 - sys_mknod(collected, mode, rdev);
72097 - sys_chown(collected, uid, gid);
72098 - sys_chmod(collected, mode);
72099 - do_utime(collected, mtime);
72100 + sys_mknod((char __force_user *)collected, mode, rdev);
72101 + sys_chown((char __force_user *)collected, uid, gid);
72102 + sys_chmod((char __force_user *)collected, mode);
72103 + do_utime((char __force_user *)collected, mtime);
72104 }
72105 }
72106 return 0;
72107 @@ -346,15 +346,15 @@ static int __init do_name(void)
72108 static int __init do_copy(void)
72109 {
72110 if (count >= body_len) {
72111 - sys_write(wfd, victim, body_len);
72112 + sys_write(wfd, (char __force_user *)victim, body_len);
72113 sys_close(wfd);
72114 - do_utime(vcollected, mtime);
72115 + do_utime((char __force_user *)vcollected, mtime);
72116 kfree(vcollected);
72117 eat(body_len);
72118 state = SkipIt;
72119 return 0;
72120 } else {
72121 - sys_write(wfd, victim, count);
72122 + sys_write(wfd, (char __force_user *)victim, count);
72123 body_len -= count;
72124 eat(count);
72125 return 1;
72126 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
72127 {
72128 collected[N_ALIGN(name_len) + body_len] = '\0';
72129 clean_path(collected, 0);
72130 - sys_symlink(collected + N_ALIGN(name_len), collected);
72131 - sys_lchown(collected, uid, gid);
72132 - do_utime(collected, mtime);
72133 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
72134 + sys_lchown((char __force_user *)collected, uid, gid);
72135 + do_utime((char __force_user *)collected, mtime);
72136 state = SkipIt;
72137 next_state = Reset;
72138 return 0;
72139 diff --git a/init/main.c b/init/main.c
72140 index cee4b5c..9c267d9 100644
72141 --- a/init/main.c
72142 +++ b/init/main.c
72143 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
72144 extern void tc_init(void);
72145 #endif
72146
72147 +extern void grsecurity_init(void);
72148 +
72149 /*
72150 * Debug helper: via this flag we know that we are in 'early bootup code'
72151 * where only the boot processor is running with IRQ disabled. This means
72152 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
72153
72154 __setup("reset_devices", set_reset_devices);
72155
72156 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
72157 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
72158 +static int __init setup_grsec_proc_gid(char *str)
72159 +{
72160 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
72161 + return 1;
72162 +}
72163 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
72164 +#endif
72165 +
72166 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
72167 +extern char pax_enter_kernel_user[];
72168 +extern char pax_exit_kernel_user[];
72169 +extern pgdval_t clone_pgd_mask;
72170 +#endif
72171 +
72172 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
72173 +static int __init setup_pax_nouderef(char *str)
72174 +{
72175 +#ifdef CONFIG_X86_32
72176 + unsigned int cpu;
72177 + struct desc_struct *gdt;
72178 +
72179 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
72180 + gdt = get_cpu_gdt_table(cpu);
72181 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
72182 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
72183 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
72184 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
72185 + }
72186 + loadsegment(ds, __KERNEL_DS);
72187 + loadsegment(es, __KERNEL_DS);
72188 + loadsegment(ss, __KERNEL_DS);
72189 +#else
72190 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
72191 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
72192 + clone_pgd_mask = ~(pgdval_t)0UL;
72193 +#endif
72194 +
72195 + return 0;
72196 +}
72197 +early_param("pax_nouderef", setup_pax_nouderef);
72198 +#endif
72199 +
72200 +#ifdef CONFIG_PAX_SOFTMODE
72201 +int pax_softmode;
72202 +
72203 +static int __init setup_pax_softmode(char *str)
72204 +{
72205 + get_option(&str, &pax_softmode);
72206 + return 1;
72207 +}
72208 +__setup("pax_softmode=", setup_pax_softmode);
72209 +#endif
72210 +
72211 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
72212 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
72213 static const char *panic_later, *panic_param;
72214 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
72215 {
72216 int count = preempt_count();
72217 int ret;
72218 + const char *msg1 = "", *msg2 = "";
72219
72220 if (initcall_debug)
72221 ret = do_one_initcall_debug(fn);
72222 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
72223 sprintf(msgbuf, "error code %d ", ret);
72224
72225 if (preempt_count() != count) {
72226 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
72227 + msg1 = " preemption imbalance";
72228 preempt_count() = count;
72229 }
72230 if (irqs_disabled()) {
72231 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
72232 + msg2 = " disabled interrupts";
72233 local_irq_enable();
72234 }
72235 - if (msgbuf[0]) {
72236 - printk("initcall %pF returned with %s\n", fn, msgbuf);
72237 + if (msgbuf[0] || *msg1 || *msg2) {
72238 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
72239 }
72240
72241 return ret;
72242 @@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
72243 "late",
72244 };
72245
72246 +#ifdef CONFIG_PAX_LATENT_ENTROPY
72247 +u64 latent_entropy;
72248 +#endif
72249 +
72250 static void __init do_initcall_level(int level)
72251 {
72252 extern const struct kernel_param __start___param[], __stop___param[];
72253 @@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
72254 level, level,
72255 &repair_env_string);
72256
72257 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
72258 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
72259 do_one_initcall(*fn);
72260 +
72261 +#ifdef CONFIG_PAX_LATENT_ENTROPY
72262 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
72263 +#endif
72264 +
72265 + }
72266 }
72267
72268 static void __init do_initcalls(void)
72269 @@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
72270 {
72271 initcall_t *fn;
72272
72273 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
72274 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
72275 do_one_initcall(*fn);
72276 +
72277 +#ifdef CONFIG_PAX_LATENT_ENTROPY
72278 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
72279 +#endif
72280 +
72281 + }
72282 }
72283
72284 static int run_init_process(const char *init_filename)
72285 @@ -877,7 +951,7 @@ static noinline void __init kernel_init_freeable(void)
72286 do_basic_setup();
72287
72288 /* Open the /dev/console on the rootfs, this should never fail */
72289 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
72290 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
72291 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
72292
72293 (void) sys_dup(0);
72294 @@ -890,11 +964,13 @@ static noinline void __init kernel_init_freeable(void)
72295 if (!ramdisk_execute_command)
72296 ramdisk_execute_command = "/init";
72297
72298 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
72299 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
72300 ramdisk_execute_command = NULL;
72301 prepare_namespace();
72302 }
72303
72304 + grsecurity_init();
72305 +
72306 /*
72307 * Ok, we have completed the initial bootup, and
72308 * we're essentially up and running. Get rid of the
72309 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
72310 index 130dfec..cc88451 100644
72311 --- a/ipc/ipc_sysctl.c
72312 +++ b/ipc/ipc_sysctl.c
72313 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
72314 static int proc_ipc_dointvec(ctl_table *table, int write,
72315 void __user *buffer, size_t *lenp, loff_t *ppos)
72316 {
72317 - struct ctl_table ipc_table;
72318 + ctl_table_no_const ipc_table;
72319
72320 memcpy(&ipc_table, table, sizeof(ipc_table));
72321 ipc_table.data = get_ipc(table);
72322 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
72323 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
72324 void __user *buffer, size_t *lenp, loff_t *ppos)
72325 {
72326 - struct ctl_table ipc_table;
72327 + ctl_table_no_const ipc_table;
72328
72329 memcpy(&ipc_table, table, sizeof(ipc_table));
72330 ipc_table.data = get_ipc(table);
72331 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
72332 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
72333 void __user *buffer, size_t *lenp, loff_t *ppos)
72334 {
72335 - struct ctl_table ipc_table;
72336 + ctl_table_no_const ipc_table;
72337 size_t lenp_bef = *lenp;
72338 int rc;
72339
72340 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
72341 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
72342 void __user *buffer, size_t *lenp, loff_t *ppos)
72343 {
72344 - struct ctl_table ipc_table;
72345 + ctl_table_no_const ipc_table;
72346 memcpy(&ipc_table, table, sizeof(ipc_table));
72347 ipc_table.data = get_ipc(table);
72348
72349 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
72350 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
72351 void __user *buffer, size_t *lenp, loff_t *ppos)
72352 {
72353 - struct ctl_table ipc_table;
72354 + ctl_table_no_const ipc_table;
72355 size_t lenp_bef = *lenp;
72356 int oldval;
72357 int rc;
72358 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
72359 index 383d638..943fdbb 100644
72360 --- a/ipc/mq_sysctl.c
72361 +++ b/ipc/mq_sysctl.c
72362 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
72363 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
72364 void __user *buffer, size_t *lenp, loff_t *ppos)
72365 {
72366 - struct ctl_table mq_table;
72367 + ctl_table_no_const mq_table;
72368 memcpy(&mq_table, table, sizeof(mq_table));
72369 mq_table.data = get_mq(table);
72370
72371 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
72372 index 71a3ca1..cc330ee 100644
72373 --- a/ipc/mqueue.c
72374 +++ b/ipc/mqueue.c
72375 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
72376 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
72377 info->attr.mq_msgsize);
72378
72379 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
72380 spin_lock(&mq_lock);
72381 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
72382 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
72383 diff --git a/ipc/msg.c b/ipc/msg.c
72384 index 950572f..266c15f 100644
72385 --- a/ipc/msg.c
72386 +++ b/ipc/msg.c
72387 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
72388 return security_msg_queue_associate(msq, msgflg);
72389 }
72390
72391 +static struct ipc_ops msg_ops = {
72392 + .getnew = newque,
72393 + .associate = msg_security,
72394 + .more_checks = NULL
72395 +};
72396 +
72397 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
72398 {
72399 struct ipc_namespace *ns;
72400 - struct ipc_ops msg_ops;
72401 struct ipc_params msg_params;
72402
72403 ns = current->nsproxy->ipc_ns;
72404
72405 - msg_ops.getnew = newque;
72406 - msg_ops.associate = msg_security;
72407 - msg_ops.more_checks = NULL;
72408 -
72409 msg_params.key = key;
72410 msg_params.flg = msgflg;
72411
72412 diff --git a/ipc/sem.c b/ipc/sem.c
72413 index 58d31f1..cce7a55 100644
72414 --- a/ipc/sem.c
72415 +++ b/ipc/sem.c
72416 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
72417 return 0;
72418 }
72419
72420 +static struct ipc_ops sem_ops = {
72421 + .getnew = newary,
72422 + .associate = sem_security,
72423 + .more_checks = sem_more_checks
72424 +};
72425 +
72426 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
72427 {
72428 struct ipc_namespace *ns;
72429 - struct ipc_ops sem_ops;
72430 struct ipc_params sem_params;
72431
72432 ns = current->nsproxy->ipc_ns;
72433 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
72434 if (nsems < 0 || nsems > ns->sc_semmsl)
72435 return -EINVAL;
72436
72437 - sem_ops.getnew = newary;
72438 - sem_ops.associate = sem_security;
72439 - sem_ops.more_checks = sem_more_checks;
72440 -
72441 sem_params.key = key;
72442 sem_params.flg = semflg;
72443 sem_params.u.nsems = nsems;
72444 diff --git a/ipc/shm.c b/ipc/shm.c
72445 index 4fa6d8f..55cff14 100644
72446 --- a/ipc/shm.c
72447 +++ b/ipc/shm.c
72448 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
72449 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
72450 #endif
72451
72452 +#ifdef CONFIG_GRKERNSEC
72453 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72454 + const time_t shm_createtime, const kuid_t cuid,
72455 + const int shmid);
72456 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72457 + const time_t shm_createtime);
72458 +#endif
72459 +
72460 void shm_init_ns(struct ipc_namespace *ns)
72461 {
72462 ns->shm_ctlmax = SHMMAX;
72463 @@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
72464 shp->shm_lprid = 0;
72465 shp->shm_atim = shp->shm_dtim = 0;
72466 shp->shm_ctim = get_seconds();
72467 +#ifdef CONFIG_GRKERNSEC
72468 + {
72469 + struct timespec timeval;
72470 + do_posix_clock_monotonic_gettime(&timeval);
72471 +
72472 + shp->shm_createtime = timeval.tv_sec;
72473 + }
72474 +#endif
72475 shp->shm_segsz = size;
72476 shp->shm_nattch = 0;
72477 shp->shm_file = file;
72478 @@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
72479 return 0;
72480 }
72481
72482 +static struct ipc_ops shm_ops = {
72483 + .getnew = newseg,
72484 + .associate = shm_security,
72485 + .more_checks = shm_more_checks
72486 +};
72487 +
72488 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
72489 {
72490 struct ipc_namespace *ns;
72491 - struct ipc_ops shm_ops;
72492 struct ipc_params shm_params;
72493
72494 ns = current->nsproxy->ipc_ns;
72495
72496 - shm_ops.getnew = newseg;
72497 - shm_ops.associate = shm_security;
72498 - shm_ops.more_checks = shm_more_checks;
72499 -
72500 shm_params.key = key;
72501 shm_params.flg = shmflg;
72502 shm_params.u.size = size;
72503 @@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
72504 f_mode = FMODE_READ | FMODE_WRITE;
72505 }
72506 if (shmflg & SHM_EXEC) {
72507 +
72508 +#ifdef CONFIG_PAX_MPROTECT
72509 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
72510 + goto out;
72511 +#endif
72512 +
72513 prot |= PROT_EXEC;
72514 acc_mode |= S_IXUGO;
72515 }
72516 @@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
72517 if (err)
72518 goto out_unlock;
72519
72520 +#ifdef CONFIG_GRKERNSEC
72521 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
72522 + shp->shm_perm.cuid, shmid) ||
72523 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
72524 + err = -EACCES;
72525 + goto out_unlock;
72526 + }
72527 +#endif
72528 +
72529 path = shp->shm_file->f_path;
72530 path_get(&path);
72531 shp->shm_nattch++;
72532 +#ifdef CONFIG_GRKERNSEC
72533 + shp->shm_lapid = current->pid;
72534 +#endif
72535 size = i_size_read(path.dentry->d_inode);
72536 shm_unlock(shp);
72537
72538 diff --git a/kernel/acct.c b/kernel/acct.c
72539 index 051e071..15e0920 100644
72540 --- a/kernel/acct.c
72541 +++ b/kernel/acct.c
72542 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
72543 */
72544 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
72545 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
72546 - file->f_op->write(file, (char *)&ac,
72547 + file->f_op->write(file, (char __force_user *)&ac,
72548 sizeof(acct_t), &file->f_pos);
72549 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
72550 set_fs(fs);
72551 diff --git a/kernel/audit.c b/kernel/audit.c
72552 index d596e53..dbef3c3 100644
72553 --- a/kernel/audit.c
72554 +++ b/kernel/audit.c
72555 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
72556 3) suppressed due to audit_rate_limit
72557 4) suppressed due to audit_backlog_limit
72558 */
72559 -static atomic_t audit_lost = ATOMIC_INIT(0);
72560 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
72561
72562 /* The netlink socket. */
72563 static struct sock *audit_sock;
72564 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
72565 unsigned long now;
72566 int print;
72567
72568 - atomic_inc(&audit_lost);
72569 + atomic_inc_unchecked(&audit_lost);
72570
72571 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
72572
72573 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
72574 printk(KERN_WARNING
72575 "audit: audit_lost=%d audit_rate_limit=%d "
72576 "audit_backlog_limit=%d\n",
72577 - atomic_read(&audit_lost),
72578 + atomic_read_unchecked(&audit_lost),
72579 audit_rate_limit,
72580 audit_backlog_limit);
72581 audit_panic(message);
72582 @@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
72583 status_set.pid = audit_pid;
72584 status_set.rate_limit = audit_rate_limit;
72585 status_set.backlog_limit = audit_backlog_limit;
72586 - status_set.lost = atomic_read(&audit_lost);
72587 + status_set.lost = atomic_read_unchecked(&audit_lost);
72588 status_set.backlog = skb_queue_len(&audit_skb_queue);
72589 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
72590 &status_set, sizeof(status_set));
72591 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
72592 index a371f85..da826c1 100644
72593 --- a/kernel/auditsc.c
72594 +++ b/kernel/auditsc.c
72595 @@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
72596 }
72597
72598 /* global counter which is incremented every time something logs in */
72599 -static atomic_t session_id = ATOMIC_INIT(0);
72600 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
72601
72602 /**
72603 * audit_set_loginuid - set current task's audit_context loginuid
72604 @@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
72605 return -EPERM;
72606 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
72607
72608 - sessionid = atomic_inc_return(&session_id);
72609 + sessionid = atomic_inc_return_unchecked(&session_id);
72610 if (context && context->in_syscall) {
72611 struct audit_buffer *ab;
72612
72613 diff --git a/kernel/capability.c b/kernel/capability.c
72614 index 493d972..f87dfbd 100644
72615 --- a/kernel/capability.c
72616 +++ b/kernel/capability.c
72617 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
72618 * before modification is attempted and the application
72619 * fails.
72620 */
72621 + if (tocopy > ARRAY_SIZE(kdata))
72622 + return -EFAULT;
72623 +
72624 if (copy_to_user(dataptr, kdata, tocopy
72625 * sizeof(struct __user_cap_data_struct))) {
72626 return -EFAULT;
72627 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
72628 int ret;
72629
72630 rcu_read_lock();
72631 - ret = security_capable(__task_cred(t), ns, cap);
72632 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
72633 + gr_task_is_capable(t, __task_cred(t), cap);
72634 rcu_read_unlock();
72635
72636 - return (ret == 0);
72637 + return ret;
72638 }
72639
72640 /**
72641 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
72642 int ret;
72643
72644 rcu_read_lock();
72645 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
72646 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
72647 rcu_read_unlock();
72648
72649 - return (ret == 0);
72650 + return ret;
72651 }
72652
72653 /**
72654 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
72655 BUG();
72656 }
72657
72658 - if (security_capable(current_cred(), ns, cap) == 0) {
72659 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
72660 current->flags |= PF_SUPERPRIV;
72661 return true;
72662 }
72663 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
72664 }
72665 EXPORT_SYMBOL(ns_capable);
72666
72667 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
72668 +{
72669 + if (unlikely(!cap_valid(cap))) {
72670 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
72671 + BUG();
72672 + }
72673 +
72674 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
72675 + current->flags |= PF_SUPERPRIV;
72676 + return true;
72677 + }
72678 + return false;
72679 +}
72680 +EXPORT_SYMBOL(ns_capable_nolog);
72681 +
72682 /**
72683 * capable - Determine if the current task has a superior capability in effect
72684 * @cap: The capability to be tested for
72685 @@ -408,6 +427,12 @@ bool capable(int cap)
72686 }
72687 EXPORT_SYMBOL(capable);
72688
72689 +bool capable_nolog(int cap)
72690 +{
72691 + return ns_capable_nolog(&init_user_ns, cap);
72692 +}
72693 +EXPORT_SYMBOL(capable_nolog);
72694 +
72695 /**
72696 * nsown_capable - Check superior capability to one's own user_ns
72697 * @cap: The capability in question
72698 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
72699
72700 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
72701 }
72702 +
72703 +bool inode_capable_nolog(const struct inode *inode, int cap)
72704 +{
72705 + struct user_namespace *ns = current_user_ns();
72706 +
72707 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
72708 +}
72709 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
72710 index 1e23664..570a83d 100644
72711 --- a/kernel/cgroup.c
72712 +++ b/kernel/cgroup.c
72713 @@ -5543,7 +5543,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
72714 struct css_set *cg = link->cg;
72715 struct task_struct *task;
72716 int count = 0;
72717 - seq_printf(seq, "css_set %p\n", cg);
72718 + seq_printf(seq, "css_set %pK\n", cg);
72719 list_for_each_entry(task, &cg->tasks, cg_list) {
72720 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
72721 seq_puts(seq, " ...\n");
72722 diff --git a/kernel/compat.c b/kernel/compat.c
72723 index 36700e9..73d770c 100644
72724 --- a/kernel/compat.c
72725 +++ b/kernel/compat.c
72726 @@ -13,6 +13,7 @@
72727
72728 #include <linux/linkage.h>
72729 #include <linux/compat.h>
72730 +#include <linux/module.h>
72731 #include <linux/errno.h>
72732 #include <linux/time.h>
72733 #include <linux/signal.h>
72734 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
72735 mm_segment_t oldfs;
72736 long ret;
72737
72738 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
72739 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
72740 oldfs = get_fs();
72741 set_fs(KERNEL_DS);
72742 ret = hrtimer_nanosleep_restart(restart);
72743 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
72744 oldfs = get_fs();
72745 set_fs(KERNEL_DS);
72746 ret = hrtimer_nanosleep(&tu,
72747 - rmtp ? (struct timespec __user *)&rmt : NULL,
72748 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
72749 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
72750 set_fs(oldfs);
72751
72752 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
72753 mm_segment_t old_fs = get_fs();
72754
72755 set_fs(KERNEL_DS);
72756 - ret = sys_sigpending((old_sigset_t __user *) &s);
72757 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
72758 set_fs(old_fs);
72759 if (ret == 0)
72760 ret = put_user(s, set);
72761 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
72762 mm_segment_t old_fs = get_fs();
72763
72764 set_fs(KERNEL_DS);
72765 - ret = sys_old_getrlimit(resource, &r);
72766 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
72767 set_fs(old_fs);
72768
72769 if (!ret) {
72770 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
72771 mm_segment_t old_fs = get_fs();
72772
72773 set_fs(KERNEL_DS);
72774 - ret = sys_getrusage(who, (struct rusage __user *) &r);
72775 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
72776 set_fs(old_fs);
72777
72778 if (ret)
72779 @@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
72780 set_fs (KERNEL_DS);
72781 ret = sys_wait4(pid,
72782 (stat_addr ?
72783 - (unsigned int __user *) &status : NULL),
72784 - options, (struct rusage __user *) &r);
72785 + (unsigned int __force_user *) &status : NULL),
72786 + options, (struct rusage __force_user *) &r);
72787 set_fs (old_fs);
72788
72789 if (ret > 0) {
72790 @@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
72791 memset(&info, 0, sizeof(info));
72792
72793 set_fs(KERNEL_DS);
72794 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
72795 - uru ? (struct rusage __user *)&ru : NULL);
72796 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
72797 + uru ? (struct rusage __force_user *)&ru : NULL);
72798 set_fs(old_fs);
72799
72800 if ((ret < 0) || (info.si_signo == 0))
72801 @@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
72802 oldfs = get_fs();
72803 set_fs(KERNEL_DS);
72804 err = sys_timer_settime(timer_id, flags,
72805 - (struct itimerspec __user *) &newts,
72806 - (struct itimerspec __user *) &oldts);
72807 + (struct itimerspec __force_user *) &newts,
72808 + (struct itimerspec __force_user *) &oldts);
72809 set_fs(oldfs);
72810 if (!err && old && put_compat_itimerspec(old, &oldts))
72811 return -EFAULT;
72812 @@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
72813 oldfs = get_fs();
72814 set_fs(KERNEL_DS);
72815 err = sys_timer_gettime(timer_id,
72816 - (struct itimerspec __user *) &ts);
72817 + (struct itimerspec __force_user *) &ts);
72818 set_fs(oldfs);
72819 if (!err && put_compat_itimerspec(setting, &ts))
72820 return -EFAULT;
72821 @@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
72822 oldfs = get_fs();
72823 set_fs(KERNEL_DS);
72824 err = sys_clock_settime(which_clock,
72825 - (struct timespec __user *) &ts);
72826 + (struct timespec __force_user *) &ts);
72827 set_fs(oldfs);
72828 return err;
72829 }
72830 @@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
72831 oldfs = get_fs();
72832 set_fs(KERNEL_DS);
72833 err = sys_clock_gettime(which_clock,
72834 - (struct timespec __user *) &ts);
72835 + (struct timespec __force_user *) &ts);
72836 set_fs(oldfs);
72837 if (!err && put_compat_timespec(&ts, tp))
72838 return -EFAULT;
72839 @@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
72840
72841 oldfs = get_fs();
72842 set_fs(KERNEL_DS);
72843 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
72844 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
72845 set_fs(oldfs);
72846
72847 err = compat_put_timex(utp, &txc);
72848 @@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
72849 oldfs = get_fs();
72850 set_fs(KERNEL_DS);
72851 err = sys_clock_getres(which_clock,
72852 - (struct timespec __user *) &ts);
72853 + (struct timespec __force_user *) &ts);
72854 set_fs(oldfs);
72855 if (!err && tp && put_compat_timespec(&ts, tp))
72856 return -EFAULT;
72857 @@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
72858 long err;
72859 mm_segment_t oldfs;
72860 struct timespec tu;
72861 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
72862 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
72863
72864 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
72865 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
72866 oldfs = get_fs();
72867 set_fs(KERNEL_DS);
72868 err = clock_nanosleep_restart(restart);
72869 @@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
72870 oldfs = get_fs();
72871 set_fs(KERNEL_DS);
72872 err = sys_clock_nanosleep(which_clock, flags,
72873 - (struct timespec __user *) &in,
72874 - (struct timespec __user *) &out);
72875 + (struct timespec __force_user *) &in,
72876 + (struct timespec __force_user *) &out);
72877 set_fs(oldfs);
72878
72879 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
72880 diff --git a/kernel/configs.c b/kernel/configs.c
72881 index 42e8fa0..9e7406b 100644
72882 --- a/kernel/configs.c
72883 +++ b/kernel/configs.c
72884 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
72885 struct proc_dir_entry *entry;
72886
72887 /* create the current config file */
72888 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
72889 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
72890 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
72891 + &ikconfig_file_ops);
72892 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72893 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
72894 + &ikconfig_file_ops);
72895 +#endif
72896 +#else
72897 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
72898 &ikconfig_file_ops);
72899 +#endif
72900 +
72901 if (!entry)
72902 return -ENOMEM;
72903
72904 diff --git a/kernel/cred.c b/kernel/cred.c
72905 index e0573a4..3874e41 100644
72906 --- a/kernel/cred.c
72907 +++ b/kernel/cred.c
72908 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
72909 validate_creds(cred);
72910 alter_cred_subscribers(cred, -1);
72911 put_cred(cred);
72912 +
72913 +#ifdef CONFIG_GRKERNSEC_SETXID
72914 + cred = (struct cred *) tsk->delayed_cred;
72915 + if (cred != NULL) {
72916 + tsk->delayed_cred = NULL;
72917 + validate_creds(cred);
72918 + alter_cred_subscribers(cred, -1);
72919 + put_cred(cred);
72920 + }
72921 +#endif
72922 }
72923
72924 /**
72925 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
72926 * Always returns 0 thus allowing this function to be tail-called at the end
72927 * of, say, sys_setgid().
72928 */
72929 -int commit_creds(struct cred *new)
72930 +static int __commit_creds(struct cred *new)
72931 {
72932 struct task_struct *task = current;
72933 const struct cred *old = task->real_cred;
72934 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
72935
72936 get_cred(new); /* we will require a ref for the subj creds too */
72937
72938 + gr_set_role_label(task, new->uid, new->gid);
72939 +
72940 /* dumpability changes */
72941 if (!uid_eq(old->euid, new->euid) ||
72942 !gid_eq(old->egid, new->egid) ||
72943 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
72944 put_cred(old);
72945 return 0;
72946 }
72947 +#ifdef CONFIG_GRKERNSEC_SETXID
72948 +extern int set_user(struct cred *new);
72949 +
72950 +void gr_delayed_cred_worker(void)
72951 +{
72952 + const struct cred *new = current->delayed_cred;
72953 + struct cred *ncred;
72954 +
72955 + current->delayed_cred = NULL;
72956 +
72957 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
72958 + // from doing get_cred on it when queueing this
72959 + put_cred(new);
72960 + return;
72961 + } else if (new == NULL)
72962 + return;
72963 +
72964 + ncred = prepare_creds();
72965 + if (!ncred)
72966 + goto die;
72967 + // uids
72968 + ncred->uid = new->uid;
72969 + ncred->euid = new->euid;
72970 + ncred->suid = new->suid;
72971 + ncred->fsuid = new->fsuid;
72972 + // gids
72973 + ncred->gid = new->gid;
72974 + ncred->egid = new->egid;
72975 + ncred->sgid = new->sgid;
72976 + ncred->fsgid = new->fsgid;
72977 + // groups
72978 + if (set_groups(ncred, new->group_info) < 0) {
72979 + abort_creds(ncred);
72980 + goto die;
72981 + }
72982 + // caps
72983 + ncred->securebits = new->securebits;
72984 + ncred->cap_inheritable = new->cap_inheritable;
72985 + ncred->cap_permitted = new->cap_permitted;
72986 + ncred->cap_effective = new->cap_effective;
72987 + ncred->cap_bset = new->cap_bset;
72988 +
72989 + if (set_user(ncred)) {
72990 + abort_creds(ncred);
72991 + goto die;
72992 + }
72993 +
72994 + // from doing get_cred on it when queueing this
72995 + put_cred(new);
72996 +
72997 + __commit_creds(ncred);
72998 + return;
72999 +die:
73000 + // from doing get_cred on it when queueing this
73001 + put_cred(new);
73002 + do_group_exit(SIGKILL);
73003 +}
73004 +#endif
73005 +
73006 +int commit_creds(struct cred *new)
73007 +{
73008 +#ifdef CONFIG_GRKERNSEC_SETXID
73009 + int ret;
73010 + int schedule_it = 0;
73011 + struct task_struct *t;
73012 +
73013 + /* we won't get called with tasklist_lock held for writing
73014 + and interrupts disabled as the cred struct in that case is
73015 + init_cred
73016 + */
73017 + if (grsec_enable_setxid && !current_is_single_threaded() &&
73018 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
73019 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
73020 + schedule_it = 1;
73021 + }
73022 + ret = __commit_creds(new);
73023 + if (schedule_it) {
73024 + rcu_read_lock();
73025 + read_lock(&tasklist_lock);
73026 + for (t = next_thread(current); t != current;
73027 + t = next_thread(t)) {
73028 + if (t->delayed_cred == NULL) {
73029 + t->delayed_cred = get_cred(new);
73030 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
73031 + set_tsk_need_resched(t);
73032 + }
73033 + }
73034 + read_unlock(&tasklist_lock);
73035 + rcu_read_unlock();
73036 + }
73037 + return ret;
73038 +#else
73039 + return __commit_creds(new);
73040 +#endif
73041 +}
73042 +
73043 EXPORT_SYMBOL(commit_creds);
73044
73045 /**
73046 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
73047 index 9a61738..c5c8f3a 100644
73048 --- a/kernel/debug/debug_core.c
73049 +++ b/kernel/debug/debug_core.c
73050 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
73051 */
73052 static atomic_t masters_in_kgdb;
73053 static atomic_t slaves_in_kgdb;
73054 -static atomic_t kgdb_break_tasklet_var;
73055 +static atomic_unchecked_t kgdb_break_tasklet_var;
73056 atomic_t kgdb_setting_breakpoint;
73057
73058 struct task_struct *kgdb_usethread;
73059 @@ -132,7 +132,7 @@ int kgdb_single_step;
73060 static pid_t kgdb_sstep_pid;
73061
73062 /* to keep track of the CPU which is doing the single stepping*/
73063 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73064 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73065
73066 /*
73067 * If you are debugging a problem where roundup (the collection of
73068 @@ -540,7 +540,7 @@ return_normal:
73069 * kernel will only try for the value of sstep_tries before
73070 * giving up and continuing on.
73071 */
73072 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
73073 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
73074 (kgdb_info[cpu].task &&
73075 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
73076 atomic_set(&kgdb_active, -1);
73077 @@ -634,8 +634,8 @@ cpu_master_loop:
73078 }
73079
73080 kgdb_restore:
73081 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
73082 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
73083 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
73084 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
73085 if (kgdb_info[sstep_cpu].task)
73086 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
73087 else
73088 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
73089 static void kgdb_tasklet_bpt(unsigned long ing)
73090 {
73091 kgdb_breakpoint();
73092 - atomic_set(&kgdb_break_tasklet_var, 0);
73093 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
73094 }
73095
73096 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
73097
73098 void kgdb_schedule_breakpoint(void)
73099 {
73100 - if (atomic_read(&kgdb_break_tasklet_var) ||
73101 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
73102 atomic_read(&kgdb_active) != -1 ||
73103 atomic_read(&kgdb_setting_breakpoint))
73104 return;
73105 - atomic_inc(&kgdb_break_tasklet_var);
73106 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
73107 tasklet_schedule(&kgdb_tasklet_breakpoint);
73108 }
73109 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
73110 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
73111 index 8875254..7cf4928 100644
73112 --- a/kernel/debug/kdb/kdb_main.c
73113 +++ b/kernel/debug/kdb/kdb_main.c
73114 @@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
73115 continue;
73116
73117 kdb_printf("%-20s%8u 0x%p ", mod->name,
73118 - mod->core_size, (void *)mod);
73119 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
73120 #ifdef CONFIG_MODULE_UNLOAD
73121 kdb_printf("%4ld ", module_refcount(mod));
73122 #endif
73123 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
73124 kdb_printf(" (Loading)");
73125 else
73126 kdb_printf(" (Live)");
73127 - kdb_printf(" 0x%p", mod->module_core);
73128 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
73129
73130 #ifdef CONFIG_MODULE_UNLOAD
73131 {
73132 diff --git a/kernel/events/core.c b/kernel/events/core.c
73133 index 7b6646a..3cb1135 100644
73134 --- a/kernel/events/core.c
73135 +++ b/kernel/events/core.c
73136 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
73137 return 0;
73138 }
73139
73140 -static atomic64_t perf_event_id;
73141 +static atomic64_unchecked_t perf_event_id;
73142
73143 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
73144 enum event_type_t event_type);
73145 @@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
73146
73147 static inline u64 perf_event_count(struct perf_event *event)
73148 {
73149 - return local64_read(&event->count) + atomic64_read(&event->child_count);
73150 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
73151 }
73152
73153 static u64 perf_event_read(struct perf_event *event)
73154 @@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
73155 mutex_lock(&event->child_mutex);
73156 total += perf_event_read(event);
73157 *enabled += event->total_time_enabled +
73158 - atomic64_read(&event->child_total_time_enabled);
73159 + atomic64_read_unchecked(&event->child_total_time_enabled);
73160 *running += event->total_time_running +
73161 - atomic64_read(&event->child_total_time_running);
73162 + atomic64_read_unchecked(&event->child_total_time_running);
73163
73164 list_for_each_entry(child, &event->child_list, child_list) {
73165 total += perf_event_read(child);
73166 @@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
73167 userpg->offset -= local64_read(&event->hw.prev_count);
73168
73169 userpg->time_enabled = enabled +
73170 - atomic64_read(&event->child_total_time_enabled);
73171 + atomic64_read_unchecked(&event->child_total_time_enabled);
73172
73173 userpg->time_running = running +
73174 - atomic64_read(&event->child_total_time_running);
73175 + atomic64_read_unchecked(&event->child_total_time_running);
73176
73177 arch_perf_update_userpage(userpg, now);
73178
73179 @@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
73180 values[n++] = perf_event_count(event);
73181 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
73182 values[n++] = enabled +
73183 - atomic64_read(&event->child_total_time_enabled);
73184 + atomic64_read_unchecked(&event->child_total_time_enabled);
73185 }
73186 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
73187 values[n++] = running +
73188 - atomic64_read(&event->child_total_time_running);
73189 + atomic64_read_unchecked(&event->child_total_time_running);
73190 }
73191 if (read_format & PERF_FORMAT_ID)
73192 values[n++] = primary_event_id(event);
73193 @@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
73194 * need to add enough zero bytes after the string to handle
73195 * the 64bit alignment we do later.
73196 */
73197 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
73198 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
73199 if (!buf) {
73200 name = strncpy(tmp, "//enomem", sizeof(tmp));
73201 goto got_name;
73202 }
73203 - name = d_path(&file->f_path, buf, PATH_MAX);
73204 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
73205 if (IS_ERR(name)) {
73206 name = strncpy(tmp, "//toolong", sizeof(tmp));
73207 goto got_name;
73208 @@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
73209 event->parent = parent_event;
73210
73211 event->ns = get_pid_ns(task_active_pid_ns(current));
73212 - event->id = atomic64_inc_return(&perf_event_id);
73213 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
73214
73215 event->state = PERF_EVENT_STATE_INACTIVE;
73216
73217 @@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
73218 /*
73219 * Add back the child's count to the parent's count:
73220 */
73221 - atomic64_add(child_val, &parent_event->child_count);
73222 - atomic64_add(child_event->total_time_enabled,
73223 + atomic64_add_unchecked(child_val, &parent_event->child_count);
73224 + atomic64_add_unchecked(child_event->total_time_enabled,
73225 &parent_event->child_total_time_enabled);
73226 - atomic64_add(child_event->total_time_running,
73227 + atomic64_add_unchecked(child_event->total_time_running,
73228 &parent_event->child_total_time_running);
73229
73230 /*
73231 diff --git a/kernel/exit.c b/kernel/exit.c
73232 index b4df219..f13c02d 100644
73233 --- a/kernel/exit.c
73234 +++ b/kernel/exit.c
73235 @@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
73236 struct task_struct *leader;
73237 int zap_leader;
73238 repeat:
73239 +#ifdef CONFIG_NET
73240 + gr_del_task_from_ip_table(p);
73241 +#endif
73242 +
73243 /* don't need to get the RCU readlock here - the process is dead and
73244 * can't be modifying its own credentials. But shut RCU-lockdep up */
73245 rcu_read_lock();
73246 @@ -338,7 +342,7 @@ int allow_signal(int sig)
73247 * know it'll be handled, so that they don't get converted to
73248 * SIGKILL or just silently dropped.
73249 */
73250 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
73251 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
73252 recalc_sigpending();
73253 spin_unlock_irq(&current->sighand->siglock);
73254 return 0;
73255 @@ -708,6 +712,8 @@ void do_exit(long code)
73256 struct task_struct *tsk = current;
73257 int group_dead;
73258
73259 + set_fs(USER_DS);
73260 +
73261 profile_task_exit(tsk);
73262
73263 WARN_ON(blk_needs_flush_plug(tsk));
73264 @@ -724,7 +730,6 @@ void do_exit(long code)
73265 * mm_release()->clear_child_tid() from writing to a user-controlled
73266 * kernel address.
73267 */
73268 - set_fs(USER_DS);
73269
73270 ptrace_event(PTRACE_EVENT_EXIT, code);
73271
73272 @@ -783,6 +788,9 @@ void do_exit(long code)
73273 tsk->exit_code = code;
73274 taskstats_exit(tsk, group_dead);
73275
73276 + gr_acl_handle_psacct(tsk, code);
73277 + gr_acl_handle_exit();
73278 +
73279 exit_mm(tsk);
73280
73281 if (group_dead)
73282 @@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
73283 * Take down every thread in the group. This is called by fatal signals
73284 * as well as by sys_exit_group (below).
73285 */
73286 -void
73287 +__noreturn void
73288 do_group_exit(int exit_code)
73289 {
73290 struct signal_struct *sig = current->signal;
73291 diff --git a/kernel/fork.c b/kernel/fork.c
73292 index c535f33..1d768f9 100644
73293 --- a/kernel/fork.c
73294 +++ b/kernel/fork.c
73295 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
73296 *stackend = STACK_END_MAGIC; /* for overflow detection */
73297
73298 #ifdef CONFIG_CC_STACKPROTECTOR
73299 - tsk->stack_canary = get_random_int();
73300 + tsk->stack_canary = pax_get_random_long();
73301 #endif
73302
73303 /*
73304 @@ -344,13 +344,81 @@ free_tsk:
73305 }
73306
73307 #ifdef CONFIG_MMU
73308 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
73309 +{
73310 + struct vm_area_struct *tmp;
73311 + unsigned long charge;
73312 + struct mempolicy *pol;
73313 + struct file *file;
73314 +
73315 + charge = 0;
73316 + if (mpnt->vm_flags & VM_ACCOUNT) {
73317 + unsigned long len = vma_pages(mpnt);
73318 +
73319 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
73320 + goto fail_nomem;
73321 + charge = len;
73322 + }
73323 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73324 + if (!tmp)
73325 + goto fail_nomem;
73326 + *tmp = *mpnt;
73327 + tmp->vm_mm = mm;
73328 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
73329 + pol = mpol_dup(vma_policy(mpnt));
73330 + if (IS_ERR(pol))
73331 + goto fail_nomem_policy;
73332 + vma_set_policy(tmp, pol);
73333 + if (anon_vma_fork(tmp, mpnt))
73334 + goto fail_nomem_anon_vma_fork;
73335 + tmp->vm_flags &= ~VM_LOCKED;
73336 + tmp->vm_next = tmp->vm_prev = NULL;
73337 + tmp->vm_mirror = NULL;
73338 + file = tmp->vm_file;
73339 + if (file) {
73340 + struct inode *inode = file->f_path.dentry->d_inode;
73341 + struct address_space *mapping = file->f_mapping;
73342 +
73343 + get_file(file);
73344 + if (tmp->vm_flags & VM_DENYWRITE)
73345 + atomic_dec(&inode->i_writecount);
73346 + mutex_lock(&mapping->i_mmap_mutex);
73347 + if (tmp->vm_flags & VM_SHARED)
73348 + mapping->i_mmap_writable++;
73349 + flush_dcache_mmap_lock(mapping);
73350 + /* insert tmp into the share list, just after mpnt */
73351 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
73352 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
73353 + else
73354 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
73355 + flush_dcache_mmap_unlock(mapping);
73356 + mutex_unlock(&mapping->i_mmap_mutex);
73357 + }
73358 +
73359 + /*
73360 + * Clear hugetlb-related page reserves for children. This only
73361 + * affects MAP_PRIVATE mappings. Faults generated by the child
73362 + * are not guaranteed to succeed, even if read-only
73363 + */
73364 + if (is_vm_hugetlb_page(tmp))
73365 + reset_vma_resv_huge_pages(tmp);
73366 +
73367 + return tmp;
73368 +
73369 +fail_nomem_anon_vma_fork:
73370 + mpol_put(pol);
73371 +fail_nomem_policy:
73372 + kmem_cache_free(vm_area_cachep, tmp);
73373 +fail_nomem:
73374 + vm_unacct_memory(charge);
73375 + return NULL;
73376 +}
73377 +
73378 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73379 {
73380 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
73381 struct rb_node **rb_link, *rb_parent;
73382 int retval;
73383 - unsigned long charge;
73384 - struct mempolicy *pol;
73385
73386 uprobe_start_dup_mmap();
73387 down_write(&oldmm->mmap_sem);
73388 @@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73389 mm->locked_vm = 0;
73390 mm->mmap = NULL;
73391 mm->mmap_cache = NULL;
73392 - mm->free_area_cache = oldmm->mmap_base;
73393 - mm->cached_hole_size = ~0UL;
73394 + mm->free_area_cache = oldmm->free_area_cache;
73395 + mm->cached_hole_size = oldmm->cached_hole_size;
73396 mm->map_count = 0;
73397 cpumask_clear(mm_cpumask(mm));
73398 mm->mm_rb = RB_ROOT;
73399 @@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73400
73401 prev = NULL;
73402 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
73403 - struct file *file;
73404 -
73405 if (mpnt->vm_flags & VM_DONTCOPY) {
73406 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
73407 -vma_pages(mpnt));
73408 continue;
73409 }
73410 - charge = 0;
73411 - if (mpnt->vm_flags & VM_ACCOUNT) {
73412 - unsigned long len = vma_pages(mpnt);
73413 -
73414 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
73415 - goto fail_nomem;
73416 - charge = len;
73417 - }
73418 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73419 - if (!tmp)
73420 - goto fail_nomem;
73421 - *tmp = *mpnt;
73422 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
73423 - pol = mpol_dup(vma_policy(mpnt));
73424 - retval = PTR_ERR(pol);
73425 - if (IS_ERR(pol))
73426 - goto fail_nomem_policy;
73427 - vma_set_policy(tmp, pol);
73428 - tmp->vm_mm = mm;
73429 - if (anon_vma_fork(tmp, mpnt))
73430 - goto fail_nomem_anon_vma_fork;
73431 - tmp->vm_flags &= ~VM_LOCKED;
73432 - tmp->vm_next = tmp->vm_prev = NULL;
73433 - file = tmp->vm_file;
73434 - if (file) {
73435 - struct inode *inode = file->f_path.dentry->d_inode;
73436 - struct address_space *mapping = file->f_mapping;
73437 -
73438 - get_file(file);
73439 - if (tmp->vm_flags & VM_DENYWRITE)
73440 - atomic_dec(&inode->i_writecount);
73441 - mutex_lock(&mapping->i_mmap_mutex);
73442 - if (tmp->vm_flags & VM_SHARED)
73443 - mapping->i_mmap_writable++;
73444 - flush_dcache_mmap_lock(mapping);
73445 - /* insert tmp into the share list, just after mpnt */
73446 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
73447 - vma_nonlinear_insert(tmp,
73448 - &mapping->i_mmap_nonlinear);
73449 - else
73450 - vma_interval_tree_insert_after(tmp, mpnt,
73451 - &mapping->i_mmap);
73452 - flush_dcache_mmap_unlock(mapping);
73453 - mutex_unlock(&mapping->i_mmap_mutex);
73454 + tmp = dup_vma(mm, oldmm, mpnt);
73455 + if (!tmp) {
73456 + retval = -ENOMEM;
73457 + goto out;
73458 }
73459
73460 /*
73461 @@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73462 if (retval)
73463 goto out;
73464 }
73465 +
73466 +#ifdef CONFIG_PAX_SEGMEXEC
73467 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
73468 + struct vm_area_struct *mpnt_m;
73469 +
73470 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
73471 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
73472 +
73473 + if (!mpnt->vm_mirror)
73474 + continue;
73475 +
73476 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
73477 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
73478 + mpnt->vm_mirror = mpnt_m;
73479 + } else {
73480 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
73481 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
73482 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
73483 + mpnt->vm_mirror->vm_mirror = mpnt;
73484 + }
73485 + }
73486 + BUG_ON(mpnt_m);
73487 + }
73488 +#endif
73489 +
73490 /* a new mm has just been created */
73491 arch_dup_mmap(oldmm, mm);
73492 retval = 0;
73493 @@ -472,14 +523,6 @@ out:
73494 up_write(&oldmm->mmap_sem);
73495 uprobe_end_dup_mmap();
73496 return retval;
73497 -fail_nomem_anon_vma_fork:
73498 - mpol_put(pol);
73499 -fail_nomem_policy:
73500 - kmem_cache_free(vm_area_cachep, tmp);
73501 -fail_nomem:
73502 - retval = -ENOMEM;
73503 - vm_unacct_memory(charge);
73504 - goto out;
73505 }
73506
73507 static inline int mm_alloc_pgd(struct mm_struct *mm)
73508 @@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
73509 return ERR_PTR(err);
73510
73511 mm = get_task_mm(task);
73512 - if (mm && mm != current->mm &&
73513 - !ptrace_may_access(task, mode)) {
73514 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
73515 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
73516 mmput(mm);
73517 mm = ERR_PTR(-EACCES);
73518 }
73519 @@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
73520 spin_unlock(&fs->lock);
73521 return -EAGAIN;
73522 }
73523 - fs->users++;
73524 + atomic_inc(&fs->users);
73525 spin_unlock(&fs->lock);
73526 return 0;
73527 }
73528 tsk->fs = copy_fs_struct(fs);
73529 if (!tsk->fs)
73530 return -ENOMEM;
73531 + /* Carry through gr_chroot_dentry and is_chrooted instead
73532 + of recomputing it here. Already copied when the task struct
73533 + is duplicated. This allows pivot_root to not be treated as
73534 + a chroot
73535 + */
73536 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
73537 +
73538 return 0;
73539 }
73540
73541 @@ -1193,6 +1243,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
73542 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
73543 #endif
73544 retval = -EAGAIN;
73545 +
73546 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
73547 +
73548 if (atomic_read(&p->real_cred->user->processes) >=
73549 task_rlimit(p, RLIMIT_NPROC)) {
73550 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
73551 @@ -1432,6 +1485,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
73552 goto bad_fork_free_pid;
73553 }
73554
73555 + /* synchronizes with gr_set_acls()
73556 + we need to call this past the point of no return for fork()
73557 + */
73558 + gr_copy_label(p);
73559 +
73560 if (clone_flags & CLONE_THREAD) {
73561 current->signal->nr_threads++;
73562 atomic_inc(&current->signal->live);
73563 @@ -1515,6 +1573,8 @@ bad_fork_cleanup_count:
73564 bad_fork_free:
73565 free_task(p);
73566 fork_out:
73567 + gr_log_forkfail(retval);
73568 +
73569 return ERR_PTR(retval);
73570 }
73571
73572 @@ -1565,6 +1625,23 @@ long do_fork(unsigned long clone_flags,
73573 return -EINVAL;
73574 }
73575
73576 +#ifdef CONFIG_GRKERNSEC
73577 + if (clone_flags & CLONE_NEWUSER) {
73578 + /*
73579 + * This doesn't really inspire confidence:
73580 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
73581 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
73582 + * Increases kernel attack surface in areas developers
73583 + * previously cared little about ("low importance due
73584 + * to requiring "root" capability")
73585 + * To be removed when this code receives *proper* review
73586 + */
73587 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
73588 + !capable(CAP_SETGID))
73589 + return -EPERM;
73590 + }
73591 +#endif
73592 +
73593 /*
73594 * Determine whether and which event to report to ptracer. When
73595 * called from kernel_thread or CLONE_UNTRACED is explicitly
73596 @@ -1599,6 +1676,8 @@ long do_fork(unsigned long clone_flags,
73597 if (clone_flags & CLONE_PARENT_SETTID)
73598 put_user(nr, parent_tidptr);
73599
73600 + gr_handle_brute_check();
73601 +
73602 if (clone_flags & CLONE_VFORK) {
73603 p->vfork_done = &vfork;
73604 init_completion(&vfork);
73605 @@ -1752,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
73606 return 0;
73607
73608 /* don't need lock here; in the worst case we'll do useless copy */
73609 - if (fs->users == 1)
73610 + if (atomic_read(&fs->users) == 1)
73611 return 0;
73612
73613 *new_fsp = copy_fs_struct(fs);
73614 @@ -1866,7 +1945,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
73615 fs = current->fs;
73616 spin_lock(&fs->lock);
73617 current->fs = new_fs;
73618 - if (--fs->users)
73619 + gr_set_chroot_entries(current, &current->fs->root);
73620 + if (atomic_dec_return(&fs->users))
73621 new_fs = NULL;
73622 else
73623 new_fs = fs;
73624 diff --git a/kernel/futex.c b/kernel/futex.c
73625 index 8879430..31696f1 100644
73626 --- a/kernel/futex.c
73627 +++ b/kernel/futex.c
73628 @@ -54,6 +54,7 @@
73629 #include <linux/mount.h>
73630 #include <linux/pagemap.h>
73631 #include <linux/syscalls.h>
73632 +#include <linux/ptrace.h>
73633 #include <linux/signal.h>
73634 #include <linux/export.h>
73635 #include <linux/magic.h>
73636 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
73637 struct page *page, *page_head;
73638 int err, ro = 0;
73639
73640 +#ifdef CONFIG_PAX_SEGMEXEC
73641 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
73642 + return -EFAULT;
73643 +#endif
73644 +
73645 /*
73646 * The futex address must be "naturally" aligned.
73647 */
73648 @@ -2731,6 +2737,7 @@ static int __init futex_init(void)
73649 {
73650 u32 curval;
73651 int i;
73652 + mm_segment_t oldfs;
73653
73654 /*
73655 * This will fail and we want it. Some arch implementations do
73656 @@ -2742,8 +2749,11 @@ static int __init futex_init(void)
73657 * implementation, the non-functional ones will return
73658 * -ENOSYS.
73659 */
73660 + oldfs = get_fs();
73661 + set_fs(USER_DS);
73662 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
73663 futex_cmpxchg_enabled = 1;
73664 + set_fs(oldfs);
73665
73666 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
73667 plist_head_init(&futex_queues[i].chain);
73668 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
73669 index 9b22d03..6295b62 100644
73670 --- a/kernel/gcov/base.c
73671 +++ b/kernel/gcov/base.c
73672 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
73673 }
73674
73675 #ifdef CONFIG_MODULES
73676 -static inline int within(void *addr, void *start, unsigned long size)
73677 -{
73678 - return ((addr >= start) && (addr < start + size));
73679 -}
73680 -
73681 /* Update list and generate events when modules are unloaded. */
73682 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
73683 void *data)
73684 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
73685 prev = NULL;
73686 /* Remove entries located in module from linked list. */
73687 for (info = gcov_info_head; info; info = info->next) {
73688 - if (within(info, mod->module_core, mod->core_size)) {
73689 + if (within_module_core_rw((unsigned long)info, mod)) {
73690 if (prev)
73691 prev->next = info->next;
73692 else
73693 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
73694 index cdd5607..c3fc919 100644
73695 --- a/kernel/hrtimer.c
73696 +++ b/kernel/hrtimer.c
73697 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
73698 local_irq_restore(flags);
73699 }
73700
73701 -static void run_hrtimer_softirq(struct softirq_action *h)
73702 +static void run_hrtimer_softirq(void)
73703 {
73704 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
73705
73706 @@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
73707 return NOTIFY_OK;
73708 }
73709
73710 -static struct notifier_block __cpuinitdata hrtimers_nb = {
73711 +static struct notifier_block hrtimers_nb = {
73712 .notifier_call = hrtimer_cpu_notify,
73713 };
73714
73715 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
73716 index 60f48fa..7f3a770 100644
73717 --- a/kernel/jump_label.c
73718 +++ b/kernel/jump_label.c
73719 @@ -13,6 +13,7 @@
73720 #include <linux/sort.h>
73721 #include <linux/err.h>
73722 #include <linux/static_key.h>
73723 +#include <linux/mm.h>
73724
73725 #ifdef HAVE_JUMP_LABEL
73726
73727 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
73728
73729 size = (((unsigned long)stop - (unsigned long)start)
73730 / sizeof(struct jump_entry));
73731 + pax_open_kernel();
73732 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
73733 + pax_close_kernel();
73734 }
73735
73736 static void jump_label_update(struct static_key *key, int enable);
73737 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
73738 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
73739 struct jump_entry *iter;
73740
73741 + pax_open_kernel();
73742 for (iter = iter_start; iter < iter_stop; iter++) {
73743 if (within_module_init(iter->code, mod))
73744 iter->code = 0;
73745 }
73746 + pax_close_kernel();
73747 }
73748
73749 static int
73750 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
73751 index 2169fee..706ccca 100644
73752 --- a/kernel/kallsyms.c
73753 +++ b/kernel/kallsyms.c
73754 @@ -11,6 +11,9 @@
73755 * Changed the compression method from stem compression to "table lookup"
73756 * compression (see scripts/kallsyms.c for a more complete description)
73757 */
73758 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73759 +#define __INCLUDED_BY_HIDESYM 1
73760 +#endif
73761 #include <linux/kallsyms.h>
73762 #include <linux/module.h>
73763 #include <linux/init.h>
73764 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
73765
73766 static inline int is_kernel_inittext(unsigned long addr)
73767 {
73768 + if (system_state != SYSTEM_BOOTING)
73769 + return 0;
73770 +
73771 if (addr >= (unsigned long)_sinittext
73772 && addr <= (unsigned long)_einittext)
73773 return 1;
73774 return 0;
73775 }
73776
73777 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73778 +#ifdef CONFIG_MODULES
73779 +static inline int is_module_text(unsigned long addr)
73780 +{
73781 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
73782 + return 1;
73783 +
73784 + addr = ktla_ktva(addr);
73785 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
73786 +}
73787 +#else
73788 +static inline int is_module_text(unsigned long addr)
73789 +{
73790 + return 0;
73791 +}
73792 +#endif
73793 +#endif
73794 +
73795 static inline int is_kernel_text(unsigned long addr)
73796 {
73797 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
73798 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
73799
73800 static inline int is_kernel(unsigned long addr)
73801 {
73802 +
73803 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73804 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
73805 + return 1;
73806 +
73807 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
73808 +#else
73809 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
73810 +#endif
73811 +
73812 return 1;
73813 return in_gate_area_no_mm(addr);
73814 }
73815
73816 static int is_ksym_addr(unsigned long addr)
73817 {
73818 +
73819 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73820 + if (is_module_text(addr))
73821 + return 0;
73822 +#endif
73823 +
73824 if (all_var)
73825 return is_kernel(addr);
73826
73827 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
73828
73829 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
73830 {
73831 - iter->name[0] = '\0';
73832 iter->nameoff = get_symbol_offset(new_pos);
73833 iter->pos = new_pos;
73834 }
73835 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
73836 {
73837 struct kallsym_iter *iter = m->private;
73838
73839 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73840 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
73841 + return 0;
73842 +#endif
73843 +
73844 /* Some debugging symbols have no name. Ignore them. */
73845 if (!iter->name[0])
73846 return 0;
73847 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
73848 */
73849 type = iter->exported ? toupper(iter->type) :
73850 tolower(iter->type);
73851 +
73852 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
73853 type, iter->name, iter->module_name);
73854 } else
73855 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
73856 struct kallsym_iter *iter;
73857 int ret;
73858
73859 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
73860 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
73861 if (!iter)
73862 return -ENOMEM;
73863 reset_iter(iter, 0);
73864 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
73865 index e30ac0f..3528cac 100644
73866 --- a/kernel/kcmp.c
73867 +++ b/kernel/kcmp.c
73868 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
73869 struct task_struct *task1, *task2;
73870 int ret;
73871
73872 +#ifdef CONFIG_GRKERNSEC
73873 + return -ENOSYS;
73874 +#endif
73875 +
73876 rcu_read_lock();
73877
73878 /*
73879 diff --git a/kernel/kexec.c b/kernel/kexec.c
73880 index 5e4bd78..00c5b91 100644
73881 --- a/kernel/kexec.c
73882 +++ b/kernel/kexec.c
73883 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
73884 unsigned long flags)
73885 {
73886 struct compat_kexec_segment in;
73887 - struct kexec_segment out, __user *ksegments;
73888 + struct kexec_segment out;
73889 + struct kexec_segment __user *ksegments;
73890 unsigned long i, result;
73891
73892 /* Don't allow clients that don't understand the native
73893 diff --git a/kernel/kmod.c b/kernel/kmod.c
73894 index 0023a87..9c0c068 100644
73895 --- a/kernel/kmod.c
73896 +++ b/kernel/kmod.c
73897 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
73898 kfree(info->argv);
73899 }
73900
73901 -static int call_modprobe(char *module_name, int wait)
73902 +static int call_modprobe(char *module_name, char *module_param, int wait)
73903 {
73904 static char *envp[] = {
73905 "HOME=/",
73906 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
73907 NULL
73908 };
73909
73910 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
73911 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
73912 if (!argv)
73913 goto out;
73914
73915 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
73916 argv[1] = "-q";
73917 argv[2] = "--";
73918 argv[3] = module_name; /* check free_modprobe_argv() */
73919 - argv[4] = NULL;
73920 + argv[4] = module_param;
73921 + argv[5] = NULL;
73922
73923 return call_usermodehelper_fns(modprobe_path, argv, envp,
73924 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
73925 @@ -120,9 +121,8 @@ out:
73926 * If module auto-loading support is disabled then this function
73927 * becomes a no-operation.
73928 */
73929 -int __request_module(bool wait, const char *fmt, ...)
73930 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
73931 {
73932 - va_list args;
73933 char module_name[MODULE_NAME_LEN];
73934 unsigned int max_modprobes;
73935 int ret;
73936 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
73937 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
73938 static int kmod_loop_msg;
73939
73940 - va_start(args, fmt);
73941 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
73942 - va_end(args);
73943 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
73944 if (ret >= MODULE_NAME_LEN)
73945 return -ENAMETOOLONG;
73946
73947 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
73948 if (ret)
73949 return ret;
73950
73951 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
73952 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
73953 + /* hack to workaround consolekit/udisks stupidity */
73954 + read_lock(&tasklist_lock);
73955 + if (!strcmp(current->comm, "mount") &&
73956 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
73957 + read_unlock(&tasklist_lock);
73958 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
73959 + return -EPERM;
73960 + }
73961 + read_unlock(&tasklist_lock);
73962 + }
73963 +#endif
73964 +
73965 /* If modprobe needs a service that is in a module, we get a recursive
73966 * loop. Limit the number of running kmod threads to max_threads/2 or
73967 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
73968 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
73969
73970 trace_module_request(module_name, wait, _RET_IP_);
73971
73972 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
73973 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
73974
73975 atomic_dec(&kmod_concurrent);
73976 return ret;
73977 }
73978 +
73979 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
73980 +{
73981 + va_list args;
73982 + int ret;
73983 +
73984 + va_start(args, fmt);
73985 + ret = ____request_module(wait, module_param, fmt, args);
73986 + va_end(args);
73987 +
73988 + return ret;
73989 +}
73990 +
73991 +int __request_module(bool wait, const char *fmt, ...)
73992 +{
73993 + va_list args;
73994 + int ret;
73995 +
73996 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
73997 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
73998 + char module_param[MODULE_NAME_LEN];
73999 +
74000 + memset(module_param, 0, sizeof(module_param));
74001 +
74002 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
74003 +
74004 + va_start(args, fmt);
74005 + ret = ____request_module(wait, module_param, fmt, args);
74006 + va_end(args);
74007 +
74008 + return ret;
74009 + }
74010 +#endif
74011 +
74012 + va_start(args, fmt);
74013 + ret = ____request_module(wait, NULL, fmt, args);
74014 + va_end(args);
74015 +
74016 + return ret;
74017 +}
74018 +
74019 EXPORT_SYMBOL(__request_module);
74020 #endif /* CONFIG_MODULES */
74021
74022 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
74023 *
74024 * Thus the __user pointer cast is valid here.
74025 */
74026 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
74027 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
74028
74029 /*
74030 * If ret is 0, either ____call_usermodehelper failed and the
74031 @@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
74032 static int proc_cap_handler(struct ctl_table *table, int write,
74033 void __user *buffer, size_t *lenp, loff_t *ppos)
74034 {
74035 - struct ctl_table t;
74036 + ctl_table_no_const t;
74037 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
74038 kernel_cap_t new_cap;
74039 int err, i;
74040 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
74041 index 098f396..fe85ff1 100644
74042 --- a/kernel/kprobes.c
74043 +++ b/kernel/kprobes.c
74044 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
74045 * kernel image and loaded module images reside. This is required
74046 * so x86_64 can correctly handle the %rip-relative fixups.
74047 */
74048 - kip->insns = module_alloc(PAGE_SIZE);
74049 + kip->insns = module_alloc_exec(PAGE_SIZE);
74050 if (!kip->insns) {
74051 kfree(kip);
74052 return NULL;
74053 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
74054 */
74055 if (!list_is_singular(&kip->list)) {
74056 list_del(&kip->list);
74057 - module_free(NULL, kip->insns);
74058 + module_free_exec(NULL, kip->insns);
74059 kfree(kip);
74060 }
74061 return 1;
74062 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
74063 {
74064 int i, err = 0;
74065 unsigned long offset = 0, size = 0;
74066 - char *modname, namebuf[128];
74067 + char *modname, namebuf[KSYM_NAME_LEN];
74068 const char *symbol_name;
74069 void *addr;
74070 struct kprobe_blackpoint *kb;
74071 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
74072 kprobe_type = "k";
74073
74074 if (sym)
74075 - seq_printf(pi, "%p %s %s+0x%x %s ",
74076 + seq_printf(pi, "%pK %s %s+0x%x %s ",
74077 p->addr, kprobe_type, sym, offset,
74078 (modname ? modname : " "));
74079 else
74080 - seq_printf(pi, "%p %s %p ",
74081 + seq_printf(pi, "%pK %s %pK ",
74082 p->addr, kprobe_type, p->addr);
74083
74084 if (!pp)
74085 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
74086 const char *sym = NULL;
74087 unsigned int i = *(loff_t *) v;
74088 unsigned long offset = 0;
74089 - char *modname, namebuf[128];
74090 + char *modname, namebuf[KSYM_NAME_LEN];
74091
74092 head = &kprobe_table[i];
74093 preempt_disable();
74094 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
74095 index 6ada93c..dce7d5d 100644
74096 --- a/kernel/ksysfs.c
74097 +++ b/kernel/ksysfs.c
74098 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
74099 {
74100 if (count+1 > UEVENT_HELPER_PATH_LEN)
74101 return -ENOENT;
74102 + if (!capable(CAP_SYS_ADMIN))
74103 + return -EPERM;
74104 memcpy(uevent_helper, buf, count);
74105 uevent_helper[count] = '\0';
74106 if (count && uevent_helper[count-1] == '\n')
74107 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
74108 return count;
74109 }
74110
74111 -static struct bin_attribute notes_attr = {
74112 +static bin_attribute_no_const notes_attr __read_only = {
74113 .attr = {
74114 .name = "notes",
74115 .mode = S_IRUGO,
74116 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
74117 index 7981e5b..7f2105c 100644
74118 --- a/kernel/lockdep.c
74119 +++ b/kernel/lockdep.c
74120 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
74121 end = (unsigned long) &_end,
74122 addr = (unsigned long) obj;
74123
74124 +#ifdef CONFIG_PAX_KERNEXEC
74125 + start = ktla_ktva(start);
74126 +#endif
74127 +
74128 /*
74129 * static variable?
74130 */
74131 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
74132 if (!static_obj(lock->key)) {
74133 debug_locks_off();
74134 printk("INFO: trying to register non-static key.\n");
74135 + printk("lock:%pS key:%pS.\n", lock, lock->key);
74136 printk("the code is fine but needs lockdep annotation.\n");
74137 printk("turning off the locking correctness validator.\n");
74138 dump_stack();
74139 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
74140 if (!class)
74141 return 0;
74142 }
74143 - atomic_inc((atomic_t *)&class->ops);
74144 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
74145 if (very_verbose(class)) {
74146 printk("\nacquire class [%p] %s", class->key, class->name);
74147 if (class->name_version > 1)
74148 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
74149 index b2c71c5..7b88d63 100644
74150 --- a/kernel/lockdep_proc.c
74151 +++ b/kernel/lockdep_proc.c
74152 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
74153 return 0;
74154 }
74155
74156 - seq_printf(m, "%p", class->key);
74157 + seq_printf(m, "%pK", class->key);
74158 #ifdef CONFIG_DEBUG_LOCKDEP
74159 seq_printf(m, " OPS:%8ld", class->ops);
74160 #endif
74161 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
74162
74163 list_for_each_entry(entry, &class->locks_after, entry) {
74164 if (entry->distance == 1) {
74165 - seq_printf(m, " -> [%p] ", entry->class->key);
74166 + seq_printf(m, " -> [%pK] ", entry->class->key);
74167 print_name(m, entry->class);
74168 seq_puts(m, "\n");
74169 }
74170 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
74171 if (!class->key)
74172 continue;
74173
74174 - seq_printf(m, "[%p] ", class->key);
74175 + seq_printf(m, "[%pK] ", class->key);
74176 print_name(m, class);
74177 seq_puts(m, "\n");
74178 }
74179 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
74180 if (!i)
74181 seq_line(m, '-', 40-namelen, namelen);
74182
74183 - snprintf(ip, sizeof(ip), "[<%p>]",
74184 + snprintf(ip, sizeof(ip), "[<%pK>]",
74185 (void *)class->contention_point[i]);
74186 seq_printf(m, "%40s %14lu %29s %pS\n",
74187 name, stats->contention_point[i],
74188 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
74189 if (!i)
74190 seq_line(m, '-', 40-namelen, namelen);
74191
74192 - snprintf(ip, sizeof(ip), "[<%p>]",
74193 + snprintf(ip, sizeof(ip), "[<%pK>]",
74194 (void *)class->contending_point[i]);
74195 seq_printf(m, "%40s %14lu %29s %pS\n",
74196 name, stats->contending_point[i],
74197 diff --git a/kernel/module.c b/kernel/module.c
74198 index eab0827..f488603 100644
74199 --- a/kernel/module.c
74200 +++ b/kernel/module.c
74201 @@ -61,6 +61,7 @@
74202 #include <linux/pfn.h>
74203 #include <linux/bsearch.h>
74204 #include <linux/fips.h>
74205 +#include <linux/grsecurity.h>
74206 #include <uapi/linux/module.h>
74207 #include "module-internal.h"
74208
74209 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
74210
74211 /* Bounds of module allocation, for speeding __module_address.
74212 * Protected by module_mutex. */
74213 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
74214 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
74215 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
74216
74217 int register_module_notifier(struct notifier_block * nb)
74218 {
74219 @@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
74220 return true;
74221
74222 list_for_each_entry_rcu(mod, &modules, list) {
74223 - struct symsearch arr[] = {
74224 + struct symsearch modarr[] = {
74225 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
74226 NOT_GPL_ONLY, false },
74227 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
74228 @@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
74229 if (mod->state == MODULE_STATE_UNFORMED)
74230 continue;
74231
74232 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
74233 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
74234 return true;
74235 }
74236 return false;
74237 @@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
74238 static int percpu_modalloc(struct module *mod,
74239 unsigned long size, unsigned long align)
74240 {
74241 - if (align > PAGE_SIZE) {
74242 + if (align-1 >= PAGE_SIZE) {
74243 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
74244 mod->name, align, PAGE_SIZE);
74245 align = PAGE_SIZE;
74246 @@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
74247 static ssize_t show_coresize(struct module_attribute *mattr,
74248 struct module_kobject *mk, char *buffer)
74249 {
74250 - return sprintf(buffer, "%u\n", mk->mod->core_size);
74251 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
74252 }
74253
74254 static struct module_attribute modinfo_coresize =
74255 @@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
74256 static ssize_t show_initsize(struct module_attribute *mattr,
74257 struct module_kobject *mk, char *buffer)
74258 {
74259 - return sprintf(buffer, "%u\n", mk->mod->init_size);
74260 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
74261 }
74262
74263 static struct module_attribute modinfo_initsize =
74264 @@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
74265 */
74266 #ifdef CONFIG_SYSFS
74267
74268 -#ifdef CONFIG_KALLSYMS
74269 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74270 static inline bool sect_empty(const Elf_Shdr *sect)
74271 {
74272 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
74273 @@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
74274 {
74275 unsigned int notes, loaded, i;
74276 struct module_notes_attrs *notes_attrs;
74277 - struct bin_attribute *nattr;
74278 + bin_attribute_no_const *nattr;
74279
74280 /* failed to create section attributes, so can't create notes */
74281 if (!mod->sect_attrs)
74282 @@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
74283 static int module_add_modinfo_attrs(struct module *mod)
74284 {
74285 struct module_attribute *attr;
74286 - struct module_attribute *temp_attr;
74287 + module_attribute_no_const *temp_attr;
74288 int error = 0;
74289 int i;
74290
74291 @@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
74292
74293 static void unset_module_core_ro_nx(struct module *mod)
74294 {
74295 - set_page_attributes(mod->module_core + mod->core_text_size,
74296 - mod->module_core + mod->core_size,
74297 + set_page_attributes(mod->module_core_rw,
74298 + mod->module_core_rw + mod->core_size_rw,
74299 set_memory_x);
74300 - set_page_attributes(mod->module_core,
74301 - mod->module_core + mod->core_ro_size,
74302 + set_page_attributes(mod->module_core_rx,
74303 + mod->module_core_rx + mod->core_size_rx,
74304 set_memory_rw);
74305 }
74306
74307 static void unset_module_init_ro_nx(struct module *mod)
74308 {
74309 - set_page_attributes(mod->module_init + mod->init_text_size,
74310 - mod->module_init + mod->init_size,
74311 + set_page_attributes(mod->module_init_rw,
74312 + mod->module_init_rw + mod->init_size_rw,
74313 set_memory_x);
74314 - set_page_attributes(mod->module_init,
74315 - mod->module_init + mod->init_ro_size,
74316 + set_page_attributes(mod->module_init_rx,
74317 + mod->module_init_rx + mod->init_size_rx,
74318 set_memory_rw);
74319 }
74320
74321 @@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
74322 list_for_each_entry_rcu(mod, &modules, list) {
74323 if (mod->state == MODULE_STATE_UNFORMED)
74324 continue;
74325 - if ((mod->module_core) && (mod->core_text_size)) {
74326 - set_page_attributes(mod->module_core,
74327 - mod->module_core + mod->core_text_size,
74328 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
74329 + set_page_attributes(mod->module_core_rx,
74330 + mod->module_core_rx + mod->core_size_rx,
74331 set_memory_rw);
74332 }
74333 - if ((mod->module_init) && (mod->init_text_size)) {
74334 - set_page_attributes(mod->module_init,
74335 - mod->module_init + mod->init_text_size,
74336 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
74337 + set_page_attributes(mod->module_init_rx,
74338 + mod->module_init_rx + mod->init_size_rx,
74339 set_memory_rw);
74340 }
74341 }
74342 @@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
74343 list_for_each_entry_rcu(mod, &modules, list) {
74344 if (mod->state == MODULE_STATE_UNFORMED)
74345 continue;
74346 - if ((mod->module_core) && (mod->core_text_size)) {
74347 - set_page_attributes(mod->module_core,
74348 - mod->module_core + mod->core_text_size,
74349 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
74350 + set_page_attributes(mod->module_core_rx,
74351 + mod->module_core_rx + mod->core_size_rx,
74352 set_memory_ro);
74353 }
74354 - if ((mod->module_init) && (mod->init_text_size)) {
74355 - set_page_attributes(mod->module_init,
74356 - mod->module_init + mod->init_text_size,
74357 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
74358 + set_page_attributes(mod->module_init_rx,
74359 + mod->module_init_rx + mod->init_size_rx,
74360 set_memory_ro);
74361 }
74362 }
74363 @@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
74364
74365 /* This may be NULL, but that's OK */
74366 unset_module_init_ro_nx(mod);
74367 - module_free(mod, mod->module_init);
74368 + module_free(mod, mod->module_init_rw);
74369 + module_free_exec(mod, mod->module_init_rx);
74370 kfree(mod->args);
74371 percpu_modfree(mod);
74372
74373 /* Free lock-classes: */
74374 - lockdep_free_key_range(mod->module_core, mod->core_size);
74375 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
74376 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
74377
74378 /* Finally, free the core (containing the module structure) */
74379 unset_module_core_ro_nx(mod);
74380 - module_free(mod, mod->module_core);
74381 + module_free_exec(mod, mod->module_core_rx);
74382 + module_free(mod, mod->module_core_rw);
74383
74384 #ifdef CONFIG_MPU
74385 update_protections(current->mm);
74386 @@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74387 int ret = 0;
74388 const struct kernel_symbol *ksym;
74389
74390 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74391 + int is_fs_load = 0;
74392 + int register_filesystem_found = 0;
74393 + char *p;
74394 +
74395 + p = strstr(mod->args, "grsec_modharden_fs");
74396 + if (p) {
74397 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
74398 + /* copy \0 as well */
74399 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
74400 + is_fs_load = 1;
74401 + }
74402 +#endif
74403 +
74404 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
74405 const char *name = info->strtab + sym[i].st_name;
74406
74407 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74408 + /* it's a real shame this will never get ripped and copied
74409 + upstream! ;(
74410 + */
74411 + if (is_fs_load && !strcmp(name, "register_filesystem"))
74412 + register_filesystem_found = 1;
74413 +#endif
74414 +
74415 switch (sym[i].st_shndx) {
74416 case SHN_COMMON:
74417 /* We compiled with -fno-common. These are not
74418 @@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74419 ksym = resolve_symbol_wait(mod, info, name);
74420 /* Ok if resolved. */
74421 if (ksym && !IS_ERR(ksym)) {
74422 + pax_open_kernel();
74423 sym[i].st_value = ksym->value;
74424 + pax_close_kernel();
74425 break;
74426 }
74427
74428 @@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74429 secbase = (unsigned long)mod_percpu(mod);
74430 else
74431 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
74432 + pax_open_kernel();
74433 sym[i].st_value += secbase;
74434 + pax_close_kernel();
74435 break;
74436 }
74437 }
74438
74439 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74440 + if (is_fs_load && !register_filesystem_found) {
74441 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
74442 + ret = -EPERM;
74443 + }
74444 +#endif
74445 +
74446 return ret;
74447 }
74448
74449 @@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
74450 || s->sh_entsize != ~0UL
74451 || strstarts(sname, ".init"))
74452 continue;
74453 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
74454 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
74455 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
74456 + else
74457 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
74458 pr_debug("\t%s\n", sname);
74459 }
74460 - switch (m) {
74461 - case 0: /* executable */
74462 - mod->core_size = debug_align(mod->core_size);
74463 - mod->core_text_size = mod->core_size;
74464 - break;
74465 - case 1: /* RO: text and ro-data */
74466 - mod->core_size = debug_align(mod->core_size);
74467 - mod->core_ro_size = mod->core_size;
74468 - break;
74469 - case 3: /* whole core */
74470 - mod->core_size = debug_align(mod->core_size);
74471 - break;
74472 - }
74473 }
74474
74475 pr_debug("Init section allocation order:\n");
74476 @@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
74477 || s->sh_entsize != ~0UL
74478 || !strstarts(sname, ".init"))
74479 continue;
74480 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
74481 - | INIT_OFFSET_MASK);
74482 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
74483 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
74484 + else
74485 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
74486 + s->sh_entsize |= INIT_OFFSET_MASK;
74487 pr_debug("\t%s\n", sname);
74488 }
74489 - switch (m) {
74490 - case 0: /* executable */
74491 - mod->init_size = debug_align(mod->init_size);
74492 - mod->init_text_size = mod->init_size;
74493 - break;
74494 - case 1: /* RO: text and ro-data */
74495 - mod->init_size = debug_align(mod->init_size);
74496 - mod->init_ro_size = mod->init_size;
74497 - break;
74498 - case 3: /* whole init */
74499 - mod->init_size = debug_align(mod->init_size);
74500 - break;
74501 - }
74502 }
74503 }
74504
74505 @@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
74506
74507 /* Put symbol section at end of init part of module. */
74508 symsect->sh_flags |= SHF_ALLOC;
74509 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
74510 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
74511 info->index.sym) | INIT_OFFSET_MASK;
74512 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
74513
74514 @@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
74515 }
74516
74517 /* Append room for core symbols at end of core part. */
74518 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
74519 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
74520 - mod->core_size += strtab_size;
74521 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
74522 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
74523 + mod->core_size_rx += strtab_size;
74524
74525 /* Put string table section at end of init part of module. */
74526 strsect->sh_flags |= SHF_ALLOC;
74527 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
74528 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
74529 info->index.str) | INIT_OFFSET_MASK;
74530 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
74531 }
74532 @@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
74533 /* Make sure we get permanent strtab: don't use info->strtab. */
74534 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
74535
74536 + pax_open_kernel();
74537 +
74538 /* Set types up while we still have access to sections. */
74539 for (i = 0; i < mod->num_symtab; i++)
74540 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
74541
74542 - mod->core_symtab = dst = mod->module_core + info->symoffs;
74543 - mod->core_strtab = s = mod->module_core + info->stroffs;
74544 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
74545 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
74546 src = mod->symtab;
74547 for (ndst = i = 0; i < mod->num_symtab; i++) {
74548 if (i == 0 ||
74549 @@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
74550 }
74551 }
74552 mod->core_num_syms = ndst;
74553 +
74554 + pax_close_kernel();
74555 }
74556 #else
74557 static inline void layout_symtab(struct module *mod, struct load_info *info)
74558 @@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
74559 return vmalloc_exec(size);
74560 }
74561
74562 -static void *module_alloc_update_bounds(unsigned long size)
74563 +static void *module_alloc_update_bounds_rw(unsigned long size)
74564 {
74565 void *ret = module_alloc(size);
74566
74567 if (ret) {
74568 mutex_lock(&module_mutex);
74569 /* Update module bounds. */
74570 - if ((unsigned long)ret < module_addr_min)
74571 - module_addr_min = (unsigned long)ret;
74572 - if ((unsigned long)ret + size > module_addr_max)
74573 - module_addr_max = (unsigned long)ret + size;
74574 + if ((unsigned long)ret < module_addr_min_rw)
74575 + module_addr_min_rw = (unsigned long)ret;
74576 + if ((unsigned long)ret + size > module_addr_max_rw)
74577 + module_addr_max_rw = (unsigned long)ret + size;
74578 + mutex_unlock(&module_mutex);
74579 + }
74580 + return ret;
74581 +}
74582 +
74583 +static void *module_alloc_update_bounds_rx(unsigned long size)
74584 +{
74585 + void *ret = module_alloc_exec(size);
74586 +
74587 + if (ret) {
74588 + mutex_lock(&module_mutex);
74589 + /* Update module bounds. */
74590 + if ((unsigned long)ret < module_addr_min_rx)
74591 + module_addr_min_rx = (unsigned long)ret;
74592 + if ((unsigned long)ret + size > module_addr_max_rx)
74593 + module_addr_max_rx = (unsigned long)ret + size;
74594 mutex_unlock(&module_mutex);
74595 }
74596 return ret;
74597 @@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
74598 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
74599 {
74600 const char *modmagic = get_modinfo(info, "vermagic");
74601 + const char *license = get_modinfo(info, "license");
74602 int err;
74603
74604 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
74605 + if (!license || !license_is_gpl_compatible(license))
74606 + return -ENOEXEC;
74607 +#endif
74608 +
74609 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
74610 modmagic = NULL;
74611
74612 @@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
74613 }
74614
74615 /* Set up license info based on the info section */
74616 - set_license(mod, get_modinfo(info, "license"));
74617 + set_license(mod, license);
74618
74619 return 0;
74620 }
74621 @@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
74622 void *ptr;
74623
74624 /* Do the allocs. */
74625 - ptr = module_alloc_update_bounds(mod->core_size);
74626 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
74627 /*
74628 * The pointer to this block is stored in the module structure
74629 * which is inside the block. Just mark it as not being a
74630 @@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
74631 if (!ptr)
74632 return -ENOMEM;
74633
74634 - memset(ptr, 0, mod->core_size);
74635 - mod->module_core = ptr;
74636 + memset(ptr, 0, mod->core_size_rw);
74637 + mod->module_core_rw = ptr;
74638
74639 - if (mod->init_size) {
74640 - ptr = module_alloc_update_bounds(mod->init_size);
74641 + if (mod->init_size_rw) {
74642 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
74643 /*
74644 * The pointer to this block is stored in the module structure
74645 * which is inside the block. This block doesn't need to be
74646 @@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
74647 */
74648 kmemleak_ignore(ptr);
74649 if (!ptr) {
74650 - module_free(mod, mod->module_core);
74651 + module_free(mod, mod->module_core_rw);
74652 return -ENOMEM;
74653 }
74654 - memset(ptr, 0, mod->init_size);
74655 - mod->module_init = ptr;
74656 + memset(ptr, 0, mod->init_size_rw);
74657 + mod->module_init_rw = ptr;
74658 } else
74659 - mod->module_init = NULL;
74660 + mod->module_init_rw = NULL;
74661 +
74662 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
74663 + kmemleak_not_leak(ptr);
74664 + if (!ptr) {
74665 + if (mod->module_init_rw)
74666 + module_free(mod, mod->module_init_rw);
74667 + module_free(mod, mod->module_core_rw);
74668 + return -ENOMEM;
74669 + }
74670 +
74671 + pax_open_kernel();
74672 + memset(ptr, 0, mod->core_size_rx);
74673 + pax_close_kernel();
74674 + mod->module_core_rx = ptr;
74675 +
74676 + if (mod->init_size_rx) {
74677 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
74678 + kmemleak_ignore(ptr);
74679 + if (!ptr && mod->init_size_rx) {
74680 + module_free_exec(mod, mod->module_core_rx);
74681 + if (mod->module_init_rw)
74682 + module_free(mod, mod->module_init_rw);
74683 + module_free(mod, mod->module_core_rw);
74684 + return -ENOMEM;
74685 + }
74686 +
74687 + pax_open_kernel();
74688 + memset(ptr, 0, mod->init_size_rx);
74689 + pax_close_kernel();
74690 + mod->module_init_rx = ptr;
74691 + } else
74692 + mod->module_init_rx = NULL;
74693
74694 /* Transfer each section which specifies SHF_ALLOC */
74695 pr_debug("final section addresses:\n");
74696 @@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
74697 if (!(shdr->sh_flags & SHF_ALLOC))
74698 continue;
74699
74700 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
74701 - dest = mod->module_init
74702 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74703 - else
74704 - dest = mod->module_core + shdr->sh_entsize;
74705 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
74706 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
74707 + dest = mod->module_init_rw
74708 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74709 + else
74710 + dest = mod->module_init_rx
74711 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74712 + } else {
74713 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
74714 + dest = mod->module_core_rw + shdr->sh_entsize;
74715 + else
74716 + dest = mod->module_core_rx + shdr->sh_entsize;
74717 + }
74718 +
74719 + if (shdr->sh_type != SHT_NOBITS) {
74720 +
74721 +#ifdef CONFIG_PAX_KERNEXEC
74722 +#ifdef CONFIG_X86_64
74723 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
74724 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
74725 +#endif
74726 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
74727 + pax_open_kernel();
74728 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
74729 + pax_close_kernel();
74730 + } else
74731 +#endif
74732
74733 - if (shdr->sh_type != SHT_NOBITS)
74734 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
74735 + }
74736 /* Update sh_addr to point to copy in image. */
74737 - shdr->sh_addr = (unsigned long)dest;
74738 +
74739 +#ifdef CONFIG_PAX_KERNEXEC
74740 + if (shdr->sh_flags & SHF_EXECINSTR)
74741 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
74742 + else
74743 +#endif
74744 +
74745 + shdr->sh_addr = (unsigned long)dest;
74746 pr_debug("\t0x%lx %s\n",
74747 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
74748 }
74749 @@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
74750 * Do it before processing of module parameters, so the module
74751 * can provide parameter accessor functions of its own.
74752 */
74753 - if (mod->module_init)
74754 - flush_icache_range((unsigned long)mod->module_init,
74755 - (unsigned long)mod->module_init
74756 - + mod->init_size);
74757 - flush_icache_range((unsigned long)mod->module_core,
74758 - (unsigned long)mod->module_core + mod->core_size);
74759 + if (mod->module_init_rx)
74760 + flush_icache_range((unsigned long)mod->module_init_rx,
74761 + (unsigned long)mod->module_init_rx
74762 + + mod->init_size_rx);
74763 + flush_icache_range((unsigned long)mod->module_core_rx,
74764 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
74765
74766 set_fs(old_fs);
74767 }
74768 @@ -2983,8 +3088,10 @@ out:
74769 static void module_deallocate(struct module *mod, struct load_info *info)
74770 {
74771 percpu_modfree(mod);
74772 - module_free(mod, mod->module_init);
74773 - module_free(mod, mod->module_core);
74774 + module_free_exec(mod, mod->module_init_rx);
74775 + module_free_exec(mod, mod->module_core_rx);
74776 + module_free(mod, mod->module_init_rw);
74777 + module_free(mod, mod->module_core_rw);
74778 }
74779
74780 int __weak module_finalize(const Elf_Ehdr *hdr,
74781 @@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
74782 static int post_relocation(struct module *mod, const struct load_info *info)
74783 {
74784 /* Sort exception table now relocations are done. */
74785 + pax_open_kernel();
74786 sort_extable(mod->extable, mod->extable + mod->num_exentries);
74787 + pax_close_kernel();
74788
74789 /* Copy relocated percpu area over. */
74790 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
74791 @@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
74792 MODULE_STATE_COMING, mod);
74793
74794 /* Set RO and NX regions for core */
74795 - set_section_ro_nx(mod->module_core,
74796 - mod->core_text_size,
74797 - mod->core_ro_size,
74798 - mod->core_size);
74799 + set_section_ro_nx(mod->module_core_rx,
74800 + mod->core_size_rx,
74801 + mod->core_size_rx,
74802 + mod->core_size_rx);
74803
74804 /* Set RO and NX regions for init */
74805 - set_section_ro_nx(mod->module_init,
74806 - mod->init_text_size,
74807 - mod->init_ro_size,
74808 - mod->init_size);
74809 + set_section_ro_nx(mod->module_init_rx,
74810 + mod->init_size_rx,
74811 + mod->init_size_rx,
74812 + mod->init_size_rx);
74813
74814 do_mod_ctors(mod);
74815 /* Start the module */
74816 @@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
74817 mod->strtab = mod->core_strtab;
74818 #endif
74819 unset_module_init_ro_nx(mod);
74820 - module_free(mod, mod->module_init);
74821 - mod->module_init = NULL;
74822 - mod->init_size = 0;
74823 - mod->init_ro_size = 0;
74824 - mod->init_text_size = 0;
74825 + module_free(mod, mod->module_init_rw);
74826 + module_free_exec(mod, mod->module_init_rx);
74827 + mod->module_init_rw = NULL;
74828 + mod->module_init_rx = NULL;
74829 + mod->init_size_rw = 0;
74830 + mod->init_size_rx = 0;
74831 mutex_unlock(&module_mutex);
74832 wake_up_all(&module_wq);
74833
74834 @@ -3209,9 +3319,38 @@ again:
74835 if (err)
74836 goto free_unload;
74837
74838 + /* Now copy in args */
74839 + mod->args = strndup_user(uargs, ~0UL >> 1);
74840 + if (IS_ERR(mod->args)) {
74841 + err = PTR_ERR(mod->args);
74842 + goto free_unload;
74843 + }
74844 +
74845 /* Set up MODINFO_ATTR fields */
74846 setup_modinfo(mod, info);
74847
74848 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74849 + {
74850 + char *p, *p2;
74851 +
74852 + if (strstr(mod->args, "grsec_modharden_netdev")) {
74853 + 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);
74854 + err = -EPERM;
74855 + goto free_modinfo;
74856 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
74857 + p += sizeof("grsec_modharden_normal") - 1;
74858 + p2 = strstr(p, "_");
74859 + if (p2) {
74860 + *p2 = '\0';
74861 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
74862 + *p2 = '_';
74863 + }
74864 + err = -EPERM;
74865 + goto free_modinfo;
74866 + }
74867 + }
74868 +#endif
74869 +
74870 /* Fix up syms, so that st_value is a pointer to location. */
74871 err = simplify_symbols(mod, info);
74872 if (err < 0)
74873 @@ -3227,13 +3366,6 @@ again:
74874
74875 flush_module_icache(mod);
74876
74877 - /* Now copy in args */
74878 - mod->args = strndup_user(uargs, ~0UL >> 1);
74879 - if (IS_ERR(mod->args)) {
74880 - err = PTR_ERR(mod->args);
74881 - goto free_arch_cleanup;
74882 - }
74883 -
74884 dynamic_debug_setup(info->debug, info->num_debug);
74885
74886 mutex_lock(&module_mutex);
74887 @@ -3278,11 +3410,10 @@ again:
74888 mutex_unlock(&module_mutex);
74889 dynamic_debug_remove(info->debug);
74890 synchronize_sched();
74891 - kfree(mod->args);
74892 - free_arch_cleanup:
74893 module_arch_cleanup(mod);
74894 free_modinfo:
74895 free_modinfo(mod);
74896 + kfree(mod->args);
74897 free_unload:
74898 module_unload_free(mod);
74899 unlink_mod:
74900 @@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
74901 unsigned long nextval;
74902
74903 /* At worse, next value is at end of module */
74904 - if (within_module_init(addr, mod))
74905 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
74906 + if (within_module_init_rx(addr, mod))
74907 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
74908 + else if (within_module_init_rw(addr, mod))
74909 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
74910 + else if (within_module_core_rx(addr, mod))
74911 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
74912 + else if (within_module_core_rw(addr, mod))
74913 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
74914 else
74915 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
74916 + return NULL;
74917
74918 /* Scan for closest preceding symbol, and next symbol. (ELF
74919 starts real symbols at 1). */
74920 @@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
74921 return 0;
74922
74923 seq_printf(m, "%s %u",
74924 - mod->name, mod->init_size + mod->core_size);
74925 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
74926 print_unload_info(m, mod);
74927
74928 /* Informative for users. */
74929 @@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
74930 mod->state == MODULE_STATE_COMING ? "Loading":
74931 "Live");
74932 /* Used by oprofile and other similar tools. */
74933 - seq_printf(m, " 0x%pK", mod->module_core);
74934 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
74935
74936 /* Taints info */
74937 if (mod->taints)
74938 @@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
74939
74940 static int __init proc_modules_init(void)
74941 {
74942 +#ifndef CONFIG_GRKERNSEC_HIDESYM
74943 +#ifdef CONFIG_GRKERNSEC_PROC_USER
74944 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
74945 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74946 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
74947 +#else
74948 proc_create("modules", 0, NULL, &proc_modules_operations);
74949 +#endif
74950 +#else
74951 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
74952 +#endif
74953 return 0;
74954 }
74955 module_init(proc_modules_init);
74956 @@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
74957 {
74958 struct module *mod;
74959
74960 - if (addr < module_addr_min || addr > module_addr_max)
74961 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
74962 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
74963 return NULL;
74964
74965 list_for_each_entry_rcu(mod, &modules, list) {
74966 if (mod->state == MODULE_STATE_UNFORMED)
74967 continue;
74968 - if (within_module_core(addr, mod)
74969 - || within_module_init(addr, mod))
74970 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
74971 return mod;
74972 }
74973 return NULL;
74974 @@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
74975 */
74976 struct module *__module_text_address(unsigned long addr)
74977 {
74978 - struct module *mod = __module_address(addr);
74979 + struct module *mod;
74980 +
74981 +#ifdef CONFIG_X86_32
74982 + addr = ktla_ktva(addr);
74983 +#endif
74984 +
74985 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
74986 + return NULL;
74987 +
74988 + mod = __module_address(addr);
74989 +
74990 if (mod) {
74991 /* Make sure it's within the text section. */
74992 - if (!within(addr, mod->module_init, mod->init_text_size)
74993 - && !within(addr, mod->module_core, mod->core_text_size))
74994 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
74995 mod = NULL;
74996 }
74997 return mod;
74998 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
74999 index 7e3443f..b2a1e6b 100644
75000 --- a/kernel/mutex-debug.c
75001 +++ b/kernel/mutex-debug.c
75002 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
75003 }
75004
75005 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75006 - struct thread_info *ti)
75007 + struct task_struct *task)
75008 {
75009 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
75010
75011 /* Mark the current thread as blocked on the lock: */
75012 - ti->task->blocked_on = waiter;
75013 + task->blocked_on = waiter;
75014 }
75015
75016 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75017 - struct thread_info *ti)
75018 + struct task_struct *task)
75019 {
75020 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
75021 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
75022 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
75023 - ti->task->blocked_on = NULL;
75024 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
75025 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
75026 + task->blocked_on = NULL;
75027
75028 list_del_init(&waiter->list);
75029 waiter->task = NULL;
75030 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
75031 index 0799fd3..d06ae3b 100644
75032 --- a/kernel/mutex-debug.h
75033 +++ b/kernel/mutex-debug.h
75034 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
75035 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
75036 extern void debug_mutex_add_waiter(struct mutex *lock,
75037 struct mutex_waiter *waiter,
75038 - struct thread_info *ti);
75039 + struct task_struct *task);
75040 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75041 - struct thread_info *ti);
75042 + struct task_struct *task);
75043 extern void debug_mutex_unlock(struct mutex *lock);
75044 extern void debug_mutex_init(struct mutex *lock, const char *name,
75045 struct lock_class_key *key);
75046 diff --git a/kernel/mutex.c b/kernel/mutex.c
75047 index a307cc9..27fd2e9 100644
75048 --- a/kernel/mutex.c
75049 +++ b/kernel/mutex.c
75050 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75051 spin_lock_mutex(&lock->wait_lock, flags);
75052
75053 debug_mutex_lock_common(lock, &waiter);
75054 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
75055 + debug_mutex_add_waiter(lock, &waiter, task);
75056
75057 /* add waiting tasks to the end of the waitqueue (FIFO): */
75058 list_add_tail(&waiter.list, &lock->wait_list);
75059 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75060 * TASK_UNINTERRUPTIBLE case.)
75061 */
75062 if (unlikely(signal_pending_state(state, task))) {
75063 - mutex_remove_waiter(lock, &waiter,
75064 - task_thread_info(task));
75065 + mutex_remove_waiter(lock, &waiter, task);
75066 mutex_release(&lock->dep_map, 1, ip);
75067 spin_unlock_mutex(&lock->wait_lock, flags);
75068
75069 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75070 done:
75071 lock_acquired(&lock->dep_map, ip);
75072 /* got the lock - rejoice! */
75073 - mutex_remove_waiter(lock, &waiter, current_thread_info());
75074 + mutex_remove_waiter(lock, &waiter, task);
75075 mutex_set_owner(lock);
75076
75077 /* set it to 0 if there are no waiters left: */
75078 diff --git a/kernel/notifier.c b/kernel/notifier.c
75079 index 2d5cc4c..d9ea600 100644
75080 --- a/kernel/notifier.c
75081 +++ b/kernel/notifier.c
75082 @@ -5,6 +5,7 @@
75083 #include <linux/rcupdate.h>
75084 #include <linux/vmalloc.h>
75085 #include <linux/reboot.h>
75086 +#include <linux/mm.h>
75087
75088 /*
75089 * Notifier list for kernel code which wants to be called
75090 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
75091 while ((*nl) != NULL) {
75092 if (n->priority > (*nl)->priority)
75093 break;
75094 - nl = &((*nl)->next);
75095 + nl = (struct notifier_block **)&((*nl)->next);
75096 }
75097 - n->next = *nl;
75098 + pax_open_kernel();
75099 + *(const void **)&n->next = *nl;
75100 rcu_assign_pointer(*nl, n);
75101 + pax_close_kernel();
75102 return 0;
75103 }
75104
75105 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
75106 return 0;
75107 if (n->priority > (*nl)->priority)
75108 break;
75109 - nl = &((*nl)->next);
75110 + nl = (struct notifier_block **)&((*nl)->next);
75111 }
75112 - n->next = *nl;
75113 + pax_open_kernel();
75114 + *(const void **)&n->next = *nl;
75115 rcu_assign_pointer(*nl, n);
75116 + pax_close_kernel();
75117 return 0;
75118 }
75119
75120 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
75121 {
75122 while ((*nl) != NULL) {
75123 if ((*nl) == n) {
75124 + pax_open_kernel();
75125 rcu_assign_pointer(*nl, n->next);
75126 + pax_close_kernel();
75127 return 0;
75128 }
75129 - nl = &((*nl)->next);
75130 + nl = (struct notifier_block **)&((*nl)->next);
75131 }
75132 return -ENOENT;
75133 }
75134 diff --git a/kernel/panic.c b/kernel/panic.c
75135 index e1b2822..5edc1d9 100644
75136 --- a/kernel/panic.c
75137 +++ b/kernel/panic.c
75138 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
75139 const char *board;
75140
75141 printk(KERN_WARNING "------------[ cut here ]------------\n");
75142 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
75143 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
75144 board = dmi_get_system_info(DMI_PRODUCT_NAME);
75145 if (board)
75146 printk(KERN_WARNING "Hardware name: %s\n", board);
75147 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
75148 */
75149 void __stack_chk_fail(void)
75150 {
75151 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
75152 + dump_stack();
75153 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
75154 __builtin_return_address(0));
75155 }
75156 EXPORT_SYMBOL(__stack_chk_fail);
75157 diff --git a/kernel/pid.c b/kernel/pid.c
75158 index f2c6a68..4922d97 100644
75159 --- a/kernel/pid.c
75160 +++ b/kernel/pid.c
75161 @@ -33,6 +33,7 @@
75162 #include <linux/rculist.h>
75163 #include <linux/bootmem.h>
75164 #include <linux/hash.h>
75165 +#include <linux/security.h>
75166 #include <linux/pid_namespace.h>
75167 #include <linux/init_task.h>
75168 #include <linux/syscalls.h>
75169 @@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
75170
75171 int pid_max = PID_MAX_DEFAULT;
75172
75173 -#define RESERVED_PIDS 300
75174 +#define RESERVED_PIDS 500
75175
75176 int pid_max_min = RESERVED_PIDS + 1;
75177 int pid_max_max = PID_MAX_LIMIT;
75178 @@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
75179 */
75180 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
75181 {
75182 + struct task_struct *task;
75183 +
75184 rcu_lockdep_assert(rcu_read_lock_held(),
75185 "find_task_by_pid_ns() needs rcu_read_lock()"
75186 " protection");
75187 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
75188 +
75189 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
75190 +
75191 + if (gr_pid_is_chrooted(task))
75192 + return NULL;
75193 +
75194 + return task;
75195 }
75196
75197 struct task_struct *find_task_by_vpid(pid_t vnr)
75198 @@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
75199 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
75200 }
75201
75202 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
75203 +{
75204 + rcu_lockdep_assert(rcu_read_lock_held(),
75205 + "find_task_by_pid_ns() needs rcu_read_lock()"
75206 + " protection");
75207 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
75208 +}
75209 +
75210 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
75211 {
75212 struct pid *pid;
75213 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
75214 index c1c3dc1..bbeaf31 100644
75215 --- a/kernel/pid_namespace.c
75216 +++ b/kernel/pid_namespace.c
75217 @@ -248,7 +248,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
75218 void __user *buffer, size_t *lenp, loff_t *ppos)
75219 {
75220 struct pid_namespace *pid_ns = task_active_pid_ns(current);
75221 - struct ctl_table tmp = *table;
75222 + ctl_table_no_const tmp = *table;
75223
75224 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
75225 return -EPERM;
75226 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
75227 index 942ca27..111e609 100644
75228 --- a/kernel/posix-cpu-timers.c
75229 +++ b/kernel/posix-cpu-timers.c
75230 @@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
75231
75232 static __init int init_posix_cpu_timers(void)
75233 {
75234 - struct k_clock process = {
75235 + static struct k_clock process = {
75236 .clock_getres = process_cpu_clock_getres,
75237 .clock_get = process_cpu_clock_get,
75238 .timer_create = process_cpu_timer_create,
75239 .nsleep = process_cpu_nsleep,
75240 .nsleep_restart = process_cpu_nsleep_restart,
75241 };
75242 - struct k_clock thread = {
75243 + static struct k_clock thread = {
75244 .clock_getres = thread_cpu_clock_getres,
75245 .clock_get = thread_cpu_clock_get,
75246 .timer_create = thread_cpu_timer_create,
75247 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
75248 index e885be1..380fe76 100644
75249 --- a/kernel/posix-timers.c
75250 +++ b/kernel/posix-timers.c
75251 @@ -43,6 +43,7 @@
75252 #include <linux/idr.h>
75253 #include <linux/posix-clock.h>
75254 #include <linux/posix-timers.h>
75255 +#include <linux/grsecurity.h>
75256 #include <linux/syscalls.h>
75257 #include <linux/wait.h>
75258 #include <linux/workqueue.h>
75259 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
75260 * which we beg off on and pass to do_sys_settimeofday().
75261 */
75262
75263 -static struct k_clock posix_clocks[MAX_CLOCKS];
75264 +static struct k_clock *posix_clocks[MAX_CLOCKS];
75265
75266 /*
75267 * These ones are defined below.
75268 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
75269 */
75270 static __init int init_posix_timers(void)
75271 {
75272 - struct k_clock clock_realtime = {
75273 + static struct k_clock clock_realtime = {
75274 .clock_getres = hrtimer_get_res,
75275 .clock_get = posix_clock_realtime_get,
75276 .clock_set = posix_clock_realtime_set,
75277 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
75278 .timer_get = common_timer_get,
75279 .timer_del = common_timer_del,
75280 };
75281 - struct k_clock clock_monotonic = {
75282 + static struct k_clock clock_monotonic = {
75283 .clock_getres = hrtimer_get_res,
75284 .clock_get = posix_ktime_get_ts,
75285 .nsleep = common_nsleep,
75286 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
75287 .timer_get = common_timer_get,
75288 .timer_del = common_timer_del,
75289 };
75290 - struct k_clock clock_monotonic_raw = {
75291 + static struct k_clock clock_monotonic_raw = {
75292 .clock_getres = hrtimer_get_res,
75293 .clock_get = posix_get_monotonic_raw,
75294 };
75295 - struct k_clock clock_realtime_coarse = {
75296 + static struct k_clock clock_realtime_coarse = {
75297 .clock_getres = posix_get_coarse_res,
75298 .clock_get = posix_get_realtime_coarse,
75299 };
75300 - struct k_clock clock_monotonic_coarse = {
75301 + static struct k_clock clock_monotonic_coarse = {
75302 .clock_getres = posix_get_coarse_res,
75303 .clock_get = posix_get_monotonic_coarse,
75304 };
75305 - struct k_clock clock_boottime = {
75306 + static struct k_clock clock_boottime = {
75307 .clock_getres = hrtimer_get_res,
75308 .clock_get = posix_get_boottime,
75309 .nsleep = common_nsleep,
75310 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
75311 return;
75312 }
75313
75314 - posix_clocks[clock_id] = *new_clock;
75315 + posix_clocks[clock_id] = new_clock;
75316 }
75317 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
75318
75319 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
75320 return (id & CLOCKFD_MASK) == CLOCKFD ?
75321 &clock_posix_dynamic : &clock_posix_cpu;
75322
75323 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
75324 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
75325 return NULL;
75326 - return &posix_clocks[id];
75327 + return posix_clocks[id];
75328 }
75329
75330 static int common_timer_create(struct k_itimer *new_timer)
75331 @@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
75332 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
75333 return -EFAULT;
75334
75335 + /* only the CLOCK_REALTIME clock can be set, all other clocks
75336 + have their clock_set fptr set to a nosettime dummy function
75337 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
75338 + call common_clock_set, which calls do_sys_settimeofday, which
75339 + we hook
75340 + */
75341 +
75342 return kc->clock_set(which_clock, &new_tp);
75343 }
75344
75345 diff --git a/kernel/power/process.c b/kernel/power/process.c
75346 index d5a258b..4271191 100644
75347 --- a/kernel/power/process.c
75348 +++ b/kernel/power/process.c
75349 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
75350 u64 elapsed_csecs64;
75351 unsigned int elapsed_csecs;
75352 bool wakeup = false;
75353 + bool timedout = false;
75354
75355 do_gettimeofday(&start);
75356
75357 @@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
75358
75359 while (true) {
75360 todo = 0;
75361 + if (time_after(jiffies, end_time))
75362 + timedout = true;
75363 read_lock(&tasklist_lock);
75364 do_each_thread(g, p) {
75365 if (p == current || !freeze_task(p))
75366 continue;
75367
75368 - if (!freezer_should_skip(p))
75369 + if (!freezer_should_skip(p)) {
75370 todo++;
75371 + if (timedout) {
75372 + printk(KERN_ERR "Task refusing to freeze:\n");
75373 + sched_show_task(p);
75374 + }
75375 + }
75376 } while_each_thread(g, p);
75377 read_unlock(&tasklist_lock);
75378
75379 @@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
75380 todo += wq_busy;
75381 }
75382
75383 - if (!todo || time_after(jiffies, end_time))
75384 + if (!todo || timedout)
75385 break;
75386
75387 if (pm_wakeup_pending()) {
75388 diff --git a/kernel/printk.c b/kernel/printk.c
75389 index 267ce78..2487112 100644
75390 --- a/kernel/printk.c
75391 +++ b/kernel/printk.c
75392 @@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
75393 return ret;
75394 }
75395
75396 +static int check_syslog_permissions(int type, bool from_file);
75397 +
75398 static int devkmsg_open(struct inode *inode, struct file *file)
75399 {
75400 struct devkmsg_user *user;
75401 int err;
75402
75403 + err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
75404 + if (err)
75405 + return err;
75406 +
75407 /* write-only does not need any file context */
75408 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
75409 return 0;
75410 @@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
75411 if (dmesg_restrict)
75412 return 1;
75413 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
75414 - return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
75415 + return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
75416 }
75417
75418 static int check_syslog_permissions(int type, bool from_file)
75419 @@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
75420 if (from_file && type != SYSLOG_ACTION_OPEN)
75421 return 0;
75422
75423 +#ifdef CONFIG_GRKERNSEC_DMESG
75424 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
75425 + return -EPERM;
75426 +#endif
75427 +
75428 if (syslog_action_restricted(type)) {
75429 if (capable(CAP_SYSLOG))
75430 return 0;
75431 diff --git a/kernel/profile.c b/kernel/profile.c
75432 index 1f39181..86093471 100644
75433 --- a/kernel/profile.c
75434 +++ b/kernel/profile.c
75435 @@ -40,7 +40,7 @@ struct profile_hit {
75436 /* Oprofile timer tick hook */
75437 static int (*timer_hook)(struct pt_regs *) __read_mostly;
75438
75439 -static atomic_t *prof_buffer;
75440 +static atomic_unchecked_t *prof_buffer;
75441 static unsigned long prof_len, prof_shift;
75442
75443 int prof_on __read_mostly;
75444 @@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
75445 hits[i].pc = 0;
75446 continue;
75447 }
75448 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
75449 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
75450 hits[i].hits = hits[i].pc = 0;
75451 }
75452 }
75453 @@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
75454 * Add the current hit(s) and flush the write-queue out
75455 * to the global buffer:
75456 */
75457 - atomic_add(nr_hits, &prof_buffer[pc]);
75458 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
75459 for (i = 0; i < NR_PROFILE_HIT; ++i) {
75460 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
75461 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
75462 hits[i].pc = hits[i].hits = 0;
75463 }
75464 out:
75465 @@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
75466 {
75467 unsigned long pc;
75468 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
75469 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
75470 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
75471 }
75472 #endif /* !CONFIG_SMP */
75473
75474 @@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
75475 return -EFAULT;
75476 buf++; p++; count--; read++;
75477 }
75478 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
75479 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
75480 if (copy_to_user(buf, (void *)pnt, count))
75481 return -EFAULT;
75482 read += count;
75483 @@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
75484 }
75485 #endif
75486 profile_discard_flip_buffers();
75487 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
75488 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
75489 return count;
75490 }
75491
75492 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
75493 index 6cbeaae..363c48a 100644
75494 --- a/kernel/ptrace.c
75495 +++ b/kernel/ptrace.c
75496 @@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
75497 if (seize)
75498 flags |= PT_SEIZED;
75499 rcu_read_lock();
75500 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
75501 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
75502 flags |= PT_PTRACE_CAP;
75503 rcu_read_unlock();
75504 task->ptrace = flags;
75505 @@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
75506 break;
75507 return -EIO;
75508 }
75509 - if (copy_to_user(dst, buf, retval))
75510 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
75511 return -EFAULT;
75512 copied += retval;
75513 src += retval;
75514 @@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
75515 bool seized = child->ptrace & PT_SEIZED;
75516 int ret = -EIO;
75517 siginfo_t siginfo, *si;
75518 - void __user *datavp = (void __user *) data;
75519 + void __user *datavp = (__force void __user *) data;
75520 unsigned long __user *datalp = datavp;
75521 unsigned long flags;
75522
75523 @@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
75524 goto out;
75525 }
75526
75527 + if (gr_handle_ptrace(child, request)) {
75528 + ret = -EPERM;
75529 + goto out_put_task_struct;
75530 + }
75531 +
75532 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
75533 ret = ptrace_attach(child, request, addr, data);
75534 /*
75535 * Some architectures need to do book-keeping after
75536 * a ptrace attach.
75537 */
75538 - if (!ret)
75539 + if (!ret) {
75540 arch_ptrace_attach(child);
75541 + gr_audit_ptrace(child);
75542 + }
75543 goto out_put_task_struct;
75544 }
75545
75546 @@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
75547 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
75548 if (copied != sizeof(tmp))
75549 return -EIO;
75550 - return put_user(tmp, (unsigned long __user *)data);
75551 + return put_user(tmp, (__force unsigned long __user *)data);
75552 }
75553
75554 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
75555 @@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
75556 goto out;
75557 }
75558
75559 + if (gr_handle_ptrace(child, request)) {
75560 + ret = -EPERM;
75561 + goto out_put_task_struct;
75562 + }
75563 +
75564 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
75565 ret = ptrace_attach(child, request, addr, data);
75566 /*
75567 * Some architectures need to do book-keeping after
75568 * a ptrace attach.
75569 */
75570 - if (!ret)
75571 + if (!ret) {
75572 arch_ptrace_attach(child);
75573 + gr_audit_ptrace(child);
75574 + }
75575 goto out_put_task_struct;
75576 }
75577
75578 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
75579 index e7dce58..ad0d7b7 100644
75580 --- a/kernel/rcutiny.c
75581 +++ b/kernel/rcutiny.c
75582 @@ -46,7 +46,7 @@
75583 struct rcu_ctrlblk;
75584 static void invoke_rcu_callbacks(void);
75585 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
75586 -static void rcu_process_callbacks(struct softirq_action *unused);
75587 +static void rcu_process_callbacks(void);
75588 static void __call_rcu(struct rcu_head *head,
75589 void (*func)(struct rcu_head *rcu),
75590 struct rcu_ctrlblk *rcp);
75591 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
75592 rcu_is_callbacks_kthread()));
75593 }
75594
75595 -static void rcu_process_callbacks(struct softirq_action *unused)
75596 +static void rcu_process_callbacks(void)
75597 {
75598 __rcu_process_callbacks(&rcu_sched_ctrlblk);
75599 __rcu_process_callbacks(&rcu_bh_ctrlblk);
75600 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
75601 index f85016a..91cb03b 100644
75602 --- a/kernel/rcutiny_plugin.h
75603 +++ b/kernel/rcutiny_plugin.h
75604 @@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
75605 have_rcu_kthread_work = morework;
75606 local_irq_restore(flags);
75607 if (work)
75608 - rcu_process_callbacks(NULL);
75609 + rcu_process_callbacks();
75610 schedule_timeout_interruptible(1); /* Leave CPU for others. */
75611 }
75612
75613 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
75614 index 31dea01..ad91ffb 100644
75615 --- a/kernel/rcutorture.c
75616 +++ b/kernel/rcutorture.c
75617 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
75618 { 0 };
75619 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
75620 { 0 };
75621 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
75622 -static atomic_t n_rcu_torture_alloc;
75623 -static atomic_t n_rcu_torture_alloc_fail;
75624 -static atomic_t n_rcu_torture_free;
75625 -static atomic_t n_rcu_torture_mberror;
75626 -static atomic_t n_rcu_torture_error;
75627 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
75628 +static atomic_unchecked_t n_rcu_torture_alloc;
75629 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
75630 +static atomic_unchecked_t n_rcu_torture_free;
75631 +static atomic_unchecked_t n_rcu_torture_mberror;
75632 +static atomic_unchecked_t n_rcu_torture_error;
75633 static long n_rcu_torture_barrier_error;
75634 static long n_rcu_torture_boost_ktrerror;
75635 static long n_rcu_torture_boost_rterror;
75636 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
75637
75638 spin_lock_bh(&rcu_torture_lock);
75639 if (list_empty(&rcu_torture_freelist)) {
75640 - atomic_inc(&n_rcu_torture_alloc_fail);
75641 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
75642 spin_unlock_bh(&rcu_torture_lock);
75643 return NULL;
75644 }
75645 - atomic_inc(&n_rcu_torture_alloc);
75646 + atomic_inc_unchecked(&n_rcu_torture_alloc);
75647 p = rcu_torture_freelist.next;
75648 list_del_init(p);
75649 spin_unlock_bh(&rcu_torture_lock);
75650 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
75651 static void
75652 rcu_torture_free(struct rcu_torture *p)
75653 {
75654 - atomic_inc(&n_rcu_torture_free);
75655 + atomic_inc_unchecked(&n_rcu_torture_free);
75656 spin_lock_bh(&rcu_torture_lock);
75657 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
75658 spin_unlock_bh(&rcu_torture_lock);
75659 @@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
75660 i = rp->rtort_pipe_count;
75661 if (i > RCU_TORTURE_PIPE_LEN)
75662 i = RCU_TORTURE_PIPE_LEN;
75663 - atomic_inc(&rcu_torture_wcount[i]);
75664 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
75665 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
75666 rp->rtort_mbtest = 0;
75667 rcu_torture_free(rp);
75668 @@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
75669 i = rp->rtort_pipe_count;
75670 if (i > RCU_TORTURE_PIPE_LEN)
75671 i = RCU_TORTURE_PIPE_LEN;
75672 - atomic_inc(&rcu_torture_wcount[i]);
75673 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
75674 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
75675 rp->rtort_mbtest = 0;
75676 list_del(&rp->rtort_free);
75677 @@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
75678 i = old_rp->rtort_pipe_count;
75679 if (i > RCU_TORTURE_PIPE_LEN)
75680 i = RCU_TORTURE_PIPE_LEN;
75681 - atomic_inc(&rcu_torture_wcount[i]);
75682 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
75683 old_rp->rtort_pipe_count++;
75684 cur_ops->deferred_free(old_rp);
75685 }
75686 @@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
75687 }
75688 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
75689 if (p->rtort_mbtest == 0)
75690 - atomic_inc(&n_rcu_torture_mberror);
75691 + atomic_inc_unchecked(&n_rcu_torture_mberror);
75692 spin_lock(&rand_lock);
75693 cur_ops->read_delay(&rand);
75694 n_rcu_torture_timers++;
75695 @@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
75696 }
75697 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
75698 if (p->rtort_mbtest == 0)
75699 - atomic_inc(&n_rcu_torture_mberror);
75700 + atomic_inc_unchecked(&n_rcu_torture_mberror);
75701 cur_ops->read_delay(&rand);
75702 preempt_disable();
75703 pipe_count = p->rtort_pipe_count;
75704 @@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
75705 rcu_torture_current,
75706 rcu_torture_current_version,
75707 list_empty(&rcu_torture_freelist),
75708 - atomic_read(&n_rcu_torture_alloc),
75709 - atomic_read(&n_rcu_torture_alloc_fail),
75710 - atomic_read(&n_rcu_torture_free));
75711 + atomic_read_unchecked(&n_rcu_torture_alloc),
75712 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
75713 + atomic_read_unchecked(&n_rcu_torture_free));
75714 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
75715 - atomic_read(&n_rcu_torture_mberror),
75716 + atomic_read_unchecked(&n_rcu_torture_mberror),
75717 n_rcu_torture_boost_ktrerror,
75718 n_rcu_torture_boost_rterror);
75719 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
75720 @@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
75721 n_barrier_attempts,
75722 n_rcu_torture_barrier_error);
75723 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
75724 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
75725 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
75726 n_rcu_torture_barrier_error != 0 ||
75727 n_rcu_torture_boost_ktrerror != 0 ||
75728 n_rcu_torture_boost_rterror != 0 ||
75729 n_rcu_torture_boost_failure != 0 ||
75730 i > 1) {
75731 cnt += sprintf(&page[cnt], "!!! ");
75732 - atomic_inc(&n_rcu_torture_error);
75733 + atomic_inc_unchecked(&n_rcu_torture_error);
75734 WARN_ON_ONCE(1);
75735 }
75736 cnt += sprintf(&page[cnt], "Reader Pipe: ");
75737 @@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
75738 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
75739 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
75740 cnt += sprintf(&page[cnt], " %d",
75741 - atomic_read(&rcu_torture_wcount[i]));
75742 + atomic_read_unchecked(&rcu_torture_wcount[i]));
75743 }
75744 cnt += sprintf(&page[cnt], "\n");
75745 if (cur_ops->stats)
75746 @@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
75747
75748 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
75749
75750 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
75751 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
75752 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
75753 else if (n_online_successes != n_online_attempts ||
75754 n_offline_successes != n_offline_attempts)
75755 @@ -1989,18 +1989,18 @@ rcu_torture_init(void)
75756
75757 rcu_torture_current = NULL;
75758 rcu_torture_current_version = 0;
75759 - atomic_set(&n_rcu_torture_alloc, 0);
75760 - atomic_set(&n_rcu_torture_alloc_fail, 0);
75761 - atomic_set(&n_rcu_torture_free, 0);
75762 - atomic_set(&n_rcu_torture_mberror, 0);
75763 - atomic_set(&n_rcu_torture_error, 0);
75764 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
75765 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
75766 + atomic_set_unchecked(&n_rcu_torture_free, 0);
75767 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
75768 + atomic_set_unchecked(&n_rcu_torture_error, 0);
75769 n_rcu_torture_barrier_error = 0;
75770 n_rcu_torture_boost_ktrerror = 0;
75771 n_rcu_torture_boost_rterror = 0;
75772 n_rcu_torture_boost_failure = 0;
75773 n_rcu_torture_boosts = 0;
75774 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
75775 - atomic_set(&rcu_torture_wcount[i], 0);
75776 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
75777 for_each_possible_cpu(cpu) {
75778 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
75779 per_cpu(rcu_torture_count, cpu)[i] = 0;
75780 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
75781 index e441b77..dd54f17 100644
75782 --- a/kernel/rcutree.c
75783 +++ b/kernel/rcutree.c
75784 @@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
75785 rcu_prepare_for_idle(smp_processor_id());
75786 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
75787 smp_mb__before_atomic_inc(); /* See above. */
75788 - atomic_inc(&rdtp->dynticks);
75789 + atomic_inc_unchecked(&rdtp->dynticks);
75790 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
75791 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
75792 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
75793
75794 /*
75795 * It is illegal to enter an extended quiescent state while
75796 @@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
75797 int user)
75798 {
75799 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
75800 - atomic_inc(&rdtp->dynticks);
75801 + atomic_inc_unchecked(&rdtp->dynticks);
75802 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
75803 smp_mb__after_atomic_inc(); /* See above. */
75804 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
75805 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
75806 rcu_cleanup_after_idle(smp_processor_id());
75807 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
75808 if (!user && !is_idle_task(current)) {
75809 @@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
75810 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
75811
75812 if (rdtp->dynticks_nmi_nesting == 0 &&
75813 - (atomic_read(&rdtp->dynticks) & 0x1))
75814 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
75815 return;
75816 rdtp->dynticks_nmi_nesting++;
75817 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
75818 - atomic_inc(&rdtp->dynticks);
75819 + atomic_inc_unchecked(&rdtp->dynticks);
75820 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
75821 smp_mb__after_atomic_inc(); /* See above. */
75822 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
75823 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
75824 }
75825
75826 /**
75827 @@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
75828 return;
75829 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
75830 smp_mb__before_atomic_inc(); /* See above. */
75831 - atomic_inc(&rdtp->dynticks);
75832 + atomic_inc_unchecked(&rdtp->dynticks);
75833 smp_mb__after_atomic_inc(); /* Force delay to next write. */
75834 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
75835 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
75836 }
75837
75838 /**
75839 @@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
75840 int ret;
75841
75842 preempt_disable();
75843 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
75844 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
75845 preempt_enable();
75846 return ret;
75847 }
75848 @@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
75849 */
75850 static int dyntick_save_progress_counter(struct rcu_data *rdp)
75851 {
75852 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
75853 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
75854 return (rdp->dynticks_snap & 0x1) == 0;
75855 }
75856
75857 @@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
75858 unsigned int curr;
75859 unsigned int snap;
75860
75861 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
75862 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
75863 snap = (unsigned int)rdp->dynticks_snap;
75864
75865 /*
75866 @@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
75867 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
75868 */
75869 if (till_stall_check < 3) {
75870 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
75871 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
75872 till_stall_check = 3;
75873 } else if (till_stall_check > 300) {
75874 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
75875 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
75876 till_stall_check = 300;
75877 }
75878 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
75879 @@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
75880 rsp->qlen += rdp->qlen;
75881 rdp->n_cbs_orphaned += rdp->qlen;
75882 rdp->qlen_lazy = 0;
75883 - ACCESS_ONCE(rdp->qlen) = 0;
75884 + ACCESS_ONCE_RW(rdp->qlen) = 0;
75885 }
75886
75887 /*
75888 @@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
75889 }
75890 smp_mb(); /* List handling before counting for rcu_barrier(). */
75891 rdp->qlen_lazy -= count_lazy;
75892 - ACCESS_ONCE(rdp->qlen) -= count;
75893 + ACCESS_ONCE_RW(rdp->qlen) -= count;
75894 rdp->n_cbs_invoked += count;
75895
75896 /* Reinstate batch limit if we have worked down the excess. */
75897 @@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
75898 /*
75899 * Do RCU core processing for the current CPU.
75900 */
75901 -static void rcu_process_callbacks(struct softirq_action *unused)
75902 +static void rcu_process_callbacks(void)
75903 {
75904 struct rcu_state *rsp;
75905
75906 @@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
75907 local_irq_restore(flags);
75908 return;
75909 }
75910 - ACCESS_ONCE(rdp->qlen)++;
75911 + ACCESS_ONCE_RW(rdp->qlen)++;
75912 if (lazy)
75913 rdp->qlen_lazy++;
75914 else
75915 @@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
75916 * counter wrap on a 32-bit system. Quite a few more CPUs would of
75917 * course be required on a 64-bit system.
75918 */
75919 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
75920 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
75921 (ulong)atomic_long_read(&rsp->expedited_done) +
75922 ULONG_MAX / 8)) {
75923 synchronize_sched();
75924 - atomic_long_inc(&rsp->expedited_wrap);
75925 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
75926 return;
75927 }
75928
75929 @@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
75930 * Take a ticket. Note that atomic_inc_return() implies a
75931 * full memory barrier.
75932 */
75933 - snap = atomic_long_inc_return(&rsp->expedited_start);
75934 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
75935 firstsnap = snap;
75936 get_online_cpus();
75937 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
75938 @@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
75939 synchronize_sched_expedited_cpu_stop,
75940 NULL) == -EAGAIN) {
75941 put_online_cpus();
75942 - atomic_long_inc(&rsp->expedited_tryfail);
75943 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
75944
75945 /* Check to see if someone else did our work for us. */
75946 s = atomic_long_read(&rsp->expedited_done);
75947 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
75948 /* ensure test happens before caller kfree */
75949 smp_mb__before_atomic_inc(); /* ^^^ */
75950 - atomic_long_inc(&rsp->expedited_workdone1);
75951 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
75952 return;
75953 }
75954
75955 @@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
75956 udelay(trycount * num_online_cpus());
75957 } else {
75958 wait_rcu_gp(call_rcu_sched);
75959 - atomic_long_inc(&rsp->expedited_normal);
75960 + atomic_long_inc_unchecked(&rsp->expedited_normal);
75961 return;
75962 }
75963
75964 @@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
75965 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
75966 /* ensure test happens before caller kfree */
75967 smp_mb__before_atomic_inc(); /* ^^^ */
75968 - atomic_long_inc(&rsp->expedited_workdone2);
75969 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
75970 return;
75971 }
75972
75973 @@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
75974 * period works for us.
75975 */
75976 get_online_cpus();
75977 - snap = atomic_long_read(&rsp->expedited_start);
75978 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
75979 smp_mb(); /* ensure read is before try_stop_cpus(). */
75980 }
75981 - atomic_long_inc(&rsp->expedited_stoppedcpus);
75982 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
75983
75984 /*
75985 * Everyone up to our most recent fetch is covered by our grace
75986 @@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
75987 * than we did already did their update.
75988 */
75989 do {
75990 - atomic_long_inc(&rsp->expedited_done_tries);
75991 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
75992 s = atomic_long_read(&rsp->expedited_done);
75993 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
75994 /* ensure test happens before caller kfree */
75995 smp_mb__before_atomic_inc(); /* ^^^ */
75996 - atomic_long_inc(&rsp->expedited_done_lost);
75997 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
75998 break;
75999 }
76000 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
76001 - atomic_long_inc(&rsp->expedited_done_exit);
76002 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
76003
76004 put_online_cpus();
76005 }
76006 @@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76007 * ACCESS_ONCE() to prevent the compiler from speculating
76008 * the increment to precede the early-exit check.
76009 */
76010 - ACCESS_ONCE(rsp->n_barrier_done)++;
76011 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76012 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
76013 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
76014 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
76015 @@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76016
76017 /* Increment ->n_barrier_done to prevent duplicate work. */
76018 smp_mb(); /* Keep increment after above mechanism. */
76019 - ACCESS_ONCE(rsp->n_barrier_done)++;
76020 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76021 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
76022 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
76023 smp_mb(); /* Keep increment before caller's subsequent code. */
76024 @@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
76025 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
76026 init_callback_list(rdp);
76027 rdp->qlen_lazy = 0;
76028 - ACCESS_ONCE(rdp->qlen) = 0;
76029 + ACCESS_ONCE_RW(rdp->qlen) = 0;
76030 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
76031 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
76032 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
76033 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
76034 #ifdef CONFIG_RCU_USER_QS
76035 WARN_ON_ONCE(rdp->dynticks->in_user);
76036 #endif
76037 @@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
76038 rdp->blimit = blimit;
76039 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
76040 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
76041 - atomic_set(&rdp->dynticks->dynticks,
76042 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
76043 + atomic_set_unchecked(&rdp->dynticks->dynticks,
76044 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
76045 rcu_prepare_for_idle_init(cpu);
76046 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
76047
76048 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
76049 index 4b69291..704c92e 100644
76050 --- a/kernel/rcutree.h
76051 +++ b/kernel/rcutree.h
76052 @@ -86,7 +86,7 @@ struct rcu_dynticks {
76053 long long dynticks_nesting; /* Track irq/process nesting level. */
76054 /* Process level is worth LLONG_MAX/2. */
76055 int dynticks_nmi_nesting; /* Track NMI nesting level. */
76056 - atomic_t dynticks; /* Even value for idle, else odd. */
76057 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
76058 #ifdef CONFIG_RCU_FAST_NO_HZ
76059 int dyntick_drain; /* Prepare-for-idle state variable. */
76060 unsigned long dyntick_holdoff;
76061 @@ -423,17 +423,17 @@ struct rcu_state {
76062 /* _rcu_barrier(). */
76063 /* End of fields guarded by barrier_mutex. */
76064
76065 - atomic_long_t expedited_start; /* Starting ticket. */
76066 - atomic_long_t expedited_done; /* Done ticket. */
76067 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
76068 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
76069 - atomic_long_t expedited_workdone1; /* # done by others #1. */
76070 - atomic_long_t expedited_workdone2; /* # done by others #2. */
76071 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
76072 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
76073 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
76074 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
76075 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
76076 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
76077 + atomic_long_t expedited_done; /* Done ticket. */
76078 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
76079 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
76080 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
76081 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
76082 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
76083 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
76084 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
76085 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
76086 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
76087
76088 unsigned long jiffies_force_qs; /* Time at which to invoke */
76089 /* force_quiescent_state(). */
76090 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
76091 index c1cc7e1..f62e436 100644
76092 --- a/kernel/rcutree_plugin.h
76093 +++ b/kernel/rcutree_plugin.h
76094 @@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
76095
76096 /* Clean up and exit. */
76097 smp_mb(); /* ensure expedited GP seen before counter increment. */
76098 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
76099 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
76100 unlock_mb_ret:
76101 mutex_unlock(&sync_rcu_preempt_exp_mutex);
76102 mb_ret:
76103 @@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
76104 free_cpumask_var(cm);
76105 }
76106
76107 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
76108 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
76109 .store = &rcu_cpu_kthread_task,
76110 .thread_should_run = rcu_cpu_kthread_should_run,
76111 .thread_fn = rcu_cpu_kthread,
76112 @@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
76113 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
76114 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
76115 cpu, ticks_value, ticks_title,
76116 - atomic_read(&rdtp->dynticks) & 0xfff,
76117 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
76118 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
76119 fast_no_hz);
76120 }
76121 @@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
76122
76123 /* Enqueue the callback on the nocb list and update counts. */
76124 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
76125 - ACCESS_ONCE(*old_rhpp) = rhp;
76126 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
76127 atomic_long_add(rhcount, &rdp->nocb_q_count);
76128 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
76129
76130 @@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
76131 * Extract queued callbacks, update counts, and wait
76132 * for a grace period to elapse.
76133 */
76134 - ACCESS_ONCE(rdp->nocb_head) = NULL;
76135 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
76136 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
76137 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
76138 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
76139 - ACCESS_ONCE(rdp->nocb_p_count) += c;
76140 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
76141 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
76142 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
76143 wait_rcu_gp(rdp->rsp->call_remote);
76144
76145 /* Each pass through the following loop invokes a callback. */
76146 @@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
76147 list = next;
76148 }
76149 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
76150 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
76151 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
76152 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
76153 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
76154 rdp->n_nocbs_invoked += c;
76155 }
76156 return 0;
76157 @@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
76158 rdp = per_cpu_ptr(rsp->rda, cpu);
76159 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
76160 BUG_ON(IS_ERR(t));
76161 - ACCESS_ONCE(rdp->nocb_kthread) = t;
76162 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
76163 }
76164 }
76165
76166 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
76167 index 0d095dc..1985b19 100644
76168 --- a/kernel/rcutree_trace.c
76169 +++ b/kernel/rcutree_trace.c
76170 @@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
76171 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
76172 rdp->passed_quiesce, rdp->qs_pending);
76173 seq_printf(m, " dt=%d/%llx/%d df=%lu",
76174 - atomic_read(&rdp->dynticks->dynticks),
76175 + atomic_read_unchecked(&rdp->dynticks->dynticks),
76176 rdp->dynticks->dynticks_nesting,
76177 rdp->dynticks->dynticks_nmi_nesting,
76178 rdp->dynticks_fqs);
76179 @@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
76180 struct rcu_state *rsp = (struct rcu_state *)m->private;
76181
76182 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",
76183 - atomic_long_read(&rsp->expedited_start),
76184 + atomic_long_read_unchecked(&rsp->expedited_start),
76185 atomic_long_read(&rsp->expedited_done),
76186 - atomic_long_read(&rsp->expedited_wrap),
76187 - atomic_long_read(&rsp->expedited_tryfail),
76188 - atomic_long_read(&rsp->expedited_workdone1),
76189 - atomic_long_read(&rsp->expedited_workdone2),
76190 - atomic_long_read(&rsp->expedited_normal),
76191 - atomic_long_read(&rsp->expedited_stoppedcpus),
76192 - atomic_long_read(&rsp->expedited_done_tries),
76193 - atomic_long_read(&rsp->expedited_done_lost),
76194 - atomic_long_read(&rsp->expedited_done_exit));
76195 + atomic_long_read_unchecked(&rsp->expedited_wrap),
76196 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
76197 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
76198 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
76199 + atomic_long_read_unchecked(&rsp->expedited_normal),
76200 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
76201 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
76202 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
76203 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
76204 return 0;
76205 }
76206
76207 diff --git a/kernel/resource.c b/kernel/resource.c
76208 index 73f35d4..4684fc4 100644
76209 --- a/kernel/resource.c
76210 +++ b/kernel/resource.c
76211 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
76212
76213 static int __init ioresources_init(void)
76214 {
76215 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
76216 +#ifdef CONFIG_GRKERNSEC_PROC_USER
76217 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
76218 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
76219 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76220 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
76221 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
76222 +#endif
76223 +#else
76224 proc_create("ioports", 0, NULL, &proc_ioports_operations);
76225 proc_create("iomem", 0, NULL, &proc_iomem_operations);
76226 +#endif
76227 return 0;
76228 }
76229 __initcall(ioresources_init);
76230 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
76231 index 98ec494..4241d6d 100644
76232 --- a/kernel/rtmutex-tester.c
76233 +++ b/kernel/rtmutex-tester.c
76234 @@ -20,7 +20,7 @@
76235 #define MAX_RT_TEST_MUTEXES 8
76236
76237 static spinlock_t rttest_lock;
76238 -static atomic_t rttest_event;
76239 +static atomic_unchecked_t rttest_event;
76240
76241 struct test_thread_data {
76242 int opcode;
76243 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76244
76245 case RTTEST_LOCKCONT:
76246 td->mutexes[td->opdata] = 1;
76247 - td->event = atomic_add_return(1, &rttest_event);
76248 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76249 return 0;
76250
76251 case RTTEST_RESET:
76252 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76253 return 0;
76254
76255 case RTTEST_RESETEVENT:
76256 - atomic_set(&rttest_event, 0);
76257 + atomic_set_unchecked(&rttest_event, 0);
76258 return 0;
76259
76260 default:
76261 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76262 return ret;
76263
76264 td->mutexes[id] = 1;
76265 - td->event = atomic_add_return(1, &rttest_event);
76266 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76267 rt_mutex_lock(&mutexes[id]);
76268 - td->event = atomic_add_return(1, &rttest_event);
76269 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76270 td->mutexes[id] = 4;
76271 return 0;
76272
76273 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76274 return ret;
76275
76276 td->mutexes[id] = 1;
76277 - td->event = atomic_add_return(1, &rttest_event);
76278 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76279 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
76280 - td->event = atomic_add_return(1, &rttest_event);
76281 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76282 td->mutexes[id] = ret ? 0 : 4;
76283 return ret ? -EINTR : 0;
76284
76285 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76286 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
76287 return ret;
76288
76289 - td->event = atomic_add_return(1, &rttest_event);
76290 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76291 rt_mutex_unlock(&mutexes[id]);
76292 - td->event = atomic_add_return(1, &rttest_event);
76293 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76294 td->mutexes[id] = 0;
76295 return 0;
76296
76297 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76298 break;
76299
76300 td->mutexes[dat] = 2;
76301 - td->event = atomic_add_return(1, &rttest_event);
76302 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76303 break;
76304
76305 default:
76306 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76307 return;
76308
76309 td->mutexes[dat] = 3;
76310 - td->event = atomic_add_return(1, &rttest_event);
76311 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76312 break;
76313
76314 case RTTEST_LOCKNOWAIT:
76315 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76316 return;
76317
76318 td->mutexes[dat] = 1;
76319 - td->event = atomic_add_return(1, &rttest_event);
76320 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76321 return;
76322
76323 default:
76324 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
76325 index 0984a21..939f183 100644
76326 --- a/kernel/sched/auto_group.c
76327 +++ b/kernel/sched/auto_group.c
76328 @@ -11,7 +11,7 @@
76329
76330 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
76331 static struct autogroup autogroup_default;
76332 -static atomic_t autogroup_seq_nr;
76333 +static atomic_unchecked_t autogroup_seq_nr;
76334
76335 void __init autogroup_init(struct task_struct *init_task)
76336 {
76337 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
76338
76339 kref_init(&ag->kref);
76340 init_rwsem(&ag->lock);
76341 - ag->id = atomic_inc_return(&autogroup_seq_nr);
76342 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
76343 ag->tg = tg;
76344 #ifdef CONFIG_RT_GROUP_SCHED
76345 /*
76346 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
76347 index 26058d0..f9d3c76 100644
76348 --- a/kernel/sched/core.c
76349 +++ b/kernel/sched/core.c
76350 @@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
76351 /* convert nice value [19,-20] to rlimit style value [1,40] */
76352 int nice_rlim = 20 - nice;
76353
76354 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
76355 +
76356 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
76357 capable(CAP_SYS_NICE));
76358 }
76359 @@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
76360 if (nice > 19)
76361 nice = 19;
76362
76363 - if (increment < 0 && !can_nice(current, nice))
76364 + if (increment < 0 && (!can_nice(current, nice) ||
76365 + gr_handle_chroot_nice()))
76366 return -EPERM;
76367
76368 retval = security_task_setnice(current, nice);
76369 @@ -3818,6 +3821,7 @@ recheck:
76370 unsigned long rlim_rtprio =
76371 task_rlimit(p, RLIMIT_RTPRIO);
76372
76373 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
76374 /* can't set/change the rt policy */
76375 if (policy != p->policy && !rlim_rtprio)
76376 return -EPERM;
76377 @@ -4901,7 +4905,7 @@ static void migrate_tasks(unsigned int dead_cpu)
76378
76379 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
76380
76381 -static struct ctl_table sd_ctl_dir[] = {
76382 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
76383 {
76384 .procname = "sched_domain",
76385 .mode = 0555,
76386 @@ -4918,17 +4922,17 @@ static struct ctl_table sd_ctl_root[] = {
76387 {}
76388 };
76389
76390 -static struct ctl_table *sd_alloc_ctl_entry(int n)
76391 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
76392 {
76393 - struct ctl_table *entry =
76394 + ctl_table_no_const *entry =
76395 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
76396
76397 return entry;
76398 }
76399
76400 -static void sd_free_ctl_entry(struct ctl_table **tablep)
76401 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
76402 {
76403 - struct ctl_table *entry;
76404 + ctl_table_no_const *entry;
76405
76406 /*
76407 * In the intermediate directories, both the child directory and
76408 @@ -4936,22 +4940,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
76409 * will always be set. In the lowest directory the names are
76410 * static strings and all have proc handlers.
76411 */
76412 - for (entry = *tablep; entry->mode; entry++) {
76413 - if (entry->child)
76414 - sd_free_ctl_entry(&entry->child);
76415 + for (entry = tablep; entry->mode; entry++) {
76416 + if (entry->child) {
76417 + sd_free_ctl_entry(entry->child);
76418 + pax_open_kernel();
76419 + entry->child = NULL;
76420 + pax_close_kernel();
76421 + }
76422 if (entry->proc_handler == NULL)
76423 kfree(entry->procname);
76424 }
76425
76426 - kfree(*tablep);
76427 - *tablep = NULL;
76428 + kfree(tablep);
76429 }
76430
76431 static int min_load_idx = 0;
76432 static int max_load_idx = CPU_LOAD_IDX_MAX;
76433
76434 static void
76435 -set_table_entry(struct ctl_table *entry,
76436 +set_table_entry(ctl_table_no_const *entry,
76437 const char *procname, void *data, int maxlen,
76438 umode_t mode, proc_handler *proc_handler,
76439 bool load_idx)
76440 @@ -4971,7 +4978,7 @@ set_table_entry(struct ctl_table *entry,
76441 static struct ctl_table *
76442 sd_alloc_ctl_domain_table(struct sched_domain *sd)
76443 {
76444 - struct ctl_table *table = sd_alloc_ctl_entry(13);
76445 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
76446
76447 if (table == NULL)
76448 return NULL;
76449 @@ -5006,9 +5013,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
76450 return table;
76451 }
76452
76453 -static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
76454 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
76455 {
76456 - struct ctl_table *entry, *table;
76457 + ctl_table_no_const *entry, *table;
76458 struct sched_domain *sd;
76459 int domain_num = 0, i;
76460 char buf[32];
76461 @@ -5035,11 +5042,13 @@ static struct ctl_table_header *sd_sysctl_header;
76462 static void register_sched_domain_sysctl(void)
76463 {
76464 int i, cpu_num = num_possible_cpus();
76465 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
76466 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
76467 char buf[32];
76468
76469 WARN_ON(sd_ctl_dir[0].child);
76470 + pax_open_kernel();
76471 sd_ctl_dir[0].child = entry;
76472 + pax_close_kernel();
76473
76474 if (entry == NULL)
76475 return;
76476 @@ -5062,8 +5071,12 @@ static void unregister_sched_domain_sysctl(void)
76477 if (sd_sysctl_header)
76478 unregister_sysctl_table(sd_sysctl_header);
76479 sd_sysctl_header = NULL;
76480 - if (sd_ctl_dir[0].child)
76481 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
76482 + if (sd_ctl_dir[0].child) {
76483 + sd_free_ctl_entry(sd_ctl_dir[0].child);
76484 + pax_open_kernel();
76485 + sd_ctl_dir[0].child = NULL;
76486 + pax_close_kernel();
76487 + }
76488 }
76489 #else
76490 static void register_sched_domain_sysctl(void)
76491 @@ -5162,7 +5175,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
76492 * happens before everything else. This has to be lower priority than
76493 * the notifier in the perf_event subsystem, though.
76494 */
76495 -static struct notifier_block __cpuinitdata migration_notifier = {
76496 +static struct notifier_block migration_notifier = {
76497 .notifier_call = migration_call,
76498 .priority = CPU_PRI_MIGRATION,
76499 };
76500 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
76501 index 81fa536..6ccf96a 100644
76502 --- a/kernel/sched/fair.c
76503 +++ b/kernel/sched/fair.c
76504 @@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
76505
76506 static void reset_ptenuma_scan(struct task_struct *p)
76507 {
76508 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
76509 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
76510 p->mm->numa_scan_offset = 0;
76511 }
76512
76513 @@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
76514 */
76515 static int select_idle_sibling(struct task_struct *p, int target)
76516 {
76517 - int cpu = smp_processor_id();
76518 - int prev_cpu = task_cpu(p);
76519 struct sched_domain *sd;
76520 struct sched_group *sg;
76521 - int i;
76522 + int i = task_cpu(p);
76523
76524 - /*
76525 - * If the task is going to be woken-up on this cpu and if it is
76526 - * already idle, then it is the right target.
76527 - */
76528 - if (target == cpu && idle_cpu(cpu))
76529 - return cpu;
76530 + if (idle_cpu(target))
76531 + return target;
76532
76533 /*
76534 - * If the task is going to be woken-up on the cpu where it previously
76535 - * ran and if it is currently idle, then it the right target.
76536 + * If the prevous cpu is cache affine and idle, don't be stupid.
76537 */
76538 - if (target == prev_cpu && idle_cpu(prev_cpu))
76539 - return prev_cpu;
76540 + if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
76541 + return i;
76542
76543 /*
76544 * Otherwise, iterate the domains and find an elegible idle cpu.
76545 @@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
76546 goto next;
76547
76548 for_each_cpu(i, sched_group_cpus(sg)) {
76549 - if (!idle_cpu(i))
76550 + if (i == target || !idle_cpu(i))
76551 goto next;
76552 }
76553
76554 @@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
76555 * run_rebalance_domains is triggered when needed from the scheduler tick.
76556 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
76557 */
76558 -static void run_rebalance_domains(struct softirq_action *h)
76559 +static void run_rebalance_domains(void)
76560 {
76561 int this_cpu = smp_processor_id();
76562 struct rq *this_rq = cpu_rq(this_cpu);
76563 diff --git a/kernel/signal.c b/kernel/signal.c
76564 index 3d09cf6..a67d2c6 100644
76565 --- a/kernel/signal.c
76566 +++ b/kernel/signal.c
76567 @@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
76568
76569 int print_fatal_signals __read_mostly;
76570
76571 -static void __user *sig_handler(struct task_struct *t, int sig)
76572 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
76573 {
76574 return t->sighand->action[sig - 1].sa.sa_handler;
76575 }
76576
76577 -static int sig_handler_ignored(void __user *handler, int sig)
76578 +static int sig_handler_ignored(__sighandler_t handler, int sig)
76579 {
76580 /* Is it explicitly or implicitly ignored? */
76581 return handler == SIG_IGN ||
76582 @@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
76583
76584 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
76585 {
76586 - void __user *handler;
76587 + __sighandler_t handler;
76588
76589 handler = sig_handler(t, sig);
76590
76591 @@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
76592 atomic_inc(&user->sigpending);
76593 rcu_read_unlock();
76594
76595 + if (!override_rlimit)
76596 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
76597 +
76598 if (override_rlimit ||
76599 atomic_read(&user->sigpending) <=
76600 task_rlimit(t, RLIMIT_SIGPENDING)) {
76601 @@ -492,7 +495,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
76602
76603 int unhandled_signal(struct task_struct *tsk, int sig)
76604 {
76605 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
76606 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
76607 if (is_global_init(tsk))
76608 return 1;
76609 if (handler != SIG_IGN && handler != SIG_DFL)
76610 @@ -812,6 +815,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
76611 }
76612 }
76613
76614 + /* allow glibc communication via tgkill to other threads in our
76615 + thread group */
76616 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
76617 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
76618 + && gr_handle_signal(t, sig))
76619 + return -EPERM;
76620 +
76621 return security_task_kill(t, info, sig, 0);
76622 }
76623
76624 @@ -1194,7 +1204,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
76625 return send_signal(sig, info, p, 1);
76626 }
76627
76628 -static int
76629 +int
76630 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76631 {
76632 return send_signal(sig, info, t, 0);
76633 @@ -1231,6 +1241,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76634 unsigned long int flags;
76635 int ret, blocked, ignored;
76636 struct k_sigaction *action;
76637 + int is_unhandled = 0;
76638
76639 spin_lock_irqsave(&t->sighand->siglock, flags);
76640 action = &t->sighand->action[sig-1];
76641 @@ -1245,9 +1256,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76642 }
76643 if (action->sa.sa_handler == SIG_DFL)
76644 t->signal->flags &= ~SIGNAL_UNKILLABLE;
76645 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
76646 + is_unhandled = 1;
76647 ret = specific_send_sig_info(sig, info, t);
76648 spin_unlock_irqrestore(&t->sighand->siglock, flags);
76649
76650 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
76651 + normal operation */
76652 + if (is_unhandled) {
76653 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
76654 + gr_handle_crash(t, sig);
76655 + }
76656 +
76657 return ret;
76658 }
76659
76660 @@ -1314,8 +1334,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
76661 ret = check_kill_permission(sig, info, p);
76662 rcu_read_unlock();
76663
76664 - if (!ret && sig)
76665 + if (!ret && sig) {
76666 ret = do_send_sig_info(sig, info, p, true);
76667 + if (!ret)
76668 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
76669 + }
76670
76671 return ret;
76672 }
76673 @@ -2852,7 +2875,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
76674 int error = -ESRCH;
76675
76676 rcu_read_lock();
76677 - p = find_task_by_vpid(pid);
76678 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76679 + /* allow glibc communication via tgkill to other threads in our
76680 + thread group */
76681 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
76682 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
76683 + p = find_task_by_vpid_unrestricted(pid);
76684 + else
76685 +#endif
76686 + p = find_task_by_vpid(pid);
76687 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
76688 error = check_kill_permission(sig, info, p);
76689 /*
76690 @@ -3135,8 +3166,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
76691 }
76692 seg = get_fs();
76693 set_fs(KERNEL_DS);
76694 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
76695 - (stack_t __force __user *) &uoss,
76696 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
76697 + (stack_t __force_user *) &uoss,
76698 compat_user_stack_pointer());
76699 set_fs(seg);
76700 if (ret >= 0 && uoss_ptr) {
76701 diff --git a/kernel/smp.c b/kernel/smp.c
76702 index 69f38bd..77bbf12 100644
76703 --- a/kernel/smp.c
76704 +++ b/kernel/smp.c
76705 @@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
76706 return NOTIFY_OK;
76707 }
76708
76709 -static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
76710 +static struct notifier_block hotplug_cfd_notifier = {
76711 .notifier_call = hotplug_cfd,
76712 };
76713
76714 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
76715 index d6c5fc0..530560c 100644
76716 --- a/kernel/smpboot.c
76717 +++ b/kernel/smpboot.c
76718 @@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
76719 }
76720 smpboot_unpark_thread(plug_thread, cpu);
76721 }
76722 - list_add(&plug_thread->list, &hotplug_threads);
76723 + pax_list_add(&plug_thread->list, &hotplug_threads);
76724 out:
76725 mutex_unlock(&smpboot_threads_lock);
76726 return ret;
76727 @@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
76728 {
76729 get_online_cpus();
76730 mutex_lock(&smpboot_threads_lock);
76731 - list_del(&plug_thread->list);
76732 + pax_list_del(&plug_thread->list);
76733 smpboot_destroy_threads(plug_thread);
76734 mutex_unlock(&smpboot_threads_lock);
76735 put_online_cpus();
76736 diff --git a/kernel/softirq.c b/kernel/softirq.c
76737 index ed567ba..e71dabf 100644
76738 --- a/kernel/softirq.c
76739 +++ b/kernel/softirq.c
76740 @@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
76741 EXPORT_SYMBOL(irq_stat);
76742 #endif
76743
76744 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
76745 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
76746
76747 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
76748
76749 -char *softirq_to_name[NR_SOFTIRQS] = {
76750 +const char * const softirq_to_name[NR_SOFTIRQS] = {
76751 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
76752 "TASKLET", "SCHED", "HRTIMER", "RCU"
76753 };
76754 @@ -244,7 +244,7 @@ restart:
76755 kstat_incr_softirqs_this_cpu(vec_nr);
76756
76757 trace_softirq_entry(vec_nr);
76758 - h->action(h);
76759 + h->action();
76760 trace_softirq_exit(vec_nr);
76761 if (unlikely(prev_count != preempt_count())) {
76762 printk(KERN_ERR "huh, entered softirq %u %s %p"
76763 @@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
76764 or_softirq_pending(1UL << nr);
76765 }
76766
76767 -void open_softirq(int nr, void (*action)(struct softirq_action *))
76768 +void __init open_softirq(int nr, void (*action)(void))
76769 {
76770 softirq_vec[nr].action = action;
76771 }
76772 @@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
76773
76774 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
76775
76776 -static void tasklet_action(struct softirq_action *a)
76777 +static void tasklet_action(void)
76778 {
76779 struct tasklet_struct *list;
76780
76781 @@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
76782 }
76783 }
76784
76785 -static void tasklet_hi_action(struct softirq_action *a)
76786 +static void tasklet_hi_action(void)
76787 {
76788 struct tasklet_struct *list;
76789
76790 @@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
76791 return NOTIFY_OK;
76792 }
76793
76794 -static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
76795 +static struct notifier_block remote_softirq_cpu_notifier = {
76796 .notifier_call = remote_softirq_cpu_notify,
76797 };
76798
76799 @@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
76800 return NOTIFY_OK;
76801 }
76802
76803 -static struct notifier_block __cpuinitdata cpu_nfb = {
76804 +static struct notifier_block cpu_nfb = {
76805 .notifier_call = cpu_callback
76806 };
76807
76808 -static struct smp_hotplug_thread softirq_threads = {
76809 +static struct smp_hotplug_thread softirq_threads __read_only = {
76810 .store = &ksoftirqd,
76811 .thread_should_run = ksoftirqd_should_run,
76812 .thread_fn = run_ksoftirqd,
76813 diff --git a/kernel/srcu.c b/kernel/srcu.c
76814 index 2b85982..d52ab26 100644
76815 --- a/kernel/srcu.c
76816 +++ b/kernel/srcu.c
76817 @@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
76818 preempt_disable();
76819 idx = rcu_dereference_index_check(sp->completed,
76820 rcu_read_lock_sched_held()) & 0x1;
76821 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
76822 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
76823 smp_mb(); /* B */ /* Avoid leaking the critical section. */
76824 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
76825 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
76826 preempt_enable();
76827 return idx;
76828 }
76829 @@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
76830 {
76831 preempt_disable();
76832 smp_mb(); /* C */ /* Avoid leaking the critical section. */
76833 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
76834 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
76835 preempt_enable();
76836 }
76837 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
76838 diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
76839 index 2f194e9..2c05ea9 100644
76840 --- a/kernel/stop_machine.c
76841 +++ b/kernel/stop_machine.c
76842 @@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
76843 * cpu notifiers. It currently shares the same priority as sched
76844 * migration_notifier.
76845 */
76846 -static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
76847 +static struct notifier_block cpu_stop_cpu_notifier = {
76848 .notifier_call = cpu_stop_cpu_callback,
76849 .priority = 10,
76850 };
76851 diff --git a/kernel/sys.c b/kernel/sys.c
76852 index 265b376..4e42ef5 100644
76853 --- a/kernel/sys.c
76854 +++ b/kernel/sys.c
76855 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
76856 error = -EACCES;
76857 goto out;
76858 }
76859 +
76860 + if (gr_handle_chroot_setpriority(p, niceval)) {
76861 + error = -EACCES;
76862 + goto out;
76863 + }
76864 +
76865 no_nice = security_task_setnice(p, niceval);
76866 if (no_nice) {
76867 error = no_nice;
76868 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
76869 goto error;
76870 }
76871
76872 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
76873 + goto error;
76874 +
76875 if (rgid != (gid_t) -1 ||
76876 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
76877 new->sgid = new->egid;
76878 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
76879 old = current_cred();
76880
76881 retval = -EPERM;
76882 +
76883 + if (gr_check_group_change(kgid, kgid, kgid))
76884 + goto error;
76885 +
76886 if (nsown_capable(CAP_SETGID))
76887 new->gid = new->egid = new->sgid = new->fsgid = kgid;
76888 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
76889 @@ -647,7 +660,7 @@ error:
76890 /*
76891 * change the user struct in a credentials set to match the new UID
76892 */
76893 -static int set_user(struct cred *new)
76894 +int set_user(struct cred *new)
76895 {
76896 struct user_struct *new_user;
76897
76898 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
76899 goto error;
76900 }
76901
76902 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
76903 + goto error;
76904 +
76905 if (!uid_eq(new->uid, old->uid)) {
76906 retval = set_user(new);
76907 if (retval < 0)
76908 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
76909 old = current_cred();
76910
76911 retval = -EPERM;
76912 +
76913 + if (gr_check_crash_uid(kuid))
76914 + goto error;
76915 + if (gr_check_user_change(kuid, kuid, kuid))
76916 + goto error;
76917 +
76918 if (nsown_capable(CAP_SETUID)) {
76919 new->suid = new->uid = kuid;
76920 if (!uid_eq(kuid, old->uid)) {
76921 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
76922 goto error;
76923 }
76924
76925 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
76926 + goto error;
76927 +
76928 if (ruid != (uid_t) -1) {
76929 new->uid = kruid;
76930 if (!uid_eq(kruid, old->uid)) {
76931 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
76932 goto error;
76933 }
76934
76935 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
76936 + goto error;
76937 +
76938 if (rgid != (gid_t) -1)
76939 new->gid = krgid;
76940 if (egid != (gid_t) -1)
76941 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
76942 if (!uid_valid(kuid))
76943 return old_fsuid;
76944
76945 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
76946 + goto error;
76947 +
76948 new = prepare_creds();
76949 if (!new)
76950 return old_fsuid;
76951 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
76952 }
76953 }
76954
76955 +error:
76956 abort_creds(new);
76957 return old_fsuid;
76958
76959 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
76960 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
76961 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
76962 nsown_capable(CAP_SETGID)) {
76963 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
76964 + goto error;
76965 +
76966 if (!gid_eq(kgid, old->fsgid)) {
76967 new->fsgid = kgid;
76968 goto change_okay;
76969 }
76970 }
76971
76972 +error:
76973 abort_creds(new);
76974 return old_fsgid;
76975
76976 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
76977 return -EFAULT;
76978
76979 down_read(&uts_sem);
76980 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
76981 + error = __copy_to_user(name->sysname, &utsname()->sysname,
76982 __OLD_UTS_LEN);
76983 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
76984 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
76985 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
76986 __OLD_UTS_LEN);
76987 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
76988 - error |= __copy_to_user(&name->release, &utsname()->release,
76989 + error |= __copy_to_user(name->release, &utsname()->release,
76990 __OLD_UTS_LEN);
76991 error |= __put_user(0, name->release + __OLD_UTS_LEN);
76992 - error |= __copy_to_user(&name->version, &utsname()->version,
76993 + error |= __copy_to_user(name->version, &utsname()->version,
76994 __OLD_UTS_LEN);
76995 error |= __put_user(0, name->version + __OLD_UTS_LEN);
76996 - error |= __copy_to_user(&name->machine, &utsname()->machine,
76997 + error |= __copy_to_user(name->machine, &utsname()->machine,
76998 __OLD_UTS_LEN);
76999 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
77000 up_read(&uts_sem);
77001 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
77002 error = get_dumpable(me->mm);
77003 break;
77004 case PR_SET_DUMPABLE:
77005 - if (arg2 < 0 || arg2 > 1) {
77006 + if (arg2 > 1) {
77007 error = -EINVAL;
77008 break;
77009 }
77010 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
77011 index c88878d..e4fa5d1 100644
77012 --- a/kernel/sysctl.c
77013 +++ b/kernel/sysctl.c
77014 @@ -92,7 +92,6 @@
77015
77016
77017 #if defined(CONFIG_SYSCTL)
77018 -
77019 /* External variables not in a header file. */
77020 extern int sysctl_overcommit_memory;
77021 extern int sysctl_overcommit_ratio;
77022 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
77023 void __user *buffer, size_t *lenp, loff_t *ppos);
77024 #endif
77025
77026 -#ifdef CONFIG_PRINTK
77027 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77028 void __user *buffer, size_t *lenp, loff_t *ppos);
77029 -#endif
77030
77031 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
77032 void __user *buffer, size_t *lenp, loff_t *ppos);
77033 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
77034
77035 #endif
77036
77037 +extern struct ctl_table grsecurity_table[];
77038 +
77039 static struct ctl_table kern_table[];
77040 static struct ctl_table vm_table[];
77041 static struct ctl_table fs_table[];
77042 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
77043 int sysctl_legacy_va_layout;
77044 #endif
77045
77046 +#ifdef CONFIG_PAX_SOFTMODE
77047 +static ctl_table pax_table[] = {
77048 + {
77049 + .procname = "softmode",
77050 + .data = &pax_softmode,
77051 + .maxlen = sizeof(unsigned int),
77052 + .mode = 0600,
77053 + .proc_handler = &proc_dointvec,
77054 + },
77055 +
77056 + { }
77057 +};
77058 +#endif
77059 +
77060 /* The default sysctl tables: */
77061
77062 static struct ctl_table sysctl_base_table[] = {
77063 @@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
77064 #endif
77065
77066 static struct ctl_table kern_table[] = {
77067 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
77068 + {
77069 + .procname = "grsecurity",
77070 + .mode = 0500,
77071 + .child = grsecurity_table,
77072 + },
77073 +#endif
77074 +
77075 +#ifdef CONFIG_PAX_SOFTMODE
77076 + {
77077 + .procname = "pax",
77078 + .mode = 0500,
77079 + .child = pax_table,
77080 + },
77081 +#endif
77082 +
77083 {
77084 .procname = "sched_child_runs_first",
77085 .data = &sysctl_sched_child_runs_first,
77086 @@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
77087 .data = &modprobe_path,
77088 .maxlen = KMOD_PATH_LEN,
77089 .mode = 0644,
77090 - .proc_handler = proc_dostring,
77091 + .proc_handler = proc_dostring_modpriv,
77092 },
77093 {
77094 .procname = "modules_disabled",
77095 @@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
77096 .extra1 = &zero,
77097 .extra2 = &one,
77098 },
77099 +#endif
77100 {
77101 .procname = "kptr_restrict",
77102 .data = &kptr_restrict,
77103 .maxlen = sizeof(int),
77104 .mode = 0644,
77105 .proc_handler = proc_dointvec_minmax_sysadmin,
77106 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77107 + .extra1 = &two,
77108 +#else
77109 .extra1 = &zero,
77110 +#endif
77111 .extra2 = &two,
77112 },
77113 -#endif
77114 {
77115 .procname = "ngroups_max",
77116 .data = &ngroups_max,
77117 @@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
77118 .proc_handler = proc_dointvec_minmax,
77119 .extra1 = &zero,
77120 },
77121 + {
77122 + .procname = "heap_stack_gap",
77123 + .data = &sysctl_heap_stack_gap,
77124 + .maxlen = sizeof(sysctl_heap_stack_gap),
77125 + .mode = 0644,
77126 + .proc_handler = proc_doulongvec_minmax,
77127 + },
77128 #else
77129 {
77130 .procname = "nr_trim_pages",
77131 @@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
77132 buffer, lenp, ppos);
77133 }
77134
77135 +int proc_dostring_modpriv(struct ctl_table *table, int write,
77136 + void __user *buffer, size_t *lenp, loff_t *ppos)
77137 +{
77138 + if (write && !capable(CAP_SYS_MODULE))
77139 + return -EPERM;
77140 +
77141 + return _proc_do_string(table->data, table->maxlen, write,
77142 + buffer, lenp, ppos);
77143 +}
77144 +
77145 static size_t proc_skip_spaces(char **buf)
77146 {
77147 size_t ret;
77148 @@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
77149 len = strlen(tmp);
77150 if (len > *size)
77151 len = *size;
77152 + if (len > sizeof(tmp))
77153 + len = sizeof(tmp);
77154 if (copy_to_user(*buf, tmp, len))
77155 return -EFAULT;
77156 *size -= len;
77157 @@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
77158 static int proc_taint(struct ctl_table *table, int write,
77159 void __user *buffer, size_t *lenp, loff_t *ppos)
77160 {
77161 - struct ctl_table t;
77162 + ctl_table_no_const t;
77163 unsigned long tmptaint = get_taint();
77164 int err;
77165
77166 @@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
77167 return err;
77168 }
77169
77170 -#ifdef CONFIG_PRINTK
77171 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77172 void __user *buffer, size_t *lenp, loff_t *ppos)
77173 {
77174 @@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77175
77176 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
77177 }
77178 -#endif
77179
77180 struct do_proc_dointvec_minmax_conv_param {
77181 int *min;
77182 @@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
77183 *i = val;
77184 } else {
77185 val = convdiv * (*i) / convmul;
77186 - if (!first)
77187 + if (!first) {
77188 err = proc_put_char(&buffer, &left, '\t');
77189 + if (err)
77190 + break;
77191 + }
77192 err = proc_put_long(&buffer, &left, val, false);
77193 if (err)
77194 break;
77195 @@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
77196 return -ENOSYS;
77197 }
77198
77199 +int proc_dostring_modpriv(struct ctl_table *table, int write,
77200 + void __user *buffer, size_t *lenp, loff_t *ppos)
77201 +{
77202 + return -ENOSYS;
77203 +}
77204 +
77205 int proc_dointvec(struct ctl_table *table, int write,
77206 void __user *buffer, size_t *lenp, loff_t *ppos)
77207 {
77208 @@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
77209 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
77210 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
77211 EXPORT_SYMBOL(proc_dostring);
77212 +EXPORT_SYMBOL(proc_dostring_modpriv);
77213 EXPORT_SYMBOL(proc_doulongvec_minmax);
77214 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
77215 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
77216 index 0ddf3a0..a199f50 100644
77217 --- a/kernel/sysctl_binary.c
77218 +++ b/kernel/sysctl_binary.c
77219 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
77220 int i;
77221
77222 set_fs(KERNEL_DS);
77223 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
77224 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
77225 set_fs(old_fs);
77226 if (result < 0)
77227 goto out_kfree;
77228 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
77229 }
77230
77231 set_fs(KERNEL_DS);
77232 - result = vfs_write(file, buffer, str - buffer, &pos);
77233 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
77234 set_fs(old_fs);
77235 if (result < 0)
77236 goto out_kfree;
77237 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
77238 int i;
77239
77240 set_fs(KERNEL_DS);
77241 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
77242 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
77243 set_fs(old_fs);
77244 if (result < 0)
77245 goto out_kfree;
77246 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
77247 }
77248
77249 set_fs(KERNEL_DS);
77250 - result = vfs_write(file, buffer, str - buffer, &pos);
77251 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
77252 set_fs(old_fs);
77253 if (result < 0)
77254 goto out_kfree;
77255 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
77256 int i;
77257
77258 set_fs(KERNEL_DS);
77259 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
77260 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
77261 set_fs(old_fs);
77262 if (result < 0)
77263 goto out;
77264 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
77265 __le16 dnaddr;
77266
77267 set_fs(KERNEL_DS);
77268 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
77269 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
77270 set_fs(old_fs);
77271 if (result < 0)
77272 goto out;
77273 @@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
77274 le16_to_cpu(dnaddr) & 0x3ff);
77275
77276 set_fs(KERNEL_DS);
77277 - result = vfs_write(file, buf, len, &pos);
77278 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
77279 set_fs(old_fs);
77280 if (result < 0)
77281 goto out;
77282 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
77283 index 145bb4d..b2aa969 100644
77284 --- a/kernel/taskstats.c
77285 +++ b/kernel/taskstats.c
77286 @@ -28,9 +28,12 @@
77287 #include <linux/fs.h>
77288 #include <linux/file.h>
77289 #include <linux/pid_namespace.h>
77290 +#include <linux/grsecurity.h>
77291 #include <net/genetlink.h>
77292 #include <linux/atomic.h>
77293
77294 +extern int gr_is_taskstats_denied(int pid);
77295 +
77296 /*
77297 * Maximum length of a cpumask that can be specified in
77298 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
77299 @@ -570,6 +573,9 @@ err:
77300
77301 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
77302 {
77303 + if (gr_is_taskstats_denied(current->pid))
77304 + return -EACCES;
77305 +
77306 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
77307 return cmd_attr_register_cpumask(info);
77308 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
77309 diff --git a/kernel/time.c b/kernel/time.c
77310 index d226c6a..c7c0960 100644
77311 --- a/kernel/time.c
77312 +++ b/kernel/time.c
77313 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
77314 return error;
77315
77316 if (tz) {
77317 + /* we log in do_settimeofday called below, so don't log twice
77318 + */
77319 + if (!tv)
77320 + gr_log_timechange();
77321 +
77322 sys_tz = *tz;
77323 update_vsyscall_tz();
77324 if (firsttime) {
77325 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
77326 index f11d83b..d016d91 100644
77327 --- a/kernel/time/alarmtimer.c
77328 +++ b/kernel/time/alarmtimer.c
77329 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
77330 struct platform_device *pdev;
77331 int error = 0;
77332 int i;
77333 - struct k_clock alarm_clock = {
77334 + static struct k_clock alarm_clock = {
77335 .clock_getres = alarm_clock_getres,
77336 .clock_get = alarm_clock_get,
77337 .timer_create = alarm_timer_create,
77338 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
77339 index f113755..ec24223 100644
77340 --- a/kernel/time/tick-broadcast.c
77341 +++ b/kernel/time/tick-broadcast.c
77342 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
77343 * then clear the broadcast bit.
77344 */
77345 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
77346 - int cpu = smp_processor_id();
77347 + cpu = smp_processor_id();
77348
77349 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
77350 tick_broadcast_clear_oneshot(cpu);
77351 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
77352 index cbc6acb..3a77191 100644
77353 --- a/kernel/time/timekeeping.c
77354 +++ b/kernel/time/timekeeping.c
77355 @@ -15,6 +15,7 @@
77356 #include <linux/init.h>
77357 #include <linux/mm.h>
77358 #include <linux/sched.h>
77359 +#include <linux/grsecurity.h>
77360 #include <linux/syscore_ops.h>
77361 #include <linux/clocksource.h>
77362 #include <linux/jiffies.h>
77363 @@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
77364 if (!timespec_valid_strict(tv))
77365 return -EINVAL;
77366
77367 + gr_log_timechange();
77368 +
77369 write_seqlock_irqsave(&tk->lock, flags);
77370
77371 timekeeping_forward_now(tk);
77372 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
77373 index af5a7e9..715611a 100644
77374 --- a/kernel/time/timer_list.c
77375 +++ b/kernel/time/timer_list.c
77376 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
77377
77378 static void print_name_offset(struct seq_file *m, void *sym)
77379 {
77380 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77381 + SEQ_printf(m, "<%p>", NULL);
77382 +#else
77383 char symname[KSYM_NAME_LEN];
77384
77385 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
77386 SEQ_printf(m, "<%pK>", sym);
77387 else
77388 SEQ_printf(m, "%s", symname);
77389 +#endif
77390 }
77391
77392 static void
77393 @@ -112,7 +116,11 @@ next_one:
77394 static void
77395 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
77396 {
77397 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77398 + SEQ_printf(m, " .base: %p\n", NULL);
77399 +#else
77400 SEQ_printf(m, " .base: %pK\n", base);
77401 +#endif
77402 SEQ_printf(m, " .index: %d\n",
77403 base->index);
77404 SEQ_printf(m, " .resolution: %Lu nsecs\n",
77405 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
77406 {
77407 struct proc_dir_entry *pe;
77408
77409 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
77410 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
77411 +#else
77412 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
77413 +#endif
77414 if (!pe)
77415 return -ENOMEM;
77416 return 0;
77417 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
77418 index 0b537f2..40d6c20 100644
77419 --- a/kernel/time/timer_stats.c
77420 +++ b/kernel/time/timer_stats.c
77421 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
77422 static unsigned long nr_entries;
77423 static struct entry entries[MAX_ENTRIES];
77424
77425 -static atomic_t overflow_count;
77426 +static atomic_unchecked_t overflow_count;
77427
77428 /*
77429 * The entries are in a hash-table, for fast lookup:
77430 @@ -140,7 +140,7 @@ static void reset_entries(void)
77431 nr_entries = 0;
77432 memset(entries, 0, sizeof(entries));
77433 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
77434 - atomic_set(&overflow_count, 0);
77435 + atomic_set_unchecked(&overflow_count, 0);
77436 }
77437
77438 static struct entry *alloc_entry(void)
77439 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
77440 if (likely(entry))
77441 entry->count++;
77442 else
77443 - atomic_inc(&overflow_count);
77444 + atomic_inc_unchecked(&overflow_count);
77445
77446 out_unlock:
77447 raw_spin_unlock_irqrestore(lock, flags);
77448 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
77449
77450 static void print_name_offset(struct seq_file *m, unsigned long addr)
77451 {
77452 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77453 + seq_printf(m, "<%p>", NULL);
77454 +#else
77455 char symname[KSYM_NAME_LEN];
77456
77457 if (lookup_symbol_name(addr, symname) < 0)
77458 - seq_printf(m, "<%p>", (void *)addr);
77459 + seq_printf(m, "<%pK>", (void *)addr);
77460 else
77461 seq_printf(m, "%s", symname);
77462 +#endif
77463 }
77464
77465 static int tstats_show(struct seq_file *m, void *v)
77466 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
77467
77468 seq_puts(m, "Timer Stats Version: v0.2\n");
77469 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
77470 - if (atomic_read(&overflow_count))
77471 + if (atomic_read_unchecked(&overflow_count))
77472 seq_printf(m, "Overflow: %d entries\n",
77473 - atomic_read(&overflow_count));
77474 + atomic_read_unchecked(&overflow_count));
77475
77476 for (i = 0; i < nr_entries; i++) {
77477 entry = entries + i;
77478 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
77479 {
77480 struct proc_dir_entry *pe;
77481
77482 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
77483 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
77484 +#else
77485 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
77486 +#endif
77487 if (!pe)
77488 return -ENOMEM;
77489 return 0;
77490 diff --git a/kernel/timer.c b/kernel/timer.c
77491 index 367d008..1ee9ed9 100644
77492 --- a/kernel/timer.c
77493 +++ b/kernel/timer.c
77494 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
77495 /*
77496 * This function runs timers and the timer-tq in bottom half context.
77497 */
77498 -static void run_timer_softirq(struct softirq_action *h)
77499 +static void run_timer_softirq(void)
77500 {
77501 struct tvec_base *base = __this_cpu_read(tvec_bases);
77502
77503 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
77504 return NOTIFY_OK;
77505 }
77506
77507 -static struct notifier_block __cpuinitdata timers_nb = {
77508 +static struct notifier_block timers_nb = {
77509 .notifier_call = timer_cpu_notify,
77510 };
77511
77512 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
77513 index c0bd030..62a1927 100644
77514 --- a/kernel/trace/blktrace.c
77515 +++ b/kernel/trace/blktrace.c
77516 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
77517 struct blk_trace *bt = filp->private_data;
77518 char buf[16];
77519
77520 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
77521 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
77522
77523 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
77524 }
77525 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
77526 return 1;
77527
77528 bt = buf->chan->private_data;
77529 - atomic_inc(&bt->dropped);
77530 + atomic_inc_unchecked(&bt->dropped);
77531 return 0;
77532 }
77533
77534 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
77535
77536 bt->dir = dir;
77537 bt->dev = dev;
77538 - atomic_set(&bt->dropped, 0);
77539 + atomic_set_unchecked(&bt->dropped, 0);
77540
77541 ret = -EIO;
77542 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
77543 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
77544 index 43defd1..76da436 100644
77545 --- a/kernel/trace/ftrace.c
77546 +++ b/kernel/trace/ftrace.c
77547 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
77548 if (unlikely(ftrace_disabled))
77549 return 0;
77550
77551 + ret = ftrace_arch_code_modify_prepare();
77552 + FTRACE_WARN_ON(ret);
77553 + if (ret)
77554 + return 0;
77555 +
77556 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
77557 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
77558 if (ret) {
77559 ftrace_bug(ret, ip);
77560 - return 0;
77561 }
77562 - return 1;
77563 + return ret ? 0 : 1;
77564 }
77565
77566 /*
77567 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
77568
77569 int
77570 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
77571 - void *data)
77572 + void *data)
77573 {
77574 struct ftrace_func_probe *entry;
77575 struct ftrace_page *pg;
77576 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
77577 if (!count)
77578 return 0;
77579
77580 + pax_open_kernel();
77581 sort(start, count, sizeof(*start),
77582 ftrace_cmp_ips, ftrace_swap_ips);
77583 + pax_close_kernel();
77584
77585 start_pg = ftrace_allocate_pages(count);
77586 if (!start_pg)
77587 @@ -4559,8 +4566,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
77588 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
77589
77590 static int ftrace_graph_active;
77591 -static struct notifier_block ftrace_suspend_notifier;
77592 -
77593 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
77594 {
77595 return 0;
77596 @@ -4704,6 +4709,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
77597 return NOTIFY_DONE;
77598 }
77599
77600 +static struct notifier_block ftrace_suspend_notifier = {
77601 + .notifier_call = ftrace_suspend_notifier_call
77602 +};
77603 +
77604 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
77605 trace_func_graph_ent_t entryfunc)
77606 {
77607 @@ -4717,7 +4726,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
77608 goto out;
77609 }
77610
77611 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
77612 register_pm_notifier(&ftrace_suspend_notifier);
77613
77614 ftrace_graph_active++;
77615 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
77616 index ce8514f..8233573 100644
77617 --- a/kernel/trace/ring_buffer.c
77618 +++ b/kernel/trace/ring_buffer.c
77619 @@ -346,9 +346,9 @@ struct buffer_data_page {
77620 */
77621 struct buffer_page {
77622 struct list_head list; /* list of buffer pages */
77623 - local_t write; /* index for next write */
77624 + local_unchecked_t write; /* index for next write */
77625 unsigned read; /* index for next read */
77626 - local_t entries; /* entries on this page */
77627 + local_unchecked_t entries; /* entries on this page */
77628 unsigned long real_end; /* real end of data */
77629 struct buffer_data_page *page; /* Actual data page */
77630 };
77631 @@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
77632 unsigned long last_overrun;
77633 local_t entries_bytes;
77634 local_t entries;
77635 - local_t overrun;
77636 - local_t commit_overrun;
77637 + local_unchecked_t overrun;
77638 + local_unchecked_t commit_overrun;
77639 local_t dropped_events;
77640 local_t committing;
77641 local_t commits;
77642 @@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
77643 *
77644 * We add a counter to the write field to denote this.
77645 */
77646 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
77647 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
77648 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
77649 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
77650
77651 /*
77652 * Just make sure we have seen our old_write and synchronize
77653 @@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
77654 * cmpxchg to only update if an interrupt did not already
77655 * do it for us. If the cmpxchg fails, we don't care.
77656 */
77657 - (void)local_cmpxchg(&next_page->write, old_write, val);
77658 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
77659 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
77660 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
77661
77662 /*
77663 * No need to worry about races with clearing out the commit.
77664 @@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
77665
77666 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
77667 {
77668 - return local_read(&bpage->entries) & RB_WRITE_MASK;
77669 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
77670 }
77671
77672 static inline unsigned long rb_page_write(struct buffer_page *bpage)
77673 {
77674 - return local_read(&bpage->write) & RB_WRITE_MASK;
77675 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
77676 }
77677
77678 static int
77679 @@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
77680 * bytes consumed in ring buffer from here.
77681 * Increment overrun to account for the lost events.
77682 */
77683 - local_add(page_entries, &cpu_buffer->overrun);
77684 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
77685 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
77686 }
77687
77688 @@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
77689 * it is our responsibility to update
77690 * the counters.
77691 */
77692 - local_add(entries, &cpu_buffer->overrun);
77693 + local_add_unchecked(entries, &cpu_buffer->overrun);
77694 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
77695
77696 /*
77697 @@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77698 if (tail == BUF_PAGE_SIZE)
77699 tail_page->real_end = 0;
77700
77701 - local_sub(length, &tail_page->write);
77702 + local_sub_unchecked(length, &tail_page->write);
77703 return;
77704 }
77705
77706 @@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77707 rb_event_set_padding(event);
77708
77709 /* Set the write back to the previous setting */
77710 - local_sub(length, &tail_page->write);
77711 + local_sub_unchecked(length, &tail_page->write);
77712 return;
77713 }
77714
77715 @@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77716
77717 /* Set write to end of buffer */
77718 length = (tail + length) - BUF_PAGE_SIZE;
77719 - local_sub(length, &tail_page->write);
77720 + local_sub_unchecked(length, &tail_page->write);
77721 }
77722
77723 /*
77724 @@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
77725 * about it.
77726 */
77727 if (unlikely(next_page == commit_page)) {
77728 - local_inc(&cpu_buffer->commit_overrun);
77729 + local_inc_unchecked(&cpu_buffer->commit_overrun);
77730 goto out_reset;
77731 }
77732
77733 @@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
77734 cpu_buffer->tail_page) &&
77735 (cpu_buffer->commit_page ==
77736 cpu_buffer->reader_page))) {
77737 - local_inc(&cpu_buffer->commit_overrun);
77738 + local_inc_unchecked(&cpu_buffer->commit_overrun);
77739 goto out_reset;
77740 }
77741 }
77742 @@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
77743 length += RB_LEN_TIME_EXTEND;
77744
77745 tail_page = cpu_buffer->tail_page;
77746 - write = local_add_return(length, &tail_page->write);
77747 + write = local_add_return_unchecked(length, &tail_page->write);
77748
77749 /* set write to only the index of the write */
77750 write &= RB_WRITE_MASK;
77751 @@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
77752 kmemcheck_annotate_bitfield(event, bitfield);
77753 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
77754
77755 - local_inc(&tail_page->entries);
77756 + local_inc_unchecked(&tail_page->entries);
77757
77758 /*
77759 * If this is the first commit on the page, then update
77760 @@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
77761
77762 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
77763 unsigned long write_mask =
77764 - local_read(&bpage->write) & ~RB_WRITE_MASK;
77765 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
77766 unsigned long event_length = rb_event_length(event);
77767 /*
77768 * This is on the tail page. It is possible that
77769 @@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
77770 */
77771 old_index += write_mask;
77772 new_index += write_mask;
77773 - index = local_cmpxchg(&bpage->write, old_index, new_index);
77774 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
77775 if (index == old_index) {
77776 /* update counters */
77777 local_sub(event_length, &cpu_buffer->entries_bytes);
77778 @@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
77779
77780 /* Do the likely case first */
77781 if (likely(bpage->page == (void *)addr)) {
77782 - local_dec(&bpage->entries);
77783 + local_dec_unchecked(&bpage->entries);
77784 return;
77785 }
77786
77787 @@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
77788 start = bpage;
77789 do {
77790 if (bpage->page == (void *)addr) {
77791 - local_dec(&bpage->entries);
77792 + local_dec_unchecked(&bpage->entries);
77793 return;
77794 }
77795 rb_inc_page(cpu_buffer, &bpage);
77796 @@ -2926,7 +2926,7 @@ static inline unsigned long
77797 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
77798 {
77799 return local_read(&cpu_buffer->entries) -
77800 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
77801 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
77802 }
77803
77804 /**
77805 @@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
77806 return 0;
77807
77808 cpu_buffer = buffer->buffers[cpu];
77809 - ret = local_read(&cpu_buffer->overrun);
77810 + ret = local_read_unchecked(&cpu_buffer->overrun);
77811
77812 return ret;
77813 }
77814 @@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
77815 return 0;
77816
77817 cpu_buffer = buffer->buffers[cpu];
77818 - ret = local_read(&cpu_buffer->commit_overrun);
77819 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
77820
77821 return ret;
77822 }
77823 @@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
77824 /* if you care about this being correct, lock the buffer */
77825 for_each_buffer_cpu(buffer, cpu) {
77826 cpu_buffer = buffer->buffers[cpu];
77827 - overruns += local_read(&cpu_buffer->overrun);
77828 + overruns += local_read_unchecked(&cpu_buffer->overrun);
77829 }
77830
77831 return overruns;
77832 @@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
77833 /*
77834 * Reset the reader page to size zero.
77835 */
77836 - local_set(&cpu_buffer->reader_page->write, 0);
77837 - local_set(&cpu_buffer->reader_page->entries, 0);
77838 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
77839 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
77840 local_set(&cpu_buffer->reader_page->page->commit, 0);
77841 cpu_buffer->reader_page->real_end = 0;
77842
77843 @@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
77844 * want to compare with the last_overrun.
77845 */
77846 smp_mb();
77847 - overwrite = local_read(&(cpu_buffer->overrun));
77848 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
77849
77850 /*
77851 * Here's the tricky part.
77852 @@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
77853
77854 cpu_buffer->head_page
77855 = list_entry(cpu_buffer->pages, struct buffer_page, list);
77856 - local_set(&cpu_buffer->head_page->write, 0);
77857 - local_set(&cpu_buffer->head_page->entries, 0);
77858 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
77859 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
77860 local_set(&cpu_buffer->head_page->page->commit, 0);
77861
77862 cpu_buffer->head_page->read = 0;
77863 @@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
77864
77865 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
77866 INIT_LIST_HEAD(&cpu_buffer->new_pages);
77867 - local_set(&cpu_buffer->reader_page->write, 0);
77868 - local_set(&cpu_buffer->reader_page->entries, 0);
77869 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
77870 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
77871 local_set(&cpu_buffer->reader_page->page->commit, 0);
77872 cpu_buffer->reader_page->read = 0;
77873
77874 local_set(&cpu_buffer->entries_bytes, 0);
77875 - local_set(&cpu_buffer->overrun, 0);
77876 - local_set(&cpu_buffer->commit_overrun, 0);
77877 + local_set_unchecked(&cpu_buffer->overrun, 0);
77878 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
77879 local_set(&cpu_buffer->dropped_events, 0);
77880 local_set(&cpu_buffer->entries, 0);
77881 local_set(&cpu_buffer->committing, 0);
77882 @@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
77883 rb_init_page(bpage);
77884 bpage = reader->page;
77885 reader->page = *data_page;
77886 - local_set(&reader->write, 0);
77887 - local_set(&reader->entries, 0);
77888 + local_set_unchecked(&reader->write, 0);
77889 + local_set_unchecked(&reader->entries, 0);
77890 reader->read = 0;
77891 *data_page = bpage;
77892
77893 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
77894 index 3c13e46..883d039 100644
77895 --- a/kernel/trace/trace.c
77896 +++ b/kernel/trace/trace.c
77897 @@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
77898 };
77899 #endif
77900
77901 -static struct dentry *d_tracer;
77902 -
77903 struct dentry *tracing_init_dentry(void)
77904 {
77905 + static struct dentry *d_tracer;
77906 static int once;
77907
77908 if (d_tracer)
77909 @@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
77910 return d_tracer;
77911 }
77912
77913 -static struct dentry *d_percpu;
77914 -
77915 struct dentry *tracing_dentry_percpu(void)
77916 {
77917 + static struct dentry *d_percpu;
77918 static int once;
77919 struct dentry *d_tracer;
77920
77921 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
77922 index 880073d..42db7c3 100644
77923 --- a/kernel/trace/trace_events.c
77924 +++ b/kernel/trace/trace_events.c
77925 @@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
77926 struct ftrace_module_file_ops {
77927 struct list_head list;
77928 struct module *mod;
77929 - struct file_operations id;
77930 - struct file_operations enable;
77931 - struct file_operations format;
77932 - struct file_operations filter;
77933 };
77934
77935 static struct ftrace_module_file_ops *
77936 @@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
77937
77938 file_ops->mod = mod;
77939
77940 - file_ops->id = ftrace_event_id_fops;
77941 - file_ops->id.owner = mod;
77942 -
77943 - file_ops->enable = ftrace_enable_fops;
77944 - file_ops->enable.owner = mod;
77945 -
77946 - file_ops->filter = ftrace_event_filter_fops;
77947 - file_ops->filter.owner = mod;
77948 -
77949 - file_ops->format = ftrace_event_format_fops;
77950 - file_ops->format.owner = mod;
77951 + pax_open_kernel();
77952 + mod->trace_id.owner = mod;
77953 + mod->trace_enable.owner = mod;
77954 + mod->trace_filter.owner = mod;
77955 + mod->trace_format.owner = mod;
77956 + pax_close_kernel();
77957
77958 list_add(&file_ops->list, &ftrace_module_file_list);
77959
77960 @@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
77961
77962 for_each_event(call, start, end) {
77963 __trace_add_event_call(*call, mod,
77964 - &file_ops->id, &file_ops->enable,
77965 - &file_ops->filter, &file_ops->format);
77966 + &mod->trace_id, &mod->trace_enable,
77967 + &mod->trace_filter, &mod->trace_format);
77968 }
77969 }
77970
77971 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
77972 index fd3c8aa..5f324a6 100644
77973 --- a/kernel/trace/trace_mmiotrace.c
77974 +++ b/kernel/trace/trace_mmiotrace.c
77975 @@ -24,7 +24,7 @@ struct header_iter {
77976 static struct trace_array *mmio_trace_array;
77977 static bool overrun_detected;
77978 static unsigned long prev_overruns;
77979 -static atomic_t dropped_count;
77980 +static atomic_unchecked_t dropped_count;
77981
77982 static void mmio_reset_data(struct trace_array *tr)
77983 {
77984 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
77985
77986 static unsigned long count_overruns(struct trace_iterator *iter)
77987 {
77988 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
77989 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
77990 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
77991
77992 if (over > prev_overruns)
77993 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
77994 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
77995 sizeof(*entry), 0, pc);
77996 if (!event) {
77997 - atomic_inc(&dropped_count);
77998 + atomic_inc_unchecked(&dropped_count);
77999 return;
78000 }
78001 entry = ring_buffer_event_data(event);
78002 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
78003 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
78004 sizeof(*entry), 0, pc);
78005 if (!event) {
78006 - atomic_inc(&dropped_count);
78007 + atomic_inc_unchecked(&dropped_count);
78008 return;
78009 }
78010 entry = ring_buffer_event_data(event);
78011 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
78012 index 194d796..76edb8f 100644
78013 --- a/kernel/trace/trace_output.c
78014 +++ b/kernel/trace/trace_output.c
78015 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
78016
78017 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
78018 if (!IS_ERR(p)) {
78019 - p = mangle_path(s->buffer + s->len, p, "\n");
78020 + p = mangle_path(s->buffer + s->len, p, "\n\\");
78021 if (p) {
78022 s->len = p - s->buffer;
78023 return 1;
78024 @@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
78025 goto out;
78026 }
78027
78028 + pax_open_kernel();
78029 if (event->funcs->trace == NULL)
78030 - event->funcs->trace = trace_nop_print;
78031 + *(void **)&event->funcs->trace = trace_nop_print;
78032 if (event->funcs->raw == NULL)
78033 - event->funcs->raw = trace_nop_print;
78034 + *(void **)&event->funcs->raw = trace_nop_print;
78035 if (event->funcs->hex == NULL)
78036 - event->funcs->hex = trace_nop_print;
78037 + *(void **)&event->funcs->hex = trace_nop_print;
78038 if (event->funcs->binary == NULL)
78039 - event->funcs->binary = trace_nop_print;
78040 + *(void **)&event->funcs->binary = trace_nop_print;
78041 + pax_close_kernel();
78042
78043 key = event->type & (EVENT_HASHSIZE - 1);
78044
78045 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
78046 index 42ca822..cdcacc6 100644
78047 --- a/kernel/trace/trace_stack.c
78048 +++ b/kernel/trace/trace_stack.c
78049 @@ -52,7 +52,7 @@ static inline void check_stack(void)
78050 return;
78051
78052 /* we do not handle interrupt stacks yet */
78053 - if (!object_is_on_stack(&this_size))
78054 + if (!object_starts_on_stack(&this_size))
78055 return;
78056
78057 local_irq_save(flags);
78058 diff --git a/kernel/user.c b/kernel/user.c
78059 index 33acb5e..57ebfd4 100644
78060 --- a/kernel/user.c
78061 +++ b/kernel/user.c
78062 @@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
78063 .count = 4294967295U,
78064 },
78065 },
78066 - .kref = {
78067 - .refcount = ATOMIC_INIT(3),
78068 - },
78069 + .count = ATOMIC_INIT(3),
78070 .owner = GLOBAL_ROOT_UID,
78071 .group = GLOBAL_ROOT_GID,
78072 .proc_inum = PROC_USER_INIT_INO,
78073 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
78074 index 2b042c4..24f8ec3 100644
78075 --- a/kernel/user_namespace.c
78076 +++ b/kernel/user_namespace.c
78077 @@ -78,7 +78,7 @@ int create_user_ns(struct cred *new)
78078 return ret;
78079 }
78080
78081 - kref_init(&ns->kref);
78082 + atomic_set(&ns->count, 1);
78083 /* Leave the new->user_ns reference with the new user namespace. */
78084 ns->parent = parent_ns;
78085 ns->owner = owner;
78086 @@ -104,15 +104,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
78087 return create_user_ns(cred);
78088 }
78089
78090 -void free_user_ns(struct kref *kref)
78091 +void free_user_ns(struct user_namespace *ns)
78092 {
78093 - struct user_namespace *parent, *ns =
78094 - container_of(kref, struct user_namespace, kref);
78095 + struct user_namespace *parent;
78096
78097 - parent = ns->parent;
78098 - proc_free_inum(ns->proc_inum);
78099 - kmem_cache_free(user_ns_cachep, ns);
78100 - put_user_ns(parent);
78101 + do {
78102 + parent = ns->parent;
78103 + proc_free_inum(ns->proc_inum);
78104 + kmem_cache_free(user_ns_cachep, ns);
78105 + ns = parent;
78106 + } while (atomic_dec_and_test(&parent->count));
78107 }
78108 EXPORT_SYMBOL(free_user_ns);
78109
78110 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
78111 index 63da38c..639904e 100644
78112 --- a/kernel/utsname_sysctl.c
78113 +++ b/kernel/utsname_sysctl.c
78114 @@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
78115 static int proc_do_uts_string(ctl_table *table, int write,
78116 void __user *buffer, size_t *lenp, loff_t *ppos)
78117 {
78118 - struct ctl_table uts_table;
78119 + ctl_table_no_const uts_table;
78120 int r;
78121 memcpy(&uts_table, table, sizeof(uts_table));
78122 uts_table.data = get_uts(table, write);
78123 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
78124 index 75a2ab3..5961da7 100644
78125 --- a/kernel/watchdog.c
78126 +++ b/kernel/watchdog.c
78127 @@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
78128 }
78129 #endif /* CONFIG_SYSCTL */
78130
78131 -static struct smp_hotplug_thread watchdog_threads = {
78132 +static struct smp_hotplug_thread watchdog_threads __read_only = {
78133 .store = &softlockup_watchdog,
78134 .thread_should_run = watchdog_should_run,
78135 .thread_fn = watchdog,
78136 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
78137 index 67604e5..fe94fb1 100644
78138 --- a/lib/Kconfig.debug
78139 +++ b/lib/Kconfig.debug
78140 @@ -550,7 +550,7 @@ config DEBUG_MUTEXES
78141
78142 config DEBUG_LOCK_ALLOC
78143 bool "Lock debugging: detect incorrect freeing of live locks"
78144 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78145 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78146 select DEBUG_SPINLOCK
78147 select DEBUG_MUTEXES
78148 select LOCKDEP
78149 @@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
78150
78151 config PROVE_LOCKING
78152 bool "Lock debugging: prove locking correctness"
78153 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78154 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78155 select LOCKDEP
78156 select DEBUG_SPINLOCK
78157 select DEBUG_MUTEXES
78158 @@ -670,7 +670,7 @@ config LOCKDEP
78159
78160 config LOCK_STAT
78161 bool "Lock usage statistics"
78162 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78163 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78164 select LOCKDEP
78165 select DEBUG_SPINLOCK
78166 select DEBUG_MUTEXES
78167 @@ -1278,6 +1278,7 @@ config LATENCYTOP
78168 depends on DEBUG_KERNEL
78169 depends on STACKTRACE_SUPPORT
78170 depends on PROC_FS
78171 + depends on !GRKERNSEC_HIDESYM
78172 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
78173 select KALLSYMS
78174 select KALLSYMS_ALL
78175 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
78176
78177 config PROVIDE_OHCI1394_DMA_INIT
78178 bool "Remote debugging over FireWire early on boot"
78179 - depends on PCI && X86
78180 + depends on PCI && X86 && !GRKERNSEC
78181 help
78182 If you want to debug problems which hang or crash the kernel early
78183 on boot and the crashing machine has a FireWire port, you can use
78184 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
78185
78186 config FIREWIRE_OHCI_REMOTE_DMA
78187 bool "Remote debugging over FireWire with firewire-ohci"
78188 - depends on FIREWIRE_OHCI
78189 + depends on FIREWIRE_OHCI && !GRKERNSEC
78190 help
78191 This option lets you use the FireWire bus for remote debugging
78192 with help of the firewire-ohci driver. It enables unfiltered
78193 diff --git a/lib/Makefile b/lib/Makefile
78194 index 02ed6c0..bd243da 100644
78195 --- a/lib/Makefile
78196 +++ b/lib/Makefile
78197 @@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
78198
78199 obj-$(CONFIG_BTREE) += btree.o
78200 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
78201 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
78202 +obj-y += list_debug.o
78203 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
78204
78205 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
78206 diff --git a/lib/bitmap.c b/lib/bitmap.c
78207 index 06f7e4f..f3cf2b0 100644
78208 --- a/lib/bitmap.c
78209 +++ b/lib/bitmap.c
78210 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
78211 {
78212 int c, old_c, totaldigits, ndigits, nchunks, nbits;
78213 u32 chunk;
78214 - const char __user __force *ubuf = (const char __user __force *)buf;
78215 + const char __user *ubuf = (const char __force_user *)buf;
78216
78217 bitmap_zero(maskp, nmaskbits);
78218
78219 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
78220 {
78221 if (!access_ok(VERIFY_READ, ubuf, ulen))
78222 return -EFAULT;
78223 - return __bitmap_parse((const char __force *)ubuf,
78224 + return __bitmap_parse((const char __force_kernel *)ubuf,
78225 ulen, 1, maskp, nmaskbits);
78226
78227 }
78228 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
78229 {
78230 unsigned a, b;
78231 int c, old_c, totaldigits;
78232 - const char __user __force *ubuf = (const char __user __force *)buf;
78233 + const char __user *ubuf = (const char __force_user *)buf;
78234 int exp_digit, in_range;
78235
78236 totaldigits = c = 0;
78237 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
78238 {
78239 if (!access_ok(VERIFY_READ, ubuf, ulen))
78240 return -EFAULT;
78241 - return __bitmap_parselist((const char __force *)ubuf,
78242 + return __bitmap_parselist((const char __force_kernel *)ubuf,
78243 ulen, 1, maskp, nmaskbits);
78244 }
78245 EXPORT_SYMBOL(bitmap_parselist_user);
78246 diff --git a/lib/bug.c b/lib/bug.c
78247 index d0cdf14..4d07bd2 100644
78248 --- a/lib/bug.c
78249 +++ b/lib/bug.c
78250 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
78251 return BUG_TRAP_TYPE_NONE;
78252
78253 bug = find_bug(bugaddr);
78254 + if (!bug)
78255 + return BUG_TRAP_TYPE_NONE;
78256
78257 file = NULL;
78258 line = 0;
78259 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
78260 index d11808c..dc2d6f8 100644
78261 --- a/lib/debugobjects.c
78262 +++ b/lib/debugobjects.c
78263 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
78264 if (limit > 4)
78265 return;
78266
78267 - is_on_stack = object_is_on_stack(addr);
78268 + is_on_stack = object_starts_on_stack(addr);
78269 if (is_on_stack == onstack)
78270 return;
78271
78272 diff --git a/lib/devres.c b/lib/devres.c
78273 index 80b9c76..9e32279 100644
78274 --- a/lib/devres.c
78275 +++ b/lib/devres.c
78276 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
78277 void devm_iounmap(struct device *dev, void __iomem *addr)
78278 {
78279 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
78280 - (void *)addr));
78281 + (void __force *)addr));
78282 iounmap(addr);
78283 }
78284 EXPORT_SYMBOL(devm_iounmap);
78285 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
78286 {
78287 ioport_unmap(addr);
78288 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
78289 - devm_ioport_map_match, (void *)addr));
78290 + devm_ioport_map_match, (void __force *)addr));
78291 }
78292 EXPORT_SYMBOL(devm_ioport_unmap);
78293
78294 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
78295 index 5e396ac..58d5de1 100644
78296 --- a/lib/dma-debug.c
78297 +++ b/lib/dma-debug.c
78298 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
78299
78300 void dma_debug_add_bus(struct bus_type *bus)
78301 {
78302 - struct notifier_block *nb;
78303 + notifier_block_no_const *nb;
78304
78305 if (global_disable)
78306 return;
78307 @@ -942,7 +942,7 @@ out:
78308
78309 static void check_for_stack(struct device *dev, void *addr)
78310 {
78311 - if (object_is_on_stack(addr))
78312 + if (object_starts_on_stack(addr))
78313 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
78314 "stack [addr=%p]\n", addr);
78315 }
78316 diff --git a/lib/inflate.c b/lib/inflate.c
78317 index 013a761..c28f3fc 100644
78318 --- a/lib/inflate.c
78319 +++ b/lib/inflate.c
78320 @@ -269,7 +269,7 @@ static void free(void *where)
78321 malloc_ptr = free_mem_ptr;
78322 }
78323 #else
78324 -#define malloc(a) kmalloc(a, GFP_KERNEL)
78325 +#define malloc(a) kmalloc((a), GFP_KERNEL)
78326 #define free(a) kfree(a)
78327 #endif
78328
78329 diff --git a/lib/ioremap.c b/lib/ioremap.c
78330 index 0c9216c..863bd89 100644
78331 --- a/lib/ioremap.c
78332 +++ b/lib/ioremap.c
78333 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
78334 unsigned long next;
78335
78336 phys_addr -= addr;
78337 - pmd = pmd_alloc(&init_mm, pud, addr);
78338 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
78339 if (!pmd)
78340 return -ENOMEM;
78341 do {
78342 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
78343 unsigned long next;
78344
78345 phys_addr -= addr;
78346 - pud = pud_alloc(&init_mm, pgd, addr);
78347 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
78348 if (!pud)
78349 return -ENOMEM;
78350 do {
78351 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
78352 index bd2bea9..6b3c95e 100644
78353 --- a/lib/is_single_threaded.c
78354 +++ b/lib/is_single_threaded.c
78355 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
78356 struct task_struct *p, *t;
78357 bool ret;
78358
78359 + if (!mm)
78360 + return true;
78361 +
78362 if (atomic_read(&task->signal->live) != 1)
78363 return false;
78364
78365 diff --git a/lib/kobject.c b/lib/kobject.c
78366 index e07ee1f..998489d 100644
78367 --- a/lib/kobject.c
78368 +++ b/lib/kobject.c
78369 @@ -852,9 +852,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
78370
78371
78372 static DEFINE_SPINLOCK(kobj_ns_type_lock);
78373 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
78374 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
78375
78376 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
78377 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
78378 {
78379 enum kobj_ns_type type = ops->type;
78380 int error;
78381 diff --git a/lib/list_debug.c b/lib/list_debug.c
78382 index c24c2f7..0475b78 100644
78383 --- a/lib/list_debug.c
78384 +++ b/lib/list_debug.c
78385 @@ -11,7 +11,9 @@
78386 #include <linux/bug.h>
78387 #include <linux/kernel.h>
78388 #include <linux/rculist.h>
78389 +#include <linux/mm.h>
78390
78391 +#ifdef CONFIG_DEBUG_LIST
78392 /*
78393 * Insert a new entry between two known consecutive entries.
78394 *
78395 @@ -19,21 +21,32 @@
78396 * the prev/next entries already!
78397 */
78398
78399 -void __list_add(struct list_head *new,
78400 - struct list_head *prev,
78401 - struct list_head *next)
78402 +static bool __list_add_debug(struct list_head *new,
78403 + struct list_head *prev,
78404 + struct list_head *next)
78405 {
78406 - WARN(next->prev != prev,
78407 + if (WARN(next->prev != prev,
78408 "list_add corruption. next->prev should be "
78409 "prev (%p), but was %p. (next=%p).\n",
78410 - prev, next->prev, next);
78411 - WARN(prev->next != next,
78412 + prev, next->prev, next) ||
78413 + WARN(prev->next != next,
78414 "list_add corruption. prev->next should be "
78415 "next (%p), but was %p. (prev=%p).\n",
78416 - next, prev->next, prev);
78417 - WARN(new == prev || new == next,
78418 + next, prev->next, prev) ||
78419 + WARN(new == prev || new == next,
78420 "list_add double add: new=%p, prev=%p, next=%p.\n",
78421 - new, prev, next);
78422 + new, prev, next))
78423 + return false;
78424 + return true;
78425 +}
78426 +
78427 +void __list_add(struct list_head *new,
78428 + struct list_head *prev,
78429 + struct list_head *next)
78430 +{
78431 + if (!__list_add_debug(new, prev, next))
78432 + return;
78433 +
78434 next->prev = new;
78435 new->next = next;
78436 new->prev = prev;
78437 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
78438 }
78439 EXPORT_SYMBOL(__list_add);
78440
78441 -void __list_del_entry(struct list_head *entry)
78442 +static bool __list_del_entry_debug(struct list_head *entry)
78443 {
78444 struct list_head *prev, *next;
78445
78446 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
78447 WARN(next->prev != entry,
78448 "list_del corruption. next->prev should be %p, "
78449 "but was %p\n", entry, next->prev))
78450 + return false;
78451 + return true;
78452 +}
78453 +
78454 +void __list_del_entry(struct list_head *entry)
78455 +{
78456 + if (!__list_del_entry_debug(entry))
78457 return;
78458
78459 - __list_del(prev, next);
78460 + __list_del(entry->prev, entry->next);
78461 }
78462 EXPORT_SYMBOL(__list_del_entry);
78463
78464 @@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
78465 void __list_add_rcu(struct list_head *new,
78466 struct list_head *prev, struct list_head *next)
78467 {
78468 - WARN(next->prev != prev,
78469 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
78470 - prev, next->prev, next);
78471 - WARN(prev->next != next,
78472 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
78473 - next, prev->next, prev);
78474 + if (!__list_add_debug(new, prev, next))
78475 + return;
78476 +
78477 new->next = next;
78478 new->prev = prev;
78479 rcu_assign_pointer(list_next_rcu(prev), new);
78480 next->prev = new;
78481 }
78482 EXPORT_SYMBOL(__list_add_rcu);
78483 +#endif
78484 +
78485 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
78486 +{
78487 +#ifdef CONFIG_DEBUG_LIST
78488 + if (!__list_add_debug(new, prev, next))
78489 + return;
78490 +#endif
78491 +
78492 + pax_open_kernel();
78493 + next->prev = new;
78494 + new->next = next;
78495 + new->prev = prev;
78496 + prev->next = new;
78497 + pax_close_kernel();
78498 +}
78499 +EXPORT_SYMBOL(__pax_list_add);
78500 +
78501 +void pax_list_del(struct list_head *entry)
78502 +{
78503 +#ifdef CONFIG_DEBUG_LIST
78504 + if (!__list_del_entry_debug(entry))
78505 + return;
78506 +#endif
78507 +
78508 + pax_open_kernel();
78509 + __list_del(entry->prev, entry->next);
78510 + entry->next = LIST_POISON1;
78511 + entry->prev = LIST_POISON2;
78512 + pax_close_kernel();
78513 +}
78514 +EXPORT_SYMBOL(pax_list_del);
78515 +
78516 +void pax_list_del_init(struct list_head *entry)
78517 +{
78518 + pax_open_kernel();
78519 + __list_del(entry->prev, entry->next);
78520 + INIT_LIST_HEAD(entry);
78521 + pax_close_kernel();
78522 +}
78523 +EXPORT_SYMBOL(pax_list_del_init);
78524 +
78525 +void __pax_list_add_rcu(struct list_head *new,
78526 + struct list_head *prev, struct list_head *next)
78527 +{
78528 +#ifdef CONFIG_DEBUG_LIST
78529 + if (!__list_add_debug(new, prev, next))
78530 + return;
78531 +#endif
78532 +
78533 + pax_open_kernel();
78534 + new->next = next;
78535 + new->prev = prev;
78536 + rcu_assign_pointer(list_next_rcu(prev), new);
78537 + next->prev = new;
78538 + pax_close_kernel();
78539 +}
78540 +EXPORT_SYMBOL(__pax_list_add_rcu);
78541 +
78542 +void pax_list_del_rcu(struct list_head *entry)
78543 +{
78544 +#ifdef CONFIG_DEBUG_LIST
78545 + if (!__list_del_entry_debug(entry))
78546 + return;
78547 +#endif
78548 +
78549 + pax_open_kernel();
78550 + __list_del(entry->prev, entry->next);
78551 + entry->next = LIST_POISON1;
78552 + entry->prev = LIST_POISON2;
78553 + pax_close_kernel();
78554 +}
78555 +EXPORT_SYMBOL(pax_list_del_rcu);
78556 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
78557 index e796429..6e38f9f 100644
78558 --- a/lib/radix-tree.c
78559 +++ b/lib/radix-tree.c
78560 @@ -92,7 +92,7 @@ struct radix_tree_preload {
78561 int nr;
78562 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
78563 };
78564 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
78565 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
78566
78567 static inline void *ptr_to_indirect(void *ptr)
78568 {
78569 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
78570 index bb2b201..46abaf9 100644
78571 --- a/lib/strncpy_from_user.c
78572 +++ b/lib/strncpy_from_user.c
78573 @@ -21,7 +21,7 @@
78574 */
78575 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
78576 {
78577 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78578 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78579 long res = 0;
78580
78581 /*
78582 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
78583 index a28df52..3d55877 100644
78584 --- a/lib/strnlen_user.c
78585 +++ b/lib/strnlen_user.c
78586 @@ -26,7 +26,7 @@
78587 */
78588 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
78589 {
78590 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78591 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78592 long align, res = 0;
78593 unsigned long c;
78594
78595 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
78596 index 196b069..358f342 100644
78597 --- a/lib/swiotlb.c
78598 +++ b/lib/swiotlb.c
78599 @@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
78600
78601 void
78602 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
78603 - dma_addr_t dev_addr)
78604 + dma_addr_t dev_addr, struct dma_attrs *attrs)
78605 {
78606 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
78607
78608 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
78609 index fab33a9..3b5fe68 100644
78610 --- a/lib/vsprintf.c
78611 +++ b/lib/vsprintf.c
78612 @@ -16,6 +16,9 @@
78613 * - scnprintf and vscnprintf
78614 */
78615
78616 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78617 +#define __INCLUDED_BY_HIDESYM 1
78618 +#endif
78619 #include <stdarg.h>
78620 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
78621 #include <linux/types.h>
78622 @@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
78623 char sym[KSYM_SYMBOL_LEN];
78624 if (ext == 'B')
78625 sprint_backtrace(sym, value);
78626 - else if (ext != 'f' && ext != 's')
78627 + else if (ext != 'f' && ext != 's' && ext != 'a')
78628 sprint_symbol(sym, value);
78629 else
78630 sprint_symbol_no_offset(sym, value);
78631 @@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
78632 return number(buf, end, *(const netdev_features_t *)addr, spec);
78633 }
78634
78635 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78636 +int kptr_restrict __read_mostly = 2;
78637 +#else
78638 int kptr_restrict __read_mostly;
78639 +#endif
78640
78641 /*
78642 * Show a '%p' thing. A kernel extension is that the '%p' is followed
78643 @@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
78644 * - 'S' For symbolic direct pointers with offset
78645 * - 's' For symbolic direct pointers without offset
78646 * - 'B' For backtraced symbolic direct pointers with offset
78647 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
78648 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
78649 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
78650 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
78651 * - 'M' For a 6-byte MAC address, it prints the address in the
78652 @@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78653
78654 if (!ptr && *fmt != 'K') {
78655 /*
78656 - * Print (null) with the same width as a pointer so it makes
78657 + * Print (nil) with the same width as a pointer so it makes
78658 * tabular output look nice.
78659 */
78660 if (spec.field_width == -1)
78661 spec.field_width = default_width;
78662 - return string(buf, end, "(null)", spec);
78663 + return string(buf, end, "(nil)", spec);
78664 }
78665
78666 switch (*fmt) {
78667 @@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78668 /* Fallthrough */
78669 case 'S':
78670 case 's':
78671 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78672 + break;
78673 +#else
78674 + return symbol_string(buf, end, ptr, spec, *fmt);
78675 +#endif
78676 + case 'A':
78677 + case 'a':
78678 case 'B':
78679 return symbol_string(buf, end, ptr, spec, *fmt);
78680 case 'R':
78681 @@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78682 va_end(va);
78683 return buf;
78684 }
78685 + case 'P':
78686 + break;
78687 case 'K':
78688 /*
78689 * %pK cannot be used in IRQ context because its test
78690 @@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78691 }
78692 break;
78693 }
78694 +
78695 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78696 + /* 'P' = approved pointers to copy to userland,
78697 + as in the /proc/kallsyms case, as we make it display nothing
78698 + for non-root users, and the real contents for root users
78699 + Also ignore 'K' pointers, since we force their NULLing for non-root users
78700 + above
78701 + */
78702 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
78703 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
78704 + dump_stack();
78705 + ptr = NULL;
78706 + }
78707 +#endif
78708 +
78709 spec.flags |= SMALL;
78710 if (spec.field_width == -1) {
78711 spec.field_width = default_width;
78712 @@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
78713 typeof(type) value; \
78714 if (sizeof(type) == 8) { \
78715 args = PTR_ALIGN(args, sizeof(u32)); \
78716 - *(u32 *)&value = *(u32 *)args; \
78717 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
78718 + *(u32 *)&value = *(const u32 *)args; \
78719 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
78720 } else { \
78721 args = PTR_ALIGN(args, sizeof(type)); \
78722 - value = *(typeof(type) *)args; \
78723 + value = *(const typeof(type) *)args; \
78724 } \
78725 args += sizeof(type); \
78726 value; \
78727 @@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
78728 case FORMAT_TYPE_STR: {
78729 const char *str_arg = args;
78730 args += strlen(str_arg) + 1;
78731 - str = string(str, end, (char *)str_arg, spec);
78732 + str = string(str, end, str_arg, spec);
78733 break;
78734 }
78735
78736 diff --git a/localversion-grsec b/localversion-grsec
78737 new file mode 100644
78738 index 0000000..7cd6065
78739 --- /dev/null
78740 +++ b/localversion-grsec
78741 @@ -0,0 +1 @@
78742 +-grsec
78743 diff --git a/mm/Kconfig b/mm/Kconfig
78744 index 278e3ab..87c384d 100644
78745 --- a/mm/Kconfig
78746 +++ b/mm/Kconfig
78747 @@ -286,10 +286,10 @@ config KSM
78748 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
78749
78750 config DEFAULT_MMAP_MIN_ADDR
78751 - int "Low address space to protect from user allocation"
78752 + int "Low address space to protect from user allocation"
78753 depends on MMU
78754 - default 4096
78755 - help
78756 + default 65536
78757 + help
78758 This is the portion of low virtual memory which should be protected
78759 from userspace allocation. Keeping a user from writing to low pages
78760 can help reduce the impact of kernel NULL pointer bugs.
78761 @@ -320,7 +320,7 @@ config MEMORY_FAILURE
78762
78763 config HWPOISON_INJECT
78764 tristate "HWPoison pages injector"
78765 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
78766 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
78767 select PROC_PAGE_MONITOR
78768
78769 config NOMMU_INITIAL_TRIM_EXCESS
78770 diff --git a/mm/filemap.c b/mm/filemap.c
78771 index 83efee7..3f99381 100644
78772 --- a/mm/filemap.c
78773 +++ b/mm/filemap.c
78774 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
78775 struct address_space *mapping = file->f_mapping;
78776
78777 if (!mapping->a_ops->readpage)
78778 - return -ENOEXEC;
78779 + return -ENODEV;
78780 file_accessed(file);
78781 vma->vm_ops = &generic_file_vm_ops;
78782 return 0;
78783 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
78784 *pos = i_size_read(inode);
78785
78786 if (limit != RLIM_INFINITY) {
78787 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
78788 if (*pos >= limit) {
78789 send_sig(SIGXFSZ, current, 0);
78790 return -EFBIG;
78791 diff --git a/mm/fremap.c b/mm/fremap.c
78792 index a0aaf0e..20325c3 100644
78793 --- a/mm/fremap.c
78794 +++ b/mm/fremap.c
78795 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
78796 retry:
78797 vma = find_vma(mm, start);
78798
78799 +#ifdef CONFIG_PAX_SEGMEXEC
78800 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
78801 + goto out;
78802 +#endif
78803 +
78804 /*
78805 * Make sure the vma is shared, that it supports prefaulting,
78806 * and that the remapped range is valid and fully within
78807 diff --git a/mm/highmem.c b/mm/highmem.c
78808 index b32b70c..e512eb0 100644
78809 --- a/mm/highmem.c
78810 +++ b/mm/highmem.c
78811 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
78812 * So no dangers, even with speculative execution.
78813 */
78814 page = pte_page(pkmap_page_table[i]);
78815 + pax_open_kernel();
78816 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
78817 -
78818 + pax_close_kernel();
78819 set_page_address(page, NULL);
78820 need_flush = 1;
78821 }
78822 @@ -198,9 +199,11 @@ start:
78823 }
78824 }
78825 vaddr = PKMAP_ADDR(last_pkmap_nr);
78826 +
78827 + pax_open_kernel();
78828 set_pte_at(&init_mm, vaddr,
78829 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
78830 -
78831 + pax_close_kernel();
78832 pkmap_count[last_pkmap_nr] = 1;
78833 set_page_address(page, (void *)vaddr);
78834
78835 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
78836 index 546db81..34830af 100644
78837 --- a/mm/hugetlb.c
78838 +++ b/mm/hugetlb.c
78839 @@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
78840 struct hstate *h = &default_hstate;
78841 unsigned long tmp;
78842 int ret;
78843 + ctl_table_no_const hugetlb_table;
78844
78845 tmp = h->max_huge_pages;
78846
78847 if (write && h->order >= MAX_ORDER)
78848 return -EINVAL;
78849
78850 - table->data = &tmp;
78851 - table->maxlen = sizeof(unsigned long);
78852 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
78853 + hugetlb_table = *table;
78854 + hugetlb_table.data = &tmp;
78855 + hugetlb_table.maxlen = sizeof(unsigned long);
78856 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
78857 if (ret)
78858 goto out;
78859
78860 @@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
78861 struct hstate *h = &default_hstate;
78862 unsigned long tmp;
78863 int ret;
78864 + ctl_table_no_const hugetlb_table;
78865
78866 tmp = h->nr_overcommit_huge_pages;
78867
78868 if (write && h->order >= MAX_ORDER)
78869 return -EINVAL;
78870
78871 - table->data = &tmp;
78872 - table->maxlen = sizeof(unsigned long);
78873 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
78874 + hugetlb_table = *table;
78875 + hugetlb_table.data = &tmp;
78876 + hugetlb_table.maxlen = sizeof(unsigned long);
78877 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
78878 if (ret)
78879 goto out;
78880
78881 @@ -2511,6 +2515,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
78882 return 1;
78883 }
78884
78885 +#ifdef CONFIG_PAX_SEGMEXEC
78886 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
78887 +{
78888 + struct mm_struct *mm = vma->vm_mm;
78889 + struct vm_area_struct *vma_m;
78890 + unsigned long address_m;
78891 + pte_t *ptep_m;
78892 +
78893 + vma_m = pax_find_mirror_vma(vma);
78894 + if (!vma_m)
78895 + return;
78896 +
78897 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
78898 + address_m = address + SEGMEXEC_TASK_SIZE;
78899 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
78900 + get_page(page_m);
78901 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
78902 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
78903 +}
78904 +#endif
78905 +
78906 /*
78907 * Hugetlb_cow() should be called with page lock of the original hugepage held.
78908 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
78909 @@ -2629,6 +2654,11 @@ retry_avoidcopy:
78910 make_huge_pte(vma, new_page, 1));
78911 page_remove_rmap(old_page);
78912 hugepage_add_new_anon_rmap(new_page, vma, address);
78913 +
78914 +#ifdef CONFIG_PAX_SEGMEXEC
78915 + pax_mirror_huge_pte(vma, address, new_page);
78916 +#endif
78917 +
78918 /* Make the old page be freed below */
78919 new_page = old_page;
78920 }
78921 @@ -2788,6 +2818,10 @@ retry:
78922 && (vma->vm_flags & VM_SHARED)));
78923 set_huge_pte_at(mm, address, ptep, new_pte);
78924
78925 +#ifdef CONFIG_PAX_SEGMEXEC
78926 + pax_mirror_huge_pte(vma, address, page);
78927 +#endif
78928 +
78929 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
78930 /* Optimization, do the COW without a second fault */
78931 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
78932 @@ -2817,6 +2851,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
78933 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
78934 struct hstate *h = hstate_vma(vma);
78935
78936 +#ifdef CONFIG_PAX_SEGMEXEC
78937 + struct vm_area_struct *vma_m;
78938 +#endif
78939 +
78940 address &= huge_page_mask(h);
78941
78942 ptep = huge_pte_offset(mm, address);
78943 @@ -2830,6 +2868,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
78944 VM_FAULT_SET_HINDEX(hstate_index(h));
78945 }
78946
78947 +#ifdef CONFIG_PAX_SEGMEXEC
78948 + vma_m = pax_find_mirror_vma(vma);
78949 + if (vma_m) {
78950 + unsigned long address_m;
78951 +
78952 + if (vma->vm_start > vma_m->vm_start) {
78953 + address_m = address;
78954 + address -= SEGMEXEC_TASK_SIZE;
78955 + vma = vma_m;
78956 + h = hstate_vma(vma);
78957 + } else
78958 + address_m = address + SEGMEXEC_TASK_SIZE;
78959 +
78960 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
78961 + return VM_FAULT_OOM;
78962 + address_m &= HPAGE_MASK;
78963 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
78964 + }
78965 +#endif
78966 +
78967 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
78968 if (!ptep)
78969 return VM_FAULT_OOM;
78970 diff --git a/mm/internal.h b/mm/internal.h
78971 index 9ba2110..eaf0674 100644
78972 --- a/mm/internal.h
78973 +++ b/mm/internal.h
78974 @@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
78975 * in mm/page_alloc.c
78976 */
78977 extern void __free_pages_bootmem(struct page *page, unsigned int order);
78978 +extern void free_compound_page(struct page *page);
78979 extern void prep_compound_page(struct page *page, unsigned long order);
78980 #ifdef CONFIG_MEMORY_FAILURE
78981 extern bool is_free_buddy_page(struct page *page);
78982 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
78983 index 752a705..6c3102e 100644
78984 --- a/mm/kmemleak.c
78985 +++ b/mm/kmemleak.c
78986 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
78987
78988 for (i = 0; i < object->trace_len; i++) {
78989 void *ptr = (void *)object->trace[i];
78990 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
78991 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
78992 }
78993 }
78994
78995 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
78996 return -ENOMEM;
78997 }
78998
78999 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
79000 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
79001 &kmemleak_fops);
79002 if (!dentry)
79003 pr_warning("Failed to create the debugfs kmemleak file\n");
79004 diff --git a/mm/maccess.c b/mm/maccess.c
79005 index d53adf9..03a24bf 100644
79006 --- a/mm/maccess.c
79007 +++ b/mm/maccess.c
79008 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
79009 set_fs(KERNEL_DS);
79010 pagefault_disable();
79011 ret = __copy_from_user_inatomic(dst,
79012 - (__force const void __user *)src, size);
79013 + (const void __force_user *)src, size);
79014 pagefault_enable();
79015 set_fs(old_fs);
79016
79017 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
79018
79019 set_fs(KERNEL_DS);
79020 pagefault_disable();
79021 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
79022 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
79023 pagefault_enable();
79024 set_fs(old_fs);
79025
79026 diff --git a/mm/madvise.c b/mm/madvise.c
79027 index 03dfa5c..b032917 100644
79028 --- a/mm/madvise.c
79029 +++ b/mm/madvise.c
79030 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
79031 pgoff_t pgoff;
79032 unsigned long new_flags = vma->vm_flags;
79033
79034 +#ifdef CONFIG_PAX_SEGMEXEC
79035 + struct vm_area_struct *vma_m;
79036 +#endif
79037 +
79038 switch (behavior) {
79039 case MADV_NORMAL:
79040 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
79041 @@ -123,6 +127,13 @@ success:
79042 /*
79043 * vm_flags is protected by the mmap_sem held in write mode.
79044 */
79045 +
79046 +#ifdef CONFIG_PAX_SEGMEXEC
79047 + vma_m = pax_find_mirror_vma(vma);
79048 + if (vma_m)
79049 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
79050 +#endif
79051 +
79052 vma->vm_flags = new_flags;
79053
79054 out:
79055 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
79056 struct vm_area_struct ** prev,
79057 unsigned long start, unsigned long end)
79058 {
79059 +
79060 +#ifdef CONFIG_PAX_SEGMEXEC
79061 + struct vm_area_struct *vma_m;
79062 +#endif
79063 +
79064 *prev = vma;
79065 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
79066 return -EINVAL;
79067 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
79068 zap_page_range(vma, start, end - start, &details);
79069 } else
79070 zap_page_range(vma, start, end - start, NULL);
79071 +
79072 +#ifdef CONFIG_PAX_SEGMEXEC
79073 + vma_m = pax_find_mirror_vma(vma);
79074 + if (vma_m) {
79075 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
79076 + struct zap_details details = {
79077 + .nonlinear_vma = vma_m,
79078 + .last_index = ULONG_MAX,
79079 + };
79080 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
79081 + } else
79082 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
79083 + }
79084 +#endif
79085 +
79086 return 0;
79087 }
79088
79089 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
79090 if (end < start)
79091 goto out;
79092
79093 +#ifdef CONFIG_PAX_SEGMEXEC
79094 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
79095 + if (end > SEGMEXEC_TASK_SIZE)
79096 + goto out;
79097 + } else
79098 +#endif
79099 +
79100 + if (end > TASK_SIZE)
79101 + goto out;
79102 +
79103 error = 0;
79104 if (end == start)
79105 goto out;
79106 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
79107 index c6e4dd3..1f41988 100644
79108 --- a/mm/memory-failure.c
79109 +++ b/mm/memory-failure.c
79110 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
79111
79112 int sysctl_memory_failure_recovery __read_mostly = 1;
79113
79114 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
79115 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
79116
79117 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
79118
79119 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
79120 pfn, t->comm, t->pid);
79121 si.si_signo = SIGBUS;
79122 si.si_errno = 0;
79123 - si.si_addr = (void *)addr;
79124 + si.si_addr = (void __user *)addr;
79125 #ifdef __ARCH_SI_TRAPNO
79126 si.si_trapno = trapno;
79127 #endif
79128 @@ -760,7 +760,7 @@ static struct page_state {
79129 unsigned long res;
79130 char *msg;
79131 int (*action)(struct page *p, unsigned long pfn);
79132 -} error_states[] = {
79133 +} __do_const error_states[] = {
79134 { reserved, reserved, "reserved kernel", me_kernel },
79135 /*
79136 * free pages are specially detected outside this table:
79137 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79138 }
79139
79140 nr_pages = 1 << compound_trans_order(hpage);
79141 - atomic_long_add(nr_pages, &mce_bad_pages);
79142 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
79143
79144 /*
79145 * We need/can do nothing about count=0 pages.
79146 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79147 if (!PageHWPoison(hpage)
79148 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
79149 || (p != hpage && TestSetPageHWPoison(hpage))) {
79150 - atomic_long_sub(nr_pages, &mce_bad_pages);
79151 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79152 return 0;
79153 }
79154 set_page_hwpoison_huge_page(hpage);
79155 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79156 }
79157 if (hwpoison_filter(p)) {
79158 if (TestClearPageHWPoison(p))
79159 - atomic_long_sub(nr_pages, &mce_bad_pages);
79160 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79161 unlock_page(hpage);
79162 put_page(hpage);
79163 return 0;
79164 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
79165 return 0;
79166 }
79167 if (TestClearPageHWPoison(p))
79168 - atomic_long_sub(nr_pages, &mce_bad_pages);
79169 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79170 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
79171 return 0;
79172 }
79173 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
79174 */
79175 if (TestClearPageHWPoison(page)) {
79176 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
79177 - atomic_long_sub(nr_pages, &mce_bad_pages);
79178 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79179 freeit = 1;
79180 if (PageHuge(page))
79181 clear_page_hwpoison_huge_page(page);
79182 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
79183 }
79184 done:
79185 if (!PageHWPoison(hpage))
79186 - atomic_long_add(1 << compound_trans_order(hpage),
79187 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
79188 &mce_bad_pages);
79189 set_page_hwpoison_huge_page(hpage);
79190 dequeue_hwpoisoned_huge_page(hpage);
79191 @@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
79192 return ret;
79193
79194 done:
79195 - atomic_long_add(1, &mce_bad_pages);
79196 + atomic_long_add_unchecked(1, &mce_bad_pages);
79197 SetPageHWPoison(page);
79198 /* keep elevated page count for bad page */
79199 return ret;
79200 diff --git a/mm/memory.c b/mm/memory.c
79201 index bb1369f..efb96b5 100644
79202 --- a/mm/memory.c
79203 +++ b/mm/memory.c
79204 @@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
79205 free_pte_range(tlb, pmd, addr);
79206 } while (pmd++, addr = next, addr != end);
79207
79208 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
79209 start &= PUD_MASK;
79210 if (start < floor)
79211 return;
79212 @@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
79213 pmd = pmd_offset(pud, start);
79214 pud_clear(pud);
79215 pmd_free_tlb(tlb, pmd, start);
79216 +#endif
79217 +
79218 }
79219
79220 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79221 @@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79222 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
79223 } while (pud++, addr = next, addr != end);
79224
79225 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
79226 start &= PGDIR_MASK;
79227 if (start < floor)
79228 return;
79229 @@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79230 pud = pud_offset(pgd, start);
79231 pgd_clear(pgd);
79232 pud_free_tlb(tlb, pud, start);
79233 +#endif
79234 +
79235 }
79236
79237 /*
79238 @@ -1618,12 +1624,6 @@ no_page_table:
79239 return page;
79240 }
79241
79242 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
79243 -{
79244 - return stack_guard_page_start(vma, addr) ||
79245 - stack_guard_page_end(vma, addr+PAGE_SIZE);
79246 -}
79247 -
79248 /**
79249 * __get_user_pages() - pin user pages in memory
79250 * @tsk: task_struct of target task
79251 @@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79252
79253 i = 0;
79254
79255 - do {
79256 + while (nr_pages) {
79257 struct vm_area_struct *vma;
79258
79259 - vma = find_extend_vma(mm, start);
79260 + vma = find_vma(mm, start);
79261 if (!vma && in_gate_area(mm, start)) {
79262 unsigned long pg = start & PAGE_MASK;
79263 pgd_t *pgd;
79264 @@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79265 goto next_page;
79266 }
79267
79268 - if (!vma ||
79269 + if (!vma || start < vma->vm_start ||
79270 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
79271 !(vm_flags & vma->vm_flags))
79272 return i ? : -EFAULT;
79273 @@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79274 int ret;
79275 unsigned int fault_flags = 0;
79276
79277 - /* For mlock, just skip the stack guard page. */
79278 - if (foll_flags & FOLL_MLOCK) {
79279 - if (stack_guard_page(vma, start))
79280 - goto next_page;
79281 - }
79282 if (foll_flags & FOLL_WRITE)
79283 fault_flags |= FAULT_FLAG_WRITE;
79284 if (nonblocking)
79285 @@ -1865,7 +1860,7 @@ next_page:
79286 start += PAGE_SIZE;
79287 nr_pages--;
79288 } while (nr_pages && start < vma->vm_end);
79289 - } while (nr_pages);
79290 + }
79291 return i;
79292 }
79293 EXPORT_SYMBOL(__get_user_pages);
79294 @@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
79295 page_add_file_rmap(page);
79296 set_pte_at(mm, addr, pte, mk_pte(page, prot));
79297
79298 +#ifdef CONFIG_PAX_SEGMEXEC
79299 + pax_mirror_file_pte(vma, addr, page, ptl);
79300 +#endif
79301 +
79302 retval = 0;
79303 pte_unmap_unlock(pte, ptl);
79304 return retval;
79305 @@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
79306 if (!page_count(page))
79307 return -EINVAL;
79308 if (!(vma->vm_flags & VM_MIXEDMAP)) {
79309 +
79310 +#ifdef CONFIG_PAX_SEGMEXEC
79311 + struct vm_area_struct *vma_m;
79312 +#endif
79313 +
79314 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
79315 BUG_ON(vma->vm_flags & VM_PFNMAP);
79316 vma->vm_flags |= VM_MIXEDMAP;
79317 +
79318 +#ifdef CONFIG_PAX_SEGMEXEC
79319 + vma_m = pax_find_mirror_vma(vma);
79320 + if (vma_m)
79321 + vma_m->vm_flags |= VM_MIXEDMAP;
79322 +#endif
79323 +
79324 }
79325 return insert_page(vma, addr, page, vma->vm_page_prot);
79326 }
79327 @@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
79328 unsigned long pfn)
79329 {
79330 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
79331 + BUG_ON(vma->vm_mirror);
79332
79333 if (addr < vma->vm_start || addr >= vma->vm_end)
79334 return -EFAULT;
79335 @@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
79336
79337 BUG_ON(pud_huge(*pud));
79338
79339 - pmd = pmd_alloc(mm, pud, addr);
79340 + pmd = (mm == &init_mm) ?
79341 + pmd_alloc_kernel(mm, pud, addr) :
79342 + pmd_alloc(mm, pud, addr);
79343 if (!pmd)
79344 return -ENOMEM;
79345 do {
79346 @@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
79347 unsigned long next;
79348 int err;
79349
79350 - pud = pud_alloc(mm, pgd, addr);
79351 + pud = (mm == &init_mm) ?
79352 + pud_alloc_kernel(mm, pgd, addr) :
79353 + pud_alloc(mm, pgd, addr);
79354 if (!pud)
79355 return -ENOMEM;
79356 do {
79357 @@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
79358 copy_user_highpage(dst, src, va, vma);
79359 }
79360
79361 +#ifdef CONFIG_PAX_SEGMEXEC
79362 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
79363 +{
79364 + struct mm_struct *mm = vma->vm_mm;
79365 + spinlock_t *ptl;
79366 + pte_t *pte, entry;
79367 +
79368 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
79369 + entry = *pte;
79370 + if (!pte_present(entry)) {
79371 + if (!pte_none(entry)) {
79372 + BUG_ON(pte_file(entry));
79373 + free_swap_and_cache(pte_to_swp_entry(entry));
79374 + pte_clear_not_present_full(mm, address, pte, 0);
79375 + }
79376 + } else {
79377 + struct page *page;
79378 +
79379 + flush_cache_page(vma, address, pte_pfn(entry));
79380 + entry = ptep_clear_flush(vma, address, pte);
79381 + BUG_ON(pte_dirty(entry));
79382 + page = vm_normal_page(vma, address, entry);
79383 + if (page) {
79384 + update_hiwater_rss(mm);
79385 + if (PageAnon(page))
79386 + dec_mm_counter_fast(mm, MM_ANONPAGES);
79387 + else
79388 + dec_mm_counter_fast(mm, MM_FILEPAGES);
79389 + page_remove_rmap(page);
79390 + page_cache_release(page);
79391 + }
79392 + }
79393 + pte_unmap_unlock(pte, ptl);
79394 +}
79395 +
79396 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
79397 + *
79398 + * the ptl of the lower mapped page is held on entry and is not released on exit
79399 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
79400 + */
79401 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
79402 +{
79403 + struct mm_struct *mm = vma->vm_mm;
79404 + unsigned long address_m;
79405 + spinlock_t *ptl_m;
79406 + struct vm_area_struct *vma_m;
79407 + pmd_t *pmd_m;
79408 + pte_t *pte_m, entry_m;
79409 +
79410 + BUG_ON(!page_m || !PageAnon(page_m));
79411 +
79412 + vma_m = pax_find_mirror_vma(vma);
79413 + if (!vma_m)
79414 + return;
79415 +
79416 + BUG_ON(!PageLocked(page_m));
79417 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79418 + address_m = address + SEGMEXEC_TASK_SIZE;
79419 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79420 + pte_m = pte_offset_map(pmd_m, address_m);
79421 + ptl_m = pte_lockptr(mm, pmd_m);
79422 + if (ptl != ptl_m) {
79423 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79424 + if (!pte_none(*pte_m))
79425 + goto out;
79426 + }
79427 +
79428 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
79429 + page_cache_get(page_m);
79430 + page_add_anon_rmap(page_m, vma_m, address_m);
79431 + inc_mm_counter_fast(mm, MM_ANONPAGES);
79432 + set_pte_at(mm, address_m, pte_m, entry_m);
79433 + update_mmu_cache(vma_m, address_m, entry_m);
79434 +out:
79435 + if (ptl != ptl_m)
79436 + spin_unlock(ptl_m);
79437 + pte_unmap(pte_m);
79438 + unlock_page(page_m);
79439 +}
79440 +
79441 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
79442 +{
79443 + struct mm_struct *mm = vma->vm_mm;
79444 + unsigned long address_m;
79445 + spinlock_t *ptl_m;
79446 + struct vm_area_struct *vma_m;
79447 + pmd_t *pmd_m;
79448 + pte_t *pte_m, entry_m;
79449 +
79450 + BUG_ON(!page_m || PageAnon(page_m));
79451 +
79452 + vma_m = pax_find_mirror_vma(vma);
79453 + if (!vma_m)
79454 + return;
79455 +
79456 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79457 + address_m = address + SEGMEXEC_TASK_SIZE;
79458 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79459 + pte_m = pte_offset_map(pmd_m, address_m);
79460 + ptl_m = pte_lockptr(mm, pmd_m);
79461 + if (ptl != ptl_m) {
79462 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79463 + if (!pte_none(*pte_m))
79464 + goto out;
79465 + }
79466 +
79467 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
79468 + page_cache_get(page_m);
79469 + page_add_file_rmap(page_m);
79470 + inc_mm_counter_fast(mm, MM_FILEPAGES);
79471 + set_pte_at(mm, address_m, pte_m, entry_m);
79472 + update_mmu_cache(vma_m, address_m, entry_m);
79473 +out:
79474 + if (ptl != ptl_m)
79475 + spin_unlock(ptl_m);
79476 + pte_unmap(pte_m);
79477 +}
79478 +
79479 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
79480 +{
79481 + struct mm_struct *mm = vma->vm_mm;
79482 + unsigned long address_m;
79483 + spinlock_t *ptl_m;
79484 + struct vm_area_struct *vma_m;
79485 + pmd_t *pmd_m;
79486 + pte_t *pte_m, entry_m;
79487 +
79488 + vma_m = pax_find_mirror_vma(vma);
79489 + if (!vma_m)
79490 + return;
79491 +
79492 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79493 + address_m = address + SEGMEXEC_TASK_SIZE;
79494 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79495 + pte_m = pte_offset_map(pmd_m, address_m);
79496 + ptl_m = pte_lockptr(mm, pmd_m);
79497 + if (ptl != ptl_m) {
79498 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79499 + if (!pte_none(*pte_m))
79500 + goto out;
79501 + }
79502 +
79503 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
79504 + set_pte_at(mm, address_m, pte_m, entry_m);
79505 +out:
79506 + if (ptl != ptl_m)
79507 + spin_unlock(ptl_m);
79508 + pte_unmap(pte_m);
79509 +}
79510 +
79511 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
79512 +{
79513 + struct page *page_m;
79514 + pte_t entry;
79515 +
79516 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
79517 + goto out;
79518 +
79519 + entry = *pte;
79520 + page_m = vm_normal_page(vma, address, entry);
79521 + if (!page_m)
79522 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
79523 + else if (PageAnon(page_m)) {
79524 + if (pax_find_mirror_vma(vma)) {
79525 + pte_unmap_unlock(pte, ptl);
79526 + lock_page(page_m);
79527 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
79528 + if (pte_same(entry, *pte))
79529 + pax_mirror_anon_pte(vma, address, page_m, ptl);
79530 + else
79531 + unlock_page(page_m);
79532 + }
79533 + } else
79534 + pax_mirror_file_pte(vma, address, page_m, ptl);
79535 +
79536 +out:
79537 + pte_unmap_unlock(pte, ptl);
79538 +}
79539 +#endif
79540 +
79541 /*
79542 * This routine handles present pages, when users try to write
79543 * to a shared page. It is done by copying the page to a new address
79544 @@ -2725,6 +2921,12 @@ gotten:
79545 */
79546 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
79547 if (likely(pte_same(*page_table, orig_pte))) {
79548 +
79549 +#ifdef CONFIG_PAX_SEGMEXEC
79550 + if (pax_find_mirror_vma(vma))
79551 + BUG_ON(!trylock_page(new_page));
79552 +#endif
79553 +
79554 if (old_page) {
79555 if (!PageAnon(old_page)) {
79556 dec_mm_counter_fast(mm, MM_FILEPAGES);
79557 @@ -2776,6 +2978,10 @@ gotten:
79558 page_remove_rmap(old_page);
79559 }
79560
79561 +#ifdef CONFIG_PAX_SEGMEXEC
79562 + pax_mirror_anon_pte(vma, address, new_page, ptl);
79563 +#endif
79564 +
79565 /* Free the old page.. */
79566 new_page = old_page;
79567 ret |= VM_FAULT_WRITE;
79568 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
79569 swap_free(entry);
79570 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
79571 try_to_free_swap(page);
79572 +
79573 +#ifdef CONFIG_PAX_SEGMEXEC
79574 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
79575 +#endif
79576 +
79577 unlock_page(page);
79578 if (swapcache) {
79579 /*
79580 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
79581
79582 /* No need to invalidate - it was non-present before */
79583 update_mmu_cache(vma, address, page_table);
79584 +
79585 +#ifdef CONFIG_PAX_SEGMEXEC
79586 + pax_mirror_anon_pte(vma, address, page, ptl);
79587 +#endif
79588 +
79589 unlock:
79590 pte_unmap_unlock(page_table, ptl);
79591 out:
79592 @@ -3093,40 +3309,6 @@ out_release:
79593 }
79594
79595 /*
79596 - * This is like a special single-page "expand_{down|up}wards()",
79597 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
79598 - * doesn't hit another vma.
79599 - */
79600 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
79601 -{
79602 - address &= PAGE_MASK;
79603 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
79604 - struct vm_area_struct *prev = vma->vm_prev;
79605 -
79606 - /*
79607 - * Is there a mapping abutting this one below?
79608 - *
79609 - * That's only ok if it's the same stack mapping
79610 - * that has gotten split..
79611 - */
79612 - if (prev && prev->vm_end == address)
79613 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
79614 -
79615 - expand_downwards(vma, address - PAGE_SIZE);
79616 - }
79617 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
79618 - struct vm_area_struct *next = vma->vm_next;
79619 -
79620 - /* As VM_GROWSDOWN but s/below/above/ */
79621 - if (next && next->vm_start == address + PAGE_SIZE)
79622 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
79623 -
79624 - expand_upwards(vma, address + PAGE_SIZE);
79625 - }
79626 - return 0;
79627 -}
79628 -
79629 -/*
79630 * We enter with non-exclusive mmap_sem (to exclude vma changes,
79631 * but allow concurrent faults), and pte mapped but not yet locked.
79632 * We return with mmap_sem still held, but pte unmapped and unlocked.
79633 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
79634 unsigned long address, pte_t *page_table, pmd_t *pmd,
79635 unsigned int flags)
79636 {
79637 - struct page *page;
79638 + struct page *page = NULL;
79639 spinlock_t *ptl;
79640 pte_t entry;
79641
79642 - pte_unmap(page_table);
79643 -
79644 - /* Check if we need to add a guard page to the stack */
79645 - if (check_stack_guard_page(vma, address) < 0)
79646 - return VM_FAULT_SIGBUS;
79647 -
79648 - /* Use the zero-page for reads */
79649 if (!(flags & FAULT_FLAG_WRITE)) {
79650 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
79651 vma->vm_page_prot));
79652 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
79653 + ptl = pte_lockptr(mm, pmd);
79654 + spin_lock(ptl);
79655 if (!pte_none(*page_table))
79656 goto unlock;
79657 goto setpte;
79658 }
79659
79660 /* Allocate our own private page. */
79661 + pte_unmap(page_table);
79662 +
79663 if (unlikely(anon_vma_prepare(vma)))
79664 goto oom;
79665 page = alloc_zeroed_user_highpage_movable(vma, address);
79666 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
79667 if (!pte_none(*page_table))
79668 goto release;
79669
79670 +#ifdef CONFIG_PAX_SEGMEXEC
79671 + if (pax_find_mirror_vma(vma))
79672 + BUG_ON(!trylock_page(page));
79673 +#endif
79674 +
79675 inc_mm_counter_fast(mm, MM_ANONPAGES);
79676 page_add_new_anon_rmap(page, vma, address);
79677 setpte:
79678 @@ -3181,6 +3364,12 @@ setpte:
79679
79680 /* No need to invalidate - it was non-present before */
79681 update_mmu_cache(vma, address, page_table);
79682 +
79683 +#ifdef CONFIG_PAX_SEGMEXEC
79684 + if (page)
79685 + pax_mirror_anon_pte(vma, address, page, ptl);
79686 +#endif
79687 +
79688 unlock:
79689 pte_unmap_unlock(page_table, ptl);
79690 return 0;
79691 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79692 */
79693 /* Only go through if we didn't race with anybody else... */
79694 if (likely(pte_same(*page_table, orig_pte))) {
79695 +
79696 +#ifdef CONFIG_PAX_SEGMEXEC
79697 + if (anon && pax_find_mirror_vma(vma))
79698 + BUG_ON(!trylock_page(page));
79699 +#endif
79700 +
79701 flush_icache_page(vma, page);
79702 entry = mk_pte(page, vma->vm_page_prot);
79703 if (flags & FAULT_FLAG_WRITE)
79704 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79705
79706 /* no need to invalidate: a not-present page won't be cached */
79707 update_mmu_cache(vma, address, page_table);
79708 +
79709 +#ifdef CONFIG_PAX_SEGMEXEC
79710 + if (anon)
79711 + pax_mirror_anon_pte(vma, address, page, ptl);
79712 + else
79713 + pax_mirror_file_pte(vma, address, page, ptl);
79714 +#endif
79715 +
79716 } else {
79717 if (cow_page)
79718 mem_cgroup_uncharge_page(cow_page);
79719 @@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
79720 if (flags & FAULT_FLAG_WRITE)
79721 flush_tlb_fix_spurious_fault(vma, address);
79722 }
79723 +
79724 +#ifdef CONFIG_PAX_SEGMEXEC
79725 + pax_mirror_pte(vma, address, pte, pmd, ptl);
79726 + return 0;
79727 +#endif
79728 +
79729 unlock:
79730 pte_unmap_unlock(pte, ptl);
79731 return 0;
79732 @@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79733 pmd_t *pmd;
79734 pte_t *pte;
79735
79736 +#ifdef CONFIG_PAX_SEGMEXEC
79737 + struct vm_area_struct *vma_m;
79738 +#endif
79739 +
79740 __set_current_state(TASK_RUNNING);
79741
79742 count_vm_event(PGFAULT);
79743 @@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79744 if (unlikely(is_vm_hugetlb_page(vma)))
79745 return hugetlb_fault(mm, vma, address, flags);
79746
79747 +#ifdef CONFIG_PAX_SEGMEXEC
79748 + vma_m = pax_find_mirror_vma(vma);
79749 + if (vma_m) {
79750 + unsigned long address_m;
79751 + pgd_t *pgd_m;
79752 + pud_t *pud_m;
79753 + pmd_t *pmd_m;
79754 +
79755 + if (vma->vm_start > vma_m->vm_start) {
79756 + address_m = address;
79757 + address -= SEGMEXEC_TASK_SIZE;
79758 + vma = vma_m;
79759 + } else
79760 + address_m = address + SEGMEXEC_TASK_SIZE;
79761 +
79762 + pgd_m = pgd_offset(mm, address_m);
79763 + pud_m = pud_alloc(mm, pgd_m, address_m);
79764 + if (!pud_m)
79765 + return VM_FAULT_OOM;
79766 + pmd_m = pmd_alloc(mm, pud_m, address_m);
79767 + if (!pmd_m)
79768 + return VM_FAULT_OOM;
79769 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
79770 + return VM_FAULT_OOM;
79771 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
79772 + }
79773 +#endif
79774 +
79775 retry:
79776 pgd = pgd_offset(mm, address);
79777 pud = pud_alloc(mm, pgd, address);
79778 @@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79779 spin_unlock(&mm->page_table_lock);
79780 return 0;
79781 }
79782 +
79783 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79784 +{
79785 + pud_t *new = pud_alloc_one(mm, address);
79786 + if (!new)
79787 + return -ENOMEM;
79788 +
79789 + smp_wmb(); /* See comment in __pte_alloc */
79790 +
79791 + spin_lock(&mm->page_table_lock);
79792 + if (pgd_present(*pgd)) /* Another has populated it */
79793 + pud_free(mm, new);
79794 + else
79795 + pgd_populate_kernel(mm, pgd, new);
79796 + spin_unlock(&mm->page_table_lock);
79797 + return 0;
79798 +}
79799 #endif /* __PAGETABLE_PUD_FOLDED */
79800
79801 #ifndef __PAGETABLE_PMD_FOLDED
79802 @@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
79803 spin_unlock(&mm->page_table_lock);
79804 return 0;
79805 }
79806 +
79807 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
79808 +{
79809 + pmd_t *new = pmd_alloc_one(mm, address);
79810 + if (!new)
79811 + return -ENOMEM;
79812 +
79813 + smp_wmb(); /* See comment in __pte_alloc */
79814 +
79815 + spin_lock(&mm->page_table_lock);
79816 +#ifndef __ARCH_HAS_4LEVEL_HACK
79817 + if (pud_present(*pud)) /* Another has populated it */
79818 + pmd_free(mm, new);
79819 + else
79820 + pud_populate_kernel(mm, pud, new);
79821 +#else
79822 + if (pgd_present(*pud)) /* Another has populated it */
79823 + pmd_free(mm, new);
79824 + else
79825 + pgd_populate_kernel(mm, pud, new);
79826 +#endif /* __ARCH_HAS_4LEVEL_HACK */
79827 + spin_unlock(&mm->page_table_lock);
79828 + return 0;
79829 +}
79830 #endif /* __PAGETABLE_PMD_FOLDED */
79831
79832 int make_pages_present(unsigned long addr, unsigned long end)
79833 @@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
79834 gate_vma.vm_start = FIXADDR_USER_START;
79835 gate_vma.vm_end = FIXADDR_USER_END;
79836 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
79837 - gate_vma.vm_page_prot = __P101;
79838 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
79839
79840 return 0;
79841 }
79842 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
79843 index e2df1c1..1e31d57 100644
79844 --- a/mm/mempolicy.c
79845 +++ b/mm/mempolicy.c
79846 @@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
79847 unsigned long vmstart;
79848 unsigned long vmend;
79849
79850 +#ifdef CONFIG_PAX_SEGMEXEC
79851 + struct vm_area_struct *vma_m;
79852 +#endif
79853 +
79854 vma = find_vma(mm, start);
79855 if (!vma || vma->vm_start > start)
79856 return -EFAULT;
79857 @@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
79858 if (err)
79859 goto out;
79860 }
79861 +
79862 err = vma_replace_policy(vma, new_pol);
79863 if (err)
79864 goto out;
79865 +
79866 +#ifdef CONFIG_PAX_SEGMEXEC
79867 + vma_m = pax_find_mirror_vma(vma);
79868 + if (vma_m) {
79869 + err = vma_replace_policy(vma_m, new_pol);
79870 + if (err)
79871 + goto out;
79872 + }
79873 +#endif
79874 +
79875 }
79876
79877 out:
79878 @@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
79879
79880 if (end < start)
79881 return -EINVAL;
79882 +
79883 +#ifdef CONFIG_PAX_SEGMEXEC
79884 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
79885 + if (end > SEGMEXEC_TASK_SIZE)
79886 + return -EINVAL;
79887 + } else
79888 +#endif
79889 +
79890 + if (end > TASK_SIZE)
79891 + return -EINVAL;
79892 +
79893 if (end == start)
79894 return 0;
79895
79896 @@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
79897 */
79898 tcred = __task_cred(task);
79899 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
79900 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
79901 - !capable(CAP_SYS_NICE)) {
79902 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
79903 rcu_read_unlock();
79904 err = -EPERM;
79905 goto out_put;
79906 @@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
79907 goto out;
79908 }
79909
79910 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
79911 + if (mm != current->mm &&
79912 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
79913 + mmput(mm);
79914 + err = -EPERM;
79915 + goto out;
79916 + }
79917 +#endif
79918 +
79919 err = do_migrate_pages(mm, old, new,
79920 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
79921
79922 diff --git a/mm/migrate.c b/mm/migrate.c
79923 index 2fd8b4a..d70358f 100644
79924 --- a/mm/migrate.c
79925 +++ b/mm/migrate.c
79926 @@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
79927 */
79928 tcred = __task_cred(task);
79929 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
79930 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
79931 - !capable(CAP_SYS_NICE)) {
79932 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
79933 rcu_read_unlock();
79934 err = -EPERM;
79935 goto out;
79936 diff --git a/mm/mlock.c b/mm/mlock.c
79937 index c9bd528..da8d069 100644
79938 --- a/mm/mlock.c
79939 +++ b/mm/mlock.c
79940 @@ -13,6 +13,7 @@
79941 #include <linux/pagemap.h>
79942 #include <linux/mempolicy.h>
79943 #include <linux/syscalls.h>
79944 +#include <linux/security.h>
79945 #include <linux/sched.h>
79946 #include <linux/export.h>
79947 #include <linux/rmap.h>
79948 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
79949 {
79950 unsigned long nstart, end, tmp;
79951 struct vm_area_struct * vma, * prev;
79952 - int error;
79953 + int error = 0;
79954
79955 VM_BUG_ON(start & ~PAGE_MASK);
79956 VM_BUG_ON(len != PAGE_ALIGN(len));
79957 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
79958 return -EINVAL;
79959 if (end == start)
79960 return 0;
79961 + if (end > TASK_SIZE)
79962 + return -EINVAL;
79963 +
79964 vma = find_vma(current->mm, start);
79965 if (!vma || vma->vm_start > start)
79966 return -ENOMEM;
79967 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
79968 for (nstart = start ; ; ) {
79969 vm_flags_t newflags;
79970
79971 +#ifdef CONFIG_PAX_SEGMEXEC
79972 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
79973 + break;
79974 +#endif
79975 +
79976 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
79977
79978 newflags = vma->vm_flags | VM_LOCKED;
79979 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
79980 lock_limit >>= PAGE_SHIFT;
79981
79982 /* check against resource limits */
79983 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
79984 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
79985 error = do_mlock(start, len, 1);
79986 up_write(&current->mm->mmap_sem);
79987 @@ -528,6 +538,12 @@ static int do_mlockall(int flags)
79988 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
79989 vm_flags_t newflags;
79990
79991 +#ifdef CONFIG_PAX_SEGMEXEC
79992 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
79993 + break;
79994 +#endif
79995 +
79996 + BUG_ON(vma->vm_end > TASK_SIZE);
79997 newflags = vma->vm_flags | VM_LOCKED;
79998 if (!(flags & MCL_CURRENT))
79999 newflags &= ~VM_LOCKED;
80000 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
80001 lock_limit >>= PAGE_SHIFT;
80002
80003 ret = -ENOMEM;
80004 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
80005 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
80006 capable(CAP_IPC_LOCK))
80007 ret = do_mlockall(flags);
80008 diff --git a/mm/mmap.c b/mm/mmap.c
80009 index 8832b87..7d36e4f 100644
80010 --- a/mm/mmap.c
80011 +++ b/mm/mmap.c
80012 @@ -32,6 +32,7 @@
80013 #include <linux/khugepaged.h>
80014 #include <linux/uprobes.h>
80015 #include <linux/rbtree_augmented.h>
80016 +#include <linux/random.h>
80017
80018 #include <asm/uaccess.h>
80019 #include <asm/cacheflush.h>
80020 @@ -48,6 +49,16 @@
80021 #define arch_rebalance_pgtables(addr, len) (addr)
80022 #endif
80023
80024 +static inline void verify_mm_writelocked(struct mm_struct *mm)
80025 +{
80026 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
80027 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
80028 + up_read(&mm->mmap_sem);
80029 + BUG();
80030 + }
80031 +#endif
80032 +}
80033 +
80034 static void unmap_region(struct mm_struct *mm,
80035 struct vm_area_struct *vma, struct vm_area_struct *prev,
80036 unsigned long start, unsigned long end);
80037 @@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
80038 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
80039 *
80040 */
80041 -pgprot_t protection_map[16] = {
80042 +pgprot_t protection_map[16] __read_only = {
80043 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
80044 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
80045 };
80046
80047 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
80048 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80049 {
80050 - return __pgprot(pgprot_val(protection_map[vm_flags &
80051 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
80052 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
80053 pgprot_val(arch_vm_get_page_prot(vm_flags)));
80054 +
80055 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80056 + if (!(__supported_pte_mask & _PAGE_NX) &&
80057 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
80058 + (vm_flags & (VM_READ | VM_WRITE)))
80059 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
80060 +#endif
80061 +
80062 + return prot;
80063 }
80064 EXPORT_SYMBOL(vm_get_page_prot);
80065
80066 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
80067 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
80068 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
80069 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
80070 /*
80071 * Make sure vm_committed_as in one cacheline and not cacheline shared with
80072 * other variables. It can be updated by several CPUs frequently.
80073 @@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
80074 struct vm_area_struct *next = vma->vm_next;
80075
80076 might_sleep();
80077 + BUG_ON(vma->vm_mirror);
80078 if (vma->vm_ops && vma->vm_ops->close)
80079 vma->vm_ops->close(vma);
80080 if (vma->vm_file)
80081 @@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
80082 * not page aligned -Ram Gupta
80083 */
80084 rlim = rlimit(RLIMIT_DATA);
80085 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
80086 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
80087 (mm->end_data - mm->start_data) > rlim)
80088 goto out;
80089 @@ -888,6 +911,12 @@ static int
80090 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
80091 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
80092 {
80093 +
80094 +#ifdef CONFIG_PAX_SEGMEXEC
80095 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
80096 + return 0;
80097 +#endif
80098 +
80099 if (is_mergeable_vma(vma, file, vm_flags) &&
80100 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
80101 if (vma->vm_pgoff == vm_pgoff)
80102 @@ -907,6 +936,12 @@ static int
80103 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
80104 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
80105 {
80106 +
80107 +#ifdef CONFIG_PAX_SEGMEXEC
80108 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
80109 + return 0;
80110 +#endif
80111 +
80112 if (is_mergeable_vma(vma, file, vm_flags) &&
80113 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
80114 pgoff_t vm_pglen;
80115 @@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
80116 struct vm_area_struct *vma_merge(struct mm_struct *mm,
80117 struct vm_area_struct *prev, unsigned long addr,
80118 unsigned long end, unsigned long vm_flags,
80119 - struct anon_vma *anon_vma, struct file *file,
80120 + struct anon_vma *anon_vma, struct file *file,
80121 pgoff_t pgoff, struct mempolicy *policy)
80122 {
80123 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
80124 struct vm_area_struct *area, *next;
80125 int err;
80126
80127 +#ifdef CONFIG_PAX_SEGMEXEC
80128 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
80129 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
80130 +
80131 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
80132 +#endif
80133 +
80134 /*
80135 * We later require that vma->vm_flags == vm_flags,
80136 * so this tests vma->vm_flags & VM_SPECIAL, too.
80137 @@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80138 if (next && next->vm_end == end) /* cases 6, 7, 8 */
80139 next = next->vm_next;
80140
80141 +#ifdef CONFIG_PAX_SEGMEXEC
80142 + if (prev)
80143 + prev_m = pax_find_mirror_vma(prev);
80144 + if (area)
80145 + area_m = pax_find_mirror_vma(area);
80146 + if (next)
80147 + next_m = pax_find_mirror_vma(next);
80148 +#endif
80149 +
80150 /*
80151 * Can it merge with the predecessor?
80152 */
80153 @@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80154 /* cases 1, 6 */
80155 err = vma_adjust(prev, prev->vm_start,
80156 next->vm_end, prev->vm_pgoff, NULL);
80157 - } else /* cases 2, 5, 7 */
80158 +
80159 +#ifdef CONFIG_PAX_SEGMEXEC
80160 + if (!err && prev_m)
80161 + err = vma_adjust(prev_m, prev_m->vm_start,
80162 + next_m->vm_end, prev_m->vm_pgoff, NULL);
80163 +#endif
80164 +
80165 + } else { /* cases 2, 5, 7 */
80166 err = vma_adjust(prev, prev->vm_start,
80167 end, prev->vm_pgoff, NULL);
80168 +
80169 +#ifdef CONFIG_PAX_SEGMEXEC
80170 + if (!err && prev_m)
80171 + err = vma_adjust(prev_m, prev_m->vm_start,
80172 + end_m, prev_m->vm_pgoff, NULL);
80173 +#endif
80174 +
80175 + }
80176 if (err)
80177 return NULL;
80178 khugepaged_enter_vma_merge(prev);
80179 @@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80180 mpol_equal(policy, vma_policy(next)) &&
80181 can_vma_merge_before(next, vm_flags,
80182 anon_vma, file, pgoff+pglen)) {
80183 - if (prev && addr < prev->vm_end) /* case 4 */
80184 + if (prev && addr < prev->vm_end) { /* case 4 */
80185 err = vma_adjust(prev, prev->vm_start,
80186 addr, prev->vm_pgoff, NULL);
80187 - else /* cases 3, 8 */
80188 +
80189 +#ifdef CONFIG_PAX_SEGMEXEC
80190 + if (!err && prev_m)
80191 + err = vma_adjust(prev_m, prev_m->vm_start,
80192 + addr_m, prev_m->vm_pgoff, NULL);
80193 +#endif
80194 +
80195 + } else { /* cases 3, 8 */
80196 err = vma_adjust(area, addr, next->vm_end,
80197 next->vm_pgoff - pglen, NULL);
80198 +
80199 +#ifdef CONFIG_PAX_SEGMEXEC
80200 + if (!err && area_m)
80201 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
80202 + next_m->vm_pgoff - pglen, NULL);
80203 +#endif
80204 +
80205 + }
80206 if (err)
80207 return NULL;
80208 khugepaged_enter_vma_merge(area);
80209 @@ -1120,16 +1201,13 @@ none:
80210 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
80211 struct file *file, long pages)
80212 {
80213 - const unsigned long stack_flags
80214 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
80215 -
80216 mm->total_vm += pages;
80217
80218 if (file) {
80219 mm->shared_vm += pages;
80220 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
80221 mm->exec_vm += pages;
80222 - } else if (flags & stack_flags)
80223 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
80224 mm->stack_vm += pages;
80225 }
80226 #endif /* CONFIG_PROC_FS */
80227 @@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80228 * (the exception is when the underlying filesystem is noexec
80229 * mounted, in which case we dont add PROT_EXEC.)
80230 */
80231 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
80232 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
80233 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
80234 prot |= PROT_EXEC;
80235
80236 @@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80237 /* Obtain the address to map to. we verify (or select) it and ensure
80238 * that it represents a valid section of the address space.
80239 */
80240 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
80241 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
80242 if (addr & ~PAGE_MASK)
80243 return addr;
80244
80245 @@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80246 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
80247 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
80248
80249 +#ifdef CONFIG_PAX_MPROTECT
80250 + if (mm->pax_flags & MF_PAX_MPROTECT) {
80251 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
80252 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
80253 + gr_log_rwxmmap(file);
80254 +
80255 +#ifdef CONFIG_PAX_EMUPLT
80256 + vm_flags &= ~VM_EXEC;
80257 +#else
80258 + return -EPERM;
80259 +#endif
80260 +
80261 + }
80262 +
80263 + if (!(vm_flags & VM_EXEC))
80264 + vm_flags &= ~VM_MAYEXEC;
80265 +#else
80266 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
80267 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
80268 +#endif
80269 + else
80270 + vm_flags &= ~VM_MAYWRITE;
80271 + }
80272 +#endif
80273 +
80274 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80275 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
80276 + vm_flags &= ~VM_PAGEEXEC;
80277 +#endif
80278 +
80279 if (flags & MAP_LOCKED)
80280 if (!can_do_mlock())
80281 return -EPERM;
80282 @@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80283 locked += mm->locked_vm;
80284 lock_limit = rlimit(RLIMIT_MEMLOCK);
80285 lock_limit >>= PAGE_SHIFT;
80286 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
80287 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
80288 return -EAGAIN;
80289 }
80290 @@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80291 }
80292 }
80293
80294 + if (!gr_acl_handle_mmap(file, prot))
80295 + return -EACCES;
80296 +
80297 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
80298 }
80299
80300 @@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
80301 vm_flags_t vm_flags = vma->vm_flags;
80302
80303 /* If it was private or non-writable, the write bit is already clear */
80304 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
80305 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
80306 return 0;
80307
80308 /* The backer wishes to know when pages are first written to? */
80309 @@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
80310 unsigned long charged = 0;
80311 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
80312
80313 +#ifdef CONFIG_PAX_SEGMEXEC
80314 + struct vm_area_struct *vma_m = NULL;
80315 +#endif
80316 +
80317 + /*
80318 + * mm->mmap_sem is required to protect against another thread
80319 + * changing the mappings in case we sleep.
80320 + */
80321 + verify_mm_writelocked(mm);
80322 +
80323 /* Clear old maps */
80324 error = -ENOMEM;
80325 -munmap_back:
80326 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
80327 if (do_munmap(mm, addr, len))
80328 return -ENOMEM;
80329 - goto munmap_back;
80330 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
80331 }
80332
80333 /* Check against address space limit. */
80334 @@ -1460,6 +1581,16 @@ munmap_back:
80335 goto unacct_error;
80336 }
80337
80338 +#ifdef CONFIG_PAX_SEGMEXEC
80339 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
80340 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
80341 + if (!vma_m) {
80342 + error = -ENOMEM;
80343 + goto free_vma;
80344 + }
80345 + }
80346 +#endif
80347 +
80348 vma->vm_mm = mm;
80349 vma->vm_start = addr;
80350 vma->vm_end = addr + len;
80351 @@ -1484,6 +1615,13 @@ munmap_back:
80352 if (error)
80353 goto unmap_and_free_vma;
80354
80355 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80356 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
80357 + vma->vm_flags |= VM_PAGEEXEC;
80358 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
80359 + }
80360 +#endif
80361 +
80362 /* Can addr have changed??
80363 *
80364 * Answer: Yes, several device drivers can do it in their
80365 @@ -1522,6 +1660,11 @@ munmap_back:
80366 vma_link(mm, vma, prev, rb_link, rb_parent);
80367 file = vma->vm_file;
80368
80369 +#ifdef CONFIG_PAX_SEGMEXEC
80370 + if (vma_m)
80371 + BUG_ON(pax_mirror_vma(vma_m, vma));
80372 +#endif
80373 +
80374 /* Once vma denies write, undo our temporary denial count */
80375 if (correct_wcount)
80376 atomic_inc(&inode->i_writecount);
80377 @@ -1529,6 +1672,7 @@ out:
80378 perf_event_mmap(vma);
80379
80380 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
80381 + track_exec_limit(mm, addr, addr + len, vm_flags);
80382 if (vm_flags & VM_LOCKED) {
80383 if (!mlock_vma_pages_range(vma, addr, addr + len))
80384 mm->locked_vm += (len >> PAGE_SHIFT);
80385 @@ -1550,6 +1694,12 @@ unmap_and_free_vma:
80386 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
80387 charged = 0;
80388 free_vma:
80389 +
80390 +#ifdef CONFIG_PAX_SEGMEXEC
80391 + if (vma_m)
80392 + kmem_cache_free(vm_area_cachep, vma_m);
80393 +#endif
80394 +
80395 kmem_cache_free(vm_area_cachep, vma);
80396 unacct_error:
80397 if (charged)
80398 @@ -1557,6 +1707,62 @@ unacct_error:
80399 return error;
80400 }
80401
80402 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
80403 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
80404 +{
80405 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
80406 + return (random32() & 0xFF) << PAGE_SHIFT;
80407 +
80408 + return 0;
80409 +}
80410 +#endif
80411 +
80412 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
80413 +{
80414 + if (!vma) {
80415 +#ifdef CONFIG_STACK_GROWSUP
80416 + if (addr > sysctl_heap_stack_gap)
80417 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
80418 + else
80419 + vma = find_vma(current->mm, 0);
80420 + if (vma && (vma->vm_flags & VM_GROWSUP))
80421 + return false;
80422 +#endif
80423 + return true;
80424 + }
80425 +
80426 + if (addr + len > vma->vm_start)
80427 + return false;
80428 +
80429 + if (vma->vm_flags & VM_GROWSDOWN)
80430 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
80431 +#ifdef CONFIG_STACK_GROWSUP
80432 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
80433 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
80434 +#endif
80435 + else if (offset)
80436 + return offset <= vma->vm_start - addr - len;
80437 +
80438 + return true;
80439 +}
80440 +
80441 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
80442 +{
80443 + if (vma->vm_start < len)
80444 + return -ENOMEM;
80445 +
80446 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
80447 + if (offset <= vma->vm_start - len)
80448 + return vma->vm_start - len - offset;
80449 + else
80450 + return -ENOMEM;
80451 + }
80452 +
80453 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
80454 + return vma->vm_start - len - sysctl_heap_stack_gap;
80455 + return -ENOMEM;
80456 +}
80457 +
80458 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
80459 {
80460 /*
80461 @@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80462 struct mm_struct *mm = current->mm;
80463 struct vm_area_struct *vma;
80464 struct vm_unmapped_area_info info;
80465 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
80466
80467 if (len > TASK_SIZE)
80468 return -ENOMEM;
80469 @@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80470 if (flags & MAP_FIXED)
80471 return addr;
80472
80473 +#ifdef CONFIG_PAX_RANDMMAP
80474 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
80475 +#endif
80476 +
80477 if (addr) {
80478 addr = PAGE_ALIGN(addr);
80479 vma = find_vma(mm, addr);
80480 - if (TASK_SIZE - len >= addr &&
80481 - (!vma || addr + len <= vma->vm_start))
80482 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
80483 return addr;
80484 }
80485
80486 info.flags = 0;
80487 info.length = len;
80488 info.low_limit = TASK_UNMAPPED_BASE;
80489 +
80490 +#ifdef CONFIG_PAX_RANDMMAP
80491 + if (mm->pax_flags & MF_PAX_RANDMMAP)
80492 + info.low_limit += mm->delta_mmap;
80493 +#endif
80494 +
80495 info.high_limit = TASK_SIZE;
80496 info.align_mask = 0;
80497 return vm_unmapped_area(&info);
80498 @@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80499
80500 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
80501 {
80502 +
80503 +#ifdef CONFIG_PAX_SEGMEXEC
80504 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
80505 + return;
80506 +#endif
80507 +
80508 /*
80509 * Is this a new hole at the lowest possible address?
80510 */
80511 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
80512 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
80513 mm->free_area_cache = addr;
80514 }
80515
80516 @@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80517 struct mm_struct *mm = current->mm;
80518 unsigned long addr = addr0;
80519 struct vm_unmapped_area_info info;
80520 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
80521
80522 /* requested length too big for entire address space */
80523 if (len > TASK_SIZE)
80524 @@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80525 if (flags & MAP_FIXED)
80526 return addr;
80527
80528 +#ifdef CONFIG_PAX_RANDMMAP
80529 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
80530 +#endif
80531 +
80532 /* requesting a specific address */
80533 if (addr) {
80534 addr = PAGE_ALIGN(addr);
80535 vma = find_vma(mm, addr);
80536 - if (TASK_SIZE - len >= addr &&
80537 - (!vma || addr + len <= vma->vm_start))
80538 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
80539 return addr;
80540 }
80541
80542 @@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80543 VM_BUG_ON(addr != -ENOMEM);
80544 info.flags = 0;
80545 info.low_limit = TASK_UNMAPPED_BASE;
80546 +
80547 +#ifdef CONFIG_PAX_RANDMMAP
80548 + if (mm->pax_flags & MF_PAX_RANDMMAP)
80549 + info.low_limit += mm->delta_mmap;
80550 +#endif
80551 +
80552 info.high_limit = TASK_SIZE;
80553 addr = vm_unmapped_area(&info);
80554 }
80555 @@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80556
80557 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
80558 {
80559 +
80560 +#ifdef CONFIG_PAX_SEGMEXEC
80561 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
80562 + return;
80563 +#endif
80564 +
80565 /*
80566 * Is this a new hole at the highest possible address?
80567 */
80568 @@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
80569 mm->free_area_cache = addr;
80570
80571 /* dont allow allocations above current base */
80572 - if (mm->free_area_cache > mm->mmap_base)
80573 + if (mm->free_area_cache > mm->mmap_base) {
80574 mm->free_area_cache = mm->mmap_base;
80575 + mm->cached_hole_size = ~0UL;
80576 + }
80577 }
80578
80579 unsigned long
80580 @@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
80581 return vma;
80582 }
80583
80584 +#ifdef CONFIG_PAX_SEGMEXEC
80585 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
80586 +{
80587 + struct vm_area_struct *vma_m;
80588 +
80589 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
80590 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
80591 + BUG_ON(vma->vm_mirror);
80592 + return NULL;
80593 + }
80594 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
80595 + vma_m = vma->vm_mirror;
80596 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
80597 + BUG_ON(vma->vm_file != vma_m->vm_file);
80598 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
80599 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
80600 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
80601 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
80602 + return vma_m;
80603 +}
80604 +#endif
80605 +
80606 /*
80607 * Verify that the stack growth is acceptable and
80608 * update accounting. This is shared with both the
80609 @@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80610 return -ENOMEM;
80611
80612 /* Stack limit test */
80613 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
80614 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
80615 return -ENOMEM;
80616
80617 @@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80618 locked = mm->locked_vm + grow;
80619 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
80620 limit >>= PAGE_SHIFT;
80621 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
80622 if (locked > limit && !capable(CAP_IPC_LOCK))
80623 return -ENOMEM;
80624 }
80625 @@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80626 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
80627 * vma is the last one with address > vma->vm_end. Have to extend vma.
80628 */
80629 +#ifndef CONFIG_IA64
80630 +static
80631 +#endif
80632 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
80633 {
80634 int error;
80635 + bool locknext;
80636
80637 if (!(vma->vm_flags & VM_GROWSUP))
80638 return -EFAULT;
80639
80640 + /* Also guard against wrapping around to address 0. */
80641 + if (address < PAGE_ALIGN(address+1))
80642 + address = PAGE_ALIGN(address+1);
80643 + else
80644 + return -ENOMEM;
80645 +
80646 /*
80647 * We must make sure the anon_vma is allocated
80648 * so that the anon_vma locking is not a noop.
80649 */
80650 if (unlikely(anon_vma_prepare(vma)))
80651 return -ENOMEM;
80652 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
80653 + if (locknext && anon_vma_prepare(vma->vm_next))
80654 + return -ENOMEM;
80655 vma_lock_anon_vma(vma);
80656 + if (locknext)
80657 + vma_lock_anon_vma(vma->vm_next);
80658
80659 /*
80660 * vma->vm_start/vm_end cannot change under us because the caller
80661 * is required to hold the mmap_sem in read mode. We need the
80662 - * anon_vma lock to serialize against concurrent expand_stacks.
80663 - * Also guard against wrapping around to address 0.
80664 + * anon_vma locks to serialize against concurrent expand_stacks
80665 + * and expand_upwards.
80666 */
80667 - if (address < PAGE_ALIGN(address+4))
80668 - address = PAGE_ALIGN(address+4);
80669 - else {
80670 - vma_unlock_anon_vma(vma);
80671 - return -ENOMEM;
80672 - }
80673 error = 0;
80674
80675 /* Somebody else might have raced and expanded it already */
80676 - if (address > vma->vm_end) {
80677 + 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)
80678 + error = -ENOMEM;
80679 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
80680 unsigned long size, grow;
80681
80682 size = address - vma->vm_start;
80683 @@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
80684 }
80685 }
80686 }
80687 + if (locknext)
80688 + vma_unlock_anon_vma(vma->vm_next);
80689 vma_unlock_anon_vma(vma);
80690 khugepaged_enter_vma_merge(vma);
80691 validate_mm(vma->vm_mm);
80692 @@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
80693 unsigned long address)
80694 {
80695 int error;
80696 + bool lockprev = false;
80697 + struct vm_area_struct *prev;
80698
80699 /*
80700 * We must make sure the anon_vma is allocated
80701 @@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
80702 if (error)
80703 return error;
80704
80705 + prev = vma->vm_prev;
80706 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
80707 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
80708 +#endif
80709 + if (lockprev && anon_vma_prepare(prev))
80710 + return -ENOMEM;
80711 + if (lockprev)
80712 + vma_lock_anon_vma(prev);
80713 +
80714 vma_lock_anon_vma(vma);
80715
80716 /*
80717 @@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
80718 */
80719
80720 /* Somebody else might have raced and expanded it already */
80721 - if (address < vma->vm_start) {
80722 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
80723 + error = -ENOMEM;
80724 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
80725 unsigned long size, grow;
80726
80727 +#ifdef CONFIG_PAX_SEGMEXEC
80728 + struct vm_area_struct *vma_m;
80729 +
80730 + vma_m = pax_find_mirror_vma(vma);
80731 +#endif
80732 +
80733 size = vma->vm_end - address;
80734 grow = (vma->vm_start - address) >> PAGE_SHIFT;
80735
80736 @@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
80737 vma->vm_pgoff -= grow;
80738 anon_vma_interval_tree_post_update_vma(vma);
80739 vma_gap_update(vma);
80740 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
80741 +
80742 +#ifdef CONFIG_PAX_SEGMEXEC
80743 + if (vma_m) {
80744 + anon_vma_interval_tree_pre_update_vma(vma_m);
80745 + vma_m->vm_start -= grow << PAGE_SHIFT;
80746 + vma_m->vm_pgoff -= grow;
80747 + anon_vma_interval_tree_post_update_vma(vma_m);
80748 + vma_gap_update(vma_m);
80749 + }
80750 +#endif
80751 +
80752 spin_unlock(&vma->vm_mm->page_table_lock);
80753
80754 perf_event_mmap(vma);
80755 @@ -2263,6 +2571,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
80756 do {
80757 long nrpages = vma_pages(vma);
80758
80759 +#ifdef CONFIG_PAX_SEGMEXEC
80760 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
80761 + vma = remove_vma(vma);
80762 + continue;
80763 + }
80764 +#endif
80765 +
80766 if (vma->vm_flags & VM_ACCOUNT)
80767 nr_accounted += nrpages;
80768 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
80769 @@ -2308,6 +2623,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
80770 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
80771 vma->vm_prev = NULL;
80772 do {
80773 +
80774 +#ifdef CONFIG_PAX_SEGMEXEC
80775 + if (vma->vm_mirror) {
80776 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
80777 + vma->vm_mirror->vm_mirror = NULL;
80778 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
80779 + vma->vm_mirror = NULL;
80780 + }
80781 +#endif
80782 +
80783 vma_rb_erase(vma, &mm->mm_rb);
80784 mm->map_count--;
80785 tail_vma = vma;
80786 @@ -2339,14 +2664,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
80787 struct vm_area_struct *new;
80788 int err = -ENOMEM;
80789
80790 +#ifdef CONFIG_PAX_SEGMEXEC
80791 + struct vm_area_struct *vma_m, *new_m = NULL;
80792 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
80793 +#endif
80794 +
80795 if (is_vm_hugetlb_page(vma) && (addr &
80796 ~(huge_page_mask(hstate_vma(vma)))))
80797 return -EINVAL;
80798
80799 +#ifdef CONFIG_PAX_SEGMEXEC
80800 + vma_m = pax_find_mirror_vma(vma);
80801 +#endif
80802 +
80803 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80804 if (!new)
80805 goto out_err;
80806
80807 +#ifdef CONFIG_PAX_SEGMEXEC
80808 + if (vma_m) {
80809 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80810 + if (!new_m) {
80811 + kmem_cache_free(vm_area_cachep, new);
80812 + goto out_err;
80813 + }
80814 + }
80815 +#endif
80816 +
80817 /* most fields are the same, copy all, and then fixup */
80818 *new = *vma;
80819
80820 @@ -2359,6 +2703,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
80821 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
80822 }
80823
80824 +#ifdef CONFIG_PAX_SEGMEXEC
80825 + if (vma_m) {
80826 + *new_m = *vma_m;
80827 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
80828 + new_m->vm_mirror = new;
80829 + new->vm_mirror = new_m;
80830 +
80831 + if (new_below)
80832 + new_m->vm_end = addr_m;
80833 + else {
80834 + new_m->vm_start = addr_m;
80835 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
80836 + }
80837 + }
80838 +#endif
80839 +
80840 pol = mpol_dup(vma_policy(vma));
80841 if (IS_ERR(pol)) {
80842 err = PTR_ERR(pol);
80843 @@ -2381,6 +2741,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
80844 else
80845 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
80846
80847 +#ifdef CONFIG_PAX_SEGMEXEC
80848 + if (!err && vma_m) {
80849 + if (anon_vma_clone(new_m, vma_m))
80850 + goto out_free_mpol;
80851 +
80852 + mpol_get(pol);
80853 + vma_set_policy(new_m, pol);
80854 +
80855 + if (new_m->vm_file)
80856 + get_file(new_m->vm_file);
80857 +
80858 + if (new_m->vm_ops && new_m->vm_ops->open)
80859 + new_m->vm_ops->open(new_m);
80860 +
80861 + if (new_below)
80862 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
80863 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
80864 + else
80865 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
80866 +
80867 + if (err) {
80868 + if (new_m->vm_ops && new_m->vm_ops->close)
80869 + new_m->vm_ops->close(new_m);
80870 + if (new_m->vm_file)
80871 + fput(new_m->vm_file);
80872 + mpol_put(pol);
80873 + }
80874 + }
80875 +#endif
80876 +
80877 /* Success. */
80878 if (!err)
80879 return 0;
80880 @@ -2390,10 +2780,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
80881 new->vm_ops->close(new);
80882 if (new->vm_file)
80883 fput(new->vm_file);
80884 - unlink_anon_vmas(new);
80885 out_free_mpol:
80886 mpol_put(pol);
80887 out_free_vma:
80888 +
80889 +#ifdef CONFIG_PAX_SEGMEXEC
80890 + if (new_m) {
80891 + unlink_anon_vmas(new_m);
80892 + kmem_cache_free(vm_area_cachep, new_m);
80893 + }
80894 +#endif
80895 +
80896 + unlink_anon_vmas(new);
80897 kmem_cache_free(vm_area_cachep, new);
80898 out_err:
80899 return err;
80900 @@ -2406,6 +2804,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
80901 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
80902 unsigned long addr, int new_below)
80903 {
80904 +
80905 +#ifdef CONFIG_PAX_SEGMEXEC
80906 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
80907 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
80908 + if (mm->map_count >= sysctl_max_map_count-1)
80909 + return -ENOMEM;
80910 + } else
80911 +#endif
80912 +
80913 if (mm->map_count >= sysctl_max_map_count)
80914 return -ENOMEM;
80915
80916 @@ -2417,11 +2824,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
80917 * work. This now handles partial unmappings.
80918 * Jeremy Fitzhardinge <jeremy@goop.org>
80919 */
80920 +#ifdef CONFIG_PAX_SEGMEXEC
80921 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
80922 {
80923 + int ret = __do_munmap(mm, start, len);
80924 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
80925 + return ret;
80926 +
80927 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
80928 +}
80929 +
80930 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
80931 +#else
80932 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
80933 +#endif
80934 +{
80935 unsigned long end;
80936 struct vm_area_struct *vma, *prev, *last;
80937
80938 + /*
80939 + * mm->mmap_sem is required to protect against another thread
80940 + * changing the mappings in case we sleep.
80941 + */
80942 + verify_mm_writelocked(mm);
80943 +
80944 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
80945 return -EINVAL;
80946
80947 @@ -2496,6 +2922,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
80948 /* Fix up all other VM information */
80949 remove_vma_list(mm, vma);
80950
80951 + track_exec_limit(mm, start, end, 0UL);
80952 +
80953 return 0;
80954 }
80955
80956 @@ -2504,6 +2932,13 @@ int vm_munmap(unsigned long start, size_t len)
80957 int ret;
80958 struct mm_struct *mm = current->mm;
80959
80960 +
80961 +#ifdef CONFIG_PAX_SEGMEXEC
80962 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
80963 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
80964 + return -EINVAL;
80965 +#endif
80966 +
80967 down_write(&mm->mmap_sem);
80968 ret = do_munmap(mm, start, len);
80969 up_write(&mm->mmap_sem);
80970 @@ -2517,16 +2952,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
80971 return vm_munmap(addr, len);
80972 }
80973
80974 -static inline void verify_mm_writelocked(struct mm_struct *mm)
80975 -{
80976 -#ifdef CONFIG_DEBUG_VM
80977 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
80978 - WARN_ON(1);
80979 - up_read(&mm->mmap_sem);
80980 - }
80981 -#endif
80982 -}
80983 -
80984 /*
80985 * this is really a simplified "do_mmap". it only handles
80986 * anonymous maps. eventually we may be able to do some
80987 @@ -2540,6 +2965,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
80988 struct rb_node ** rb_link, * rb_parent;
80989 pgoff_t pgoff = addr >> PAGE_SHIFT;
80990 int error;
80991 + unsigned long charged;
80992
80993 len = PAGE_ALIGN(len);
80994 if (!len)
80995 @@ -2547,16 +2973,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
80996
80997 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
80998
80999 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
81000 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
81001 + flags &= ~VM_EXEC;
81002 +
81003 +#ifdef CONFIG_PAX_MPROTECT
81004 + if (mm->pax_flags & MF_PAX_MPROTECT)
81005 + flags &= ~VM_MAYEXEC;
81006 +#endif
81007 +
81008 + }
81009 +#endif
81010 +
81011 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
81012 if (error & ~PAGE_MASK)
81013 return error;
81014
81015 + charged = len >> PAGE_SHIFT;
81016 +
81017 /*
81018 * mlock MCL_FUTURE?
81019 */
81020 if (mm->def_flags & VM_LOCKED) {
81021 unsigned long locked, lock_limit;
81022 - locked = len >> PAGE_SHIFT;
81023 + locked = charged;
81024 locked += mm->locked_vm;
81025 lock_limit = rlimit(RLIMIT_MEMLOCK);
81026 lock_limit >>= PAGE_SHIFT;
81027 @@ -2573,21 +3013,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81028 /*
81029 * Clear old maps. this also does some error checking for us
81030 */
81031 - munmap_back:
81032 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
81033 if (do_munmap(mm, addr, len))
81034 return -ENOMEM;
81035 - goto munmap_back;
81036 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
81037 }
81038
81039 /* Check against address space limits *after* clearing old maps... */
81040 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
81041 + if (!may_expand_vm(mm, charged))
81042 return -ENOMEM;
81043
81044 if (mm->map_count > sysctl_max_map_count)
81045 return -ENOMEM;
81046
81047 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
81048 + if (security_vm_enough_memory_mm(mm, charged))
81049 return -ENOMEM;
81050
81051 /* Can we just expand an old private anonymous mapping? */
81052 @@ -2601,7 +3040,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81053 */
81054 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81055 if (!vma) {
81056 - vm_unacct_memory(len >> PAGE_SHIFT);
81057 + vm_unacct_memory(charged);
81058 return -ENOMEM;
81059 }
81060
81061 @@ -2615,11 +3054,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81062 vma_link(mm, vma, prev, rb_link, rb_parent);
81063 out:
81064 perf_event_mmap(vma);
81065 - mm->total_vm += len >> PAGE_SHIFT;
81066 + mm->total_vm += charged;
81067 if (flags & VM_LOCKED) {
81068 if (!mlock_vma_pages_range(vma, addr, addr + len))
81069 - mm->locked_vm += (len >> PAGE_SHIFT);
81070 + mm->locked_vm += charged;
81071 }
81072 + track_exec_limit(mm, addr, addr + len, flags);
81073 return addr;
81074 }
81075
81076 @@ -2677,6 +3117,7 @@ void exit_mmap(struct mm_struct *mm)
81077 while (vma) {
81078 if (vma->vm_flags & VM_ACCOUNT)
81079 nr_accounted += vma_pages(vma);
81080 + vma->vm_mirror = NULL;
81081 vma = remove_vma(vma);
81082 }
81083 vm_unacct_memory(nr_accounted);
81084 @@ -2693,6 +3134,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
81085 struct vm_area_struct *prev;
81086 struct rb_node **rb_link, *rb_parent;
81087
81088 +#ifdef CONFIG_PAX_SEGMEXEC
81089 + struct vm_area_struct *vma_m = NULL;
81090 +#endif
81091 +
81092 + if (security_mmap_addr(vma->vm_start))
81093 + return -EPERM;
81094 +
81095 /*
81096 * The vm_pgoff of a purely anonymous vma should be irrelevant
81097 * until its first write fault, when page's anon_vma and index
81098 @@ -2716,7 +3164,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
81099 security_vm_enough_memory_mm(mm, vma_pages(vma)))
81100 return -ENOMEM;
81101
81102 +#ifdef CONFIG_PAX_SEGMEXEC
81103 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
81104 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81105 + if (!vma_m)
81106 + return -ENOMEM;
81107 + }
81108 +#endif
81109 +
81110 vma_link(mm, vma, prev, rb_link, rb_parent);
81111 +
81112 +#ifdef CONFIG_PAX_SEGMEXEC
81113 + if (vma_m)
81114 + BUG_ON(pax_mirror_vma(vma_m, vma));
81115 +#endif
81116 +
81117 return 0;
81118 }
81119
81120 @@ -2736,6 +3198,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
81121 struct mempolicy *pol;
81122 bool faulted_in_anon_vma = true;
81123
81124 + BUG_ON(vma->vm_mirror);
81125 +
81126 /*
81127 * If anonymous vma has not yet been faulted, update new pgoff
81128 * to match new location, to increase its chance of merging.
81129 @@ -2802,6 +3266,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
81130 return NULL;
81131 }
81132
81133 +#ifdef CONFIG_PAX_SEGMEXEC
81134 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
81135 +{
81136 + struct vm_area_struct *prev_m;
81137 + struct rb_node **rb_link_m, *rb_parent_m;
81138 + struct mempolicy *pol_m;
81139 +
81140 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
81141 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
81142 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
81143 + *vma_m = *vma;
81144 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
81145 + if (anon_vma_clone(vma_m, vma))
81146 + return -ENOMEM;
81147 + pol_m = vma_policy(vma_m);
81148 + mpol_get(pol_m);
81149 + vma_set_policy(vma_m, pol_m);
81150 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
81151 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
81152 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
81153 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
81154 + if (vma_m->vm_file)
81155 + get_file(vma_m->vm_file);
81156 + if (vma_m->vm_ops && vma_m->vm_ops->open)
81157 + vma_m->vm_ops->open(vma_m);
81158 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
81159 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
81160 + vma_m->vm_mirror = vma;
81161 + vma->vm_mirror = vma_m;
81162 + return 0;
81163 +}
81164 +#endif
81165 +
81166 /*
81167 * Return true if the calling process may expand its vm space by the passed
81168 * number of pages
81169 @@ -2813,6 +3310,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
81170
81171 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
81172
81173 +#ifdef CONFIG_PAX_RANDMMAP
81174 + if (mm->pax_flags & MF_PAX_RANDMMAP)
81175 + cur -= mm->brk_gap;
81176 +#endif
81177 +
81178 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
81179 if (cur + npages > lim)
81180 return 0;
81181 return 1;
81182 @@ -2883,6 +3386,22 @@ int install_special_mapping(struct mm_struct *mm,
81183 vma->vm_start = addr;
81184 vma->vm_end = addr + len;
81185
81186 +#ifdef CONFIG_PAX_MPROTECT
81187 + if (mm->pax_flags & MF_PAX_MPROTECT) {
81188 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
81189 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
81190 + return -EPERM;
81191 + if (!(vm_flags & VM_EXEC))
81192 + vm_flags &= ~VM_MAYEXEC;
81193 +#else
81194 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
81195 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
81196 +#endif
81197 + else
81198 + vm_flags &= ~VM_MAYWRITE;
81199 + }
81200 +#endif
81201 +
81202 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
81203 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
81204
81205 diff --git a/mm/mprotect.c b/mm/mprotect.c
81206 index 94722a4..9837984 100644
81207 --- a/mm/mprotect.c
81208 +++ b/mm/mprotect.c
81209 @@ -23,10 +23,17 @@
81210 #include <linux/mmu_notifier.h>
81211 #include <linux/migrate.h>
81212 #include <linux/perf_event.h>
81213 +
81214 +#ifdef CONFIG_PAX_MPROTECT
81215 +#include <linux/elf.h>
81216 +#include <linux/binfmts.h>
81217 +#endif
81218 +
81219 #include <asm/uaccess.h>
81220 #include <asm/pgtable.h>
81221 #include <asm/cacheflush.h>
81222 #include <asm/tlbflush.h>
81223 +#include <asm/mmu_context.h>
81224
81225 #ifndef pgprot_modify
81226 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
81227 @@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
81228 return pages;
81229 }
81230
81231 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81232 +/* called while holding the mmap semaphor for writing except stack expansion */
81233 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
81234 +{
81235 + unsigned long oldlimit, newlimit = 0UL;
81236 +
81237 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
81238 + return;
81239 +
81240 + spin_lock(&mm->page_table_lock);
81241 + oldlimit = mm->context.user_cs_limit;
81242 + if ((prot & VM_EXEC) && oldlimit < end)
81243 + /* USER_CS limit moved up */
81244 + newlimit = end;
81245 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
81246 + /* USER_CS limit moved down */
81247 + newlimit = start;
81248 +
81249 + if (newlimit) {
81250 + mm->context.user_cs_limit = newlimit;
81251 +
81252 +#ifdef CONFIG_SMP
81253 + wmb();
81254 + cpus_clear(mm->context.cpu_user_cs_mask);
81255 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
81256 +#endif
81257 +
81258 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
81259 + }
81260 + spin_unlock(&mm->page_table_lock);
81261 + if (newlimit == end) {
81262 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
81263 +
81264 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
81265 + if (is_vm_hugetlb_page(vma))
81266 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
81267 + else
81268 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
81269 + }
81270 +}
81271 +#endif
81272 +
81273 int
81274 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81275 unsigned long start, unsigned long end, unsigned long newflags)
81276 @@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81277 int error;
81278 int dirty_accountable = 0;
81279
81280 +#ifdef CONFIG_PAX_SEGMEXEC
81281 + struct vm_area_struct *vma_m = NULL;
81282 + unsigned long start_m, end_m;
81283 +
81284 + start_m = start + SEGMEXEC_TASK_SIZE;
81285 + end_m = end + SEGMEXEC_TASK_SIZE;
81286 +#endif
81287 +
81288 if (newflags == oldflags) {
81289 *pprev = vma;
81290 return 0;
81291 }
81292
81293 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
81294 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
81295 +
81296 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
81297 + return -ENOMEM;
81298 +
81299 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
81300 + return -ENOMEM;
81301 + }
81302 +
81303 /*
81304 * If we make a private mapping writable we increase our commit;
81305 * but (without finer accounting) cannot reduce our commit if we
81306 @@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81307 }
81308 }
81309
81310 +#ifdef CONFIG_PAX_SEGMEXEC
81311 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
81312 + if (start != vma->vm_start) {
81313 + error = split_vma(mm, vma, start, 1);
81314 + if (error)
81315 + goto fail;
81316 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
81317 + *pprev = (*pprev)->vm_next;
81318 + }
81319 +
81320 + if (end != vma->vm_end) {
81321 + error = split_vma(mm, vma, end, 0);
81322 + if (error)
81323 + goto fail;
81324 + }
81325 +
81326 + if (pax_find_mirror_vma(vma)) {
81327 + error = __do_munmap(mm, start_m, end_m - start_m);
81328 + if (error)
81329 + goto fail;
81330 + } else {
81331 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81332 + if (!vma_m) {
81333 + error = -ENOMEM;
81334 + goto fail;
81335 + }
81336 + vma->vm_flags = newflags;
81337 + error = pax_mirror_vma(vma_m, vma);
81338 + if (error) {
81339 + vma->vm_flags = oldflags;
81340 + goto fail;
81341 + }
81342 + }
81343 + }
81344 +#endif
81345 +
81346 /*
81347 * First try to merge with previous and/or next vma.
81348 */
81349 @@ -296,9 +399,21 @@ success:
81350 * vm_flags and vm_page_prot are protected by the mmap_sem
81351 * held in write mode.
81352 */
81353 +
81354 +#ifdef CONFIG_PAX_SEGMEXEC
81355 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
81356 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
81357 +#endif
81358 +
81359 vma->vm_flags = newflags;
81360 +
81361 +#ifdef CONFIG_PAX_MPROTECT
81362 + if (mm->binfmt && mm->binfmt->handle_mprotect)
81363 + mm->binfmt->handle_mprotect(vma, newflags);
81364 +#endif
81365 +
81366 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
81367 - vm_get_page_prot(newflags));
81368 + vm_get_page_prot(vma->vm_flags));
81369
81370 if (vma_wants_writenotify(vma)) {
81371 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
81372 @@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81373 end = start + len;
81374 if (end <= start)
81375 return -ENOMEM;
81376 +
81377 +#ifdef CONFIG_PAX_SEGMEXEC
81378 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81379 + if (end > SEGMEXEC_TASK_SIZE)
81380 + return -EINVAL;
81381 + } else
81382 +#endif
81383 +
81384 + if (end > TASK_SIZE)
81385 + return -EINVAL;
81386 +
81387 if (!arch_validate_prot(prot))
81388 return -EINVAL;
81389
81390 @@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81391 /*
81392 * Does the application expect PROT_READ to imply PROT_EXEC:
81393 */
81394 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
81395 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
81396 prot |= PROT_EXEC;
81397
81398 vm_flags = calc_vm_prot_bits(prot);
81399 @@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81400 if (start > vma->vm_start)
81401 prev = vma;
81402
81403 +#ifdef CONFIG_PAX_MPROTECT
81404 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
81405 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
81406 +#endif
81407 +
81408 for (nstart = start ; ; ) {
81409 unsigned long newflags;
81410
81411 @@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81412
81413 /* newflags >> 4 shift VM_MAY% in place of VM_% */
81414 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
81415 + if (prot & (PROT_WRITE | PROT_EXEC))
81416 + gr_log_rwxmprotect(vma->vm_file);
81417 +
81418 + error = -EACCES;
81419 + goto out;
81420 + }
81421 +
81422 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
81423 error = -EACCES;
81424 goto out;
81425 }
81426 @@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81427 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
81428 if (error)
81429 goto out;
81430 +
81431 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
81432 +
81433 nstart = tmp;
81434
81435 if (nstart < prev->vm_end)
81436 diff --git a/mm/mremap.c b/mm/mremap.c
81437 index e1031e1..1f2a0a1 100644
81438 --- a/mm/mremap.c
81439 +++ b/mm/mremap.c
81440 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
81441 continue;
81442 pte = ptep_get_and_clear(mm, old_addr, old_pte);
81443 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
81444 +
81445 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81446 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
81447 + pte = pte_exprotect(pte);
81448 +#endif
81449 +
81450 set_pte_at(mm, new_addr, new_pte, pte);
81451 }
81452
81453 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
81454 if (is_vm_hugetlb_page(vma))
81455 goto Einval;
81456
81457 +#ifdef CONFIG_PAX_SEGMEXEC
81458 + if (pax_find_mirror_vma(vma))
81459 + goto Einval;
81460 +#endif
81461 +
81462 /* We can't remap across vm area boundaries */
81463 if (old_len > vma->vm_end - addr)
81464 goto Efault;
81465 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
81466 unsigned long ret = -EINVAL;
81467 unsigned long charged = 0;
81468 unsigned long map_flags;
81469 + unsigned long pax_task_size = TASK_SIZE;
81470
81471 if (new_addr & ~PAGE_MASK)
81472 goto out;
81473
81474 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
81475 +#ifdef CONFIG_PAX_SEGMEXEC
81476 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
81477 + pax_task_size = SEGMEXEC_TASK_SIZE;
81478 +#endif
81479 +
81480 + pax_task_size -= PAGE_SIZE;
81481 +
81482 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
81483 goto out;
81484
81485 /* Check if the location we're moving into overlaps the
81486 * old location at all, and fail if it does.
81487 */
81488 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
81489 - goto out;
81490 -
81491 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
81492 + if (addr + old_len > new_addr && new_addr + new_len > addr)
81493 goto out;
81494
81495 ret = do_munmap(mm, new_addr, new_len);
81496 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81497 struct vm_area_struct *vma;
81498 unsigned long ret = -EINVAL;
81499 unsigned long charged = 0;
81500 + unsigned long pax_task_size = TASK_SIZE;
81501
81502 down_write(&current->mm->mmap_sem);
81503
81504 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81505 if (!new_len)
81506 goto out;
81507
81508 +#ifdef CONFIG_PAX_SEGMEXEC
81509 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
81510 + pax_task_size = SEGMEXEC_TASK_SIZE;
81511 +#endif
81512 +
81513 + pax_task_size -= PAGE_SIZE;
81514 +
81515 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
81516 + old_len > pax_task_size || addr > pax_task_size-old_len)
81517 + goto out;
81518 +
81519 if (flags & MREMAP_FIXED) {
81520 if (flags & MREMAP_MAYMOVE)
81521 ret = mremap_to(addr, old_len, new_addr, new_len);
81522 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81523 addr + new_len);
81524 }
81525 ret = addr;
81526 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
81527 goto out;
81528 }
81529 }
81530 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81531 goto out;
81532 }
81533
81534 + map_flags = vma->vm_flags;
81535 ret = move_vma(vma, addr, old_len, new_len, new_addr);
81536 + if (!(ret & ~PAGE_MASK)) {
81537 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
81538 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
81539 + }
81540 }
81541 out:
81542 if (ret & ~PAGE_MASK)
81543 diff --git a/mm/nommu.c b/mm/nommu.c
81544 index 79c3cac..4d357e0 100644
81545 --- a/mm/nommu.c
81546 +++ b/mm/nommu.c
81547 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
81548 int sysctl_overcommit_ratio = 50; /* default is 50% */
81549 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
81550 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
81551 -int heap_stack_gap = 0;
81552
81553 atomic_long_t mmap_pages_allocated;
81554
81555 @@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
81556 EXPORT_SYMBOL(find_vma);
81557
81558 /*
81559 - * find a VMA
81560 - * - we don't extend stack VMAs under NOMMU conditions
81561 - */
81562 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
81563 -{
81564 - return find_vma(mm, addr);
81565 -}
81566 -
81567 -/*
81568 * expand a stack to a given address
81569 * - not supported under NOMMU conditions
81570 */
81571 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81572
81573 /* most fields are the same, copy all, and then fixup */
81574 *new = *vma;
81575 + INIT_LIST_HEAD(&new->anon_vma_chain);
81576 *region = *vma->vm_region;
81577 new->vm_region = region;
81578
81579 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
81580 index 0713bfb..e3774e0 100644
81581 --- a/mm/page-writeback.c
81582 +++ b/mm/page-writeback.c
81583 @@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
81584 }
81585 }
81586
81587 -static struct notifier_block __cpuinitdata ratelimit_nb = {
81588 +static struct notifier_block ratelimit_nb = {
81589 .notifier_call = ratelimit_handler,
81590 .next = NULL,
81591 };
81592 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
81593 index 6a83cd3..bc2dcb6 100644
81594 --- a/mm/page_alloc.c
81595 +++ b/mm/page_alloc.c
81596 @@ -338,7 +338,7 @@ out:
81597 * This usage means that zero-order pages may not be compound.
81598 */
81599
81600 -static void free_compound_page(struct page *page)
81601 +void free_compound_page(struct page *page)
81602 {
81603 __free_pages_ok(page, compound_order(page));
81604 }
81605 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
81606 int i;
81607 int bad = 0;
81608
81609 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81610 + unsigned long index = 1UL << order;
81611 +#endif
81612 +
81613 trace_mm_page_free(page, order);
81614 kmemcheck_free_shadow(page, order);
81615
81616 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
81617 debug_check_no_obj_freed(page_address(page),
81618 PAGE_SIZE << order);
81619 }
81620 +
81621 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81622 + for (; index; --index)
81623 + sanitize_highpage(page + index - 1);
81624 +#endif
81625 +
81626 arch_free_page(page, order);
81627 kernel_map_pages(page, 1 << order, 0);
81628
81629 @@ -861,8 +871,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
81630 arch_alloc_page(page, order);
81631 kernel_map_pages(page, 1 << order, 1);
81632
81633 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
81634 if (gfp_flags & __GFP_ZERO)
81635 prep_zero_page(page, order, gfp_flags);
81636 +#endif
81637
81638 if (order && (gfp_flags & __GFP_COMP))
81639 prep_compound_page(page, order);
81640 @@ -3752,7 +3764,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
81641 unsigned long pfn;
81642
81643 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
81644 +#ifdef CONFIG_X86_32
81645 + /* boot failures in VMware 8 on 32bit vanilla since
81646 + this change */
81647 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
81648 +#else
81649 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
81650 +#endif
81651 return 1;
81652 }
81653 return 0;
81654 diff --git a/mm/percpu.c b/mm/percpu.c
81655 index 8c8e08f..73a5cda 100644
81656 --- a/mm/percpu.c
81657 +++ b/mm/percpu.c
81658 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
81659 static unsigned int pcpu_high_unit_cpu __read_mostly;
81660
81661 /* the address of the first chunk which starts with the kernel static area */
81662 -void *pcpu_base_addr __read_mostly;
81663 +void *pcpu_base_addr __read_only;
81664 EXPORT_SYMBOL_GPL(pcpu_base_addr);
81665
81666 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
81667 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
81668 index 926b466..b23df53 100644
81669 --- a/mm/process_vm_access.c
81670 +++ b/mm/process_vm_access.c
81671 @@ -13,6 +13,7 @@
81672 #include <linux/uio.h>
81673 #include <linux/sched.h>
81674 #include <linux/highmem.h>
81675 +#include <linux/security.h>
81676 #include <linux/ptrace.h>
81677 #include <linux/slab.h>
81678 #include <linux/syscalls.h>
81679 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
81680 size_t iov_l_curr_offset = 0;
81681 ssize_t iov_len;
81682
81683 + return -ENOSYS; // PaX: until properly audited
81684 +
81685 /*
81686 * Work out how many pages of struct pages we're going to need
81687 * when eventually calling get_user_pages
81688 */
81689 for (i = 0; i < riovcnt; i++) {
81690 iov_len = rvec[i].iov_len;
81691 - if (iov_len > 0) {
81692 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
81693 - + iov_len)
81694 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
81695 - / PAGE_SIZE + 1;
81696 - nr_pages = max(nr_pages, nr_pages_iov);
81697 - }
81698 + if (iov_len <= 0)
81699 + continue;
81700 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
81701 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
81702 + nr_pages = max(nr_pages, nr_pages_iov);
81703 }
81704
81705 if (nr_pages == 0)
81706 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
81707 goto free_proc_pages;
81708 }
81709
81710 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
81711 + rc = -EPERM;
81712 + goto put_task_struct;
81713 + }
81714 +
81715 mm = mm_access(task, PTRACE_MODE_ATTACH);
81716 if (!mm || IS_ERR(mm)) {
81717 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
81718 diff --git a/mm/rmap.c b/mm/rmap.c
81719 index 2c78f8c..9e9c624 100644
81720 --- a/mm/rmap.c
81721 +++ b/mm/rmap.c
81722 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81723 struct anon_vma *anon_vma = vma->anon_vma;
81724 struct anon_vma_chain *avc;
81725
81726 +#ifdef CONFIG_PAX_SEGMEXEC
81727 + struct anon_vma_chain *avc_m = NULL;
81728 +#endif
81729 +
81730 might_sleep();
81731 if (unlikely(!anon_vma)) {
81732 struct mm_struct *mm = vma->vm_mm;
81733 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81734 if (!avc)
81735 goto out_enomem;
81736
81737 +#ifdef CONFIG_PAX_SEGMEXEC
81738 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
81739 + if (!avc_m)
81740 + goto out_enomem_free_avc;
81741 +#endif
81742 +
81743 anon_vma = find_mergeable_anon_vma(vma);
81744 allocated = NULL;
81745 if (!anon_vma) {
81746 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81747 /* page_table_lock to protect against threads */
81748 spin_lock(&mm->page_table_lock);
81749 if (likely(!vma->anon_vma)) {
81750 +
81751 +#ifdef CONFIG_PAX_SEGMEXEC
81752 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
81753 +
81754 + if (vma_m) {
81755 + BUG_ON(vma_m->anon_vma);
81756 + vma_m->anon_vma = anon_vma;
81757 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
81758 + avc_m = NULL;
81759 + }
81760 +#endif
81761 +
81762 vma->anon_vma = anon_vma;
81763 anon_vma_chain_link(vma, avc, anon_vma);
81764 allocated = NULL;
81765 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81766
81767 if (unlikely(allocated))
81768 put_anon_vma(allocated);
81769 +
81770 +#ifdef CONFIG_PAX_SEGMEXEC
81771 + if (unlikely(avc_m))
81772 + anon_vma_chain_free(avc_m);
81773 +#endif
81774 +
81775 if (unlikely(avc))
81776 anon_vma_chain_free(avc);
81777 }
81778 return 0;
81779
81780 out_enomem_free_avc:
81781 +
81782 +#ifdef CONFIG_PAX_SEGMEXEC
81783 + if (avc_m)
81784 + anon_vma_chain_free(avc_m);
81785 +#endif
81786 +
81787 anon_vma_chain_free(avc);
81788 out_enomem:
81789 return -ENOMEM;
81790 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
81791 * Attach the anon_vmas from src to dst.
81792 * Returns 0 on success, -ENOMEM on failure.
81793 */
81794 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
81795 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
81796 {
81797 struct anon_vma_chain *avc, *pavc;
81798 struct anon_vma *root = NULL;
81799 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
81800 * the corresponding VMA in the parent process is attached to.
81801 * Returns 0 on success, non-zero on failure.
81802 */
81803 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
81804 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
81805 {
81806 struct anon_vma_chain *avc;
81807 struct anon_vma *anon_vma;
81808 diff --git a/mm/shmem.c b/mm/shmem.c
81809 index efd0b3a..994b702 100644
81810 --- a/mm/shmem.c
81811 +++ b/mm/shmem.c
81812 @@ -31,7 +31,7 @@
81813 #include <linux/export.h>
81814 #include <linux/swap.h>
81815
81816 -static struct vfsmount *shm_mnt;
81817 +struct vfsmount *shm_mnt;
81818
81819 #ifdef CONFIG_SHMEM
81820 /*
81821 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
81822 #define BOGO_DIRENT_SIZE 20
81823
81824 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
81825 -#define SHORT_SYMLINK_LEN 128
81826 +#define SHORT_SYMLINK_LEN 64
81827
81828 /*
81829 * shmem_fallocate and shmem_writepage communicate via inode->i_private
81830 @@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
81831 static int shmem_xattr_validate(const char *name)
81832 {
81833 struct { const char *prefix; size_t len; } arr[] = {
81834 +
81835 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
81836 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
81837 +#endif
81838 +
81839 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
81840 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
81841 };
81842 @@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
81843 if (err)
81844 return err;
81845
81846 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
81847 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
81848 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
81849 + return -EOPNOTSUPP;
81850 + if (size > 8)
81851 + return -EINVAL;
81852 + }
81853 +#endif
81854 +
81855 return simple_xattr_set(&info->xattrs, name, value, size, flags);
81856 }
81857
81858 @@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
81859 int err = -ENOMEM;
81860
81861 /* Round up to L1_CACHE_BYTES to resist false sharing */
81862 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
81863 - L1_CACHE_BYTES), GFP_KERNEL);
81864 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
81865 if (!sbinfo)
81866 return -ENOMEM;
81867
81868 diff --git a/mm/slab.c b/mm/slab.c
81869 index e7667a3..b62c169 100644
81870 --- a/mm/slab.c
81871 +++ b/mm/slab.c
81872 @@ -306,7 +306,7 @@ struct kmem_list3 {
81873 * Need this for bootstrapping a per node allocator.
81874 */
81875 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
81876 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
81877 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
81878 #define CACHE_CACHE 0
81879 #define SIZE_AC MAX_NUMNODES
81880 #define SIZE_L3 (2 * MAX_NUMNODES)
81881 @@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
81882 if ((x)->max_freeable < i) \
81883 (x)->max_freeable = i; \
81884 } while (0)
81885 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
81886 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
81887 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
81888 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
81889 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
81890 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
81891 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
81892 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
81893 #else
81894 #define STATS_INC_ACTIVE(x) do { } while (0)
81895 #define STATS_DEC_ACTIVE(x) do { } while (0)
81896 @@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
81897 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
81898 */
81899 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
81900 - const struct slab *slab, void *obj)
81901 + const struct slab *slab, const void *obj)
81902 {
81903 u32 offset = (obj - slab->s_mem);
81904 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
81905 @@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
81906 struct cache_names {
81907 char *name;
81908 char *name_dma;
81909 + char *name_usercopy;
81910 };
81911
81912 static struct cache_names __initdata cache_names[] = {
81913 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
81914 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
81915 #include <linux/kmalloc_sizes.h>
81916 - {NULL,}
81917 + {NULL}
81918 #undef CACHE
81919 };
81920
81921 @@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
81922 if (unlikely(gfpflags & GFP_DMA))
81923 return csizep->cs_dmacachep;
81924 #endif
81925 +
81926 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81927 + if (unlikely(gfpflags & GFP_USERCOPY))
81928 + return csizep->cs_usercopycachep;
81929 +#endif
81930 +
81931 return csizep->cs_cachep;
81932 }
81933
81934 @@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
81935 return notifier_from_errno(err);
81936 }
81937
81938 -static struct notifier_block __cpuinitdata cpucache_notifier = {
81939 +static struct notifier_block cpucache_notifier = {
81940 &cpuup_callback, NULL, 0
81941 };
81942
81943 @@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
81944 */
81945
81946 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
81947 - sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
81948 + sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
81949
81950 if (INDEX_AC != INDEX_L3)
81951 sizes[INDEX_L3].cs_cachep =
81952 create_kmalloc_cache(names[INDEX_L3].name,
81953 - sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
81954 + sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
81955
81956 slab_early_init = 0;
81957
81958 @@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
81959 */
81960 if (!sizes->cs_cachep)
81961 sizes->cs_cachep = create_kmalloc_cache(names->name,
81962 - sizes->cs_size, ARCH_KMALLOC_FLAGS);
81963 + sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
81964
81965 #ifdef CONFIG_ZONE_DMA
81966 sizes->cs_dmacachep = create_kmalloc_cache(
81967 names->name_dma, sizes->cs_size,
81968 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
81969 #endif
81970 +
81971 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81972 + sizes->cs_usercopycachep = create_kmalloc_cache(
81973 + names->name_usercopy, sizes->cs_size,
81974 + ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
81975 +#endif
81976 +
81977 sizes++;
81978 names++;
81979 }
81980 @@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
81981 }
81982 /* cpu stats */
81983 {
81984 - unsigned long allochit = atomic_read(&cachep->allochit);
81985 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
81986 - unsigned long freehit = atomic_read(&cachep->freehit);
81987 - unsigned long freemiss = atomic_read(&cachep->freemiss);
81988 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
81989 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
81990 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
81991 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
81992
81993 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
81994 allochit, allocmiss, freehit, freemiss);
81995 @@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
81996 static int __init slab_proc_init(void)
81997 {
81998 #ifdef CONFIG_DEBUG_SLAB_LEAK
81999 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
82000 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
82001 #endif
82002 return 0;
82003 }
82004 module_init(slab_proc_init);
82005 #endif
82006
82007 +bool is_usercopy_object(const void *ptr)
82008 +{
82009 + struct page *page;
82010 + struct kmem_cache *cachep;
82011 +
82012 + if (ZERO_OR_NULL_PTR(ptr))
82013 + return false;
82014 +
82015 + if (!slab_is_available())
82016 + return false;
82017 +
82018 + if (!virt_addr_valid(ptr))
82019 + return false;
82020 +
82021 + page = virt_to_head_page(ptr);
82022 +
82023 + if (!PageSlab(page))
82024 + return false;
82025 +
82026 + cachep = page->slab_cache;
82027 + return cachep->flags & SLAB_USERCOPY;
82028 +}
82029 +
82030 +#ifdef CONFIG_PAX_USERCOPY
82031 +const char *check_heap_object(const void *ptr, unsigned long n)
82032 +{
82033 + struct page *page;
82034 + struct kmem_cache *cachep;
82035 + struct slab *slabp;
82036 + unsigned int objnr;
82037 + unsigned long offset;
82038 +
82039 + if (ZERO_OR_NULL_PTR(ptr))
82040 + return "<null>";
82041 +
82042 + if (!virt_addr_valid(ptr))
82043 + return NULL;
82044 +
82045 + page = virt_to_head_page(ptr);
82046 +
82047 + if (!PageSlab(page))
82048 + return NULL;
82049 +
82050 + cachep = page->slab_cache;
82051 + if (!(cachep->flags & SLAB_USERCOPY))
82052 + return cachep->name;
82053 +
82054 + slabp = page->slab_page;
82055 + objnr = obj_to_index(cachep, slabp, ptr);
82056 + BUG_ON(objnr >= cachep->num);
82057 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
82058 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
82059 + return NULL;
82060 +
82061 + return cachep->name;
82062 +}
82063 +#endif
82064 +
82065 /**
82066 * ksize - get the actual amount of memory allocated for a given object
82067 * @objp: Pointer to the object
82068 diff --git a/mm/slab.h b/mm/slab.h
82069 index 34a98d6..73633d1 100644
82070 --- a/mm/slab.h
82071 +++ b/mm/slab.h
82072 @@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82073
82074 /* Legal flag mask for kmem_cache_create(), for various configurations */
82075 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
82076 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
82077 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
82078
82079 #if defined(CONFIG_DEBUG_SLAB)
82080 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
82081 @@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
82082 return s;
82083
82084 page = virt_to_head_page(x);
82085 +
82086 + BUG_ON(!PageSlab(page));
82087 +
82088 cachep = page->slab_cache;
82089 if (slab_equal_or_root(cachep, s))
82090 return cachep;
82091 diff --git a/mm/slab_common.c b/mm/slab_common.c
82092 index 3f3cd97..93b0236 100644
82093 --- a/mm/slab_common.c
82094 +++ b/mm/slab_common.c
82095 @@ -22,7 +22,7 @@
82096
82097 #include "slab.h"
82098
82099 -enum slab_state slab_state;
82100 +enum slab_state slab_state __read_only;
82101 LIST_HEAD(slab_caches);
82102 DEFINE_MUTEX(slab_mutex);
82103 struct kmem_cache *kmem_cache;
82104 @@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
82105
82106 err = __kmem_cache_create(s, flags);
82107 if (!err) {
82108 - s->refcount = 1;
82109 + atomic_set(&s->refcount, 1);
82110 list_add(&s->list, &slab_caches);
82111 memcg_cache_list_add(memcg, s);
82112 } else {
82113 @@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
82114
82115 get_online_cpus();
82116 mutex_lock(&slab_mutex);
82117 - s->refcount--;
82118 - if (!s->refcount) {
82119 + if (atomic_dec_and_test(&s->refcount)) {
82120 list_del(&s->list);
82121
82122 if (!__kmem_cache_shutdown(s)) {
82123 @@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
82124 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
82125 name, size, err);
82126
82127 - s->refcount = -1; /* Exempt from merging for now */
82128 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
82129 }
82130
82131 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
82132 @@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
82133
82134 create_boot_cache(s, name, size, flags);
82135 list_add(&s->list, &slab_caches);
82136 - s->refcount = 1;
82137 + atomic_set(&s->refcount, 1);
82138 return s;
82139 }
82140
82141 diff --git a/mm/slob.c b/mm/slob.c
82142 index a99fdf7..f5b6577 100644
82143 --- a/mm/slob.c
82144 +++ b/mm/slob.c
82145 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
82146 /*
82147 * Return the size of a slob block.
82148 */
82149 -static slobidx_t slob_units(slob_t *s)
82150 +static slobidx_t slob_units(const slob_t *s)
82151 {
82152 if (s->units > 0)
82153 return s->units;
82154 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
82155 /*
82156 * Return the next free slob block pointer after this one.
82157 */
82158 -static slob_t *slob_next(slob_t *s)
82159 +static slob_t *slob_next(const slob_t *s)
82160 {
82161 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
82162 slobidx_t next;
82163 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
82164 /*
82165 * Returns true if s is the last free block in its page.
82166 */
82167 -static int slob_last(slob_t *s)
82168 +static int slob_last(const slob_t *s)
82169 {
82170 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
82171 }
82172
82173 -static void *slob_new_pages(gfp_t gfp, int order, int node)
82174 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
82175 {
82176 - void *page;
82177 + struct page *page;
82178
82179 #ifdef CONFIG_NUMA
82180 if (node != NUMA_NO_NODE)
82181 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
82182 if (!page)
82183 return NULL;
82184
82185 - return page_address(page);
82186 + __SetPageSlab(page);
82187 + return page;
82188 }
82189
82190 -static void slob_free_pages(void *b, int order)
82191 +static void slob_free_pages(struct page *sp, int order)
82192 {
82193 if (current->reclaim_state)
82194 current->reclaim_state->reclaimed_slab += 1 << order;
82195 - free_pages((unsigned long)b, order);
82196 + __ClearPageSlab(sp);
82197 + reset_page_mapcount(sp);
82198 + sp->private = 0;
82199 + __free_pages(sp, order);
82200 }
82201
82202 /*
82203 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
82204
82205 /* Not enough space: must allocate a new page */
82206 if (!b) {
82207 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
82208 - if (!b)
82209 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
82210 + if (!sp)
82211 return NULL;
82212 - sp = virt_to_page(b);
82213 - __SetPageSlab(sp);
82214 + b = page_address(sp);
82215
82216 spin_lock_irqsave(&slob_lock, flags);
82217 sp->units = SLOB_UNITS(PAGE_SIZE);
82218 sp->freelist = b;
82219 + sp->private = 0;
82220 INIT_LIST_HEAD(&sp->list);
82221 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
82222 set_slob_page_free(sp, slob_list);
82223 @@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
82224 if (slob_page_free(sp))
82225 clear_slob_page_free(sp);
82226 spin_unlock_irqrestore(&slob_lock, flags);
82227 - __ClearPageSlab(sp);
82228 - reset_page_mapcount(sp);
82229 - slob_free_pages(b, 0);
82230 + slob_free_pages(sp, 0);
82231 return;
82232 }
82233
82234 @@ -424,11 +426,10 @@ out:
82235 */
82236
82237 static __always_inline void *
82238 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82239 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
82240 {
82241 - unsigned int *m;
82242 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82243 - void *ret;
82244 + slob_t *m;
82245 + void *ret = NULL;
82246
82247 gfp &= gfp_allowed_mask;
82248
82249 @@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82250
82251 if (!m)
82252 return NULL;
82253 - *m = size;
82254 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
82255 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
82256 + m[0].units = size;
82257 + m[1].units = align;
82258 ret = (void *)m + align;
82259
82260 trace_kmalloc_node(caller, ret,
82261 size, size + align, gfp, node);
82262 } else {
82263 unsigned int order = get_order(size);
82264 + struct page *page;
82265
82266 if (likely(order))
82267 gfp |= __GFP_COMP;
82268 - ret = slob_new_pages(gfp, order, node);
82269 + page = slob_new_pages(gfp, order, node);
82270 + if (page) {
82271 + ret = page_address(page);
82272 + page->private = size;
82273 + }
82274
82275 trace_kmalloc_node(caller, ret,
82276 size, PAGE_SIZE << order, gfp, node);
82277 }
82278
82279 - kmemleak_alloc(ret, size, 1, gfp);
82280 + return ret;
82281 +}
82282 +
82283 +static __always_inline void *
82284 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82285 +{
82286 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82287 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
82288 +
82289 + if (!ZERO_OR_NULL_PTR(ret))
82290 + kmemleak_alloc(ret, size, 1, gfp);
82291 return ret;
82292 }
82293
82294 @@ -494,33 +513,110 @@ void kfree(const void *block)
82295 kmemleak_free(block);
82296
82297 sp = virt_to_page(block);
82298 - if (PageSlab(sp)) {
82299 + VM_BUG_ON(!PageSlab(sp));
82300 + if (!sp->private) {
82301 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82302 - unsigned int *m = (unsigned int *)(block - align);
82303 - slob_free(m, *m + align);
82304 - } else
82305 + slob_t *m = (slob_t *)(block - align);
82306 + slob_free(m, m[0].units + align);
82307 + } else {
82308 + __ClearPageSlab(sp);
82309 + reset_page_mapcount(sp);
82310 + sp->private = 0;
82311 __free_pages(sp, compound_order(sp));
82312 + }
82313 }
82314 EXPORT_SYMBOL(kfree);
82315
82316 +bool is_usercopy_object(const void *ptr)
82317 +{
82318 + if (!slab_is_available())
82319 + return false;
82320 +
82321 + // PAX: TODO
82322 +
82323 + return false;
82324 +}
82325 +
82326 +#ifdef CONFIG_PAX_USERCOPY
82327 +const char *check_heap_object(const void *ptr, unsigned long n)
82328 +{
82329 + struct page *page;
82330 + const slob_t *free;
82331 + const void *base;
82332 + unsigned long flags;
82333 +
82334 + if (ZERO_OR_NULL_PTR(ptr))
82335 + return "<null>";
82336 +
82337 + if (!virt_addr_valid(ptr))
82338 + return NULL;
82339 +
82340 + page = virt_to_head_page(ptr);
82341 + if (!PageSlab(page))
82342 + return NULL;
82343 +
82344 + if (page->private) {
82345 + base = page;
82346 + if (base <= ptr && n <= page->private - (ptr - base))
82347 + return NULL;
82348 + return "<slob>";
82349 + }
82350 +
82351 + /* some tricky double walking to find the chunk */
82352 + spin_lock_irqsave(&slob_lock, flags);
82353 + base = (void *)((unsigned long)ptr & PAGE_MASK);
82354 + free = page->freelist;
82355 +
82356 + while (!slob_last(free) && (void *)free <= ptr) {
82357 + base = free + slob_units(free);
82358 + free = slob_next(free);
82359 + }
82360 +
82361 + while (base < (void *)free) {
82362 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
82363 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
82364 + int offset;
82365 +
82366 + if (ptr < base + align)
82367 + break;
82368 +
82369 + offset = ptr - base - align;
82370 + if (offset >= m) {
82371 + base += size;
82372 + continue;
82373 + }
82374 +
82375 + if (n > m - offset)
82376 + break;
82377 +
82378 + spin_unlock_irqrestore(&slob_lock, flags);
82379 + return NULL;
82380 + }
82381 +
82382 + spin_unlock_irqrestore(&slob_lock, flags);
82383 + return "<slob>";
82384 +}
82385 +#endif
82386 +
82387 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
82388 size_t ksize(const void *block)
82389 {
82390 struct page *sp;
82391 int align;
82392 - unsigned int *m;
82393 + slob_t *m;
82394
82395 BUG_ON(!block);
82396 if (unlikely(block == ZERO_SIZE_PTR))
82397 return 0;
82398
82399 sp = virt_to_page(block);
82400 - if (unlikely(!PageSlab(sp)))
82401 - return PAGE_SIZE << compound_order(sp);
82402 + VM_BUG_ON(!PageSlab(sp));
82403 + if (sp->private)
82404 + return sp->private;
82405
82406 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82407 - m = (unsigned int *)(block - align);
82408 - return SLOB_UNITS(*m) * SLOB_UNIT;
82409 + m = (slob_t *)(block - align);
82410 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
82411 }
82412 EXPORT_SYMBOL(ksize);
82413
82414 @@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
82415
82416 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
82417 {
82418 - void *b;
82419 + void *b = NULL;
82420
82421 flags &= gfp_allowed_mask;
82422
82423 lockdep_trace_alloc(flags);
82424
82425 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82426 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
82427 +#else
82428 if (c->size < PAGE_SIZE) {
82429 b = slob_alloc(c->size, flags, c->align, node);
82430 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
82431 SLOB_UNITS(c->size) * SLOB_UNIT,
82432 flags, node);
82433 } else {
82434 - b = slob_new_pages(flags, get_order(c->size), node);
82435 + struct page *sp;
82436 +
82437 + sp = slob_new_pages(flags, get_order(c->size), node);
82438 + if (sp) {
82439 + b = page_address(sp);
82440 + sp->private = c->size;
82441 + }
82442 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
82443 PAGE_SIZE << get_order(c->size),
82444 flags, node);
82445 }
82446 +#endif
82447
82448 if (c->ctor)
82449 c->ctor(b);
82450 @@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
82451
82452 static void __kmem_cache_free(void *b, int size)
82453 {
82454 - if (size < PAGE_SIZE)
82455 + struct page *sp;
82456 +
82457 + sp = virt_to_page(b);
82458 + BUG_ON(!PageSlab(sp));
82459 + if (!sp->private)
82460 slob_free(b, size);
82461 else
82462 - slob_free_pages(b, get_order(size));
82463 + slob_free_pages(sp, get_order(size));
82464 }
82465
82466 static void kmem_rcu_free(struct rcu_head *head)
82467 @@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
82468
82469 void kmem_cache_free(struct kmem_cache *c, void *b)
82470 {
82471 + int size = c->size;
82472 +
82473 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82474 + if (size + c->align < PAGE_SIZE) {
82475 + size += c->align;
82476 + b -= c->align;
82477 + }
82478 +#endif
82479 +
82480 kmemleak_free_recursive(b, c->flags);
82481 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
82482 struct slob_rcu *slob_rcu;
82483 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
82484 - slob_rcu->size = c->size;
82485 + slob_rcu = b + (size - sizeof(struct slob_rcu));
82486 + slob_rcu->size = size;
82487 call_rcu(&slob_rcu->head, kmem_rcu_free);
82488 } else {
82489 - __kmem_cache_free(b, c->size);
82490 + __kmem_cache_free(b, size);
82491 }
82492
82493 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82494 + trace_kfree(_RET_IP_, b);
82495 +#else
82496 trace_kmem_cache_free(_RET_IP_, b);
82497 +#endif
82498 +
82499 }
82500 EXPORT_SYMBOL(kmem_cache_free);
82501
82502 diff --git a/mm/slub.c b/mm/slub.c
82503 index ba2ca53..00b1f4e 100644
82504 --- a/mm/slub.c
82505 +++ b/mm/slub.c
82506 @@ -197,7 +197,7 @@ struct track {
82507
82508 enum track_item { TRACK_ALLOC, TRACK_FREE };
82509
82510 -#ifdef CONFIG_SYSFS
82511 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82512 static int sysfs_slab_add(struct kmem_cache *);
82513 static int sysfs_slab_alias(struct kmem_cache *, const char *);
82514 static void sysfs_slab_remove(struct kmem_cache *);
82515 @@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
82516 if (!t->addr)
82517 return;
82518
82519 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
82520 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
82521 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
82522 #ifdef CONFIG_STACKTRACE
82523 {
82524 @@ -2653,7 +2653,7 @@ static int slub_min_objects;
82525 * Merge control. If this is set then no merging of slab caches will occur.
82526 * (Could be removed. This was introduced to pacify the merge skeptics.)
82527 */
82528 -static int slub_nomerge;
82529 +static int slub_nomerge = 1;
82530
82531 /*
82532 * Calculate the order of allocation given an slab object size.
82533 @@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
82534 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
82535 #endif
82536
82537 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82538 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
82539 +#endif
82540 +
82541 static int __init setup_slub_min_order(char *str)
82542 {
82543 get_option(&str, &slub_min_order);
82544 @@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
82545 return kmalloc_dma_caches[index];
82546
82547 #endif
82548 +
82549 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82550 + if (flags & SLAB_USERCOPY)
82551 + return kmalloc_usercopy_caches[index];
82552 +
82553 +#endif
82554 +
82555 return kmalloc_caches[index];
82556 }
82557
82558 @@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
82559 EXPORT_SYMBOL(__kmalloc_node);
82560 #endif
82561
82562 +bool is_usercopy_object(const void *ptr)
82563 +{
82564 + struct page *page;
82565 + struct kmem_cache *s;
82566 +
82567 + if (ZERO_OR_NULL_PTR(ptr))
82568 + return false;
82569 +
82570 + if (!slab_is_available())
82571 + return false;
82572 +
82573 + if (!virt_addr_valid(ptr))
82574 + return false;
82575 +
82576 + page = virt_to_head_page(ptr);
82577 +
82578 + if (!PageSlab(page))
82579 + return false;
82580 +
82581 + s = page->slab_cache;
82582 + return s->flags & SLAB_USERCOPY;
82583 +}
82584 +
82585 +#ifdef CONFIG_PAX_USERCOPY
82586 +const char *check_heap_object(const void *ptr, unsigned long n)
82587 +{
82588 + struct page *page;
82589 + struct kmem_cache *s;
82590 + unsigned long offset;
82591 +
82592 + if (ZERO_OR_NULL_PTR(ptr))
82593 + return "<null>";
82594 +
82595 + if (!virt_addr_valid(ptr))
82596 + return NULL;
82597 +
82598 + page = virt_to_head_page(ptr);
82599 +
82600 + if (!PageSlab(page))
82601 + return NULL;
82602 +
82603 + s = page->slab_cache;
82604 + if (!(s->flags & SLAB_USERCOPY))
82605 + return s->name;
82606 +
82607 + offset = (ptr - page_address(page)) % s->size;
82608 + if (offset <= s->object_size && n <= s->object_size - offset)
82609 + return NULL;
82610 +
82611 + return s->name;
82612 +}
82613 +#endif
82614 +
82615 size_t ksize(const void *object)
82616 {
82617 struct page *page;
82618 @@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
82619
82620 /* Caches that are not of the two-to-the-power-of size */
82621 if (KMALLOC_MIN_SIZE <= 32) {
82622 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
82623 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
82624 caches++;
82625 }
82626
82627 if (KMALLOC_MIN_SIZE <= 64) {
82628 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
82629 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
82630 caches++;
82631 }
82632
82633 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
82634 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
82635 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
82636 caches++;
82637 }
82638
82639 @@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
82640 }
82641 }
82642 #endif
82643 +
82644 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82645 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
82646 + struct kmem_cache *s = kmalloc_caches[i];
82647 +
82648 + if (s && s->size) {
82649 + char *name = kasprintf(GFP_NOWAIT,
82650 + "usercopy-kmalloc-%d", s->object_size);
82651 +
82652 + BUG_ON(!name);
82653 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
82654 + s->object_size, SLAB_USERCOPY);
82655 + }
82656 + }
82657 +#endif
82658 +
82659 printk(KERN_INFO
82660 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
82661 " CPUs=%d, Nodes=%d\n",
82662 @@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
82663 /*
82664 * We may have set a slab to be unmergeable during bootstrap.
82665 */
82666 - if (s->refcount < 0)
82667 + if (atomic_read(&s->refcount) < 0)
82668 return 1;
82669
82670 return 0;
82671 @@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82672
82673 s = find_mergeable(memcg, size, align, flags, name, ctor);
82674 if (s) {
82675 - s->refcount++;
82676 + atomic_inc(&s->refcount);
82677 /*
82678 * Adjust the object sizes so that we clear
82679 * the complete object on kzalloc.
82680 @@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82681 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
82682
82683 if (sysfs_slab_alias(s, name)) {
82684 - s->refcount--;
82685 + atomic_dec(&s->refcount);
82686 s = NULL;
82687 }
82688 }
82689 @@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
82690 return NOTIFY_OK;
82691 }
82692
82693 -static struct notifier_block __cpuinitdata slab_notifier = {
82694 +static struct notifier_block slab_notifier = {
82695 .notifier_call = slab_cpuup_callback
82696 };
82697
82698 @@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
82699 }
82700 #endif
82701
82702 -#ifdef CONFIG_SYSFS
82703 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82704 static int count_inuse(struct page *page)
82705 {
82706 return page->inuse;
82707 @@ -4364,12 +4444,12 @@ static void resiliency_test(void)
82708 validate_slab_cache(kmalloc_caches[9]);
82709 }
82710 #else
82711 -#ifdef CONFIG_SYSFS
82712 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82713 static void resiliency_test(void) {};
82714 #endif
82715 #endif
82716
82717 -#ifdef CONFIG_SYSFS
82718 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82719 enum slab_stat_type {
82720 SL_ALL, /* All slabs */
82721 SL_PARTIAL, /* Only partially allocated slabs */
82722 @@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
82723
82724 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
82725 {
82726 - return sprintf(buf, "%d\n", s->refcount - 1);
82727 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
82728 }
82729 SLAB_ATTR_RO(aliases);
82730
82731 @@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
82732 return name;
82733 }
82734
82735 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82736 static int sysfs_slab_add(struct kmem_cache *s)
82737 {
82738 int err;
82739 @@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
82740 kobject_del(&s->kobj);
82741 kobject_put(&s->kobj);
82742 }
82743 +#endif
82744
82745 /*
82746 * Need to buffer aliases during bootup until sysfs becomes
82747 @@ -5336,6 +5418,7 @@ struct saved_alias {
82748
82749 static struct saved_alias *alias_list;
82750
82751 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82752 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
82753 {
82754 struct saved_alias *al;
82755 @@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
82756 alias_list = al;
82757 return 0;
82758 }
82759 +#endif
82760
82761 static int __init slab_sysfs_init(void)
82762 {
82763 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
82764 index 1b7e22a..3fcd4f3 100644
82765 --- a/mm/sparse-vmemmap.c
82766 +++ b/mm/sparse-vmemmap.c
82767 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
82768 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
82769 if (!p)
82770 return NULL;
82771 - pud_populate(&init_mm, pud, p);
82772 + pud_populate_kernel(&init_mm, pud, p);
82773 }
82774 return pud;
82775 }
82776 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
82777 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
82778 if (!p)
82779 return NULL;
82780 - pgd_populate(&init_mm, pgd, p);
82781 + pgd_populate_kernel(&init_mm, pgd, p);
82782 }
82783 return pgd;
82784 }
82785 diff --git a/mm/sparse.c b/mm/sparse.c
82786 index 6b5fb76..db0c190 100644
82787 --- a/mm/sparse.c
82788 +++ b/mm/sparse.c
82789 @@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
82790
82791 for (i = 0; i < PAGES_PER_SECTION; i++) {
82792 if (PageHWPoison(&memmap[i])) {
82793 - atomic_long_sub(1, &mce_bad_pages);
82794 + atomic_long_sub_unchecked(1, &mce_bad_pages);
82795 ClearPageHWPoison(&memmap[i]);
82796 }
82797 }
82798 diff --git a/mm/swap.c b/mm/swap.c
82799 index 6310dc2..3662b3f 100644
82800 --- a/mm/swap.c
82801 +++ b/mm/swap.c
82802 @@ -30,6 +30,7 @@
82803 #include <linux/backing-dev.h>
82804 #include <linux/memcontrol.h>
82805 #include <linux/gfp.h>
82806 +#include <linux/hugetlb.h>
82807
82808 #include "internal.h"
82809
82810 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
82811
82812 __page_cache_release(page);
82813 dtor = get_compound_page_dtor(page);
82814 + if (!PageHuge(page))
82815 + BUG_ON(dtor != free_compound_page);
82816 (*dtor)(page);
82817 }
82818
82819 diff --git a/mm/swapfile.c b/mm/swapfile.c
82820 index e97a0e5..b50e796 100644
82821 --- a/mm/swapfile.c
82822 +++ b/mm/swapfile.c
82823 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
82824
82825 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
82826 /* Activity counter to indicate that a swapon or swapoff has occurred */
82827 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
82828 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
82829
82830 static inline unsigned char swap_count(unsigned char ent)
82831 {
82832 @@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
82833 }
82834 filp_close(swap_file, NULL);
82835 err = 0;
82836 - atomic_inc(&proc_poll_event);
82837 + atomic_inc_unchecked(&proc_poll_event);
82838 wake_up_interruptible(&proc_poll_wait);
82839
82840 out_dput:
82841 @@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
82842
82843 poll_wait(file, &proc_poll_wait, wait);
82844
82845 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
82846 - seq->poll_event = atomic_read(&proc_poll_event);
82847 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
82848 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
82849 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
82850 }
82851
82852 @@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
82853 return ret;
82854
82855 seq = file->private_data;
82856 - seq->poll_event = atomic_read(&proc_poll_event);
82857 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
82858 return 0;
82859 }
82860
82861 @@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
82862 (frontswap_map) ? "FS" : "");
82863
82864 mutex_unlock(&swapon_mutex);
82865 - atomic_inc(&proc_poll_event);
82866 + atomic_inc_unchecked(&proc_poll_event);
82867 wake_up_interruptible(&proc_poll_wait);
82868
82869 if (S_ISREG(inode->i_mode))
82870 diff --git a/mm/util.c b/mm/util.c
82871 index c55e26b..3f913a9 100644
82872 --- a/mm/util.c
82873 +++ b/mm/util.c
82874 @@ -292,6 +292,12 @@ done:
82875 void arch_pick_mmap_layout(struct mm_struct *mm)
82876 {
82877 mm->mmap_base = TASK_UNMAPPED_BASE;
82878 +
82879 +#ifdef CONFIG_PAX_RANDMMAP
82880 + if (mm->pax_flags & MF_PAX_RANDMMAP)
82881 + mm->mmap_base += mm->delta_mmap;
82882 +#endif
82883 +
82884 mm->get_unmapped_area = arch_get_unmapped_area;
82885 mm->unmap_area = arch_unmap_area;
82886 }
82887 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
82888 index 5123a16..f234a48 100644
82889 --- a/mm/vmalloc.c
82890 +++ b/mm/vmalloc.c
82891 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
82892
82893 pte = pte_offset_kernel(pmd, addr);
82894 do {
82895 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
82896 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
82897 +
82898 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82899 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
82900 + BUG_ON(!pte_exec(*pte));
82901 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
82902 + continue;
82903 + }
82904 +#endif
82905 +
82906 + {
82907 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
82908 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
82909 + }
82910 } while (pte++, addr += PAGE_SIZE, addr != end);
82911 }
82912
82913 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
82914 pte = pte_alloc_kernel(pmd, addr);
82915 if (!pte)
82916 return -ENOMEM;
82917 +
82918 + pax_open_kernel();
82919 do {
82920 struct page *page = pages[*nr];
82921
82922 - if (WARN_ON(!pte_none(*pte)))
82923 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82924 + if (pgprot_val(prot) & _PAGE_NX)
82925 +#endif
82926 +
82927 + if (!pte_none(*pte)) {
82928 + pax_close_kernel();
82929 + WARN_ON(1);
82930 return -EBUSY;
82931 - if (WARN_ON(!page))
82932 + }
82933 + if (!page) {
82934 + pax_close_kernel();
82935 + WARN_ON(1);
82936 return -ENOMEM;
82937 + }
82938 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
82939 (*nr)++;
82940 } while (pte++, addr += PAGE_SIZE, addr != end);
82941 + pax_close_kernel();
82942 return 0;
82943 }
82944
82945 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
82946 pmd_t *pmd;
82947 unsigned long next;
82948
82949 - pmd = pmd_alloc(&init_mm, pud, addr);
82950 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
82951 if (!pmd)
82952 return -ENOMEM;
82953 do {
82954 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
82955 pud_t *pud;
82956 unsigned long next;
82957
82958 - pud = pud_alloc(&init_mm, pgd, addr);
82959 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
82960 if (!pud)
82961 return -ENOMEM;
82962 do {
82963 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
82964 * and fall back on vmalloc() if that fails. Others
82965 * just put it in the vmalloc space.
82966 */
82967 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
82968 +#ifdef CONFIG_MODULES
82969 +#ifdef MODULES_VADDR
82970 unsigned long addr = (unsigned long)x;
82971 if (addr >= MODULES_VADDR && addr < MODULES_END)
82972 return 1;
82973 #endif
82974 +
82975 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
82976 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
82977 + return 1;
82978 +#endif
82979 +
82980 +#endif
82981 +
82982 return is_vmalloc_addr(x);
82983 }
82984
82985 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
82986
82987 if (!pgd_none(*pgd)) {
82988 pud_t *pud = pud_offset(pgd, addr);
82989 +#ifdef CONFIG_X86
82990 + if (!pud_large(*pud))
82991 +#endif
82992 if (!pud_none(*pud)) {
82993 pmd_t *pmd = pmd_offset(pud, addr);
82994 +#ifdef CONFIG_X86
82995 + if (!pmd_large(*pmd))
82996 +#endif
82997 if (!pmd_none(*pmd)) {
82998 pte_t *ptep, pte;
82999
83000 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
83001 * Allocate a region of KVA of the specified size and alignment, within the
83002 * vstart and vend.
83003 */
83004 -static struct vmap_area *alloc_vmap_area(unsigned long size,
83005 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
83006 unsigned long align,
83007 unsigned long vstart, unsigned long vend,
83008 int node, gfp_t gfp_mask)
83009 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
83010 struct vm_struct *area;
83011
83012 BUG_ON(in_interrupt());
83013 +
83014 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83015 + if (flags & VM_KERNEXEC) {
83016 + if (start != VMALLOC_START || end != VMALLOC_END)
83017 + return NULL;
83018 + start = (unsigned long)MODULES_EXEC_VADDR;
83019 + end = (unsigned long)MODULES_EXEC_END;
83020 + }
83021 +#endif
83022 +
83023 if (flags & VM_IOREMAP) {
83024 int bit = fls(size);
83025
83026 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
83027 if (count > totalram_pages)
83028 return NULL;
83029
83030 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83031 + if (!(pgprot_val(prot) & _PAGE_NX))
83032 + flags |= VM_KERNEXEC;
83033 +#endif
83034 +
83035 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
83036 __builtin_return_address(0));
83037 if (!area)
83038 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
83039 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
83040 goto fail;
83041
83042 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83043 + if (!(pgprot_val(prot) & _PAGE_NX))
83044 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
83045 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
83046 + else
83047 +#endif
83048 +
83049 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
83050 start, end, node, gfp_mask, caller);
83051 if (!area)
83052 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
83053 * For tight control over page level allocator and protection flags
83054 * use __vmalloc() instead.
83055 */
83056 -
83057 void *vmalloc_exec(unsigned long size)
83058 {
83059 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
83060 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
83061 -1, __builtin_return_address(0));
83062 }
83063
83064 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
83065 unsigned long uaddr = vma->vm_start;
83066 unsigned long usize = vma->vm_end - vma->vm_start;
83067
83068 + BUG_ON(vma->vm_mirror);
83069 +
83070 if ((PAGE_SIZE-1) & (unsigned long)addr)
83071 return -EINVAL;
83072
83073 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
83074 v->addr, v->addr + v->size, v->size);
83075
83076 if (v->caller)
83077 +#ifdef CONFIG_GRKERNSEC_HIDESYM
83078 + seq_printf(m, " %pK", v->caller);
83079 +#else
83080 seq_printf(m, " %pS", v->caller);
83081 +#endif
83082
83083 if (v->nr_pages)
83084 seq_printf(m, " pages=%d", v->nr_pages);
83085 diff --git a/mm/vmstat.c b/mm/vmstat.c
83086 index 9800306..76b4b27 100644
83087 --- a/mm/vmstat.c
83088 +++ b/mm/vmstat.c
83089 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
83090 *
83091 * vm_stat contains the global counters
83092 */
83093 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
83094 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
83095 EXPORT_SYMBOL(vm_stat);
83096
83097 #ifdef CONFIG_SMP
83098 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
83099 v = p->vm_stat_diff[i];
83100 p->vm_stat_diff[i] = 0;
83101 local_irq_restore(flags);
83102 - atomic_long_add(v, &zone->vm_stat[i]);
83103 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
83104 global_diff[i] += v;
83105 #ifdef CONFIG_NUMA
83106 /* 3 seconds idle till flush */
83107 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
83108
83109 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
83110 if (global_diff[i])
83111 - atomic_long_add(global_diff[i], &vm_stat[i]);
83112 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
83113 }
83114
83115 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
83116 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
83117 if (pset->vm_stat_diff[i]) {
83118 int v = pset->vm_stat_diff[i];
83119 pset->vm_stat_diff[i] = 0;
83120 - atomic_long_add(v, &zone->vm_stat[i]);
83121 - atomic_long_add(v, &vm_stat[i]);
83122 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
83123 + atomic_long_add_unchecked(v, &vm_stat[i]);
83124 }
83125 }
83126 #endif
83127 @@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
83128 return NOTIFY_OK;
83129 }
83130
83131 -static struct notifier_block __cpuinitdata vmstat_notifier =
83132 +static struct notifier_block vmstat_notifier =
83133 { &vmstat_cpuup_callback, NULL, 0 };
83134 #endif
83135
83136 @@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
83137 start_cpu_timer(cpu);
83138 #endif
83139 #ifdef CONFIG_PROC_FS
83140 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
83141 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
83142 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
83143 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
83144 + {
83145 + mode_t gr_mode = S_IRUGO;
83146 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
83147 + gr_mode = S_IRUSR;
83148 +#endif
83149 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
83150 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
83151 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83152 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
83153 +#else
83154 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
83155 +#endif
83156 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
83157 + }
83158 #endif
83159 return 0;
83160 }
83161 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
83162 index a292e80..785ee68 100644
83163 --- a/net/8021q/vlan.c
83164 +++ b/net/8021q/vlan.c
83165 @@ -485,7 +485,7 @@ out:
83166 return NOTIFY_DONE;
83167 }
83168
83169 -static struct notifier_block vlan_notifier_block __read_mostly = {
83170 +static struct notifier_block vlan_notifier_block = {
83171 .notifier_call = vlan_device_event,
83172 };
83173
83174 @@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
83175 err = -EPERM;
83176 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
83177 break;
83178 - if ((args.u.name_type >= 0) &&
83179 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
83180 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
83181 struct vlan_net *vn;
83182
83183 vn = net_generic(net, vlan_net_id);
83184 diff --git a/net/9p/mod.c b/net/9p/mod.c
83185 index 6ab36ae..6f1841b 100644
83186 --- a/net/9p/mod.c
83187 +++ b/net/9p/mod.c
83188 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
83189 void v9fs_register_trans(struct p9_trans_module *m)
83190 {
83191 spin_lock(&v9fs_trans_lock);
83192 - list_add_tail(&m->list, &v9fs_trans_list);
83193 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
83194 spin_unlock(&v9fs_trans_lock);
83195 }
83196 EXPORT_SYMBOL(v9fs_register_trans);
83197 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
83198 void v9fs_unregister_trans(struct p9_trans_module *m)
83199 {
83200 spin_lock(&v9fs_trans_lock);
83201 - list_del_init(&m->list);
83202 + pax_list_del_init((struct list_head *)&m->list);
83203 spin_unlock(&v9fs_trans_lock);
83204 }
83205 EXPORT_SYMBOL(v9fs_unregister_trans);
83206 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
83207 index 02efb25..41541a9 100644
83208 --- a/net/9p/trans_fd.c
83209 +++ b/net/9p/trans_fd.c
83210 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
83211 oldfs = get_fs();
83212 set_fs(get_ds());
83213 /* The cast to a user pointer is valid due to the set_fs() */
83214 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
83215 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
83216 set_fs(oldfs);
83217
83218 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
83219 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
83220 index 876fbe8..8bbea9f 100644
83221 --- a/net/atm/atm_misc.c
83222 +++ b/net/atm/atm_misc.c
83223 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
83224 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
83225 return 1;
83226 atm_return(vcc, truesize);
83227 - atomic_inc(&vcc->stats->rx_drop);
83228 + atomic_inc_unchecked(&vcc->stats->rx_drop);
83229 return 0;
83230 }
83231 EXPORT_SYMBOL(atm_charge);
83232 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
83233 }
83234 }
83235 atm_return(vcc, guess);
83236 - atomic_inc(&vcc->stats->rx_drop);
83237 + atomic_inc_unchecked(&vcc->stats->rx_drop);
83238 return NULL;
83239 }
83240 EXPORT_SYMBOL(atm_alloc_charge);
83241 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
83242
83243 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
83244 {
83245 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
83246 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
83247 __SONET_ITEMS
83248 #undef __HANDLE_ITEM
83249 }
83250 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
83251
83252 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
83253 {
83254 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
83255 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
83256 __SONET_ITEMS
83257 #undef __HANDLE_ITEM
83258 }
83259 diff --git a/net/atm/lec.h b/net/atm/lec.h
83260 index a86aff9..3a0d6f6 100644
83261 --- a/net/atm/lec.h
83262 +++ b/net/atm/lec.h
83263 @@ -48,7 +48,7 @@ struct lane2_ops {
83264 const u8 *tlvs, u32 sizeoftlvs);
83265 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
83266 const u8 *tlvs, u32 sizeoftlvs);
83267 -};
83268 +} __no_const;
83269
83270 /*
83271 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
83272 diff --git a/net/atm/proc.c b/net/atm/proc.c
83273 index 0d020de..011c7bb 100644
83274 --- a/net/atm/proc.c
83275 +++ b/net/atm/proc.c
83276 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
83277 const struct k_atm_aal_stats *stats)
83278 {
83279 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
83280 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
83281 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
83282 - atomic_read(&stats->rx_drop));
83283 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
83284 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
83285 + atomic_read_unchecked(&stats->rx_drop));
83286 }
83287
83288 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
83289 diff --git a/net/atm/resources.c b/net/atm/resources.c
83290 index 0447d5d..3cf4728 100644
83291 --- a/net/atm/resources.c
83292 +++ b/net/atm/resources.c
83293 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
83294 static void copy_aal_stats(struct k_atm_aal_stats *from,
83295 struct atm_aal_stats *to)
83296 {
83297 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
83298 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
83299 __AAL_STAT_ITEMS
83300 #undef __HANDLE_ITEM
83301 }
83302 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
83303 static void subtract_aal_stats(struct k_atm_aal_stats *from,
83304 struct atm_aal_stats *to)
83305 {
83306 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
83307 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
83308 __AAL_STAT_ITEMS
83309 #undef __HANDLE_ITEM
83310 }
83311 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
83312 index d5744b7..506bae3 100644
83313 --- a/net/ax25/sysctl_net_ax25.c
83314 +++ b/net/ax25/sysctl_net_ax25.c
83315 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
83316 {
83317 char path[sizeof("net/ax25/") + IFNAMSIZ];
83318 int k;
83319 - struct ctl_table *table;
83320 + ctl_table_no_const *table;
83321
83322 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
83323 if (!table)
83324 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
83325 index 7d02ebd..4d4cc01 100644
83326 --- a/net/batman-adv/bat_iv_ogm.c
83327 +++ b/net/batman-adv/bat_iv_ogm.c
83328 @@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
83329
83330 /* randomize initial seqno to avoid collision */
83331 get_random_bytes(&random_seqno, sizeof(random_seqno));
83332 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
83333 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
83334
83335 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
83336 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
83337 @@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
83338 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
83339
83340 /* change sequence number to network order */
83341 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
83342 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
83343 batadv_ogm_packet->seqno = htonl(seqno);
83344 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
83345 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
83346
83347 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
83348 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
83349 @@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
83350 return;
83351
83352 /* could be changed by schedule_own_packet() */
83353 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
83354 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
83355
83356 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
83357 has_directlink_flag = 1;
83358 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
83359 index f1d37cd..4190879 100644
83360 --- a/net/batman-adv/hard-interface.c
83361 +++ b/net/batman-adv/hard-interface.c
83362 @@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
83363 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
83364 dev_add_pack(&hard_iface->batman_adv_ptype);
83365
83366 - atomic_set(&hard_iface->frag_seqno, 1);
83367 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
83368 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
83369 hard_iface->net_dev->name);
83370
83371 @@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
83372 /* This can't be called via a bat_priv callback because
83373 * we have no bat_priv yet.
83374 */
83375 - atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
83376 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
83377 hard_iface->bat_iv.ogm_buff = NULL;
83378
83379 return hard_iface;
83380 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
83381 index 6b548fd..fc32c8d 100644
83382 --- a/net/batman-adv/soft-interface.c
83383 +++ b/net/batman-adv/soft-interface.c
83384 @@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
83385 primary_if->net_dev->dev_addr, ETH_ALEN);
83386
83387 /* set broadcast sequence number */
83388 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
83389 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
83390 bcast_packet->seqno = htonl(seqno);
83391
83392 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
83393 @@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
83394 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
83395
83396 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
83397 - atomic_set(&bat_priv->bcast_seqno, 1);
83398 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
83399 atomic_set(&bat_priv->tt.vn, 0);
83400 atomic_set(&bat_priv->tt.local_changes, 0);
83401 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
83402 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
83403 index ae9ac9a..11e0fe7 100644
83404 --- a/net/batman-adv/types.h
83405 +++ b/net/batman-adv/types.h
83406 @@ -48,7 +48,7 @@
83407 struct batadv_hard_iface_bat_iv {
83408 unsigned char *ogm_buff;
83409 int ogm_buff_len;
83410 - atomic_t ogm_seqno;
83411 + atomic_unchecked_t ogm_seqno;
83412 };
83413
83414 struct batadv_hard_iface {
83415 @@ -56,7 +56,7 @@ struct batadv_hard_iface {
83416 int16_t if_num;
83417 char if_status;
83418 struct net_device *net_dev;
83419 - atomic_t frag_seqno;
83420 + atomic_unchecked_t frag_seqno;
83421 struct kobject *hardif_obj;
83422 atomic_t refcount;
83423 struct packet_type batman_adv_ptype;
83424 @@ -284,7 +284,7 @@ struct batadv_priv {
83425 atomic_t orig_interval; /* uint */
83426 atomic_t hop_penalty; /* uint */
83427 atomic_t log_level; /* uint */
83428 - atomic_t bcast_seqno;
83429 + atomic_unchecked_t bcast_seqno;
83430 atomic_t bcast_queue_left;
83431 atomic_t batman_queue_left;
83432 char num_ifaces;
83433 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
83434 index 10aff49..ea8e021 100644
83435 --- a/net/batman-adv/unicast.c
83436 +++ b/net/batman-adv/unicast.c
83437 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
83438 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
83439 frag2->flags = large_tail;
83440
83441 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
83442 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
83443 frag1->seqno = htons(seqno - 1);
83444 frag2->seqno = htons(seqno);
83445
83446 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
83447 index 07f0739..3c42e34 100644
83448 --- a/net/bluetooth/hci_sock.c
83449 +++ b/net/bluetooth/hci_sock.c
83450 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
83451 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
83452 }
83453
83454 - len = min_t(unsigned int, len, sizeof(uf));
83455 + len = min((size_t)len, sizeof(uf));
83456 if (copy_from_user(&uf, optval, len)) {
83457 err = -EFAULT;
83458 break;
83459 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
83460 index 22e6583..426e2f3 100644
83461 --- a/net/bluetooth/l2cap_core.c
83462 +++ b/net/bluetooth/l2cap_core.c
83463 @@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
83464 break;
83465
83466 case L2CAP_CONF_RFC:
83467 - if (olen == sizeof(rfc))
83468 - memcpy(&rfc, (void *)val, olen);
83469 + if (olen != sizeof(rfc))
83470 + break;
83471 +
83472 + memcpy(&rfc, (void *)val, olen);
83473
83474 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
83475 rfc.mode != chan->mode)
83476 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
83477 index 1bcfb84..dad9f98 100644
83478 --- a/net/bluetooth/l2cap_sock.c
83479 +++ b/net/bluetooth/l2cap_sock.c
83480 @@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
83481 struct sock *sk = sock->sk;
83482 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
83483 struct l2cap_options opts;
83484 - int len, err = 0;
83485 + int err = 0;
83486 + size_t len = optlen;
83487 u32 opt;
83488
83489 BT_DBG("sk %p", sk);
83490 @@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
83491 opts.max_tx = chan->max_tx;
83492 opts.txwin_size = chan->tx_win;
83493
83494 - len = min_t(unsigned int, sizeof(opts), optlen);
83495 + len = min(sizeof(opts), len);
83496 if (copy_from_user((char *) &opts, optval, len)) {
83497 err = -EFAULT;
83498 break;
83499 @@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83500 struct bt_security sec;
83501 struct bt_power pwr;
83502 struct l2cap_conn *conn;
83503 - int len, err = 0;
83504 + int err = 0;
83505 + size_t len = optlen;
83506 u32 opt;
83507
83508 BT_DBG("sk %p", sk);
83509 @@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83510
83511 sec.level = BT_SECURITY_LOW;
83512
83513 - len = min_t(unsigned int, sizeof(sec), optlen);
83514 + len = min(sizeof(sec), len);
83515 if (copy_from_user((char *) &sec, optval, len)) {
83516 err = -EFAULT;
83517 break;
83518 @@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83519
83520 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
83521
83522 - len = min_t(unsigned int, sizeof(pwr), optlen);
83523 + len = min(sizeof(pwr), len);
83524 if (copy_from_user((char *) &pwr, optval, len)) {
83525 err = -EFAULT;
83526 break;
83527 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
83528 index ce3f665..2c7d08f 100644
83529 --- a/net/bluetooth/rfcomm/sock.c
83530 +++ b/net/bluetooth/rfcomm/sock.c
83531 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
83532 struct sock *sk = sock->sk;
83533 struct bt_security sec;
83534 int err = 0;
83535 - size_t len;
83536 + size_t len = optlen;
83537 u32 opt;
83538
83539 BT_DBG("sk %p", sk);
83540 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
83541
83542 sec.level = BT_SECURITY_LOW;
83543
83544 - len = min_t(unsigned int, sizeof(sec), optlen);
83545 + len = min(sizeof(sec), len);
83546 if (copy_from_user((char *) &sec, optval, len)) {
83547 err = -EFAULT;
83548 break;
83549 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
83550 index bd6fd0f..6492cba 100644
83551 --- a/net/bluetooth/rfcomm/tty.c
83552 +++ b/net/bluetooth/rfcomm/tty.c
83553 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
83554 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
83555
83556 spin_lock_irqsave(&dev->port.lock, flags);
83557 - if (dev->port.count > 0) {
83558 + if (atomic_read(&dev->port.count) > 0) {
83559 spin_unlock_irqrestore(&dev->port.lock, flags);
83560 return;
83561 }
83562 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
83563 return -ENODEV;
83564
83565 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
83566 - dev->channel, dev->port.count);
83567 + dev->channel, atomic_read(&dev->port.count));
83568
83569 spin_lock_irqsave(&dev->port.lock, flags);
83570 - if (++dev->port.count > 1) {
83571 + if (atomic_inc_return(&dev->port.count) > 1) {
83572 spin_unlock_irqrestore(&dev->port.lock, flags);
83573 return 0;
83574 }
83575 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
83576 return;
83577
83578 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
83579 - dev->port.count);
83580 + atomic_read(&dev->port.count));
83581
83582 spin_lock_irqsave(&dev->port.lock, flags);
83583 - if (!--dev->port.count) {
83584 + if (!atomic_dec_return(&dev->port.count)) {
83585 spin_unlock_irqrestore(&dev->port.lock, flags);
83586 if (dev->tty_dev->parent)
83587 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
83588 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
83589 index 5fe2ff3..121d696 100644
83590 --- a/net/bridge/netfilter/ebtables.c
83591 +++ b/net/bridge/netfilter/ebtables.c
83592 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
83593 tmp.valid_hooks = t->table->valid_hooks;
83594 }
83595 mutex_unlock(&ebt_mutex);
83596 - if (copy_to_user(user, &tmp, *len) != 0){
83597 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
83598 BUGPRINT("c2u Didn't work\n");
83599 ret = -EFAULT;
83600 break;
83601 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
83602 goto out;
83603 tmp.valid_hooks = t->valid_hooks;
83604
83605 - if (copy_to_user(user, &tmp, *len) != 0) {
83606 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
83607 ret = -EFAULT;
83608 break;
83609 }
83610 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
83611 tmp.entries_size = t->table->entries_size;
83612 tmp.valid_hooks = t->table->valid_hooks;
83613
83614 - if (copy_to_user(user, &tmp, *len) != 0) {
83615 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
83616 ret = -EFAULT;
83617 break;
83618 }
83619 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
83620 index a376ec1..1fbd6be 100644
83621 --- a/net/caif/cfctrl.c
83622 +++ b/net/caif/cfctrl.c
83623 @@ -10,6 +10,7 @@
83624 #include <linux/spinlock.h>
83625 #include <linux/slab.h>
83626 #include <linux/pkt_sched.h>
83627 +#include <linux/sched.h>
83628 #include <net/caif/caif_layer.h>
83629 #include <net/caif/cfpkt.h>
83630 #include <net/caif/cfctrl.h>
83631 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
83632 memset(&dev_info, 0, sizeof(dev_info));
83633 dev_info.id = 0xff;
83634 cfsrvl_init(&this->serv, 0, &dev_info, false);
83635 - atomic_set(&this->req_seq_no, 1);
83636 - atomic_set(&this->rsp_seq_no, 1);
83637 + atomic_set_unchecked(&this->req_seq_no, 1);
83638 + atomic_set_unchecked(&this->rsp_seq_no, 1);
83639 this->serv.layer.receive = cfctrl_recv;
83640 sprintf(this->serv.layer.name, "ctrl");
83641 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
83642 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
83643 struct cfctrl_request_info *req)
83644 {
83645 spin_lock_bh(&ctrl->info_list_lock);
83646 - atomic_inc(&ctrl->req_seq_no);
83647 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
83648 + atomic_inc_unchecked(&ctrl->req_seq_no);
83649 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
83650 list_add_tail(&req->list, &ctrl->list);
83651 spin_unlock_bh(&ctrl->info_list_lock);
83652 }
83653 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
83654 if (p != first)
83655 pr_warn("Requests are not received in order\n");
83656
83657 - atomic_set(&ctrl->rsp_seq_no,
83658 + atomic_set_unchecked(&ctrl->rsp_seq_no,
83659 p->sequence_no);
83660 list_del(&p->list);
83661 goto out;
83662 diff --git a/net/can/af_can.c b/net/can/af_can.c
83663 index ddac1ee..3ee0a78 100644
83664 --- a/net/can/af_can.c
83665 +++ b/net/can/af_can.c
83666 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
83667 };
83668
83669 /* notifier block for netdevice event */
83670 -static struct notifier_block can_netdev_notifier __read_mostly = {
83671 +static struct notifier_block can_netdev_notifier = {
83672 .notifier_call = can_notifier,
83673 };
83674
83675 diff --git a/net/can/gw.c b/net/can/gw.c
83676 index 574dda78e..3d2b3da 100644
83677 --- a/net/can/gw.c
83678 +++ b/net/can/gw.c
83679 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
83680 MODULE_ALIAS("can-gw");
83681
83682 static HLIST_HEAD(cgw_list);
83683 -static struct notifier_block notifier;
83684
83685 static struct kmem_cache *cgw_cache __read_mostly;
83686
83687 @@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
83688 return err;
83689 }
83690
83691 +static struct notifier_block notifier = {
83692 + .notifier_call = cgw_notifier
83693 +};
83694 +
83695 static __init int cgw_module_init(void)
83696 {
83697 printk(banner);
83698 @@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
83699 return -ENOMEM;
83700
83701 /* set notifier */
83702 - notifier.notifier_call = cgw_notifier;
83703 register_netdevice_notifier(&notifier);
83704
83705 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
83706 diff --git a/net/compat.c b/net/compat.c
83707 index 79ae884..17c5c09 100644
83708 --- a/net/compat.c
83709 +++ b/net/compat.c
83710 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
83711 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
83712 __get_user(kmsg->msg_flags, &umsg->msg_flags))
83713 return -EFAULT;
83714 - kmsg->msg_name = compat_ptr(tmp1);
83715 - kmsg->msg_iov = compat_ptr(tmp2);
83716 - kmsg->msg_control = compat_ptr(tmp3);
83717 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
83718 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
83719 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
83720 return 0;
83721 }
83722
83723 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
83724
83725 if (kern_msg->msg_namelen) {
83726 if (mode == VERIFY_READ) {
83727 - int err = move_addr_to_kernel(kern_msg->msg_name,
83728 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
83729 kern_msg->msg_namelen,
83730 kern_address);
83731 if (err < 0)
83732 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
83733 kern_msg->msg_name = NULL;
83734
83735 tot_len = iov_from_user_compat_to_kern(kern_iov,
83736 - (struct compat_iovec __user *)kern_msg->msg_iov,
83737 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
83738 kern_msg->msg_iovlen);
83739 if (tot_len >= 0)
83740 kern_msg->msg_iov = kern_iov;
83741 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
83742
83743 #define CMSG_COMPAT_FIRSTHDR(msg) \
83744 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
83745 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
83746 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
83747 (struct compat_cmsghdr __user *)NULL)
83748
83749 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
83750 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
83751 (ucmlen) <= (unsigned long) \
83752 ((mhdr)->msg_controllen - \
83753 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
83754 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
83755
83756 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
83757 struct compat_cmsghdr __user *cmsg, int cmsg_len)
83758 {
83759 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
83760 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
83761 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
83762 msg->msg_controllen)
83763 return NULL;
83764 return (struct compat_cmsghdr __user *)ptr;
83765 @@ -219,7 +219,7 @@ Efault:
83766
83767 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
83768 {
83769 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
83770 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
83771 struct compat_cmsghdr cmhdr;
83772 struct compat_timeval ctv;
83773 struct compat_timespec cts[3];
83774 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
83775
83776 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
83777 {
83778 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
83779 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
83780 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
83781 int fdnum = scm->fp->count;
83782 struct file **fp = scm->fp->fp;
83783 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
83784 return -EFAULT;
83785 old_fs = get_fs();
83786 set_fs(KERNEL_DS);
83787 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
83788 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
83789 set_fs(old_fs);
83790
83791 return err;
83792 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
83793 len = sizeof(ktime);
83794 old_fs = get_fs();
83795 set_fs(KERNEL_DS);
83796 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
83797 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
83798 set_fs(old_fs);
83799
83800 if (!err) {
83801 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
83802 case MCAST_JOIN_GROUP:
83803 case MCAST_LEAVE_GROUP:
83804 {
83805 - struct compat_group_req __user *gr32 = (void *)optval;
83806 + struct compat_group_req __user *gr32 = (void __user *)optval;
83807 struct group_req __user *kgr =
83808 compat_alloc_user_space(sizeof(struct group_req));
83809 u32 interface;
83810 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
83811 case MCAST_BLOCK_SOURCE:
83812 case MCAST_UNBLOCK_SOURCE:
83813 {
83814 - struct compat_group_source_req __user *gsr32 = (void *)optval;
83815 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
83816 struct group_source_req __user *kgsr = compat_alloc_user_space(
83817 sizeof(struct group_source_req));
83818 u32 interface;
83819 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
83820 }
83821 case MCAST_MSFILTER:
83822 {
83823 - struct compat_group_filter __user *gf32 = (void *)optval;
83824 + struct compat_group_filter __user *gf32 = (void __user *)optval;
83825 struct group_filter __user *kgf;
83826 u32 interface, fmode, numsrc;
83827
83828 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
83829 char __user *optval, int __user *optlen,
83830 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
83831 {
83832 - struct compat_group_filter __user *gf32 = (void *)optval;
83833 + struct compat_group_filter __user *gf32 = (void __user *)optval;
83834 struct group_filter __user *kgf;
83835 int __user *koptlen;
83836 u32 interface, fmode, numsrc;
83837 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
83838
83839 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
83840 return -EINVAL;
83841 - if (copy_from_user(a, args, nas[call]))
83842 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
83843 return -EFAULT;
83844 a0 = a[0];
83845 a1 = a[1];
83846 diff --git a/net/core/datagram.c b/net/core/datagram.c
83847 index 368f9c3..f82d4a3 100644
83848 --- a/net/core/datagram.c
83849 +++ b/net/core/datagram.c
83850 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
83851 }
83852
83853 kfree_skb(skb);
83854 - atomic_inc(&sk->sk_drops);
83855 + atomic_inc_unchecked(&sk->sk_drops);
83856 sk_mem_reclaim_partial(sk);
83857
83858 return err;
83859 diff --git a/net/core/dev.c b/net/core/dev.c
83860 index f64e439..8f959e6 100644
83861 --- a/net/core/dev.c
83862 +++ b/net/core/dev.c
83863 @@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
83864 if (no_module && capable(CAP_NET_ADMIN))
83865 no_module = request_module("netdev-%s", name);
83866 if (no_module && capable(CAP_SYS_MODULE)) {
83867 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
83868 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
83869 +#else
83870 if (!request_module("%s", name))
83871 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
83872 name);
83873 +#endif
83874 }
83875 }
83876 EXPORT_SYMBOL(dev_load);
83877 @@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
83878 {
83879 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
83880 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
83881 - atomic_long_inc(&dev->rx_dropped);
83882 + atomic_long_inc_unchecked(&dev->rx_dropped);
83883 kfree_skb(skb);
83884 return NET_RX_DROP;
83885 }
83886 @@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
83887 nf_reset(skb);
83888
83889 if (unlikely(!is_skb_forwardable(dev, skb))) {
83890 - atomic_long_inc(&dev->rx_dropped);
83891 + atomic_long_inc_unchecked(&dev->rx_dropped);
83892 kfree_skb(skb);
83893 return NET_RX_DROP;
83894 }
83895 @@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
83896
83897 struct dev_gso_cb {
83898 void (*destructor)(struct sk_buff *skb);
83899 -};
83900 +} __no_const;
83901
83902 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
83903
83904 @@ -3053,7 +3057,7 @@ enqueue:
83905
83906 local_irq_restore(flags);
83907
83908 - atomic_long_inc(&skb->dev->rx_dropped);
83909 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
83910 kfree_skb(skb);
83911 return NET_RX_DROP;
83912 }
83913 @@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
83914 }
83915 EXPORT_SYMBOL(netif_rx_ni);
83916
83917 -static void net_tx_action(struct softirq_action *h)
83918 +static void net_tx_action(void)
83919 {
83920 struct softnet_data *sd = &__get_cpu_var(softnet_data);
83921
83922 @@ -3456,7 +3460,7 @@ ncls:
83923 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
83924 } else {
83925 drop:
83926 - atomic_long_inc(&skb->dev->rx_dropped);
83927 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
83928 kfree_skb(skb);
83929 /* Jamal, now you will not able to escape explaining
83930 * me how you were going to use this. :-)
83931 @@ -4039,7 +4043,7 @@ void netif_napi_del(struct napi_struct *napi)
83932 }
83933 EXPORT_SYMBOL(netif_napi_del);
83934
83935 -static void net_rx_action(struct softirq_action *h)
83936 +static void net_rx_action(void)
83937 {
83938 struct softnet_data *sd = &__get_cpu_var(softnet_data);
83939 unsigned long time_limit = jiffies + 2;
83940 @@ -4523,8 +4527,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
83941 else
83942 seq_printf(seq, "%04x", ntohs(pt->type));
83943
83944 +#ifdef CONFIG_GRKERNSEC_HIDESYM
83945 + seq_printf(seq, " %-8s %p\n",
83946 + pt->dev ? pt->dev->name : "", NULL);
83947 +#else
83948 seq_printf(seq, " %-8s %pF\n",
83949 pt->dev ? pt->dev->name : "", pt->func);
83950 +#endif
83951 }
83952
83953 return 0;
83954 @@ -6096,7 +6105,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
83955 } else {
83956 netdev_stats_to_stats64(storage, &dev->stats);
83957 }
83958 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
83959 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
83960 return storage;
83961 }
83962 EXPORT_SYMBOL(dev_get_stats);
83963 diff --git a/net/core/flow.c b/net/core/flow.c
83964 index b0901ee..7d3c2ca 100644
83965 --- a/net/core/flow.c
83966 +++ b/net/core/flow.c
83967 @@ -61,7 +61,7 @@ struct flow_cache {
83968 struct timer_list rnd_timer;
83969 };
83970
83971 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
83972 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
83973 EXPORT_SYMBOL(flow_cache_genid);
83974 static struct flow_cache flow_cache_global;
83975 static struct kmem_cache *flow_cachep __read_mostly;
83976 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
83977
83978 static int flow_entry_valid(struct flow_cache_entry *fle)
83979 {
83980 - if (atomic_read(&flow_cache_genid) != fle->genid)
83981 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
83982 return 0;
83983 if (fle->object && !fle->object->ops->check(fle->object))
83984 return 0;
83985 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
83986 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
83987 fcp->hash_count++;
83988 }
83989 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
83990 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
83991 flo = fle->object;
83992 if (!flo)
83993 goto ret_object;
83994 @@ -280,7 +280,7 @@ nocache:
83995 }
83996 flo = resolver(net, key, family, dir, flo, ctx);
83997 if (fle) {
83998 - fle->genid = atomic_read(&flow_cache_genid);
83999 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
84000 if (!IS_ERR(flo))
84001 fle->object = flo;
84002 else
84003 diff --git a/net/core/iovec.c b/net/core/iovec.c
84004 index 7e7aeb0..2a998cb 100644
84005 --- a/net/core/iovec.c
84006 +++ b/net/core/iovec.c
84007 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
84008 if (m->msg_namelen) {
84009 if (mode == VERIFY_READ) {
84010 void __user *namep;
84011 - namep = (void __user __force *) m->msg_name;
84012 + namep = (void __force_user *) m->msg_name;
84013 err = move_addr_to_kernel(namep, m->msg_namelen,
84014 address);
84015 if (err < 0)
84016 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
84017 }
84018
84019 size = m->msg_iovlen * sizeof(struct iovec);
84020 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
84021 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
84022 return -EFAULT;
84023
84024 m->msg_iov = iov;
84025 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
84026 index c815f28..e6403f2 100644
84027 --- a/net/core/neighbour.c
84028 +++ b/net/core/neighbour.c
84029 @@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
84030 size_t *lenp, loff_t *ppos)
84031 {
84032 int size, ret;
84033 - ctl_table tmp = *ctl;
84034 + ctl_table_no_const tmp = *ctl;
84035
84036 tmp.extra1 = &zero;
84037 tmp.extra2 = &unres_qlen_max;
84038 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
84039 index 28c5f5a..7edf2e2 100644
84040 --- a/net/core/net-sysfs.c
84041 +++ b/net/core/net-sysfs.c
84042 @@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
84043 }
84044 EXPORT_SYMBOL(netdev_class_remove_file);
84045
84046 -int netdev_kobject_init(void)
84047 +int __init netdev_kobject_init(void)
84048 {
84049 kobj_ns_type_register(&net_ns_type_operations);
84050 return class_register(&net_class);
84051 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
84052 index 8acce01..2e306bb 100644
84053 --- a/net/core/net_namespace.c
84054 +++ b/net/core/net_namespace.c
84055 @@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
84056 int error;
84057 LIST_HEAD(net_exit_list);
84058
84059 - list_add_tail(&ops->list, list);
84060 + pax_list_add_tail((struct list_head *)&ops->list, list);
84061 if (ops->init || (ops->id && ops->size)) {
84062 for_each_net(net) {
84063 error = ops_init(ops, net);
84064 @@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
84065
84066 out_undo:
84067 /* If I have an error cleanup all namespaces I initialized */
84068 - list_del(&ops->list);
84069 + pax_list_del((struct list_head *)&ops->list);
84070 ops_exit_list(ops, &net_exit_list);
84071 ops_free_list(ops, &net_exit_list);
84072 return error;
84073 @@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
84074 struct net *net;
84075 LIST_HEAD(net_exit_list);
84076
84077 - list_del(&ops->list);
84078 + pax_list_del((struct list_head *)&ops->list);
84079 for_each_net(net)
84080 list_add_tail(&net->exit_list, &net_exit_list);
84081 ops_exit_list(ops, &net_exit_list);
84082 @@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
84083 mutex_lock(&net_mutex);
84084 error = register_pernet_operations(&pernet_list, ops);
84085 if (!error && (first_device == &pernet_list))
84086 - first_device = &ops->list;
84087 + first_device = (struct list_head *)&ops->list;
84088 mutex_unlock(&net_mutex);
84089 return error;
84090 }
84091 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
84092 index 1868625..b1b1284 100644
84093 --- a/net/core/rtnetlink.c
84094 +++ b/net/core/rtnetlink.c
84095 @@ -58,7 +58,7 @@ struct rtnl_link {
84096 rtnl_doit_func doit;
84097 rtnl_dumpit_func dumpit;
84098 rtnl_calcit_func calcit;
84099 -};
84100 +} __no_const;
84101
84102 static DEFINE_MUTEX(rtnl_mutex);
84103
84104 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
84105 if (rtnl_link_ops_get(ops->kind))
84106 return -EEXIST;
84107
84108 - if (!ops->dellink)
84109 - ops->dellink = unregister_netdevice_queue;
84110 + if (!ops->dellink) {
84111 + pax_open_kernel();
84112 + *(void **)&ops->dellink = unregister_netdevice_queue;
84113 + pax_close_kernel();
84114 + }
84115
84116 - list_add_tail(&ops->list, &link_ops);
84117 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
84118 return 0;
84119 }
84120 EXPORT_SYMBOL_GPL(__rtnl_link_register);
84121 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
84122 for_each_net(net) {
84123 __rtnl_kill_links(net, ops);
84124 }
84125 - list_del(&ops->list);
84126 + pax_list_del((struct list_head *)&ops->list);
84127 }
84128 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
84129
84130 diff --git a/net/core/scm.c b/net/core/scm.c
84131 index 905dcc6..14ee2d6 100644
84132 --- a/net/core/scm.c
84133 +++ b/net/core/scm.c
84134 @@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
84135 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
84136 {
84137 struct cmsghdr __user *cm
84138 - = (__force struct cmsghdr __user *)msg->msg_control;
84139 + = (struct cmsghdr __force_user *)msg->msg_control;
84140 struct cmsghdr cmhdr;
84141 int cmlen = CMSG_LEN(len);
84142 int err;
84143 @@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
84144 err = -EFAULT;
84145 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
84146 goto out;
84147 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
84148 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
84149 goto out;
84150 cmlen = CMSG_SPACE(len);
84151 if (msg->msg_controllen < cmlen)
84152 @@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
84153 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
84154 {
84155 struct cmsghdr __user *cm
84156 - = (__force struct cmsghdr __user*)msg->msg_control;
84157 + = (struct cmsghdr __force_user *)msg->msg_control;
84158
84159 int fdmax = 0;
84160 int fdnum = scm->fp->count;
84161 @@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
84162 if (fdnum < fdmax)
84163 fdmax = fdnum;
84164
84165 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
84166 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
84167 i++, cmfptr++)
84168 {
84169 struct socket *sock;
84170 diff --git a/net/core/sock.c b/net/core/sock.c
84171 index bc131d4..029e378 100644
84172 --- a/net/core/sock.c
84173 +++ b/net/core/sock.c
84174 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84175 struct sk_buff_head *list = &sk->sk_receive_queue;
84176
84177 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
84178 - atomic_inc(&sk->sk_drops);
84179 + atomic_inc_unchecked(&sk->sk_drops);
84180 trace_sock_rcvqueue_full(sk, skb);
84181 return -ENOMEM;
84182 }
84183 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84184 return err;
84185
84186 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
84187 - atomic_inc(&sk->sk_drops);
84188 + atomic_inc_unchecked(&sk->sk_drops);
84189 return -ENOBUFS;
84190 }
84191
84192 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84193 skb_dst_force(skb);
84194
84195 spin_lock_irqsave(&list->lock, flags);
84196 - skb->dropcount = atomic_read(&sk->sk_drops);
84197 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
84198 __skb_queue_tail(list, skb);
84199 spin_unlock_irqrestore(&list->lock, flags);
84200
84201 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
84202 skb->dev = NULL;
84203
84204 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
84205 - atomic_inc(&sk->sk_drops);
84206 + atomic_inc_unchecked(&sk->sk_drops);
84207 goto discard_and_relse;
84208 }
84209 if (nested)
84210 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
84211 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
84212 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
84213 bh_unlock_sock(sk);
84214 - atomic_inc(&sk->sk_drops);
84215 + atomic_inc_unchecked(&sk->sk_drops);
84216 goto discard_and_relse;
84217 }
84218
84219 @@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84220 struct timeval tm;
84221 } v;
84222
84223 - int lv = sizeof(int);
84224 - int len;
84225 + unsigned int lv = sizeof(int);
84226 + unsigned int len;
84227
84228 if (get_user(len, optlen))
84229 return -EFAULT;
84230 - if (len < 0)
84231 + if (len > INT_MAX)
84232 return -EINVAL;
84233
84234 memset(&v, 0, sizeof(v));
84235 @@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84236
84237 case SO_PEERNAME:
84238 {
84239 - char address[128];
84240 + char address[_K_SS_MAXSIZE];
84241
84242 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
84243 return -ENOTCONN;
84244 - if (lv < len)
84245 + if (lv < len || sizeof address < len)
84246 return -EINVAL;
84247 if (copy_to_user(optval, address, len))
84248 return -EFAULT;
84249 @@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84250
84251 if (len > lv)
84252 len = lv;
84253 - if (copy_to_user(optval, &v, len))
84254 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
84255 return -EFAULT;
84256 lenout:
84257 if (put_user(len, optlen))
84258 @@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
84259 */
84260 smp_wmb();
84261 atomic_set(&sk->sk_refcnt, 1);
84262 - atomic_set(&sk->sk_drops, 0);
84263 + atomic_set_unchecked(&sk->sk_drops, 0);
84264 }
84265 EXPORT_SYMBOL(sock_init_data);
84266
84267 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
84268 index 750f44f..922399c 100644
84269 --- a/net/core/sock_diag.c
84270 +++ b/net/core/sock_diag.c
84271 @@ -9,26 +9,33 @@
84272 #include <linux/inet_diag.h>
84273 #include <linux/sock_diag.h>
84274
84275 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
84276 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
84277 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
84278 static DEFINE_MUTEX(sock_diag_table_mutex);
84279
84280 int sock_diag_check_cookie(void *sk, __u32 *cookie)
84281 {
84282 +#ifndef CONFIG_GRKERNSEC_HIDESYM
84283 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
84284 cookie[1] != INET_DIAG_NOCOOKIE) &&
84285 ((u32)(unsigned long)sk != cookie[0] ||
84286 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
84287 return -ESTALE;
84288 else
84289 +#endif
84290 return 0;
84291 }
84292 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
84293
84294 void sock_diag_save_cookie(void *sk, __u32 *cookie)
84295 {
84296 +#ifdef CONFIG_GRKERNSEC_HIDESYM
84297 + cookie[0] = 0;
84298 + cookie[1] = 0;
84299 +#else
84300 cookie[0] = (u32)(unsigned long)sk;
84301 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
84302 +#endif
84303 }
84304 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
84305
84306 @@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
84307 mutex_lock(&sock_diag_table_mutex);
84308 if (sock_diag_handlers[hndl->family])
84309 err = -EBUSY;
84310 - else
84311 + else {
84312 + pax_open_kernel();
84313 sock_diag_handlers[hndl->family] = hndl;
84314 + pax_close_kernel();
84315 + }
84316 mutex_unlock(&sock_diag_table_mutex);
84317
84318 return err;
84319 @@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
84320
84321 mutex_lock(&sock_diag_table_mutex);
84322 BUG_ON(sock_diag_handlers[family] != hnld);
84323 + pax_open_kernel();
84324 sock_diag_handlers[family] = NULL;
84325 + pax_close_kernel();
84326 mutex_unlock(&sock_diag_table_mutex);
84327 }
84328 EXPORT_SYMBOL_GPL(sock_diag_unregister);
84329
84330 -static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
84331 -{
84332 - if (sock_diag_handlers[family] == NULL)
84333 - request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
84334 - NETLINK_SOCK_DIAG, family);
84335 -
84336 - mutex_lock(&sock_diag_table_mutex);
84337 - return sock_diag_handlers[family];
84338 -}
84339 -
84340 -static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
84341 -{
84342 - mutex_unlock(&sock_diag_table_mutex);
84343 -}
84344 -
84345 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84346 {
84347 int err;
84348 @@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84349 if (req->sdiag_family >= AF_MAX)
84350 return -EINVAL;
84351
84352 - hndl = sock_diag_lock_handler(req->sdiag_family);
84353 + if (sock_diag_handlers[req->sdiag_family] == NULL)
84354 + request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
84355 + NETLINK_SOCK_DIAG, req->sdiag_family);
84356 +
84357 + mutex_lock(&sock_diag_table_mutex);
84358 + hndl = sock_diag_handlers[req->sdiag_family];
84359 if (hndl == NULL)
84360 err = -ENOENT;
84361 else
84362 err = hndl->dump(skb, nlh);
84363 - sock_diag_unlock_handler(hndl);
84364 + mutex_unlock(&sock_diag_table_mutex);
84365
84366 return err;
84367 }
84368 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
84369 index d1b0804..417ffbe 100644
84370 --- a/net/core/sysctl_net_core.c
84371 +++ b/net/core/sysctl_net_core.c
84372 @@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
84373 {
84374 unsigned int orig_size, size;
84375 int ret, i;
84376 - ctl_table tmp = {
84377 + ctl_table_no_const tmp = {
84378 .data = &size,
84379 .maxlen = sizeof(size),
84380 .mode = table->mode
84381 @@ -205,11 +205,10 @@ static struct ctl_table netns_core_table[] = {
84382
84383 static __net_init int sysctl_core_net_init(struct net *net)
84384 {
84385 - struct ctl_table *tbl;
84386 + ctl_table_no_const *tbl = NULL;
84387
84388 net->core.sysctl_somaxconn = SOMAXCONN;
84389
84390 - tbl = netns_core_table;
84391 if (!net_eq(net, &init_net)) {
84392 tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
84393 if (tbl == NULL)
84394 @@ -221,16 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
84395 if (net->user_ns != &init_user_ns) {
84396 tbl[0].procname = NULL;
84397 }
84398 - }
84399 -
84400 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
84401 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
84402 + } else
84403 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
84404 if (net->core.sysctl_hdr == NULL)
84405 goto err_reg;
84406
84407 return 0;
84408
84409 err_reg:
84410 - if (tbl != netns_core_table)
84411 + if (tbl)
84412 kfree(tbl);
84413 err_dup:
84414 return -ENOMEM;
84415 @@ -246,7 +245,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
84416 kfree(tbl);
84417 }
84418
84419 -static __net_initdata struct pernet_operations sysctl_core_ops = {
84420 +static __net_initconst struct pernet_operations sysctl_core_ops = {
84421 .init = sysctl_core_net_init,
84422 .exit = sysctl_core_net_exit,
84423 };
84424 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
84425 index a55eecc..dd8428c 100644
84426 --- a/net/decnet/sysctl_net_decnet.c
84427 +++ b/net/decnet/sysctl_net_decnet.c
84428 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
84429
84430 if (len > *lenp) len = *lenp;
84431
84432 - if (copy_to_user(buffer, addr, len))
84433 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
84434 return -EFAULT;
84435
84436 *lenp = len;
84437 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
84438
84439 if (len > *lenp) len = *lenp;
84440
84441 - if (copy_to_user(buffer, devname, len))
84442 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
84443 return -EFAULT;
84444
84445 *lenp = len;
84446 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
84447 index fcf104e..95552d4 100644
84448 --- a/net/ipv4/af_inet.c
84449 +++ b/net/ipv4/af_inet.c
84450 @@ -1717,13 +1717,9 @@ static int __init inet_init(void)
84451
84452 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
84453
84454 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
84455 - if (!sysctl_local_reserved_ports)
84456 - goto out;
84457 -
84458 rc = proto_register(&tcp_prot, 1);
84459 if (rc)
84460 - goto out_free_reserved_ports;
84461 + goto out;
84462
84463 rc = proto_register(&udp_prot, 1);
84464 if (rc)
84465 @@ -1832,8 +1828,6 @@ out_unregister_udp_proto:
84466 proto_unregister(&udp_prot);
84467 out_unregister_tcp_proto:
84468 proto_unregister(&tcp_prot);
84469 -out_free_reserved_ports:
84470 - kfree(sysctl_local_reserved_ports);
84471 goto out;
84472 }
84473
84474 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
84475 index a69b4e4..dbccba5 100644
84476 --- a/net/ipv4/ah4.c
84477 +++ b/net/ipv4/ah4.c
84478 @@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
84479 return;
84480
84481 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
84482 - atomic_inc(&flow_cache_genid);
84483 + atomic_inc_unchecked(&flow_cache_genid);
84484 rt_genid_bump(net);
84485
84486 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
84487 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
84488 index a8e4f26..27042f1 100644
84489 --- a/net/ipv4/devinet.c
84490 +++ b/net/ipv4/devinet.c
84491 @@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
84492 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
84493 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
84494
84495 -static struct devinet_sysctl_table {
84496 +static const struct devinet_sysctl_table {
84497 struct ctl_table_header *sysctl_header;
84498 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
84499 } devinet_sysctl = {
84500 @@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
84501 int err;
84502 struct ipv4_devconf *all, *dflt;
84503 #ifdef CONFIG_SYSCTL
84504 - struct ctl_table *tbl = ctl_forward_entry;
84505 + ctl_table_no_const *tbl = NULL;
84506 struct ctl_table_header *forw_hdr;
84507 #endif
84508
84509 @@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
84510 goto err_reg_dflt;
84511
84512 err = -ENOMEM;
84513 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
84514 + if (!net_eq(net, &init_net))
84515 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
84516 + else
84517 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
84518 if (forw_hdr == NULL)
84519 goto err_reg_ctl;
84520 net->ipv4.forw_hdr = forw_hdr;
84521 @@ -1935,8 +1938,7 @@ err_reg_ctl:
84522 err_reg_dflt:
84523 __devinet_sysctl_unregister(all);
84524 err_reg_all:
84525 - if (tbl != ctl_forward_entry)
84526 - kfree(tbl);
84527 + kfree(tbl);
84528 err_alloc_ctl:
84529 #endif
84530 if (dflt != &ipv4_devconf_dflt)
84531 diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
84532 index 3b4f0cd..8cb864c 100644
84533 --- a/net/ipv4/esp4.c
84534 +++ b/net/ipv4/esp4.c
84535 @@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
84536 return;
84537
84538 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
84539 - atomic_inc(&flow_cache_genid);
84540 + atomic_inc_unchecked(&flow_cache_genid);
84541 rt_genid_bump(net);
84542
84543 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
84544 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
84545 index 5cd75e2..f57ef39 100644
84546 --- a/net/ipv4/fib_frontend.c
84547 +++ b/net/ipv4/fib_frontend.c
84548 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
84549 #ifdef CONFIG_IP_ROUTE_MULTIPATH
84550 fib_sync_up(dev);
84551 #endif
84552 - atomic_inc(&net->ipv4.dev_addr_genid);
84553 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84554 rt_cache_flush(dev_net(dev));
84555 break;
84556 case NETDEV_DOWN:
84557 fib_del_ifaddr(ifa, NULL);
84558 - atomic_inc(&net->ipv4.dev_addr_genid);
84559 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84560 if (ifa->ifa_dev->ifa_list == NULL) {
84561 /* Last address was deleted from this interface.
84562 * Disable IP.
84563 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
84564 #ifdef CONFIG_IP_ROUTE_MULTIPATH
84565 fib_sync_up(dev);
84566 #endif
84567 - atomic_inc(&net->ipv4.dev_addr_genid);
84568 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84569 rt_cache_flush(net);
84570 break;
84571 case NETDEV_DOWN:
84572 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
84573 index 4797a80..2bd54e9 100644
84574 --- a/net/ipv4/fib_semantics.c
84575 +++ b/net/ipv4/fib_semantics.c
84576 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
84577 nh->nh_saddr = inet_select_addr(nh->nh_dev,
84578 nh->nh_gw,
84579 nh->nh_parent->fib_scope);
84580 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
84581 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
84582
84583 return nh->nh_saddr;
84584 }
84585 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
84586 index d0670f0..744ac80 100644
84587 --- a/net/ipv4/inet_connection_sock.c
84588 +++ b/net/ipv4/inet_connection_sock.c
84589 @@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
84590 .range = { 32768, 61000 },
84591 };
84592
84593 -unsigned long *sysctl_local_reserved_ports;
84594 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
84595 EXPORT_SYMBOL(sysctl_local_reserved_ports);
84596
84597 void inet_get_local_port_range(int *low, int *high)
84598 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
84599 index fa3ae81..0dbe6b8 100644
84600 --- a/net/ipv4/inet_hashtables.c
84601 +++ b/net/ipv4/inet_hashtables.c
84602 @@ -18,12 +18,15 @@
84603 #include <linux/sched.h>
84604 #include <linux/slab.h>
84605 #include <linux/wait.h>
84606 +#include <linux/security.h>
84607
84608 #include <net/inet_connection_sock.h>
84609 #include <net/inet_hashtables.h>
84610 #include <net/secure_seq.h>
84611 #include <net/ip.h>
84612
84613 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
84614 +
84615 /*
84616 * Allocate and initialize a new local port bind bucket.
84617 * The bindhash mutex for snum's hash chain must be held here.
84618 @@ -540,6 +543,8 @@ ok:
84619 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
84620 spin_unlock(&head->lock);
84621
84622 + gr_update_task_in_ip_table(current, inet_sk(sk));
84623 +
84624 if (tw) {
84625 inet_twsk_deschedule(tw, death_row);
84626 while (twrefcnt) {
84627 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
84628 index 000e3d2..5472da3 100644
84629 --- a/net/ipv4/inetpeer.c
84630 +++ b/net/ipv4/inetpeer.c
84631 @@ -503,8 +503,8 @@ relookup:
84632 if (p) {
84633 p->daddr = *daddr;
84634 atomic_set(&p->refcnt, 1);
84635 - atomic_set(&p->rid, 0);
84636 - atomic_set(&p->ip_id_count,
84637 + atomic_set_unchecked(&p->rid, 0);
84638 + atomic_set_unchecked(&p->ip_id_count,
84639 (daddr->family == AF_INET) ?
84640 secure_ip_id(daddr->addr.a4) :
84641 secure_ipv6_id(daddr->addr.a6));
84642 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
84643 index eb9d63a..7bbf787 100644
84644 --- a/net/ipv4/ip_fragment.c
84645 +++ b/net/ipv4/ip_fragment.c
84646 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
84647 return 0;
84648
84649 start = qp->rid;
84650 - end = atomic_inc_return(&peer->rid);
84651 + end = atomic_inc_return_unchecked(&peer->rid);
84652 qp->rid = end;
84653
84654 rc = qp->q.fragments && (end - start) > max;
84655 @@ -789,10 +789,9 @@ static struct ctl_table ip4_frags_ctl_table[] = {
84656
84657 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
84658 {
84659 - struct ctl_table *table;
84660 + ctl_table_no_const *table = NULL;
84661 struct ctl_table_header *hdr;
84662
84663 - table = ip4_frags_ns_ctl_table;
84664 if (!net_eq(net, &init_net)) {
84665 table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
84666 if (table == NULL)
84667 @@ -805,9 +804,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
84668 /* Don't export sysctls to unprivileged users */
84669 if (net->user_ns != &init_user_ns)
84670 table[0].procname = NULL;
84671 + hdr = register_net_sysctl(net, "net/ipv4", table);
84672 }
84673 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
84674
84675 - hdr = register_net_sysctl(net, "net/ipv4", table);
84676 if (hdr == NULL)
84677 goto err_reg;
84678
84679 @@ -815,8 +815,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
84680 return 0;
84681
84682 err_reg:
84683 - if (!net_eq(net, &init_net))
84684 - kfree(table);
84685 + kfree(table);
84686 err_alloc:
84687 return -ENOMEM;
84688 }
84689 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
84690 index e81b1ca..6f3b5b9 100644
84691 --- a/net/ipv4/ip_gre.c
84692 +++ b/net/ipv4/ip_gre.c
84693 @@ -124,7 +124,7 @@ static bool log_ecn_error = true;
84694 module_param(log_ecn_error, bool, 0644);
84695 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
84696
84697 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
84698 +static struct rtnl_link_ops ipgre_link_ops;
84699 static int ipgre_tunnel_init(struct net_device *dev);
84700 static void ipgre_tunnel_setup(struct net_device *dev);
84701 static int ipgre_tunnel_bind_dev(struct net_device *dev);
84702 @@ -1756,7 +1756,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
84703 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
84704 };
84705
84706 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
84707 +static struct rtnl_link_ops ipgre_link_ops = {
84708 .kind = "gre",
84709 .maxtype = IFLA_GRE_MAX,
84710 .policy = ipgre_policy,
84711 @@ -1769,7 +1769,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
84712 .fill_info = ipgre_fill_info,
84713 };
84714
84715 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
84716 +static struct rtnl_link_ops ipgre_tap_ops = {
84717 .kind = "gretap",
84718 .maxtype = IFLA_GRE_MAX,
84719 .policy = ipgre_policy,
84720 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
84721 index d9c4f11..02b82db 100644
84722 --- a/net/ipv4/ip_sockglue.c
84723 +++ b/net/ipv4/ip_sockglue.c
84724 @@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
84725 len = min_t(unsigned int, len, opt->optlen);
84726 if (put_user(len, optlen))
84727 return -EFAULT;
84728 - if (copy_to_user(optval, opt->__data, len))
84729 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
84730 + copy_to_user(optval, opt->__data, len))
84731 return -EFAULT;
84732 return 0;
84733 }
84734 @@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
84735 if (sk->sk_type != SOCK_STREAM)
84736 return -ENOPROTOOPT;
84737
84738 - msg.msg_control = optval;
84739 + msg.msg_control = (void __force_kernel *)optval;
84740 msg.msg_controllen = len;
84741 msg.msg_flags = flags;
84742
84743 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
84744 index c3a4233..1412161 100644
84745 --- a/net/ipv4/ip_vti.c
84746 +++ b/net/ipv4/ip_vti.c
84747 @@ -47,7 +47,7 @@
84748 #define HASH_SIZE 16
84749 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
84750
84751 -static struct rtnl_link_ops vti_link_ops __read_mostly;
84752 +static struct rtnl_link_ops vti_link_ops;
84753
84754 static int vti_net_id __read_mostly;
84755 struct vti_net {
84756 @@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
84757 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
84758 };
84759
84760 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
84761 +static struct rtnl_link_ops vti_link_ops = {
84762 .kind = "vti",
84763 .maxtype = IFLA_VTI_MAX,
84764 .policy = vti_policy,
84765 diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
84766 index 9a46dae..5f793a0 100644
84767 --- a/net/ipv4/ipcomp.c
84768 +++ b/net/ipv4/ipcomp.c
84769 @@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
84770 return;
84771
84772 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
84773 - atomic_inc(&flow_cache_genid);
84774 + atomic_inc_unchecked(&flow_cache_genid);
84775 rt_genid_bump(net);
84776
84777 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
84778 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
84779 index a2e50ae..e152b7c 100644
84780 --- a/net/ipv4/ipconfig.c
84781 +++ b/net/ipv4/ipconfig.c
84782 @@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
84783
84784 mm_segment_t oldfs = get_fs();
84785 set_fs(get_ds());
84786 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
84787 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
84788 set_fs(oldfs);
84789 return res;
84790 }
84791 @@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
84792
84793 mm_segment_t oldfs = get_fs();
84794 set_fs(get_ds());
84795 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
84796 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
84797 set_fs(oldfs);
84798 return res;
84799 }
84800 @@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
84801
84802 mm_segment_t oldfs = get_fs();
84803 set_fs(get_ds());
84804 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
84805 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
84806 set_fs(oldfs);
84807 return res;
84808 }
84809 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
84810 index 191fc24..1b3b804 100644
84811 --- a/net/ipv4/ipip.c
84812 +++ b/net/ipv4/ipip.c
84813 @@ -138,7 +138,7 @@ struct ipip_net {
84814 static int ipip_tunnel_init(struct net_device *dev);
84815 static void ipip_tunnel_setup(struct net_device *dev);
84816 static void ipip_dev_free(struct net_device *dev);
84817 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
84818 +static struct rtnl_link_ops ipip_link_ops;
84819
84820 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
84821 struct rtnl_link_stats64 *tot)
84822 @@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
84823 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
84824 };
84825
84826 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
84827 +static struct rtnl_link_ops ipip_link_ops = {
84828 .kind = "ipip",
84829 .maxtype = IFLA_IPTUN_MAX,
84830 .policy = ipip_policy,
84831 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
84832 index 3ea4127..849297b 100644
84833 --- a/net/ipv4/netfilter/arp_tables.c
84834 +++ b/net/ipv4/netfilter/arp_tables.c
84835 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
84836 #endif
84837
84838 static int get_info(struct net *net, void __user *user,
84839 - const int *len, int compat)
84840 + int len, int compat)
84841 {
84842 char name[XT_TABLE_MAXNAMELEN];
84843 struct xt_table *t;
84844 int ret;
84845
84846 - if (*len != sizeof(struct arpt_getinfo)) {
84847 - duprintf("length %u != %Zu\n", *len,
84848 + if (len != sizeof(struct arpt_getinfo)) {
84849 + duprintf("length %u != %Zu\n", len,
84850 sizeof(struct arpt_getinfo));
84851 return -EINVAL;
84852 }
84853 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
84854 info.size = private->size;
84855 strcpy(info.name, name);
84856
84857 - if (copy_to_user(user, &info, *len) != 0)
84858 + if (copy_to_user(user, &info, len) != 0)
84859 ret = -EFAULT;
84860 else
84861 ret = 0;
84862 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
84863
84864 switch (cmd) {
84865 case ARPT_SO_GET_INFO:
84866 - ret = get_info(sock_net(sk), user, len, 1);
84867 + ret = get_info(sock_net(sk), user, *len, 1);
84868 break;
84869 case ARPT_SO_GET_ENTRIES:
84870 ret = compat_get_entries(sock_net(sk), user, len);
84871 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
84872
84873 switch (cmd) {
84874 case ARPT_SO_GET_INFO:
84875 - ret = get_info(sock_net(sk), user, len, 0);
84876 + ret = get_info(sock_net(sk), user, *len, 0);
84877 break;
84878
84879 case ARPT_SO_GET_ENTRIES:
84880 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
84881 index 17c5e06..1b91206 100644
84882 --- a/net/ipv4/netfilter/ip_tables.c
84883 +++ b/net/ipv4/netfilter/ip_tables.c
84884 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
84885 #endif
84886
84887 static int get_info(struct net *net, void __user *user,
84888 - const int *len, int compat)
84889 + int len, int compat)
84890 {
84891 char name[XT_TABLE_MAXNAMELEN];
84892 struct xt_table *t;
84893 int ret;
84894
84895 - if (*len != sizeof(struct ipt_getinfo)) {
84896 - duprintf("length %u != %zu\n", *len,
84897 + if (len != sizeof(struct ipt_getinfo)) {
84898 + duprintf("length %u != %zu\n", len,
84899 sizeof(struct ipt_getinfo));
84900 return -EINVAL;
84901 }
84902 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
84903 info.size = private->size;
84904 strcpy(info.name, name);
84905
84906 - if (copy_to_user(user, &info, *len) != 0)
84907 + if (copy_to_user(user, &info, len) != 0)
84908 ret = -EFAULT;
84909 else
84910 ret = 0;
84911 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
84912
84913 switch (cmd) {
84914 case IPT_SO_GET_INFO:
84915 - ret = get_info(sock_net(sk), user, len, 1);
84916 + ret = get_info(sock_net(sk), user, *len, 1);
84917 break;
84918 case IPT_SO_GET_ENTRIES:
84919 ret = compat_get_entries(sock_net(sk), user, len);
84920 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
84921
84922 switch (cmd) {
84923 case IPT_SO_GET_INFO:
84924 - ret = get_info(sock_net(sk), user, len, 0);
84925 + ret = get_info(sock_net(sk), user, *len, 0);
84926 break;
84927
84928 case IPT_SO_GET_ENTRIES:
84929 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
84930 index dc454cc..5bb917f 100644
84931 --- a/net/ipv4/ping.c
84932 +++ b/net/ipv4/ping.c
84933 @@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
84934 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
84935 0, sock_i_ino(sp),
84936 atomic_read(&sp->sk_refcnt), sp,
84937 - atomic_read(&sp->sk_drops), len);
84938 + atomic_read_unchecked(&sp->sk_drops), len);
84939 }
84940
84941 static int ping_seq_show(struct seq_file *seq, void *v)
84942 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
84943 index 6f08991..55867ad 100644
84944 --- a/net/ipv4/raw.c
84945 +++ b/net/ipv4/raw.c
84946 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
84947 int raw_rcv(struct sock *sk, struct sk_buff *skb)
84948 {
84949 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
84950 - atomic_inc(&sk->sk_drops);
84951 + atomic_inc_unchecked(&sk->sk_drops);
84952 kfree_skb(skb);
84953 return NET_RX_DROP;
84954 }
84955 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
84956
84957 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
84958 {
84959 + struct icmp_filter filter;
84960 +
84961 if (optlen > sizeof(struct icmp_filter))
84962 optlen = sizeof(struct icmp_filter);
84963 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
84964 + if (copy_from_user(&filter, optval, optlen))
84965 return -EFAULT;
84966 + raw_sk(sk)->filter = filter;
84967 return 0;
84968 }
84969
84970 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
84971 {
84972 int len, ret = -EFAULT;
84973 + struct icmp_filter filter;
84974
84975 if (get_user(len, optlen))
84976 goto out;
84977 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
84978 if (len > sizeof(struct icmp_filter))
84979 len = sizeof(struct icmp_filter);
84980 ret = -EFAULT;
84981 - if (put_user(len, optlen) ||
84982 - copy_to_user(optval, &raw_sk(sk)->filter, len))
84983 + filter = raw_sk(sk)->filter;
84984 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
84985 goto out;
84986 ret = 0;
84987 out: return ret;
84988 @@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
84989 0, 0L, 0,
84990 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
84991 0, sock_i_ino(sp),
84992 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
84993 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
84994 }
84995
84996 static int raw_seq_show(struct seq_file *seq, void *v)
84997 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
84998 index a0fcc47..bc43196 100644
84999 --- a/net/ipv4/route.c
85000 +++ b/net/ipv4/route.c
85001 @@ -2552,15 +2552,15 @@ static struct ctl_table ipv4_route_flush_table[] = {
85002 .maxlen = sizeof(int),
85003 .mode = 0200,
85004 .proc_handler = ipv4_sysctl_rtcache_flush,
85005 + .extra1 = &init_net,
85006 },
85007 { },
85008 };
85009
85010 static __net_init int sysctl_route_net_init(struct net *net)
85011 {
85012 - struct ctl_table *tbl;
85013 + ctl_table_no_const *tbl = NULL;
85014
85015 - tbl = ipv4_route_flush_table;
85016 if (!net_eq(net, &init_net)) {
85017 tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
85018 if (tbl == NULL)
85019 @@ -2569,17 +2569,17 @@ static __net_init int sysctl_route_net_init(struct net *net)
85020 /* Don't export sysctls to unprivileged users */
85021 if (net->user_ns != &init_user_ns)
85022 tbl[0].procname = NULL;
85023 - }
85024 - tbl[0].extra1 = net;
85025 + tbl[0].extra1 = net;
85026 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
85027 + } else
85028 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
85029
85030 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
85031 if (net->ipv4.route_hdr == NULL)
85032 goto err_reg;
85033 return 0;
85034
85035 err_reg:
85036 - if (tbl != ipv4_route_flush_table)
85037 - kfree(tbl);
85038 + kfree(tbl);
85039 err_dup:
85040 return -ENOMEM;
85041 }
85042 @@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
85043
85044 static __net_init int rt_genid_init(struct net *net)
85045 {
85046 - atomic_set(&net->rt_genid, 0);
85047 + atomic_set_unchecked(&net->rt_genid, 0);
85048 get_random_bytes(&net->ipv4.dev_addr_genid,
85049 sizeof(net->ipv4.dev_addr_genid));
85050 return 0;
85051 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
85052 index d84400b..7c2959a 100644
85053 --- a/net/ipv4/sysctl_net_ipv4.c
85054 +++ b/net/ipv4/sysctl_net_ipv4.c
85055 @@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
85056 {
85057 int ret;
85058 int range[2];
85059 - ctl_table tmp = {
85060 + ctl_table_no_const tmp = {
85061 .data = &range,
85062 .maxlen = sizeof(range),
85063 .mode = table->mode,
85064 @@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
85065 int ret;
85066 gid_t urange[2];
85067 kgid_t low, high;
85068 - ctl_table tmp = {
85069 + ctl_table_no_const tmp = {
85070 .data = &urange,
85071 .maxlen = sizeof(urange),
85072 .mode = table->mode,
85073 @@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
85074 void __user *buffer, size_t *lenp, loff_t *ppos)
85075 {
85076 char val[TCP_CA_NAME_MAX];
85077 - ctl_table tbl = {
85078 + ctl_table_no_const tbl = {
85079 .data = val,
85080 .maxlen = TCP_CA_NAME_MAX,
85081 };
85082 @@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
85083 void __user *buffer, size_t *lenp,
85084 loff_t *ppos)
85085 {
85086 - ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
85087 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
85088 int ret;
85089
85090 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
85091 @@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
85092 void __user *buffer, size_t *lenp,
85093 loff_t *ppos)
85094 {
85095 - ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
85096 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
85097 int ret;
85098
85099 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
85100 @@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
85101 struct mem_cgroup *memcg;
85102 #endif
85103
85104 - ctl_table tmp = {
85105 + ctl_table_no_const tmp = {
85106 .data = &vec,
85107 .maxlen = sizeof(vec),
85108 .mode = ctl->mode,
85109 };
85110
85111 if (!write) {
85112 - ctl->data = &net->ipv4.sysctl_tcp_mem;
85113 - return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
85114 + ctl_table_no_const tcp_mem = *ctl;
85115 +
85116 + tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
85117 + return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
85118 }
85119
85120 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
85121 @@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
85122 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
85123 size_t *lenp, loff_t *ppos)
85124 {
85125 - ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
85126 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
85127 struct tcp_fastopen_context *ctxt;
85128 int ret;
85129 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
85130 @@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
85131 },
85132 {
85133 .procname = "ip_local_reserved_ports",
85134 - .data = NULL, /* initialized in sysctl_ipv4_init */
85135 + .data = sysctl_local_reserved_ports,
85136 .maxlen = 65536,
85137 .mode = 0644,
85138 .proc_handler = proc_do_large_bitmap,
85139 @@ -860,9 +862,8 @@ static struct ctl_table ipv4_net_table[] = {
85140
85141 static __net_init int ipv4_sysctl_init_net(struct net *net)
85142 {
85143 - struct ctl_table *table;
85144 + ctl_table_no_const *table = NULL;
85145
85146 - table = ipv4_net_table;
85147 if (!net_eq(net, &init_net)) {
85148 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
85149 if (table == NULL)
85150 @@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
85151
85152 tcp_init_mem(net);
85153
85154 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
85155 + if (!net_eq(net, &init_net))
85156 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
85157 + else
85158 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
85159 if (net->ipv4.ipv4_hdr == NULL)
85160 goto err_reg;
85161
85162 return 0;
85163
85164 err_reg:
85165 - if (!net_eq(net, &init_net))
85166 - kfree(table);
85167 + kfree(table);
85168 err_alloc:
85169 return -ENOMEM;
85170 }
85171 @@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
85172 static __init int sysctl_ipv4_init(void)
85173 {
85174 struct ctl_table_header *hdr;
85175 - struct ctl_table *i;
85176 -
85177 - for (i = ipv4_table; i->procname; i++) {
85178 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
85179 - i->data = sysctl_local_reserved_ports;
85180 - break;
85181 - }
85182 - }
85183 - if (!i->procname)
85184 - return -EINVAL;
85185
85186 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
85187 if (hdr == NULL)
85188 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
85189 index ad70a96..50cb55b 100644
85190 --- a/net/ipv4/tcp_input.c
85191 +++ b/net/ipv4/tcp_input.c
85192 @@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
85193 * simplifies code)
85194 */
85195 static void
85196 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
85197 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
85198 struct sk_buff *head, struct sk_buff *tail,
85199 u32 start, u32 end)
85200 {
85201 @@ -5850,6 +5850,7 @@ discard:
85202 tcp_paws_reject(&tp->rx_opt, 0))
85203 goto discard_and_undo;
85204
85205 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
85206 if (th->syn) {
85207 /* We see SYN without ACK. It is attempt of
85208 * simultaneous connect with crossed SYNs.
85209 @@ -5900,6 +5901,7 @@ discard:
85210 goto discard;
85211 #endif
85212 }
85213 +#endif
85214 /* "fifth, if neither of the SYN or RST bits is set then
85215 * drop the segment and return."
85216 */
85217 @@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
85218 goto discard;
85219
85220 if (th->syn) {
85221 - if (th->fin)
85222 + if (th->fin || th->urg || th->psh)
85223 goto discard;
85224 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
85225 return 1;
85226 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
85227 index eadb693..e8f7251 100644
85228 --- a/net/ipv4/tcp_ipv4.c
85229 +++ b/net/ipv4/tcp_ipv4.c
85230 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
85231 EXPORT_SYMBOL(sysctl_tcp_low_latency);
85232
85233
85234 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85235 +extern int grsec_enable_blackhole;
85236 +#endif
85237 +
85238 #ifdef CONFIG_TCP_MD5SIG
85239 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
85240 __be32 daddr, __be32 saddr, const struct tcphdr *th);
85241 @@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
85242 return 0;
85243
85244 reset:
85245 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85246 + if (!grsec_enable_blackhole)
85247 +#endif
85248 tcp_v4_send_reset(rsk, skb);
85249 discard:
85250 kfree_skb(skb);
85251 @@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
85252 TCP_SKB_CB(skb)->sacked = 0;
85253
85254 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
85255 - if (!sk)
85256 + if (!sk) {
85257 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85258 + ret = 1;
85259 +#endif
85260 goto no_tcp_socket;
85261 -
85262 + }
85263 process:
85264 - if (sk->sk_state == TCP_TIME_WAIT)
85265 + if (sk->sk_state == TCP_TIME_WAIT) {
85266 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85267 + ret = 2;
85268 +#endif
85269 goto do_time_wait;
85270 + }
85271
85272 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
85273 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
85274 @@ -2050,6 +2064,10 @@ no_tcp_socket:
85275 bad_packet:
85276 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
85277 } else {
85278 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85279 + if (!grsec_enable_blackhole || (ret == 1 &&
85280 + (skb->dev->flags & IFF_LOOPBACK)))
85281 +#endif
85282 tcp_v4_send_reset(NULL, skb);
85283 }
85284
85285 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
85286 index f35f2df..ccb5ca6 100644
85287 --- a/net/ipv4/tcp_minisocks.c
85288 +++ b/net/ipv4/tcp_minisocks.c
85289 @@ -27,6 +27,10 @@
85290 #include <net/inet_common.h>
85291 #include <net/xfrm.h>
85292
85293 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85294 +extern int grsec_enable_blackhole;
85295 +#endif
85296 +
85297 int sysctl_tcp_syncookies __read_mostly = 1;
85298 EXPORT_SYMBOL(sysctl_tcp_syncookies);
85299
85300 @@ -742,7 +746,10 @@ embryonic_reset:
85301 * avoid becoming vulnerable to outside attack aiming at
85302 * resetting legit local connections.
85303 */
85304 - req->rsk_ops->send_reset(sk, skb);
85305 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85306 + if (!grsec_enable_blackhole)
85307 +#endif
85308 + req->rsk_ops->send_reset(sk, skb);
85309 } else if (fastopen) { /* received a valid RST pkt */
85310 reqsk_fastopen_remove(sk, req, true);
85311 tcp_reset(sk);
85312 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
85313 index 4526fe6..1a34e43 100644
85314 --- a/net/ipv4/tcp_probe.c
85315 +++ b/net/ipv4/tcp_probe.c
85316 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
85317 if (cnt + width >= len)
85318 break;
85319
85320 - if (copy_to_user(buf + cnt, tbuf, width))
85321 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
85322 return -EFAULT;
85323 cnt += width;
85324 }
85325 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
85326 index b78aac3..e18230b 100644
85327 --- a/net/ipv4/tcp_timer.c
85328 +++ b/net/ipv4/tcp_timer.c
85329 @@ -22,6 +22,10 @@
85330 #include <linux/gfp.h>
85331 #include <net/tcp.h>
85332
85333 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85334 +extern int grsec_lastack_retries;
85335 +#endif
85336 +
85337 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
85338 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
85339 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
85340 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
85341 }
85342 }
85343
85344 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85345 + if ((sk->sk_state == TCP_LAST_ACK) &&
85346 + (grsec_lastack_retries > 0) &&
85347 + (grsec_lastack_retries < retry_until))
85348 + retry_until = grsec_lastack_retries;
85349 +#endif
85350 +
85351 if (retransmits_timed_out(sk, retry_until,
85352 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
85353 /* Has it gone just too far? */
85354 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
85355 index 1f4d405..3524677 100644
85356 --- a/net/ipv4/udp.c
85357 +++ b/net/ipv4/udp.c
85358 @@ -87,6 +87,7 @@
85359 #include <linux/types.h>
85360 #include <linux/fcntl.h>
85361 #include <linux/module.h>
85362 +#include <linux/security.h>
85363 #include <linux/socket.h>
85364 #include <linux/sockios.h>
85365 #include <linux/igmp.h>
85366 @@ -111,6 +112,10 @@
85367 #include <trace/events/skb.h>
85368 #include "udp_impl.h"
85369
85370 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85371 +extern int grsec_enable_blackhole;
85372 +#endif
85373 +
85374 struct udp_table udp_table __read_mostly;
85375 EXPORT_SYMBOL(udp_table);
85376
85377 @@ -569,6 +574,9 @@ found:
85378 return s;
85379 }
85380
85381 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
85382 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
85383 +
85384 /*
85385 * This routine is called by the ICMP module when it gets some
85386 * sort of error condition. If err < 0 then the socket should
85387 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
85388 dport = usin->sin_port;
85389 if (dport == 0)
85390 return -EINVAL;
85391 +
85392 + err = gr_search_udp_sendmsg(sk, usin);
85393 + if (err)
85394 + return err;
85395 } else {
85396 if (sk->sk_state != TCP_ESTABLISHED)
85397 return -EDESTADDRREQ;
85398 +
85399 + err = gr_search_udp_sendmsg(sk, NULL);
85400 + if (err)
85401 + return err;
85402 +
85403 daddr = inet->inet_daddr;
85404 dport = inet->inet_dport;
85405 /* Open fast path for connected socket.
85406 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
85407 udp_lib_checksum_complete(skb)) {
85408 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
85409 IS_UDPLITE(sk));
85410 - atomic_inc(&sk->sk_drops);
85411 + atomic_inc_unchecked(&sk->sk_drops);
85412 __skb_unlink(skb, rcvq);
85413 __skb_queue_tail(&list_kill, skb);
85414 }
85415 @@ -1194,6 +1211,10 @@ try_again:
85416 if (!skb)
85417 goto out;
85418
85419 + err = gr_search_udp_recvmsg(sk, skb);
85420 + if (err)
85421 + goto out_free;
85422 +
85423 ulen = skb->len - sizeof(struct udphdr);
85424 copied = len;
85425 if (copied > ulen)
85426 @@ -1227,7 +1248,7 @@ try_again:
85427 if (unlikely(err)) {
85428 trace_kfree_skb(skb, udp_recvmsg);
85429 if (!peeked) {
85430 - atomic_inc(&sk->sk_drops);
85431 + atomic_inc_unchecked(&sk->sk_drops);
85432 UDP_INC_STATS_USER(sock_net(sk),
85433 UDP_MIB_INERRORS, is_udplite);
85434 }
85435 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85436
85437 drop:
85438 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
85439 - atomic_inc(&sk->sk_drops);
85440 + atomic_inc_unchecked(&sk->sk_drops);
85441 kfree_skb(skb);
85442 return -1;
85443 }
85444 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
85445 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
85446
85447 if (!skb1) {
85448 - atomic_inc(&sk->sk_drops);
85449 + atomic_inc_unchecked(&sk->sk_drops);
85450 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
85451 IS_UDPLITE(sk));
85452 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
85453 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
85454 goto csum_error;
85455
85456 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
85457 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85458 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
85459 +#endif
85460 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
85461
85462 /*
85463 @@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
85464 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
85465 0, sock_i_ino(sp),
85466 atomic_read(&sp->sk_refcnt), sp,
85467 - atomic_read(&sp->sk_drops), len);
85468 + atomic_read_unchecked(&sp->sk_drops), len);
85469 }
85470
85471 int udp4_seq_show(struct seq_file *seq, void *v)
85472 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
85473 index 1b5d8cb..ffb0833 100644
85474 --- a/net/ipv6/addrconf.c
85475 +++ b/net/ipv6/addrconf.c
85476 @@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
85477 p.iph.ihl = 5;
85478 p.iph.protocol = IPPROTO_IPV6;
85479 p.iph.ttl = 64;
85480 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
85481 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
85482
85483 if (ops->ndo_do_ioctl) {
85484 mm_segment_t oldfs = get_fs();
85485 @@ -4388,7 +4388,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
85486 int *valp = ctl->data;
85487 int val = *valp;
85488 loff_t pos = *ppos;
85489 - ctl_table lctl;
85490 + ctl_table_no_const lctl;
85491 int ret;
85492
85493 /*
85494 @@ -4470,7 +4470,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
85495 int *valp = ctl->data;
85496 int val = *valp;
85497 loff_t pos = *ppos;
85498 - ctl_table lctl;
85499 + ctl_table_no_const lctl;
85500 int ret;
85501
85502 /*
85503 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
85504 index fff5bdd..15194fb 100644
85505 --- a/net/ipv6/icmp.c
85506 +++ b/net/ipv6/icmp.c
85507 @@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
85508
85509 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
85510 {
85511 - struct ctl_table *table;
85512 + ctl_table_no_const *table;
85513
85514 table = kmemdup(ipv6_icmp_table_template,
85515 sizeof(ipv6_icmp_table_template),
85516 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
85517 index 131dd09..f7ed64f 100644
85518 --- a/net/ipv6/ip6_gre.c
85519 +++ b/net/ipv6/ip6_gre.c
85520 @@ -73,7 +73,7 @@ struct ip6gre_net {
85521 struct net_device *fb_tunnel_dev;
85522 };
85523
85524 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
85525 +static struct rtnl_link_ops ip6gre_link_ops;
85526 static int ip6gre_tunnel_init(struct net_device *dev);
85527 static void ip6gre_tunnel_setup(struct net_device *dev);
85528 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
85529 @@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
85530 }
85531
85532
85533 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
85534 +static struct inet6_protocol ip6gre_protocol = {
85535 .handler = ip6gre_rcv,
85536 .err_handler = ip6gre_err,
85537 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
85538 @@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
85539 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
85540 };
85541
85542 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
85543 +static struct rtnl_link_ops ip6gre_link_ops = {
85544 .kind = "ip6gre",
85545 .maxtype = IFLA_GRE_MAX,
85546 .policy = ip6gre_policy,
85547 @@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
85548 .fill_info = ip6gre_fill_info,
85549 };
85550
85551 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
85552 +static struct rtnl_link_ops ip6gre_tap_ops = {
85553 .kind = "ip6gretap",
85554 .maxtype = IFLA_GRE_MAX,
85555 .policy = ip6gre_policy,
85556 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
85557 index a14f28b..b4b8956 100644
85558 --- a/net/ipv6/ip6_tunnel.c
85559 +++ b/net/ipv6/ip6_tunnel.c
85560 @@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
85561
85562 static int ip6_tnl_dev_init(struct net_device *dev);
85563 static void ip6_tnl_dev_setup(struct net_device *dev);
85564 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
85565 +static struct rtnl_link_ops ip6_link_ops;
85566
85567 static int ip6_tnl_net_id __read_mostly;
85568 struct ip6_tnl_net {
85569 @@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
85570 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
85571 };
85572
85573 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
85574 +static struct rtnl_link_ops ip6_link_ops = {
85575 .kind = "ip6tnl",
85576 .maxtype = IFLA_IPTUN_MAX,
85577 .policy = ip6_tnl_policy,
85578 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
85579 index d1e2e8e..51c19ae 100644
85580 --- a/net/ipv6/ipv6_sockglue.c
85581 +++ b/net/ipv6/ipv6_sockglue.c
85582 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
85583 if (sk->sk_type != SOCK_STREAM)
85584 return -ENOPROTOOPT;
85585
85586 - msg.msg_control = optval;
85587 + msg.msg_control = (void __force_kernel *)optval;
85588 msg.msg_controllen = len;
85589 msg.msg_flags = flags;
85590
85591 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
85592 index 125a90d..2a11f36 100644
85593 --- a/net/ipv6/netfilter/ip6_tables.c
85594 +++ b/net/ipv6/netfilter/ip6_tables.c
85595 @@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
85596 #endif
85597
85598 static int get_info(struct net *net, void __user *user,
85599 - const int *len, int compat)
85600 + int len, int compat)
85601 {
85602 char name[XT_TABLE_MAXNAMELEN];
85603 struct xt_table *t;
85604 int ret;
85605
85606 - if (*len != sizeof(struct ip6t_getinfo)) {
85607 - duprintf("length %u != %zu\n", *len,
85608 + if (len != sizeof(struct ip6t_getinfo)) {
85609 + duprintf("length %u != %zu\n", len,
85610 sizeof(struct ip6t_getinfo));
85611 return -EINVAL;
85612 }
85613 @@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
85614 info.size = private->size;
85615 strcpy(info.name, name);
85616
85617 - if (copy_to_user(user, &info, *len) != 0)
85618 + if (copy_to_user(user, &info, len) != 0)
85619 ret = -EFAULT;
85620 else
85621 ret = 0;
85622 @@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85623
85624 switch (cmd) {
85625 case IP6T_SO_GET_INFO:
85626 - ret = get_info(sock_net(sk), user, len, 1);
85627 + ret = get_info(sock_net(sk), user, *len, 1);
85628 break;
85629 case IP6T_SO_GET_ENTRIES:
85630 ret = compat_get_entries(sock_net(sk), user, len);
85631 @@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85632
85633 switch (cmd) {
85634 case IP6T_SO_GET_INFO:
85635 - ret = get_info(sock_net(sk), user, len, 0);
85636 + ret = get_info(sock_net(sk), user, *len, 0);
85637 break;
85638
85639 case IP6T_SO_GET_ENTRIES:
85640 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
85641 index 3dacecc..71c5adb 100644
85642 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
85643 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
85644 @@ -87,10 +87,9 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
85645
85646 static int nf_ct_frag6_sysctl_register(struct net *net)
85647 {
85648 - struct ctl_table *table;
85649 + ctl_table_no_const *table = NULL;
85650 struct ctl_table_header *hdr;
85651
85652 - table = nf_ct_frag6_sysctl_table;
85653 if (!net_eq(net, &init_net)) {
85654 table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
85655 GFP_KERNEL);
85656 @@ -100,9 +99,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
85657 table[0].data = &net->ipv6.frags.high_thresh;
85658 table[1].data = &net->ipv6.frags.low_thresh;
85659 table[2].data = &net->ipv6.frags.timeout;
85660 - }
85661 -
85662 - hdr = register_net_sysctl(net, "net/netfilter", table);
85663 + hdr = register_net_sysctl(net, "net/netfilter", table);
85664 + } else
85665 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
85666 if (hdr == NULL)
85667 goto err_reg;
85668
85669 @@ -110,8 +109,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
85670 return 0;
85671
85672 err_reg:
85673 - if (!net_eq(net, &init_net))
85674 - kfree(table);
85675 + kfree(table);
85676 err_alloc:
85677 return -ENOMEM;
85678 }
85679 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
85680 index 70fa814..d70c28c 100644
85681 --- a/net/ipv6/raw.c
85682 +++ b/net/ipv6/raw.c
85683 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
85684 {
85685 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
85686 skb_checksum_complete(skb)) {
85687 - atomic_inc(&sk->sk_drops);
85688 + atomic_inc_unchecked(&sk->sk_drops);
85689 kfree_skb(skb);
85690 return NET_RX_DROP;
85691 }
85692 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
85693 struct raw6_sock *rp = raw6_sk(sk);
85694
85695 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
85696 - atomic_inc(&sk->sk_drops);
85697 + atomic_inc_unchecked(&sk->sk_drops);
85698 kfree_skb(skb);
85699 return NET_RX_DROP;
85700 }
85701 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
85702
85703 if (inet->hdrincl) {
85704 if (skb_checksum_complete(skb)) {
85705 - atomic_inc(&sk->sk_drops);
85706 + atomic_inc_unchecked(&sk->sk_drops);
85707 kfree_skb(skb);
85708 return NET_RX_DROP;
85709 }
85710 @@ -604,7 +604,7 @@ out:
85711 return err;
85712 }
85713
85714 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
85715 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
85716 struct flowi6 *fl6, struct dst_entry **dstp,
85717 unsigned int flags)
85718 {
85719 @@ -916,12 +916,15 @@ do_confirm:
85720 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
85721 char __user *optval, int optlen)
85722 {
85723 + struct icmp6_filter filter;
85724 +
85725 switch (optname) {
85726 case ICMPV6_FILTER:
85727 if (optlen > sizeof(struct icmp6_filter))
85728 optlen = sizeof(struct icmp6_filter);
85729 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
85730 + if (copy_from_user(&filter, optval, optlen))
85731 return -EFAULT;
85732 + raw6_sk(sk)->filter = filter;
85733 return 0;
85734 default:
85735 return -ENOPROTOOPT;
85736 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
85737 char __user *optval, int __user *optlen)
85738 {
85739 int len;
85740 + struct icmp6_filter filter;
85741
85742 switch (optname) {
85743 case ICMPV6_FILTER:
85744 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
85745 len = sizeof(struct icmp6_filter);
85746 if (put_user(len, optlen))
85747 return -EFAULT;
85748 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
85749 + filter = raw6_sk(sk)->filter;
85750 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
85751 return -EFAULT;
85752 return 0;
85753 default:
85754 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
85755 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
85756 0,
85757 sock_i_ino(sp),
85758 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
85759 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
85760 }
85761
85762 static int raw6_seq_show(struct seq_file *seq, void *v)
85763 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
85764 index e5253ec..7b06a3b 100644
85765 --- a/net/ipv6/reassembly.c
85766 +++ b/net/ipv6/reassembly.c
85767 @@ -604,10 +604,9 @@ static struct ctl_table ip6_frags_ctl_table[] = {
85768
85769 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
85770 {
85771 - struct ctl_table *table;
85772 + ctl_table_no_const *table = NULL;
85773 struct ctl_table_header *hdr;
85774
85775 - table = ip6_frags_ns_ctl_table;
85776 if (!net_eq(net, &init_net)) {
85777 table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
85778 if (table == NULL)
85779 @@ -620,9 +619,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
85780 /* Don't export sysctls to unprivileged users */
85781 if (net->user_ns != &init_user_ns)
85782 table[0].procname = NULL;
85783 - }
85784 + hdr = register_net_sysctl(net, "net/ipv6", table);
85785 + } else
85786 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
85787
85788 - hdr = register_net_sysctl(net, "net/ipv6", table);
85789 if (hdr == NULL)
85790 goto err_reg;
85791
85792 @@ -630,8 +630,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
85793 return 0;
85794
85795 err_reg:
85796 - if (!net_eq(net, &init_net))
85797 - kfree(table);
85798 + kfree(table);
85799 err_alloc:
85800 return -ENOMEM;
85801 }
85802 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
85803 index 6f9f7b6..2306d63 100644
85804 --- a/net/ipv6/route.c
85805 +++ b/net/ipv6/route.c
85806 @@ -2965,7 +2965,7 @@ ctl_table ipv6_route_table_template[] = {
85807
85808 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
85809 {
85810 - struct ctl_table *table;
85811 + ctl_table_no_const *table;
85812
85813 table = kmemdup(ipv6_route_table_template,
85814 sizeof(ipv6_route_table_template),
85815 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
85816 index cfba99b..20ca511 100644
85817 --- a/net/ipv6/sit.c
85818 +++ b/net/ipv6/sit.c
85819 @@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
85820 static int ipip6_tunnel_init(struct net_device *dev);
85821 static void ipip6_tunnel_setup(struct net_device *dev);
85822 static void ipip6_dev_free(struct net_device *dev);
85823 -static struct rtnl_link_ops sit_link_ops __read_mostly;
85824 +static struct rtnl_link_ops sit_link_ops;
85825
85826 static int sit_net_id __read_mostly;
85827 struct sit_net {
85828 @@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
85829 #endif
85830 };
85831
85832 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
85833 +static struct rtnl_link_ops sit_link_ops = {
85834 .kind = "sit",
85835 .maxtype = IFLA_IPTUN_MAX,
85836 .policy = ipip6_policy,
85837 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
85838 index e85c48b..b8268d3 100644
85839 --- a/net/ipv6/sysctl_net_ipv6.c
85840 +++ b/net/ipv6/sysctl_net_ipv6.c
85841 @@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
85842
85843 static int __net_init ipv6_sysctl_net_init(struct net *net)
85844 {
85845 - struct ctl_table *ipv6_table;
85846 + ctl_table_no_const *ipv6_table;
85847 struct ctl_table *ipv6_route_table;
85848 struct ctl_table *ipv6_icmp_table;
85849 int err;
85850 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
85851 index 4f435371..5de9da7 100644
85852 --- a/net/ipv6/tcp_ipv6.c
85853 +++ b/net/ipv6/tcp_ipv6.c
85854 @@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
85855 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
85856 }
85857
85858 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85859 +extern int grsec_enable_blackhole;
85860 +#endif
85861 +
85862 static void tcp_v6_hash(struct sock *sk)
85863 {
85864 if (sk->sk_state != TCP_CLOSE) {
85865 @@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
85866 return 0;
85867
85868 reset:
85869 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85870 + if (!grsec_enable_blackhole)
85871 +#endif
85872 tcp_v6_send_reset(sk, skb);
85873 discard:
85874 if (opt_skb)
85875 @@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
85876 TCP_SKB_CB(skb)->sacked = 0;
85877
85878 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
85879 - if (!sk)
85880 + if (!sk) {
85881 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85882 + ret = 1;
85883 +#endif
85884 goto no_tcp_socket;
85885 + }
85886
85887 process:
85888 - if (sk->sk_state == TCP_TIME_WAIT)
85889 + if (sk->sk_state == TCP_TIME_WAIT) {
85890 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85891 + ret = 2;
85892 +#endif
85893 goto do_time_wait;
85894 + }
85895
85896 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
85897 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
85898 @@ -1568,6 +1583,10 @@ no_tcp_socket:
85899 bad_packet:
85900 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
85901 } else {
85902 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85903 + if (!grsec_enable_blackhole || (ret == 1 &&
85904 + (skb->dev->flags & IFF_LOOPBACK)))
85905 +#endif
85906 tcp_v6_send_reset(NULL, skb);
85907 }
85908
85909 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
85910 index fb08329..2d6919e 100644
85911 --- a/net/ipv6/udp.c
85912 +++ b/net/ipv6/udp.c
85913 @@ -51,6 +51,10 @@
85914 #include <trace/events/skb.h>
85915 #include "udp_impl.h"
85916
85917 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85918 +extern int grsec_enable_blackhole;
85919 +#endif
85920 +
85921 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
85922 {
85923 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
85924 @@ -395,7 +399,7 @@ try_again:
85925 if (unlikely(err)) {
85926 trace_kfree_skb(skb, udpv6_recvmsg);
85927 if (!peeked) {
85928 - atomic_inc(&sk->sk_drops);
85929 + atomic_inc_unchecked(&sk->sk_drops);
85930 if (is_udp4)
85931 UDP_INC_STATS_USER(sock_net(sk),
85932 UDP_MIB_INERRORS,
85933 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85934 return rc;
85935 drop:
85936 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
85937 - atomic_inc(&sk->sk_drops);
85938 + atomic_inc_unchecked(&sk->sk_drops);
85939 kfree_skb(skb);
85940 return -1;
85941 }
85942 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
85943 if (likely(skb1 == NULL))
85944 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
85945 if (!skb1) {
85946 - atomic_inc(&sk->sk_drops);
85947 + atomic_inc_unchecked(&sk->sk_drops);
85948 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
85949 IS_UDPLITE(sk));
85950 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
85951 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
85952 goto discard;
85953
85954 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
85955 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85956 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
85957 +#endif
85958 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
85959
85960 kfree_skb(skb);
85961 @@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
85962 0,
85963 sock_i_ino(sp),
85964 atomic_read(&sp->sk_refcnt), sp,
85965 - atomic_read(&sp->sk_drops));
85966 + atomic_read_unchecked(&sp->sk_drops));
85967 }
85968
85969 int udp6_seq_show(struct seq_file *seq, void *v)
85970 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
85971 index a68c88c..d55b0c5 100644
85972 --- a/net/irda/ircomm/ircomm_tty.c
85973 +++ b/net/irda/ircomm/ircomm_tty.c
85974 @@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
85975 add_wait_queue(&port->open_wait, &wait);
85976
85977 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
85978 - __FILE__, __LINE__, tty->driver->name, port->count);
85979 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
85980
85981 spin_lock_irqsave(&port->lock, flags);
85982 if (!tty_hung_up_p(filp)) {
85983 extra_count = 1;
85984 - port->count--;
85985 + atomic_dec(&port->count);
85986 }
85987 spin_unlock_irqrestore(&port->lock, flags);
85988 port->blocked_open++;
85989 @@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
85990 }
85991
85992 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
85993 - __FILE__, __LINE__, tty->driver->name, port->count);
85994 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
85995
85996 schedule();
85997 }
85998 @@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
85999 if (extra_count) {
86000 /* ++ is not atomic, so this should be protected - Jean II */
86001 spin_lock_irqsave(&port->lock, flags);
86002 - port->count++;
86003 + atomic_inc(&port->count);
86004 spin_unlock_irqrestore(&port->lock, flags);
86005 }
86006 port->blocked_open--;
86007
86008 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
86009 - __FILE__, __LINE__, tty->driver->name, port->count);
86010 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
86011
86012 if (!retval)
86013 port->flags |= ASYNC_NORMAL_ACTIVE;
86014 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
86015
86016 /* ++ is not atomic, so this should be protected - Jean II */
86017 spin_lock_irqsave(&self->port.lock, flags);
86018 - self->port.count++;
86019 + atomic_inc(&self->port.count);
86020 spin_unlock_irqrestore(&self->port.lock, flags);
86021 tty_port_tty_set(&self->port, tty);
86022
86023 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
86024 - self->line, self->port.count);
86025 + self->line, atomic_read(&self->port.count));
86026
86027 /* Not really used by us, but lets do it anyway */
86028 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
86029 @@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
86030 tty_kref_put(port->tty);
86031 }
86032 port->tty = NULL;
86033 - port->count = 0;
86034 + atomic_set(&port->count, 0);
86035 spin_unlock_irqrestore(&port->lock, flags);
86036
86037 wake_up_interruptible(&port->open_wait);
86038 @@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
86039 seq_putc(m, '\n');
86040
86041 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
86042 - seq_printf(m, "Open count: %d\n", self->port.count);
86043 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
86044 seq_printf(m, "Max data size: %d\n", self->max_data_size);
86045 seq_printf(m, "Max header size: %d\n", self->max_header_size);
86046
86047 diff --git a/net/irda/iriap.c b/net/irda/iriap.c
86048 index e71e85b..29340a9 100644
86049 --- a/net/irda/iriap.c
86050 +++ b/net/irda/iriap.c
86051 @@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
86052 /* case CS_ISO_8859_9: */
86053 /* case CS_UNICODE: */
86054 default:
86055 - IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
86056 - __func__, ias_charset_types[charset]);
86057 + IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
86058 + __func__, charset,
86059 + charset < ARRAY_SIZE(ias_charset_types) ?
86060 + ias_charset_types[charset] :
86061 + "(unknown)");
86062
86063 /* Aborting, close connection! */
86064 iriap_disconnect_request(self);
86065 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
86066 index cd6f7a9..e63fe89 100644
86067 --- a/net/iucv/af_iucv.c
86068 +++ b/net/iucv/af_iucv.c
86069 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
86070
86071 write_lock_bh(&iucv_sk_list.lock);
86072
86073 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
86074 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
86075 while (__iucv_get_sock_by_name(name)) {
86076 sprintf(name, "%08x",
86077 - atomic_inc_return(&iucv_sk_list.autobind_name));
86078 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
86079 }
86080
86081 write_unlock_bh(&iucv_sk_list.lock);
86082 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
86083 index df08250..02021fe 100644
86084 --- a/net/iucv/iucv.c
86085 +++ b/net/iucv/iucv.c
86086 @@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
86087 return NOTIFY_OK;
86088 }
86089
86090 -static struct notifier_block __refdata iucv_cpu_notifier = {
86091 +static struct notifier_block iucv_cpu_notifier = {
86092 .notifier_call = iucv_cpu_notify,
86093 };
86094
86095 diff --git a/net/key/af_key.c b/net/key/af_key.c
86096 index 5b426a6..970032b 100644
86097 --- a/net/key/af_key.c
86098 +++ b/net/key/af_key.c
86099 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
86100 static u32 get_acqseq(void)
86101 {
86102 u32 res;
86103 - static atomic_t acqseq;
86104 + static atomic_unchecked_t acqseq;
86105
86106 do {
86107 - res = atomic_inc_return(&acqseq);
86108 + res = atomic_inc_return_unchecked(&acqseq);
86109 } while (!res);
86110 return res;
86111 }
86112 diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
86113 index 716605c..044e9e1 100644
86114 --- a/net/l2tp/l2tp_ppp.c
86115 +++ b/net/l2tp/l2tp_ppp.c
86116 @@ -355,6 +355,7 @@ static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msgh
86117 l2tp_xmit_skb(session, skb, session->hdr_len);
86118
86119 sock_put(ps->tunnel_sock);
86120 + sock_put(sk);
86121
86122 return error;
86123
86124 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
86125 index 0479c64..d031db6 100644
86126 --- a/net/mac80211/cfg.c
86127 +++ b/net/mac80211/cfg.c
86128 @@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
86129 ret = ieee80211_vif_use_channel(sdata, chandef,
86130 IEEE80211_CHANCTX_EXCLUSIVE);
86131 }
86132 - } else if (local->open_count == local->monitors) {
86133 + } else if (local_read(&local->open_count) == local->monitors) {
86134 local->_oper_channel = chandef->chan;
86135 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
86136 ieee80211_hw_config(local, 0);
86137 @@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
86138 else
86139 local->probe_req_reg--;
86140
86141 - if (!local->open_count)
86142 + if (!local_read(&local->open_count))
86143 break;
86144
86145 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
86146 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
86147 index 2ed065c..948177f 100644
86148 --- a/net/mac80211/ieee80211_i.h
86149 +++ b/net/mac80211/ieee80211_i.h
86150 @@ -28,6 +28,7 @@
86151 #include <net/ieee80211_radiotap.h>
86152 #include <net/cfg80211.h>
86153 #include <net/mac80211.h>
86154 +#include <asm/local.h>
86155 #include "key.h"
86156 #include "sta_info.h"
86157 #include "debug.h"
86158 @@ -909,7 +910,7 @@ struct ieee80211_local {
86159 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
86160 spinlock_t queue_stop_reason_lock;
86161
86162 - int open_count;
86163 + local_t open_count;
86164 int monitors, cooked_mntrs;
86165 /* number of interfaces with corresponding FIF_ flags */
86166 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
86167 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
86168 index 8be854e..ad72a69 100644
86169 --- a/net/mac80211/iface.c
86170 +++ b/net/mac80211/iface.c
86171 @@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86172 break;
86173 }
86174
86175 - if (local->open_count == 0) {
86176 + if (local_read(&local->open_count) == 0) {
86177 res = drv_start(local);
86178 if (res)
86179 goto err_del_bss;
86180 @@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86181 break;
86182 }
86183
86184 - if (local->monitors == 0 && local->open_count == 0) {
86185 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
86186 res = ieee80211_add_virtual_monitor(local);
86187 if (res)
86188 goto err_stop;
86189 @@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86190 mutex_unlock(&local->mtx);
86191
86192 if (coming_up)
86193 - local->open_count++;
86194 + local_inc(&local->open_count);
86195
86196 if (hw_reconf_flags)
86197 ieee80211_hw_config(local, hw_reconf_flags);
86198 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86199 err_del_interface:
86200 drv_remove_interface(local, sdata);
86201 err_stop:
86202 - if (!local->open_count)
86203 + if (!local_read(&local->open_count))
86204 drv_stop(local);
86205 err_del_bss:
86206 sdata->bss = NULL;
86207 @@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86208 }
86209
86210 if (going_down)
86211 - local->open_count--;
86212 + local_dec(&local->open_count);
86213
86214 switch (sdata->vif.type) {
86215 case NL80211_IFTYPE_AP_VLAN:
86216 @@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86217
86218 ieee80211_recalc_ps(local, -1);
86219
86220 - if (local->open_count == 0) {
86221 + if (local_read(&local->open_count) == 0) {
86222 if (local->ops->napi_poll)
86223 napi_disable(&local->napi);
86224 ieee80211_clear_tx_pending(local);
86225 @@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86226 }
86227 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
86228
86229 - if (local->monitors == local->open_count && local->monitors > 0)
86230 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
86231 ieee80211_add_virtual_monitor(local);
86232 }
86233
86234 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
86235 index 1b087ff..bf600e9 100644
86236 --- a/net/mac80211/main.c
86237 +++ b/net/mac80211/main.c
86238 @@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
86239 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
86240 IEEE80211_CONF_CHANGE_POWER);
86241
86242 - if (changed && local->open_count) {
86243 + if (changed && local_read(&local->open_count)) {
86244 ret = drv_config(local, changed);
86245 /*
86246 * Goal:
86247 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
86248 index 79a48f3..5e185c9 100644
86249 --- a/net/mac80211/pm.c
86250 +++ b/net/mac80211/pm.c
86251 @@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86252 struct sta_info *sta;
86253 struct ieee80211_chanctx *ctx;
86254
86255 - if (!local->open_count)
86256 + if (!local_read(&local->open_count))
86257 goto suspend;
86258
86259 ieee80211_scan_cancel(local);
86260 @@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86261 cancel_work_sync(&local->dynamic_ps_enable_work);
86262 del_timer_sync(&local->dynamic_ps_timer);
86263
86264 - local->wowlan = wowlan && local->open_count;
86265 + local->wowlan = wowlan && local_read(&local->open_count);
86266 if (local->wowlan) {
86267 int err = drv_suspend(local, wowlan);
86268 if (err < 0) {
86269 @@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86270 mutex_unlock(&local->chanctx_mtx);
86271
86272 /* stop hardware - this must stop RX */
86273 - if (local->open_count)
86274 + if (local_read(&local->open_count))
86275 ieee80211_stop_device(local);
86276
86277 suspend:
86278 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
86279 index dd88381..eef4dd6 100644
86280 --- a/net/mac80211/rate.c
86281 +++ b/net/mac80211/rate.c
86282 @@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
86283
86284 ASSERT_RTNL();
86285
86286 - if (local->open_count)
86287 + if (local_read(&local->open_count))
86288 return -EBUSY;
86289
86290 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
86291 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
86292 index c97a065..ff61928 100644
86293 --- a/net/mac80211/rc80211_pid_debugfs.c
86294 +++ b/net/mac80211/rc80211_pid_debugfs.c
86295 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
86296
86297 spin_unlock_irqrestore(&events->lock, status);
86298
86299 - if (copy_to_user(buf, pb, p))
86300 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
86301 return -EFAULT;
86302
86303 return p;
86304 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
86305 index f11e8c5..08d0013 100644
86306 --- a/net/mac80211/util.c
86307 +++ b/net/mac80211/util.c
86308 @@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
86309 }
86310 #endif
86311 /* everything else happens only if HW was up & running */
86312 - if (!local->open_count)
86313 + if (!local_read(&local->open_count))
86314 goto wake_up;
86315
86316 /*
86317 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
86318 index 49e96df..63a51c3 100644
86319 --- a/net/netfilter/Kconfig
86320 +++ b/net/netfilter/Kconfig
86321 @@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
86322
86323 To compile it as a module, choose M here. If unsure, say N.
86324
86325 +config NETFILTER_XT_MATCH_GRADM
86326 + tristate '"gradm" match support'
86327 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
86328 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
86329 + ---help---
86330 + The gradm match allows to match on grsecurity RBAC being enabled.
86331 + It is useful when iptables rules are applied early on bootup to
86332 + prevent connections to the machine (except from a trusted host)
86333 + while the RBAC system is disabled.
86334 +
86335 config NETFILTER_XT_MATCH_HASHLIMIT
86336 tristate '"hashlimit" match support'
86337 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
86338 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
86339 index 3259697..54d5393 100644
86340 --- a/net/netfilter/Makefile
86341 +++ b/net/netfilter/Makefile
86342 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
86343 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
86344 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
86345 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
86346 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
86347 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
86348 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
86349 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
86350 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
86351 index 6d6d8f2..a676749 100644
86352 --- a/net/netfilter/ipset/ip_set_core.c
86353 +++ b/net/netfilter/ipset/ip_set_core.c
86354 @@ -1800,7 +1800,7 @@ done:
86355 return ret;
86356 }
86357
86358 -static struct nf_sockopt_ops so_set __read_mostly = {
86359 +static struct nf_sockopt_ops so_set = {
86360 .pf = PF_INET,
86361 .get_optmin = SO_IP_SET,
86362 .get_optmax = SO_IP_SET + 1,
86363 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
86364 index 30e764a..c3b6a9d 100644
86365 --- a/net/netfilter/ipvs/ip_vs_conn.c
86366 +++ b/net/netfilter/ipvs/ip_vs_conn.c
86367 @@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
86368 /* Increase the refcnt counter of the dest */
86369 atomic_inc(&dest->refcnt);
86370
86371 - conn_flags = atomic_read(&dest->conn_flags);
86372 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
86373 if (cp->protocol != IPPROTO_UDP)
86374 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
86375 flags = cp->flags;
86376 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
86377 atomic_set(&cp->refcnt, 1);
86378
86379 atomic_set(&cp->n_control, 0);
86380 - atomic_set(&cp->in_pkts, 0);
86381 + atomic_set_unchecked(&cp->in_pkts, 0);
86382
86383 atomic_inc(&ipvs->conn_count);
86384 if (flags & IP_VS_CONN_F_NO_CPORT)
86385 @@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
86386
86387 /* Don't drop the entry if its number of incoming packets is not
86388 located in [0, 8] */
86389 - i = atomic_read(&cp->in_pkts);
86390 + i = atomic_read_unchecked(&cp->in_pkts);
86391 if (i > 8 || i < 0) return 0;
86392
86393 if (!todrop_rate[i]) return 0;
86394 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
86395 index 47edf5a..235b07d 100644
86396 --- a/net/netfilter/ipvs/ip_vs_core.c
86397 +++ b/net/netfilter/ipvs/ip_vs_core.c
86398 @@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
86399 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
86400 /* do not touch skb anymore */
86401
86402 - atomic_inc(&cp->in_pkts);
86403 + atomic_inc_unchecked(&cp->in_pkts);
86404 ip_vs_conn_put(cp);
86405 return ret;
86406 }
86407 @@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
86408 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
86409 pkts = sysctl_sync_threshold(ipvs);
86410 else
86411 - pkts = atomic_add_return(1, &cp->in_pkts);
86412 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86413
86414 if (ipvs->sync_state & IP_VS_STATE_MASTER)
86415 ip_vs_sync_conn(net, cp, pkts);
86416 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
86417 index ec664cb..7f34a77 100644
86418 --- a/net/netfilter/ipvs/ip_vs_ctl.c
86419 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
86420 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
86421 ip_vs_rs_hash(ipvs, dest);
86422 write_unlock_bh(&ipvs->rs_lock);
86423 }
86424 - atomic_set(&dest->conn_flags, conn_flags);
86425 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
86426
86427 /* bind the service */
86428 if (!dest->svc) {
86429 @@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
86430 * align with netns init in ip_vs_control_net_init()
86431 */
86432
86433 -static struct ctl_table vs_vars[] = {
86434 +static ctl_table_no_const vs_vars[] __read_only = {
86435 {
86436 .procname = "amemthresh",
86437 .maxlen = sizeof(int),
86438 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
86439 " %-7s %-6d %-10d %-10d\n",
86440 &dest->addr.in6,
86441 ntohs(dest->port),
86442 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
86443 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
86444 atomic_read(&dest->weight),
86445 atomic_read(&dest->activeconns),
86446 atomic_read(&dest->inactconns));
86447 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
86448 "%-7s %-6d %-10d %-10d\n",
86449 ntohl(dest->addr.ip),
86450 ntohs(dest->port),
86451 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
86452 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
86453 atomic_read(&dest->weight),
86454 atomic_read(&dest->activeconns),
86455 atomic_read(&dest->inactconns));
86456 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
86457
86458 entry.addr = dest->addr.ip;
86459 entry.port = dest->port;
86460 - entry.conn_flags = atomic_read(&dest->conn_flags);
86461 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
86462 entry.weight = atomic_read(&dest->weight);
86463 entry.u_threshold = dest->u_threshold;
86464 entry.l_threshold = dest->l_threshold;
86465 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
86466 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
86467 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
86468 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
86469 - (atomic_read(&dest->conn_flags) &
86470 + (atomic_read_unchecked(&dest->conn_flags) &
86471 IP_VS_CONN_F_FWD_MASK)) ||
86472 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
86473 atomic_read(&dest->weight)) ||
86474 @@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
86475 {
86476 int idx;
86477 struct netns_ipvs *ipvs = net_ipvs(net);
86478 - struct ctl_table *tbl;
86479 + ctl_table_no_const *tbl;
86480
86481 atomic_set(&ipvs->dropentry, 0);
86482 spin_lock_init(&ipvs->dropentry_lock);
86483 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
86484 index fdd89b9..bd96aa9 100644
86485 --- a/net/netfilter/ipvs/ip_vs_lblc.c
86486 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
86487 @@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
86488 * IPVS LBLC sysctl table
86489 */
86490 #ifdef CONFIG_SYSCTL
86491 -static ctl_table vs_vars_table[] = {
86492 +static ctl_table_no_const vs_vars_table[] __read_only = {
86493 {
86494 .procname = "lblc_expiration",
86495 .data = NULL,
86496 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
86497 index c03b6a3..8ce3681 100644
86498 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
86499 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
86500 @@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
86501 * IPVS LBLCR sysctl table
86502 */
86503
86504 -static ctl_table vs_vars_table[] = {
86505 +static ctl_table_no_const vs_vars_table[] __read_only = {
86506 {
86507 .procname = "lblcr_expiration",
86508 .data = NULL,
86509 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
86510 index 44fd10c..2a163b3 100644
86511 --- a/net/netfilter/ipvs/ip_vs_sync.c
86512 +++ b/net/netfilter/ipvs/ip_vs_sync.c
86513 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
86514 cp = cp->control;
86515 if (cp) {
86516 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
86517 - pkts = atomic_add_return(1, &cp->in_pkts);
86518 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86519 else
86520 pkts = sysctl_sync_threshold(ipvs);
86521 ip_vs_sync_conn(net, cp->control, pkts);
86522 @@ -758,7 +758,7 @@ control:
86523 if (!cp)
86524 return;
86525 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
86526 - pkts = atomic_add_return(1, &cp->in_pkts);
86527 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86528 else
86529 pkts = sysctl_sync_threshold(ipvs);
86530 goto sloop;
86531 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
86532
86533 if (opt)
86534 memcpy(&cp->in_seq, opt, sizeof(*opt));
86535 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
86536 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
86537 cp->state = state;
86538 cp->old_state = cp->state;
86539 /*
86540 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
86541 index ee6b7a9..f9a89f6 100644
86542 --- a/net/netfilter/ipvs/ip_vs_xmit.c
86543 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
86544 @@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
86545 else
86546 rc = NF_ACCEPT;
86547 /* do not touch skb anymore */
86548 - atomic_inc(&cp->in_pkts);
86549 + atomic_inc_unchecked(&cp->in_pkts);
86550 goto out;
86551 }
86552
86553 @@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
86554 else
86555 rc = NF_ACCEPT;
86556 /* do not touch skb anymore */
86557 - atomic_inc(&cp->in_pkts);
86558 + atomic_inc_unchecked(&cp->in_pkts);
86559 goto out;
86560 }
86561
86562 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
86563 index 7df424e..a527b02 100644
86564 --- a/net/netfilter/nf_conntrack_acct.c
86565 +++ b/net/netfilter/nf_conntrack_acct.c
86566 @@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
86567 #ifdef CONFIG_SYSCTL
86568 static int nf_conntrack_acct_init_sysctl(struct net *net)
86569 {
86570 - struct ctl_table *table;
86571 + ctl_table_no_const *table;
86572
86573 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
86574 GFP_KERNEL);
86575 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
86576 index e4a0c4f..c263f28 100644
86577 --- a/net/netfilter/nf_conntrack_core.c
86578 +++ b/net/netfilter/nf_conntrack_core.c
86579 @@ -1529,6 +1529,10 @@ err_extend:
86580 #define DYING_NULLS_VAL ((1<<30)+1)
86581 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
86582
86583 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86584 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
86585 +#endif
86586 +
86587 static int nf_conntrack_init_net(struct net *net)
86588 {
86589 int ret;
86590 @@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
86591 goto err_stat;
86592 }
86593
86594 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86595 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
86596 +#else
86597 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
86598 +#endif
86599 if (!net->ct.slabname) {
86600 ret = -ENOMEM;
86601 goto err_slabname;
86602 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
86603 index faa978f..1afb18f 100644
86604 --- a/net/netfilter/nf_conntrack_ecache.c
86605 +++ b/net/netfilter/nf_conntrack_ecache.c
86606 @@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
86607 #ifdef CONFIG_SYSCTL
86608 static int nf_conntrack_event_init_sysctl(struct net *net)
86609 {
86610 - struct ctl_table *table;
86611 + ctl_table_no_const *table;
86612
86613 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
86614 GFP_KERNEL);
86615 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
86616 index 884f2b3..d53b33a 100644
86617 --- a/net/netfilter/nf_conntrack_helper.c
86618 +++ b/net/netfilter/nf_conntrack_helper.c
86619 @@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
86620
86621 static int nf_conntrack_helper_init_sysctl(struct net *net)
86622 {
86623 - struct ctl_table *table;
86624 + ctl_table_no_const *table;
86625
86626 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
86627 GFP_KERNEL);
86628 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
86629 index 51e928d..72a413a 100644
86630 --- a/net/netfilter/nf_conntrack_proto.c
86631 +++ b/net/netfilter/nf_conntrack_proto.c
86632 @@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
86633
86634 static void
86635 nf_ct_unregister_sysctl(struct ctl_table_header **header,
86636 - struct ctl_table **table,
86637 + ctl_table_no_const **table,
86638 unsigned int users)
86639 {
86640 if (users > 0)
86641 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
86642 index e7185c6..4ad6c9c 100644
86643 --- a/net/netfilter/nf_conntrack_standalone.c
86644 +++ b/net/netfilter/nf_conntrack_standalone.c
86645 @@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
86646
86647 static int nf_conntrack_standalone_init_sysctl(struct net *net)
86648 {
86649 - struct ctl_table *table;
86650 + ctl_table_no_const *table;
86651
86652 if (net_eq(net, &init_net)) {
86653 nf_ct_netfilter_header =
86654 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
86655 index 7ea8026..bc9512d 100644
86656 --- a/net/netfilter/nf_conntrack_timestamp.c
86657 +++ b/net/netfilter/nf_conntrack_timestamp.c
86658 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
86659 #ifdef CONFIG_SYSCTL
86660 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
86661 {
86662 - struct ctl_table *table;
86663 + ctl_table_no_const *table;
86664
86665 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
86666 GFP_KERNEL);
86667 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
86668 index 9e31269..bc4c1b7 100644
86669 --- a/net/netfilter/nf_log.c
86670 +++ b/net/netfilter/nf_log.c
86671 @@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
86672
86673 #ifdef CONFIG_SYSCTL
86674 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
86675 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
86676 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
86677 static struct ctl_table_header *nf_log_dir_header;
86678
86679 static int nf_log_proc_dostring(ctl_table *table, int write,
86680 @@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
86681 rcu_assign_pointer(nf_loggers[tindex], logger);
86682 mutex_unlock(&nf_log_mutex);
86683 } else {
86684 + ctl_table_no_const nf_log_table = *table;
86685 +
86686 mutex_lock(&nf_log_mutex);
86687 logger = rcu_dereference_protected(nf_loggers[tindex],
86688 lockdep_is_held(&nf_log_mutex));
86689 if (!logger)
86690 - table->data = "NONE";
86691 + nf_log_table.data = "NONE";
86692 else
86693 - table->data = logger->name;
86694 - r = proc_dostring(table, write, buffer, lenp, ppos);
86695 + nf_log_table.data = logger->name;
86696 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
86697 mutex_unlock(&nf_log_mutex);
86698 }
86699
86700 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
86701 index f042ae5..30ea486 100644
86702 --- a/net/netfilter/nf_sockopt.c
86703 +++ b/net/netfilter/nf_sockopt.c
86704 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
86705 }
86706 }
86707
86708 - list_add(&reg->list, &nf_sockopts);
86709 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
86710 out:
86711 mutex_unlock(&nf_sockopt_mutex);
86712 return ret;
86713 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
86714 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
86715 {
86716 mutex_lock(&nf_sockopt_mutex);
86717 - list_del(&reg->list);
86718 + pax_list_del((struct list_head *)&reg->list);
86719 mutex_unlock(&nf_sockopt_mutex);
86720 }
86721 EXPORT_SYMBOL(nf_unregister_sockopt);
86722 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
86723 index 92fd8ec..3f6ea4b 100644
86724 --- a/net/netfilter/nfnetlink_log.c
86725 +++ b/net/netfilter/nfnetlink_log.c
86726 @@ -72,7 +72,7 @@ struct nfulnl_instance {
86727 };
86728
86729 static DEFINE_SPINLOCK(instances_lock);
86730 -static atomic_t global_seq;
86731 +static atomic_unchecked_t global_seq;
86732
86733 #define INSTANCE_BUCKETS 16
86734 static struct hlist_head instance_table[INSTANCE_BUCKETS];
86735 @@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
86736 /* global sequence number */
86737 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
86738 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
86739 - htonl(atomic_inc_return(&global_seq))))
86740 + htonl(atomic_inc_return_unchecked(&global_seq))))
86741 goto nla_put_failure;
86742
86743 if (data_len) {
86744 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
86745 new file mode 100644
86746 index 0000000..c566332
86747 --- /dev/null
86748 +++ b/net/netfilter/xt_gradm.c
86749 @@ -0,0 +1,51 @@
86750 +/*
86751 + * gradm match for netfilter
86752 + * Copyright © Zbigniew Krzystolik, 2010
86753 + *
86754 + * This program is free software; you can redistribute it and/or modify
86755 + * it under the terms of the GNU General Public License; either version
86756 + * 2 or 3 as published by the Free Software Foundation.
86757 + */
86758 +#include <linux/module.h>
86759 +#include <linux/moduleparam.h>
86760 +#include <linux/skbuff.h>
86761 +#include <linux/netfilter/x_tables.h>
86762 +#include <linux/grsecurity.h>
86763 +#include <linux/netfilter/xt_gradm.h>
86764 +
86765 +static bool
86766 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
86767 +{
86768 + const struct xt_gradm_mtinfo *info = par->matchinfo;
86769 + bool retval = false;
86770 + if (gr_acl_is_enabled())
86771 + retval = true;
86772 + return retval ^ info->invflags;
86773 +}
86774 +
86775 +static struct xt_match gradm_mt_reg __read_mostly = {
86776 + .name = "gradm",
86777 + .revision = 0,
86778 + .family = NFPROTO_UNSPEC,
86779 + .match = gradm_mt,
86780 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
86781 + .me = THIS_MODULE,
86782 +};
86783 +
86784 +static int __init gradm_mt_init(void)
86785 +{
86786 + return xt_register_match(&gradm_mt_reg);
86787 +}
86788 +
86789 +static void __exit gradm_mt_exit(void)
86790 +{
86791 + xt_unregister_match(&gradm_mt_reg);
86792 +}
86793 +
86794 +module_init(gradm_mt_init);
86795 +module_exit(gradm_mt_exit);
86796 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
86797 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
86798 +MODULE_LICENSE("GPL");
86799 +MODULE_ALIAS("ipt_gradm");
86800 +MODULE_ALIAS("ip6t_gradm");
86801 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
86802 index 4fe4fb4..87a89e5 100644
86803 --- a/net/netfilter/xt_statistic.c
86804 +++ b/net/netfilter/xt_statistic.c
86805 @@ -19,7 +19,7 @@
86806 #include <linux/module.h>
86807
86808 struct xt_statistic_priv {
86809 - atomic_t count;
86810 + atomic_unchecked_t count;
86811 } ____cacheline_aligned_in_smp;
86812
86813 MODULE_LICENSE("GPL");
86814 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
86815 break;
86816 case XT_STATISTIC_MODE_NTH:
86817 do {
86818 - oval = atomic_read(&info->master->count);
86819 + oval = atomic_read_unchecked(&info->master->count);
86820 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
86821 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
86822 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
86823 if (nval == 0)
86824 ret = !ret;
86825 break;
86826 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
86827 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
86828 if (info->master == NULL)
86829 return -ENOMEM;
86830 - atomic_set(&info->master->count, info->u.nth.count);
86831 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
86832
86833 return 0;
86834 }
86835 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
86836 index c0353d5..fcb0270 100644
86837 --- a/net/netlink/af_netlink.c
86838 +++ b/net/netlink/af_netlink.c
86839 @@ -785,7 +785,7 @@ static void netlink_overrun(struct sock *sk)
86840 sk->sk_error_report(sk);
86841 }
86842 }
86843 - atomic_inc(&sk->sk_drops);
86844 + atomic_inc_unchecked(&sk->sk_drops);
86845 }
86846
86847 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
86848 @@ -2071,7 +2071,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
86849 sk_wmem_alloc_get(s),
86850 nlk->cb,
86851 atomic_read(&s->sk_refcnt),
86852 - atomic_read(&s->sk_drops),
86853 + atomic_read_unchecked(&s->sk_drops),
86854 sock_i_ino(s)
86855 );
86856
86857 diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
86858 index f2aabb6..2e5e66e 100644
86859 --- a/net/netlink/genetlink.c
86860 +++ b/net/netlink/genetlink.c
86861 @@ -295,18 +295,20 @@ int genl_register_ops(struct genl_family *family, struct genl_ops *ops)
86862 goto errout;
86863 }
86864
86865 + pax_open_kernel();
86866 if (ops->dumpit)
86867 - ops->flags |= GENL_CMD_CAP_DUMP;
86868 + *(unsigned int *)&ops->flags |= GENL_CMD_CAP_DUMP;
86869 if (ops->doit)
86870 - ops->flags |= GENL_CMD_CAP_DO;
86871 + *(unsigned int *)&ops->flags |= GENL_CMD_CAP_DO;
86872 if (ops->policy)
86873 - ops->flags |= GENL_CMD_CAP_HASPOL;
86874 + *(unsigned int *)&ops->flags |= GENL_CMD_CAP_HASPOL;
86875 + pax_close_kernel();
86876
86877 genl_lock();
86878 - list_add_tail(&ops->ops_list, &family->ops_list);
86879 + pax_list_add_tail((struct list_head *)&ops->ops_list, &family->ops_list);
86880 genl_unlock();
86881
86882 - genl_ctrl_event(CTRL_CMD_NEWOPS, ops);
86883 + genl_ctrl_event(CTRL_CMD_NEWOPS, (void *)ops);
86884 err = 0;
86885 errout:
86886 return err;
86887 @@ -336,9 +338,9 @@ int genl_unregister_ops(struct genl_family *family, struct genl_ops *ops)
86888 genl_lock();
86889 list_for_each_entry(rc, &family->ops_list, ops_list) {
86890 if (rc == ops) {
86891 - list_del(&ops->ops_list);
86892 + pax_list_del((struct list_head *)&ops->ops_list);
86893 genl_unlock();
86894 - genl_ctrl_event(CTRL_CMD_DELOPS, ops);
86895 + genl_ctrl_event(CTRL_CMD_DELOPS, (void *)ops);
86896 return 0;
86897 }
86898 }
86899 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
86900 index 7261eb8..44e8ac6 100644
86901 --- a/net/netrom/af_netrom.c
86902 +++ b/net/netrom/af_netrom.c
86903 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
86904 struct sock *sk = sock->sk;
86905 struct nr_sock *nr = nr_sk(sk);
86906
86907 + memset(sax, 0, sizeof(*sax));
86908 lock_sock(sk);
86909 if (peer != 0) {
86910 if (sk->sk_state != TCP_ESTABLISHED) {
86911 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
86912 *uaddr_len = sizeof(struct full_sockaddr_ax25);
86913 } else {
86914 sax->fsa_ax25.sax25_family = AF_NETROM;
86915 - sax->fsa_ax25.sax25_ndigis = 0;
86916 sax->fsa_ax25.sax25_call = nr->source_addr;
86917 *uaddr_len = sizeof(struct sockaddr_ax25);
86918 }
86919 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
86920 index c111bd0..7788ff7 100644
86921 --- a/net/packet/af_packet.c
86922 +++ b/net/packet/af_packet.c
86923 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
86924
86925 spin_lock(&sk->sk_receive_queue.lock);
86926 po->stats.tp_packets++;
86927 - skb->dropcount = atomic_read(&sk->sk_drops);
86928 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
86929 __skb_queue_tail(&sk->sk_receive_queue, skb);
86930 spin_unlock(&sk->sk_receive_queue.lock);
86931 sk->sk_data_ready(sk, skb->len);
86932 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
86933 drop_n_acct:
86934 spin_lock(&sk->sk_receive_queue.lock);
86935 po->stats.tp_drops++;
86936 - atomic_inc(&sk->sk_drops);
86937 + atomic_inc_unchecked(&sk->sk_drops);
86938 spin_unlock(&sk->sk_receive_queue.lock);
86939
86940 drop_n_restore:
86941 @@ -2565,6 +2565,7 @@ out:
86942
86943 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
86944 {
86945 + struct sock_extended_err ee;
86946 struct sock_exterr_skb *serr;
86947 struct sk_buff *skb, *skb2;
86948 int copied, err;
86949 @@ -2586,8 +2587,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
86950 sock_recv_timestamp(msg, sk, skb);
86951
86952 serr = SKB_EXT_ERR(skb);
86953 + ee = serr->ee;
86954 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
86955 - sizeof(serr->ee), &serr->ee);
86956 + sizeof ee, &ee);
86957
86958 msg->msg_flags |= MSG_ERRQUEUE;
86959 err = copied;
86960 @@ -3212,7 +3214,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
86961 case PACKET_HDRLEN:
86962 if (len > sizeof(int))
86963 len = sizeof(int);
86964 - if (copy_from_user(&val, optval, len))
86965 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
86966 return -EFAULT;
86967 switch (val) {
86968 case TPACKET_V1:
86969 @@ -3254,7 +3256,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
86970 len = lv;
86971 if (put_user(len, optlen))
86972 return -EFAULT;
86973 - if (copy_to_user(optval, data, len))
86974 + if (len > sizeof(st) || copy_to_user(optval, data, len))
86975 return -EFAULT;
86976 return 0;
86977 }
86978 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
86979 index 5a940db..f0b9c12 100644
86980 --- a/net/phonet/af_phonet.c
86981 +++ b/net/phonet/af_phonet.c
86982 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
86983 {
86984 struct phonet_protocol *pp;
86985
86986 - if (protocol >= PHONET_NPROTO)
86987 + if (protocol < 0 || protocol >= PHONET_NPROTO)
86988 return NULL;
86989
86990 rcu_read_lock();
86991 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
86992 {
86993 int err = 0;
86994
86995 - if (protocol >= PHONET_NPROTO)
86996 + if (protocol < 0 || protocol >= PHONET_NPROTO)
86997 return -EINVAL;
86998
86999 err = proto_register(pp->prot, 1);
87000 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
87001 index 576f22c..bc7a71b 100644
87002 --- a/net/phonet/pep.c
87003 +++ b/net/phonet/pep.c
87004 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
87005
87006 case PNS_PEP_CTRL_REQ:
87007 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
87008 - atomic_inc(&sk->sk_drops);
87009 + atomic_inc_unchecked(&sk->sk_drops);
87010 break;
87011 }
87012 __skb_pull(skb, 4);
87013 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
87014 }
87015
87016 if (pn->rx_credits == 0) {
87017 - atomic_inc(&sk->sk_drops);
87018 + atomic_inc_unchecked(&sk->sk_drops);
87019 err = -ENOBUFS;
87020 break;
87021 }
87022 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
87023 }
87024
87025 if (pn->rx_credits == 0) {
87026 - atomic_inc(&sk->sk_drops);
87027 + atomic_inc_unchecked(&sk->sk_drops);
87028 err = NET_RX_DROP;
87029 break;
87030 }
87031 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
87032 index b7e9827..c264c85 100644
87033 --- a/net/phonet/socket.c
87034 +++ b/net/phonet/socket.c
87035 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
87036 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
87037 sock_i_ino(sk),
87038 atomic_read(&sk->sk_refcnt), sk,
87039 - atomic_read(&sk->sk_drops), &len);
87040 + atomic_read_unchecked(&sk->sk_drops), &len);
87041 }
87042 seq_printf(seq, "%*s\n", 127 - len, "");
87043 return 0;
87044 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
87045 index d6bbbbd..61561e4 100644
87046 --- a/net/phonet/sysctl.c
87047 +++ b/net/phonet/sysctl.c
87048 @@ -67,7 +67,7 @@ static int proc_local_port_range(ctl_table *table, int write,
87049 {
87050 int ret;
87051 int range[2] = {local_port_range[0], local_port_range[1]};
87052 - ctl_table tmp = {
87053 + ctl_table_no_const tmp = {
87054 .data = &range,
87055 .maxlen = sizeof(range),
87056 .mode = table->mode,
87057 diff --git a/net/rds/cong.c b/net/rds/cong.c
87058 index e5b65ac..f3b6fb7 100644
87059 --- a/net/rds/cong.c
87060 +++ b/net/rds/cong.c
87061 @@ -78,7 +78,7 @@
87062 * finds that the saved generation number is smaller than the global generation
87063 * number, it wakes up the process.
87064 */
87065 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
87066 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
87067
87068 /*
87069 * Congestion monitoring
87070 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
87071 rdsdebug("waking map %p for %pI4\n",
87072 map, &map->m_addr);
87073 rds_stats_inc(s_cong_update_received);
87074 - atomic_inc(&rds_cong_generation);
87075 + atomic_inc_unchecked(&rds_cong_generation);
87076 if (waitqueue_active(&map->m_waitq))
87077 wake_up(&map->m_waitq);
87078 if (waitqueue_active(&rds_poll_waitq))
87079 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
87080
87081 int rds_cong_updated_since(unsigned long *recent)
87082 {
87083 - unsigned long gen = atomic_read(&rds_cong_generation);
87084 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
87085
87086 if (likely(*recent == gen))
87087 return 0;
87088 diff --git a/net/rds/ib.h b/net/rds/ib.h
87089 index 7280ab8..e04f4ea 100644
87090 --- a/net/rds/ib.h
87091 +++ b/net/rds/ib.h
87092 @@ -128,7 +128,7 @@ struct rds_ib_connection {
87093 /* sending acks */
87094 unsigned long i_ack_flags;
87095 #ifdef KERNEL_HAS_ATOMIC64
87096 - atomic64_t i_ack_next; /* next ACK to send */
87097 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
87098 #else
87099 spinlock_t i_ack_lock; /* protect i_ack_next */
87100 u64 i_ack_next; /* next ACK to send */
87101 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
87102 index 31b74f5..dc1fbfa 100644
87103 --- a/net/rds/ib_cm.c
87104 +++ b/net/rds/ib_cm.c
87105 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
87106 /* Clear the ACK state */
87107 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
87108 #ifdef KERNEL_HAS_ATOMIC64
87109 - atomic64_set(&ic->i_ack_next, 0);
87110 + atomic64_set_unchecked(&ic->i_ack_next, 0);
87111 #else
87112 ic->i_ack_next = 0;
87113 #endif
87114 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
87115 index 8eb9501..0c386ff 100644
87116 --- a/net/rds/ib_recv.c
87117 +++ b/net/rds/ib_recv.c
87118 @@ -597,7 +597,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
87119 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
87120 int ack_required)
87121 {
87122 - atomic64_set(&ic->i_ack_next, seq);
87123 + atomic64_set_unchecked(&ic->i_ack_next, seq);
87124 if (ack_required) {
87125 smp_mb__before_clear_bit();
87126 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87127 @@ -609,7 +609,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
87128 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87129 smp_mb__after_clear_bit();
87130
87131 - return atomic64_read(&ic->i_ack_next);
87132 + return atomic64_read_unchecked(&ic->i_ack_next);
87133 }
87134 #endif
87135
87136 diff --git a/net/rds/iw.h b/net/rds/iw.h
87137 index 04ce3b1..48119a6 100644
87138 --- a/net/rds/iw.h
87139 +++ b/net/rds/iw.h
87140 @@ -134,7 +134,7 @@ struct rds_iw_connection {
87141 /* sending acks */
87142 unsigned long i_ack_flags;
87143 #ifdef KERNEL_HAS_ATOMIC64
87144 - atomic64_t i_ack_next; /* next ACK to send */
87145 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
87146 #else
87147 spinlock_t i_ack_lock; /* protect i_ack_next */
87148 u64 i_ack_next; /* next ACK to send */
87149 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
87150 index a91e1db..cf3053f 100644
87151 --- a/net/rds/iw_cm.c
87152 +++ b/net/rds/iw_cm.c
87153 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
87154 /* Clear the ACK state */
87155 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
87156 #ifdef KERNEL_HAS_ATOMIC64
87157 - atomic64_set(&ic->i_ack_next, 0);
87158 + atomic64_set_unchecked(&ic->i_ack_next, 0);
87159 #else
87160 ic->i_ack_next = 0;
87161 #endif
87162 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
87163 index 4503335..db566b4 100644
87164 --- a/net/rds/iw_recv.c
87165 +++ b/net/rds/iw_recv.c
87166 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
87167 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
87168 int ack_required)
87169 {
87170 - atomic64_set(&ic->i_ack_next, seq);
87171 + atomic64_set_unchecked(&ic->i_ack_next, seq);
87172 if (ack_required) {
87173 smp_mb__before_clear_bit();
87174 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87175 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
87176 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87177 smp_mb__after_clear_bit();
87178
87179 - return atomic64_read(&ic->i_ack_next);
87180 + return atomic64_read_unchecked(&ic->i_ack_next);
87181 }
87182 #endif
87183
87184 diff --git a/net/rds/message.c b/net/rds/message.c
87185 index f0a4658..aff589c 100644
87186 --- a/net/rds/message.c
87187 +++ b/net/rds/message.c
87188 @@ -197,6 +197,9 @@ struct rds_message *rds_message_alloc(unsigned int extra_len, gfp_t gfp)
87189 {
87190 struct rds_message *rm;
87191
87192 + if (extra_len > KMALLOC_MAX_SIZE - sizeof(struct rds_message))
87193 + return NULL;
87194 +
87195 rm = kzalloc(sizeof(struct rds_message) + extra_len, gfp);
87196 if (!rm)
87197 goto out;
87198 diff --git a/net/rds/rds.h b/net/rds/rds.h
87199 index ec1d731..90a3a8d 100644
87200 --- a/net/rds/rds.h
87201 +++ b/net/rds/rds.h
87202 @@ -449,7 +449,7 @@ struct rds_transport {
87203 void (*sync_mr)(void *trans_private, int direction);
87204 void (*free_mr)(void *trans_private, int invalidate);
87205 void (*flush_mrs)(void);
87206 -};
87207 +} __do_const;
87208
87209 struct rds_sock {
87210 struct sock rs_sk;
87211 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
87212 index edac9ef..16bcb98 100644
87213 --- a/net/rds/tcp.c
87214 +++ b/net/rds/tcp.c
87215 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
87216 int val = 1;
87217
87218 set_fs(KERNEL_DS);
87219 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
87220 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
87221 sizeof(val));
87222 set_fs(oldfs);
87223 }
87224 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
87225 index 81cf5a4..b5826ff 100644
87226 --- a/net/rds/tcp_send.c
87227 +++ b/net/rds/tcp_send.c
87228 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
87229
87230 oldfs = get_fs();
87231 set_fs(KERNEL_DS);
87232 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
87233 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
87234 sizeof(val));
87235 set_fs(oldfs);
87236 }
87237 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
87238 index 05996d0..5a1dfe0 100644
87239 --- a/net/rxrpc/af_rxrpc.c
87240 +++ b/net/rxrpc/af_rxrpc.c
87241 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
87242 __be32 rxrpc_epoch;
87243
87244 /* current debugging ID */
87245 -atomic_t rxrpc_debug_id;
87246 +atomic_unchecked_t rxrpc_debug_id;
87247
87248 /* count of skbs currently in use */
87249 atomic_t rxrpc_n_skbs;
87250 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
87251 index e4d9cbc..b229649 100644
87252 --- a/net/rxrpc/ar-ack.c
87253 +++ b/net/rxrpc/ar-ack.c
87254 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
87255
87256 _enter("{%d,%d,%d,%d},",
87257 call->acks_hard, call->acks_unacked,
87258 - atomic_read(&call->sequence),
87259 + atomic_read_unchecked(&call->sequence),
87260 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
87261
87262 stop = 0;
87263 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
87264
87265 /* each Tx packet has a new serial number */
87266 sp->hdr.serial =
87267 - htonl(atomic_inc_return(&call->conn->serial));
87268 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
87269
87270 hdr = (struct rxrpc_header *) txb->head;
87271 hdr->serial = sp->hdr.serial;
87272 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
87273 */
87274 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
87275 {
87276 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
87277 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
87278 }
87279
87280 /*
87281 @@ -629,7 +629,7 @@ process_further:
87282
87283 latest = ntohl(sp->hdr.serial);
87284 hard = ntohl(ack.firstPacket);
87285 - tx = atomic_read(&call->sequence);
87286 + tx = atomic_read_unchecked(&call->sequence);
87287
87288 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
87289 latest,
87290 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
87291 goto maybe_reschedule;
87292
87293 send_ACK_with_skew:
87294 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
87295 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
87296 ntohl(ack.serial));
87297 send_ACK:
87298 mtu = call->conn->trans->peer->if_mtu;
87299 @@ -1173,7 +1173,7 @@ send_ACK:
87300 ackinfo.rxMTU = htonl(5692);
87301 ackinfo.jumbo_max = htonl(4);
87302
87303 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
87304 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
87305 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
87306 ntohl(hdr.serial),
87307 ntohs(ack.maxSkew),
87308 @@ -1191,7 +1191,7 @@ send_ACK:
87309 send_message:
87310 _debug("send message");
87311
87312 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
87313 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
87314 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
87315 send_message_2:
87316
87317 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
87318 index a3bbb36..3341fb9 100644
87319 --- a/net/rxrpc/ar-call.c
87320 +++ b/net/rxrpc/ar-call.c
87321 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
87322 spin_lock_init(&call->lock);
87323 rwlock_init(&call->state_lock);
87324 atomic_set(&call->usage, 1);
87325 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
87326 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87327 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
87328
87329 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
87330 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
87331 index 4106ca9..a338d7a 100644
87332 --- a/net/rxrpc/ar-connection.c
87333 +++ b/net/rxrpc/ar-connection.c
87334 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
87335 rwlock_init(&conn->lock);
87336 spin_lock_init(&conn->state_lock);
87337 atomic_set(&conn->usage, 1);
87338 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
87339 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87340 conn->avail_calls = RXRPC_MAXCALLS;
87341 conn->size_align = 4;
87342 conn->header_size = sizeof(struct rxrpc_header);
87343 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
87344 index e7ed43a..6afa140 100644
87345 --- a/net/rxrpc/ar-connevent.c
87346 +++ b/net/rxrpc/ar-connevent.c
87347 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
87348
87349 len = iov[0].iov_len + iov[1].iov_len;
87350
87351 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
87352 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
87353 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
87354
87355 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
87356 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
87357 index 529572f..c758ca7 100644
87358 --- a/net/rxrpc/ar-input.c
87359 +++ b/net/rxrpc/ar-input.c
87360 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
87361 /* track the latest serial number on this connection for ACK packet
87362 * information */
87363 serial = ntohl(sp->hdr.serial);
87364 - hi_serial = atomic_read(&call->conn->hi_serial);
87365 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
87366 while (serial > hi_serial)
87367 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
87368 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
87369 serial);
87370
87371 /* request ACK generation for any ACK or DATA packet that requests
87372 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
87373 index a693aca..81e7293 100644
87374 --- a/net/rxrpc/ar-internal.h
87375 +++ b/net/rxrpc/ar-internal.h
87376 @@ -272,8 +272,8 @@ struct rxrpc_connection {
87377 int error; /* error code for local abort */
87378 int debug_id; /* debug ID for printks */
87379 unsigned int call_counter; /* call ID counter */
87380 - atomic_t serial; /* packet serial number counter */
87381 - atomic_t hi_serial; /* highest serial number received */
87382 + atomic_unchecked_t serial; /* packet serial number counter */
87383 + atomic_unchecked_t hi_serial; /* highest serial number received */
87384 u8 avail_calls; /* number of calls available */
87385 u8 size_align; /* data size alignment (for security) */
87386 u8 header_size; /* rxrpc + security header size */
87387 @@ -346,7 +346,7 @@ struct rxrpc_call {
87388 spinlock_t lock;
87389 rwlock_t state_lock; /* lock for state transition */
87390 atomic_t usage;
87391 - atomic_t sequence; /* Tx data packet sequence counter */
87392 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
87393 u32 abort_code; /* local/remote abort code */
87394 enum { /* current state of call */
87395 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
87396 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
87397 */
87398 extern atomic_t rxrpc_n_skbs;
87399 extern __be32 rxrpc_epoch;
87400 -extern atomic_t rxrpc_debug_id;
87401 +extern atomic_unchecked_t rxrpc_debug_id;
87402 extern struct workqueue_struct *rxrpc_workqueue;
87403
87404 /*
87405 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
87406 index 87f7135..74d3703 100644
87407 --- a/net/rxrpc/ar-local.c
87408 +++ b/net/rxrpc/ar-local.c
87409 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
87410 spin_lock_init(&local->lock);
87411 rwlock_init(&local->services_lock);
87412 atomic_set(&local->usage, 1);
87413 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
87414 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87415 memcpy(&local->srx, srx, sizeof(*srx));
87416 }
87417
87418 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
87419 index e1ac183..b43e10e 100644
87420 --- a/net/rxrpc/ar-output.c
87421 +++ b/net/rxrpc/ar-output.c
87422 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
87423 sp->hdr.cid = call->cid;
87424 sp->hdr.callNumber = call->call_id;
87425 sp->hdr.seq =
87426 - htonl(atomic_inc_return(&call->sequence));
87427 + htonl(atomic_inc_return_unchecked(&call->sequence));
87428 sp->hdr.serial =
87429 - htonl(atomic_inc_return(&conn->serial));
87430 + htonl(atomic_inc_return_unchecked(&conn->serial));
87431 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
87432 sp->hdr.userStatus = 0;
87433 sp->hdr.securityIndex = conn->security_ix;
87434 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
87435 index bebaa43..2644591 100644
87436 --- a/net/rxrpc/ar-peer.c
87437 +++ b/net/rxrpc/ar-peer.c
87438 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
87439 INIT_LIST_HEAD(&peer->error_targets);
87440 spin_lock_init(&peer->lock);
87441 atomic_set(&peer->usage, 1);
87442 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
87443 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87444 memcpy(&peer->srx, srx, sizeof(*srx));
87445
87446 rxrpc_assess_MTU_size(peer);
87447 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
87448 index 38047f7..9f48511 100644
87449 --- a/net/rxrpc/ar-proc.c
87450 +++ b/net/rxrpc/ar-proc.c
87451 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
87452 atomic_read(&conn->usage),
87453 rxrpc_conn_states[conn->state],
87454 key_serial(conn->key),
87455 - atomic_read(&conn->serial),
87456 - atomic_read(&conn->hi_serial));
87457 + atomic_read_unchecked(&conn->serial),
87458 + atomic_read_unchecked(&conn->hi_serial));
87459
87460 return 0;
87461 }
87462 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
87463 index 92df566..87ec1bf 100644
87464 --- a/net/rxrpc/ar-transport.c
87465 +++ b/net/rxrpc/ar-transport.c
87466 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
87467 spin_lock_init(&trans->client_lock);
87468 rwlock_init(&trans->conn_lock);
87469 atomic_set(&trans->usage, 1);
87470 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
87471 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87472
87473 if (peer->srx.transport.family == AF_INET) {
87474 switch (peer->srx.transport_type) {
87475 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
87476 index f226709..0e735a8 100644
87477 --- a/net/rxrpc/rxkad.c
87478 +++ b/net/rxrpc/rxkad.c
87479 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
87480
87481 len = iov[0].iov_len + iov[1].iov_len;
87482
87483 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
87484 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
87485 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
87486
87487 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
87488 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
87489
87490 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
87491
87492 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
87493 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
87494 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
87495
87496 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
87497 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
87498 index 391a245..296b3d7 100644
87499 --- a/net/sctp/ipv6.c
87500 +++ b/net/sctp/ipv6.c
87501 @@ -981,7 +981,7 @@ static const struct inet6_protocol sctpv6_protocol = {
87502 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
87503 };
87504
87505 -static struct sctp_af sctp_af_inet6 = {
87506 +static struct sctp_af sctp_af_inet6 __read_only = {
87507 .sa_family = AF_INET6,
87508 .sctp_xmit = sctp_v6_xmit,
87509 .setsockopt = ipv6_setsockopt,
87510 @@ -1013,7 +1013,7 @@ static struct sctp_af sctp_af_inet6 = {
87511 #endif
87512 };
87513
87514 -static struct sctp_pf sctp_pf_inet6 = {
87515 +static struct sctp_pf sctp_pf_inet6 __read_only = {
87516 .event_msgname = sctp_inet6_event_msgname,
87517 .skb_msgname = sctp_inet6_skb_msgname,
87518 .af_supported = sctp_inet6_af_supported,
87519 @@ -1038,7 +1038,7 @@ void sctp_v6_pf_init(void)
87520
87521 void sctp_v6_pf_exit(void)
87522 {
87523 - list_del(&sctp_af_inet6.list);
87524 + pax_list_del(&sctp_af_inet6.list);
87525 }
87526
87527 /* Initialize IPv6 support and register with socket layer. */
87528 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
87529 index 8c19e97..16264b8 100644
87530 --- a/net/sctp/proc.c
87531 +++ b/net/sctp/proc.c
87532 @@ -338,7 +338,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
87533 seq_printf(seq,
87534 "%8pK %8pK %-3d %-3d %-2d %-4d "
87535 "%4d %8d %8d %7d %5lu %-5d %5d ",
87536 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
87537 + assoc, sk,
87538 + sctp_sk(sk)->type, sk->sk_state,
87539 assoc->state, hash,
87540 assoc->assoc_id,
87541 assoc->sndbuf_used,
87542 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
87543 index f898b1c..a2d0fe8 100644
87544 --- a/net/sctp/protocol.c
87545 +++ b/net/sctp/protocol.c
87546 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
87547 return 0;
87548 }
87549
87550 + pax_open_kernel();
87551 INIT_LIST_HEAD(&af->list);
87552 - list_add_tail(&af->list, &sctp_address_families);
87553 + pax_close_kernel();
87554 + pax_list_add_tail(&af->list, &sctp_address_families);
87555 return 1;
87556 }
87557
87558 @@ -966,7 +968,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
87559
87560 static struct sctp_af sctp_af_inet;
87561
87562 -static struct sctp_pf sctp_pf_inet = {
87563 +static struct sctp_pf sctp_pf_inet __read_only = {
87564 .event_msgname = sctp_inet_event_msgname,
87565 .skb_msgname = sctp_inet_skb_msgname,
87566 .af_supported = sctp_inet_af_supported,
87567 @@ -1037,7 +1039,7 @@ static const struct net_protocol sctp_protocol = {
87568 };
87569
87570 /* IPv4 address related functions. */
87571 -static struct sctp_af sctp_af_inet = {
87572 +static struct sctp_af sctp_af_inet __read_only = {
87573 .sa_family = AF_INET,
87574 .sctp_xmit = sctp_v4_xmit,
87575 .setsockopt = ip_setsockopt,
87576 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
87577
87578 static void sctp_v4_pf_exit(void)
87579 {
87580 - list_del(&sctp_af_inet.list);
87581 + pax_list_del(&sctp_af_inet.list);
87582 }
87583
87584 static int sctp_v4_protosw_init(void)
87585 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
87586 index c957775..6d4593a 100644
87587 --- a/net/sctp/sm_sideeffect.c
87588 +++ b/net/sctp/sm_sideeffect.c
87589 @@ -447,7 +447,7 @@ static void sctp_generate_sack_event(unsigned long data)
87590 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
87591 }
87592
87593 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
87594 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
87595 NULL,
87596 sctp_generate_t1_cookie_event,
87597 sctp_generate_t1_init_event,
87598 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
87599 index cedd9bf..d577d71 100644
87600 --- a/net/sctp/socket.c
87601 +++ b/net/sctp/socket.c
87602 @@ -4665,6 +4665,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
87603 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
87604 if (space_left < addrlen)
87605 return -ENOMEM;
87606 + if (addrlen > sizeof(temp) || addrlen < 0)
87607 + return -EFAULT;
87608 if (copy_to_user(to, &temp, addrlen))
87609 return -EFAULT;
87610 to += addrlen;
87611 @@ -5653,6 +5655,9 @@ static int sctp_getsockopt_assoc_stats(struct sock *sk, int len,
87612 if (len < sizeof(sctp_assoc_t))
87613 return -EINVAL;
87614
87615 + /* Allow the struct to grow and fill in as much as possible */
87616 + len = min_t(size_t, len, sizeof(sas));
87617 +
87618 if (copy_from_user(&sas, optval, len))
87619 return -EFAULT;
87620
87621 @@ -5686,9 +5691,6 @@ static int sctp_getsockopt_assoc_stats(struct sock *sk, int len,
87622 /* Mark beginning of a new observation period */
87623 asoc->stats.max_obs_rto = asoc->rto_min;
87624
87625 - /* Allow the struct to grow and fill in as much as possible */
87626 - len = min_t(size_t, len, sizeof(sas));
87627 -
87628 if (put_user(len, optlen))
87629 return -EFAULT;
87630
87631 diff --git a/net/sctp/ssnmap.c b/net/sctp/ssnmap.c
87632 index 442ad4e..825ea94 100644
87633 --- a/net/sctp/ssnmap.c
87634 +++ b/net/sctp/ssnmap.c
87635 @@ -41,8 +41,6 @@
87636 #include <net/sctp/sctp.h>
87637 #include <net/sctp/sm.h>
87638
87639 -#define MAX_KMALLOC_SIZE 131072
87640 -
87641 static struct sctp_ssnmap *sctp_ssnmap_init(struct sctp_ssnmap *map, __u16 in,
87642 __u16 out);
87643
87644 @@ -65,7 +63,7 @@ struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
87645 int size;
87646
87647 size = sctp_ssnmap_size(in, out);
87648 - if (size <= MAX_KMALLOC_SIZE)
87649 + if (size <= KMALLOC_MAX_SIZE)
87650 retval = kmalloc(size, gfp);
87651 else
87652 retval = (struct sctp_ssnmap *)
87653 @@ -82,7 +80,7 @@ struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
87654 return retval;
87655
87656 fail_map:
87657 - if (size <= MAX_KMALLOC_SIZE)
87658 + if (size <= KMALLOC_MAX_SIZE)
87659 kfree(retval);
87660 else
87661 free_pages((unsigned long)retval, get_order(size));
87662 @@ -124,7 +122,7 @@ void sctp_ssnmap_free(struct sctp_ssnmap *map)
87663 int size;
87664
87665 size = sctp_ssnmap_size(map->in.len, map->out.len);
87666 - if (size <= MAX_KMALLOC_SIZE)
87667 + if (size <= KMALLOC_MAX_SIZE)
87668 kfree(map);
87669 else
87670 free_pages((unsigned long)map, get_order(size));
87671 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
87672 index bf3c6e8..376d8d0 100644
87673 --- a/net/sctp/sysctl.c
87674 +++ b/net/sctp/sysctl.c
87675 @@ -307,7 +307,7 @@ static int proc_sctp_do_hmac_alg(ctl_table *ctl,
87676 {
87677 struct net *net = current->nsproxy->net_ns;
87678 char tmp[8];
87679 - ctl_table tbl;
87680 + ctl_table_no_const tbl;
87681 int ret;
87682 int changed = 0;
87683 char *none = "none";
87684 @@ -350,7 +350,7 @@ static int proc_sctp_do_hmac_alg(ctl_table *ctl,
87685
87686 int sctp_sysctl_net_register(struct net *net)
87687 {
87688 - struct ctl_table *table;
87689 + ctl_table_no_const *table;
87690 int i;
87691
87692 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
87693 diff --git a/net/socket.c b/net/socket.c
87694 index 2ca51c7..45d0b31 100644
87695 --- a/net/socket.c
87696 +++ b/net/socket.c
87697 @@ -89,6 +89,7 @@
87698 #include <linux/magic.h>
87699 #include <linux/slab.h>
87700 #include <linux/xattr.h>
87701 +#include <linux/in.h>
87702
87703 #include <asm/uaccess.h>
87704 #include <asm/unistd.h>
87705 @@ -106,6 +107,8 @@
87706 #include <linux/sockios.h>
87707 #include <linux/atalk.h>
87708
87709 +#include <linux/grsock.h>
87710 +
87711 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
87712 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
87713 unsigned long nr_segs, loff_t pos);
87714 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
87715 &sockfs_dentry_operations, SOCKFS_MAGIC);
87716 }
87717
87718 -static struct vfsmount *sock_mnt __read_mostly;
87719 +struct vfsmount *sock_mnt __read_mostly;
87720
87721 static struct file_system_type sock_fs_type = {
87722 .name = "sockfs",
87723 @@ -1270,6 +1273,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
87724 return -EAFNOSUPPORT;
87725 if (type < 0 || type >= SOCK_MAX)
87726 return -EINVAL;
87727 + if (protocol < 0)
87728 + return -EINVAL;
87729
87730 /* Compatibility.
87731
87732 @@ -1401,6 +1406,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
87733 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
87734 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
87735
87736 + if(!gr_search_socket(family, type, protocol)) {
87737 + retval = -EACCES;
87738 + goto out;
87739 + }
87740 +
87741 + if (gr_handle_sock_all(family, type, protocol)) {
87742 + retval = -EACCES;
87743 + goto out;
87744 + }
87745 +
87746 retval = sock_create(family, type, protocol, &sock);
87747 if (retval < 0)
87748 goto out;
87749 @@ -1528,6 +1543,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
87750 if (sock) {
87751 err = move_addr_to_kernel(umyaddr, addrlen, &address);
87752 if (err >= 0) {
87753 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
87754 + err = -EACCES;
87755 + goto error;
87756 + }
87757 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
87758 + if (err)
87759 + goto error;
87760 +
87761 err = security_socket_bind(sock,
87762 (struct sockaddr *)&address,
87763 addrlen);
87764 @@ -1536,6 +1559,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
87765 (struct sockaddr *)
87766 &address, addrlen);
87767 }
87768 +error:
87769 fput_light(sock->file, fput_needed);
87770 }
87771 return err;
87772 @@ -1559,10 +1583,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
87773 if ((unsigned int)backlog > somaxconn)
87774 backlog = somaxconn;
87775
87776 + if (gr_handle_sock_server_other(sock->sk)) {
87777 + err = -EPERM;
87778 + goto error;
87779 + }
87780 +
87781 + err = gr_search_listen(sock);
87782 + if (err)
87783 + goto error;
87784 +
87785 err = security_socket_listen(sock, backlog);
87786 if (!err)
87787 err = sock->ops->listen(sock, backlog);
87788
87789 +error:
87790 fput_light(sock->file, fput_needed);
87791 }
87792 return err;
87793 @@ -1606,6 +1640,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
87794 newsock->type = sock->type;
87795 newsock->ops = sock->ops;
87796
87797 + if (gr_handle_sock_server_other(sock->sk)) {
87798 + err = -EPERM;
87799 + sock_release(newsock);
87800 + goto out_put;
87801 + }
87802 +
87803 + err = gr_search_accept(sock);
87804 + if (err) {
87805 + sock_release(newsock);
87806 + goto out_put;
87807 + }
87808 +
87809 /*
87810 * We don't need try_module_get here, as the listening socket (sock)
87811 * has the protocol module (sock->ops->owner) held.
87812 @@ -1651,6 +1697,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
87813 fd_install(newfd, newfile);
87814 err = newfd;
87815
87816 + gr_attach_curr_ip(newsock->sk);
87817 +
87818 out_put:
87819 fput_light(sock->file, fput_needed);
87820 out:
87821 @@ -1683,6 +1731,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
87822 int, addrlen)
87823 {
87824 struct socket *sock;
87825 + struct sockaddr *sck;
87826 struct sockaddr_storage address;
87827 int err, fput_needed;
87828
87829 @@ -1693,6 +1742,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
87830 if (err < 0)
87831 goto out_put;
87832
87833 + sck = (struct sockaddr *)&address;
87834 +
87835 + if (gr_handle_sock_client(sck)) {
87836 + err = -EACCES;
87837 + goto out_put;
87838 + }
87839 +
87840 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
87841 + if (err)
87842 + goto out_put;
87843 +
87844 err =
87845 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
87846 if (err)
87847 @@ -2047,7 +2107,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
87848 * checking falls down on this.
87849 */
87850 if (copy_from_user(ctl_buf,
87851 - (void __user __force *)msg_sys->msg_control,
87852 + (void __force_user *)msg_sys->msg_control,
87853 ctl_len))
87854 goto out_freectl;
87855 msg_sys->msg_control = ctl_buf;
87856 @@ -2215,7 +2275,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
87857 * kernel msghdr to use the kernel address space)
87858 */
87859
87860 - uaddr = (__force void __user *)msg_sys->msg_name;
87861 + uaddr = (void __force_user *)msg_sys->msg_name;
87862 uaddr_len = COMPAT_NAMELEN(msg);
87863 if (MSG_CMSG_COMPAT & flags) {
87864 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
87865 @@ -2838,7 +2898,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
87866 }
87867
87868 ifr = compat_alloc_user_space(buf_size);
87869 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
87870 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
87871
87872 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
87873 return -EFAULT;
87874 @@ -2862,12 +2922,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
87875 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
87876
87877 if (copy_in_user(rxnfc, compat_rxnfc,
87878 - (void *)(&rxnfc->fs.m_ext + 1) -
87879 - (void *)rxnfc) ||
87880 + (void __user *)(&rxnfc->fs.m_ext + 1) -
87881 + (void __user *)rxnfc) ||
87882 copy_in_user(&rxnfc->fs.ring_cookie,
87883 &compat_rxnfc->fs.ring_cookie,
87884 - (void *)(&rxnfc->fs.location + 1) -
87885 - (void *)&rxnfc->fs.ring_cookie) ||
87886 + (void __user *)(&rxnfc->fs.location + 1) -
87887 + (void __user *)&rxnfc->fs.ring_cookie) ||
87888 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
87889 sizeof(rxnfc->rule_cnt)))
87890 return -EFAULT;
87891 @@ -2879,12 +2939,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
87892
87893 if (convert_out) {
87894 if (copy_in_user(compat_rxnfc, rxnfc,
87895 - (const void *)(&rxnfc->fs.m_ext + 1) -
87896 - (const void *)rxnfc) ||
87897 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
87898 + (const void __user *)rxnfc) ||
87899 copy_in_user(&compat_rxnfc->fs.ring_cookie,
87900 &rxnfc->fs.ring_cookie,
87901 - (const void *)(&rxnfc->fs.location + 1) -
87902 - (const void *)&rxnfc->fs.ring_cookie) ||
87903 + (const void __user *)(&rxnfc->fs.location + 1) -
87904 + (const void __user *)&rxnfc->fs.ring_cookie) ||
87905 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
87906 sizeof(rxnfc->rule_cnt)))
87907 return -EFAULT;
87908 @@ -2954,7 +3014,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
87909 old_fs = get_fs();
87910 set_fs(KERNEL_DS);
87911 err = dev_ioctl(net, cmd,
87912 - (struct ifreq __user __force *) &kifr);
87913 + (struct ifreq __force_user *) &kifr);
87914 set_fs(old_fs);
87915
87916 return err;
87917 @@ -3063,7 +3123,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
87918
87919 old_fs = get_fs();
87920 set_fs(KERNEL_DS);
87921 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
87922 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
87923 set_fs(old_fs);
87924
87925 if (cmd == SIOCGIFMAP && !err) {
87926 @@ -3168,7 +3228,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
87927 ret |= __get_user(rtdev, &(ur4->rt_dev));
87928 if (rtdev) {
87929 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
87930 - r4.rt_dev = (char __user __force *)devname;
87931 + r4.rt_dev = (char __force_user *)devname;
87932 devname[15] = 0;
87933 } else
87934 r4.rt_dev = NULL;
87935 @@ -3394,8 +3454,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
87936 int __user *uoptlen;
87937 int err;
87938
87939 - uoptval = (char __user __force *) optval;
87940 - uoptlen = (int __user __force *) optlen;
87941 + uoptval = (char __force_user *) optval;
87942 + uoptlen = (int __force_user *) optlen;
87943
87944 set_fs(KERNEL_DS);
87945 if (level == SOL_SOCKET)
87946 @@ -3415,7 +3475,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
87947 char __user *uoptval;
87948 int err;
87949
87950 - uoptval = (char __user __force *) optval;
87951 + uoptval = (char __force_user *) optval;
87952
87953 set_fs(KERNEL_DS);
87954 if (level == SOL_SOCKET)
87955 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
87956 index 507b5e8..049e64a 100644
87957 --- a/net/sunrpc/clnt.c
87958 +++ b/net/sunrpc/clnt.c
87959 @@ -1272,7 +1272,9 @@ call_start(struct rpc_task *task)
87960 (RPC_IS_ASYNC(task) ? "async" : "sync"));
87961
87962 /* Increment call count */
87963 - task->tk_msg.rpc_proc->p_count++;
87964 + pax_open_kernel();
87965 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
87966 + pax_close_kernel();
87967 clnt->cl_stats->rpccnt++;
87968 task->tk_action = call_reserve;
87969 }
87970 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
87971 index fb20f25..e3ba316 100644
87972 --- a/net/sunrpc/sched.c
87973 +++ b/net/sunrpc/sched.c
87974 @@ -259,9 +259,9 @@ static int rpc_wait_bit_killable(void *word)
87975 #ifdef RPC_DEBUG
87976 static void rpc_task_set_debuginfo(struct rpc_task *task)
87977 {
87978 - static atomic_t rpc_pid;
87979 + static atomic_unchecked_t rpc_pid;
87980
87981 - task->tk_pid = atomic_inc_return(&rpc_pid);
87982 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
87983 }
87984 #else
87985 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
87986 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
87987 index 2d34b6b..e2d584d 100644
87988 --- a/net/sunrpc/svc.c
87989 +++ b/net/sunrpc/svc.c
87990 @@ -1156,7 +1156,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
87991 svc_putnl(resv, RPC_SUCCESS);
87992
87993 /* Bump per-procedure stats counter */
87994 - procp->pc_count++;
87995 + pax_open_kernel();
87996 + (*(unsigned int *)&procp->pc_count)++;
87997 + pax_close_kernel();
87998
87999 /* Initialize storage for argp and resp */
88000 memset(rqstp->rq_argp, 0, procp->pc_argsize);
88001 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
88002 index 8343737..677025e 100644
88003 --- a/net/sunrpc/xprtrdma/svc_rdma.c
88004 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
88005 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
88006 static unsigned int min_max_inline = 4096;
88007 static unsigned int max_max_inline = 65536;
88008
88009 -atomic_t rdma_stat_recv;
88010 -atomic_t rdma_stat_read;
88011 -atomic_t rdma_stat_write;
88012 -atomic_t rdma_stat_sq_starve;
88013 -atomic_t rdma_stat_rq_starve;
88014 -atomic_t rdma_stat_rq_poll;
88015 -atomic_t rdma_stat_rq_prod;
88016 -atomic_t rdma_stat_sq_poll;
88017 -atomic_t rdma_stat_sq_prod;
88018 +atomic_unchecked_t rdma_stat_recv;
88019 +atomic_unchecked_t rdma_stat_read;
88020 +atomic_unchecked_t rdma_stat_write;
88021 +atomic_unchecked_t rdma_stat_sq_starve;
88022 +atomic_unchecked_t rdma_stat_rq_starve;
88023 +atomic_unchecked_t rdma_stat_rq_poll;
88024 +atomic_unchecked_t rdma_stat_rq_prod;
88025 +atomic_unchecked_t rdma_stat_sq_poll;
88026 +atomic_unchecked_t rdma_stat_sq_prod;
88027
88028 /* Temporary NFS request map and context caches */
88029 struct kmem_cache *svc_rdma_map_cachep;
88030 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
88031 len -= *ppos;
88032 if (len > *lenp)
88033 len = *lenp;
88034 - if (len && copy_to_user(buffer, str_buf, len))
88035 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
88036 return -EFAULT;
88037 *lenp = len;
88038 *ppos += len;
88039 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
88040 {
88041 .procname = "rdma_stat_read",
88042 .data = &rdma_stat_read,
88043 - .maxlen = sizeof(atomic_t),
88044 + .maxlen = sizeof(atomic_unchecked_t),
88045 .mode = 0644,
88046 .proc_handler = read_reset_stat,
88047 },
88048 {
88049 .procname = "rdma_stat_recv",
88050 .data = &rdma_stat_recv,
88051 - .maxlen = sizeof(atomic_t),
88052 + .maxlen = sizeof(atomic_unchecked_t),
88053 .mode = 0644,
88054 .proc_handler = read_reset_stat,
88055 },
88056 {
88057 .procname = "rdma_stat_write",
88058 .data = &rdma_stat_write,
88059 - .maxlen = sizeof(atomic_t),
88060 + .maxlen = sizeof(atomic_unchecked_t),
88061 .mode = 0644,
88062 .proc_handler = read_reset_stat,
88063 },
88064 {
88065 .procname = "rdma_stat_sq_starve",
88066 .data = &rdma_stat_sq_starve,
88067 - .maxlen = sizeof(atomic_t),
88068 + .maxlen = sizeof(atomic_unchecked_t),
88069 .mode = 0644,
88070 .proc_handler = read_reset_stat,
88071 },
88072 {
88073 .procname = "rdma_stat_rq_starve",
88074 .data = &rdma_stat_rq_starve,
88075 - .maxlen = sizeof(atomic_t),
88076 + .maxlen = sizeof(atomic_unchecked_t),
88077 .mode = 0644,
88078 .proc_handler = read_reset_stat,
88079 },
88080 {
88081 .procname = "rdma_stat_rq_poll",
88082 .data = &rdma_stat_rq_poll,
88083 - .maxlen = sizeof(atomic_t),
88084 + .maxlen = sizeof(atomic_unchecked_t),
88085 .mode = 0644,
88086 .proc_handler = read_reset_stat,
88087 },
88088 {
88089 .procname = "rdma_stat_rq_prod",
88090 .data = &rdma_stat_rq_prod,
88091 - .maxlen = sizeof(atomic_t),
88092 + .maxlen = sizeof(atomic_unchecked_t),
88093 .mode = 0644,
88094 .proc_handler = read_reset_stat,
88095 },
88096 {
88097 .procname = "rdma_stat_sq_poll",
88098 .data = &rdma_stat_sq_poll,
88099 - .maxlen = sizeof(atomic_t),
88100 + .maxlen = sizeof(atomic_unchecked_t),
88101 .mode = 0644,
88102 .proc_handler = read_reset_stat,
88103 },
88104 {
88105 .procname = "rdma_stat_sq_prod",
88106 .data = &rdma_stat_sq_prod,
88107 - .maxlen = sizeof(atomic_t),
88108 + .maxlen = sizeof(atomic_unchecked_t),
88109 .mode = 0644,
88110 .proc_handler = read_reset_stat,
88111 },
88112 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
88113 index 0ce7552..d074459 100644
88114 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
88115 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
88116 @@ -501,7 +501,7 @@ next_sge:
88117 svc_rdma_put_context(ctxt, 0);
88118 goto out;
88119 }
88120 - atomic_inc(&rdma_stat_read);
88121 + atomic_inc_unchecked(&rdma_stat_read);
88122
88123 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
88124 chl_map->ch[ch_no].count -= read_wr.num_sge;
88125 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
88126 dto_q);
88127 list_del_init(&ctxt->dto_q);
88128 } else {
88129 - atomic_inc(&rdma_stat_rq_starve);
88130 + atomic_inc_unchecked(&rdma_stat_rq_starve);
88131 clear_bit(XPT_DATA, &xprt->xpt_flags);
88132 ctxt = NULL;
88133 }
88134 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
88135 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
88136 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
88137 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
88138 - atomic_inc(&rdma_stat_recv);
88139 + atomic_inc_unchecked(&rdma_stat_recv);
88140
88141 /* Build up the XDR from the receive buffers. */
88142 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
88143 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
88144 index c1d124d..acfc59e 100644
88145 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
88146 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
88147 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
88148 write_wr.wr.rdma.remote_addr = to;
88149
88150 /* Post It */
88151 - atomic_inc(&rdma_stat_write);
88152 + atomic_inc_unchecked(&rdma_stat_write);
88153 if (svc_rdma_send(xprt, &write_wr))
88154 goto err;
88155 return 0;
88156 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
88157 index 62e4f9b..dd3f2d7 100644
88158 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
88159 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
88160 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
88161 return;
88162
88163 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
88164 - atomic_inc(&rdma_stat_rq_poll);
88165 + atomic_inc_unchecked(&rdma_stat_rq_poll);
88166
88167 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
88168 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
88169 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
88170 }
88171
88172 if (ctxt)
88173 - atomic_inc(&rdma_stat_rq_prod);
88174 + atomic_inc_unchecked(&rdma_stat_rq_prod);
88175
88176 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
88177 /*
88178 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
88179 return;
88180
88181 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
88182 - atomic_inc(&rdma_stat_sq_poll);
88183 + atomic_inc_unchecked(&rdma_stat_sq_poll);
88184 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
88185 if (wc.status != IB_WC_SUCCESS)
88186 /* Close the transport */
88187 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
88188 }
88189
88190 if (ctxt)
88191 - atomic_inc(&rdma_stat_sq_prod);
88192 + atomic_inc_unchecked(&rdma_stat_sq_prod);
88193 }
88194
88195 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
88196 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
88197 spin_lock_bh(&xprt->sc_lock);
88198 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
88199 spin_unlock_bh(&xprt->sc_lock);
88200 - atomic_inc(&rdma_stat_sq_starve);
88201 + atomic_inc_unchecked(&rdma_stat_sq_starve);
88202
88203 /* See if we can opportunistically reap SQ WR to make room */
88204 sq_cq_reap(xprt);
88205 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
88206 index 9bc6db0..47ac8c0 100644
88207 --- a/net/sysctl_net.c
88208 +++ b/net/sysctl_net.c
88209 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
88210 kgid_t root_gid = make_kgid(net->user_ns, 0);
88211
88212 /* Allow network administrator to have same access as root. */
88213 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
88214 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
88215 uid_eq(root_uid, current_uid())) {
88216 int mode = (table->mode >> 6) & 7;
88217 return (mode << 6) | (mode << 3) | mode;
88218 diff --git a/net/tipc/link.c b/net/tipc/link.c
88219 index daa6080..02d357f 100644
88220 --- a/net/tipc/link.c
88221 +++ b/net/tipc/link.c
88222 @@ -1201,7 +1201,7 @@ static int link_send_sections_long(struct tipc_port *sender,
88223 struct tipc_msg fragm_hdr;
88224 struct sk_buff *buf, *buf_chain, *prev;
88225 u32 fragm_crs, fragm_rest, hsz, sect_rest;
88226 - const unchar *sect_crs;
88227 + const unchar __user *sect_crs;
88228 int curr_sect;
88229 u32 fragm_no;
88230
88231 @@ -1242,7 +1242,7 @@ again:
88232
88233 if (!sect_rest) {
88234 sect_rest = msg_sect[++curr_sect].iov_len;
88235 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
88236 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
88237 }
88238
88239 if (sect_rest < fragm_rest)
88240 @@ -1261,7 +1261,7 @@ error:
88241 }
88242 } else
88243 skb_copy_to_linear_data_offset(buf, fragm_crs,
88244 - sect_crs, sz);
88245 + (const void __force_kernel *)sect_crs, sz);
88246 sect_crs += sz;
88247 sect_rest -= sz;
88248 fragm_crs += sz;
88249 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
88250 index f2db8a8..9245aa4 100644
88251 --- a/net/tipc/msg.c
88252 +++ b/net/tipc/msg.c
88253 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
88254 msg_sect[cnt].iov_len);
88255 else
88256 skb_copy_to_linear_data_offset(*buf, pos,
88257 - msg_sect[cnt].iov_base,
88258 + (const void __force_kernel *)msg_sect[cnt].iov_base,
88259 msg_sect[cnt].iov_len);
88260 pos += msg_sect[cnt].iov_len;
88261 }
88262 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
88263 index 6b42d47..2ac24d5 100644
88264 --- a/net/tipc/subscr.c
88265 +++ b/net/tipc/subscr.c
88266 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
88267 {
88268 struct iovec msg_sect;
88269
88270 - msg_sect.iov_base = (void *)&sub->evt;
88271 + msg_sect.iov_base = (void __force_user *)&sub->evt;
88272 msg_sect.iov_len = sizeof(struct tipc_event);
88273
88274 sub->evt.event = htohl(event, sub->swap);
88275 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
88276 index 5b5c876..3127bf7 100644
88277 --- a/net/unix/af_unix.c
88278 +++ b/net/unix/af_unix.c
88279 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
88280 err = -ECONNREFUSED;
88281 if (!S_ISSOCK(inode->i_mode))
88282 goto put_fail;
88283 +
88284 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
88285 + err = -EACCES;
88286 + goto put_fail;
88287 + }
88288 +
88289 u = unix_find_socket_byinode(inode);
88290 if (!u)
88291 goto put_fail;
88292 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
88293 if (u) {
88294 struct dentry *dentry;
88295 dentry = unix_sk(u)->path.dentry;
88296 +
88297 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
88298 + err = -EPERM;
88299 + sock_put(u);
88300 + goto fail;
88301 + }
88302 +
88303 if (dentry)
88304 touch_atime(&unix_sk(u)->path);
88305 } else
88306 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
88307 */
88308 err = security_path_mknod(&path, dentry, mode, 0);
88309 if (!err) {
88310 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
88311 + err = -EACCES;
88312 + goto out;
88313 + }
88314 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
88315 if (!err) {
88316 res->mnt = mntget(path.mnt);
88317 res->dentry = dget(dentry);
88318 + gr_handle_create(dentry, path.mnt);
88319 }
88320 }
88321 +out:
88322 done_path_create(&path, dentry);
88323 return err;
88324 }
88325 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
88326 index 8800604..0526440 100644
88327 --- a/net/unix/sysctl_net_unix.c
88328 +++ b/net/unix/sysctl_net_unix.c
88329 @@ -28,7 +28,7 @@ static ctl_table unix_table[] = {
88330
88331 int __net_init unix_sysctl_register(struct net *net)
88332 {
88333 - struct ctl_table *table;
88334 + ctl_table_no_const *table;
88335
88336 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
88337 if (table == NULL)
88338 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
88339 index c8717c1..08539f5 100644
88340 --- a/net/wireless/wext-core.c
88341 +++ b/net/wireless/wext-core.c
88342 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
88343 */
88344
88345 /* Support for very large requests */
88346 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
88347 - (user_length > descr->max_tokens)) {
88348 + if (user_length > descr->max_tokens) {
88349 /* Allow userspace to GET more than max so
88350 * we can support any size GET requests.
88351 * There is still a limit : -ENOMEM.
88352 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
88353 }
88354 }
88355
88356 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
88357 - /*
88358 - * If this is a GET, but not NOMAX, it means that the extra
88359 - * data is not bounded by userspace, but by max_tokens. Thus
88360 - * set the length to max_tokens. This matches the extra data
88361 - * allocation.
88362 - * The driver should fill it with the number of tokens it
88363 - * provided, and it may check iwp->length rather than having
88364 - * knowledge of max_tokens. If the driver doesn't change the
88365 - * iwp->length, this ioctl just copies back max_token tokens
88366 - * filled with zeroes. Hopefully the driver isn't claiming
88367 - * them to be valid data.
88368 - */
88369 - iwp->length = descr->max_tokens;
88370 - }
88371 -
88372 err = handler(dev, info, (union iwreq_data *) iwp, extra);
88373
88374 iwp->length += essid_compat;
88375 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
88376 index 07c5857..fde4018 100644
88377 --- a/net/xfrm/xfrm_policy.c
88378 +++ b/net/xfrm/xfrm_policy.c
88379 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
88380 {
88381 policy->walk.dead = 1;
88382
88383 - atomic_inc(&policy->genid);
88384 + atomic_inc_unchecked(&policy->genid);
88385
88386 if (del_timer(&policy->timer))
88387 xfrm_pol_put(policy);
88388 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
88389 hlist_add_head(&policy->bydst, chain);
88390 xfrm_pol_hold(policy);
88391 net->xfrm.policy_count[dir]++;
88392 - atomic_inc(&flow_cache_genid);
88393 + atomic_inc_unchecked(&flow_cache_genid);
88394 rt_genid_bump(net);
88395 if (delpol)
88396 __xfrm_policy_unlink(delpol, dir);
88397 @@ -1550,7 +1550,7 @@ free_dst:
88398 goto out;
88399 }
88400
88401 -static int inline
88402 +static inline int
88403 xfrm_dst_alloc_copy(void **target, const void *src, int size)
88404 {
88405 if (!*target) {
88406 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
88407 return 0;
88408 }
88409
88410 -static int inline
88411 +static inline int
88412 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
88413 {
88414 #ifdef CONFIG_XFRM_SUB_POLICY
88415 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
88416 #endif
88417 }
88418
88419 -static int inline
88420 +static inline int
88421 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
88422 {
88423 #ifdef CONFIG_XFRM_SUB_POLICY
88424 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
88425
88426 xdst->num_pols = num_pols;
88427 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
88428 - xdst->policy_genid = atomic_read(&pols[0]->genid);
88429 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
88430
88431 return xdst;
88432 }
88433 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
88434 if (xdst->xfrm_genid != dst->xfrm->genid)
88435 return 0;
88436 if (xdst->num_pols > 0 &&
88437 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
88438 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
88439 return 0;
88440
88441 mtu = dst_mtu(dst->child);
88442 @@ -2457,8 +2457,11 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
88443 dst_ops->link_failure = xfrm_link_failure;
88444 if (likely(dst_ops->neigh_lookup == NULL))
88445 dst_ops->neigh_lookup = xfrm_neigh_lookup;
88446 - if (likely(afinfo->garbage_collect == NULL))
88447 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
88448 + if (likely(afinfo->garbage_collect == NULL)) {
88449 + pax_open_kernel();
88450 + *(void **)&afinfo->garbage_collect = xfrm_garbage_collect_deferred;
88451 + pax_close_kernel();
88452 + }
88453 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
88454 }
88455 spin_unlock(&xfrm_policy_afinfo_lock);
88456 @@ -2512,7 +2515,9 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
88457 dst_ops->check = NULL;
88458 dst_ops->negative_advice = NULL;
88459 dst_ops->link_failure = NULL;
88460 - afinfo->garbage_collect = NULL;
88461 + pax_open_kernel();
88462 + *(void **)&afinfo->garbage_collect = NULL;
88463 + pax_close_kernel();
88464 }
88465 return err;
88466 }
88467 @@ -2896,7 +2901,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
88468 sizeof(pol->xfrm_vec[i].saddr));
88469 pol->xfrm_vec[i].encap_family = mp->new_family;
88470 /* flush bundles */
88471 - atomic_inc(&pol->genid);
88472 + atomic_inc_unchecked(&pol->genid);
88473 }
88474 }
88475
88476 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
88477 index 3459692..e7cdb1a 100644
88478 --- a/net/xfrm/xfrm_state.c
88479 +++ b/net/xfrm/xfrm_state.c
88480 @@ -194,11 +194,13 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
88481
88482 if (unlikely(afinfo == NULL))
88483 return -EAFNOSUPPORT;
88484 - typemap = afinfo->type_map;
88485 + typemap = (const struct xfrm_type **)afinfo->type_map;
88486
88487 - if (likely(typemap[type->proto] == NULL))
88488 + if (likely(typemap[type->proto] == NULL)) {
88489 + pax_open_kernel();
88490 typemap[type->proto] = type;
88491 - else
88492 + pax_close_kernel();
88493 + } else
88494 err = -EEXIST;
88495 xfrm_state_unlock_afinfo(afinfo);
88496 return err;
88497 @@ -213,12 +215,15 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
88498
88499 if (unlikely(afinfo == NULL))
88500 return -EAFNOSUPPORT;
88501 - typemap = afinfo->type_map;
88502 + typemap = (const struct xfrm_type **)afinfo->type_map;
88503
88504 if (unlikely(typemap[type->proto] != type))
88505 err = -ENOENT;
88506 - else
88507 + else {
88508 + pax_open_kernel();
88509 typemap[type->proto] = NULL;
88510 + pax_close_kernel();
88511 + }
88512 xfrm_state_unlock_afinfo(afinfo);
88513 return err;
88514 }
88515 @@ -227,7 +232,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
88516 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
88517 {
88518 struct xfrm_state_afinfo *afinfo;
88519 - const struct xfrm_type **typemap;
88520 const struct xfrm_type *type;
88521 int modload_attempted = 0;
88522
88523 @@ -235,9 +239,8 @@ retry:
88524 afinfo = xfrm_state_get_afinfo(family);
88525 if (unlikely(afinfo == NULL))
88526 return NULL;
88527 - typemap = afinfo->type_map;
88528
88529 - type = typemap[proto];
88530 + type = afinfo->type_map[proto];
88531 if (unlikely(type && !try_module_get(type->owner)))
88532 type = NULL;
88533 if (!type && !modload_attempted) {
88534 @@ -270,7 +273,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
88535 return -EAFNOSUPPORT;
88536
88537 err = -EEXIST;
88538 - modemap = afinfo->mode_map;
88539 + modemap = (struct xfrm_mode **)afinfo->mode_map;
88540 if (modemap[mode->encap])
88541 goto out;
88542
88543 @@ -278,8 +281,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
88544 if (!try_module_get(afinfo->owner))
88545 goto out;
88546
88547 - mode->afinfo = afinfo;
88548 + pax_open_kernel();
88549 + *(const void **)&mode->afinfo = afinfo;
88550 modemap[mode->encap] = mode;
88551 + pax_close_kernel();
88552 err = 0;
88553
88554 out:
88555 @@ -302,9 +307,11 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
88556 return -EAFNOSUPPORT;
88557
88558 err = -ENOENT;
88559 - modemap = afinfo->mode_map;
88560 + modemap = (struct xfrm_mode **)afinfo->mode_map;
88561 if (likely(modemap[mode->encap] == mode)) {
88562 + pax_open_kernel();
88563 modemap[mode->encap] = NULL;
88564 + pax_close_kernel();
88565 module_put(mode->afinfo->owner);
88566 err = 0;
88567 }
88568 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
88569 index 05a6e3d..6716ec9 100644
88570 --- a/net/xfrm/xfrm_sysctl.c
88571 +++ b/net/xfrm/xfrm_sysctl.c
88572 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
88573
88574 int __net_init xfrm_sysctl_init(struct net *net)
88575 {
88576 - struct ctl_table *table;
88577 + ctl_table_no_const *table;
88578
88579 __xfrm_sysctl_init(net);
88580
88581 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
88582 index 0e801c3..5c8ad3b 100644
88583 --- a/scripts/Makefile.build
88584 +++ b/scripts/Makefile.build
88585 @@ -111,7 +111,7 @@ endif
88586 endif
88587
88588 # Do not include host rules unless needed
88589 -ifneq ($(hostprogs-y)$(hostprogs-m),)
88590 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
88591 include scripts/Makefile.host
88592 endif
88593
88594 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
88595 index 686cb0d..9d653bf 100644
88596 --- a/scripts/Makefile.clean
88597 +++ b/scripts/Makefile.clean
88598 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
88599 __clean-files := $(extra-y) $(always) \
88600 $(targets) $(clean-files) \
88601 $(host-progs) \
88602 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
88603 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
88604 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
88605
88606 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
88607
88608 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
88609 index 1ac414f..38575f7 100644
88610 --- a/scripts/Makefile.host
88611 +++ b/scripts/Makefile.host
88612 @@ -31,6 +31,8 @@
88613 # Note: Shared libraries consisting of C++ files are not supported
88614
88615 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
88616 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
88617 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
88618
88619 # C code
88620 # Executables compiled from a single .c file
88621 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
88622 # Shared libaries (only .c supported)
88623 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
88624 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
88625 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
88626 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
88627 # Remove .so files from "xxx-objs"
88628 host-cobjs := $(filter-out %.so,$(host-cobjs))
88629 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
88630
88631 -#Object (.o) files used by the shared libaries
88632 +# Object (.o) files used by the shared libaries
88633 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
88634 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
88635
88636 # output directory for programs/.o files
88637 # hostprogs-y := tools/build may have been specified. Retrieve directory
88638 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
88639 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
88640 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
88641 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
88642 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
88643 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
88644 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
88645 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
88646
88647 obj-dirs += $(host-objdirs)
88648 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
88649 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
88650 $(call if_changed_dep,host-cshobjs)
88651
88652 +# Compile .c file, create position independent .o file
88653 +# host-cxxshobjs -> .o
88654 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
88655 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
88656 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
88657 + $(call if_changed_dep,host-cxxshobjs)
88658 +
88659 # Link a shared library, based on position independent .o files
88660 # *.o -> .so shared library (host-cshlib)
88661 quiet_cmd_host-cshlib = HOSTLLD -shared $@
88662 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
88663 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
88664 $(call if_changed,host-cshlib)
88665
88666 +# Link a shared library, based on position independent .o files
88667 +# *.o -> .so shared library (host-cxxshlib)
88668 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
88669 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
88670 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
88671 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
88672 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
88673 + $(call if_changed,host-cxxshlib)
88674 +
88675 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
88676 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
88677 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
88678
88679 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
88680 index cb1f50c..cef2a7c 100644
88681 --- a/scripts/basic/fixdep.c
88682 +++ b/scripts/basic/fixdep.c
88683 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
88684 /*
88685 * Lookup a value in the configuration string.
88686 */
88687 -static int is_defined_config(const char *name, int len, unsigned int hash)
88688 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
88689 {
88690 struct item *aux;
88691
88692 @@ -211,10 +211,10 @@ static void clear_config(void)
88693 /*
88694 * Record the use of a CONFIG_* word.
88695 */
88696 -static void use_config(const char *m, int slen)
88697 +static void use_config(const char *m, unsigned int slen)
88698 {
88699 unsigned int hash = strhash(m, slen);
88700 - int c, i;
88701 + unsigned int c, i;
88702
88703 if (is_defined_config(m, slen, hash))
88704 return;
88705 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
88706
88707 static void parse_config_file(const char *map, size_t len)
88708 {
88709 - const int *end = (const int *) (map + len);
88710 + const unsigned int *end = (const unsigned int *) (map + len);
88711 /* start at +1, so that p can never be < map */
88712 - const int *m = (const int *) map + 1;
88713 + const unsigned int *m = (const unsigned int *) map + 1;
88714 const char *p, *q;
88715
88716 for (; m < end; m++) {
88717 @@ -406,7 +406,7 @@ static void print_deps(void)
88718 static void traps(void)
88719 {
88720 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
88721 - int *p = (int *)test;
88722 + unsigned int *p = (unsigned int *)test;
88723
88724 if (*p != INT_CONF) {
88725 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
88726 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
88727 new file mode 100644
88728 index 0000000..5e0222d
88729 --- /dev/null
88730 +++ b/scripts/gcc-plugin.sh
88731 @@ -0,0 +1,17 @@
88732 +#!/bin/bash
88733 +plugincc=`$1 -E -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
88734 +#include "gcc-plugin.h"
88735 +#include "tree.h"
88736 +#include "tm.h"
88737 +#include "rtl.h"
88738 +#ifdef ENABLE_BUILD_WITH_CXX
88739 +#warning $2
88740 +#else
88741 +#warning $1
88742 +#endif
88743 +EOF`
88744 +if [ $? -eq 0 ]
88745 +then
88746 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
88747 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
88748 +fi
88749 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
88750 index b3d907e..a4782ab 100644
88751 --- a/scripts/link-vmlinux.sh
88752 +++ b/scripts/link-vmlinux.sh
88753 @@ -152,7 +152,7 @@ else
88754 fi;
88755
88756 # final build of init/
88757 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
88758 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
88759
88760 kallsymso=""
88761 kallsyms_vmlinux=""
88762 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
88763 index df4fc23..0ea719d 100644
88764 --- a/scripts/mod/file2alias.c
88765 +++ b/scripts/mod/file2alias.c
88766 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
88767 unsigned long size, unsigned long id_size,
88768 void *symval)
88769 {
88770 - int i;
88771 + unsigned int i;
88772
88773 if (size % id_size || size < id_size) {
88774 if (cross_build != 0)
88775 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
88776 /* USB is special because the bcdDevice can be matched against a numeric range */
88777 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
88778 static void do_usb_entry(struct usb_device_id *id,
88779 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
88780 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
88781 unsigned char range_lo, unsigned char range_hi,
88782 unsigned char max, struct module *mod)
88783 {
88784 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
88785 {
88786 unsigned int devlo, devhi;
88787 unsigned char chi, clo, max;
88788 - int ndigits;
88789 + unsigned int ndigits;
88790
88791 id->match_flags = TO_NATIVE(id->match_flags);
88792 id->idVendor = TO_NATIVE(id->idVendor);
88793 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
88794 for (i = 0; i < count; i++) {
88795 const char *id = (char *)devs[i].id;
88796 char acpi_id[sizeof(devs[0].id)];
88797 - int j;
88798 + unsigned int j;
88799
88800 buf_printf(&mod->dev_table_buf,
88801 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
88802 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
88803
88804 for (j = 0; j < PNP_MAX_DEVICES; j++) {
88805 const char *id = (char *)card->devs[j].id;
88806 - int i2, j2;
88807 + unsigned int i2, j2;
88808 int dup = 0;
88809
88810 if (!id[0])
88811 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
88812 /* add an individual alias for every device entry */
88813 if (!dup) {
88814 char acpi_id[sizeof(card->devs[0].id)];
88815 - int k;
88816 + unsigned int k;
88817
88818 buf_printf(&mod->dev_table_buf,
88819 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
88820 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
88821 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
88822 char *alias)
88823 {
88824 - int i, j;
88825 + unsigned int i, j;
88826
88827 sprintf(alias, "dmi*");
88828
88829 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
88830 index ff36c50..7ab4fa9 100644
88831 --- a/scripts/mod/modpost.c
88832 +++ b/scripts/mod/modpost.c
88833 @@ -929,6 +929,7 @@ enum mismatch {
88834 ANY_INIT_TO_ANY_EXIT,
88835 ANY_EXIT_TO_ANY_INIT,
88836 EXPORT_TO_INIT_EXIT,
88837 + DATA_TO_TEXT
88838 };
88839
88840 struct sectioncheck {
88841 @@ -1043,6 +1044,12 @@ const struct sectioncheck sectioncheck[] = {
88842 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
88843 .mismatch = EXPORT_TO_INIT_EXIT,
88844 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
88845 +},
88846 +/* Do not reference code from writable data */
88847 +{
88848 + .fromsec = { DATA_SECTIONS, NULL },
88849 + .tosec = { TEXT_SECTIONS, NULL },
88850 + .mismatch = DATA_TO_TEXT
88851 }
88852 };
88853
88854 @@ -1165,10 +1172,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
88855 continue;
88856 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
88857 continue;
88858 - if (sym->st_value == addr)
88859 - return sym;
88860 /* Find a symbol nearby - addr are maybe negative */
88861 d = sym->st_value - addr;
88862 + if (d == 0)
88863 + return sym;
88864 if (d < 0)
88865 d = addr - sym->st_value;
88866 if (d < distance) {
88867 @@ -1447,6 +1454,14 @@ static void report_sec_mismatch(const char *modname,
88868 tosym, prl_to, prl_to, tosym);
88869 free(prl_to);
88870 break;
88871 + case DATA_TO_TEXT:
88872 +#if 0
88873 + fprintf(stderr,
88874 + "The %s %s:%s references\n"
88875 + "the %s %s:%s%s\n",
88876 + from, fromsec, fromsym, to, tosec, tosym, to_p);
88877 +#endif
88878 + break;
88879 }
88880 fprintf(stderr, "\n");
88881 }
88882 @@ -1681,7 +1696,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
88883 static void check_sec_ref(struct module *mod, const char *modname,
88884 struct elf_info *elf)
88885 {
88886 - int i;
88887 + unsigned int i;
88888 Elf_Shdr *sechdrs = elf->sechdrs;
88889
88890 /* Walk through all sections */
88891 @@ -1779,7 +1794,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
88892 va_end(ap);
88893 }
88894
88895 -void buf_write(struct buffer *buf, const char *s, int len)
88896 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
88897 {
88898 if (buf->size - buf->pos < len) {
88899 buf->size += len + SZ;
88900 @@ -1997,7 +2012,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
88901 if (fstat(fileno(file), &st) < 0)
88902 goto close_write;
88903
88904 - if (st.st_size != b->pos)
88905 + if (st.st_size != (off_t)b->pos)
88906 goto close_write;
88907
88908 tmp = NOFAIL(malloc(b->pos));
88909 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
88910 index 51207e4..f7d603d 100644
88911 --- a/scripts/mod/modpost.h
88912 +++ b/scripts/mod/modpost.h
88913 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
88914
88915 struct buffer {
88916 char *p;
88917 - int pos;
88918 - int size;
88919 + unsigned int pos;
88920 + unsigned int size;
88921 };
88922
88923 void __attribute__((format(printf, 2, 3)))
88924 buf_printf(struct buffer *buf, const char *fmt, ...);
88925
88926 void
88927 -buf_write(struct buffer *buf, const char *s, int len);
88928 +buf_write(struct buffer *buf, const char *s, unsigned int len);
88929
88930 struct module {
88931 struct module *next;
88932 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
88933 index 9dfcd6d..099068e 100644
88934 --- a/scripts/mod/sumversion.c
88935 +++ b/scripts/mod/sumversion.c
88936 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
88937 goto out;
88938 }
88939
88940 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
88941 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
88942 warn("writing sum in %s failed: %s\n",
88943 filename, strerror(errno));
88944 goto out;
88945 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
88946 index 68bb4ef..2f419e1 100644
88947 --- a/scripts/pnmtologo.c
88948 +++ b/scripts/pnmtologo.c
88949 @@ -244,14 +244,14 @@ static void write_header(void)
88950 fprintf(out, " * Linux logo %s\n", logoname);
88951 fputs(" */\n\n", out);
88952 fputs("#include <linux/linux_logo.h>\n\n", out);
88953 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
88954 + fprintf(out, "static unsigned char %s_data[] = {\n",
88955 logoname);
88956 }
88957
88958 static void write_footer(void)
88959 {
88960 fputs("\n};\n\n", out);
88961 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
88962 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
88963 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
88964 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
88965 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
88966 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
88967 fputs("\n};\n\n", out);
88968
88969 /* write logo clut */
88970 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
88971 + fprintf(out, "static unsigned char %s_clut[] = {\n",
88972 logoname);
88973 write_hex_cnt = 0;
88974 for (i = 0; i < logo_clutsize; i++) {
88975 diff --git a/security/Kconfig b/security/Kconfig
88976 index e9c6ac7..da94e8b 100644
88977 --- a/security/Kconfig
88978 +++ b/security/Kconfig
88979 @@ -4,6 +4,920 @@
88980
88981 menu "Security options"
88982
88983 +menu "Grsecurity"
88984 +
88985 + config ARCH_TRACK_EXEC_LIMIT
88986 + bool
88987 +
88988 + config PAX_KERNEXEC_PLUGIN
88989 + bool
88990 +
88991 + config PAX_PER_CPU_PGD
88992 + bool
88993 +
88994 + config TASK_SIZE_MAX_SHIFT
88995 + int
88996 + depends on X86_64
88997 + default 47 if !PAX_PER_CPU_PGD
88998 + default 42 if PAX_PER_CPU_PGD
88999 +
89000 + config PAX_ENABLE_PAE
89001 + bool
89002 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
89003 +
89004 + config PAX_USERCOPY_SLABS
89005 + bool
89006 +
89007 +config GRKERNSEC
89008 + bool "Grsecurity"
89009 + select CRYPTO
89010 + select CRYPTO_SHA256
89011 + select PROC_FS
89012 + select STOP_MACHINE
89013 + help
89014 + If you say Y here, you will be able to configure many features
89015 + that will enhance the security of your system. It is highly
89016 + recommended that you say Y here and read through the help
89017 + for each option so that you fully understand the features and
89018 + can evaluate their usefulness for your machine.
89019 +
89020 +choice
89021 + prompt "Configuration Method"
89022 + depends on GRKERNSEC
89023 + default GRKERNSEC_CONFIG_CUSTOM
89024 + help
89025 +
89026 +config GRKERNSEC_CONFIG_AUTO
89027 + bool "Automatic"
89028 + help
89029 + If you choose this configuration method, you'll be able to answer a small
89030 + number of simple questions about how you plan to use this kernel.
89031 + The settings of grsecurity and PaX will be automatically configured for
89032 + the highest commonly-used settings within the provided constraints.
89033 +
89034 + If you require additional configuration, custom changes can still be made
89035 + from the "custom configuration" menu.
89036 +
89037 +config GRKERNSEC_CONFIG_CUSTOM
89038 + bool "Custom"
89039 + help
89040 + If you choose this configuration method, you'll be able to configure all
89041 + grsecurity and PaX settings manually. Via this method, no options are
89042 + automatically enabled.
89043 +
89044 +endchoice
89045 +
89046 +choice
89047 + prompt "Usage Type"
89048 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
89049 + default GRKERNSEC_CONFIG_SERVER
89050 + help
89051 +
89052 +config GRKERNSEC_CONFIG_SERVER
89053 + bool "Server"
89054 + help
89055 + Choose this option if you plan to use this kernel on a server.
89056 +
89057 +config GRKERNSEC_CONFIG_DESKTOP
89058 + bool "Desktop"
89059 + help
89060 + Choose this option if you plan to use this kernel on a desktop.
89061 +
89062 +endchoice
89063 +
89064 +choice
89065 + prompt "Virtualization Type"
89066 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
89067 + default GRKERNSEC_CONFIG_VIRT_NONE
89068 + help
89069 +
89070 +config GRKERNSEC_CONFIG_VIRT_NONE
89071 + bool "None"
89072 + help
89073 + Choose this option if this kernel will be run on bare metal.
89074 +
89075 +config GRKERNSEC_CONFIG_VIRT_GUEST
89076 + bool "Guest"
89077 + help
89078 + Choose this option if this kernel will be run as a VM guest.
89079 +
89080 +config GRKERNSEC_CONFIG_VIRT_HOST
89081 + bool "Host"
89082 + help
89083 + Choose this option if this kernel will be run as a VM host.
89084 +
89085 +endchoice
89086 +
89087 +choice
89088 + prompt "Virtualization Hardware"
89089 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
89090 + help
89091 +
89092 +config GRKERNSEC_CONFIG_VIRT_EPT
89093 + bool "EPT/RVI Processor Support"
89094 + depends on X86
89095 + help
89096 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
89097 + hardware virtualization. This allows for additional kernel hardening protections
89098 + to operate without additional performance impact.
89099 +
89100 + To see if your Intel processor supports EPT, see:
89101 + http://ark.intel.com/Products/VirtualizationTechnology
89102 + (Most Core i3/5/7 support EPT)
89103 +
89104 + To see if your AMD processor supports RVI, see:
89105 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
89106 +
89107 +config GRKERNSEC_CONFIG_VIRT_SOFT
89108 + bool "First-gen/No Hardware Virtualization"
89109 + help
89110 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
89111 + support hardware virtualization or doesn't support the EPT/RVI extensions.
89112 +
89113 +endchoice
89114 +
89115 +choice
89116 + prompt "Virtualization Software"
89117 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
89118 + help
89119 +
89120 +config GRKERNSEC_CONFIG_VIRT_XEN
89121 + bool "Xen"
89122 + help
89123 + Choose this option if this kernel is running as a Xen guest or host.
89124 +
89125 +config GRKERNSEC_CONFIG_VIRT_VMWARE
89126 + bool "VMWare"
89127 + help
89128 + Choose this option if this kernel is running as a VMWare guest or host.
89129 +
89130 +config GRKERNSEC_CONFIG_VIRT_KVM
89131 + bool "KVM"
89132 + help
89133 + Choose this option if this kernel is running as a KVM guest or host.
89134 +
89135 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
89136 + bool "VirtualBox"
89137 + help
89138 + Choose this option if this kernel is running as a VirtualBox guest or host.
89139 +
89140 +endchoice
89141 +
89142 +choice
89143 + prompt "Required Priorities"
89144 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
89145 + default GRKERNSEC_CONFIG_PRIORITY_PERF
89146 + help
89147 +
89148 +config GRKERNSEC_CONFIG_PRIORITY_PERF
89149 + bool "Performance"
89150 + help
89151 + Choose this option if performance is of highest priority for this deployment
89152 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
89153 + and freed memory sanitizing will be disabled.
89154 +
89155 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
89156 + bool "Security"
89157 + help
89158 + Choose this option if security is of highest priority for this deployment of
89159 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
89160 + be enabled for this kernel. In a worst-case scenario, these features can
89161 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
89162 +
89163 +endchoice
89164 +
89165 +menu "Default Special Groups"
89166 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
89167 +
89168 +config GRKERNSEC_PROC_GID
89169 + int "GID exempted from /proc restrictions"
89170 + default 1001
89171 + help
89172 + Setting this GID determines which group will be exempted from
89173 + grsecurity's /proc restrictions, allowing users of the specified
89174 + group to view network statistics and the existence of other users'
89175 + processes on the system. This GID may also be chosen at boot time
89176 + via "grsec_proc_gid=" on the kernel commandline.
89177 +
89178 +config GRKERNSEC_TPE_UNTRUSTED_GID
89179 + int "GID for TPE-untrusted users"
89180 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
89181 + default 1005
89182 + help
89183 + Setting this GID determines which group untrusted users should
89184 + be added to. These users will be placed under grsecurity's Trusted Path
89185 + Execution mechanism, preventing them from executing their own binaries.
89186 + The users will only be able to execute binaries in directories owned and
89187 + writable only by the root user. If the sysctl option is enabled, a sysctl
89188 + option with name "tpe_gid" is created.
89189 +
89190 +config GRKERNSEC_TPE_TRUSTED_GID
89191 + int "GID for TPE-trusted users"
89192 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
89193 + default 1005
89194 + help
89195 + Setting this GID determines what group TPE restrictions will be
89196 + *disabled* for. If the sysctl option is enabled, a sysctl option
89197 + with name "tpe_gid" is created.
89198 +
89199 +config GRKERNSEC_SYMLINKOWN_GID
89200 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
89201 + depends on GRKERNSEC_CONFIG_SERVER
89202 + default 1006
89203 + help
89204 + Setting this GID determines what group kernel-enforced
89205 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
89206 + is enabled, a sysctl option with name "symlinkown_gid" is created.
89207 +
89208 +
89209 +endmenu
89210 +
89211 +menu "Customize Configuration"
89212 +depends on GRKERNSEC
89213 +
89214 +menu "PaX"
89215 +
89216 +config PAX
89217 + bool "Enable various PaX features"
89218 + default y if GRKERNSEC_CONFIG_AUTO
89219 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
89220 + help
89221 + This allows you to enable various PaX features. PaX adds
89222 + intrusion prevention mechanisms to the kernel that reduce
89223 + the risks posed by exploitable memory corruption bugs.
89224 +
89225 +menu "PaX Control"
89226 + depends on PAX
89227 +
89228 +config PAX_SOFTMODE
89229 + bool 'Support soft mode'
89230 + help
89231 + Enabling this option will allow you to run PaX in soft mode, that
89232 + is, PaX features will not be enforced by default, only on executables
89233 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
89234 + support as they are the only way to mark executables for soft mode use.
89235 +
89236 + Soft mode can be activated by using the "pax_softmode=1" kernel command
89237 + line option on boot. Furthermore you can control various PaX features
89238 + at runtime via the entries in /proc/sys/kernel/pax.
89239 +
89240 +config PAX_EI_PAX
89241 + bool 'Use legacy ELF header marking'
89242 + default y if GRKERNSEC_CONFIG_AUTO
89243 + help
89244 + Enabling this option will allow you to control PaX features on
89245 + a per executable basis via the 'chpax' utility available at
89246 + http://pax.grsecurity.net/. The control flags will be read from
89247 + an otherwise reserved part of the ELF header. This marking has
89248 + numerous drawbacks (no support for soft-mode, toolchain does not
89249 + know about the non-standard use of the ELF header) therefore it
89250 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
89251 + support.
89252 +
89253 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
89254 + support as well, they will override the legacy EI_PAX marks.
89255 +
89256 + If you enable none of the marking options then all applications
89257 + will run with PaX enabled on them by default.
89258 +
89259 +config PAX_PT_PAX_FLAGS
89260 + bool 'Use ELF program header marking'
89261 + default y if GRKERNSEC_CONFIG_AUTO
89262 + help
89263 + Enabling this option will allow you to control PaX features on
89264 + a per executable basis via the 'paxctl' utility available at
89265 + http://pax.grsecurity.net/. The control flags will be read from
89266 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
89267 + has the benefits of supporting both soft mode and being fully
89268 + integrated into the toolchain (the binutils patch is available
89269 + from http://pax.grsecurity.net).
89270 +
89271 + Note that if you enable the legacy EI_PAX marking support as well,
89272 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
89273 +
89274 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
89275 + must make sure that the marks are the same if a binary has both marks.
89276 +
89277 + If you enable none of the marking options then all applications
89278 + will run with PaX enabled on them by default.
89279 +
89280 +config PAX_XATTR_PAX_FLAGS
89281 + bool 'Use filesystem extended attributes marking'
89282 + default y if GRKERNSEC_CONFIG_AUTO
89283 + select CIFS_XATTR if CIFS
89284 + select EXT2_FS_XATTR if EXT2_FS
89285 + select EXT3_FS_XATTR if EXT3_FS
89286 + select EXT4_FS_XATTR if EXT4_FS
89287 + select JFFS2_FS_XATTR if JFFS2_FS
89288 + select REISERFS_FS_XATTR if REISERFS_FS
89289 + select SQUASHFS_XATTR if SQUASHFS
89290 + select TMPFS_XATTR if TMPFS
89291 + select UBIFS_FS_XATTR if UBIFS_FS
89292 + help
89293 + Enabling this option will allow you to control PaX features on
89294 + a per executable basis via the 'setfattr' utility. The control
89295 + flags will be read from the user.pax.flags extended attribute of
89296 + the file. This marking has the benefit of supporting binary-only
89297 + applications that self-check themselves (e.g., skype) and would
89298 + not tolerate chpax/paxctl changes. The main drawback is that
89299 + extended attributes are not supported by some filesystems (e.g.,
89300 + isofs, udf, vfat) so copying files through such filesystems will
89301 + lose the extended attributes and these PaX markings.
89302 +
89303 + Note that if you enable the legacy EI_PAX marking support as well,
89304 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
89305 +
89306 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
89307 + must make sure that the marks are the same if a binary has both marks.
89308 +
89309 + If you enable none of the marking options then all applications
89310 + will run with PaX enabled on them by default.
89311 +
89312 +choice
89313 + prompt 'MAC system integration'
89314 + default PAX_HAVE_ACL_FLAGS
89315 + help
89316 + Mandatory Access Control systems have the option of controlling
89317 + PaX flags on a per executable basis, choose the method supported
89318 + by your particular system.
89319 +
89320 + - "none": if your MAC system does not interact with PaX,
89321 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
89322 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
89323 +
89324 + NOTE: this option is for developers/integrators only.
89325 +
89326 + config PAX_NO_ACL_FLAGS
89327 + bool 'none'
89328 +
89329 + config PAX_HAVE_ACL_FLAGS
89330 + bool 'direct'
89331 +
89332 + config PAX_HOOK_ACL_FLAGS
89333 + bool 'hook'
89334 +endchoice
89335 +
89336 +endmenu
89337 +
89338 +menu "Non-executable pages"
89339 + depends on PAX
89340 +
89341 +config PAX_NOEXEC
89342 + bool "Enforce non-executable pages"
89343 + default y if GRKERNSEC_CONFIG_AUTO
89344 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
89345 + help
89346 + By design some architectures do not allow for protecting memory
89347 + pages against execution or even if they do, Linux does not make
89348 + use of this feature. In practice this means that if a page is
89349 + readable (such as the stack or heap) it is also executable.
89350 +
89351 + There is a well known exploit technique that makes use of this
89352 + fact and a common programming mistake where an attacker can
89353 + introduce code of his choice somewhere in the attacked program's
89354 + memory (typically the stack or the heap) and then execute it.
89355 +
89356 + If the attacked program was running with different (typically
89357 + higher) privileges than that of the attacker, then he can elevate
89358 + his own privilege level (e.g. get a root shell, write to files for
89359 + which he does not have write access to, etc).
89360 +
89361 + Enabling this option will let you choose from various features
89362 + that prevent the injection and execution of 'foreign' code in
89363 + a program.
89364 +
89365 + This will also break programs that rely on the old behaviour and
89366 + expect that dynamically allocated memory via the malloc() family
89367 + of functions is executable (which it is not). Notable examples
89368 + are the XFree86 4.x server, the java runtime and wine.
89369 +
89370 +config PAX_PAGEEXEC
89371 + bool "Paging based non-executable pages"
89372 + default y if GRKERNSEC_CONFIG_AUTO
89373 + 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)
89374 + select S390_SWITCH_AMODE if S390
89375 + select S390_EXEC_PROTECT if S390
89376 + select ARCH_TRACK_EXEC_LIMIT if X86_32
89377 + help
89378 + This implementation is based on the paging feature of the CPU.
89379 + On i386 without hardware non-executable bit support there is a
89380 + variable but usually low performance impact, however on Intel's
89381 + P4 core based CPUs it is very high so you should not enable this
89382 + for kernels meant to be used on such CPUs.
89383 +
89384 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
89385 + with hardware non-executable bit support there is no performance
89386 + impact, on ppc the impact is negligible.
89387 +
89388 + Note that several architectures require various emulations due to
89389 + badly designed userland ABIs, this will cause a performance impact
89390 + but will disappear as soon as userland is fixed. For example, ppc
89391 + userland MUST have been built with secure-plt by a recent toolchain.
89392 +
89393 +config PAX_SEGMEXEC
89394 + bool "Segmentation based non-executable pages"
89395 + default y if GRKERNSEC_CONFIG_AUTO
89396 + depends on PAX_NOEXEC && X86_32
89397 + help
89398 + This implementation is based on the segmentation feature of the
89399 + CPU and has a very small performance impact, however applications
89400 + will be limited to a 1.5 GB address space instead of the normal
89401 + 3 GB.
89402 +
89403 +config PAX_EMUTRAMP
89404 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
89405 + default y if PARISC
89406 + help
89407 + There are some programs and libraries that for one reason or
89408 + another attempt to execute special small code snippets from
89409 + non-executable memory pages. Most notable examples are the
89410 + signal handler return code generated by the kernel itself and
89411 + the GCC trampolines.
89412 +
89413 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
89414 + such programs will no longer work under your kernel.
89415 +
89416 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
89417 + utilities to enable trampoline emulation for the affected programs
89418 + yet still have the protection provided by the non-executable pages.
89419 +
89420 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
89421 + your system will not even boot.
89422 +
89423 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
89424 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
89425 + for the affected files.
89426 +
89427 + NOTE: enabling this feature *may* open up a loophole in the
89428 + protection provided by non-executable pages that an attacker
89429 + could abuse. Therefore the best solution is to not have any
89430 + files on your system that would require this option. This can
89431 + be achieved by not using libc5 (which relies on the kernel
89432 + signal handler return code) and not using or rewriting programs
89433 + that make use of the nested function implementation of GCC.
89434 + Skilled users can just fix GCC itself so that it implements
89435 + nested function calls in a way that does not interfere with PaX.
89436 +
89437 +config PAX_EMUSIGRT
89438 + bool "Automatically emulate sigreturn trampolines"
89439 + depends on PAX_EMUTRAMP && PARISC
89440 + default y
89441 + help
89442 + Enabling this option will have the kernel automatically detect
89443 + and emulate signal return trampolines executing on the stack
89444 + that would otherwise lead to task termination.
89445 +
89446 + This solution is intended as a temporary one for users with
89447 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
89448 + Modula-3 runtime, etc) or executables linked to such, basically
89449 + everything that does not specify its own SA_RESTORER function in
89450 + normal executable memory like glibc 2.1+ does.
89451 +
89452 + On parisc you MUST enable this option, otherwise your system will
89453 + not even boot.
89454 +
89455 + NOTE: this feature cannot be disabled on a per executable basis
89456 + and since it *does* open up a loophole in the protection provided
89457 + by non-executable pages, the best solution is to not have any
89458 + files on your system that would require this option.
89459 +
89460 +config PAX_MPROTECT
89461 + bool "Restrict mprotect()"
89462 + default y if GRKERNSEC_CONFIG_AUTO
89463 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
89464 + help
89465 + Enabling this option will prevent programs from
89466 + - changing the executable status of memory pages that were
89467 + not originally created as executable,
89468 + - making read-only executable pages writable again,
89469 + - creating executable pages from anonymous memory,
89470 + - making read-only-after-relocations (RELRO) data pages writable again.
89471 +
89472 + You should say Y here to complete the protection provided by
89473 + the enforcement of non-executable pages.
89474 +
89475 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
89476 + this feature on a per file basis.
89477 +
89478 +config PAX_MPROTECT_COMPAT
89479 + bool "Use legacy/compat protection demoting (read help)"
89480 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
89481 + depends on PAX_MPROTECT
89482 + help
89483 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
89484 + by sending the proper error code to the application. For some broken
89485 + userland, this can cause problems with Python or other applications. The
89486 + current implementation however allows for applications like clamav to
89487 + detect if JIT compilation/execution is allowed and to fall back gracefully
89488 + to an interpreter-based mode if it does not. While we encourage everyone
89489 + to use the current implementation as-is and push upstream to fix broken
89490 + userland (note that the RWX logging option can assist with this), in some
89491 + environments this may not be possible. Having to disable MPROTECT
89492 + completely on certain binaries reduces the security benefit of PaX,
89493 + so this option is provided for those environments to revert to the old
89494 + behavior.
89495 +
89496 +config PAX_ELFRELOCS
89497 + bool "Allow ELF text relocations (read help)"
89498 + depends on PAX_MPROTECT
89499 + default n
89500 + help
89501 + Non-executable pages and mprotect() restrictions are effective
89502 + in preventing the introduction of new executable code into an
89503 + attacked task's address space. There remain only two venues
89504 + for this kind of attack: if the attacker can execute already
89505 + existing code in the attacked task then he can either have it
89506 + create and mmap() a file containing his code or have it mmap()
89507 + an already existing ELF library that does not have position
89508 + independent code in it and use mprotect() on it to make it
89509 + writable and copy his code there. While protecting against
89510 + the former approach is beyond PaX, the latter can be prevented
89511 + by having only PIC ELF libraries on one's system (which do not
89512 + need to relocate their code). If you are sure this is your case,
89513 + as is the case with all modern Linux distributions, then leave
89514 + this option disabled. You should say 'n' here.
89515 +
89516 +config PAX_ETEXECRELOCS
89517 + bool "Allow ELF ET_EXEC text relocations"
89518 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
89519 + select PAX_ELFRELOCS
89520 + default y
89521 + help
89522 + On some architectures there are incorrectly created applications
89523 + that require text relocations and would not work without enabling
89524 + this option. If you are an alpha, ia64 or parisc user, you should
89525 + enable this option and disable it once you have made sure that
89526 + none of your applications need it.
89527 +
89528 +config PAX_EMUPLT
89529 + bool "Automatically emulate ELF PLT"
89530 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
89531 + default y
89532 + help
89533 + Enabling this option will have the kernel automatically detect
89534 + and emulate the Procedure Linkage Table entries in ELF files.
89535 + On some architectures such entries are in writable memory, and
89536 + become non-executable leading to task termination. Therefore
89537 + it is mandatory that you enable this option on alpha, parisc,
89538 + sparc and sparc64, otherwise your system would not even boot.
89539 +
89540 + NOTE: this feature *does* open up a loophole in the protection
89541 + provided by the non-executable pages, therefore the proper
89542 + solution is to modify the toolchain to produce a PLT that does
89543 + not need to be writable.
89544 +
89545 +config PAX_DLRESOLVE
89546 + bool 'Emulate old glibc resolver stub'
89547 + depends on PAX_EMUPLT && SPARC
89548 + default n
89549 + help
89550 + This option is needed if userland has an old glibc (before 2.4)
89551 + that puts a 'save' instruction into the runtime generated resolver
89552 + stub that needs special emulation.
89553 +
89554 +config PAX_KERNEXEC
89555 + bool "Enforce non-executable kernel pages"
89556 + 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))
89557 + depends on ((X86 && (!X86_32 || X86_WP_WORKS_OK)) || (ARM && (CPU_V6 || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
89558 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
89559 + select PAX_KERNEXEC_PLUGIN if X86_64
89560 + help
89561 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
89562 + that is, enabling this option will make it harder to inject
89563 + and execute 'foreign' code in kernel memory itself.
89564 +
89565 +choice
89566 + prompt "Return Address Instrumentation Method"
89567 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
89568 + depends on PAX_KERNEXEC_PLUGIN
89569 + help
89570 + Select the method used to instrument function pointer dereferences.
89571 + Note that binary modules cannot be instrumented by this approach.
89572 +
89573 + Note that the implementation requires a gcc with plugin support,
89574 + i.e., gcc 4.5 or newer. You may need to install the supporting
89575 + headers explicitly in addition to the normal gcc package.
89576 +
89577 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
89578 + bool "bts"
89579 + help
89580 + This method is compatible with binary only modules but has
89581 + a higher runtime overhead.
89582 +
89583 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
89584 + bool "or"
89585 + depends on !PARAVIRT
89586 + help
89587 + This method is incompatible with binary only modules but has
89588 + a lower runtime overhead.
89589 +endchoice
89590 +
89591 +config PAX_KERNEXEC_PLUGIN_METHOD
89592 + string
89593 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
89594 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
89595 + default ""
89596 +
89597 +config PAX_KERNEXEC_MODULE_TEXT
89598 + int "Minimum amount of memory reserved for module code"
89599 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
89600 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
89601 + depends on PAX_KERNEXEC && X86_32 && MODULES
89602 + help
89603 + Due to implementation details the kernel must reserve a fixed
89604 + amount of memory for module code at compile time that cannot be
89605 + changed at runtime. Here you can specify the minimum amount
89606 + in MB that will be reserved. Due to the same implementation
89607 + details this size will always be rounded up to the next 2/4 MB
89608 + boundary (depends on PAE) so the actually available memory for
89609 + module code will usually be more than this minimum.
89610 +
89611 + The default 4 MB should be enough for most users but if you have
89612 + an excessive number of modules (e.g., most distribution configs
89613 + compile many drivers as modules) or use huge modules such as
89614 + nvidia's kernel driver, you will need to adjust this amount.
89615 + A good rule of thumb is to look at your currently loaded kernel
89616 + modules and add up their sizes.
89617 +
89618 +endmenu
89619 +
89620 +menu "Address Space Layout Randomization"
89621 + depends on PAX
89622 +
89623 +config PAX_ASLR
89624 + bool "Address Space Layout Randomization"
89625 + default y if GRKERNSEC_CONFIG_AUTO
89626 + help
89627 + Many if not most exploit techniques rely on the knowledge of
89628 + certain addresses in the attacked program. The following options
89629 + will allow the kernel to apply a certain amount of randomization
89630 + to specific parts of the program thereby forcing an attacker to
89631 + guess them in most cases. Any failed guess will most likely crash
89632 + the attacked program which allows the kernel to detect such attempts
89633 + and react on them. PaX itself provides no reaction mechanisms,
89634 + instead it is strongly encouraged that you make use of Nergal's
89635 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
89636 + (http://www.grsecurity.net/) built-in crash detection features or
89637 + develop one yourself.
89638 +
89639 + By saying Y here you can choose to randomize the following areas:
89640 + - top of the task's kernel stack
89641 + - top of the task's userland stack
89642 + - base address for mmap() requests that do not specify one
89643 + (this includes all libraries)
89644 + - base address of the main executable
89645 +
89646 + It is strongly recommended to say Y here as address space layout
89647 + randomization has negligible impact on performance yet it provides
89648 + a very effective protection.
89649 +
89650 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
89651 + this feature on a per file basis.
89652 +
89653 +config PAX_RANDKSTACK
89654 + bool "Randomize kernel stack base"
89655 + default y if GRKERNSEC_CONFIG_AUTO
89656 + depends on X86_TSC && X86
89657 + help
89658 + By saying Y here the kernel will randomize every task's kernel
89659 + stack on every system call. This will not only force an attacker
89660 + to guess it but also prevent him from making use of possible
89661 + leaked information about it.
89662 +
89663 + Since the kernel stack is a rather scarce resource, randomization
89664 + may cause unexpected stack overflows, therefore you should very
89665 + carefully test your system. Note that once enabled in the kernel
89666 + configuration, this feature cannot be disabled on a per file basis.
89667 +
89668 +config PAX_RANDUSTACK
89669 + bool "Randomize user stack base"
89670 + default y if GRKERNSEC_CONFIG_AUTO
89671 + depends on PAX_ASLR
89672 + help
89673 + By saying Y here the kernel will randomize every task's userland
89674 + stack. The randomization is done in two steps where the second
89675 + one may apply a big amount of shift to the top of the stack and
89676 + cause problems for programs that want to use lots of memory (more
89677 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
89678 + For this reason the second step can be controlled by 'chpax' or
89679 + 'paxctl' on a per file basis.
89680 +
89681 +config PAX_RANDMMAP
89682 + bool "Randomize mmap() base"
89683 + default y if GRKERNSEC_CONFIG_AUTO
89684 + depends on PAX_ASLR
89685 + help
89686 + By saying Y here the kernel will use a randomized base address for
89687 + mmap() requests that do not specify one themselves. As a result
89688 + all dynamically loaded libraries will appear at random addresses
89689 + and therefore be harder to exploit by a technique where an attacker
89690 + attempts to execute library code for his purposes (e.g. spawn a
89691 + shell from an exploited program that is running at an elevated
89692 + privilege level).
89693 +
89694 + Furthermore, if a program is relinked as a dynamic ELF file, its
89695 + base address will be randomized as well, completing the full
89696 + randomization of the address space layout. Attacking such programs
89697 + becomes a guess game. You can find an example of doing this at
89698 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
89699 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
89700 +
89701 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
89702 + feature on a per file basis.
89703 +
89704 +endmenu
89705 +
89706 +menu "Miscellaneous hardening features"
89707 +
89708 +config PAX_MEMORY_SANITIZE
89709 + bool "Sanitize all freed memory"
89710 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
89711 + depends on !HIBERNATION
89712 + help
89713 + By saying Y here the kernel will erase memory pages as soon as they
89714 + are freed. This in turn reduces the lifetime of data stored in the
89715 + pages, making it less likely that sensitive information such as
89716 + passwords, cryptographic secrets, etc stay in memory for too long.
89717 +
89718 + This is especially useful for programs whose runtime is short, long
89719 + lived processes and the kernel itself benefit from this as long as
89720 + they operate on whole memory pages and ensure timely freeing of pages
89721 + that may hold sensitive information.
89722 +
89723 + The tradeoff is performance impact, on a single CPU system kernel
89724 + compilation sees a 3% slowdown, other systems and workloads may vary
89725 + and you are advised to test this feature on your expected workload
89726 + before deploying it.
89727 +
89728 + Note that this feature does not protect data stored in live pages,
89729 + e.g., process memory swapped to disk may stay there for a long time.
89730 +
89731 +config PAX_MEMORY_STACKLEAK
89732 + bool "Sanitize kernel stack"
89733 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
89734 + depends on X86
89735 + help
89736 + By saying Y here the kernel will erase the kernel stack before it
89737 + returns from a system call. This in turn reduces the information
89738 + that a kernel stack leak bug can reveal.
89739 +
89740 + Note that such a bug can still leak information that was put on
89741 + the stack by the current system call (the one eventually triggering
89742 + the bug) but traces of earlier system calls on the kernel stack
89743 + cannot leak anymore.
89744 +
89745 + The tradeoff is performance impact: on a single CPU system kernel
89746 + compilation sees a 1% slowdown, other systems and workloads may vary
89747 + and you are advised to test this feature on your expected workload
89748 + before deploying it.
89749 +
89750 + Note that the full feature requires a gcc with plugin support,
89751 + i.e., gcc 4.5 or newer. You may need to install the supporting
89752 + headers explicitly in addition to the normal gcc package. Using
89753 + older gcc versions means that functions with large enough stack
89754 + frames may leave uninitialized memory behind that may be exposed
89755 + to a later syscall leaking the stack.
89756 +
89757 +config PAX_MEMORY_UDEREF
89758 + bool "Prevent invalid userland pointer dereference"
89759 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
89760 + depends on (X86 || (ARM && (CPU_V6 || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
89761 + select PAX_PER_CPU_PGD if X86_64
89762 + help
89763 + By saying Y here the kernel will be prevented from dereferencing
89764 + userland pointers in contexts where the kernel expects only kernel
89765 + pointers. This is both a useful runtime debugging feature and a
89766 + security measure that prevents exploiting a class of kernel bugs.
89767 +
89768 + The tradeoff is that some virtualization solutions may experience
89769 + a huge slowdown and therefore you should not enable this feature
89770 + for kernels meant to run in such environments. Whether a given VM
89771 + solution is affected or not is best determined by simply trying it
89772 + out, the performance impact will be obvious right on boot as this
89773 + mechanism engages from very early on. A good rule of thumb is that
89774 + VMs running on CPUs without hardware virtualization support (i.e.,
89775 + the majority of IA-32 CPUs) will likely experience the slowdown.
89776 +
89777 +config PAX_REFCOUNT
89778 + bool "Prevent various kernel object reference counter overflows"
89779 + default y if GRKERNSEC_CONFIG_AUTO
89780 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
89781 + help
89782 + By saying Y here the kernel will detect and prevent overflowing
89783 + various (but not all) kinds of object reference counters. Such
89784 + overflows can normally occur due to bugs only and are often, if
89785 + not always, exploitable.
89786 +
89787 + The tradeoff is that data structures protected by an overflowed
89788 + refcount will never be freed and therefore will leak memory. Note
89789 + that this leak also happens even without this protection but in
89790 + that case the overflow can eventually trigger the freeing of the
89791 + data structure while it is still being used elsewhere, resulting
89792 + in the exploitable situation that this feature prevents.
89793 +
89794 + Since this has a negligible performance impact, you should enable
89795 + this feature.
89796 +
89797 +config PAX_CONSTIFY_PLUGIN
89798 + bool "Automatically constify eligible structures"
89799 + default y
89800 + depends on !UML
89801 + help
89802 + By saying Y here the compiler will automatically constify a class
89803 + of types that contain only function pointers. This reduces the
89804 + kernel's attack surface and also produces a better memory layout.
89805 +
89806 + Note that the implementation requires a gcc with plugin support,
89807 + i.e., gcc 4.5 or newer. You may need to install the supporting
89808 + headers explicitly in addition to the normal gcc package.
89809 +
89810 + Note that if some code really has to modify constified variables
89811 + then the source code will have to be patched to allow it. Examples
89812 + can be found in PaX itself (the no_const attribute) and for some
89813 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
89814 +
89815 +config PAX_USERCOPY
89816 + bool "Harden heap object copies between kernel and userland"
89817 + default y if GRKERNSEC_CONFIG_AUTO
89818 + depends on ARM || IA64 || PPC || SPARC || X86
89819 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
89820 + select PAX_USERCOPY_SLABS
89821 + help
89822 + By saying Y here the kernel will enforce the size of heap objects
89823 + when they are copied in either direction between the kernel and
89824 + userland, even if only a part of the heap object is copied.
89825 +
89826 + Specifically, this checking prevents information leaking from the
89827 + kernel heap during kernel to userland copies (if the kernel heap
89828 + object is otherwise fully initialized) and prevents kernel heap
89829 + overflows during userland to kernel copies.
89830 +
89831 + Note that the current implementation provides the strictest bounds
89832 + checks for the SLUB allocator.
89833 +
89834 + Enabling this option also enables per-slab cache protection against
89835 + data in a given cache being copied into/out of via userland
89836 + accessors. Though the whitelist of regions will be reduced over
89837 + time, it notably protects important data structures like task structs.
89838 +
89839 + If frame pointers are enabled on x86, this option will also restrict
89840 + copies into and out of the kernel stack to local variables within a
89841 + single frame.
89842 +
89843 + Since this has a negligible performance impact, you should enable
89844 + this feature.
89845 +
89846 +
89847 +config PAX_USERCOPY_DEBUG
89848 + bool
89849 + depends on X86 && PAX_USERCOPY
89850 + default n
89851 +
89852 +config PAX_SIZE_OVERFLOW
89853 + bool "Prevent various integer overflows in function size parameters"
89854 + default y if GRKERNSEC_CONFIG_AUTO
89855 + depends on X86
89856 + help
89857 + By saying Y here the kernel recomputes expressions of function
89858 + arguments marked by a size_overflow attribute with double integer
89859 + precision (DImode/TImode for 32/64 bit integer types).
89860 +
89861 + The recomputed argument is checked against TYPE_MAX and an event
89862 + is logged on overflow and the triggering process is killed.
89863 +
89864 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
89865 +
89866 + Note that the implementation requires a gcc with plugin support,
89867 + i.e., gcc 4.5 or newer. You may need to install the supporting
89868 + headers explicitly in addition to the normal gcc package.
89869 +
89870 +config PAX_LATENT_ENTROPY
89871 + bool "Generate some entropy during boot"
89872 + default y if GRKERNSEC_CONFIG_AUTO
89873 + help
89874 + By saying Y here the kernel will instrument early boot code to
89875 + extract some entropy from both original and artificially created
89876 + program state. This will help especially embedded systems where
89877 + there is little 'natural' source of entropy normally. The cost
89878 + is some slowdown of the boot process.
89879 +
89880 + Note that the implementation requires a gcc with plugin support,
89881 + i.e., gcc 4.5 or newer. You may need to install the supporting
89882 + headers explicitly in addition to the normal gcc package.
89883 +
89884 + Note that entropy extracted this way is not cryptographically
89885 + secure!
89886 +
89887 +endmenu
89888 +
89889 +endmenu
89890 +
89891 +source grsecurity/Kconfig
89892 +
89893 +endmenu
89894 +
89895 +endmenu
89896 +
89897 source security/keys/Kconfig
89898
89899 config SECURITY_DMESG_RESTRICT
89900 @@ -103,7 +1017,7 @@ config INTEL_TXT
89901 config LSM_MMAP_MIN_ADDR
89902 int "Low address space for LSM to protect from user allocation"
89903 depends on SECURITY && SECURITY_SELINUX
89904 - default 32768 if ARM
89905 + default 32768 if ALPHA || ARM || PARISC || SPARC32
89906 default 65536
89907 help
89908 This is the portion of low virtual memory which should be protected
89909 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
89910 index 8c2a7f6..b133ac9 100644
89911 --- a/security/apparmor/lsm.c
89912 +++ b/security/apparmor/lsm.c
89913 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
89914 return error;
89915 }
89916
89917 -static struct security_operations apparmor_ops = {
89918 +static struct security_operations apparmor_ops __read_only = {
89919 .name = "apparmor",
89920
89921 .ptrace_access_check = apparmor_ptrace_access_check,
89922 diff --git a/security/commoncap.c b/security/commoncap.c
89923 index 7ee08c7..8d1a9d6 100644
89924 --- a/security/commoncap.c
89925 +++ b/security/commoncap.c
89926 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
89927 return 0;
89928 }
89929
89930 +/* returns:
89931 + 1 for suid privilege
89932 + 2 for sgid privilege
89933 + 3 for fscap privilege
89934 +*/
89935 +int is_privileged_binary(const struct dentry *dentry)
89936 +{
89937 + struct cpu_vfs_cap_data capdata;
89938 + struct inode *inode = dentry->d_inode;
89939 +
89940 + if (!inode || S_ISDIR(inode->i_mode))
89941 + return 0;
89942 +
89943 + if (inode->i_mode & S_ISUID)
89944 + return 1;
89945 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
89946 + return 2;
89947 +
89948 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
89949 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
89950 + return 3;
89951 + }
89952 +
89953 + return 0;
89954 +}
89955 +
89956 /*
89957 * Attempt to get the on-exec apply capability sets for an executable file from
89958 * its xattrs and, if present, apply them to the proposed credentials being
89959 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
89960 const struct cred *cred = current_cred();
89961 kuid_t root_uid = make_kuid(cred->user_ns, 0);
89962
89963 + if (gr_acl_enable_at_secure())
89964 + return 1;
89965 +
89966 if (!uid_eq(cred->uid, root_uid)) {
89967 if (bprm->cap_effective)
89968 return 1;
89969 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
89970 index 079a85d..12e93f8 100644
89971 --- a/security/integrity/ima/ima.h
89972 +++ b/security/integrity/ima/ima.h
89973 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
89974 extern spinlock_t ima_queue_lock;
89975
89976 struct ima_h_table {
89977 - atomic_long_t len; /* number of stored measurements in the list */
89978 - atomic_long_t violations;
89979 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
89980 + atomic_long_unchecked_t violations;
89981 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
89982 };
89983 extern struct ima_h_table ima_htable;
89984 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
89985 index 0cea3db..2f0ef77 100644
89986 --- a/security/integrity/ima/ima_api.c
89987 +++ b/security/integrity/ima/ima_api.c
89988 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
89989 int result;
89990
89991 /* can overflow, only indicator */
89992 - atomic_long_inc(&ima_htable.violations);
89993 + atomic_long_inc_unchecked(&ima_htable.violations);
89994
89995 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
89996 if (!entry) {
89997 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
89998 index 38477c9..87a60c7 100644
89999 --- a/security/integrity/ima/ima_fs.c
90000 +++ b/security/integrity/ima/ima_fs.c
90001 @@ -28,12 +28,12 @@
90002 static int valid_policy = 1;
90003 #define TMPBUFLEN 12
90004 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
90005 - loff_t *ppos, atomic_long_t *val)
90006 + loff_t *ppos, atomic_long_unchecked_t *val)
90007 {
90008 char tmpbuf[TMPBUFLEN];
90009 ssize_t len;
90010
90011 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
90012 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
90013 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
90014 }
90015
90016 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
90017 index 55a6271..ad829c3 100644
90018 --- a/security/integrity/ima/ima_queue.c
90019 +++ b/security/integrity/ima/ima_queue.c
90020 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
90021 INIT_LIST_HEAD(&qe->later);
90022 list_add_tail_rcu(&qe->later, &ima_measurements);
90023
90024 - atomic_long_inc(&ima_htable.len);
90025 + atomic_long_inc_unchecked(&ima_htable.len);
90026 key = ima_hash_key(entry->digest);
90027 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
90028 return 0;
90029 diff --git a/security/keys/compat.c b/security/keys/compat.c
90030 index 1c26176..64a1ba2 100644
90031 --- a/security/keys/compat.c
90032 +++ b/security/keys/compat.c
90033 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
90034 if (ret == 0)
90035 goto no_payload_free;
90036
90037 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
90038 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
90039
90040 if (iov != iovstack)
90041 kfree(iov);
90042 diff --git a/security/keys/key.c b/security/keys/key.c
90043 index 8fb7c7b..ba3610d 100644
90044 --- a/security/keys/key.c
90045 +++ b/security/keys/key.c
90046 @@ -284,7 +284,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
90047
90048 atomic_set(&key->usage, 1);
90049 init_rwsem(&key->sem);
90050 - lockdep_set_class(&key->sem, &type->lock_class);
90051 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
90052 key->type = type;
90053 key->user = user;
90054 key->quotalen = quotalen;
90055 @@ -1032,7 +1032,9 @@ int register_key_type(struct key_type *ktype)
90056 struct key_type *p;
90057 int ret;
90058
90059 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
90060 + pax_open_kernel();
90061 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
90062 + pax_close_kernel();
90063
90064 ret = -EEXIST;
90065 down_write(&key_types_sem);
90066 @@ -1044,7 +1046,7 @@ int register_key_type(struct key_type *ktype)
90067 }
90068
90069 /* store the type */
90070 - list_add(&ktype->link, &key_types_list);
90071 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
90072
90073 pr_notice("Key type %s registered\n", ktype->name);
90074 ret = 0;
90075 @@ -1066,7 +1068,7 @@ EXPORT_SYMBOL(register_key_type);
90076 void unregister_key_type(struct key_type *ktype)
90077 {
90078 down_write(&key_types_sem);
90079 - list_del_init(&ktype->link);
90080 + pax_list_del_init((struct list_head *)&ktype->link);
90081 downgrade_write(&key_types_sem);
90082 key_gc_keytype(ktype);
90083 pr_notice("Key type %s unregistered\n", ktype->name);
90084 @@ -1084,10 +1086,10 @@ void __init key_init(void)
90085 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
90086
90087 /* add the special key types */
90088 - list_add_tail(&key_type_keyring.link, &key_types_list);
90089 - list_add_tail(&key_type_dead.link, &key_types_list);
90090 - list_add_tail(&key_type_user.link, &key_types_list);
90091 - list_add_tail(&key_type_logon.link, &key_types_list);
90092 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
90093 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
90094 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
90095 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
90096
90097 /* record the root user tracking */
90098 rb_link_node(&root_key_user.node,
90099 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
90100 index 4b5c948..2054dc1 100644
90101 --- a/security/keys/keyctl.c
90102 +++ b/security/keys/keyctl.c
90103 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
90104 /*
90105 * Copy the iovec data from userspace
90106 */
90107 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
90108 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
90109 unsigned ioc)
90110 {
90111 for (; ioc > 0; ioc--) {
90112 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
90113 * If successful, 0 will be returned.
90114 */
90115 long keyctl_instantiate_key_common(key_serial_t id,
90116 - const struct iovec *payload_iov,
90117 + const struct iovec __user *payload_iov,
90118 unsigned ioc,
90119 size_t plen,
90120 key_serial_t ringid)
90121 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
90122 [0].iov_len = plen
90123 };
90124
90125 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
90126 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
90127 }
90128
90129 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
90130 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
90131 if (ret == 0)
90132 goto no_payload_free;
90133
90134 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
90135 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
90136 err:
90137 if (iov != iovstack)
90138 kfree(iov);
90139 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
90140 index 6ece7f2..ecdb55c 100644
90141 --- a/security/keys/keyring.c
90142 +++ b/security/keys/keyring.c
90143 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
90144 ret = -EFAULT;
90145
90146 for (loop = 0; loop < klist->nkeys; loop++) {
90147 + key_serial_t serial;
90148 key = rcu_deref_link_locked(klist, loop,
90149 keyring);
90150 + serial = key->serial;
90151
90152 tmp = sizeof(key_serial_t);
90153 if (tmp > buflen)
90154 tmp = buflen;
90155
90156 - if (copy_to_user(buffer,
90157 - &key->serial,
90158 - tmp) != 0)
90159 + if (copy_to_user(buffer, &serial, tmp))
90160 goto error;
90161
90162 buflen -= tmp;
90163 diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
90164 index 58dfe08..c5ec083 100644
90165 --- a/security/keys/process_keys.c
90166 +++ b/security/keys/process_keys.c
90167 @@ -57,7 +57,7 @@ int install_user_keyrings(void)
90168
90169 kenter("%p{%u}", user, uid);
90170
90171 - if (user->uid_keyring) {
90172 + if (user->uid_keyring && user->session_keyring) {
90173 kleave(" = 0 [exist]");
90174 return 0;
90175 }
90176 diff --git a/security/min_addr.c b/security/min_addr.c
90177 index f728728..6457a0c 100644
90178 --- a/security/min_addr.c
90179 +++ b/security/min_addr.c
90180 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
90181 */
90182 static void update_mmap_min_addr(void)
90183 {
90184 +#ifndef SPARC
90185 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
90186 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
90187 mmap_min_addr = dac_mmap_min_addr;
90188 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
90189 #else
90190 mmap_min_addr = dac_mmap_min_addr;
90191 #endif
90192 +#endif
90193 }
90194
90195 /*
90196 diff --git a/security/security.c b/security/security.c
90197 index 7b88c6a..1e3ea8f 100644
90198 --- a/security/security.c
90199 +++ b/security/security.c
90200 @@ -20,6 +20,7 @@
90201 #include <linux/ima.h>
90202 #include <linux/evm.h>
90203 #include <linux/fsnotify.h>
90204 +#include <linux/mm.h>
90205 #include <linux/mman.h>
90206 #include <linux/mount.h>
90207 #include <linux/personality.h>
90208 @@ -32,8 +33,8 @@
90209 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
90210 CONFIG_DEFAULT_SECURITY;
90211
90212 -static struct security_operations *security_ops;
90213 -static struct security_operations default_security_ops = {
90214 +static struct security_operations *security_ops __read_only;
90215 +static struct security_operations default_security_ops __read_only = {
90216 .name = "default",
90217 };
90218
90219 @@ -74,7 +75,9 @@ int __init security_init(void)
90220
90221 void reset_security_ops(void)
90222 {
90223 + pax_open_kernel();
90224 security_ops = &default_security_ops;
90225 + pax_close_kernel();
90226 }
90227
90228 /* Save user chosen LSM */
90229 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
90230 index ef26e96..642fb78 100644
90231 --- a/security/selinux/hooks.c
90232 +++ b/security/selinux/hooks.c
90233 @@ -95,8 +95,6 @@
90234
90235 #define NUM_SEL_MNT_OPTS 5
90236
90237 -extern struct security_operations *security_ops;
90238 -
90239 /* SECMARK reference count */
90240 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
90241
90242 @@ -5501,7 +5499,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
90243
90244 #endif
90245
90246 -static struct security_operations selinux_ops = {
90247 +static struct security_operations selinux_ops __read_only = {
90248 .name = "selinux",
90249
90250 .ptrace_access_check = selinux_ptrace_access_check,
90251 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
90252 index 65f67cb..3f141ef 100644
90253 --- a/security/selinux/include/xfrm.h
90254 +++ b/security/selinux/include/xfrm.h
90255 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
90256
90257 static inline void selinux_xfrm_notify_policyload(void)
90258 {
90259 - atomic_inc(&flow_cache_genid);
90260 + atomic_inc_unchecked(&flow_cache_genid);
90261 rt_genid_bump(&init_net);
90262 }
90263 #else
90264 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
90265 index 38be92c..21f49ee 100644
90266 --- a/security/smack/smack_lsm.c
90267 +++ b/security/smack/smack_lsm.c
90268 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
90269 return 0;
90270 }
90271
90272 -struct security_operations smack_ops = {
90273 +struct security_operations smack_ops __read_only = {
90274 .name = "smack",
90275
90276 .ptrace_access_check = smack_ptrace_access_check,
90277 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
90278 index 390c646..f2f8db3 100644
90279 --- a/security/tomoyo/mount.c
90280 +++ b/security/tomoyo/mount.c
90281 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
90282 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
90283 need_dev = -1; /* dev_name is a directory */
90284 } else {
90285 + if (!capable(CAP_SYS_ADMIN)) {
90286 + error = -EPERM;
90287 + goto out;
90288 + }
90289 fstype = get_fs_type(type);
90290 if (!fstype) {
90291 error = -ENODEV;
90292 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
90293 index a2ee362..5754f34 100644
90294 --- a/security/tomoyo/tomoyo.c
90295 +++ b/security/tomoyo/tomoyo.c
90296 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
90297 * tomoyo_security_ops is a "struct security_operations" which is used for
90298 * registering TOMOYO.
90299 */
90300 -static struct security_operations tomoyo_security_ops = {
90301 +static struct security_operations tomoyo_security_ops __read_only = {
90302 .name = "tomoyo",
90303 .cred_alloc_blank = tomoyo_cred_alloc_blank,
90304 .cred_prepare = tomoyo_cred_prepare,
90305 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
90306 index 20ef514..4182bed 100644
90307 --- a/security/yama/Kconfig
90308 +++ b/security/yama/Kconfig
90309 @@ -1,6 +1,6 @@
90310 config SECURITY_YAMA
90311 bool "Yama support"
90312 - depends on SECURITY
90313 + depends on SECURITY && !GRKERNSEC
90314 select SECURITYFS
90315 select SECURITY_PATH
90316 default n
90317 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
90318 index 23414b9..b92b314 100644
90319 --- a/security/yama/yama_lsm.c
90320 +++ b/security/yama/yama_lsm.c
90321 @@ -367,7 +367,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
90322 }
90323
90324 #ifndef CONFIG_SECURITY_YAMA_STACKED
90325 -static struct security_operations yama_ops = {
90326 +static struct security_operations yama_ops __read_only = {
90327 .name = "yama",
90328
90329 .ptrace_access_check = yama_ptrace_access_check,
90330 @@ -378,28 +378,24 @@ static struct security_operations yama_ops = {
90331 #endif
90332
90333 #ifdef CONFIG_SYSCTL
90334 +static int zero __read_only;
90335 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
90336 +
90337 static int yama_dointvec_minmax(struct ctl_table *table, int write,
90338 void __user *buffer, size_t *lenp, loff_t *ppos)
90339 {
90340 - int rc;
90341 + ctl_table_no_const yama_table;
90342
90343 if (write && !capable(CAP_SYS_PTRACE))
90344 return -EPERM;
90345
90346 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90347 - if (rc)
90348 - return rc;
90349 -
90350 + yama_table = *table;
90351 /* Lock the max value if it ever gets set. */
90352 - if (write && *(int *)table->data == *(int *)table->extra2)
90353 - table->extra1 = table->extra2;
90354 -
90355 - return rc;
90356 + if (ptrace_scope == max_scope)
90357 + yama_table.extra1 = &max_scope;
90358 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
90359 }
90360
90361 -static int zero;
90362 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
90363 -
90364 struct ctl_path yama_sysctl_path[] = {
90365 { .procname = "kernel", },
90366 { .procname = "yama", },
90367 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
90368 index 4cedc69..e59d8a3 100644
90369 --- a/sound/aoa/codecs/onyx.c
90370 +++ b/sound/aoa/codecs/onyx.c
90371 @@ -54,7 +54,7 @@ struct onyx {
90372 spdif_locked:1,
90373 analog_locked:1,
90374 original_mute:2;
90375 - int open_count;
90376 + local_t open_count;
90377 struct codec_info *codec_info;
90378
90379 /* mutex serializes concurrent access to the device
90380 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
90381 struct onyx *onyx = cii->codec_data;
90382
90383 mutex_lock(&onyx->mutex);
90384 - onyx->open_count++;
90385 + local_inc(&onyx->open_count);
90386 mutex_unlock(&onyx->mutex);
90387
90388 return 0;
90389 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
90390 struct onyx *onyx = cii->codec_data;
90391
90392 mutex_lock(&onyx->mutex);
90393 - onyx->open_count--;
90394 - if (!onyx->open_count)
90395 + if (local_dec_and_test(&onyx->open_count))
90396 onyx->spdif_locked = onyx->analog_locked = 0;
90397 mutex_unlock(&onyx->mutex);
90398
90399 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
90400 index ffd2025..df062c9 100644
90401 --- a/sound/aoa/codecs/onyx.h
90402 +++ b/sound/aoa/codecs/onyx.h
90403 @@ -11,6 +11,7 @@
90404 #include <linux/i2c.h>
90405 #include <asm/pmac_low_i2c.h>
90406 #include <asm/prom.h>
90407 +#include <asm/local.h>
90408
90409 /* PCM3052 register definitions */
90410
90411 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
90412 index 4c1cc51..16040040 100644
90413 --- a/sound/core/oss/pcm_oss.c
90414 +++ b/sound/core/oss/pcm_oss.c
90415 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
90416 if (in_kernel) {
90417 mm_segment_t fs;
90418 fs = snd_enter_user();
90419 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
90420 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
90421 snd_leave_user(fs);
90422 } else {
90423 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
90424 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
90425 }
90426 if (ret != -EPIPE && ret != -ESTRPIPE)
90427 break;
90428 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
90429 if (in_kernel) {
90430 mm_segment_t fs;
90431 fs = snd_enter_user();
90432 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
90433 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
90434 snd_leave_user(fs);
90435 } else {
90436 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
90437 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
90438 }
90439 if (ret == -EPIPE) {
90440 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
90441 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
90442 struct snd_pcm_plugin_channel *channels;
90443 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
90444 if (!in_kernel) {
90445 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
90446 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
90447 return -EFAULT;
90448 buf = runtime->oss.buffer;
90449 }
90450 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
90451 }
90452 } else {
90453 tmp = snd_pcm_oss_write2(substream,
90454 - (const char __force *)buf,
90455 + (const char __force_kernel *)buf,
90456 runtime->oss.period_bytes, 0);
90457 if (tmp <= 0)
90458 goto err;
90459 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
90460 struct snd_pcm_runtime *runtime = substream->runtime;
90461 snd_pcm_sframes_t frames, frames1;
90462 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
90463 - char __user *final_dst = (char __force __user *)buf;
90464 + char __user *final_dst = (char __force_user *)buf;
90465 if (runtime->oss.plugin_first) {
90466 struct snd_pcm_plugin_channel *channels;
90467 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
90468 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
90469 xfer += tmp;
90470 runtime->oss.buffer_used -= tmp;
90471 } else {
90472 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
90473 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
90474 runtime->oss.period_bytes, 0);
90475 if (tmp <= 0)
90476 goto err;
90477 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
90478 size1);
90479 size1 /= runtime->channels; /* frames */
90480 fs = snd_enter_user();
90481 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
90482 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
90483 snd_leave_user(fs);
90484 }
90485 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
90486 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
90487 index af49721..e85058e 100644
90488 --- a/sound/core/pcm_compat.c
90489 +++ b/sound/core/pcm_compat.c
90490 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
90491 int err;
90492
90493 fs = snd_enter_user();
90494 - err = snd_pcm_delay(substream, &delay);
90495 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
90496 snd_leave_user(fs);
90497 if (err < 0)
90498 return err;
90499 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
90500 index 09b4286..8620fac 100644
90501 --- a/sound/core/pcm_native.c
90502 +++ b/sound/core/pcm_native.c
90503 @@ -2806,11 +2806,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
90504 switch (substream->stream) {
90505 case SNDRV_PCM_STREAM_PLAYBACK:
90506 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
90507 - (void __user *)arg);
90508 + (void __force_user *)arg);
90509 break;
90510 case SNDRV_PCM_STREAM_CAPTURE:
90511 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
90512 - (void __user *)arg);
90513 + (void __force_user *)arg);
90514 break;
90515 default:
90516 result = -EINVAL;
90517 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
90518 index 040c60e..989a19a 100644
90519 --- a/sound/core/seq/seq_device.c
90520 +++ b/sound/core/seq/seq_device.c
90521 @@ -64,7 +64,7 @@ struct ops_list {
90522 int argsize; /* argument size */
90523
90524 /* operators */
90525 - struct snd_seq_dev_ops ops;
90526 + struct snd_seq_dev_ops *ops;
90527
90528 /* registered devices */
90529 struct list_head dev_list; /* list of devices */
90530 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
90531
90532 mutex_lock(&ops->reg_mutex);
90533 /* copy driver operators */
90534 - ops->ops = *entry;
90535 + ops->ops = entry;
90536 ops->driver |= DRIVER_LOADED;
90537 ops->argsize = argsize;
90538
90539 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
90540 dev->name, ops->id, ops->argsize, dev->argsize);
90541 return -EINVAL;
90542 }
90543 - if (ops->ops.init_device(dev) >= 0) {
90544 + if (ops->ops->init_device(dev) >= 0) {
90545 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
90546 ops->num_init_devices++;
90547 } else {
90548 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
90549 dev->name, ops->id, ops->argsize, dev->argsize);
90550 return -EINVAL;
90551 }
90552 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
90553 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
90554 dev->status = SNDRV_SEQ_DEVICE_FREE;
90555 dev->driver_data = NULL;
90556 ops->num_init_devices--;
90557 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
90558 index 4e0dd22..7a1f32c 100644
90559 --- a/sound/drivers/mts64.c
90560 +++ b/sound/drivers/mts64.c
90561 @@ -29,6 +29,7 @@
90562 #include <sound/initval.h>
90563 #include <sound/rawmidi.h>
90564 #include <sound/control.h>
90565 +#include <asm/local.h>
90566
90567 #define CARD_NAME "Miditerminal 4140"
90568 #define DRIVER_NAME "MTS64"
90569 @@ -67,7 +68,7 @@ struct mts64 {
90570 struct pardevice *pardev;
90571 int pardev_claimed;
90572
90573 - int open_count;
90574 + local_t open_count;
90575 int current_midi_output_port;
90576 int current_midi_input_port;
90577 u8 mode[MTS64_NUM_INPUT_PORTS];
90578 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
90579 {
90580 struct mts64 *mts = substream->rmidi->private_data;
90581
90582 - if (mts->open_count == 0) {
90583 + if (local_read(&mts->open_count) == 0) {
90584 /* We don't need a spinlock here, because this is just called
90585 if the device has not been opened before.
90586 So there aren't any IRQs from the device */
90587 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
90588
90589 msleep(50);
90590 }
90591 - ++(mts->open_count);
90592 + local_inc(&mts->open_count);
90593
90594 return 0;
90595 }
90596 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
90597 struct mts64 *mts = substream->rmidi->private_data;
90598 unsigned long flags;
90599
90600 - --(mts->open_count);
90601 - if (mts->open_count == 0) {
90602 + if (local_dec_return(&mts->open_count) == 0) {
90603 /* We need the spinlock_irqsave here because we can still
90604 have IRQs at this point */
90605 spin_lock_irqsave(&mts->lock, flags);
90606 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
90607
90608 msleep(500);
90609
90610 - } else if (mts->open_count < 0)
90611 - mts->open_count = 0;
90612 + } else if (local_read(&mts->open_count) < 0)
90613 + local_set(&mts->open_count, 0);
90614
90615 return 0;
90616 }
90617 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
90618 index b953fb4..1999c01 100644
90619 --- a/sound/drivers/opl4/opl4_lib.c
90620 +++ b/sound/drivers/opl4/opl4_lib.c
90621 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
90622 MODULE_DESCRIPTION("OPL4 driver");
90623 MODULE_LICENSE("GPL");
90624
90625 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
90626 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
90627 {
90628 int timeout = 10;
90629 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
90630 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
90631 index 991018d..8984740 100644
90632 --- a/sound/drivers/portman2x4.c
90633 +++ b/sound/drivers/portman2x4.c
90634 @@ -48,6 +48,7 @@
90635 #include <sound/initval.h>
90636 #include <sound/rawmidi.h>
90637 #include <sound/control.h>
90638 +#include <asm/local.h>
90639
90640 #define CARD_NAME "Portman 2x4"
90641 #define DRIVER_NAME "portman"
90642 @@ -85,7 +86,7 @@ struct portman {
90643 struct pardevice *pardev;
90644 int pardev_claimed;
90645
90646 - int open_count;
90647 + local_t open_count;
90648 int mode[PORTMAN_NUM_INPUT_PORTS];
90649 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
90650 };
90651 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
90652 index ea995af..f1bfa37 100644
90653 --- a/sound/firewire/amdtp.c
90654 +++ b/sound/firewire/amdtp.c
90655 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
90656 ptr = s->pcm_buffer_pointer + data_blocks;
90657 if (ptr >= pcm->runtime->buffer_size)
90658 ptr -= pcm->runtime->buffer_size;
90659 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
90660 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
90661
90662 s->pcm_period_pointer += data_blocks;
90663 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
90664 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
90665 */
90666 void amdtp_out_stream_update(struct amdtp_out_stream *s)
90667 {
90668 - ACCESS_ONCE(s->source_node_id_field) =
90669 + ACCESS_ONCE_RW(s->source_node_id_field) =
90670 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
90671 }
90672 EXPORT_SYMBOL(amdtp_out_stream_update);
90673 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
90674 index b680c5e..061b7a0 100644
90675 --- a/sound/firewire/amdtp.h
90676 +++ b/sound/firewire/amdtp.h
90677 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
90678 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
90679 struct snd_pcm_substream *pcm)
90680 {
90681 - ACCESS_ONCE(s->pcm) = pcm;
90682 + ACCESS_ONCE_RW(s->pcm) = pcm;
90683 }
90684
90685 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
90686 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
90687 index d428ffe..751ef78 100644
90688 --- a/sound/firewire/isight.c
90689 +++ b/sound/firewire/isight.c
90690 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
90691 ptr += count;
90692 if (ptr >= runtime->buffer_size)
90693 ptr -= runtime->buffer_size;
90694 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
90695 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
90696
90697 isight->period_counter += count;
90698 if (isight->period_counter >= runtime->period_size) {
90699 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
90700 if (err < 0)
90701 return err;
90702
90703 - ACCESS_ONCE(isight->pcm_active) = true;
90704 + ACCESS_ONCE_RW(isight->pcm_active) = true;
90705
90706 return 0;
90707 }
90708 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
90709 {
90710 struct isight *isight = substream->private_data;
90711
90712 - ACCESS_ONCE(isight->pcm_active) = false;
90713 + ACCESS_ONCE_RW(isight->pcm_active) = false;
90714
90715 mutex_lock(&isight->mutex);
90716 isight_stop_streaming(isight);
90717 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
90718
90719 switch (cmd) {
90720 case SNDRV_PCM_TRIGGER_START:
90721 - ACCESS_ONCE(isight->pcm_running) = true;
90722 + ACCESS_ONCE_RW(isight->pcm_running) = true;
90723 break;
90724 case SNDRV_PCM_TRIGGER_STOP:
90725 - ACCESS_ONCE(isight->pcm_running) = false;
90726 + ACCESS_ONCE_RW(isight->pcm_running) = false;
90727 break;
90728 default:
90729 return -EINVAL;
90730 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
90731 index 844a555..985ab83 100644
90732 --- a/sound/firewire/scs1x.c
90733 +++ b/sound/firewire/scs1x.c
90734 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
90735 {
90736 struct scs *scs = stream->rmidi->private_data;
90737
90738 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
90739 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
90740 if (up) {
90741 scs->output_idle = false;
90742 tasklet_schedule(&scs->tasklet);
90743 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
90744 {
90745 struct scs *scs = stream->rmidi->private_data;
90746
90747 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
90748 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
90749 }
90750
90751 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
90752 @@ -457,8 +457,8 @@ static int scs_remove(struct device *dev)
90753
90754 snd_card_disconnect(scs->card);
90755
90756 - ACCESS_ONCE(scs->output) = NULL;
90757 - ACCESS_ONCE(scs->input) = NULL;
90758 + ACCESS_ONCE_RW(scs->output) = NULL;
90759 + ACCESS_ONCE_RW(scs->input) = NULL;
90760
90761 wait_event(scs->idle_wait, scs->output_idle);
90762
90763 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
90764 index 048439a..3be9f6f 100644
90765 --- a/sound/oss/sb_audio.c
90766 +++ b/sound/oss/sb_audio.c
90767 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
90768 buf16 = (signed short *)(localbuf + localoffs);
90769 while (c)
90770 {
90771 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
90772 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
90773 if (copy_from_user(lbuf8,
90774 userbuf+useroffs + p,
90775 locallen))
90776 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
90777 index 7d8803a..559f8d0 100644
90778 --- a/sound/oss/swarm_cs4297a.c
90779 +++ b/sound/oss/swarm_cs4297a.c
90780 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
90781 {
90782 struct cs4297a_state *s;
90783 u32 pwr, id;
90784 - mm_segment_t fs;
90785 int rval;
90786 #ifndef CONFIG_BCM_CS4297A_CSWARM
90787 u64 cfg;
90788 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
90789 if (!rval) {
90790 char *sb1250_duart_present;
90791
90792 +#if 0
90793 + mm_segment_t fs;
90794 fs = get_fs();
90795 set_fs(KERNEL_DS);
90796 -#if 0
90797 val = SOUND_MASK_LINE;
90798 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
90799 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
90800 val = initvol[i].vol;
90801 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
90802 }
90803 + set_fs(fs);
90804 // cs4297a_write_ac97(s, 0x18, 0x0808);
90805 #else
90806 // cs4297a_write_ac97(s, 0x5e, 0x180);
90807 cs4297a_write_ac97(s, 0x02, 0x0808);
90808 cs4297a_write_ac97(s, 0x18, 0x0808);
90809 #endif
90810 - set_fs(fs);
90811
90812 list_add(&s->list, &cs4297a_devs);
90813
90814 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
90815 index 4631a23..001ae57 100644
90816 --- a/sound/pci/ymfpci/ymfpci.h
90817 +++ b/sound/pci/ymfpci/ymfpci.h
90818 @@ -358,7 +358,7 @@ struct snd_ymfpci {
90819 spinlock_t reg_lock;
90820 spinlock_t voice_lock;
90821 wait_queue_head_t interrupt_sleep;
90822 - atomic_t interrupt_sleep_count;
90823 + atomic_unchecked_t interrupt_sleep_count;
90824 struct snd_info_entry *proc_entry;
90825 const struct firmware *dsp_microcode;
90826 const struct firmware *controller_microcode;
90827 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
90828 index 22056c5..25d3244 100644
90829 --- a/sound/pci/ymfpci/ymfpci_main.c
90830 +++ b/sound/pci/ymfpci/ymfpci_main.c
90831 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
90832 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
90833 break;
90834 }
90835 - if (atomic_read(&chip->interrupt_sleep_count)) {
90836 - atomic_set(&chip->interrupt_sleep_count, 0);
90837 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
90838 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
90839 wake_up(&chip->interrupt_sleep);
90840 }
90841 __end:
90842 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
90843 continue;
90844 init_waitqueue_entry(&wait, current);
90845 add_wait_queue(&chip->interrupt_sleep, &wait);
90846 - atomic_inc(&chip->interrupt_sleep_count);
90847 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
90848 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
90849 remove_wait_queue(&chip->interrupt_sleep, &wait);
90850 }
90851 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
90852 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
90853 spin_unlock(&chip->reg_lock);
90854
90855 - if (atomic_read(&chip->interrupt_sleep_count)) {
90856 - atomic_set(&chip->interrupt_sleep_count, 0);
90857 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
90858 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
90859 wake_up(&chip->interrupt_sleep);
90860 }
90861 }
90862 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
90863 spin_lock_init(&chip->reg_lock);
90864 spin_lock_init(&chip->voice_lock);
90865 init_waitqueue_head(&chip->interrupt_sleep);
90866 - atomic_set(&chip->interrupt_sleep_count, 0);
90867 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
90868 chip->card = card;
90869 chip->pci = pci;
90870 chip->irq = -1;
90871 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
90872 new file mode 100644
90873 index 0000000..50f2f2f
90874 --- /dev/null
90875 +++ b/tools/gcc/.gitignore
90876 @@ -0,0 +1 @@
90877 +size_overflow_hash.h
90878 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
90879 new file mode 100644
90880 index 0000000..6920fb3
90881 --- /dev/null
90882 +++ b/tools/gcc/Makefile
90883 @@ -0,0 +1,43 @@
90884 +#CC := gcc
90885 +#PLUGIN_SOURCE_FILES := pax_plugin.c
90886 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
90887 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
90888 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
90889 +
90890 +ifeq ($(PLUGINCC),$(HOSTCC))
90891 +HOSTLIBS := hostlibs
90892 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
90893 +else
90894 +HOSTLIBS := hostcxxlibs
90895 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -ggdb -Wno-unused-parameter
90896 +endif
90897 +
90898 +$(HOSTLIBS)-y := constify_plugin.so
90899 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
90900 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
90901 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
90902 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
90903 +$(HOSTLIBS)-y += colorize_plugin.so
90904 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
90905 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
90906 +
90907 +always := $($(HOSTLIBS)-y)
90908 +
90909 +constify_plugin-objs := constify_plugin.o
90910 +stackleak_plugin-objs := stackleak_plugin.o
90911 +kallocstat_plugin-objs := kallocstat_plugin.o
90912 +kernexec_plugin-objs := kernexec_plugin.o
90913 +checker_plugin-objs := checker_plugin.o
90914 +colorize_plugin-objs := colorize_plugin.o
90915 +size_overflow_plugin-objs := size_overflow_plugin.o
90916 +latent_entropy_plugin-objs := latent_entropy_plugin.o
90917 +
90918 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
90919 +
90920 +quiet_cmd_build_size_overflow_hash = GENHASH $@
90921 + cmd_build_size_overflow_hash = \
90922 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
90923 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
90924 + $(call if_changed,build_size_overflow_hash)
90925 +
90926 +targets += size_overflow_hash.h
90927 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
90928 new file mode 100644
90929 index 0000000..d41b5af
90930 --- /dev/null
90931 +++ b/tools/gcc/checker_plugin.c
90932 @@ -0,0 +1,171 @@
90933 +/*
90934 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
90935 + * Licensed under the GPL v2
90936 + *
90937 + * Note: the choice of the license means that the compilation process is
90938 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
90939 + * but for the kernel it doesn't matter since it doesn't link against
90940 + * any of the gcc libraries
90941 + *
90942 + * gcc plugin to implement various sparse (source code checker) features
90943 + *
90944 + * TODO:
90945 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
90946 + *
90947 + * BUGS:
90948 + * - none known
90949 + */
90950 +#include "gcc-plugin.h"
90951 +#include "config.h"
90952 +#include "system.h"
90953 +#include "coretypes.h"
90954 +#include "tree.h"
90955 +#include "tree-pass.h"
90956 +#include "flags.h"
90957 +#include "intl.h"
90958 +#include "toplev.h"
90959 +#include "plugin.h"
90960 +//#include "expr.h" where are you...
90961 +#include "diagnostic.h"
90962 +#include "plugin-version.h"
90963 +#include "tm.h"
90964 +#include "function.h"
90965 +#include "basic-block.h"
90966 +#include "gimple.h"
90967 +#include "rtl.h"
90968 +#include "emit-rtl.h"
90969 +#include "tree-flow.h"
90970 +#include "target.h"
90971 +
90972 +extern void c_register_addr_space (const char *str, addr_space_t as);
90973 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
90974 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
90975 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
90976 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
90977 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
90978 +
90979 +extern void print_gimple_stmt(FILE *, gimple, int, int);
90980 +extern rtx emit_move_insn(rtx x, rtx y);
90981 +
90982 +int plugin_is_GPL_compatible;
90983 +
90984 +static struct plugin_info checker_plugin_info = {
90985 + .version = "201111150100",
90986 +};
90987 +
90988 +#define ADDR_SPACE_KERNEL 0
90989 +#define ADDR_SPACE_FORCE_KERNEL 1
90990 +#define ADDR_SPACE_USER 2
90991 +#define ADDR_SPACE_FORCE_USER 3
90992 +#define ADDR_SPACE_IOMEM 0
90993 +#define ADDR_SPACE_FORCE_IOMEM 0
90994 +#define ADDR_SPACE_PERCPU 0
90995 +#define ADDR_SPACE_FORCE_PERCPU 0
90996 +#define ADDR_SPACE_RCU 0
90997 +#define ADDR_SPACE_FORCE_RCU 0
90998 +
90999 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
91000 +{
91001 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
91002 +}
91003 +
91004 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
91005 +{
91006 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
91007 +}
91008 +
91009 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
91010 +{
91011 + return default_addr_space_valid_pointer_mode(mode, as);
91012 +}
91013 +
91014 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
91015 +{
91016 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
91017 +}
91018 +
91019 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
91020 +{
91021 + return default_addr_space_legitimize_address(x, oldx, mode, as);
91022 +}
91023 +
91024 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
91025 +{
91026 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
91027 + return true;
91028 +
91029 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
91030 + return true;
91031 +
91032 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
91033 + return true;
91034 +
91035 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
91036 + return true;
91037 +
91038 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
91039 + return true;
91040 +
91041 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
91042 + return true;
91043 +
91044 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
91045 + return true;
91046 +
91047 + return subset == superset;
91048 +}
91049 +
91050 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
91051 +{
91052 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
91053 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
91054 +
91055 + return op;
91056 +}
91057 +
91058 +static void register_checker_address_spaces(void *event_data, void *data)
91059 +{
91060 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
91061 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
91062 + c_register_addr_space("__user", ADDR_SPACE_USER);
91063 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
91064 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
91065 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
91066 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
91067 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
91068 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
91069 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
91070 +
91071 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
91072 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
91073 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
91074 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
91075 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
91076 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
91077 + targetm.addr_space.convert = checker_addr_space_convert;
91078 +}
91079 +
91080 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91081 +{
91082 + const char * const plugin_name = plugin_info->base_name;
91083 + const int argc = plugin_info->argc;
91084 + const struct plugin_argument * const argv = plugin_info->argv;
91085 + int i;
91086 +
91087 + if (!plugin_default_version_check(version, &gcc_version)) {
91088 + error(G_("incompatible gcc/plugin versions"));
91089 + return 1;
91090 + }
91091 +
91092 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
91093 +
91094 + for (i = 0; i < argc; ++i)
91095 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
91096 +
91097 + if (TARGET_64BIT == 0)
91098 + return 0;
91099 +
91100 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
91101 +
91102 + return 0;
91103 +}
91104 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
91105 new file mode 100644
91106 index 0000000..414fe5e
91107 --- /dev/null
91108 +++ b/tools/gcc/colorize_plugin.c
91109 @@ -0,0 +1,151 @@
91110 +/*
91111 + * Copyright 2012-2013 by PaX Team <pageexec@freemail.hu>
91112 + * Licensed under the GPL v2
91113 + *
91114 + * Note: the choice of the license means that the compilation process is
91115 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
91116 + * but for the kernel it doesn't matter since it doesn't link against
91117 + * any of the gcc libraries
91118 + *
91119 + * gcc plugin to colorize diagnostic output
91120 + *
91121 + */
91122 +
91123 +#include "gcc-plugin.h"
91124 +#include "config.h"
91125 +#include "system.h"
91126 +#include "coretypes.h"
91127 +#include "tree.h"
91128 +#include "tree-pass.h"
91129 +#include "flags.h"
91130 +#include "intl.h"
91131 +#include "toplev.h"
91132 +#include "plugin.h"
91133 +#include "diagnostic.h"
91134 +#include "plugin-version.h"
91135 +#include "tm.h"
91136 +
91137 +int plugin_is_GPL_compatible;
91138 +
91139 +static struct plugin_info colorize_plugin_info = {
91140 + .version = "201302112000",
91141 + .help = NULL,
91142 +};
91143 +
91144 +#define GREEN "\033[32m\033[2m"
91145 +#define LIGHTGREEN "\033[32m\033[1m"
91146 +#define YELLOW "\033[33m\033[2m"
91147 +#define LIGHTYELLOW "\033[33m\033[1m"
91148 +#define RED "\033[31m\033[2m"
91149 +#define LIGHTRED "\033[31m\033[1m"
91150 +#define BLUE "\033[34m\033[2m"
91151 +#define LIGHTBLUE "\033[34m\033[1m"
91152 +#define BRIGHT "\033[m\033[1m"
91153 +#define NORMAL "\033[m"
91154 +
91155 +static diagnostic_starter_fn old_starter;
91156 +static diagnostic_finalizer_fn old_finalizer;
91157 +
91158 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
91159 +{
91160 + const char *color;
91161 + char *newprefix;
91162 +
91163 + switch (diagnostic->kind) {
91164 + case DK_NOTE:
91165 + color = LIGHTBLUE;
91166 + break;
91167 +
91168 + case DK_PEDWARN:
91169 + case DK_WARNING:
91170 + color = LIGHTYELLOW;
91171 + break;
91172 +
91173 + case DK_ERROR:
91174 + case DK_FATAL:
91175 + case DK_ICE:
91176 + case DK_PERMERROR:
91177 + case DK_SORRY:
91178 + color = LIGHTRED;
91179 + break;
91180 +
91181 + default:
91182 + color = NORMAL;
91183 + }
91184 +
91185 + old_starter(context, diagnostic);
91186 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
91187 + return;
91188 + pp_destroy_prefix(context->printer);
91189 + pp_set_prefix(context->printer, newprefix);
91190 +}
91191 +
91192 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
91193 +{
91194 + old_finalizer(context, diagnostic);
91195 +}
91196 +
91197 +static void colorize_arm(void)
91198 +{
91199 + old_starter = diagnostic_starter(global_dc);
91200 + old_finalizer = diagnostic_finalizer(global_dc);
91201 +
91202 + diagnostic_starter(global_dc) = start_colorize;
91203 + diagnostic_finalizer(global_dc) = finalize_colorize;
91204 +}
91205 +
91206 +static unsigned int execute_colorize_rearm(void)
91207 +{
91208 + if (diagnostic_starter(global_dc) == start_colorize)
91209 + return 0;
91210 +
91211 + colorize_arm();
91212 + return 0;
91213 +}
91214 +
91215 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
91216 + .pass = {
91217 + .type = SIMPLE_IPA_PASS,
91218 + .name = "colorize_rearm",
91219 +#if BUILDING_GCC_VERSION >= 4008
91220 + .optinfo_flags = OPTGROUP_NONE,
91221 +#endif
91222 + .gate = NULL,
91223 + .execute = execute_colorize_rearm,
91224 + .sub = NULL,
91225 + .next = NULL,
91226 + .static_pass_number = 0,
91227 + .tv_id = TV_NONE,
91228 + .properties_required = 0,
91229 + .properties_provided = 0,
91230 + .properties_destroyed = 0,
91231 + .todo_flags_start = 0,
91232 + .todo_flags_finish = 0
91233 + }
91234 +};
91235 +
91236 +static void colorize_start_unit(void *gcc_data, void *user_data)
91237 +{
91238 + colorize_arm();
91239 +}
91240 +
91241 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91242 +{
91243 + const char * const plugin_name = plugin_info->base_name;
91244 + struct register_pass_info colorize_rearm_pass_info = {
91245 + .pass = &pass_ipa_colorize_rearm.pass,
91246 + .reference_pass_name = "*free_lang_data",
91247 + .ref_pass_instance_number = 1,
91248 + .pos_op = PASS_POS_INSERT_AFTER
91249 + };
91250 +
91251 + if (!plugin_default_version_check(version, &gcc_version)) {
91252 + error(G_("incompatible gcc/plugin versions"));
91253 + return 1;
91254 + }
91255 +
91256 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
91257 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
91258 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
91259 + return 0;
91260 +}
91261 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
91262 new file mode 100644
91263 index 0000000..43e86d6
91264 --- /dev/null
91265 +++ b/tools/gcc/constify_plugin.c
91266 @@ -0,0 +1,512 @@
91267 +/*
91268 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
91269 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
91270 + * Licensed under the GPL v2, or (at your option) v3
91271 + *
91272 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
91273 + *
91274 + * Homepage:
91275 + * http://www.grsecurity.net/~ephox/const_plugin/
91276 + *
91277 + * Usage:
91278 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
91279 + * $ gcc -fplugin=constify_plugin.so test.c -O2
91280 + */
91281 +
91282 +#include "gcc-plugin.h"
91283 +#include "config.h"
91284 +#include "system.h"
91285 +#include "coretypes.h"
91286 +#include "tree.h"
91287 +#include "tree-pass.h"
91288 +#include "flags.h"
91289 +#include "intl.h"
91290 +#include "toplev.h"
91291 +#include "plugin.h"
91292 +#include "diagnostic.h"
91293 +#include "plugin-version.h"
91294 +#include "tm.h"
91295 +#include "function.h"
91296 +#include "basic-block.h"
91297 +#include "gimple.h"
91298 +#include "rtl.h"
91299 +#include "emit-rtl.h"
91300 +#include "tree-flow.h"
91301 +#include "target.h"
91302 +
91303 +// should come from c-tree.h if only it were installed for gcc 4.5...
91304 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
91305 +
91306 +// unused type flag in all versions 4.5-4.8
91307 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
91308 +
91309 +int plugin_is_GPL_compatible;
91310 +
91311 +static struct plugin_info const_plugin_info = {
91312 + .version = "201303070020",
91313 + .help = "no-constify\tturn off constification\n",
91314 +};
91315 +
91316 +typedef struct {
91317 + bool has_fptr_field;
91318 + bool has_writable_field;
91319 + bool has_do_const_field;
91320 + bool has_no_const_field;
91321 +} constify_info;
91322 +
91323 +static const_tree get_field_type(const_tree field)
91324 +{
91325 + return strip_array_types(TREE_TYPE(field));
91326 +}
91327 +
91328 +static bool is_fptr(const_tree field)
91329 +{
91330 + const_tree ptr = get_field_type(field);
91331 +
91332 + if (TREE_CODE(ptr) != POINTER_TYPE)
91333 + return false;
91334 +
91335 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
91336 +}
91337 +
91338 +/*
91339 + * determine whether the given structure type meets the requirements for automatic constification,
91340 + * including the constification attributes on nested structure types
91341 + */
91342 +static void constifiable(const_tree node, constify_info *cinfo)
91343 +{
91344 + const_tree field;
91345 +
91346 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
91347 +
91348 + // e.g., pointer to structure fields while still constructing the structure type
91349 + if (TYPE_FIELDS(node) == NULL_TREE)
91350 + return;
91351 +
91352 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
91353 + const_tree type = get_field_type(field);
91354 + enum tree_code code = TREE_CODE(type);
91355 +
91356 + if (node == type)
91357 + continue;
91358 +
91359 + if (is_fptr(field))
91360 + cinfo->has_fptr_field = true;
91361 + else if (!TREE_READONLY(field))
91362 + cinfo->has_writable_field = true;
91363 +
91364 + if (code == RECORD_TYPE || code == UNION_TYPE) {
91365 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91366 + cinfo->has_do_const_field = true;
91367 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
91368 + cinfo->has_no_const_field = true;
91369 + else
91370 + constifiable(type, cinfo);
91371 + }
91372 + }
91373 +}
91374 +
91375 +static bool constified(const_tree node)
91376 +{
91377 + constify_info cinfo = {
91378 + .has_fptr_field = false,
91379 + .has_writable_field = false,
91380 + .has_do_const_field = false,
91381 + .has_no_const_field = false
91382 + };
91383 +
91384 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
91385 +
91386 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
91387 + gcc_assert(!TYPE_READONLY(node));
91388 + return false;
91389 + }
91390 +
91391 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
91392 + gcc_assert(TYPE_READONLY(node));
91393 + return true;
91394 + }
91395 +
91396 + constifiable(node, &cinfo);
91397 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
91398 + return false;
91399 +
91400 + return TYPE_READONLY(node);
91401 +}
91402 +
91403 +static void deconstify_tree(tree node);
91404 +
91405 +static void deconstify_type(tree type)
91406 +{
91407 + tree field;
91408 +
91409 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
91410 +
91411 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
91412 + const_tree fieldtype = get_field_type(field);
91413 +
91414 + // special case handling of simple ptr-to-same-array-type members
91415 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
91416 + const_tree ptrtype = TREE_TYPE(TREE_TYPE(field));
91417 +
91418 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
91419 + continue;
91420 + if (TREE_TYPE(TREE_TYPE(field)) == type)
91421 + continue;
91422 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
91423 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
91424 + TREE_TYPE(TREE_TYPE(field)) = type;
91425 + }
91426 + continue;
91427 + }
91428 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
91429 + continue;
91430 + if (!constified(fieldtype))
91431 + continue;
91432 +
91433 + deconstify_tree(field);
91434 + TREE_READONLY(field) = 0;
91435 + }
91436 + TYPE_READONLY(type) = 0;
91437 + C_TYPE_FIELDS_READONLY(type) = 0;
91438 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91439 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
91440 +}
91441 +
91442 +static void deconstify_tree(tree node)
91443 +{
91444 + tree old_type, new_type, field;
91445 +
91446 + old_type = TREE_TYPE(node);
91447 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
91448 + node = TREE_TYPE(node) = copy_node(old_type);
91449 + old_type = TREE_TYPE(old_type);
91450 + }
91451 +
91452 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
91453 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
91454 +
91455 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
91456 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
91457 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
91458 + DECL_FIELD_CONTEXT(field) = new_type;
91459 +
91460 + deconstify_type(new_type);
91461 +
91462 + TREE_TYPE(node) = new_type;
91463 +}
91464 +
91465 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
91466 +{
91467 + tree type;
91468 + constify_info cinfo = {
91469 + .has_fptr_field = false,
91470 + .has_writable_field = false,
91471 + .has_do_const_field = false,
91472 + .has_no_const_field = false
91473 + };
91474 +
91475 + *no_add_attrs = true;
91476 + if (TREE_CODE(*node) == FUNCTION_DECL) {
91477 + error("%qE attribute does not apply to functions", name);
91478 + return NULL_TREE;
91479 + }
91480 +
91481 + if (TREE_CODE(*node) == PARM_DECL) {
91482 + error("%qE attribute does not apply to function parameters", name);
91483 + return NULL_TREE;
91484 + }
91485 +
91486 + if (TREE_CODE(*node) == VAR_DECL) {
91487 + error("%qE attribute does not apply to variables", name);
91488 + return NULL_TREE;
91489 + }
91490 +
91491 + if (TYPE_P(*node)) {
91492 + *no_add_attrs = false;
91493 + type = *node;
91494 + } else {
91495 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
91496 + type = TREE_TYPE(*node);
91497 + }
91498 +
91499 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
91500 + error("%qE attribute applies to struct and union types only", name);
91501 + return NULL_TREE;
91502 + }
91503 +
91504 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
91505 + error("%qE attribute is already applied to the type", name);
91506 + return NULL_TREE;
91507 + }
91508 +
91509 + if (TYPE_P(*node)) {
91510 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91511 + error("%qE attribute is incompatible with 'do_const'", name);
91512 + return NULL_TREE;
91513 + }
91514 +
91515 + constifiable(type, &cinfo);
91516 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
91517 + deconstify_tree(*node);
91518 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
91519 + return NULL_TREE;
91520 + }
91521 +
91522 + error("%qE attribute used on type that is not constified", name);
91523 + return NULL_TREE;
91524 +}
91525 +
91526 +static void constify_type(tree type)
91527 +{
91528 + TYPE_READONLY(type) = 1;
91529 + C_TYPE_FIELDS_READONLY(type) = 1;
91530 + TYPE_CONSTIFY_VISITED(type) = 1;
91531 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
91532 +}
91533 +
91534 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
91535 +{
91536 + *no_add_attrs = true;
91537 + if (!TYPE_P(*node)) {
91538 + error("%qE attribute applies to types only", name);
91539 + return NULL_TREE;
91540 + }
91541 +
91542 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
91543 + error("%qE attribute applies to struct and union types only", name);
91544 + return NULL_TREE;
91545 + }
91546 +
91547 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
91548 + error("%qE attribute is already applied to the type", name);
91549 + return NULL_TREE;
91550 + }
91551 +
91552 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
91553 + error("%qE attribute is incompatible with 'no_const'", name);
91554 + return NULL_TREE;
91555 + }
91556 +
91557 + *no_add_attrs = false;
91558 + return NULL_TREE;
91559 +}
91560 +
91561 +static struct attribute_spec no_const_attr = {
91562 + .name = "no_const",
91563 + .min_length = 0,
91564 + .max_length = 0,
91565 + .decl_required = false,
91566 + .type_required = false,
91567 + .function_type_required = false,
91568 + .handler = handle_no_const_attribute,
91569 +#if BUILDING_GCC_VERSION >= 4007
91570 + .affects_type_identity = true
91571 +#endif
91572 +};
91573 +
91574 +static struct attribute_spec do_const_attr = {
91575 + .name = "do_const",
91576 + .min_length = 0,
91577 + .max_length = 0,
91578 + .decl_required = false,
91579 + .type_required = false,
91580 + .function_type_required = false,
91581 + .handler = handle_do_const_attribute,
91582 +#if BUILDING_GCC_VERSION >= 4007
91583 + .affects_type_identity = true
91584 +#endif
91585 +};
91586 +
91587 +static void register_attributes(void *event_data, void *data)
91588 +{
91589 + register_attribute(&no_const_attr);
91590 + register_attribute(&do_const_attr);
91591 +}
91592 +
91593 +static void finish_type(void *event_data, void *data)
91594 +{
91595 + tree type = (tree)event_data;
91596 + constify_info cinfo = {
91597 + .has_fptr_field = false,
91598 + .has_writable_field = false,
91599 + .has_do_const_field = false,
91600 + .has_no_const_field = false
91601 + };
91602 +
91603 + if (type == NULL_TREE || type == error_mark_node)
91604 + return;
91605 +
91606 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
91607 + return;
91608 +
91609 + constifiable(type, &cinfo);
91610 +
91611 + if (TYPE_READONLY(type) && C_TYPE_FIELDS_READONLY(type)) {
91612 + if (!lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91613 + return;
91614 + if (cinfo.has_writable_field)
91615 + return;
91616 + error("'do_const' attribute used on type that is%sconstified", cinfo.has_fptr_field ? " " : " not ");
91617 + return;
91618 + }
91619 +
91620 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
91621 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
91622 + deconstify_type(type);
91623 + TYPE_CONSTIFY_VISITED(type) = 1;
91624 + } else
91625 + error("'no_const' attribute used on type that is not constified");
91626 + return;
91627 + }
91628 +
91629 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
91630 + constify_type(type);
91631 + return;
91632 + }
91633 +
91634 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
91635 + constify_type(type);
91636 + return;
91637 + }
91638 +
91639 + deconstify_type(type);
91640 + TYPE_CONSTIFY_VISITED(type) = 1;
91641 +}
91642 +
91643 +static unsigned int check_local_variables(void)
91644 +{
91645 + unsigned int ret = 0;
91646 + tree var;
91647 +
91648 +#if BUILDING_GCC_VERSION == 4005
91649 + tree vars;
91650 +#else
91651 + unsigned int i;
91652 +#endif
91653 +
91654 +#if BUILDING_GCC_VERSION == 4005
91655 + for (vars = cfun->local_decls; vars; vars = TREE_CHAIN(vars)) {
91656 + var = TREE_VALUE(vars);
91657 +#else
91658 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
91659 +#endif
91660 + tree type = TREE_TYPE(var);
91661 +
91662 + gcc_assert(DECL_P(var));
91663 + if (is_global_var(var))
91664 + continue;
91665 +
91666 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
91667 + continue;
91668 +
91669 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
91670 + continue;
91671 +
91672 + if (!TYPE_CONSTIFY_VISITED(type))
91673 + continue;
91674 +
91675 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
91676 + ret = 1;
91677 + }
91678 + return ret;
91679 +}
91680 +
91681 +static struct gimple_opt_pass pass_local_variable = {
91682 + {
91683 + .type = GIMPLE_PASS,
91684 + .name = "check_local_variables",
91685 +#if BUILDING_GCC_VERSION >= 4008
91686 + .optinfo_flags = OPTGROUP_NONE,
91687 +#endif
91688 + .gate = NULL,
91689 + .execute = check_local_variables,
91690 + .sub = NULL,
91691 + .next = NULL,
91692 + .static_pass_number = 0,
91693 + .tv_id = TV_NONE,
91694 + .properties_required = 0,
91695 + .properties_provided = 0,
91696 + .properties_destroyed = 0,
91697 + .todo_flags_start = 0,
91698 + .todo_flags_finish = 0
91699 + }
91700 +};
91701 +
91702 +static struct {
91703 + const char *name;
91704 + const char *asm_op;
91705 +} sections[] = {
91706 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
91707 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
91708 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
91709 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
91710 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
91711 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
91712 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
91713 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
91714 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
91715 +};
91716 +
91717 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
91718 +
91719 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
91720 +{
91721 + size_t i;
91722 +
91723 + for (i = 0; i < ARRAY_SIZE(sections); i++)
91724 + if (!strcmp(sections[i].name, name))
91725 + return 0;
91726 + return old_section_type_flags(decl, name, reloc);
91727 +}
91728 +
91729 +static void constify_start_unit(void *gcc_data, void *user_data)
91730 +{
91731 +// size_t i;
91732 +
91733 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
91734 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
91735 +// sections[i].section = get_section(sections[i].name, 0, NULL);
91736 +
91737 + old_section_type_flags = targetm.section_type_flags;
91738 + targetm.section_type_flags = constify_section_type_flags;
91739 +}
91740 +
91741 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91742 +{
91743 + const char * const plugin_name = plugin_info->base_name;
91744 + const int argc = plugin_info->argc;
91745 + const struct plugin_argument * const argv = plugin_info->argv;
91746 + int i;
91747 + bool constify = true;
91748 +
91749 + struct register_pass_info local_variable_pass_info = {
91750 + .pass = &pass_local_variable.pass,
91751 + .reference_pass_name = "ssa",
91752 + .ref_pass_instance_number = 1,
91753 + .pos_op = PASS_POS_INSERT_BEFORE
91754 + };
91755 +
91756 + if (!plugin_default_version_check(version, &gcc_version)) {
91757 + error(G_("incompatible gcc/plugin versions"));
91758 + return 1;
91759 + }
91760 +
91761 + for (i = 0; i < argc; ++i) {
91762 + if (!(strcmp(argv[i].key, "no-constify"))) {
91763 + constify = false;
91764 + continue;
91765 + }
91766 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
91767 + }
91768 +
91769 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
91770 + if (constify) {
91771 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
91772 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
91773 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
91774 + }
91775 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
91776 +
91777 + return 0;
91778 +}
91779 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
91780 new file mode 100644
91781 index 0000000..e518932
91782 --- /dev/null
91783 +++ b/tools/gcc/generate_size_overflow_hash.sh
91784 @@ -0,0 +1,94 @@
91785 +#!/bin/bash
91786 +
91787 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
91788 +
91789 +header1="size_overflow_hash.h"
91790 +database="size_overflow_hash.data"
91791 +n=65536
91792 +
91793 +usage() {
91794 +cat <<EOF
91795 +usage: $0 options
91796 +OPTIONS:
91797 + -h|--help help
91798 + -o header file
91799 + -d database file
91800 + -n hash array size
91801 +EOF
91802 + return 0
91803 +}
91804 +
91805 +while true
91806 +do
91807 + case "$1" in
91808 + -h|--help) usage && exit 0;;
91809 + -n) n=$2; shift 2;;
91810 + -o) header1="$2"; shift 2;;
91811 + -d) database="$2"; shift 2;;
91812 + --) shift 1; break ;;
91813 + *) break ;;
91814 + esac
91815 +done
91816 +
91817 +create_defines() {
91818 + for i in `seq 0 31`
91819 + do
91820 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
91821 + done
91822 + echo >> "$header1"
91823 +}
91824 +
91825 +create_structs() {
91826 + rm -f "$header1"
91827 +
91828 + create_defines
91829 +
91830 + cat "$database" | while read data
91831 + do
91832 + data_array=($data)
91833 + struct_hash_name="${data_array[0]}"
91834 + funcn="${data_array[1]}"
91835 + params="${data_array[2]}"
91836 + next="${data_array[4]}"
91837 +
91838 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
91839 +
91840 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
91841 + echo -en "\t.param\t= " >> "$header1"
91842 + line=
91843 + for param_num in ${params//-/ };
91844 + do
91845 + line="${line}PARAM"$param_num"|"
91846 + done
91847 +
91848 + echo -e "${line%?},\n};\n" >> "$header1"
91849 + done
91850 +}
91851 +
91852 +create_headers() {
91853 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
91854 +}
91855 +
91856 +create_array_elements() {
91857 + index=0
91858 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
91859 + do
91860 + data_array=($data)
91861 + i="${data_array[3]}"
91862 + hash="${data_array[0]}"
91863 + while [[ $index -lt $i ]]
91864 + do
91865 + echo -e "\t["$index"]\t= NULL," >> "$header1"
91866 + index=$(($index + 1))
91867 + done
91868 + index=$(($index + 1))
91869 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
91870 + done
91871 + echo '};' >> $header1
91872 +}
91873 +
91874 +create_structs
91875 +create_headers
91876 +create_array_elements
91877 +
91878 +exit 0
91879 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
91880 new file mode 100644
91881 index 0000000..568b360
91882 --- /dev/null
91883 +++ b/tools/gcc/kallocstat_plugin.c
91884 @@ -0,0 +1,170 @@
91885 +/*
91886 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
91887 + * Licensed under the GPL v2
91888 + *
91889 + * Note: the choice of the license means that the compilation process is
91890 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
91891 + * but for the kernel it doesn't matter since it doesn't link against
91892 + * any of the gcc libraries
91893 + *
91894 + * gcc plugin to find the distribution of k*alloc sizes
91895 + *
91896 + * TODO:
91897 + *
91898 + * BUGS:
91899 + * - none known
91900 + */
91901 +#include "gcc-plugin.h"
91902 +#include "config.h"
91903 +#include "system.h"
91904 +#include "coretypes.h"
91905 +#include "tree.h"
91906 +#include "tree-pass.h"
91907 +#include "flags.h"
91908 +#include "intl.h"
91909 +#include "toplev.h"
91910 +#include "plugin.h"
91911 +//#include "expr.h" where are you...
91912 +#include "diagnostic.h"
91913 +#include "plugin-version.h"
91914 +#include "tm.h"
91915 +#include "function.h"
91916 +#include "basic-block.h"
91917 +#include "gimple.h"
91918 +#include "rtl.h"
91919 +#include "emit-rtl.h"
91920 +
91921 +extern void print_gimple_stmt(FILE *, gimple, int, int);
91922 +
91923 +int plugin_is_GPL_compatible;
91924 +
91925 +static const char * const kalloc_functions[] = {
91926 + "__kmalloc",
91927 + "kmalloc",
91928 + "kmalloc_large",
91929 + "kmalloc_node",
91930 + "kmalloc_order",
91931 + "kmalloc_order_trace",
91932 + "kmalloc_slab",
91933 + "kzalloc",
91934 + "kzalloc_node",
91935 +};
91936 +
91937 +static struct plugin_info kallocstat_plugin_info = {
91938 + .version = "201302112000",
91939 +};
91940 +
91941 +static unsigned int execute_kallocstat(void);
91942 +
91943 +static struct gimple_opt_pass kallocstat_pass = {
91944 + .pass = {
91945 + .type = GIMPLE_PASS,
91946 + .name = "kallocstat",
91947 +#if BUILDING_GCC_VERSION >= 4008
91948 + .optinfo_flags = OPTGROUP_NONE,
91949 +#endif
91950 + .gate = NULL,
91951 + .execute = execute_kallocstat,
91952 + .sub = NULL,
91953 + .next = NULL,
91954 + .static_pass_number = 0,
91955 + .tv_id = TV_NONE,
91956 + .properties_required = 0,
91957 + .properties_provided = 0,
91958 + .properties_destroyed = 0,
91959 + .todo_flags_start = 0,
91960 + .todo_flags_finish = 0
91961 + }
91962 +};
91963 +
91964 +static bool is_kalloc(const char *fnname)
91965 +{
91966 + size_t i;
91967 +
91968 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
91969 + if (!strcmp(fnname, kalloc_functions[i]))
91970 + return true;
91971 + return false;
91972 +}
91973 +
91974 +static unsigned int execute_kallocstat(void)
91975 +{
91976 + basic_block bb;
91977 +
91978 + // 1. loop through BBs and GIMPLE statements
91979 + FOR_EACH_BB(bb) {
91980 + gimple_stmt_iterator gsi;
91981 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
91982 + // gimple match:
91983 + tree fndecl, size;
91984 + gimple call_stmt;
91985 + const char *fnname;
91986 +
91987 + // is it a call
91988 + call_stmt = gsi_stmt(gsi);
91989 + if (!is_gimple_call(call_stmt))
91990 + continue;
91991 + fndecl = gimple_call_fndecl(call_stmt);
91992 + if (fndecl == NULL_TREE)
91993 + continue;
91994 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
91995 + continue;
91996 +
91997 + // is it a call to k*alloc
91998 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
91999 + if (!is_kalloc(fnname))
92000 + continue;
92001 +
92002 + // is the size arg the result of a simple const assignment
92003 + size = gimple_call_arg(call_stmt, 0);
92004 + while (true) {
92005 + gimple def_stmt;
92006 + expanded_location xloc;
92007 + size_t size_val;
92008 +
92009 + if (TREE_CODE(size) != SSA_NAME)
92010 + break;
92011 + def_stmt = SSA_NAME_DEF_STMT(size);
92012 + if (!def_stmt || !is_gimple_assign(def_stmt))
92013 + break;
92014 + if (gimple_num_ops(def_stmt) != 2)
92015 + break;
92016 + size = gimple_assign_rhs1(def_stmt);
92017 + if (!TREE_CONSTANT(size))
92018 + continue;
92019 + xloc = expand_location(gimple_location(def_stmt));
92020 + if (!xloc.file)
92021 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
92022 + size_val = TREE_INT_CST_LOW(size);
92023 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
92024 + break;
92025 + }
92026 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
92027 +//debug_tree(gimple_call_fn(call_stmt));
92028 +//print_node(stderr, "pax", fndecl, 4);
92029 + }
92030 + }
92031 +
92032 + return 0;
92033 +}
92034 +
92035 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92036 +{
92037 + const char * const plugin_name = plugin_info->base_name;
92038 + struct register_pass_info kallocstat_pass_info = {
92039 + .pass = &kallocstat_pass.pass,
92040 + .reference_pass_name = "ssa",
92041 + .ref_pass_instance_number = 1,
92042 + .pos_op = PASS_POS_INSERT_AFTER
92043 + };
92044 +
92045 + if (!plugin_default_version_check(version, &gcc_version)) {
92046 + error(G_("incompatible gcc/plugin versions"));
92047 + return 1;
92048 + }
92049 +
92050 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
92051 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
92052 +
92053 + return 0;
92054 +}
92055 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
92056 new file mode 100644
92057 index 0000000..0408e06
92058 --- /dev/null
92059 +++ b/tools/gcc/kernexec_plugin.c
92060 @@ -0,0 +1,465 @@
92061 +/*
92062 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
92063 + * Licensed under the GPL v2
92064 + *
92065 + * Note: the choice of the license means that the compilation process is
92066 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92067 + * but for the kernel it doesn't matter since it doesn't link against
92068 + * any of the gcc libraries
92069 + *
92070 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
92071 + *
92072 + * TODO:
92073 + *
92074 + * BUGS:
92075 + * - none known
92076 + */
92077 +#include "gcc-plugin.h"
92078 +#include "config.h"
92079 +#include "system.h"
92080 +#include "coretypes.h"
92081 +#include "tree.h"
92082 +#include "tree-pass.h"
92083 +#include "flags.h"
92084 +#include "intl.h"
92085 +#include "toplev.h"
92086 +#include "plugin.h"
92087 +//#include "expr.h" where are you...
92088 +#include "diagnostic.h"
92089 +#include "plugin-version.h"
92090 +#include "tm.h"
92091 +#include "function.h"
92092 +#include "basic-block.h"
92093 +#include "gimple.h"
92094 +#include "rtl.h"
92095 +#include "emit-rtl.h"
92096 +#include "tree-flow.h"
92097 +
92098 +extern void print_gimple_stmt(FILE *, gimple, int, int);
92099 +extern rtx emit_move_insn(rtx x, rtx y);
92100 +
92101 +#if BUILDING_GCC_VERSION <= 4006
92102 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
92103 +#endif
92104 +
92105 +#if BUILDING_GCC_VERSION >= 4008
92106 +#define TODO_dump_func 0
92107 +#endif
92108 +
92109 +int plugin_is_GPL_compatible;
92110 +
92111 +static struct plugin_info kernexec_plugin_info = {
92112 + .version = "201302112000",
92113 + .help = "method=[bts|or]\tinstrumentation method\n"
92114 +};
92115 +
92116 +static unsigned int execute_kernexec_reload(void);
92117 +static unsigned int execute_kernexec_fptr(void);
92118 +static unsigned int execute_kernexec_retaddr(void);
92119 +static bool kernexec_cmodel_check(void);
92120 +
92121 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
92122 +static void (*kernexec_instrument_retaddr)(rtx);
92123 +
92124 +static struct gimple_opt_pass kernexec_reload_pass = {
92125 + .pass = {
92126 + .type = GIMPLE_PASS,
92127 + .name = "kernexec_reload",
92128 +#if BUILDING_GCC_VERSION >= 4008
92129 + .optinfo_flags = OPTGROUP_NONE,
92130 +#endif
92131 + .gate = kernexec_cmodel_check,
92132 + .execute = execute_kernexec_reload,
92133 + .sub = NULL,
92134 + .next = NULL,
92135 + .static_pass_number = 0,
92136 + .tv_id = TV_NONE,
92137 + .properties_required = 0,
92138 + .properties_provided = 0,
92139 + .properties_destroyed = 0,
92140 + .todo_flags_start = 0,
92141 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
92142 + }
92143 +};
92144 +
92145 +static struct gimple_opt_pass kernexec_fptr_pass = {
92146 + .pass = {
92147 + .type = GIMPLE_PASS,
92148 + .name = "kernexec_fptr",
92149 +#if BUILDING_GCC_VERSION >= 4008
92150 + .optinfo_flags = OPTGROUP_NONE,
92151 +#endif
92152 + .gate = kernexec_cmodel_check,
92153 + .execute = execute_kernexec_fptr,
92154 + .sub = NULL,
92155 + .next = NULL,
92156 + .static_pass_number = 0,
92157 + .tv_id = TV_NONE,
92158 + .properties_required = 0,
92159 + .properties_provided = 0,
92160 + .properties_destroyed = 0,
92161 + .todo_flags_start = 0,
92162 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
92163 + }
92164 +};
92165 +
92166 +static struct rtl_opt_pass kernexec_retaddr_pass = {
92167 + .pass = {
92168 + .type = RTL_PASS,
92169 + .name = "kernexec_retaddr",
92170 +#if BUILDING_GCC_VERSION >= 4008
92171 + .optinfo_flags = OPTGROUP_NONE,
92172 +#endif
92173 + .gate = kernexec_cmodel_check,
92174 + .execute = execute_kernexec_retaddr,
92175 + .sub = NULL,
92176 + .next = NULL,
92177 + .static_pass_number = 0,
92178 + .tv_id = TV_NONE,
92179 + .properties_required = 0,
92180 + .properties_provided = 0,
92181 + .properties_destroyed = 0,
92182 + .todo_flags_start = 0,
92183 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
92184 + }
92185 +};
92186 +
92187 +static bool kernexec_cmodel_check(void)
92188 +{
92189 + tree section;
92190 +
92191 + if (ix86_cmodel != CM_KERNEL)
92192 + return false;
92193 +
92194 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
92195 + if (!section || !TREE_VALUE(section))
92196 + return true;
92197 +
92198 + section = TREE_VALUE(TREE_VALUE(section));
92199 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
92200 + return true;
92201 +
92202 + return false;
92203 +}
92204 +
92205 +/*
92206 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
92207 + */
92208 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
92209 +{
92210 + gimple asm_movabs_stmt;
92211 +
92212 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
92213 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
92214 + gimple_asm_set_volatile(asm_movabs_stmt, true);
92215 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
92216 + update_stmt(asm_movabs_stmt);
92217 +}
92218 +
92219 +/*
92220 + * find all asm() stmts that clobber r10 and add a reload of r10
92221 + */
92222 +static unsigned int execute_kernexec_reload(void)
92223 +{
92224 + basic_block bb;
92225 +
92226 + // 1. loop through BBs and GIMPLE statements
92227 + FOR_EACH_BB(bb) {
92228 + gimple_stmt_iterator gsi;
92229 +
92230 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92231 + // gimple match: __asm__ ("" : : : "r10");
92232 + gimple asm_stmt;
92233 + size_t nclobbers;
92234 +
92235 + // is it an asm ...
92236 + asm_stmt = gsi_stmt(gsi);
92237 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
92238 + continue;
92239 +
92240 + // ... clobbering r10
92241 + nclobbers = gimple_asm_nclobbers(asm_stmt);
92242 + while (nclobbers--) {
92243 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
92244 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
92245 + continue;
92246 + kernexec_reload_fptr_mask(&gsi);
92247 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
92248 + break;
92249 + }
92250 + }
92251 + }
92252 +
92253 + return 0;
92254 +}
92255 +
92256 +/*
92257 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
92258 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
92259 + */
92260 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
92261 +{
92262 + gimple assign_intptr, assign_new_fptr, call_stmt;
92263 + tree intptr, old_fptr, new_fptr, kernexec_mask;
92264 +
92265 + call_stmt = gsi_stmt(*gsi);
92266 + old_fptr = gimple_call_fn(call_stmt);
92267 +
92268 + // create temporary unsigned long variable used for bitops and cast fptr to it
92269 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
92270 +#if BUILDING_GCC_VERSION <= 4007
92271 + add_referenced_var(intptr);
92272 + mark_sym_for_renaming(intptr);
92273 +#endif
92274 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
92275 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
92276 + update_stmt(assign_intptr);
92277 +
92278 + // apply logical or to temporary unsigned long and bitmask
92279 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
92280 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
92281 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
92282 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
92283 + update_stmt(assign_intptr);
92284 +
92285 + // cast temporary unsigned long back to a temporary fptr variable
92286 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
92287 +#if BUILDING_GCC_VERSION <= 4007
92288 + add_referenced_var(new_fptr);
92289 + mark_sym_for_renaming(new_fptr);
92290 +#endif
92291 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
92292 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
92293 + update_stmt(assign_new_fptr);
92294 +
92295 + // replace call stmt fn with the new fptr
92296 + gimple_call_set_fn(call_stmt, new_fptr);
92297 + update_stmt(call_stmt);
92298 +}
92299 +
92300 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
92301 +{
92302 + gimple asm_or_stmt, call_stmt;
92303 + tree old_fptr, new_fptr, input, output;
92304 +#if BUILDING_GCC_VERSION <= 4007
92305 + VEC(tree, gc) *inputs = NULL;
92306 + VEC(tree, gc) *outputs = NULL;
92307 +#else
92308 + vec<tree, va_gc> *inputs = NULL;
92309 + vec<tree, va_gc> *outputs = NULL;
92310 +#endif
92311 +
92312 + call_stmt = gsi_stmt(*gsi);
92313 + old_fptr = gimple_call_fn(call_stmt);
92314 +
92315 + // create temporary fptr variable
92316 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
92317 +#if BUILDING_GCC_VERSION <= 4007
92318 + add_referenced_var(new_fptr);
92319 + mark_sym_for_renaming(new_fptr);
92320 +#endif
92321 +
92322 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
92323 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
92324 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
92325 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
92326 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
92327 +#if BUILDING_GCC_VERSION <= 4007
92328 + VEC_safe_push(tree, gc, inputs, input);
92329 + VEC_safe_push(tree, gc, outputs, output);
92330 +#else
92331 + vec_safe_push(inputs, input);
92332 + vec_safe_push(outputs, output);
92333 +#endif
92334 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
92335 + gimple_asm_set_volatile(asm_or_stmt, true);
92336 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
92337 + update_stmt(asm_or_stmt);
92338 +
92339 + // replace call stmt fn with the new fptr
92340 + gimple_call_set_fn(call_stmt, new_fptr);
92341 + update_stmt(call_stmt);
92342 +}
92343 +
92344 +/*
92345 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
92346 + */
92347 +static unsigned int execute_kernexec_fptr(void)
92348 +{
92349 + basic_block bb;
92350 +
92351 + // 1. loop through BBs and GIMPLE statements
92352 + FOR_EACH_BB(bb) {
92353 + gimple_stmt_iterator gsi;
92354 +
92355 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92356 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
92357 + tree fn;
92358 + gimple call_stmt;
92359 +
92360 + // is it a call ...
92361 + call_stmt = gsi_stmt(gsi);
92362 + if (!is_gimple_call(call_stmt))
92363 + continue;
92364 + fn = gimple_call_fn(call_stmt);
92365 + if (TREE_CODE(fn) == ADDR_EXPR)
92366 + continue;
92367 + if (TREE_CODE(fn) != SSA_NAME)
92368 + gcc_unreachable();
92369 +
92370 + // ... through a function pointer
92371 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
92372 + fn = SSA_NAME_VAR(fn);
92373 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
92374 + debug_tree(fn);
92375 + gcc_unreachable();
92376 + }
92377 + }
92378 + fn = TREE_TYPE(fn);
92379 + if (TREE_CODE(fn) != POINTER_TYPE)
92380 + continue;
92381 + fn = TREE_TYPE(fn);
92382 + if (TREE_CODE(fn) != FUNCTION_TYPE)
92383 + continue;
92384 +
92385 + kernexec_instrument_fptr(&gsi);
92386 +
92387 +//debug_tree(gimple_call_fn(call_stmt));
92388 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
92389 + }
92390 + }
92391 +
92392 + return 0;
92393 +}
92394 +
92395 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
92396 +static void kernexec_instrument_retaddr_bts(rtx insn)
92397 +{
92398 + rtx btsq;
92399 + rtvec argvec, constraintvec, labelvec;
92400 + int line;
92401 +
92402 + // create asm volatile("btsq $63,(%%rsp)":::)
92403 + argvec = rtvec_alloc(0);
92404 + constraintvec = rtvec_alloc(0);
92405 + labelvec = rtvec_alloc(0);
92406 + line = expand_location(RTL_LOCATION(insn)).line;
92407 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
92408 + MEM_VOLATILE_P(btsq) = 1;
92409 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
92410 + emit_insn_before(btsq, insn);
92411 +}
92412 +
92413 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
92414 +static void kernexec_instrument_retaddr_or(rtx insn)
92415 +{
92416 + rtx orq;
92417 + rtvec argvec, constraintvec, labelvec;
92418 + int line;
92419 +
92420 + // create asm volatile("orq %%r10,(%%rsp)":::)
92421 + argvec = rtvec_alloc(0);
92422 + constraintvec = rtvec_alloc(0);
92423 + labelvec = rtvec_alloc(0);
92424 + line = expand_location(RTL_LOCATION(insn)).line;
92425 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
92426 + MEM_VOLATILE_P(orq) = 1;
92427 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
92428 + emit_insn_before(orq, insn);
92429 +}
92430 +
92431 +/*
92432 + * find all asm level function returns and forcibly set the highest bit of the return address
92433 + */
92434 +static unsigned int execute_kernexec_retaddr(void)
92435 +{
92436 + rtx insn;
92437 +
92438 + // 1. find function returns
92439 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
92440 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
92441 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
92442 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
92443 + rtx body;
92444 +
92445 + // is it a retn
92446 + if (!JUMP_P(insn))
92447 + continue;
92448 + body = PATTERN(insn);
92449 + if (GET_CODE(body) == PARALLEL)
92450 + body = XVECEXP(body, 0, 0);
92451 + if (!ANY_RETURN_P(body))
92452 + continue;
92453 + kernexec_instrument_retaddr(insn);
92454 + }
92455 +
92456 +// print_simple_rtl(stderr, get_insns());
92457 +// print_rtl(stderr, get_insns());
92458 +
92459 + return 0;
92460 +}
92461 +
92462 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92463 +{
92464 + const char * const plugin_name = plugin_info->base_name;
92465 + const int argc = plugin_info->argc;
92466 + const struct plugin_argument * const argv = plugin_info->argv;
92467 + int i;
92468 + struct register_pass_info kernexec_reload_pass_info = {
92469 + .pass = &kernexec_reload_pass.pass,
92470 + .reference_pass_name = "ssa",
92471 + .ref_pass_instance_number = 1,
92472 + .pos_op = PASS_POS_INSERT_AFTER
92473 + };
92474 + struct register_pass_info kernexec_fptr_pass_info = {
92475 + .pass = &kernexec_fptr_pass.pass,
92476 + .reference_pass_name = "ssa",
92477 + .ref_pass_instance_number = 1,
92478 + .pos_op = PASS_POS_INSERT_AFTER
92479 + };
92480 + struct register_pass_info kernexec_retaddr_pass_info = {
92481 + .pass = &kernexec_retaddr_pass.pass,
92482 + .reference_pass_name = "pro_and_epilogue",
92483 + .ref_pass_instance_number = 1,
92484 + .pos_op = PASS_POS_INSERT_AFTER
92485 + };
92486 +
92487 + if (!plugin_default_version_check(version, &gcc_version)) {
92488 + error(G_("incompatible gcc/plugin versions"));
92489 + return 1;
92490 + }
92491 +
92492 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
92493 +
92494 + if (TARGET_64BIT == 0)
92495 + return 0;
92496 +
92497 + for (i = 0; i < argc; ++i) {
92498 + if (!strcmp(argv[i].key, "method")) {
92499 + if (!argv[i].value) {
92500 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92501 + continue;
92502 + }
92503 + if (!strcmp(argv[i].value, "bts")) {
92504 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
92505 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
92506 + } else if (!strcmp(argv[i].value, "or")) {
92507 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
92508 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
92509 + fix_register("r10", 1, 1);
92510 + } else
92511 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92512 + continue;
92513 + }
92514 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92515 + }
92516 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
92517 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
92518 +
92519 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
92520 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
92521 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
92522 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
92523 +
92524 + return 0;
92525 +}
92526 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
92527 new file mode 100644
92528 index 0000000..1276616
92529 --- /dev/null
92530 +++ b/tools/gcc/latent_entropy_plugin.c
92531 @@ -0,0 +1,321 @@
92532 +/*
92533 + * Copyright 2012-2013 by the PaX Team <pageexec@freemail.hu>
92534 + * Licensed under the GPL v2
92535 + *
92536 + * Note: the choice of the license means that the compilation process is
92537 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92538 + * but for the kernel it doesn't matter since it doesn't link against
92539 + * any of the gcc libraries
92540 + *
92541 + * gcc plugin to help generate a little bit of entropy from program state,
92542 + * used during boot in the kernel
92543 + *
92544 + * TODO:
92545 + * - add ipa pass to identify not explicitly marked candidate functions
92546 + * - mix in more program state (function arguments/return values, loop variables, etc)
92547 + * - more instrumentation control via attribute parameters
92548 + *
92549 + * BUGS:
92550 + * - LTO needs -flto-partition=none for now
92551 + */
92552 +#include "gcc-plugin.h"
92553 +#include "config.h"
92554 +#include "system.h"
92555 +#include "coretypes.h"
92556 +#include "tree.h"
92557 +#include "tree-pass.h"
92558 +#include "flags.h"
92559 +#include "intl.h"
92560 +#include "toplev.h"
92561 +#include "plugin.h"
92562 +//#include "expr.h" where are you...
92563 +#include "diagnostic.h"
92564 +#include "plugin-version.h"
92565 +#include "tm.h"
92566 +#include "function.h"
92567 +#include "basic-block.h"
92568 +#include "gimple.h"
92569 +#include "rtl.h"
92570 +#include "emit-rtl.h"
92571 +#include "tree-flow.h"
92572 +
92573 +#if BUILDING_GCC_VERSION >= 4008
92574 +#define TODO_dump_func 0
92575 +#endif
92576 +
92577 +int plugin_is_GPL_compatible;
92578 +
92579 +static tree latent_entropy_decl;
92580 +
92581 +static struct plugin_info latent_entropy_plugin_info = {
92582 + .version = "201302112000",
92583 + .help = NULL
92584 +};
92585 +
92586 +static unsigned int execute_latent_entropy(void);
92587 +static bool gate_latent_entropy(void);
92588 +
92589 +static struct gimple_opt_pass latent_entropy_pass = {
92590 + .pass = {
92591 + .type = GIMPLE_PASS,
92592 + .name = "latent_entropy",
92593 +#if BUILDING_GCC_VERSION >= 4008
92594 + .optinfo_flags = OPTGROUP_NONE,
92595 +#endif
92596 + .gate = gate_latent_entropy,
92597 + .execute = execute_latent_entropy,
92598 + .sub = NULL,
92599 + .next = NULL,
92600 + .static_pass_number = 0,
92601 + .tv_id = TV_NONE,
92602 + .properties_required = PROP_gimple_leh | PROP_cfg,
92603 + .properties_provided = 0,
92604 + .properties_destroyed = 0,
92605 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
92606 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
92607 + }
92608 +};
92609 +
92610 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
92611 +{
92612 + if (TREE_CODE(*node) != FUNCTION_DECL) {
92613 + *no_add_attrs = true;
92614 + error("%qE attribute only applies to functions", name);
92615 + }
92616 + return NULL_TREE;
92617 +}
92618 +
92619 +static struct attribute_spec latent_entropy_attr = {
92620 + .name = "latent_entropy",
92621 + .min_length = 0,
92622 + .max_length = 0,
92623 + .decl_required = true,
92624 + .type_required = false,
92625 + .function_type_required = false,
92626 + .handler = handle_latent_entropy_attribute,
92627 +#if BUILDING_GCC_VERSION >= 4007
92628 + .affects_type_identity = false
92629 +#endif
92630 +};
92631 +
92632 +static void register_attributes(void *event_data, void *data)
92633 +{
92634 + register_attribute(&latent_entropy_attr);
92635 +}
92636 +
92637 +static bool gate_latent_entropy(void)
92638 +{
92639 + tree latent_entropy_attr;
92640 +
92641 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
92642 + return latent_entropy_attr != NULL_TREE;
92643 +}
92644 +
92645 +static unsigned HOST_WIDE_INT seed;
92646 +static unsigned HOST_WIDE_INT get_random_const(void)
92647 +{
92648 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
92649 + return seed;
92650 +}
92651 +
92652 +static enum tree_code get_op(tree *rhs)
92653 +{
92654 + static enum tree_code op;
92655 + unsigned HOST_WIDE_INT random_const;
92656 +
92657 + random_const = get_random_const();
92658 +
92659 + switch (op) {
92660 + case BIT_XOR_EXPR:
92661 + op = PLUS_EXPR;
92662 + break;
92663 +
92664 + case PLUS_EXPR:
92665 + if (rhs) {
92666 + op = LROTATE_EXPR;
92667 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
92668 + break;
92669 + }
92670 +
92671 + case LROTATE_EXPR:
92672 + default:
92673 + op = BIT_XOR_EXPR;
92674 + break;
92675 + }
92676 + if (rhs)
92677 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
92678 + return op;
92679 +}
92680 +
92681 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
92682 +{
92683 + gimple_stmt_iterator gsi;
92684 + gimple assign;
92685 + tree addxorrol, rhs;
92686 + enum tree_code op;
92687 +
92688 + op = get_op(&rhs);
92689 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
92690 + assign = gimple_build_assign(local_entropy, addxorrol);
92691 +#if BUILDING_GCC_VERSION <= 4007
92692 + find_referenced_vars_in(assign);
92693 +#endif
92694 +//debug_bb(bb);
92695 + gsi = gsi_after_labels(bb);
92696 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
92697 + update_stmt(assign);
92698 +}
92699 +
92700 +static void perturb_latent_entropy(basic_block bb, tree rhs)
92701 +{
92702 + gimple_stmt_iterator gsi;
92703 + gimple assign;
92704 + tree addxorrol, temp;
92705 +
92706 + // 1. create temporary copy of latent_entropy
92707 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
92708 +#if BUILDING_GCC_VERSION <= 4007
92709 + add_referenced_var(temp);
92710 + mark_sym_for_renaming(temp);
92711 +#endif
92712 +
92713 + // 2. read...
92714 + assign = gimple_build_assign(temp, latent_entropy_decl);
92715 +#if BUILDING_GCC_VERSION <= 4007
92716 + find_referenced_vars_in(assign);
92717 +#endif
92718 + gsi = gsi_after_labels(bb);
92719 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
92720 + update_stmt(assign);
92721 +
92722 + // 3. ...modify...
92723 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
92724 + assign = gimple_build_assign(temp, addxorrol);
92725 +#if BUILDING_GCC_VERSION <= 4007
92726 + find_referenced_vars_in(assign);
92727 +#endif
92728 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
92729 + update_stmt(assign);
92730 +
92731 + // 4. ...write latent_entropy
92732 + assign = gimple_build_assign(latent_entropy_decl, temp);
92733 +#if BUILDING_GCC_VERSION <= 4007
92734 + find_referenced_vars_in(assign);
92735 +#endif
92736 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
92737 + update_stmt(assign);
92738 +}
92739 +
92740 +static unsigned int execute_latent_entropy(void)
92741 +{
92742 + basic_block bb;
92743 + gimple assign;
92744 + gimple_stmt_iterator gsi;
92745 + tree local_entropy;
92746 +
92747 + if (!latent_entropy_decl) {
92748 + struct varpool_node *node;
92749 +
92750 +#if BUILDING_GCC_VERSION <= 4007
92751 + for (node = varpool_nodes; node; node = node->next) {
92752 + tree var = node->decl;
92753 +#else
92754 + FOR_EACH_VARIABLE(node) {
92755 + tree var = node->symbol.decl;
92756 +#endif
92757 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
92758 + continue;
92759 + latent_entropy_decl = var;
92760 +// debug_tree(var);
92761 + break;
92762 + }
92763 + if (!latent_entropy_decl) {
92764 +// debug_tree(current_function_decl);
92765 + return 0;
92766 + }
92767 + }
92768 +
92769 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
92770 +
92771 + // 1. create local entropy variable
92772 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
92773 +#if BUILDING_GCC_VERSION <= 4007
92774 + add_referenced_var(local_entropy);
92775 + mark_sym_for_renaming(local_entropy);
92776 +#endif
92777 +
92778 + // 2. initialize local entropy variable
92779 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
92780 + if (dom_info_available_p(CDI_DOMINATORS))
92781 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
92782 + gsi = gsi_start_bb(bb);
92783 +
92784 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
92785 +// gimple_set_location(assign, loc);
92786 +#if BUILDING_GCC_VERSION <= 4007
92787 + find_referenced_vars_in(assign);
92788 +#endif
92789 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
92790 + update_stmt(assign);
92791 + bb = bb->next_bb;
92792 +
92793 + // 3. instrument each BB with an operation on the local entropy variable
92794 + while (bb != EXIT_BLOCK_PTR) {
92795 + perturb_local_entropy(bb, local_entropy);
92796 + bb = bb->next_bb;
92797 + };
92798 +
92799 + // 4. mix local entropy into the global entropy variable
92800 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
92801 + return 0;
92802 +}
92803 +
92804 +static void start_unit_callback(void *gcc_data, void *user_data)
92805 +{
92806 +#if BUILDING_GCC_VERSION >= 4007
92807 + seed = get_random_seed(false);
92808 +#else
92809 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
92810 + seed *= seed;
92811 +#endif
92812 +
92813 + if (in_lto_p)
92814 + return;
92815 +
92816 + // extern u64 latent_entropy
92817 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
92818 +
92819 + TREE_STATIC(latent_entropy_decl) = 1;
92820 + TREE_PUBLIC(latent_entropy_decl) = 1;
92821 + TREE_USED(latent_entropy_decl) = 1;
92822 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
92823 + DECL_EXTERNAL(latent_entropy_decl) = 1;
92824 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
92825 + DECL_INITIAL(latent_entropy_decl) = NULL;
92826 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
92827 +// varpool_finalize_decl(latent_entropy_decl);
92828 +// varpool_mark_needed_node(latent_entropy_decl);
92829 +}
92830 +
92831 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92832 +{
92833 + const char * const plugin_name = plugin_info->base_name;
92834 + struct register_pass_info latent_entropy_pass_info = {
92835 + .pass = &latent_entropy_pass.pass,
92836 + .reference_pass_name = "optimized",
92837 + .ref_pass_instance_number = 1,
92838 + .pos_op = PASS_POS_INSERT_BEFORE
92839 + };
92840 +
92841 + if (!plugin_default_version_check(version, &gcc_version)) {
92842 + error(G_("incompatible gcc/plugin versions"));
92843 + return 1;
92844 + }
92845 +
92846 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
92847 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
92848 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
92849 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
92850 +
92851 + return 0;
92852 +}
92853 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
92854 new file mode 100644
92855 index 0000000..5921fd7
92856 --- /dev/null
92857 +++ b/tools/gcc/size_overflow_hash.data
92858 @@ -0,0 +1,3713 @@
92859 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
92860 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
92861 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
92862 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
92863 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
92864 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
92865 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
92866 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
92867 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
92868 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
92869 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
92870 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
92871 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
92872 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
92873 +create_log_8225 create_log 2 8225 NULL
92874 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
92875 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
92876 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
92877 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
92878 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
92879 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
92880 +padzero_55 padzero 1 55 &sel_read_policyvers_55
92881 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
92882 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
92883 +read_file_blob_57406 read_file_blob 3 57406 NULL
92884 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
92885 +enclosure_register_57412 enclosure_register 3 57412 NULL
92886 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
92887 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
92888 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
92889 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
92890 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
92891 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
92892 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
92893 +init_cdev_8274 init_cdev 1 8274 NULL
92894 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
92895 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
92896 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
92897 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
92898 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
92899 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
92900 +load_msg_95 load_msg 2 95 NULL
92901 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
92902 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
92903 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
92904 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
92905 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
92906 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
92907 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
92908 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
92909 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
92910 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
92911 +send_midi_async_57463 send_midi_async 3 57463 NULL
92912 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
92913 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
92914 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
92915 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
92916 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
92917 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
92918 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
92919 +init_q_132 init_q 4 132 NULL
92920 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
92921 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
92922 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
92923 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
92924 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
92925 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
92926 +uio_read_49300 uio_read 3 49300 NULL
92927 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
92928 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
92929 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
92930 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
92931 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
92932 +play_iframe_8219 play_iframe 3 8219 NULL
92933 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
92934 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
92935 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
92936 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
92937 +init_tag_map_57515 init_tag_map 3 57515 NULL
92938 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
92939 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
92940 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
92941 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
92942 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
92943 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
92944 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
92945 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
92946 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
92947 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
92948 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
92949 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
92950 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
92951 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
92952 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
92953 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
92954 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
92955 +cache_read_24790 cache_read 3 24790 NULL
92956 +px_raw_event_49371 px_raw_event 4 49371 NULL
92957 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
92958 +compat_filldir_32999 compat_filldir 3 32999 NULL
92959 +hci_si_event_1404 hci_si_event 3 1404 NULL
92960 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
92961 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
92962 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
92963 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
92964 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
92965 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
92966 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
92967 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
92968 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
92969 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
92970 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
92971 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
92972 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
92973 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
92974 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
92975 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
92976 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
92977 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
92978 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
92979 +mem_read_57631 mem_read 3 57631 NULL
92980 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
92981 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
92982 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
92983 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
92984 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
92985 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
92986 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
92987 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
92988 +queues_read_24877 queues_read 3 24877 NULL
92989 +__fprog_create_41263 __fprog_create 2 41263 NULL
92990 +syslog_print_307 syslog_print 2 307 NULL
92991 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
92992 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
92993 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
92994 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
92995 +r3964_write_57662 r3964_write 4 57662 NULL
92996 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
92997 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
92998 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
92999 +alloc_context_41283 alloc_context 1 41283 NULL
93000 +__lgwrite_57669 __lgwrite 4 57669 NULL
93001 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
93002 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
93003 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
93004 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
93005 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
93006 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
93007 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
93008 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
93009 +write_node_33121 write_node 4 33121 NULL
93010 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
93011 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
93012 +profile_remove_8556 profile_remove 3 8556 NULL
93013 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
93014 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
93015 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
93016 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
93017 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
93018 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
93019 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
93020 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
93021 +tower_write_8580 tower_write 3 8580 NULL
93022 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
93023 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
93024 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
93025 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
93026 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
93027 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
93028 +smk_write_access_49561 smk_write_access 3 49561 NULL
93029 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
93030 +kmp_init_41373 kmp_init 2 41373 NULL
93031 +context_alloc_24645 context_alloc 3 24645 NULL
93032 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
93033 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
93034 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
93035 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
93036 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
93037 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
93038 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
93039 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
93040 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
93041 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
93042 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
93043 +pp_read_33210 pp_read 3 33210 NULL
93044 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
93045 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
93046 +ivtv_read_57796 ivtv_read 3 57796 NULL
93047 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
93048 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
93049 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
93050 +heap_init_49617 heap_init 2 49617 NULL
93051 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
93052 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
93053 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
93054 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
93055 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
93056 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
93057 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
93058 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
93059 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
93060 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
93061 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
93062 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
93063 +st_write_16874 st_write 3 16874 NULL
93064 +copy_to_user_57835 copy_to_user 3 57835 NULL
93065 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
93066 +pidlist_resize_496 pidlist_resize 2 496 NULL
93067 +flash_read_57843 flash_read 3 57843 NULL
93068 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
93069 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
93070 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
93071 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
93072 +arcfb_write_8702 arcfb_write 3 8702 NULL
93073 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
93074 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
93075 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
93076 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
93077 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
93078 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
93079 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
93080 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
93081 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
93082 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
93083 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
93084 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
93085 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
93086 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
93087 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
93088 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
93089 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
93090 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
93091 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
93092 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
93093 +devres_alloc_551 devres_alloc 2 551 NULL
93094 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
93095 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
93096 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
93097 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
93098 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
93099 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
93100 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
93101 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
93102 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
93103 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
93104 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
93105 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
93106 +sys_prctl_8766 sys_prctl 4 8766 NULL
93107 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
93108 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
93109 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
93110 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
93111 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
93112 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
93113 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
93114 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
93115 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
93116 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
93117 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
93118 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
93119 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
93120 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
93121 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
93122 +gserial_setup_41558 gserial_setup 2 41558 NULL
93123 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
93124 +rx_57944 rx 4 57944 NULL
93125 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
93126 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
93127 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
93128 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
93129 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
93130 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
93131 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
93132 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
93133 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
93134 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
93135 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
93136 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
93137 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
93138 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
93139 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
93140 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
93141 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
93142 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
93143 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
93144 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
93145 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
93146 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
93147 +a2mp_send_41615 a2mp_send 4 41615 NULL
93148 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
93149 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
93150 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
93151 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
93152 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
93153 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
93154 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
93155 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
93156 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
93157 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
93158 +add_uuid_49831 add_uuid 4 49831 NULL
93159 +send_pages_8872 send_pages 3 8872 NULL
93160 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
93161 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
93162 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
93163 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
93164 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
93165 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
93166 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
93167 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
93168 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
93169 +vfs_writev_25278 vfs_writev 3 25278 NULL
93170 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
93171 +alloc_async_14208 alloc_async 1 14208 NULL
93172 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
93173 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
93174 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
93175 +create_entry_33479 create_entry 2 33479 NULL
93176 +mce_async_out_58056 mce_async_out 3 58056 NULL
93177 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
93178 +sys_preadv_17100 sys_preadv 3 17100 NULL
93179 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
93180 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
93181 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
93182 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
93183 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
93184 +res_counter_read_33499 res_counter_read 4 33499 NULL
93185 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
93186 +cm4040_write_58079 cm4040_write 3 58079 NULL
93187 +fb_read_33506 fb_read 3 33506 NULL
93188 +help_25316 help 5 25316 NULL nohasharray
93189 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
93190 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
93191 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
93192 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
93193 +ddp_set_map_751 ddp_set_map 4 751 NULL
93194 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
93195 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
93196 +dvb_video_write_754 dvb_video_write 3 754 NULL
93197 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
93198 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
93199 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
93200 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
93201 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
93202 +udi_log_event_58105 udi_log_event 3 58105 NULL
93203 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
93204 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
93205 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
93206 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
93207 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
93208 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
93209 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
93210 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
93211 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
93212 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
93213 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
93214 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
93215 +sep_read_17161 sep_read 3 17161 NULL
93216 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
93217 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
93218 +dup_array_33551 dup_array 3 33551 NULL
93219 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
93220 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
93221 +fillonedir_41746 fillonedir 3 41746 NULL
93222 +init_bch_64130 init_bch 1-2 64130 NULL
93223 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
93224 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
93225 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
93226 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
93227 +savemem_58129 savemem 3 58129 NULL
93228 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
93229 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
93230 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
93231 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
93232 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
93233 +if_writecmd_815 if_writecmd 2 815 NULL
93234 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
93235 +read_fifo_826 read_fifo 3 826 NULL
93236 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
93237 +scsi_execute_33596 scsi_execute 5 33596 NULL
93238 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
93239 +ms_rw_17220 ms_rw 3-4 17220 NULL
93240 +read_tree_block_841 read_tree_block 3 841 NULL
93241 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
93242 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
93243 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
93244 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
93245 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
93246 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
93247 +um_idi_read_850 um_idi_read 3 850 NULL
93248 +__module_alloc_50004 __module_alloc 1 50004 NULL
93249 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
93250 +ts_read_44687 ts_read 3 44687 NULL
93251 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
93252 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
93253 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
93254 +provide_user_output_41105 provide_user_output 3 41105 NULL
93255 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
93256 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
93257 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
93258 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
93259 +alloc_ep_17269 alloc_ep 1 17269 NULL
93260 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
93261 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
93262 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
93263 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
93264 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
93265 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
93266 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
93267 +create_queues_9088 create_queues 2-3 9088 NULL
93268 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
93269 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
93270 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
93271 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
93272 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
93273 +read_file_debug_58256 read_file_debug 3 58256 NULL
93274 +skb_pad_17302 skb_pad 2 17302 NULL
93275 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
93276 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
93277 +profile_load_58267 profile_load 3 58267 NULL
93278 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
93279 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
93280 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
93281 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
93282 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
93283 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
93284 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
93285 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
93286 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
93287 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
93288 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
93289 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
93290 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
93291 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
93292 +get_packet_41914 get_packet 3 41914 NULL
93293 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
93294 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
93295 +read_file_slot_50111 read_file_slot 3 50111 NULL
93296 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
93297 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
93298 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
93299 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
93300 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
93301 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
93302 +copy_items_50140 copy_items 6 50140 NULL
93303 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
93304 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
93305 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
93306 +map_addr_56144 map_addr 7 56144 NULL
93307 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
93308 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
93309 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
93310 +portnames_read_41958 portnames_read 3 41958 NULL
93311 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
93312 +hashtab_create_33769 hashtab_create 3 33769 NULL
93313 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
93314 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
93315 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
93316 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
93317 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
93318 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
93319 +odev_update_50169 odev_update 2 50169 NULL
93320 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
93321 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
93322 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
93323 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
93324 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
93325 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
93326 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
93327 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
93328 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
93329 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
93330 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
93331 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
93332 +lguest_map_42008 lguest_map 1-2 42008 NULL
93333 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
93334 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
93335 +pool_allocate_42012 pool_allocate 3 42012 NULL
93336 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
93337 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
93338 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
93339 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
93340 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
93341 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
93342 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
93343 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
93344 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
93345 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
93346 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
93347 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
93348 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
93349 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
93350 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
93351 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
93352 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
93353 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
93354 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
93355 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
93356 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
93357 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
93358 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
93359 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
93360 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
93361 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
93362 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
93363 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
93364 +config_proc_write_33878 config_proc_write 3 33878 NULL
93365 +capabilities_read_58457 capabilities_read 3 58457 NULL
93366 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
93367 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
93368 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
93369 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
93370 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
93371 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
93372 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
93373 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
93374 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
93375 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
93376 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
93377 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
93378 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
93379 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
93380 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
93381 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
93382 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
93383 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
93384 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
93385 +vme_user_write_15587 vme_user_write 3 15587 NULL
93386 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
93387 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
93388 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
93389 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
93390 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
93391 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
93392 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
93393 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
93394 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
93395 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
93396 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
93397 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
93398 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
93399 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
93400 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
93401 +read_9397 read 3 9397 NULL
93402 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
93403 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
93404 +printer_write_60276 printer_write 3 60276 NULL
93405 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
93406 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
93407 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
93408 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
93409 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
93410 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
93411 +osst_execute_17607 osst_execute 7-6 17607 NULL
93412 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
93413 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
93414 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
93415 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
93416 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
93417 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
93418 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
93419 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
93420 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
93421 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
93422 +xip_file_read_58592 xip_file_read 3 58592 NULL
93423 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
93424 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
93425 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
93426 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
93427 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
93428 +ppp_write_34034 ppp_write 3 34034 NULL
93429 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
93430 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
93431 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
93432 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
93433 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
93434 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
93435 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
93436 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
93437 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
93438 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
93439 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
93440 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
93441 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
93442 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
93443 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
93444 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
93445 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
93446 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
93447 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
93448 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
93449 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
93450 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
93451 +lp_write_9511 lp_write 3 9511 NULL
93452 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
93453 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
93454 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
93455 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
93456 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
93457 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
93458 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
93459 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
93460 +read_file_dma_9530 read_file_dma 3 9530 NULL
93461 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
93462 +rcname_read_25919 rcname_read 3 25919 NULL
93463 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
93464 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
93465 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
93466 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
93467 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
93468 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
93469 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
93470 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
93471 +key_flags_read_25931 key_flags_read 3 25931 NULL
93472 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
93473 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
93474 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
93475 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
93476 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
93477 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
93478 +fw_node_create_9559 fw_node_create 2 9559 NULL
93479 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
93480 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
93481 +kobj_map_9566 kobj_map 2-3 9566 NULL
93482 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
93483 +acpi_map_58725 acpi_map 1-2 58725 NULL
93484 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
93485 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
93486 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
93487 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
93488 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
93489 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
93490 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
93491 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
93492 +file_read_actor_1401 file_read_actor 4 1401 NULL
93493 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
93494 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
93495 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
93496 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
93497 +do_sync_9604 do_sync 1 9604 NULL
93498 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
93499 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
93500 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
93501 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
93502 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
93503 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
93504 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
93505 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
93506 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
93507 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
93508 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
93509 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
93510 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
93511 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
93512 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
93513 +sge_rx_50594 sge_rx 3 50594 NULL
93514 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
93515 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
93516 +skb_padto_50759 skb_padto 2 50759 NULL
93517 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
93518 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
93519 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
93520 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
93521 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
93522 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
93523 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
93524 +ep_read_58813 ep_read 3 58813 NULL
93525 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
93526 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
93527 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
93528 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
93529 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
93530 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
93531 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
93532 +dns_query_9676 dns_query 3 9676 NULL
93533 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
93534 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
93535 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
93536 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
93537 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
93538 +command_write_58841 command_write 3 58841 NULL
93539 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
93540 +dev_config_8506 dev_config 3 8506 NULL
93541 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
93542 +sys_readv_50664 sys_readv 3 50664 NULL
93543 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
93544 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
93545 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
93546 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
93547 +recover_head_17904 recover_head 3 17904 NULL
93548 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
93549 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
93550 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
93551 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
93552 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
93553 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
93554 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
93555 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
93556 +skb_cow_26138 skb_cow 2 26138 NULL
93557 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
93558 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
93559 +do_sigpending_9766 do_sigpending 2 9766 NULL
93560 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
93561 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
93562 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
93563 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
93564 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
93565 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
93566 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
93567 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
93568 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
93569 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
93570 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
93571 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
93572 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
93573 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
93574 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
93575 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
93576 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
93577 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
93578 +get_registers_26187 get_registers 3 26187 NULL
93579 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
93580 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
93581 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
93582 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
93583 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
93584 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
93585 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
93586 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
93587 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
93588 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
93589 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
93590 +mce_write_26201 mce_write 3 26201 NULL
93591 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
93592 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
93593 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
93594 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
93595 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
93596 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
93597 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
93598 +tpm_write_50798 tpm_write 3 50798 NULL
93599 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
93600 +tun_do_read_50800 tun_do_read 4 50800 NULL
93601 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
93602 +write_flush_50803 write_flush 3 50803 NULL
93603 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
93604 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
93605 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
93606 +dvb_play_50814 dvb_play 3 50814 NULL
93607 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
93608 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
93609 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
93610 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
93611 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
93612 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
93613 +dma_attach_50831 dma_attach 6-7 50831 NULL
93614 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
93615 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
93616 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
93617 +packet_came_18072 packet_came 3 18072 NULL
93618 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
93619 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
93620 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
93621 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
93622 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
93623 +get_vm_area_18080 get_vm_area 1 18080 NULL
93624 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
93625 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
93626 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
93627 +self_check_write_50856 self_check_write 5 50856 NULL
93628 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
93629 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
93630 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
93631 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
93632 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
93633 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
93634 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
93635 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
93636 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
93637 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
93638 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
93639 +vb2_read_42703 vb2_read 3 42703 NULL
93640 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
93641 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
93642 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
93643 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
93644 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
93645 +read_file_misc_9948 read_file_misc 3 9948 NULL
93646 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
93647 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
93648 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
93649 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
93650 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
93651 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
93652 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
93653 +cosa_write_1774 cosa_write 3 1774 NULL
93654 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
93655 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
93656 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
93657 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
93658 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
93659 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
93660 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
93661 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
93662 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
93663 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
93664 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
93665 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
93666 +mld_newpack_50950 mld_newpack 2 50950 NULL
93667 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
93668 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
93669 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
93670 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
93671 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
93672 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
93673 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
93674 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
93675 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
93676 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
93677 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
93678 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
93679 +handle_request_10024 handle_request 9 10024 NULL
93680 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
93681 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
93682 +timeout_write_50991 timeout_write 3 50991 NULL
93683 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
93684 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
93685 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
93686 +proc_write_51003 proc_write 3 51003 NULL
93687 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
93688 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
93689 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
93690 +set_arg_42824 set_arg 3 42824 NULL
93691 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
93692 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
93693 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
93694 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
93695 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
93696 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
93697 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
93698 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
93699 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
93700 +dt3155_read_59226 dt3155_read 3 59226 NULL
93701 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
93702 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
93703 +dump_midi_51040 dump_midi 3 51040 NULL
93704 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
93705 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
93706 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
93707 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
93708 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
93709 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
93710 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
93711 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
93712 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
93713 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
93714 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
93715 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
93716 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
93717 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
93718 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
93719 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
93720 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
93721 +read_vmcore_26501 read_vmcore 3 26501 NULL
93722 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
93723 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
93724 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
93725 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
93726 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
93727 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
93728 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
93729 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
93730 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
93731 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
93732 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
93733 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
93734 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
93735 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
93736 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
93737 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
93738 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
93739 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
93740 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
93741 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
93742 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
93743 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
93744 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
93745 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
93746 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
93747 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
93748 +fd_copyout_59323 fd_copyout 3 59323 NULL
93749 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
93750 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
93751 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
93752 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
93753 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
93754 +solos_param_store_34755 solos_param_store 4 34755 NULL
93755 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
93756 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
93757 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
93758 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
93759 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
93760 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
93761 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
93762 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
93763 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
93764 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
93765 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
93766 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
93767 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
93768 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
93769 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
93770 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
93771 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
93772 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
93773 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
93774 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
93775 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
93776 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
93777 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
93778 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
93779 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
93780 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
93781 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
93782 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
93783 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
93784 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
93785 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
93786 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
93787 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
93788 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
93789 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
93790 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
93791 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
93792 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
93793 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
93794 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
93795 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
93796 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
93797 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
93798 +tipc_send_51238 tipc_send 4 51238 NULL
93799 +drm_property_create_51239 drm_property_create 4 51239 NULL
93800 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
93801 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
93802 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
93803 +audit_expand_2098 audit_expand 2 2098 NULL
93804 +st_read_51251 st_read 3 51251 NULL
93805 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
93806 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
93807 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
93808 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
93809 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
93810 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
93811 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
93812 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
93813 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
93814 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
93815 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
93816 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
93817 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
93818 +c4_add_card_54968 c4_add_card 3 54968 NULL
93819 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
93820 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
93821 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
93822 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
93823 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
93824 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
93825 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
93826 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
93827 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
93828 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
93829 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
93830 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
93831 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
93832 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
93833 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
93834 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
93835 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
93836 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
93837 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
93838 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
93839 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
93840 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
93841 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
93842 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
93843 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
93844 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
93845 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
93846 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
93847 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
93848 +debug_output_18575 debug_output 3 18575 NULL
93849 +Realloc_34961 Realloc 2 34961 NULL
93850 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
93851 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
93852 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
93853 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
93854 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
93855 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
93856 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
93857 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
93858 +vhci_write_2224 vhci_write 3 2224 NULL
93859 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
93860 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
93861 +rb_alloc_3102 rb_alloc 1 3102 NULL
93862 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
93863 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
93864 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
93865 +write_pbl_59583 write_pbl 4 59583 NULL
93866 +from_buffer_18625 from_buffer 3 18625 NULL
93867 +uio_write_43202 uio_write 3 43202 NULL
93868 +memdup_user_59590 memdup_user 2 59590 NULL
93869 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
93870 +iso_callback_43208 iso_callback 3 43208 NULL
93871 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
93872 +smk_write_load_26829 smk_write_load 3 26829 NULL
93873 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
93874 +do_update_counters_2259 do_update_counters 4 2259 NULL
93875 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
93876 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
93877 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
93878 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
93879 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
93880 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
93881 +mtrr_write_59622 mtrr_write 3 59622 NULL
93882 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
93883 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
93884 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
93885 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
93886 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
93887 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
93888 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
93889 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
93890 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
93891 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
93892 +fixup_leb_43256 fixup_leb 3 43256 NULL
93893 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
93894 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
93895 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
93896 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
93897 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
93898 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
93899 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
93900 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
93901 +evtchn_write_43278 evtchn_write 3 43278 NULL
93902 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
93903 +store_ifalias_35088 store_ifalias 4 35088 NULL
93904 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
93905 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
93906 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
93907 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
93908 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
93909 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
93910 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
93911 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
93912 +capi_write_35104 capi_write 3 35104 NULL nohasharray
93913 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
93914 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
93915 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
93916 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
93917 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
93918 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
93919 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
93920 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
93921 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
93922 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
93923 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
93924 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
93925 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
93926 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
93927 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
93928 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
93929 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
93930 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
93931 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
93932 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
93933 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
93934 +do_trimming_26952 do_trimming 3 26952 NULL
93935 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
93936 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
93937 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
93938 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
93939 +alloc_buf_34532 alloc_buf 1 34532 NULL
93940 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
93941 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
93942 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
93943 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
93944 +otp_read_10594 otp_read 2-4-5 10594 NULL
93945 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
93946 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
93947 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
93948 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
93949 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
93950 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
93951 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
93952 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
93953 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
93954 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
93955 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
93956 +venus_remove_59781 venus_remove 4 59781 NULL
93957 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
93958 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
93959 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
93960 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
93961 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
93962 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
93963 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
93964 +xenfb_write_43412 xenfb_write 3 43412 NULL
93965 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
93966 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
93967 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
93968 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
93969 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
93970 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
93971 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
93972 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
93973 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
93974 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
93975 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
93976 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
93977 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
93978 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
93979 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
93980 +cmd_complete_51629 cmd_complete 6 51629 NULL
93981 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
93982 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
93983 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
93984 +set_fd_set_35249 set_fd_set 1 35249 NULL
93985 +wiphy_new_2482 wiphy_new 2 2482 NULL
93986 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
93987 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
93988 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
93989 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
93990 +tcp_push_10680 tcp_push 3 10680 NULL
93991 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
93992 +c101_run_37279 c101_run 2 37279 NULL
93993 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
93994 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
93995 +tun_put_user_59849 tun_put_user 4 59849 NULL
93996 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
93997 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
93998 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
93999 +dm_write_2513 dm_write 3 2513 NULL
94000 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
94001 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
94002 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
94003 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
94004 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
94005 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
94006 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
94007 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
94008 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
94009 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
94010 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
94011 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
94012 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
94013 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
94014 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
94015 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
94016 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
94017 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
94018 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
94019 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
94020 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
94021 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
94022 +sel_write_access_51704 sel_write_access 3 51704 NULL
94023 +sys_syslog_10746 sys_syslog 3 10746 NULL
94024 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
94025 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
94026 +do_readlink_43518 do_readlink 2 43518 NULL
94027 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
94028 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
94029 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
94030 +read_file_reset_52310 read_file_reset 3 52310 NULL
94031 +pms_capture_27142 pms_capture 4 27142 NULL
94032 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
94033 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
94034 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
94035 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
94036 +msg_set_51725 msg_set 3 51725 NULL
94037 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
94038 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
94039 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
94040 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
94041 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
94042 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
94043 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
94044 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
94045 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
94046 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
94047 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
94048 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
94049 +sys_bind_10799 sys_bind 3 10799 NULL
94050 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
94051 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
94052 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
94053 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
94054 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
94055 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
94056 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
94057 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
94058 +send_command_10832 send_command 4 10832 NULL
94059 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
94060 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
94061 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
94062 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
94063 +proc_read_43614 proc_read 3 43614 NULL
94064 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
94065 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
94066 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
94067 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
94068 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
94069 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
94070 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
94071 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
94072 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
94073 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
94074 +vmalloc_15464 vmalloc 1 15464 NULL
94075 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
94076 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
94077 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
94078 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
94079 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
94080 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
94081 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
94082 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
94083 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
94084 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
94085 +adu_write_30487 adu_write 3 30487 NULL
94086 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
94087 +get_scq_10897 get_scq 2 10897 NULL
94088 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
94089 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
94090 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
94091 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
94092 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
94093 +load_module_60056 load_module 2 60056 NULL nohasharray
94094 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
94095 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
94096 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
94097 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
94098 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
94099 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
94100 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
94101 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
94102 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
94103 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
94104 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
94105 +user_read_51881 user_read 3 51881 NULL
94106 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
94107 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
94108 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
94109 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
94110 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
94111 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
94112 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
94113 +async_setkey_35521 async_setkey 3 35521 NULL
94114 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
94115 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
94116 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
94117 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
94118 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
94119 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
94120 +add_tty_40055 add_tty 1 40055 NULL nohasharray
94121 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
94122 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
94123 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
94124 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
94125 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
94126 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
94127 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
94128 +alloc_context_3194 alloc_context 1 3194 NULL
94129 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
94130 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
94131 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
94132 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
94133 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
94134 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
94135 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
94136 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
94137 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
94138 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
94139 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
94140 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
94141 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
94142 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
94143 +init_state_60165 init_state 2 60165 NULL
94144 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
94145 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
94146 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
94147 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
94148 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
94149 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
94150 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
94151 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
94152 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
94153 +calc_hmac_32010 calc_hmac 3 32010 NULL
94154 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
94155 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
94156 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
94157 +kernel_readv_35617 kernel_readv 3 35617 NULL
94158 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
94159 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
94160 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
94161 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
94162 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
94163 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
94164 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
94165 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
94166 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
94167 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
94168 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
94169 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
94170 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
94171 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
94172 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
94173 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
94174 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
94175 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
94176 +store_debug_level_35652 store_debug_level 3 35652 NULL
94177 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
94178 +read_flush_43851 read_flush 3 43851 NULL
94179 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
94180 +cmm_write_2896 cmm_write 3 2896 NULL
94181 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
94182 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
94183 +tunables_write_59563 tunables_write 3 59563 NULL
94184 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
94185 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
94186 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
94187 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
94188 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
94189 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
94190 +dm_table_create_35687 dm_table_create 3 35687 NULL
94191 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
94192 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
94193 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
94194 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
94195 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
94196 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
94197 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
94198 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
94199 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
94200 +debug_read_19322 debug_read 3 19322 NULL
94201 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
94202 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
94203 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
94204 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
94205 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
94206 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
94207 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
94208 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
94209 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
94210 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
94211 +doc_probe_23285 doc_probe 1 23285 NULL
94212 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
94213 +SendString_43928 SendString 3 43928 NULL
94214 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
94215 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
94216 +retry_count_read_52129 retry_count_read 3 52129 NULL
94217 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
94218 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
94219 +read_zero_19366 read_zero 3 19366 NULL
94220 +bch_alloc_4593 bch_alloc 1 4593 NULL
94221 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
94222 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
94223 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
94224 +raid5_resize_63306 raid5_resize 2 63306 NULL
94225 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
94226 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
94227 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
94228 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
94229 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
94230 +depth_write_3021 depth_write 3 3021 NULL
94231 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
94232 +read_file_stations_35795 read_file_stations 3 35795 NULL
94233 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
94234 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
94235 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
94236 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
94237 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
94238 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
94239 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
94240 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
94241 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
94242 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
94243 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
94244 +driver_names_read_60399 driver_names_read 3 60399 NULL
94245 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
94246 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
94247 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
94248 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
94249 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
94250 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
94251 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
94252 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
94253 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
94254 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
94255 +rx_data_60442 rx_data 4 60442 NULL
94256 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
94257 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
94258 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
94259 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
94260 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
94261 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
94262 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
94263 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
94264 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
94265 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
94266 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
94267 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
94268 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
94269 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
94270 +construct_key_11329 construct_key 3 11329 NULL
94271 +evm_write_key_27715 evm_write_key 3 27715 NULL
94272 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
94273 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
94274 +filldir_55137 filldir 3 55137 NULL
94275 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
94276 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
94277 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
94278 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
94279 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
94280 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
94281 +sel_write_create_11353 sel_write_create 3 11353 NULL
94282 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
94283 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
94284 +hwflags_read_52318 hwflags_read 3 52318 NULL
94285 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
94286 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
94287 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
94288 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
94289 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
94290 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
94291 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
94292 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
94293 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
94294 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
94295 +nfsd_read_19568 nfsd_read 5 19568 NULL
94296 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
94297 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
94298 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
94299 +kcalloc_27770 kcalloc 1-2 27770 NULL
94300 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
94301 +bm_status_read_19583 bm_status_read 3 19583 NULL
94302 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
94303 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
94304 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
94305 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
94306 +acl_alloc_35979 acl_alloc 1 35979 NULL
94307 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
94308 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
94309 +str_to_user_11411 str_to_user 2 11411 NULL
94310 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
94311 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
94312 +trace_options_read_11419 trace_options_read 3 11419 NULL
94313 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
94314 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
94315 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
94316 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
94317 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
94318 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
94319 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
94320 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
94321 +console_store_36007 console_store 4 36007 NULL
94322 +bttv_read_11432 bttv_read 3 11432 NULL
94323 +key_key_read_3241 key_key_read 3 3241 NULL
94324 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
94325 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
94326 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
94327 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
94328 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
94329 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
94330 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
94331 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
94332 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
94333 +um_idi_write_18293 um_idi_write 3 18293 NULL
94334 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
94335 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
94336 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
94337 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
94338 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
94339 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
94340 +sys_init_module_36047 sys_init_module 2 36047 NULL
94341 +read_profile_27859 read_profile 3 27859 NULL
94342 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
94343 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
94344 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
94345 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
94346 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
94347 +refill_pool_19477 refill_pool 2 19477 NULL
94348 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
94349 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
94350 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
94351 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
94352 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
94353 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
94354 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
94355 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
94356 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
94357 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
94358 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
94359 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
94360 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
94361 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
94362 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
94363 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
94364 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
94365 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
94366 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
94367 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
94368 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
94369 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
94370 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
94371 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
94372 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
94373 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
94374 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
94375 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
94376 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
94377 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
94378 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
94379 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
94380 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
94381 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
94382 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
94383 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
94384 +init_data_container_60709 init_data_container 1 60709 NULL
94385 +p9_client_read_19750 p9_client_read 5 19750 NULL
94386 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
94387 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
94388 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
94389 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
94390 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
94391 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
94392 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
94393 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
94394 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
94395 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
94396 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
94397 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
94398 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
94399 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
94400 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
94401 +send_stream_3397 send_stream 4 3397 NULL
94402 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
94403 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
94404 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
94405 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
94406 +msix_map_region_3411 msix_map_region 3 3411 NULL
94407 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
94408 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
94409 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
94410 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
94411 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
94412 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
94413 +opticon_write_60775 opticon_write 4 60775 NULL
94414 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
94415 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
94416 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
94417 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
94418 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
94419 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
94420 +vip_read_19832 vip_read 3 19832 NULL
94421 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
94422 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
94423 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
94424 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
94425 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
94426 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
94427 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
94428 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
94429 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
94430 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
94431 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
94432 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
94433 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
94434 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
94435 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
94436 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
94437 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
94438 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
94439 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
94440 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
94441 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
94442 +split_11691 split 2 11691 NULL
94443 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
94444 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
94445 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
94446 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
94447 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
94448 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
94449 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
94450 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
94451 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
94452 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
94453 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
94454 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
94455 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
94456 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
94457 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
94458 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
94459 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
94460 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
94461 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
94462 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
94463 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
94464 +spidev_write_44510 spidev_write 3 44510 NULL
94465 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
94466 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
94467 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
94468 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
94469 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
94470 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
94471 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
94472 +kone_receive_4690 kone_receive 4 4690 NULL
94473 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
94474 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
94475 +evtchn_read_3569 evtchn_read 3 3569 NULL
94476 +video_read_28148 video_read 3 28148 NULL
94477 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
94478 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
94479 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
94480 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
94481 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
94482 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
94483 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
94484 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
94485 +vc_resize_3585 vc_resize 2-3 3585 NULL
94486 +gluebi_write_27905 gluebi_write 3 27905 NULL
94487 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
94488 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
94489 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
94490 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
94491 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
94492 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
94493 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
94494 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
94495 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
94496 +pti_char_write_60960 pti_char_write 3 60960 NULL
94497 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
94498 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
94499 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
94500 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
94501 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
94502 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
94503 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
94504 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
94505 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
94506 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
94507 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
94508 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
94509 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
94510 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
94511 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
94512 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
94513 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
94514 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
94515 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
94516 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
94517 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
94518 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
94519 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
94520 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
94521 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
94522 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
94523 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
94524 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
94525 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
94526 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
94527 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
94528 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
94529 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
94530 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
94531 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
94532 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
94533 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
94534 +symtab_init_61050 symtab_init 2 61050 NULL
94535 +team_options_register_20091 team_options_register 3 20091 NULL
94536 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
94537 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
94538 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
94539 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
94540 +mpi_resize_44674 mpi_resize 2 44674 NULL
94541 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
94542 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
94543 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
94544 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
94545 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
94546 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
94547 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
94548 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
94549 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
94550 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
94551 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
94552 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
94553 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
94554 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
94555 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
94556 +pms_read_53873 pms_read 3 53873 NULL
94557 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
94558 +get_derived_key_61100 get_derived_key 4 61100 NULL
94559 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
94560 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
94561 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
94562 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
94563 +dm_read_15674 dm_read 3 15674 NULL
94564 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
94565 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
94566 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
94567 +kone_send_63435 kone_send 4 63435 NULL
94568 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
94569 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
94570 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
94571 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
94572 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
94573 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
94574 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
94575 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
94576 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
94577 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
94578 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
94579 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
94580 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
94581 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
94582 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
94583 +send_packet_52960 send_packet 4 52960 NULL
94584 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
94585 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
94586 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
94587 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
94588 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
94589 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
94590 +put_cmsg_36589 put_cmsg 4 36589 NULL
94591 +__vmalloc_61168 __vmalloc 1 61168 NULL
94592 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
94593 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
94594 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
94595 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
94596 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
94597 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
94598 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
94599 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
94600 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
94601 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
94602 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
94603 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
94604 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
94605 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
94606 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
94607 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
94608 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
94609 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
94610 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
94611 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
94612 +get_fd_set_3866 get_fd_set 1 3866 NULL
94613 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
94614 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
94615 +unlink_queued_645 unlink_queued 3-4 645 NULL
94616 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
94617 +sisusb_write_44834 sisusb_write 3 44834 NULL
94618 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
94619 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
94620 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
94621 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
94622 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
94623 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
94624 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
94625 +nvram_write_3894 nvram_write 3 3894 NULL
94626 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
94627 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
94628 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
94629 +vcs_write_3910 vcs_write 3 3910 NULL
94630 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
94631 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
94632 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
94633 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
94634 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
94635 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
94636 +do_tty_write_44896 do_tty_write 5 44896 NULL
94637 +set_powered_12129 set_powered 4 12129 NULL
94638 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
94639 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
94640 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
94641 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
94642 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
94643 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
94644 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
94645 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
94646 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
94647 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
94648 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
94649 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
94650 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
94651 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
94652 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
94653 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
94654 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
94655 +gather_array_56641 gather_array 3 56641 NULL
94656 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
94657 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
94658 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
94659 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
94660 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
94661 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
94662 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
94663 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
94664 +do_add_counters_3992 do_add_counters 3 3992 NULL
94665 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
94666 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
94667 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
94668 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
94669 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
94670 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
94671 +mei_write_4005 mei_write 3 4005 NULL
94672 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
94673 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
94674 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
94675 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
94676 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
94677 +receive_copy_12216 receive_copy 3 12216 NULL
94678 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
94679 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
94680 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
94681 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
94682 +change_xattr_61390 change_xattr 5 61390 NULL
94683 +find_skb_20431 find_skb 2 20431 NULL
94684 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
94685 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
94686 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
94687 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
94688 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
94689 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
94690 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
94691 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
94692 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
94693 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
94694 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
94695 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
94696 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
94697 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
94698 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
94699 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
94700 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
94701 +read_buf_20469 read_buf 2 20469 NULL
94702 +cm_write_36858 cm_write 3 36858 NULL
94703 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
94704 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
94705 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
94706 +sel_write_user_45060 sel_write_user 3 45060 NULL
94707 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
94708 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
94709 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
94710 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
94711 +fast_user_write_20494 fast_user_write 5 20494 NULL
94712 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
94713 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
94714 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
94715 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
94716 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
94717 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
94718 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
94719 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
94720 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
94721 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
94722 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
94723 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
94724 +osst_read_40237 osst_read 3 40237 NULL
94725 +tm6000_read_4151 tm6000_read 3 4151 NULL
94726 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
94727 +usbdev_read_45114 usbdev_read 3 45114 NULL
94728 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
94729 +spi_execute_28736 spi_execute 5 28736 NULL
94730 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
94731 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
94732 +get_alua_req_4166 get_alua_req 3 4166 NULL
94733 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
94734 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
94735 +venus_create_20555 venus_create 4 20555 NULL
94736 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
94737 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
94738 +receive_packet_12367 receive_packet 2 12367 NULL
94739 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
94740 +mem_write_22232 mem_write 3 22232 NULL
94741 +read_file_bool_4180 read_file_bool 3 4180 NULL
94742 +send_to_tty_45141 send_to_tty 3 45141 NULL
94743 +fops_read_40672 fops_read 3 40672 NULL
94744 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
94745 +write_leb_36957 write_leb 5 36957 NULL
94746 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
94747 +device_write_45156 device_write 3 45156 NULL
94748 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
94749 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
94750 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
94751 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
94752 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
94753 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
94754 +isp1760_register_628 isp1760_register 1-2 628 NULL
94755 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
94756 +lirc_write_20604 lirc_write 3 20604 NULL
94757 +sel_write_member_28800 sel_write_member 3 28800 NULL
94758 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
94759 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
94760 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
94761 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
94762 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
94763 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
94764 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
94765 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
94766 +setxattr_37006 setxattr 4 37006 NULL
94767 +add_child_45201 add_child 4 45201 NULL
94768 +seq_open_private_61589 seq_open_private 3 61589 NULL
94769 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
94770 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
94771 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
94772 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
94773 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
94774 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
94775 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
94776 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
94777 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
94778 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
94779 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
94780 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
94781 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
94782 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
94783 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
94784 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
94785 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
94786 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
94787 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
94788 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
94789 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
94790 +resize_stripes_61650 resize_stripes 2 61650 NULL
94791 +n2_run_53459 n2_run 3 53459 NULL
94792 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
94793 +parse_command_37079 parse_command 2 37079 NULL
94794 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
94795 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
94796 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
94797 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
94798 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
94799 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
94800 +insert_one_name_61668 insert_one_name 7 61668 NULL
94801 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
94802 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
94803 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
94804 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
94805 +lock_loop_61681 lock_loop 1 61681 NULL
94806 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
94807 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
94808 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
94809 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
94810 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
94811 +push_rx_28939 push_rx 3 28939 NULL
94812 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
94813 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
94814 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
94815 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
94816 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
94817 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
94818 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
94819 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
94820 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
94821 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
94822 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
94823 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
94824 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
94825 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
94826 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
94827 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
94828 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
94829 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
94830 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
94831 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
94832 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
94833 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
94834 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
94835 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
94836 +bin_uuid_28999 bin_uuid 3 28999 NULL
94837 +sys_sendto_20809 sys_sendto 6 20809 NULL
94838 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
94839 +set_registers_53582 set_registers 3 53582 NULL
94840 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
94841 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
94842 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
94843 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
94844 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
94845 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
94846 +keymap_store_45406 keymap_store 4 45406 NULL
94847 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
94848 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
94849 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
94850 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
94851 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
94852 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
94853 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
94854 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
94855 +__do_replace_37227 __do_replace 5 37227 NULL
94856 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
94857 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
94858 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
94859 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
94860 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
94861 +tso_fragment_29050 tso_fragment 3 29050 NULL
94862 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
94863 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
94864 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
94865 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
94866 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
94867 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
94868 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
94869 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
94870 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
94871 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
94872 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
94873 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
94874 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
94875 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
94876 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
94877 +set_link_security_4502 set_link_security 4 4502 NULL
94878 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
94879 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
94880 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
94881 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
94882 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
94883 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
94884 +mmio_read_40348 mmio_read 4 40348 NULL
94885 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
94886 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
94887 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
94888 +ivtv_write_12721 ivtv_write 3 12721 NULL
94889 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
94890 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
94891 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
94892 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
94893 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
94894 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
94895 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
94896 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
94897 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
94898 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
94899 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
94900 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
94901 +send_msg_37323 send_msg 4 37323 NULL
94902 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
94903 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
94904 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
94905 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
94906 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
94907 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
94908 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
94909 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
94910 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
94911 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
94912 +reshape_ring_29147 reshape_ring 2 29147 NULL
94913 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
94914 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
94915 +copy_macs_45534 copy_macs 4 45534 NULL
94916 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
94917 +listxattr_12769 listxattr 3 12769 NULL
94918 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
94919 +wdm_write_53735 wdm_write 3 53735 NULL
94920 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
94921 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
94922 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
94923 +mempool_create_29437 mempool_create 1 29437 NULL
94924 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
94925 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
94926 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
94927 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
94928 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
94929 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
94930 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
94931 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
94932 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
94933 +mgmt_event_12810 mgmt_event 4 12810 NULL
94934 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
94935 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
94936 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
94937 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
94938 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
94939 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
94940 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
94941 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
94942 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
94943 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
94944 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
94945 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
94946 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
94947 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
94948 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
94949 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
94950 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
94951 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
94952 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
94953 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
94954 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
94955 +recover_peb_29238 recover_peb 6-7 29238 NULL
94956 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
94957 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
94958 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
94959 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
94960 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
94961 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
94962 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
94963 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
94964 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
94965 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
94966 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
94967 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
94968 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
94969 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
94970 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
94971 +do_pselect_62061 do_pselect 1 62061 NULL
94972 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
94973 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
94974 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
94975 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
94976 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
94977 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
94978 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
94979 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
94980 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
94981 +sg_read_25799 sg_read 3 25799 NULL
94982 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
94983 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
94984 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
94985 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
94986 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
94987 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
94988 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
94989 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
94990 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
94991 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
94992 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
94993 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
94994 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
94995 +new_skb_21148 new_skb 1 21148 NULL
94996 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
94997 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
94998 +bm_status_write_12964 bm_status_write 3 12964 NULL
94999 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
95000 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
95001 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
95002 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
95003 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
95004 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
95005 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
95006 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
95007 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
95008 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
95009 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
95010 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
95011 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
95012 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
95013 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
95014 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
95015 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
95016 +video_usercopy_62151 video_usercopy 2 62151 NULL
95017 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
95018 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
95019 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
95020 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
95021 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
95022 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
95023 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
95024 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
95025 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
95026 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
95027 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
95028 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
95029 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
95030 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
95031 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
95032 +input_ff_create_21240 input_ff_create 2 21240 NULL
95033 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
95034 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
95035 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
95036 +amthi_read_45831 amthi_read 4 45831 NULL
95037 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
95038 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
95039 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
95040 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
95041 +sys_ipc_4889 sys_ipc 3 4889 NULL
95042 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
95043 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
95044 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
95045 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
95046 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
95047 +do_register_entry_29478 do_register_entry 4 29478 NULL
95048 +isdn_write_45863 isdn_write 3 45863 NULL
95049 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
95050 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
95051 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
95052 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
95053 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
95054 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
95055 +_malloc_54077 _malloc 1 54077 NULL
95056 +add_res_range_21310 add_res_range 4 21310 NULL
95057 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
95058 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
95059 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
95060 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
95061 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
95062 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
95063 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
95064 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
95065 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
95066 +create_xattr_54106 create_xattr 5 54106 NULL
95067 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
95068 +ep_write_59008 ep_write 3 59008 NULL
95069 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
95070 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
95071 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
95072 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
95073 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
95074 +alloc_mr_45935 alloc_mr 1 45935 NULL
95075 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
95076 +isku_receive_54130 isku_receive 4 54130 NULL
95077 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
95078 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
95079 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
95080 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
95081 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
95082 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
95083 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
95084 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
95085 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
95086 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
95087 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
95088 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
95089 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
95090 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
95091 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
95092 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
95093 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
95094 +comedi_read_13199 comedi_read 3 13199 NULL
95095 +flash_write_62354 flash_write 3 62354 NULL
95096 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
95097 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
95098 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
95099 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
95100 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
95101 +proc_file_read_53905 proc_file_read 3 53905 NULL
95102 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
95103 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
95104 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
95105 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
95106 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
95107 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
95108 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
95109 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
95110 +cru_detect_11272 cru_detect 1 11272 NULL
95111 +altera_irscan_62396 altera_irscan 2 62396 NULL
95112 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
95113 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
95114 +fw_download_code_13249 fw_download_code 3 13249 NULL
95115 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
95116 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
95117 +set_ssp_62411 set_ssp 4 62411 NULL
95118 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
95119 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
95120 +get_free_entries_46030 get_free_entries 1 46030 NULL
95121 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
95122 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
95123 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
95124 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
95125 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
95126 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
95127 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
95128 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
95129 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
95130 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
95131 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
95132 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
95133 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
95134 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
95135 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
95136 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
95137 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
95138 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
95139 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
95140 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
95141 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
95142 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
95143 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
95144 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
95145 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
95146 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
95147 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
95148 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
95149 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
95150 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
95151 +probes_write_29711 probes_write 3 29711 NULL
95152 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
95153 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
95154 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
95155 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
95156 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
95157 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
95158 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
95159 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
95160 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
95161 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
95162 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
95163 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
95164 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
95165 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
95166 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
95167 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
95168 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
95169 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
95170 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
95171 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
95172 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
95173 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
95174 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
95175 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
95176 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
95177 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
95178 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
95179 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
95180 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
95181 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
95182 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
95183 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
95184 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
95185 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
95186 +isdn_read_50021 isdn_read 3 50021 NULL
95187 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
95188 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
95189 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
95190 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
95191 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
95192 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
95193 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
95194 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
95195 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
95196 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
95197 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
95198 +get_subdir_62581 get_subdir 3 62581 NULL
95199 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
95200 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
95201 +vfs_readv_38011 vfs_readv 3 38011 NULL
95202 +keyring_read_13438 keyring_read 3 13438 NULL
95203 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
95204 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
95205 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
95206 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
95207 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
95208 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
95209 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
95210 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
95211 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
95212 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
95213 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
95214 +ftrace_write_29551 ftrace_write 3 29551 NULL
95215 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
95216 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
95217 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
95218 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
95219 +dev_write_7708 dev_write 3 7708 NULL
95220 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
95221 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
95222 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
95223 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
95224 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
95225 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
95226 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
95227 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
95228 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
95229 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
95230 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
95231 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
95232 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
95233 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
95234 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
95235 +bm_init_13529 bm_init 2 13529 NULL
95236 +check586_29914 check586 2 29914 NULL
95237 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
95238 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
95239 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
95240 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
95241 +pg_read_17276 pg_read 3 17276 NULL
95242 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
95243 +ep0_read_38095 ep0_read 3 38095 NULL
95244 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
95245 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
95246 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
95247 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
95248 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
95249 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
95250 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
95251 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
95252 +l2down_create_21755 l2down_create 4 21755 NULL
95253 +alloc_tio_13564 alloc_tio 3 13564 NULL
95254 +viacam_read_54526 viacam_read 3 54526 NULL
95255 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
95256 +tunables_read_36385 tunables_read 3 36385 NULL
95257 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
95258 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
95259 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
95260 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
95261 +setsockopt_54539 setsockopt 5 54539 NULL
95262 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
95263 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
95264 +tty_register_device_4544 tty_register_device 2 4544 NULL
95265 +cache_write_13589 cache_write 3 13589 NULL
95266 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
95267 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
95268 +key_replays_read_62746 key_replays_read 3 62746 NULL
95269 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
95270 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
95271 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
95272 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
95273 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
95274 +cdev_add_38176 cdev_add 2-3 38176 NULL
95275 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
95276 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
95277 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
95278 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
95279 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
95280 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
95281 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
95282 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
95283 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
95284 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
95285 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
95286 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
95287 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
95288 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
95289 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
95290 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
95291 +packet_snd_13634 packet_snd 3 13634 NULL
95292 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
95293 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
95294 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
95295 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
95296 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
95297 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
95298 +drp_wmove_30043 drp_wmove 4 30043 NULL
95299 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
95300 +cache_downcall_13666 cache_downcall 3 13666 NULL
95301 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
95302 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
95303 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
95304 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
95305 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
95306 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
95307 +tty_write_5494 tty_write 3 5494 NULL
95308 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
95309 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
95310 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
95311 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
95312 +teiup_create_43201 teiup_create 3 43201 NULL
95313 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
95314 +filldir64_46469 filldir64 3 46469 NULL
95315 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
95316 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
95317 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
95318 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
95319 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
95320 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
95321 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
95322 +spidev_message_5518 spidev_message 3 5518 NULL
95323 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
95324 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
95325 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
95326 +evm_read_key_54674 evm_read_key 3 54674 NULL
95327 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
95328 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
95329 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
95330 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
95331 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
95332 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
95333 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
95334 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
95335 +u32_array_read_2219 u32_array_read 3 2219 NULL
95336 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
95337 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
95338 +sys_add_key_61288 sys_add_key 4 61288 NULL
95339 +kmsg_read_46514 kmsg_read 3 46514 NULL
95340 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
95341 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
95342 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
95343 +recv_stream_30138 recv_stream 4 30138 NULL
95344 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
95345 +getdqbuf_62908 getdqbuf 1 62908 NULL
95346 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
95347 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
95348 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
95349 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
95350 +fir16_create_5574 fir16_create 3 5574 NULL
95351 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
95352 +pt_write_40159 pt_write 3 40159 NULL
95353 +bioset_create_5580 bioset_create 1 5580 NULL
95354 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
95355 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
95356 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
95357 +kzalloc_54740 kzalloc 1 54740 NULL
95358 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
95359 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
95360 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
95361 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
95362 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
95363 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
95364 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
95365 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
95366 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
95367 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
95368 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
95369 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
95370 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
95371 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
95372 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
95373 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
95374 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
95375 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
95376 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
95377 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
95378 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
95379 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
95380 +ti_recv_22027 ti_recv 4 22027 NULL
95381 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
95382 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
95383 +nfsd_write_54809 nfsd_write 6 54809 NULL
95384 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
95385 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
95386 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
95387 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
95388 +get_skb_63008 get_skb 2 63008 NULL
95389 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
95390 +netlink_send_38434 netlink_send 5 38434 NULL
95391 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
95392 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
95393 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
95394 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
95395 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
95396 +write_rio_54837 write_rio 3 54837 NULL
95397 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
95398 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
95399 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
95400 +get_arg_5694 get_arg 3 5694 NULL
95401 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
95402 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
95403 +compat_readv_30273 compat_readv 3 30273 NULL
95404 +printer_read_54851 printer_read 3 54851 NULL
95405 +mem_rw_22085 mem_rw 3 22085 NULL
95406 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
95407 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
95408 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
95409 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
95410 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
95411 +unlink1_63059 unlink1 3 63059 NULL
95412 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
95413 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
95414 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
95415 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
95416 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
95417 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
95418 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
95419 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
95420 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
95421 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
95422 +dev_names_read_38509 dev_names_read 3 38509 NULL
95423 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
95424 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
95425 +get_packet_5747 get_packet 3 5747 NULL
95426 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
95427 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
95428 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
95429 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
95430 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
95431 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
95432 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
95433 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
95434 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
95435 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
95436 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
95437 +resource_from_user_30341 resource_from_user 3 30341 NULL
95438 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
95439 +sound_write_5102 sound_write 3 5102 NULL
95440 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
95441 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
95442 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
95443 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
95444 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
95445 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
95446 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
95447 +com90xx_found_13974 com90xx_found 3 13974 NULL
95448 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
95449 +qcam_read_13977 qcam_read 3 13977 NULL
95450 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
95451 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
95452 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
95453 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
95454 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
95455 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
95456 +generic_readlink_32654 generic_readlink 3 32654 NULL
95457 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
95458 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
95459 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
95460 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
95461 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
95462 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
95463 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
95464 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
95465 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
95466 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
95467 +concat_writev_21451 concat_writev 3 21451 NULL
95468 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
95469 +_queue_data_54983 _queue_data 4 54983 NULL
95470 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
95471 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
95472 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
95473 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
95474 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
95475 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
95476 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
95477 +setup_req_5848 setup_req 3 5848 NULL
95478 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
95479 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
95480 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
95481 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
95482 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
95483 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
95484 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
95485 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
95486 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
95487 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
95488 +cma_create_area_38642 cma_create_area 2 38642 NULL
95489 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
95490 +sriov_enable_59689 sriov_enable 2 59689 NULL
95491 +enable_write_30456 enable_write 3 30456 NULL
95492 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
95493 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
95494 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
95495 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
95496 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
95497 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
95498 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
95499 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
95500 +port_show_regs_5904 port_show_regs 3 5904 NULL
95501 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
95502 +ptp_read_63251 ptp_read 4 63251 NULL
95503 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
95504 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
95505 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
95506 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
95507 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
95508 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
95509 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
95510 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
95511 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
95512 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
95513 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
95514 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
95515 +read_dma_55086 read_dma 3 55086 NULL
95516 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
95517 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
95518 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
95519 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
95520 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
95521 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
95522 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
95523 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
95524 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
95525 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
95526 +em_canid_change_14150 em_canid_change 3 14150 NULL
95527 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
95528 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
95529 +fb_write_46924 fb_write 3 46924 NULL
95530 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
95531 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
95532 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
95533 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
95534 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
95535 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
95536 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
95537 +udf_readpages_38761 udf_readpages 4 38761 NULL
95538 +reada_add_block_54247 reada_add_block 2 54247 NULL
95539 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
95540 +proc_info_read_63344 proc_info_read 3 63344 NULL
95541 +pep_indicate_38611 pep_indicate 5 38611 NULL
95542 +set_le_30581 set_le 4 30581 NULL
95543 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
95544 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
95545 +alloc_private_22399 alloc_private 2 22399 NULL
95546 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
95547 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
95548 +zoran_write_22404 zoran_write 3 22404 NULL
95549 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
95550 +idmouse_read_63374 idmouse_read 3 63374 NULL
95551 +queue_reply_22416 queue_reply 3 22416 NULL
95552 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
95553 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
95554 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
95555 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
95556 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
95557 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
95558 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
95559 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
95560 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
95561 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
95562 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
95563 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
95564 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
95565 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
95566 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
95567 +sys_select_38827 sys_select 1 38827 NULL
95568 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
95569 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
95570 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
95571 +direct_entry_38836 direct_entry 3 38836 NULL
95572 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
95573 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
95574 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
95575 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
95576 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
95577 +write_head_30481 write_head 4 30481 NULL
95578 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
95579 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
95580 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
95581 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
95582 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
95583 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
95584 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
95585 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
95586 +agp_remap_30665 agp_remap 2 30665 NULL
95587 +interfaces_38859 interfaces 2 38859 NULL
95588 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
95589 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
95590 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
95591 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
95592 +qc_capture_19298 qc_capture 3 19298 NULL
95593 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
95594 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
95595 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
95596 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
95597 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
95598 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
95599 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
95600 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
95601 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
95602 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
95603 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
95604 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
95605 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
95606 +read_kcore_63488 read_kcore 3 63488 NULL
95607 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
95608 +__skb_cow_39254 __skb_cow 2 39254 NULL
95609 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
95610 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
95611 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
95612 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
95613 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
95614 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
95615 +mousedev_read_47123 mousedev_read 3 47123 NULL
95616 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
95617 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
95618 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
95619 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
95620 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
95621 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
95622 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
95623 +vme_user_read_55338 vme_user_read 3 55338 NULL
95624 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
95625 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
95626 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
95627 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
95628 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
95629 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
95630 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
95631 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
95632 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
95633 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
95634 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
95635 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
95636 +snapshot_read_22601 snapshot_read 3 22601 NULL
95637 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
95638 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
95639 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
95640 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
95641 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
95642 +__send_to_port_55383 __send_to_port 3 55383 NULL
95643 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
95644 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
95645 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
95646 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
95647 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
95648 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
95649 +get_nodes_39012 get_nodes 3 39012 NULL
95650 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
95651 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
95652 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
95653 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
95654 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
95655 +create_subvol_30836 create_subvol 4 30836 NULL
95656 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
95657 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
95658 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
95659 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
95660 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
95661 +read_oldmem_55658 read_oldmem 3 55658 NULL
95662 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
95663 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
95664 +options_write_47243 options_write 3 47243 NULL
95665 +module_alloc_63630 module_alloc 1 63630 NULL
95666 +alloc_skb_55439 alloc_skb 1 55439 NULL
95667 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
95668 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
95669 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
95670 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
95671 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
95672 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
95673 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
95674 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
95675 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
95676 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
95677 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
95678 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
95679 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
95680 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
95681 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
95682 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
95683 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
95684 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
95685 +vbi_read_63673 vbi_read 3 63673 NULL
95686 +tun_get_user_39099 tun_get_user 4 39099 NULL
95687 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
95688 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
95689 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
95690 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
95691 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
95692 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
95693 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
95694 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
95695 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
95696 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
95697 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
95698 +ax25_output_22736 ax25_output 2 22736 NULL
95699 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
95700 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
95701 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
95702 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
95703 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
95704 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
95705 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
95706 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
95707 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
95708 +hid_input_report_32458 hid_input_report 4 32458 NULL
95709 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
95710 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
95711 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
95712 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
95713 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
95714 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
95715 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
95716 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
95717 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
95718 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
95719 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
95720 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
95721 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
95722 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
95723 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
95724 +get_info_55681 get_info 3 55681 NULL
95725 +setkey_14987 setkey 3 14987 NULL
95726 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
95727 +init_list_set_39188 init_list_set 2-3 39188 NULL
95728 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
95729 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
95730 +l2up_create_6430 l2up_create 3 6430 NULL
95731 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
95732 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
95733 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
95734 +add_partition_55588 add_partition 2 55588 NULL
95735 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
95736 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
95737 +depth_read_31112 depth_read 3 31112 NULL
95738 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
95739 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
95740 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
95741 +profile_replace_14652 profile_replace 3 14652 NULL
95742 +vzalloc_47421 vzalloc 1 47421 NULL
95743 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
95744 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
95745 +sys_writev_28384 sys_writev 3 28384 NULL
95746 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
95747 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
95748 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
95749 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
95750 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
95751 +create_attr_set_22861 create_attr_set 1 22861 NULL
95752 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
95753 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
95754 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
95755 +sel_write_load_63830 sel_write_load 3 63830 NULL
95756 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
95757 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
95758 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
95759 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
95760 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
95761 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
95762 +probe_bios_17467 probe_bios 1 17467 NULL
95763 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
95764 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
95765 +mei_read_6507 mei_read 3 6507 NULL
95766 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
95767 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
95768 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
95769 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
95770 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
95771 +SetArea_50835 SetArea 4 50835 NULL
95772 +tpm_read_50344 tpm_read 3 50344 NULL
95773 +newpart_47485 newpart 6 47485 NULL
95774 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
95775 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
95776 +core_sys_select_47494 core_sys_select 1 47494 NULL
95777 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
95778 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
95779 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
95780 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
95781 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
95782 +unlink_simple_47506 unlink_simple 3 47506 NULL
95783 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
95784 +wdm_read_6549 wdm_read 3 6549 NULL
95785 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
95786 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
95787 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
95788 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
95789 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
95790 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
95791 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
95792 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
95793 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
95794 +filter_read_61692 filter_read 3 61692 NULL
95795 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
95796 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
95797 +debugfs_read_62535 debugfs_read 3 62535 NULL
95798 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
95799 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
95800 +divas_write_63901 divas_write 3 63901 NULL
95801 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
95802 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
95803 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
95804 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
95805 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
95806 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
95807 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
95808 +ipw_write_59807 ipw_write 3 59807 NULL
95809 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
95810 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
95811 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
95812 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
95813 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
95814 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
95815 +cycx_setup_47562 cycx_setup 4 47562 NULL
95816 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
95817 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
95818 +set_local_name_55757 set_local_name 4 55757 NULL
95819 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
95820 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
95821 +read_ldt_47570 read_ldt 2 47570 NULL
95822 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
95823 +pci_iomap_47575 pci_iomap 3 47575 NULL
95824 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
95825 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
95826 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
95827 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
95828 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
95829 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
95830 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
95831 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
95832 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
95833 +conf_read_55786 conf_read 3 55786 NULL
95834 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
95835 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
95836 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
95837 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
95838 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
95839 +user_power_read_39414 user_power_read 3 39414 NULL
95840 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
95841 +uea_request_47613 uea_request 4 47613 NULL
95842 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
95843 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
95844 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
95845 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
95846 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
95847 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
95848 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
95849 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
95850 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
95851 +kmemdup_64015 kmemdup 2 64015 NULL
95852 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
95853 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
95854 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
95855 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
95856 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
95857 +oz_events_read_47535 oz_events_read 3 47535 NULL
95858 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
95859 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
95860 +sys_semop_39457 sys_semop 3 39457 NULL
95861 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
95862 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
95863 +update_pmkid_2481 update_pmkid 4 2481 NULL
95864 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
95865 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
95866 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
95867 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
95868 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
95869 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
95870 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
95871 +mpeg_read_6708 mpeg_read 3 6708 NULL
95872 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
95873 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
95874 +sky2_receive_13407 sky2_receive 2 13407 NULL
95875 +krealloc_14908 krealloc 2 14908 NULL
95876 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
95877 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
95878 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
95879 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
95880 +video_proc_write_6724 video_proc_write 3 6724 NULL
95881 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
95882 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
95883 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
95884 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
95885 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
95886 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
95887 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
95888 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
95889 +command_file_write_31318 command_file_write 3 31318 NULL
95890 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
95891 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
95892 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
95893 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
95894 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
95895 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
95896 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
95897 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
95898 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
95899 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
95900 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
95901 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
95902 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
95903 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
95904 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
95905 +int_proc_write_39542 int_proc_write 3 39542 NULL
95906 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
95907 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
95908 +read_file_ani_23161 read_file_ani 3 23161 NULL
95909 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
95910 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
95911 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
95912 +pp_write_39554 pp_write 3 39554 NULL
95913 +ioremap_23172 ioremap 1-2 23172 NULL
95914 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
95915 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
95916 +usblp_write_23178 usblp_write 3 23178 NULL
95917 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
95918 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
95919 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
95920 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
95921 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
95922 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
95923 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
95924 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
95925 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
95926 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
95927 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
95928 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
95929 +__team_options_register_63941 __team_options_register 3 63941 NULL
95930 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
95931 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
95932 +rvmalloc_46873 rvmalloc 1 46873 NULL
95933 +vmap_15025 vmap 2 15025 NULL
95934 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
95935 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
95936 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
95937 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
95938 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
95939 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
95940 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
95941 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
95942 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
95943 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
95944 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
95945 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
95946 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
95947 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
95948 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
95949 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
95950 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
95951 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
95952 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
95953 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
95954 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
95955 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
95956 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
95957 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
95958 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
95959 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
95960 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
95961 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
95962 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
95963 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
95964 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
95965 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
95966 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
95967 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
95968 +alg_setkey_31485 alg_setkey 3 31485 NULL
95969 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
95970 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
95971 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
95972 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
95973 +vhci_read_47878 vhci_read 3 47878 NULL
95974 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
95975 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
95976 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
95977 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
95978 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
95979 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
95980 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
95981 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
95982 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
95983 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
95984 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
95985 +timeout_read_47915 timeout_read 3 47915 NULL
95986 +hidraw_write_31536 hidraw_write 3 31536 NULL
95987 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
95988 +page_readlink_23346 page_readlink 3 23346 NULL
95989 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
95990 +comedi_write_47926 comedi_write 3 47926 NULL
95991 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
95992 +dsp_write_46218 dsp_write 2 46218 NULL
95993 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
95994 +usbvision_read_31555 usbvision_read 3 31555 NULL
95995 +pd_video_read_24510 pd_video_read 3 24510 NULL
95996 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
95997 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
95998 +request_key_async_6990 request_key_async 4 6990 NULL
95999 +ts_write_64336 ts_write 3 64336 NULL
96000 +handle_response_55951 handle_response 5 55951 NULL
96001 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
96002 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
96003 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
96004 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
96005 +osst_write_31581 osst_write 3 31581 NULL
96006 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
96007 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
96008 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
96009 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
96010 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
96011 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
96012 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
96013 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
96014 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
96015 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
96016 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
96017 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
96018 +ilo_write_64378 ilo_write 3 64378 NULL
96019 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
96020 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
96021 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
96022 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
96023 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
96024 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
96025 +copy_from_user_17559 copy_from_user 3 17559 NULL
96026 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
96027 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
96028 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
96029 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
96030 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
96031 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
96032 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
96033 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
96034 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
96035 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
96036 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
96037 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
96038 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
96039 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
96040 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
96041 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
96042 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
96043 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
96044 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
96045 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
96046 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
96047 +__lgread_31668 __lgread 4 31668 NULL
96048 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
96049 +fd_copyin_56247 fd_copyin 3 56247 NULL
96050 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
96051 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
96052 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
96053 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
96054 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
96055 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
96056 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
96057 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
96058 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
96059 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
96060 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
96061 +event_filter_read_23494 event_filter_read 3 23494 NULL
96062 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
96063 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
96064 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
96065 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
96066 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
96067 +pkt_add_39897 pkt_add 3 39897 NULL
96068 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
96069 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
96070 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
96071 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
96072 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
96073 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
96074 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
96075 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
96076 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
96077 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
96078 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
96079 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
96080 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
96081 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
96082 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
96083 +remove_uuid_64505 remove_uuid 4 64505 NULL
96084 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
96085 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
96086 +create_table_16213 create_table 2 16213 NULL
96087 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
96088 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
96089 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
96090 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
96091 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
96092 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
96093 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
96094 +set_discoverable_48141 set_discoverable 4 48141 NULL
96095 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
96096 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
96097 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
96098 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
96099 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
96100 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
96101 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
96102 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
96103 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
96104 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
96105 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
96106 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
96107 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
96108 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
96109 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
96110 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
96111 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
96112 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
96113 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
96114 +dev_read_56369 dev_read 3 56369 NULL
96115 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
96116 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
96117 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
96118 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
96119 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
96120 +init_ipath_48187 init_ipath 1 48187 NULL
96121 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
96122 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
96123 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
96124 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
96125 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
96126 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
96127 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
96128 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
96129 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
96130 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
96131 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
96132 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
96133 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
96134 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
96135 +use_pool_64607 use_pool 2 64607 NULL
96136 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
96137 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
96138 +store_msg_56417 store_msg 3 56417 NULL
96139 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
96140 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
96141 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
96142 +read_file_recv_48232 read_file_recv 3 48232 NULL
96143 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
96144 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
96145 +fanotify_write_64623 fanotify_write 3 64623 NULL
96146 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
96147 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
96148 +fl_create_56435 fl_create 5 56435 NULL
96149 +gnttab_map_56439 gnttab_map 2 56439 NULL
96150 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
96151 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
96152 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
96153 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
96154 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
96155 +set_connectable_56458 set_connectable 4 56458 NULL
96156 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
96157 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
96158 +add_port_54941 add_port 2 54941 NULL
96159 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
96160 +cx18_read_23699 cx18_read 3 23699 NULL
96161 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
96162 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
96163 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
96164 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
96165 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
96166 +send_set_info_48288 send_set_info 7 48288 NULL
96167 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
96168 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
96169 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
96170 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
96171 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
96172 +new_dir_31919 new_dir 3 31919 NULL
96173 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
96174 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
96175 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
96176 +mgmt_control_7349 mgmt_control 3 7349 NULL
96177 +hash_setkey_48310 hash_setkey 3 48310 NULL
96178 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
96179 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
96180 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
96181 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
96182 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
96183 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
96184 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
96185 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
96186 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
96187 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
96188 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
96189 +vb2_write_31948 vb2_write 3 31948 NULL
96190 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
96191 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
96192 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
96193 +ip_options_get_56538 ip_options_get 4 56538 NULL
96194 +write_62671 write 3 62671 NULL
96195 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
96196 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
96197 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
96198 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
96199 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
96200 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
96201 +skb_add_data_48363 skb_add_data 3 48363 NULL
96202 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
96203 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
96204 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
96205 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
96206 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
96207 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
96208 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
96209 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
96210 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
96211 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
96212 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
96213 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
96214 +system_enable_read_25815 system_enable_read 3 25815 NULL
96215 +allocate_probes_40204 allocate_probes 1 40204 NULL
96216 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
96217 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
96218 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
96219 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
96220 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
96221 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
96222 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
96223 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
96224 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
96225 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
96226 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
96227 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
96228 +fs_path_add_15648 fs_path_add 3 15648 NULL
96229 +event_filter_write_56609 event_filter_write 3 56609 NULL
96230 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
96231 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
96232 +xsd_read_15653 xsd_read 3 15653 NULL
96233 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
96234 +p54_init_common_23850 p54_init_common 1 23850 NULL
96235 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
96236 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
96237 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
96238 +garp_request_join_7471 garp_request_join 4 7471 NULL
96239 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
96240 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
96241 +unifi_read_14899 unifi_read 3 14899 NULL
96242 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
96243 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
96244 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
96245 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
96246 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
96247 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
96248 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
96249 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
96250 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
96251 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
96252 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
96253 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
96254 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
96255 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
96256 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
96257 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
96258 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
96259 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
96260 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
96261 +bio_alloc_32095 bio_alloc 2 32095 NULL
96262 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
96263 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
96264 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
96265 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
96266 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
96267 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
96268 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
96269 +send_control_msg_48498 send_control_msg 6 48498 NULL
96270 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
96271 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
96272 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
96273 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
96274 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
96275 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
96276 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
96277 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
96278 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
96279 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
96280 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
96281 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
96282 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
96283 +alloc_tx_32143 alloc_tx 2 32143 NULL
96284 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
96285 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
96286 +hsc_write_55875 hsc_write 3 55875 NULL
96287 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
96288 +do_test_15766 do_test 1 15766 NULL
96289 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
96290 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
96291 +named_distribute_48544 named_distribute 4 48544 NULL
96292 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
96293 +venus_link_32165 venus_link 5 32165 NULL
96294 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
96295 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
96296 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
96297 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
96298 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
96299 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
96300 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
96301 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
96302 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
96303 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
96304 +groups_alloc_7614 groups_alloc 1 7614 NULL
96305 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
96306 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
96307 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
96308 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
96309 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
96310 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
96311 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
96312 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
96313 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
96314 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
96315 +snapshot_write_28351 snapshot_write 3 28351 NULL
96316 +event_enable_read_7074 event_enable_read 3 7074 NULL
96317 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
96318 +do_syslog_56807 do_syslog 3 56807 NULL
96319 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
96320 +pskb_pull_65005 pskb_pull 2 65005 NULL
96321 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
96322 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
96323 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
96324 +unifi_write_65012 unifi_write 3 65012 NULL
96325 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
96326 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
96327 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
96328 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
96329 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
96330 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
96331 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
96332 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
96333 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
96334 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
96335 +if_write_51756 if_write 3 51756 NULL
96336 +insert_dent_65034 insert_dent 7 65034 NULL
96337 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
96338 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
96339 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
96340 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
96341 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
96342 +lc_create_48662 lc_create 3 48662 NULL
96343 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
96344 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
96345 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
96346 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
96347 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
96348 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
96349 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
96350 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
96351 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
96352 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
96353 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
96354 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
96355 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
96356 +altera_drscan_48698 altera_drscan 2 48698 NULL
96357 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
96358 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
96359 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
96360 +power_read_15939 power_read 3 15939 NULL
96361 +recv_msg_48709 recv_msg 4 48709 NULL
96362 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
96363 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
96364 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
96365 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
96366 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
96367 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
96368 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
96369 +revalidate_19043 revalidate 2 19043 NULL
96370 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
96371 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
96372 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
96373 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
96374 +check_header_56930 check_header 2 56930 NULL
96375 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
96376 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
96377 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
96378 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
96379 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
96380 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
96381 +frame_alloc_15981 frame_alloc 4 15981 NULL
96382 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
96383 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
96384 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
96385 +adu_read_24177 adu_read 3 24177 NULL
96386 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
96387 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
96388 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
96389 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
96390 +vfd_write_14717 vfd_write 3 14717 NULL
96391 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
96392 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
96393 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
96394 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
96395 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
96396 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
96397 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
96398 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
96399 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
96400 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
96401 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
96402 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
96403 +register_device_60015 register_device 2-3 60015 NULL
96404 +got_frame_16028 got_frame 2 16028 NULL
96405 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
96406 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
96407 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
96408 +scsi_register_49094 scsi_register 2 49094 NULL
96409 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
96410 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
96411 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
96412 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
96413 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
96414 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
96415 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
96416 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
96417 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
96418 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
96419 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
96420 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
96421 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
96422 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
96423 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
96424 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
96425 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
96426 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
96427 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
96428 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
96429 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
96430 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
96431 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
96432 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
96433 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
96434 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
96435 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
96436 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
96437 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
96438 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
96439 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
96440 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
96441 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
96442 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
96443 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
96444 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
96445 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
96446 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
96447 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
96448 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
96449 +fsm_init_16134 fsm_init 2 16134 NULL
96450 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
96451 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
96452 +disconnect_32521 disconnect 4 32521 NULL
96453 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
96454 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
96455 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
96456 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
96457 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
96458 +ilo_read_32531 ilo_read 3 32531 NULL
96459 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
96460 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
96461 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
96462 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
96463 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
96464 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
96465 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
96466 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
96467 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
96468 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
96469 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
96470 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
96471 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
96472 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
96473 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
96474 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
96475 +card_send_command_40757 card_send_command 3 40757 NULL
96476 +sys_mbind_7990 sys_mbind 5 7990 NULL
96477 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
96478 +pg_write_40766 pg_write 3 40766 NULL
96479 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
96480 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
96481 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
96482 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
96483 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
96484 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
96485 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
96486 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
96487 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
96488 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
96489 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
96490 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
96491 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
96492 +vcs_read_8017 vcs_read 3 8017 NULL
96493 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
96494 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
96495 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
96496 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
96497 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
96498 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
96499 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
96500 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
96501 +copy_and_check_19089 copy_and_check 3 19089 NULL
96502 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
96503 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
96504 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
96505 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
96506 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
96507 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
96508 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
96509 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
96510 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
96511 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
96512 +smk_user_access_24440 smk_user_access 3 24440 NULL
96513 +xd_rw_49020 xd_rw 3-4 49020 NULL
96514 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
96515 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
96516 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
96517 +kvmalloc_32646 kvmalloc 1 32646 NULL
96518 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
96519 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
96520 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
96521 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
96522 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
96523 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
96524 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
96525 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
96526 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
96527 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
96528 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
96529 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
96530 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
96531 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
96532 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
96533 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
96534 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
96535 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
96536 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
96537 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
96538 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
96539 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
96540 +venus_lookup_8121 venus_lookup 4 8121 NULL
96541 +compat_writev_60063 compat_writev 3 60063 NULL
96542 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
96543 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
96544 +read_file_queue_40895 read_file_queue 3 40895 NULL
96545 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
96546 +waiters_read_40902 waiters_read 3 40902 NULL
96547 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
96548 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
96549 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
96550 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
96551 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
96552 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
96553 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
96554 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
96555 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
96556 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
96557 +alloc_dr_65495 alloc_dr 2 65495 NULL
96558 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
96559 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
96560 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
96561 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
96562 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
96563 +rbd_add_16366 rbd_add 3 16366 NULL
96564 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
96565 +pt_read_49136 pt_read 3 49136 NULL
96566 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
96567 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
96568 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
96569 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
96570 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
96571 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
96572 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
96573 new file mode 100644
96574 index 0000000..838ea58
96575 --- /dev/null
96576 +++ b/tools/gcc/size_overflow_plugin.c
96577 @@ -0,0 +1,1936 @@
96578 +/*
96579 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
96580 + * Licensed under the GPL v2, or (at your option) v3
96581 + *
96582 + * Homepage:
96583 + * http://www.grsecurity.net/~ephox/overflow_plugin/
96584 + *
96585 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
96586 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
96587 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
96588 + *
96589 + * Usage:
96590 + * $ 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
96591 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
96592 + */
96593 +
96594 +#include "gcc-plugin.h"
96595 +#include "config.h"
96596 +#include "system.h"
96597 +#include "coretypes.h"
96598 +#include "tree.h"
96599 +#include "tree-pass.h"
96600 +#include "intl.h"
96601 +#include "plugin-version.h"
96602 +#include "tm.h"
96603 +#include "toplev.h"
96604 +#include "function.h"
96605 +#include "tree-flow.h"
96606 +#include "plugin.h"
96607 +#include "gimple.h"
96608 +#include "diagnostic.h"
96609 +#include "cfgloop.h"
96610 +
96611 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2(EXP)
96612 +
96613 +#if BUILDING_GCC_VERSION >= 4008
96614 +#define TODO_dump_func 0
96615 +#endif
96616 +
96617 +struct size_overflow_hash {
96618 + const struct size_overflow_hash * const next;
96619 + const char * const name;
96620 + const unsigned int param;
96621 +};
96622 +
96623 +#include "size_overflow_hash.h"
96624 +
96625 +enum marked {
96626 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
96627 +};
96628 +
96629 +static unsigned int call_count = 0;
96630 +
96631 +#define __unused __attribute__((__unused__))
96632 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
96633 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
96634 +#define BEFORE_STMT true
96635 +#define AFTER_STMT false
96636 +#define CREATE_NEW_VAR NULL_TREE
96637 +#define CODES_LIMIT 32
96638 +#define MAX_PARAM 32
96639 +#define MY_STMT GF_PLF_1
96640 +#define NO_CAST_CHECK GF_PLF_2
96641 +
96642 +#if BUILDING_GCC_VERSION == 4005
96643 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
96644 +#endif
96645 +
96646 +int plugin_is_GPL_compatible;
96647 +void debug_gimple_stmt(gimple gs);
96648 +
96649 +static tree expand(struct pointer_set_t *visited, tree lhs);
96650 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
96651 +static tree report_size_overflow_decl;
96652 +static const_tree const_char_ptr_type_node;
96653 +static unsigned int handle_function(void);
96654 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
96655 +static tree get_size_overflow_type(gimple stmt, const_tree node);
96656 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
96657 +
96658 +static struct plugin_info size_overflow_plugin_info = {
96659 + .version = "20130109beta",
96660 + .help = "no-size-overflow\tturn off size overflow checking\n",
96661 +};
96662 +
96663 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
96664 +{
96665 + unsigned int arg_count;
96666 + enum tree_code code = TREE_CODE(*node);
96667 +
96668 + switch (code) {
96669 + case FUNCTION_DECL:
96670 + arg_count = type_num_arguments(TREE_TYPE(*node));
96671 + break;
96672 + case FUNCTION_TYPE:
96673 + case METHOD_TYPE:
96674 + arg_count = type_num_arguments(*node);
96675 + break;
96676 + default:
96677 + *no_add_attrs = true;
96678 + error("%s: %qE attribute only applies to functions", __func__, name);
96679 + return NULL_TREE;
96680 + }
96681 +
96682 + for (; args; args = TREE_CHAIN(args)) {
96683 + tree position = TREE_VALUE(args);
96684 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
96685 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
96686 + *no_add_attrs = true;
96687 + }
96688 + }
96689 + return NULL_TREE;
96690 +}
96691 +
96692 +static const char* get_asm_name(tree node)
96693 +{
96694 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
96695 +}
96696 +
96697 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
96698 +{
96699 + unsigned int arg_count, arg_num;
96700 + enum tree_code code = TREE_CODE(*node);
96701 +
96702 + switch (code) {
96703 + case FUNCTION_DECL:
96704 + arg_count = type_num_arguments(TREE_TYPE(*node));
96705 + break;
96706 + case FUNCTION_TYPE:
96707 + case METHOD_TYPE:
96708 + arg_count = type_num_arguments(*node);
96709 + break;
96710 + case FIELD_DECL:
96711 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
96712 + if (arg_num != 0) {
96713 + *no_add_attrs = true;
96714 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
96715 + }
96716 + return NULL_TREE;
96717 + default:
96718 + *no_add_attrs = true;
96719 + error("%qE attribute only applies to functions", name);
96720 + return NULL_TREE;
96721 + }
96722 +
96723 + for (; args; args = TREE_CHAIN(args)) {
96724 + tree position = TREE_VALUE(args);
96725 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
96726 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
96727 + *no_add_attrs = true;
96728 + }
96729 + }
96730 + return NULL_TREE;
96731 +}
96732 +
96733 +static struct attribute_spec size_overflow_attr = {
96734 + .name = "size_overflow",
96735 + .min_length = 1,
96736 + .max_length = -1,
96737 + .decl_required = true,
96738 + .type_required = false,
96739 + .function_type_required = false,
96740 + .handler = handle_size_overflow_attribute,
96741 +#if BUILDING_GCC_VERSION >= 4007
96742 + .affects_type_identity = false
96743 +#endif
96744 +};
96745 +
96746 +static struct attribute_spec intentional_overflow_attr = {
96747 + .name = "intentional_overflow",
96748 + .min_length = 1,
96749 + .max_length = -1,
96750 + .decl_required = true,
96751 + .type_required = false,
96752 + .function_type_required = false,
96753 + .handler = handle_intentional_overflow_attribute,
96754 +#if BUILDING_GCC_VERSION >= 4007
96755 + .affects_type_identity = false
96756 +#endif
96757 +};
96758 +
96759 +static void register_attributes(void __unused *event_data, void __unused *data)
96760 +{
96761 + register_attribute(&size_overflow_attr);
96762 + register_attribute(&intentional_overflow_attr);
96763 +}
96764 +
96765 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
96766 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
96767 +{
96768 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
96769 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
96770 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
96771 +
96772 + unsigned int m = 0x57559429;
96773 + unsigned int n = 0x5052acdb;
96774 + const unsigned int *key4 = (const unsigned int *)key;
96775 + unsigned int h = len;
96776 + unsigned int k = len + seed + n;
96777 + unsigned long long p;
96778 +
96779 + while (len >= 8) {
96780 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
96781 + len -= 8;
96782 + }
96783 + if (len >= 4) {
96784 + cwmixb(key4[0]) key4 += 1;
96785 + len -= 4;
96786 + }
96787 + if (len)
96788 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
96789 + cwmixb(h ^ (k + n));
96790 + return k ^ h;
96791 +
96792 +#undef cwfold
96793 +#undef cwmixa
96794 +#undef cwmixb
96795 +}
96796 +
96797 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
96798 +{
96799 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
96800 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
96801 + return fn ^ codes;
96802 +}
96803 +
96804 +static inline tree get_original_function_decl(tree fndecl)
96805 +{
96806 + if (DECL_ABSTRACT_ORIGIN(fndecl))
96807 + return DECL_ABSTRACT_ORIGIN(fndecl);
96808 + return fndecl;
96809 +}
96810 +
96811 +static inline gimple get_def_stmt(const_tree node)
96812 +{
96813 + gcc_assert(node != NULL_TREE);
96814 + gcc_assert(TREE_CODE(node) == SSA_NAME);
96815 + return SSA_NAME_DEF_STMT(node);
96816 +}
96817 +
96818 +static unsigned char get_tree_code(const_tree type)
96819 +{
96820 + switch (TREE_CODE(type)) {
96821 + case ARRAY_TYPE:
96822 + return 0;
96823 + case BOOLEAN_TYPE:
96824 + return 1;
96825 + case ENUMERAL_TYPE:
96826 + return 2;
96827 + case FUNCTION_TYPE:
96828 + return 3;
96829 + case INTEGER_TYPE:
96830 + return 4;
96831 + case POINTER_TYPE:
96832 + return 5;
96833 + case RECORD_TYPE:
96834 + return 6;
96835 + case UNION_TYPE:
96836 + return 7;
96837 + case VOID_TYPE:
96838 + return 8;
96839 + case REAL_TYPE:
96840 + return 9;
96841 + case VECTOR_TYPE:
96842 + return 10;
96843 + case REFERENCE_TYPE:
96844 + return 11;
96845 + case OFFSET_TYPE:
96846 + return 12;
96847 + case COMPLEX_TYPE:
96848 + return 13;
96849 + default:
96850 + debug_tree((tree)type);
96851 + gcc_unreachable();
96852 + }
96853 +}
96854 +
96855 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
96856 +{
96857 + gcc_assert(type != NULL_TREE);
96858 +
96859 + while (type && len < CODES_LIMIT) {
96860 + tree_codes[len] = get_tree_code(type);
96861 + len++;
96862 + type = TREE_TYPE(type);
96863 + }
96864 + return len;
96865 +}
96866 +
96867 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
96868 +{
96869 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
96870 + enum tree_code code = TREE_CODE(type);
96871 + size_t len = 0;
96872 +
96873 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
96874 +
96875 + arg = TYPE_ARG_TYPES(type);
96876 + // skip builtins __builtin_constant_p
96877 + if (!arg && DECL_BUILT_IN(fndecl))
96878 + return 0;
96879 +
96880 + if (TREE_CODE_CLASS(code) == tcc_type)
96881 + result = type;
96882 + else
96883 + result = DECL_RESULT(fndecl);
96884 +
96885 + gcc_assert(result != NULL_TREE);
96886 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
96887 +
96888 + if (arg == NULL_TREE) {
96889 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
96890 + arg_field = DECL_ARGUMENT_FLD(fndecl);
96891 + if (arg_field == NULL_TREE)
96892 + return 0;
96893 + arg = TREE_TYPE(arg_field);
96894 + len = add_type_codes(arg, tree_codes, len);
96895 + gcc_assert(len != 0);
96896 + return len;
96897 + }
96898 +
96899 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
96900 + while (arg && len < CODES_LIMIT) {
96901 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
96902 + arg = TREE_CHAIN(arg);
96903 + }
96904 +
96905 + gcc_assert(len != 0);
96906 + return len;
96907 +}
96908 +
96909 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
96910 +{
96911 + unsigned int hash;
96912 + const struct size_overflow_hash *entry;
96913 + unsigned char tree_codes[CODES_LIMIT];
96914 + size_t len;
96915 + const char *func_name = get_asm_name(fndecl);
96916 +
96917 + len = get_function_decl(fndecl, tree_codes);
96918 + if (len == 0)
96919 + return NULL;
96920 +
96921 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
96922 +
96923 + entry = size_overflow_hash[hash];
96924 + while (entry) {
96925 + if (!strcmp(entry->name, func_name))
96926 + return entry;
96927 + entry = entry->next;
96928 + }
96929 +
96930 + return NULL;
96931 +}
96932 +
96933 +static void check_arg_type(const_tree arg)
96934 +{
96935 + const_tree type = TREE_TYPE(arg);
96936 + enum tree_code code = TREE_CODE(type);
96937 +
96938 + if (code == BOOLEAN_TYPE)
96939 + return;
96940 +
96941 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
96942 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
96943 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
96944 +}
96945 +
96946 +static unsigned int find_arg_number(const_tree arg, tree func)
96947 +{
96948 + tree var;
96949 + unsigned int argnum = 1;
96950 +
96951 + if (TREE_CODE(arg) == SSA_NAME)
96952 + arg = SSA_NAME_VAR(arg);
96953 +
96954 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
96955 + if (strcmp(NAME(arg), NAME(var))) {
96956 + argnum++;
96957 + continue;
96958 + }
96959 + check_arg_type(var);
96960 + return argnum;
96961 + }
96962 + gcc_unreachable();
96963 +}
96964 +
96965 +static tree create_new_var(tree type)
96966 +{
96967 + tree new_var = create_tmp_var(type, "cicus");
96968 +
96969 +#if BUILDING_GCC_VERSION <= 4007
96970 + add_referenced_var(new_var);
96971 + mark_sym_for_renaming(new_var);
96972 +#endif
96973 + return new_var;
96974 +}
96975 +
96976 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
96977 +{
96978 + gimple assign;
96979 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
96980 + tree type = TREE_TYPE(rhs1);
96981 + tree lhs = create_new_var(type);
96982 +
96983 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
96984 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
96985 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
96986 +
96987 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
96988 + update_stmt(assign);
96989 + gimple_set_plf(assign, MY_STMT, true);
96990 + return assign;
96991 +}
96992 +
96993 +static bool is_bool(const_tree node)
96994 +{
96995 + const_tree type;
96996 +
96997 + if (node == NULL_TREE)
96998 + return false;
96999 +
97000 + type = TREE_TYPE(node);
97001 + if (!INTEGRAL_TYPE_P(type))
97002 + return false;
97003 + if (TREE_CODE(type) == BOOLEAN_TYPE)
97004 + return true;
97005 + if (TYPE_PRECISION(type) == 1)
97006 + return true;
97007 + return false;
97008 +}
97009 +
97010 +static tree cast_a_tree(tree type, tree var)
97011 +{
97012 + gcc_assert(type != NULL_TREE);
97013 + gcc_assert(var != NULL_TREE);
97014 + gcc_assert(fold_convertible_p(type, var));
97015 +
97016 + return fold_convert(type, var);
97017 +}
97018 +
97019 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
97020 +{
97021 + gimple assign;
97022 +
97023 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
97024 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
97025 + gcc_unreachable();
97026 +
97027 + if (lhs == CREATE_NEW_VAR)
97028 + lhs = create_new_var(dst_type);
97029 +
97030 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
97031 +
97032 + if (!gsi_end_p(*gsi)) {
97033 + location_t loc = gimple_location(gsi_stmt(*gsi));
97034 + gimple_set_location(assign, loc);
97035 + }
97036 +
97037 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
97038 +
97039 + if (before)
97040 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
97041 + else
97042 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
97043 + update_stmt(assign);
97044 + gimple_set_plf(assign, MY_STMT, true);
97045 +
97046 + return assign;
97047 +}
97048 +
97049 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
97050 +{
97051 + gimple assign;
97052 + gimple_stmt_iterator gsi;
97053 +
97054 + if (rhs == NULL_TREE)
97055 + return NULL_TREE;
97056 +
97057 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
97058 + return rhs;
97059 +
97060 + gsi = gsi_for_stmt(stmt);
97061 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
97062 + gimple_set_plf(assign, MY_STMT, true);
97063 + return gimple_get_lhs(assign);
97064 +}
97065 +
97066 +static tree cast_to_TI_type(gimple stmt, tree node)
97067 +{
97068 + gimple_stmt_iterator gsi;
97069 + gimple cast_stmt;
97070 + tree type = TREE_TYPE(node);
97071 +
97072 + if (types_compatible_p(type, intTI_type_node))
97073 + return node;
97074 +
97075 + gsi = gsi_for_stmt(stmt);
97076 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
97077 + gimple_set_plf(cast_stmt, MY_STMT, true);
97078 + return gimple_get_lhs(cast_stmt);
97079 +}
97080 +
97081 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
97082 +{
97083 + tree lhs;
97084 + gimple_stmt_iterator gsi;
97085 +
97086 + if (rhs1 == NULL_TREE) {
97087 + debug_gimple_stmt(oldstmt);
97088 + error("%s: rhs1 is NULL_TREE", __func__);
97089 + gcc_unreachable();
97090 + }
97091 +
97092 + switch (gimple_code(oldstmt)) {
97093 + case GIMPLE_ASM:
97094 + lhs = rhs1;
97095 + break;
97096 + case GIMPLE_CALL:
97097 + lhs = gimple_call_lhs(oldstmt);
97098 + break;
97099 + case GIMPLE_ASSIGN:
97100 + lhs = gimple_get_lhs(oldstmt);
97101 + break;
97102 + default:
97103 + debug_gimple_stmt(oldstmt);
97104 + gcc_unreachable();
97105 + }
97106 +
97107 + gsi = gsi_for_stmt(oldstmt);
97108 + pointer_set_insert(visited, oldstmt);
97109 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
97110 + basic_block next_bb, cur_bb;
97111 + const_edge e;
97112 +
97113 + gcc_assert(before == false);
97114 + gcc_assert(stmt_can_throw_internal(oldstmt));
97115 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
97116 + gcc_assert(!gsi_end_p(gsi));
97117 +
97118 + cur_bb = gimple_bb(oldstmt);
97119 + next_bb = cur_bb->next_bb;
97120 + e = find_edge(cur_bb, next_bb);
97121 + gcc_assert(e != NULL);
97122 + gcc_assert(e->flags & EDGE_FALLTHRU);
97123 +
97124 + gsi = gsi_after_labels(next_bb);
97125 + gcc_assert(!gsi_end_p(gsi));
97126 +
97127 + before = true;
97128 + oldstmt = gsi_stmt(gsi);
97129 + }
97130 +
97131 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
97132 +}
97133 +
97134 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
97135 +{
97136 + gimple stmt;
97137 + gimple_stmt_iterator gsi;
97138 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
97139 +
97140 + if (gimple_plf(oldstmt, MY_STMT))
97141 + return lhs;
97142 +
97143 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
97144 + rhs1 = gimple_assign_rhs1(oldstmt);
97145 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
97146 + }
97147 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
97148 + rhs2 = gimple_assign_rhs2(oldstmt);
97149 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
97150 + }
97151 +
97152 + stmt = gimple_copy(oldstmt);
97153 + gimple_set_location(stmt, gimple_location(oldstmt));
97154 + gimple_set_plf(stmt, MY_STMT, true);
97155 +
97156 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
97157 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
97158 +
97159 + size_overflow_type = get_size_overflow_type(oldstmt, node);
97160 +
97161 + if (is_bool(lhs))
97162 + new_var = SSA_NAME_VAR(lhs);
97163 + else
97164 + new_var = create_new_var(size_overflow_type);
97165 + new_var = make_ssa_name(new_var, stmt);
97166 + gimple_set_lhs(stmt, new_var);
97167 +
97168 + if (rhs1 != NULL_TREE)
97169 + gimple_assign_set_rhs1(stmt, rhs1);
97170 +
97171 + if (rhs2 != NULL_TREE)
97172 + gimple_assign_set_rhs2(stmt, rhs2);
97173 +#if BUILDING_GCC_VERSION >= 4007
97174 + if (rhs3 != NULL_TREE)
97175 + gimple_assign_set_rhs3(stmt, rhs3);
97176 +#endif
97177 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
97178 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
97179 +
97180 + gsi = gsi_for_stmt(oldstmt);
97181 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
97182 + update_stmt(stmt);
97183 + pointer_set_insert(visited, oldstmt);
97184 + return gimple_get_lhs(stmt);
97185 +}
97186 +
97187 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
97188 +{
97189 + basic_block bb;
97190 + gimple phi;
97191 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
97192 + gimple_seq seq;
97193 +
97194 + bb = gsi_bb(gsi);
97195 +
97196 + phi = create_phi_node(result, bb);
97197 + seq = phi_nodes(bb);
97198 + gsi = gsi_last(seq);
97199 + gsi_remove(&gsi, false);
97200 +
97201 + gsi = gsi_for_stmt(oldstmt);
97202 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
97203 + gimple_set_bb(phi, bb);
97204 + gimple_set_plf(phi, MY_STMT, true);
97205 + return phi;
97206 +}
97207 +
97208 +static basic_block create_a_first_bb(void)
97209 +{
97210 + basic_block first_bb;
97211 +
97212 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
97213 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
97214 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
97215 + return first_bb;
97216 +}
97217 +
97218 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
97219 +{
97220 + basic_block bb;
97221 + const_gimple newstmt;
97222 + gimple_stmt_iterator gsi;
97223 + bool before = BEFORE_STMT;
97224 +
97225 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
97226 + gsi = gsi_for_stmt(get_def_stmt(arg));
97227 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
97228 + return gimple_get_lhs(newstmt);
97229 + }
97230 +
97231 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
97232 + gsi = gsi_after_labels(bb);
97233 + if (bb->index == 0) {
97234 + bb = create_a_first_bb();
97235 + gsi = gsi_start_bb(bb);
97236 + }
97237 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
97238 + return gimple_get_lhs(newstmt);
97239 +}
97240 +
97241 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
97242 +{
97243 + gimple newstmt;
97244 + gimple_stmt_iterator gsi;
97245 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
97246 + gimple def_newstmt = get_def_stmt(new_rhs);
97247 +
97248 + gsi_insert = gsi_insert_after;
97249 + gsi = gsi_for_stmt(def_newstmt);
97250 +
97251 + switch (gimple_code(get_def_stmt(arg))) {
97252 + case GIMPLE_PHI:
97253 + newstmt = gimple_build_assign(new_var, new_rhs);
97254 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
97255 + gsi_insert = gsi_insert_before;
97256 + break;
97257 + case GIMPLE_ASM:
97258 + case GIMPLE_CALL:
97259 + newstmt = gimple_build_assign(new_var, new_rhs);
97260 + break;
97261 + case GIMPLE_ASSIGN:
97262 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
97263 + break;
97264 + default:
97265 + /* unknown gimple_code (handle_build_new_phi_arg) */
97266 + gcc_unreachable();
97267 + }
97268 +
97269 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
97270 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
97271 + gimple_set_plf(newstmt, MY_STMT, true);
97272 + update_stmt(newstmt);
97273 + return newstmt;
97274 +}
97275 +
97276 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
97277 +{
97278 + const_gimple newstmt;
97279 + gimple def_stmt;
97280 + tree new_rhs;
97281 +
97282 + new_rhs = expand(visited, arg);
97283 + if (new_rhs == NULL_TREE)
97284 + return NULL_TREE;
97285 +
97286 + def_stmt = get_def_stmt(new_rhs);
97287 + if (gimple_code(def_stmt) == GIMPLE_NOP)
97288 + return NULL_TREE;
97289 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
97290 +
97291 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
97292 + return gimple_get_lhs(newstmt);
97293 +}
97294 +
97295 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
97296 +{
97297 + gimple phi, oldstmt = get_def_stmt(orig_result);
97298 + tree new_result, size_overflow_type;
97299 + unsigned int i;
97300 + unsigned int n = gimple_phi_num_args(oldstmt);
97301 +
97302 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
97303 +
97304 + new_result = create_new_var(size_overflow_type);
97305 +
97306 + pointer_set_insert(visited, oldstmt);
97307 + phi = overflow_create_phi_node(oldstmt, new_result);
97308 + for (i = 0; i < n; i++) {
97309 + tree arg, lhs;
97310 +
97311 + arg = gimple_phi_arg_def(oldstmt, i);
97312 + if (is_gimple_constant(arg))
97313 + arg = cast_a_tree(size_overflow_type, arg);
97314 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
97315 + if (lhs == NULL_TREE)
97316 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
97317 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
97318 + }
97319 +
97320 + update_stmt(phi);
97321 + return gimple_phi_result(phi);
97322 +}
97323 +
97324 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
97325 +{
97326 + const_gimple assign;
97327 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
97328 + tree origtype = TREE_TYPE(orig_rhs);
97329 +
97330 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
97331 +
97332 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
97333 + return gimple_get_lhs(assign);
97334 +}
97335 +
97336 +static void change_rhs1(gimple stmt, tree new_rhs1)
97337 +{
97338 + tree assign_rhs;
97339 + const_tree rhs = gimple_assign_rhs1(stmt);
97340 +
97341 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
97342 + gimple_assign_set_rhs1(stmt, assign_rhs);
97343 + update_stmt(stmt);
97344 +}
97345 +
97346 +static bool check_mode_type(const_gimple stmt)
97347 +{
97348 + const_tree lhs = gimple_get_lhs(stmt);
97349 + const_tree lhs_type = TREE_TYPE(lhs);
97350 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
97351 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
97352 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
97353 +
97354 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
97355 + return false;
97356 +
97357 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
97358 + return false;
97359 +
97360 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
97361 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
97362 + return false;
97363 +
97364 + return true;
97365 +}
97366 +
97367 +static bool check_undefined_integer_operation(const_gimple stmt)
97368 +{
97369 + const_gimple def_stmt;
97370 + const_tree lhs = gimple_get_lhs(stmt);
97371 + const_tree rhs1 = gimple_assign_rhs1(stmt);
97372 + const_tree rhs1_type = TREE_TYPE(rhs1);
97373 + const_tree lhs_type = TREE_TYPE(lhs);
97374 +
97375 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
97376 + return false;
97377 +
97378 + def_stmt = get_def_stmt(rhs1);
97379 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
97380 + return false;
97381 +
97382 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
97383 + return false;
97384 + return true;
97385 +}
97386 +
97387 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
97388 +{
97389 + const_tree rhs1, lhs, rhs1_type, lhs_type;
97390 + enum machine_mode lhs_mode, rhs_mode;
97391 + gimple def_stmt = get_def_stmt(no_const_rhs);
97392 +
97393 + if (!gimple_assign_cast_p(def_stmt))
97394 + return false;
97395 +
97396 + rhs1 = gimple_assign_rhs1(def_stmt);
97397 + lhs = gimple_get_lhs(def_stmt);
97398 + rhs1_type = TREE_TYPE(rhs1);
97399 + lhs_type = TREE_TYPE(lhs);
97400 + rhs_mode = TYPE_MODE(rhs1_type);
97401 + lhs_mode = TYPE_MODE(lhs_type);
97402 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
97403 + return false;
97404 +
97405 + return true;
97406 +}
97407 +
97408 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
97409 +{
97410 + tree rhs1 = gimple_assign_rhs1(stmt);
97411 + tree lhs = gimple_get_lhs(stmt);
97412 + const_tree rhs1_type = TREE_TYPE(rhs1);
97413 + const_tree lhs_type = TREE_TYPE(lhs);
97414 +
97415 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
97416 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97417 +
97418 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
97419 +}
97420 +
97421 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
97422 +{
97423 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
97424 + tree new_rhs1 = NULL_TREE;
97425 + tree rhs1 = gimple_assign_rhs1(stmt);
97426 + const_tree rhs1_type = TREE_TYPE(rhs1);
97427 + const_tree lhs_type = TREE_TYPE(lhs);
97428 +
97429 + if (gimple_plf(stmt, MY_STMT))
97430 + return lhs;
97431 +
97432 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
97433 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97434 +
97435 + new_rhs1 = expand(visited, rhs1);
97436 +
97437 + if (new_rhs1 == NULL_TREE)
97438 + return create_cast_assign(visited, stmt);
97439 +
97440 + if (gimple_plf(stmt, NO_CAST_CHECK))
97441 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
97442 +
97443 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
97444 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
97445 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
97446 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
97447 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97448 + }
97449 +
97450 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
97451 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
97452 +
97453 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
97454 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
97455 +
97456 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
97457 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
97458 +
97459 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
97460 +
97461 + change_rhs1(stmt, new_rhs1);
97462 +
97463 + if (!check_mode_type(stmt))
97464 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97465 +
97466 + size_overflow_type = get_size_overflow_type(stmt, lhs);
97467 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
97468 +
97469 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
97470 +
97471 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97472 +}
97473 +
97474 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
97475 +{
97476 + tree rhs1, lhs = gimple_get_lhs(stmt);
97477 + gimple def_stmt = get_def_stmt(lhs);
97478 +
97479 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
97480 + rhs1 = gimple_assign_rhs1(def_stmt);
97481 +
97482 + if (is_gimple_constant(rhs1))
97483 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
97484 +
97485 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
97486 + switch (TREE_CODE(rhs1)) {
97487 + case SSA_NAME:
97488 + return handle_unary_rhs(visited, def_stmt);
97489 + case ARRAY_REF:
97490 + case BIT_FIELD_REF:
97491 + case ADDR_EXPR:
97492 + case COMPONENT_REF:
97493 + case INDIRECT_REF:
97494 +#if BUILDING_GCC_VERSION >= 4006
97495 + case MEM_REF:
97496 +#endif
97497 + case TARGET_MEM_REF:
97498 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
97499 + case PARM_DECL:
97500 + case VAR_DECL:
97501 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97502 +
97503 + default:
97504 + debug_gimple_stmt(def_stmt);
97505 + debug_tree(rhs1);
97506 + gcc_unreachable();
97507 + }
97508 +}
97509 +
97510 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
97511 +{
97512 + gimple cond_stmt;
97513 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
97514 +
97515 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
97516 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
97517 + update_stmt(cond_stmt);
97518 +}
97519 +
97520 +static tree create_string_param(tree string)
97521 +{
97522 + tree i_type, a_type;
97523 + const int length = TREE_STRING_LENGTH(string);
97524 +
97525 + gcc_assert(length > 0);
97526 +
97527 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
97528 + a_type = build_array_type(char_type_node, i_type);
97529 +
97530 + TREE_TYPE(string) = a_type;
97531 + TREE_CONSTANT(string) = 1;
97532 + TREE_READONLY(string) = 1;
97533 +
97534 + return build1(ADDR_EXPR, ptr_type_node, string);
97535 +}
97536 +
97537 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
97538 +{
97539 + gimple func_stmt;
97540 + const_gimple def_stmt;
97541 + const_tree loc_line;
97542 + tree loc_file, ssa_name, current_func;
97543 + expanded_location xloc;
97544 + char *ssa_name_buf;
97545 + int len;
97546 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
97547 +
97548 + def_stmt = get_def_stmt(arg);
97549 + xloc = expand_location(gimple_location(def_stmt));
97550 +
97551 + if (!gimple_has_location(def_stmt)) {
97552 + xloc = expand_location(gimple_location(stmt));
97553 + if (!gimple_has_location(stmt))
97554 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
97555 + }
97556 +
97557 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
97558 +
97559 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
97560 + loc_file = create_string_param(loc_file);
97561 +
97562 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
97563 + current_func = create_string_param(current_func);
97564 +
97565 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
97566 + call_count++;
97567 + 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);
97568 + gcc_assert(len > 0);
97569 + ssa_name = build_string(len + 1, ssa_name_buf);
97570 + free(ssa_name_buf);
97571 + ssa_name = create_string_param(ssa_name);
97572 +
97573 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
97574 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
97575 +
97576 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
97577 +}
97578 +
97579 +static void __unused print_the_code_insertions(const_gimple stmt)
97580 +{
97581 + location_t loc = gimple_location(stmt);
97582 +
97583 + inform(loc, "Integer size_overflow check applied here.");
97584 +}
97585 +
97586 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
97587 +{
97588 + basic_block cond_bb, join_bb, bb_true;
97589 + edge e;
97590 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
97591 +
97592 + cond_bb = gimple_bb(stmt);
97593 + if (before)
97594 + gsi_prev(&gsi);
97595 + if (gsi_end_p(gsi))
97596 + e = split_block_after_labels(cond_bb);
97597 + else
97598 + e = split_block(cond_bb, gsi_stmt(gsi));
97599 + cond_bb = e->src;
97600 + join_bb = e->dest;
97601 + e->flags = EDGE_FALSE_VALUE;
97602 + e->probability = REG_BR_PROB_BASE;
97603 +
97604 + bb_true = create_empty_bb(cond_bb);
97605 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
97606 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
97607 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
97608 +
97609 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
97610 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
97611 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
97612 +
97613 + if (current_loops != NULL) {
97614 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
97615 + add_bb_to_loop(bb_true, cond_bb->loop_father);
97616 + }
97617 +
97618 + insert_cond(cond_bb, arg, cond_code, type_value);
97619 + insert_cond_result(bb_true, stmt, arg, min);
97620 +
97621 +// print_the_code_insertions(stmt);
97622 +}
97623 +
97624 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
97625 +{
97626 + const_tree rhs_type = TREE_TYPE(rhs);
97627 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
97628 +
97629 + gcc_assert(rhs_type != NULL_TREE);
97630 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
97631 + return;
97632 +
97633 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
97634 +
97635 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
97636 + // typemax (-1) < typemin (0)
97637 + if (TREE_OVERFLOW(type_max))
97638 + return;
97639 +
97640 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
97641 +
97642 + cast_rhs_type = TREE_TYPE(cast_rhs);
97643 + type_max_type = TREE_TYPE(type_max);
97644 + type_min_type = TREE_TYPE(type_min);
97645 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
97646 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
97647 +
97648 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
97649 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
97650 +}
97651 +
97652 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
97653 +{
97654 + gimple change_rhs_def_stmt;
97655 + tree lhs = gimple_get_lhs(def_stmt);
97656 + tree lhs_type = TREE_TYPE(lhs);
97657 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
97658 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
97659 +
97660 + if (change_rhs == NULL_TREE)
97661 + return get_size_overflow_type(def_stmt, lhs);
97662 +
97663 + change_rhs_def_stmt = get_def_stmt(change_rhs);
97664 +
97665 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
97666 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
97667 +
97668 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
97669 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
97670 +
97671 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
97672 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
97673 +
97674 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
97675 + debug_gimple_stmt(def_stmt);
97676 + gcc_unreachable();
97677 + }
97678 +
97679 + return get_size_overflow_type(def_stmt, lhs);
97680 +}
97681 +
97682 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
97683 +{
97684 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
97685 + return false;
97686 + if (!is_gimple_constant(rhs))
97687 + return false;
97688 + return true;
97689 +}
97690 +
97691 +static bool is_subtraction_special(const_gimple stmt)
97692 +{
97693 + gimple rhs1_def_stmt, rhs2_def_stmt;
97694 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
97695 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
97696 + const_tree rhs1 = gimple_assign_rhs1(stmt);
97697 + const_tree rhs2 = gimple_assign_rhs2(stmt);
97698 +
97699 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
97700 + return false;
97701 +
97702 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
97703 +
97704 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
97705 + return false;
97706 +
97707 + rhs1_def_stmt = get_def_stmt(rhs1);
97708 + rhs2_def_stmt = get_def_stmt(rhs2);
97709 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
97710 + return false;
97711 +
97712 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
97713 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
97714 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
97715 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
97716 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
97717 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
97718 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
97719 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
97720 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
97721 + return false;
97722 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
97723 + return false;
97724 +
97725 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
97726 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
97727 + return true;
97728 +}
97729 +
97730 +static tree get_def_stmt_rhs(const_tree var)
97731 +{
97732 + tree rhs1, def_stmt_rhs1;
97733 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
97734 +
97735 + def_stmt = get_def_stmt(var);
97736 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
97737 +
97738 + rhs1 = gimple_assign_rhs1(def_stmt);
97739 + rhs1_def_stmt = get_def_stmt(rhs1);
97740 + if (!gimple_assign_cast_p(rhs1_def_stmt))
97741 + return rhs1;
97742 +
97743 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
97744 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
97745 +
97746 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
97747 + case GIMPLE_CALL:
97748 + case GIMPLE_NOP:
97749 + case GIMPLE_ASM:
97750 + return def_stmt_rhs1;
97751 + case GIMPLE_ASSIGN:
97752 + return rhs1;
97753 + default:
97754 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
97755 + gcc_unreachable();
97756 + }
97757 +}
97758 +
97759 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
97760 +{
97761 + tree new_rhs1, new_rhs2;
97762 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
97763 + gimple assign, stmt = get_def_stmt(lhs);
97764 + tree rhs1 = gimple_assign_rhs1(stmt);
97765 + tree rhs2 = gimple_assign_rhs2(stmt);
97766 +
97767 + if (!is_subtraction_special(stmt))
97768 + return NULL_TREE;
97769 +
97770 + new_rhs1 = expand(visited, rhs1);
97771 + new_rhs2 = expand(visited, rhs2);
97772 +
97773 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
97774 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
97775 +
97776 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
97777 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
97778 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
97779 + }
97780 +
97781 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
97782 + new_lhs = gimple_get_lhs(assign);
97783 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
97784 +
97785 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
97786 +}
97787 +
97788 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
97789 +{
97790 + const_gimple def_stmt;
97791 +
97792 + if (TREE_CODE(rhs) != SSA_NAME)
97793 + return false;
97794 +
97795 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
97796 + return false;
97797 +
97798 + def_stmt = get_def_stmt(rhs);
97799 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
97800 + return false;
97801 +
97802 + return true;
97803 +}
97804 +
97805 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
97806 +{
97807 + tree new_rhs, size_overflow_type, orig_rhs;
97808 + void (*gimple_assign_set_rhs)(gimple, tree);
97809 + tree rhs1 = gimple_assign_rhs1(stmt);
97810 + tree rhs2 = gimple_assign_rhs2(stmt);
97811 + tree lhs = gimple_get_lhs(stmt);
97812 +
97813 + if (change_rhs == NULL_TREE)
97814 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97815 +
97816 + if (new_rhs2 == NULL_TREE) {
97817 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
97818 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
97819 + orig_rhs = rhs1;
97820 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
97821 + } else {
97822 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
97823 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
97824 + orig_rhs = rhs2;
97825 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
97826 + }
97827 +
97828 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
97829 +
97830 + if (check_overflow)
97831 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
97832 +
97833 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
97834 + gimple_assign_set_rhs(stmt, new_rhs);
97835 + update_stmt(stmt);
97836 +
97837 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97838 +}
97839 +
97840 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
97841 +{
97842 + tree rhs1, rhs2, new_lhs;
97843 + gimple def_stmt = get_def_stmt(lhs);
97844 + tree new_rhs1 = NULL_TREE;
97845 + tree new_rhs2 = NULL_TREE;
97846 +
97847 + rhs1 = gimple_assign_rhs1(def_stmt);
97848 + rhs2 = gimple_assign_rhs2(def_stmt);
97849 +
97850 + /* no DImode/TImode division in the 32/64 bit kernel */
97851 + switch (gimple_assign_rhs_code(def_stmt)) {
97852 + case RDIV_EXPR:
97853 + case TRUNC_DIV_EXPR:
97854 + case CEIL_DIV_EXPR:
97855 + case FLOOR_DIV_EXPR:
97856 + case ROUND_DIV_EXPR:
97857 + case TRUNC_MOD_EXPR:
97858 + case CEIL_MOD_EXPR:
97859 + case FLOOR_MOD_EXPR:
97860 + case ROUND_MOD_EXPR:
97861 + case EXACT_DIV_EXPR:
97862 + case POINTER_PLUS_EXPR:
97863 + case BIT_AND_EXPR:
97864 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
97865 + default:
97866 + break;
97867 + }
97868 +
97869 + new_lhs = handle_integer_truncation(visited, lhs);
97870 + if (new_lhs != NULL_TREE)
97871 + return new_lhs;
97872 +
97873 + if (TREE_CODE(rhs1) == SSA_NAME)
97874 + new_rhs1 = expand(visited, rhs1);
97875 + if (TREE_CODE(rhs2) == SSA_NAME)
97876 + new_rhs2 = expand(visited, rhs2);
97877 +
97878 + if (is_a_neg_overflow(def_stmt, rhs2))
97879 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
97880 + if (is_a_neg_overflow(def_stmt, rhs1))
97881 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
97882 +
97883 + if (is_a_constant_overflow(def_stmt, rhs2))
97884 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
97885 + if (is_a_constant_overflow(def_stmt, rhs1))
97886 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
97887 +
97888 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
97889 +}
97890 +
97891 +#if BUILDING_GCC_VERSION >= 4007
97892 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
97893 +{
97894 + if (is_gimple_constant(rhs))
97895 + return cast_a_tree(size_overflow_type, rhs);
97896 + if (TREE_CODE(rhs) != SSA_NAME)
97897 + return NULL_TREE;
97898 + return expand(visited, rhs);
97899 +}
97900 +
97901 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
97902 +{
97903 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
97904 + gimple def_stmt = get_def_stmt(lhs);
97905 +
97906 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
97907 +
97908 + rhs1 = gimple_assign_rhs1(def_stmt);
97909 + rhs2 = gimple_assign_rhs2(def_stmt);
97910 + rhs3 = gimple_assign_rhs3(def_stmt);
97911 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
97912 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
97913 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
97914 +
97915 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
97916 +}
97917 +#endif
97918 +
97919 +static tree get_size_overflow_type(gimple stmt, const_tree node)
97920 +{
97921 + const_tree type;
97922 + tree new_type;
97923 +
97924 + gcc_assert(node != NULL_TREE);
97925 +
97926 + type = TREE_TYPE(node);
97927 +
97928 + if (gimple_plf(stmt, MY_STMT))
97929 + return TREE_TYPE(node);
97930 +
97931 + switch (TYPE_MODE(type)) {
97932 + case QImode:
97933 + new_type = intHI_type_node;
97934 + break;
97935 + case HImode:
97936 + new_type = intSI_type_node;
97937 + break;
97938 + case SImode:
97939 + new_type = intDI_type_node;
97940 + break;
97941 + case DImode:
97942 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
97943 + new_type = intDI_type_node;
97944 + else
97945 + new_type = intTI_type_node;
97946 + break;
97947 + default:
97948 + debug_tree((tree)node);
97949 + error("%s: unsupported gcc configuration.", __func__);
97950 + gcc_unreachable();
97951 + }
97952 +
97953 + if (TYPE_QUALS(type) != 0)
97954 + return build_qualified_type(new_type, TYPE_QUALS(type));
97955 + return new_type;
97956 +}
97957 +
97958 +static tree expand_visited(gimple def_stmt)
97959 +{
97960 + const_gimple next_stmt;
97961 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
97962 +
97963 + gsi_next(&gsi);
97964 + next_stmt = gsi_stmt(gsi);
97965 +
97966 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
97967 +
97968 + switch (gimple_code(next_stmt)) {
97969 + case GIMPLE_ASSIGN:
97970 + return gimple_get_lhs(next_stmt);
97971 + case GIMPLE_PHI:
97972 + return gimple_phi_result(next_stmt);
97973 + case GIMPLE_CALL:
97974 + return gimple_call_lhs(next_stmt);
97975 + default:
97976 + return NULL_TREE;
97977 + }
97978 +}
97979 +
97980 +static tree expand(struct pointer_set_t *visited, tree lhs)
97981 +{
97982 + gimple def_stmt;
97983 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
97984 +
97985 + if (is_gimple_constant(lhs))
97986 + return NULL_TREE;
97987 +
97988 + if (TREE_CODE(lhs) == ADDR_EXPR)
97989 + return NULL_TREE;
97990 +
97991 + if (code == REAL_TYPE)
97992 + return NULL_TREE;
97993 +
97994 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
97995 +
97996 + def_stmt = get_def_stmt(lhs);
97997 +
97998 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
97999 + return NULL_TREE;
98000 +
98001 + if (gimple_plf(def_stmt, MY_STMT))
98002 + return lhs;
98003 +
98004 + if (pointer_set_contains(visited, def_stmt))
98005 + return expand_visited(def_stmt);
98006 +
98007 + switch (gimple_code(def_stmt)) {
98008 + case GIMPLE_PHI:
98009 + return build_new_phi(visited, lhs);
98010 + case GIMPLE_CALL:
98011 + case GIMPLE_ASM:
98012 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
98013 + case GIMPLE_ASSIGN:
98014 + switch (gimple_num_ops(def_stmt)) {
98015 + case 2:
98016 + return handle_unary_ops(visited, def_stmt);
98017 + case 3:
98018 + return handle_binary_ops(visited, lhs);
98019 +#if BUILDING_GCC_VERSION >= 4007
98020 + case 4:
98021 + return handle_ternary_ops(visited, lhs);
98022 +#endif
98023 + }
98024 + default:
98025 + debug_gimple_stmt(def_stmt);
98026 + error("%s: unknown gimple code", __func__);
98027 + gcc_unreachable();
98028 + }
98029 +}
98030 +
98031 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
98032 +{
98033 + const_gimple assign;
98034 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
98035 + tree origtype = TREE_TYPE(origarg);
98036 +
98037 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
98038 +
98039 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
98040 +
98041 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
98042 + update_stmt(stmt);
98043 +}
98044 +
98045 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
98046 +{
98047 + const char *origid;
98048 + tree arg;
98049 + const_tree origarg;
98050 +
98051 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
98052 + return true;
98053 +
98054 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
98055 + while (origarg && *argnum) {
98056 + (*argnum)--;
98057 + origarg = TREE_CHAIN(origarg);
98058 + }
98059 +
98060 + gcc_assert(*argnum == 0);
98061 +
98062 + gcc_assert(origarg != NULL_TREE);
98063 + origid = NAME(origarg);
98064 + *argnum = 0;
98065 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
98066 + if (!strcmp(origid, NAME(arg)))
98067 + return true;
98068 + (*argnum)++;
98069 + }
98070 + return false;
98071 +}
98072 +
98073 +static bool skip_types(const_tree var)
98074 +{
98075 + const_tree type;
98076 +
98077 + switch (TREE_CODE(var)) {
98078 + case ADDR_EXPR:
98079 +#if BUILDING_GCC_VERSION >= 4006
98080 + case MEM_REF:
98081 +#endif
98082 + case ARRAY_REF:
98083 + case BIT_FIELD_REF:
98084 + case INDIRECT_REF:
98085 + case TARGET_MEM_REF:
98086 + case VAR_DECL:
98087 + return true;
98088 + default:
98089 + break;
98090 + }
98091 +
98092 + type = TREE_TYPE(TREE_TYPE(var));
98093 + if (!type)
98094 + return false;
98095 + switch (TREE_CODE(type)) {
98096 + case RECORD_TYPE:
98097 + return true;
98098 + default:
98099 + break;
98100 + }
98101 +
98102 + return false;
98103 +}
98104 +
98105 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
98106 +{
98107 + gimple phi = get_def_stmt(result);
98108 + unsigned int i, n = gimple_phi_num_args(phi);
98109 +
98110 + if (!phi)
98111 + return false;
98112 +
98113 + pointer_set_insert(visited, phi);
98114 + for (i = 0; i < n; i++) {
98115 + const_tree arg = gimple_phi_arg_def(phi, i);
98116 + if (pre_expand(visited, arg))
98117 + return true;
98118 + }
98119 + return false;
98120 +}
98121 +
98122 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
98123 +{
98124 + gimple def_stmt = get_def_stmt(lhs);
98125 + const_tree rhs;
98126 +
98127 + if (!def_stmt)
98128 + return false;
98129 +
98130 + rhs = gimple_assign_rhs1(def_stmt);
98131 + if (pre_expand(visited, rhs))
98132 + return true;
98133 + return false;
98134 +}
98135 +
98136 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
98137 +{
98138 + bool rhs1_found, rhs2_found;
98139 + gimple def_stmt = get_def_stmt(lhs);
98140 + const_tree rhs1, rhs2;
98141 +
98142 + if (!def_stmt)
98143 + return false;
98144 +
98145 + rhs1 = gimple_assign_rhs1(def_stmt);
98146 + rhs2 = gimple_assign_rhs2(def_stmt);
98147 + rhs1_found = pre_expand(visited, rhs1);
98148 + rhs2_found = pre_expand(visited, rhs2);
98149 +
98150 + return rhs1_found || rhs2_found;
98151 +}
98152 +
98153 +static const_tree search_field_decl(const_tree comp_ref)
98154 +{
98155 + const_tree field = NULL_TREE;
98156 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
98157 +
98158 + for (i = 0; i < len; i++) {
98159 + field = TREE_OPERAND(comp_ref, i);
98160 + if (TREE_CODE(field) == FIELD_DECL)
98161 + break;
98162 + }
98163 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
98164 + return field;
98165 +}
98166 +
98167 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
98168 +{
98169 + const_tree attr, p;
98170 +
98171 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
98172 + if (!attr || !TREE_VALUE(attr))
98173 + return MARKED_NO;
98174 +
98175 + p = TREE_VALUE(attr);
98176 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
98177 + return MARKED_NOT_INTENTIONAL;
98178 +
98179 + do {
98180 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
98181 + return MARKED_YES;
98182 + p = TREE_CHAIN(p);
98183 + } while (p);
98184 +
98185 + return MARKED_NO;
98186 +}
98187 +
98188 +static void print_missing_msg(tree func, unsigned int argnum)
98189 +{
98190 + unsigned int new_hash;
98191 + size_t len;
98192 + unsigned char tree_codes[CODES_LIMIT];
98193 + location_t loc = DECL_SOURCE_LOCATION(func);
98194 + const char *curfunc = get_asm_name(func);
98195 +
98196 + len = get_function_decl(func, tree_codes);
98197 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
98198 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
98199 +}
98200 +
98201 +static unsigned int search_missing_attribute(const_tree arg)
98202 +{
98203 + const_tree type = TREE_TYPE(arg);
98204 + tree func = get_original_function_decl(current_function_decl);
98205 + unsigned int argnum;
98206 + const struct size_overflow_hash *hash;
98207 +
98208 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
98209 +
98210 + if (TREE_CODE(type) == POINTER_TYPE)
98211 + return 0;
98212 +
98213 + argnum = find_arg_number(arg, func);
98214 + if (argnum == 0)
98215 + return 0;
98216 +
98217 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
98218 + return argnum;
98219 +
98220 + hash = get_function_hash(func);
98221 + if (!hash || !(hash->param & (1U << argnum))) {
98222 + print_missing_msg(func, argnum);
98223 + return 0;
98224 + }
98225 + return argnum;
98226 +}
98227 +
98228 +static bool is_already_marked(const_tree lhs)
98229 +{
98230 + unsigned int argnum;
98231 + const_tree fndecl;
98232 +
98233 + argnum = search_missing_attribute(lhs);
98234 + fndecl = get_original_function_decl(current_function_decl);
98235 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
98236 + return true;
98237 + return false;
98238 +}
98239 +
98240 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
98241 +{
98242 + const_gimple def_stmt;
98243 +
98244 + if (is_gimple_constant(lhs))
98245 + return false;
98246 +
98247 + if (skip_types(lhs))
98248 + return false;
98249 +
98250 + // skip char type (FIXME: only kernel)
98251 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
98252 + return false;
98253 +
98254 + if (TREE_CODE(lhs) == PARM_DECL)
98255 + return is_already_marked(lhs);
98256 +
98257 + if (TREE_CODE(lhs) == COMPONENT_REF) {
98258 + const_tree field, attr;
98259 +
98260 + field = search_field_decl(lhs);
98261 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
98262 + if (!attr || !TREE_VALUE(attr))
98263 + return false;
98264 + return true;
98265 + }
98266 +
98267 + def_stmt = get_def_stmt(lhs);
98268 +
98269 + if (!def_stmt)
98270 + return false;
98271 +
98272 + if (pointer_set_contains(visited, def_stmt))
98273 + return false;
98274 +
98275 + switch (gimple_code(def_stmt)) {
98276 + case GIMPLE_NOP:
98277 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
98278 + return is_already_marked(lhs);
98279 + return false;
98280 + case GIMPLE_PHI:
98281 + return walk_phi(visited, lhs);
98282 + case GIMPLE_CALL:
98283 + case GIMPLE_ASM:
98284 + return false;
98285 + case GIMPLE_ASSIGN:
98286 + switch (gimple_num_ops(def_stmt)) {
98287 + case 2:
98288 + return walk_unary_ops(visited, lhs);
98289 + case 3:
98290 + return walk_binary_ops(visited, lhs);
98291 + }
98292 + default:
98293 + debug_gimple_stmt((gimple)def_stmt);
98294 + error("%s: unknown gimple code", __func__);
98295 + gcc_unreachable();
98296 + }
98297 +}
98298 +
98299 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
98300 +{
98301 + struct pointer_set_t *visited;
98302 + bool is_found;
98303 + enum marked is_marked;
98304 + location_t loc;
98305 +
98306 + visited = pointer_set_create();
98307 + is_found = pre_expand(visited, arg);
98308 + pointer_set_destroy(visited);
98309 +
98310 + is_marked = mark_status(fndecl, argnum + 1);
98311 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
98312 + return true;
98313 +
98314 + if (is_found) {
98315 + loc = DECL_SOURCE_LOCATION(fndecl);
98316 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
98317 + return true;
98318 + }
98319 + return false;
98320 +}
98321 +
98322 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
98323 +{
98324 + struct pointer_set_t *visited;
98325 + tree arg, newarg;
98326 + bool match;
98327 +
98328 + match = get_function_arg(&argnum, fndecl);
98329 + if (!match)
98330 + return;
98331 + gcc_assert(gimple_call_num_args(stmt) > argnum);
98332 + arg = gimple_call_arg(stmt, argnum);
98333 + if (arg == NULL_TREE)
98334 + return;
98335 +
98336 + if (is_gimple_constant(arg))
98337 + return;
98338 +
98339 + if (search_attributes(fndecl, arg, argnum))
98340 + return;
98341 +
98342 + if (TREE_CODE(arg) != SSA_NAME)
98343 + return;
98344 +
98345 + check_arg_type(arg);
98346 +
98347 + visited = pointer_set_create();
98348 + newarg = expand(visited, arg);
98349 + pointer_set_destroy(visited);
98350 +
98351 + if (newarg == NULL_TREE)
98352 + return;
98353 +
98354 + change_function_arg(stmt, arg, argnum, newarg);
98355 +
98356 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
98357 +}
98358 +
98359 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
98360 +{
98361 + tree p = TREE_VALUE(attr);
98362 + do {
98363 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
98364 + p = TREE_CHAIN(p);
98365 + } while (p);
98366 +}
98367 +
98368 +static void handle_function_by_hash(gimple stmt, tree fndecl)
98369 +{
98370 + tree orig_fndecl;
98371 + unsigned int num;
98372 + const struct size_overflow_hash *hash;
98373 +
98374 + orig_fndecl = get_original_function_decl(fndecl);
98375 + if (C_DECL_IMPLICIT(orig_fndecl))
98376 + return;
98377 + hash = get_function_hash(orig_fndecl);
98378 + if (!hash)
98379 + return;
98380 +
98381 + for (num = 1; num <= MAX_PARAM; num++)
98382 + if (hash->param & (1U << num))
98383 + handle_function_arg(stmt, fndecl, num - 1);
98384 +}
98385 +
98386 +static void set_plf_false(void)
98387 +{
98388 + basic_block bb;
98389 +
98390 + FOR_ALL_BB(bb) {
98391 + gimple_stmt_iterator si;
98392 +
98393 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
98394 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
98395 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
98396 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
98397 + }
98398 +}
98399 +
98400 +static unsigned int handle_function(void)
98401 +{
98402 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
98403 +
98404 + set_plf_false();
98405 +
98406 + do {
98407 + gimple_stmt_iterator gsi;
98408 + next = bb->next_bb;
98409 +
98410 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
98411 + tree fndecl, attr;
98412 + gimple stmt = gsi_stmt(gsi);
98413 +
98414 + if (!(is_gimple_call(stmt)))
98415 + continue;
98416 + fndecl = gimple_call_fndecl(stmt);
98417 + if (fndecl == NULL_TREE)
98418 + continue;
98419 + if (gimple_call_num_args(stmt) == 0)
98420 + continue;
98421 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
98422 + if (!attr || !TREE_VALUE(attr))
98423 + handle_function_by_hash(stmt, fndecl);
98424 + else
98425 + handle_function_by_attribute(stmt, attr, fndecl);
98426 + gsi = gsi_for_stmt(stmt);
98427 + next = gimple_bb(stmt)->next_bb;
98428 + }
98429 + bb = next;
98430 + } while (bb);
98431 + return 0;
98432 +}
98433 +
98434 +static struct gimple_opt_pass size_overflow_pass = {
98435 + .pass = {
98436 + .type = GIMPLE_PASS,
98437 + .name = "size_overflow",
98438 +#if BUILDING_GCC_VERSION >= 4008
98439 + .optinfo_flags = OPTGROUP_NONE,
98440 +#endif
98441 + .gate = NULL,
98442 + .execute = handle_function,
98443 + .sub = NULL,
98444 + .next = NULL,
98445 + .static_pass_number = 0,
98446 + .tv_id = TV_NONE,
98447 + .properties_required = PROP_cfg,
98448 + .properties_provided = 0,
98449 + .properties_destroyed = 0,
98450 + .todo_flags_start = 0,
98451 + .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
98452 + }
98453 +};
98454 +
98455 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
98456 +{
98457 + tree fntype;
98458 +
98459 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
98460 +
98461 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
98462 + fntype = build_function_type_list(void_type_node,
98463 + const_char_ptr_type_node,
98464 + unsigned_type_node,
98465 + const_char_ptr_type_node,
98466 + const_char_ptr_type_node,
98467 + NULL_TREE);
98468 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
98469 +
98470 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
98471 + TREE_PUBLIC(report_size_overflow_decl) = 1;
98472 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
98473 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
98474 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
98475 +}
98476 +
98477 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
98478 +{
98479 + int i;
98480 + const char * const plugin_name = plugin_info->base_name;
98481 + const int argc = plugin_info->argc;
98482 + const struct plugin_argument * const argv = plugin_info->argv;
98483 + bool enable = true;
98484 +
98485 + struct register_pass_info size_overflow_pass_info = {
98486 + .pass = &size_overflow_pass.pass,
98487 + .reference_pass_name = "ssa",
98488 + .ref_pass_instance_number = 1,
98489 + .pos_op = PASS_POS_INSERT_AFTER
98490 + };
98491 +
98492 + if (!plugin_default_version_check(version, &gcc_version)) {
98493 + error(G_("incompatible gcc/plugin versions"));
98494 + return 1;
98495 + }
98496 +
98497 + for (i = 0; i < argc; ++i) {
98498 + if (!strcmp(argv[i].key, "no-size-overflow")) {
98499 + enable = false;
98500 + continue;
98501 + }
98502 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
98503 + }
98504 +
98505 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
98506 + if (enable) {
98507 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
98508 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
98509 + }
98510 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
98511 +
98512 + return 0;
98513 +}
98514 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
98515 new file mode 100644
98516 index 0000000..ac2901e
98517 --- /dev/null
98518 +++ b/tools/gcc/stackleak_plugin.c
98519 @@ -0,0 +1,327 @@
98520 +/*
98521 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
98522 + * Licensed under the GPL v2
98523 + *
98524 + * Note: the choice of the license means that the compilation process is
98525 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
98526 + * but for the kernel it doesn't matter since it doesn't link against
98527 + * any of the gcc libraries
98528 + *
98529 + * gcc plugin to help implement various PaX features
98530 + *
98531 + * - track lowest stack pointer
98532 + *
98533 + * TODO:
98534 + * - initialize all local variables
98535 + *
98536 + * BUGS:
98537 + * - none known
98538 + */
98539 +#include "gcc-plugin.h"
98540 +#include "config.h"
98541 +#include "system.h"
98542 +#include "coretypes.h"
98543 +#include "tree.h"
98544 +#include "tree-pass.h"
98545 +#include "flags.h"
98546 +#include "intl.h"
98547 +#include "toplev.h"
98548 +#include "plugin.h"
98549 +//#include "expr.h" where are you...
98550 +#include "diagnostic.h"
98551 +#include "plugin-version.h"
98552 +#include "tm.h"
98553 +#include "function.h"
98554 +#include "basic-block.h"
98555 +#include "gimple.h"
98556 +#include "rtl.h"
98557 +#include "emit-rtl.h"
98558 +
98559 +#if BUILDING_GCC_VERSION >= 4008
98560 +#define TODO_dump_func 0
98561 +#endif
98562 +
98563 +extern void print_gimple_stmt(FILE *, gimple, int, int);
98564 +
98565 +int plugin_is_GPL_compatible;
98566 +
98567 +static int track_frame_size = -1;
98568 +static const char track_function[] = "pax_track_stack";
98569 +static const char check_function[] = "pax_check_alloca";
98570 +static bool init_locals;
98571 +
98572 +static struct plugin_info stackleak_plugin_info = {
98573 + .version = "201302112000",
98574 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
98575 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
98576 +};
98577 +
98578 +static bool gate_stackleak_track_stack(void);
98579 +static unsigned int execute_stackleak_tree_instrument(void);
98580 +static unsigned int execute_stackleak_final(void);
98581 +
98582 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
98583 + .pass = {
98584 + .type = GIMPLE_PASS,
98585 + .name = "stackleak_tree_instrument",
98586 +#if BUILDING_GCC_VERSION >= 4008
98587 + .optinfo_flags = OPTGROUP_NONE,
98588 +#endif
98589 + .gate = gate_stackleak_track_stack,
98590 + .execute = execute_stackleak_tree_instrument,
98591 + .sub = NULL,
98592 + .next = NULL,
98593 + .static_pass_number = 0,
98594 + .tv_id = TV_NONE,
98595 + .properties_required = PROP_gimple_leh | PROP_cfg,
98596 + .properties_provided = 0,
98597 + .properties_destroyed = 0,
98598 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
98599 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
98600 + }
98601 +};
98602 +
98603 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
98604 + .pass = {
98605 + .type = RTL_PASS,
98606 + .name = "stackleak_final",
98607 +#if BUILDING_GCC_VERSION >= 4008
98608 + .optinfo_flags = OPTGROUP_NONE,
98609 +#endif
98610 + .gate = gate_stackleak_track_stack,
98611 + .execute = execute_stackleak_final,
98612 + .sub = NULL,
98613 + .next = NULL,
98614 + .static_pass_number = 0,
98615 + .tv_id = TV_NONE,
98616 + .properties_required = 0,
98617 + .properties_provided = 0,
98618 + .properties_destroyed = 0,
98619 + .todo_flags_start = 0,
98620 + .todo_flags_finish = TODO_dump_func
98621 + }
98622 +};
98623 +
98624 +static bool gate_stackleak_track_stack(void)
98625 +{
98626 + return track_frame_size >= 0;
98627 +}
98628 +
98629 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
98630 +{
98631 + gimple check_alloca;
98632 + tree fntype, fndecl, alloca_size;
98633 +
98634 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
98635 + fndecl = build_fn_decl(check_function, fntype);
98636 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
98637 +
98638 + // insert call to void pax_check_alloca(unsigned long size)
98639 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
98640 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
98641 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
98642 +}
98643 +
98644 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
98645 +{
98646 + gimple track_stack;
98647 + tree fntype, fndecl;
98648 +
98649 + fntype = build_function_type_list(void_type_node, NULL_TREE);
98650 + fndecl = build_fn_decl(track_function, fntype);
98651 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
98652 +
98653 + // insert call to void pax_track_stack(void)
98654 + track_stack = gimple_build_call(fndecl, 0);
98655 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
98656 +}
98657 +
98658 +#if BUILDING_GCC_VERSION == 4005
98659 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
98660 +{
98661 + tree fndecl;
98662 +
98663 + if (!is_gimple_call(stmt))
98664 + return false;
98665 + fndecl = gimple_call_fndecl(stmt);
98666 + if (!fndecl)
98667 + return false;
98668 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
98669 + return false;
98670 +// print_node(stderr, "pax", fndecl, 4);
98671 + return DECL_FUNCTION_CODE(fndecl) == code;
98672 +}
98673 +#endif
98674 +
98675 +static bool is_alloca(gimple stmt)
98676 +{
98677 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
98678 + return true;
98679 +
98680 +#if BUILDING_GCC_VERSION >= 4007
98681 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
98682 + return true;
98683 +#endif
98684 +
98685 + return false;
98686 +}
98687 +
98688 +static unsigned int execute_stackleak_tree_instrument(void)
98689 +{
98690 + basic_block bb, entry_bb;
98691 + bool prologue_instrumented = false, is_leaf = true;
98692 +
98693 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
98694 +
98695 + // 1. loop through BBs and GIMPLE statements
98696 + FOR_EACH_BB(bb) {
98697 + gimple_stmt_iterator gsi;
98698 +
98699 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
98700 + gimple stmt;
98701 +
98702 + stmt = gsi_stmt(gsi);
98703 +
98704 + if (is_gimple_call(stmt))
98705 + is_leaf = false;
98706 +
98707 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
98708 + if (!is_alloca(stmt))
98709 + continue;
98710 +
98711 + // 2. insert stack overflow check before each __builtin_alloca call
98712 + stackleak_check_alloca(&gsi);
98713 +
98714 + // 3. insert track call after each __builtin_alloca call
98715 + stackleak_add_instrumentation(&gsi);
98716 + if (bb == entry_bb)
98717 + prologue_instrumented = true;
98718 + }
98719 + }
98720 +
98721 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
98722 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
98723 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
98724 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
98725 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
98726 + return 0;
98727 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
98728 + return 0;
98729 +
98730 + // 4. insert track call at the beginning
98731 + if (!prologue_instrumented) {
98732 + gimple_stmt_iterator gsi;
98733 +
98734 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
98735 + if (dom_info_available_p(CDI_DOMINATORS))
98736 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
98737 + gsi = gsi_start_bb(bb);
98738 + stackleak_add_instrumentation(&gsi);
98739 + }
98740 +
98741 + return 0;
98742 +}
98743 +
98744 +static unsigned int execute_stackleak_final(void)
98745 +{
98746 + rtx insn, next;
98747 +
98748 + if (cfun->calls_alloca)
98749 + return 0;
98750 +
98751 + // keep calls only if function frame is big enough
98752 + if (get_frame_size() >= track_frame_size)
98753 + return 0;
98754 +
98755 + // 1. find pax_track_stack calls
98756 + for (insn = get_insns(); insn; insn = next) {
98757 + // 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))
98758 + rtx body;
98759 +
98760 + next = NEXT_INSN(insn);
98761 + if (!CALL_P(insn))
98762 + continue;
98763 + body = PATTERN(insn);
98764 + if (GET_CODE(body) != CALL)
98765 + continue;
98766 + body = XEXP(body, 0);
98767 + if (GET_CODE(body) != MEM)
98768 + continue;
98769 + body = XEXP(body, 0);
98770 + if (GET_CODE(body) != SYMBOL_REF)
98771 + continue;
98772 + if (strcmp(XSTR(body, 0), track_function))
98773 + continue;
98774 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
98775 + // 2. delete call
98776 + delete_insn_and_edges(insn);
98777 +#if BUILDING_GCC_VERSION >= 4007
98778 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
98779 + insn = next;
98780 + next = NEXT_INSN(insn);
98781 + delete_insn_and_edges(insn);
98782 + }
98783 +#endif
98784 + }
98785 +
98786 +// print_simple_rtl(stderr, get_insns());
98787 +// print_rtl(stderr, get_insns());
98788 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
98789 +
98790 + return 0;
98791 +}
98792 +
98793 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
98794 +{
98795 + const char * const plugin_name = plugin_info->base_name;
98796 + const int argc = plugin_info->argc;
98797 + const struct plugin_argument * const argv = plugin_info->argv;
98798 + int i;
98799 + struct register_pass_info stackleak_tree_instrument_pass_info = {
98800 + .pass = &stackleak_tree_instrument_pass.pass,
98801 +// .reference_pass_name = "tree_profile",
98802 + .reference_pass_name = "optimized",
98803 + .ref_pass_instance_number = 1,
98804 + .pos_op = PASS_POS_INSERT_BEFORE
98805 + };
98806 + struct register_pass_info stackleak_final_pass_info = {
98807 + .pass = &stackleak_final_rtl_opt_pass.pass,
98808 + .reference_pass_name = "final",
98809 + .ref_pass_instance_number = 1,
98810 + .pos_op = PASS_POS_INSERT_BEFORE
98811 + };
98812 +
98813 + if (!plugin_default_version_check(version, &gcc_version)) {
98814 + error(G_("incompatible gcc/plugin versions"));
98815 + return 1;
98816 + }
98817 +
98818 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
98819 +
98820 + for (i = 0; i < argc; ++i) {
98821 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
98822 + if (!argv[i].value) {
98823 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
98824 + continue;
98825 + }
98826 + track_frame_size = atoi(argv[i].value);
98827 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
98828 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
98829 + continue;
98830 + }
98831 + if (!strcmp(argv[i].key, "initialize-locals")) {
98832 + if (argv[i].value) {
98833 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
98834 + continue;
98835 + }
98836 + init_locals = true;
98837 + continue;
98838 + }
98839 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
98840 + }
98841 +
98842 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
98843 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
98844 +
98845 + return 0;
98846 +}
98847 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
98848 index 6789d78..4afd019e 100644
98849 --- a/tools/perf/util/include/asm/alternative-asm.h
98850 +++ b/tools/perf/util/include/asm/alternative-asm.h
98851 @@ -5,4 +5,7 @@
98852
98853 #define altinstruction_entry #
98854
98855 + .macro pax_force_retaddr rip=0, reload=0
98856 + .endm
98857 +
98858 #endif
98859 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
98860 index 1cd693a..f4a7b20 100644
98861 --- a/virt/kvm/kvm_main.c
98862 +++ b/virt/kvm/kvm_main.c
98863 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
98864
98865 static cpumask_var_t cpus_hardware_enabled;
98866 static int kvm_usage_count = 0;
98867 -static atomic_t hardware_enable_failed;
98868 +static atomic_unchecked_t hardware_enable_failed;
98869
98870 struct kmem_cache *kvm_vcpu_cache;
98871 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
98872
98873 -static __read_mostly struct preempt_ops kvm_preempt_ops;
98874 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
98875 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
98876 +static struct preempt_ops kvm_preempt_ops = {
98877 + .sched_in = kvm_sched_in,
98878 + .sched_out = kvm_sched_out,
98879 +};
98880
98881 struct dentry *kvm_debugfs_dir;
98882
98883 @@ -731,7 +736,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
98884 /* We can read the guest memory with __xxx_user() later on. */
98885 if (user_alloc &&
98886 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
98887 - !access_ok(VERIFY_WRITE,
98888 + !__access_ok(VERIFY_WRITE,
98889 (void __user *)(unsigned long)mem->userspace_addr,
98890 mem->memory_size)))
98891 goto out;
98892 @@ -1783,7 +1788,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
98893 return 0;
98894 }
98895
98896 -static struct file_operations kvm_vcpu_fops = {
98897 +static file_operations_no_const kvm_vcpu_fops __read_only = {
98898 .release = kvm_vcpu_release,
98899 .unlocked_ioctl = kvm_vcpu_ioctl,
98900 #ifdef CONFIG_COMPAT
98901 @@ -2304,7 +2309,7 @@ static int kvm_vm_mmap(struct file *file, struct vm_area_struct *vma)
98902 return 0;
98903 }
98904
98905 -static struct file_operations kvm_vm_fops = {
98906 +static file_operations_no_const kvm_vm_fops __read_only = {
98907 .release = kvm_vm_release,
98908 .unlocked_ioctl = kvm_vm_ioctl,
98909 #ifdef CONFIG_COMPAT
98910 @@ -2402,7 +2407,7 @@ out:
98911 return r;
98912 }
98913
98914 -static struct file_operations kvm_chardev_ops = {
98915 +static file_operations_no_const kvm_chardev_ops __read_only = {
98916 .unlocked_ioctl = kvm_dev_ioctl,
98917 .compat_ioctl = kvm_dev_ioctl,
98918 .llseek = noop_llseek,
98919 @@ -2428,7 +2433,7 @@ static void hardware_enable_nolock(void *junk)
98920
98921 if (r) {
98922 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
98923 - atomic_inc(&hardware_enable_failed);
98924 + atomic_inc_unchecked(&hardware_enable_failed);
98925 printk(KERN_INFO "kvm: enabling virtualization on "
98926 "CPU%d failed\n", cpu);
98927 }
98928 @@ -2482,10 +2487,10 @@ static int hardware_enable_all(void)
98929
98930 kvm_usage_count++;
98931 if (kvm_usage_count == 1) {
98932 - atomic_set(&hardware_enable_failed, 0);
98933 + atomic_set_unchecked(&hardware_enable_failed, 0);
98934 on_each_cpu(hardware_enable_nolock, NULL, 1);
98935
98936 - if (atomic_read(&hardware_enable_failed)) {
98937 + if (atomic_read_unchecked(&hardware_enable_failed)) {
98938 hardware_disable_all_nolock();
98939 r = -EBUSY;
98940 }
98941 @@ -2843,7 +2848,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
98942 kvm_arch_vcpu_put(vcpu);
98943 }
98944
98945 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
98946 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
98947 struct module *module)
98948 {
98949 int r;
98950 @@ -2879,7 +2884,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
98951 if (!vcpu_align)
98952 vcpu_align = __alignof__(struct kvm_vcpu);
98953 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
98954 - 0, NULL);
98955 + SLAB_USERCOPY, NULL);
98956 if (!kvm_vcpu_cache) {
98957 r = -ENOMEM;
98958 goto out_free_3;
98959 @@ -2889,9 +2894,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
98960 if (r)
98961 goto out_free;
98962
98963 + pax_open_kernel();
98964 kvm_chardev_ops.owner = module;
98965 kvm_vm_fops.owner = module;
98966 kvm_vcpu_fops.owner = module;
98967 + pax_close_kernel();
98968
98969 r = misc_register(&kvm_dev);
98970 if (r) {
98971 @@ -2901,9 +2908,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
98972
98973 register_syscore_ops(&kvm_syscore_ops);
98974
98975 - kvm_preempt_ops.sched_in = kvm_sched_in;
98976 - kvm_preempt_ops.sched_out = kvm_sched_out;
98977 -
98978 r = kvm_init_debug();
98979 if (r) {
98980 printk(KERN_ERR "kvm: create debugfs files failed\n");