]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.8.2-201303101356.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.2-201303101356.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b89a739..b47493f 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -69,6 +75,7 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 @@ -80,6 +87,7 @@ aic7*seq.h*
53 aicasm
54 aicdb.h*
55 altivec*.c
56 +ashldi3.S
57 asm-offsets.h
58 asm_offsets.h
59 autoconf.h*
60 @@ -92,19 +100,24 @@ bounds.h
61 bsetup
62 btfixupprep
63 build
64 +builtin-policy.h
65 bvmlinux
66 bzImage*
67 capability_names.h
68 capflags.c
69 classlist.h*
70 +clut_vga16.c
71 +common-cmds.h
72 comp*.log
73 compile.h*
74 conf
75 config
76 config-*
77 config_data.h*
78 +config.c
79 config.mak
80 config.mak.autogen
81 +config.tmp
82 conmakehash
83 consolemap_deftbl.c*
84 cpustr.h
85 @@ -115,9 +128,11 @@ devlist.h*
86 dnotify_test
87 docproc
88 dslm
89 +dtc-lexer.lex.c
90 elf2ecoff
91 elfconfig.h*
92 evergreen_reg_safe.h
93 +exception_policy.conf
94 fixdep
95 flask.h
96 fore200e_mkfirm
97 @@ -125,12 +140,15 @@ fore200e_pca_fw.c*
98 gconf
99 gconf.glade.h
100 gen-devlist
101 +gen-kdb_cmds.c
102 gen_crc32table
103 gen_init_cpio
104 generated
105 genheaders
106 genksyms
107 *_gray256.c
108 +hash
109 +hid-example
110 hpet_example
111 hugepage-mmap
112 hugepage-shm
113 @@ -145,14 +163,14 @@ int32.c
114 int4.c
115 int8.c
116 kallsyms
117 -kconfig
118 +kern_constants.h
119 keywords.c
120 ksym.c*
121 ksym.h*
122 kxgettext
123 lex.c
124 lex.*.c
125 -linux
126 +lib1funcs.S
127 logo_*.c
128 logo_*_clut224.c
129 logo_*_mono.c
130 @@ -162,14 +180,15 @@ mach-types.h
131 machtypes.h
132 map
133 map_hugetlb
134 -media
135 mconf
136 +mdp
137 miboot*
138 mk_elfconfig
139 mkboot
140 mkbugboot
141 mkcpustr
142 mkdep
143 +mkpiggy
144 mkprep
145 mkregtable
146 mktables
147 @@ -185,6 +204,8 @@ oui.c*
148 page-types
149 parse.c
150 parse.h
151 +parse-events*
152 +pasyms.h
153 patches*
154 pca200e.bin
155 pca200e_ecd.bin2
156 @@ -194,6 +215,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160 +pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164 @@ -203,7 +225,10 @@ r200_reg_safe.h
165 r300_reg_safe.h
166 r420_reg_safe.h
167 r600_reg_safe.h
168 +realmode.lds
169 +realmode.relocs
170 recordmcount
171 +regdb.c
172 relocs
173 rlim_names.h
174 rn50_reg_safe.h
175 @@ -213,8 +238,12 @@ series
176 setup
177 setup.bin
178 setup.elf
179 +signing_key*
180 +size_overflow_hash.h
181 sImage
182 +slabinfo
183 sm_tbl*
184 +sortextable
185 split-include
186 syscalltab.h
187 tables.c
188 @@ -224,6 +253,7 @@ tftpboot.img
189 timeconst.h
190 times.h*
191 trix_boot.h
192 +user_constants.h
193 utsrelease.h*
194 vdso-syms.lds
195 vdso.lds
196 @@ -235,13 +265,17 @@ vdso32.lds
197 vdso32.so.dbg
198 vdso64.lds
199 vdso64.so.dbg
200 +vdsox32.lds
201 +vdsox32-syms.lds
202 version.h*
203 vmImage
204 vmlinux
205 vmlinux-*
206 vmlinux.aout
207 vmlinux.bin.all
208 +vmlinux.bin.bz2
209 vmlinux.lds
210 +vmlinux.relocs
211 vmlinuz
212 voffset.h
213 vsyscall.lds
214 @@ -249,9 +283,12 @@ vsyscall_32.lds
215 wanxlfw.inc
216 uImage
217 unifdef
218 +utsrelease.h
219 wakeup.bin
220 wakeup.elf
221 wakeup.lds
222 +x509*
223 zImage*
224 zconf.hash.c
225 +zconf.lex.c
226 zoffset.h
227 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
228 index 986614d..e8bfedc 100644
229 --- a/Documentation/kernel-parameters.txt
230 +++ b/Documentation/kernel-parameters.txt
231 @@ -922,6 +922,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
232 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
233 Default: 1024
234
235 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
236 + ignore grsecurity's /proc restrictions
237 +
238 +
239 hashdist= [KNL,NUMA] Large hashes allocated during boot
240 are distributed across NUMA nodes. Defaults on
241 for 64-bit NUMA, off otherwise.
242 @@ -2121,6 +2125,18 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
243 the specified number of seconds. This is to be used if
244 your oopses keep scrolling off the screen.
245
246 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
247 + virtualization environments that don't cope well with the
248 + expand down segment used by UDEREF on X86-32 or the frequent
249 + page table updates on X86-64.
250 +
251 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
252 +
253 + pax_extra_latent_entropy
254 + Enable a very simple form of latent entropy extraction
255 + from the first 4GB of memory as the bootmem allocator
256 + passes the memory pages to the buddy allocator.
257 +
258 pcbit= [HW,ISDN]
259
260 pcd. [PARIDE]
261 diff --git a/Makefile b/Makefile
262 index 20d5318..d5cec9c 100644
263 --- a/Makefile
264 +++ b/Makefile
265 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
266
267 HOSTCC = gcc
268 HOSTCXX = g++
269 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
270 -HOSTCXXFLAGS = -O2
271 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
272 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
273 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
274
275 # Decide whether to build built-in, modular, or both.
276 # Normally, just do built-in.
277 @@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
278 # Rules shared between *config targets and build targets
279
280 # Basic helpers built in scripts/
281 -PHONY += scripts_basic
282 -scripts_basic:
283 +PHONY += scripts_basic gcc-plugins
284 +scripts_basic: gcc-plugins
285 $(Q)$(MAKE) $(build)=scripts/basic
286 $(Q)rm -f .tmp_quiet_recordmcount
287
288 @@ -575,6 +576,62 @@ else
289 KBUILD_CFLAGS += -O2
290 endif
291
292 +ifndef DISABLE_PAX_PLUGINS
293 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
294 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
295 +else
296 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
297 +endif
298 +ifneq ($(PLUGINCC),)
299 +ifndef CONFIG_UML
300 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
301 +endif
302 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
303 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
304 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
305 +endif
306 +ifdef CONFIG_KALLOCSTAT_PLUGIN
307 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
308 +endif
309 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
310 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
311 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
312 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
313 +endif
314 +ifdef CONFIG_CHECKER_PLUGIN
315 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
316 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
317 +endif
318 +endif
319 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
320 +ifdef CONFIG_PAX_SIZE_OVERFLOW
321 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
322 +endif
323 +ifdef CONFIG_PAX_LATENT_ENTROPY
324 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
325 +endif
326 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
327 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
328 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
329 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
330 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
331 +ifeq ($(KBUILD_EXTMOD),)
332 +gcc-plugins:
333 + $(Q)$(MAKE) $(build)=tools/gcc
334 +else
335 +gcc-plugins: ;
336 +endif
337 +else
338 +gcc-plugins:
339 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
340 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
341 +else
342 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
343 +endif
344 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
345 +endif
346 +endif
347 +
348 include $(srctree)/arch/$(SRCARCH)/Makefile
349
350 ifdef CONFIG_READABLE_ASM
351 @@ -731,7 +788,7 @@ export mod_sign_cmd
352
353
354 ifeq ($(KBUILD_EXTMOD),)
355 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
356 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
357
358 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
359 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
360 @@ -778,6 +835,8 @@ endif
361
362 # The actual objects are generated when descending,
363 # make sure no implicit rule kicks in
364 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
365 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
366 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
367
368 # Handle descending into subdirectories listed in $(vmlinux-dirs)
369 @@ -787,7 +846,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
370 # Error messages still appears in the original language
371
372 PHONY += $(vmlinux-dirs)
373 -$(vmlinux-dirs): prepare scripts
374 +$(vmlinux-dirs): gcc-plugins prepare scripts
375 $(Q)$(MAKE) $(build)=$@
376
377 # Store (new) KERNELRELASE string in include/config/kernel.release
378 @@ -831,6 +890,7 @@ prepare0: archprepare FORCE
379 $(Q)$(MAKE) $(build)=.
380
381 # All the preparing..
382 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
383 prepare: prepare0
384
385 # Generate some files
386 @@ -938,6 +998,8 @@ all: modules
387 # using awk while concatenating to the final file.
388
389 PHONY += modules
390 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
391 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
392 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
393 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
394 @$(kecho) ' Building modules, stage 2.';
395 @@ -953,7 +1015,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
396
397 # Target to prepare building external modules
398 PHONY += modules_prepare
399 -modules_prepare: prepare scripts
400 +modules_prepare: gcc-plugins prepare scripts
401
402 # Target to install modules
403 PHONY += modules_install
404 @@ -1019,7 +1081,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
405 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
406 signing_key.priv signing_key.x509 x509.genkey \
407 extra_certificates signing_key.x509.keyid \
408 - signing_key.x509.signer
409 + signing_key.x509.signer tools/gcc/size_overflow_hash.h
410
411 # clean - Delete most, but leave enough to build external modules
412 #
413 @@ -1059,6 +1121,7 @@ distclean: mrproper
414 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
415 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
416 -o -name '.*.rej' \
417 + -o -name '.*.rej' -o -name '*.so' \
418 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
419 -type f -print | xargs rm -f
420
421 @@ -1219,6 +1282,8 @@ PHONY += $(module-dirs) modules
422 $(module-dirs): crmodverdir $(objtree)/Module.symvers
423 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
424
425 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 modules: $(module-dirs)
428 @$(kecho) ' Building modules, stage 2.';
429 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
430 @@ -1355,17 +1420,21 @@ else
431 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
432 endif
433
434 -%.s: %.c prepare scripts FORCE
435 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
436 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
437 +%.s: %.c gcc-plugins prepare scripts FORCE
438 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
439 %.i: %.c prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 -%.o: %.c prepare scripts FORCE
442 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
443 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
444 +%.o: %.c gcc-plugins prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 %.lst: %.c prepare scripts FORCE
447 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
448 -%.s: %.S prepare scripts FORCE
449 +%.s: %.S gcc-plugins prepare scripts FORCE
450 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
451 -%.o: %.S prepare scripts FORCE
452 +%.o: %.S gcc-plugins prepare scripts FORCE
453 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
454 %.symtypes: %.c prepare scripts FORCE
455 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
456 @@ -1375,11 +1444,15 @@ endif
457 $(cmd_crmodverdir)
458 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
459 $(build)=$(build-dir)
460 -%/: prepare scripts FORCE
461 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
462 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
463 +%/: gcc-plugins prepare scripts FORCE
464 $(cmd_crmodverdir)
465 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
466 $(build)=$(build-dir)
467 -%.ko: prepare scripts FORCE
468 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
469 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
470 +%.ko: gcc-plugins prepare scripts FORCE
471 $(cmd_crmodverdir)
472 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
473 $(build)=$(build-dir) $(@:.ko=.o)
474 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
475 index c2cbe4f..f7264b4 100644
476 --- a/arch/alpha/include/asm/atomic.h
477 +++ b/arch/alpha/include/asm/atomic.h
478 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
479 #define atomic_dec(v) atomic_sub(1,(v))
480 #define atomic64_dec(v) atomic64_sub(1,(v))
481
482 +#define atomic64_read_unchecked(v) atomic64_read(v)
483 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
484 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
485 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
486 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
487 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
488 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
489 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
490 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
491 +
492 #define smp_mb__before_atomic_dec() smp_mb()
493 #define smp_mb__after_atomic_dec() smp_mb()
494 #define smp_mb__before_atomic_inc() smp_mb()
495 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
496 index ad368a9..fbe0f25 100644
497 --- a/arch/alpha/include/asm/cache.h
498 +++ b/arch/alpha/include/asm/cache.h
499 @@ -4,19 +4,19 @@
500 #ifndef __ARCH_ALPHA_CACHE_H
501 #define __ARCH_ALPHA_CACHE_H
502
503 +#include <linux/const.h>
504
505 /* Bytes per L1 (data) cache line. */
506 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
507 -# define L1_CACHE_BYTES 64
508 # define L1_CACHE_SHIFT 6
509 #else
510 /* Both EV4 and EV5 are write-through, read-allocate,
511 direct-mapped, physical.
512 */
513 -# define L1_CACHE_BYTES 32
514 # define L1_CACHE_SHIFT 5
515 #endif
516
517 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
518 #define SMP_CACHE_BYTES L1_CACHE_BYTES
519
520 #endif
521 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
522 index 968d999..d36b2df 100644
523 --- a/arch/alpha/include/asm/elf.h
524 +++ b/arch/alpha/include/asm/elf.h
525 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
526
527 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
528
529 +#ifdef CONFIG_PAX_ASLR
530 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
531 +
532 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
533 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
534 +#endif
535 +
536 /* $0 is set by ld.so to a pointer to a function which might be
537 registered using atexit. This provides a mean for the dynamic
538 linker to call DT_FINI functions for shared libraries that have
539 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
540 index bc2a0da..8ad11ee 100644
541 --- a/arch/alpha/include/asm/pgalloc.h
542 +++ b/arch/alpha/include/asm/pgalloc.h
543 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
544 pgd_set(pgd, pmd);
545 }
546
547 +static inline void
548 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
549 +{
550 + pgd_populate(mm, pgd, pmd);
551 +}
552 +
553 extern pgd_t *pgd_alloc(struct mm_struct *mm);
554
555 static inline void
556 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
557 index 81a4342..348b927 100644
558 --- a/arch/alpha/include/asm/pgtable.h
559 +++ b/arch/alpha/include/asm/pgtable.h
560 @@ -102,6 +102,17 @@ struct vm_area_struct;
561 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
562 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
563 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
564 +
565 +#ifdef CONFIG_PAX_PAGEEXEC
566 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
567 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
568 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
569 +#else
570 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
571 +# define PAGE_COPY_NOEXEC PAGE_COPY
572 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
573 +#endif
574 +
575 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
576
577 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
578 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
579 index 2fd00b7..cfd5069 100644
580 --- a/arch/alpha/kernel/module.c
581 +++ b/arch/alpha/kernel/module.c
582 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
583
584 /* The small sections were sorted to the end of the segment.
585 The following should definitely cover them. */
586 - gp = (u64)me->module_core + me->core_size - 0x8000;
587 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
588 got = sechdrs[me->arch.gotsecindex].sh_addr;
589
590 for (i = 0; i < n; i++) {
591 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
592 index 14db93e..47bed62 100644
593 --- a/arch/alpha/kernel/osf_sys.c
594 +++ b/arch/alpha/kernel/osf_sys.c
595 @@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
596 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
597
598 static unsigned long
599 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
600 - unsigned long limit)
601 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
602 + unsigned long limit, unsigned long flags)
603 {
604 struct vm_area_struct *vma = find_vma(current->mm, addr);
605 -
606 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
607 while (1) {
608 /* At this point: (!vma || addr < vma->vm_end). */
609 if (limit - len < addr)
610 return -ENOMEM;
611 - if (!vma || addr + len <= vma->vm_start)
612 + if (check_heap_stack_gap(vma, addr, len, offset))
613 return addr;
614 addr = vma->vm_end;
615 vma = vma->vm_next;
616 @@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
617 merely specific addresses, but regions of memory -- perhaps
618 this feature should be incorporated into all ports? */
619
620 +#ifdef CONFIG_PAX_RANDMMAP
621 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
622 +#endif
623 +
624 if (addr) {
625 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
626 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
627 if (addr != (unsigned long) -ENOMEM)
628 return addr;
629 }
630
631 /* Next, try allocating at TASK_UNMAPPED_BASE. */
632 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
633 - len, limit);
634 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
635 +
636 if (addr != (unsigned long) -ENOMEM)
637 return addr;
638
639 /* Finally, try allocating in low memory. */
640 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
641 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
642
643 return addr;
644 }
645 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
646 index 0c4132d..88f0d53 100644
647 --- a/arch/alpha/mm/fault.c
648 +++ b/arch/alpha/mm/fault.c
649 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
650 __reload_thread(pcb);
651 }
652
653 +#ifdef CONFIG_PAX_PAGEEXEC
654 +/*
655 + * PaX: decide what to do with offenders (regs->pc = fault address)
656 + *
657 + * returns 1 when task should be killed
658 + * 2 when patched PLT trampoline was detected
659 + * 3 when unpatched PLT trampoline was detected
660 + */
661 +static int pax_handle_fetch_fault(struct pt_regs *regs)
662 +{
663 +
664 +#ifdef CONFIG_PAX_EMUPLT
665 + int err;
666 +
667 + do { /* PaX: patched PLT emulation #1 */
668 + unsigned int ldah, ldq, jmp;
669 +
670 + err = get_user(ldah, (unsigned int *)regs->pc);
671 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
672 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
673 +
674 + if (err)
675 + break;
676 +
677 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
678 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
679 + jmp == 0x6BFB0000U)
680 + {
681 + unsigned long r27, addr;
682 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
683 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
684 +
685 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
686 + err = get_user(r27, (unsigned long *)addr);
687 + if (err)
688 + break;
689 +
690 + regs->r27 = r27;
691 + regs->pc = r27;
692 + return 2;
693 + }
694 + } while (0);
695 +
696 + do { /* PaX: patched PLT emulation #2 */
697 + unsigned int ldah, lda, br;
698 +
699 + err = get_user(ldah, (unsigned int *)regs->pc);
700 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
701 + err |= get_user(br, (unsigned int *)(regs->pc+8));
702 +
703 + if (err)
704 + break;
705 +
706 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
707 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
708 + (br & 0xFFE00000U) == 0xC3E00000U)
709 + {
710 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
711 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
712 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
713 +
714 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
715 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
716 + return 2;
717 + }
718 + } while (0);
719 +
720 + do { /* PaX: unpatched PLT emulation */
721 + unsigned int br;
722 +
723 + err = get_user(br, (unsigned int *)regs->pc);
724 +
725 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
726 + unsigned int br2, ldq, nop, jmp;
727 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
728 +
729 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
730 + err = get_user(br2, (unsigned int *)addr);
731 + err |= get_user(ldq, (unsigned int *)(addr+4));
732 + err |= get_user(nop, (unsigned int *)(addr+8));
733 + err |= get_user(jmp, (unsigned int *)(addr+12));
734 + err |= get_user(resolver, (unsigned long *)(addr+16));
735 +
736 + if (err)
737 + break;
738 +
739 + if (br2 == 0xC3600000U &&
740 + ldq == 0xA77B000CU &&
741 + nop == 0x47FF041FU &&
742 + jmp == 0x6B7B0000U)
743 + {
744 + regs->r28 = regs->pc+4;
745 + regs->r27 = addr+16;
746 + regs->pc = resolver;
747 + return 3;
748 + }
749 + }
750 + } while (0);
751 +#endif
752 +
753 + return 1;
754 +}
755 +
756 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
757 +{
758 + unsigned long i;
759 +
760 + printk(KERN_ERR "PAX: bytes at PC: ");
761 + for (i = 0; i < 5; i++) {
762 + unsigned int c;
763 + if (get_user(c, (unsigned int *)pc+i))
764 + printk(KERN_CONT "???????? ");
765 + else
766 + printk(KERN_CONT "%08x ", c);
767 + }
768 + printk("\n");
769 +}
770 +#endif
771
772 /*
773 * This routine handles page faults. It determines the address,
774 @@ -133,8 +251,29 @@ retry:
775 good_area:
776 si_code = SEGV_ACCERR;
777 if (cause < 0) {
778 - if (!(vma->vm_flags & VM_EXEC))
779 + if (!(vma->vm_flags & VM_EXEC)) {
780 +
781 +#ifdef CONFIG_PAX_PAGEEXEC
782 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
783 + goto bad_area;
784 +
785 + up_read(&mm->mmap_sem);
786 + switch (pax_handle_fetch_fault(regs)) {
787 +
788 +#ifdef CONFIG_PAX_EMUPLT
789 + case 2:
790 + case 3:
791 + return;
792 +#endif
793 +
794 + }
795 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
796 + do_group_exit(SIGKILL);
797 +#else
798 goto bad_area;
799 +#endif
800 +
801 + }
802 } else if (!cause) {
803 /* Allow reads even for write-only mappings */
804 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
805 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
806 index 67874b8..0e40765 100644
807 --- a/arch/arm/Kconfig
808 +++ b/arch/arm/Kconfig
809 @@ -1813,7 +1813,7 @@ config ALIGNMENT_TRAP
810
811 config UACCESS_WITH_MEMCPY
812 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
813 - depends on MMU
814 + depends on MMU && !PAX_MEMORY_UDEREF
815 default y if CPU_FEROCEON
816 help
817 Implement faster copy_to_user and clear_user methods for CPU
818 diff --git a/arch/arm/common/gic.c b/arch/arm/common/gic.c
819 index 87dfa902..3a523fc 100644
820 --- a/arch/arm/common/gic.c
821 +++ b/arch/arm/common/gic.c
822 @@ -81,7 +81,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
823 * Supported arch specific GIC irq extension.
824 * Default make them NULL.
825 */
826 -struct irq_chip gic_arch_extn = {
827 +irq_chip_no_const gic_arch_extn __read_only = {
828 .irq_eoi = NULL,
829 .irq_mask = NULL,
830 .irq_unmask = NULL,
831 @@ -329,7 +329,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
832 chained_irq_exit(chip, desc);
833 }
834
835 -static struct irq_chip gic_chip = {
836 +static irq_chip_no_const gic_chip __read_only = {
837 .name = "GIC",
838 .irq_mask = gic_mask_irq,
839 .irq_unmask = gic_unmask_irq,
840 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
841 index c79f61f..9ac0642 100644
842 --- a/arch/arm/include/asm/atomic.h
843 +++ b/arch/arm/include/asm/atomic.h
844 @@ -17,17 +17,35 @@
845 #include <asm/barrier.h>
846 #include <asm/cmpxchg.h>
847
848 +#ifdef CONFIG_GENERIC_ATOMIC64
849 +#include <asm-generic/atomic64.h>
850 +#endif
851 +
852 #define ATOMIC_INIT(i) { (i) }
853
854 #ifdef __KERNEL__
855
856 +#define _ASM_EXTABLE(from, to) \
857 +" .pushsection __ex_table,\"a\"\n"\
858 +" .align 3\n" \
859 +" .long " #from ", " #to"\n" \
860 +" .popsection"
861 +
862 /*
863 * On ARM, ordinary assignment (str instruction) doesn't clear the local
864 * strex/ldrex monitor on some implementations. The reason we can use it for
865 * atomic_set() is the clrex or dummy strex done on every exception return.
866 */
867 #define atomic_read(v) (*(volatile int *)&(v)->counter)
868 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
869 +{
870 + return v->counter;
871 +}
872 #define atomic_set(v,i) (((v)->counter) = (i))
873 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
874 +{
875 + v->counter = i;
876 +}
877
878 #if __LINUX_ARM_ARCH__ >= 6
879
880 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
881 int result;
882
883 __asm__ __volatile__("@ atomic_add\n"
884 +"1: ldrex %1, [%3]\n"
885 +" adds %0, %1, %4\n"
886 +
887 +#ifdef CONFIG_PAX_REFCOUNT
888 +" bvc 3f\n"
889 +"2: bkpt 0xf103\n"
890 +"3:\n"
891 +#endif
892 +
893 +" strex %1, %0, [%3]\n"
894 +" teq %1, #0\n"
895 +" bne 1b"
896 +
897 +#ifdef CONFIG_PAX_REFCOUNT
898 +"\n4:\n"
899 + _ASM_EXTABLE(2b, 4b)
900 +#endif
901 +
902 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
903 + : "r" (&v->counter), "Ir" (i)
904 + : "cc");
905 +}
906 +
907 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
908 +{
909 + unsigned long tmp;
910 + int result;
911 +
912 + __asm__ __volatile__("@ atomic_add_unchecked\n"
913 "1: ldrex %0, [%3]\n"
914 " add %0, %0, %4\n"
915 " strex %1, %0, [%3]\n"
916 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
917 smp_mb();
918
919 __asm__ __volatile__("@ atomic_add_return\n"
920 +"1: ldrex %1, [%3]\n"
921 +" adds %0, %1, %4\n"
922 +
923 +#ifdef CONFIG_PAX_REFCOUNT
924 +" bvc 3f\n"
925 +" mov %0, %1\n"
926 +"2: bkpt 0xf103\n"
927 +"3:\n"
928 +#endif
929 +
930 +" strex %1, %0, [%3]\n"
931 +" teq %1, #0\n"
932 +" bne 1b"
933 +
934 +#ifdef CONFIG_PAX_REFCOUNT
935 +"\n4:\n"
936 + _ASM_EXTABLE(2b, 4b)
937 +#endif
938 +
939 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
940 + : "r" (&v->counter), "Ir" (i)
941 + : "cc");
942 +
943 + smp_mb();
944 +
945 + return result;
946 +}
947 +
948 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
949 +{
950 + unsigned long tmp;
951 + int result;
952 +
953 + smp_mb();
954 +
955 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
956 "1: ldrex %0, [%3]\n"
957 " add %0, %0, %4\n"
958 " strex %1, %0, [%3]\n"
959 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
960 int result;
961
962 __asm__ __volatile__("@ atomic_sub\n"
963 +"1: ldrex %1, [%3]\n"
964 +" subs %0, %1, %4\n"
965 +
966 +#ifdef CONFIG_PAX_REFCOUNT
967 +" bvc 3f\n"
968 +"2: bkpt 0xf103\n"
969 +"3:\n"
970 +#endif
971 +
972 +" strex %1, %0, [%3]\n"
973 +" teq %1, #0\n"
974 +" bne 1b"
975 +
976 +#ifdef CONFIG_PAX_REFCOUNT
977 +"\n4:\n"
978 + _ASM_EXTABLE(2b, 4b)
979 +#endif
980 +
981 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
982 + : "r" (&v->counter), "Ir" (i)
983 + : "cc");
984 +}
985 +
986 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
987 +{
988 + unsigned long tmp;
989 + int result;
990 +
991 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
992 "1: ldrex %0, [%3]\n"
993 " sub %0, %0, %4\n"
994 " strex %1, %0, [%3]\n"
995 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
996 smp_mb();
997
998 __asm__ __volatile__("@ atomic_sub_return\n"
999 -"1: ldrex %0, [%3]\n"
1000 -" sub %0, %0, %4\n"
1001 +"1: ldrex %1, [%3]\n"
1002 +" subs %0, %1, %4\n"
1003 +
1004 +#ifdef CONFIG_PAX_REFCOUNT
1005 +" bvc 3f\n"
1006 +" mov %0, %1\n"
1007 +"2: bkpt 0xf103\n"
1008 +"3:\n"
1009 +#endif
1010 +
1011 " strex %1, %0, [%3]\n"
1012 " teq %1, #0\n"
1013 " bne 1b"
1014 +
1015 +#ifdef CONFIG_PAX_REFCOUNT
1016 +"\n4:\n"
1017 + _ASM_EXTABLE(2b, 4b)
1018 +#endif
1019 +
1020 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1021 : "r" (&v->counter), "Ir" (i)
1022 : "cc");
1023 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1024 return oldval;
1025 }
1026
1027 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1028 +{
1029 + unsigned long oldval, res;
1030 +
1031 + smp_mb();
1032 +
1033 + do {
1034 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1035 + "ldrex %1, [%3]\n"
1036 + "mov %0, #0\n"
1037 + "teq %1, %4\n"
1038 + "strexeq %0, %5, [%3]\n"
1039 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1040 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1041 + : "cc");
1042 + } while (res);
1043 +
1044 + smp_mb();
1045 +
1046 + return oldval;
1047 +}
1048 +
1049 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1050 {
1051 unsigned long tmp, tmp2;
1052 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1053
1054 return val;
1055 }
1056 +
1057 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1058 +{
1059 + return atomic_add_return(i, v);
1060 +}
1061 +
1062 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1063 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1064 +{
1065 + (void) atomic_add_return(i, v);
1066 +}
1067
1068 static inline int atomic_sub_return(int i, atomic_t *v)
1069 {
1070 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1071 return val;
1072 }
1073 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1074 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1075 +{
1076 + (void) atomic_sub_return(i, v);
1077 +}
1078
1079 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1080 {
1081 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1082 return ret;
1083 }
1084
1085 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1086 +{
1087 + return atomic_cmpxchg(v, old, new);
1088 +}
1089 +
1090 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1091 {
1092 unsigned long flags;
1093 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1094 #endif /* __LINUX_ARM_ARCH__ */
1095
1096 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1097 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1098 +{
1099 + return xchg(&v->counter, new);
1100 +}
1101
1102 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1103 {
1104 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1105 }
1106
1107 #define atomic_inc(v) atomic_add(1, v)
1108 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1109 +{
1110 + atomic_add_unchecked(1, v);
1111 +}
1112 #define atomic_dec(v) atomic_sub(1, v)
1113 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1114 +{
1115 + atomic_sub_unchecked(1, v);
1116 +}
1117
1118 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1119 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1120 +{
1121 + return atomic_add_return_unchecked(1, v) == 0;
1122 +}
1123 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1124 #define atomic_inc_return(v) (atomic_add_return(1, v))
1125 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1126 +{
1127 + return atomic_add_return_unchecked(1, v);
1128 +}
1129 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1130 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1131
1132 @@ -241,6 +428,14 @@ typedef struct {
1133 u64 __aligned(8) counter;
1134 } atomic64_t;
1135
1136 +#ifdef CONFIG_PAX_REFCOUNT
1137 +typedef struct {
1138 + u64 __aligned(8) counter;
1139 +} atomic64_unchecked_t;
1140 +#else
1141 +typedef atomic64_t atomic64_unchecked_t;
1142 +#endif
1143 +
1144 #define ATOMIC64_INIT(i) { (i) }
1145
1146 static inline u64 atomic64_read(const atomic64_t *v)
1147 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1148 return result;
1149 }
1150
1151 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1152 +{
1153 + u64 result;
1154 +
1155 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1156 +" ldrexd %0, %H0, [%1]"
1157 + : "=&r" (result)
1158 + : "r" (&v->counter), "Qo" (v->counter)
1159 + );
1160 +
1161 + return result;
1162 +}
1163 +
1164 static inline void atomic64_set(atomic64_t *v, u64 i)
1165 {
1166 u64 tmp;
1167 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1168 : "cc");
1169 }
1170
1171 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1172 +{
1173 + u64 tmp;
1174 +
1175 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1176 +"1: ldrexd %0, %H0, [%2]\n"
1177 +" strexd %0, %3, %H3, [%2]\n"
1178 +" teq %0, #0\n"
1179 +" bne 1b"
1180 + : "=&r" (tmp), "=Qo" (v->counter)
1181 + : "r" (&v->counter), "r" (i)
1182 + : "cc");
1183 +}
1184 +
1185 static inline void atomic64_add(u64 i, atomic64_t *v)
1186 {
1187 u64 result;
1188 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1189 __asm__ __volatile__("@ atomic64_add\n"
1190 "1: ldrexd %0, %H0, [%3]\n"
1191 " adds %0, %0, %4\n"
1192 +" adcs %H0, %H0, %H4\n"
1193 +
1194 +#ifdef CONFIG_PAX_REFCOUNT
1195 +" bvc 3f\n"
1196 +"2: bkpt 0xf103\n"
1197 +"3:\n"
1198 +#endif
1199 +
1200 +" strexd %1, %0, %H0, [%3]\n"
1201 +" teq %1, #0\n"
1202 +" bne 1b"
1203 +
1204 +#ifdef CONFIG_PAX_REFCOUNT
1205 +"\n4:\n"
1206 + _ASM_EXTABLE(2b, 4b)
1207 +#endif
1208 +
1209 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1210 + : "r" (&v->counter), "r" (i)
1211 + : "cc");
1212 +}
1213 +
1214 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1215 +{
1216 + u64 result;
1217 + unsigned long tmp;
1218 +
1219 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1220 +"1: ldrexd %0, %H0, [%3]\n"
1221 +" adds %0, %0, %4\n"
1222 " adc %H0, %H0, %H4\n"
1223 " strexd %1, %0, %H0, [%3]\n"
1224 " teq %1, #0\n"
1225 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1226
1227 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1228 {
1229 - u64 result;
1230 - unsigned long tmp;
1231 + u64 result, tmp;
1232
1233 smp_mb();
1234
1235 __asm__ __volatile__("@ atomic64_add_return\n"
1236 +"1: ldrexd %1, %H1, [%3]\n"
1237 +" adds %0, %1, %4\n"
1238 +" adcs %H0, %H1, %H4\n"
1239 +
1240 +#ifdef CONFIG_PAX_REFCOUNT
1241 +" bvc 3f\n"
1242 +" mov %0, %1\n"
1243 +" mov %H0, %H1\n"
1244 +"2: bkpt 0xf103\n"
1245 +"3:\n"
1246 +#endif
1247 +
1248 +" strexd %1, %0, %H0, [%3]\n"
1249 +" teq %1, #0\n"
1250 +" bne 1b"
1251 +
1252 +#ifdef CONFIG_PAX_REFCOUNT
1253 +"\n4:\n"
1254 + _ASM_EXTABLE(2b, 4b)
1255 +#endif
1256 +
1257 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1258 + : "r" (&v->counter), "r" (i)
1259 + : "cc");
1260 +
1261 + smp_mb();
1262 +
1263 + return result;
1264 +}
1265 +
1266 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1267 +{
1268 + u64 result;
1269 + unsigned long tmp;
1270 +
1271 + smp_mb();
1272 +
1273 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1274 "1: ldrexd %0, %H0, [%3]\n"
1275 " adds %0, %0, %4\n"
1276 " adc %H0, %H0, %H4\n"
1277 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1278 __asm__ __volatile__("@ atomic64_sub\n"
1279 "1: ldrexd %0, %H0, [%3]\n"
1280 " subs %0, %0, %4\n"
1281 +" sbcs %H0, %H0, %H4\n"
1282 +
1283 +#ifdef CONFIG_PAX_REFCOUNT
1284 +" bvc 3f\n"
1285 +"2: bkpt 0xf103\n"
1286 +"3:\n"
1287 +#endif
1288 +
1289 +" strexd %1, %0, %H0, [%3]\n"
1290 +" teq %1, #0\n"
1291 +" bne 1b"
1292 +
1293 +#ifdef CONFIG_PAX_REFCOUNT
1294 +"\n4:\n"
1295 + _ASM_EXTABLE(2b, 4b)
1296 +#endif
1297 +
1298 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1299 + : "r" (&v->counter), "r" (i)
1300 + : "cc");
1301 +}
1302 +
1303 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1304 +{
1305 + u64 result;
1306 + unsigned long tmp;
1307 +
1308 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1309 +"1: ldrexd %0, %H0, [%3]\n"
1310 +" subs %0, %0, %4\n"
1311 " sbc %H0, %H0, %H4\n"
1312 " strexd %1, %0, %H0, [%3]\n"
1313 " teq %1, #0\n"
1314 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1315
1316 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1317 {
1318 - u64 result;
1319 - unsigned long tmp;
1320 + u64 result, tmp;
1321
1322 smp_mb();
1323
1324 __asm__ __volatile__("@ atomic64_sub_return\n"
1325 -"1: ldrexd %0, %H0, [%3]\n"
1326 -" subs %0, %0, %4\n"
1327 -" sbc %H0, %H0, %H4\n"
1328 +"1: ldrexd %1, %H1, [%3]\n"
1329 +" subs %0, %1, %4\n"
1330 +" sbcs %H0, %H1, %H4\n"
1331 +
1332 +#ifdef CONFIG_PAX_REFCOUNT
1333 +" bvc 3f\n"
1334 +" mov %0, %1\n"
1335 +" mov %H0, %H1\n"
1336 +"2: bkpt 0xf103\n"
1337 +"3:\n"
1338 +#endif
1339 +
1340 " strexd %1, %0, %H0, [%3]\n"
1341 " teq %1, #0\n"
1342 " bne 1b"
1343 +
1344 +#ifdef CONFIG_PAX_REFCOUNT
1345 +"\n4:\n"
1346 + _ASM_EXTABLE(2b, 4b)
1347 +#endif
1348 +
1349 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1350 : "r" (&v->counter), "r" (i)
1351 : "cc");
1352 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1353 return oldval;
1354 }
1355
1356 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1357 +{
1358 + u64 oldval;
1359 + unsigned long res;
1360 +
1361 + smp_mb();
1362 +
1363 + do {
1364 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1365 + "ldrexd %1, %H1, [%3]\n"
1366 + "mov %0, #0\n"
1367 + "teq %1, %4\n"
1368 + "teqeq %H1, %H4\n"
1369 + "strexdeq %0, %5, %H5, [%3]"
1370 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1371 + : "r" (&ptr->counter), "r" (old), "r" (new)
1372 + : "cc");
1373 + } while (res);
1374 +
1375 + smp_mb();
1376 +
1377 + return oldval;
1378 +}
1379 +
1380 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1381 {
1382 u64 result;
1383 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1384
1385 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1386 {
1387 - u64 result;
1388 - unsigned long tmp;
1389 + u64 result, tmp;
1390
1391 smp_mb();
1392
1393 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1394 -"1: ldrexd %0, %H0, [%3]\n"
1395 -" subs %0, %0, #1\n"
1396 -" sbc %H0, %H0, #0\n"
1397 +"1: ldrexd %1, %H1, [%3]\n"
1398 +" subs %0, %1, #1\n"
1399 +" sbcs %H0, %H1, #0\n"
1400 +
1401 +#ifdef CONFIG_PAX_REFCOUNT
1402 +" bvc 3f\n"
1403 +" mov %0, %1\n"
1404 +" mov %H0, %H1\n"
1405 +"2: bkpt 0xf103\n"
1406 +"3:\n"
1407 +#endif
1408 +
1409 " teq %H0, #0\n"
1410 -" bmi 2f\n"
1411 +" bmi 4f\n"
1412 " strexd %1, %0, %H0, [%3]\n"
1413 " teq %1, #0\n"
1414 " bne 1b\n"
1415 -"2:"
1416 +"4:\n"
1417 +
1418 +#ifdef CONFIG_PAX_REFCOUNT
1419 + _ASM_EXTABLE(2b, 4b)
1420 +#endif
1421 +
1422 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1423 : "r" (&v->counter)
1424 : "cc");
1425 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1426 " teq %0, %5\n"
1427 " teqeq %H0, %H5\n"
1428 " moveq %1, #0\n"
1429 -" beq 2f\n"
1430 +" beq 4f\n"
1431 " adds %0, %0, %6\n"
1432 -" adc %H0, %H0, %H6\n"
1433 +" adcs %H0, %H0, %H6\n"
1434 +
1435 +#ifdef CONFIG_PAX_REFCOUNT
1436 +" bvc 3f\n"
1437 +"2: bkpt 0xf103\n"
1438 +"3:\n"
1439 +#endif
1440 +
1441 " strexd %2, %0, %H0, [%4]\n"
1442 " teq %2, #0\n"
1443 " bne 1b\n"
1444 -"2:"
1445 +"4:\n"
1446 +
1447 +#ifdef CONFIG_PAX_REFCOUNT
1448 + _ASM_EXTABLE(2b, 4b)
1449 +#endif
1450 +
1451 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1452 : "r" (&v->counter), "r" (u), "r" (a)
1453 : "cc");
1454 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1455
1456 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1457 #define atomic64_inc(v) atomic64_add(1LL, (v))
1458 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1459 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1460 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1461 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1462 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1463 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1464 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1465 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1466 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1467 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1468 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1469 index 75fe66b..ba3dee4 100644
1470 --- a/arch/arm/include/asm/cache.h
1471 +++ b/arch/arm/include/asm/cache.h
1472 @@ -4,8 +4,10 @@
1473 #ifndef __ASMARM_CACHE_H
1474 #define __ASMARM_CACHE_H
1475
1476 +#include <linux/const.h>
1477 +
1478 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1479 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1480 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1481
1482 /*
1483 * Memory returned by kmalloc() may be used for DMA, so we must make
1484 @@ -24,5 +26,6 @@
1485 #endif
1486
1487 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1488 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1489
1490 #endif
1491 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1492 index e1489c5..d418304 100644
1493 --- a/arch/arm/include/asm/cacheflush.h
1494 +++ b/arch/arm/include/asm/cacheflush.h
1495 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1496 void (*dma_unmap_area)(const void *, size_t, int);
1497
1498 void (*dma_flush_range)(const void *, const void *);
1499 -};
1500 +} __no_const;
1501
1502 /*
1503 * Select the calling method
1504 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1505 index 6dcc164..b14d917 100644
1506 --- a/arch/arm/include/asm/checksum.h
1507 +++ b/arch/arm/include/asm/checksum.h
1508 @@ -37,7 +37,19 @@ __wsum
1509 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1510
1511 __wsum
1512 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1513 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1514 +
1515 +static inline __wsum
1516 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1517 +{
1518 + __wsum ret;
1519 + pax_open_userland();
1520 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1521 + pax_close_userland();
1522 + return ret;
1523 +}
1524 +
1525 +
1526
1527 /*
1528 * Fold a partial checksum without adding pseudo headers
1529 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1530 index 7eb18c1..e38b6d2 100644
1531 --- a/arch/arm/include/asm/cmpxchg.h
1532 +++ b/arch/arm/include/asm/cmpxchg.h
1533 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1534
1535 #define xchg(ptr,x) \
1536 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1537 +#define xchg_unchecked(ptr,x) \
1538 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1539
1540 #include <asm-generic/cmpxchg-local.h>
1541
1542 diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1543 index ab98fdd..6b19938 100644
1544 --- a/arch/arm/include/asm/delay.h
1545 +++ b/arch/arm/include/asm/delay.h
1546 @@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1547 void (*delay)(unsigned long);
1548 void (*const_udelay)(unsigned long);
1549 void (*udelay)(unsigned long);
1550 -} arm_delay_ops;
1551 +} *arm_delay_ops;
1552
1553 -#define __delay(n) arm_delay_ops.delay(n)
1554 +#define __delay(n) arm_delay_ops->delay(n)
1555
1556 /*
1557 * This function intentionally does not exist; if you see references to
1558 @@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1559 * first constant multiplications gets optimized away if the delay is
1560 * a constant)
1561 */
1562 -#define __udelay(n) arm_delay_ops.udelay(n)
1563 -#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1564 +#define __udelay(n) arm_delay_ops->udelay(n)
1565 +#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1566
1567 #define udelay(n) \
1568 (__builtin_constant_p(n) ? \
1569 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1570 index 6ddbe44..b5e38b1 100644
1571 --- a/arch/arm/include/asm/domain.h
1572 +++ b/arch/arm/include/asm/domain.h
1573 @@ -48,18 +48,37 @@
1574 * Domain types
1575 */
1576 #define DOMAIN_NOACCESS 0
1577 -#define DOMAIN_CLIENT 1
1578 #ifdef CONFIG_CPU_USE_DOMAINS
1579 +#define DOMAIN_USERCLIENT 1
1580 +#define DOMAIN_KERNELCLIENT 1
1581 #define DOMAIN_MANAGER 3
1582 +#define DOMAIN_VECTORS DOMAIN_USER
1583 #else
1584 +
1585 +#ifdef CONFIG_PAX_KERNEXEC
1586 #define DOMAIN_MANAGER 1
1587 +#define DOMAIN_KERNEXEC 3
1588 +#else
1589 +#define DOMAIN_MANAGER 1
1590 +#endif
1591 +
1592 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1593 +#define DOMAIN_USERCLIENT 0
1594 +#define DOMAIN_UDEREF 1
1595 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1596 +#else
1597 +#define DOMAIN_USERCLIENT 1
1598 +#define DOMAIN_VECTORS DOMAIN_USER
1599 +#endif
1600 +#define DOMAIN_KERNELCLIENT 1
1601 +
1602 #endif
1603
1604 #define domain_val(dom,type) ((type) << (2*(dom)))
1605
1606 #ifndef __ASSEMBLY__
1607
1608 -#ifdef CONFIG_CPU_USE_DOMAINS
1609 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1610 static inline void set_domain(unsigned val)
1611 {
1612 asm volatile(
1613 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1614 isb();
1615 }
1616
1617 -#define modify_domain(dom,type) \
1618 - do { \
1619 - struct thread_info *thread = current_thread_info(); \
1620 - unsigned int domain = thread->cpu_domain; \
1621 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1622 - thread->cpu_domain = domain | domain_val(dom, type); \
1623 - set_domain(thread->cpu_domain); \
1624 - } while (0)
1625 -
1626 +extern void modify_domain(unsigned int dom, unsigned int type);
1627 #else
1628 static inline void set_domain(unsigned val) { }
1629 static inline void modify_domain(unsigned dom, unsigned type) { }
1630 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1631 index 38050b1..9d90e8b 100644
1632 --- a/arch/arm/include/asm/elf.h
1633 +++ b/arch/arm/include/asm/elf.h
1634 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1635 the loader. We need to make sure that it is out of the way of the program
1636 that it will "exec", and that there is sufficient room for the brk. */
1637
1638 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1639 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1640 +
1641 +#ifdef CONFIG_PAX_ASLR
1642 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1643 +
1644 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1645 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1646 +#endif
1647
1648 /* When the program starts, a1 contains a pointer to a function to be
1649 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1650 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1651 extern void elf_set_personality(const struct elf32_hdr *);
1652 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1653
1654 -struct mm_struct;
1655 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1656 -#define arch_randomize_brk arch_randomize_brk
1657 -
1658 #endif
1659 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1660 index de53547..52b9a28 100644
1661 --- a/arch/arm/include/asm/fncpy.h
1662 +++ b/arch/arm/include/asm/fncpy.h
1663 @@ -81,7 +81,9 @@
1664 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1665 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1666 \
1667 + pax_open_kernel(); \
1668 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1669 + pax_close_kernel(); \
1670 flush_icache_range((unsigned long)(dest_buf), \
1671 (unsigned long)(dest_buf) + (size)); \
1672 \
1673 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1674 index e42cf59..7b94b8f 100644
1675 --- a/arch/arm/include/asm/futex.h
1676 +++ b/arch/arm/include/asm/futex.h
1677 @@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1678 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1679 return -EFAULT;
1680
1681 + pax_open_userland();
1682 +
1683 smp_mb();
1684 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1685 "1: ldrex %1, [%4]\n"
1686 @@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1687 : "cc", "memory");
1688 smp_mb();
1689
1690 + pax_close_userland();
1691 +
1692 *uval = val;
1693 return ret;
1694 }
1695 @@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1696 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1697 return -EFAULT;
1698
1699 + pax_open_userland();
1700 +
1701 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1702 "1: " TUSER(ldr) " %1, [%4]\n"
1703 " teq %1, %2\n"
1704 @@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1705 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1706 : "cc", "memory");
1707
1708 + pax_close_userland();
1709 +
1710 *uval = val;
1711 return ret;
1712 }
1713 @@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1714 return -EFAULT;
1715
1716 pagefault_disable(); /* implies preempt_disable() */
1717 + pax_open_userland();
1718
1719 switch (op) {
1720 case FUTEX_OP_SET:
1721 @@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1722 ret = -ENOSYS;
1723 }
1724
1725 + pax_close_userland();
1726 pagefault_enable(); /* subsumes preempt_enable() */
1727
1728 if (!ret) {
1729 diff --git a/arch/arm/include/asm/hardware/gic.h b/arch/arm/include/asm/hardware/gic.h
1730 index 4b1ce6c..bea3f73 100644
1731 --- a/arch/arm/include/asm/hardware/gic.h
1732 +++ b/arch/arm/include/asm/hardware/gic.h
1733 @@ -34,9 +34,10 @@
1734
1735 #ifndef __ASSEMBLY__
1736 #include <linux/irqdomain.h>
1737 +#include <linux/irq.h>
1738 struct device_node;
1739
1740 -extern struct irq_chip gic_arch_extn;
1741 +extern irq_chip_no_const gic_arch_extn;
1742
1743 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
1744 u32 offset, struct device_node *);
1745 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1746 index 83eb2f7..ed77159 100644
1747 --- a/arch/arm/include/asm/kmap_types.h
1748 +++ b/arch/arm/include/asm/kmap_types.h
1749 @@ -4,6 +4,6 @@
1750 /*
1751 * This is the "bare minimum". AIO seems to require this.
1752 */
1753 -#define KM_TYPE_NR 16
1754 +#define KM_TYPE_NR 17
1755
1756 #endif
1757 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1758 index 9e614a1..3302cca 100644
1759 --- a/arch/arm/include/asm/mach/dma.h
1760 +++ b/arch/arm/include/asm/mach/dma.h
1761 @@ -22,7 +22,7 @@ struct dma_ops {
1762 int (*residue)(unsigned int, dma_t *); /* optional */
1763 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1764 const char *type;
1765 -};
1766 +} __do_const;
1767
1768 struct dma_struct {
1769 void *addr; /* single DMA address */
1770 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1771 index 2fe141f..192dc01 100644
1772 --- a/arch/arm/include/asm/mach/map.h
1773 +++ b/arch/arm/include/asm/mach/map.h
1774 @@ -27,13 +27,16 @@ struct map_desc {
1775 #define MT_MINICLEAN 6
1776 #define MT_LOW_VECTORS 7
1777 #define MT_HIGH_VECTORS 8
1778 -#define MT_MEMORY 9
1779 +#define MT_MEMORY_RWX 9
1780 #define MT_ROM 10
1781 -#define MT_MEMORY_NONCACHED 11
1782 +#define MT_MEMORY_NONCACHED_RX 11
1783 #define MT_MEMORY_DTCM 12
1784 #define MT_MEMORY_ITCM 13
1785 #define MT_MEMORY_SO 14
1786 #define MT_MEMORY_DMA_READY 15
1787 +#define MT_MEMORY_RW 16
1788 +#define MT_MEMORY_RX 17
1789 +#define MT_MEMORY_NONCACHED_RW 18
1790
1791 #ifdef CONFIG_MMU
1792 extern void iotable_init(struct map_desc *, int);
1793 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1794 index 53426c6..c7baff3 100644
1795 --- a/arch/arm/include/asm/outercache.h
1796 +++ b/arch/arm/include/asm/outercache.h
1797 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1798 #endif
1799 void (*set_debug)(unsigned long);
1800 void (*resume)(void);
1801 -};
1802 +} __no_const;
1803
1804 #ifdef CONFIG_OUTER_CACHE
1805
1806 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1807 index 812a494..71fc0b6 100644
1808 --- a/arch/arm/include/asm/page.h
1809 +++ b/arch/arm/include/asm/page.h
1810 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1811 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1812 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1813 unsigned long vaddr, struct vm_area_struct *vma);
1814 -};
1815 +} __no_const;
1816
1817 #ifdef MULTI_USER
1818 extern struct cpu_user_fns cpu_user;
1819 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1820 index 943504f..c37a730 100644
1821 --- a/arch/arm/include/asm/pgalloc.h
1822 +++ b/arch/arm/include/asm/pgalloc.h
1823 @@ -17,6 +17,7 @@
1824 #include <asm/processor.h>
1825 #include <asm/cacheflush.h>
1826 #include <asm/tlbflush.h>
1827 +#include <asm/system_info.h>
1828
1829 #define check_pgt_cache() do { } while (0)
1830
1831 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1832 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1833 }
1834
1835 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1836 +{
1837 + pud_populate(mm, pud, pmd);
1838 +}
1839 +
1840 #else /* !CONFIG_ARM_LPAE */
1841
1842 /*
1843 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1844 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1845 #define pmd_free(mm, pmd) do { } while (0)
1846 #define pud_populate(mm,pmd,pte) BUG()
1847 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1848
1849 #endif /* CONFIG_ARM_LPAE */
1850
1851 @@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1852 __free_page(pte);
1853 }
1854
1855 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1856 +{
1857 +#ifdef CONFIG_ARM_LPAE
1858 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1859 +#else
1860 + if (addr & SECTION_SIZE)
1861 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1862 + else
1863 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1864 +#endif
1865 + flush_pmd_entry(pmdp);
1866 +}
1867 +
1868 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1869 pmdval_t prot)
1870 {
1871 @@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1872 static inline void
1873 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1874 {
1875 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1876 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1877 }
1878 #define pmd_pgtable(pmd) pmd_page(pmd)
1879
1880 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1881 index 5cfba15..f415e1a 100644
1882 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1883 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1884 @@ -20,12 +20,15 @@
1885 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1886 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1887 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1888 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1889 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1890 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1891 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1892 +
1893 /*
1894 * - section
1895 */
1896 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1897 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1898 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1899 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1900 @@ -37,6 +40,7 @@
1901 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1902 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1903 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1904 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1905
1906 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1907 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1908 @@ -66,6 +70,7 @@
1909 * - extended small page/tiny page
1910 */
1911 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1912 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1913 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1914 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1915 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1916 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1917 index f97ee02..07f1be5 100644
1918 --- a/arch/arm/include/asm/pgtable-2level.h
1919 +++ b/arch/arm/include/asm/pgtable-2level.h
1920 @@ -125,6 +125,7 @@
1921 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1922 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1923 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1924 +#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1925
1926 /*
1927 * These are the memory types, defined to be compatible with
1928 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1929 index d795282..a43ea90 100644
1930 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1931 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1932 @@ -32,15 +32,18 @@
1933 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1934 #define PMD_BIT4 (_AT(pmdval_t, 0))
1935 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1936 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1937
1938 /*
1939 * - section
1940 */
1941 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1942 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1943 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1944 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1945 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1946 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1947 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1948 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1949 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1950 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1951 @@ -66,6 +69,7 @@
1952 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1953 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1954 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1955 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1956 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1957
1958 /*
1959 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1960 index a3f3792..7b932a6 100644
1961 --- a/arch/arm/include/asm/pgtable-3level.h
1962 +++ b/arch/arm/include/asm/pgtable-3level.h
1963 @@ -74,6 +74,7 @@
1964 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1965 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1966 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1967 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1968 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1969 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1970 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1971 @@ -82,6 +83,7 @@
1972 /*
1973 * To be used in assembly code with the upper page attributes.
1974 */
1975 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1976 #define L_PTE_XN_HIGH (1 << (54 - 32))
1977 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1978
1979 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1980 index 9c82f988..514705a 100644
1981 --- a/arch/arm/include/asm/pgtable.h
1982 +++ b/arch/arm/include/asm/pgtable.h
1983 @@ -30,6 +30,9 @@
1984 #include <asm/pgtable-2level.h>
1985 #endif
1986
1987 +#define ktla_ktva(addr) (addr)
1988 +#define ktva_ktla(addr) (addr)
1989 +
1990 /*
1991 * Just any arbitrary offset to the start of the vmalloc VM area: the
1992 * current 8MB value just means that there will be a 8MB "hole" after the
1993 @@ -45,6 +48,9 @@
1994 #define LIBRARY_TEXT_START 0x0c000000
1995
1996 #ifndef __ASSEMBLY__
1997 +extern pteval_t __supported_pte_mask;
1998 +extern pmdval_t __supported_pmd_mask;
1999 +
2000 extern void __pte_error(const char *file, int line, pte_t);
2001 extern void __pmd_error(const char *file, int line, pmd_t);
2002 extern void __pgd_error(const char *file, int line, pgd_t);
2003 @@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2004 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2005 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2006
2007 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2008 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2009 +
2010 +#ifdef CONFIG_PAX_KERNEXEC
2011 +#include <asm/domain.h>
2012 +#include <linux/thread_info.h>
2013 +#include <linux/preempt.h>
2014 +#endif
2015 +
2016 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2017 +static inline int test_domain(int domain, int domaintype)
2018 +{
2019 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2020 +}
2021 +#endif
2022 +
2023 +#ifdef CONFIG_PAX_KERNEXEC
2024 +static inline unsigned long pax_open_kernel(void) {
2025 +#ifdef CONFIG_ARM_LPAE
2026 + /* TODO */
2027 +#else
2028 + preempt_disable();
2029 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2030 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2031 +#endif
2032 + return 0;
2033 +}
2034 +
2035 +static inline unsigned long pax_close_kernel(void) {
2036 +#ifdef CONFIG_ARM_LPAE
2037 + /* TODO */
2038 +#else
2039 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2040 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2041 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2042 + preempt_enable_no_resched();
2043 +#endif
2044 + return 0;
2045 +}
2046 +#else
2047 +static inline unsigned long pax_open_kernel(void) { return 0; }
2048 +static inline unsigned long pax_close_kernel(void) { return 0; }
2049 +#endif
2050 +
2051 /*
2052 * This is the lowest virtual address we can permit any user space
2053 * mapping to be mapped at. This is particularly important for
2054 @@ -63,8 +113,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2055 /*
2056 * The pgprot_* and protection_map entries will be fixed up in runtime
2057 * to include the cachable and bufferable bits based on memory policy,
2058 - * as well as any architecture dependent bits like global/ASID and SMP
2059 - * shared mapping bits.
2060 + * as well as any architecture dependent bits like global/ASID, PXN,
2061 + * and SMP shared mapping bits.
2062 */
2063 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2064
2065 @@ -240,7 +290,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2066
2067 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2068 {
2069 - const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE;
2070 + const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE | __supported_pte_mask;
2071 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2072 return pte;
2073 }
2074 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2075 index f3628fb..a0672dd 100644
2076 --- a/arch/arm/include/asm/proc-fns.h
2077 +++ b/arch/arm/include/asm/proc-fns.h
2078 @@ -75,7 +75,7 @@ extern struct processor {
2079 unsigned int suspend_size;
2080 void (*do_suspend)(void *);
2081 void (*do_resume)(void *);
2082 -} processor;
2083 +} __do_const processor;
2084
2085 #ifndef MULTI_CPU
2086 extern void cpu_proc_init(void);
2087 diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2088 index 06e7d50..8a8e251 100644
2089 --- a/arch/arm/include/asm/processor.h
2090 +++ b/arch/arm/include/asm/processor.h
2091 @@ -65,9 +65,8 @@ struct thread_struct {
2092 regs->ARM_cpsr |= PSR_ENDSTATE; \
2093 regs->ARM_pc = pc & ~1; /* pc */ \
2094 regs->ARM_sp = sp; /* sp */ \
2095 - regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2096 - regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2097 - regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2098 + /* r2 (envp), r1 (argv), r0 (argc) */ \
2099 + (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2100 nommu_start_thread(regs); \
2101 })
2102
2103 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2104 index d3a22be..3a69ad5 100644
2105 --- a/arch/arm/include/asm/smp.h
2106 +++ b/arch/arm/include/asm/smp.h
2107 @@ -107,7 +107,7 @@ struct smp_operations {
2108 int (*cpu_disable)(unsigned int cpu);
2109 #endif
2110 #endif
2111 -};
2112 +} __no_const;
2113
2114 /*
2115 * set platform specific SMP operations
2116 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2117 index cddda1f..ff357f7 100644
2118 --- a/arch/arm/include/asm/thread_info.h
2119 +++ b/arch/arm/include/asm/thread_info.h
2120 @@ -77,9 +77,9 @@ struct thread_info {
2121 .flags = 0, \
2122 .preempt_count = INIT_PREEMPT_COUNT, \
2123 .addr_limit = KERNEL_DS, \
2124 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2125 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2126 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2127 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2128 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2129 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2130 .restart_block = { \
2131 .fn = do_no_restart_syscall, \
2132 }, \
2133 @@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2134 #define TIF_SYSCALL_AUDIT 9
2135 #define TIF_SYSCALL_TRACEPOINT 10
2136 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2137 +
2138 +/* within 8 bits of TIF_SYSCALL_TRACE
2139 + * to meet flexible second operand requirements
2140 + */
2141 +#define TIF_GRSEC_SETXID 12
2142 +
2143 #define TIF_USING_IWMMXT 17
2144 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2145 #define TIF_RESTORE_SIGMASK 20
2146 @@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2147 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2148 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2149 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2150 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2151
2152 /* Checks for any syscall work in entry-common.S */
2153 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2154 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2155 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2156
2157 /*
2158 * Change these and you break ASM code in entry-common.S
2159 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2160 index 7e1f760..752fcb7 100644
2161 --- a/arch/arm/include/asm/uaccess.h
2162 +++ b/arch/arm/include/asm/uaccess.h
2163 @@ -18,6 +18,7 @@
2164 #include <asm/domain.h>
2165 #include <asm/unified.h>
2166 #include <asm/compiler.h>
2167 +#include <asm/pgtable.h>
2168
2169 #define VERIFY_READ 0
2170 #define VERIFY_WRITE 1
2171 @@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2172 #define USER_DS TASK_SIZE
2173 #define get_fs() (current_thread_info()->addr_limit)
2174
2175 +static inline void pax_open_userland(void)
2176 +{
2177 +
2178 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2179 + if (get_fs() == USER_DS) {
2180 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2181 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2182 + }
2183 +#endif
2184 +
2185 +}
2186 +
2187 +static inline void pax_close_userland(void)
2188 +{
2189 +
2190 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2191 + if (get_fs() == USER_DS) {
2192 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2193 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2194 + }
2195 +#endif
2196 +
2197 +}
2198 +
2199 static inline void set_fs(mm_segment_t fs)
2200 {
2201 current_thread_info()->addr_limit = fs;
2202 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2203 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2204 }
2205
2206 #define segment_eq(a,b) ((a) == (b))
2207 @@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2208
2209 #define get_user(x,p) \
2210 ({ \
2211 + int __e; \
2212 might_fault(); \
2213 - __get_user_check(x,p); \
2214 + pax_open_userland(); \
2215 + __e = __get_user_check(x,p); \
2216 + pax_close_userland(); \
2217 + __e; \
2218 })
2219
2220 extern int __put_user_1(void *, unsigned int);
2221 @@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2222
2223 #define put_user(x,p) \
2224 ({ \
2225 + int __e; \
2226 might_fault(); \
2227 - __put_user_check(x,p); \
2228 + pax_open_userland(); \
2229 + __e = __put_user_check(x,p); \
2230 + pax_close_userland(); \
2231 + __e; \
2232 })
2233
2234 #else /* CONFIG_MMU */
2235 @@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2236 #define __get_user(x,ptr) \
2237 ({ \
2238 long __gu_err = 0; \
2239 + pax_open_userland(); \
2240 __get_user_err((x),(ptr),__gu_err); \
2241 + pax_close_userland(); \
2242 __gu_err; \
2243 })
2244
2245 #define __get_user_error(x,ptr,err) \
2246 ({ \
2247 + pax_open_userland(); \
2248 __get_user_err((x),(ptr),err); \
2249 + pax_close_userland(); \
2250 (void) 0; \
2251 })
2252
2253 @@ -312,13 +349,17 @@ do { \
2254 #define __put_user(x,ptr) \
2255 ({ \
2256 long __pu_err = 0; \
2257 + pax_open_userland(); \
2258 __put_user_err((x),(ptr),__pu_err); \
2259 + pax_close_userland(); \
2260 __pu_err; \
2261 })
2262
2263 #define __put_user_error(x,ptr,err) \
2264 ({ \
2265 + pax_open_userland(); \
2266 __put_user_err((x),(ptr),err); \
2267 + pax_close_userland(); \
2268 (void) 0; \
2269 })
2270
2271 @@ -418,11 +459,44 @@ do { \
2272
2273
2274 #ifdef CONFIG_MMU
2275 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2276 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2277 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2278 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2279 +
2280 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2281 +{
2282 + unsigned long ret;
2283 +
2284 + check_object_size(to, n, false);
2285 + pax_open_userland();
2286 + ret = ___copy_from_user(to, from, n);
2287 + pax_close_userland();
2288 + return ret;
2289 +}
2290 +
2291 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2292 +{
2293 + unsigned long ret;
2294 +
2295 + check_object_size(from, n, true);
2296 + pax_open_userland();
2297 + ret = ___copy_to_user(to, from, n);
2298 + pax_close_userland();
2299 + return ret;
2300 +}
2301 +
2302 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2303 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2304 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2305 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2306 +
2307 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2308 +{
2309 + unsigned long ret;
2310 + pax_open_userland();
2311 + ret = ___clear_user(addr, n);
2312 + pax_close_userland();
2313 + return ret;
2314 +}
2315 +
2316 #else
2317 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2318 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2319 @@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2320
2321 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2322 {
2323 + if ((long)n < 0)
2324 + return n;
2325 +
2326 if (access_ok(VERIFY_READ, from, n))
2327 n = __copy_from_user(to, from, n);
2328 else /* security hole - plug it */
2329 @@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2330
2331 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2332 {
2333 + if ((long)n < 0)
2334 + return n;
2335 +
2336 if (access_ok(VERIFY_WRITE, to, n))
2337 n = __copy_to_user(to, from, n);
2338 return n;
2339 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2340 index 96ee092..37f1844 100644
2341 --- a/arch/arm/include/uapi/asm/ptrace.h
2342 +++ b/arch/arm/include/uapi/asm/ptrace.h
2343 @@ -73,7 +73,7 @@
2344 * ARMv7 groups of PSR bits
2345 */
2346 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2347 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2348 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2349 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2350 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2351
2352 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2353 index 60d3b73..d27ee09 100644
2354 --- a/arch/arm/kernel/armksyms.c
2355 +++ b/arch/arm/kernel/armksyms.c
2356 @@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2357 #ifdef CONFIG_MMU
2358 EXPORT_SYMBOL(copy_page);
2359
2360 -EXPORT_SYMBOL(__copy_from_user);
2361 -EXPORT_SYMBOL(__copy_to_user);
2362 -EXPORT_SYMBOL(__clear_user);
2363 +EXPORT_SYMBOL(___copy_from_user);
2364 +EXPORT_SYMBOL(___copy_to_user);
2365 +EXPORT_SYMBOL(___clear_user);
2366
2367 EXPORT_SYMBOL(__get_user_1);
2368 EXPORT_SYMBOL(__get_user_2);
2369 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2370 index 0f82098..3dbd3ee 100644
2371 --- a/arch/arm/kernel/entry-armv.S
2372 +++ b/arch/arm/kernel/entry-armv.S
2373 @@ -47,6 +47,87 @@
2374 9997:
2375 .endm
2376
2377 + .macro pax_enter_kernel
2378 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2379 + @ make aligned space for saved DACR
2380 + sub sp, sp, #8
2381 + @ save regs
2382 + stmdb sp!, {r1, r2}
2383 + @ read DACR from cpu_domain into r1
2384 + mov r2, sp
2385 + @ assume 8K pages, since we have to split the immediate in two
2386 + bic r2, r2, #(0x1fc0)
2387 + bic r2, r2, #(0x3f)
2388 + ldr r1, [r2, #TI_CPU_DOMAIN]
2389 + @ store old DACR on stack
2390 + str r1, [sp, #8]
2391 +#ifdef CONFIG_PAX_KERNEXEC
2392 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2393 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2394 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2395 +#endif
2396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2397 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2398 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2399 +#endif
2400 + @ write r1 to current_thread_info()->cpu_domain
2401 + str r1, [r2, #TI_CPU_DOMAIN]
2402 + @ write r1 to DACR
2403 + mcr p15, 0, r1, c3, c0, 0
2404 + @ instruction sync
2405 + instr_sync
2406 + @ restore regs
2407 + ldmia sp!, {r1, r2}
2408 +#endif
2409 + .endm
2410 +
2411 + .macro pax_open_userland
2412 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2413 + @ save regs
2414 + stmdb sp!, {r0, r1}
2415 + @ read DACR from cpu_domain into r1
2416 + mov r0, sp
2417 + @ assume 8K pages, since we have to split the immediate in two
2418 + bic r0, r0, #(0x1fc0)
2419 + bic r0, r0, #(0x3f)
2420 + ldr r1, [r0, #TI_CPU_DOMAIN]
2421 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2422 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2423 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2424 + @ write r1 to current_thread_info()->cpu_domain
2425 + str r1, [r0, #TI_CPU_DOMAIN]
2426 + @ write r1 to DACR
2427 + mcr p15, 0, r1, c3, c0, 0
2428 + @ instruction sync
2429 + instr_sync
2430 + @ restore regs
2431 + ldmia sp!, {r0, r1}
2432 +#endif
2433 + .endm
2434 +
2435 + .macro pax_close_userland
2436 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2437 + @ save regs
2438 + stmdb sp!, {r0, r1}
2439 + @ read DACR from cpu_domain into r1
2440 + mov r0, sp
2441 + @ assume 8K pages, since we have to split the immediate in two
2442 + bic r0, r0, #(0x1fc0)
2443 + bic r0, r0, #(0x3f)
2444 + ldr r1, [r0, #TI_CPU_DOMAIN]
2445 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2446 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2447 + @ write r1 to current_thread_info()->cpu_domain
2448 + str r1, [r0, #TI_CPU_DOMAIN]
2449 + @ write r1 to DACR
2450 + mcr p15, 0, r1, c3, c0, 0
2451 + @ instruction sync
2452 + instr_sync
2453 + @ restore regs
2454 + ldmia sp!, {r0, r1}
2455 +#endif
2456 + .endm
2457 +
2458 .macro pabt_helper
2459 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2460 #ifdef MULTI_PABORT
2461 @@ -89,11 +170,15 @@
2462 * Invalid mode handlers
2463 */
2464 .macro inv_entry, reason
2465 +
2466 + pax_enter_kernel
2467 +
2468 sub sp, sp, #S_FRAME_SIZE
2469 ARM( stmib sp, {r1 - lr} )
2470 THUMB( stmia sp, {r0 - r12} )
2471 THUMB( str sp, [sp, #S_SP] )
2472 THUMB( str lr, [sp, #S_LR] )
2473 +
2474 mov r1, #\reason
2475 .endm
2476
2477 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2478 .macro svc_entry, stack_hole=0
2479 UNWIND(.fnstart )
2480 UNWIND(.save {r0 - pc} )
2481 +
2482 + pax_enter_kernel
2483 +
2484 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2485 +
2486 #ifdef CONFIG_THUMB2_KERNEL
2487 SPFIX( str r0, [sp] ) @ temporarily saved
2488 SPFIX( mov r0, sp )
2489 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2490 ldmia r0, {r3 - r5}
2491 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2492 mov r6, #-1 @ "" "" "" ""
2493 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2494 + @ offset sp by 8 as done in pax_enter_kernel
2495 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2496 +#else
2497 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2498 +#endif
2499 SPFIX( addeq r2, r2, #4 )
2500 str r3, [sp, #-4]! @ save the "real" r0 copied
2501 @ from the exception stack
2502 @@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2503 .macro usr_entry
2504 UNWIND(.fnstart )
2505 UNWIND(.cantunwind ) @ don't unwind the user space
2506 +
2507 + pax_enter_kernel_user
2508 +
2509 sub sp, sp, #S_FRAME_SIZE
2510 ARM( stmib sp, {r1 - r12} )
2511 THUMB( stmia sp, {r0 - r12} )
2512 @@ -456,7 +553,9 @@ __und_usr:
2513 tst r3, #PSR_T_BIT @ Thumb mode?
2514 bne __und_usr_thumb
2515 sub r4, r2, #4 @ ARM instr at LR - 4
2516 + pax_open_userland
2517 1: ldrt r0, [r4]
2518 + pax_close_userland
2519 #ifdef CONFIG_CPU_ENDIAN_BE8
2520 rev r0, r0 @ little endian instruction
2521 #endif
2522 @@ -491,10 +590,14 @@ __und_usr_thumb:
2523 */
2524 .arch armv6t2
2525 #endif
2526 + pax_open_userland
2527 2: ldrht r5, [r4]
2528 + pax_close_userland
2529 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2530 blo __und_usr_fault_16 @ 16bit undefined instruction
2531 + pax_open_userland
2532 3: ldrht r0, [r2]
2533 + pax_close_userland
2534 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2535 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2536 orr r0, r0, r5, lsl #16
2537 @@ -733,7 +836,7 @@ ENTRY(__switch_to)
2538 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2539 THUMB( str sp, [ip], #4 )
2540 THUMB( str lr, [ip], #4 )
2541 -#ifdef CONFIG_CPU_USE_DOMAINS
2542 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2543 ldr r6, [r2, #TI_CPU_DOMAIN]
2544 #endif
2545 set_tls r3, r4, r5
2546 @@ -742,7 +845,7 @@ ENTRY(__switch_to)
2547 ldr r8, =__stack_chk_guard
2548 ldr r7, [r7, #TSK_STACK_CANARY]
2549 #endif
2550 -#ifdef CONFIG_CPU_USE_DOMAINS
2551 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2552 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2553 #endif
2554 mov r5, r0
2555 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2556 index a6c301e..908821b 100644
2557 --- a/arch/arm/kernel/entry-common.S
2558 +++ b/arch/arm/kernel/entry-common.S
2559 @@ -10,18 +10,46 @@
2560
2561 #include <asm/unistd.h>
2562 #include <asm/ftrace.h>
2563 +#include <asm/domain.h>
2564 #include <asm/unwind.h>
2565
2566 +#include "entry-header.S"
2567 +
2568 #ifdef CONFIG_NEED_RET_TO_USER
2569 #include <mach/entry-macro.S>
2570 #else
2571 .macro arch_ret_to_user, tmp1, tmp2
2572 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2573 + @ save regs
2574 + stmdb sp!, {r1, r2}
2575 + @ read DACR from cpu_domain into r1
2576 + mov r2, sp
2577 + @ assume 8K pages, since we have to split the immediate in two
2578 + bic r2, r2, #(0x1fc0)
2579 + bic r2, r2, #(0x3f)
2580 + ldr r1, [r2, #TI_CPU_DOMAIN]
2581 +#ifdef CONFIG_PAX_KERNEXEC
2582 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2583 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2584 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2585 +#endif
2586 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2587 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2588 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2589 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2590 +#endif
2591 + @ write r1 to current_thread_info()->cpu_domain
2592 + str r1, [r2, #TI_CPU_DOMAIN]
2593 + @ write r1 to DACR
2594 + mcr p15, 0, r1, c3, c0, 0
2595 + @ instruction sync
2596 + instr_sync
2597 + @ restore regs
2598 + ldmia sp!, {r1, r2}
2599 +#endif
2600 .endm
2601 #endif
2602
2603 -#include "entry-header.S"
2604 -
2605 -
2606 .align 5
2607 /*
2608 * This is the fast syscall return path. We do as little as
2609 @@ -339,6 +367,7 @@ ENDPROC(ftrace_stub)
2610
2611 .align 5
2612 ENTRY(vector_swi)
2613 +
2614 sub sp, sp, #S_FRAME_SIZE
2615 stmia sp, {r0 - r12} @ Calling r0 - r12
2616 ARM( add r8, sp, #S_PC )
2617 @@ -388,6 +417,12 @@ ENTRY(vector_swi)
2618 ldr scno, [lr, #-4] @ get SWI instruction
2619 #endif
2620
2621 + /*
2622 + * do this here to avoid a performance hit of wrapping the code above
2623 + * that directly dereferences userland to parse the SWI instruction
2624 + */
2625 + pax_enter_kernel_user
2626 +
2627 #ifdef CONFIG_ALIGNMENT_TRAP
2628 ldr ip, __cr_alignment
2629 ldr ip, [ip]
2630 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2631 index 9a8531e..812e287 100644
2632 --- a/arch/arm/kernel/entry-header.S
2633 +++ b/arch/arm/kernel/entry-header.S
2634 @@ -73,9 +73,66 @@
2635 msr cpsr_c, \rtemp @ switch back to the SVC mode
2636 .endm
2637
2638 + .macro pax_enter_kernel_user
2639 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2640 + @ save regs
2641 + stmdb sp!, {r0, r1}
2642 + @ read DACR from cpu_domain into r1
2643 + mov r0, sp
2644 + @ assume 8K pages, since we have to split the immediate in two
2645 + bic r0, r0, #(0x1fc0)
2646 + bic r0, r0, #(0x3f)
2647 + ldr r1, [r0, #TI_CPU_DOMAIN]
2648 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2649 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2650 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2651 +#endif
2652 +#ifdef CONFIG_PAX_KERNEXEC
2653 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2654 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2655 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2656 +#endif
2657 + @ write r1 to current_thread_info()->cpu_domain
2658 + str r1, [r0, #TI_CPU_DOMAIN]
2659 + @ write r1 to DACR
2660 + mcr p15, 0, r1, c3, c0, 0
2661 + @ instruction sync
2662 + instr_sync
2663 + @ restore regs
2664 + ldmia sp!, {r0, r1}
2665 +#endif
2666 + .endm
2667 +
2668 + .macro pax_exit_kernel
2669 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2670 + @ save regs
2671 + stmdb sp!, {r0, r1}
2672 + @ read old DACR from stack into r1
2673 + ldr r1, [sp, #(8 + S_SP)]
2674 + sub r1, r1, #8
2675 + ldr r1, [r1]
2676 +
2677 + @ write r1 to current_thread_info()->cpu_domain
2678 + mov r0, sp
2679 + @ assume 8K pages, since we have to split the immediate in two
2680 + bic r0, r0, #(0x1fc0)
2681 + bic r0, r0, #(0x3f)
2682 + str r1, [r0, #TI_CPU_DOMAIN]
2683 + @ write r1 to DACR
2684 + mcr p15, 0, r1, c3, c0, 0
2685 + @ instruction sync
2686 + instr_sync
2687 + @ restore regs
2688 + ldmia sp!, {r0, r1}
2689 +#endif
2690 + .endm
2691 +
2692 #ifndef CONFIG_THUMB2_KERNEL
2693 .macro svc_exit, rpsr
2694 msr spsr_cxsf, \rpsr
2695 +
2696 + pax_exit_kernel
2697 +
2698 #if defined(CONFIG_CPU_V6)
2699 ldr r0, [sp]
2700 strex r1, r2, [sp] @ clear the exclusive monitor
2701 @@ -121,6 +178,9 @@
2702 .endm
2703 #else /* CONFIG_THUMB2_KERNEL */
2704 .macro svc_exit, rpsr
2705 +
2706 + pax_exit_kernel
2707 +
2708 ldr lr, [sp, #S_SP] @ top of the stack
2709 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2710 clrex @ clear the exclusive monitor
2711 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2712 index 2adda11..7fbe958 100644
2713 --- a/arch/arm/kernel/fiq.c
2714 +++ b/arch/arm/kernel/fiq.c
2715 @@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2716 #if defined(CONFIG_CPU_USE_DOMAINS)
2717 memcpy((void *)0xffff001c, start, length);
2718 #else
2719 + pax_open_kernel();
2720 memcpy(vectors_page + 0x1c, start, length);
2721 + pax_close_kernel();
2722 #endif
2723 flush_icache_range(0xffff001c, 0xffff001c + length);
2724 if (!vectors_high())
2725 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2726 index 486a15a..2d6880e 100644
2727 --- a/arch/arm/kernel/head.S
2728 +++ b/arch/arm/kernel/head.S
2729 @@ -52,7 +52,9 @@
2730 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2731
2732 .macro pgtbl, rd, phys
2733 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2734 + mov \rd, #TEXT_OFFSET
2735 + sub \rd, #PG_DIR_SIZE
2736 + add \rd, \rd, \phys
2737 .endm
2738
2739 /*
2740 @@ -416,7 +418,7 @@ __enable_mmu:
2741 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2742 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2743 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2744 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2745 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2746 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2747 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2748 #endif
2749 diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2750 index 5ff2e77..556d030 100644
2751 --- a/arch/arm/kernel/hw_breakpoint.c
2752 +++ b/arch/arm/kernel/hw_breakpoint.c
2753 @@ -1011,7 +1011,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2754 return NOTIFY_OK;
2755 }
2756
2757 -static struct notifier_block __cpuinitdata dbg_reset_nb = {
2758 +static struct notifier_block dbg_reset_nb = {
2759 .notifier_call = dbg_reset_notify,
2760 };
2761
2762 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2763 index 1e9be5d..03edbc2 100644
2764 --- a/arch/arm/kernel/module.c
2765 +++ b/arch/arm/kernel/module.c
2766 @@ -37,12 +37,37 @@
2767 #endif
2768
2769 #ifdef CONFIG_MMU
2770 -void *module_alloc(unsigned long size)
2771 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2772 {
2773 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2774 + return NULL;
2775 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2776 - GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2777 + GFP_KERNEL, prot, -1,
2778 __builtin_return_address(0));
2779 }
2780 +
2781 +void *module_alloc(unsigned long size)
2782 +{
2783 +
2784 +#ifdef CONFIG_PAX_KERNEXEC
2785 + return __module_alloc(size, PAGE_KERNEL);
2786 +#else
2787 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2788 +#endif
2789 +
2790 +}
2791 +
2792 +#ifdef CONFIG_PAX_KERNEXEC
2793 +void module_free_exec(struct module *mod, void *module_region)
2794 +{
2795 + module_free(mod, module_region);
2796 +}
2797 +
2798 +void *module_alloc_exec(unsigned long size)
2799 +{
2800 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2801 +}
2802 +#endif
2803 #endif
2804
2805 int
2806 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2807 index 07314af..c46655c 100644
2808 --- a/arch/arm/kernel/patch.c
2809 +++ b/arch/arm/kernel/patch.c
2810 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2811 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2812 int size;
2813
2814 + pax_open_kernel();
2815 if (thumb2 && __opcode_is_thumb16(insn)) {
2816 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2817 size = sizeof(u16);
2818 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2819 *(u32 *)addr = insn;
2820 size = sizeof(u32);
2821 }
2822 + pax_close_kernel();
2823
2824 flush_icache_range((uintptr_t)(addr),
2825 (uintptr_t)(addr) + size);
2826 diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2827 index 5f66206..dce492f 100644
2828 --- a/arch/arm/kernel/perf_event_cpu.c
2829 +++ b/arch/arm/kernel/perf_event_cpu.c
2830 @@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2831 return NOTIFY_OK;
2832 }
2833
2834 -static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2835 +static struct notifier_block cpu_pmu_hotplug_notifier = {
2836 .notifier_call = cpu_pmu_notify,
2837 };
2838
2839 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2840 index c6dec5f..f853532 100644
2841 --- a/arch/arm/kernel/process.c
2842 +++ b/arch/arm/kernel/process.c
2843 @@ -28,7 +28,6 @@
2844 #include <linux/tick.h>
2845 #include <linux/utsname.h>
2846 #include <linux/uaccess.h>
2847 -#include <linux/random.h>
2848 #include <linux/hw_breakpoint.h>
2849 #include <linux/cpuidle.h>
2850 #include <linux/leds.h>
2851 @@ -256,9 +255,10 @@ void machine_power_off(void)
2852 machine_shutdown();
2853 if (pm_power_off)
2854 pm_power_off();
2855 + BUG();
2856 }
2857
2858 -void machine_restart(char *cmd)
2859 +__noreturn void machine_restart(char *cmd)
2860 {
2861 machine_shutdown();
2862
2863 @@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2864 init_utsname()->release,
2865 (int)strcspn(init_utsname()->version, " "),
2866 init_utsname()->version);
2867 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2868 - print_symbol("LR is at %s\n", regs->ARM_lr);
2869 + printk("PC is at %pA\n", instruction_pointer(regs));
2870 + printk("LR is at %pA\n", regs->ARM_lr);
2871 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2872 "sp : %08lx ip : %08lx fp : %08lx\n",
2873 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2874 @@ -452,12 +452,6 @@ unsigned long get_wchan(struct task_struct *p)
2875 return 0;
2876 }
2877
2878 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2879 -{
2880 - unsigned long range_end = mm->brk + 0x02000000;
2881 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2882 -}
2883 -
2884 #ifdef CONFIG_MMU
2885 /*
2886 * The vectors page is always readable from user space for the
2887 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2888 index 03deeff..741ce88 100644
2889 --- a/arch/arm/kernel/ptrace.c
2890 +++ b/arch/arm/kernel/ptrace.c
2891 @@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2892 return current_thread_info()->syscall;
2893 }
2894
2895 +#ifdef CONFIG_GRKERNSEC_SETXID
2896 +extern void gr_delayed_cred_worker(void);
2897 +#endif
2898 +
2899 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2900 {
2901 current_thread_info()->syscall = scno;
2902
2903 +#ifdef CONFIG_GRKERNSEC_SETXID
2904 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2905 + gr_delayed_cred_worker();
2906 +#endif
2907 +
2908 /* Do the secure computing check first; failures should be fast. */
2909 if (secure_computing(scno) == -1)
2910 return -1;
2911 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2912 index 3f6cbb2..6d856f5 100644
2913 --- a/arch/arm/kernel/setup.c
2914 +++ b/arch/arm/kernel/setup.c
2915 @@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2916 unsigned int elf_hwcap __read_mostly;
2917 EXPORT_SYMBOL(elf_hwcap);
2918
2919 +pteval_t __supported_pte_mask __read_only;
2920 +pmdval_t __supported_pmd_mask __read_only;
2921
2922 #ifdef MULTI_CPU
2923 -struct processor processor __read_mostly;
2924 +struct processor processor;
2925 #endif
2926 #ifdef MULTI_TLB
2927 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2928 +struct cpu_tlb_fns cpu_tlb __read_only;
2929 #endif
2930 #ifdef MULTI_USER
2931 -struct cpu_user_fns cpu_user __read_mostly;
2932 +struct cpu_user_fns cpu_user __read_only;
2933 #endif
2934 #ifdef MULTI_CACHE
2935 -struct cpu_cache_fns cpu_cache __read_mostly;
2936 +struct cpu_cache_fns cpu_cache __read_only;
2937 #endif
2938 #ifdef CONFIG_OUTER_CACHE
2939 -struct outer_cache_fns outer_cache __read_mostly;
2940 +struct outer_cache_fns outer_cache __read_only;
2941 EXPORT_SYMBOL(outer_cache);
2942 #endif
2943
2944 @@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2945 asm("mrc p15, 0, %0, c0, c1, 4"
2946 : "=r" (mmfr0));
2947 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2948 - (mmfr0 & 0x000000f0) >= 0x00000030)
2949 + (mmfr0 & 0x000000f0) >= 0x00000030) {
2950 cpu_arch = CPU_ARCH_ARMv7;
2951 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2952 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2953 + __supported_pte_mask |= L_PTE_PXN;
2954 + __supported_pmd_mask |= PMD_PXNTABLE;
2955 + }
2956 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2957 (mmfr0 & 0x000000f0) == 0x00000020)
2958 cpu_arch = CPU_ARCH_ARMv6;
2959 else
2960 @@ -462,7 +468,7 @@ static void __init setup_processor(void)
2961 __cpu_architecture = __get_cpu_architecture();
2962
2963 #ifdef MULTI_CPU
2964 - processor = *list->proc;
2965 + memcpy((void *)&processor, list->proc, sizeof processor);
2966 #endif
2967 #ifdef MULTI_TLB
2968 cpu_tlb = *list->tlb;
2969 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2970 index 84f4cbf..672f5b8 100644
2971 --- a/arch/arm/kernel/smp.c
2972 +++ b/arch/arm/kernel/smp.c
2973 @@ -70,7 +70,7 @@ enum ipi_msg_type {
2974
2975 static DECLARE_COMPLETION(cpu_running);
2976
2977 -static struct smp_operations smp_ops;
2978 +static struct smp_operations smp_ops __read_only;
2979
2980 void __init smp_set_ops(struct smp_operations *ops)
2981 {
2982 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2983 index b0179b8..b7b16c7 100644
2984 --- a/arch/arm/kernel/traps.c
2985 +++ b/arch/arm/kernel/traps.c
2986 @@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2987 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2988 {
2989 #ifdef CONFIG_KALLSYMS
2990 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2991 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2992 #else
2993 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2994 #endif
2995 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2996 static int die_owner = -1;
2997 static unsigned int die_nest_count;
2998
2999 +extern void gr_handle_kernel_exploit(void);
3000 +
3001 static unsigned long oops_begin(void)
3002 {
3003 int cpu;
3004 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3005 panic("Fatal exception in interrupt");
3006 if (panic_on_oops)
3007 panic("Fatal exception");
3008 +
3009 + gr_handle_kernel_exploit();
3010 +
3011 if (signr)
3012 do_exit(signr);
3013 }
3014 @@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3015 * The user helper at 0xffff0fe0 must be used instead.
3016 * (see entry-armv.S for details)
3017 */
3018 + pax_open_kernel();
3019 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3020 + pax_close_kernel();
3021 }
3022 return 0;
3023
3024 @@ -849,5 +856,9 @@ void __init early_trap_init(void *vectors_base)
3025 sigreturn_codes, sizeof(sigreturn_codes));
3026
3027 flush_icache_range(vectors, vectors + PAGE_SIZE);
3028 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3029 +
3030 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3031 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3032 +#endif
3033 +
3034 }
3035 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3036 index 11c1785..c67d54c 100644
3037 --- a/arch/arm/kernel/vmlinux.lds.S
3038 +++ b/arch/arm/kernel/vmlinux.lds.S
3039 @@ -8,7 +8,11 @@
3040 #include <asm/thread_info.h>
3041 #include <asm/memory.h>
3042 #include <asm/page.h>
3043 -
3044 +
3045 +#ifdef CONFIG_PAX_KERNEXEC
3046 +#include <asm/pgtable.h>
3047 +#endif
3048 +
3049 #define PROC_INFO \
3050 . = ALIGN(4); \
3051 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3052 @@ -90,6 +94,11 @@ SECTIONS
3053 _text = .;
3054 HEAD_TEXT
3055 }
3056 +
3057 +#ifdef CONFIG_PAX_KERNEXEC
3058 + . = ALIGN(1<<SECTION_SHIFT);
3059 +#endif
3060 +
3061 .text : { /* Real text segment */
3062 _stext = .; /* Text and read-only data */
3063 __exception_text_start = .;
3064 @@ -144,6 +153,10 @@ SECTIONS
3065
3066 _etext = .; /* End of text and rodata section */
3067
3068 +#ifdef CONFIG_PAX_KERNEXEC
3069 + . = ALIGN(1<<SECTION_SHIFT);
3070 +#endif
3071 +
3072 #ifndef CONFIG_XIP_KERNEL
3073 . = ALIGN(PAGE_SIZE);
3074 __init_begin = .;
3075 @@ -203,6 +216,11 @@ SECTIONS
3076 . = PAGE_OFFSET + TEXT_OFFSET;
3077 #else
3078 __init_end = .;
3079 +
3080 +#ifdef CONFIG_PAX_KERNEXEC
3081 + . = ALIGN(1<<SECTION_SHIFT);
3082 +#endif
3083 +
3084 . = ALIGN(THREAD_SIZE);
3085 __data_loc = .;
3086 #endif
3087 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3088 index 14a0d98..7771a7d 100644
3089 --- a/arch/arm/lib/clear_user.S
3090 +++ b/arch/arm/lib/clear_user.S
3091 @@ -12,14 +12,14 @@
3092
3093 .text
3094
3095 -/* Prototype: int __clear_user(void *addr, size_t sz)
3096 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3097 * Purpose : clear some user memory
3098 * Params : addr - user memory address to clear
3099 * : sz - number of bytes to clear
3100 * Returns : number of bytes NOT cleared
3101 */
3102 ENTRY(__clear_user_std)
3103 -WEAK(__clear_user)
3104 +WEAK(___clear_user)
3105 stmfd sp!, {r1, lr}
3106 mov r2, #0
3107 cmp r1, #4
3108 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3109 USER( strnebt r2, [r0])
3110 mov r0, #0
3111 ldmfd sp!, {r1, pc}
3112 -ENDPROC(__clear_user)
3113 +ENDPROC(___clear_user)
3114 ENDPROC(__clear_user_std)
3115
3116 .pushsection .fixup,"ax"
3117 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3118 index 66a477a..bee61d3 100644
3119 --- a/arch/arm/lib/copy_from_user.S
3120 +++ b/arch/arm/lib/copy_from_user.S
3121 @@ -16,7 +16,7 @@
3122 /*
3123 * Prototype:
3124 *
3125 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3126 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3127 *
3128 * Purpose:
3129 *
3130 @@ -84,11 +84,11 @@
3131
3132 .text
3133
3134 -ENTRY(__copy_from_user)
3135 +ENTRY(___copy_from_user)
3136
3137 #include "copy_template.S"
3138
3139 -ENDPROC(__copy_from_user)
3140 +ENDPROC(___copy_from_user)
3141
3142 .pushsection .fixup,"ax"
3143 .align 0
3144 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3145 index 6ee2f67..d1cce76 100644
3146 --- a/arch/arm/lib/copy_page.S
3147 +++ b/arch/arm/lib/copy_page.S
3148 @@ -10,6 +10,7 @@
3149 * ASM optimised string functions
3150 */
3151 #include <linux/linkage.h>
3152 +#include <linux/const.h>
3153 #include <asm/assembler.h>
3154 #include <asm/asm-offsets.h>
3155 #include <asm/cache.h>
3156 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3157 index d066df6..df28194 100644
3158 --- a/arch/arm/lib/copy_to_user.S
3159 +++ b/arch/arm/lib/copy_to_user.S
3160 @@ -16,7 +16,7 @@
3161 /*
3162 * Prototype:
3163 *
3164 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3165 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3166 *
3167 * Purpose:
3168 *
3169 @@ -88,11 +88,11 @@
3170 .text
3171
3172 ENTRY(__copy_to_user_std)
3173 -WEAK(__copy_to_user)
3174 +WEAK(___copy_to_user)
3175
3176 #include "copy_template.S"
3177
3178 -ENDPROC(__copy_to_user)
3179 +ENDPROC(___copy_to_user)
3180 ENDPROC(__copy_to_user_std)
3181
3182 .pushsection .fixup,"ax"
3183 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3184 index 7d08b43..f7ca7ea 100644
3185 --- a/arch/arm/lib/csumpartialcopyuser.S
3186 +++ b/arch/arm/lib/csumpartialcopyuser.S
3187 @@ -57,8 +57,8 @@
3188 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3189 */
3190
3191 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3192 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3193 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3194 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3195
3196 #include "csumpartialcopygeneric.S"
3197
3198 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3199 index 0dc5385..45833ef 100644
3200 --- a/arch/arm/lib/delay.c
3201 +++ b/arch/arm/lib/delay.c
3202 @@ -28,12 +28,14 @@
3203 /*
3204 * Default to the loop-based delay implementation.
3205 */
3206 -struct arm_delay_ops arm_delay_ops = {
3207 +static struct arm_delay_ops arm_loop_delay_ops = {
3208 .delay = __loop_delay,
3209 .const_udelay = __loop_const_udelay,
3210 .udelay = __loop_udelay,
3211 };
3212
3213 +struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
3214 +
3215 static const struct delay_timer *delay_timer;
3216 static bool delay_calibrated;
3217
3218 @@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
3219 __timer_const_udelay(usecs * UDELAY_MULT);
3220 }
3221
3222 +static struct arm_delay_ops arm_timer_delay_ops = {
3223 + .delay = __timer_delay,
3224 + .const_udelay = __timer_const_udelay,
3225 + .udelay = __timer_udelay,
3226 +};
3227 +
3228 void __init register_current_timer_delay(const struct delay_timer *timer)
3229 {
3230 if (!delay_calibrated) {
3231 @@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
3232 delay_timer = timer;
3233 lpj_fine = timer->freq / HZ;
3234 loops_per_jiffy = lpj_fine;
3235 - arm_delay_ops.delay = __timer_delay;
3236 - arm_delay_ops.const_udelay = __timer_const_udelay;
3237 - arm_delay_ops.udelay = __timer_udelay;
3238 + arm_delay_ops = &arm_timer_delay_ops;
3239 delay_calibrated = true;
3240 } else {
3241 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
3242 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3243 index 025f742..8432b08 100644
3244 --- a/arch/arm/lib/uaccess_with_memcpy.c
3245 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3246 @@ -104,7 +104,7 @@ out:
3247 }
3248
3249 unsigned long
3250 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3251 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3252 {
3253 /*
3254 * This test is stubbed out of the main function above to keep
3255 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3256 index bac21a5..b67ef8e 100644
3257 --- a/arch/arm/mach-kirkwood/common.c
3258 +++ b/arch/arm/mach-kirkwood/common.c
3259 @@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3260 clk_gate_ops.disable(hw);
3261 }
3262
3263 -static struct clk_ops clk_gate_fn_ops;
3264 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3265 +{
3266 + return clk_gate_ops.is_enabled(hw);
3267 +}
3268 +
3269 +static struct clk_ops clk_gate_fn_ops = {
3270 + .enable = clk_gate_fn_enable,
3271 + .disable = clk_gate_fn_disable,
3272 + .is_enabled = clk_gate_fn_is_enabled,
3273 +};
3274
3275 static struct clk __init *clk_register_gate_fn(struct device *dev,
3276 const char *name,
3277 @@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3278 gate_fn->fn_en = fn_en;
3279 gate_fn->fn_dis = fn_dis;
3280
3281 - /* ops is the gate ops, but with our enable/disable functions */
3282 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3283 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3284 - clk_gate_fn_ops = clk_gate_ops;
3285 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3286 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3287 - }
3288 -
3289 clk = clk_register(dev, &gate_fn->gate.hw);
3290
3291 if (IS_ERR(clk))
3292 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3293 index 0abb30f..54064da 100644
3294 --- a/arch/arm/mach-omap2/board-n8x0.c
3295 +++ b/arch/arm/mach-omap2/board-n8x0.c
3296 @@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3297 }
3298 #endif
3299
3300 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3301 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3302 .late_init = n8x0_menelaus_late_init,
3303 };
3304
3305 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3306 index 5d3b4f4..ddba3c0 100644
3307 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3308 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3309 @@ -340,7 +340,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3310 return NOTIFY_OK;
3311 }
3312
3313 -static struct notifier_block __refdata irq_hotplug_notifier = {
3314 +static struct notifier_block irq_hotplug_notifier = {
3315 .notifier_call = irq_cpu_hotplug_notify,
3316 };
3317
3318 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3319 index 4653efb..8c60bf7 100644
3320 --- a/arch/arm/mach-omap2/omap_hwmod.c
3321 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3322 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
3323 int (*init_clkdm)(struct omap_hwmod *oh);
3324 void (*update_context_lost)(struct omap_hwmod *oh);
3325 int (*get_context_lost)(struct omap_hwmod *oh);
3326 -};
3327 +} __no_const;
3328
3329 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3330 -static struct omap_hwmod_soc_ops soc_ops;
3331 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3332
3333 /* omap_hwmod_list contains all registered struct omap_hwmods */
3334 static LIST_HEAD(omap_hwmod_list);
3335 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3336 index 7c2b4ed..b2ea51f 100644
3337 --- a/arch/arm/mach-omap2/wd_timer.c
3338 +++ b/arch/arm/mach-omap2/wd_timer.c
3339 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3340 struct omap_hwmod *oh;
3341 char *oh_name = "wd_timer2";
3342 char *dev_name = "omap_wdt";
3343 - struct omap_wd_timer_platform_data pdata;
3344 + static struct omap_wd_timer_platform_data pdata = {
3345 + .read_reset_sources = prm_read_reset_sources
3346 + };
3347
3348 if (!cpu_class_is_omap2() || of_have_populated_dt())
3349 return 0;
3350 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3351 return -EINVAL;
3352 }
3353
3354 - pdata.read_reset_sources = prm_read_reset_sources;
3355 -
3356 pdev = omap_device_build(dev_name, id, oh, &pdata,
3357 sizeof(struct omap_wd_timer_platform_data),
3358 NULL, 0, 0);
3359 diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3360 index 6be4c4d..32ac32a 100644
3361 --- a/arch/arm/mach-ux500/include/mach/setup.h
3362 +++ b/arch/arm/mach-ux500/include/mach/setup.h
3363 @@ -38,13 +38,6 @@ extern struct sys_timer ux500_timer;
3364 .type = MT_DEVICE, \
3365 }
3366
3367 -#define __MEM_DEV_DESC(x, sz) { \
3368 - .virtual = IO_ADDRESS(x), \
3369 - .pfn = __phys_to_pfn(x), \
3370 - .length = sz, \
3371 - .type = MT_MEMORY, \
3372 -}
3373 -
3374 extern struct smp_operations ux500_smp_ops;
3375 extern void ux500_cpu_die(unsigned int cpu);
3376
3377 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3378 index 3fd629d..8b1aca9 100644
3379 --- a/arch/arm/mm/Kconfig
3380 +++ b/arch/arm/mm/Kconfig
3381 @@ -425,7 +425,7 @@ config CPU_32v5
3382
3383 config CPU_32v6
3384 bool
3385 - select CPU_USE_DOMAINS if CPU_V6 && MMU
3386 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3387 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3388
3389 config CPU_32v6K
3390 @@ -577,6 +577,7 @@ config CPU_CP15_MPU
3391
3392 config CPU_USE_DOMAINS
3393 bool
3394 + depends on !ARM_LPAE && !PAX_KERNEXEC
3395 help
3396 This option enables or disables the use of domain switching
3397 via the set_fs() function.
3398 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3399 index 5dbf13f..6393f55 100644
3400 --- a/arch/arm/mm/fault.c
3401 +++ b/arch/arm/mm/fault.c
3402 @@ -25,6 +25,7 @@
3403 #include <asm/system_misc.h>
3404 #include <asm/system_info.h>
3405 #include <asm/tlbflush.h>
3406 +#include <asm/sections.h>
3407
3408 #include "fault.h"
3409
3410 @@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3411 if (fixup_exception(regs))
3412 return;
3413
3414 +#ifdef CONFIG_PAX_KERNEXEC
3415 + if ((fsr & FSR_WRITE) &&
3416 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3417 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3418 + {
3419 + if (current->signal->curr_ip)
3420 + 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),
3421 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3422 + else
3423 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3424 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3425 + }
3426 +#endif
3427 +
3428 /*
3429 * No handler, we'll have to terminate things with extreme prejudice.
3430 */
3431 @@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3432 }
3433 #endif
3434
3435 +#ifdef CONFIG_PAX_PAGEEXEC
3436 + if (fsr & FSR_LNX_PF) {
3437 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3438 + do_group_exit(SIGKILL);
3439 + }
3440 +#endif
3441 +
3442 tsk->thread.address = addr;
3443 tsk->thread.error_code = fsr;
3444 tsk->thread.trap_no = 14;
3445 @@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3446 }
3447 #endif /* CONFIG_MMU */
3448
3449 +#ifdef CONFIG_PAX_PAGEEXEC
3450 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3451 +{
3452 + long i;
3453 +
3454 + printk(KERN_ERR "PAX: bytes at PC: ");
3455 + for (i = 0; i < 20; i++) {
3456 + unsigned char c;
3457 + if (get_user(c, (__force unsigned char __user *)pc+i))
3458 + printk(KERN_CONT "?? ");
3459 + else
3460 + printk(KERN_CONT "%02x ", c);
3461 + }
3462 + printk("\n");
3463 +
3464 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3465 + for (i = -1; i < 20; i++) {
3466 + unsigned long c;
3467 + if (get_user(c, (__force unsigned long __user *)sp+i))
3468 + printk(KERN_CONT "???????? ");
3469 + else
3470 + printk(KERN_CONT "%08lx ", c);
3471 + }
3472 + printk("\n");
3473 +}
3474 +#endif
3475 +
3476 /*
3477 * First Level Translation Fault Handler
3478 *
3479 @@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3480 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3481 struct siginfo info;
3482
3483 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3484 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3485 + if (current->signal->curr_ip)
3486 + 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),
3487 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3488 + else
3489 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3490 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3491 + goto die;
3492 + }
3493 +#endif
3494 +
3495 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3496 return;
3497
3498 +die:
3499 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3500 inf->name, fsr, addr);
3501
3502 @@ -575,9 +637,38 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3503 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3504 struct siginfo info;
3505
3506 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3507 + if (!user_mode(regs) && (is_domain_fault(ifsr) || is_xn_fault(ifsr))) {
3508 + if (current->signal->curr_ip)
3509 + 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),
3510 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3511 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3512 + else
3513 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3514 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3515 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3516 + goto die;
3517 + }
3518 +#endif
3519 +
3520 +#ifdef CONFIG_PAX_REFCOUNT
3521 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3522 + unsigned int bkpt;
3523 +
3524 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3525 + current->thread.error_code = ifsr;
3526 + current->thread.trap_no = 0;
3527 + pax_report_refcount_overflow(regs);
3528 + fixup_exception(regs);
3529 + return;
3530 + }
3531 + }
3532 +#endif
3533 +
3534 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3535 return;
3536
3537 +die:
3538 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3539 inf->name, ifsr, addr);
3540
3541 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3542 index cf08bdf..772656c 100644
3543 --- a/arch/arm/mm/fault.h
3544 +++ b/arch/arm/mm/fault.h
3545 @@ -3,6 +3,7 @@
3546
3547 /*
3548 * Fault status register encodings. We steal bit 31 for our own purposes.
3549 + * Set when the FSR value is from an instruction fault.
3550 */
3551 #define FSR_LNX_PF (1 << 31)
3552 #define FSR_WRITE (1 << 11)
3553 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3554 }
3555 #endif
3556
3557 +/* valid for LPAE and !LPAE */
3558 +static inline int is_xn_fault(unsigned int fsr)
3559 +{
3560 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
3561 +}
3562 +
3563 +static inline int is_domain_fault(unsigned int fsr)
3564 +{
3565 + return ((fsr_fs(fsr) & 0xD) == 0x9);
3566 +}
3567 +
3568 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3569 unsigned long search_exception_table(unsigned long addr);
3570
3571 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3572 index ad722f1..763fdd3 100644
3573 --- a/arch/arm/mm/init.c
3574 +++ b/arch/arm/mm/init.c
3575 @@ -30,6 +30,8 @@
3576 #include <asm/setup.h>
3577 #include <asm/tlb.h>
3578 #include <asm/fixmap.h>
3579 +#include <asm/system_info.h>
3580 +#include <asm/cp15.h>
3581
3582 #include <asm/mach/arch.h>
3583 #include <asm/mach/map.h>
3584 @@ -736,7 +738,46 @@ void free_initmem(void)
3585 {
3586 #ifdef CONFIG_HAVE_TCM
3587 extern char __tcm_start, __tcm_end;
3588 +#endif
3589
3590 +#ifdef CONFIG_PAX_KERNEXEC
3591 + unsigned long addr;
3592 + pgd_t *pgd;
3593 + pud_t *pud;
3594 + pmd_t *pmd;
3595 + int cpu_arch = cpu_architecture();
3596 + unsigned int cr = get_cr();
3597 +
3598 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3599 + /* make pages tables, etc before .text NX */
3600 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3601 + pgd = pgd_offset_k(addr);
3602 + pud = pud_offset(pgd, addr);
3603 + pmd = pmd_offset(pud, addr);
3604 + __section_update(pmd, addr, PMD_SECT_XN);
3605 + }
3606 + /* make init NX */
3607 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3608 + pgd = pgd_offset_k(addr);
3609 + pud = pud_offset(pgd, addr);
3610 + pmd = pmd_offset(pud, addr);
3611 + __section_update(pmd, addr, PMD_SECT_XN);
3612 + }
3613 + /* make kernel code/rodata RX */
3614 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3615 + pgd = pgd_offset_k(addr);
3616 + pud = pud_offset(pgd, addr);
3617 + pmd = pmd_offset(pud, addr);
3618 +#ifdef CONFIG_ARM_LPAE
3619 + __section_update(pmd, addr, PMD_SECT_RDONLY);
3620 +#else
3621 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3622 +#endif
3623 + }
3624 + }
3625 +#endif
3626 +
3627 +#ifdef CONFIG_HAVE_TCM
3628 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3629 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3630 __phys_to_pfn(__pa(&__tcm_end)),
3631 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3632 index 88fd86c..7a224ce 100644
3633 --- a/arch/arm/mm/ioremap.c
3634 +++ b/arch/arm/mm/ioremap.c
3635 @@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3636 unsigned int mtype;
3637
3638 if (cached)
3639 - mtype = MT_MEMORY;
3640 + mtype = MT_MEMORY_RX;
3641 else
3642 - mtype = MT_MEMORY_NONCACHED;
3643 + mtype = MT_MEMORY_NONCACHED_RX;
3644
3645 return __arm_ioremap_caller(phys_addr, size, mtype,
3646 __builtin_return_address(0));
3647 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3648 index 10062ce..aa96dd7 100644
3649 --- a/arch/arm/mm/mmap.c
3650 +++ b/arch/arm/mm/mmap.c
3651 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3652 struct vm_area_struct *vma;
3653 int do_align = 0;
3654 int aliasing = cache_is_vipt_aliasing();
3655 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3656 struct vm_unmapped_area_info info;
3657
3658 /*
3659 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3660 if (len > TASK_SIZE)
3661 return -ENOMEM;
3662
3663 +#ifdef CONFIG_PAX_RANDMMAP
3664 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3665 +#endif
3666 +
3667 if (addr) {
3668 if (do_align)
3669 addr = COLOUR_ALIGN(addr, pgoff);
3670 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3671 addr = PAGE_ALIGN(addr);
3672
3673 vma = find_vma(mm, addr);
3674 - if (TASK_SIZE - len >= addr &&
3675 - (!vma || addr + len <= vma->vm_start))
3676 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3677 return addr;
3678 }
3679
3680 @@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3681 unsigned long addr = addr0;
3682 int do_align = 0;
3683 int aliasing = cache_is_vipt_aliasing();
3684 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3685 struct vm_unmapped_area_info info;
3686
3687 /*
3688 @@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3689 return addr;
3690 }
3691
3692 +#ifdef CONFIG_PAX_RANDMMAP
3693 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3694 +#endif
3695 +
3696 /* requesting a specific address */
3697 if (addr) {
3698 if (do_align)
3699 @@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3700 else
3701 addr = PAGE_ALIGN(addr);
3702 vma = find_vma(mm, addr);
3703 - if (TASK_SIZE - len >= addr &&
3704 - (!vma || addr + len <= vma->vm_start))
3705 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3706 return addr;
3707 }
3708
3709 @@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3710 VM_BUG_ON(addr != -ENOMEM);
3711 info.flags = 0;
3712 info.low_limit = mm->mmap_base;
3713 +
3714 +#ifdef CONFIG_PAX_RANDMMAP
3715 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3716 + info.low_limit += mm->delta_mmap;
3717 +#endif
3718 +
3719 info.high_limit = TASK_SIZE;
3720 addr = vm_unmapped_area(&info);
3721 }
3722 @@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3723 {
3724 unsigned long random_factor = 0UL;
3725
3726 +#ifdef CONFIG_PAX_RANDMMAP
3727 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3728 +#endif
3729 +
3730 /* 8 bits of randomness in 20 address space bits */
3731 if ((current->flags & PF_RANDOMIZE) &&
3732 !(current->personality & ADDR_NO_RANDOMIZE))
3733 @@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3734
3735 if (mmap_is_legacy()) {
3736 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3737 +
3738 +#ifdef CONFIG_PAX_RANDMMAP
3739 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3740 + mm->mmap_base += mm->delta_mmap;
3741 +#endif
3742 +
3743 mm->get_unmapped_area = arch_get_unmapped_area;
3744 mm->unmap_area = arch_unmap_area;
3745 } else {
3746 mm->mmap_base = mmap_base(random_factor);
3747 +
3748 +#ifdef CONFIG_PAX_RANDMMAP
3749 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3750 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3751 +#endif
3752 +
3753 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3754 mm->unmap_area = arch_unmap_area_topdown;
3755 }
3756 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3757 index ce328c7..f82bebb 100644
3758 --- a/arch/arm/mm/mmu.c
3759 +++ b/arch/arm/mm/mmu.c
3760 @@ -35,6 +35,23 @@
3761
3762 #include "mm.h"
3763
3764 +
3765 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3766 +void modify_domain(unsigned int dom, unsigned int type)
3767 +{
3768 + struct thread_info *thread = current_thread_info();
3769 + unsigned int domain = thread->cpu_domain;
3770 + /*
3771 + * DOMAIN_MANAGER might be defined to some other value,
3772 + * use the arch-defined constant
3773 + */
3774 + domain &= ~domain_val(dom, 3);
3775 + thread->cpu_domain = domain | domain_val(dom, type);
3776 + set_domain(thread->cpu_domain);
3777 +}
3778 +EXPORT_SYMBOL(modify_domain);
3779 +#endif
3780 +
3781 /*
3782 * empty_zero_page is a special page that is used for
3783 * zero-initialized data and COW.
3784 @@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
3785 }
3786 #endif
3787
3788 -#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
3789 +#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
3790 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
3791
3792 -static struct mem_type mem_types[] = {
3793 +#ifdef CONFIG_PAX_KERNEXEC
3794 +#define L_PTE_KERNEXEC L_PTE_RDONLY
3795 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
3796 +#else
3797 +#define L_PTE_KERNEXEC L_PTE_DIRTY
3798 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
3799 +#endif
3800 +
3801 +static struct mem_type mem_types[] __read_only = {
3802 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
3803 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
3804 L_PTE_SHARED,
3805 @@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
3806 [MT_UNCACHED] = {
3807 .prot_pte = PROT_PTE_DEVICE,
3808 .prot_l1 = PMD_TYPE_TABLE,
3809 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3810 + .prot_sect = PROT_SECT_DEVICE,
3811 .domain = DOMAIN_IO,
3812 },
3813 [MT_CACHECLEAN] = {
3814 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3815 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3816 .domain = DOMAIN_KERNEL,
3817 },
3818 #ifndef CONFIG_ARM_LPAE
3819 [MT_MINICLEAN] = {
3820 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
3821 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
3822 .domain = DOMAIN_KERNEL,
3823 },
3824 #endif
3825 @@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
3826 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3827 L_PTE_RDONLY,
3828 .prot_l1 = PMD_TYPE_TABLE,
3829 - .domain = DOMAIN_USER,
3830 + .domain = DOMAIN_VECTORS,
3831 },
3832 [MT_HIGH_VECTORS] = {
3833 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3834 L_PTE_USER | L_PTE_RDONLY,
3835 .prot_l1 = PMD_TYPE_TABLE,
3836 - .domain = DOMAIN_USER,
3837 + .domain = DOMAIN_VECTORS,
3838 },
3839 - [MT_MEMORY] = {
3840 + [MT_MEMORY_RWX] = {
3841 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3842 .prot_l1 = PMD_TYPE_TABLE,
3843 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3844 .domain = DOMAIN_KERNEL,
3845 },
3846 + [MT_MEMORY_RW] = {
3847 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3848 + .prot_l1 = PMD_TYPE_TABLE,
3849 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3850 + .domain = DOMAIN_KERNEL,
3851 + },
3852 + [MT_MEMORY_RX] = {
3853 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
3854 + .prot_l1 = PMD_TYPE_TABLE,
3855 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3856 + .domain = DOMAIN_KERNEL,
3857 + },
3858 [MT_ROM] = {
3859 - .prot_sect = PMD_TYPE_SECT,
3860 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3861 .domain = DOMAIN_KERNEL,
3862 },
3863 - [MT_MEMORY_NONCACHED] = {
3864 + [MT_MEMORY_NONCACHED_RW] = {
3865 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3866 L_PTE_MT_BUFFERABLE,
3867 .prot_l1 = PMD_TYPE_TABLE,
3868 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3869 .domain = DOMAIN_KERNEL,
3870 },
3871 + [MT_MEMORY_NONCACHED_RX] = {
3872 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
3873 + L_PTE_MT_BUFFERABLE,
3874 + .prot_l1 = PMD_TYPE_TABLE,
3875 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3876 + .domain = DOMAIN_KERNEL,
3877 + },
3878 [MT_MEMORY_DTCM] = {
3879 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3880 - L_PTE_XN,
3881 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3882 .prot_l1 = PMD_TYPE_TABLE,
3883 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3884 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3885 .domain = DOMAIN_KERNEL,
3886 },
3887 [MT_MEMORY_ITCM] = {
3888 @@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
3889 },
3890 [MT_MEMORY_SO] = {
3891 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3892 - L_PTE_MT_UNCACHED | L_PTE_XN,
3893 + L_PTE_MT_UNCACHED,
3894 .prot_l1 = PMD_TYPE_TABLE,
3895 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
3896 - PMD_SECT_UNCACHED | PMD_SECT_XN,
3897 + PMD_SECT_UNCACHED,
3898 .domain = DOMAIN_KERNEL,
3899 },
3900 [MT_MEMORY_DMA_READY] = {
3901 @@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
3902 * to prevent speculative instruction fetches.
3903 */
3904 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
3905 + mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
3906 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
3907 + mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
3908 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
3909 + mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
3910 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
3911 + mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
3912 +
3913 + /* Mark other regions on ARMv6+ as execute-never */
3914 +
3915 +#ifdef CONFIG_PAX_KERNEXEC
3916 + mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
3917 + mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
3918 + mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
3919 + mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
3920 +#ifndef CONFIG_ARM_LPAE
3921 + mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
3922 + mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
3923 +#endif
3924 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
3925 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
3926 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
3927 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
3928 + mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
3929 + mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
3930 +#endif
3931 +
3932 + mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
3933 + mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
3934 }
3935 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3936 /*
3937 @@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
3938 * from SVC mode and no access from userspace.
3939 */
3940 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3941 +#ifdef CONFIG_PAX_KERNEXEC
3942 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3943 +#endif
3944 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3945 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3946 #endif
3947 @@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
3948 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
3949 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
3950 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
3951 - mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
3952 - mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
3953 + mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
3954 + mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
3955 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
3956 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
3957 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
3958 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
3959 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
3960 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
3961 - mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
3962 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
3963 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
3964 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
3965 + mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
3966 }
3967 }
3968
3969 @@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
3970 if (cpu_arch >= CPU_ARCH_ARMv6) {
3971 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3972 /* Non-cacheable Normal is XCB = 001 */
3973 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3974 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3975 + PMD_SECT_BUFFERED;
3976 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3977 PMD_SECT_BUFFERED;
3978 } else {
3979 /* For both ARMv6 and non-TEX-remapping ARMv7 */
3980 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3981 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3982 + PMD_SECT_TEX(1);
3983 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3984 PMD_SECT_TEX(1);
3985 }
3986 } else {
3987 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
3988 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
3989 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
3990 }
3991
3992 #ifdef CONFIG_ARM_LPAE
3993 @@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
3994 vecs_pgprot |= PTE_EXT_AF;
3995 #endif
3996
3997 + user_pgprot |= __supported_pte_mask;
3998 +
3999 for (i = 0; i < 16; i++) {
4000 pteval_t v = pgprot_val(protection_map[i]);
4001 protection_map[i] = __pgprot(v | user_pgprot);
4002 @@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
4003
4004 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4005 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4006 - mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4007 - mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4008 + mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4009 + mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4010 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4011 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4012 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4013 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4014 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4015 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4016 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4017 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4018 mem_types[MT_ROM].prot_sect |= cp->pmd;
4019
4020 switch (cp->pmd) {
4021 @@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
4022 * called function. This means you can't use any function or debugging
4023 * method which may touch any device, otherwise the kernel _will_ crash.
4024 */
4025 +
4026 +static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4027 +
4028 static void __init devicemaps_init(struct machine_desc *mdesc)
4029 {
4030 struct map_desc map;
4031 unsigned long addr;
4032 - void *vectors;
4033
4034 - /*
4035 - * Allocate the vector page early.
4036 - */
4037 - vectors = early_alloc(PAGE_SIZE);
4038 -
4039 - early_trap_init(vectors);
4040 + early_trap_init(&vectors);
4041
4042 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4043 pmd_clear(pmd_off_k(addr));
4044 @@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4045 * location (0xffff0000). If we aren't using high-vectors, also
4046 * create a mapping at the low-vectors virtual address.
4047 */
4048 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4049 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4050 map.virtual = 0xffff0000;
4051 map.length = PAGE_SIZE;
4052 map.type = MT_HIGH_VECTORS;
4053 @@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
4054 map.pfn = __phys_to_pfn(start);
4055 map.virtual = __phys_to_virt(start);
4056 map.length = end - start;
4057 - map.type = MT_MEMORY;
4058
4059 +#ifdef CONFIG_PAX_KERNEXEC
4060 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4061 + struct map_desc kernel;
4062 + struct map_desc initmap;
4063 +
4064 + /* when freeing initmem we will make this RW */
4065 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4066 + initmap.virtual = (unsigned long)__init_begin;
4067 + initmap.length = _sdata - __init_begin;
4068 + initmap.type = MT_MEMORY_RWX;
4069 + create_mapping(&initmap);
4070 +
4071 + /* when freeing initmem we will make this RX */
4072 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4073 + kernel.virtual = (unsigned long)_stext;
4074 + kernel.length = __init_begin - _stext;
4075 + kernel.type = MT_MEMORY_RWX;
4076 + create_mapping(&kernel);
4077 +
4078 + if (map.virtual < (unsigned long)_stext) {
4079 + map.length = (unsigned long)_stext - map.virtual;
4080 + map.type = MT_MEMORY_RWX;
4081 + create_mapping(&map);
4082 + }
4083 +
4084 + map.pfn = __phys_to_pfn(__pa(_sdata));
4085 + map.virtual = (unsigned long)_sdata;
4086 + map.length = end - __pa(_sdata);
4087 + }
4088 +#endif
4089 +
4090 + map.type = MT_MEMORY_RW;
4091 create_mapping(&map);
4092 }
4093 }
4094 diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4095 index 6d98c13..3cfb174 100644
4096 --- a/arch/arm/mm/proc-v7-2level.S
4097 +++ b/arch/arm/mm/proc-v7-2level.S
4098 @@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4099 tst r1, #L_PTE_XN
4100 orrne r3, r3, #PTE_EXT_XN
4101
4102 + tst r1, #L_PTE_PXN
4103 + orrne r3, r3, #PTE_EXT_PXN
4104 +
4105 tst r1, #L_PTE_YOUNG
4106 tstne r1, #L_PTE_VALID
4107 #ifndef CONFIG_CPU_USE_DOMAINS
4108 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4109 index a5bc92d..0bb4730 100644
4110 --- a/arch/arm/plat-omap/sram.c
4111 +++ b/arch/arm/plat-omap/sram.c
4112 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4113 * Looks like we need to preserve some bootloader code at the
4114 * beginning of SRAM for jumping to flash for reboot to work...
4115 */
4116 + pax_open_kernel();
4117 memset_io(omap_sram_base + omap_sram_skip, 0,
4118 omap_sram_size - omap_sram_skip);
4119 + pax_close_kernel();
4120 }
4121 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
4122 index b76c065..b6e766b 100644
4123 --- a/arch/arm/plat-orion/include/plat/addr-map.h
4124 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
4125 @@ -27,7 +27,7 @@ struct orion_addr_map_cfg {
4126 value in bridge_virt_base */
4127 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
4128 const int win);
4129 -};
4130 +} __no_const;
4131
4132 /*
4133 * Information needed to setup one address mapping.
4134 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4135 index f5144cd..71f6d1f 100644
4136 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4137 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4138 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4139 int (*started)(unsigned ch);
4140 int (*flush)(unsigned ch);
4141 int (*stop)(unsigned ch);
4142 -};
4143 +} __no_const;
4144
4145 extern void *samsung_dmadev_get_ops(void);
4146 extern void *s3c_dma_get_ops(void);
4147 diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4148 index 0c3ba9f..95722b3 100644
4149 --- a/arch/arm64/kernel/debug-monitors.c
4150 +++ b/arch/arm64/kernel/debug-monitors.c
4151 @@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4152 return NOTIFY_OK;
4153 }
4154
4155 -static struct notifier_block __cpuinitdata os_lock_nb = {
4156 +static struct notifier_block os_lock_nb = {
4157 .notifier_call = os_lock_notify,
4158 };
4159
4160 diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4161 index 5ab825c..96aaec8 100644
4162 --- a/arch/arm64/kernel/hw_breakpoint.c
4163 +++ b/arch/arm64/kernel/hw_breakpoint.c
4164 @@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4165 return NOTIFY_OK;
4166 }
4167
4168 -static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4169 +static struct notifier_block hw_breakpoint_reset_nb = {
4170 .notifier_call = hw_breakpoint_reset_notify,
4171 };
4172
4173 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4174 index c3a58a1..78fbf54 100644
4175 --- a/arch/avr32/include/asm/cache.h
4176 +++ b/arch/avr32/include/asm/cache.h
4177 @@ -1,8 +1,10 @@
4178 #ifndef __ASM_AVR32_CACHE_H
4179 #define __ASM_AVR32_CACHE_H
4180
4181 +#include <linux/const.h>
4182 +
4183 #define L1_CACHE_SHIFT 5
4184 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4185 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4186
4187 /*
4188 * Memory returned by kmalloc() may be used for DMA, so we must make
4189 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4190 index e2c3287..6c4f98c 100644
4191 --- a/arch/avr32/include/asm/elf.h
4192 +++ b/arch/avr32/include/asm/elf.h
4193 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4194 the loader. We need to make sure that it is out of the way of the program
4195 that it will "exec", and that there is sufficient room for the brk. */
4196
4197 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4198 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4199
4200 +#ifdef CONFIG_PAX_ASLR
4201 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4202 +
4203 +#define PAX_DELTA_MMAP_LEN 15
4204 +#define PAX_DELTA_STACK_LEN 15
4205 +#endif
4206
4207 /* This yields a mask that user programs can use to figure out what
4208 instruction set this CPU supports. This could be done in user space,
4209 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4210 index 479330b..53717a8 100644
4211 --- a/arch/avr32/include/asm/kmap_types.h
4212 +++ b/arch/avr32/include/asm/kmap_types.h
4213 @@ -2,9 +2,9 @@
4214 #define __ASM_AVR32_KMAP_TYPES_H
4215
4216 #ifdef CONFIG_DEBUG_HIGHMEM
4217 -# define KM_TYPE_NR 29
4218 +# define KM_TYPE_NR 30
4219 #else
4220 -# define KM_TYPE_NR 14
4221 +# define KM_TYPE_NR 15
4222 #endif
4223
4224 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4225 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4226 index b2f2d2d..d1c85cb 100644
4227 --- a/arch/avr32/mm/fault.c
4228 +++ b/arch/avr32/mm/fault.c
4229 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4230
4231 int exception_trace = 1;
4232
4233 +#ifdef CONFIG_PAX_PAGEEXEC
4234 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4235 +{
4236 + unsigned long i;
4237 +
4238 + printk(KERN_ERR "PAX: bytes at PC: ");
4239 + for (i = 0; i < 20; i++) {
4240 + unsigned char c;
4241 + if (get_user(c, (unsigned char *)pc+i))
4242 + printk(KERN_CONT "???????? ");
4243 + else
4244 + printk(KERN_CONT "%02x ", c);
4245 + }
4246 + printk("\n");
4247 +}
4248 +#endif
4249 +
4250 /*
4251 * This routine handles page faults. It determines the address and the
4252 * problem, and then passes it off to one of the appropriate routines.
4253 @@ -174,6 +191,16 @@ bad_area:
4254 up_read(&mm->mmap_sem);
4255
4256 if (user_mode(regs)) {
4257 +
4258 +#ifdef CONFIG_PAX_PAGEEXEC
4259 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4260 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4261 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4262 + do_group_exit(SIGKILL);
4263 + }
4264 + }
4265 +#endif
4266 +
4267 if (exception_trace && printk_ratelimit())
4268 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4269 "sp %08lx ecr %lu\n",
4270 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4271 index 568885a..f8008df 100644
4272 --- a/arch/blackfin/include/asm/cache.h
4273 +++ b/arch/blackfin/include/asm/cache.h
4274 @@ -7,6 +7,7 @@
4275 #ifndef __ARCH_BLACKFIN_CACHE_H
4276 #define __ARCH_BLACKFIN_CACHE_H
4277
4278 +#include <linux/const.h>
4279 #include <linux/linkage.h> /* for asmlinkage */
4280
4281 /*
4282 @@ -14,7 +15,7 @@
4283 * Blackfin loads 32 bytes for cache
4284 */
4285 #define L1_CACHE_SHIFT 5
4286 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4287 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4288 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4289
4290 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4291 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4292 index aea2718..3639a60 100644
4293 --- a/arch/cris/include/arch-v10/arch/cache.h
4294 +++ b/arch/cris/include/arch-v10/arch/cache.h
4295 @@ -1,8 +1,9 @@
4296 #ifndef _ASM_ARCH_CACHE_H
4297 #define _ASM_ARCH_CACHE_H
4298
4299 +#include <linux/const.h>
4300 /* Etrax 100LX have 32-byte cache-lines. */
4301 -#define L1_CACHE_BYTES 32
4302 #define L1_CACHE_SHIFT 5
4303 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4304
4305 #endif /* _ASM_ARCH_CACHE_H */
4306 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4307 index 7caf25d..ee65ac5 100644
4308 --- a/arch/cris/include/arch-v32/arch/cache.h
4309 +++ b/arch/cris/include/arch-v32/arch/cache.h
4310 @@ -1,11 +1,12 @@
4311 #ifndef _ASM_CRIS_ARCH_CACHE_H
4312 #define _ASM_CRIS_ARCH_CACHE_H
4313
4314 +#include <linux/const.h>
4315 #include <arch/hwregs/dma.h>
4316
4317 /* A cache-line is 32 bytes. */
4318 -#define L1_CACHE_BYTES 32
4319 #define L1_CACHE_SHIFT 5
4320 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4321
4322 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4323
4324 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4325 index b86329d..6709906 100644
4326 --- a/arch/frv/include/asm/atomic.h
4327 +++ b/arch/frv/include/asm/atomic.h
4328 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4329 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4330 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4331
4332 +#define atomic64_read_unchecked(v) atomic64_read(v)
4333 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4334 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4335 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4336 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4337 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4338 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4339 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4340 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4341 +
4342 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4343 {
4344 int c, old;
4345 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4346 index 2797163..c2a401d 100644
4347 --- a/arch/frv/include/asm/cache.h
4348 +++ b/arch/frv/include/asm/cache.h
4349 @@ -12,10 +12,11 @@
4350 #ifndef __ASM_CACHE_H
4351 #define __ASM_CACHE_H
4352
4353 +#include <linux/const.h>
4354
4355 /* bytes per L1 cache line */
4356 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4357 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4358 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4359
4360 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4361 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4362 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4363 index 43901f2..0d8b865 100644
4364 --- a/arch/frv/include/asm/kmap_types.h
4365 +++ b/arch/frv/include/asm/kmap_types.h
4366 @@ -2,6 +2,6 @@
4367 #ifndef _ASM_KMAP_TYPES_H
4368 #define _ASM_KMAP_TYPES_H
4369
4370 -#define KM_TYPE_NR 17
4371 +#define KM_TYPE_NR 18
4372
4373 #endif
4374 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4375 index 385fd30..3aaf4fe 100644
4376 --- a/arch/frv/mm/elf-fdpic.c
4377 +++ b/arch/frv/mm/elf-fdpic.c
4378 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4379 {
4380 struct vm_area_struct *vma;
4381 unsigned long limit;
4382 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4383
4384 if (len > TASK_SIZE)
4385 return -ENOMEM;
4386 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4387 if (addr) {
4388 addr = PAGE_ALIGN(addr);
4389 vma = find_vma(current->mm, addr);
4390 - if (TASK_SIZE - len >= addr &&
4391 - (!vma || addr + len <= vma->vm_start))
4392 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4393 goto success;
4394 }
4395
4396 @@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4397 for (; vma; vma = vma->vm_next) {
4398 if (addr > limit)
4399 break;
4400 - if (addr + len <= vma->vm_start)
4401 + if (check_heap_stack_gap(vma, addr, len, offset))
4402 goto success;
4403 addr = vma->vm_end;
4404 }
4405 @@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4406 for (; vma; vma = vma->vm_next) {
4407 if (addr > limit)
4408 break;
4409 - if (addr + len <= vma->vm_start)
4410 + if (check_heap_stack_gap(vma, addr, len, offset))
4411 goto success;
4412 addr = vma->vm_end;
4413 }
4414 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4415 index f4ca594..adc72fd6 100644
4416 --- a/arch/hexagon/include/asm/cache.h
4417 +++ b/arch/hexagon/include/asm/cache.h
4418 @@ -21,9 +21,11 @@
4419 #ifndef __ASM_CACHE_H
4420 #define __ASM_CACHE_H
4421
4422 +#include <linux/const.h>
4423 +
4424 /* Bytes per L1 cache line */
4425 -#define L1_CACHE_SHIFT (5)
4426 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4427 +#define L1_CACHE_SHIFT 5
4428 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4429
4430 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4431 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4432 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4433 index 6e6fe18..a6ae668 100644
4434 --- a/arch/ia64/include/asm/atomic.h
4435 +++ b/arch/ia64/include/asm/atomic.h
4436 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4437 #define atomic64_inc(v) atomic64_add(1, (v))
4438 #define atomic64_dec(v) atomic64_sub(1, (v))
4439
4440 +#define atomic64_read_unchecked(v) atomic64_read(v)
4441 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4442 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4443 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4444 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4445 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4446 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4447 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4448 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4449 +
4450 /* Atomic operations are already serializing */
4451 #define smp_mb__before_atomic_dec() barrier()
4452 #define smp_mb__after_atomic_dec() barrier()
4453 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4454 index 988254a..e1ee885 100644
4455 --- a/arch/ia64/include/asm/cache.h
4456 +++ b/arch/ia64/include/asm/cache.h
4457 @@ -1,6 +1,7 @@
4458 #ifndef _ASM_IA64_CACHE_H
4459 #define _ASM_IA64_CACHE_H
4460
4461 +#include <linux/const.h>
4462
4463 /*
4464 * Copyright (C) 1998-2000 Hewlett-Packard Co
4465 @@ -9,7 +10,7 @@
4466
4467 /* Bytes per L1 (data) cache line. */
4468 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4469 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4470 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4471
4472 #ifdef CONFIG_SMP
4473 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4474 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4475 index b5298eb..67c6e62 100644
4476 --- a/arch/ia64/include/asm/elf.h
4477 +++ b/arch/ia64/include/asm/elf.h
4478 @@ -42,6 +42,13 @@
4479 */
4480 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4481
4482 +#ifdef CONFIG_PAX_ASLR
4483 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4484 +
4485 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4486 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4487 +#endif
4488 +
4489 #define PT_IA_64_UNWIND 0x70000001
4490
4491 /* IA-64 relocations: */
4492 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4493 index 96a8d92..617a1cf 100644
4494 --- a/arch/ia64/include/asm/pgalloc.h
4495 +++ b/arch/ia64/include/asm/pgalloc.h
4496 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4497 pgd_val(*pgd_entry) = __pa(pud);
4498 }
4499
4500 +static inline void
4501 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4502 +{
4503 + pgd_populate(mm, pgd_entry, pud);
4504 +}
4505 +
4506 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4507 {
4508 return quicklist_alloc(0, GFP_KERNEL, NULL);
4509 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4510 pud_val(*pud_entry) = __pa(pmd);
4511 }
4512
4513 +static inline void
4514 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4515 +{
4516 + pud_populate(mm, pud_entry, pmd);
4517 +}
4518 +
4519 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4520 {
4521 return quicklist_alloc(0, GFP_KERNEL, NULL);
4522 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4523 index 815810c..d60bd4c 100644
4524 --- a/arch/ia64/include/asm/pgtable.h
4525 +++ b/arch/ia64/include/asm/pgtable.h
4526 @@ -12,7 +12,7 @@
4527 * David Mosberger-Tang <davidm@hpl.hp.com>
4528 */
4529
4530 -
4531 +#include <linux/const.h>
4532 #include <asm/mman.h>
4533 #include <asm/page.h>
4534 #include <asm/processor.h>
4535 @@ -142,6 +142,17 @@
4536 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4537 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4538 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4539 +
4540 +#ifdef CONFIG_PAX_PAGEEXEC
4541 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4542 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4543 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4544 +#else
4545 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4546 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4547 +# define PAGE_COPY_NOEXEC PAGE_COPY
4548 +#endif
4549 +
4550 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4551 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4552 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4553 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4554 index 54ff557..70c88b7 100644
4555 --- a/arch/ia64/include/asm/spinlock.h
4556 +++ b/arch/ia64/include/asm/spinlock.h
4557 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4558 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4559
4560 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4561 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4562 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4563 }
4564
4565 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4566 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4567 index 449c8c0..50cdf87 100644
4568 --- a/arch/ia64/include/asm/uaccess.h
4569 +++ b/arch/ia64/include/asm/uaccess.h
4570 @@ -42,6 +42,8 @@
4571 #include <asm/pgtable.h>
4572 #include <asm/io.h>
4573
4574 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
4575 +
4576 /*
4577 * For historical reasons, the following macros are grossly misnamed:
4578 */
4579 @@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4580 static inline unsigned long
4581 __copy_to_user (void __user *to, const void *from, unsigned long count)
4582 {
4583 + if (count > INT_MAX)
4584 + return count;
4585 +
4586 + if (!__builtin_constant_p(count))
4587 + check_object_size(from, count, true);
4588 +
4589 return __copy_user(to, (__force void __user *) from, count);
4590 }
4591
4592 static inline unsigned long
4593 __copy_from_user (void *to, const void __user *from, unsigned long count)
4594 {
4595 + if (count > INT_MAX)
4596 + return count;
4597 +
4598 + if (!__builtin_constant_p(count))
4599 + check_object_size(to, count, false);
4600 +
4601 return __copy_user((__force void __user *) to, from, count);
4602 }
4603
4604 @@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4605 ({ \
4606 void __user *__cu_to = (to); \
4607 const void *__cu_from = (from); \
4608 - long __cu_len = (n); \
4609 + unsigned long __cu_len = (n); \
4610 \
4611 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
4612 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4613 + if (!__builtin_constant_p(n)) \
4614 + check_object_size(__cu_from, __cu_len, true); \
4615 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4616 + } \
4617 __cu_len; \
4618 })
4619
4620 @@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4621 ({ \
4622 void *__cu_to = (to); \
4623 const void __user *__cu_from = (from); \
4624 - long __cu_len = (n); \
4625 + unsigned long __cu_len = (n); \
4626 \
4627 __chk_user_ptr(__cu_from); \
4628 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
4629 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4630 + if (!__builtin_constant_p(n)) \
4631 + check_object_size(__cu_to, __cu_len, false); \
4632 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4633 + } \
4634 __cu_len; \
4635 })
4636
4637 diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4638 index 2d67317..07d8bfa 100644
4639 --- a/arch/ia64/kernel/err_inject.c
4640 +++ b/arch/ia64/kernel/err_inject.c
4641 @@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4642 return NOTIFY_OK;
4643 }
4644
4645 -static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4646 +static struct notifier_block err_inject_cpu_notifier =
4647 {
4648 .notifier_call = err_inject_cpu_callback,
4649 };
4650 diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4651 index 65bf9cd..794f06b 100644
4652 --- a/arch/ia64/kernel/mca.c
4653 +++ b/arch/ia64/kernel/mca.c
4654 @@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4655 return NOTIFY_OK;
4656 }
4657
4658 -static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4659 +static struct notifier_block mca_cpu_notifier = {
4660 .notifier_call = mca_cpu_callback
4661 };
4662
4663 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4664 index 24603be..948052d 100644
4665 --- a/arch/ia64/kernel/module.c
4666 +++ b/arch/ia64/kernel/module.c
4667 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4668 void
4669 module_free (struct module *mod, void *module_region)
4670 {
4671 - if (mod && mod->arch.init_unw_table &&
4672 - module_region == mod->module_init) {
4673 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4674 unw_remove_unwind_table(mod->arch.init_unw_table);
4675 mod->arch.init_unw_table = NULL;
4676 }
4677 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4678 }
4679
4680 static inline int
4681 +in_init_rx (const struct module *mod, uint64_t addr)
4682 +{
4683 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4684 +}
4685 +
4686 +static inline int
4687 +in_init_rw (const struct module *mod, uint64_t addr)
4688 +{
4689 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4690 +}
4691 +
4692 +static inline int
4693 in_init (const struct module *mod, uint64_t addr)
4694 {
4695 - return addr - (uint64_t) mod->module_init < mod->init_size;
4696 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4697 +}
4698 +
4699 +static inline int
4700 +in_core_rx (const struct module *mod, uint64_t addr)
4701 +{
4702 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4703 +}
4704 +
4705 +static inline int
4706 +in_core_rw (const struct module *mod, uint64_t addr)
4707 +{
4708 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4709 }
4710
4711 static inline int
4712 in_core (const struct module *mod, uint64_t addr)
4713 {
4714 - return addr - (uint64_t) mod->module_core < mod->core_size;
4715 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4716 }
4717
4718 static inline int
4719 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4720 break;
4721
4722 case RV_BDREL:
4723 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4724 + if (in_init_rx(mod, val))
4725 + val -= (uint64_t) mod->module_init_rx;
4726 + else if (in_init_rw(mod, val))
4727 + val -= (uint64_t) mod->module_init_rw;
4728 + else if (in_core_rx(mod, val))
4729 + val -= (uint64_t) mod->module_core_rx;
4730 + else if (in_core_rw(mod, val))
4731 + val -= (uint64_t) mod->module_core_rw;
4732 break;
4733
4734 case RV_LTV:
4735 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4736 * addresses have been selected...
4737 */
4738 uint64_t gp;
4739 - if (mod->core_size > MAX_LTOFF)
4740 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4741 /*
4742 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4743 * at the end of the module.
4744 */
4745 - gp = mod->core_size - MAX_LTOFF / 2;
4746 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4747 else
4748 - gp = mod->core_size / 2;
4749 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4750 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4751 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4752 mod->arch.gp = gp;
4753 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4754 }
4755 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4756 index 77597e5..6f28f3f 100644
4757 --- a/arch/ia64/kernel/palinfo.c
4758 +++ b/arch/ia64/kernel/palinfo.c
4759 @@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4760 return NOTIFY_OK;
4761 }
4762
4763 -static struct notifier_block __refdata palinfo_cpu_notifier =
4764 +static struct notifier_block palinfo_cpu_notifier =
4765 {
4766 .notifier_call = palinfo_cpu_callback,
4767 .priority = 0,
4768 diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4769 index 79802e5..1a89ec5 100644
4770 --- a/arch/ia64/kernel/salinfo.c
4771 +++ b/arch/ia64/kernel/salinfo.c
4772 @@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4773 return NOTIFY_OK;
4774 }
4775
4776 -static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4777 +static struct notifier_block salinfo_cpu_notifier =
4778 {
4779 .notifier_call = salinfo_cpu_callback,
4780 .priority = 0,
4781 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4782 index d9439ef..d0cac6b 100644
4783 --- a/arch/ia64/kernel/sys_ia64.c
4784 +++ b/arch/ia64/kernel/sys_ia64.c
4785 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4786 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
4787 struct mm_struct *mm = current->mm;
4788 struct vm_area_struct *vma;
4789 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4790
4791 if (len > RGN_MAP_LIMIT)
4792 return -ENOMEM;
4793 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4794 if (REGION_NUMBER(addr) == RGN_HPAGE)
4795 addr = 0;
4796 #endif
4797 +
4798 +#ifdef CONFIG_PAX_RANDMMAP
4799 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4800 + addr = mm->free_area_cache;
4801 + else
4802 +#endif
4803 +
4804 if (!addr)
4805 addr = mm->free_area_cache;
4806
4807 @@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4808 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
4809 /* At this point: (!vma || addr < vma->vm_end). */
4810 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
4811 - if (start_addr != TASK_UNMAPPED_BASE) {
4812 + if (start_addr != mm->mmap_base) {
4813 /* Start a new search --- just in case we missed some holes. */
4814 - addr = TASK_UNMAPPED_BASE;
4815 + addr = mm->mmap_base;
4816 goto full_search;
4817 }
4818 return -ENOMEM;
4819 }
4820 - if (!vma || addr + len <= vma->vm_start) {
4821 + if (check_heap_stack_gap(vma, addr, len, offset)) {
4822 /* Remember the address where we stopped this search: */
4823 mm->free_area_cache = addr + len;
4824 return addr;
4825 diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
4826 index dc00b2c..cce53c2 100644
4827 --- a/arch/ia64/kernel/topology.c
4828 +++ b/arch/ia64/kernel/topology.c
4829 @@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
4830 return NOTIFY_OK;
4831 }
4832
4833 -static struct notifier_block __cpuinitdata cache_cpu_notifier =
4834 +static struct notifier_block cache_cpu_notifier =
4835 {
4836 .notifier_call = cache_cpu_callback
4837 };
4838 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
4839 index 0ccb28f..8992469 100644
4840 --- a/arch/ia64/kernel/vmlinux.lds.S
4841 +++ b/arch/ia64/kernel/vmlinux.lds.S
4842 @@ -198,7 +198,7 @@ SECTIONS {
4843 /* Per-cpu data: */
4844 . = ALIGN(PERCPU_PAGE_SIZE);
4845 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
4846 - __phys_per_cpu_start = __per_cpu_load;
4847 + __phys_per_cpu_start = per_cpu_load;
4848 /*
4849 * ensure percpu data fits
4850 * into percpu page size
4851 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
4852 index 6cf0341..d352594 100644
4853 --- a/arch/ia64/mm/fault.c
4854 +++ b/arch/ia64/mm/fault.c
4855 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
4856 return pte_present(pte);
4857 }
4858
4859 +#ifdef CONFIG_PAX_PAGEEXEC
4860 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4861 +{
4862 + unsigned long i;
4863 +
4864 + printk(KERN_ERR "PAX: bytes at PC: ");
4865 + for (i = 0; i < 8; i++) {
4866 + unsigned int c;
4867 + if (get_user(c, (unsigned int *)pc+i))
4868 + printk(KERN_CONT "???????? ");
4869 + else
4870 + printk(KERN_CONT "%08x ", c);
4871 + }
4872 + printk("\n");
4873 +}
4874 +#endif
4875 +
4876 # define VM_READ_BIT 0
4877 # define VM_WRITE_BIT 1
4878 # define VM_EXEC_BIT 2
4879 @@ -149,8 +166,21 @@ retry:
4880 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
4881 goto bad_area;
4882
4883 - if ((vma->vm_flags & mask) != mask)
4884 + if ((vma->vm_flags & mask) != mask) {
4885 +
4886 +#ifdef CONFIG_PAX_PAGEEXEC
4887 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
4888 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
4889 + goto bad_area;
4890 +
4891 + up_read(&mm->mmap_sem);
4892 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
4893 + do_group_exit(SIGKILL);
4894 + }
4895 +#endif
4896 +
4897 goto bad_area;
4898 + }
4899
4900 /*
4901 * If for any reason at all we couldn't handle the fault, make
4902 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
4903 index 5ca674b..127c3cb 100644
4904 --- a/arch/ia64/mm/hugetlbpage.c
4905 +++ b/arch/ia64/mm/hugetlbpage.c
4906 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4907 unsigned long pgoff, unsigned long flags)
4908 {
4909 struct vm_area_struct *vmm;
4910 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
4911
4912 if (len > RGN_MAP_LIMIT)
4913 return -ENOMEM;
4914 @@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4915 /* At this point: (!vmm || addr < vmm->vm_end). */
4916 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
4917 return -ENOMEM;
4918 - if (!vmm || (addr + len) <= vmm->vm_start)
4919 + if (check_heap_stack_gap(vmm, addr, len, offset))
4920 return addr;
4921 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
4922 }
4923 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
4924 index b755ea9..b9a969e 100644
4925 --- a/arch/ia64/mm/init.c
4926 +++ b/arch/ia64/mm/init.c
4927 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
4928 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
4929 vma->vm_end = vma->vm_start + PAGE_SIZE;
4930 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
4931 +
4932 +#ifdef CONFIG_PAX_PAGEEXEC
4933 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
4934 + vma->vm_flags &= ~VM_EXEC;
4935 +
4936 +#ifdef CONFIG_PAX_MPROTECT
4937 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
4938 + vma->vm_flags &= ~VM_MAYEXEC;
4939 +#endif
4940 +
4941 + }
4942 +#endif
4943 +
4944 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4945 down_write(&current->mm->mmap_sem);
4946 if (insert_vm_struct(current->mm, vma)) {
4947 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
4948 index 40b3ee9..8c2c112 100644
4949 --- a/arch/m32r/include/asm/cache.h
4950 +++ b/arch/m32r/include/asm/cache.h
4951 @@ -1,8 +1,10 @@
4952 #ifndef _ASM_M32R_CACHE_H
4953 #define _ASM_M32R_CACHE_H
4954
4955 +#include <linux/const.h>
4956 +
4957 /* L1 cache line size */
4958 #define L1_CACHE_SHIFT 4
4959 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4960 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4961
4962 #endif /* _ASM_M32R_CACHE_H */
4963 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
4964 index 82abd15..d95ae5d 100644
4965 --- a/arch/m32r/lib/usercopy.c
4966 +++ b/arch/m32r/lib/usercopy.c
4967 @@ -14,6 +14,9 @@
4968 unsigned long
4969 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4970 {
4971 + if ((long)n < 0)
4972 + return n;
4973 +
4974 prefetch(from);
4975 if (access_ok(VERIFY_WRITE, to, n))
4976 __copy_user(to,from,n);
4977 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4978 unsigned long
4979 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
4980 {
4981 + if ((long)n < 0)
4982 + return n;
4983 +
4984 prefetchw(to);
4985 if (access_ok(VERIFY_READ, from, n))
4986 __copy_user_zeroing(to,from,n);
4987 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
4988 index 0395c51..5f26031 100644
4989 --- a/arch/m68k/include/asm/cache.h
4990 +++ b/arch/m68k/include/asm/cache.h
4991 @@ -4,9 +4,11 @@
4992 #ifndef __ARCH_M68K_CACHE_H
4993 #define __ARCH_M68K_CACHE_H
4994
4995 +#include <linux/const.h>
4996 +
4997 /* bytes per L1 cache line */
4998 #define L1_CACHE_SHIFT 4
4999 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5000 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5001
5002 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5003
5004 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5005 index 4efe96a..60e8699 100644
5006 --- a/arch/microblaze/include/asm/cache.h
5007 +++ b/arch/microblaze/include/asm/cache.h
5008 @@ -13,11 +13,12 @@
5009 #ifndef _ASM_MICROBLAZE_CACHE_H
5010 #define _ASM_MICROBLAZE_CACHE_H
5011
5012 +#include <linux/const.h>
5013 #include <asm/registers.h>
5014
5015 #define L1_CACHE_SHIFT 5
5016 /* word-granular cache in microblaze */
5017 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5018 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5019
5020 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5021
5022 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5023 index 01cc6ba..bcb7a5d 100644
5024 --- a/arch/mips/include/asm/atomic.h
5025 +++ b/arch/mips/include/asm/atomic.h
5026 @@ -21,6 +21,10 @@
5027 #include <asm/cmpxchg.h>
5028 #include <asm/war.h>
5029
5030 +#ifdef CONFIG_GENERIC_ATOMIC64
5031 +#include <asm-generic/atomic64.h>
5032 +#endif
5033 +
5034 #define ATOMIC_INIT(i) { (i) }
5035
5036 /*
5037 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5038 */
5039 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5040
5041 +#define atomic64_read_unchecked(v) atomic64_read(v)
5042 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5043 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5044 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5045 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5046 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5047 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5048 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5049 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5050 +
5051 #endif /* CONFIG_64BIT */
5052
5053 /*
5054 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5055 index b4db69f..8f3b093 100644
5056 --- a/arch/mips/include/asm/cache.h
5057 +++ b/arch/mips/include/asm/cache.h
5058 @@ -9,10 +9,11 @@
5059 #ifndef _ASM_CACHE_H
5060 #define _ASM_CACHE_H
5061
5062 +#include <linux/const.h>
5063 #include <kmalloc.h>
5064
5065 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5066 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5067 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5068
5069 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5070 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5071 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5072 index 455c0ac..ad65fbe 100644
5073 --- a/arch/mips/include/asm/elf.h
5074 +++ b/arch/mips/include/asm/elf.h
5075 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
5076 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5077 #endif
5078
5079 +#ifdef CONFIG_PAX_ASLR
5080 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5081 +
5082 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5083 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5084 +#endif
5085 +
5086 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5087 struct linux_binprm;
5088 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5089 int uses_interp);
5090
5091 -struct mm_struct;
5092 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5093 -#define arch_randomize_brk arch_randomize_brk
5094 -
5095 #endif /* _ASM_ELF_H */
5096 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5097 index c1f6afa..38cc6e9 100644
5098 --- a/arch/mips/include/asm/exec.h
5099 +++ b/arch/mips/include/asm/exec.h
5100 @@ -12,6 +12,6 @@
5101 #ifndef _ASM_EXEC_H
5102 #define _ASM_EXEC_H
5103
5104 -extern unsigned long arch_align_stack(unsigned long sp);
5105 +#define arch_align_stack(x) ((x) & ~0xfUL)
5106
5107 #endif /* _ASM_EXEC_H */
5108 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5109 index dbaec94..6a14935 100644
5110 --- a/arch/mips/include/asm/page.h
5111 +++ b/arch/mips/include/asm/page.h
5112 @@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5113 #ifdef CONFIG_CPU_MIPS32
5114 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5115 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5116 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5117 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5118 #else
5119 typedef struct { unsigned long long pte; } pte_t;
5120 #define pte_val(x) ((x).pte)
5121 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5122 index 881d18b..cea38bc 100644
5123 --- a/arch/mips/include/asm/pgalloc.h
5124 +++ b/arch/mips/include/asm/pgalloc.h
5125 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5126 {
5127 set_pud(pud, __pud((unsigned long)pmd));
5128 }
5129 +
5130 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5131 +{
5132 + pud_populate(mm, pud, pmd);
5133 +}
5134 #endif
5135
5136 /*
5137 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5138 index b2050b9..d71bb1b 100644
5139 --- a/arch/mips/include/asm/thread_info.h
5140 +++ b/arch/mips/include/asm/thread_info.h
5141 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5142 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5143 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5144 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5145 +/* li takes a 32bit immediate */
5146 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5147 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5148
5149 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5150 @@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5151 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5152 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5153 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5154 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5155 +
5156 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5157
5158 /* work to do in syscall_trace_leave() */
5159 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5160 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5161
5162 /* work to do on interrupt/exception return */
5163 #define _TIF_WORK_MASK \
5164 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5165 /* work to do on any return to u-space */
5166 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5167 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5168
5169 #endif /* __KERNEL__ */
5170
5171 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5172 index 9fdd8bc..4bd7f1a 100644
5173 --- a/arch/mips/kernel/binfmt_elfn32.c
5174 +++ b/arch/mips/kernel/binfmt_elfn32.c
5175 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5176 #undef ELF_ET_DYN_BASE
5177 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5178
5179 +#ifdef CONFIG_PAX_ASLR
5180 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5181 +
5182 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5183 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5184 +#endif
5185 +
5186 #include <asm/processor.h>
5187 #include <linux/module.h>
5188 #include <linux/elfcore.h>
5189 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5190 index ff44823..97f8906 100644
5191 --- a/arch/mips/kernel/binfmt_elfo32.c
5192 +++ b/arch/mips/kernel/binfmt_elfo32.c
5193 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5194 #undef ELF_ET_DYN_BASE
5195 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5196
5197 +#ifdef CONFIG_PAX_ASLR
5198 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5199 +
5200 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5201 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5202 +#endif
5203 +
5204 #include <asm/processor.h>
5205
5206 /*
5207 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5208 index a11c6f9..be5e164 100644
5209 --- a/arch/mips/kernel/process.c
5210 +++ b/arch/mips/kernel/process.c
5211 @@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5212 out:
5213 return pc;
5214 }
5215 -
5216 -/*
5217 - * Don't forget that the stack pointer must be aligned on a 8 bytes
5218 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5219 - */
5220 -unsigned long arch_align_stack(unsigned long sp)
5221 -{
5222 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5223 - sp -= get_random_int() & ~PAGE_MASK;
5224 -
5225 - return sp & ALMASK;
5226 -}
5227 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5228 index 4812c6d..2069554 100644
5229 --- a/arch/mips/kernel/ptrace.c
5230 +++ b/arch/mips/kernel/ptrace.c
5231 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
5232 return arch;
5233 }
5234
5235 +#ifdef CONFIG_GRKERNSEC_SETXID
5236 +extern void gr_delayed_cred_worker(void);
5237 +#endif
5238 +
5239 /*
5240 * Notification of system call entry/exit
5241 * - triggered by current->work.syscall_trace
5242 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5243 /* do the secure computing check first */
5244 secure_computing_strict(regs->regs[2]);
5245
5246 +#ifdef CONFIG_GRKERNSEC_SETXID
5247 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5248 + gr_delayed_cred_worker();
5249 +#endif
5250 +
5251 if (!(current->ptrace & PT_PTRACED))
5252 goto out;
5253
5254 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5255 index d20a4bc..7096ae5 100644
5256 --- a/arch/mips/kernel/scall32-o32.S
5257 +++ b/arch/mips/kernel/scall32-o32.S
5258 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5259
5260 stack_done:
5261 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5262 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5263 + li t1, _TIF_SYSCALL_WORK
5264 and t0, t1
5265 bnez t0, syscall_trace_entry # -> yes
5266
5267 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5268 index b64f642..0fe6eab 100644
5269 --- a/arch/mips/kernel/scall64-64.S
5270 +++ b/arch/mips/kernel/scall64-64.S
5271 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5272
5273 sd a3, PT_R26(sp) # save a3 for syscall restarting
5274
5275 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5276 + li t1, _TIF_SYSCALL_WORK
5277 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5278 and t0, t1, t0
5279 bnez t0, syscall_trace_entry
5280 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5281 index c29ac19..c592d05 100644
5282 --- a/arch/mips/kernel/scall64-n32.S
5283 +++ b/arch/mips/kernel/scall64-n32.S
5284 @@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5285
5286 sd a3, PT_R26(sp) # save a3 for syscall restarting
5287
5288 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5289 + li t1, _TIF_SYSCALL_WORK
5290 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5291 and t0, t1, t0
5292 bnez t0, n32_syscall_trace_entry
5293 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5294 index cf3e75e..72e93fe 100644
5295 --- a/arch/mips/kernel/scall64-o32.S
5296 +++ b/arch/mips/kernel/scall64-o32.S
5297 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5298 PTR 4b, bad_stack
5299 .previous
5300
5301 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5302 + li t1, _TIF_SYSCALL_WORK
5303 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5304 and t0, t1, t0
5305 bnez t0, trace_a_syscall
5306 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5307 index ddcec1e..c7f983e 100644
5308 --- a/arch/mips/mm/fault.c
5309 +++ b/arch/mips/mm/fault.c
5310 @@ -27,6 +27,23 @@
5311 #include <asm/highmem.h> /* For VMALLOC_END */
5312 #include <linux/kdebug.h>
5313
5314 +#ifdef CONFIG_PAX_PAGEEXEC
5315 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5316 +{
5317 + unsigned long i;
5318 +
5319 + printk(KERN_ERR "PAX: bytes at PC: ");
5320 + for (i = 0; i < 5; i++) {
5321 + unsigned int c;
5322 + if (get_user(c, (unsigned int *)pc+i))
5323 + printk(KERN_CONT "???????? ");
5324 + else
5325 + printk(KERN_CONT "%08x ", c);
5326 + }
5327 + printk("\n");
5328 +}
5329 +#endif
5330 +
5331 /*
5332 * This routine handles page faults. It determines the address,
5333 * and the problem, and then passes it off to one of the appropriate
5334 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5335 index 7e5fe27..479a219 100644
5336 --- a/arch/mips/mm/mmap.c
5337 +++ b/arch/mips/mm/mmap.c
5338 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5339 struct vm_area_struct *vma;
5340 unsigned long addr = addr0;
5341 int do_color_align;
5342 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5343 struct vm_unmapped_area_info info;
5344
5345 if (unlikely(len > TASK_SIZE))
5346 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5347 do_color_align = 1;
5348
5349 /* requesting a specific address */
5350 +
5351 +#ifdef CONFIG_PAX_RANDMMAP
5352 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5353 +#endif
5354 +
5355 if (addr) {
5356 if (do_color_align)
5357 addr = COLOUR_ALIGN(addr, pgoff);
5358 @@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5359 addr = PAGE_ALIGN(addr);
5360
5361 vma = find_vma(mm, addr);
5362 - if (TASK_SIZE - len >= addr &&
5363 - (!vma || addr + len <= vma->vm_start))
5364 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5365 return addr;
5366 }
5367
5368 @@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5369 {
5370 unsigned long random_factor = 0UL;
5371
5372 +#ifdef CONFIG_PAX_RANDMMAP
5373 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5374 +#endif
5375 +
5376 if (current->flags & PF_RANDOMIZE) {
5377 random_factor = get_random_int();
5378 random_factor = random_factor << PAGE_SHIFT;
5379 @@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5380
5381 if (mmap_is_legacy()) {
5382 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5383 +
5384 +#ifdef CONFIG_PAX_RANDMMAP
5385 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5386 + mm->mmap_base += mm->delta_mmap;
5387 +#endif
5388 +
5389 mm->get_unmapped_area = arch_get_unmapped_area;
5390 mm->unmap_area = arch_unmap_area;
5391 } else {
5392 mm->mmap_base = mmap_base(random_factor);
5393 +
5394 +#ifdef CONFIG_PAX_RANDMMAP
5395 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5396 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5397 +#endif
5398 +
5399 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5400 mm->unmap_area = arch_unmap_area_topdown;
5401 }
5402 }
5403
5404 -static inline unsigned long brk_rnd(void)
5405 -{
5406 - unsigned long rnd = get_random_int();
5407 -
5408 - rnd = rnd << PAGE_SHIFT;
5409 - /* 8MB for 32bit, 256MB for 64bit */
5410 - if (TASK_IS_32BIT_ADDR)
5411 - rnd = rnd & 0x7ffffful;
5412 - else
5413 - rnd = rnd & 0xffffffful;
5414 -
5415 - return rnd;
5416 -}
5417 -
5418 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5419 -{
5420 - unsigned long base = mm->brk;
5421 - unsigned long ret;
5422 -
5423 - ret = PAGE_ALIGN(base + brk_rnd());
5424 -
5425 - if (ret < mm->brk)
5426 - return mm->brk;
5427 -
5428 - return ret;
5429 -}
5430 -
5431 int __virt_addr_valid(const volatile void *kaddr)
5432 {
5433 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5434 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5435 index 967d144..db12197 100644
5436 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5437 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5438 @@ -11,12 +11,14 @@
5439 #ifndef _ASM_PROC_CACHE_H
5440 #define _ASM_PROC_CACHE_H
5441
5442 +#include <linux/const.h>
5443 +
5444 /* L1 cache */
5445
5446 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5447 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5448 -#define L1_CACHE_BYTES 16 /* bytes per entry */
5449 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5450 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5451 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5452
5453 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5454 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5455 index bcb5df2..84fabd2 100644
5456 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5457 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5458 @@ -16,13 +16,15 @@
5459 #ifndef _ASM_PROC_CACHE_H
5460 #define _ASM_PROC_CACHE_H
5461
5462 +#include <linux/const.h>
5463 +
5464 /*
5465 * L1 cache
5466 */
5467 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5468 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5469 -#define L1_CACHE_BYTES 32 /* bytes per entry */
5470 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5471 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5472 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5473
5474 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5475 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5476 index 4ce7a01..449202a 100644
5477 --- a/arch/openrisc/include/asm/cache.h
5478 +++ b/arch/openrisc/include/asm/cache.h
5479 @@ -19,11 +19,13 @@
5480 #ifndef __ASM_OPENRISC_CACHE_H
5481 #define __ASM_OPENRISC_CACHE_H
5482
5483 +#include <linux/const.h>
5484 +
5485 /* FIXME: How can we replace these with values from the CPU...
5486 * they shouldn't be hard-coded!
5487 */
5488
5489 -#define L1_CACHE_BYTES 16
5490 #define L1_CACHE_SHIFT 4
5491 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5492
5493 #endif /* __ASM_OPENRISC_CACHE_H */
5494 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5495 index af9cf30..2aae9b2 100644
5496 --- a/arch/parisc/include/asm/atomic.h
5497 +++ b/arch/parisc/include/asm/atomic.h
5498 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5499
5500 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5501
5502 +#define atomic64_read_unchecked(v) atomic64_read(v)
5503 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5504 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5505 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5506 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5507 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5508 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5509 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5510 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5511 +
5512 #endif /* !CONFIG_64BIT */
5513
5514
5515 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5516 index 47f11c7..3420df2 100644
5517 --- a/arch/parisc/include/asm/cache.h
5518 +++ b/arch/parisc/include/asm/cache.h
5519 @@ -5,6 +5,7 @@
5520 #ifndef __ARCH_PARISC_CACHE_H
5521 #define __ARCH_PARISC_CACHE_H
5522
5523 +#include <linux/const.h>
5524
5525 /*
5526 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5527 @@ -15,13 +16,13 @@
5528 * just ruin performance.
5529 */
5530 #ifdef CONFIG_PA20
5531 -#define L1_CACHE_BYTES 64
5532 #define L1_CACHE_SHIFT 6
5533 #else
5534 -#define L1_CACHE_BYTES 32
5535 #define L1_CACHE_SHIFT 5
5536 #endif
5537
5538 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5539 +
5540 #ifndef __ASSEMBLY__
5541
5542 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5543 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5544 index 19f6cb1..6c78cf2 100644
5545 --- a/arch/parisc/include/asm/elf.h
5546 +++ b/arch/parisc/include/asm/elf.h
5547 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5548
5549 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5550
5551 +#ifdef CONFIG_PAX_ASLR
5552 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5553 +
5554 +#define PAX_DELTA_MMAP_LEN 16
5555 +#define PAX_DELTA_STACK_LEN 16
5556 +#endif
5557 +
5558 /* This yields a mask that user programs can use to figure out what
5559 instruction set this CPU supports. This could be done in user space,
5560 but it's not easy, and we've already done it here. */
5561 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5562 index fc987a1..6e068ef 100644
5563 --- a/arch/parisc/include/asm/pgalloc.h
5564 +++ b/arch/parisc/include/asm/pgalloc.h
5565 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5566 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5567 }
5568
5569 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5570 +{
5571 + pgd_populate(mm, pgd, pmd);
5572 +}
5573 +
5574 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5575 {
5576 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5577 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5578 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5579 #define pmd_free(mm, x) do { } while (0)
5580 #define pgd_populate(mm, pmd, pte) BUG()
5581 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
5582
5583 #endif
5584
5585 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5586 index 7df49fa..38b62bf 100644
5587 --- a/arch/parisc/include/asm/pgtable.h
5588 +++ b/arch/parisc/include/asm/pgtable.h
5589 @@ -218,6 +218,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5590 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5591 #define PAGE_COPY PAGE_EXECREAD
5592 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5593 +
5594 +#ifdef CONFIG_PAX_PAGEEXEC
5595 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5596 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5597 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5598 +#else
5599 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5600 +# define PAGE_COPY_NOEXEC PAGE_COPY
5601 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5602 +#endif
5603 +
5604 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5605 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5606 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5607 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5608 index 4ba2c93..f5e3974 100644
5609 --- a/arch/parisc/include/asm/uaccess.h
5610 +++ b/arch/parisc/include/asm/uaccess.h
5611 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5612 const void __user *from,
5613 unsigned long n)
5614 {
5615 - int sz = __compiletime_object_size(to);
5616 + size_t sz = __compiletime_object_size(to);
5617 int ret = -EFAULT;
5618
5619 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5620 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5621 ret = __copy_from_user(to, from, n);
5622 else
5623 copy_from_user_overflow();
5624 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5625 index 2a625fb..9908930 100644
5626 --- a/arch/parisc/kernel/module.c
5627 +++ b/arch/parisc/kernel/module.c
5628 @@ -98,16 +98,38 @@
5629
5630 /* three functions to determine where in the module core
5631 * or init pieces the location is */
5632 +static inline int in_init_rx(struct module *me, void *loc)
5633 +{
5634 + return (loc >= me->module_init_rx &&
5635 + loc < (me->module_init_rx + me->init_size_rx));
5636 +}
5637 +
5638 +static inline int in_init_rw(struct module *me, void *loc)
5639 +{
5640 + return (loc >= me->module_init_rw &&
5641 + loc < (me->module_init_rw + me->init_size_rw));
5642 +}
5643 +
5644 static inline int in_init(struct module *me, void *loc)
5645 {
5646 - return (loc >= me->module_init &&
5647 - loc <= (me->module_init + me->init_size));
5648 + return in_init_rx(me, loc) || in_init_rw(me, loc);
5649 +}
5650 +
5651 +static inline int in_core_rx(struct module *me, void *loc)
5652 +{
5653 + return (loc >= me->module_core_rx &&
5654 + loc < (me->module_core_rx + me->core_size_rx));
5655 +}
5656 +
5657 +static inline int in_core_rw(struct module *me, void *loc)
5658 +{
5659 + return (loc >= me->module_core_rw &&
5660 + loc < (me->module_core_rw + me->core_size_rw));
5661 }
5662
5663 static inline int in_core(struct module *me, void *loc)
5664 {
5665 - return (loc >= me->module_core &&
5666 - loc <= (me->module_core + me->core_size));
5667 + return in_core_rx(me, loc) || in_core_rw(me, loc);
5668 }
5669
5670 static inline int in_local(struct module *me, void *loc)
5671 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5672 }
5673
5674 /* align things a bit */
5675 - me->core_size = ALIGN(me->core_size, 16);
5676 - me->arch.got_offset = me->core_size;
5677 - me->core_size += gots * sizeof(struct got_entry);
5678 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
5679 + me->arch.got_offset = me->core_size_rw;
5680 + me->core_size_rw += gots * sizeof(struct got_entry);
5681
5682 - me->core_size = ALIGN(me->core_size, 16);
5683 - me->arch.fdesc_offset = me->core_size;
5684 - me->core_size += fdescs * sizeof(Elf_Fdesc);
5685 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
5686 + me->arch.fdesc_offset = me->core_size_rw;
5687 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5688
5689 me->arch.got_max = gots;
5690 me->arch.fdesc_max = fdescs;
5691 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5692
5693 BUG_ON(value == 0);
5694
5695 - got = me->module_core + me->arch.got_offset;
5696 + got = me->module_core_rw + me->arch.got_offset;
5697 for (i = 0; got[i].addr; i++)
5698 if (got[i].addr == value)
5699 goto out;
5700 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5701 #ifdef CONFIG_64BIT
5702 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5703 {
5704 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5705 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5706
5707 if (!value) {
5708 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5709 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5710
5711 /* Create new one */
5712 fdesc->addr = value;
5713 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5714 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5715 return (Elf_Addr)fdesc;
5716 }
5717 #endif /* CONFIG_64BIT */
5718 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5719
5720 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5721 end = table + sechdrs[me->arch.unwind_section].sh_size;
5722 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5723 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5724
5725 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5726 me->arch.unwind_section, table, end, gp);
5727 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5728 index f76c108..92bad82 100644
5729 --- a/arch/parisc/kernel/sys_parisc.c
5730 +++ b/arch/parisc/kernel/sys_parisc.c
5731 @@ -33,9 +33,11 @@
5732 #include <linux/utsname.h>
5733 #include <linux/personality.h>
5734
5735 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5736 +static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5737 + unsigned long flags)
5738 {
5739 struct vm_area_struct *vma;
5740 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5741
5742 addr = PAGE_ALIGN(addr);
5743
5744 @@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5745 /* At this point: (!vma || addr < vma->vm_end). */
5746 if (TASK_SIZE - len < addr)
5747 return -ENOMEM;
5748 - if (!vma || addr + len <= vma->vm_start)
5749 + if (check_heap_stack_gap(vma, addr, len, offset))
5750 return addr;
5751 addr = vma->vm_end;
5752 }
5753 @@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
5754 return offset & 0x3FF000;
5755 }
5756
5757 -static unsigned long get_shared_area(struct address_space *mapping,
5758 - unsigned long addr, unsigned long len, unsigned long pgoff)
5759 +static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5760 + unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5761 {
5762 struct vm_area_struct *vma;
5763 int offset = mapping ? get_offset(mapping) : 0;
5764 + unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5765
5766 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
5767
5768 @@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5769 /* At this point: (!vma || addr < vma->vm_end). */
5770 if (TASK_SIZE - len < addr)
5771 return -ENOMEM;
5772 - if (!vma || addr + len <= vma->vm_start)
5773 + if (check_heap_stack_gap(vma, addr, len, rand_offset))
5774 return addr;
5775 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
5776 if (addr < vma->vm_end) /* handle wraparound */
5777 @@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5778 if (flags & MAP_FIXED)
5779 return addr;
5780 if (!addr)
5781 - addr = TASK_UNMAPPED_BASE;
5782 + addr = current->mm->mmap_base;
5783
5784 if (filp) {
5785 - addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
5786 + addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
5787 } else if(flags & MAP_SHARED) {
5788 - addr = get_shared_area(NULL, addr, len, pgoff);
5789 + addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
5790 } else {
5791 - addr = get_unshared_area(addr, len);
5792 + addr = get_unshared_area(filp, addr, len, flags);
5793 }
5794 return addr;
5795 }
5796 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
5797 index 45ba99f..8e22c33 100644
5798 --- a/arch/parisc/kernel/traps.c
5799 +++ b/arch/parisc/kernel/traps.c
5800 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
5801
5802 down_read(&current->mm->mmap_sem);
5803 vma = find_vma(current->mm,regs->iaoq[0]);
5804 - if (vma && (regs->iaoq[0] >= vma->vm_start)
5805 - && (vma->vm_flags & VM_EXEC)) {
5806 -
5807 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
5808 fault_address = regs->iaoq[0];
5809 fault_space = regs->iasq[0];
5810
5811 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
5812 index 18162ce..94de376 100644
5813 --- a/arch/parisc/mm/fault.c
5814 +++ b/arch/parisc/mm/fault.c
5815 @@ -15,6 +15,7 @@
5816 #include <linux/sched.h>
5817 #include <linux/interrupt.h>
5818 #include <linux/module.h>
5819 +#include <linux/unistd.h>
5820
5821 #include <asm/uaccess.h>
5822 #include <asm/traps.h>
5823 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
5824 static unsigned long
5825 parisc_acctyp(unsigned long code, unsigned int inst)
5826 {
5827 - if (code == 6 || code == 16)
5828 + if (code == 6 || code == 7 || code == 16)
5829 return VM_EXEC;
5830
5831 switch (inst & 0xf0000000) {
5832 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
5833 }
5834 #endif
5835
5836 +#ifdef CONFIG_PAX_PAGEEXEC
5837 +/*
5838 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
5839 + *
5840 + * returns 1 when task should be killed
5841 + * 2 when rt_sigreturn trampoline was detected
5842 + * 3 when unpatched PLT trampoline was detected
5843 + */
5844 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5845 +{
5846 +
5847 +#ifdef CONFIG_PAX_EMUPLT
5848 + int err;
5849 +
5850 + do { /* PaX: unpatched PLT emulation */
5851 + unsigned int bl, depwi;
5852 +
5853 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
5854 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
5855 +
5856 + if (err)
5857 + break;
5858 +
5859 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
5860 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
5861 +
5862 + err = get_user(ldw, (unsigned int *)addr);
5863 + err |= get_user(bv, (unsigned int *)(addr+4));
5864 + err |= get_user(ldw2, (unsigned int *)(addr+8));
5865 +
5866 + if (err)
5867 + break;
5868 +
5869 + if (ldw == 0x0E801096U &&
5870 + bv == 0xEAC0C000U &&
5871 + ldw2 == 0x0E881095U)
5872 + {
5873 + unsigned int resolver, map;
5874 +
5875 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
5876 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
5877 + if (err)
5878 + break;
5879 +
5880 + regs->gr[20] = instruction_pointer(regs)+8;
5881 + regs->gr[21] = map;
5882 + regs->gr[22] = resolver;
5883 + regs->iaoq[0] = resolver | 3UL;
5884 + regs->iaoq[1] = regs->iaoq[0] + 4;
5885 + return 3;
5886 + }
5887 + }
5888 + } while (0);
5889 +#endif
5890 +
5891 +#ifdef CONFIG_PAX_EMUTRAMP
5892 +
5893 +#ifndef CONFIG_PAX_EMUSIGRT
5894 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
5895 + return 1;
5896 +#endif
5897 +
5898 + do { /* PaX: rt_sigreturn emulation */
5899 + unsigned int ldi1, ldi2, bel, nop;
5900 +
5901 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
5902 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
5903 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
5904 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
5905 +
5906 + if (err)
5907 + break;
5908 +
5909 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
5910 + ldi2 == 0x3414015AU &&
5911 + bel == 0xE4008200U &&
5912 + nop == 0x08000240U)
5913 + {
5914 + regs->gr[25] = (ldi1 & 2) >> 1;
5915 + regs->gr[20] = __NR_rt_sigreturn;
5916 + regs->gr[31] = regs->iaoq[1] + 16;
5917 + regs->sr[0] = regs->iasq[1];
5918 + regs->iaoq[0] = 0x100UL;
5919 + regs->iaoq[1] = regs->iaoq[0] + 4;
5920 + regs->iasq[0] = regs->sr[2];
5921 + regs->iasq[1] = regs->sr[2];
5922 + return 2;
5923 + }
5924 + } while (0);
5925 +#endif
5926 +
5927 + return 1;
5928 +}
5929 +
5930 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5931 +{
5932 + unsigned long i;
5933 +
5934 + printk(KERN_ERR "PAX: bytes at PC: ");
5935 + for (i = 0; i < 5; i++) {
5936 + unsigned int c;
5937 + if (get_user(c, (unsigned int *)pc+i))
5938 + printk(KERN_CONT "???????? ");
5939 + else
5940 + printk(KERN_CONT "%08x ", c);
5941 + }
5942 + printk("\n");
5943 +}
5944 +#endif
5945 +
5946 int fixup_exception(struct pt_regs *regs)
5947 {
5948 const struct exception_table_entry *fix;
5949 @@ -192,8 +303,33 @@ good_area:
5950
5951 acc_type = parisc_acctyp(code,regs->iir);
5952
5953 - if ((vma->vm_flags & acc_type) != acc_type)
5954 + if ((vma->vm_flags & acc_type) != acc_type) {
5955 +
5956 +#ifdef CONFIG_PAX_PAGEEXEC
5957 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
5958 + (address & ~3UL) == instruction_pointer(regs))
5959 + {
5960 + up_read(&mm->mmap_sem);
5961 + switch (pax_handle_fetch_fault(regs)) {
5962 +
5963 +#ifdef CONFIG_PAX_EMUPLT
5964 + case 3:
5965 + return;
5966 +#endif
5967 +
5968 +#ifdef CONFIG_PAX_EMUTRAMP
5969 + case 2:
5970 + return;
5971 +#endif
5972 +
5973 + }
5974 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
5975 + do_group_exit(SIGKILL);
5976 + }
5977 +#endif
5978 +
5979 goto bad_area;
5980 + }
5981
5982 /*
5983 * If for any reason at all we couldn't handle the fault, make
5984 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
5985 index e3b1d41..8e81edf 100644
5986 --- a/arch/powerpc/include/asm/atomic.h
5987 +++ b/arch/powerpc/include/asm/atomic.h
5988 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
5989 return t1;
5990 }
5991
5992 +#define atomic64_read_unchecked(v) atomic64_read(v)
5993 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5994 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5995 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5996 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5997 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5998 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5999 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
6000 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6001 +
6002 #endif /* __powerpc64__ */
6003
6004 #endif /* __KERNEL__ */
6005 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6006 index 9e495c9..b6878e5 100644
6007 --- a/arch/powerpc/include/asm/cache.h
6008 +++ b/arch/powerpc/include/asm/cache.h
6009 @@ -3,6 +3,7 @@
6010
6011 #ifdef __KERNEL__
6012
6013 +#include <linux/const.h>
6014
6015 /* bytes per L1 cache line */
6016 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6017 @@ -22,7 +23,7 @@
6018 #define L1_CACHE_SHIFT 7
6019 #endif
6020
6021 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6022 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6023
6024 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6025
6026 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6027 index 6abf0a1..459d0f1 100644
6028 --- a/arch/powerpc/include/asm/elf.h
6029 +++ b/arch/powerpc/include/asm/elf.h
6030 @@ -28,8 +28,19 @@
6031 the loader. We need to make sure that it is out of the way of the program
6032 that it will "exec", and that there is sufficient room for the brk. */
6033
6034 -extern unsigned long randomize_et_dyn(unsigned long base);
6035 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6036 +#define ELF_ET_DYN_BASE (0x20000000)
6037 +
6038 +#ifdef CONFIG_PAX_ASLR
6039 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6040 +
6041 +#ifdef __powerpc64__
6042 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6043 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6044 +#else
6045 +#define PAX_DELTA_MMAP_LEN 15
6046 +#define PAX_DELTA_STACK_LEN 15
6047 +#endif
6048 +#endif
6049
6050 /*
6051 * Our registers are always unsigned longs, whether we're a 32 bit
6052 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6053 (0x7ff >> (PAGE_SHIFT - 12)) : \
6054 (0x3ffff >> (PAGE_SHIFT - 12)))
6055
6056 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6057 -#define arch_randomize_brk arch_randomize_brk
6058 -
6059 -
6060 #ifdef CONFIG_SPU_BASE
6061 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6062 #define NT_SPU 1
6063 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6064 index 8196e9c..d83a9f3 100644
6065 --- a/arch/powerpc/include/asm/exec.h
6066 +++ b/arch/powerpc/include/asm/exec.h
6067 @@ -4,6 +4,6 @@
6068 #ifndef _ASM_POWERPC_EXEC_H
6069 #define _ASM_POWERPC_EXEC_H
6070
6071 -extern unsigned long arch_align_stack(unsigned long sp);
6072 +#define arch_align_stack(x) ((x) & ~0xfUL)
6073
6074 #endif /* _ASM_POWERPC_EXEC_H */
6075 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6076 index 5acabbd..7ea14fa 100644
6077 --- a/arch/powerpc/include/asm/kmap_types.h
6078 +++ b/arch/powerpc/include/asm/kmap_types.h
6079 @@ -10,7 +10,7 @@
6080 * 2 of the License, or (at your option) any later version.
6081 */
6082
6083 -#define KM_TYPE_NR 16
6084 +#define KM_TYPE_NR 17
6085
6086 #endif /* __KERNEL__ */
6087 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6088 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6089 index 8565c25..2865190 100644
6090 --- a/arch/powerpc/include/asm/mman.h
6091 +++ b/arch/powerpc/include/asm/mman.h
6092 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6093 }
6094 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6095
6096 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6097 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6098 {
6099 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6100 }
6101 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6102 index f072e97..b436dee 100644
6103 --- a/arch/powerpc/include/asm/page.h
6104 +++ b/arch/powerpc/include/asm/page.h
6105 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6106 * and needs to be executable. This means the whole heap ends
6107 * up being executable.
6108 */
6109 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6110 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6111 +#define VM_DATA_DEFAULT_FLAGS32 \
6112 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6113 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6114
6115 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6116 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6117 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6118 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6119 #endif
6120
6121 +#define ktla_ktva(addr) (addr)
6122 +#define ktva_ktla(addr) (addr)
6123 +
6124 /*
6125 * Use the top bit of the higher-level page table entries to indicate whether
6126 * the entries we point to contain hugepages. This works because we know that
6127 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6128 index cd915d6..c10cee8 100644
6129 --- a/arch/powerpc/include/asm/page_64.h
6130 +++ b/arch/powerpc/include/asm/page_64.h
6131 @@ -154,15 +154,18 @@ do { \
6132 * stack by default, so in the absence of a PT_GNU_STACK program header
6133 * we turn execute permission off.
6134 */
6135 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6136 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6137 +#define VM_STACK_DEFAULT_FLAGS32 \
6138 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6139 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6140
6141 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6142 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6143
6144 +#ifndef CONFIG_PAX_PAGEEXEC
6145 #define VM_STACK_DEFAULT_FLAGS \
6146 (is_32bit_task() ? \
6147 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6148 +#endif
6149
6150 #include <asm-generic/getorder.h>
6151
6152 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6153 index 292725c..f87ae14 100644
6154 --- a/arch/powerpc/include/asm/pgalloc-64.h
6155 +++ b/arch/powerpc/include/asm/pgalloc-64.h
6156 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6157 #ifndef CONFIG_PPC_64K_PAGES
6158
6159 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6160 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6161
6162 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6163 {
6164 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6165 pud_set(pud, (unsigned long)pmd);
6166 }
6167
6168 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6169 +{
6170 + pud_populate(mm, pud, pmd);
6171 +}
6172 +
6173 #define pmd_populate(mm, pmd, pte_page) \
6174 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6175 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6176 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6177 #else /* CONFIG_PPC_64K_PAGES */
6178
6179 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6180 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6181
6182 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6183 pte_t *pte)
6184 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6185 index a9cbd3b..3b67efa 100644
6186 --- a/arch/powerpc/include/asm/pgtable.h
6187 +++ b/arch/powerpc/include/asm/pgtable.h
6188 @@ -2,6 +2,7 @@
6189 #define _ASM_POWERPC_PGTABLE_H
6190 #ifdef __KERNEL__
6191
6192 +#include <linux/const.h>
6193 #ifndef __ASSEMBLY__
6194 #include <asm/processor.h> /* For TASK_SIZE */
6195 #include <asm/mmu.h>
6196 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6197 index 4aad413..85d86bf 100644
6198 --- a/arch/powerpc/include/asm/pte-hash32.h
6199 +++ b/arch/powerpc/include/asm/pte-hash32.h
6200 @@ -21,6 +21,7 @@
6201 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6202 #define _PAGE_USER 0x004 /* usermode access allowed */
6203 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6204 +#define _PAGE_EXEC _PAGE_GUARDED
6205 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6206 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6207 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6208 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6209 index 3d5c9dc..62f8414 100644
6210 --- a/arch/powerpc/include/asm/reg.h
6211 +++ b/arch/powerpc/include/asm/reg.h
6212 @@ -215,6 +215,7 @@
6213 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6214 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6215 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6216 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6217 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6218 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6219 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6220 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6221 index 406b7b9..af63426 100644
6222 --- a/arch/powerpc/include/asm/thread_info.h
6223 +++ b/arch/powerpc/include/asm/thread_info.h
6224 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6225 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6226 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6227 #define TIF_SINGLESTEP 8 /* singlestepping active */
6228 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6229 #define TIF_SECCOMP 10 /* secure computing */
6230 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6231 #define TIF_NOERROR 12 /* Force successful syscall return */
6232 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6233 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6234 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6235 for stack store? */
6236 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6237 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6238 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6239
6240 /* as above, but as bit values */
6241 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6242 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6243 #define _TIF_UPROBE (1<<TIF_UPROBE)
6244 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6245 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6246 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6247 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6248 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6249 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6250 + _TIF_GRSEC_SETXID)
6251
6252 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6253 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6254 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6255 index 4db4959..335e00c 100644
6256 --- a/arch/powerpc/include/asm/uaccess.h
6257 +++ b/arch/powerpc/include/asm/uaccess.h
6258 @@ -13,6 +13,8 @@
6259 #define VERIFY_READ 0
6260 #define VERIFY_WRITE 1
6261
6262 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
6263 +
6264 /*
6265 * The fs value determines whether argument validity checking should be
6266 * performed or not. If get_fs() == USER_DS, checking is performed, with
6267 @@ -318,52 +320,6 @@ do { \
6268 extern unsigned long __copy_tofrom_user(void __user *to,
6269 const void __user *from, unsigned long size);
6270
6271 -#ifndef __powerpc64__
6272 -
6273 -static inline unsigned long copy_from_user(void *to,
6274 - const void __user *from, unsigned long n)
6275 -{
6276 - unsigned long over;
6277 -
6278 - if (access_ok(VERIFY_READ, from, n))
6279 - return __copy_tofrom_user((__force void __user *)to, from, n);
6280 - if ((unsigned long)from < TASK_SIZE) {
6281 - over = (unsigned long)from + n - TASK_SIZE;
6282 - return __copy_tofrom_user((__force void __user *)to, from,
6283 - n - over) + over;
6284 - }
6285 - return n;
6286 -}
6287 -
6288 -static inline unsigned long copy_to_user(void __user *to,
6289 - const void *from, unsigned long n)
6290 -{
6291 - unsigned long over;
6292 -
6293 - if (access_ok(VERIFY_WRITE, to, n))
6294 - return __copy_tofrom_user(to, (__force void __user *)from, n);
6295 - if ((unsigned long)to < TASK_SIZE) {
6296 - over = (unsigned long)to + n - TASK_SIZE;
6297 - return __copy_tofrom_user(to, (__force void __user *)from,
6298 - n - over) + over;
6299 - }
6300 - return n;
6301 -}
6302 -
6303 -#else /* __powerpc64__ */
6304 -
6305 -#define __copy_in_user(to, from, size) \
6306 - __copy_tofrom_user((to), (from), (size))
6307 -
6308 -extern unsigned long copy_from_user(void *to, const void __user *from,
6309 - unsigned long n);
6310 -extern unsigned long copy_to_user(void __user *to, const void *from,
6311 - unsigned long n);
6312 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
6313 - unsigned long n);
6314 -
6315 -#endif /* __powerpc64__ */
6316 -
6317 static inline unsigned long __copy_from_user_inatomic(void *to,
6318 const void __user *from, unsigned long n)
6319 {
6320 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6321 if (ret == 0)
6322 return 0;
6323 }
6324 +
6325 + if (!__builtin_constant_p(n))
6326 + check_object_size(to, n, false);
6327 +
6328 return __copy_tofrom_user((__force void __user *)to, from, n);
6329 }
6330
6331 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6332 if (ret == 0)
6333 return 0;
6334 }
6335 +
6336 + if (!__builtin_constant_p(n))
6337 + check_object_size(from, n, true);
6338 +
6339 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6340 }
6341
6342 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6343 return __copy_to_user_inatomic(to, from, size);
6344 }
6345
6346 +#ifndef __powerpc64__
6347 +
6348 +static inline unsigned long __must_check copy_from_user(void *to,
6349 + const void __user *from, unsigned long n)
6350 +{
6351 + unsigned long over;
6352 +
6353 + if ((long)n < 0)
6354 + return n;
6355 +
6356 + if (access_ok(VERIFY_READ, from, n)) {
6357 + if (!__builtin_constant_p(n))
6358 + check_object_size(to, n, false);
6359 + return __copy_tofrom_user((__force void __user *)to, from, n);
6360 + }
6361 + if ((unsigned long)from < TASK_SIZE) {
6362 + over = (unsigned long)from + n - TASK_SIZE;
6363 + if (!__builtin_constant_p(n - over))
6364 + check_object_size(to, n - over, false);
6365 + return __copy_tofrom_user((__force void __user *)to, from,
6366 + n - over) + over;
6367 + }
6368 + return n;
6369 +}
6370 +
6371 +static inline unsigned long __must_check copy_to_user(void __user *to,
6372 + const void *from, unsigned long n)
6373 +{
6374 + unsigned long over;
6375 +
6376 + if ((long)n < 0)
6377 + return n;
6378 +
6379 + if (access_ok(VERIFY_WRITE, to, n)) {
6380 + if (!__builtin_constant_p(n))
6381 + check_object_size(from, n, true);
6382 + return __copy_tofrom_user(to, (__force void __user *)from, n);
6383 + }
6384 + if ((unsigned long)to < TASK_SIZE) {
6385 + over = (unsigned long)to + n - TASK_SIZE;
6386 + if (!__builtin_constant_p(n))
6387 + check_object_size(from, n - over, true);
6388 + return __copy_tofrom_user(to, (__force void __user *)from,
6389 + n - over) + over;
6390 + }
6391 + return n;
6392 +}
6393 +
6394 +#else /* __powerpc64__ */
6395 +
6396 +#define __copy_in_user(to, from, size) \
6397 + __copy_tofrom_user((to), (from), (size))
6398 +
6399 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6400 +{
6401 + if ((long)n < 0 || n > INT_MAX)
6402 + return n;
6403 +
6404 + if (!__builtin_constant_p(n))
6405 + check_object_size(to, n, false);
6406 +
6407 + if (likely(access_ok(VERIFY_READ, from, n)))
6408 + n = __copy_from_user(to, from, n);
6409 + else
6410 + memset(to, 0, n);
6411 + return n;
6412 +}
6413 +
6414 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6415 +{
6416 + if ((long)n < 0 || n > INT_MAX)
6417 + return n;
6418 +
6419 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
6420 + if (!__builtin_constant_p(n))
6421 + check_object_size(from, n, true);
6422 + n = __copy_to_user(to, from, n);
6423 + }
6424 + return n;
6425 +}
6426 +
6427 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
6428 + unsigned long n);
6429 +
6430 +#endif /* __powerpc64__ */
6431 +
6432 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6433
6434 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6435 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6436 index 4684e33..acc4d19e 100644
6437 --- a/arch/powerpc/kernel/exceptions-64e.S
6438 +++ b/arch/powerpc/kernel/exceptions-64e.S
6439 @@ -715,6 +715,7 @@ storage_fault_common:
6440 std r14,_DAR(r1)
6441 std r15,_DSISR(r1)
6442 addi r3,r1,STACK_FRAME_OVERHEAD
6443 + bl .save_nvgprs
6444 mr r4,r14
6445 mr r5,r15
6446 ld r14,PACA_EXGEN+EX_R14(r13)
6447 @@ -723,8 +724,7 @@ storage_fault_common:
6448 cmpdi r3,0
6449 bne- 1f
6450 b .ret_from_except_lite
6451 -1: bl .save_nvgprs
6452 - mr r5,r3
6453 +1: mr r5,r3
6454 addi r3,r1,STACK_FRAME_OVERHEAD
6455 ld r4,_DAR(r1)
6456 bl .bad_page_fault
6457 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6458 index 4665e82..080ea99 100644
6459 --- a/arch/powerpc/kernel/exceptions-64s.S
6460 +++ b/arch/powerpc/kernel/exceptions-64s.S
6461 @@ -1206,10 +1206,10 @@ handle_page_fault:
6462 11: ld r4,_DAR(r1)
6463 ld r5,_DSISR(r1)
6464 addi r3,r1,STACK_FRAME_OVERHEAD
6465 + bl .save_nvgprs
6466 bl .do_page_fault
6467 cmpdi r3,0
6468 beq+ 12f
6469 - bl .save_nvgprs
6470 mr r5,r3
6471 addi r3,r1,STACK_FRAME_OVERHEAD
6472 lwz r4,_DAR(r1)
6473 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6474 index 2e3200c..72095ce 100644
6475 --- a/arch/powerpc/kernel/module_32.c
6476 +++ b/arch/powerpc/kernel/module_32.c
6477 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6478 me->arch.core_plt_section = i;
6479 }
6480 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6481 - printk("Module doesn't contain .plt or .init.plt sections.\n");
6482 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6483 return -ENOEXEC;
6484 }
6485
6486 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6487
6488 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6489 /* Init, or core PLT? */
6490 - if (location >= mod->module_core
6491 - && location < mod->module_core + mod->core_size)
6492 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6493 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6494 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6495 - else
6496 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6497 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6498 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6499 + else {
6500 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6501 + return ~0UL;
6502 + }
6503
6504 /* Find this entry, or if that fails, the next avail. entry */
6505 while (entry->jump[0]) {
6506 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6507 index 8143067..21ae55b 100644
6508 --- a/arch/powerpc/kernel/process.c
6509 +++ b/arch/powerpc/kernel/process.c
6510 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6511 * Lookup NIP late so we have the best change of getting the
6512 * above info out without failing
6513 */
6514 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6515 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6516 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6517 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6518 #endif
6519 show_stack(current, (unsigned long *) regs->gpr[1]);
6520 if (!user_mode(regs))
6521 @@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6522 newsp = stack[0];
6523 ip = stack[STACK_FRAME_LR_SAVE];
6524 if (!firstframe || ip != lr) {
6525 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6526 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6527 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6528 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6529 - printk(" (%pS)",
6530 + printk(" (%pA)",
6531 (void *)current->ret_stack[curr_frame].ret);
6532 curr_frame--;
6533 }
6534 @@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6535 struct pt_regs *regs = (struct pt_regs *)
6536 (sp + STACK_FRAME_OVERHEAD);
6537 lr = regs->link;
6538 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
6539 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
6540 regs->trap, (void *)regs->nip, (void *)lr);
6541 firstframe = 1;
6542 }
6543 @@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
6544 mtspr(SPRN_CTRLT, ctrl);
6545 }
6546 #endif /* CONFIG_PPC64 */
6547 -
6548 -unsigned long arch_align_stack(unsigned long sp)
6549 -{
6550 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6551 - sp -= get_random_int() & ~PAGE_MASK;
6552 - return sp & ~0xf;
6553 -}
6554 -
6555 -static inline unsigned long brk_rnd(void)
6556 -{
6557 - unsigned long rnd = 0;
6558 -
6559 - /* 8MB for 32bit, 1GB for 64bit */
6560 - if (is_32bit_task())
6561 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6562 - else
6563 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6564 -
6565 - return rnd << PAGE_SHIFT;
6566 -}
6567 -
6568 -unsigned long arch_randomize_brk(struct mm_struct *mm)
6569 -{
6570 - unsigned long base = mm->brk;
6571 - unsigned long ret;
6572 -
6573 -#ifdef CONFIG_PPC_STD_MMU_64
6574 - /*
6575 - * If we are using 1TB segments and we are allowed to randomise
6576 - * the heap, we can put it above 1TB so it is backed by a 1TB
6577 - * segment. Otherwise the heap will be in the bottom 1TB
6578 - * which always uses 256MB segments and this may result in a
6579 - * performance penalty.
6580 - */
6581 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6582 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6583 -#endif
6584 -
6585 - ret = PAGE_ALIGN(base + brk_rnd());
6586 -
6587 - if (ret < mm->brk)
6588 - return mm->brk;
6589 -
6590 - return ret;
6591 -}
6592 -
6593 -unsigned long randomize_et_dyn(unsigned long base)
6594 -{
6595 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6596 -
6597 - if (ret < base)
6598 - return base;
6599 -
6600 - return ret;
6601 -}
6602 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6603 index c497000..8fde506 100644
6604 --- a/arch/powerpc/kernel/ptrace.c
6605 +++ b/arch/powerpc/kernel/ptrace.c
6606 @@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
6607 return ret;
6608 }
6609
6610 +#ifdef CONFIG_GRKERNSEC_SETXID
6611 +extern void gr_delayed_cred_worker(void);
6612 +#endif
6613 +
6614 /*
6615 * We must return the syscall number to actually look up in the table.
6616 * This can be -1L to skip running any syscall at all.
6617 @@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6618
6619 secure_computing_strict(regs->gpr[0]);
6620
6621 +#ifdef CONFIG_GRKERNSEC_SETXID
6622 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6623 + gr_delayed_cred_worker();
6624 +#endif
6625 +
6626 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6627 tracehook_report_syscall_entry(regs))
6628 /*
6629 @@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6630 {
6631 int step;
6632
6633 +#ifdef CONFIG_GRKERNSEC_SETXID
6634 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6635 + gr_delayed_cred_worker();
6636 +#endif
6637 +
6638 audit_syscall_exit(regs);
6639
6640 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6641 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6642 index 804e323..79181c1 100644
6643 --- a/arch/powerpc/kernel/signal_32.c
6644 +++ b/arch/powerpc/kernel/signal_32.c
6645 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6646 /* Save user registers on the stack */
6647 frame = &rt_sf->uc.uc_mcontext;
6648 addr = frame;
6649 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6650 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6651 if (save_user_regs(regs, frame, 0, 1))
6652 goto badframe;
6653 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6654 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6655 index 1ca045d..139c3f7 100644
6656 --- a/arch/powerpc/kernel/signal_64.c
6657 +++ b/arch/powerpc/kernel/signal_64.c
6658 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6659 current->thread.fpscr.val = 0;
6660
6661 /* Set up to return from userspace. */
6662 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6663 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6664 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6665 } else {
6666 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6667 diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6668 index 3ce1f86..c30e629 100644
6669 --- a/arch/powerpc/kernel/sysfs.c
6670 +++ b/arch/powerpc/kernel/sysfs.c
6671 @@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6672 return NOTIFY_OK;
6673 }
6674
6675 -static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6676 +static struct notifier_block sysfs_cpu_nb = {
6677 .notifier_call = sysfs_cpu_notify,
6678 };
6679
6680 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6681 index 3251840..3f7c77a 100644
6682 --- a/arch/powerpc/kernel/traps.c
6683 +++ b/arch/powerpc/kernel/traps.c
6684 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6685 return flags;
6686 }
6687
6688 +extern void gr_handle_kernel_exploit(void);
6689 +
6690 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6691 int signr)
6692 {
6693 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6694 panic("Fatal exception in interrupt");
6695 if (panic_on_oops)
6696 panic("Fatal exception");
6697 +
6698 + gr_handle_kernel_exploit();
6699 +
6700 do_exit(signr);
6701 }
6702
6703 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6704 index 1b2076f..835e4be 100644
6705 --- a/arch/powerpc/kernel/vdso.c
6706 +++ b/arch/powerpc/kernel/vdso.c
6707 @@ -34,6 +34,7 @@
6708 #include <asm/firmware.h>
6709 #include <asm/vdso.h>
6710 #include <asm/vdso_datapage.h>
6711 +#include <asm/mman.h>
6712
6713 #include "setup.h"
6714
6715 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6716 vdso_base = VDSO32_MBASE;
6717 #endif
6718
6719 - current->mm->context.vdso_base = 0;
6720 + current->mm->context.vdso_base = ~0UL;
6721
6722 /* vDSO has a problem and was disabled, just don't "enable" it for the
6723 * process
6724 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6725 vdso_base = get_unmapped_area(NULL, vdso_base,
6726 (vdso_pages << PAGE_SHIFT) +
6727 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6728 - 0, 0);
6729 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
6730 if (IS_ERR_VALUE(vdso_base)) {
6731 rc = vdso_base;
6732 goto fail_mmapsem;
6733 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6734 index 5eea6f3..5d10396 100644
6735 --- a/arch/powerpc/lib/usercopy_64.c
6736 +++ b/arch/powerpc/lib/usercopy_64.c
6737 @@ -9,22 +9,6 @@
6738 #include <linux/module.h>
6739 #include <asm/uaccess.h>
6740
6741 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6742 -{
6743 - if (likely(access_ok(VERIFY_READ, from, n)))
6744 - n = __copy_from_user(to, from, n);
6745 - else
6746 - memset(to, 0, n);
6747 - return n;
6748 -}
6749 -
6750 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6751 -{
6752 - if (likely(access_ok(VERIFY_WRITE, to, n)))
6753 - n = __copy_to_user(to, from, n);
6754 - return n;
6755 -}
6756 -
6757 unsigned long copy_in_user(void __user *to, const void __user *from,
6758 unsigned long n)
6759 {
6760 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6761 return n;
6762 }
6763
6764 -EXPORT_SYMBOL(copy_from_user);
6765 -EXPORT_SYMBOL(copy_to_user);
6766 EXPORT_SYMBOL(copy_in_user);
6767
6768 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6769 index 3a8489a..6a63b3b 100644
6770 --- a/arch/powerpc/mm/fault.c
6771 +++ b/arch/powerpc/mm/fault.c
6772 @@ -32,6 +32,10 @@
6773 #include <linux/perf_event.h>
6774 #include <linux/magic.h>
6775 #include <linux/ratelimit.h>
6776 +#include <linux/slab.h>
6777 +#include <linux/pagemap.h>
6778 +#include <linux/compiler.h>
6779 +#include <linux/unistd.h>
6780
6781 #include <asm/firmware.h>
6782 #include <asm/page.h>
6783 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6784 }
6785 #endif
6786
6787 +#ifdef CONFIG_PAX_PAGEEXEC
6788 +/*
6789 + * PaX: decide what to do with offenders (regs->nip = fault address)
6790 + *
6791 + * returns 1 when task should be killed
6792 + */
6793 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6794 +{
6795 + return 1;
6796 +}
6797 +
6798 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6799 +{
6800 + unsigned long i;
6801 +
6802 + printk(KERN_ERR "PAX: bytes at PC: ");
6803 + for (i = 0; i < 5; i++) {
6804 + unsigned int c;
6805 + if (get_user(c, (unsigned int __user *)pc+i))
6806 + printk(KERN_CONT "???????? ");
6807 + else
6808 + printk(KERN_CONT "%08x ", c);
6809 + }
6810 + printk("\n");
6811 +}
6812 +#endif
6813 +
6814 /*
6815 * Check whether the instruction at regs->nip is a store using
6816 * an update addressing form which will update r1.
6817 @@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
6818 * indicate errors in DSISR but can validly be set in SRR1.
6819 */
6820 if (trap == 0x400)
6821 - error_code &= 0x48200000;
6822 + error_code &= 0x58200000;
6823 else
6824 is_write = error_code & DSISR_ISSTORE;
6825 #else
6826 @@ -364,7 +395,7 @@ good_area:
6827 * "undefined". Of those that can be set, this is the only
6828 * one which seems bad.
6829 */
6830 - if (error_code & 0x10000000)
6831 + if (error_code & DSISR_GUARDED)
6832 /* Guarded storage error. */
6833 goto bad_area;
6834 #endif /* CONFIG_8xx */
6835 @@ -379,7 +410,7 @@ good_area:
6836 * processors use the same I/D cache coherency mechanism
6837 * as embedded.
6838 */
6839 - if (error_code & DSISR_PROTFAULT)
6840 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
6841 goto bad_area;
6842 #endif /* CONFIG_PPC_STD_MMU */
6843
6844 @@ -462,6 +493,23 @@ bad_area:
6845 bad_area_nosemaphore:
6846 /* User mode accesses cause a SIGSEGV */
6847 if (user_mode(regs)) {
6848 +
6849 +#ifdef CONFIG_PAX_PAGEEXEC
6850 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
6851 +#ifdef CONFIG_PPC_STD_MMU
6852 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
6853 +#else
6854 + if (is_exec && regs->nip == address) {
6855 +#endif
6856 + switch (pax_handle_fetch_fault(regs)) {
6857 + }
6858 +
6859 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
6860 + do_group_exit(SIGKILL);
6861 + }
6862 + }
6863 +#endif
6864 +
6865 _exception(SIGSEGV, regs, code, address);
6866 return 0;
6867 }
6868 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
6869 index 67a42ed..cd463e0 100644
6870 --- a/arch/powerpc/mm/mmap_64.c
6871 +++ b/arch/powerpc/mm/mmap_64.c
6872 @@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
6873 {
6874 unsigned long rnd = 0;
6875
6876 +#ifdef CONFIG_PAX_RANDMMAP
6877 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6878 +#endif
6879 +
6880 if (current->flags & PF_RANDOMIZE) {
6881 /* 8MB for 32bit, 1GB for 64bit */
6882 if (is_32bit_task())
6883 @@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6884 */
6885 if (mmap_is_legacy()) {
6886 mm->mmap_base = TASK_UNMAPPED_BASE;
6887 +
6888 +#ifdef CONFIG_PAX_RANDMMAP
6889 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6890 + mm->mmap_base += mm->delta_mmap;
6891 +#endif
6892 +
6893 mm->get_unmapped_area = arch_get_unmapped_area;
6894 mm->unmap_area = arch_unmap_area;
6895 } else {
6896 mm->mmap_base = mmap_base();
6897 +
6898 +#ifdef CONFIG_PAX_RANDMMAP
6899 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6900 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6901 +#endif
6902 +
6903 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6904 mm->unmap_area = arch_unmap_area_topdown;
6905 }
6906 diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
6907 index e779642..e5bb889 100644
6908 --- a/arch/powerpc/mm/mmu_context_nohash.c
6909 +++ b/arch/powerpc/mm/mmu_context_nohash.c
6910 @@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
6911 return NOTIFY_OK;
6912 }
6913
6914 -static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
6915 +static struct notifier_block mmu_context_cpu_nb = {
6916 .notifier_call = mmu_context_cpu_notify,
6917 };
6918
6919 diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
6920 index bba87ca..c346a33 100644
6921 --- a/arch/powerpc/mm/numa.c
6922 +++ b/arch/powerpc/mm/numa.c
6923 @@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
6924 return ret;
6925 }
6926
6927 -static struct notifier_block __cpuinitdata ppc64_numa_nb = {
6928 +static struct notifier_block ppc64_numa_nb = {
6929 .notifier_call = cpu_numa_callback,
6930 .priority = 1 /* Must run before sched domains notifier. */
6931 };
6932 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
6933 index cf9dada..241529f 100644
6934 --- a/arch/powerpc/mm/slice.c
6935 +++ b/arch/powerpc/mm/slice.c
6936 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
6937 if ((mm->task_size - len) < addr)
6938 return 0;
6939 vma = find_vma(mm, addr);
6940 - return (!vma || (addr + len) <= vma->vm_start);
6941 + return check_heap_stack_gap(vma, addr, len, 0);
6942 }
6943
6944 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
6945 @@ -272,7 +272,7 @@ full_search:
6946 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
6947 continue;
6948 }
6949 - if (!vma || addr + len <= vma->vm_start) {
6950 + if (check_heap_stack_gap(vma, addr, len, 0)) {
6951 /*
6952 * Remember the place where we stopped the search:
6953 */
6954 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6955 }
6956 }
6957
6958 - addr = mm->mmap_base;
6959 - while (addr > len) {
6960 + if (mm->mmap_base < len)
6961 + addr = -ENOMEM;
6962 + else
6963 + addr = mm->mmap_base - len;
6964 +
6965 + while (!IS_ERR_VALUE(addr)) {
6966 /* Go down by chunk size */
6967 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
6968 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
6969
6970 /* Check for hit with different page size */
6971 mask = slice_range_to_mask(addr, len);
6972 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6973 * return with success:
6974 */
6975 vma = find_vma(mm, addr);
6976 - if (!vma || (addr + len) <= vma->vm_start) {
6977 + if (check_heap_stack_gap(vma, addr, len, 0)) {
6978 /* remember the address as a hint for next time */
6979 if (use_cache)
6980 mm->free_area_cache = addr;
6981 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6982 mm->cached_hole_size = vma->vm_start - addr;
6983
6984 /* try just below the current vma->vm_start */
6985 - addr = vma->vm_start;
6986 + addr = skip_heap_stack_gap(vma, len, 0);
6987 }
6988
6989 /*
6990 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
6991 if (fixed && addr > (mm->task_size - len))
6992 return -EINVAL;
6993
6994 +#ifdef CONFIG_PAX_RANDMMAP
6995 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
6996 + addr = 0;
6997 +#endif
6998 +
6999 /* If hint, make sure it matches our alignment restrictions */
7000 if (!fixed && addr) {
7001 addr = _ALIGN_UP(addr, 1ul << pshift);
7002 diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7003 index bdb738a..49c9f95 100644
7004 --- a/arch/powerpc/platforms/powermac/smp.c
7005 +++ b/arch/powerpc/platforms/powermac/smp.c
7006 @@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7007 return NOTIFY_OK;
7008 }
7009
7010 -static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7011 +static struct notifier_block smp_core99_cpu_nb = {
7012 .notifier_call = smp_core99_cpu_notify,
7013 };
7014 #endif /* CONFIG_HOTPLUG_CPU */
7015 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7016 index c797832..ce575c8 100644
7017 --- a/arch/s390/include/asm/atomic.h
7018 +++ b/arch/s390/include/asm/atomic.h
7019 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7020 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7021 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7022
7023 +#define atomic64_read_unchecked(v) atomic64_read(v)
7024 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7025 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7026 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7027 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7028 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7029 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7030 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7031 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7032 +
7033 #define smp_mb__before_atomic_dec() smp_mb()
7034 #define smp_mb__after_atomic_dec() smp_mb()
7035 #define smp_mb__before_atomic_inc() smp_mb()
7036 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7037 index 4d7ccac..d03d0ad 100644
7038 --- a/arch/s390/include/asm/cache.h
7039 +++ b/arch/s390/include/asm/cache.h
7040 @@ -9,8 +9,10 @@
7041 #ifndef __ARCH_S390_CACHE_H
7042 #define __ARCH_S390_CACHE_H
7043
7044 -#define L1_CACHE_BYTES 256
7045 +#include <linux/const.h>
7046 +
7047 #define L1_CACHE_SHIFT 8
7048 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7049 #define NET_SKB_PAD 32
7050
7051 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7052 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7053 index 178ff96..8c93bd1 100644
7054 --- a/arch/s390/include/asm/elf.h
7055 +++ b/arch/s390/include/asm/elf.h
7056 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
7057 the loader. We need to make sure that it is out of the way of the program
7058 that it will "exec", and that there is sufficient room for the brk. */
7059
7060 -extern unsigned long randomize_et_dyn(unsigned long base);
7061 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7062 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7063 +
7064 +#ifdef CONFIG_PAX_ASLR
7065 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7066 +
7067 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7068 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7069 +#endif
7070
7071 /* This yields a mask that user programs can use to figure out what
7072 instruction set this CPU supports. */
7073 @@ -210,9 +216,6 @@ struct linux_binprm;
7074 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7075 int arch_setup_additional_pages(struct linux_binprm *, int);
7076
7077 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7078 -#define arch_randomize_brk arch_randomize_brk
7079 -
7080 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7081
7082 #endif
7083 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7084 index c4a93d6..4d2a9b4 100644
7085 --- a/arch/s390/include/asm/exec.h
7086 +++ b/arch/s390/include/asm/exec.h
7087 @@ -7,6 +7,6 @@
7088 #ifndef __ASM_EXEC_H
7089 #define __ASM_EXEC_H
7090
7091 -extern unsigned long arch_align_stack(unsigned long sp);
7092 +#define arch_align_stack(x) ((x) & ~0xfUL)
7093
7094 #endif /* __ASM_EXEC_H */
7095 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7096 index 34268df..ea97318 100644
7097 --- a/arch/s390/include/asm/uaccess.h
7098 +++ b/arch/s390/include/asm/uaccess.h
7099 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
7100 copy_to_user(void __user *to, const void *from, unsigned long n)
7101 {
7102 might_fault();
7103 +
7104 + if ((long)n < 0)
7105 + return n;
7106 +
7107 if (access_ok(VERIFY_WRITE, to, n))
7108 n = __copy_to_user(to, from, n);
7109 return n;
7110 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7111 static inline unsigned long __must_check
7112 __copy_from_user(void *to, const void __user *from, unsigned long n)
7113 {
7114 + if ((long)n < 0)
7115 + return n;
7116 +
7117 if (__builtin_constant_p(n) && (n <= 256))
7118 return uaccess.copy_from_user_small(n, from, to);
7119 else
7120 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7121 static inline unsigned long __must_check
7122 copy_from_user(void *to, const void __user *from, unsigned long n)
7123 {
7124 - unsigned int sz = __compiletime_object_size(to);
7125 + size_t sz = __compiletime_object_size(to);
7126
7127 might_fault();
7128 - if (unlikely(sz != -1 && sz < n)) {
7129 +
7130 + if ((long)n < 0)
7131 + return n;
7132 +
7133 + if (unlikely(sz != (size_t)-1 && sz < n)) {
7134 copy_from_user_overflow();
7135 return n;
7136 }
7137 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7138 index 4610dea..cf0af21 100644
7139 --- a/arch/s390/kernel/module.c
7140 +++ b/arch/s390/kernel/module.c
7141 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7142
7143 /* Increase core size by size of got & plt and set start
7144 offsets for got and plt. */
7145 - me->core_size = ALIGN(me->core_size, 4);
7146 - me->arch.got_offset = me->core_size;
7147 - me->core_size += me->arch.got_size;
7148 - me->arch.plt_offset = me->core_size;
7149 - me->core_size += me->arch.plt_size;
7150 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
7151 + me->arch.got_offset = me->core_size_rw;
7152 + me->core_size_rw += me->arch.got_size;
7153 + me->arch.plt_offset = me->core_size_rx;
7154 + me->core_size_rx += me->arch.plt_size;
7155 return 0;
7156 }
7157
7158 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7159 if (info->got_initialized == 0) {
7160 Elf_Addr *gotent;
7161
7162 - gotent = me->module_core + me->arch.got_offset +
7163 + gotent = me->module_core_rw + me->arch.got_offset +
7164 info->got_offset;
7165 *gotent = val;
7166 info->got_initialized = 1;
7167 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7168 else if (r_type == R_390_GOTENT ||
7169 r_type == R_390_GOTPLTENT)
7170 *(unsigned int *) loc =
7171 - (val + (Elf_Addr) me->module_core - loc) >> 1;
7172 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7173 else if (r_type == R_390_GOT64 ||
7174 r_type == R_390_GOTPLT64)
7175 *(unsigned long *) loc = val;
7176 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7177 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7178 if (info->plt_initialized == 0) {
7179 unsigned int *ip;
7180 - ip = me->module_core + me->arch.plt_offset +
7181 + ip = me->module_core_rx + me->arch.plt_offset +
7182 info->plt_offset;
7183 #ifndef CONFIG_64BIT
7184 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7185 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7186 val - loc + 0xffffUL < 0x1ffffeUL) ||
7187 (r_type == R_390_PLT32DBL &&
7188 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7189 - val = (Elf_Addr) me->module_core +
7190 + val = (Elf_Addr) me->module_core_rx +
7191 me->arch.plt_offset +
7192 info->plt_offset;
7193 val += rela->r_addend - loc;
7194 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7195 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7196 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7197 val = val + rela->r_addend -
7198 - ((Elf_Addr) me->module_core + me->arch.got_offset);
7199 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7200 if (r_type == R_390_GOTOFF16)
7201 *(unsigned short *) loc = val;
7202 else if (r_type == R_390_GOTOFF32)
7203 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7204 break;
7205 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7206 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7207 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
7208 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7209 rela->r_addend - loc;
7210 if (r_type == R_390_GOTPC)
7211 *(unsigned int *) loc = val;
7212 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7213 index 536d645..4a5bd9e 100644
7214 --- a/arch/s390/kernel/process.c
7215 +++ b/arch/s390/kernel/process.c
7216 @@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7217 }
7218 return 0;
7219 }
7220 -
7221 -unsigned long arch_align_stack(unsigned long sp)
7222 -{
7223 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7224 - sp -= get_random_int() & ~PAGE_MASK;
7225 - return sp & ~0xf;
7226 -}
7227 -
7228 -static inline unsigned long brk_rnd(void)
7229 -{
7230 - /* 8MB for 32bit, 1GB for 64bit */
7231 - if (is_32bit_task())
7232 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7233 - else
7234 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7235 -}
7236 -
7237 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7238 -{
7239 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7240 -
7241 - if (ret < mm->brk)
7242 - return mm->brk;
7243 - return ret;
7244 -}
7245 -
7246 -unsigned long randomize_et_dyn(unsigned long base)
7247 -{
7248 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7249 -
7250 - if (!(current->flags & PF_RANDOMIZE))
7251 - return base;
7252 - if (ret < base)
7253 - return base;
7254 - return ret;
7255 -}
7256 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7257 index c59a5ef..3fae59c 100644
7258 --- a/arch/s390/mm/mmap.c
7259 +++ b/arch/s390/mm/mmap.c
7260 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7261 */
7262 if (mmap_is_legacy()) {
7263 mm->mmap_base = TASK_UNMAPPED_BASE;
7264 +
7265 +#ifdef CONFIG_PAX_RANDMMAP
7266 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7267 + mm->mmap_base += mm->delta_mmap;
7268 +#endif
7269 +
7270 mm->get_unmapped_area = arch_get_unmapped_area;
7271 mm->unmap_area = arch_unmap_area;
7272 } else {
7273 mm->mmap_base = mmap_base();
7274 +
7275 +#ifdef CONFIG_PAX_RANDMMAP
7276 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7277 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7278 +#endif
7279 +
7280 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7281 mm->unmap_area = arch_unmap_area_topdown;
7282 }
7283 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7284 */
7285 if (mmap_is_legacy()) {
7286 mm->mmap_base = TASK_UNMAPPED_BASE;
7287 +
7288 +#ifdef CONFIG_PAX_RANDMMAP
7289 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7290 + mm->mmap_base += mm->delta_mmap;
7291 +#endif
7292 +
7293 mm->get_unmapped_area = s390_get_unmapped_area;
7294 mm->unmap_area = arch_unmap_area;
7295 } else {
7296 mm->mmap_base = mmap_base();
7297 +
7298 +#ifdef CONFIG_PAX_RANDMMAP
7299 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7300 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7301 +#endif
7302 +
7303 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7304 mm->unmap_area = arch_unmap_area_topdown;
7305 }
7306 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7307 index ae3d59f..f65f075 100644
7308 --- a/arch/score/include/asm/cache.h
7309 +++ b/arch/score/include/asm/cache.h
7310 @@ -1,7 +1,9 @@
7311 #ifndef _ASM_SCORE_CACHE_H
7312 #define _ASM_SCORE_CACHE_H
7313
7314 +#include <linux/const.h>
7315 +
7316 #define L1_CACHE_SHIFT 4
7317 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7318 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7319
7320 #endif /* _ASM_SCORE_CACHE_H */
7321 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7322 index f9f3cd5..58ff438 100644
7323 --- a/arch/score/include/asm/exec.h
7324 +++ b/arch/score/include/asm/exec.h
7325 @@ -1,6 +1,6 @@
7326 #ifndef _ASM_SCORE_EXEC_H
7327 #define _ASM_SCORE_EXEC_H
7328
7329 -extern unsigned long arch_align_stack(unsigned long sp);
7330 +#define arch_align_stack(x) (x)
7331
7332 #endif /* _ASM_SCORE_EXEC_H */
7333 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7334 index 7956846..5f37677 100644
7335 --- a/arch/score/kernel/process.c
7336 +++ b/arch/score/kernel/process.c
7337 @@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7338
7339 return task_pt_regs(task)->cp0_epc;
7340 }
7341 -
7342 -unsigned long arch_align_stack(unsigned long sp)
7343 -{
7344 - return sp;
7345 -}
7346 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7347 index ef9e555..331bd29 100644
7348 --- a/arch/sh/include/asm/cache.h
7349 +++ b/arch/sh/include/asm/cache.h
7350 @@ -9,10 +9,11 @@
7351 #define __ASM_SH_CACHE_H
7352 #ifdef __KERNEL__
7353
7354 +#include <linux/const.h>
7355 #include <linux/init.h>
7356 #include <cpu/cache.h>
7357
7358 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7359 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7360
7361 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7362
7363 diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7364 index 03f2b55..b027032 100644
7365 --- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7366 +++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7367 @@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7368 return NOTIFY_OK;
7369 }
7370
7371 -static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7372 +static struct notifier_block shx3_cpu_notifier = {
7373 .notifier_call = shx3_cpu_callback,
7374 };
7375
7376 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7377 index 6777177..cb5e44f 100644
7378 --- a/arch/sh/mm/mmap.c
7379 +++ b/arch/sh/mm/mmap.c
7380 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7381 struct mm_struct *mm = current->mm;
7382 struct vm_area_struct *vma;
7383 int do_colour_align;
7384 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7385 struct vm_unmapped_area_info info;
7386
7387 if (flags & MAP_FIXED) {
7388 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7389 if (filp || (flags & MAP_SHARED))
7390 do_colour_align = 1;
7391
7392 +#ifdef CONFIG_PAX_RANDMMAP
7393 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7394 +#endif
7395 +
7396 if (addr) {
7397 if (do_colour_align)
7398 addr = COLOUR_ALIGN(addr, pgoff);
7399 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7400 addr = PAGE_ALIGN(addr);
7401
7402 vma = find_vma(mm, addr);
7403 - if (TASK_SIZE - len >= addr &&
7404 - (!vma || addr + len <= vma->vm_start))
7405 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7406 return addr;
7407 }
7408
7409 info.flags = 0;
7410 info.length = len;
7411 - info.low_limit = TASK_UNMAPPED_BASE;
7412 + info.low_limit = mm->mmap_base;
7413 info.high_limit = TASK_SIZE;
7414 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7415 info.align_offset = pgoff << PAGE_SHIFT;
7416 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7417 struct mm_struct *mm = current->mm;
7418 unsigned long addr = addr0;
7419 int do_colour_align;
7420 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7421 struct vm_unmapped_area_info info;
7422
7423 if (flags & MAP_FIXED) {
7424 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7425 if (filp || (flags & MAP_SHARED))
7426 do_colour_align = 1;
7427
7428 +#ifdef CONFIG_PAX_RANDMMAP
7429 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7430 +#endif
7431 +
7432 /* requesting a specific address */
7433 if (addr) {
7434 if (do_colour_align)
7435 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7436 addr = PAGE_ALIGN(addr);
7437
7438 vma = find_vma(mm, addr);
7439 - if (TASK_SIZE - len >= addr &&
7440 - (!vma || addr + len <= vma->vm_start))
7441 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7442 return addr;
7443 }
7444
7445 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7446 VM_BUG_ON(addr != -ENOMEM);
7447 info.flags = 0;
7448 info.low_limit = TASK_UNMAPPED_BASE;
7449 +
7450 +#ifdef CONFIG_PAX_RANDMMAP
7451 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7452 + info.low_limit += mm->delta_mmap;
7453 +#endif
7454 +
7455 info.high_limit = TASK_SIZE;
7456 addr = vm_unmapped_area(&info);
7457 }
7458 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7459 index be56a24..443328f 100644
7460 --- a/arch/sparc/include/asm/atomic_64.h
7461 +++ b/arch/sparc/include/asm/atomic_64.h
7462 @@ -14,18 +14,40 @@
7463 #define ATOMIC64_INIT(i) { (i) }
7464
7465 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7466 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7467 +{
7468 + return v->counter;
7469 +}
7470 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7471 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7472 +{
7473 + return v->counter;
7474 +}
7475
7476 #define atomic_set(v, i) (((v)->counter) = i)
7477 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7478 +{
7479 + v->counter = i;
7480 +}
7481 #define atomic64_set(v, i) (((v)->counter) = i)
7482 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7483 +{
7484 + v->counter = i;
7485 +}
7486
7487 extern void atomic_add(int, atomic_t *);
7488 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7489 extern void atomic64_add(long, atomic64_t *);
7490 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7491 extern void atomic_sub(int, atomic_t *);
7492 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7493 extern void atomic64_sub(long, atomic64_t *);
7494 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7495
7496 extern int atomic_add_ret(int, atomic_t *);
7497 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7498 extern long atomic64_add_ret(long, atomic64_t *);
7499 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7500 extern int atomic_sub_ret(int, atomic_t *);
7501 extern long atomic64_sub_ret(long, atomic64_t *);
7502
7503 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7504 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7505
7506 #define atomic_inc_return(v) atomic_add_ret(1, v)
7507 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7508 +{
7509 + return atomic_add_ret_unchecked(1, v);
7510 +}
7511 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7512 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7513 +{
7514 + return atomic64_add_ret_unchecked(1, v);
7515 +}
7516
7517 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7518 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7519
7520 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7521 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7522 +{
7523 + return atomic_add_ret_unchecked(i, v);
7524 +}
7525 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7526 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7527 +{
7528 + return atomic64_add_ret_unchecked(i, v);
7529 +}
7530
7531 /*
7532 * atomic_inc_and_test - increment and test
7533 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7534 * other cases.
7535 */
7536 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7537 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7538 +{
7539 + return atomic_inc_return_unchecked(v) == 0;
7540 +}
7541 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7542
7543 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7544 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7545 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7546
7547 #define atomic_inc(v) atomic_add(1, v)
7548 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7549 +{
7550 + atomic_add_unchecked(1, v);
7551 +}
7552 #define atomic64_inc(v) atomic64_add(1, v)
7553 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7554 +{
7555 + atomic64_add_unchecked(1, v);
7556 +}
7557
7558 #define atomic_dec(v) atomic_sub(1, v)
7559 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7560 +{
7561 + atomic_sub_unchecked(1, v);
7562 +}
7563 #define atomic64_dec(v) atomic64_sub(1, v)
7564 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7565 +{
7566 + atomic64_sub_unchecked(1, v);
7567 +}
7568
7569 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7570 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7571
7572 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7573 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7574 +{
7575 + return cmpxchg(&v->counter, old, new);
7576 +}
7577 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7578 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7579 +{
7580 + return xchg(&v->counter, new);
7581 +}
7582
7583 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7584 {
7585 - int c, old;
7586 + int c, old, new;
7587 c = atomic_read(v);
7588 for (;;) {
7589 - if (unlikely(c == (u)))
7590 + if (unlikely(c == u))
7591 break;
7592 - old = atomic_cmpxchg((v), c, c + (a));
7593 +
7594 + asm volatile("addcc %2, %0, %0\n"
7595 +
7596 +#ifdef CONFIG_PAX_REFCOUNT
7597 + "tvs %%icc, 6\n"
7598 +#endif
7599 +
7600 + : "=r" (new)
7601 + : "0" (c), "ir" (a)
7602 + : "cc");
7603 +
7604 + old = atomic_cmpxchg(v, c, new);
7605 if (likely(old == c))
7606 break;
7607 c = old;
7608 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7609 #define atomic64_cmpxchg(v, o, n) \
7610 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7611 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7612 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7613 +{
7614 + return xchg(&v->counter, new);
7615 +}
7616
7617 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7618 {
7619 - long c, old;
7620 + long c, old, new;
7621 c = atomic64_read(v);
7622 for (;;) {
7623 - if (unlikely(c == (u)))
7624 + if (unlikely(c == u))
7625 break;
7626 - old = atomic64_cmpxchg((v), c, c + (a));
7627 +
7628 + asm volatile("addcc %2, %0, %0\n"
7629 +
7630 +#ifdef CONFIG_PAX_REFCOUNT
7631 + "tvs %%xcc, 6\n"
7632 +#endif
7633 +
7634 + : "=r" (new)
7635 + : "0" (c), "ir" (a)
7636 + : "cc");
7637 +
7638 + old = atomic64_cmpxchg(v, c, new);
7639 if (likely(old == c))
7640 break;
7641 c = old;
7642 }
7643 - return c != (u);
7644 + return c != u;
7645 }
7646
7647 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7648 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7649 index 5bb6991..5c2132e 100644
7650 --- a/arch/sparc/include/asm/cache.h
7651 +++ b/arch/sparc/include/asm/cache.h
7652 @@ -7,10 +7,12 @@
7653 #ifndef _SPARC_CACHE_H
7654 #define _SPARC_CACHE_H
7655
7656 +#include <linux/const.h>
7657 +
7658 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7659
7660 #define L1_CACHE_SHIFT 5
7661 -#define L1_CACHE_BYTES 32
7662 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7663
7664 #ifdef CONFIG_SPARC32
7665 #define SMP_CACHE_BYTES_SHIFT 5
7666 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7667 index ac74a2c..a9e58af 100644
7668 --- a/arch/sparc/include/asm/elf_32.h
7669 +++ b/arch/sparc/include/asm/elf_32.h
7670 @@ -114,6 +114,13 @@ typedef struct {
7671
7672 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7673
7674 +#ifdef CONFIG_PAX_ASLR
7675 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7676 +
7677 +#define PAX_DELTA_MMAP_LEN 16
7678 +#define PAX_DELTA_STACK_LEN 16
7679 +#endif
7680 +
7681 /* This yields a mask that user programs can use to figure out what
7682 instruction set this cpu supports. This can NOT be done in userspace
7683 on Sparc. */
7684 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7685 index 370ca1e..d4f4a98 100644
7686 --- a/arch/sparc/include/asm/elf_64.h
7687 +++ b/arch/sparc/include/asm/elf_64.h
7688 @@ -189,6 +189,13 @@ typedef struct {
7689 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7690 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7691
7692 +#ifdef CONFIG_PAX_ASLR
7693 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7694 +
7695 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7696 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7697 +#endif
7698 +
7699 extern unsigned long sparc64_elf_hwcap;
7700 #define ELF_HWCAP sparc64_elf_hwcap
7701
7702 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7703 index 9b1c36d..209298b 100644
7704 --- a/arch/sparc/include/asm/pgalloc_32.h
7705 +++ b/arch/sparc/include/asm/pgalloc_32.h
7706 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7707 }
7708
7709 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7710 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7711
7712 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7713 unsigned long address)
7714 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7715 index bcfe063..b333142 100644
7716 --- a/arch/sparc/include/asm/pgalloc_64.h
7717 +++ b/arch/sparc/include/asm/pgalloc_64.h
7718 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7719 }
7720
7721 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7722 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7723
7724 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7725 {
7726 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7727 index 6fc1348..390c50a 100644
7728 --- a/arch/sparc/include/asm/pgtable_32.h
7729 +++ b/arch/sparc/include/asm/pgtable_32.h
7730 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7731 #define PAGE_SHARED SRMMU_PAGE_SHARED
7732 #define PAGE_COPY SRMMU_PAGE_COPY
7733 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7734 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7735 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7736 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7737 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7738
7739 /* Top-level page directory - dummy used by init-mm.
7740 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7741
7742 /* xwr */
7743 #define __P000 PAGE_NONE
7744 -#define __P001 PAGE_READONLY
7745 -#define __P010 PAGE_COPY
7746 -#define __P011 PAGE_COPY
7747 +#define __P001 PAGE_READONLY_NOEXEC
7748 +#define __P010 PAGE_COPY_NOEXEC
7749 +#define __P011 PAGE_COPY_NOEXEC
7750 #define __P100 PAGE_READONLY
7751 #define __P101 PAGE_READONLY
7752 #define __P110 PAGE_COPY
7753 #define __P111 PAGE_COPY
7754
7755 #define __S000 PAGE_NONE
7756 -#define __S001 PAGE_READONLY
7757 -#define __S010 PAGE_SHARED
7758 -#define __S011 PAGE_SHARED
7759 +#define __S001 PAGE_READONLY_NOEXEC
7760 +#define __S010 PAGE_SHARED_NOEXEC
7761 +#define __S011 PAGE_SHARED_NOEXEC
7762 #define __S100 PAGE_READONLY
7763 #define __S101 PAGE_READONLY
7764 #define __S110 PAGE_SHARED
7765 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7766 index 79da178..c2eede8 100644
7767 --- a/arch/sparc/include/asm/pgtsrmmu.h
7768 +++ b/arch/sparc/include/asm/pgtsrmmu.h
7769 @@ -115,6 +115,11 @@
7770 SRMMU_EXEC | SRMMU_REF)
7771 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7772 SRMMU_EXEC | SRMMU_REF)
7773 +
7774 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7775 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7776 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7777 +
7778 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7779 SRMMU_DIRTY | SRMMU_REF)
7780
7781 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7782 index 9689176..63c18ea 100644
7783 --- a/arch/sparc/include/asm/spinlock_64.h
7784 +++ b/arch/sparc/include/asm/spinlock_64.h
7785 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7786
7787 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7788
7789 -static void inline arch_read_lock(arch_rwlock_t *lock)
7790 +static inline void arch_read_lock(arch_rwlock_t *lock)
7791 {
7792 unsigned long tmp1, tmp2;
7793
7794 __asm__ __volatile__ (
7795 "1: ldsw [%2], %0\n"
7796 " brlz,pn %0, 2f\n"
7797 -"4: add %0, 1, %1\n"
7798 +"4: addcc %0, 1, %1\n"
7799 +
7800 +#ifdef CONFIG_PAX_REFCOUNT
7801 +" tvs %%icc, 6\n"
7802 +#endif
7803 +
7804 " cas [%2], %0, %1\n"
7805 " cmp %0, %1\n"
7806 " bne,pn %%icc, 1b\n"
7807 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
7808 " .previous"
7809 : "=&r" (tmp1), "=&r" (tmp2)
7810 : "r" (lock)
7811 - : "memory");
7812 + : "memory", "cc");
7813 }
7814
7815 -static int inline arch_read_trylock(arch_rwlock_t *lock)
7816 +static inline int arch_read_trylock(arch_rwlock_t *lock)
7817 {
7818 int tmp1, tmp2;
7819
7820 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7821 "1: ldsw [%2], %0\n"
7822 " brlz,a,pn %0, 2f\n"
7823 " mov 0, %0\n"
7824 -" add %0, 1, %1\n"
7825 +" addcc %0, 1, %1\n"
7826 +
7827 +#ifdef CONFIG_PAX_REFCOUNT
7828 +" tvs %%icc, 6\n"
7829 +#endif
7830 +
7831 " cas [%2], %0, %1\n"
7832 " cmp %0, %1\n"
7833 " bne,pn %%icc, 1b\n"
7834 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7835 return tmp1;
7836 }
7837
7838 -static void inline arch_read_unlock(arch_rwlock_t *lock)
7839 +static inline void arch_read_unlock(arch_rwlock_t *lock)
7840 {
7841 unsigned long tmp1, tmp2;
7842
7843 __asm__ __volatile__(
7844 "1: lduw [%2], %0\n"
7845 -" sub %0, 1, %1\n"
7846 +" subcc %0, 1, %1\n"
7847 +
7848 +#ifdef CONFIG_PAX_REFCOUNT
7849 +" tvs %%icc, 6\n"
7850 +#endif
7851 +
7852 " cas [%2], %0, %1\n"
7853 " cmp %0, %1\n"
7854 " bne,pn %%xcc, 1b\n"
7855 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
7856 : "memory");
7857 }
7858
7859 -static void inline arch_write_lock(arch_rwlock_t *lock)
7860 +static inline void arch_write_lock(arch_rwlock_t *lock)
7861 {
7862 unsigned long mask, tmp1, tmp2;
7863
7864 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
7865 : "memory");
7866 }
7867
7868 -static void inline arch_write_unlock(arch_rwlock_t *lock)
7869 +static inline void arch_write_unlock(arch_rwlock_t *lock)
7870 {
7871 __asm__ __volatile__(
7872 " stw %%g0, [%0]"
7873 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
7874 : "memory");
7875 }
7876
7877 -static int inline arch_write_trylock(arch_rwlock_t *lock)
7878 +static inline int arch_write_trylock(arch_rwlock_t *lock)
7879 {
7880 unsigned long mask, tmp1, tmp2, result;
7881
7882 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
7883 index 25849ae..924c54b 100644
7884 --- a/arch/sparc/include/asm/thread_info_32.h
7885 +++ b/arch/sparc/include/asm/thread_info_32.h
7886 @@ -49,6 +49,8 @@ struct thread_info {
7887 unsigned long w_saved;
7888
7889 struct restart_block restart_block;
7890 +
7891 + unsigned long lowest_stack;
7892 };
7893
7894 /*
7895 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
7896 index 269bd92..e46a9b8 100644
7897 --- a/arch/sparc/include/asm/thread_info_64.h
7898 +++ b/arch/sparc/include/asm/thread_info_64.h
7899 @@ -63,6 +63,8 @@ struct thread_info {
7900 struct pt_regs *kern_una_regs;
7901 unsigned int kern_una_insn;
7902
7903 + unsigned long lowest_stack;
7904 +
7905 unsigned long fpregs[0] __attribute__ ((aligned(64)));
7906 };
7907
7908 @@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
7909 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
7910 /* flag bit 6 is available */
7911 #define TIF_32BIT 7 /* 32-bit binary */
7912 -/* flag bit 8 is available */
7913 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
7914 #define TIF_SECCOMP 9 /* secure computing */
7915 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
7916 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
7917 +
7918 /* NOTE: Thread flags >= 12 should be ones we have no interest
7919 * in using in assembly, else we can't use the mask as
7920 * an immediate value in instructions such as andcc.
7921 @@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
7922 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
7923 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7924 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
7925 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7926
7927 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
7928 _TIF_DO_NOTIFY_RESUME_MASK | \
7929 _TIF_NEED_RESCHED)
7930 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
7931
7932 +#define _TIF_WORK_SYSCALL \
7933 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
7934 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7935 +
7936 +
7937 /*
7938 * Thread-synchronous status.
7939 *
7940 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
7941 index 0167d26..9acd8ed 100644
7942 --- a/arch/sparc/include/asm/uaccess.h
7943 +++ b/arch/sparc/include/asm/uaccess.h
7944 @@ -1,5 +1,13 @@
7945 #ifndef ___ASM_SPARC_UACCESS_H
7946 #define ___ASM_SPARC_UACCESS_H
7947 +
7948 +#ifdef __KERNEL__
7949 +#ifndef __ASSEMBLY__
7950 +#include <linux/types.h>
7951 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
7952 +#endif
7953 +#endif
7954 +
7955 #if defined(__sparc__) && defined(__arch64__)
7956 #include <asm/uaccess_64.h>
7957 #else
7958 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
7959 index 53a28dd..50c38c3 100644
7960 --- a/arch/sparc/include/asm/uaccess_32.h
7961 +++ b/arch/sparc/include/asm/uaccess_32.h
7962 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
7963
7964 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
7965 {
7966 - if (n && __access_ok((unsigned long) to, n))
7967 + if ((long)n < 0)
7968 + return n;
7969 +
7970 + if (n && __access_ok((unsigned long) to, n)) {
7971 + if (!__builtin_constant_p(n))
7972 + check_object_size(from, n, true);
7973 return __copy_user(to, (__force void __user *) from, n);
7974 - else
7975 + } else
7976 return n;
7977 }
7978
7979 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
7980 {
7981 + if ((long)n < 0)
7982 + return n;
7983 +
7984 + if (!__builtin_constant_p(n))
7985 + check_object_size(from, n, true);
7986 +
7987 return __copy_user(to, (__force void __user *) from, n);
7988 }
7989
7990 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
7991 {
7992 - if (n && __access_ok((unsigned long) from, n))
7993 + if ((long)n < 0)
7994 + return n;
7995 +
7996 + if (n && __access_ok((unsigned long) from, n)) {
7997 + if (!__builtin_constant_p(n))
7998 + check_object_size(to, n, false);
7999 return __copy_user((__force void __user *) to, from, n);
8000 - else
8001 + } else
8002 return n;
8003 }
8004
8005 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8006 {
8007 + if ((long)n < 0)
8008 + return n;
8009 +
8010 return __copy_user((__force void __user *) to, from, n);
8011 }
8012
8013 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8014 index e562d3c..191f176 100644
8015 --- a/arch/sparc/include/asm/uaccess_64.h
8016 +++ b/arch/sparc/include/asm/uaccess_64.h
8017 @@ -10,6 +10,7 @@
8018 #include <linux/compiler.h>
8019 #include <linux/string.h>
8020 #include <linux/thread_info.h>
8021 +#include <linux/kernel.h>
8022 #include <asm/asi.h>
8023 #include <asm/spitfire.h>
8024 #include <asm-generic/uaccess-unaligned.h>
8025 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8026 static inline unsigned long __must_check
8027 copy_from_user(void *to, const void __user *from, unsigned long size)
8028 {
8029 - unsigned long ret = ___copy_from_user(to, from, size);
8030 + unsigned long ret;
8031
8032 + if ((long)size < 0 || size > INT_MAX)
8033 + return size;
8034 +
8035 + if (!__builtin_constant_p(size))
8036 + check_object_size(to, size, false);
8037 +
8038 + ret = ___copy_from_user(to, from, size);
8039 if (unlikely(ret))
8040 ret = copy_from_user_fixup(to, from, size);
8041
8042 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8043 static inline unsigned long __must_check
8044 copy_to_user(void __user *to, const void *from, unsigned long size)
8045 {
8046 - unsigned long ret = ___copy_to_user(to, from, size);
8047 + unsigned long ret;
8048
8049 + if ((long)size < 0 || size > INT_MAX)
8050 + return size;
8051 +
8052 + if (!__builtin_constant_p(size))
8053 + check_object_size(from, size, true);
8054 +
8055 + ret = ___copy_to_user(to, from, size);
8056 if (unlikely(ret))
8057 ret = copy_to_user_fixup(to, from, size);
8058 return ret;
8059 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8060 index 6cf591b..b49e65a 100644
8061 --- a/arch/sparc/kernel/Makefile
8062 +++ b/arch/sparc/kernel/Makefile
8063 @@ -3,7 +3,7 @@
8064 #
8065
8066 asflags-y := -ansi
8067 -ccflags-y := -Werror
8068 +#ccflags-y := -Werror
8069
8070 extra-y := head_$(BITS).o
8071
8072 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8073 index be8e862..5b50b12 100644
8074 --- a/arch/sparc/kernel/process_32.c
8075 +++ b/arch/sparc/kernel/process_32.c
8076 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
8077
8078 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8079 r->psr, r->pc, r->npc, r->y, print_tainted());
8080 - printk("PC: <%pS>\n", (void *) r->pc);
8081 + printk("PC: <%pA>\n", (void *) r->pc);
8082 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8083 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8084 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8085 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8086 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8087 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8088 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8089 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8090
8091 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8092 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8093 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8094 rw = (struct reg_window32 *) fp;
8095 pc = rw->ins[7];
8096 printk("[%08lx : ", pc);
8097 - printk("%pS ] ", (void *) pc);
8098 + printk("%pA ] ", (void *) pc);
8099 fp = rw->ins[6];
8100 } while (++count < 16);
8101 printk("\n");
8102 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8103 index cdb80b2..5ca141d 100644
8104 --- a/arch/sparc/kernel/process_64.c
8105 +++ b/arch/sparc/kernel/process_64.c
8106 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8107 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8108 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8109 if (regs->tstate & TSTATE_PRIV)
8110 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8111 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8112 }
8113
8114 void show_regs(struct pt_regs *regs)
8115 {
8116 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8117 regs->tpc, regs->tnpc, regs->y, print_tainted());
8118 - printk("TPC: <%pS>\n", (void *) regs->tpc);
8119 + printk("TPC: <%pA>\n", (void *) regs->tpc);
8120 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8121 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8122 regs->u_regs[3]);
8123 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8124 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8125 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8126 regs->u_regs[15]);
8127 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8128 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8129 show_regwindow(regs);
8130 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8131 }
8132 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8133 ((tp && tp->task) ? tp->task->pid : -1));
8134
8135 if (gp->tstate & TSTATE_PRIV) {
8136 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8137 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8138 (void *) gp->tpc,
8139 (void *) gp->o7,
8140 (void *) gp->i7,
8141 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8142 index 7ff45e4..a58f271 100644
8143 --- a/arch/sparc/kernel/ptrace_64.c
8144 +++ b/arch/sparc/kernel/ptrace_64.c
8145 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8146 return ret;
8147 }
8148
8149 +#ifdef CONFIG_GRKERNSEC_SETXID
8150 +extern void gr_delayed_cred_worker(void);
8151 +#endif
8152 +
8153 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8154 {
8155 int ret = 0;
8156 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8157 /* do the secure computing check first */
8158 secure_computing_strict(regs->u_regs[UREG_G1]);
8159
8160 +#ifdef CONFIG_GRKERNSEC_SETXID
8161 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8162 + gr_delayed_cred_worker();
8163 +#endif
8164 +
8165 if (test_thread_flag(TIF_SYSCALL_TRACE))
8166 ret = tracehook_report_syscall_entry(regs);
8167
8168 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8169
8170 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8171 {
8172 +#ifdef CONFIG_GRKERNSEC_SETXID
8173 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8174 + gr_delayed_cred_worker();
8175 +#endif
8176 +
8177 audit_syscall_exit(regs);
8178
8179 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8180 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8181 index 2da0bdc..79128d2 100644
8182 --- a/arch/sparc/kernel/sys_sparc_32.c
8183 +++ b/arch/sparc/kernel/sys_sparc_32.c
8184 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8185 if (len > TASK_SIZE - PAGE_SIZE)
8186 return -ENOMEM;
8187 if (!addr)
8188 - addr = TASK_UNMAPPED_BASE;
8189 + addr = current->mm->mmap_base;
8190
8191 info.flags = 0;
8192 info.length = len;
8193 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8194 index 708bc29..f0129cb 100644
8195 --- a/arch/sparc/kernel/sys_sparc_64.c
8196 +++ b/arch/sparc/kernel/sys_sparc_64.c
8197 @@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8198 struct vm_area_struct * vma;
8199 unsigned long task_size = TASK_SIZE;
8200 int do_color_align;
8201 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8202 struct vm_unmapped_area_info info;
8203
8204 if (flags & MAP_FIXED) {
8205 /* We do not accept a shared mapping if it would violate
8206 * cache aliasing constraints.
8207 */
8208 - if ((flags & MAP_SHARED) &&
8209 + if ((filp || (flags & MAP_SHARED)) &&
8210 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8211 return -EINVAL;
8212 return addr;
8213 @@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8214 if (filp || (flags & MAP_SHARED))
8215 do_color_align = 1;
8216
8217 +#ifdef CONFIG_PAX_RANDMMAP
8218 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8219 +#endif
8220 +
8221 if (addr) {
8222 if (do_color_align)
8223 addr = COLOR_ALIGN(addr, pgoff);
8224 @@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8225 addr = PAGE_ALIGN(addr);
8226
8227 vma = find_vma(mm, addr);
8228 - if (task_size - len >= addr &&
8229 - (!vma || addr + len <= vma->vm_start))
8230 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8231 return addr;
8232 }
8233
8234 info.flags = 0;
8235 info.length = len;
8236 - info.low_limit = TASK_UNMAPPED_BASE;
8237 + info.low_limit = mm->mmap_base;
8238 info.high_limit = min(task_size, VA_EXCLUDE_START);
8239 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8240 info.align_offset = pgoff << PAGE_SHIFT;
8241 @@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8242 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8243 VM_BUG_ON(addr != -ENOMEM);
8244 info.low_limit = VA_EXCLUDE_END;
8245 +
8246 +#ifdef CONFIG_PAX_RANDMMAP
8247 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8248 + info.low_limit += mm->delta_mmap;
8249 +#endif
8250 +
8251 info.high_limit = task_size;
8252 addr = vm_unmapped_area(&info);
8253 }
8254 @@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8255 unsigned long task_size = STACK_TOP32;
8256 unsigned long addr = addr0;
8257 int do_color_align;
8258 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8259 struct vm_unmapped_area_info info;
8260
8261 /* This should only ever run for 32-bit processes. */
8262 @@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8263 /* We do not accept a shared mapping if it would violate
8264 * cache aliasing constraints.
8265 */
8266 - if ((flags & MAP_SHARED) &&
8267 + if ((filp || (flags & MAP_SHARED)) &&
8268 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8269 return -EINVAL;
8270 return addr;
8271 @@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8272 if (filp || (flags & MAP_SHARED))
8273 do_color_align = 1;
8274
8275 +#ifdef CONFIG_PAX_RANDMMAP
8276 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8277 +#endif
8278 +
8279 /* requesting a specific address */
8280 if (addr) {
8281 if (do_color_align)
8282 @@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8283 addr = PAGE_ALIGN(addr);
8284
8285 vma = find_vma(mm, addr);
8286 - if (task_size - len >= addr &&
8287 - (!vma || addr + len <= vma->vm_start))
8288 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8289 return addr;
8290 }
8291
8292 @@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8293 VM_BUG_ON(addr != -ENOMEM);
8294 info.flags = 0;
8295 info.low_limit = TASK_UNMAPPED_BASE;
8296 +
8297 +#ifdef CONFIG_PAX_RANDMMAP
8298 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8299 + info.low_limit += mm->delta_mmap;
8300 +#endif
8301 +
8302 info.high_limit = STACK_TOP32;
8303 addr = vm_unmapped_area(&info);
8304 }
8305 @@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8306 {
8307 unsigned long rnd = 0UL;
8308
8309 +#ifdef CONFIG_PAX_RANDMMAP
8310 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8311 +#endif
8312 +
8313 if (current->flags & PF_RANDOMIZE) {
8314 unsigned long val = get_random_int();
8315 if (test_thread_flag(TIF_32BIT))
8316 @@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8317 gap == RLIM_INFINITY ||
8318 sysctl_legacy_va_layout) {
8319 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8320 +
8321 +#ifdef CONFIG_PAX_RANDMMAP
8322 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8323 + mm->mmap_base += mm->delta_mmap;
8324 +#endif
8325 +
8326 mm->get_unmapped_area = arch_get_unmapped_area;
8327 mm->unmap_area = arch_unmap_area;
8328 } else {
8329 @@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8330 gap = (task_size / 6 * 5);
8331
8332 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8333 +
8334 +#ifdef CONFIG_PAX_RANDMMAP
8335 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8336 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8337 +#endif
8338 +
8339 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8340 mm->unmap_area = arch_unmap_area_topdown;
8341 }
8342 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8343 index e0fed77..604a7e5 100644
8344 --- a/arch/sparc/kernel/syscalls.S
8345 +++ b/arch/sparc/kernel/syscalls.S
8346 @@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8347 #endif
8348 .align 32
8349 1: ldx [%g6 + TI_FLAGS], %l5
8350 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8351 + andcc %l5, _TIF_WORK_SYSCALL, %g0
8352 be,pt %icc, rtrap
8353 nop
8354 call syscall_trace_leave
8355 @@ -190,7 +190,7 @@ linux_sparc_syscall32:
8356
8357 srl %i5, 0, %o5 ! IEU1
8358 srl %i2, 0, %o2 ! IEU0 Group
8359 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8360 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8361 bne,pn %icc, linux_syscall_trace32 ! CTI
8362 mov %i0, %l5 ! IEU1
8363 call %l7 ! CTI Group brk forced
8364 @@ -213,7 +213,7 @@ linux_sparc_syscall:
8365
8366 mov %i3, %o3 ! IEU1
8367 mov %i4, %o4 ! IEU0 Group
8368 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8369 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8370 bne,pn %icc, linux_syscall_trace ! CTI Group
8371 mov %i0, %l5 ! IEU0
8372 2: call %l7 ! CTI Group brk forced
8373 @@ -229,7 +229,7 @@ ret_sys_call:
8374
8375 cmp %o0, -ERESTART_RESTARTBLOCK
8376 bgeu,pn %xcc, 1f
8377 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8378 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8379 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8380
8381 2:
8382 diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8383 index 654e8aa..45f431b 100644
8384 --- a/arch/sparc/kernel/sysfs.c
8385 +++ b/arch/sparc/kernel/sysfs.c
8386 @@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8387 return NOTIFY_OK;
8388 }
8389
8390 -static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8391 +static struct notifier_block sysfs_cpu_nb = {
8392 .notifier_call = sysfs_cpu_notify,
8393 };
8394
8395 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8396 index a5785ea..405c5f7 100644
8397 --- a/arch/sparc/kernel/traps_32.c
8398 +++ b/arch/sparc/kernel/traps_32.c
8399 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8400 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8401 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8402
8403 +extern void gr_handle_kernel_exploit(void);
8404 +
8405 void die_if_kernel(char *str, struct pt_regs *regs)
8406 {
8407 static int die_counter;
8408 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8409 count++ < 30 &&
8410 (((unsigned long) rw) >= PAGE_OFFSET) &&
8411 !(((unsigned long) rw) & 0x7)) {
8412 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
8413 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
8414 (void *) rw->ins[7]);
8415 rw = (struct reg_window32 *)rw->ins[6];
8416 }
8417 }
8418 printk("Instruction DUMP:");
8419 instruction_dump ((unsigned long *) regs->pc);
8420 - if(regs->psr & PSR_PS)
8421 + if(regs->psr & PSR_PS) {
8422 + gr_handle_kernel_exploit();
8423 do_exit(SIGKILL);
8424 + }
8425 do_exit(SIGSEGV);
8426 }
8427
8428 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8429 index e7ecf15..6520e65 100644
8430 --- a/arch/sparc/kernel/traps_64.c
8431 +++ b/arch/sparc/kernel/traps_64.c
8432 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8433 i + 1,
8434 p->trapstack[i].tstate, p->trapstack[i].tpc,
8435 p->trapstack[i].tnpc, p->trapstack[i].tt);
8436 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8437 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8438 }
8439 }
8440
8441 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8442
8443 lvl -= 0x100;
8444 if (regs->tstate & TSTATE_PRIV) {
8445 +
8446 +#ifdef CONFIG_PAX_REFCOUNT
8447 + if (lvl == 6)
8448 + pax_report_refcount_overflow(regs);
8449 +#endif
8450 +
8451 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8452 die_if_kernel(buffer, regs);
8453 }
8454 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8455 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8456 {
8457 char buffer[32];
8458 -
8459 +
8460 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8461 0, lvl, SIGTRAP) == NOTIFY_STOP)
8462 return;
8463
8464 +#ifdef CONFIG_PAX_REFCOUNT
8465 + if (lvl == 6)
8466 + pax_report_refcount_overflow(regs);
8467 +#endif
8468 +
8469 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8470
8471 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8472 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8473 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8474 printk("%s" "ERROR(%d): ",
8475 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8476 - printk("TPC<%pS>\n", (void *) regs->tpc);
8477 + printk("TPC<%pA>\n", (void *) regs->tpc);
8478 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8479 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8480 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8481 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8482 smp_processor_id(),
8483 (type & 0x1) ? 'I' : 'D',
8484 regs->tpc);
8485 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8486 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8487 panic("Irrecoverable Cheetah+ parity error.");
8488 }
8489
8490 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8491 smp_processor_id(),
8492 (type & 0x1) ? 'I' : 'D',
8493 regs->tpc);
8494 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8495 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8496 }
8497
8498 struct sun4v_error_entry {
8499 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8500
8501 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8502 regs->tpc, tl);
8503 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8504 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8505 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8506 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8507 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8508 (void *) regs->u_regs[UREG_I7]);
8509 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8510 "pte[%lx] error[%lx]\n",
8511 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8512
8513 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8514 regs->tpc, tl);
8515 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8516 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8517 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8518 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8519 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8520 (void *) regs->u_regs[UREG_I7]);
8521 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8522 "pte[%lx] error[%lx]\n",
8523 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8524 fp = (unsigned long)sf->fp + STACK_BIAS;
8525 }
8526
8527 - printk(" [%016lx] %pS\n", pc, (void *) pc);
8528 + printk(" [%016lx] %pA\n", pc, (void *) pc);
8529 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8530 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8531 int index = tsk->curr_ret_stack;
8532 if (tsk->ret_stack && index >= graph) {
8533 pc = tsk->ret_stack[index - graph].ret;
8534 - printk(" [%016lx] %pS\n", pc, (void *) pc);
8535 + printk(" [%016lx] %pA\n", pc, (void *) pc);
8536 graph++;
8537 }
8538 }
8539 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8540 return (struct reg_window *) (fp + STACK_BIAS);
8541 }
8542
8543 +extern void gr_handle_kernel_exploit(void);
8544 +
8545 void die_if_kernel(char *str, struct pt_regs *regs)
8546 {
8547 static int die_counter;
8548 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8549 while (rw &&
8550 count++ < 30 &&
8551 kstack_valid(tp, (unsigned long) rw)) {
8552 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
8553 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
8554 (void *) rw->ins[7]);
8555
8556 rw = kernel_stack_up(rw);
8557 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8558 }
8559 user_instruction_dump ((unsigned int __user *) regs->tpc);
8560 }
8561 - if (regs->tstate & TSTATE_PRIV)
8562 + if (regs->tstate & TSTATE_PRIV) {
8563 + gr_handle_kernel_exploit();
8564 do_exit(SIGKILL);
8565 + }
8566 do_exit(SIGSEGV);
8567 }
8568 EXPORT_SYMBOL(die_if_kernel);
8569 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8570 index 8201c25e..072a2a7 100644
8571 --- a/arch/sparc/kernel/unaligned_64.c
8572 +++ b/arch/sparc/kernel/unaligned_64.c
8573 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8574 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8575
8576 if (__ratelimit(&ratelimit)) {
8577 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
8578 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
8579 regs->tpc, (void *) regs->tpc);
8580 }
8581 }
8582 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8583 index 8410065f2..4fd4ca22 100644
8584 --- a/arch/sparc/lib/Makefile
8585 +++ b/arch/sparc/lib/Makefile
8586 @@ -2,7 +2,7 @@
8587 #
8588
8589 asflags-y := -ansi -DST_DIV0=0x02
8590 -ccflags-y := -Werror
8591 +#ccflags-y := -Werror
8592
8593 lib-$(CONFIG_SPARC32) += ashrdi3.o
8594 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8595 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8596 index 85c233d..68500e0 100644
8597 --- a/arch/sparc/lib/atomic_64.S
8598 +++ b/arch/sparc/lib/atomic_64.S
8599 @@ -17,7 +17,12 @@
8600 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8601 BACKOFF_SETUP(%o2)
8602 1: lduw [%o1], %g1
8603 - add %g1, %o0, %g7
8604 + addcc %g1, %o0, %g7
8605 +
8606 +#ifdef CONFIG_PAX_REFCOUNT
8607 + tvs %icc, 6
8608 +#endif
8609 +
8610 cas [%o1], %g1, %g7
8611 cmp %g1, %g7
8612 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8613 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8614 2: BACKOFF_SPIN(%o2, %o3, 1b)
8615 ENDPROC(atomic_add)
8616
8617 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8618 + BACKOFF_SETUP(%o2)
8619 +1: lduw [%o1], %g1
8620 + add %g1, %o0, %g7
8621 + cas [%o1], %g1, %g7
8622 + cmp %g1, %g7
8623 + bne,pn %icc, 2f
8624 + nop
8625 + retl
8626 + nop
8627 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8628 +ENDPROC(atomic_add_unchecked)
8629 +
8630 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8631 BACKOFF_SETUP(%o2)
8632 1: lduw [%o1], %g1
8633 - sub %g1, %o0, %g7
8634 + subcc %g1, %o0, %g7
8635 +
8636 +#ifdef CONFIG_PAX_REFCOUNT
8637 + tvs %icc, 6
8638 +#endif
8639 +
8640 cas [%o1], %g1, %g7
8641 cmp %g1, %g7
8642 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8643 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8644 2: BACKOFF_SPIN(%o2, %o3, 1b)
8645 ENDPROC(atomic_sub)
8646
8647 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8648 + BACKOFF_SETUP(%o2)
8649 +1: lduw [%o1], %g1
8650 + sub %g1, %o0, %g7
8651 + cas [%o1], %g1, %g7
8652 + cmp %g1, %g7
8653 + bne,pn %icc, 2f
8654 + nop
8655 + retl
8656 + nop
8657 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8658 +ENDPROC(atomic_sub_unchecked)
8659 +
8660 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8661 BACKOFF_SETUP(%o2)
8662 1: lduw [%o1], %g1
8663 - add %g1, %o0, %g7
8664 + addcc %g1, %o0, %g7
8665 +
8666 +#ifdef CONFIG_PAX_REFCOUNT
8667 + tvs %icc, 6
8668 +#endif
8669 +
8670 cas [%o1], %g1, %g7
8671 cmp %g1, %g7
8672 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8673 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8674 2: BACKOFF_SPIN(%o2, %o3, 1b)
8675 ENDPROC(atomic_add_ret)
8676
8677 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8678 + BACKOFF_SETUP(%o2)
8679 +1: lduw [%o1], %g1
8680 + addcc %g1, %o0, %g7
8681 + cas [%o1], %g1, %g7
8682 + cmp %g1, %g7
8683 + bne,pn %icc, 2f
8684 + add %g7, %o0, %g7
8685 + sra %g7, 0, %o0
8686 + retl
8687 + nop
8688 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8689 +ENDPROC(atomic_add_ret_unchecked)
8690 +
8691 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8692 BACKOFF_SETUP(%o2)
8693 1: lduw [%o1], %g1
8694 - sub %g1, %o0, %g7
8695 + subcc %g1, %o0, %g7
8696 +
8697 +#ifdef CONFIG_PAX_REFCOUNT
8698 + tvs %icc, 6
8699 +#endif
8700 +
8701 cas [%o1], %g1, %g7
8702 cmp %g1, %g7
8703 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8704 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8705 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8706 BACKOFF_SETUP(%o2)
8707 1: ldx [%o1], %g1
8708 - add %g1, %o0, %g7
8709 + addcc %g1, %o0, %g7
8710 +
8711 +#ifdef CONFIG_PAX_REFCOUNT
8712 + tvs %xcc, 6
8713 +#endif
8714 +
8715 casx [%o1], %g1, %g7
8716 cmp %g1, %g7
8717 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8718 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8719 2: BACKOFF_SPIN(%o2, %o3, 1b)
8720 ENDPROC(atomic64_add)
8721
8722 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8723 + BACKOFF_SETUP(%o2)
8724 +1: ldx [%o1], %g1
8725 + addcc %g1, %o0, %g7
8726 + casx [%o1], %g1, %g7
8727 + cmp %g1, %g7
8728 + bne,pn %xcc, 2f
8729 + nop
8730 + retl
8731 + nop
8732 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8733 +ENDPROC(atomic64_add_unchecked)
8734 +
8735 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8736 BACKOFF_SETUP(%o2)
8737 1: ldx [%o1], %g1
8738 - sub %g1, %o0, %g7
8739 + subcc %g1, %o0, %g7
8740 +
8741 +#ifdef CONFIG_PAX_REFCOUNT
8742 + tvs %xcc, 6
8743 +#endif
8744 +
8745 casx [%o1], %g1, %g7
8746 cmp %g1, %g7
8747 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8748 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8749 2: BACKOFF_SPIN(%o2, %o3, 1b)
8750 ENDPROC(atomic64_sub)
8751
8752 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8753 + BACKOFF_SETUP(%o2)
8754 +1: ldx [%o1], %g1
8755 + subcc %g1, %o0, %g7
8756 + casx [%o1], %g1, %g7
8757 + cmp %g1, %g7
8758 + bne,pn %xcc, 2f
8759 + nop
8760 + retl
8761 + nop
8762 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8763 +ENDPROC(atomic64_sub_unchecked)
8764 +
8765 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8766 BACKOFF_SETUP(%o2)
8767 1: ldx [%o1], %g1
8768 - add %g1, %o0, %g7
8769 + addcc %g1, %o0, %g7
8770 +
8771 +#ifdef CONFIG_PAX_REFCOUNT
8772 + tvs %xcc, 6
8773 +#endif
8774 +
8775 casx [%o1], %g1, %g7
8776 cmp %g1, %g7
8777 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8778 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8779 2: BACKOFF_SPIN(%o2, %o3, 1b)
8780 ENDPROC(atomic64_add_ret)
8781
8782 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8783 + BACKOFF_SETUP(%o2)
8784 +1: ldx [%o1], %g1
8785 + addcc %g1, %o0, %g7
8786 + casx [%o1], %g1, %g7
8787 + cmp %g1, %g7
8788 + bne,pn %xcc, 2f
8789 + add %g7, %o0, %g7
8790 + mov %g7, %o0
8791 + retl
8792 + nop
8793 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8794 +ENDPROC(atomic64_add_ret_unchecked)
8795 +
8796 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8797 BACKOFF_SETUP(%o2)
8798 1: ldx [%o1], %g1
8799 - sub %g1, %o0, %g7
8800 + subcc %g1, %o0, %g7
8801 +
8802 +#ifdef CONFIG_PAX_REFCOUNT
8803 + tvs %xcc, 6
8804 +#endif
8805 +
8806 casx [%o1], %g1, %g7
8807 cmp %g1, %g7
8808 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8809 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
8810 index 0c4e35e..745d3e4 100644
8811 --- a/arch/sparc/lib/ksyms.c
8812 +++ b/arch/sparc/lib/ksyms.c
8813 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
8814
8815 /* Atomic counter implementation. */
8816 EXPORT_SYMBOL(atomic_add);
8817 +EXPORT_SYMBOL(atomic_add_unchecked);
8818 EXPORT_SYMBOL(atomic_add_ret);
8819 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
8820 EXPORT_SYMBOL(atomic_sub);
8821 +EXPORT_SYMBOL(atomic_sub_unchecked);
8822 EXPORT_SYMBOL(atomic_sub_ret);
8823 EXPORT_SYMBOL(atomic64_add);
8824 +EXPORT_SYMBOL(atomic64_add_unchecked);
8825 EXPORT_SYMBOL(atomic64_add_ret);
8826 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
8827 EXPORT_SYMBOL(atomic64_sub);
8828 +EXPORT_SYMBOL(atomic64_sub_unchecked);
8829 EXPORT_SYMBOL(atomic64_sub_ret);
8830 EXPORT_SYMBOL(atomic64_dec_if_positive);
8831
8832 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
8833 index 30c3ecc..736f015 100644
8834 --- a/arch/sparc/mm/Makefile
8835 +++ b/arch/sparc/mm/Makefile
8836 @@ -2,7 +2,7 @@
8837 #
8838
8839 asflags-y := -ansi
8840 -ccflags-y := -Werror
8841 +#ccflags-y := -Werror
8842
8843 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
8844 obj-y += fault_$(BITS).o
8845 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
8846 index e98bfda..ea8d221 100644
8847 --- a/arch/sparc/mm/fault_32.c
8848 +++ b/arch/sparc/mm/fault_32.c
8849 @@ -21,6 +21,9 @@
8850 #include <linux/perf_event.h>
8851 #include <linux/interrupt.h>
8852 #include <linux/kdebug.h>
8853 +#include <linux/slab.h>
8854 +#include <linux/pagemap.h>
8855 +#include <linux/compiler.h>
8856
8857 #include <asm/page.h>
8858 #include <asm/pgtable.h>
8859 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
8860 return safe_compute_effective_address(regs, insn);
8861 }
8862
8863 +#ifdef CONFIG_PAX_PAGEEXEC
8864 +#ifdef CONFIG_PAX_DLRESOLVE
8865 +static void pax_emuplt_close(struct vm_area_struct *vma)
8866 +{
8867 + vma->vm_mm->call_dl_resolve = 0UL;
8868 +}
8869 +
8870 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8871 +{
8872 + unsigned int *kaddr;
8873 +
8874 + vmf->page = alloc_page(GFP_HIGHUSER);
8875 + if (!vmf->page)
8876 + return VM_FAULT_OOM;
8877 +
8878 + kaddr = kmap(vmf->page);
8879 + memset(kaddr, 0, PAGE_SIZE);
8880 + kaddr[0] = 0x9DE3BFA8U; /* save */
8881 + flush_dcache_page(vmf->page);
8882 + kunmap(vmf->page);
8883 + return VM_FAULT_MAJOR;
8884 +}
8885 +
8886 +static const struct vm_operations_struct pax_vm_ops = {
8887 + .close = pax_emuplt_close,
8888 + .fault = pax_emuplt_fault
8889 +};
8890 +
8891 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
8892 +{
8893 + int ret;
8894 +
8895 + INIT_LIST_HEAD(&vma->anon_vma_chain);
8896 + vma->vm_mm = current->mm;
8897 + vma->vm_start = addr;
8898 + vma->vm_end = addr + PAGE_SIZE;
8899 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
8900 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
8901 + vma->vm_ops = &pax_vm_ops;
8902 +
8903 + ret = insert_vm_struct(current->mm, vma);
8904 + if (ret)
8905 + return ret;
8906 +
8907 + ++current->mm->total_vm;
8908 + return 0;
8909 +}
8910 +#endif
8911 +
8912 +/*
8913 + * PaX: decide what to do with offenders (regs->pc = fault address)
8914 + *
8915 + * returns 1 when task should be killed
8916 + * 2 when patched PLT trampoline was detected
8917 + * 3 when unpatched PLT trampoline was detected
8918 + */
8919 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8920 +{
8921 +
8922 +#ifdef CONFIG_PAX_EMUPLT
8923 + int err;
8924 +
8925 + do { /* PaX: patched PLT emulation #1 */
8926 + unsigned int sethi1, sethi2, jmpl;
8927 +
8928 + err = get_user(sethi1, (unsigned int *)regs->pc);
8929 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
8930 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
8931 +
8932 + if (err)
8933 + break;
8934 +
8935 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8936 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
8937 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
8938 + {
8939 + unsigned int addr;
8940 +
8941 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8942 + addr = regs->u_regs[UREG_G1];
8943 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8944 + regs->pc = addr;
8945 + regs->npc = addr+4;
8946 + return 2;
8947 + }
8948 + } while (0);
8949 +
8950 + do { /* PaX: patched PLT emulation #2 */
8951 + unsigned int ba;
8952 +
8953 + err = get_user(ba, (unsigned int *)regs->pc);
8954 +
8955 + if (err)
8956 + break;
8957 +
8958 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8959 + unsigned int addr;
8960 +
8961 + if ((ba & 0xFFC00000U) == 0x30800000U)
8962 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8963 + else
8964 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8965 + regs->pc = addr;
8966 + regs->npc = addr+4;
8967 + return 2;
8968 + }
8969 + } while (0);
8970 +
8971 + do { /* PaX: patched PLT emulation #3 */
8972 + unsigned int sethi, bajmpl, nop;
8973 +
8974 + err = get_user(sethi, (unsigned int *)regs->pc);
8975 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
8976 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
8977 +
8978 + if (err)
8979 + break;
8980 +
8981 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8982 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8983 + nop == 0x01000000U)
8984 + {
8985 + unsigned int addr;
8986 +
8987 + addr = (sethi & 0x003FFFFFU) << 10;
8988 + regs->u_regs[UREG_G1] = addr;
8989 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8990 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8991 + else
8992 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8993 + regs->pc = addr;
8994 + regs->npc = addr+4;
8995 + return 2;
8996 + }
8997 + } while (0);
8998 +
8999 + do { /* PaX: unpatched PLT emulation step 1 */
9000 + unsigned int sethi, ba, nop;
9001 +
9002 + err = get_user(sethi, (unsigned int *)regs->pc);
9003 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
9004 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
9005 +
9006 + if (err)
9007 + break;
9008 +
9009 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9010 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9011 + nop == 0x01000000U)
9012 + {
9013 + unsigned int addr, save, call;
9014 +
9015 + if ((ba & 0xFFC00000U) == 0x30800000U)
9016 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9017 + else
9018 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9019 +
9020 + err = get_user(save, (unsigned int *)addr);
9021 + err |= get_user(call, (unsigned int *)(addr+4));
9022 + err |= get_user(nop, (unsigned int *)(addr+8));
9023 + if (err)
9024 + break;
9025 +
9026 +#ifdef CONFIG_PAX_DLRESOLVE
9027 + if (save == 0x9DE3BFA8U &&
9028 + (call & 0xC0000000U) == 0x40000000U &&
9029 + nop == 0x01000000U)
9030 + {
9031 + struct vm_area_struct *vma;
9032 + unsigned long call_dl_resolve;
9033 +
9034 + down_read(&current->mm->mmap_sem);
9035 + call_dl_resolve = current->mm->call_dl_resolve;
9036 + up_read(&current->mm->mmap_sem);
9037 + if (likely(call_dl_resolve))
9038 + goto emulate;
9039 +
9040 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9041 +
9042 + down_write(&current->mm->mmap_sem);
9043 + if (current->mm->call_dl_resolve) {
9044 + call_dl_resolve = current->mm->call_dl_resolve;
9045 + up_write(&current->mm->mmap_sem);
9046 + if (vma)
9047 + kmem_cache_free(vm_area_cachep, vma);
9048 + goto emulate;
9049 + }
9050 +
9051 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9052 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9053 + up_write(&current->mm->mmap_sem);
9054 + if (vma)
9055 + kmem_cache_free(vm_area_cachep, vma);
9056 + return 1;
9057 + }
9058 +
9059 + if (pax_insert_vma(vma, call_dl_resolve)) {
9060 + up_write(&current->mm->mmap_sem);
9061 + kmem_cache_free(vm_area_cachep, vma);
9062 + return 1;
9063 + }
9064 +
9065 + current->mm->call_dl_resolve = call_dl_resolve;
9066 + up_write(&current->mm->mmap_sem);
9067 +
9068 +emulate:
9069 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9070 + regs->pc = call_dl_resolve;
9071 + regs->npc = addr+4;
9072 + return 3;
9073 + }
9074 +#endif
9075 +
9076 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9077 + if ((save & 0xFFC00000U) == 0x05000000U &&
9078 + (call & 0xFFFFE000U) == 0x85C0A000U &&
9079 + nop == 0x01000000U)
9080 + {
9081 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9082 + regs->u_regs[UREG_G2] = addr + 4;
9083 + addr = (save & 0x003FFFFFU) << 10;
9084 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9085 + regs->pc = addr;
9086 + regs->npc = addr+4;
9087 + return 3;
9088 + }
9089 + }
9090 + } while (0);
9091 +
9092 + do { /* PaX: unpatched PLT emulation step 2 */
9093 + unsigned int save, call, nop;
9094 +
9095 + err = get_user(save, (unsigned int *)(regs->pc-4));
9096 + err |= get_user(call, (unsigned int *)regs->pc);
9097 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
9098 + if (err)
9099 + break;
9100 +
9101 + if (save == 0x9DE3BFA8U &&
9102 + (call & 0xC0000000U) == 0x40000000U &&
9103 + nop == 0x01000000U)
9104 + {
9105 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9106 +
9107 + regs->u_regs[UREG_RETPC] = regs->pc;
9108 + regs->pc = dl_resolve;
9109 + regs->npc = dl_resolve+4;
9110 + return 3;
9111 + }
9112 + } while (0);
9113 +#endif
9114 +
9115 + return 1;
9116 +}
9117 +
9118 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9119 +{
9120 + unsigned long i;
9121 +
9122 + printk(KERN_ERR "PAX: bytes at PC: ");
9123 + for (i = 0; i < 8; i++) {
9124 + unsigned int c;
9125 + if (get_user(c, (unsigned int *)pc+i))
9126 + printk(KERN_CONT "???????? ");
9127 + else
9128 + printk(KERN_CONT "%08x ", c);
9129 + }
9130 + printk("\n");
9131 +}
9132 +#endif
9133 +
9134 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9135 int text_fault)
9136 {
9137 @@ -230,6 +504,24 @@ good_area:
9138 if (!(vma->vm_flags & VM_WRITE))
9139 goto bad_area;
9140 } else {
9141 +
9142 +#ifdef CONFIG_PAX_PAGEEXEC
9143 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9144 + up_read(&mm->mmap_sem);
9145 + switch (pax_handle_fetch_fault(regs)) {
9146 +
9147 +#ifdef CONFIG_PAX_EMUPLT
9148 + case 2:
9149 + case 3:
9150 + return;
9151 +#endif
9152 +
9153 + }
9154 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9155 + do_group_exit(SIGKILL);
9156 + }
9157 +#endif
9158 +
9159 /* Allow reads even for write-only mappings */
9160 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9161 goto bad_area;
9162 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9163 index 5062ff3..e0b75f3 100644
9164 --- a/arch/sparc/mm/fault_64.c
9165 +++ b/arch/sparc/mm/fault_64.c
9166 @@ -21,6 +21,9 @@
9167 #include <linux/kprobes.h>
9168 #include <linux/kdebug.h>
9169 #include <linux/percpu.h>
9170 +#include <linux/slab.h>
9171 +#include <linux/pagemap.h>
9172 +#include <linux/compiler.h>
9173
9174 #include <asm/page.h>
9175 #include <asm/pgtable.h>
9176 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9177 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9178 regs->tpc);
9179 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9180 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9181 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9182 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9183 dump_stack();
9184 unhandled_fault(regs->tpc, current, regs);
9185 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9186 show_regs(regs);
9187 }
9188
9189 +#ifdef CONFIG_PAX_PAGEEXEC
9190 +#ifdef CONFIG_PAX_DLRESOLVE
9191 +static void pax_emuplt_close(struct vm_area_struct *vma)
9192 +{
9193 + vma->vm_mm->call_dl_resolve = 0UL;
9194 +}
9195 +
9196 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9197 +{
9198 + unsigned int *kaddr;
9199 +
9200 + vmf->page = alloc_page(GFP_HIGHUSER);
9201 + if (!vmf->page)
9202 + return VM_FAULT_OOM;
9203 +
9204 + kaddr = kmap(vmf->page);
9205 + memset(kaddr, 0, PAGE_SIZE);
9206 + kaddr[0] = 0x9DE3BFA8U; /* save */
9207 + flush_dcache_page(vmf->page);
9208 + kunmap(vmf->page);
9209 + return VM_FAULT_MAJOR;
9210 +}
9211 +
9212 +static const struct vm_operations_struct pax_vm_ops = {
9213 + .close = pax_emuplt_close,
9214 + .fault = pax_emuplt_fault
9215 +};
9216 +
9217 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9218 +{
9219 + int ret;
9220 +
9221 + INIT_LIST_HEAD(&vma->anon_vma_chain);
9222 + vma->vm_mm = current->mm;
9223 + vma->vm_start = addr;
9224 + vma->vm_end = addr + PAGE_SIZE;
9225 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9226 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9227 + vma->vm_ops = &pax_vm_ops;
9228 +
9229 + ret = insert_vm_struct(current->mm, vma);
9230 + if (ret)
9231 + return ret;
9232 +
9233 + ++current->mm->total_vm;
9234 + return 0;
9235 +}
9236 +#endif
9237 +
9238 +/*
9239 + * PaX: decide what to do with offenders (regs->tpc = fault address)
9240 + *
9241 + * returns 1 when task should be killed
9242 + * 2 when patched PLT trampoline was detected
9243 + * 3 when unpatched PLT trampoline was detected
9244 + */
9245 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9246 +{
9247 +
9248 +#ifdef CONFIG_PAX_EMUPLT
9249 + int err;
9250 +
9251 + do { /* PaX: patched PLT emulation #1 */
9252 + unsigned int sethi1, sethi2, jmpl;
9253 +
9254 + err = get_user(sethi1, (unsigned int *)regs->tpc);
9255 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9256 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9257 +
9258 + if (err)
9259 + break;
9260 +
9261 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9262 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
9263 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
9264 + {
9265 + unsigned long addr;
9266 +
9267 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9268 + addr = regs->u_regs[UREG_G1];
9269 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9270 +
9271 + if (test_thread_flag(TIF_32BIT))
9272 + addr &= 0xFFFFFFFFUL;
9273 +
9274 + regs->tpc = addr;
9275 + regs->tnpc = addr+4;
9276 + return 2;
9277 + }
9278 + } while (0);
9279 +
9280 + do { /* PaX: patched PLT emulation #2 */
9281 + unsigned int ba;
9282 +
9283 + err = get_user(ba, (unsigned int *)regs->tpc);
9284 +
9285 + if (err)
9286 + break;
9287 +
9288 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9289 + unsigned long addr;
9290 +
9291 + if ((ba & 0xFFC00000U) == 0x30800000U)
9292 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9293 + else
9294 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9295 +
9296 + if (test_thread_flag(TIF_32BIT))
9297 + addr &= 0xFFFFFFFFUL;
9298 +
9299 + regs->tpc = addr;
9300 + regs->tnpc = addr+4;
9301 + return 2;
9302 + }
9303 + } while (0);
9304 +
9305 + do { /* PaX: patched PLT emulation #3 */
9306 + unsigned int sethi, bajmpl, nop;
9307 +
9308 + err = get_user(sethi, (unsigned int *)regs->tpc);
9309 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9310 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9311 +
9312 + if (err)
9313 + break;
9314 +
9315 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9316 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9317 + nop == 0x01000000U)
9318 + {
9319 + unsigned long addr;
9320 +
9321 + addr = (sethi & 0x003FFFFFU) << 10;
9322 + regs->u_regs[UREG_G1] = addr;
9323 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9324 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9325 + else
9326 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9327 +
9328 + if (test_thread_flag(TIF_32BIT))
9329 + addr &= 0xFFFFFFFFUL;
9330 +
9331 + regs->tpc = addr;
9332 + regs->tnpc = addr+4;
9333 + return 2;
9334 + }
9335 + } while (0);
9336 +
9337 + do { /* PaX: patched PLT emulation #4 */
9338 + unsigned int sethi, mov1, call, mov2;
9339 +
9340 + err = get_user(sethi, (unsigned int *)regs->tpc);
9341 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9342 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
9343 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9344 +
9345 + if (err)
9346 + break;
9347 +
9348 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9349 + mov1 == 0x8210000FU &&
9350 + (call & 0xC0000000U) == 0x40000000U &&
9351 + mov2 == 0x9E100001U)
9352 + {
9353 + unsigned long addr;
9354 +
9355 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9356 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9357 +
9358 + if (test_thread_flag(TIF_32BIT))
9359 + addr &= 0xFFFFFFFFUL;
9360 +
9361 + regs->tpc = addr;
9362 + regs->tnpc = addr+4;
9363 + return 2;
9364 + }
9365 + } while (0);
9366 +
9367 + do { /* PaX: patched PLT emulation #5 */
9368 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9369 +
9370 + err = get_user(sethi, (unsigned int *)regs->tpc);
9371 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9372 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9373 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9374 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9375 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9376 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9377 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9378 +
9379 + if (err)
9380 + break;
9381 +
9382 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9383 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
9384 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9385 + (or1 & 0xFFFFE000U) == 0x82106000U &&
9386 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
9387 + sllx == 0x83287020U &&
9388 + jmpl == 0x81C04005U &&
9389 + nop == 0x01000000U)
9390 + {
9391 + unsigned long addr;
9392 +
9393 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9394 + regs->u_regs[UREG_G1] <<= 32;
9395 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9396 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9397 + regs->tpc = addr;
9398 + regs->tnpc = addr+4;
9399 + return 2;
9400 + }
9401 + } while (0);
9402 +
9403 + do { /* PaX: patched PLT emulation #6 */
9404 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9405 +
9406 + err = get_user(sethi, (unsigned int *)regs->tpc);
9407 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9408 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9409 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9410 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
9411 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9412 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9413 +
9414 + if (err)
9415 + break;
9416 +
9417 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9418 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
9419 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9420 + sllx == 0x83287020U &&
9421 + (or & 0xFFFFE000U) == 0x8A116000U &&
9422 + jmpl == 0x81C04005U &&
9423 + nop == 0x01000000U)
9424 + {
9425 + unsigned long addr;
9426 +
9427 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9428 + regs->u_regs[UREG_G1] <<= 32;
9429 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9430 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9431 + regs->tpc = addr;
9432 + regs->tnpc = addr+4;
9433 + return 2;
9434 + }
9435 + } while (0);
9436 +
9437 + do { /* PaX: unpatched PLT emulation step 1 */
9438 + unsigned int sethi, ba, nop;
9439 +
9440 + err = get_user(sethi, (unsigned int *)regs->tpc);
9441 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9442 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9443 +
9444 + if (err)
9445 + break;
9446 +
9447 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9448 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9449 + nop == 0x01000000U)
9450 + {
9451 + unsigned long addr;
9452 + unsigned int save, call;
9453 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9454 +
9455 + if ((ba & 0xFFC00000U) == 0x30800000U)
9456 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9457 + else
9458 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9459 +
9460 + if (test_thread_flag(TIF_32BIT))
9461 + addr &= 0xFFFFFFFFUL;
9462 +
9463 + err = get_user(save, (unsigned int *)addr);
9464 + err |= get_user(call, (unsigned int *)(addr+4));
9465 + err |= get_user(nop, (unsigned int *)(addr+8));
9466 + if (err)
9467 + break;
9468 +
9469 +#ifdef CONFIG_PAX_DLRESOLVE
9470 + if (save == 0x9DE3BFA8U &&
9471 + (call & 0xC0000000U) == 0x40000000U &&
9472 + nop == 0x01000000U)
9473 + {
9474 + struct vm_area_struct *vma;
9475 + unsigned long call_dl_resolve;
9476 +
9477 + down_read(&current->mm->mmap_sem);
9478 + call_dl_resolve = current->mm->call_dl_resolve;
9479 + up_read(&current->mm->mmap_sem);
9480 + if (likely(call_dl_resolve))
9481 + goto emulate;
9482 +
9483 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9484 +
9485 + down_write(&current->mm->mmap_sem);
9486 + if (current->mm->call_dl_resolve) {
9487 + call_dl_resolve = current->mm->call_dl_resolve;
9488 + up_write(&current->mm->mmap_sem);
9489 + if (vma)
9490 + kmem_cache_free(vm_area_cachep, vma);
9491 + goto emulate;
9492 + }
9493 +
9494 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9495 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9496 + up_write(&current->mm->mmap_sem);
9497 + if (vma)
9498 + kmem_cache_free(vm_area_cachep, vma);
9499 + return 1;
9500 + }
9501 +
9502 + if (pax_insert_vma(vma, call_dl_resolve)) {
9503 + up_write(&current->mm->mmap_sem);
9504 + kmem_cache_free(vm_area_cachep, vma);
9505 + return 1;
9506 + }
9507 +
9508 + current->mm->call_dl_resolve = call_dl_resolve;
9509 + up_write(&current->mm->mmap_sem);
9510 +
9511 +emulate:
9512 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9513 + regs->tpc = call_dl_resolve;
9514 + regs->tnpc = addr+4;
9515 + return 3;
9516 + }
9517 +#endif
9518 +
9519 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9520 + if ((save & 0xFFC00000U) == 0x05000000U &&
9521 + (call & 0xFFFFE000U) == 0x85C0A000U &&
9522 + nop == 0x01000000U)
9523 + {
9524 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9525 + regs->u_regs[UREG_G2] = addr + 4;
9526 + addr = (save & 0x003FFFFFU) << 10;
9527 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9528 +
9529 + if (test_thread_flag(TIF_32BIT))
9530 + addr &= 0xFFFFFFFFUL;
9531 +
9532 + regs->tpc = addr;
9533 + regs->tnpc = addr+4;
9534 + return 3;
9535 + }
9536 +
9537 + /* PaX: 64-bit PLT stub */
9538 + err = get_user(sethi1, (unsigned int *)addr);
9539 + err |= get_user(sethi2, (unsigned int *)(addr+4));
9540 + err |= get_user(or1, (unsigned int *)(addr+8));
9541 + err |= get_user(or2, (unsigned int *)(addr+12));
9542 + err |= get_user(sllx, (unsigned int *)(addr+16));
9543 + err |= get_user(add, (unsigned int *)(addr+20));
9544 + err |= get_user(jmpl, (unsigned int *)(addr+24));
9545 + err |= get_user(nop, (unsigned int *)(addr+28));
9546 + if (err)
9547 + break;
9548 +
9549 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9550 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9551 + (or1 & 0xFFFFE000U) == 0x88112000U &&
9552 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
9553 + sllx == 0x89293020U &&
9554 + add == 0x8A010005U &&
9555 + jmpl == 0x89C14000U &&
9556 + nop == 0x01000000U)
9557 + {
9558 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9559 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9560 + regs->u_regs[UREG_G4] <<= 32;
9561 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9562 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9563 + regs->u_regs[UREG_G4] = addr + 24;
9564 + addr = regs->u_regs[UREG_G5];
9565 + regs->tpc = addr;
9566 + regs->tnpc = addr+4;
9567 + return 3;
9568 + }
9569 + }
9570 + } while (0);
9571 +
9572 +#ifdef CONFIG_PAX_DLRESOLVE
9573 + do { /* PaX: unpatched PLT emulation step 2 */
9574 + unsigned int save, call, nop;
9575 +
9576 + err = get_user(save, (unsigned int *)(regs->tpc-4));
9577 + err |= get_user(call, (unsigned int *)regs->tpc);
9578 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9579 + if (err)
9580 + break;
9581 +
9582 + if (save == 0x9DE3BFA8U &&
9583 + (call & 0xC0000000U) == 0x40000000U &&
9584 + nop == 0x01000000U)
9585 + {
9586 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9587 +
9588 + if (test_thread_flag(TIF_32BIT))
9589 + dl_resolve &= 0xFFFFFFFFUL;
9590 +
9591 + regs->u_regs[UREG_RETPC] = regs->tpc;
9592 + regs->tpc = dl_resolve;
9593 + regs->tnpc = dl_resolve+4;
9594 + return 3;
9595 + }
9596 + } while (0);
9597 +#endif
9598 +
9599 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9600 + unsigned int sethi, ba, nop;
9601 +
9602 + err = get_user(sethi, (unsigned int *)regs->tpc);
9603 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9604 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9605 +
9606 + if (err)
9607 + break;
9608 +
9609 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9610 + (ba & 0xFFF00000U) == 0x30600000U &&
9611 + nop == 0x01000000U)
9612 + {
9613 + unsigned long addr;
9614 +
9615 + addr = (sethi & 0x003FFFFFU) << 10;
9616 + regs->u_regs[UREG_G1] = addr;
9617 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9618 +
9619 + if (test_thread_flag(TIF_32BIT))
9620 + addr &= 0xFFFFFFFFUL;
9621 +
9622 + regs->tpc = addr;
9623 + regs->tnpc = addr+4;
9624 + return 2;
9625 + }
9626 + } while (0);
9627 +
9628 +#endif
9629 +
9630 + return 1;
9631 +}
9632 +
9633 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9634 +{
9635 + unsigned long i;
9636 +
9637 + printk(KERN_ERR "PAX: bytes at PC: ");
9638 + for (i = 0; i < 8; i++) {
9639 + unsigned int c;
9640 + if (get_user(c, (unsigned int *)pc+i))
9641 + printk(KERN_CONT "???????? ");
9642 + else
9643 + printk(KERN_CONT "%08x ", c);
9644 + }
9645 + printk("\n");
9646 +}
9647 +#endif
9648 +
9649 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9650 {
9651 struct mm_struct *mm = current->mm;
9652 @@ -341,6 +804,29 @@ retry:
9653 if (!vma)
9654 goto bad_area;
9655
9656 +#ifdef CONFIG_PAX_PAGEEXEC
9657 + /* PaX: detect ITLB misses on non-exec pages */
9658 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9659 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9660 + {
9661 + if (address != regs->tpc)
9662 + goto good_area;
9663 +
9664 + up_read(&mm->mmap_sem);
9665 + switch (pax_handle_fetch_fault(regs)) {
9666 +
9667 +#ifdef CONFIG_PAX_EMUPLT
9668 + case 2:
9669 + case 3:
9670 + return;
9671 +#endif
9672 +
9673 + }
9674 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9675 + do_group_exit(SIGKILL);
9676 + }
9677 +#endif
9678 +
9679 /* Pure DTLB misses do not tell us whether the fault causing
9680 * load/store/atomic was a write or not, it only says that there
9681 * was no match. So in such a case we (carefully) read the
9682 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9683 index d2b5944..bd813f2 100644
9684 --- a/arch/sparc/mm/hugetlbpage.c
9685 +++ b/arch/sparc/mm/hugetlbpage.c
9686 @@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9687
9688 info.flags = 0;
9689 info.length = len;
9690 - info.low_limit = TASK_UNMAPPED_BASE;
9691 + info.low_limit = mm->mmap_base;
9692 info.high_limit = min(task_size, VA_EXCLUDE_START);
9693 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9694 info.align_offset = 0;
9695 @@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9696 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9697 VM_BUG_ON(addr != -ENOMEM);
9698 info.low_limit = VA_EXCLUDE_END;
9699 +
9700 +#ifdef CONFIG_PAX_RANDMMAP
9701 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9702 + info.low_limit += mm->delta_mmap;
9703 +#endif
9704 +
9705 info.high_limit = task_size;
9706 addr = vm_unmapped_area(&info);
9707 }
9708 @@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9709 VM_BUG_ON(addr != -ENOMEM);
9710 info.flags = 0;
9711 info.low_limit = TASK_UNMAPPED_BASE;
9712 +
9713 +#ifdef CONFIG_PAX_RANDMMAP
9714 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9715 + info.low_limit += mm->delta_mmap;
9716 +#endif
9717 +
9718 info.high_limit = STACK_TOP32;
9719 addr = vm_unmapped_area(&info);
9720 }
9721 @@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9722 struct mm_struct *mm = current->mm;
9723 struct vm_area_struct *vma;
9724 unsigned long task_size = TASK_SIZE;
9725 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9726
9727 if (test_thread_flag(TIF_32BIT))
9728 task_size = STACK_TOP32;
9729 @@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9730 return addr;
9731 }
9732
9733 +#ifdef CONFIG_PAX_RANDMMAP
9734 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9735 +#endif
9736 +
9737 if (addr) {
9738 addr = ALIGN(addr, HPAGE_SIZE);
9739 vma = find_vma(mm, addr);
9740 - if (task_size - len >= addr &&
9741 - (!vma || addr + len <= vma->vm_start))
9742 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9743 return addr;
9744 }
9745 if (mm->get_unmapped_area == arch_get_unmapped_area)
9746 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9747 index f4500c6..889656c 100644
9748 --- a/arch/tile/include/asm/atomic_64.h
9749 +++ b/arch/tile/include/asm/atomic_64.h
9750 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9751
9752 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9753
9754 +#define atomic64_read_unchecked(v) atomic64_read(v)
9755 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9756 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9757 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9758 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9759 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9760 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9761 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9762 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9763 +
9764 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
9765 #define smp_mb__before_atomic_dec() smp_mb()
9766 #define smp_mb__after_atomic_dec() smp_mb()
9767 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
9768 index a9a5299..0fce79e 100644
9769 --- a/arch/tile/include/asm/cache.h
9770 +++ b/arch/tile/include/asm/cache.h
9771 @@ -15,11 +15,12 @@
9772 #ifndef _ASM_TILE_CACHE_H
9773 #define _ASM_TILE_CACHE_H
9774
9775 +#include <linux/const.h>
9776 #include <arch/chip.h>
9777
9778 /* bytes per L1 data cache line */
9779 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
9780 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9781 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9782
9783 /* bytes per L2 cache line */
9784 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
9785 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
9786 index 9ab078a..d6635c2 100644
9787 --- a/arch/tile/include/asm/uaccess.h
9788 +++ b/arch/tile/include/asm/uaccess.h
9789 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
9790 const void __user *from,
9791 unsigned long n)
9792 {
9793 - int sz = __compiletime_object_size(to);
9794 + size_t sz = __compiletime_object_size(to);
9795
9796 - if (likely(sz == -1 || sz >= n))
9797 + if (likely(sz == (size_t)-1 || sz >= n))
9798 n = _copy_from_user(to, from, n);
9799 else
9800 copy_from_user_overflow();
9801 diff --git a/arch/um/Makefile b/arch/um/Makefile
9802 index 133f7de..1d6f2f1 100644
9803 --- a/arch/um/Makefile
9804 +++ b/arch/um/Makefile
9805 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
9806 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
9807 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
9808
9809 +ifdef CONSTIFY_PLUGIN
9810 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
9811 +endif
9812 +
9813 #This will adjust *FLAGS accordingly to the platform.
9814 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
9815
9816 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
9817 index 19e1bdd..3665b77 100644
9818 --- a/arch/um/include/asm/cache.h
9819 +++ b/arch/um/include/asm/cache.h
9820 @@ -1,6 +1,7 @@
9821 #ifndef __UM_CACHE_H
9822 #define __UM_CACHE_H
9823
9824 +#include <linux/const.h>
9825
9826 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
9827 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9828 @@ -12,6 +13,6 @@
9829 # define L1_CACHE_SHIFT 5
9830 #endif
9831
9832 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9833 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9834
9835 #endif
9836 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
9837 index 2e0a6b1..a64d0f5 100644
9838 --- a/arch/um/include/asm/kmap_types.h
9839 +++ b/arch/um/include/asm/kmap_types.h
9840 @@ -8,6 +8,6 @@
9841
9842 /* No more #include "asm/arch/kmap_types.h" ! */
9843
9844 -#define KM_TYPE_NR 14
9845 +#define KM_TYPE_NR 15
9846
9847 #endif
9848 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
9849 index 5ff53d9..5850cdf 100644
9850 --- a/arch/um/include/asm/page.h
9851 +++ b/arch/um/include/asm/page.h
9852 @@ -14,6 +14,9 @@
9853 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
9854 #define PAGE_MASK (~(PAGE_SIZE-1))
9855
9856 +#define ktla_ktva(addr) (addr)
9857 +#define ktva_ktla(addr) (addr)
9858 +
9859 #ifndef __ASSEMBLY__
9860
9861 struct page;
9862 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
9863 index 0032f92..cd151e0 100644
9864 --- a/arch/um/include/asm/pgtable-3level.h
9865 +++ b/arch/um/include/asm/pgtable-3level.h
9866 @@ -58,6 +58,7 @@
9867 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
9868 #define pud_populate(mm, pud, pmd) \
9869 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
9870 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9871
9872 #ifdef CONFIG_64BIT
9873 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
9874 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
9875 index b462b13..e7a19aa 100644
9876 --- a/arch/um/kernel/process.c
9877 +++ b/arch/um/kernel/process.c
9878 @@ -386,22 +386,6 @@ int singlestepping(void * t)
9879 return 2;
9880 }
9881
9882 -/*
9883 - * Only x86 and x86_64 have an arch_align_stack().
9884 - * All other arches have "#define arch_align_stack(x) (x)"
9885 - * in their asm/system.h
9886 - * As this is included in UML from asm-um/system-generic.h,
9887 - * we can use it to behave as the subarch does.
9888 - */
9889 -#ifndef arch_align_stack
9890 -unsigned long arch_align_stack(unsigned long sp)
9891 -{
9892 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9893 - sp -= get_random_int() % 8192;
9894 - return sp & ~0xf;
9895 -}
9896 -#endif
9897 -
9898 unsigned long get_wchan(struct task_struct *p)
9899 {
9900 unsigned long stack_page, sp, ip;
9901 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
9902 index ad8f795..2c7eec6 100644
9903 --- a/arch/unicore32/include/asm/cache.h
9904 +++ b/arch/unicore32/include/asm/cache.h
9905 @@ -12,8 +12,10 @@
9906 #ifndef __UNICORE_CACHE_H__
9907 #define __UNICORE_CACHE_H__
9908
9909 -#define L1_CACHE_SHIFT (5)
9910 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9911 +#include <linux/const.h>
9912 +
9913 +#define L1_CACHE_SHIFT 5
9914 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9915
9916 /*
9917 * Memory returned by kmalloc() may be used for DMA, so we must make
9918 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
9919 index 0694d09..b58b3aa 100644
9920 --- a/arch/x86/Kconfig
9921 +++ b/arch/x86/Kconfig
9922 @@ -238,7 +238,7 @@ config X86_HT
9923
9924 config X86_32_LAZY_GS
9925 def_bool y
9926 - depends on X86_32 && !CC_STACKPROTECTOR
9927 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
9928
9929 config ARCH_HWEIGHT_CFLAGS
9930 string
9931 @@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
9932
9933 config X86_MSR
9934 tristate "/dev/cpu/*/msr - Model-specific register support"
9935 + depends on !GRKERNSEC_KMEM
9936 ---help---
9937 This device gives privileged processes access to the x86
9938 Model-Specific Registers (MSRs). It is a character device with
9939 @@ -1054,7 +1055,7 @@ choice
9940
9941 config NOHIGHMEM
9942 bool "off"
9943 - depends on !X86_NUMAQ
9944 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9945 ---help---
9946 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
9947 However, the address space of 32-bit x86 processors is only 4
9948 @@ -1091,7 +1092,7 @@ config NOHIGHMEM
9949
9950 config HIGHMEM4G
9951 bool "4GB"
9952 - depends on !X86_NUMAQ
9953 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9954 ---help---
9955 Select this if you have a 32-bit processor and between 1 and 4
9956 gigabytes of physical RAM.
9957 @@ -1145,7 +1146,7 @@ config PAGE_OFFSET
9958 hex
9959 default 0xB0000000 if VMSPLIT_3G_OPT
9960 default 0x80000000 if VMSPLIT_2G
9961 - default 0x78000000 if VMSPLIT_2G_OPT
9962 + default 0x70000000 if VMSPLIT_2G_OPT
9963 default 0x40000000 if VMSPLIT_1G
9964 default 0xC0000000
9965 depends on X86_32
9966 @@ -1542,6 +1543,7 @@ config SECCOMP
9967
9968 config CC_STACKPROTECTOR
9969 bool "Enable -fstack-protector buffer overflow detection"
9970 + depends on X86_64 || !PAX_MEMORY_UDEREF
9971 ---help---
9972 This option turns on the -fstack-protector GCC feature. This
9973 feature puts, at the beginning of functions, a canary value on
9974 @@ -1599,6 +1601,7 @@ config KEXEC_JUMP
9975 config PHYSICAL_START
9976 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
9977 default "0x1000000"
9978 + range 0x400000 0x40000000
9979 ---help---
9980 This gives the physical address where the kernel is loaded.
9981
9982 @@ -1662,6 +1665,7 @@ config X86_NEED_RELOCS
9983 config PHYSICAL_ALIGN
9984 hex "Alignment value to which kernel should be aligned" if X86_32
9985 default "0x1000000"
9986 + range 0x400000 0x1000000 if PAX_KERNEXEC
9987 range 0x2000 0x1000000
9988 ---help---
9989 This value puts the alignment restrictions on physical address
9990 @@ -1737,9 +1741,10 @@ config DEBUG_HOTPLUG_CPU0
9991 If unsure, say N.
9992
9993 config COMPAT_VDSO
9994 - def_bool y
9995 + def_bool n
9996 prompt "Compat VDSO support"
9997 depends on X86_32 || IA32_EMULATION
9998 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
9999 ---help---
10000 Map the 32-bit VDSO to the predictable old-style address too.
10001
10002 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10003 index c026cca..14657ae 100644
10004 --- a/arch/x86/Kconfig.cpu
10005 +++ b/arch/x86/Kconfig.cpu
10006 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10007
10008 config X86_F00F_BUG
10009 def_bool y
10010 - depends on M586MMX || M586TSC || M586 || M486
10011 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10012
10013 config X86_INVD_BUG
10014 def_bool y
10015 @@ -327,7 +327,7 @@ config X86_INVD_BUG
10016
10017 config X86_ALIGNMENT_16
10018 def_bool y
10019 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10020 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10021
10022 config X86_INTEL_USERCOPY
10023 def_bool y
10024 @@ -373,7 +373,7 @@ config X86_CMPXCHG64
10025 # generates cmov.
10026 config X86_CMOV
10027 def_bool y
10028 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10029 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10030
10031 config X86_MINIMUM_CPU_FAMILY
10032 int
10033 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10034 index b322f12..652d0d9 100644
10035 --- a/arch/x86/Kconfig.debug
10036 +++ b/arch/x86/Kconfig.debug
10037 @@ -84,7 +84,7 @@ config X86_PTDUMP
10038 config DEBUG_RODATA
10039 bool "Write protect kernel read-only data structures"
10040 default y
10041 - depends on DEBUG_KERNEL
10042 + depends on DEBUG_KERNEL && BROKEN
10043 ---help---
10044 Mark the kernel read-only data as write-protected in the pagetables,
10045 in order to catch accidental (and incorrect) writes to such const
10046 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10047
10048 config DEBUG_SET_MODULE_RONX
10049 bool "Set loadable kernel module data as NX and text as RO"
10050 - depends on MODULES
10051 + depends on MODULES && BROKEN
10052 ---help---
10053 This option helps catch unintended modifications to loadable
10054 kernel module's text and read-only data. It also prevents execution
10055 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
10056
10057 config DEBUG_STRICT_USER_COPY_CHECKS
10058 bool "Strict copy size checks"
10059 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
10060 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
10061 ---help---
10062 Enabling this option turns a certain set of sanity checks for user
10063 copy operations into compile time failures.
10064 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10065 index e71fc42..7829607 100644
10066 --- a/arch/x86/Makefile
10067 +++ b/arch/x86/Makefile
10068 @@ -50,6 +50,7 @@ else
10069 UTS_MACHINE := x86_64
10070 CHECKFLAGS += -D__x86_64__ -m64
10071
10072 + biarch := $(call cc-option,-m64)
10073 KBUILD_AFLAGS += -m64
10074 KBUILD_CFLAGS += -m64
10075
10076 @@ -230,3 +231,12 @@ define archhelp
10077 echo ' FDARGS="..." arguments for the booted kernel'
10078 echo ' FDINITRD=file initrd for the booted kernel'
10079 endef
10080 +
10081 +define OLD_LD
10082 +
10083 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10084 +*** Please upgrade your binutils to 2.18 or newer
10085 +endef
10086 +
10087 +archprepare:
10088 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10089 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10090 index 379814b..add62ce 100644
10091 --- a/arch/x86/boot/Makefile
10092 +++ b/arch/x86/boot/Makefile
10093 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10094 $(call cc-option, -fno-stack-protector) \
10095 $(call cc-option, -mpreferred-stack-boundary=2)
10096 KBUILD_CFLAGS += $(call cc-option, -m32)
10097 +ifdef CONSTIFY_PLUGIN
10098 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10099 +endif
10100 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10101 GCOV_PROFILE := n
10102
10103 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10104 index 878e4b9..20537ab 100644
10105 --- a/arch/x86/boot/bitops.h
10106 +++ b/arch/x86/boot/bitops.h
10107 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10108 u8 v;
10109 const u32 *p = (const u32 *)addr;
10110
10111 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10112 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10113 return v;
10114 }
10115
10116 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10117
10118 static inline void set_bit(int nr, void *addr)
10119 {
10120 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10121 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10122 }
10123
10124 #endif /* BOOT_BITOPS_H */
10125 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10126 index 18997e5..83d9c67 100644
10127 --- a/arch/x86/boot/boot.h
10128 +++ b/arch/x86/boot/boot.h
10129 @@ -85,7 +85,7 @@ static inline void io_delay(void)
10130 static inline u16 ds(void)
10131 {
10132 u16 seg;
10133 - asm("movw %%ds,%0" : "=rm" (seg));
10134 + asm volatile("movw %%ds,%0" : "=rm" (seg));
10135 return seg;
10136 }
10137
10138 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10139 static inline int memcmp(const void *s1, const void *s2, size_t len)
10140 {
10141 u8 diff;
10142 - asm("repe; cmpsb; setnz %0"
10143 + asm volatile("repe; cmpsb; setnz %0"
10144 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10145 return diff;
10146 }
10147 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10148 index 8a84501..b2d165f 100644
10149 --- a/arch/x86/boot/compressed/Makefile
10150 +++ b/arch/x86/boot/compressed/Makefile
10151 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10152 KBUILD_CFLAGS += $(cflags-y)
10153 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10154 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10155 +ifdef CONSTIFY_PLUGIN
10156 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10157 +endif
10158
10159 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10160 GCOV_PROFILE := n
10161 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10162 index c205035..5853587 100644
10163 --- a/arch/x86/boot/compressed/eboot.c
10164 +++ b/arch/x86/boot/compressed/eboot.c
10165 @@ -150,7 +150,6 @@ again:
10166 *addr = max_addr;
10167 }
10168
10169 -free_pool:
10170 efi_call_phys1(sys_table->boottime->free_pool, map);
10171
10172 fail:
10173 @@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10174 if (i == map_size / desc_size)
10175 status = EFI_NOT_FOUND;
10176
10177 -free_pool:
10178 efi_call_phys1(sys_table->boottime->free_pool, map);
10179 fail:
10180 return status;
10181 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10182 index 1e3184f..0d11e2e 100644
10183 --- a/arch/x86/boot/compressed/head_32.S
10184 +++ b/arch/x86/boot/compressed/head_32.S
10185 @@ -118,7 +118,7 @@ preferred_addr:
10186 notl %eax
10187 andl %eax, %ebx
10188 #else
10189 - movl $LOAD_PHYSICAL_ADDR, %ebx
10190 + movl $____LOAD_PHYSICAL_ADDR, %ebx
10191 #endif
10192
10193 /* Target address to relocate to for decompression */
10194 @@ -204,7 +204,7 @@ relocated:
10195 * and where it was actually loaded.
10196 */
10197 movl %ebp, %ebx
10198 - subl $LOAD_PHYSICAL_ADDR, %ebx
10199 + subl $____LOAD_PHYSICAL_ADDR, %ebx
10200 jz 2f /* Nothing to be done if loaded at compiled addr. */
10201 /*
10202 * Process relocations.
10203 @@ -212,8 +212,7 @@ relocated:
10204
10205 1: subl $4, %edi
10206 movl (%edi), %ecx
10207 - testl %ecx, %ecx
10208 - jz 2f
10209 + jecxz 2f
10210 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10211 jmp 1b
10212 2:
10213 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10214 index f5d1aaa..cce11dc 100644
10215 --- a/arch/x86/boot/compressed/head_64.S
10216 +++ b/arch/x86/boot/compressed/head_64.S
10217 @@ -91,7 +91,7 @@ ENTRY(startup_32)
10218 notl %eax
10219 andl %eax, %ebx
10220 #else
10221 - movl $LOAD_PHYSICAL_ADDR, %ebx
10222 + movl $____LOAD_PHYSICAL_ADDR, %ebx
10223 #endif
10224
10225 /* Target address to relocate to for decompression */
10226 @@ -273,7 +273,7 @@ preferred_addr:
10227 notq %rax
10228 andq %rax, %rbp
10229 #else
10230 - movq $LOAD_PHYSICAL_ADDR, %rbp
10231 + movq $____LOAD_PHYSICAL_ADDR, %rbp
10232 #endif
10233
10234 /* Target address to relocate to for decompression */
10235 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10236 index 88f7ff6..ed695dd 100644
10237 --- a/arch/x86/boot/compressed/misc.c
10238 +++ b/arch/x86/boot/compressed/misc.c
10239 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
10240 case PT_LOAD:
10241 #ifdef CONFIG_RELOCATABLE
10242 dest = output;
10243 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10244 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10245 #else
10246 dest = (void *)(phdr->p_paddr);
10247 #endif
10248 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10249 error("Destination address too large");
10250 #endif
10251 #ifndef CONFIG_RELOCATABLE
10252 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10253 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10254 error("Wrong destination address");
10255 #endif
10256
10257 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10258 index 4d3ff03..e4972ff 100644
10259 --- a/arch/x86/boot/cpucheck.c
10260 +++ b/arch/x86/boot/cpucheck.c
10261 @@ -74,7 +74,7 @@ static int has_fpu(void)
10262 u16 fcw = -1, fsw = -1;
10263 u32 cr0;
10264
10265 - asm("movl %%cr0,%0" : "=r" (cr0));
10266 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
10267 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10268 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10269 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10270 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10271 {
10272 u32 f0, f1;
10273
10274 - asm("pushfl ; "
10275 + asm volatile("pushfl ; "
10276 "pushfl ; "
10277 "popl %0 ; "
10278 "movl %0,%1 ; "
10279 @@ -115,7 +115,7 @@ static void get_flags(void)
10280 set_bit(X86_FEATURE_FPU, cpu.flags);
10281
10282 if (has_eflag(X86_EFLAGS_ID)) {
10283 - asm("cpuid"
10284 + asm volatile("cpuid"
10285 : "=a" (max_intel_level),
10286 "=b" (cpu_vendor[0]),
10287 "=d" (cpu_vendor[1]),
10288 @@ -124,7 +124,7 @@ static void get_flags(void)
10289
10290 if (max_intel_level >= 0x00000001 &&
10291 max_intel_level <= 0x0000ffff) {
10292 - asm("cpuid"
10293 + asm volatile("cpuid"
10294 : "=a" (tfms),
10295 "=c" (cpu.flags[4]),
10296 "=d" (cpu.flags[0])
10297 @@ -136,7 +136,7 @@ static void get_flags(void)
10298 cpu.model += ((tfms >> 16) & 0xf) << 4;
10299 }
10300
10301 - asm("cpuid"
10302 + asm volatile("cpuid"
10303 : "=a" (max_amd_level)
10304 : "a" (0x80000000)
10305 : "ebx", "ecx", "edx");
10306 @@ -144,7 +144,7 @@ static void get_flags(void)
10307 if (max_amd_level >= 0x80000001 &&
10308 max_amd_level <= 0x8000ffff) {
10309 u32 eax = 0x80000001;
10310 - asm("cpuid"
10311 + asm volatile("cpuid"
10312 : "+a" (eax),
10313 "=c" (cpu.flags[6]),
10314 "=d" (cpu.flags[1])
10315 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10316 u32 ecx = MSR_K7_HWCR;
10317 u32 eax, edx;
10318
10319 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10320 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10321 eax &= ~(1 << 15);
10322 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10323 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10324
10325 get_flags(); /* Make sure it really did something */
10326 err = check_flags();
10327 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10328 u32 ecx = MSR_VIA_FCR;
10329 u32 eax, edx;
10330
10331 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10332 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10333 eax |= (1<<1)|(1<<7);
10334 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10335 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10336
10337 set_bit(X86_FEATURE_CX8, cpu.flags);
10338 err = check_flags();
10339 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10340 u32 eax, edx;
10341 u32 level = 1;
10342
10343 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10344 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10345 - asm("cpuid"
10346 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10347 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10348 + asm volatile("cpuid"
10349 : "+a" (level), "=d" (cpu.flags[0])
10350 : : "ecx", "ebx");
10351 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10352 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10353
10354 err = check_flags();
10355 }
10356 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10357 index 944ce59..87ee37a 100644
10358 --- a/arch/x86/boot/header.S
10359 +++ b/arch/x86/boot/header.S
10360 @@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10361 # single linked list of
10362 # struct setup_data
10363
10364 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10365 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10366
10367 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10368 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10369 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10370 +#else
10371 #define VO_INIT_SIZE (VO__end - VO__text)
10372 +#endif
10373 #if ZO_INIT_SIZE > VO_INIT_SIZE
10374 #define INIT_SIZE ZO_INIT_SIZE
10375 #else
10376 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10377 index db75d07..8e6d0af 100644
10378 --- a/arch/x86/boot/memory.c
10379 +++ b/arch/x86/boot/memory.c
10380 @@ -19,7 +19,7 @@
10381
10382 static int detect_memory_e820(void)
10383 {
10384 - int count = 0;
10385 + unsigned int count = 0;
10386 struct biosregs ireg, oreg;
10387 struct e820entry *desc = boot_params.e820_map;
10388 static struct e820entry buf; /* static so it is zeroed */
10389 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10390 index 11e8c6e..fdbb1ed 100644
10391 --- a/arch/x86/boot/video-vesa.c
10392 +++ b/arch/x86/boot/video-vesa.c
10393 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10394
10395 boot_params.screen_info.vesapm_seg = oreg.es;
10396 boot_params.screen_info.vesapm_off = oreg.di;
10397 + boot_params.screen_info.vesapm_size = oreg.cx;
10398 }
10399
10400 /*
10401 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10402 index 43eda28..5ab5fdb 100644
10403 --- a/arch/x86/boot/video.c
10404 +++ b/arch/x86/boot/video.c
10405 @@ -96,7 +96,7 @@ static void store_mode_params(void)
10406 static unsigned int get_entry(void)
10407 {
10408 char entry_buf[4];
10409 - int i, len = 0;
10410 + unsigned int i, len = 0;
10411 int key;
10412 unsigned int v;
10413
10414 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10415 index 5b577d5..3c1fed4 100644
10416 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
10417 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10418 @@ -8,6 +8,8 @@
10419 * including this sentence is retained in full.
10420 */
10421
10422 +#include <asm/alternative-asm.h>
10423 +
10424 .extern crypto_ft_tab
10425 .extern crypto_it_tab
10426 .extern crypto_fl_tab
10427 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
10428 je B192; \
10429 leaq 32(r9),r9;
10430
10431 +#define ret pax_force_retaddr 0, 1; ret
10432 +
10433 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10434 movq r1,r2; \
10435 movq r3,r4; \
10436 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10437 index 3470624..201259d 100644
10438 --- a/arch/x86/crypto/aesni-intel_asm.S
10439 +++ b/arch/x86/crypto/aesni-intel_asm.S
10440 @@ -31,6 +31,7 @@
10441
10442 #include <linux/linkage.h>
10443 #include <asm/inst.h>
10444 +#include <asm/alternative-asm.h>
10445
10446 #ifdef __x86_64__
10447 .data
10448 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
10449 pop %r14
10450 pop %r13
10451 pop %r12
10452 + pax_force_retaddr 0, 1
10453 ret
10454 +ENDPROC(aesni_gcm_dec)
10455
10456
10457 /*****************************************************************************
10458 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
10459 pop %r14
10460 pop %r13
10461 pop %r12
10462 + pax_force_retaddr 0, 1
10463 ret
10464 +ENDPROC(aesni_gcm_enc)
10465
10466 #endif
10467
10468 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
10469 pxor %xmm1, %xmm0
10470 movaps %xmm0, (TKEYP)
10471 add $0x10, TKEYP
10472 + pax_force_retaddr_bts
10473 ret
10474
10475 .align 4
10476 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
10477 shufps $0b01001110, %xmm2, %xmm1
10478 movaps %xmm1, 0x10(TKEYP)
10479 add $0x20, TKEYP
10480 + pax_force_retaddr_bts
10481 ret
10482
10483 .align 4
10484 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
10485
10486 movaps %xmm0, (TKEYP)
10487 add $0x10, TKEYP
10488 + pax_force_retaddr_bts
10489 ret
10490
10491 .align 4
10492 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
10493 pxor %xmm1, %xmm2
10494 movaps %xmm2, (TKEYP)
10495 add $0x10, TKEYP
10496 + pax_force_retaddr_bts
10497 ret
10498
10499 /*
10500 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
10501 #ifndef __x86_64__
10502 popl KEYP
10503 #endif
10504 + pax_force_retaddr 0, 1
10505 ret
10506 +ENDPROC(aesni_set_key)
10507
10508 /*
10509 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
10510 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
10511 popl KLEN
10512 popl KEYP
10513 #endif
10514 + pax_force_retaddr 0, 1
10515 ret
10516 +ENDPROC(aesni_enc)
10517
10518 /*
10519 * _aesni_enc1: internal ABI
10520 @@ -1959,6 +1972,7 @@ _aesni_enc1:
10521 AESENC KEY STATE
10522 movaps 0x70(TKEYP), KEY
10523 AESENCLAST KEY STATE
10524 + pax_force_retaddr_bts
10525 ret
10526
10527 /*
10528 @@ -2067,6 +2081,7 @@ _aesni_enc4:
10529 AESENCLAST KEY STATE2
10530 AESENCLAST KEY STATE3
10531 AESENCLAST KEY STATE4
10532 + pax_force_retaddr_bts
10533 ret
10534
10535 /*
10536 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
10537 popl KLEN
10538 popl KEYP
10539 #endif
10540 + pax_force_retaddr 0, 1
10541 ret
10542 +ENDPROC(aesni_dec)
10543
10544 /*
10545 * _aesni_dec1: internal ABI
10546 @@ -2146,6 +2163,7 @@ _aesni_dec1:
10547 AESDEC KEY STATE
10548 movaps 0x70(TKEYP), KEY
10549 AESDECLAST KEY STATE
10550 + pax_force_retaddr_bts
10551 ret
10552
10553 /*
10554 @@ -2254,6 +2272,7 @@ _aesni_dec4:
10555 AESDECLAST KEY STATE2
10556 AESDECLAST KEY STATE3
10557 AESDECLAST KEY STATE4
10558 + pax_force_retaddr_bts
10559 ret
10560
10561 /*
10562 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
10563 popl KEYP
10564 popl LEN
10565 #endif
10566 + pax_force_retaddr 0, 1
10567 ret
10568 +ENDPROC(aesni_ecb_enc)
10569
10570 /*
10571 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10572 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
10573 popl KEYP
10574 popl LEN
10575 #endif
10576 + pax_force_retaddr 0, 1
10577 ret
10578 +ENDPROC(aesni_ecb_dec)
10579
10580 /*
10581 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10582 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
10583 popl LEN
10584 popl IVP
10585 #endif
10586 + pax_force_retaddr 0, 1
10587 ret
10588 +ENDPROC(aesni_cbc_enc)
10589
10590 /*
10591 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10592 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
10593 popl LEN
10594 popl IVP
10595 #endif
10596 + pax_force_retaddr 0, 1
10597 ret
10598 +ENDPROC(aesni_cbc_dec)
10599
10600 #ifdef __x86_64__
10601 .align 16
10602 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
10603 mov $1, TCTR_LOW
10604 MOVQ_R64_XMM TCTR_LOW INC
10605 MOVQ_R64_XMM CTR TCTR_LOW
10606 + pax_force_retaddr_bts
10607 ret
10608
10609 /*
10610 @@ -2554,6 +2582,7 @@ _aesni_inc:
10611 .Linc_low:
10612 movaps CTR, IV
10613 PSHUFB_XMM BSWAP_MASK IV
10614 + pax_force_retaddr_bts
10615 ret
10616
10617 /*
10618 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
10619 .Lctr_enc_ret:
10620 movups IV, (IVP)
10621 .Lctr_enc_just_ret:
10622 + pax_force_retaddr 0, 1
10623 ret
10624 +ENDPROC(aesni_ctr_enc)
10625 #endif
10626 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10627 index 391d245..67f35c2 100644
10628 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10629 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10630 @@ -20,6 +20,8 @@
10631 *
10632 */
10633
10634 +#include <asm/alternative-asm.h>
10635 +
10636 .file "blowfish-x86_64-asm.S"
10637 .text
10638
10639 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
10640 jnz __enc_xor;
10641
10642 write_block();
10643 + pax_force_retaddr 0, 1
10644 ret;
10645 __enc_xor:
10646 xor_block();
10647 + pax_force_retaddr 0, 1
10648 ret;
10649
10650 .align 8
10651 @@ -188,6 +192,7 @@ blowfish_dec_blk:
10652
10653 movq %r11, %rbp;
10654
10655 + pax_force_retaddr 0, 1
10656 ret;
10657
10658 /**********************************************************************
10659 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
10660
10661 popq %rbx;
10662 popq %rbp;
10663 + pax_force_retaddr 0, 1
10664 ret;
10665
10666 __enc_xor4:
10667 @@ -349,6 +355,7 @@ __enc_xor4:
10668
10669 popq %rbx;
10670 popq %rbp;
10671 + pax_force_retaddr 0, 1
10672 ret;
10673
10674 .align 8
10675 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
10676 popq %rbx;
10677 popq %rbp;
10678
10679 + pax_force_retaddr 0, 1
10680 ret;
10681
10682 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10683 index 0b33743..7a56206 100644
10684 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10685 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10686 @@ -20,6 +20,8 @@
10687 *
10688 */
10689
10690 +#include <asm/alternative-asm.h>
10691 +
10692 .file "camellia-x86_64-asm_64.S"
10693 .text
10694
10695 @@ -229,12 +231,14 @@ __enc_done:
10696 enc_outunpack(mov, RT1);
10697
10698 movq RRBP, %rbp;
10699 + pax_force_retaddr 0, 1
10700 ret;
10701
10702 __enc_xor:
10703 enc_outunpack(xor, RT1);
10704
10705 movq RRBP, %rbp;
10706 + pax_force_retaddr 0, 1
10707 ret;
10708
10709 .global camellia_dec_blk;
10710 @@ -275,6 +279,7 @@ __dec_rounds16:
10711 dec_outunpack();
10712
10713 movq RRBP, %rbp;
10714 + pax_force_retaddr 0, 1
10715 ret;
10716
10717 /**********************************************************************
10718 @@ -468,6 +473,7 @@ __enc2_done:
10719
10720 movq RRBP, %rbp;
10721 popq %rbx;
10722 + pax_force_retaddr 0, 1
10723 ret;
10724
10725 __enc2_xor:
10726 @@ -475,6 +481,7 @@ __enc2_xor:
10727
10728 movq RRBP, %rbp;
10729 popq %rbx;
10730 + pax_force_retaddr 0, 1
10731 ret;
10732
10733 .global camellia_dec_blk_2way;
10734 @@ -517,4 +524,5 @@ __dec2_rounds16:
10735
10736 movq RRBP, %rbp;
10737 movq RXOR, %rbx;
10738 + pax_force_retaddr 0, 1
10739 ret;
10740 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10741 index 15b00ac..2071784 100644
10742 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10743 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10744 @@ -23,6 +23,8 @@
10745 *
10746 */
10747
10748 +#include <asm/alternative-asm.h>
10749 +
10750 .file "cast5-avx-x86_64-asm_64.S"
10751
10752 .extern cast_s1
10753 @@ -281,6 +283,7 @@ __skip_enc:
10754 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10755 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10756
10757 + pax_force_retaddr 0, 1
10758 ret;
10759
10760 .align 16
10761 @@ -353,6 +356,7 @@ __dec_tail:
10762 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10763 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10764
10765 + pax_force_retaddr 0, 1
10766 ret;
10767
10768 __skip_dec:
10769 @@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
10770 vmovdqu RR4, (6*4*4)(%r11);
10771 vmovdqu RL4, (7*4*4)(%r11);
10772
10773 + pax_force_retaddr
10774 ret;
10775
10776 .align 16
10777 @@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
10778 vmovdqu RR4, (6*4*4)(%r11);
10779 vmovdqu RL4, (7*4*4)(%r11);
10780
10781 + pax_force_retaddr
10782 ret;
10783
10784 .align 16
10785 @@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
10786
10787 popq %r12;
10788
10789 + pax_force_retaddr
10790 ret;
10791
10792 .align 16
10793 @@ -555,4 +562,5 @@ cast5_ctr_16way:
10794
10795 popq %r12;
10796
10797 + pax_force_retaddr
10798 ret;
10799 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10800 index 2569d0d..637c289 100644
10801 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10802 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10803 @@ -23,6 +23,8 @@
10804 *
10805 */
10806
10807 +#include <asm/alternative-asm.h>
10808 +
10809 #include "glue_helper-asm-avx.S"
10810
10811 .file "cast6-avx-x86_64-asm_64.S"
10812 @@ -294,6 +296,7 @@ __cast6_enc_blk8:
10813 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10814 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10815
10816 + pax_force_retaddr 0, 1
10817 ret;
10818
10819 .align 8
10820 @@ -340,6 +343,7 @@ __cast6_dec_blk8:
10821 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10822 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10823
10824 + pax_force_retaddr 0, 1
10825 ret;
10826
10827 .align 8
10828 @@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
10829
10830 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10831
10832 + pax_force_retaddr
10833 ret;
10834
10835 .align 8
10836 @@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
10837
10838 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10839
10840 + pax_force_retaddr
10841 ret;
10842
10843 .align 8
10844 @@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
10845
10846 popq %r12;
10847
10848 + pax_force_retaddr
10849 ret;
10850
10851 .align 8
10852 @@ -436,4 +443,5 @@ cast6_ctr_8way:
10853
10854 popq %r12;
10855
10856 + pax_force_retaddr
10857 ret;
10858 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10859 index 6214a9b..1f4fc9a 100644
10860 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
10861 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10862 @@ -1,3 +1,5 @@
10863 +#include <asm/alternative-asm.h>
10864 +
10865 # enter ECRYPT_encrypt_bytes
10866 .text
10867 .p2align 5
10868 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
10869 add %r11,%rsp
10870 mov %rdi,%rax
10871 mov %rsi,%rdx
10872 + pax_force_retaddr 0, 1
10873 ret
10874 # bytesatleast65:
10875 ._bytesatleast65:
10876 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
10877 add %r11,%rsp
10878 mov %rdi,%rax
10879 mov %rsi,%rdx
10880 + pax_force_retaddr
10881 ret
10882 # enter ECRYPT_ivsetup
10883 .text
10884 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
10885 add %r11,%rsp
10886 mov %rdi,%rax
10887 mov %rsi,%rdx
10888 + pax_force_retaddr
10889 ret
10890 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10891 index 02b0e9f..cf4cf5c 100644
10892 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10893 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10894 @@ -24,6 +24,8 @@
10895 *
10896 */
10897
10898 +#include <asm/alternative-asm.h>
10899 +
10900 #include "glue_helper-asm-avx.S"
10901
10902 .file "serpent-avx-x86_64-asm_64.S"
10903 @@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
10904 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10905 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10906
10907 + pax_force_retaddr
10908 ret;
10909
10910 .align 8
10911 @@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
10912 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10913 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10914
10915 + pax_force_retaddr
10916 ret;
10917
10918 .align 8
10919 @@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
10920
10921 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10922
10923 + pax_force_retaddr
10924 ret;
10925
10926 .align 8
10927 @@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
10928
10929 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10930
10931 + pax_force_retaddr
10932 ret;
10933
10934 .align 8
10935 @@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
10936
10937 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10938
10939 + pax_force_retaddr
10940 ret;
10941
10942 .align 8
10943 @@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
10944
10945 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10946
10947 + pax_force_retaddr
10948 ret;
10949 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10950 index 3ee1ff0..cbc568b 100644
10951 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10952 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10953 @@ -24,6 +24,8 @@
10954 *
10955 */
10956
10957 +#include <asm/alternative-asm.h>
10958 +
10959 .file "serpent-sse2-x86_64-asm_64.S"
10960 .text
10961
10962 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
10963 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10964 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10965
10966 + pax_force_retaddr
10967 ret;
10968
10969 __enc_xor8:
10970 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10971 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10972
10973 + pax_force_retaddr
10974 ret;
10975
10976 .align 8
10977 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
10978 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10979 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10980
10981 + pax_force_retaddr
10982 ret;
10983 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
10984 index 49d6987..df66bd4 100644
10985 --- a/arch/x86/crypto/sha1_ssse3_asm.S
10986 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
10987 @@ -28,6 +28,8 @@
10988 * (at your option) any later version.
10989 */
10990
10991 +#include <asm/alternative-asm.h>
10992 +
10993 #define CTX %rdi // arg1
10994 #define BUF %rsi // arg2
10995 #define CNT %rdx // arg3
10996 @@ -104,6 +106,7 @@
10997 pop %r12
10998 pop %rbp
10999 pop %rbx
11000 + pax_force_retaddr 0, 1
11001 ret
11002
11003 .size \name, .-\name
11004 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11005 index ebac16b..8092eb9 100644
11006 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11007 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11008 @@ -23,6 +23,8 @@
11009 *
11010 */
11011
11012 +#include <asm/alternative-asm.h>
11013 +
11014 #include "glue_helper-asm-avx.S"
11015
11016 .file "twofish-avx-x86_64-asm_64.S"
11017 @@ -283,6 +285,7 @@ __twofish_enc_blk8:
11018 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11019 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11020
11021 + pax_force_retaddr 0, 1
11022 ret;
11023
11024 .align 8
11025 @@ -324,6 +327,7 @@ __twofish_dec_blk8:
11026 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11027 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11028
11029 + pax_force_retaddr 0, 1
11030 ret;
11031
11032 .align 8
11033 @@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
11034
11035 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11036
11037 + pax_force_retaddr 0, 1
11038 ret;
11039
11040 .align 8
11041 @@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
11042
11043 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11044
11045 + pax_force_retaddr 0, 1
11046 ret;
11047
11048 .align 8
11049 @@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
11050
11051 popq %r12;
11052
11053 + pax_force_retaddr 0, 1
11054 ret;
11055
11056 .align 8
11057 @@ -420,4 +427,5 @@ twofish_ctr_8way:
11058
11059 popq %r12;
11060
11061 + pax_force_retaddr 0, 1
11062 ret;
11063 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11064 index 5b012a2..36d5364 100644
11065 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11066 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11067 @@ -20,6 +20,8 @@
11068 *
11069 */
11070
11071 +#include <asm/alternative-asm.h>
11072 +
11073 .file "twofish-x86_64-asm-3way.S"
11074 .text
11075
11076 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
11077 popq %r13;
11078 popq %r14;
11079 popq %r15;
11080 + pax_force_retaddr 0, 1
11081 ret;
11082
11083 __enc_xor3:
11084 @@ -271,6 +274,7 @@ __enc_xor3:
11085 popq %r13;
11086 popq %r14;
11087 popq %r15;
11088 + pax_force_retaddr 0, 1
11089 ret;
11090
11091 .global twofish_dec_blk_3way
11092 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11093 popq %r13;
11094 popq %r14;
11095 popq %r15;
11096 + pax_force_retaddr 0, 1
11097 ret;
11098
11099 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11100 index 7bcf3fc..f53832f 100644
11101 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11102 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11103 @@ -21,6 +21,7 @@
11104 .text
11105
11106 #include <asm/asm-offsets.h>
11107 +#include <asm/alternative-asm.h>
11108
11109 #define a_offset 0
11110 #define b_offset 4
11111 @@ -268,6 +269,7 @@ twofish_enc_blk:
11112
11113 popq R1
11114 movq $1,%rax
11115 + pax_force_retaddr 0, 1
11116 ret
11117
11118 twofish_dec_blk:
11119 @@ -319,4 +321,5 @@ twofish_dec_blk:
11120
11121 popq R1
11122 movq $1,%rax
11123 + pax_force_retaddr 0, 1
11124 ret
11125 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11126 index a703af1..f5b9c36 100644
11127 --- a/arch/x86/ia32/ia32_aout.c
11128 +++ b/arch/x86/ia32/ia32_aout.c
11129 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11130 unsigned long dump_start, dump_size;
11131 struct user32 dump;
11132
11133 + memset(&dump, 0, sizeof(dump));
11134 +
11135 fs = get_fs();
11136 set_fs(KERNEL_DS);
11137 has_dumped = 1;
11138 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11139 index a1daf4a..f8c4537 100644
11140 --- a/arch/x86/ia32/ia32_signal.c
11141 +++ b/arch/x86/ia32/ia32_signal.c
11142 @@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11143 sp -= frame_size;
11144 /* Align the stack pointer according to the i386 ABI,
11145 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11146 - sp = ((sp + 4) & -16ul) - 4;
11147 + sp = ((sp - 12) & -16ul) - 4;
11148 return (void __user *) sp;
11149 }
11150
11151 @@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11152 * These are actually not used anymore, but left because some
11153 * gdb versions depend on them as a marker.
11154 */
11155 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11156 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11157 } put_user_catch(err);
11158
11159 if (err)
11160 @@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11161 0xb8,
11162 __NR_ia32_rt_sigreturn,
11163 0x80cd,
11164 - 0,
11165 + 0
11166 };
11167
11168 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11169 @@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11170
11171 if (ka->sa.sa_flags & SA_RESTORER)
11172 restorer = ka->sa.sa_restorer;
11173 + else if (current->mm->context.vdso)
11174 + /* Return stub is in 32bit vsyscall page */
11175 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11176 else
11177 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11178 - rt_sigreturn);
11179 + restorer = &frame->retcode;
11180 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11181
11182 /*
11183 * Not actually used anymore, but left because some gdb
11184 * versions need it.
11185 */
11186 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11187 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11188 } put_user_catch(err);
11189
11190 err |= copy_siginfo_to_user32(&frame->info, info);
11191 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11192 index 142c4ce..19b683f 100644
11193 --- a/arch/x86/ia32/ia32entry.S
11194 +++ b/arch/x86/ia32/ia32entry.S
11195 @@ -15,8 +15,10 @@
11196 #include <asm/irqflags.h>
11197 #include <asm/asm.h>
11198 #include <asm/smap.h>
11199 +#include <asm/pgtable.h>
11200 #include <linux/linkage.h>
11201 #include <linux/err.h>
11202 +#include <asm/alternative-asm.h>
11203
11204 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11205 #include <linux/elf-em.h>
11206 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11207 ENDPROC(native_irq_enable_sysexit)
11208 #endif
11209
11210 + .macro pax_enter_kernel_user
11211 + pax_set_fptr_mask
11212 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11213 + call pax_enter_kernel_user
11214 +#endif
11215 + .endm
11216 +
11217 + .macro pax_exit_kernel_user
11218 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11219 + call pax_exit_kernel_user
11220 +#endif
11221 +#ifdef CONFIG_PAX_RANDKSTACK
11222 + pushq %rax
11223 + pushq %r11
11224 + call pax_randomize_kstack
11225 + popq %r11
11226 + popq %rax
11227 +#endif
11228 + .endm
11229 +
11230 +.macro pax_erase_kstack
11231 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11232 + call pax_erase_kstack
11233 +#endif
11234 +.endm
11235 +
11236 /*
11237 * 32bit SYSENTER instruction entry.
11238 *
11239 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11240 CFI_REGISTER rsp,rbp
11241 SWAPGS_UNSAFE_STACK
11242 movq PER_CPU_VAR(kernel_stack), %rsp
11243 - addq $(KERNEL_STACK_OFFSET),%rsp
11244 - /*
11245 - * No need to follow this irqs on/off section: the syscall
11246 - * disabled irqs, here we enable it straight after entry:
11247 - */
11248 - ENABLE_INTERRUPTS(CLBR_NONE)
11249 movl %ebp,%ebp /* zero extension */
11250 pushq_cfi $__USER32_DS
11251 /*CFI_REL_OFFSET ss,0*/
11252 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11253 CFI_REL_OFFSET rsp,0
11254 pushfq_cfi
11255 /*CFI_REL_OFFSET rflags,0*/
11256 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11257 - CFI_REGISTER rip,r10
11258 + orl $X86_EFLAGS_IF,(%rsp)
11259 + GET_THREAD_INFO(%r11)
11260 + movl TI_sysenter_return(%r11), %r11d
11261 + CFI_REGISTER rip,r11
11262 pushq_cfi $__USER32_CS
11263 /*CFI_REL_OFFSET cs,0*/
11264 movl %eax, %eax
11265 - pushq_cfi %r10
11266 + pushq_cfi %r11
11267 CFI_REL_OFFSET rip,0
11268 pushq_cfi %rax
11269 cld
11270 SAVE_ARGS 0,1,0
11271 + pax_enter_kernel_user
11272 +
11273 +#ifdef CONFIG_PAX_RANDKSTACK
11274 + pax_erase_kstack
11275 +#endif
11276 +
11277 + /*
11278 + * No need to follow this irqs on/off section: the syscall
11279 + * disabled irqs, here we enable it straight after entry:
11280 + */
11281 + ENABLE_INTERRUPTS(CLBR_NONE)
11282 /* no need to do an access_ok check here because rbp has been
11283 32bit zero extended */
11284 +
11285 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11286 + mov $PAX_USER_SHADOW_BASE,%r11
11287 + add %r11,%rbp
11288 +#endif
11289 +
11290 ASM_STAC
11291 1: movl (%rbp),%ebp
11292 _ASM_EXTABLE(1b,ia32_badarg)
11293 ASM_CLAC
11294 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11295 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11296 + GET_THREAD_INFO(%r11)
11297 + orl $TS_COMPAT,TI_status(%r11)
11298 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11299 CFI_REMEMBER_STATE
11300 jnz sysenter_tracesys
11301 cmpq $(IA32_NR_syscalls-1),%rax
11302 @@ -162,12 +204,15 @@ sysenter_do_call:
11303 sysenter_dispatch:
11304 call *ia32_sys_call_table(,%rax,8)
11305 movq %rax,RAX-ARGOFFSET(%rsp)
11306 + GET_THREAD_INFO(%r11)
11307 DISABLE_INTERRUPTS(CLBR_NONE)
11308 TRACE_IRQS_OFF
11309 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11310 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11311 jnz sysexit_audit
11312 sysexit_from_sys_call:
11313 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11314 + pax_exit_kernel_user
11315 + pax_erase_kstack
11316 + andl $~TS_COMPAT,TI_status(%r11)
11317 /* clear IF, that popfq doesn't enable interrupts early */
11318 andl $~0x200,EFLAGS-R11(%rsp)
11319 movl RIP-R11(%rsp),%edx /* User %eip */
11320 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
11321 movl %eax,%esi /* 2nd arg: syscall number */
11322 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11323 call __audit_syscall_entry
11324 +
11325 + pax_erase_kstack
11326 +
11327 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11328 cmpq $(IA32_NR_syscalls-1),%rax
11329 ja ia32_badsys
11330 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
11331 .endm
11332
11333 .macro auditsys_exit exit
11334 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11335 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11336 jnz ia32_ret_from_sys_call
11337 TRACE_IRQS_ON
11338 ENABLE_INTERRUPTS(CLBR_NONE)
11339 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
11340 1: setbe %al /* 1 if error, 0 if not */
11341 movzbl %al,%edi /* zero-extend that into %edi */
11342 call __audit_syscall_exit
11343 + GET_THREAD_INFO(%r11)
11344 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11345 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11346 DISABLE_INTERRUPTS(CLBR_NONE)
11347 TRACE_IRQS_OFF
11348 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11349 + testl %edi,TI_flags(%r11)
11350 jz \exit
11351 CLEAR_RREGS -ARGOFFSET
11352 jmp int_with_check
11353 @@ -237,7 +286,7 @@ sysexit_audit:
11354
11355 sysenter_tracesys:
11356 #ifdef CONFIG_AUDITSYSCALL
11357 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11358 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11359 jz sysenter_auditsys
11360 #endif
11361 SAVE_REST
11362 @@ -249,6 +298,9 @@ sysenter_tracesys:
11363 RESTORE_REST
11364 cmpq $(IA32_NR_syscalls-1),%rax
11365 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11366 +
11367 + pax_erase_kstack
11368 +
11369 jmp sysenter_do_call
11370 CFI_ENDPROC
11371 ENDPROC(ia32_sysenter_target)
11372 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11373 ENTRY(ia32_cstar_target)
11374 CFI_STARTPROC32 simple
11375 CFI_SIGNAL_FRAME
11376 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11377 + CFI_DEF_CFA rsp,0
11378 CFI_REGISTER rip,rcx
11379 /*CFI_REGISTER rflags,r11*/
11380 SWAPGS_UNSAFE_STACK
11381 movl %esp,%r8d
11382 CFI_REGISTER rsp,r8
11383 movq PER_CPU_VAR(kernel_stack),%rsp
11384 + SAVE_ARGS 8*6,0,0
11385 + pax_enter_kernel_user
11386 +
11387 +#ifdef CONFIG_PAX_RANDKSTACK
11388 + pax_erase_kstack
11389 +#endif
11390 +
11391 /*
11392 * No need to follow this irqs on/off section: the syscall
11393 * disabled irqs and here we enable it straight after entry:
11394 */
11395 ENABLE_INTERRUPTS(CLBR_NONE)
11396 - SAVE_ARGS 8,0,0
11397 movl %eax,%eax /* zero extension */
11398 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11399 movq %rcx,RIP-ARGOFFSET(%rsp)
11400 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11401 /* no need to do an access_ok check here because r8 has been
11402 32bit zero extended */
11403 /* hardware stack frame is complete now */
11404 +
11405 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11406 + mov $PAX_USER_SHADOW_BASE,%r11
11407 + add %r11,%r8
11408 +#endif
11409 +
11410 ASM_STAC
11411 1: movl (%r8),%r9d
11412 _ASM_EXTABLE(1b,ia32_badarg)
11413 ASM_CLAC
11414 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11415 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11416 + GET_THREAD_INFO(%r11)
11417 + orl $TS_COMPAT,TI_status(%r11)
11418 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11419 CFI_REMEMBER_STATE
11420 jnz cstar_tracesys
11421 cmpq $IA32_NR_syscalls-1,%rax
11422 @@ -319,12 +384,15 @@ cstar_do_call:
11423 cstar_dispatch:
11424 call *ia32_sys_call_table(,%rax,8)
11425 movq %rax,RAX-ARGOFFSET(%rsp)
11426 + GET_THREAD_INFO(%r11)
11427 DISABLE_INTERRUPTS(CLBR_NONE)
11428 TRACE_IRQS_OFF
11429 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11430 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11431 jnz sysretl_audit
11432 sysretl_from_sys_call:
11433 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11434 + pax_exit_kernel_user
11435 + pax_erase_kstack
11436 + andl $~TS_COMPAT,TI_status(%r11)
11437 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11438 movl RIP-ARGOFFSET(%rsp),%ecx
11439 CFI_REGISTER rip,rcx
11440 @@ -352,7 +420,7 @@ sysretl_audit:
11441
11442 cstar_tracesys:
11443 #ifdef CONFIG_AUDITSYSCALL
11444 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11445 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11446 jz cstar_auditsys
11447 #endif
11448 xchgl %r9d,%ebp
11449 @@ -366,6 +434,9 @@ cstar_tracesys:
11450 xchgl %ebp,%r9d
11451 cmpq $(IA32_NR_syscalls-1),%rax
11452 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11453 +
11454 + pax_erase_kstack
11455 +
11456 jmp cstar_do_call
11457 END(ia32_cstar_target)
11458
11459 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11460 CFI_REL_OFFSET rip,RIP-RIP
11461 PARAVIRT_ADJUST_EXCEPTION_FRAME
11462 SWAPGS
11463 - /*
11464 - * No need to follow this irqs on/off section: the syscall
11465 - * disabled irqs and here we enable it straight after entry:
11466 - */
11467 - ENABLE_INTERRUPTS(CLBR_NONE)
11468 movl %eax,%eax
11469 pushq_cfi %rax
11470 cld
11471 /* note the registers are not zero extended to the sf.
11472 this could be a problem. */
11473 SAVE_ARGS 0,1,0
11474 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11475 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11476 + pax_enter_kernel_user
11477 +
11478 +#ifdef CONFIG_PAX_RANDKSTACK
11479 + pax_erase_kstack
11480 +#endif
11481 +
11482 + /*
11483 + * No need to follow this irqs on/off section: the syscall
11484 + * disabled irqs and here we enable it straight after entry:
11485 + */
11486 + ENABLE_INTERRUPTS(CLBR_NONE)
11487 + GET_THREAD_INFO(%r11)
11488 + orl $TS_COMPAT,TI_status(%r11)
11489 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11490 jnz ia32_tracesys
11491 cmpq $(IA32_NR_syscalls-1),%rax
11492 ja ia32_badsys
11493 @@ -442,6 +520,9 @@ ia32_tracesys:
11494 RESTORE_REST
11495 cmpq $(IA32_NR_syscalls-1),%rax
11496 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11497 +
11498 + pax_erase_kstack
11499 +
11500 jmp ia32_do_call
11501 END(ia32_syscall)
11502
11503 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11504 index d0b689b..34be51d 100644
11505 --- a/arch/x86/ia32/sys_ia32.c
11506 +++ b/arch/x86/ia32/sys_ia32.c
11507 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11508 */
11509 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11510 {
11511 - typeof(ubuf->st_uid) uid = 0;
11512 - typeof(ubuf->st_gid) gid = 0;
11513 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
11514 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
11515 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11516 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11517 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11518 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11519 mm_segment_t old_fs = get_fs();
11520
11521 set_fs(KERNEL_DS);
11522 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
11523 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
11524 set_fs(old_fs);
11525 if (put_compat_timespec(&t, interval))
11526 return -EFAULT;
11527 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
11528 mm_segment_t old_fs = get_fs();
11529
11530 set_fs(KERNEL_DS);
11531 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
11532 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
11533 set_fs(old_fs);
11534 if (!ret) {
11535 switch (_NSIG_WORDS) {
11536 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
11537 if (copy_siginfo_from_user32(&info, uinfo))
11538 return -EFAULT;
11539 set_fs(KERNEL_DS);
11540 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
11541 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
11542 set_fs(old_fs);
11543 return ret;
11544 }
11545 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11546 return -EFAULT;
11547
11548 set_fs(KERNEL_DS);
11549 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11550 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11551 count);
11552 set_fs(old_fs);
11553
11554 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11555 index 372231c..a5aa1a1 100644
11556 --- a/arch/x86/include/asm/alternative-asm.h
11557 +++ b/arch/x86/include/asm/alternative-asm.h
11558 @@ -18,6 +18,45 @@
11559 .endm
11560 #endif
11561
11562 +#ifdef KERNEXEC_PLUGIN
11563 + .macro pax_force_retaddr_bts rip=0
11564 + btsq $63,\rip(%rsp)
11565 + .endm
11566 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11567 + .macro pax_force_retaddr rip=0, reload=0
11568 + btsq $63,\rip(%rsp)
11569 + .endm
11570 + .macro pax_force_fptr ptr
11571 + btsq $63,\ptr
11572 + .endm
11573 + .macro pax_set_fptr_mask
11574 + .endm
11575 +#endif
11576 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11577 + .macro pax_force_retaddr rip=0, reload=0
11578 + .if \reload
11579 + pax_set_fptr_mask
11580 + .endif
11581 + orq %r10,\rip(%rsp)
11582 + .endm
11583 + .macro pax_force_fptr ptr
11584 + orq %r10,\ptr
11585 + .endm
11586 + .macro pax_set_fptr_mask
11587 + movabs $0x8000000000000000,%r10
11588 + .endm
11589 +#endif
11590 +#else
11591 + .macro pax_force_retaddr rip=0, reload=0
11592 + .endm
11593 + .macro pax_force_fptr ptr
11594 + .endm
11595 + .macro pax_force_retaddr_bts rip=0
11596 + .endm
11597 + .macro pax_set_fptr_mask
11598 + .endm
11599 +#endif
11600 +
11601 .macro altinstruction_entry orig alt feature orig_len alt_len
11602 .long \orig - .
11603 .long \alt - .
11604 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11605 index 58ed6d9..f1cbe58 100644
11606 --- a/arch/x86/include/asm/alternative.h
11607 +++ b/arch/x86/include/asm/alternative.h
11608 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11609 ".pushsection .discard,\"aw\",@progbits\n" \
11610 DISCARD_ENTRY(1) \
11611 ".popsection\n" \
11612 - ".pushsection .altinstr_replacement, \"ax\"\n" \
11613 + ".pushsection .altinstr_replacement, \"a\"\n" \
11614 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11615 ".popsection"
11616
11617 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11618 DISCARD_ENTRY(1) \
11619 DISCARD_ENTRY(2) \
11620 ".popsection\n" \
11621 - ".pushsection .altinstr_replacement, \"ax\"\n" \
11622 + ".pushsection .altinstr_replacement, \"a\"\n" \
11623 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11624 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11625 ".popsection"
11626 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11627 index 3388034..050f0b9 100644
11628 --- a/arch/x86/include/asm/apic.h
11629 +++ b/arch/x86/include/asm/apic.h
11630 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11631
11632 #ifdef CONFIG_X86_LOCAL_APIC
11633
11634 -extern unsigned int apic_verbosity;
11635 +extern int apic_verbosity;
11636 extern int local_apic_timer_c2_ok;
11637
11638 extern int disable_apic;
11639 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11640 index 20370c6..a2eb9b0 100644
11641 --- a/arch/x86/include/asm/apm.h
11642 +++ b/arch/x86/include/asm/apm.h
11643 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11644 __asm__ __volatile__(APM_DO_ZERO_SEGS
11645 "pushl %%edi\n\t"
11646 "pushl %%ebp\n\t"
11647 - "lcall *%%cs:apm_bios_entry\n\t"
11648 + "lcall *%%ss:apm_bios_entry\n\t"
11649 "setc %%al\n\t"
11650 "popl %%ebp\n\t"
11651 "popl %%edi\n\t"
11652 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11653 __asm__ __volatile__(APM_DO_ZERO_SEGS
11654 "pushl %%edi\n\t"
11655 "pushl %%ebp\n\t"
11656 - "lcall *%%cs:apm_bios_entry\n\t"
11657 + "lcall *%%ss:apm_bios_entry\n\t"
11658 "setc %%bl\n\t"
11659 "popl %%ebp\n\t"
11660 "popl %%edi\n\t"
11661 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11662 index 722aa3b..3a0bb27 100644
11663 --- a/arch/x86/include/asm/atomic.h
11664 +++ b/arch/x86/include/asm/atomic.h
11665 @@ -22,7 +22,18 @@
11666 */
11667 static inline int atomic_read(const atomic_t *v)
11668 {
11669 - return (*(volatile int *)&(v)->counter);
11670 + return (*(volatile const int *)&(v)->counter);
11671 +}
11672 +
11673 +/**
11674 + * atomic_read_unchecked - read atomic variable
11675 + * @v: pointer of type atomic_unchecked_t
11676 + *
11677 + * Atomically reads the value of @v.
11678 + */
11679 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11680 +{
11681 + return (*(volatile const int *)&(v)->counter);
11682 }
11683
11684 /**
11685 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11686 }
11687
11688 /**
11689 + * atomic_set_unchecked - set atomic variable
11690 + * @v: pointer of type atomic_unchecked_t
11691 + * @i: required value
11692 + *
11693 + * Atomically sets the value of @v to @i.
11694 + */
11695 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
11696 +{
11697 + v->counter = i;
11698 +}
11699 +
11700 +/**
11701 * atomic_add - add integer to atomic variable
11702 * @i: integer value to add
11703 * @v: pointer of type atomic_t
11704 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
11705 */
11706 static inline void atomic_add(int i, atomic_t *v)
11707 {
11708 - asm volatile(LOCK_PREFIX "addl %1,%0"
11709 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
11710 +
11711 +#ifdef CONFIG_PAX_REFCOUNT
11712 + "jno 0f\n"
11713 + LOCK_PREFIX "subl %1,%0\n"
11714 + "int $4\n0:\n"
11715 + _ASM_EXTABLE(0b, 0b)
11716 +#endif
11717 +
11718 + : "+m" (v->counter)
11719 + : "ir" (i));
11720 +}
11721 +
11722 +/**
11723 + * atomic_add_unchecked - add integer to atomic variable
11724 + * @i: integer value to add
11725 + * @v: pointer of type atomic_unchecked_t
11726 + *
11727 + * Atomically adds @i to @v.
11728 + */
11729 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
11730 +{
11731 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
11732 : "+m" (v->counter)
11733 : "ir" (i));
11734 }
11735 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
11736 */
11737 static inline void atomic_sub(int i, atomic_t *v)
11738 {
11739 - asm volatile(LOCK_PREFIX "subl %1,%0"
11740 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
11741 +
11742 +#ifdef CONFIG_PAX_REFCOUNT
11743 + "jno 0f\n"
11744 + LOCK_PREFIX "addl %1,%0\n"
11745 + "int $4\n0:\n"
11746 + _ASM_EXTABLE(0b, 0b)
11747 +#endif
11748 +
11749 + : "+m" (v->counter)
11750 + : "ir" (i));
11751 +}
11752 +
11753 +/**
11754 + * atomic_sub_unchecked - subtract integer from atomic variable
11755 + * @i: integer value to subtract
11756 + * @v: pointer of type atomic_unchecked_t
11757 + *
11758 + * Atomically subtracts @i from @v.
11759 + */
11760 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
11761 +{
11762 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
11763 : "+m" (v->counter)
11764 : "ir" (i));
11765 }
11766 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11767 {
11768 unsigned char c;
11769
11770 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
11771 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
11772 +
11773 +#ifdef CONFIG_PAX_REFCOUNT
11774 + "jno 0f\n"
11775 + LOCK_PREFIX "addl %2,%0\n"
11776 + "int $4\n0:\n"
11777 + _ASM_EXTABLE(0b, 0b)
11778 +#endif
11779 +
11780 + "sete %1\n"
11781 : "+m" (v->counter), "=qm" (c)
11782 : "ir" (i) : "memory");
11783 return c;
11784 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11785 */
11786 static inline void atomic_inc(atomic_t *v)
11787 {
11788 - asm volatile(LOCK_PREFIX "incl %0"
11789 + asm volatile(LOCK_PREFIX "incl %0\n"
11790 +
11791 +#ifdef CONFIG_PAX_REFCOUNT
11792 + "jno 0f\n"
11793 + LOCK_PREFIX "decl %0\n"
11794 + "int $4\n0:\n"
11795 + _ASM_EXTABLE(0b, 0b)
11796 +#endif
11797 +
11798 + : "+m" (v->counter));
11799 +}
11800 +
11801 +/**
11802 + * atomic_inc_unchecked - increment atomic variable
11803 + * @v: pointer of type atomic_unchecked_t
11804 + *
11805 + * Atomically increments @v by 1.
11806 + */
11807 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
11808 +{
11809 + asm volatile(LOCK_PREFIX "incl %0\n"
11810 : "+m" (v->counter));
11811 }
11812
11813 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
11814 */
11815 static inline void atomic_dec(atomic_t *v)
11816 {
11817 - asm volatile(LOCK_PREFIX "decl %0"
11818 + asm volatile(LOCK_PREFIX "decl %0\n"
11819 +
11820 +#ifdef CONFIG_PAX_REFCOUNT
11821 + "jno 0f\n"
11822 + LOCK_PREFIX "incl %0\n"
11823 + "int $4\n0:\n"
11824 + _ASM_EXTABLE(0b, 0b)
11825 +#endif
11826 +
11827 + : "+m" (v->counter));
11828 +}
11829 +
11830 +/**
11831 + * atomic_dec_unchecked - decrement atomic variable
11832 + * @v: pointer of type atomic_unchecked_t
11833 + *
11834 + * Atomically decrements @v by 1.
11835 + */
11836 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
11837 +{
11838 + asm volatile(LOCK_PREFIX "decl %0\n"
11839 : "+m" (v->counter));
11840 }
11841
11842 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
11843 {
11844 unsigned char c;
11845
11846 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
11847 + asm volatile(LOCK_PREFIX "decl %0\n"
11848 +
11849 +#ifdef CONFIG_PAX_REFCOUNT
11850 + "jno 0f\n"
11851 + LOCK_PREFIX "incl %0\n"
11852 + "int $4\n0:\n"
11853 + _ASM_EXTABLE(0b, 0b)
11854 +#endif
11855 +
11856 + "sete %1\n"
11857 : "+m" (v->counter), "=qm" (c)
11858 : : "memory");
11859 return c != 0;
11860 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
11861 {
11862 unsigned char c;
11863
11864 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
11865 + asm volatile(LOCK_PREFIX "incl %0\n"
11866 +
11867 +#ifdef CONFIG_PAX_REFCOUNT
11868 + "jno 0f\n"
11869 + LOCK_PREFIX "decl %0\n"
11870 + "int $4\n0:\n"
11871 + _ASM_EXTABLE(0b, 0b)
11872 +#endif
11873 +
11874 + "sete %1\n"
11875 + : "+m" (v->counter), "=qm" (c)
11876 + : : "memory");
11877 + return c != 0;
11878 +}
11879 +
11880 +/**
11881 + * atomic_inc_and_test_unchecked - increment and test
11882 + * @v: pointer of type atomic_unchecked_t
11883 + *
11884 + * Atomically increments @v by 1
11885 + * and returns true if the result is zero, or false for all
11886 + * other cases.
11887 + */
11888 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
11889 +{
11890 + unsigned char c;
11891 +
11892 + asm volatile(LOCK_PREFIX "incl %0\n"
11893 + "sete %1\n"
11894 : "+m" (v->counter), "=qm" (c)
11895 : : "memory");
11896 return c != 0;
11897 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11898 {
11899 unsigned char c;
11900
11901 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
11902 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
11903 +
11904 +#ifdef CONFIG_PAX_REFCOUNT
11905 + "jno 0f\n"
11906 + LOCK_PREFIX "subl %2,%0\n"
11907 + "int $4\n0:\n"
11908 + _ASM_EXTABLE(0b, 0b)
11909 +#endif
11910 +
11911 + "sets %1\n"
11912 : "+m" (v->counter), "=qm" (c)
11913 : "ir" (i) : "memory");
11914 return c;
11915 @@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11916 */
11917 static inline int atomic_add_return(int i, atomic_t *v)
11918 {
11919 + return i + xadd_check_overflow(&v->counter, i);
11920 +}
11921 +
11922 +/**
11923 + * atomic_add_return_unchecked - add integer and return
11924 + * @i: integer value to add
11925 + * @v: pointer of type atomic_unchecked_t
11926 + *
11927 + * Atomically adds @i to @v and returns @i + @v
11928 + */
11929 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
11930 +{
11931 return i + xadd(&v->counter, i);
11932 }
11933
11934 @@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
11935 }
11936
11937 #define atomic_inc_return(v) (atomic_add_return(1, v))
11938 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
11939 +{
11940 + return atomic_add_return_unchecked(1, v);
11941 +}
11942 #define atomic_dec_return(v) (atomic_sub_return(1, v))
11943
11944 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11945 @@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11946 return cmpxchg(&v->counter, old, new);
11947 }
11948
11949 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
11950 +{
11951 + return cmpxchg(&v->counter, old, new);
11952 +}
11953 +
11954 static inline int atomic_xchg(atomic_t *v, int new)
11955 {
11956 return xchg(&v->counter, new);
11957 }
11958
11959 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
11960 +{
11961 + return xchg(&v->counter, new);
11962 +}
11963 +
11964 /**
11965 * __atomic_add_unless - add unless the number is already a given value
11966 * @v: pointer of type atomic_t
11967 @@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
11968 */
11969 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11970 {
11971 - int c, old;
11972 + int c, old, new;
11973 c = atomic_read(v);
11974 for (;;) {
11975 - if (unlikely(c == (u)))
11976 + if (unlikely(c == u))
11977 break;
11978 - old = atomic_cmpxchg((v), c, c + (a));
11979 +
11980 + asm volatile("addl %2,%0\n"
11981 +
11982 +#ifdef CONFIG_PAX_REFCOUNT
11983 + "jno 0f\n"
11984 + "subl %2,%0\n"
11985 + "int $4\n0:\n"
11986 + _ASM_EXTABLE(0b, 0b)
11987 +#endif
11988 +
11989 + : "=r" (new)
11990 + : "0" (c), "ir" (a));
11991 +
11992 + old = atomic_cmpxchg(v, c, new);
11993 if (likely(old == c))
11994 break;
11995 c = old;
11996 @@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11997 }
11998
11999 /**
12000 + * atomic_inc_not_zero_hint - increment if not null
12001 + * @v: pointer of type atomic_t
12002 + * @hint: probable value of the atomic before the increment
12003 + *
12004 + * This version of atomic_inc_not_zero() gives a hint of probable
12005 + * value of the atomic. This helps processor to not read the memory
12006 + * before doing the atomic read/modify/write cycle, lowering
12007 + * number of bus transactions on some arches.
12008 + *
12009 + * Returns: 0 if increment was not done, 1 otherwise.
12010 + */
12011 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12012 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12013 +{
12014 + int val, c = hint, new;
12015 +
12016 + /* sanity test, should be removed by compiler if hint is a constant */
12017 + if (!hint)
12018 + return __atomic_add_unless(v, 1, 0);
12019 +
12020 + do {
12021 + asm volatile("incl %0\n"
12022 +
12023 +#ifdef CONFIG_PAX_REFCOUNT
12024 + "jno 0f\n"
12025 + "decl %0\n"
12026 + "int $4\n0:\n"
12027 + _ASM_EXTABLE(0b, 0b)
12028 +#endif
12029 +
12030 + : "=r" (new)
12031 + : "0" (c));
12032 +
12033 + val = atomic_cmpxchg(v, c, new);
12034 + if (val == c)
12035 + return 1;
12036 + c = val;
12037 + } while (c);
12038 +
12039 + return 0;
12040 +}
12041 +
12042 +/**
12043 * atomic_inc_short - increment of a short integer
12044 * @v: pointer to type int
12045 *
12046 @@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12047 #endif
12048
12049 /* These are x86-specific, used by some header files */
12050 -#define atomic_clear_mask(mask, addr) \
12051 - asm volatile(LOCK_PREFIX "andl %0,%1" \
12052 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
12053 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12054 +{
12055 + asm volatile(LOCK_PREFIX "andl %1,%0"
12056 + : "+m" (v->counter)
12057 + : "r" (~(mask))
12058 + : "memory");
12059 +}
12060
12061 -#define atomic_set_mask(mask, addr) \
12062 - asm volatile(LOCK_PREFIX "orl %0,%1" \
12063 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12064 - : "memory")
12065 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12066 +{
12067 + asm volatile(LOCK_PREFIX "andl %1,%0"
12068 + : "+m" (v->counter)
12069 + : "r" (~(mask))
12070 + : "memory");
12071 +}
12072 +
12073 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12074 +{
12075 + asm volatile(LOCK_PREFIX "orl %1,%0"
12076 + : "+m" (v->counter)
12077 + : "r" (mask)
12078 + : "memory");
12079 +}
12080 +
12081 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12082 +{
12083 + asm volatile(LOCK_PREFIX "orl %1,%0"
12084 + : "+m" (v->counter)
12085 + : "r" (mask)
12086 + : "memory");
12087 +}
12088
12089 /* Atomic operations are already serializing on x86 */
12090 #define smp_mb__before_atomic_dec() barrier()
12091 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12092 index b154de7..aadebd8 100644
12093 --- a/arch/x86/include/asm/atomic64_32.h
12094 +++ b/arch/x86/include/asm/atomic64_32.h
12095 @@ -12,6 +12,14 @@ typedef struct {
12096 u64 __aligned(8) counter;
12097 } atomic64_t;
12098
12099 +#ifdef CONFIG_PAX_REFCOUNT
12100 +typedef struct {
12101 + u64 __aligned(8) counter;
12102 +} atomic64_unchecked_t;
12103 +#else
12104 +typedef atomic64_t atomic64_unchecked_t;
12105 +#endif
12106 +
12107 #define ATOMIC64_INIT(val) { (val) }
12108
12109 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12110 @@ -37,21 +45,31 @@ typedef struct {
12111 ATOMIC64_DECL_ONE(sym##_386)
12112
12113 ATOMIC64_DECL_ONE(add_386);
12114 +ATOMIC64_DECL_ONE(add_unchecked_386);
12115 ATOMIC64_DECL_ONE(sub_386);
12116 +ATOMIC64_DECL_ONE(sub_unchecked_386);
12117 ATOMIC64_DECL_ONE(inc_386);
12118 +ATOMIC64_DECL_ONE(inc_unchecked_386);
12119 ATOMIC64_DECL_ONE(dec_386);
12120 +ATOMIC64_DECL_ONE(dec_unchecked_386);
12121 #endif
12122
12123 #define alternative_atomic64(f, out, in...) \
12124 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12125
12126 ATOMIC64_DECL(read);
12127 +ATOMIC64_DECL(read_unchecked);
12128 ATOMIC64_DECL(set);
12129 +ATOMIC64_DECL(set_unchecked);
12130 ATOMIC64_DECL(xchg);
12131 ATOMIC64_DECL(add_return);
12132 +ATOMIC64_DECL(add_return_unchecked);
12133 ATOMIC64_DECL(sub_return);
12134 +ATOMIC64_DECL(sub_return_unchecked);
12135 ATOMIC64_DECL(inc_return);
12136 +ATOMIC64_DECL(inc_return_unchecked);
12137 ATOMIC64_DECL(dec_return);
12138 +ATOMIC64_DECL(dec_return_unchecked);
12139 ATOMIC64_DECL(dec_if_positive);
12140 ATOMIC64_DECL(inc_not_zero);
12141 ATOMIC64_DECL(add_unless);
12142 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12143 }
12144
12145 /**
12146 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12147 + * @p: pointer to type atomic64_unchecked_t
12148 + * @o: expected value
12149 + * @n: new value
12150 + *
12151 + * Atomically sets @v to @n if it was equal to @o and returns
12152 + * the old value.
12153 + */
12154 +
12155 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12156 +{
12157 + return cmpxchg64(&v->counter, o, n);
12158 +}
12159 +
12160 +/**
12161 * atomic64_xchg - xchg atomic64 variable
12162 * @v: pointer to type atomic64_t
12163 * @n: value to assign
12164 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12165 }
12166
12167 /**
12168 + * atomic64_set_unchecked - set atomic64 variable
12169 + * @v: pointer to type atomic64_unchecked_t
12170 + * @n: value to assign
12171 + *
12172 + * Atomically sets the value of @v to @n.
12173 + */
12174 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12175 +{
12176 + unsigned high = (unsigned)(i >> 32);
12177 + unsigned low = (unsigned)i;
12178 + alternative_atomic64(set, /* no output */,
12179 + "S" (v), "b" (low), "c" (high)
12180 + : "eax", "edx", "memory");
12181 +}
12182 +
12183 +/**
12184 * atomic64_read - read atomic64 variable
12185 * @v: pointer to type atomic64_t
12186 *
12187 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12188 }
12189
12190 /**
12191 + * atomic64_read_unchecked - read atomic64 variable
12192 + * @v: pointer to type atomic64_unchecked_t
12193 + *
12194 + * Atomically reads the value of @v and returns it.
12195 + */
12196 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12197 +{
12198 + long long r;
12199 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12200 + return r;
12201 + }
12202 +
12203 +/**
12204 * atomic64_add_return - add and return
12205 * @i: integer value to add
12206 * @v: pointer to type atomic64_t
12207 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12208 return i;
12209 }
12210
12211 +/**
12212 + * atomic64_add_return_unchecked - add and return
12213 + * @i: integer value to add
12214 + * @v: pointer to type atomic64_unchecked_t
12215 + *
12216 + * Atomically adds @i to @v and returns @i + *@v
12217 + */
12218 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12219 +{
12220 + alternative_atomic64(add_return_unchecked,
12221 + ASM_OUTPUT2("+A" (i), "+c" (v)),
12222 + ASM_NO_INPUT_CLOBBER("memory"));
12223 + return i;
12224 +}
12225 +
12226 /*
12227 * Other variants with different arithmetic operators:
12228 */
12229 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12230 return a;
12231 }
12232
12233 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12234 +{
12235 + long long a;
12236 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
12237 + "S" (v) : "memory", "ecx");
12238 + return a;
12239 +}
12240 +
12241 static inline long long atomic64_dec_return(atomic64_t *v)
12242 {
12243 long long a;
12244 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12245 }
12246
12247 /**
12248 + * atomic64_add_unchecked - add integer to atomic64 variable
12249 + * @i: integer value to add
12250 + * @v: pointer to type atomic64_unchecked_t
12251 + *
12252 + * Atomically adds @i to @v.
12253 + */
12254 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12255 +{
12256 + __alternative_atomic64(add_unchecked, add_return_unchecked,
12257 + ASM_OUTPUT2("+A" (i), "+c" (v)),
12258 + ASM_NO_INPUT_CLOBBER("memory"));
12259 + return i;
12260 +}
12261 +
12262 +/**
12263 * atomic64_sub - subtract the atomic64 variable
12264 * @i: integer value to subtract
12265 * @v: pointer to type atomic64_t
12266 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12267 index 0e1cbfc..5623683 100644
12268 --- a/arch/x86/include/asm/atomic64_64.h
12269 +++ b/arch/x86/include/asm/atomic64_64.h
12270 @@ -18,7 +18,19 @@
12271 */
12272 static inline long atomic64_read(const atomic64_t *v)
12273 {
12274 - return (*(volatile long *)&(v)->counter);
12275 + return (*(volatile const long *)&(v)->counter);
12276 +}
12277 +
12278 +/**
12279 + * atomic64_read_unchecked - read atomic64 variable
12280 + * @v: pointer of type atomic64_unchecked_t
12281 + *
12282 + * Atomically reads the value of @v.
12283 + * Doesn't imply a read memory barrier.
12284 + */
12285 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12286 +{
12287 + return (*(volatile const long *)&(v)->counter);
12288 }
12289
12290 /**
12291 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12292 }
12293
12294 /**
12295 + * atomic64_set_unchecked - set atomic64 variable
12296 + * @v: pointer to type atomic64_unchecked_t
12297 + * @i: required value
12298 + *
12299 + * Atomically sets the value of @v to @i.
12300 + */
12301 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12302 +{
12303 + v->counter = i;
12304 +}
12305 +
12306 +/**
12307 * atomic64_add - add integer to atomic64 variable
12308 * @i: integer value to add
12309 * @v: pointer to type atomic64_t
12310 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12311 */
12312 static inline void atomic64_add(long i, atomic64_t *v)
12313 {
12314 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
12315 +
12316 +#ifdef CONFIG_PAX_REFCOUNT
12317 + "jno 0f\n"
12318 + LOCK_PREFIX "subq %1,%0\n"
12319 + "int $4\n0:\n"
12320 + _ASM_EXTABLE(0b, 0b)
12321 +#endif
12322 +
12323 + : "=m" (v->counter)
12324 + : "er" (i), "m" (v->counter));
12325 +}
12326 +
12327 +/**
12328 + * atomic64_add_unchecked - add integer to atomic64 variable
12329 + * @i: integer value to add
12330 + * @v: pointer to type atomic64_unchecked_t
12331 + *
12332 + * Atomically adds @i to @v.
12333 + */
12334 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12335 +{
12336 asm volatile(LOCK_PREFIX "addq %1,%0"
12337 : "=m" (v->counter)
12338 : "er" (i), "m" (v->counter));
12339 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12340 */
12341 static inline void atomic64_sub(long i, atomic64_t *v)
12342 {
12343 - asm volatile(LOCK_PREFIX "subq %1,%0"
12344 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
12345 +
12346 +#ifdef CONFIG_PAX_REFCOUNT
12347 + "jno 0f\n"
12348 + LOCK_PREFIX "addq %1,%0\n"
12349 + "int $4\n0:\n"
12350 + _ASM_EXTABLE(0b, 0b)
12351 +#endif
12352 +
12353 + : "=m" (v->counter)
12354 + : "er" (i), "m" (v->counter));
12355 +}
12356 +
12357 +/**
12358 + * atomic64_sub_unchecked - subtract the atomic64 variable
12359 + * @i: integer value to subtract
12360 + * @v: pointer to type atomic64_unchecked_t
12361 + *
12362 + * Atomically subtracts @i from @v.
12363 + */
12364 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12365 +{
12366 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
12367 : "=m" (v->counter)
12368 : "er" (i), "m" (v->counter));
12369 }
12370 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12371 {
12372 unsigned char c;
12373
12374 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12375 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
12376 +
12377 +#ifdef CONFIG_PAX_REFCOUNT
12378 + "jno 0f\n"
12379 + LOCK_PREFIX "addq %2,%0\n"
12380 + "int $4\n0:\n"
12381 + _ASM_EXTABLE(0b, 0b)
12382 +#endif
12383 +
12384 + "sete %1\n"
12385 : "=m" (v->counter), "=qm" (c)
12386 : "er" (i), "m" (v->counter) : "memory");
12387 return c;
12388 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12389 */
12390 static inline void atomic64_inc(atomic64_t *v)
12391 {
12392 + asm volatile(LOCK_PREFIX "incq %0\n"
12393 +
12394 +#ifdef CONFIG_PAX_REFCOUNT
12395 + "jno 0f\n"
12396 + LOCK_PREFIX "decq %0\n"
12397 + "int $4\n0:\n"
12398 + _ASM_EXTABLE(0b, 0b)
12399 +#endif
12400 +
12401 + : "=m" (v->counter)
12402 + : "m" (v->counter));
12403 +}
12404 +
12405 +/**
12406 + * atomic64_inc_unchecked - increment atomic64 variable
12407 + * @v: pointer to type atomic64_unchecked_t
12408 + *
12409 + * Atomically increments @v by 1.
12410 + */
12411 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12412 +{
12413 asm volatile(LOCK_PREFIX "incq %0"
12414 : "=m" (v->counter)
12415 : "m" (v->counter));
12416 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12417 */
12418 static inline void atomic64_dec(atomic64_t *v)
12419 {
12420 - asm volatile(LOCK_PREFIX "decq %0"
12421 + asm volatile(LOCK_PREFIX "decq %0\n"
12422 +
12423 +#ifdef CONFIG_PAX_REFCOUNT
12424 + "jno 0f\n"
12425 + LOCK_PREFIX "incq %0\n"
12426 + "int $4\n0:\n"
12427 + _ASM_EXTABLE(0b, 0b)
12428 +#endif
12429 +
12430 + : "=m" (v->counter)
12431 + : "m" (v->counter));
12432 +}
12433 +
12434 +/**
12435 + * atomic64_dec_unchecked - decrement atomic64 variable
12436 + * @v: pointer to type atomic64_t
12437 + *
12438 + * Atomically decrements @v by 1.
12439 + */
12440 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12441 +{
12442 + asm volatile(LOCK_PREFIX "decq %0\n"
12443 : "=m" (v->counter)
12444 : "m" (v->counter));
12445 }
12446 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12447 {
12448 unsigned char c;
12449
12450 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
12451 + asm volatile(LOCK_PREFIX "decq %0\n"
12452 +
12453 +#ifdef CONFIG_PAX_REFCOUNT
12454 + "jno 0f\n"
12455 + LOCK_PREFIX "incq %0\n"
12456 + "int $4\n0:\n"
12457 + _ASM_EXTABLE(0b, 0b)
12458 +#endif
12459 +
12460 + "sete %1\n"
12461 : "=m" (v->counter), "=qm" (c)
12462 : "m" (v->counter) : "memory");
12463 return c != 0;
12464 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12465 {
12466 unsigned char c;
12467
12468 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
12469 + asm volatile(LOCK_PREFIX "incq %0\n"
12470 +
12471 +#ifdef CONFIG_PAX_REFCOUNT
12472 + "jno 0f\n"
12473 + LOCK_PREFIX "decq %0\n"
12474 + "int $4\n0:\n"
12475 + _ASM_EXTABLE(0b, 0b)
12476 +#endif
12477 +
12478 + "sete %1\n"
12479 : "=m" (v->counter), "=qm" (c)
12480 : "m" (v->counter) : "memory");
12481 return c != 0;
12482 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12483 {
12484 unsigned char c;
12485
12486 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12487 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
12488 +
12489 +#ifdef CONFIG_PAX_REFCOUNT
12490 + "jno 0f\n"
12491 + LOCK_PREFIX "subq %2,%0\n"
12492 + "int $4\n0:\n"
12493 + _ASM_EXTABLE(0b, 0b)
12494 +#endif
12495 +
12496 + "sets %1\n"
12497 : "=m" (v->counter), "=qm" (c)
12498 : "er" (i), "m" (v->counter) : "memory");
12499 return c;
12500 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12501 */
12502 static inline long atomic64_add_return(long i, atomic64_t *v)
12503 {
12504 + return i + xadd_check_overflow(&v->counter, i);
12505 +}
12506 +
12507 +/**
12508 + * atomic64_add_return_unchecked - add and return
12509 + * @i: integer value to add
12510 + * @v: pointer to type atomic64_unchecked_t
12511 + *
12512 + * Atomically adds @i to @v and returns @i + @v
12513 + */
12514 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12515 +{
12516 return i + xadd(&v->counter, i);
12517 }
12518
12519 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12520 }
12521
12522 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12523 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12524 +{
12525 + return atomic64_add_return_unchecked(1, v);
12526 +}
12527 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12528
12529 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12530 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12531 return cmpxchg(&v->counter, old, new);
12532 }
12533
12534 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12535 +{
12536 + return cmpxchg(&v->counter, old, new);
12537 +}
12538 +
12539 static inline long atomic64_xchg(atomic64_t *v, long new)
12540 {
12541 return xchg(&v->counter, new);
12542 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12543 */
12544 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12545 {
12546 - long c, old;
12547 + long c, old, new;
12548 c = atomic64_read(v);
12549 for (;;) {
12550 - if (unlikely(c == (u)))
12551 + if (unlikely(c == u))
12552 break;
12553 - old = atomic64_cmpxchg((v), c, c + (a));
12554 +
12555 + asm volatile("add %2,%0\n"
12556 +
12557 +#ifdef CONFIG_PAX_REFCOUNT
12558 + "jno 0f\n"
12559 + "sub %2,%0\n"
12560 + "int $4\n0:\n"
12561 + _ASM_EXTABLE(0b, 0b)
12562 +#endif
12563 +
12564 + : "=r" (new)
12565 + : "0" (c), "ir" (a));
12566 +
12567 + old = atomic64_cmpxchg(v, c, new);
12568 if (likely(old == c))
12569 break;
12570 c = old;
12571 }
12572 - return c != (u);
12573 + return c != u;
12574 }
12575
12576 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12577 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12578 index 6dfd019..0c6699f 100644
12579 --- a/arch/x86/include/asm/bitops.h
12580 +++ b/arch/x86/include/asm/bitops.h
12581 @@ -40,7 +40,7 @@
12582 * a mask operation on a byte.
12583 */
12584 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12585 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12586 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12587 #define CONST_MASK(nr) (1 << ((nr) & 7))
12588
12589 /**
12590 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12591 index 4fa687a..60f2d39 100644
12592 --- a/arch/x86/include/asm/boot.h
12593 +++ b/arch/x86/include/asm/boot.h
12594 @@ -6,10 +6,15 @@
12595 #include <uapi/asm/boot.h>
12596
12597 /* Physical address where kernel should be loaded. */
12598 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12599 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12600 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12601 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12602
12603 +#ifndef __ASSEMBLY__
12604 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
12605 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12606 +#endif
12607 +
12608 /* Minimum kernel alignment, as a power of two */
12609 #ifdef CONFIG_X86_64
12610 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12611 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12612 index 48f99f1..d78ebf9 100644
12613 --- a/arch/x86/include/asm/cache.h
12614 +++ b/arch/x86/include/asm/cache.h
12615 @@ -5,12 +5,13 @@
12616
12617 /* L1 cache line size */
12618 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12619 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12620 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12621
12622 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12623 +#define __read_only __attribute__((__section__(".data..read_only")))
12624
12625 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12626 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12627 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12628
12629 #ifdef CONFIG_X86_VSMP
12630 #ifdef CONFIG_SMP
12631 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12632 index 9863ee3..4a1f8e1 100644
12633 --- a/arch/x86/include/asm/cacheflush.h
12634 +++ b/arch/x86/include/asm/cacheflush.h
12635 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12636 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12637
12638 if (pg_flags == _PGMT_DEFAULT)
12639 - return -1;
12640 + return ~0UL;
12641 else if (pg_flags == _PGMT_WC)
12642 return _PAGE_CACHE_WC;
12643 else if (pg_flags == _PGMT_UC_MINUS)
12644 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12645 index 46fc474..b02b0f9 100644
12646 --- a/arch/x86/include/asm/checksum_32.h
12647 +++ b/arch/x86/include/asm/checksum_32.h
12648 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12649 int len, __wsum sum,
12650 int *src_err_ptr, int *dst_err_ptr);
12651
12652 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12653 + int len, __wsum sum,
12654 + int *src_err_ptr, int *dst_err_ptr);
12655 +
12656 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12657 + int len, __wsum sum,
12658 + int *src_err_ptr, int *dst_err_ptr);
12659 +
12660 /*
12661 * Note: when you get a NULL pointer exception here this means someone
12662 * passed in an incorrect kernel address to one of these functions.
12663 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12664 int *err_ptr)
12665 {
12666 might_sleep();
12667 - return csum_partial_copy_generic((__force void *)src, dst,
12668 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
12669 len, sum, err_ptr, NULL);
12670 }
12671
12672 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12673 {
12674 might_sleep();
12675 if (access_ok(VERIFY_WRITE, dst, len))
12676 - return csum_partial_copy_generic(src, (__force void *)dst,
12677 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12678 len, sum, NULL, err_ptr);
12679
12680 if (len)
12681 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
12682 index 8d871ea..c1a0dc9 100644
12683 --- a/arch/x86/include/asm/cmpxchg.h
12684 +++ b/arch/x86/include/asm/cmpxchg.h
12685 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
12686 __compiletime_error("Bad argument size for cmpxchg");
12687 extern void __xadd_wrong_size(void)
12688 __compiletime_error("Bad argument size for xadd");
12689 +extern void __xadd_check_overflow_wrong_size(void)
12690 + __compiletime_error("Bad argument size for xadd_check_overflow");
12691 extern void __add_wrong_size(void)
12692 __compiletime_error("Bad argument size for add");
12693 +extern void __add_check_overflow_wrong_size(void)
12694 + __compiletime_error("Bad argument size for add_check_overflow");
12695
12696 /*
12697 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
12698 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
12699 __ret; \
12700 })
12701
12702 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
12703 + ({ \
12704 + __typeof__ (*(ptr)) __ret = (arg); \
12705 + switch (sizeof(*(ptr))) { \
12706 + case __X86_CASE_L: \
12707 + asm volatile (lock #op "l %0, %1\n" \
12708 + "jno 0f\n" \
12709 + "mov %0,%1\n" \
12710 + "int $4\n0:\n" \
12711 + _ASM_EXTABLE(0b, 0b) \
12712 + : "+r" (__ret), "+m" (*(ptr)) \
12713 + : : "memory", "cc"); \
12714 + break; \
12715 + case __X86_CASE_Q: \
12716 + asm volatile (lock #op "q %q0, %1\n" \
12717 + "jno 0f\n" \
12718 + "mov %0,%1\n" \
12719 + "int $4\n0:\n" \
12720 + _ASM_EXTABLE(0b, 0b) \
12721 + : "+r" (__ret), "+m" (*(ptr)) \
12722 + : : "memory", "cc"); \
12723 + break; \
12724 + default: \
12725 + __ ## op ## _check_overflow_wrong_size(); \
12726 + } \
12727 + __ret; \
12728 + })
12729 +
12730 /*
12731 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
12732 * Since this is generally used to protect other memory information, we
12733 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
12734 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
12735 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
12736
12737 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
12738 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
12739 +
12740 #define __add(ptr, inc, lock) \
12741 ({ \
12742 __typeof__ (*(ptr)) __ret = (inc); \
12743 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
12744 index 2d9075e..b75a844 100644
12745 --- a/arch/x86/include/asm/cpufeature.h
12746 +++ b/arch/x86/include/asm/cpufeature.h
12747 @@ -206,7 +206,7 @@
12748 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
12749 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
12750 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
12751 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
12752 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
12753 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
12754 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
12755 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
12756 @@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
12757 ".section .discard,\"aw\",@progbits\n"
12758 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
12759 ".previous\n"
12760 - ".section .altinstr_replacement,\"ax\"\n"
12761 + ".section .altinstr_replacement,\"a\"\n"
12762 "3: movb $1,%0\n"
12763 "4:\n"
12764 ".previous\n"
12765 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
12766 index 8bf1c06..f723dfd 100644
12767 --- a/arch/x86/include/asm/desc.h
12768 +++ b/arch/x86/include/asm/desc.h
12769 @@ -4,6 +4,7 @@
12770 #include <asm/desc_defs.h>
12771 #include <asm/ldt.h>
12772 #include <asm/mmu.h>
12773 +#include <asm/pgtable.h>
12774
12775 #include <linux/smp.h>
12776 #include <linux/percpu.h>
12777 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12778
12779 desc->type = (info->read_exec_only ^ 1) << 1;
12780 desc->type |= info->contents << 2;
12781 + desc->type |= info->seg_not_present ^ 1;
12782
12783 desc->s = 1;
12784 desc->dpl = 0x3;
12785 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12786 }
12787
12788 extern struct desc_ptr idt_descr;
12789 -extern gate_desc idt_table[];
12790 extern struct desc_ptr nmi_idt_descr;
12791 -extern gate_desc nmi_idt_table[];
12792 -
12793 -struct gdt_page {
12794 - struct desc_struct gdt[GDT_ENTRIES];
12795 -} __attribute__((aligned(PAGE_SIZE)));
12796 -
12797 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
12798 +extern gate_desc idt_table[256];
12799 +extern gate_desc nmi_idt_table[256];
12800
12801 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
12802 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
12803 {
12804 - return per_cpu(gdt_page, cpu).gdt;
12805 + return cpu_gdt_table[cpu];
12806 }
12807
12808 #ifdef CONFIG_X86_64
12809 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
12810 unsigned long base, unsigned dpl, unsigned flags,
12811 unsigned short seg)
12812 {
12813 - gate->a = (seg << 16) | (base & 0xffff);
12814 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
12815 + gate->gate.offset_low = base;
12816 + gate->gate.seg = seg;
12817 + gate->gate.reserved = 0;
12818 + gate->gate.type = type;
12819 + gate->gate.s = 0;
12820 + gate->gate.dpl = dpl;
12821 + gate->gate.p = 1;
12822 + gate->gate.offset_high = base >> 16;
12823 }
12824
12825 #endif
12826 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
12827
12828 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
12829 {
12830 + pax_open_kernel();
12831 memcpy(&idt[entry], gate, sizeof(*gate));
12832 + pax_close_kernel();
12833 }
12834
12835 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
12836 {
12837 + pax_open_kernel();
12838 memcpy(&ldt[entry], desc, 8);
12839 + pax_close_kernel();
12840 }
12841
12842 static inline void
12843 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
12844 default: size = sizeof(*gdt); break;
12845 }
12846
12847 + pax_open_kernel();
12848 memcpy(&gdt[entry], desc, size);
12849 + pax_close_kernel();
12850 }
12851
12852 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
12853 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
12854
12855 static inline void native_load_tr_desc(void)
12856 {
12857 + pax_open_kernel();
12858 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
12859 + pax_close_kernel();
12860 }
12861
12862 static inline void native_load_gdt(const struct desc_ptr *dtr)
12863 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
12864 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
12865 unsigned int i;
12866
12867 + pax_open_kernel();
12868 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
12869 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
12870 + pax_close_kernel();
12871 }
12872
12873 #define _LDT_empty(info) \
12874 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
12875 }
12876
12877 #ifdef CONFIG_X86_64
12878 -static inline void set_nmi_gate(int gate, void *addr)
12879 +static inline void set_nmi_gate(int gate, const void *addr)
12880 {
12881 gate_desc s;
12882
12883 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
12884 }
12885 #endif
12886
12887 -static inline void _set_gate(int gate, unsigned type, void *addr,
12888 +static inline void _set_gate(int gate, unsigned type, const void *addr,
12889 unsigned dpl, unsigned ist, unsigned seg)
12890 {
12891 gate_desc s;
12892 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
12893 * Pentium F0 0F bugfix can have resulted in the mapped
12894 * IDT being write-protected.
12895 */
12896 -static inline void set_intr_gate(unsigned int n, void *addr)
12897 +static inline void set_intr_gate(unsigned int n, const void *addr)
12898 {
12899 BUG_ON((unsigned)n > 0xFF);
12900 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
12901 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
12902 /*
12903 * This routine sets up an interrupt gate at directory privilege level 3.
12904 */
12905 -static inline void set_system_intr_gate(unsigned int n, void *addr)
12906 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
12907 {
12908 BUG_ON((unsigned)n > 0xFF);
12909 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
12910 }
12911
12912 -static inline void set_system_trap_gate(unsigned int n, void *addr)
12913 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
12914 {
12915 BUG_ON((unsigned)n > 0xFF);
12916 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
12917 }
12918
12919 -static inline void set_trap_gate(unsigned int n, void *addr)
12920 +static inline void set_trap_gate(unsigned int n, const void *addr)
12921 {
12922 BUG_ON((unsigned)n > 0xFF);
12923 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
12924 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
12925 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
12926 {
12927 BUG_ON((unsigned)n > 0xFF);
12928 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
12929 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
12930 }
12931
12932 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
12933 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
12934 {
12935 BUG_ON((unsigned)n > 0xFF);
12936 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
12937 }
12938
12939 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
12940 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
12941 {
12942 BUG_ON((unsigned)n > 0xFF);
12943 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
12944 }
12945
12946 +#ifdef CONFIG_X86_32
12947 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
12948 +{
12949 + struct desc_struct d;
12950 +
12951 + if (likely(limit))
12952 + limit = (limit - 1UL) >> PAGE_SHIFT;
12953 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
12954 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
12955 +}
12956 +#endif
12957 +
12958 #endif /* _ASM_X86_DESC_H */
12959 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
12960 index 278441f..b95a174 100644
12961 --- a/arch/x86/include/asm/desc_defs.h
12962 +++ b/arch/x86/include/asm/desc_defs.h
12963 @@ -31,6 +31,12 @@ struct desc_struct {
12964 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
12965 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
12966 };
12967 + struct {
12968 + u16 offset_low;
12969 + u16 seg;
12970 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
12971 + unsigned offset_high: 16;
12972 + } gate;
12973 };
12974 } __attribute__((packed));
12975
12976 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
12977 index 9c999c1..3860cb8 100644
12978 --- a/arch/x86/include/asm/elf.h
12979 +++ b/arch/x86/include/asm/elf.h
12980 @@ -243,7 +243,25 @@ extern int force_personality32;
12981 the loader. We need to make sure that it is out of the way of the program
12982 that it will "exec", and that there is sufficient room for the brk. */
12983
12984 +#ifdef CONFIG_PAX_SEGMEXEC
12985 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
12986 +#else
12987 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
12988 +#endif
12989 +
12990 +#ifdef CONFIG_PAX_ASLR
12991 +#ifdef CONFIG_X86_32
12992 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
12993 +
12994 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12995 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12996 +#else
12997 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
12998 +
12999 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13000 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13001 +#endif
13002 +#endif
13003
13004 /* This yields a mask that user programs can use to figure out what
13005 instruction set this CPU supports. This could be done in user space,
13006 @@ -296,16 +314,12 @@ do { \
13007
13008 #define ARCH_DLINFO \
13009 do { \
13010 - if (vdso_enabled) \
13011 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13012 - (unsigned long)current->mm->context.vdso); \
13013 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13014 } while (0)
13015
13016 #define ARCH_DLINFO_X32 \
13017 do { \
13018 - if (vdso_enabled) \
13019 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13020 - (unsigned long)current->mm->context.vdso); \
13021 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13022 } while (0)
13023
13024 #define AT_SYSINFO 32
13025 @@ -320,7 +334,7 @@ else \
13026
13027 #endif /* !CONFIG_X86_32 */
13028
13029 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13030 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13031
13032 #define VDSO_ENTRY \
13033 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13034 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13035 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13036 #define compat_arch_setup_additional_pages syscall32_setup_pages
13037
13038 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13039 -#define arch_randomize_brk arch_randomize_brk
13040 -
13041 /*
13042 * True on X86_32 or when emulating IA32 on X86_64
13043 */
13044 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13045 index 75ce3f4..882e801 100644
13046 --- a/arch/x86/include/asm/emergency-restart.h
13047 +++ b/arch/x86/include/asm/emergency-restart.h
13048 @@ -13,6 +13,6 @@ enum reboot_type {
13049
13050 extern enum reboot_type reboot_type;
13051
13052 -extern void machine_emergency_restart(void);
13053 +extern void machine_emergency_restart(void) __noreturn;
13054
13055 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13056 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13057 index 41ab26e..a88c9e6 100644
13058 --- a/arch/x86/include/asm/fpu-internal.h
13059 +++ b/arch/x86/include/asm/fpu-internal.h
13060 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13061 ({ \
13062 int err; \
13063 asm volatile(ASM_STAC "\n" \
13064 - "1:" #insn "\n\t" \
13065 + "1:" \
13066 + __copyuser_seg \
13067 + #insn "\n\t" \
13068 "2: " ASM_CLAC "\n" \
13069 ".section .fixup,\"ax\"\n" \
13070 "3: movl $-1,%[err]\n" \
13071 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13072 "emms\n\t" /* clear stack tags */
13073 "fildl %P[addr]", /* set F?P to defined value */
13074 X86_FEATURE_FXSAVE_LEAK,
13075 - [addr] "m" (tsk->thread.fpu.has_fpu));
13076 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13077
13078 return fpu_restore_checking(&tsk->thread.fpu);
13079 }
13080 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13081 index be27ba1..8f13ff9 100644
13082 --- a/arch/x86/include/asm/futex.h
13083 +++ b/arch/x86/include/asm/futex.h
13084 @@ -12,6 +12,7 @@
13085 #include <asm/smap.h>
13086
13087 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13088 + typecheck(u32 __user *, uaddr); \
13089 asm volatile("\t" ASM_STAC "\n" \
13090 "1:\t" insn "\n" \
13091 "2:\t" ASM_CLAC "\n" \
13092 @@ -20,15 +21,16 @@
13093 "\tjmp\t2b\n" \
13094 "\t.previous\n" \
13095 _ASM_EXTABLE(1b, 3b) \
13096 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13097 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13098 : "i" (-EFAULT), "0" (oparg), "1" (0))
13099
13100 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13101 + typecheck(u32 __user *, uaddr); \
13102 asm volatile("\t" ASM_STAC "\n" \
13103 "1:\tmovl %2, %0\n" \
13104 "\tmovl\t%0, %3\n" \
13105 "\t" insn "\n" \
13106 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13107 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13108 "\tjnz\t1b\n" \
13109 "3:\t" ASM_CLAC "\n" \
13110 "\t.section .fixup,\"ax\"\n" \
13111 @@ -38,7 +40,7 @@
13112 _ASM_EXTABLE(1b, 4b) \
13113 _ASM_EXTABLE(2b, 4b) \
13114 : "=&a" (oldval), "=&r" (ret), \
13115 - "+m" (*uaddr), "=&r" (tem) \
13116 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13117 : "r" (oparg), "i" (-EFAULT), "1" (0))
13118
13119 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13120 @@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13121
13122 switch (op) {
13123 case FUTEX_OP_SET:
13124 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13125 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13126 break;
13127 case FUTEX_OP_ADD:
13128 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13129 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13130 uaddr, oparg);
13131 break;
13132 case FUTEX_OP_OR:
13133 @@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13134 return -EFAULT;
13135
13136 asm volatile("\t" ASM_STAC "\n"
13137 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13138 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13139 "2:\t" ASM_CLAC "\n"
13140 "\t.section .fixup, \"ax\"\n"
13141 "3:\tmov %3, %0\n"
13142 "\tjmp 2b\n"
13143 "\t.previous\n"
13144 _ASM_EXTABLE(1b, 3b)
13145 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13146 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13147 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13148 : "memory"
13149 );
13150 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13151 index eb92a6e..b98b2f4 100644
13152 --- a/arch/x86/include/asm/hw_irq.h
13153 +++ b/arch/x86/include/asm/hw_irq.h
13154 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13155 extern void enable_IO_APIC(void);
13156
13157 /* Statistics */
13158 -extern atomic_t irq_err_count;
13159 -extern atomic_t irq_mis_count;
13160 +extern atomic_unchecked_t irq_err_count;
13161 +extern atomic_unchecked_t irq_mis_count;
13162
13163 /* EISA */
13164 extern void eisa_set_level_irq(unsigned int irq);
13165 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13166 index a203659..9889f1c 100644
13167 --- a/arch/x86/include/asm/i8259.h
13168 +++ b/arch/x86/include/asm/i8259.h
13169 @@ -62,7 +62,7 @@ struct legacy_pic {
13170 void (*init)(int auto_eoi);
13171 int (*irq_pending)(unsigned int irq);
13172 void (*make_irq)(unsigned int irq);
13173 -};
13174 +} __do_const;
13175
13176 extern struct legacy_pic *legacy_pic;
13177 extern struct legacy_pic null_legacy_pic;
13178 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13179 index d8e8eef..15b1179 100644
13180 --- a/arch/x86/include/asm/io.h
13181 +++ b/arch/x86/include/asm/io.h
13182 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13183 return ioremap_nocache(offset, size);
13184 }
13185
13186 -extern void iounmap(volatile void __iomem *addr);
13187 +extern void iounmap(const volatile void __iomem *addr);
13188
13189 extern void set_iounmap_nonlazy(void);
13190
13191 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13192
13193 #include <linux/vmalloc.h>
13194
13195 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13196 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13197 +{
13198 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13199 +}
13200 +
13201 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13202 +{
13203 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13204 +}
13205 +
13206 /*
13207 * Convert a virtual cached pointer to an uncached pointer
13208 */
13209 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13210 index bba3cf8..06bc8da 100644
13211 --- a/arch/x86/include/asm/irqflags.h
13212 +++ b/arch/x86/include/asm/irqflags.h
13213 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13214 sti; \
13215 sysexit
13216
13217 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
13218 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13219 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
13220 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13221 +
13222 #else
13223 #define INTERRUPT_RETURN iret
13224 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13225 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13226 index d3ddd17..c9fb0cc 100644
13227 --- a/arch/x86/include/asm/kprobes.h
13228 +++ b/arch/x86/include/asm/kprobes.h
13229 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13230 #define RELATIVEJUMP_SIZE 5
13231 #define RELATIVECALL_OPCODE 0xe8
13232 #define RELATIVE_ADDR_SIZE 4
13233 -#define MAX_STACK_SIZE 64
13234 -#define MIN_STACK_SIZE(ADDR) \
13235 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13236 - THREAD_SIZE - (unsigned long)(ADDR))) \
13237 - ? (MAX_STACK_SIZE) \
13238 - : (((unsigned long)current_thread_info()) + \
13239 - THREAD_SIZE - (unsigned long)(ADDR)))
13240 +#define MAX_STACK_SIZE 64UL
13241 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13242
13243 #define flush_insn_slot(p) do { } while (0)
13244
13245 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13246 index 2d89e39..baee879 100644
13247 --- a/arch/x86/include/asm/local.h
13248 +++ b/arch/x86/include/asm/local.h
13249 @@ -10,33 +10,97 @@ typedef struct {
13250 atomic_long_t a;
13251 } local_t;
13252
13253 +typedef struct {
13254 + atomic_long_unchecked_t a;
13255 +} local_unchecked_t;
13256 +
13257 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13258
13259 #define local_read(l) atomic_long_read(&(l)->a)
13260 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13261 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13262 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13263
13264 static inline void local_inc(local_t *l)
13265 {
13266 - asm volatile(_ASM_INC "%0"
13267 + asm volatile(_ASM_INC "%0\n"
13268 +
13269 +#ifdef CONFIG_PAX_REFCOUNT
13270 + "jno 0f\n"
13271 + _ASM_DEC "%0\n"
13272 + "int $4\n0:\n"
13273 + _ASM_EXTABLE(0b, 0b)
13274 +#endif
13275 +
13276 + : "+m" (l->a.counter));
13277 +}
13278 +
13279 +static inline void local_inc_unchecked(local_unchecked_t *l)
13280 +{
13281 + asm volatile(_ASM_INC "%0\n"
13282 : "+m" (l->a.counter));
13283 }
13284
13285 static inline void local_dec(local_t *l)
13286 {
13287 - asm volatile(_ASM_DEC "%0"
13288 + asm volatile(_ASM_DEC "%0\n"
13289 +
13290 +#ifdef CONFIG_PAX_REFCOUNT
13291 + "jno 0f\n"
13292 + _ASM_INC "%0\n"
13293 + "int $4\n0:\n"
13294 + _ASM_EXTABLE(0b, 0b)
13295 +#endif
13296 +
13297 + : "+m" (l->a.counter));
13298 +}
13299 +
13300 +static inline void local_dec_unchecked(local_unchecked_t *l)
13301 +{
13302 + asm volatile(_ASM_DEC "%0\n"
13303 : "+m" (l->a.counter));
13304 }
13305
13306 static inline void local_add(long i, local_t *l)
13307 {
13308 - asm volatile(_ASM_ADD "%1,%0"
13309 + asm volatile(_ASM_ADD "%1,%0\n"
13310 +
13311 +#ifdef CONFIG_PAX_REFCOUNT
13312 + "jno 0f\n"
13313 + _ASM_SUB "%1,%0\n"
13314 + "int $4\n0:\n"
13315 + _ASM_EXTABLE(0b, 0b)
13316 +#endif
13317 +
13318 + : "+m" (l->a.counter)
13319 + : "ir" (i));
13320 +}
13321 +
13322 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
13323 +{
13324 + asm volatile(_ASM_ADD "%1,%0\n"
13325 : "+m" (l->a.counter)
13326 : "ir" (i));
13327 }
13328
13329 static inline void local_sub(long i, local_t *l)
13330 {
13331 - asm volatile(_ASM_SUB "%1,%0"
13332 + asm volatile(_ASM_SUB "%1,%0\n"
13333 +
13334 +#ifdef CONFIG_PAX_REFCOUNT
13335 + "jno 0f\n"
13336 + _ASM_ADD "%1,%0\n"
13337 + "int $4\n0:\n"
13338 + _ASM_EXTABLE(0b, 0b)
13339 +#endif
13340 +
13341 + : "+m" (l->a.counter)
13342 + : "ir" (i));
13343 +}
13344 +
13345 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13346 +{
13347 + asm volatile(_ASM_SUB "%1,%0\n"
13348 : "+m" (l->a.counter)
13349 : "ir" (i));
13350 }
13351 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13352 {
13353 unsigned char c;
13354
13355 - asm volatile(_ASM_SUB "%2,%0; sete %1"
13356 + asm volatile(_ASM_SUB "%2,%0\n"
13357 +
13358 +#ifdef CONFIG_PAX_REFCOUNT
13359 + "jno 0f\n"
13360 + _ASM_ADD "%2,%0\n"
13361 + "int $4\n0:\n"
13362 + _ASM_EXTABLE(0b, 0b)
13363 +#endif
13364 +
13365 + "sete %1\n"
13366 : "+m" (l->a.counter), "=qm" (c)
13367 : "ir" (i) : "memory");
13368 return c;
13369 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13370 {
13371 unsigned char c;
13372
13373 - asm volatile(_ASM_DEC "%0; sete %1"
13374 + asm volatile(_ASM_DEC "%0\n"
13375 +
13376 +#ifdef CONFIG_PAX_REFCOUNT
13377 + "jno 0f\n"
13378 + _ASM_INC "%0\n"
13379 + "int $4\n0:\n"
13380 + _ASM_EXTABLE(0b, 0b)
13381 +#endif
13382 +
13383 + "sete %1\n"
13384 : "+m" (l->a.counter), "=qm" (c)
13385 : : "memory");
13386 return c != 0;
13387 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13388 {
13389 unsigned char c;
13390
13391 - asm volatile(_ASM_INC "%0; sete %1"
13392 + asm volatile(_ASM_INC "%0\n"
13393 +
13394 +#ifdef CONFIG_PAX_REFCOUNT
13395 + "jno 0f\n"
13396 + _ASM_DEC "%0\n"
13397 + "int $4\n0:\n"
13398 + _ASM_EXTABLE(0b, 0b)
13399 +#endif
13400 +
13401 + "sete %1\n"
13402 : "+m" (l->a.counter), "=qm" (c)
13403 : : "memory");
13404 return c != 0;
13405 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13406 {
13407 unsigned char c;
13408
13409 - asm volatile(_ASM_ADD "%2,%0; sets %1"
13410 + asm volatile(_ASM_ADD "%2,%0\n"
13411 +
13412 +#ifdef CONFIG_PAX_REFCOUNT
13413 + "jno 0f\n"
13414 + _ASM_SUB "%2,%0\n"
13415 + "int $4\n0:\n"
13416 + _ASM_EXTABLE(0b, 0b)
13417 +#endif
13418 +
13419 + "sets %1\n"
13420 : "+m" (l->a.counter), "=qm" (c)
13421 : "ir" (i) : "memory");
13422 return c;
13423 @@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13424 static inline long local_add_return(long i, local_t *l)
13425 {
13426 long __i = i;
13427 + asm volatile(_ASM_XADD "%0, %1\n"
13428 +
13429 +#ifdef CONFIG_PAX_REFCOUNT
13430 + "jno 0f\n"
13431 + _ASM_MOV "%0,%1\n"
13432 + "int $4\n0:\n"
13433 + _ASM_EXTABLE(0b, 0b)
13434 +#endif
13435 +
13436 + : "+r" (i), "+m" (l->a.counter)
13437 + : : "memory");
13438 + return i + __i;
13439 +}
13440 +
13441 +/**
13442 + * local_add_return_unchecked - add and return
13443 + * @i: integer value to add
13444 + * @l: pointer to type local_unchecked_t
13445 + *
13446 + * Atomically adds @i to @l and returns @i + @l
13447 + */
13448 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13449 +{
13450 + long __i = i;
13451 asm volatile(_ASM_XADD "%0, %1;"
13452 : "+r" (i), "+m" (l->a.counter)
13453 : : "memory");
13454 @@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13455
13456 #define local_cmpxchg(l, o, n) \
13457 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13458 +#define local_cmpxchg_unchecked(l, o, n) \
13459 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
13460 /* Always has a lock prefix */
13461 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13462
13463 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13464 new file mode 100644
13465 index 0000000..2bfd3ba
13466 --- /dev/null
13467 +++ b/arch/x86/include/asm/mman.h
13468 @@ -0,0 +1,15 @@
13469 +#ifndef _X86_MMAN_H
13470 +#define _X86_MMAN_H
13471 +
13472 +#include <uapi/asm/mman.h>
13473 +
13474 +#ifdef __KERNEL__
13475 +#ifndef __ASSEMBLY__
13476 +#ifdef CONFIG_X86_32
13477 +#define arch_mmap_check i386_mmap_check
13478 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13479 +#endif
13480 +#endif
13481 +#endif
13482 +
13483 +#endif /* X86_MMAN_H */
13484 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13485 index 5f55e69..e20bfb1 100644
13486 --- a/arch/x86/include/asm/mmu.h
13487 +++ b/arch/x86/include/asm/mmu.h
13488 @@ -9,7 +9,7 @@
13489 * we put the segment information here.
13490 */
13491 typedef struct {
13492 - void *ldt;
13493 + struct desc_struct *ldt;
13494 int size;
13495
13496 #ifdef CONFIG_X86_64
13497 @@ -18,7 +18,19 @@ typedef struct {
13498 #endif
13499
13500 struct mutex lock;
13501 - void *vdso;
13502 + unsigned long vdso;
13503 +
13504 +#ifdef CONFIG_X86_32
13505 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13506 + unsigned long user_cs_base;
13507 + unsigned long user_cs_limit;
13508 +
13509 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13510 + cpumask_t cpu_user_cs_mask;
13511 +#endif
13512 +
13513 +#endif
13514 +#endif
13515 } mm_context_t;
13516
13517 #ifdef CONFIG_SMP
13518 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13519 index cdbf367..adb37ac 100644
13520 --- a/arch/x86/include/asm/mmu_context.h
13521 +++ b/arch/x86/include/asm/mmu_context.h
13522 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13523
13524 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13525 {
13526 +
13527 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13528 + unsigned int i;
13529 + pgd_t *pgd;
13530 +
13531 + pax_open_kernel();
13532 + pgd = get_cpu_pgd(smp_processor_id());
13533 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13534 + set_pgd_batched(pgd+i, native_make_pgd(0));
13535 + pax_close_kernel();
13536 +#endif
13537 +
13538 #ifdef CONFIG_SMP
13539 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13540 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13541 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13542 struct task_struct *tsk)
13543 {
13544 unsigned cpu = smp_processor_id();
13545 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13546 + int tlbstate = TLBSTATE_OK;
13547 +#endif
13548
13549 if (likely(prev != next)) {
13550 #ifdef CONFIG_SMP
13551 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13552 + tlbstate = this_cpu_read(cpu_tlbstate.state);
13553 +#endif
13554 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13555 this_cpu_write(cpu_tlbstate.active_mm, next);
13556 #endif
13557 cpumask_set_cpu(cpu, mm_cpumask(next));
13558
13559 /* Re-load page tables */
13560 +#ifdef CONFIG_PAX_PER_CPU_PGD
13561 + pax_open_kernel();
13562 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13563 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13564 + pax_close_kernel();
13565 + load_cr3(get_cpu_pgd(cpu));
13566 +#else
13567 load_cr3(next->pgd);
13568 +#endif
13569
13570 /* stop flush ipis for the previous mm */
13571 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13572 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13573 */
13574 if (unlikely(prev->context.ldt != next->context.ldt))
13575 load_LDT_nolock(&next->context);
13576 - }
13577 +
13578 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13579 + if (!(__supported_pte_mask & _PAGE_NX)) {
13580 + smp_mb__before_clear_bit();
13581 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13582 + smp_mb__after_clear_bit();
13583 + cpu_set(cpu, next->context.cpu_user_cs_mask);
13584 + }
13585 +#endif
13586 +
13587 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13588 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13589 + prev->context.user_cs_limit != next->context.user_cs_limit))
13590 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13591 #ifdef CONFIG_SMP
13592 + else if (unlikely(tlbstate != TLBSTATE_OK))
13593 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13594 +#endif
13595 +#endif
13596 +
13597 + }
13598 else {
13599 +
13600 +#ifdef CONFIG_PAX_PER_CPU_PGD
13601 + pax_open_kernel();
13602 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13603 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13604 + pax_close_kernel();
13605 + load_cr3(get_cpu_pgd(cpu));
13606 +#endif
13607 +
13608 +#ifdef CONFIG_SMP
13609 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13610 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13611
13612 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13613 * tlb flush IPI delivery. We must reload CR3
13614 * to make sure to use no freed page tables.
13615 */
13616 +
13617 +#ifndef CONFIG_PAX_PER_CPU_PGD
13618 load_cr3(next->pgd);
13619 +#endif
13620 +
13621 load_LDT_nolock(&next->context);
13622 +
13623 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13624 + if (!(__supported_pte_mask & _PAGE_NX))
13625 + cpu_set(cpu, next->context.cpu_user_cs_mask);
13626 +#endif
13627 +
13628 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13629 +#ifdef CONFIG_PAX_PAGEEXEC
13630 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
13631 +#endif
13632 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13633 +#endif
13634 +
13635 }
13636 +#endif
13637 }
13638 -#endif
13639 }
13640
13641 #define activate_mm(prev, next) \
13642 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
13643 index e3b7819..b257c64 100644
13644 --- a/arch/x86/include/asm/module.h
13645 +++ b/arch/x86/include/asm/module.h
13646 @@ -5,6 +5,7 @@
13647
13648 #ifdef CONFIG_X86_64
13649 /* X86_64 does not define MODULE_PROC_FAMILY */
13650 +#define MODULE_PROC_FAMILY ""
13651 #elif defined CONFIG_M486
13652 #define MODULE_PROC_FAMILY "486 "
13653 #elif defined CONFIG_M586
13654 @@ -57,8 +58,20 @@
13655 #error unknown processor family
13656 #endif
13657
13658 -#ifdef CONFIG_X86_32
13659 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
13660 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13661 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
13662 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
13663 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
13664 +#else
13665 +#define MODULE_PAX_KERNEXEC ""
13666 #endif
13667
13668 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13669 +#define MODULE_PAX_UDEREF "UDEREF "
13670 +#else
13671 +#define MODULE_PAX_UDEREF ""
13672 +#endif
13673 +
13674 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
13675 +
13676 #endif /* _ASM_X86_MODULE_H */
13677 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
13678 index c0fa356..07a498a 100644
13679 --- a/arch/x86/include/asm/nmi.h
13680 +++ b/arch/x86/include/asm/nmi.h
13681 @@ -42,11 +42,11 @@ struct nmiaction {
13682 nmi_handler_t handler;
13683 unsigned long flags;
13684 const char *name;
13685 -};
13686 +} __do_const;
13687
13688 #define register_nmi_handler(t, fn, fg, n, init...) \
13689 ({ \
13690 - static struct nmiaction init fn##_na = { \
13691 + static const struct nmiaction init fn##_na = { \
13692 .handler = (fn), \
13693 .name = (n), \
13694 .flags = (fg), \
13695 @@ -54,7 +54,7 @@ struct nmiaction {
13696 __register_nmi_handler((t), &fn##_na); \
13697 })
13698
13699 -int __register_nmi_handler(unsigned int, struct nmiaction *);
13700 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
13701
13702 void unregister_nmi_handler(unsigned int, const char *);
13703
13704 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
13705 index 320f7bb..e89f8f8 100644
13706 --- a/arch/x86/include/asm/page_64_types.h
13707 +++ b/arch/x86/include/asm/page_64_types.h
13708 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
13709
13710 /* duplicated to the one in bootmem.h */
13711 extern unsigned long max_pfn;
13712 -extern unsigned long phys_base;
13713 +extern const unsigned long phys_base;
13714
13715 extern unsigned long __phys_addr(unsigned long);
13716 #define __phys_reloc_hide(x) (x)
13717 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
13718 index 5edd174..9cf5821 100644
13719 --- a/arch/x86/include/asm/paravirt.h
13720 +++ b/arch/x86/include/asm/paravirt.h
13721 @@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
13722 val);
13723 }
13724
13725 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
13726 +{
13727 + pgdval_t val = native_pgd_val(pgd);
13728 +
13729 + if (sizeof(pgdval_t) > sizeof(long))
13730 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
13731 + val, (u64)val >> 32);
13732 + else
13733 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
13734 + val);
13735 +}
13736 +
13737 static inline void pgd_clear(pgd_t *pgdp)
13738 {
13739 set_pgd(pgdp, __pgd(0));
13740 @@ -711,6 +723,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
13741 pv_mmu_ops.set_fixmap(idx, phys, flags);
13742 }
13743
13744 +#ifdef CONFIG_PAX_KERNEXEC
13745 +static inline unsigned long pax_open_kernel(void)
13746 +{
13747 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
13748 +}
13749 +
13750 +static inline unsigned long pax_close_kernel(void)
13751 +{
13752 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
13753 +}
13754 +#else
13755 +static inline unsigned long pax_open_kernel(void) { return 0; }
13756 +static inline unsigned long pax_close_kernel(void) { return 0; }
13757 +#endif
13758 +
13759 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
13760
13761 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
13762 @@ -927,7 +954,7 @@ extern void default_banner(void);
13763
13764 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
13765 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
13766 -#define PARA_INDIRECT(addr) *%cs:addr
13767 +#define PARA_INDIRECT(addr) *%ss:addr
13768 #endif
13769
13770 #define INTERRUPT_RETURN \
13771 @@ -1002,6 +1029,21 @@ extern void default_banner(void);
13772 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
13773 CLBR_NONE, \
13774 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
13775 +
13776 +#define GET_CR0_INTO_RDI \
13777 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
13778 + mov %rax,%rdi
13779 +
13780 +#define SET_RDI_INTO_CR0 \
13781 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13782 +
13783 +#define GET_CR3_INTO_RDI \
13784 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
13785 + mov %rax,%rdi
13786 +
13787 +#define SET_RDI_INTO_CR3 \
13788 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
13789 +
13790 #endif /* CONFIG_X86_32 */
13791
13792 #endif /* __ASSEMBLY__ */
13793 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
13794 index 142236e..5446ffbc 100644
13795 --- a/arch/x86/include/asm/paravirt_types.h
13796 +++ b/arch/x86/include/asm/paravirt_types.h
13797 @@ -84,7 +84,7 @@ struct pv_init_ops {
13798 */
13799 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
13800 unsigned long addr, unsigned len);
13801 -};
13802 +} __no_const;
13803
13804
13805 struct pv_lazy_ops {
13806 @@ -97,7 +97,7 @@ struct pv_time_ops {
13807 unsigned long long (*sched_clock)(void);
13808 unsigned long long (*steal_clock)(int cpu);
13809 unsigned long (*get_tsc_khz)(void);
13810 -};
13811 +} __no_const;
13812
13813 struct pv_cpu_ops {
13814 /* hooks for various privileged instructions */
13815 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
13816
13817 void (*start_context_switch)(struct task_struct *prev);
13818 void (*end_context_switch)(struct task_struct *next);
13819 -};
13820 +} __no_const;
13821
13822 struct pv_irq_ops {
13823 /*
13824 @@ -222,7 +222,7 @@ struct pv_apic_ops {
13825 unsigned long start_eip,
13826 unsigned long start_esp);
13827 #endif
13828 -};
13829 +} __no_const;
13830
13831 struct pv_mmu_ops {
13832 unsigned long (*read_cr2)(void);
13833 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
13834 struct paravirt_callee_save make_pud;
13835
13836 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
13837 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
13838 #endif /* PAGETABLE_LEVELS == 4 */
13839 #endif /* PAGETABLE_LEVELS >= 3 */
13840
13841 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
13842 an mfn. We can tell which is which from the index. */
13843 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
13844 phys_addr_t phys, pgprot_t flags);
13845 +
13846 +#ifdef CONFIG_PAX_KERNEXEC
13847 + unsigned long (*pax_open_kernel)(void);
13848 + unsigned long (*pax_close_kernel)(void);
13849 +#endif
13850 +
13851 };
13852
13853 struct arch_spinlock;
13854 @@ -333,7 +340,7 @@ struct pv_lock_ops {
13855 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
13856 int (*spin_trylock)(struct arch_spinlock *lock);
13857 void (*spin_unlock)(struct arch_spinlock *lock);
13858 -};
13859 +} __no_const;
13860
13861 /* This contains all the paravirt structures: we get a convenient
13862 * number for each function using the offset which we use to indicate
13863 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
13864 index b4389a4..7024269 100644
13865 --- a/arch/x86/include/asm/pgalloc.h
13866 +++ b/arch/x86/include/asm/pgalloc.h
13867 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
13868 pmd_t *pmd, pte_t *pte)
13869 {
13870 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13871 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
13872 +}
13873 +
13874 +static inline void pmd_populate_user(struct mm_struct *mm,
13875 + pmd_t *pmd, pte_t *pte)
13876 +{
13877 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13878 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
13879 }
13880
13881 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
13882
13883 #ifdef CONFIG_X86_PAE
13884 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
13885 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
13886 +{
13887 + pud_populate(mm, pudp, pmd);
13888 +}
13889 #else /* !CONFIG_X86_PAE */
13890 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13891 {
13892 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13893 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
13894 }
13895 +
13896 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13897 +{
13898 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13899 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
13900 +}
13901 #endif /* CONFIG_X86_PAE */
13902
13903 #if PAGETABLE_LEVELS > 3
13904 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13905 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
13906 }
13907
13908 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13909 +{
13910 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
13911 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
13912 +}
13913 +
13914 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
13915 {
13916 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
13917 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
13918 index f2b489c..4f7e2e5 100644
13919 --- a/arch/x86/include/asm/pgtable-2level.h
13920 +++ b/arch/x86/include/asm/pgtable-2level.h
13921 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
13922
13923 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13924 {
13925 + pax_open_kernel();
13926 *pmdp = pmd;
13927 + pax_close_kernel();
13928 }
13929
13930 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13931 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
13932 index 4cc9f2b..5fd9226 100644
13933 --- a/arch/x86/include/asm/pgtable-3level.h
13934 +++ b/arch/x86/include/asm/pgtable-3level.h
13935 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13936
13937 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13938 {
13939 + pax_open_kernel();
13940 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
13941 + pax_close_kernel();
13942 }
13943
13944 static inline void native_set_pud(pud_t *pudp, pud_t pud)
13945 {
13946 + pax_open_kernel();
13947 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
13948 + pax_close_kernel();
13949 }
13950
13951 /*
13952 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
13953 index 1c1a955..50f828c 100644
13954 --- a/arch/x86/include/asm/pgtable.h
13955 +++ b/arch/x86/include/asm/pgtable.h
13956 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13957
13958 #ifndef __PAGETABLE_PUD_FOLDED
13959 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
13960 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
13961 #define pgd_clear(pgd) native_pgd_clear(pgd)
13962 #endif
13963
13964 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13965
13966 #define arch_end_context_switch(prev) do {} while(0)
13967
13968 +#define pax_open_kernel() native_pax_open_kernel()
13969 +#define pax_close_kernel() native_pax_close_kernel()
13970 #endif /* CONFIG_PARAVIRT */
13971
13972 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
13973 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
13974 +
13975 +#ifdef CONFIG_PAX_KERNEXEC
13976 +static inline unsigned long native_pax_open_kernel(void)
13977 +{
13978 + unsigned long cr0;
13979 +
13980 + preempt_disable();
13981 + barrier();
13982 + cr0 = read_cr0() ^ X86_CR0_WP;
13983 + BUG_ON(cr0 & X86_CR0_WP);
13984 + write_cr0(cr0);
13985 + return cr0 ^ X86_CR0_WP;
13986 +}
13987 +
13988 +static inline unsigned long native_pax_close_kernel(void)
13989 +{
13990 + unsigned long cr0;
13991 +
13992 + cr0 = read_cr0() ^ X86_CR0_WP;
13993 + BUG_ON(!(cr0 & X86_CR0_WP));
13994 + write_cr0(cr0);
13995 + barrier();
13996 + preempt_enable_no_resched();
13997 + return cr0 ^ X86_CR0_WP;
13998 +}
13999 +#else
14000 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
14001 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
14002 +#endif
14003 +
14004 /*
14005 * The following only work if pte_present() is true.
14006 * Undefined behaviour if not..
14007 */
14008 +static inline int pte_user(pte_t pte)
14009 +{
14010 + return pte_val(pte) & _PAGE_USER;
14011 +}
14012 +
14013 static inline int pte_dirty(pte_t pte)
14014 {
14015 return pte_flags(pte) & _PAGE_DIRTY;
14016 @@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14017 return pte_clear_flags(pte, _PAGE_RW);
14018 }
14019
14020 +static inline pte_t pte_mkread(pte_t pte)
14021 +{
14022 + return __pte(pte_val(pte) | _PAGE_USER);
14023 +}
14024 +
14025 static inline pte_t pte_mkexec(pte_t pte)
14026 {
14027 - return pte_clear_flags(pte, _PAGE_NX);
14028 +#ifdef CONFIG_X86_PAE
14029 + if (__supported_pte_mask & _PAGE_NX)
14030 + return pte_clear_flags(pte, _PAGE_NX);
14031 + else
14032 +#endif
14033 + return pte_set_flags(pte, _PAGE_USER);
14034 +}
14035 +
14036 +static inline pte_t pte_exprotect(pte_t pte)
14037 +{
14038 +#ifdef CONFIG_X86_PAE
14039 + if (__supported_pte_mask & _PAGE_NX)
14040 + return pte_set_flags(pte, _PAGE_NX);
14041 + else
14042 +#endif
14043 + return pte_clear_flags(pte, _PAGE_USER);
14044 }
14045
14046 static inline pte_t pte_mkdirty(pte_t pte)
14047 @@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14048 #endif
14049
14050 #ifndef __ASSEMBLY__
14051 +
14052 +#ifdef CONFIG_PAX_PER_CPU_PGD
14053 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14054 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14055 +{
14056 + return cpu_pgd[cpu];
14057 +}
14058 +#endif
14059 +
14060 #include <linux/mm_types.h>
14061
14062 static inline int pte_none(pte_t pte)
14063 @@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14064
14065 static inline int pgd_bad(pgd_t pgd)
14066 {
14067 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14068 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14069 }
14070
14071 static inline int pgd_none(pgd_t pgd)
14072 @@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
14073 * pgd_offset() returns a (pgd_t *)
14074 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14075 */
14076 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14077 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14078 +
14079 +#ifdef CONFIG_PAX_PER_CPU_PGD
14080 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14081 +#endif
14082 +
14083 /*
14084 * a shortcut which implies the use of the kernel's pgd, instead
14085 * of a process's
14086 @@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
14087 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14088 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14089
14090 +#ifdef CONFIG_X86_32
14091 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14092 +#else
14093 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14094 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14095 +
14096 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14097 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
14098 +#else
14099 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
14100 +#endif
14101 +
14102 +#endif
14103 +
14104 #ifndef __ASSEMBLY__
14105
14106 extern int direct_gbpages;
14107 @@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14108 * dst and src can be on the same page, but the range must not overlap,
14109 * and must not cross a page boundary.
14110 */
14111 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14112 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14113 {
14114 - memcpy(dst, src, count * sizeof(pgd_t));
14115 + pax_open_kernel();
14116 + while (count--)
14117 + *dst++ = *src++;
14118 + pax_close_kernel();
14119 }
14120
14121 +#ifdef CONFIG_PAX_PER_CPU_PGD
14122 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14123 +#endif
14124 +
14125 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14126 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14127 +#else
14128 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14129 +#endif
14130
14131 #include <asm-generic/pgtable.h>
14132 #endif /* __ASSEMBLY__ */
14133 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14134 index 8faa215..a8a17ea 100644
14135 --- a/arch/x86/include/asm/pgtable_32.h
14136 +++ b/arch/x86/include/asm/pgtable_32.h
14137 @@ -25,9 +25,6 @@
14138 struct mm_struct;
14139 struct vm_area_struct;
14140
14141 -extern pgd_t swapper_pg_dir[1024];
14142 -extern pgd_t initial_page_table[1024];
14143 -
14144 static inline void pgtable_cache_init(void) { }
14145 static inline void check_pgt_cache(void) { }
14146 void paging_init(void);
14147 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14148 # include <asm/pgtable-2level.h>
14149 #endif
14150
14151 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14152 +extern pgd_t initial_page_table[PTRS_PER_PGD];
14153 +#ifdef CONFIG_X86_PAE
14154 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14155 +#endif
14156 +
14157 #if defined(CONFIG_HIGHPTE)
14158 #define pte_offset_map(dir, address) \
14159 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14160 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14161 /* Clear a kernel PTE and flush it from the TLB */
14162 #define kpte_clear_flush(ptep, vaddr) \
14163 do { \
14164 + pax_open_kernel(); \
14165 pte_clear(&init_mm, (vaddr), (ptep)); \
14166 + pax_close_kernel(); \
14167 __flush_tlb_one((vaddr)); \
14168 } while (0)
14169
14170 @@ -75,6 +80,9 @@ do { \
14171
14172 #endif /* !__ASSEMBLY__ */
14173
14174 +#define HAVE_ARCH_UNMAPPED_AREA
14175 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14176 +
14177 /*
14178 * kern_addr_valid() is (1) for FLATMEM and (0) for
14179 * SPARSEMEM and DISCONTIGMEM
14180 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14181 index ed5903b..c7fe163 100644
14182 --- a/arch/x86/include/asm/pgtable_32_types.h
14183 +++ b/arch/x86/include/asm/pgtable_32_types.h
14184 @@ -8,7 +8,7 @@
14185 */
14186 #ifdef CONFIG_X86_PAE
14187 # include <asm/pgtable-3level_types.h>
14188 -# define PMD_SIZE (1UL << PMD_SHIFT)
14189 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14190 # define PMD_MASK (~(PMD_SIZE - 1))
14191 #else
14192 # include <asm/pgtable-2level_types.h>
14193 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14194 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14195 #endif
14196
14197 +#ifdef CONFIG_PAX_KERNEXEC
14198 +#ifndef __ASSEMBLY__
14199 +extern unsigned char MODULES_EXEC_VADDR[];
14200 +extern unsigned char MODULES_EXEC_END[];
14201 +#endif
14202 +#include <asm/boot.h>
14203 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14204 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14205 +#else
14206 +#define ktla_ktva(addr) (addr)
14207 +#define ktva_ktla(addr) (addr)
14208 +#endif
14209 +
14210 #define MODULES_VADDR VMALLOC_START
14211 #define MODULES_END VMALLOC_END
14212 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14213 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14214 index 47356f9..deb94a2 100644
14215 --- a/arch/x86/include/asm/pgtable_64.h
14216 +++ b/arch/x86/include/asm/pgtable_64.h
14217 @@ -16,10 +16,14 @@
14218
14219 extern pud_t level3_kernel_pgt[512];
14220 extern pud_t level3_ident_pgt[512];
14221 +extern pud_t level3_vmalloc_start_pgt[512];
14222 +extern pud_t level3_vmalloc_end_pgt[512];
14223 +extern pud_t level3_vmemmap_pgt[512];
14224 +extern pud_t level2_vmemmap_pgt[512];
14225 extern pmd_t level2_kernel_pgt[512];
14226 extern pmd_t level2_fixmap_pgt[512];
14227 -extern pmd_t level2_ident_pgt[512];
14228 -extern pgd_t init_level4_pgt[];
14229 +extern pmd_t level2_ident_pgt[512*2];
14230 +extern pgd_t init_level4_pgt[512];
14231
14232 #define swapper_pg_dir init_level4_pgt
14233
14234 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14235
14236 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14237 {
14238 + pax_open_kernel();
14239 *pmdp = pmd;
14240 + pax_close_kernel();
14241 }
14242
14243 static inline void native_pmd_clear(pmd_t *pmd)
14244 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14245
14246 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14247 {
14248 + pax_open_kernel();
14249 *pudp = pud;
14250 + pax_close_kernel();
14251 }
14252
14253 static inline void native_pud_clear(pud_t *pud)
14254 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14255
14256 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14257 {
14258 + pax_open_kernel();
14259 + *pgdp = pgd;
14260 + pax_close_kernel();
14261 +}
14262 +
14263 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14264 +{
14265 *pgdp = pgd;
14266 }
14267
14268 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14269 index 766ea16..5b96cb3 100644
14270 --- a/arch/x86/include/asm/pgtable_64_types.h
14271 +++ b/arch/x86/include/asm/pgtable_64_types.h
14272 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14273 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14274 #define MODULES_END _AC(0xffffffffff000000, UL)
14275 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14276 +#define MODULES_EXEC_VADDR MODULES_VADDR
14277 +#define MODULES_EXEC_END MODULES_END
14278 +
14279 +#define ktla_ktva(addr) (addr)
14280 +#define ktva_ktla(addr) (addr)
14281
14282 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14283 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14284 index 3c32db8..1ddccf5 100644
14285 --- a/arch/x86/include/asm/pgtable_types.h
14286 +++ b/arch/x86/include/asm/pgtable_types.h
14287 @@ -16,13 +16,12 @@
14288 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14289 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14290 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14291 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14292 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14293 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14294 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14295 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14296 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14297 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14298 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14299 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14300 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14301 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14302
14303 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14304 @@ -40,7 +39,6 @@
14305 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14306 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14307 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14308 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14309 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14310 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14311 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14312 @@ -57,8 +55,10 @@
14313
14314 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14315 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14316 -#else
14317 +#elif defined(CONFIG_KMEMCHECK)
14318 #define _PAGE_NX (_AT(pteval_t, 0))
14319 +#else
14320 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14321 #endif
14322
14323 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14324 @@ -116,6 +116,9 @@
14325 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14326 _PAGE_ACCESSED)
14327
14328 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
14329 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
14330 +
14331 #define __PAGE_KERNEL_EXEC \
14332 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14333 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14334 @@ -126,7 +129,7 @@
14335 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14336 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14337 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14338 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14339 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14340 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14341 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14342 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14343 @@ -188,8 +191,8 @@
14344 * bits are combined, this will alow user to access the high address mapped
14345 * VDSO in the presence of CONFIG_COMPAT_VDSO
14346 */
14347 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14348 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14349 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14350 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14351 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14352 #endif
14353
14354 @@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14355 {
14356 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14357 }
14358 +#endif
14359
14360 +#if PAGETABLE_LEVELS == 3
14361 +#include <asm-generic/pgtable-nopud.h>
14362 +#endif
14363 +
14364 +#if PAGETABLE_LEVELS == 2
14365 +#include <asm-generic/pgtable-nopmd.h>
14366 +#endif
14367 +
14368 +#ifndef __ASSEMBLY__
14369 #if PAGETABLE_LEVELS > 3
14370 typedef struct { pudval_t pud; } pud_t;
14371
14372 @@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14373 return pud.pud;
14374 }
14375 #else
14376 -#include <asm-generic/pgtable-nopud.h>
14377 -
14378 static inline pudval_t native_pud_val(pud_t pud)
14379 {
14380 return native_pgd_val(pud.pgd);
14381 @@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14382 return pmd.pmd;
14383 }
14384 #else
14385 -#include <asm-generic/pgtable-nopmd.h>
14386 -
14387 static inline pmdval_t native_pmd_val(pmd_t pmd)
14388 {
14389 return native_pgd_val(pmd.pud.pgd);
14390 @@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14391
14392 extern pteval_t __supported_pte_mask;
14393 extern void set_nx(void);
14394 -extern int nx_enabled;
14395
14396 #define pgprot_writecombine pgprot_writecombine
14397 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14398 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14399 index 888184b..a07ac89 100644
14400 --- a/arch/x86/include/asm/processor.h
14401 +++ b/arch/x86/include/asm/processor.h
14402 @@ -287,7 +287,7 @@ struct tss_struct {
14403
14404 } ____cacheline_aligned;
14405
14406 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14407 +extern struct tss_struct init_tss[NR_CPUS];
14408
14409 /*
14410 * Save the original ist values for checking stack pointers during debugging
14411 @@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
14412 */
14413 #define TASK_SIZE PAGE_OFFSET
14414 #define TASK_SIZE_MAX TASK_SIZE
14415 +
14416 +#ifdef CONFIG_PAX_SEGMEXEC
14417 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14418 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14419 +#else
14420 #define STACK_TOP TASK_SIZE
14421 -#define STACK_TOP_MAX STACK_TOP
14422 +#endif
14423 +
14424 +#define STACK_TOP_MAX TASK_SIZE
14425
14426 #define INIT_THREAD { \
14427 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
14428 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14429 .vm86_info = NULL, \
14430 .sysenter_cs = __KERNEL_CS, \
14431 .io_bitmap_ptr = NULL, \
14432 @@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
14433 */
14434 #define INIT_TSS { \
14435 .x86_tss = { \
14436 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
14437 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14438 .ss0 = __KERNEL_DS, \
14439 .ss1 = __KERNEL_CS, \
14440 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14441 @@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
14442 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14443
14444 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14445 -#define KSTK_TOP(info) \
14446 -({ \
14447 - unsigned long *__ptr = (unsigned long *)(info); \
14448 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14449 -})
14450 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14451
14452 /*
14453 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14454 @@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14455 #define task_pt_regs(task) \
14456 ({ \
14457 struct pt_regs *__regs__; \
14458 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14459 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14460 __regs__ - 1; \
14461 })
14462
14463 @@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14464 /*
14465 * User space process size. 47bits minus one guard page.
14466 */
14467 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14468 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14469
14470 /* This decides where the kernel will search for a free chunk of vm
14471 * space during mmap's.
14472 */
14473 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14474 - 0xc0000000 : 0xFFFFe000)
14475 + 0xc0000000 : 0xFFFFf000)
14476
14477 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14478 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14479 @@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14480 #define STACK_TOP_MAX TASK_SIZE_MAX
14481
14482 #define INIT_THREAD { \
14483 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14484 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14485 }
14486
14487 #define INIT_TSS { \
14488 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14489 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14490 }
14491
14492 /*
14493 @@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14494 */
14495 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14496
14497 +#ifdef CONFIG_PAX_SEGMEXEC
14498 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14499 +#endif
14500 +
14501 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14502
14503 /* Get/set a process' ability to use the timestamp counter instruction */
14504 @@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
14505 #define cpu_has_amd_erratum(x) (false)
14506 #endif /* CONFIG_CPU_SUP_AMD */
14507
14508 -extern unsigned long arch_align_stack(unsigned long sp);
14509 +#define arch_align_stack(x) ((x) & ~0xfUL)
14510 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14511
14512 void default_idle(void);
14513 bool set_pm_idle_to_default(void);
14514
14515 -void stop_this_cpu(void *dummy);
14516 +void stop_this_cpu(void *dummy) __noreturn;
14517
14518 #endif /* _ASM_X86_PROCESSOR_H */
14519 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14520 index 942a086..6c26446 100644
14521 --- a/arch/x86/include/asm/ptrace.h
14522 +++ b/arch/x86/include/asm/ptrace.h
14523 @@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14524 }
14525
14526 /*
14527 - * user_mode_vm(regs) determines whether a register set came from user mode.
14528 + * user_mode(regs) determines whether a register set came from user mode.
14529 * This is true if V8086 mode was enabled OR if the register set was from
14530 * protected mode with RPL-3 CS value. This tricky test checks that with
14531 * one comparison. Many places in the kernel can bypass this full check
14532 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14533 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14534 + * be used.
14535 */
14536 -static inline int user_mode(struct pt_regs *regs)
14537 +static inline int user_mode_novm(struct pt_regs *regs)
14538 {
14539 #ifdef CONFIG_X86_32
14540 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14541 #else
14542 - return !!(regs->cs & 3);
14543 + return !!(regs->cs & SEGMENT_RPL_MASK);
14544 #endif
14545 }
14546
14547 -static inline int user_mode_vm(struct pt_regs *regs)
14548 +static inline int user_mode(struct pt_regs *regs)
14549 {
14550 #ifdef CONFIG_X86_32
14551 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14552 USER_RPL;
14553 #else
14554 - return user_mode(regs);
14555 + return user_mode_novm(regs);
14556 #endif
14557 }
14558
14559 @@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14560 #ifdef CONFIG_X86_64
14561 static inline bool user_64bit_mode(struct pt_regs *regs)
14562 {
14563 + unsigned long cs = regs->cs & 0xffff;
14564 #ifndef CONFIG_PARAVIRT
14565 /*
14566 * On non-paravirt systems, this is the only long mode CPL 3
14567 * selector. We do not allow long mode selectors in the LDT.
14568 */
14569 - return regs->cs == __USER_CS;
14570 + return cs == __USER_CS;
14571 #else
14572 /* Headers are too twisted for this to go in paravirt.h. */
14573 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14574 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14575 #endif
14576 }
14577
14578 @@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14579 * Traps from the kernel do not save sp and ss.
14580 * Use the helper function to retrieve sp.
14581 */
14582 - if (offset == offsetof(struct pt_regs, sp) &&
14583 - regs->cs == __KERNEL_CS)
14584 - return kernel_stack_pointer(regs);
14585 + if (offset == offsetof(struct pt_regs, sp)) {
14586 + unsigned long cs = regs->cs & 0xffff;
14587 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
14588 + return kernel_stack_pointer(regs);
14589 + }
14590 #endif
14591 return *(unsigned long *)((unsigned long)regs + offset);
14592 }
14593 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
14594 index fe1ec5b..dc5c3fe 100644
14595 --- a/arch/x86/include/asm/realmode.h
14596 +++ b/arch/x86/include/asm/realmode.h
14597 @@ -22,16 +22,14 @@ struct real_mode_header {
14598 #endif
14599 /* APM/BIOS reboot */
14600 u32 machine_real_restart_asm;
14601 -#ifdef CONFIG_X86_64
14602 u32 machine_real_restart_seg;
14603 -#endif
14604 };
14605
14606 /* This must match data at trampoline_32/64.S */
14607 struct trampoline_header {
14608 #ifdef CONFIG_X86_32
14609 u32 start;
14610 - u16 gdt_pad;
14611 + u16 boot_cs;
14612 u16 gdt_limit;
14613 u32 gdt_base;
14614 #else
14615 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
14616 index a82c4f1..ac45053 100644
14617 --- a/arch/x86/include/asm/reboot.h
14618 +++ b/arch/x86/include/asm/reboot.h
14619 @@ -6,13 +6,13 @@
14620 struct pt_regs;
14621
14622 struct machine_ops {
14623 - void (*restart)(char *cmd);
14624 - void (*halt)(void);
14625 - void (*power_off)(void);
14626 + void (* __noreturn restart)(char *cmd);
14627 + void (* __noreturn halt)(void);
14628 + void (* __noreturn power_off)(void);
14629 void (*shutdown)(void);
14630 void (*crash_shutdown)(struct pt_regs *);
14631 - void (*emergency_restart)(void);
14632 -};
14633 + void (* __noreturn emergency_restart)(void);
14634 +} __no_const;
14635
14636 extern struct machine_ops machine_ops;
14637
14638 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
14639 index 2dbe4a7..ce1db00 100644
14640 --- a/arch/x86/include/asm/rwsem.h
14641 +++ b/arch/x86/include/asm/rwsem.h
14642 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
14643 {
14644 asm volatile("# beginning down_read\n\t"
14645 LOCK_PREFIX _ASM_INC "(%1)\n\t"
14646 +
14647 +#ifdef CONFIG_PAX_REFCOUNT
14648 + "jno 0f\n"
14649 + LOCK_PREFIX _ASM_DEC "(%1)\n"
14650 + "int $4\n0:\n"
14651 + _ASM_EXTABLE(0b, 0b)
14652 +#endif
14653 +
14654 /* adds 0x00000001 */
14655 " jns 1f\n"
14656 " call call_rwsem_down_read_failed\n"
14657 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
14658 "1:\n\t"
14659 " mov %1,%2\n\t"
14660 " add %3,%2\n\t"
14661 +
14662 +#ifdef CONFIG_PAX_REFCOUNT
14663 + "jno 0f\n"
14664 + "sub %3,%2\n"
14665 + "int $4\n0:\n"
14666 + _ASM_EXTABLE(0b, 0b)
14667 +#endif
14668 +
14669 " jle 2f\n\t"
14670 LOCK_PREFIX " cmpxchg %2,%0\n\t"
14671 " jnz 1b\n\t"
14672 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
14673 long tmp;
14674 asm volatile("# beginning down_write\n\t"
14675 LOCK_PREFIX " xadd %1,(%2)\n\t"
14676 +
14677 +#ifdef CONFIG_PAX_REFCOUNT
14678 + "jno 0f\n"
14679 + "mov %1,(%2)\n"
14680 + "int $4\n0:\n"
14681 + _ASM_EXTABLE(0b, 0b)
14682 +#endif
14683 +
14684 /* adds 0xffff0001, returns the old value */
14685 " test %1,%1\n\t"
14686 /* was the count 0 before? */
14687 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
14688 long tmp;
14689 asm volatile("# beginning __up_read\n\t"
14690 LOCK_PREFIX " xadd %1,(%2)\n\t"
14691 +
14692 +#ifdef CONFIG_PAX_REFCOUNT
14693 + "jno 0f\n"
14694 + "mov %1,(%2)\n"
14695 + "int $4\n0:\n"
14696 + _ASM_EXTABLE(0b, 0b)
14697 +#endif
14698 +
14699 /* subtracts 1, returns the old value */
14700 " jns 1f\n\t"
14701 " call call_rwsem_wake\n" /* expects old value in %edx */
14702 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
14703 long tmp;
14704 asm volatile("# beginning __up_write\n\t"
14705 LOCK_PREFIX " xadd %1,(%2)\n\t"
14706 +
14707 +#ifdef CONFIG_PAX_REFCOUNT
14708 + "jno 0f\n"
14709 + "mov %1,(%2)\n"
14710 + "int $4\n0:\n"
14711 + _ASM_EXTABLE(0b, 0b)
14712 +#endif
14713 +
14714 /* subtracts 0xffff0001, returns the old value */
14715 " jns 1f\n\t"
14716 " call call_rwsem_wake\n" /* expects old value in %edx */
14717 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14718 {
14719 asm volatile("# beginning __downgrade_write\n\t"
14720 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
14721 +
14722 +#ifdef CONFIG_PAX_REFCOUNT
14723 + "jno 0f\n"
14724 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
14725 + "int $4\n0:\n"
14726 + _ASM_EXTABLE(0b, 0b)
14727 +#endif
14728 +
14729 /*
14730 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
14731 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
14732 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14733 */
14734 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14735 {
14736 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
14737 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
14738 +
14739 +#ifdef CONFIG_PAX_REFCOUNT
14740 + "jno 0f\n"
14741 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
14742 + "int $4\n0:\n"
14743 + _ASM_EXTABLE(0b, 0b)
14744 +#endif
14745 +
14746 : "+m" (sem->count)
14747 : "er" (delta));
14748 }
14749 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14750 */
14751 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
14752 {
14753 - return delta + xadd(&sem->count, delta);
14754 + return delta + xadd_check_overflow(&sem->count, delta);
14755 }
14756
14757 #endif /* __KERNEL__ */
14758 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
14759 index c48a950..c6d7468 100644
14760 --- a/arch/x86/include/asm/segment.h
14761 +++ b/arch/x86/include/asm/segment.h
14762 @@ -64,10 +64,15 @@
14763 * 26 - ESPFIX small SS
14764 * 27 - per-cpu [ offset to per-cpu data area ]
14765 * 28 - stack_canary-20 [ for stack protector ]
14766 - * 29 - unused
14767 - * 30 - unused
14768 + * 29 - PCI BIOS CS
14769 + * 30 - PCI BIOS DS
14770 * 31 - TSS for double fault handler
14771 */
14772 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
14773 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
14774 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
14775 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
14776 +
14777 #define GDT_ENTRY_TLS_MIN 6
14778 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
14779
14780 @@ -79,6 +84,8 @@
14781
14782 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
14783
14784 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
14785 +
14786 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
14787
14788 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
14789 @@ -104,6 +111,12 @@
14790 #define __KERNEL_STACK_CANARY 0
14791 #endif
14792
14793 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
14794 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
14795 +
14796 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
14797 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
14798 +
14799 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
14800
14801 /*
14802 @@ -141,7 +154,7 @@
14803 */
14804
14805 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
14806 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
14807 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
14808
14809
14810 #else
14811 @@ -165,6 +178,8 @@
14812 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
14813 #define __USER32_DS __USER_DS
14814
14815 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
14816 +
14817 #define GDT_ENTRY_TSS 8 /* needs two entries */
14818 #define GDT_ENTRY_LDT 10 /* needs two entries */
14819 #define GDT_ENTRY_TLS_MIN 12
14820 @@ -185,6 +200,7 @@
14821 #endif
14822
14823 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
14824 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
14825 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
14826 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
14827 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
14828 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
14829 {
14830 unsigned long __limit;
14831 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
14832 - return __limit + 1;
14833 + return __limit;
14834 }
14835
14836 #endif /* !__ASSEMBLY__ */
14837 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
14838 index b073aae..39f9bdd 100644
14839 --- a/arch/x86/include/asm/smp.h
14840 +++ b/arch/x86/include/asm/smp.h
14841 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
14842 /* cpus sharing the last level cache: */
14843 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
14844 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
14845 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
14846 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
14847
14848 static inline struct cpumask *cpu_sibling_mask(int cpu)
14849 {
14850 @@ -79,7 +79,7 @@ struct smp_ops {
14851
14852 void (*send_call_func_ipi)(const struct cpumask *mask);
14853 void (*send_call_func_single_ipi)(int cpu);
14854 -};
14855 +} __no_const;
14856
14857 /* Globals due to paravirt */
14858 extern void set_cpu_sibling_map(int cpu);
14859 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
14860 extern int safe_smp_processor_id(void);
14861
14862 #elif defined(CONFIG_X86_64_SMP)
14863 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14864 -
14865 -#define stack_smp_processor_id() \
14866 -({ \
14867 - struct thread_info *ti; \
14868 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
14869 - ti->cpu; \
14870 -})
14871 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14872 +#define stack_smp_processor_id() raw_smp_processor_id()
14873 #define safe_smp_processor_id() smp_processor_id()
14874
14875 #endif
14876 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
14877 index 33692ea..350a534 100644
14878 --- a/arch/x86/include/asm/spinlock.h
14879 +++ b/arch/x86/include/asm/spinlock.h
14880 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
14881 static inline void arch_read_lock(arch_rwlock_t *rw)
14882 {
14883 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
14884 +
14885 +#ifdef CONFIG_PAX_REFCOUNT
14886 + "jno 0f\n"
14887 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
14888 + "int $4\n0:\n"
14889 + _ASM_EXTABLE(0b, 0b)
14890 +#endif
14891 +
14892 "jns 1f\n"
14893 "call __read_lock_failed\n\t"
14894 "1:\n"
14895 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
14896 static inline void arch_write_lock(arch_rwlock_t *rw)
14897 {
14898 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
14899 +
14900 +#ifdef CONFIG_PAX_REFCOUNT
14901 + "jno 0f\n"
14902 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
14903 + "int $4\n0:\n"
14904 + _ASM_EXTABLE(0b, 0b)
14905 +#endif
14906 +
14907 "jz 1f\n"
14908 "call __write_lock_failed\n\t"
14909 "1:\n"
14910 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
14911
14912 static inline void arch_read_unlock(arch_rwlock_t *rw)
14913 {
14914 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
14915 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
14916 +
14917 +#ifdef CONFIG_PAX_REFCOUNT
14918 + "jno 0f\n"
14919 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
14920 + "int $4\n0:\n"
14921 + _ASM_EXTABLE(0b, 0b)
14922 +#endif
14923 +
14924 :"+m" (rw->lock) : : "memory");
14925 }
14926
14927 static inline void arch_write_unlock(arch_rwlock_t *rw)
14928 {
14929 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
14930 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
14931 +
14932 +#ifdef CONFIG_PAX_REFCOUNT
14933 + "jno 0f\n"
14934 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
14935 + "int $4\n0:\n"
14936 + _ASM_EXTABLE(0b, 0b)
14937 +#endif
14938 +
14939 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
14940 }
14941
14942 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
14943 index 6a99859..03cb807 100644
14944 --- a/arch/x86/include/asm/stackprotector.h
14945 +++ b/arch/x86/include/asm/stackprotector.h
14946 @@ -47,7 +47,7 @@
14947 * head_32 for boot CPU and setup_per_cpu_areas() for others.
14948 */
14949 #define GDT_STACK_CANARY_INIT \
14950 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
14951 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
14952
14953 /*
14954 * Initialize the stackprotector canary value.
14955 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
14956
14957 static inline void load_stack_canary_segment(void)
14958 {
14959 -#ifdef CONFIG_X86_32
14960 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
14961 asm volatile ("mov %0, %%gs" : : "r" (0));
14962 #endif
14963 }
14964 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
14965 index 70bbe39..4ae2bd4 100644
14966 --- a/arch/x86/include/asm/stacktrace.h
14967 +++ b/arch/x86/include/asm/stacktrace.h
14968 @@ -11,28 +11,20 @@
14969
14970 extern int kstack_depth_to_print;
14971
14972 -struct thread_info;
14973 +struct task_struct;
14974 struct stacktrace_ops;
14975
14976 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
14977 - unsigned long *stack,
14978 - unsigned long bp,
14979 - const struct stacktrace_ops *ops,
14980 - void *data,
14981 - unsigned long *end,
14982 - int *graph);
14983 +typedef unsigned long walk_stack_t(struct task_struct *task,
14984 + void *stack_start,
14985 + unsigned long *stack,
14986 + unsigned long bp,
14987 + const struct stacktrace_ops *ops,
14988 + void *data,
14989 + unsigned long *end,
14990 + int *graph);
14991
14992 -extern unsigned long
14993 -print_context_stack(struct thread_info *tinfo,
14994 - unsigned long *stack, unsigned long bp,
14995 - const struct stacktrace_ops *ops, void *data,
14996 - unsigned long *end, int *graph);
14997 -
14998 -extern unsigned long
14999 -print_context_stack_bp(struct thread_info *tinfo,
15000 - unsigned long *stack, unsigned long bp,
15001 - const struct stacktrace_ops *ops, void *data,
15002 - unsigned long *end, int *graph);
15003 +extern walk_stack_t print_context_stack;
15004 +extern walk_stack_t print_context_stack_bp;
15005
15006 /* Generic stack tracer with callbacks */
15007
15008 @@ -40,7 +32,7 @@ struct stacktrace_ops {
15009 void (*address)(void *data, unsigned long address, int reliable);
15010 /* On negative return stop dumping */
15011 int (*stack)(void *data, char *name);
15012 - walk_stack_t walk_stack;
15013 + walk_stack_t *walk_stack;
15014 };
15015
15016 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15017 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15018 index 4ec45b3..a4f0a8a 100644
15019 --- a/arch/x86/include/asm/switch_to.h
15020 +++ b/arch/x86/include/asm/switch_to.h
15021 @@ -108,7 +108,7 @@ do { \
15022 "call __switch_to\n\t" \
15023 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15024 __switch_canary \
15025 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
15026 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15027 "movq %%rax,%%rdi\n\t" \
15028 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15029 "jnz ret_from_fork\n\t" \
15030 @@ -119,7 +119,7 @@ do { \
15031 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15032 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15033 [_tif_fork] "i" (_TIF_FORK), \
15034 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
15035 + [thread_info] "m" (current_tinfo), \
15036 [current_task] "m" (current_task) \
15037 __switch_canary_iparam \
15038 : "memory", "cc" __EXTRA_CLOBBER)
15039 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15040 index 2d946e6..e453ec4 100644
15041 --- a/arch/x86/include/asm/thread_info.h
15042 +++ b/arch/x86/include/asm/thread_info.h
15043 @@ -10,6 +10,7 @@
15044 #include <linux/compiler.h>
15045 #include <asm/page.h>
15046 #include <asm/types.h>
15047 +#include <asm/percpu.h>
15048
15049 /*
15050 * low level task data that entry.S needs immediate access to
15051 @@ -24,7 +25,6 @@ struct exec_domain;
15052 #include <linux/atomic.h>
15053
15054 struct thread_info {
15055 - struct task_struct *task; /* main task structure */
15056 struct exec_domain *exec_domain; /* execution domain */
15057 __u32 flags; /* low level flags */
15058 __u32 status; /* thread synchronous flags */
15059 @@ -34,19 +34,13 @@ struct thread_info {
15060 mm_segment_t addr_limit;
15061 struct restart_block restart_block;
15062 void __user *sysenter_return;
15063 -#ifdef CONFIG_X86_32
15064 - unsigned long previous_esp; /* ESP of the previous stack in
15065 - case of nested (IRQ) stacks
15066 - */
15067 - __u8 supervisor_stack[0];
15068 -#endif
15069 + unsigned long lowest_stack;
15070 unsigned int sig_on_uaccess_error:1;
15071 unsigned int uaccess_err:1; /* uaccess failed */
15072 };
15073
15074 -#define INIT_THREAD_INFO(tsk) \
15075 +#define INIT_THREAD_INFO \
15076 { \
15077 - .task = &tsk, \
15078 .exec_domain = &default_exec_domain, \
15079 .flags = 0, \
15080 .cpu = 0, \
15081 @@ -57,7 +51,7 @@ struct thread_info {
15082 }, \
15083 }
15084
15085 -#define init_thread_info (init_thread_union.thread_info)
15086 +#define init_thread_info (init_thread_union.stack)
15087 #define init_stack (init_thread_union.stack)
15088
15089 #else /* !__ASSEMBLY__ */
15090 @@ -98,6 +92,7 @@ struct thread_info {
15091 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15092 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15093 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15094 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15095
15096 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15097 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15098 @@ -122,17 +117,18 @@ struct thread_info {
15099 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15100 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15101 #define _TIF_X32 (1 << TIF_X32)
15102 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15103
15104 /* work to do in syscall_trace_enter() */
15105 #define _TIF_WORK_SYSCALL_ENTRY \
15106 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15107 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15108 - _TIF_NOHZ)
15109 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
15110
15111 /* work to do in syscall_trace_leave() */
15112 #define _TIF_WORK_SYSCALL_EXIT \
15113 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15114 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15115 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15116
15117 /* work to do on interrupt/exception return */
15118 #define _TIF_WORK_MASK \
15119 @@ -143,7 +139,7 @@ struct thread_info {
15120 /* work to do on any return to user space */
15121 #define _TIF_ALLWORK_MASK \
15122 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15123 - _TIF_NOHZ)
15124 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
15125
15126 /* Only used for 64 bit */
15127 #define _TIF_DO_NOTIFY_MASK \
15128 @@ -159,45 +155,40 @@ struct thread_info {
15129
15130 #define PREEMPT_ACTIVE 0x10000000
15131
15132 -#ifdef CONFIG_X86_32
15133 -
15134 -#define STACK_WARN (THREAD_SIZE/8)
15135 -/*
15136 - * macros/functions for gaining access to the thread information structure
15137 - *
15138 - * preempt_count needs to be 1 initially, until the scheduler is functional.
15139 - */
15140 -#ifndef __ASSEMBLY__
15141 -
15142 -
15143 -/* how to get the current stack pointer from C */
15144 -register unsigned long current_stack_pointer asm("esp") __used;
15145 -
15146 -/* how to get the thread information struct from C */
15147 -static inline struct thread_info *current_thread_info(void)
15148 -{
15149 - return (struct thread_info *)
15150 - (current_stack_pointer & ~(THREAD_SIZE - 1));
15151 -}
15152 -
15153 -#else /* !__ASSEMBLY__ */
15154 -
15155 +#ifdef __ASSEMBLY__
15156 /* how to get the thread information struct from ASM */
15157 #define GET_THREAD_INFO(reg) \
15158 - movl $-THREAD_SIZE, reg; \
15159 - andl %esp, reg
15160 + mov PER_CPU_VAR(current_tinfo), reg
15161
15162 /* use this one if reg already contains %esp */
15163 -#define GET_THREAD_INFO_WITH_ESP(reg) \
15164 - andl $-THREAD_SIZE, reg
15165 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15166 +#else
15167 +/* how to get the thread information struct from C */
15168 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15169 +
15170 +static __always_inline struct thread_info *current_thread_info(void)
15171 +{
15172 + return this_cpu_read_stable(current_tinfo);
15173 +}
15174 +#endif
15175 +
15176 +#ifdef CONFIG_X86_32
15177 +
15178 +#define STACK_WARN (THREAD_SIZE/8)
15179 +/*
15180 + * macros/functions for gaining access to the thread information structure
15181 + *
15182 + * preempt_count needs to be 1 initially, until the scheduler is functional.
15183 + */
15184 +#ifndef __ASSEMBLY__
15185 +
15186 +/* how to get the current stack pointer from C */
15187 +register unsigned long current_stack_pointer asm("esp") __used;
15188
15189 #endif
15190
15191 #else /* X86_32 */
15192
15193 -#include <asm/percpu.h>
15194 -#define KERNEL_STACK_OFFSET (5*8)
15195 -
15196 /*
15197 * macros/functions for gaining access to the thread information structure
15198 * preempt_count needs to be 1 initially, until the scheduler is functional.
15199 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15200 #ifndef __ASSEMBLY__
15201 DECLARE_PER_CPU(unsigned long, kernel_stack);
15202
15203 -static inline struct thread_info *current_thread_info(void)
15204 -{
15205 - struct thread_info *ti;
15206 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
15207 - KERNEL_STACK_OFFSET - THREAD_SIZE);
15208 - return ti;
15209 -}
15210 -
15211 -#else /* !__ASSEMBLY__ */
15212 -
15213 -/* how to get the thread information struct from ASM */
15214 -#define GET_THREAD_INFO(reg) \
15215 - movq PER_CPU_VAR(kernel_stack),reg ; \
15216 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15217 -
15218 -/*
15219 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15220 - * a certain register (to be used in assembler memory operands).
15221 - */
15222 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15223 -
15224 +/* how to get the current stack pointer from C */
15225 +register unsigned long current_stack_pointer asm("rsp") __used;
15226 #endif
15227
15228 #endif /* !X86_32 */
15229 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15230 extern void arch_task_cache_init(void);
15231 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15232 extern void arch_release_task_struct(struct task_struct *tsk);
15233 +
15234 +#define __HAVE_THREAD_FUNCTIONS
15235 +#define task_thread_info(task) (&(task)->tinfo)
15236 +#define task_stack_page(task) ((task)->stack)
15237 +#define setup_thread_stack(p, org) do {} while (0)
15238 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15239 +
15240 #endif
15241 #endif /* _ASM_X86_THREAD_INFO_H */
15242 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15243 index 1709801..0a60f2f 100644
15244 --- a/arch/x86/include/asm/uaccess.h
15245 +++ b/arch/x86/include/asm/uaccess.h
15246 @@ -7,6 +7,7 @@
15247 #include <linux/compiler.h>
15248 #include <linux/thread_info.h>
15249 #include <linux/string.h>
15250 +#include <linux/sched.h>
15251 #include <asm/asm.h>
15252 #include <asm/page.h>
15253 #include <asm/smap.h>
15254 @@ -29,7 +30,12 @@
15255
15256 #define get_ds() (KERNEL_DS)
15257 #define get_fs() (current_thread_info()->addr_limit)
15258 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15259 +void __set_fs(mm_segment_t x);
15260 +void set_fs(mm_segment_t x);
15261 +#else
15262 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15263 +#endif
15264
15265 #define segment_eq(a, b) ((a).seg == (b).seg)
15266
15267 @@ -77,8 +83,33 @@
15268 * checks that the pointer is in the user space range - after calling
15269 * this function, memory access functions may still return -EFAULT.
15270 */
15271 -#define access_ok(type, addr, size) \
15272 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15273 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15274 +#define access_ok(type, addr, size) \
15275 +({ \
15276 + long __size = size; \
15277 + unsigned long __addr = (unsigned long)addr; \
15278 + unsigned long __addr_ao = __addr & PAGE_MASK; \
15279 + unsigned long __end_ao = __addr + __size - 1; \
15280 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15281 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15282 + while(__addr_ao <= __end_ao) { \
15283 + char __c_ao; \
15284 + __addr_ao += PAGE_SIZE; \
15285 + if (__size > PAGE_SIZE) \
15286 + cond_resched(); \
15287 + if (__get_user(__c_ao, (char __user *)__addr)) \
15288 + break; \
15289 + if (type != VERIFY_WRITE) { \
15290 + __addr = __addr_ao; \
15291 + continue; \
15292 + } \
15293 + if (__put_user(__c_ao, (char __user *)__addr)) \
15294 + break; \
15295 + __addr = __addr_ao; \
15296 + } \
15297 + } \
15298 + __ret_ao; \
15299 +})
15300
15301 /*
15302 * The exception table consists of pairs of addresses relative to the
15303 @@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15304 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15305 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15306
15307 -
15308 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15309 +#define __copyuser_seg "gs;"
15310 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15311 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15312 +#else
15313 +#define __copyuser_seg
15314 +#define __COPYUSER_SET_ES
15315 +#define __COPYUSER_RESTORE_ES
15316 +#endif
15317
15318 #ifdef CONFIG_X86_32
15319 #define __put_user_asm_u64(x, addr, err, errret) \
15320 asm volatile(ASM_STAC "\n" \
15321 - "1: movl %%eax,0(%2)\n" \
15322 - "2: movl %%edx,4(%2)\n" \
15323 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15324 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15325 "3: " ASM_CLAC "\n" \
15326 ".section .fixup,\"ax\"\n" \
15327 "4: movl %3,%0\n" \
15328 @@ -208,8 +247,8 @@ extern int __get_user_bad(void);
15329
15330 #define __put_user_asm_ex_u64(x, addr) \
15331 asm volatile(ASM_STAC "\n" \
15332 - "1: movl %%eax,0(%1)\n" \
15333 - "2: movl %%edx,4(%1)\n" \
15334 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15335 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15336 "3: " ASM_CLAC "\n" \
15337 _ASM_EXTABLE_EX(1b, 2b) \
15338 _ASM_EXTABLE_EX(2b, 3b) \
15339 @@ -259,7 +298,7 @@ extern void __put_user_8(void);
15340 __typeof__(*(ptr)) __pu_val; \
15341 __chk_user_ptr(ptr); \
15342 might_fault(); \
15343 - __pu_val = x; \
15344 + __pu_val = (x); \
15345 switch (sizeof(*(ptr))) { \
15346 case 1: \
15347 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15348 @@ -358,7 +397,7 @@ do { \
15349
15350 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15351 asm volatile(ASM_STAC "\n" \
15352 - "1: mov"itype" %2,%"rtype"1\n" \
15353 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15354 "2: " ASM_CLAC "\n" \
15355 ".section .fixup,\"ax\"\n" \
15356 "3: mov %3,%0\n" \
15357 @@ -366,7 +405,7 @@ do { \
15358 " jmp 2b\n" \
15359 ".previous\n" \
15360 _ASM_EXTABLE(1b, 3b) \
15361 - : "=r" (err), ltype(x) \
15362 + : "=r" (err), ltype (x) \
15363 : "m" (__m(addr)), "i" (errret), "0" (err))
15364
15365 #define __get_user_size_ex(x, ptr, size) \
15366 @@ -391,7 +430,7 @@ do { \
15367 } while (0)
15368
15369 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15370 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15371 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15372 "2:\n" \
15373 _ASM_EXTABLE_EX(1b, 2b) \
15374 : ltype(x) : "m" (__m(addr)))
15375 @@ -408,13 +447,24 @@ do { \
15376 int __gu_err; \
15377 unsigned long __gu_val; \
15378 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15379 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
15380 + (x) = (__typeof__(*(ptr)))__gu_val; \
15381 __gu_err; \
15382 })
15383
15384 /* FIXME: this hack is definitely wrong -AK */
15385 struct __large_struct { unsigned long buf[100]; };
15386 -#define __m(x) (*(struct __large_struct __user *)(x))
15387 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15388 +#define ____m(x) \
15389 +({ \
15390 + unsigned long ____x = (unsigned long)(x); \
15391 + if (____x < PAX_USER_SHADOW_BASE) \
15392 + ____x += PAX_USER_SHADOW_BASE; \
15393 + (void __user *)____x; \
15394 +})
15395 +#else
15396 +#define ____m(x) (x)
15397 +#endif
15398 +#define __m(x) (*(struct __large_struct __user *)____m(x))
15399
15400 /*
15401 * Tell gcc we read from memory instead of writing: this is because
15402 @@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
15403 */
15404 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15405 asm volatile(ASM_STAC "\n" \
15406 - "1: mov"itype" %"rtype"1,%2\n" \
15407 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15408 "2: " ASM_CLAC "\n" \
15409 ".section .fixup,\"ax\"\n" \
15410 "3: mov %3,%0\n" \
15411 @@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
15412 ".previous\n" \
15413 _ASM_EXTABLE(1b, 3b) \
15414 : "=r"(err) \
15415 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15416 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15417
15418 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15419 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15420 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15421 "2:\n" \
15422 _ASM_EXTABLE_EX(1b, 2b) \
15423 : : ltype(x), "m" (__m(addr)))
15424 @@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
15425 * On error, the variable @x is set to zero.
15426 */
15427
15428 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15429 +#define __get_user(x, ptr) get_user((x), (ptr))
15430 +#else
15431 #define __get_user(x, ptr) \
15432 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15433 +#endif
15434
15435 /**
15436 * __put_user: - Write a simple value into user space, with less checking.
15437 @@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
15438 * Returns zero on success, or -EFAULT on error.
15439 */
15440
15441 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15442 +#define __put_user(x, ptr) put_user((x), (ptr))
15443 +#else
15444 #define __put_user(x, ptr) \
15445 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15446 +#endif
15447
15448 #define __get_user_unaligned __get_user
15449 #define __put_user_unaligned __put_user
15450 @@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
15451 #define get_user_ex(x, ptr) do { \
15452 unsigned long __gue_val; \
15453 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15454 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
15455 + (x) = (__typeof__(*(ptr)))__gue_val; \
15456 } while (0)
15457
15458 #define put_user_try uaccess_try
15459 @@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15460 extern __must_check long strlen_user(const char __user *str);
15461 extern __must_check long strnlen_user(const char __user *str, long n);
15462
15463 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15464 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15465 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15466 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15467
15468 /*
15469 * movsl can be slow when source and dest are not both 8-byte aligned
15470 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15471 index 7f760a9..04b1c65 100644
15472 --- a/arch/x86/include/asm/uaccess_32.h
15473 +++ b/arch/x86/include/asm/uaccess_32.h
15474 @@ -11,15 +11,15 @@
15475 #include <asm/page.h>
15476
15477 unsigned long __must_check __copy_to_user_ll
15478 - (void __user *to, const void *from, unsigned long n);
15479 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15480 unsigned long __must_check __copy_from_user_ll
15481 - (void *to, const void __user *from, unsigned long n);
15482 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15483 unsigned long __must_check __copy_from_user_ll_nozero
15484 - (void *to, const void __user *from, unsigned long n);
15485 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15486 unsigned long __must_check __copy_from_user_ll_nocache
15487 - (void *to, const void __user *from, unsigned long n);
15488 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15489 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15490 - (void *to, const void __user *from, unsigned long n);
15491 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15492
15493 /**
15494 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15495 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15496 static __always_inline unsigned long __must_check
15497 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15498 {
15499 + if ((long)n < 0)
15500 + return n;
15501 +
15502 + check_object_size(from, n, true);
15503 +
15504 if (__builtin_constant_p(n)) {
15505 unsigned long ret;
15506
15507 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15508 __copy_to_user(void __user *to, const void *from, unsigned long n)
15509 {
15510 might_fault();
15511 +
15512 return __copy_to_user_inatomic(to, from, n);
15513 }
15514
15515 static __always_inline unsigned long
15516 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15517 {
15518 + if ((long)n < 0)
15519 + return n;
15520 +
15521 /* Avoid zeroing the tail if the copy fails..
15522 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15523 * but as the zeroing behaviour is only significant when n is not
15524 @@ -137,6 +146,12 @@ static __always_inline unsigned long
15525 __copy_from_user(void *to, const void __user *from, unsigned long n)
15526 {
15527 might_fault();
15528 +
15529 + if ((long)n < 0)
15530 + return n;
15531 +
15532 + check_object_size(to, n, false);
15533 +
15534 if (__builtin_constant_p(n)) {
15535 unsigned long ret;
15536
15537 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15538 const void __user *from, unsigned long n)
15539 {
15540 might_fault();
15541 +
15542 + if ((long)n < 0)
15543 + return n;
15544 +
15545 if (__builtin_constant_p(n)) {
15546 unsigned long ret;
15547
15548 @@ -181,15 +200,19 @@ static __always_inline unsigned long
15549 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15550 unsigned long n)
15551 {
15552 - return __copy_from_user_ll_nocache_nozero(to, from, n);
15553 + if ((long)n < 0)
15554 + return n;
15555 +
15556 + return __copy_from_user_ll_nocache_nozero(to, from, n);
15557 }
15558
15559 -unsigned long __must_check copy_to_user(void __user *to,
15560 - const void *from, unsigned long n);
15561 -unsigned long __must_check _copy_from_user(void *to,
15562 - const void __user *from,
15563 - unsigned long n);
15564 -
15565 +extern void copy_to_user_overflow(void)
15566 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15567 + __compiletime_error("copy_to_user() buffer size is not provably correct")
15568 +#else
15569 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
15570 +#endif
15571 +;
15572
15573 extern void copy_from_user_overflow(void)
15574 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15575 @@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15576 #endif
15577 ;
15578
15579 -static inline unsigned long __must_check copy_from_user(void *to,
15580 - const void __user *from,
15581 - unsigned long n)
15582 +/**
15583 + * copy_to_user: - Copy a block of data into user space.
15584 + * @to: Destination address, in user space.
15585 + * @from: Source address, in kernel space.
15586 + * @n: Number of bytes to copy.
15587 + *
15588 + * Context: User context only. This function may sleep.
15589 + *
15590 + * Copy data from kernel space to user space.
15591 + *
15592 + * Returns number of bytes that could not be copied.
15593 + * On success, this will be zero.
15594 + */
15595 +static inline unsigned long __must_check
15596 +copy_to_user(void __user *to, const void *from, unsigned long n)
15597 {
15598 - int sz = __compiletime_object_size(to);
15599 + size_t sz = __compiletime_object_size(from);
15600
15601 - if (likely(sz == -1 || sz >= n))
15602 - n = _copy_from_user(to, from, n);
15603 - else
15604 + if (unlikely(sz != (size_t)-1 && sz < n))
15605 + copy_to_user_overflow();
15606 + else if (access_ok(VERIFY_WRITE, to, n))
15607 + n = __copy_to_user(to, from, n);
15608 + return n;
15609 +}
15610 +
15611 +/**
15612 + * copy_from_user: - Copy a block of data from user space.
15613 + * @to: Destination address, in kernel space.
15614 + * @from: Source address, in user space.
15615 + * @n: Number of bytes to copy.
15616 + *
15617 + * Context: User context only. This function may sleep.
15618 + *
15619 + * Copy data from user space to kernel space.
15620 + *
15621 + * Returns number of bytes that could not be copied.
15622 + * On success, this will be zero.
15623 + *
15624 + * If some data could not be copied, this function will pad the copied
15625 + * data to the requested size using zero bytes.
15626 + */
15627 +static inline unsigned long __must_check
15628 +copy_from_user(void *to, const void __user *from, unsigned long n)
15629 +{
15630 + size_t sz = __compiletime_object_size(to);
15631 +
15632 + check_object_size(to, n, false);
15633 +
15634 + if (unlikely(sz != (size_t)-1 && sz < n))
15635 copy_from_user_overflow();
15636 -
15637 + else if (access_ok(VERIFY_READ, from, n))
15638 + n = __copy_from_user(to, from, n);
15639 + else if ((long)n > 0)
15640 + memset(to, 0, n);
15641 return n;
15642 }
15643
15644 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
15645 index 142810c..747941a 100644
15646 --- a/arch/x86/include/asm/uaccess_64.h
15647 +++ b/arch/x86/include/asm/uaccess_64.h
15648 @@ -10,6 +10,9 @@
15649 #include <asm/alternative.h>
15650 #include <asm/cpufeature.h>
15651 #include <asm/page.h>
15652 +#include <asm/pgtable.h>
15653 +
15654 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
15655
15656 /*
15657 * Copy To/From Userspace
15658 @@ -17,13 +20,13 @@
15659
15660 /* Handles exceptions in both to and from, but doesn't do access_ok */
15661 __must_check unsigned long
15662 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
15663 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
15664 __must_check unsigned long
15665 -copy_user_generic_string(void *to, const void *from, unsigned len);
15666 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
15667 __must_check unsigned long
15668 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
15669 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
15670
15671 -static __always_inline __must_check unsigned long
15672 +static __always_inline __must_check __size_overflow(3) unsigned long
15673 copy_user_generic(void *to, const void *from, unsigned len)
15674 {
15675 unsigned ret;
15676 @@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
15677 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
15678 "=d" (len)),
15679 "1" (to), "2" (from), "3" (len)
15680 - : "memory", "rcx", "r8", "r9", "r10", "r11");
15681 + : "memory", "rcx", "r8", "r9", "r11");
15682 return ret;
15683 }
15684
15685 +static __always_inline __must_check unsigned long
15686 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
15687 +static __always_inline __must_check unsigned long
15688 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
15689 __must_check unsigned long
15690 -_copy_to_user(void __user *to, const void *from, unsigned len);
15691 -__must_check unsigned long
15692 -_copy_from_user(void *to, const void __user *from, unsigned len);
15693 -__must_check unsigned long
15694 -copy_in_user(void __user *to, const void __user *from, unsigned len);
15695 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
15696 +
15697 +extern void copy_to_user_overflow(void)
15698 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15699 + __compiletime_error("copy_to_user() buffer size is not provably correct")
15700 +#else
15701 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
15702 +#endif
15703 +;
15704 +
15705 +extern void copy_from_user_overflow(void)
15706 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15707 + __compiletime_error("copy_from_user() buffer size is not provably correct")
15708 +#else
15709 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
15710 +#endif
15711 +;
15712
15713 static inline unsigned long __must_check copy_from_user(void *to,
15714 const void __user *from,
15715 unsigned long n)
15716 {
15717 - int sz = __compiletime_object_size(to);
15718 -
15719 might_fault();
15720 - if (likely(sz == -1 || sz >= n))
15721 - n = _copy_from_user(to, from, n);
15722 -#ifdef CONFIG_DEBUG_VM
15723 - else
15724 - WARN(1, "Buffer overflow detected!\n");
15725 -#endif
15726 +
15727 + check_object_size(to, n, false);
15728 +
15729 + if (access_ok(VERIFY_READ, from, n))
15730 + n = __copy_from_user(to, from, n);
15731 + else if (n < INT_MAX)
15732 + memset(to, 0, n);
15733 return n;
15734 }
15735
15736 static __always_inline __must_check
15737 -int copy_to_user(void __user *dst, const void *src, unsigned size)
15738 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
15739 {
15740 might_fault();
15741
15742 - return _copy_to_user(dst, src, size);
15743 + if (access_ok(VERIFY_WRITE, dst, size))
15744 + size = __copy_to_user(dst, src, size);
15745 + return size;
15746 }
15747
15748 static __always_inline __must_check
15749 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
15750 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
15751 {
15752 - int ret = 0;
15753 + size_t sz = __compiletime_object_size(dst);
15754 + unsigned ret = 0;
15755
15756 might_fault();
15757 +
15758 + if (size > INT_MAX)
15759 + return size;
15760 +
15761 + check_object_size(dst, size, false);
15762 +
15763 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15764 + if (!__access_ok(VERIFY_READ, src, size))
15765 + return size;
15766 +#endif
15767 +
15768 + if (unlikely(sz != (size_t)-1 && sz < size)) {
15769 + copy_from_user_overflow();
15770 + return size;
15771 + }
15772 +
15773 if (!__builtin_constant_p(size))
15774 - return copy_user_generic(dst, (__force void *)src, size);
15775 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15776 switch (size) {
15777 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
15778 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
15779 ret, "b", "b", "=q", 1);
15780 return ret;
15781 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
15782 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
15783 ret, "w", "w", "=r", 2);
15784 return ret;
15785 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
15786 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
15787 ret, "l", "k", "=r", 4);
15788 return ret;
15789 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
15790 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15791 ret, "q", "", "=r", 8);
15792 return ret;
15793 case 10:
15794 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15795 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15796 ret, "q", "", "=r", 10);
15797 if (unlikely(ret))
15798 return ret;
15799 __get_user_asm(*(u16 *)(8 + (char *)dst),
15800 - (u16 __user *)(8 + (char __user *)src),
15801 + (const u16 __user *)(8 + (const char __user *)src),
15802 ret, "w", "w", "=r", 2);
15803 return ret;
15804 case 16:
15805 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15806 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15807 ret, "q", "", "=r", 16);
15808 if (unlikely(ret))
15809 return ret;
15810 __get_user_asm(*(u64 *)(8 + (char *)dst),
15811 - (u64 __user *)(8 + (char __user *)src),
15812 + (const u64 __user *)(8 + (const char __user *)src),
15813 ret, "q", "", "=r", 8);
15814 return ret;
15815 default:
15816 - return copy_user_generic(dst, (__force void *)src, size);
15817 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15818 }
15819 }
15820
15821 static __always_inline __must_check
15822 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
15823 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
15824 {
15825 - int ret = 0;
15826 + size_t sz = __compiletime_object_size(src);
15827 + unsigned ret = 0;
15828
15829 might_fault();
15830 +
15831 + if (size > INT_MAX)
15832 + return size;
15833 +
15834 + check_object_size(src, size, true);
15835 +
15836 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15837 + if (!__access_ok(VERIFY_WRITE, dst, size))
15838 + return size;
15839 +#endif
15840 +
15841 + if (unlikely(sz != (size_t)-1 && sz < size)) {
15842 + copy_to_user_overflow();
15843 + return size;
15844 + }
15845 +
15846 if (!__builtin_constant_p(size))
15847 - return copy_user_generic((__force void *)dst, src, size);
15848 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15849 switch (size) {
15850 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
15851 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
15852 ret, "b", "b", "iq", 1);
15853 return ret;
15854 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
15855 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
15856 ret, "w", "w", "ir", 2);
15857 return ret;
15858 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
15859 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
15860 ret, "l", "k", "ir", 4);
15861 return ret;
15862 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
15863 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15864 ret, "q", "", "er", 8);
15865 return ret;
15866 case 10:
15867 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15868 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15869 ret, "q", "", "er", 10);
15870 if (unlikely(ret))
15871 return ret;
15872 asm("":::"memory");
15873 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
15874 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
15875 ret, "w", "w", "ir", 2);
15876 return ret;
15877 case 16:
15878 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15879 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15880 ret, "q", "", "er", 16);
15881 if (unlikely(ret))
15882 return ret;
15883 asm("":::"memory");
15884 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
15885 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
15886 ret, "q", "", "er", 8);
15887 return ret;
15888 default:
15889 - return copy_user_generic((__force void *)dst, src, size);
15890 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15891 }
15892 }
15893
15894 static __always_inline __must_check
15895 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15896 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
15897 {
15898 - int ret = 0;
15899 + unsigned ret = 0;
15900
15901 might_fault();
15902 +
15903 + if (size > INT_MAX)
15904 + return size;
15905 +
15906 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15907 + if (!__access_ok(VERIFY_READ, src, size))
15908 + return size;
15909 + if (!__access_ok(VERIFY_WRITE, dst, size))
15910 + return size;
15911 +#endif
15912 +
15913 if (!__builtin_constant_p(size))
15914 - return copy_user_generic((__force void *)dst,
15915 - (__force void *)src, size);
15916 + return copy_user_generic((__force_kernel void *)____m(dst),
15917 + (__force_kernel const void *)____m(src), size);
15918 switch (size) {
15919 case 1: {
15920 u8 tmp;
15921 - __get_user_asm(tmp, (u8 __user *)src,
15922 + __get_user_asm(tmp, (const u8 __user *)src,
15923 ret, "b", "b", "=q", 1);
15924 if (likely(!ret))
15925 __put_user_asm(tmp, (u8 __user *)dst,
15926 @@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15927 }
15928 case 2: {
15929 u16 tmp;
15930 - __get_user_asm(tmp, (u16 __user *)src,
15931 + __get_user_asm(tmp, (const u16 __user *)src,
15932 ret, "w", "w", "=r", 2);
15933 if (likely(!ret))
15934 __put_user_asm(tmp, (u16 __user *)dst,
15935 @@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15936
15937 case 4: {
15938 u32 tmp;
15939 - __get_user_asm(tmp, (u32 __user *)src,
15940 + __get_user_asm(tmp, (const u32 __user *)src,
15941 ret, "l", "k", "=r", 4);
15942 if (likely(!ret))
15943 __put_user_asm(tmp, (u32 __user *)dst,
15944 @@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15945 }
15946 case 8: {
15947 u64 tmp;
15948 - __get_user_asm(tmp, (u64 __user *)src,
15949 + __get_user_asm(tmp, (const u64 __user *)src,
15950 ret, "q", "", "=r", 8);
15951 if (likely(!ret))
15952 __put_user_asm(tmp, (u64 __user *)dst,
15953 @@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15954 return ret;
15955 }
15956 default:
15957 - return copy_user_generic((__force void *)dst,
15958 - (__force void *)src, size);
15959 + return copy_user_generic((__force_kernel void *)____m(dst),
15960 + (__force_kernel const void *)____m(src), size);
15961 }
15962 }
15963
15964 static __must_check __always_inline int
15965 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
15966 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
15967 {
15968 - return copy_user_generic(dst, (__force const void *)src, size);
15969 + if (size > INT_MAX)
15970 + return size;
15971 +
15972 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15973 + if (!__access_ok(VERIFY_READ, src, size))
15974 + return size;
15975 +#endif
15976 +
15977 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15978 }
15979
15980 -static __must_check __always_inline int
15981 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
15982 +static __must_check __always_inline unsigned long
15983 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
15984 {
15985 - return copy_user_generic((__force void *)dst, src, size);
15986 + if (size > INT_MAX)
15987 + return size;
15988 +
15989 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15990 + if (!__access_ok(VERIFY_WRITE, dst, size))
15991 + return size;
15992 +#endif
15993 +
15994 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15995 }
15996
15997 -extern long __copy_user_nocache(void *dst, const void __user *src,
15998 - unsigned size, int zerorest);
15999 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16000 + unsigned long size, int zerorest) __size_overflow(3);
16001
16002 -static inline int
16003 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16004 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16005 {
16006 might_sleep();
16007 +
16008 + if (size > INT_MAX)
16009 + return size;
16010 +
16011 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16012 + if (!__access_ok(VERIFY_READ, src, size))
16013 + return size;
16014 +#endif
16015 +
16016 return __copy_user_nocache(dst, src, size, 1);
16017 }
16018
16019 -static inline int
16020 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16021 - unsigned size)
16022 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16023 + unsigned long size)
16024 {
16025 + if (size > INT_MAX)
16026 + return size;
16027 +
16028 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16029 + if (!__access_ok(VERIFY_READ, src, size))
16030 + return size;
16031 +#endif
16032 +
16033 return __copy_user_nocache(dst, src, size, 0);
16034 }
16035
16036 -unsigned long
16037 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16038 +extern unsigned long
16039 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16040
16041 #endif /* _ASM_X86_UACCESS_64_H */
16042 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16043 index 5b238981..77fdd78 100644
16044 --- a/arch/x86/include/asm/word-at-a-time.h
16045 +++ b/arch/x86/include/asm/word-at-a-time.h
16046 @@ -11,7 +11,7 @@
16047 * and shift, for example.
16048 */
16049 struct word_at_a_time {
16050 - const unsigned long one_bits, high_bits;
16051 + unsigned long one_bits, high_bits;
16052 };
16053
16054 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16055 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16056 index 5769349..a3d3e2a 100644
16057 --- a/arch/x86/include/asm/x86_init.h
16058 +++ b/arch/x86/include/asm/x86_init.h
16059 @@ -141,7 +141,7 @@ struct x86_init_ops {
16060 struct x86_init_timers timers;
16061 struct x86_init_iommu iommu;
16062 struct x86_init_pci pci;
16063 -};
16064 +} __no_const;
16065
16066 /**
16067 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16068 @@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
16069 void (*setup_percpu_clockev)(void);
16070 void (*early_percpu_clock_init)(void);
16071 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16072 -};
16073 +} __no_const;
16074
16075 /**
16076 * struct x86_platform_ops - platform specific runtime functions
16077 @@ -178,7 +178,7 @@ struct x86_platform_ops {
16078 void (*save_sched_clock_state)(void);
16079 void (*restore_sched_clock_state)(void);
16080 void (*apic_post_init)(void);
16081 -};
16082 +} __no_const;
16083
16084 struct pci_dev;
16085
16086 @@ -187,14 +187,14 @@ struct x86_msi_ops {
16087 void (*teardown_msi_irq)(unsigned int irq);
16088 void (*teardown_msi_irqs)(struct pci_dev *dev);
16089 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16090 -};
16091 +} __no_const;
16092
16093 struct x86_io_apic_ops {
16094 void (*init) (void);
16095 unsigned int (*read) (unsigned int apic, unsigned int reg);
16096 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
16097 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
16098 -};
16099 +} __no_const;
16100
16101 extern struct x86_init_ops x86_init;
16102 extern struct x86_cpuinit_ops x86_cpuinit;
16103 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16104 index 0415cda..b43d877 100644
16105 --- a/arch/x86/include/asm/xsave.h
16106 +++ b/arch/x86/include/asm/xsave.h
16107 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16108 return -EFAULT;
16109
16110 __asm__ __volatile__(ASM_STAC "\n"
16111 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16112 + "1:"
16113 + __copyuser_seg
16114 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16115 "2: " ASM_CLAC "\n"
16116 ".section .fixup,\"ax\"\n"
16117 "3: movl $-1,%[err]\n"
16118 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16119 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16120 {
16121 int err;
16122 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16123 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16124 u32 lmask = mask;
16125 u32 hmask = mask >> 32;
16126
16127 __asm__ __volatile__(ASM_STAC "\n"
16128 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16129 + "1:"
16130 + __copyuser_seg
16131 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16132 "2: " ASM_CLAC "\n"
16133 ".section .fixup,\"ax\"\n"
16134 "3: movl $-1,%[err]\n"
16135 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16136 index bbae024..e1528f9 100644
16137 --- a/arch/x86/include/uapi/asm/e820.h
16138 +++ b/arch/x86/include/uapi/asm/e820.h
16139 @@ -63,7 +63,7 @@ struct e820map {
16140 #define ISA_START_ADDRESS 0xa0000
16141 #define ISA_END_ADDRESS 0x100000
16142
16143 -#define BIOS_BEGIN 0x000a0000
16144 +#define BIOS_BEGIN 0x000c0000
16145 #define BIOS_END 0x00100000
16146
16147 #define BIOS_ROM_BASE 0xffe00000
16148 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16149 index 34e923a..0c6bb6e 100644
16150 --- a/arch/x86/kernel/Makefile
16151 +++ b/arch/x86/kernel/Makefile
16152 @@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16153 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16154 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16155 obj-y += probe_roms.o
16156 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16157 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16158 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16159 obj-y += syscall_$(BITS).o
16160 obj-$(CONFIG_X86_64) += vsyscall_64.o
16161 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16162 index bacf4b0..4ede72e 100644
16163 --- a/arch/x86/kernel/acpi/boot.c
16164 +++ b/arch/x86/kernel/acpi/boot.c
16165 @@ -1358,7 +1358,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16166 * If your system is blacklisted here, but you find that acpi=force
16167 * works for you, please contact linux-acpi@vger.kernel.org
16168 */
16169 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
16170 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16171 /*
16172 * Boxes that need ACPI disabled
16173 */
16174 @@ -1433,7 +1433,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16175 };
16176
16177 /* second table for DMI checks that should run after early-quirks */
16178 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16179 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16180 /*
16181 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16182 * which includes some code which overrides all temperature
16183 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16184 index d5e0d71..6533e08 100644
16185 --- a/arch/x86/kernel/acpi/sleep.c
16186 +++ b/arch/x86/kernel/acpi/sleep.c
16187 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16188 #else /* CONFIG_64BIT */
16189 #ifdef CONFIG_SMP
16190 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16191 +
16192 + pax_open_kernel();
16193 early_gdt_descr.address =
16194 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16195 + pax_close_kernel();
16196 +
16197 initial_gs = per_cpu_offset(smp_processor_id());
16198 #endif
16199 initial_code = (unsigned long)wakeup_long64;
16200 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16201 index 13ab720..95d5442 100644
16202 --- a/arch/x86/kernel/acpi/wakeup_32.S
16203 +++ b/arch/x86/kernel/acpi/wakeup_32.S
16204 @@ -30,13 +30,11 @@ wakeup_pmode_return:
16205 # and restore the stack ... but you need gdt for this to work
16206 movl saved_context_esp, %esp
16207
16208 - movl %cs:saved_magic, %eax
16209 - cmpl $0x12345678, %eax
16210 + cmpl $0x12345678, saved_magic
16211 jne bogus_magic
16212
16213 # jump to place where we left off
16214 - movl saved_eip, %eax
16215 - jmp *%eax
16216 + jmp *(saved_eip)
16217
16218 bogus_magic:
16219 jmp bogus_magic
16220 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16221 index ef5ccca..bd83949 100644
16222 --- a/arch/x86/kernel/alternative.c
16223 +++ b/arch/x86/kernel/alternative.c
16224 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16225 */
16226 for (a = start; a < end; a++) {
16227 instr = (u8 *)&a->instr_offset + a->instr_offset;
16228 +
16229 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16230 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16231 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16232 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16233 +#endif
16234 +
16235 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16236 BUG_ON(a->replacementlen > a->instrlen);
16237 BUG_ON(a->instrlen > sizeof(insnbuf));
16238 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16239 for (poff = start; poff < end; poff++) {
16240 u8 *ptr = (u8 *)poff + *poff;
16241
16242 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16243 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16244 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16245 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16246 +#endif
16247 +
16248 if (!*poff || ptr < text || ptr >= text_end)
16249 continue;
16250 /* turn DS segment override prefix into lock prefix */
16251 - if (*ptr == 0x3e)
16252 + if (*ktla_ktva(ptr) == 0x3e)
16253 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16254 }
16255 mutex_unlock(&text_mutex);
16256 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16257 for (poff = start; poff < end; poff++) {
16258 u8 *ptr = (u8 *)poff + *poff;
16259
16260 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16261 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16262 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16263 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16264 +#endif
16265 +
16266 if (!*poff || ptr < text || ptr >= text_end)
16267 continue;
16268 /* turn lock prefix into DS segment override prefix */
16269 - if (*ptr == 0xf0)
16270 + if (*ktla_ktva(ptr) == 0xf0)
16271 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16272 }
16273 mutex_unlock(&text_mutex);
16274 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16275
16276 BUG_ON(p->len > MAX_PATCH_LEN);
16277 /* prep the buffer with the original instructions */
16278 - memcpy(insnbuf, p->instr, p->len);
16279 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16280 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16281 (unsigned long)p->instr, p->len);
16282
16283 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16284 if (!uniproc_patched || num_possible_cpus() == 1)
16285 free_init_pages("SMP alternatives",
16286 (unsigned long)__smp_locks,
16287 - (unsigned long)__smp_locks_end);
16288 + PAGE_ALIGN((unsigned long)__smp_locks_end));
16289 #endif
16290
16291 apply_paravirt(__parainstructions, __parainstructions_end);
16292 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16293 * instructions. And on the local CPU you need to be protected again NMI or MCE
16294 * handlers seeing an inconsistent instruction while you patch.
16295 */
16296 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
16297 +void *__kprobes text_poke_early(void *addr, const void *opcode,
16298 size_t len)
16299 {
16300 unsigned long flags;
16301 local_irq_save(flags);
16302 - memcpy(addr, opcode, len);
16303 +
16304 + pax_open_kernel();
16305 + memcpy(ktla_ktva(addr), opcode, len);
16306 sync_core();
16307 + pax_close_kernel();
16308 +
16309 local_irq_restore(flags);
16310 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16311 that causes hangs on some VIA CPUs. */
16312 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16313 */
16314 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16315 {
16316 - unsigned long flags;
16317 - char *vaddr;
16318 + unsigned char *vaddr = ktla_ktva(addr);
16319 struct page *pages[2];
16320 - int i;
16321 + size_t i;
16322
16323 if (!core_kernel_text((unsigned long)addr)) {
16324 - pages[0] = vmalloc_to_page(addr);
16325 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16326 + pages[0] = vmalloc_to_page(vaddr);
16327 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16328 } else {
16329 - pages[0] = virt_to_page(addr);
16330 + pages[0] = virt_to_page(vaddr);
16331 WARN_ON(!PageReserved(pages[0]));
16332 - pages[1] = virt_to_page(addr + PAGE_SIZE);
16333 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16334 }
16335 BUG_ON(!pages[0]);
16336 - local_irq_save(flags);
16337 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16338 - if (pages[1])
16339 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16340 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16341 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16342 - clear_fixmap(FIX_TEXT_POKE0);
16343 - if (pages[1])
16344 - clear_fixmap(FIX_TEXT_POKE1);
16345 - local_flush_tlb();
16346 - sync_core();
16347 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
16348 - that causes hangs on some VIA CPUs. */
16349 + text_poke_early(addr, opcode, len);
16350 for (i = 0; i < len; i++)
16351 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16352 - local_irq_restore(flags);
16353 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16354 return addr;
16355 }
16356
16357 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16358 index cbf5121..812b537 100644
16359 --- a/arch/x86/kernel/apic/apic.c
16360 +++ b/arch/x86/kernel/apic/apic.c
16361 @@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16362 /*
16363 * Debug level, exported for io_apic.c
16364 */
16365 -unsigned int apic_verbosity;
16366 +int apic_verbosity;
16367
16368 int pic_mode;
16369
16370 @@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16371 apic_write(APIC_ESR, 0);
16372 v1 = apic_read(APIC_ESR);
16373 ack_APIC_irq();
16374 - atomic_inc(&irq_err_count);
16375 + atomic_inc_unchecked(&irq_err_count);
16376
16377 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16378 smp_processor_id(), v0 , v1);
16379 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16380 index 00c77cf..2dc6a2d 100644
16381 --- a/arch/x86/kernel/apic/apic_flat_64.c
16382 +++ b/arch/x86/kernel/apic/apic_flat_64.c
16383 @@ -157,7 +157,7 @@ static int flat_probe(void)
16384 return 1;
16385 }
16386
16387 -static struct apic apic_flat = {
16388 +static struct apic apic_flat __read_only = {
16389 .name = "flat",
16390 .probe = flat_probe,
16391 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16392 @@ -271,7 +271,7 @@ static int physflat_probe(void)
16393 return 0;
16394 }
16395
16396 -static struct apic apic_physflat = {
16397 +static struct apic apic_physflat __read_only = {
16398
16399 .name = "physical flat",
16400 .probe = physflat_probe,
16401 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16402 index e145f28..2752888 100644
16403 --- a/arch/x86/kernel/apic/apic_noop.c
16404 +++ b/arch/x86/kernel/apic/apic_noop.c
16405 @@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16406 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16407 }
16408
16409 -struct apic apic_noop = {
16410 +struct apic apic_noop __read_only = {
16411 .name = "noop",
16412 .probe = noop_probe,
16413 .acpi_madt_oem_check = NULL,
16414 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16415 index d50e364..543bee3 100644
16416 --- a/arch/x86/kernel/apic/bigsmp_32.c
16417 +++ b/arch/x86/kernel/apic/bigsmp_32.c
16418 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16419 return dmi_bigsmp;
16420 }
16421
16422 -static struct apic apic_bigsmp = {
16423 +static struct apic apic_bigsmp __read_only = {
16424
16425 .name = "bigsmp",
16426 .probe = probe_bigsmp,
16427 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16428 index 0874799..a7a7892 100644
16429 --- a/arch/x86/kernel/apic/es7000_32.c
16430 +++ b/arch/x86/kernel/apic/es7000_32.c
16431 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16432 return ret && es7000_apic_is_cluster();
16433 }
16434
16435 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16436 -static struct apic __refdata apic_es7000_cluster = {
16437 +static struct apic apic_es7000_cluster __read_only = {
16438
16439 .name = "es7000",
16440 .probe = probe_es7000,
16441 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16442 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16443 };
16444
16445 -static struct apic __refdata apic_es7000 = {
16446 +static struct apic apic_es7000 __read_only = {
16447
16448 .name = "es7000",
16449 .probe = probe_es7000,
16450 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16451 index b739d39..aebc14c 100644
16452 --- a/arch/x86/kernel/apic/io_apic.c
16453 +++ b/arch/x86/kernel/apic/io_apic.c
16454 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16455 }
16456 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16457
16458 -void lock_vector_lock(void)
16459 +void lock_vector_lock(void) __acquires(vector_lock)
16460 {
16461 /* Used to the online set of cpus does not change
16462 * during assign_irq_vector.
16463 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
16464 raw_spin_lock(&vector_lock);
16465 }
16466
16467 -void unlock_vector_lock(void)
16468 +void unlock_vector_lock(void) __releases(vector_lock)
16469 {
16470 raw_spin_unlock(&vector_lock);
16471 }
16472 @@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
16473 ack_APIC_irq();
16474 }
16475
16476 -atomic_t irq_mis_count;
16477 +atomic_unchecked_t irq_mis_count;
16478
16479 #ifdef CONFIG_GENERIC_PENDING_IRQ
16480 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16481 @@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
16482 * at the cpu.
16483 */
16484 if (!(v & (1 << (i & 0x1f)))) {
16485 - atomic_inc(&irq_mis_count);
16486 + atomic_inc_unchecked(&irq_mis_count);
16487
16488 eoi_ioapic_irq(irq, cfg);
16489 }
16490 @@ -2567,11 +2567,13 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
16491
16492 static void irq_remap_modify_chip_defaults(struct irq_chip *chip)
16493 {
16494 - chip->irq_print_chip = ir_print_prefix;
16495 - chip->irq_ack = ir_ack_apic_edge;
16496 - chip->irq_eoi = ir_ack_apic_level;
16497 + pax_open_kernel();
16498 + *(void **)&chip->irq_print_chip = ir_print_prefix;
16499 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
16500 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
16501
16502 - chip->irq_set_affinity = set_remapped_irq_affinity;
16503 + *(void **)&chip->irq_set_affinity = set_remapped_irq_affinity;
16504 + pax_close_kernel();
16505 }
16506 #endif /* CONFIG_IRQ_REMAP */
16507
16508 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16509 index d661ee9..791fd33 100644
16510 --- a/arch/x86/kernel/apic/numaq_32.c
16511 +++ b/arch/x86/kernel/apic/numaq_32.c
16512 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16513 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16514 }
16515
16516 -/* Use __refdata to keep false positive warning calm. */
16517 -static struct apic __refdata apic_numaq = {
16518 +static struct apic apic_numaq __read_only = {
16519
16520 .name = "NUMAQ",
16521 .probe = probe_numaq,
16522 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16523 index eb35ef9..f184a21 100644
16524 --- a/arch/x86/kernel/apic/probe_32.c
16525 +++ b/arch/x86/kernel/apic/probe_32.c
16526 @@ -72,7 +72,7 @@ static int probe_default(void)
16527 return 1;
16528 }
16529
16530 -static struct apic apic_default = {
16531 +static struct apic apic_default __read_only = {
16532
16533 .name = "default",
16534 .probe = probe_default,
16535 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16536 index 77c95c0..434f8a4 100644
16537 --- a/arch/x86/kernel/apic/summit_32.c
16538 +++ b/arch/x86/kernel/apic/summit_32.c
16539 @@ -486,7 +486,7 @@ void setup_summit(void)
16540 }
16541 #endif
16542
16543 -static struct apic apic_summit = {
16544 +static struct apic apic_summit __read_only = {
16545
16546 .name = "summit",
16547 .probe = probe_summit,
16548 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16549 index c88baa4..757aee1 100644
16550 --- a/arch/x86/kernel/apic/x2apic_cluster.c
16551 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
16552 @@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16553 return notifier_from_errno(err);
16554 }
16555
16556 -static struct notifier_block __refdata x2apic_cpu_notifier = {
16557 +static struct notifier_block x2apic_cpu_notifier = {
16558 .notifier_call = update_clusterinfo,
16559 };
16560
16561 @@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16562 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16563 }
16564
16565 -static struct apic apic_x2apic_cluster = {
16566 +static struct apic apic_x2apic_cluster __read_only = {
16567
16568 .name = "cluster x2apic",
16569 .probe = x2apic_cluster_probe,
16570 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16571 index 562a76d..a003c0f 100644
16572 --- a/arch/x86/kernel/apic/x2apic_phys.c
16573 +++ b/arch/x86/kernel/apic/x2apic_phys.c
16574 @@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16575 return apic == &apic_x2apic_phys;
16576 }
16577
16578 -static struct apic apic_x2apic_phys = {
16579 +static struct apic apic_x2apic_phys __read_only = {
16580
16581 .name = "physical x2apic",
16582 .probe = x2apic_phys_probe,
16583 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16584 index 8cfade9..b9d04fc 100644
16585 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
16586 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16587 @@ -333,7 +333,7 @@ static int uv_probe(void)
16588 return apic == &apic_x2apic_uv_x;
16589 }
16590
16591 -static struct apic __refdata apic_x2apic_uv_x = {
16592 +static struct apic apic_x2apic_uv_x __read_only = {
16593
16594 .name = "UV large system",
16595 .probe = uv_probe,
16596 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16597 index d65464e..1035d31 100644
16598 --- a/arch/x86/kernel/apm_32.c
16599 +++ b/arch/x86/kernel/apm_32.c
16600 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
16601 * This is for buggy BIOS's that refer to (real mode) segment 0x40
16602 * even though they are called in protected mode.
16603 */
16604 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
16605 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
16606 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
16607
16608 static const char driver_version[] = "1.16ac"; /* no spaces */
16609 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
16610 BUG_ON(cpu != 0);
16611 gdt = get_cpu_gdt_table(cpu);
16612 save_desc_40 = gdt[0x40 / 8];
16613 +
16614 + pax_open_kernel();
16615 gdt[0x40 / 8] = bad_bios_desc;
16616 + pax_close_kernel();
16617
16618 apm_irq_save(flags);
16619 APM_DO_SAVE_SEGS;
16620 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
16621 &call->esi);
16622 APM_DO_RESTORE_SEGS;
16623 apm_irq_restore(flags);
16624 +
16625 + pax_open_kernel();
16626 gdt[0x40 / 8] = save_desc_40;
16627 + pax_close_kernel();
16628 +
16629 put_cpu();
16630
16631 return call->eax & 0xff;
16632 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
16633 BUG_ON(cpu != 0);
16634 gdt = get_cpu_gdt_table(cpu);
16635 save_desc_40 = gdt[0x40 / 8];
16636 +
16637 + pax_open_kernel();
16638 gdt[0x40 / 8] = bad_bios_desc;
16639 + pax_close_kernel();
16640
16641 apm_irq_save(flags);
16642 APM_DO_SAVE_SEGS;
16643 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
16644 &call->eax);
16645 APM_DO_RESTORE_SEGS;
16646 apm_irq_restore(flags);
16647 +
16648 + pax_open_kernel();
16649 gdt[0x40 / 8] = save_desc_40;
16650 + pax_close_kernel();
16651 +
16652 put_cpu();
16653 return error;
16654 }
16655 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
16656 * code to that CPU.
16657 */
16658 gdt = get_cpu_gdt_table(0);
16659 +
16660 + pax_open_kernel();
16661 set_desc_base(&gdt[APM_CS >> 3],
16662 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
16663 set_desc_base(&gdt[APM_CS_16 >> 3],
16664 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
16665 set_desc_base(&gdt[APM_DS >> 3],
16666 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
16667 + pax_close_kernel();
16668
16669 proc_create("apm", 0, NULL, &apm_file_ops);
16670
16671 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
16672 index 2861082..6d4718e 100644
16673 --- a/arch/x86/kernel/asm-offsets.c
16674 +++ b/arch/x86/kernel/asm-offsets.c
16675 @@ -33,6 +33,8 @@ void common(void) {
16676 OFFSET(TI_status, thread_info, status);
16677 OFFSET(TI_addr_limit, thread_info, addr_limit);
16678 OFFSET(TI_preempt_count, thread_info, preempt_count);
16679 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
16680 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
16681
16682 BLANK();
16683 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
16684 @@ -53,8 +55,26 @@ void common(void) {
16685 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
16686 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
16687 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
16688 +
16689 +#ifdef CONFIG_PAX_KERNEXEC
16690 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
16691 #endif
16692
16693 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16694 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
16695 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
16696 +#ifdef CONFIG_X86_64
16697 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
16698 +#endif
16699 +#endif
16700 +
16701 +#endif
16702 +
16703 + BLANK();
16704 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
16705 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
16706 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
16707 +
16708 #ifdef CONFIG_XEN
16709 BLANK();
16710 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
16711 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
16712 index 1b4754f..fbb4227 100644
16713 --- a/arch/x86/kernel/asm-offsets_64.c
16714 +++ b/arch/x86/kernel/asm-offsets_64.c
16715 @@ -76,6 +76,7 @@ int main(void)
16716 BLANK();
16717 #undef ENTRY
16718
16719 + DEFINE(TSS_size, sizeof(struct tss_struct));
16720 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
16721 BLANK();
16722
16723 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
16724 index a0e067d..9c7db16 100644
16725 --- a/arch/x86/kernel/cpu/Makefile
16726 +++ b/arch/x86/kernel/cpu/Makefile
16727 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
16728 CFLAGS_REMOVE_perf_event.o = -pg
16729 endif
16730
16731 -# Make sure load_percpu_segment has no stackprotector
16732 -nostackp := $(call cc-option, -fno-stack-protector)
16733 -CFLAGS_common.o := $(nostackp)
16734 -
16735 obj-y := intel_cacheinfo.o scattered.o topology.o
16736 obj-y += proc.o capflags.o powerflags.o common.o
16737 obj-y += vmware.o hypervisor.o mshyperv.o
16738 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
16739 index 15239ff..e23e04e 100644
16740 --- a/arch/x86/kernel/cpu/amd.c
16741 +++ b/arch/x86/kernel/cpu/amd.c
16742 @@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
16743 unsigned int size)
16744 {
16745 /* AMD errata T13 (order #21922) */
16746 - if ((c->x86 == 6)) {
16747 + if (c->x86 == 6) {
16748 /* Duron Rev A0 */
16749 if (c->x86_model == 3 && c->x86_mask == 0)
16750 size = 64;
16751 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
16752 index 9c3ab43..51e6366 100644
16753 --- a/arch/x86/kernel/cpu/common.c
16754 +++ b/arch/x86/kernel/cpu/common.c
16755 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
16756
16757 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
16758
16759 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
16760 -#ifdef CONFIG_X86_64
16761 - /*
16762 - * We need valid kernel segments for data and code in long mode too
16763 - * IRET will check the segment types kkeil 2000/10/28
16764 - * Also sysret mandates a special GDT layout
16765 - *
16766 - * TLS descriptors are currently at a different place compared to i386.
16767 - * Hopefully nobody expects them at a fixed place (Wine?)
16768 - */
16769 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
16770 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
16771 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
16772 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
16773 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
16774 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
16775 -#else
16776 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
16777 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16778 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
16779 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
16780 - /*
16781 - * Segments used for calling PnP BIOS have byte granularity.
16782 - * They code segments and data segments have fixed 64k limits,
16783 - * the transfer segment sizes are set at run time.
16784 - */
16785 - /* 32-bit code */
16786 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16787 - /* 16-bit code */
16788 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16789 - /* 16-bit data */
16790 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
16791 - /* 16-bit data */
16792 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
16793 - /* 16-bit data */
16794 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
16795 - /*
16796 - * The APM segments have byte granularity and their bases
16797 - * are set at run time. All have 64k limits.
16798 - */
16799 - /* 32-bit code */
16800 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16801 - /* 16-bit code */
16802 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16803 - /* data */
16804 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
16805 -
16806 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16807 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16808 - GDT_STACK_CANARY_INIT
16809 -#endif
16810 -} };
16811 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
16812 -
16813 static int __init x86_xsave_setup(char *s)
16814 {
16815 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
16816 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
16817 {
16818 struct desc_ptr gdt_descr;
16819
16820 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
16821 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16822 gdt_descr.size = GDT_SIZE - 1;
16823 load_gdt(&gdt_descr);
16824 /* Reload the per-cpu base */
16825 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
16826 /* Filter out anything that depends on CPUID levels we don't have */
16827 filter_cpuid_features(c, true);
16828
16829 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16830 + setup_clear_cpu_cap(X86_FEATURE_SEP);
16831 +#endif
16832 +
16833 /* If the model name is still unset, do table lookup. */
16834 if (!c->x86_model_id[0]) {
16835 const char *p;
16836 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
16837 }
16838 __setup("clearcpuid=", setup_disablecpuid);
16839
16840 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
16841 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
16842 +
16843 #ifdef CONFIG_X86_64
16844 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
16845 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
16846 - (unsigned long) nmi_idt_table };
16847 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
16848
16849 DEFINE_PER_CPU_FIRST(union irq_stack_union,
16850 irq_stack_union) __aligned(PAGE_SIZE);
16851 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
16852 EXPORT_PER_CPU_SYMBOL(current_task);
16853
16854 DEFINE_PER_CPU(unsigned long, kernel_stack) =
16855 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
16856 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
16857 EXPORT_PER_CPU_SYMBOL(kernel_stack);
16858
16859 DEFINE_PER_CPU(char *, irq_stack_ptr) =
16860 @@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
16861 int i;
16862
16863 cpu = stack_smp_processor_id();
16864 - t = &per_cpu(init_tss, cpu);
16865 + t = init_tss + cpu;
16866 oist = &per_cpu(orig_ist, cpu);
16867
16868 #ifdef CONFIG_NUMA
16869 @@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
16870 switch_to_new_gdt(cpu);
16871 loadsegment(fs, 0);
16872
16873 - load_idt((const struct desc_ptr *)&idt_descr);
16874 + load_idt(&idt_descr);
16875
16876 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
16877 syscall_init();
16878 @@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
16879 wrmsrl(MSR_KERNEL_GS_BASE, 0);
16880 barrier();
16881
16882 - x86_configure_nx();
16883 enable_x2apic();
16884
16885 /*
16886 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
16887 {
16888 int cpu = smp_processor_id();
16889 struct task_struct *curr = current;
16890 - struct tss_struct *t = &per_cpu(init_tss, cpu);
16891 + struct tss_struct *t = init_tss + cpu;
16892 struct thread_struct *thread = &curr->thread;
16893
16894 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
16895 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
16896 index fcaabd0..7b55a26 100644
16897 --- a/arch/x86/kernel/cpu/intel.c
16898 +++ b/arch/x86/kernel/cpu/intel.c
16899 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
16900 * Update the IDT descriptor and reload the IDT so that
16901 * it uses the read-only mapped virtual address.
16902 */
16903 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
16904 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
16905 load_idt(&idt_descr);
16906 }
16907 #endif
16908 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
16909 index 84c1309..39b7224 100644
16910 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
16911 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
16912 @@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
16913 };
16914
16915 #ifdef CONFIG_AMD_NB
16916 +static struct attribute *default_attrs_amd_nb[] = {
16917 + &type.attr,
16918 + &level.attr,
16919 + &coherency_line_size.attr,
16920 + &physical_line_partition.attr,
16921 + &ways_of_associativity.attr,
16922 + &number_of_sets.attr,
16923 + &size.attr,
16924 + &shared_cpu_map.attr,
16925 + &shared_cpu_list.attr,
16926 + NULL,
16927 + NULL,
16928 + NULL,
16929 + NULL
16930 +};
16931 +
16932 static struct attribute ** __cpuinit amd_l3_attrs(void)
16933 {
16934 static struct attribute **attrs;
16935 @@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
16936
16937 n = ARRAY_SIZE(default_attrs);
16938
16939 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
16940 - n += 2;
16941 -
16942 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
16943 - n += 1;
16944 -
16945 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
16946 - if (attrs == NULL)
16947 - return attrs = default_attrs;
16948 -
16949 - for (n = 0; default_attrs[n]; n++)
16950 - attrs[n] = default_attrs[n];
16951 + attrs = default_attrs_amd_nb;
16952
16953 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
16954 attrs[n++] = &cache_disable_0.attr;
16955 @@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
16956 .default_attrs = default_attrs,
16957 };
16958
16959 +#ifdef CONFIG_AMD_NB
16960 +static struct kobj_type ktype_cache_amd_nb = {
16961 + .sysfs_ops = &sysfs_ops,
16962 + .default_attrs = default_attrs_amd_nb,
16963 +};
16964 +#endif
16965 +
16966 static struct kobj_type ktype_percpu_entry = {
16967 .sysfs_ops = &sysfs_ops,
16968 };
16969 @@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
16970 return retval;
16971 }
16972
16973 +#ifdef CONFIG_AMD_NB
16974 + amd_l3_attrs();
16975 +#endif
16976 +
16977 for (i = 0; i < num_cache_leaves; i++) {
16978 + struct kobj_type *ktype;
16979 +
16980 this_object = INDEX_KOBJECT_PTR(cpu, i);
16981 this_object->cpu = cpu;
16982 this_object->index = i;
16983
16984 this_leaf = CPUID4_INFO_IDX(cpu, i);
16985
16986 - ktype_cache.default_attrs = default_attrs;
16987 + ktype = &ktype_cache;
16988 #ifdef CONFIG_AMD_NB
16989 if (this_leaf->base.nb)
16990 - ktype_cache.default_attrs = amd_l3_attrs();
16991 + ktype = &ktype_cache_amd_nb;
16992 #endif
16993 retval = kobject_init_and_add(&(this_object->kobj),
16994 - &ktype_cache,
16995 + ktype,
16996 per_cpu(ici_cache_kobject, cpu),
16997 "index%1lu", i);
16998 if (unlikely(retval)) {
16999 @@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17000 return NOTIFY_OK;
17001 }
17002
17003 -static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17004 +static struct notifier_block cacheinfo_cpu_notifier = {
17005 .notifier_call = cacheinfo_cpu_callback,
17006 };
17007
17008 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17009 index 80dbda8..be16652 100644
17010 --- a/arch/x86/kernel/cpu/mcheck/mce.c
17011 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
17012 @@ -45,6 +45,7 @@
17013 #include <asm/processor.h>
17014 #include <asm/mce.h>
17015 #include <asm/msr.h>
17016 +#include <asm/local.h>
17017
17018 #include "mce-internal.h"
17019
17020 @@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17021 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17022 m->cs, m->ip);
17023
17024 - if (m->cs == __KERNEL_CS)
17025 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17026 print_symbol("{%s}", m->ip);
17027 pr_cont("\n");
17028 }
17029 @@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17030
17031 #define PANIC_TIMEOUT 5 /* 5 seconds */
17032
17033 -static atomic_t mce_paniced;
17034 +static atomic_unchecked_t mce_paniced;
17035
17036 static int fake_panic;
17037 -static atomic_t mce_fake_paniced;
17038 +static atomic_unchecked_t mce_fake_paniced;
17039
17040 /* Panic in progress. Enable interrupts and wait for final IPI */
17041 static void wait_for_panic(void)
17042 @@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17043 /*
17044 * Make sure only one CPU runs in machine check panic
17045 */
17046 - if (atomic_inc_return(&mce_paniced) > 1)
17047 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17048 wait_for_panic();
17049 barrier();
17050
17051 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17052 console_verbose();
17053 } else {
17054 /* Don't log too much for fake panic */
17055 - if (atomic_inc_return(&mce_fake_paniced) > 1)
17056 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17057 return;
17058 }
17059 /* First print corrected ones that are still unlogged */
17060 @@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
17061 * might have been modified by someone else.
17062 */
17063 rmb();
17064 - if (atomic_read(&mce_paniced))
17065 + if (atomic_read_unchecked(&mce_paniced))
17066 wait_for_panic();
17067 if (!mca_cfg.monarch_timeout)
17068 goto out;
17069 @@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17070 }
17071
17072 /* Call the installed machine check handler for this CPU setup. */
17073 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
17074 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17075 unexpected_machine_check;
17076
17077 /*
17078 @@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17079 return;
17080 }
17081
17082 + pax_open_kernel();
17083 machine_check_vector = do_machine_check;
17084 + pax_close_kernel();
17085
17086 __mcheck_cpu_init_generic();
17087 __mcheck_cpu_init_vendor(c);
17088 @@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17089 */
17090
17091 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17092 -static int mce_chrdev_open_count; /* #times opened */
17093 +static local_t mce_chrdev_open_count; /* #times opened */
17094 static int mce_chrdev_open_exclu; /* already open exclusive? */
17095
17096 static int mce_chrdev_open(struct inode *inode, struct file *file)
17097 @@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17098 spin_lock(&mce_chrdev_state_lock);
17099
17100 if (mce_chrdev_open_exclu ||
17101 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17102 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17103 spin_unlock(&mce_chrdev_state_lock);
17104
17105 return -EBUSY;
17106 @@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17107
17108 if (file->f_flags & O_EXCL)
17109 mce_chrdev_open_exclu = 1;
17110 - mce_chrdev_open_count++;
17111 + local_inc(&mce_chrdev_open_count);
17112
17113 spin_unlock(&mce_chrdev_state_lock);
17114
17115 @@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17116 {
17117 spin_lock(&mce_chrdev_state_lock);
17118
17119 - mce_chrdev_open_count--;
17120 + local_dec(&mce_chrdev_open_count);
17121 mce_chrdev_open_exclu = 0;
17122
17123 spin_unlock(&mce_chrdev_state_lock);
17124 @@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17125 return NOTIFY_OK;
17126 }
17127
17128 -static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17129 +static struct notifier_block mce_cpu_notifier = {
17130 .notifier_call = mce_cpu_callback,
17131 };
17132
17133 @@ -2382,7 +2385,7 @@ static __init void mce_init_banks(void)
17134
17135 for (i = 0; i < mca_cfg.banks; i++) {
17136 struct mce_bank *b = &mce_banks[i];
17137 - struct device_attribute *a = &b->attr;
17138 + device_attribute_no_const *a = &b->attr;
17139
17140 sysfs_attr_init(&a->attr);
17141 a->attr.name = b->attrname;
17142 @@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
17143 static void mce_reset(void)
17144 {
17145 cpu_missing = 0;
17146 - atomic_set(&mce_fake_paniced, 0);
17147 + atomic_set_unchecked(&mce_fake_paniced, 0);
17148 atomic_set(&mce_executing, 0);
17149 atomic_set(&mce_callin, 0);
17150 atomic_set(&global_nwo, 0);
17151 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17152 index 2d5454c..51987eb 100644
17153 --- a/arch/x86/kernel/cpu/mcheck/p5.c
17154 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
17155 @@ -11,6 +11,7 @@
17156 #include <asm/processor.h>
17157 #include <asm/mce.h>
17158 #include <asm/msr.h>
17159 +#include <asm/pgtable.h>
17160
17161 /* By default disabled */
17162 int mce_p5_enabled __read_mostly;
17163 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17164 if (!cpu_has(c, X86_FEATURE_MCE))
17165 return;
17166
17167 + pax_open_kernel();
17168 machine_check_vector = pentium_machine_check;
17169 + pax_close_kernel();
17170 /* Make sure the vector pointer is visible before we enable MCEs: */
17171 wmb();
17172
17173 diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17174 index 47a1870..8c019a7 100644
17175 --- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17176 +++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17177 @@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17178 return notifier_from_errno(err);
17179 }
17180
17181 -static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17182 +static struct notifier_block thermal_throttle_cpu_notifier =
17183 {
17184 .notifier_call = thermal_throttle_cpu_callback,
17185 };
17186 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17187 index 2d7998f..17c9de1 100644
17188 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
17189 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17190 @@ -10,6 +10,7 @@
17191 #include <asm/processor.h>
17192 #include <asm/mce.h>
17193 #include <asm/msr.h>
17194 +#include <asm/pgtable.h>
17195
17196 /* Machine check handler for WinChip C6: */
17197 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17198 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17199 {
17200 u32 lo, hi;
17201
17202 + pax_open_kernel();
17203 machine_check_vector = winchip_machine_check;
17204 + pax_close_kernel();
17205 /* Make sure the vector pointer is visible before we enable MCEs: */
17206 wmb();
17207
17208 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17209 index 726bf96..81f0526 100644
17210 --- a/arch/x86/kernel/cpu/mtrr/main.c
17211 +++ b/arch/x86/kernel/cpu/mtrr/main.c
17212 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17213 u64 size_or_mask, size_and_mask;
17214 static bool mtrr_aps_delayed_init;
17215
17216 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17217 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17218
17219 const struct mtrr_ops *mtrr_if;
17220
17221 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17222 index df5e41f..816c719 100644
17223 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17224 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17225 @@ -25,7 +25,7 @@ struct mtrr_ops {
17226 int (*validate_add_page)(unsigned long base, unsigned long size,
17227 unsigned int type);
17228 int (*have_wrcomb)(void);
17229 -};
17230 +} __do_const;
17231
17232 extern int generic_get_free_region(unsigned long base, unsigned long size,
17233 int replace_reg);
17234 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17235 index 6774c17..72c1b22 100644
17236 --- a/arch/x86/kernel/cpu/perf_event.c
17237 +++ b/arch/x86/kernel/cpu/perf_event.c
17238 @@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17239 pr_info("no hardware sampling interrupt available.\n");
17240 }
17241
17242 -static struct attribute_group x86_pmu_format_group = {
17243 +static attribute_group_no_const x86_pmu_format_group = {
17244 .name = "format",
17245 .attrs = NULL,
17246 };
17247 @@ -1313,7 +1313,7 @@ static struct attribute_group x86_pmu_format_group = {
17248 struct perf_pmu_events_attr {
17249 struct device_attribute attr;
17250 u64 id;
17251 -};
17252 +} __do_const;
17253
17254 /*
17255 * Remove all undefined events (x86_pmu.event_map(id) == 0)
17256 @@ -1381,7 +1381,7 @@ static struct attribute *events_attr[] = {
17257 NULL,
17258 };
17259
17260 -static struct attribute_group x86_pmu_events_group = {
17261 +static attribute_group_no_const x86_pmu_events_group = {
17262 .name = "events",
17263 .attrs = events_attr,
17264 };
17265 @@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17266 if (idx > GDT_ENTRIES)
17267 return 0;
17268
17269 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17270 + desc = get_cpu_gdt_table(smp_processor_id());
17271 }
17272
17273 return get_desc_base(desc + idx);
17274 @@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17275 break;
17276
17277 perf_callchain_store(entry, frame.return_address);
17278 - fp = frame.next_frame;
17279 + fp = (const void __force_user *)frame.next_frame;
17280 }
17281 }
17282
17283 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17284 index 4914e94..60b06e3 100644
17285 --- a/arch/x86/kernel/cpu/perf_event_intel.c
17286 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
17287 @@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17288 * v2 and above have a perf capabilities MSR
17289 */
17290 if (version > 1) {
17291 - u64 capabilities;
17292 + u64 capabilities = x86_pmu.intel_cap.capabilities;
17293
17294 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17295 - x86_pmu.intel_cap.capabilities = capabilities;
17296 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17297 + x86_pmu.intel_cap.capabilities = capabilities;
17298 }
17299
17300 intel_ds_init();
17301 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17302 index b43200d..7fdcdbb 100644
17303 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17304 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17305 @@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17306 static int __init uncore_type_init(struct intel_uncore_type *type)
17307 {
17308 struct intel_uncore_pmu *pmus;
17309 - struct attribute_group *events_group;
17310 + attribute_group_no_const *events_group;
17311 struct attribute **attrs;
17312 int i, j;
17313
17314 @@ -2826,7 +2826,7 @@ static int
17315 return NOTIFY_OK;
17316 }
17317
17318 -static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17319 +static struct notifier_block uncore_cpu_nb = {
17320 .notifier_call = uncore_cpu_notifier,
17321 /*
17322 * to migrate uncore events, our notifier should be executed
17323 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17324 index e68a455..975a932 100644
17325 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17326 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17327 @@ -428,7 +428,7 @@ struct intel_uncore_box {
17328 struct uncore_event_desc {
17329 struct kobj_attribute attr;
17330 const char *config;
17331 -};
17332 +} __do_const;
17333
17334 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17335 { \
17336 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17337 index 60c7891..9e911d3 100644
17338 --- a/arch/x86/kernel/cpuid.c
17339 +++ b/arch/x86/kernel/cpuid.c
17340 @@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17341 return notifier_from_errno(err);
17342 }
17343
17344 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
17345 +static struct notifier_block cpuid_class_cpu_notifier =
17346 {
17347 .notifier_call = cpuid_class_cpu_callback,
17348 };
17349 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17350 index 74467fe..18793d5 100644
17351 --- a/arch/x86/kernel/crash.c
17352 +++ b/arch/x86/kernel/crash.c
17353 @@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17354 {
17355 #ifdef CONFIG_X86_32
17356 struct pt_regs fixed_regs;
17357 -#endif
17358
17359 -#ifdef CONFIG_X86_32
17360 - if (!user_mode_vm(regs)) {
17361 + if (!user_mode(regs)) {
17362 crash_fixup_ss_esp(&fixed_regs, regs);
17363 regs = &fixed_regs;
17364 }
17365 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17366 index 37250fe..bf2ec74 100644
17367 --- a/arch/x86/kernel/doublefault_32.c
17368 +++ b/arch/x86/kernel/doublefault_32.c
17369 @@ -11,7 +11,7 @@
17370
17371 #define DOUBLEFAULT_STACKSIZE (1024)
17372 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17373 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17374 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17375
17376 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17377
17378 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
17379 unsigned long gdt, tss;
17380
17381 store_gdt(&gdt_desc);
17382 - gdt = gdt_desc.address;
17383 + gdt = (unsigned long)gdt_desc.address;
17384
17385 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17386
17387 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17388 /* 0x2 bit is always set */
17389 .flags = X86_EFLAGS_SF | 0x2,
17390 .sp = STACK_START,
17391 - .es = __USER_DS,
17392 + .es = __KERNEL_DS,
17393 .cs = __KERNEL_CS,
17394 .ss = __KERNEL_DS,
17395 - .ds = __USER_DS,
17396 + .ds = __KERNEL_DS,
17397 .fs = __KERNEL_PERCPU,
17398
17399 .__cr3 = __pa_nodebug(swapper_pg_dir),
17400 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17401 index ae42418b..787c16b 100644
17402 --- a/arch/x86/kernel/dumpstack.c
17403 +++ b/arch/x86/kernel/dumpstack.c
17404 @@ -2,6 +2,9 @@
17405 * Copyright (C) 1991, 1992 Linus Torvalds
17406 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17407 */
17408 +#ifdef CONFIG_GRKERNSEC_HIDESYM
17409 +#define __INCLUDED_BY_HIDESYM 1
17410 +#endif
17411 #include <linux/kallsyms.h>
17412 #include <linux/kprobes.h>
17413 #include <linux/uaccess.h>
17414 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17415 static void
17416 print_ftrace_graph_addr(unsigned long addr, void *data,
17417 const struct stacktrace_ops *ops,
17418 - struct thread_info *tinfo, int *graph)
17419 + struct task_struct *task, int *graph)
17420 {
17421 - struct task_struct *task;
17422 unsigned long ret_addr;
17423 int index;
17424
17425 if (addr != (unsigned long)return_to_handler)
17426 return;
17427
17428 - task = tinfo->task;
17429 index = task->curr_ret_stack;
17430
17431 if (!task->ret_stack || index < *graph)
17432 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17433 static inline void
17434 print_ftrace_graph_addr(unsigned long addr, void *data,
17435 const struct stacktrace_ops *ops,
17436 - struct thread_info *tinfo, int *graph)
17437 + struct task_struct *task, int *graph)
17438 { }
17439 #endif
17440
17441 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17442 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17443 */
17444
17445 -static inline int valid_stack_ptr(struct thread_info *tinfo,
17446 - void *p, unsigned int size, void *end)
17447 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17448 {
17449 - void *t = tinfo;
17450 if (end) {
17451 if (p < end && p >= (end-THREAD_SIZE))
17452 return 1;
17453 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17454 }
17455
17456 unsigned long
17457 -print_context_stack(struct thread_info *tinfo,
17458 +print_context_stack(struct task_struct *task, void *stack_start,
17459 unsigned long *stack, unsigned long bp,
17460 const struct stacktrace_ops *ops, void *data,
17461 unsigned long *end, int *graph)
17462 {
17463 struct stack_frame *frame = (struct stack_frame *)bp;
17464
17465 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17466 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17467 unsigned long addr;
17468
17469 addr = *stack;
17470 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17471 } else {
17472 ops->address(data, addr, 0);
17473 }
17474 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17475 + print_ftrace_graph_addr(addr, data, ops, task, graph);
17476 }
17477 stack++;
17478 }
17479 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17480 EXPORT_SYMBOL_GPL(print_context_stack);
17481
17482 unsigned long
17483 -print_context_stack_bp(struct thread_info *tinfo,
17484 +print_context_stack_bp(struct task_struct *task, void *stack_start,
17485 unsigned long *stack, unsigned long bp,
17486 const struct stacktrace_ops *ops, void *data,
17487 unsigned long *end, int *graph)
17488 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17489 struct stack_frame *frame = (struct stack_frame *)bp;
17490 unsigned long *ret_addr = &frame->return_address;
17491
17492 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17493 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17494 unsigned long addr = *ret_addr;
17495
17496 if (!__kernel_text_address(addr))
17497 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17498 ops->address(data, addr, 1);
17499 frame = frame->next_frame;
17500 ret_addr = &frame->return_address;
17501 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17502 + print_ftrace_graph_addr(addr, data, ops, task, graph);
17503 }
17504
17505 return (unsigned long)frame;
17506 @@ -189,7 +188,7 @@ void dump_stack(void)
17507
17508 bp = stack_frame(current, NULL);
17509 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17510 - current->pid, current->comm, print_tainted(),
17511 + task_pid_nr(current), current->comm, print_tainted(),
17512 init_utsname()->release,
17513 (int)strcspn(init_utsname()->version, " "),
17514 init_utsname()->version);
17515 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17516 }
17517 EXPORT_SYMBOL_GPL(oops_begin);
17518
17519 +extern void gr_handle_kernel_exploit(void);
17520 +
17521 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17522 {
17523 if (regs && kexec_should_crash(current))
17524 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17525 panic("Fatal exception in interrupt");
17526 if (panic_on_oops)
17527 panic("Fatal exception");
17528 - do_exit(signr);
17529 +
17530 + gr_handle_kernel_exploit();
17531 +
17532 + do_group_exit(signr);
17533 }
17534
17535 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17536 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17537 print_modules();
17538 show_regs(regs);
17539 #ifdef CONFIG_X86_32
17540 - if (user_mode_vm(regs)) {
17541 + if (user_mode(regs)) {
17542 sp = regs->sp;
17543 ss = regs->ss & 0xffff;
17544 } else {
17545 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17546 unsigned long flags = oops_begin();
17547 int sig = SIGSEGV;
17548
17549 - if (!user_mode_vm(regs))
17550 + if (!user_mode(regs))
17551 report_bug(regs->ip, regs);
17552
17553 if (__die(str, regs, err))
17554 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17555 index 1038a41..db2c12b 100644
17556 --- a/arch/x86/kernel/dumpstack_32.c
17557 +++ b/arch/x86/kernel/dumpstack_32.c
17558 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17559 bp = stack_frame(task, regs);
17560
17561 for (;;) {
17562 - struct thread_info *context;
17563 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17564
17565 - context = (struct thread_info *)
17566 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17567 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17568 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17569
17570 - stack = (unsigned long *)context->previous_esp;
17571 - if (!stack)
17572 + if (stack_start == task_stack_page(task))
17573 break;
17574 + stack = *(unsigned long **)stack_start;
17575 if (ops->stack(data, "IRQ") < 0)
17576 break;
17577 touch_nmi_watchdog();
17578 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17579 {
17580 int i;
17581
17582 - __show_regs(regs, !user_mode_vm(regs));
17583 + __show_regs(regs, !user_mode(regs));
17584
17585 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17586 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17587 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17588 * When in-kernel, we also print out the stack and code at the
17589 * time of the fault..
17590 */
17591 - if (!user_mode_vm(regs)) {
17592 + if (!user_mode(regs)) {
17593 unsigned int code_prologue = code_bytes * 43 / 64;
17594 unsigned int code_len = code_bytes;
17595 unsigned char c;
17596 u8 *ip;
17597 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
17598
17599 pr_emerg("Stack:\n");
17600 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
17601
17602 pr_emerg("Code:");
17603
17604 - ip = (u8 *)regs->ip - code_prologue;
17605 + ip = (u8 *)regs->ip - code_prologue + cs_base;
17606 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
17607 /* try starting at IP */
17608 - ip = (u8 *)regs->ip;
17609 + ip = (u8 *)regs->ip + cs_base;
17610 code_len = code_len - code_prologue + 1;
17611 }
17612 for (i = 0; i < code_len; i++, ip++) {
17613 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
17614 pr_cont(" Bad EIP value.");
17615 break;
17616 }
17617 - if (ip == (u8 *)regs->ip)
17618 + if (ip == (u8 *)regs->ip + cs_base)
17619 pr_cont(" <%02x>", c);
17620 else
17621 pr_cont(" %02x", c);
17622 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
17623 {
17624 unsigned short ud2;
17625
17626 + ip = ktla_ktva(ip);
17627 if (ip < PAGE_OFFSET)
17628 return 0;
17629 if (probe_kernel_address((unsigned short *)ip, ud2))
17630 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
17631
17632 return ud2 == 0x0b0f;
17633 }
17634 +
17635 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17636 +void pax_check_alloca(unsigned long size)
17637 +{
17638 + unsigned long sp = (unsigned long)&sp, stack_left;
17639 +
17640 + /* all kernel stacks are of the same size */
17641 + stack_left = sp & (THREAD_SIZE - 1);
17642 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17643 +}
17644 +EXPORT_SYMBOL(pax_check_alloca);
17645 +#endif
17646 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
17647 index b653675..51cc8c0 100644
17648 --- a/arch/x86/kernel/dumpstack_64.c
17649 +++ b/arch/x86/kernel/dumpstack_64.c
17650 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17651 unsigned long *irq_stack_end =
17652 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
17653 unsigned used = 0;
17654 - struct thread_info *tinfo;
17655 int graph = 0;
17656 unsigned long dummy;
17657 + void *stack_start;
17658
17659 if (!task)
17660 task = current;
17661 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17662 * current stack address. If the stacks consist of nested
17663 * exceptions
17664 */
17665 - tinfo = task_thread_info(task);
17666 for (;;) {
17667 char *id;
17668 unsigned long *estack_end;
17669 +
17670 estack_end = in_exception_stack(cpu, (unsigned long)stack,
17671 &used, &id);
17672
17673 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17674 if (ops->stack(data, id) < 0)
17675 break;
17676
17677 - bp = ops->walk_stack(tinfo, stack, bp, ops,
17678 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
17679 data, estack_end, &graph);
17680 ops->stack(data, "<EOE>");
17681 /*
17682 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17683 * second-to-last pointer (index -2 to end) in the
17684 * exception stack:
17685 */
17686 + if ((u16)estack_end[-1] != __KERNEL_DS)
17687 + goto out;
17688 stack = (unsigned long *) estack_end[-2];
17689 continue;
17690 }
17691 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17692 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
17693 if (ops->stack(data, "IRQ") < 0)
17694 break;
17695 - bp = ops->walk_stack(tinfo, stack, bp,
17696 + bp = ops->walk_stack(task, irq_stack, stack, bp,
17697 ops, data, irq_stack_end, &graph);
17698 /*
17699 * We link to the next stack (which would be
17700 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17701 /*
17702 * This handles the process stack:
17703 */
17704 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
17705 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17706 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17707 +out:
17708 put_cpu();
17709 }
17710 EXPORT_SYMBOL(dump_trace);
17711 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
17712 {
17713 int i;
17714 unsigned long sp;
17715 - const int cpu = smp_processor_id();
17716 + const int cpu = raw_smp_processor_id();
17717 struct task_struct *cur = current;
17718
17719 sp = regs->sp;
17720 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
17721
17722 return ud2 == 0x0b0f;
17723 }
17724 +
17725 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17726 +void pax_check_alloca(unsigned long size)
17727 +{
17728 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
17729 + unsigned cpu, used;
17730 + char *id;
17731 +
17732 + /* check the process stack first */
17733 + stack_start = (unsigned long)task_stack_page(current);
17734 + stack_end = stack_start + THREAD_SIZE;
17735 + if (likely(stack_start <= sp && sp < stack_end)) {
17736 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
17737 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17738 + return;
17739 + }
17740 +
17741 + cpu = get_cpu();
17742 +
17743 + /* check the irq stacks */
17744 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
17745 + stack_start = stack_end - IRQ_STACK_SIZE;
17746 + if (stack_start <= sp && sp < stack_end) {
17747 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
17748 + put_cpu();
17749 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17750 + return;
17751 + }
17752 +
17753 + /* check the exception stacks */
17754 + used = 0;
17755 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
17756 + stack_start = stack_end - EXCEPTION_STKSZ;
17757 + if (stack_end && stack_start <= sp && sp < stack_end) {
17758 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
17759 + put_cpu();
17760 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17761 + return;
17762 + }
17763 +
17764 + put_cpu();
17765 +
17766 + /* unknown stack */
17767 + BUG();
17768 +}
17769 +EXPORT_SYMBOL(pax_check_alloca);
17770 +#endif
17771 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
17772 index 9b9f18b..9fcaa04 100644
17773 --- a/arch/x86/kernel/early_printk.c
17774 +++ b/arch/x86/kernel/early_printk.c
17775 @@ -7,6 +7,7 @@
17776 #include <linux/pci_regs.h>
17777 #include <linux/pci_ids.h>
17778 #include <linux/errno.h>
17779 +#include <linux/sched.h>
17780 #include <asm/io.h>
17781 #include <asm/processor.h>
17782 #include <asm/fcntl.h>
17783 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
17784 index 6ed91d9..6cc365b 100644
17785 --- a/arch/x86/kernel/entry_32.S
17786 +++ b/arch/x86/kernel/entry_32.S
17787 @@ -177,13 +177,153 @@
17788 /*CFI_REL_OFFSET gs, PT_GS*/
17789 .endm
17790 .macro SET_KERNEL_GS reg
17791 +
17792 +#ifdef CONFIG_CC_STACKPROTECTOR
17793 movl $(__KERNEL_STACK_CANARY), \reg
17794 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17795 + movl $(__USER_DS), \reg
17796 +#else
17797 + xorl \reg, \reg
17798 +#endif
17799 +
17800 movl \reg, %gs
17801 .endm
17802
17803 #endif /* CONFIG_X86_32_LAZY_GS */
17804
17805 -.macro SAVE_ALL
17806 +.macro pax_enter_kernel
17807 +#ifdef CONFIG_PAX_KERNEXEC
17808 + call pax_enter_kernel
17809 +#endif
17810 +.endm
17811 +
17812 +.macro pax_exit_kernel
17813 +#ifdef CONFIG_PAX_KERNEXEC
17814 + call pax_exit_kernel
17815 +#endif
17816 +.endm
17817 +
17818 +#ifdef CONFIG_PAX_KERNEXEC
17819 +ENTRY(pax_enter_kernel)
17820 +#ifdef CONFIG_PARAVIRT
17821 + pushl %eax
17822 + pushl %ecx
17823 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
17824 + mov %eax, %esi
17825 +#else
17826 + mov %cr0, %esi
17827 +#endif
17828 + bts $16, %esi
17829 + jnc 1f
17830 + mov %cs, %esi
17831 + cmp $__KERNEL_CS, %esi
17832 + jz 3f
17833 + ljmp $__KERNEL_CS, $3f
17834 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
17835 +2:
17836 +#ifdef CONFIG_PARAVIRT
17837 + mov %esi, %eax
17838 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17839 +#else
17840 + mov %esi, %cr0
17841 +#endif
17842 +3:
17843 +#ifdef CONFIG_PARAVIRT
17844 + popl %ecx
17845 + popl %eax
17846 +#endif
17847 + ret
17848 +ENDPROC(pax_enter_kernel)
17849 +
17850 +ENTRY(pax_exit_kernel)
17851 +#ifdef CONFIG_PARAVIRT
17852 + pushl %eax
17853 + pushl %ecx
17854 +#endif
17855 + mov %cs, %esi
17856 + cmp $__KERNEXEC_KERNEL_CS, %esi
17857 + jnz 2f
17858 +#ifdef CONFIG_PARAVIRT
17859 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
17860 + mov %eax, %esi
17861 +#else
17862 + mov %cr0, %esi
17863 +#endif
17864 + btr $16, %esi
17865 + ljmp $__KERNEL_CS, $1f
17866 +1:
17867 +#ifdef CONFIG_PARAVIRT
17868 + mov %esi, %eax
17869 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
17870 +#else
17871 + mov %esi, %cr0
17872 +#endif
17873 +2:
17874 +#ifdef CONFIG_PARAVIRT
17875 + popl %ecx
17876 + popl %eax
17877 +#endif
17878 + ret
17879 +ENDPROC(pax_exit_kernel)
17880 +#endif
17881 +
17882 +.macro pax_erase_kstack
17883 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17884 + call pax_erase_kstack
17885 +#endif
17886 +.endm
17887 +
17888 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17889 +/*
17890 + * ebp: thread_info
17891 + */
17892 +ENTRY(pax_erase_kstack)
17893 + pushl %edi
17894 + pushl %ecx
17895 + pushl %eax
17896 +
17897 + mov TI_lowest_stack(%ebp), %edi
17898 + mov $-0xBEEF, %eax
17899 + std
17900 +
17901 +1: mov %edi, %ecx
17902 + and $THREAD_SIZE_asm - 1, %ecx
17903 + shr $2, %ecx
17904 + repne scasl
17905 + jecxz 2f
17906 +
17907 + cmp $2*16, %ecx
17908 + jc 2f
17909 +
17910 + mov $2*16, %ecx
17911 + repe scasl
17912 + jecxz 2f
17913 + jne 1b
17914 +
17915 +2: cld
17916 + mov %esp, %ecx
17917 + sub %edi, %ecx
17918 +
17919 + cmp $THREAD_SIZE_asm, %ecx
17920 + jb 3f
17921 + ud2
17922 +3:
17923 +
17924 + shr $2, %ecx
17925 + rep stosl
17926 +
17927 + mov TI_task_thread_sp0(%ebp), %edi
17928 + sub $128, %edi
17929 + mov %edi, TI_lowest_stack(%ebp)
17930 +
17931 + popl %eax
17932 + popl %ecx
17933 + popl %edi
17934 + ret
17935 +ENDPROC(pax_erase_kstack)
17936 +#endif
17937 +
17938 +.macro __SAVE_ALL _DS
17939 cld
17940 PUSH_GS
17941 pushl_cfi %fs
17942 @@ -206,7 +346,7 @@
17943 CFI_REL_OFFSET ecx, 0
17944 pushl_cfi %ebx
17945 CFI_REL_OFFSET ebx, 0
17946 - movl $(__USER_DS), %edx
17947 + movl $\_DS, %edx
17948 movl %edx, %ds
17949 movl %edx, %es
17950 movl $(__KERNEL_PERCPU), %edx
17951 @@ -214,6 +354,15 @@
17952 SET_KERNEL_GS %edx
17953 .endm
17954
17955 +.macro SAVE_ALL
17956 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
17957 + __SAVE_ALL __KERNEL_DS
17958 + pax_enter_kernel
17959 +#else
17960 + __SAVE_ALL __USER_DS
17961 +#endif
17962 +.endm
17963 +
17964 .macro RESTORE_INT_REGS
17965 popl_cfi %ebx
17966 CFI_RESTORE ebx
17967 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
17968 popfl_cfi
17969 jmp syscall_exit
17970 CFI_ENDPROC
17971 -END(ret_from_fork)
17972 +ENDPROC(ret_from_fork)
17973
17974 ENTRY(ret_from_kernel_thread)
17975 CFI_STARTPROC
17976 @@ -344,7 +493,15 @@ ret_from_intr:
17977 andl $SEGMENT_RPL_MASK, %eax
17978 #endif
17979 cmpl $USER_RPL, %eax
17980 +
17981 +#ifdef CONFIG_PAX_KERNEXEC
17982 + jae resume_userspace
17983 +
17984 + pax_exit_kernel
17985 + jmp resume_kernel
17986 +#else
17987 jb resume_kernel # not returning to v8086 or userspace
17988 +#endif
17989
17990 ENTRY(resume_userspace)
17991 LOCKDEP_SYS_EXIT
17992 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
17993 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
17994 # int/exception return?
17995 jne work_pending
17996 - jmp restore_all
17997 -END(ret_from_exception)
17998 + jmp restore_all_pax
17999 +ENDPROC(ret_from_exception)
18000
18001 #ifdef CONFIG_PREEMPT
18002 ENTRY(resume_kernel)
18003 @@ -372,7 +529,7 @@ need_resched:
18004 jz restore_all
18005 call preempt_schedule_irq
18006 jmp need_resched
18007 -END(resume_kernel)
18008 +ENDPROC(resume_kernel)
18009 #endif
18010 CFI_ENDPROC
18011 /*
18012 @@ -406,30 +563,45 @@ sysenter_past_esp:
18013 /*CFI_REL_OFFSET cs, 0*/
18014 /*
18015 * Push current_thread_info()->sysenter_return to the stack.
18016 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18017 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
18018 */
18019 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18020 + pushl_cfi $0
18021 CFI_REL_OFFSET eip, 0
18022
18023 pushl_cfi %eax
18024 SAVE_ALL
18025 + GET_THREAD_INFO(%ebp)
18026 + movl TI_sysenter_return(%ebp),%ebp
18027 + movl %ebp,PT_EIP(%esp)
18028 ENABLE_INTERRUPTS(CLBR_NONE)
18029
18030 /*
18031 * Load the potential sixth argument from user stack.
18032 * Careful about security.
18033 */
18034 + movl PT_OLDESP(%esp),%ebp
18035 +
18036 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18037 + mov PT_OLDSS(%esp),%ds
18038 +1: movl %ds:(%ebp),%ebp
18039 + push %ss
18040 + pop %ds
18041 +#else
18042 cmpl $__PAGE_OFFSET-3,%ebp
18043 jae syscall_fault
18044 ASM_STAC
18045 1: movl (%ebp),%ebp
18046 ASM_CLAC
18047 +#endif
18048 +
18049 movl %ebp,PT_EBP(%esp)
18050 _ASM_EXTABLE(1b,syscall_fault)
18051
18052 GET_THREAD_INFO(%ebp)
18053
18054 +#ifdef CONFIG_PAX_RANDKSTACK
18055 + pax_erase_kstack
18056 +#endif
18057 +
18058 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18059 jnz sysenter_audit
18060 sysenter_do_call:
18061 @@ -444,12 +616,24 @@ sysenter_do_call:
18062 testl $_TIF_ALLWORK_MASK, %ecx
18063 jne sysexit_audit
18064 sysenter_exit:
18065 +
18066 +#ifdef CONFIG_PAX_RANDKSTACK
18067 + pushl_cfi %eax
18068 + movl %esp, %eax
18069 + call pax_randomize_kstack
18070 + popl_cfi %eax
18071 +#endif
18072 +
18073 + pax_erase_kstack
18074 +
18075 /* if something modifies registers it must also disable sysexit */
18076 movl PT_EIP(%esp), %edx
18077 movl PT_OLDESP(%esp), %ecx
18078 xorl %ebp,%ebp
18079 TRACE_IRQS_ON
18080 1: mov PT_FS(%esp), %fs
18081 +2: mov PT_DS(%esp), %ds
18082 +3: mov PT_ES(%esp), %es
18083 PTGS_TO_GS
18084 ENABLE_INTERRUPTS_SYSEXIT
18085
18086 @@ -466,6 +650,9 @@ sysenter_audit:
18087 movl %eax,%edx /* 2nd arg: syscall number */
18088 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18089 call __audit_syscall_entry
18090 +
18091 + pax_erase_kstack
18092 +
18093 pushl_cfi %ebx
18094 movl PT_EAX(%esp),%eax /* reload syscall number */
18095 jmp sysenter_do_call
18096 @@ -491,10 +678,16 @@ sysexit_audit:
18097
18098 CFI_ENDPROC
18099 .pushsection .fixup,"ax"
18100 -2: movl $0,PT_FS(%esp)
18101 +4: movl $0,PT_FS(%esp)
18102 + jmp 1b
18103 +5: movl $0,PT_DS(%esp)
18104 + jmp 1b
18105 +6: movl $0,PT_ES(%esp)
18106 jmp 1b
18107 .popsection
18108 - _ASM_EXTABLE(1b,2b)
18109 + _ASM_EXTABLE(1b,4b)
18110 + _ASM_EXTABLE(2b,5b)
18111 + _ASM_EXTABLE(3b,6b)
18112 PTGS_TO_GS_EX
18113 ENDPROC(ia32_sysenter_target)
18114
18115 @@ -509,6 +702,11 @@ ENTRY(system_call)
18116 pushl_cfi %eax # save orig_eax
18117 SAVE_ALL
18118 GET_THREAD_INFO(%ebp)
18119 +
18120 +#ifdef CONFIG_PAX_RANDKSTACK
18121 + pax_erase_kstack
18122 +#endif
18123 +
18124 # system call tracing in operation / emulation
18125 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18126 jnz syscall_trace_entry
18127 @@ -527,6 +725,15 @@ syscall_exit:
18128 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18129 jne syscall_exit_work
18130
18131 +restore_all_pax:
18132 +
18133 +#ifdef CONFIG_PAX_RANDKSTACK
18134 + movl %esp, %eax
18135 + call pax_randomize_kstack
18136 +#endif
18137 +
18138 + pax_erase_kstack
18139 +
18140 restore_all:
18141 TRACE_IRQS_IRET
18142 restore_all_notrace:
18143 @@ -583,14 +790,34 @@ ldt_ss:
18144 * compensating for the offset by changing to the ESPFIX segment with
18145 * a base address that matches for the difference.
18146 */
18147 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18148 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18149 mov %esp, %edx /* load kernel esp */
18150 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18151 mov %dx, %ax /* eax: new kernel esp */
18152 sub %eax, %edx /* offset (low word is 0) */
18153 +#ifdef CONFIG_SMP
18154 + movl PER_CPU_VAR(cpu_number), %ebx
18155 + shll $PAGE_SHIFT_asm, %ebx
18156 + addl $cpu_gdt_table, %ebx
18157 +#else
18158 + movl $cpu_gdt_table, %ebx
18159 +#endif
18160 shr $16, %edx
18161 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18162 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18163 +
18164 +#ifdef CONFIG_PAX_KERNEXEC
18165 + mov %cr0, %esi
18166 + btr $16, %esi
18167 + mov %esi, %cr0
18168 +#endif
18169 +
18170 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18171 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18172 +
18173 +#ifdef CONFIG_PAX_KERNEXEC
18174 + bts $16, %esi
18175 + mov %esi, %cr0
18176 +#endif
18177 +
18178 pushl_cfi $__ESPFIX_SS
18179 pushl_cfi %eax /* new kernel esp */
18180 /* Disable interrupts, but do not irqtrace this section: we
18181 @@ -619,20 +846,18 @@ work_resched:
18182 movl TI_flags(%ebp), %ecx
18183 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18184 # than syscall tracing?
18185 - jz restore_all
18186 + jz restore_all_pax
18187 testb $_TIF_NEED_RESCHED, %cl
18188 jnz work_resched
18189
18190 work_notifysig: # deal with pending signals and
18191 # notify-resume requests
18192 + movl %esp, %eax
18193 #ifdef CONFIG_VM86
18194 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18195 - movl %esp, %eax
18196 jne work_notifysig_v86 # returning to kernel-space or
18197 # vm86-space
18198 1:
18199 -#else
18200 - movl %esp, %eax
18201 #endif
18202 TRACE_IRQS_ON
18203 ENABLE_INTERRUPTS(CLBR_NONE)
18204 @@ -653,7 +878,7 @@ work_notifysig_v86:
18205 movl %eax, %esp
18206 jmp 1b
18207 #endif
18208 -END(work_pending)
18209 +ENDPROC(work_pending)
18210
18211 # perform syscall exit tracing
18212 ALIGN
18213 @@ -661,11 +886,14 @@ syscall_trace_entry:
18214 movl $-ENOSYS,PT_EAX(%esp)
18215 movl %esp, %eax
18216 call syscall_trace_enter
18217 +
18218 + pax_erase_kstack
18219 +
18220 /* What it returned is what we'll actually use. */
18221 cmpl $(NR_syscalls), %eax
18222 jnae syscall_call
18223 jmp syscall_exit
18224 -END(syscall_trace_entry)
18225 +ENDPROC(syscall_trace_entry)
18226
18227 # perform syscall exit tracing
18228 ALIGN
18229 @@ -678,21 +906,25 @@ syscall_exit_work:
18230 movl %esp, %eax
18231 call syscall_trace_leave
18232 jmp resume_userspace
18233 -END(syscall_exit_work)
18234 +ENDPROC(syscall_exit_work)
18235 CFI_ENDPROC
18236
18237 RING0_INT_FRAME # can't unwind into user space anyway
18238 syscall_fault:
18239 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18240 + push %ss
18241 + pop %ds
18242 +#endif
18243 ASM_CLAC
18244 GET_THREAD_INFO(%ebp)
18245 movl $-EFAULT,PT_EAX(%esp)
18246 jmp resume_userspace
18247 -END(syscall_fault)
18248 +ENDPROC(syscall_fault)
18249
18250 syscall_badsys:
18251 movl $-ENOSYS,PT_EAX(%esp)
18252 jmp resume_userspace
18253 -END(syscall_badsys)
18254 +ENDPROC(syscall_badsys)
18255 CFI_ENDPROC
18256 /*
18257 * End of kprobes section
18258 @@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18259 * normal stack and adjusts ESP with the matching offset.
18260 */
18261 /* fixup the stack */
18262 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18263 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18264 +#ifdef CONFIG_SMP
18265 + movl PER_CPU_VAR(cpu_number), %ebx
18266 + shll $PAGE_SHIFT_asm, %ebx
18267 + addl $cpu_gdt_table, %ebx
18268 +#else
18269 + movl $cpu_gdt_table, %ebx
18270 +#endif
18271 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18272 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18273 shl $16, %eax
18274 addl %esp, %eax /* the adjusted stack pointer */
18275 pushl_cfi $__KERNEL_DS
18276 @@ -807,7 +1046,7 @@ vector=vector+1
18277 .endr
18278 2: jmp common_interrupt
18279 .endr
18280 -END(irq_entries_start)
18281 +ENDPROC(irq_entries_start)
18282
18283 .previous
18284 END(interrupt)
18285 @@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18286 pushl_cfi $do_coprocessor_error
18287 jmp error_code
18288 CFI_ENDPROC
18289 -END(coprocessor_error)
18290 +ENDPROC(coprocessor_error)
18291
18292 ENTRY(simd_coprocessor_error)
18293 RING0_INT_FRAME
18294 @@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
18295 #endif
18296 jmp error_code
18297 CFI_ENDPROC
18298 -END(simd_coprocessor_error)
18299 +ENDPROC(simd_coprocessor_error)
18300
18301 ENTRY(device_not_available)
18302 RING0_INT_FRAME
18303 @@ -889,18 +1128,18 @@ ENTRY(device_not_available)
18304 pushl_cfi $do_device_not_available
18305 jmp error_code
18306 CFI_ENDPROC
18307 -END(device_not_available)
18308 +ENDPROC(device_not_available)
18309
18310 #ifdef CONFIG_PARAVIRT
18311 ENTRY(native_iret)
18312 iret
18313 _ASM_EXTABLE(native_iret, iret_exc)
18314 -END(native_iret)
18315 +ENDPROC(native_iret)
18316
18317 ENTRY(native_irq_enable_sysexit)
18318 sti
18319 sysexit
18320 -END(native_irq_enable_sysexit)
18321 +ENDPROC(native_irq_enable_sysexit)
18322 #endif
18323
18324 ENTRY(overflow)
18325 @@ -910,7 +1149,7 @@ ENTRY(overflow)
18326 pushl_cfi $do_overflow
18327 jmp error_code
18328 CFI_ENDPROC
18329 -END(overflow)
18330 +ENDPROC(overflow)
18331
18332 ENTRY(bounds)
18333 RING0_INT_FRAME
18334 @@ -919,7 +1158,7 @@ ENTRY(bounds)
18335 pushl_cfi $do_bounds
18336 jmp error_code
18337 CFI_ENDPROC
18338 -END(bounds)
18339 +ENDPROC(bounds)
18340
18341 ENTRY(invalid_op)
18342 RING0_INT_FRAME
18343 @@ -928,7 +1167,7 @@ ENTRY(invalid_op)
18344 pushl_cfi $do_invalid_op
18345 jmp error_code
18346 CFI_ENDPROC
18347 -END(invalid_op)
18348 +ENDPROC(invalid_op)
18349
18350 ENTRY(coprocessor_segment_overrun)
18351 RING0_INT_FRAME
18352 @@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
18353 pushl_cfi $do_coprocessor_segment_overrun
18354 jmp error_code
18355 CFI_ENDPROC
18356 -END(coprocessor_segment_overrun)
18357 +ENDPROC(coprocessor_segment_overrun)
18358
18359 ENTRY(invalid_TSS)
18360 RING0_EC_FRAME
18361 @@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
18362 pushl_cfi $do_invalid_TSS
18363 jmp error_code
18364 CFI_ENDPROC
18365 -END(invalid_TSS)
18366 +ENDPROC(invalid_TSS)
18367
18368 ENTRY(segment_not_present)
18369 RING0_EC_FRAME
18370 @@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
18371 pushl_cfi $do_segment_not_present
18372 jmp error_code
18373 CFI_ENDPROC
18374 -END(segment_not_present)
18375 +ENDPROC(segment_not_present)
18376
18377 ENTRY(stack_segment)
18378 RING0_EC_FRAME
18379 @@ -961,7 +1200,7 @@ ENTRY(stack_segment)
18380 pushl_cfi $do_stack_segment
18381 jmp error_code
18382 CFI_ENDPROC
18383 -END(stack_segment)
18384 +ENDPROC(stack_segment)
18385
18386 ENTRY(alignment_check)
18387 RING0_EC_FRAME
18388 @@ -969,7 +1208,7 @@ ENTRY(alignment_check)
18389 pushl_cfi $do_alignment_check
18390 jmp error_code
18391 CFI_ENDPROC
18392 -END(alignment_check)
18393 +ENDPROC(alignment_check)
18394
18395 ENTRY(divide_error)
18396 RING0_INT_FRAME
18397 @@ -978,7 +1217,7 @@ ENTRY(divide_error)
18398 pushl_cfi $do_divide_error
18399 jmp error_code
18400 CFI_ENDPROC
18401 -END(divide_error)
18402 +ENDPROC(divide_error)
18403
18404 #ifdef CONFIG_X86_MCE
18405 ENTRY(machine_check)
18406 @@ -988,7 +1227,7 @@ ENTRY(machine_check)
18407 pushl_cfi machine_check_vector
18408 jmp error_code
18409 CFI_ENDPROC
18410 -END(machine_check)
18411 +ENDPROC(machine_check)
18412 #endif
18413
18414 ENTRY(spurious_interrupt_bug)
18415 @@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
18416 pushl_cfi $do_spurious_interrupt_bug
18417 jmp error_code
18418 CFI_ENDPROC
18419 -END(spurious_interrupt_bug)
18420 +ENDPROC(spurious_interrupt_bug)
18421 /*
18422 * End of kprobes section
18423 */
18424 @@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
18425
18426 ENTRY(mcount)
18427 ret
18428 -END(mcount)
18429 +ENDPROC(mcount)
18430
18431 ENTRY(ftrace_caller)
18432 cmpl $0, function_trace_stop
18433 @@ -1134,7 +1373,7 @@ ftrace_graph_call:
18434 .globl ftrace_stub
18435 ftrace_stub:
18436 ret
18437 -END(ftrace_caller)
18438 +ENDPROC(ftrace_caller)
18439
18440 ENTRY(ftrace_regs_caller)
18441 pushf /* push flags before compare (in cs location) */
18442 @@ -1235,7 +1474,7 @@ trace:
18443 popl %ecx
18444 popl %eax
18445 jmp ftrace_stub
18446 -END(mcount)
18447 +ENDPROC(mcount)
18448 #endif /* CONFIG_DYNAMIC_FTRACE */
18449 #endif /* CONFIG_FUNCTION_TRACER */
18450
18451 @@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
18452 popl %ecx
18453 popl %eax
18454 ret
18455 -END(ftrace_graph_caller)
18456 +ENDPROC(ftrace_graph_caller)
18457
18458 .globl return_to_handler
18459 return_to_handler:
18460 @@ -1309,15 +1548,18 @@ error_code:
18461 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18462 REG_TO_PTGS %ecx
18463 SET_KERNEL_GS %ecx
18464 - movl $(__USER_DS), %ecx
18465 + movl $(__KERNEL_DS), %ecx
18466 movl %ecx, %ds
18467 movl %ecx, %es
18468 +
18469 + pax_enter_kernel
18470 +
18471 TRACE_IRQS_OFF
18472 movl %esp,%eax # pt_regs pointer
18473 call *%edi
18474 jmp ret_from_exception
18475 CFI_ENDPROC
18476 -END(page_fault)
18477 +ENDPROC(page_fault)
18478
18479 /*
18480 * Debug traps and NMI can happen at the one SYSENTER instruction
18481 @@ -1360,7 +1602,7 @@ debug_stack_correct:
18482 call do_debug
18483 jmp ret_from_exception
18484 CFI_ENDPROC
18485 -END(debug)
18486 +ENDPROC(debug)
18487
18488 /*
18489 * NMI is doubly nasty. It can happen _while_ we're handling
18490 @@ -1398,6 +1640,9 @@ nmi_stack_correct:
18491 xorl %edx,%edx # zero error code
18492 movl %esp,%eax # pt_regs pointer
18493 call do_nmi
18494 +
18495 + pax_exit_kernel
18496 +
18497 jmp restore_all_notrace
18498 CFI_ENDPROC
18499
18500 @@ -1434,12 +1679,15 @@ nmi_espfix_stack:
18501 FIXUP_ESPFIX_STACK # %eax == %esp
18502 xorl %edx,%edx # zero error code
18503 call do_nmi
18504 +
18505 + pax_exit_kernel
18506 +
18507 RESTORE_REGS
18508 lss 12+4(%esp), %esp # back to espfix stack
18509 CFI_ADJUST_CFA_OFFSET -24
18510 jmp irq_return
18511 CFI_ENDPROC
18512 -END(nmi)
18513 +ENDPROC(nmi)
18514
18515 ENTRY(int3)
18516 RING0_INT_FRAME
18517 @@ -1452,14 +1700,14 @@ ENTRY(int3)
18518 call do_int3
18519 jmp ret_from_exception
18520 CFI_ENDPROC
18521 -END(int3)
18522 +ENDPROC(int3)
18523
18524 ENTRY(general_protection)
18525 RING0_EC_FRAME
18526 pushl_cfi $do_general_protection
18527 jmp error_code
18528 CFI_ENDPROC
18529 -END(general_protection)
18530 +ENDPROC(general_protection)
18531
18532 #ifdef CONFIG_KVM_GUEST
18533 ENTRY(async_page_fault)
18534 @@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
18535 pushl_cfi $do_async_page_fault
18536 jmp error_code
18537 CFI_ENDPROC
18538 -END(async_page_fault)
18539 +ENDPROC(async_page_fault)
18540 #endif
18541
18542 /*
18543 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18544 index cb3c591..bc63707 100644
18545 --- a/arch/x86/kernel/entry_64.S
18546 +++ b/arch/x86/kernel/entry_64.S
18547 @@ -59,6 +59,8 @@
18548 #include <asm/context_tracking.h>
18549 #include <asm/smap.h>
18550 #include <linux/err.h>
18551 +#include <asm/pgtable.h>
18552 +#include <asm/alternative-asm.h>
18553
18554 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18555 #include <linux/elf-em.h>
18556 @@ -80,8 +82,9 @@
18557 #ifdef CONFIG_DYNAMIC_FTRACE
18558
18559 ENTRY(function_hook)
18560 + pax_force_retaddr
18561 retq
18562 -END(function_hook)
18563 +ENDPROC(function_hook)
18564
18565 /* skip is set if stack has been adjusted */
18566 .macro ftrace_caller_setup skip=0
18567 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18568 #endif
18569
18570 GLOBAL(ftrace_stub)
18571 + pax_force_retaddr
18572 retq
18573 -END(ftrace_caller)
18574 +ENDPROC(ftrace_caller)
18575
18576 ENTRY(ftrace_regs_caller)
18577 /* Save the current flags before compare (in SS location)*/
18578 @@ -191,7 +195,7 @@ ftrace_restore_flags:
18579 popfq
18580 jmp ftrace_stub
18581
18582 -END(ftrace_regs_caller)
18583 +ENDPROC(ftrace_regs_caller)
18584
18585
18586 #else /* ! CONFIG_DYNAMIC_FTRACE */
18587 @@ -212,6 +216,7 @@ ENTRY(function_hook)
18588 #endif
18589
18590 GLOBAL(ftrace_stub)
18591 + pax_force_retaddr
18592 retq
18593
18594 trace:
18595 @@ -225,12 +230,13 @@ trace:
18596 #endif
18597 subq $MCOUNT_INSN_SIZE, %rdi
18598
18599 + pax_force_fptr ftrace_trace_function
18600 call *ftrace_trace_function
18601
18602 MCOUNT_RESTORE_FRAME
18603
18604 jmp ftrace_stub
18605 -END(function_hook)
18606 +ENDPROC(function_hook)
18607 #endif /* CONFIG_DYNAMIC_FTRACE */
18608 #endif /* CONFIG_FUNCTION_TRACER */
18609
18610 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
18611
18612 MCOUNT_RESTORE_FRAME
18613
18614 + pax_force_retaddr
18615 retq
18616 -END(ftrace_graph_caller)
18617 +ENDPROC(ftrace_graph_caller)
18618
18619 GLOBAL(return_to_handler)
18620 subq $24, %rsp
18621 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
18622 movq 8(%rsp), %rdx
18623 movq (%rsp), %rax
18624 addq $24, %rsp
18625 + pax_force_fptr %rdi
18626 jmp *%rdi
18627 +ENDPROC(return_to_handler)
18628 #endif
18629
18630
18631 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
18632 ENDPROC(native_usergs_sysret64)
18633 #endif /* CONFIG_PARAVIRT */
18634
18635 + .macro ljmpq sel, off
18636 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
18637 + .byte 0x48; ljmp *1234f(%rip)
18638 + .pushsection .rodata
18639 + .align 16
18640 + 1234: .quad \off; .word \sel
18641 + .popsection
18642 +#else
18643 + pushq $\sel
18644 + pushq $\off
18645 + lretq
18646 +#endif
18647 + .endm
18648 +
18649 + .macro pax_enter_kernel
18650 + pax_set_fptr_mask
18651 +#ifdef CONFIG_PAX_KERNEXEC
18652 + call pax_enter_kernel
18653 +#endif
18654 + .endm
18655 +
18656 + .macro pax_exit_kernel
18657 +#ifdef CONFIG_PAX_KERNEXEC
18658 + call pax_exit_kernel
18659 +#endif
18660 + .endm
18661 +
18662 +#ifdef CONFIG_PAX_KERNEXEC
18663 +ENTRY(pax_enter_kernel)
18664 + pushq %rdi
18665 +
18666 +#ifdef CONFIG_PARAVIRT
18667 + PV_SAVE_REGS(CLBR_RDI)
18668 +#endif
18669 +
18670 + GET_CR0_INTO_RDI
18671 + bts $16,%rdi
18672 + jnc 3f
18673 + mov %cs,%edi
18674 + cmp $__KERNEL_CS,%edi
18675 + jnz 2f
18676 +1:
18677 +
18678 +#ifdef CONFIG_PARAVIRT
18679 + PV_RESTORE_REGS(CLBR_RDI)
18680 +#endif
18681 +
18682 + popq %rdi
18683 + pax_force_retaddr
18684 + retq
18685 +
18686 +2: ljmpq __KERNEL_CS,1f
18687 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
18688 +4: SET_RDI_INTO_CR0
18689 + jmp 1b
18690 +ENDPROC(pax_enter_kernel)
18691 +
18692 +ENTRY(pax_exit_kernel)
18693 + pushq %rdi
18694 +
18695 +#ifdef CONFIG_PARAVIRT
18696 + PV_SAVE_REGS(CLBR_RDI)
18697 +#endif
18698 +
18699 + mov %cs,%rdi
18700 + cmp $__KERNEXEC_KERNEL_CS,%edi
18701 + jz 2f
18702 +1:
18703 +
18704 +#ifdef CONFIG_PARAVIRT
18705 + PV_RESTORE_REGS(CLBR_RDI);
18706 +#endif
18707 +
18708 + popq %rdi
18709 + pax_force_retaddr
18710 + retq
18711 +
18712 +2: GET_CR0_INTO_RDI
18713 + btr $16,%rdi
18714 + ljmpq __KERNEL_CS,3f
18715 +3: SET_RDI_INTO_CR0
18716 + jmp 1b
18717 +ENDPROC(pax_exit_kernel)
18718 +#endif
18719 +
18720 + .macro pax_enter_kernel_user
18721 + pax_set_fptr_mask
18722 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18723 + call pax_enter_kernel_user
18724 +#endif
18725 + .endm
18726 +
18727 + .macro pax_exit_kernel_user
18728 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18729 + call pax_exit_kernel_user
18730 +#endif
18731 +#ifdef CONFIG_PAX_RANDKSTACK
18732 + pushq %rax
18733 + call pax_randomize_kstack
18734 + popq %rax
18735 +#endif
18736 + .endm
18737 +
18738 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18739 +ENTRY(pax_enter_kernel_user)
18740 + pushq %rdi
18741 + pushq %rbx
18742 +
18743 +#ifdef CONFIG_PARAVIRT
18744 + PV_SAVE_REGS(CLBR_RDI)
18745 +#endif
18746 +
18747 + GET_CR3_INTO_RDI
18748 + mov %rdi,%rbx
18749 + add $__START_KERNEL_map,%rbx
18750 + sub phys_base(%rip),%rbx
18751 +
18752 +#ifdef CONFIG_PARAVIRT
18753 + pushq %rdi
18754 + cmpl $0, pv_info+PARAVIRT_enabled
18755 + jz 1f
18756 + i = 0
18757 + .rept USER_PGD_PTRS
18758 + mov i*8(%rbx),%rsi
18759 + mov $0,%sil
18760 + lea i*8(%rbx),%rdi
18761 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18762 + i = i + 1
18763 + .endr
18764 + jmp 2f
18765 +1:
18766 +#endif
18767 +
18768 + i = 0
18769 + .rept USER_PGD_PTRS
18770 + movb $0,i*8(%rbx)
18771 + i = i + 1
18772 + .endr
18773 +
18774 +#ifdef CONFIG_PARAVIRT
18775 +2: popq %rdi
18776 +#endif
18777 + SET_RDI_INTO_CR3
18778 +
18779 +#ifdef CONFIG_PAX_KERNEXEC
18780 + GET_CR0_INTO_RDI
18781 + bts $16,%rdi
18782 + SET_RDI_INTO_CR0
18783 +#endif
18784 +
18785 +#ifdef CONFIG_PARAVIRT
18786 + PV_RESTORE_REGS(CLBR_RDI)
18787 +#endif
18788 +
18789 + popq %rbx
18790 + popq %rdi
18791 + pax_force_retaddr
18792 + retq
18793 +ENDPROC(pax_enter_kernel_user)
18794 +
18795 +ENTRY(pax_exit_kernel_user)
18796 + push %rdi
18797 +
18798 +#ifdef CONFIG_PARAVIRT
18799 + pushq %rbx
18800 + PV_SAVE_REGS(CLBR_RDI)
18801 +#endif
18802 +
18803 +#ifdef CONFIG_PAX_KERNEXEC
18804 + GET_CR0_INTO_RDI
18805 + btr $16,%rdi
18806 + SET_RDI_INTO_CR0
18807 +#endif
18808 +
18809 + GET_CR3_INTO_RDI
18810 + add $__START_KERNEL_map,%rdi
18811 + sub phys_base(%rip),%rdi
18812 +
18813 +#ifdef CONFIG_PARAVIRT
18814 + cmpl $0, pv_info+PARAVIRT_enabled
18815 + jz 1f
18816 + mov %rdi,%rbx
18817 + i = 0
18818 + .rept USER_PGD_PTRS
18819 + mov i*8(%rbx),%rsi
18820 + mov $0x67,%sil
18821 + lea i*8(%rbx),%rdi
18822 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18823 + i = i + 1
18824 + .endr
18825 + jmp 2f
18826 +1:
18827 +#endif
18828 +
18829 + i = 0
18830 + .rept USER_PGD_PTRS
18831 + movb $0x67,i*8(%rdi)
18832 + i = i + 1
18833 + .endr
18834 +
18835 +#ifdef CONFIG_PARAVIRT
18836 +2: PV_RESTORE_REGS(CLBR_RDI)
18837 + popq %rbx
18838 +#endif
18839 +
18840 + popq %rdi
18841 + pax_force_retaddr
18842 + retq
18843 +ENDPROC(pax_exit_kernel_user)
18844 +#endif
18845 +
18846 +.macro pax_erase_kstack
18847 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18848 + call pax_erase_kstack
18849 +#endif
18850 +.endm
18851 +
18852 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18853 +ENTRY(pax_erase_kstack)
18854 + pushq %rdi
18855 + pushq %rcx
18856 + pushq %rax
18857 + pushq %r11
18858 +
18859 + GET_THREAD_INFO(%r11)
18860 + mov TI_lowest_stack(%r11), %rdi
18861 + mov $-0xBEEF, %rax
18862 + std
18863 +
18864 +1: mov %edi, %ecx
18865 + and $THREAD_SIZE_asm - 1, %ecx
18866 + shr $3, %ecx
18867 + repne scasq
18868 + jecxz 2f
18869 +
18870 + cmp $2*8, %ecx
18871 + jc 2f
18872 +
18873 + mov $2*8, %ecx
18874 + repe scasq
18875 + jecxz 2f
18876 + jne 1b
18877 +
18878 +2: cld
18879 + mov %esp, %ecx
18880 + sub %edi, %ecx
18881 +
18882 + cmp $THREAD_SIZE_asm, %rcx
18883 + jb 3f
18884 + ud2
18885 +3:
18886 +
18887 + shr $3, %ecx
18888 + rep stosq
18889 +
18890 + mov TI_task_thread_sp0(%r11), %rdi
18891 + sub $256, %rdi
18892 + mov %rdi, TI_lowest_stack(%r11)
18893 +
18894 + popq %r11
18895 + popq %rax
18896 + popq %rcx
18897 + popq %rdi
18898 + pax_force_retaddr
18899 + ret
18900 +ENDPROC(pax_erase_kstack)
18901 +#endif
18902
18903 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
18904 #ifdef CONFIG_TRACE_IRQFLAGS
18905 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
18906 .endm
18907
18908 .macro UNFAKE_STACK_FRAME
18909 - addq $8*6, %rsp
18910 - CFI_ADJUST_CFA_OFFSET -(6*8)
18911 + addq $8*6 + ARG_SKIP, %rsp
18912 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
18913 .endm
18914
18915 /*
18916 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
18917 movq %rsp, %rsi
18918
18919 leaq -RBP(%rsp),%rdi /* arg1 for handler */
18920 - testl $3, CS-RBP(%rsi)
18921 + testb $3, CS-RBP(%rsi)
18922 je 1f
18923 SWAPGS
18924 /*
18925 @@ -498,9 +774,10 @@ ENTRY(save_rest)
18926 movq_cfi r15, R15+16
18927 movq %r11, 8(%rsp) /* return address */
18928 FIXUP_TOP_OF_STACK %r11, 16
18929 + pax_force_retaddr
18930 ret
18931 CFI_ENDPROC
18932 -END(save_rest)
18933 +ENDPROC(save_rest)
18934
18935 /* save complete stack frame */
18936 .pushsection .kprobes.text, "ax"
18937 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
18938 js 1f /* negative -> in kernel */
18939 SWAPGS
18940 xorl %ebx,%ebx
18941 -1: ret
18942 +1: pax_force_retaddr_bts
18943 + ret
18944 CFI_ENDPROC
18945 -END(save_paranoid)
18946 +ENDPROC(save_paranoid)
18947 .popsection
18948
18949 /*
18950 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
18951
18952 RESTORE_REST
18953
18954 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18955 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18956 jz 1f
18957
18958 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
18959 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
18960 RESTORE_REST
18961 jmp int_ret_from_sys_call
18962 CFI_ENDPROC
18963 -END(ret_from_fork)
18964 +ENDPROC(ret_from_fork)
18965
18966 /*
18967 * System call entry. Up to 6 arguments in registers are supported.
18968 @@ -608,7 +886,7 @@ END(ret_from_fork)
18969 ENTRY(system_call)
18970 CFI_STARTPROC simple
18971 CFI_SIGNAL_FRAME
18972 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
18973 + CFI_DEF_CFA rsp,0
18974 CFI_REGISTER rip,rcx
18975 /*CFI_REGISTER rflags,r11*/
18976 SWAPGS_UNSAFE_STACK
18977 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
18978
18979 movq %rsp,PER_CPU_VAR(old_rsp)
18980 movq PER_CPU_VAR(kernel_stack),%rsp
18981 + SAVE_ARGS 8*6,0
18982 + pax_enter_kernel_user
18983 +
18984 +#ifdef CONFIG_PAX_RANDKSTACK
18985 + pax_erase_kstack
18986 +#endif
18987 +
18988 /*
18989 * No need to follow this irqs off/on section - it's straight
18990 * and short:
18991 */
18992 ENABLE_INTERRUPTS(CLBR_NONE)
18993 - SAVE_ARGS 8,0
18994 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
18995 movq %rcx,RIP-ARGOFFSET(%rsp)
18996 CFI_REL_OFFSET rip,RIP-ARGOFFSET
18997 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18998 + GET_THREAD_INFO(%rcx)
18999 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19000 jnz tracesys
19001 system_call_fastpath:
19002 #if __SYSCALL_MASK == ~0
19003 @@ -640,7 +925,7 @@ system_call_fastpath:
19004 cmpl $__NR_syscall_max,%eax
19005 #endif
19006 ja badsys
19007 - movq %r10,%rcx
19008 + movq R10-ARGOFFSET(%rsp),%rcx
19009 call *sys_call_table(,%rax,8) # XXX: rip relative
19010 movq %rax,RAX-ARGOFFSET(%rsp)
19011 /*
19012 @@ -654,10 +939,13 @@ sysret_check:
19013 LOCKDEP_SYS_EXIT
19014 DISABLE_INTERRUPTS(CLBR_NONE)
19015 TRACE_IRQS_OFF
19016 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19017 + GET_THREAD_INFO(%rcx)
19018 + movl TI_flags(%rcx),%edx
19019 andl %edi,%edx
19020 jnz sysret_careful
19021 CFI_REMEMBER_STATE
19022 + pax_exit_kernel_user
19023 + pax_erase_kstack
19024 /*
19025 * sysretq will re-enable interrupts:
19026 */
19027 @@ -709,14 +997,18 @@ badsys:
19028 * jump back to the normal fast path.
19029 */
19030 auditsys:
19031 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
19032 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19033 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19034 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19035 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19036 movq %rax,%rsi /* 2nd arg: syscall number */
19037 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19038 call __audit_syscall_entry
19039 +
19040 + pax_erase_kstack
19041 +
19042 LOAD_ARGS 0 /* reload call-clobbered registers */
19043 + pax_set_fptr_mask
19044 jmp system_call_fastpath
19045
19046 /*
19047 @@ -737,7 +1029,7 @@ sysret_audit:
19048 /* Do syscall tracing */
19049 tracesys:
19050 #ifdef CONFIG_AUDITSYSCALL
19051 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19052 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19053 jz auditsys
19054 #endif
19055 SAVE_REST
19056 @@ -745,12 +1037,16 @@ tracesys:
19057 FIXUP_TOP_OF_STACK %rdi
19058 movq %rsp,%rdi
19059 call syscall_trace_enter
19060 +
19061 + pax_erase_kstack
19062 +
19063 /*
19064 * Reload arg registers from stack in case ptrace changed them.
19065 * We don't reload %rax because syscall_trace_enter() returned
19066 * the value it wants us to use in the table lookup.
19067 */
19068 LOAD_ARGS ARGOFFSET, 1
19069 + pax_set_fptr_mask
19070 RESTORE_REST
19071 #if __SYSCALL_MASK == ~0
19072 cmpq $__NR_syscall_max,%rax
19073 @@ -759,7 +1055,7 @@ tracesys:
19074 cmpl $__NR_syscall_max,%eax
19075 #endif
19076 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19077 - movq %r10,%rcx /* fixup for C */
19078 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19079 call *sys_call_table(,%rax,8)
19080 movq %rax,RAX-ARGOFFSET(%rsp)
19081 /* Use IRET because user could have changed frame */
19082 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
19083 andl %edi,%edx
19084 jnz int_careful
19085 andl $~TS_COMPAT,TI_status(%rcx)
19086 - jmp retint_swapgs
19087 + pax_exit_kernel_user
19088 + pax_erase_kstack
19089 + jmp retint_swapgs_pax
19090
19091 /* Either reschedule or signal or syscall exit tracking needed. */
19092 /* First do a reschedule test. */
19093 @@ -826,7 +1124,7 @@ int_restore_rest:
19094 TRACE_IRQS_OFF
19095 jmp int_with_check
19096 CFI_ENDPROC
19097 -END(system_call)
19098 +ENDPROC(system_call)
19099
19100 /*
19101 * Certain special system calls that need to save a complete full stack frame.
19102 @@ -842,7 +1140,7 @@ ENTRY(\label)
19103 call \func
19104 jmp ptregscall_common
19105 CFI_ENDPROC
19106 -END(\label)
19107 +ENDPROC(\label)
19108 .endm
19109
19110 .macro FORK_LIKE func
19111 @@ -856,9 +1154,10 @@ ENTRY(stub_\func)
19112 DEFAULT_FRAME 0 8 /* offset 8: return address */
19113 call sys_\func
19114 RESTORE_TOP_OF_STACK %r11, 8
19115 + pax_force_retaddr
19116 ret $REST_SKIP /* pop extended registers */
19117 CFI_ENDPROC
19118 -END(stub_\func)
19119 +ENDPROC(stub_\func)
19120 .endm
19121
19122 FORK_LIKE clone
19123 @@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
19124 movq_cfi_restore R12+8, r12
19125 movq_cfi_restore RBP+8, rbp
19126 movq_cfi_restore RBX+8, rbx
19127 + pax_force_retaddr
19128 ret $REST_SKIP /* pop extended registers */
19129 CFI_ENDPROC
19130 -END(ptregscall_common)
19131 +ENDPROC(ptregscall_common)
19132
19133 ENTRY(stub_execve)
19134 CFI_STARTPROC
19135 @@ -891,7 +1191,7 @@ ENTRY(stub_execve)
19136 RESTORE_REST
19137 jmp int_ret_from_sys_call
19138 CFI_ENDPROC
19139 -END(stub_execve)
19140 +ENDPROC(stub_execve)
19141
19142 /*
19143 * sigreturn is special because it needs to restore all registers on return.
19144 @@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
19145 RESTORE_REST
19146 jmp int_ret_from_sys_call
19147 CFI_ENDPROC
19148 -END(stub_rt_sigreturn)
19149 +ENDPROC(stub_rt_sigreturn)
19150
19151 #ifdef CONFIG_X86_X32_ABI
19152 ENTRY(stub_x32_rt_sigreturn)
19153 @@ -975,7 +1275,7 @@ vector=vector+1
19154 2: jmp common_interrupt
19155 .endr
19156 CFI_ENDPROC
19157 -END(irq_entries_start)
19158 +ENDPROC(irq_entries_start)
19159
19160 .previous
19161 END(interrupt)
19162 @@ -995,6 +1295,16 @@ END(interrupt)
19163 subq $ORIG_RAX-RBP, %rsp
19164 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19165 SAVE_ARGS_IRQ
19166 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19167 + testb $3, CS(%rdi)
19168 + jnz 1f
19169 + pax_enter_kernel
19170 + jmp 2f
19171 +1: pax_enter_kernel_user
19172 +2:
19173 +#else
19174 + pax_enter_kernel
19175 +#endif
19176 call \func
19177 .endm
19178
19179 @@ -1027,7 +1337,7 @@ ret_from_intr:
19180
19181 exit_intr:
19182 GET_THREAD_INFO(%rcx)
19183 - testl $3,CS-ARGOFFSET(%rsp)
19184 + testb $3,CS-ARGOFFSET(%rsp)
19185 je retint_kernel
19186
19187 /* Interrupt came from user space */
19188 @@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
19189 * The iretq could re-enable interrupts:
19190 */
19191 DISABLE_INTERRUPTS(CLBR_ANY)
19192 + pax_exit_kernel_user
19193 +retint_swapgs_pax:
19194 TRACE_IRQS_IRETQ
19195 SWAPGS
19196 jmp restore_args
19197
19198 retint_restore_args: /* return to kernel space */
19199 DISABLE_INTERRUPTS(CLBR_ANY)
19200 + pax_exit_kernel
19201 + pax_force_retaddr (RIP-ARGOFFSET)
19202 /*
19203 * The iretq could re-enable interrupts:
19204 */
19205 @@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
19206 #endif
19207
19208 CFI_ENDPROC
19209 -END(common_interrupt)
19210 +ENDPROC(common_interrupt)
19211 /*
19212 * End of kprobes section
19213 */
19214 @@ -1155,7 +1469,7 @@ ENTRY(\sym)
19215 interrupt \do_sym
19216 jmp ret_from_intr
19217 CFI_ENDPROC
19218 -END(\sym)
19219 +ENDPROC(\sym)
19220 .endm
19221
19222 #ifdef CONFIG_SMP
19223 @@ -1211,12 +1525,22 @@ ENTRY(\sym)
19224 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19225 call error_entry
19226 DEFAULT_FRAME 0
19227 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19228 + testb $3, CS(%rsp)
19229 + jnz 1f
19230 + pax_enter_kernel
19231 + jmp 2f
19232 +1: pax_enter_kernel_user
19233 +2:
19234 +#else
19235 + pax_enter_kernel
19236 +#endif
19237 movq %rsp,%rdi /* pt_regs pointer */
19238 xorl %esi,%esi /* no error code */
19239 call \do_sym
19240 jmp error_exit /* %ebx: no swapgs flag */
19241 CFI_ENDPROC
19242 -END(\sym)
19243 +ENDPROC(\sym)
19244 .endm
19245
19246 .macro paranoidzeroentry sym do_sym
19247 @@ -1229,15 +1553,25 @@ ENTRY(\sym)
19248 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19249 call save_paranoid
19250 TRACE_IRQS_OFF
19251 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19252 + testb $3, CS(%rsp)
19253 + jnz 1f
19254 + pax_enter_kernel
19255 + jmp 2f
19256 +1: pax_enter_kernel_user
19257 +2:
19258 +#else
19259 + pax_enter_kernel
19260 +#endif
19261 movq %rsp,%rdi /* pt_regs pointer */
19262 xorl %esi,%esi /* no error code */
19263 call \do_sym
19264 jmp paranoid_exit /* %ebx: no swapgs flag */
19265 CFI_ENDPROC
19266 -END(\sym)
19267 +ENDPROC(\sym)
19268 .endm
19269
19270 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19271 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19272 .macro paranoidzeroentry_ist sym do_sym ist
19273 ENTRY(\sym)
19274 INTR_FRAME
19275 @@ -1248,14 +1582,30 @@ ENTRY(\sym)
19276 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19277 call save_paranoid
19278 TRACE_IRQS_OFF_DEBUG
19279 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19280 + testb $3, CS(%rsp)
19281 + jnz 1f
19282 + pax_enter_kernel
19283 + jmp 2f
19284 +1: pax_enter_kernel_user
19285 +2:
19286 +#else
19287 + pax_enter_kernel
19288 +#endif
19289 movq %rsp,%rdi /* pt_regs pointer */
19290 xorl %esi,%esi /* no error code */
19291 +#ifdef CONFIG_SMP
19292 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19293 + lea init_tss(%r12), %r12
19294 +#else
19295 + lea init_tss(%rip), %r12
19296 +#endif
19297 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19298 call \do_sym
19299 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19300 jmp paranoid_exit /* %ebx: no swapgs flag */
19301 CFI_ENDPROC
19302 -END(\sym)
19303 +ENDPROC(\sym)
19304 .endm
19305
19306 .macro errorentry sym do_sym
19307 @@ -1267,13 +1617,23 @@ ENTRY(\sym)
19308 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19309 call error_entry
19310 DEFAULT_FRAME 0
19311 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19312 + testb $3, CS(%rsp)
19313 + jnz 1f
19314 + pax_enter_kernel
19315 + jmp 2f
19316 +1: pax_enter_kernel_user
19317 +2:
19318 +#else
19319 + pax_enter_kernel
19320 +#endif
19321 movq %rsp,%rdi /* pt_regs pointer */
19322 movq ORIG_RAX(%rsp),%rsi /* get error code */
19323 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19324 call \do_sym
19325 jmp error_exit /* %ebx: no swapgs flag */
19326 CFI_ENDPROC
19327 -END(\sym)
19328 +ENDPROC(\sym)
19329 .endm
19330
19331 /* error code is on the stack already */
19332 @@ -1287,13 +1647,23 @@ ENTRY(\sym)
19333 call save_paranoid
19334 DEFAULT_FRAME 0
19335 TRACE_IRQS_OFF
19336 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19337 + testb $3, CS(%rsp)
19338 + jnz 1f
19339 + pax_enter_kernel
19340 + jmp 2f
19341 +1: pax_enter_kernel_user
19342 +2:
19343 +#else
19344 + pax_enter_kernel
19345 +#endif
19346 movq %rsp,%rdi /* pt_regs pointer */
19347 movq ORIG_RAX(%rsp),%rsi /* get error code */
19348 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19349 call \do_sym
19350 jmp paranoid_exit /* %ebx: no swapgs flag */
19351 CFI_ENDPROC
19352 -END(\sym)
19353 +ENDPROC(\sym)
19354 .endm
19355
19356 zeroentry divide_error do_divide_error
19357 @@ -1323,9 +1693,10 @@ gs_change:
19358 2: mfence /* workaround */
19359 SWAPGS
19360 popfq_cfi
19361 + pax_force_retaddr
19362 ret
19363 CFI_ENDPROC
19364 -END(native_load_gs_index)
19365 +ENDPROC(native_load_gs_index)
19366
19367 _ASM_EXTABLE(gs_change,bad_gs)
19368 .section .fixup,"ax"
19369 @@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
19370 CFI_DEF_CFA_REGISTER rsp
19371 CFI_ADJUST_CFA_OFFSET -8
19372 decl PER_CPU_VAR(irq_count)
19373 + pax_force_retaddr
19374 ret
19375 CFI_ENDPROC
19376 -END(call_softirq)
19377 +ENDPROC(call_softirq)
19378
19379 #ifdef CONFIG_XEN
19380 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19381 @@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19382 decl PER_CPU_VAR(irq_count)
19383 jmp error_exit
19384 CFI_ENDPROC
19385 -END(xen_do_hypervisor_callback)
19386 +ENDPROC(xen_do_hypervisor_callback)
19387
19388 /*
19389 * Hypervisor uses this for application faults while it executes.
19390 @@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
19391 SAVE_ALL
19392 jmp error_exit
19393 CFI_ENDPROC
19394 -END(xen_failsafe_callback)
19395 +ENDPROC(xen_failsafe_callback)
19396
19397 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
19398 xen_hvm_callback_vector xen_evtchn_do_upcall
19399 @@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
19400 TRACE_IRQS_OFF_DEBUG
19401 testl %ebx,%ebx /* swapgs needed? */
19402 jnz paranoid_restore
19403 - testl $3,CS(%rsp)
19404 + testb $3,CS(%rsp)
19405 jnz paranoid_userspace
19406 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19407 + pax_exit_kernel
19408 + TRACE_IRQS_IRETQ 0
19409 + SWAPGS_UNSAFE_STACK
19410 + RESTORE_ALL 8
19411 + pax_force_retaddr_bts
19412 + jmp irq_return
19413 +#endif
19414 paranoid_swapgs:
19415 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19416 + pax_exit_kernel_user
19417 +#else
19418 + pax_exit_kernel
19419 +#endif
19420 TRACE_IRQS_IRETQ 0
19421 SWAPGS_UNSAFE_STACK
19422 RESTORE_ALL 8
19423 jmp irq_return
19424 paranoid_restore:
19425 + pax_exit_kernel
19426 TRACE_IRQS_IRETQ_DEBUG 0
19427 RESTORE_ALL 8
19428 + pax_force_retaddr_bts
19429 jmp irq_return
19430 paranoid_userspace:
19431 GET_THREAD_INFO(%rcx)
19432 @@ -1539,7 +1926,7 @@ paranoid_schedule:
19433 TRACE_IRQS_OFF
19434 jmp paranoid_userspace
19435 CFI_ENDPROC
19436 -END(paranoid_exit)
19437 +ENDPROC(paranoid_exit)
19438
19439 /*
19440 * Exception entry point. This expects an error code/orig_rax on the stack.
19441 @@ -1566,12 +1953,13 @@ ENTRY(error_entry)
19442 movq_cfi r14, R14+8
19443 movq_cfi r15, R15+8
19444 xorl %ebx,%ebx
19445 - testl $3,CS+8(%rsp)
19446 + testb $3,CS+8(%rsp)
19447 je error_kernelspace
19448 error_swapgs:
19449 SWAPGS
19450 error_sti:
19451 TRACE_IRQS_OFF
19452 + pax_force_retaddr_bts
19453 ret
19454
19455 /*
19456 @@ -1598,7 +1986,7 @@ bstep_iret:
19457 movq %rcx,RIP+8(%rsp)
19458 jmp error_swapgs
19459 CFI_ENDPROC
19460 -END(error_entry)
19461 +ENDPROC(error_entry)
19462
19463
19464 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19465 @@ -1618,7 +2006,7 @@ ENTRY(error_exit)
19466 jnz retint_careful
19467 jmp retint_swapgs
19468 CFI_ENDPROC
19469 -END(error_exit)
19470 +ENDPROC(error_exit)
19471
19472 /*
19473 * Test if a given stack is an NMI stack or not.
19474 @@ -1676,9 +2064,11 @@ ENTRY(nmi)
19475 * If %cs was not the kernel segment, then the NMI triggered in user
19476 * space, which means it is definitely not nested.
19477 */
19478 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19479 + je 1f
19480 cmpl $__KERNEL_CS, 16(%rsp)
19481 jne first_nmi
19482 -
19483 +1:
19484 /*
19485 * Check the special variable on the stack to see if NMIs are
19486 * executing.
19487 @@ -1847,6 +2237,17 @@ end_repeat_nmi:
19488 */
19489 movq %cr2, %r12
19490
19491 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19492 + testb $3, CS(%rsp)
19493 + jnz 1f
19494 + pax_enter_kernel
19495 + jmp 2f
19496 +1: pax_enter_kernel_user
19497 +2:
19498 +#else
19499 + pax_enter_kernel
19500 +#endif
19501 +
19502 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19503 movq %rsp,%rdi
19504 movq $-1,%rsi
19505 @@ -1862,23 +2263,34 @@ end_repeat_nmi:
19506 testl %ebx,%ebx /* swapgs needed? */
19507 jnz nmi_restore
19508 nmi_swapgs:
19509 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19510 + pax_exit_kernel_user
19511 +#else
19512 + pax_exit_kernel
19513 +#endif
19514 SWAPGS_UNSAFE_STACK
19515 + RESTORE_ALL 6*8
19516 + /* Clear the NMI executing stack variable */
19517 + movq $0, 5*8(%rsp)
19518 + jmp irq_return
19519 nmi_restore:
19520 + pax_exit_kernel
19521 /* Pop the extra iret frame at once */
19522 RESTORE_ALL 6*8
19523 + pax_force_retaddr_bts
19524
19525 /* Clear the NMI executing stack variable */
19526 movq $0, 5*8(%rsp)
19527 jmp irq_return
19528 CFI_ENDPROC
19529 -END(nmi)
19530 +ENDPROC(nmi)
19531
19532 ENTRY(ignore_sysret)
19533 CFI_STARTPROC
19534 mov $-ENOSYS,%eax
19535 sysret
19536 CFI_ENDPROC
19537 -END(ignore_sysret)
19538 +ENDPROC(ignore_sysret)
19539
19540 /*
19541 * End of kprobes section
19542 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19543 index 1d41402..af9a46a 100644
19544 --- a/arch/x86/kernel/ftrace.c
19545 +++ b/arch/x86/kernel/ftrace.c
19546 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19547 {
19548 unsigned char replaced[MCOUNT_INSN_SIZE];
19549
19550 + ip = ktla_ktva(ip);
19551 +
19552 /*
19553 * Note: Due to modules and __init, code can
19554 * disappear and change, we need to protect against faulting
19555 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19556 unsigned char old[MCOUNT_INSN_SIZE], *new;
19557 int ret;
19558
19559 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
19560 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
19561 new = ftrace_call_replace(ip, (unsigned long)func);
19562
19563 /* See comment above by declaration of modifying_ftrace_code */
19564 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19565 /* Also update the regs callback function */
19566 if (!ret) {
19567 ip = (unsigned long)(&ftrace_regs_call);
19568 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
19569 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
19570 new = ftrace_call_replace(ip, (unsigned long)func);
19571 ret = ftrace_modify_code(ip, old, new);
19572 }
19573 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
19574 * kernel identity mapping to modify code.
19575 */
19576 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
19577 - ip = (unsigned long)__va(__pa(ip));
19578 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
19579
19580 return probe_kernel_write((void *)ip, val, size);
19581 }
19582 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
19583 unsigned char replaced[MCOUNT_INSN_SIZE];
19584 unsigned char brk = BREAKPOINT_INSTRUCTION;
19585
19586 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
19587 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
19588 return -EFAULT;
19589
19590 /* Make sure it is what we expect it to be */
19591 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
19592 return ret;
19593
19594 fail_update:
19595 - probe_kernel_write((void *)ip, &old_code[0], 1);
19596 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
19597 goto out;
19598 }
19599
19600 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
19601 {
19602 unsigned char code[MCOUNT_INSN_SIZE];
19603
19604 + ip = ktla_ktva(ip);
19605 +
19606 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
19607 return -EFAULT;
19608
19609 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
19610 index c18f59d..9c0c9f6 100644
19611 --- a/arch/x86/kernel/head32.c
19612 +++ b/arch/x86/kernel/head32.c
19613 @@ -18,6 +18,7 @@
19614 #include <asm/io_apic.h>
19615 #include <asm/bios_ebda.h>
19616 #include <asm/tlbflush.h>
19617 +#include <asm/boot.h>
19618
19619 static void __init i386_default_early_setup(void)
19620 {
19621 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
19622
19623 void __init i386_start_kernel(void)
19624 {
19625 - memblock_reserve(__pa_symbol(&_text),
19626 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
19627 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
19628
19629 #ifdef CONFIG_BLK_DEV_INITRD
19630 /* Reserve INITRD */
19631 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
19632 index c8932c7..d56b622 100644
19633 --- a/arch/x86/kernel/head_32.S
19634 +++ b/arch/x86/kernel/head_32.S
19635 @@ -26,6 +26,12 @@
19636 /* Physical address */
19637 #define pa(X) ((X) - __PAGE_OFFSET)
19638
19639 +#ifdef CONFIG_PAX_KERNEXEC
19640 +#define ta(X) (X)
19641 +#else
19642 +#define ta(X) ((X) - __PAGE_OFFSET)
19643 +#endif
19644 +
19645 /*
19646 * References to members of the new_cpu_data structure.
19647 */
19648 @@ -55,11 +61,7 @@
19649 * and small than max_low_pfn, otherwise will waste some page table entries
19650 */
19651
19652 -#if PTRS_PER_PMD > 1
19653 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
19654 -#else
19655 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
19656 -#endif
19657 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
19658
19659 /* Number of possible pages in the lowmem region */
19660 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
19661 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
19662 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19663
19664 /*
19665 + * Real beginning of normal "text" segment
19666 + */
19667 +ENTRY(stext)
19668 +ENTRY(_stext)
19669 +
19670 +/*
19671 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
19672 * %esi points to the real-mode code as a 32-bit pointer.
19673 * CS and DS must be 4 GB flat segments, but we don't depend on
19674 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19675 * can.
19676 */
19677 __HEAD
19678 +
19679 +#ifdef CONFIG_PAX_KERNEXEC
19680 + jmp startup_32
19681 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
19682 +.fill PAGE_SIZE-5,1,0xcc
19683 +#endif
19684 +
19685 ENTRY(startup_32)
19686 movl pa(stack_start),%ecx
19687
19688 @@ -106,6 +121,59 @@ ENTRY(startup_32)
19689 2:
19690 leal -__PAGE_OFFSET(%ecx),%esp
19691
19692 +#ifdef CONFIG_SMP
19693 + movl $pa(cpu_gdt_table),%edi
19694 + movl $__per_cpu_load,%eax
19695 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
19696 + rorl $16,%eax
19697 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
19698 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
19699 + movl $__per_cpu_end - 1,%eax
19700 + subl $__per_cpu_start,%eax
19701 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
19702 +#endif
19703 +
19704 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19705 + movl $NR_CPUS,%ecx
19706 + movl $pa(cpu_gdt_table),%edi
19707 +1:
19708 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
19709 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
19710 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
19711 + addl $PAGE_SIZE_asm,%edi
19712 + loop 1b
19713 +#endif
19714 +
19715 +#ifdef CONFIG_PAX_KERNEXEC
19716 + movl $pa(boot_gdt),%edi
19717 + movl $__LOAD_PHYSICAL_ADDR,%eax
19718 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
19719 + rorl $16,%eax
19720 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
19721 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
19722 + rorl $16,%eax
19723 +
19724 + ljmp $(__BOOT_CS),$1f
19725 +1:
19726 +
19727 + movl $NR_CPUS,%ecx
19728 + movl $pa(cpu_gdt_table),%edi
19729 + addl $__PAGE_OFFSET,%eax
19730 +1:
19731 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
19732 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
19733 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
19734 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
19735 + rorl $16,%eax
19736 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
19737 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
19738 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
19739 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
19740 + rorl $16,%eax
19741 + addl $PAGE_SIZE_asm,%edi
19742 + loop 1b
19743 +#endif
19744 +
19745 /*
19746 * Clear BSS first so that there are no surprises...
19747 */
19748 @@ -196,8 +264,11 @@ ENTRY(startup_32)
19749 movl %eax, pa(max_pfn_mapped)
19750
19751 /* Do early initialization of the fixmap area */
19752 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19753 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
19754 +#ifdef CONFIG_COMPAT_VDSO
19755 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
19756 +#else
19757 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
19758 +#endif
19759 #else /* Not PAE */
19760
19761 page_pde_offset = (__PAGE_OFFSET >> 20);
19762 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19763 movl %eax, pa(max_pfn_mapped)
19764
19765 /* Do early initialization of the fixmap area */
19766 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19767 - movl %eax,pa(initial_page_table+0xffc)
19768 +#ifdef CONFIG_COMPAT_VDSO
19769 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
19770 +#else
19771 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
19772 +#endif
19773 #endif
19774
19775 #ifdef CONFIG_PARAVIRT
19776 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19777 cmpl $num_subarch_entries, %eax
19778 jae bad_subarch
19779
19780 - movl pa(subarch_entries)(,%eax,4), %eax
19781 - subl $__PAGE_OFFSET, %eax
19782 - jmp *%eax
19783 + jmp *pa(subarch_entries)(,%eax,4)
19784
19785 bad_subarch:
19786 WEAK(lguest_entry)
19787 @@ -256,10 +328,10 @@ WEAK(xen_entry)
19788 __INITDATA
19789
19790 subarch_entries:
19791 - .long default_entry /* normal x86/PC */
19792 - .long lguest_entry /* lguest hypervisor */
19793 - .long xen_entry /* Xen hypervisor */
19794 - .long default_entry /* Moorestown MID */
19795 + .long ta(default_entry) /* normal x86/PC */
19796 + .long ta(lguest_entry) /* lguest hypervisor */
19797 + .long ta(xen_entry) /* Xen hypervisor */
19798 + .long ta(default_entry) /* Moorestown MID */
19799 num_subarch_entries = (. - subarch_entries) / 4
19800 .previous
19801 #else
19802 @@ -335,6 +407,7 @@ default_entry:
19803 movl pa(mmu_cr4_features),%eax
19804 movl %eax,%cr4
19805
19806 +#ifdef CONFIG_X86_PAE
19807 testb $X86_CR4_PAE, %al # check if PAE is enabled
19808 jz 6f
19809
19810 @@ -363,6 +436,9 @@ default_entry:
19811 /* Make changes effective */
19812 wrmsr
19813
19814 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
19815 +#endif
19816 +
19817 6:
19818
19819 /*
19820 @@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
19821 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
19822 movl %eax,%ss # after changing gdt.
19823
19824 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
19825 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
19826 movl %eax,%ds
19827 movl %eax,%es
19828
19829 movl $(__KERNEL_PERCPU), %eax
19830 movl %eax,%fs # set this cpu's percpu
19831
19832 +#ifdef CONFIG_CC_STACKPROTECTOR
19833 movl $(__KERNEL_STACK_CANARY),%eax
19834 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
19835 + movl $(__USER_DS),%eax
19836 +#else
19837 + xorl %eax,%eax
19838 +#endif
19839 movl %eax,%gs
19840
19841 xorl %eax,%eax # Clear LDT
19842 @@ -544,8 +626,11 @@ setup_once:
19843 * relocation. Manually set base address in stack canary
19844 * segment descriptor.
19845 */
19846 - movl $gdt_page,%eax
19847 + movl $cpu_gdt_table,%eax
19848 movl $stack_canary,%ecx
19849 +#ifdef CONFIG_SMP
19850 + addl $__per_cpu_load,%ecx
19851 +#endif
19852 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
19853 shrl $16, %ecx
19854 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
19855 @@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
19856 /* This is global to keep gas from relaxing the jumps */
19857 ENTRY(early_idt_handler)
19858 cld
19859 - cmpl $2,%ss:early_recursion_flag
19860 + cmpl $1,%ss:early_recursion_flag
19861 je hlt_loop
19862 incl %ss:early_recursion_flag
19863
19864 @@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
19865 pushl (20+6*4)(%esp) /* trapno */
19866 pushl $fault_msg
19867 call printk
19868 -#endif
19869 call dump_stack
19870 +#endif
19871 hlt_loop:
19872 hlt
19873 jmp hlt_loop
19874 @@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
19875 /* This is the default interrupt "handler" :-) */
19876 ALIGN
19877 ignore_int:
19878 - cld
19879 #ifdef CONFIG_PRINTK
19880 + cmpl $2,%ss:early_recursion_flag
19881 + je hlt_loop
19882 + incl %ss:early_recursion_flag
19883 + cld
19884 pushl %eax
19885 pushl %ecx
19886 pushl %edx
19887 @@ -644,9 +732,6 @@ ignore_int:
19888 movl $(__KERNEL_DS),%eax
19889 movl %eax,%ds
19890 movl %eax,%es
19891 - cmpl $2,early_recursion_flag
19892 - je hlt_loop
19893 - incl early_recursion_flag
19894 pushl 16(%esp)
19895 pushl 24(%esp)
19896 pushl 32(%esp)
19897 @@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
19898 /*
19899 * BSS section
19900 */
19901 -__PAGE_ALIGNED_BSS
19902 - .align PAGE_SIZE
19903 #ifdef CONFIG_X86_PAE
19904 +.section .initial_pg_pmd,"a",@progbits
19905 initial_pg_pmd:
19906 .fill 1024*KPMDS,4,0
19907 #else
19908 +.section .initial_page_table,"a",@progbits
19909 ENTRY(initial_page_table)
19910 .fill 1024,4,0
19911 #endif
19912 +.section .initial_pg_fixmap,"a",@progbits
19913 initial_pg_fixmap:
19914 .fill 1024,4,0
19915 +.section .empty_zero_page,"a",@progbits
19916 ENTRY(empty_zero_page)
19917 .fill 4096,1,0
19918 +.section .swapper_pg_dir,"a",@progbits
19919 ENTRY(swapper_pg_dir)
19920 +#ifdef CONFIG_X86_PAE
19921 + .fill 4,8,0
19922 +#else
19923 .fill 1024,4,0
19924 +#endif
19925 +
19926 +/*
19927 + * The IDT has to be page-aligned to simplify the Pentium
19928 + * F0 0F bug workaround.. We have a special link segment
19929 + * for this.
19930 + */
19931 +.section .idt,"a",@progbits
19932 +ENTRY(idt_table)
19933 + .fill 256,8,0
19934
19935 /*
19936 * This starts the data section.
19937 */
19938 #ifdef CONFIG_X86_PAE
19939 -__PAGE_ALIGNED_DATA
19940 - /* Page-aligned for the benefit of paravirt? */
19941 - .align PAGE_SIZE
19942 +.section .initial_page_table,"a",@progbits
19943 ENTRY(initial_page_table)
19944 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
19945 # if KPMDS == 3
19946 @@ -721,12 +820,20 @@ ENTRY(initial_page_table)
19947 # error "Kernel PMDs should be 1, 2 or 3"
19948 # endif
19949 .align PAGE_SIZE /* needs to be page-sized too */
19950 +
19951 +#ifdef CONFIG_PAX_PER_CPU_PGD
19952 +ENTRY(cpu_pgd)
19953 + .rept NR_CPUS
19954 + .fill 4,8,0
19955 + .endr
19956 +#endif
19957 +
19958 #endif
19959
19960 .data
19961 .balign 4
19962 ENTRY(stack_start)
19963 - .long init_thread_union+THREAD_SIZE
19964 + .long init_thread_union+THREAD_SIZE-8
19965
19966 __INITRODATA
19967 int_msg:
19968 @@ -754,7 +861,7 @@ fault_msg:
19969 * segment size, and 32-bit linear address value:
19970 */
19971
19972 - .data
19973 +.section .rodata,"a",@progbits
19974 .globl boot_gdt_descr
19975 .globl idt_descr
19976
19977 @@ -763,7 +870,7 @@ fault_msg:
19978 .word 0 # 32 bit align gdt_desc.address
19979 boot_gdt_descr:
19980 .word __BOOT_DS+7
19981 - .long boot_gdt - __PAGE_OFFSET
19982 + .long pa(boot_gdt)
19983
19984 .word 0 # 32-bit align idt_desc.address
19985 idt_descr:
19986 @@ -774,7 +881,7 @@ idt_descr:
19987 .word 0 # 32 bit align gdt_desc.address
19988 ENTRY(early_gdt_descr)
19989 .word GDT_ENTRIES*8-1
19990 - .long gdt_page /* Overwritten for secondary CPUs */
19991 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
19992
19993 /*
19994 * The boot_gdt must mirror the equivalent in setup.S and is
19995 @@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
19996 .align L1_CACHE_BYTES
19997 ENTRY(boot_gdt)
19998 .fill GDT_ENTRY_BOOT_CS,8,0
19999 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20000 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20001 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20002 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20003 +
20004 + .align PAGE_SIZE_asm
20005 +ENTRY(cpu_gdt_table)
20006 + .rept NR_CPUS
20007 + .quad 0x0000000000000000 /* NULL descriptor */
20008 + .quad 0x0000000000000000 /* 0x0b reserved */
20009 + .quad 0x0000000000000000 /* 0x13 reserved */
20010 + .quad 0x0000000000000000 /* 0x1b reserved */
20011 +
20012 +#ifdef CONFIG_PAX_KERNEXEC
20013 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20014 +#else
20015 + .quad 0x0000000000000000 /* 0x20 unused */
20016 +#endif
20017 +
20018 + .quad 0x0000000000000000 /* 0x28 unused */
20019 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20020 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20021 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20022 + .quad 0x0000000000000000 /* 0x4b reserved */
20023 + .quad 0x0000000000000000 /* 0x53 reserved */
20024 + .quad 0x0000000000000000 /* 0x5b reserved */
20025 +
20026 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20027 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20028 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20029 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20030 +
20031 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20032 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20033 +
20034 + /*
20035 + * Segments used for calling PnP BIOS have byte granularity.
20036 + * The code segments and data segments have fixed 64k limits,
20037 + * the transfer segment sizes are set at run time.
20038 + */
20039 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
20040 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
20041 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
20042 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
20043 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
20044 +
20045 + /*
20046 + * The APM segments have byte granularity and their bases
20047 + * are set at run time. All have 64k limits.
20048 + */
20049 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20050 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20051 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
20052 +
20053 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20054 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20055 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20056 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20057 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20058 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20059 +
20060 + /* Be sure this is zeroed to avoid false validations in Xen */
20061 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20062 + .endr
20063 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20064 index 980053c..74d3b44 100644
20065 --- a/arch/x86/kernel/head_64.S
20066 +++ b/arch/x86/kernel/head_64.S
20067 @@ -20,6 +20,8 @@
20068 #include <asm/processor-flags.h>
20069 #include <asm/percpu.h>
20070 #include <asm/nops.h>
20071 +#include <asm/cpufeature.h>
20072 +#include <asm/alternative-asm.h>
20073
20074 #ifdef CONFIG_PARAVIRT
20075 #include <asm/asm-offsets.h>
20076 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20077 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20078 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20079 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20080 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
20081 +L3_VMALLOC_START = pud_index(VMALLOC_START)
20082 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
20083 +L3_VMALLOC_END = pud_index(VMALLOC_END)
20084 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20085 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20086
20087 .text
20088 __HEAD
20089 @@ -88,35 +96,23 @@ startup_64:
20090 */
20091 addq %rbp, init_level4_pgt + 0(%rip)
20092 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20093 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20094 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20095 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20096 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20097
20098 addq %rbp, level3_ident_pgt + 0(%rip)
20099 +#ifndef CONFIG_XEN
20100 + addq %rbp, level3_ident_pgt + 8(%rip)
20101 +#endif
20102
20103 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20104 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20105 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20106 +
20107 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20108 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
20109
20110 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20111 -
20112 - /* Add an Identity mapping if I am above 1G */
20113 - leaq _text(%rip), %rdi
20114 - andq $PMD_PAGE_MASK, %rdi
20115 -
20116 - movq %rdi, %rax
20117 - shrq $PUD_SHIFT, %rax
20118 - andq $(PTRS_PER_PUD - 1), %rax
20119 - jz ident_complete
20120 -
20121 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
20122 - leaq level3_ident_pgt(%rip), %rbx
20123 - movq %rdx, 0(%rbx, %rax, 8)
20124 -
20125 - movq %rdi, %rax
20126 - shrq $PMD_SHIFT, %rax
20127 - andq $(PTRS_PER_PMD - 1), %rax
20128 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
20129 - leaq level2_spare_pgt(%rip), %rbx
20130 - movq %rdx, 0(%rbx, %rax, 8)
20131 -ident_complete:
20132 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20133
20134 /*
20135 * Fixup the kernel text+data virtual addresses. Note that
20136 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
20137 * after the boot processor executes this code.
20138 */
20139
20140 - /* Enable PAE mode and PGE */
20141 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
20142 + /* Enable PAE mode and PSE/PGE */
20143 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
20144 movq %rax, %cr4
20145
20146 /* Setup early boot stage 4 level pagetables. */
20147 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
20148 movl $MSR_EFER, %ecx
20149 rdmsr
20150 btsl $_EFER_SCE, %eax /* Enable System Call */
20151 - btl $20,%edi /* No Execute supported? */
20152 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20153 jnc 1f
20154 btsl $_EFER_NX, %eax
20155 + leaq init_level4_pgt(%rip), %rdi
20156 +#ifndef CONFIG_EFI
20157 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20158 +#endif
20159 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20160 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20161 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20162 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20163 1: wrmsr /* Make changes effective */
20164
20165 /* Setup cr0 */
20166 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
20167 * jump. In addition we need to ensure %cs is set so we make this
20168 * a far return.
20169 */
20170 + pax_set_fptr_mask
20171 movq initial_code(%rip),%rax
20172 pushq $0 # fake return address to stop unwinder
20173 pushq $__KERNEL_CS # set correct cs
20174 @@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
20175 bad_address:
20176 jmp bad_address
20177
20178 - .section ".init.text","ax"
20179 + __INIT
20180 .globl early_idt_handlers
20181 early_idt_handlers:
20182 # 104(%rsp) %rflags
20183 @@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
20184 call dump_stack
20185 #ifdef CONFIG_KALLSYMS
20186 leaq early_idt_ripmsg(%rip),%rdi
20187 - movq 40(%rsp),%rsi # %rip again
20188 + movq 88(%rsp),%rsi # %rip again
20189 call __print_symbol
20190 #endif
20191 #endif /* EARLY_PRINTK */
20192 @@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
20193 addq $16,%rsp # drop vector number and error code
20194 decl early_recursion_flag(%rip)
20195 INTERRUPT_RETURN
20196 + .previous
20197
20198 + __INITDATA
20199 .balign 4
20200 early_recursion_flag:
20201 .long 0
20202 + .previous
20203
20204 + .section .rodata,"a",@progbits
20205 #ifdef CONFIG_EARLY_PRINTK
20206 early_idt_msg:
20207 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20208 @@ -376,6 +385,7 @@ early_idt_ripmsg:
20209 #endif /* CONFIG_EARLY_PRINTK */
20210 .previous
20211
20212 + .section .rodata,"a",@progbits
20213 #define NEXT_PAGE(name) \
20214 .balign PAGE_SIZE; \
20215 ENTRY(name)
20216 @@ -388,7 +398,6 @@ ENTRY(name)
20217 i = i + 1 ; \
20218 .endr
20219
20220 - .data
20221 /*
20222 * This default setting generates an ident mapping at address 0x100000
20223 * and a mapping for the kernel that precisely maps virtual address
20224 @@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
20225 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20226 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20227 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20228 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
20229 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20230 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
20231 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20232 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20233 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20234 .org init_level4_pgt + L4_START_KERNEL*8, 0
20235 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20236 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20237
20238 +#ifdef CONFIG_PAX_PER_CPU_PGD
20239 +NEXT_PAGE(cpu_pgd)
20240 + .rept NR_CPUS
20241 + .fill 512,8,0
20242 + .endr
20243 +#endif
20244 +
20245 NEXT_PAGE(level3_ident_pgt)
20246 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20247 +#ifdef CONFIG_XEN
20248 .fill 511,8,0
20249 +#else
20250 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20251 + .fill 510,8,0
20252 +#endif
20253 +
20254 +NEXT_PAGE(level3_vmalloc_start_pgt)
20255 + .fill 512,8,0
20256 +
20257 +NEXT_PAGE(level3_vmalloc_end_pgt)
20258 + .fill 512,8,0
20259 +
20260 +NEXT_PAGE(level3_vmemmap_pgt)
20261 + .fill L3_VMEMMAP_START,8,0
20262 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20263
20264 NEXT_PAGE(level3_kernel_pgt)
20265 .fill L3_START_KERNEL,8,0
20266 @@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
20267 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20268 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20269
20270 +NEXT_PAGE(level2_vmemmap_pgt)
20271 + .fill 512,8,0
20272 +
20273 NEXT_PAGE(level2_fixmap_pgt)
20274 - .fill 506,8,0
20275 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20276 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20277 - .fill 5,8,0
20278 + .fill 507,8,0
20279 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20280 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20281 + .fill 4,8,0
20282
20283 -NEXT_PAGE(level1_fixmap_pgt)
20284 +NEXT_PAGE(level1_vsyscall_pgt)
20285 .fill 512,8,0
20286
20287 -NEXT_PAGE(level2_ident_pgt)
20288 - /* Since I easily can, map the first 1G.
20289 + /* Since I easily can, map the first 2G.
20290 * Don't set NX because code runs from these pages.
20291 */
20292 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20293 +NEXT_PAGE(level2_ident_pgt)
20294 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20295
20296 NEXT_PAGE(level2_kernel_pgt)
20297 /*
20298 @@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
20299 * If you want to increase this then increase MODULES_VADDR
20300 * too.)
20301 */
20302 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
20303 - KERNEL_IMAGE_SIZE/PMD_SIZE)
20304 -
20305 -NEXT_PAGE(level2_spare_pgt)
20306 - .fill 512, 8, 0
20307 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
20308
20309 #undef PMDS
20310 #undef NEXT_PAGE
20311
20312 - .data
20313 + .align PAGE_SIZE
20314 +ENTRY(cpu_gdt_table)
20315 + .rept NR_CPUS
20316 + .quad 0x0000000000000000 /* NULL descriptor */
20317 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20318 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
20319 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
20320 + .quad 0x00cffb000000ffff /* __USER32_CS */
20321 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20322 + .quad 0x00affb000000ffff /* __USER_CS */
20323 +
20324 +#ifdef CONFIG_PAX_KERNEXEC
20325 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20326 +#else
20327 + .quad 0x0 /* unused */
20328 +#endif
20329 +
20330 + .quad 0,0 /* TSS */
20331 + .quad 0,0 /* LDT */
20332 + .quad 0,0,0 /* three TLS descriptors */
20333 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
20334 + /* asm/segment.h:GDT_ENTRIES must match this */
20335 +
20336 + /* zero the remaining page */
20337 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20338 + .endr
20339 +
20340 .align 16
20341 .globl early_gdt_descr
20342 early_gdt_descr:
20343 .word GDT_ENTRIES*8-1
20344 early_gdt_descr_base:
20345 - .quad INIT_PER_CPU_VAR(gdt_page)
20346 + .quad cpu_gdt_table
20347
20348 ENTRY(phys_base)
20349 /* This must match the first entry in level2_kernel_pgt */
20350 .quad 0x0000000000000000
20351
20352 #include "../../x86/xen/xen-head.S"
20353 -
20354 - .section .bss, "aw", @nobits
20355 +
20356 + .section .rodata,"a",@progbits
20357 .align L1_CACHE_BYTES
20358 ENTRY(idt_table)
20359 - .skip IDT_ENTRIES * 16
20360 + .fill 512,8,0
20361
20362 .align L1_CACHE_BYTES
20363 ENTRY(nmi_idt_table)
20364 - .skip IDT_ENTRIES * 16
20365 + .fill 512,8,0
20366
20367 __PAGE_ALIGNED_BSS
20368 .align PAGE_SIZE
20369 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20370 index 9c3bd4a..e1d9b35 100644
20371 --- a/arch/x86/kernel/i386_ksyms_32.c
20372 +++ b/arch/x86/kernel/i386_ksyms_32.c
20373 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20374 EXPORT_SYMBOL(cmpxchg8b_emu);
20375 #endif
20376
20377 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
20378 +
20379 /* Networking helper routines. */
20380 EXPORT_SYMBOL(csum_partial_copy_generic);
20381 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20382 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20383
20384 EXPORT_SYMBOL(__get_user_1);
20385 EXPORT_SYMBOL(__get_user_2);
20386 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
20387
20388 EXPORT_SYMBOL(csum_partial);
20389 EXPORT_SYMBOL(empty_zero_page);
20390 +
20391 +#ifdef CONFIG_PAX_KERNEXEC
20392 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20393 +#endif
20394 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20395 index 245a71d..89d9ce4 100644
20396 --- a/arch/x86/kernel/i387.c
20397 +++ b/arch/x86/kernel/i387.c
20398 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20399 static inline bool interrupted_user_mode(void)
20400 {
20401 struct pt_regs *regs = get_irq_regs();
20402 - return regs && user_mode_vm(regs);
20403 + return regs && user_mode(regs);
20404 }
20405
20406 /*
20407 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20408 index 9a5c460..b332a4b 100644
20409 --- a/arch/x86/kernel/i8259.c
20410 +++ b/arch/x86/kernel/i8259.c
20411 @@ -209,7 +209,7 @@ spurious_8259A_irq:
20412 "spurious 8259A interrupt: IRQ%d.\n", irq);
20413 spurious_irq_mask |= irqmask;
20414 }
20415 - atomic_inc(&irq_err_count);
20416 + atomic_inc_unchecked(&irq_err_count);
20417 /*
20418 * Theoretically we do not have to handle this IRQ,
20419 * but in Linux this does not cause problems and is
20420 @@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20421 /* (slave's support for AEOI in flat mode is to be investigated) */
20422 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20423
20424 + pax_open_kernel();
20425 if (auto_eoi)
20426 /*
20427 * In AEOI mode we just have to mask the interrupt
20428 * when acking.
20429 */
20430 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
20431 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20432 else
20433 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20434 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20435 + pax_close_kernel();
20436
20437 udelay(100); /* wait for 8259A to initialize */
20438
20439 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20440 index a979b5b..1d6db75 100644
20441 --- a/arch/x86/kernel/io_delay.c
20442 +++ b/arch/x86/kernel/io_delay.c
20443 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20444 * Quirk table for systems that misbehave (lock up, etc.) if port
20445 * 0x80 is used:
20446 */
20447 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20448 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20449 {
20450 .callback = dmi_io_delay_0xed_port,
20451 .ident = "Compaq Presario V6000",
20452 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20453 index 8c96897..be66bfa 100644
20454 --- a/arch/x86/kernel/ioport.c
20455 +++ b/arch/x86/kernel/ioport.c
20456 @@ -6,6 +6,7 @@
20457 #include <linux/sched.h>
20458 #include <linux/kernel.h>
20459 #include <linux/capability.h>
20460 +#include <linux/security.h>
20461 #include <linux/errno.h>
20462 #include <linux/types.h>
20463 #include <linux/ioport.h>
20464 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20465
20466 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20467 return -EINVAL;
20468 +#ifdef CONFIG_GRKERNSEC_IO
20469 + if (turn_on && grsec_disable_privio) {
20470 + gr_handle_ioperm();
20471 + return -EPERM;
20472 + }
20473 +#endif
20474 if (turn_on && !capable(CAP_SYS_RAWIO))
20475 return -EPERM;
20476
20477 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20478 * because the ->io_bitmap_max value must match the bitmap
20479 * contents:
20480 */
20481 - tss = &per_cpu(init_tss, get_cpu());
20482 + tss = init_tss + get_cpu();
20483
20484 if (turn_on)
20485 bitmap_clear(t->io_bitmap_ptr, from, num);
20486 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
20487 return -EINVAL;
20488 /* Trying to gain more privileges? */
20489 if (level > old) {
20490 +#ifdef CONFIG_GRKERNSEC_IO
20491 + if (grsec_disable_privio) {
20492 + gr_handle_iopl();
20493 + return -EPERM;
20494 + }
20495 +#endif
20496 if (!capable(CAP_SYS_RAWIO))
20497 return -EPERM;
20498 }
20499 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20500 index e4595f1..ee3bfb8 100644
20501 --- a/arch/x86/kernel/irq.c
20502 +++ b/arch/x86/kernel/irq.c
20503 @@ -18,7 +18,7 @@
20504 #include <asm/mce.h>
20505 #include <asm/hw_irq.h>
20506
20507 -atomic_t irq_err_count;
20508 +atomic_unchecked_t irq_err_count;
20509
20510 /* Function pointer for generic interrupt vector handling */
20511 void (*x86_platform_ipi_callback)(void) = NULL;
20512 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20513 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20514 seq_printf(p, " Machine check polls\n");
20515 #endif
20516 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20517 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20518 #if defined(CONFIG_X86_IO_APIC)
20519 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20520 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20521 #endif
20522 return 0;
20523 }
20524 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20525
20526 u64 arch_irq_stat(void)
20527 {
20528 - u64 sum = atomic_read(&irq_err_count);
20529 + u64 sum = atomic_read_unchecked(&irq_err_count);
20530
20531 #ifdef CONFIG_X86_IO_APIC
20532 - sum += atomic_read(&irq_mis_count);
20533 + sum += atomic_read_unchecked(&irq_mis_count);
20534 #endif
20535 return sum;
20536 }
20537 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20538 index 344faf8..355f60d 100644
20539 --- a/arch/x86/kernel/irq_32.c
20540 +++ b/arch/x86/kernel/irq_32.c
20541 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20542 __asm__ __volatile__("andl %%esp,%0" :
20543 "=r" (sp) : "0" (THREAD_SIZE - 1));
20544
20545 - return sp < (sizeof(struct thread_info) + STACK_WARN);
20546 + return sp < STACK_WARN;
20547 }
20548
20549 static void print_stack_overflow(void)
20550 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20551 * per-CPU IRQ handling contexts (thread information and stack)
20552 */
20553 union irq_ctx {
20554 - struct thread_info tinfo;
20555 - u32 stack[THREAD_SIZE/sizeof(u32)];
20556 + unsigned long previous_esp;
20557 + u32 stack[THREAD_SIZE/sizeof(u32)];
20558 } __attribute__((aligned(THREAD_SIZE)));
20559
20560 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20561 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20562 static inline int
20563 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20564 {
20565 - union irq_ctx *curctx, *irqctx;
20566 + union irq_ctx *irqctx;
20567 u32 *isp, arg1, arg2;
20568
20569 - curctx = (union irq_ctx *) current_thread_info();
20570 irqctx = __this_cpu_read(hardirq_ctx);
20571
20572 /*
20573 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20574 * handler) we can't do that and just have to keep using the
20575 * current stack (which is the irq stack already after all)
20576 */
20577 - if (unlikely(curctx == irqctx))
20578 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20579 return 0;
20580
20581 /* build the stack frame on the IRQ stack */
20582 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20583 - irqctx->tinfo.task = curctx->tinfo.task;
20584 - irqctx->tinfo.previous_esp = current_stack_pointer;
20585 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20586 + irqctx->previous_esp = current_stack_pointer;
20587
20588 - /* Copy the preempt_count so that the [soft]irq checks work. */
20589 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20590 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20591 + __set_fs(MAKE_MM_SEG(0));
20592 +#endif
20593
20594 if (unlikely(overflow))
20595 call_on_stack(print_stack_overflow, isp);
20596 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20597 : "0" (irq), "1" (desc), "2" (isp),
20598 "D" (desc->handle_irq)
20599 : "memory", "cc", "ecx");
20600 +
20601 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20602 + __set_fs(current_thread_info()->addr_limit);
20603 +#endif
20604 +
20605 return 1;
20606 }
20607
20608 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20609 */
20610 void __cpuinit irq_ctx_init(int cpu)
20611 {
20612 - union irq_ctx *irqctx;
20613 -
20614 if (per_cpu(hardirq_ctx, cpu))
20615 return;
20616
20617 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20618 - THREADINFO_GFP,
20619 - THREAD_SIZE_ORDER));
20620 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20621 - irqctx->tinfo.cpu = cpu;
20622 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
20623 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20624 -
20625 - per_cpu(hardirq_ctx, cpu) = irqctx;
20626 -
20627 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20628 - THREADINFO_GFP,
20629 - THREAD_SIZE_ORDER));
20630 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20631 - irqctx->tinfo.cpu = cpu;
20632 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20633 -
20634 - per_cpu(softirq_ctx, cpu) = irqctx;
20635 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20636 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20637 +
20638 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20639 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20640
20641 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20642 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20643 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
20644 asmlinkage void do_softirq(void)
20645 {
20646 unsigned long flags;
20647 - struct thread_info *curctx;
20648 union irq_ctx *irqctx;
20649 u32 *isp;
20650
20651 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
20652 local_irq_save(flags);
20653
20654 if (local_softirq_pending()) {
20655 - curctx = current_thread_info();
20656 irqctx = __this_cpu_read(softirq_ctx);
20657 - irqctx->tinfo.task = curctx->task;
20658 - irqctx->tinfo.previous_esp = current_stack_pointer;
20659 + irqctx->previous_esp = current_stack_pointer;
20660
20661 /* build the stack frame on the softirq stack */
20662 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20663 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20664 +
20665 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20666 + __set_fs(MAKE_MM_SEG(0));
20667 +#endif
20668
20669 call_on_stack(__do_softirq, isp);
20670 +
20671 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20672 + __set_fs(current_thread_info()->addr_limit);
20673 +#endif
20674 +
20675 /*
20676 * Shouldn't happen, we returned above if in_interrupt():
20677 */
20678 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
20679 if (unlikely(!desc))
20680 return false;
20681
20682 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20683 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20684 if (unlikely(overflow))
20685 print_stack_overflow();
20686 desc->handle_irq(irq, desc);
20687 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
20688 index d04d3ec..ea4b374 100644
20689 --- a/arch/x86/kernel/irq_64.c
20690 +++ b/arch/x86/kernel/irq_64.c
20691 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
20692 u64 estack_top, estack_bottom;
20693 u64 curbase = (u64)task_stack_page(current);
20694
20695 - if (user_mode_vm(regs))
20696 + if (user_mode(regs))
20697 return;
20698
20699 if (regs->sp >= curbase + sizeof(struct thread_info) +
20700 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
20701 index dc1404b..bbc43e7 100644
20702 --- a/arch/x86/kernel/kdebugfs.c
20703 +++ b/arch/x86/kernel/kdebugfs.c
20704 @@ -27,7 +27,7 @@ struct setup_data_node {
20705 u32 len;
20706 };
20707
20708 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
20709 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
20710 size_t count, loff_t *ppos)
20711 {
20712 struct setup_data_node *node = file->private_data;
20713 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
20714 index 836f832..a8bda67 100644
20715 --- a/arch/x86/kernel/kgdb.c
20716 +++ b/arch/x86/kernel/kgdb.c
20717 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
20718 #ifdef CONFIG_X86_32
20719 switch (regno) {
20720 case GDB_SS:
20721 - if (!user_mode_vm(regs))
20722 + if (!user_mode(regs))
20723 *(unsigned long *)mem = __KERNEL_DS;
20724 break;
20725 case GDB_SP:
20726 - if (!user_mode_vm(regs))
20727 + if (!user_mode(regs))
20728 *(unsigned long *)mem = kernel_stack_pointer(regs);
20729 break;
20730 case GDB_GS:
20731 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
20732 bp->attr.bp_addr = breakinfo[breakno].addr;
20733 bp->attr.bp_len = breakinfo[breakno].len;
20734 bp->attr.bp_type = breakinfo[breakno].type;
20735 - info->address = breakinfo[breakno].addr;
20736 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
20737 + info->address = ktla_ktva(breakinfo[breakno].addr);
20738 + else
20739 + info->address = breakinfo[breakno].addr;
20740 info->len = breakinfo[breakno].len;
20741 info->type = breakinfo[breakno].type;
20742 val = arch_install_hw_breakpoint(bp);
20743 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
20744 case 'k':
20745 /* clear the trace bit */
20746 linux_regs->flags &= ~X86_EFLAGS_TF;
20747 - atomic_set(&kgdb_cpu_doing_single_step, -1);
20748 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
20749
20750 /* set the trace bit if we're stepping */
20751 if (remcomInBuffer[0] == 's') {
20752 linux_regs->flags |= X86_EFLAGS_TF;
20753 - atomic_set(&kgdb_cpu_doing_single_step,
20754 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
20755 raw_smp_processor_id());
20756 }
20757
20758 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
20759
20760 switch (cmd) {
20761 case DIE_DEBUG:
20762 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
20763 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
20764 if (user_mode(regs))
20765 return single_step_cont(regs, args);
20766 break;
20767 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20768 #endif /* CONFIG_DEBUG_RODATA */
20769
20770 bpt->type = BP_BREAKPOINT;
20771 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
20772 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
20773 BREAK_INSTR_SIZE);
20774 if (err)
20775 return err;
20776 - err = probe_kernel_write((char *)bpt->bpt_addr,
20777 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20778 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
20779 #ifdef CONFIG_DEBUG_RODATA
20780 if (!err)
20781 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20782 return -EBUSY;
20783 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
20784 BREAK_INSTR_SIZE);
20785 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20786 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20787 if (err)
20788 return err;
20789 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
20790 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
20791 if (mutex_is_locked(&text_mutex))
20792 goto knl_write;
20793 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
20794 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20795 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20796 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
20797 goto knl_write;
20798 return err;
20799 knl_write:
20800 #endif /* CONFIG_DEBUG_RODATA */
20801 - return probe_kernel_write((char *)bpt->bpt_addr,
20802 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20803 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
20804 }
20805
20806 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
20807 index c5e410e..ed5a7f0 100644
20808 --- a/arch/x86/kernel/kprobes-opt.c
20809 +++ b/arch/x86/kernel/kprobes-opt.c
20810 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20811 * Verify if the address gap is in 2GB range, because this uses
20812 * a relative jump.
20813 */
20814 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
20815 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
20816 if (abs(rel) > 0x7fffffff)
20817 return -ERANGE;
20818
20819 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20820 op->optinsn.size = ret;
20821
20822 /* Copy arch-dep-instance from template */
20823 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
20824 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
20825
20826 /* Set probe information */
20827 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
20828
20829 /* Set probe function call */
20830 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
20831 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
20832
20833 /* Set returning jmp instruction at the tail of out-of-line buffer */
20834 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
20835 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
20836 (u8 *)op->kp.addr + op->optinsn.size);
20837
20838 flush_icache_range((unsigned long) buf,
20839 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
20840 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
20841
20842 /* Backup instructions which will be replaced by jump address */
20843 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
20844 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
20845 RELATIVE_ADDR_SIZE);
20846
20847 insn_buf[0] = RELATIVEJUMP_OPCODE;
20848 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
20849 /* This kprobe is really able to run optimized path. */
20850 op = container_of(p, struct optimized_kprobe, kp);
20851 /* Detour through copied instructions */
20852 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
20853 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
20854 if (!reenter)
20855 reset_current_kprobe();
20856 preempt_enable_no_resched();
20857 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
20858 index 57916c0..9e0b9d0 100644
20859 --- a/arch/x86/kernel/kprobes.c
20860 +++ b/arch/x86/kernel/kprobes.c
20861 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
20862 s32 raddr;
20863 } __attribute__((packed)) *insn;
20864
20865 - insn = (struct __arch_relative_insn *)from;
20866 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
20867 +
20868 + pax_open_kernel();
20869 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
20870 insn->op = op;
20871 + pax_close_kernel();
20872 }
20873
20874 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
20875 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
20876 kprobe_opcode_t opcode;
20877 kprobe_opcode_t *orig_opcodes = opcodes;
20878
20879 - if (search_exception_tables((unsigned long)opcodes))
20880 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
20881 return 0; /* Page fault may occur on this address. */
20882
20883 retry:
20884 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
20885 * for the first byte, we can recover the original instruction
20886 * from it and kp->opcode.
20887 */
20888 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20889 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20890 buf[0] = kp->opcode;
20891 - return (unsigned long)buf;
20892 + return ktva_ktla((unsigned long)buf);
20893 }
20894
20895 /*
20896 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20897 /* Another subsystem puts a breakpoint, failed to recover */
20898 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
20899 return 0;
20900 + pax_open_kernel();
20901 memcpy(dest, insn.kaddr, insn.length);
20902 + pax_close_kernel();
20903
20904 #ifdef CONFIG_X86_64
20905 if (insn_rip_relative(&insn)) {
20906 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20907 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
20908 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
20909 disp = (u8 *) dest + insn_offset_displacement(&insn);
20910 + pax_open_kernel();
20911 *(s32 *) disp = (s32) newdisp;
20912 + pax_close_kernel();
20913 }
20914 #endif
20915 return insn.length;
20916 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20917 * nor set current_kprobe, because it doesn't use single
20918 * stepping.
20919 */
20920 - regs->ip = (unsigned long)p->ainsn.insn;
20921 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20922 preempt_enable_no_resched();
20923 return;
20924 }
20925 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20926 regs->flags &= ~X86_EFLAGS_IF;
20927 /* single step inline if the instruction is an int3 */
20928 if (p->opcode == BREAKPOINT_INSTRUCTION)
20929 - regs->ip = (unsigned long)p->addr;
20930 + regs->ip = ktla_ktva((unsigned long)p->addr);
20931 else
20932 - regs->ip = (unsigned long)p->ainsn.insn;
20933 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20934 }
20935
20936 /*
20937 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
20938 setup_singlestep(p, regs, kcb, 0);
20939 return 1;
20940 }
20941 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
20942 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
20943 /*
20944 * The breakpoint instruction was removed right
20945 * after we hit it. Another cpu has removed
20946 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
20947 " movq %rax, 152(%rsp)\n"
20948 RESTORE_REGS_STRING
20949 " popfq\n"
20950 +#ifdef KERNEXEC_PLUGIN
20951 + " btsq $63,(%rsp)\n"
20952 +#endif
20953 #else
20954 " pushf\n"
20955 SAVE_REGS_STRING
20956 @@ -788,7 +798,7 @@ static void __kprobes
20957 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
20958 {
20959 unsigned long *tos = stack_addr(regs);
20960 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
20961 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
20962 unsigned long orig_ip = (unsigned long)p->addr;
20963 kprobe_opcode_t *insn = p->ainsn.insn;
20964
20965 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
20966 struct die_args *args = data;
20967 int ret = NOTIFY_DONE;
20968
20969 - if (args->regs && user_mode_vm(args->regs))
20970 + if (args->regs && user_mode(args->regs))
20971 return ret;
20972
20973 switch (val) {
20974 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
20975 index 9c2bd8b..bb1131c 100644
20976 --- a/arch/x86/kernel/kvm.c
20977 +++ b/arch/x86/kernel/kvm.c
20978 @@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
20979 return NOTIFY_OK;
20980 }
20981
20982 -static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
20983 +static struct notifier_block kvm_cpu_notifier = {
20984 .notifier_call = kvm_cpu_notify,
20985 };
20986 #endif
20987 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
20988 index ebc9873..1b9724b 100644
20989 --- a/arch/x86/kernel/ldt.c
20990 +++ b/arch/x86/kernel/ldt.c
20991 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
20992 if (reload) {
20993 #ifdef CONFIG_SMP
20994 preempt_disable();
20995 - load_LDT(pc);
20996 + load_LDT_nolock(pc);
20997 if (!cpumask_equal(mm_cpumask(current->mm),
20998 cpumask_of(smp_processor_id())))
20999 smp_call_function(flush_ldt, current->mm, 1);
21000 preempt_enable();
21001 #else
21002 - load_LDT(pc);
21003 + load_LDT_nolock(pc);
21004 #endif
21005 }
21006 if (oldsize) {
21007 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21008 return err;
21009
21010 for (i = 0; i < old->size; i++)
21011 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21012 + write_ldt_entry(new->ldt, i, old->ldt + i);
21013 return 0;
21014 }
21015
21016 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21017 retval = copy_ldt(&mm->context, &old_mm->context);
21018 mutex_unlock(&old_mm->context.lock);
21019 }
21020 +
21021 + if (tsk == current) {
21022 + mm->context.vdso = 0;
21023 +
21024 +#ifdef CONFIG_X86_32
21025 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21026 + mm->context.user_cs_base = 0UL;
21027 + mm->context.user_cs_limit = ~0UL;
21028 +
21029 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21030 + cpus_clear(mm->context.cpu_user_cs_mask);
21031 +#endif
21032 +
21033 +#endif
21034 +#endif
21035 +
21036 + }
21037 +
21038 return retval;
21039 }
21040
21041 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21042 }
21043 }
21044
21045 +#ifdef CONFIG_PAX_SEGMEXEC
21046 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21047 + error = -EINVAL;
21048 + goto out_unlock;
21049 + }
21050 +#endif
21051 +
21052 fill_ldt(&ldt, &ldt_info);
21053 if (oldmode)
21054 ldt.avl = 0;
21055 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21056 index 5b19e4d..6476a76 100644
21057 --- a/arch/x86/kernel/machine_kexec_32.c
21058 +++ b/arch/x86/kernel/machine_kexec_32.c
21059 @@ -26,7 +26,7 @@
21060 #include <asm/cacheflush.h>
21061 #include <asm/debugreg.h>
21062
21063 -static void set_idt(void *newidt, __u16 limit)
21064 +static void set_idt(struct desc_struct *newidt, __u16 limit)
21065 {
21066 struct desc_ptr curidt;
21067
21068 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21069 }
21070
21071
21072 -static void set_gdt(void *newgdt, __u16 limit)
21073 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21074 {
21075 struct desc_ptr curgdt;
21076
21077 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21078 }
21079
21080 control_page = page_address(image->control_code_page);
21081 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21082 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21083
21084 relocate_kernel_ptr = control_page;
21085 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21086 diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21087 index 3a04b22..1d2eb09 100644
21088 --- a/arch/x86/kernel/microcode_core.c
21089 +++ b/arch/x86/kernel/microcode_core.c
21090 @@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21091 return NOTIFY_OK;
21092 }
21093
21094 -static struct notifier_block __refdata mc_cpu_notifier = {
21095 +static struct notifier_block mc_cpu_notifier = {
21096 .notifier_call = mc_cpu_callback,
21097 };
21098
21099 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21100 index 3544aed..01ddc1c 100644
21101 --- a/arch/x86/kernel/microcode_intel.c
21102 +++ b/arch/x86/kernel/microcode_intel.c
21103 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21104
21105 static int get_ucode_user(void *to, const void *from, size_t n)
21106 {
21107 - return copy_from_user(to, from, n);
21108 + return copy_from_user(to, (const void __force_user *)from, n);
21109 }
21110
21111 static enum ucode_state
21112 request_microcode_user(int cpu, const void __user *buf, size_t size)
21113 {
21114 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21115 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21116 }
21117
21118 static void microcode_fini_cpu(int cpu)
21119 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21120 index 216a4d7..228255a 100644
21121 --- a/arch/x86/kernel/module.c
21122 +++ b/arch/x86/kernel/module.c
21123 @@ -43,15 +43,60 @@ do { \
21124 } while (0)
21125 #endif
21126
21127 -void *module_alloc(unsigned long size)
21128 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21129 {
21130 - if (PAGE_ALIGN(size) > MODULES_LEN)
21131 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21132 return NULL;
21133 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21134 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21135 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21136 -1, __builtin_return_address(0));
21137 }
21138
21139 +void *module_alloc(unsigned long size)
21140 +{
21141 +
21142 +#ifdef CONFIG_PAX_KERNEXEC
21143 + return __module_alloc(size, PAGE_KERNEL);
21144 +#else
21145 + return __module_alloc(size, PAGE_KERNEL_EXEC);
21146 +#endif
21147 +
21148 +}
21149 +
21150 +#ifdef CONFIG_PAX_KERNEXEC
21151 +#ifdef CONFIG_X86_32
21152 +void *module_alloc_exec(unsigned long size)
21153 +{
21154 + struct vm_struct *area;
21155 +
21156 + if (size == 0)
21157 + return NULL;
21158 +
21159 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21160 + return area ? area->addr : NULL;
21161 +}
21162 +EXPORT_SYMBOL(module_alloc_exec);
21163 +
21164 +void module_free_exec(struct module *mod, void *module_region)
21165 +{
21166 + vunmap(module_region);
21167 +}
21168 +EXPORT_SYMBOL(module_free_exec);
21169 +#else
21170 +void module_free_exec(struct module *mod, void *module_region)
21171 +{
21172 + module_free(mod, module_region);
21173 +}
21174 +EXPORT_SYMBOL(module_free_exec);
21175 +
21176 +void *module_alloc_exec(unsigned long size)
21177 +{
21178 + return __module_alloc(size, PAGE_KERNEL_RX);
21179 +}
21180 +EXPORT_SYMBOL(module_alloc_exec);
21181 +#endif
21182 +#endif
21183 +
21184 #ifdef CONFIG_X86_32
21185 int apply_relocate(Elf32_Shdr *sechdrs,
21186 const char *strtab,
21187 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21188 unsigned int i;
21189 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21190 Elf32_Sym *sym;
21191 - uint32_t *location;
21192 + uint32_t *plocation, location;
21193
21194 DEBUGP("Applying relocate section %u to %u\n",
21195 relsec, sechdrs[relsec].sh_info);
21196 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21197 /* This is where to make the change */
21198 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21199 - + rel[i].r_offset;
21200 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21201 + location = (uint32_t)plocation;
21202 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21203 + plocation = ktla_ktva((void *)plocation);
21204 /* This is the symbol it is referring to. Note that all
21205 undefined symbols have been resolved. */
21206 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21207 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21208 switch (ELF32_R_TYPE(rel[i].r_info)) {
21209 case R_386_32:
21210 /* We add the value into the location given */
21211 - *location += sym->st_value;
21212 + pax_open_kernel();
21213 + *plocation += sym->st_value;
21214 + pax_close_kernel();
21215 break;
21216 case R_386_PC32:
21217 /* Add the value, subtract its position */
21218 - *location += sym->st_value - (uint32_t)location;
21219 + pax_open_kernel();
21220 + *plocation += sym->st_value - location;
21221 + pax_close_kernel();
21222 break;
21223 default:
21224 pr_err("%s: Unknown relocation: %u\n",
21225 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21226 case R_X86_64_NONE:
21227 break;
21228 case R_X86_64_64:
21229 + pax_open_kernel();
21230 *(u64 *)loc = val;
21231 + pax_close_kernel();
21232 break;
21233 case R_X86_64_32:
21234 + pax_open_kernel();
21235 *(u32 *)loc = val;
21236 + pax_close_kernel();
21237 if (val != *(u32 *)loc)
21238 goto overflow;
21239 break;
21240 case R_X86_64_32S:
21241 + pax_open_kernel();
21242 *(s32 *)loc = val;
21243 + pax_close_kernel();
21244 if ((s64)val != *(s32 *)loc)
21245 goto overflow;
21246 break;
21247 case R_X86_64_PC32:
21248 val -= (u64)loc;
21249 + pax_open_kernel();
21250 *(u32 *)loc = val;
21251 + pax_close_kernel();
21252 +
21253 #if 0
21254 if ((s64)val != *(s32 *)loc)
21255 goto overflow;
21256 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21257 index 4929502..686c291 100644
21258 --- a/arch/x86/kernel/msr.c
21259 +++ b/arch/x86/kernel/msr.c
21260 @@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21261 return notifier_from_errno(err);
21262 }
21263
21264 -static struct notifier_block __refdata msr_class_cpu_notifier = {
21265 +static struct notifier_block msr_class_cpu_notifier = {
21266 .notifier_call = msr_class_cpu_callback,
21267 };
21268
21269 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21270 index f84f5c5..f404e81 100644
21271 --- a/arch/x86/kernel/nmi.c
21272 +++ b/arch/x86/kernel/nmi.c
21273 @@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21274 return handled;
21275 }
21276
21277 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21278 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21279 {
21280 struct nmi_desc *desc = nmi_to_desc(type);
21281 unsigned long flags;
21282 @@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21283 * event confuses some handlers (kdump uses this flag)
21284 */
21285 if (action->flags & NMI_FLAG_FIRST)
21286 - list_add_rcu(&action->list, &desc->head);
21287 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21288 else
21289 - list_add_tail_rcu(&action->list, &desc->head);
21290 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21291
21292 spin_unlock_irqrestore(&desc->lock, flags);
21293 return 0;
21294 @@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21295 if (!strcmp(n->name, name)) {
21296 WARN(in_nmi(),
21297 "Trying to free NMI (%s) from NMI context!\n", n->name);
21298 - list_del_rcu(&n->list);
21299 + pax_list_del_rcu((struct list_head *)&n->list);
21300 break;
21301 }
21302 }
21303 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21304 dotraplinkage notrace __kprobes void
21305 do_nmi(struct pt_regs *regs, long error_code)
21306 {
21307 +
21308 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21309 + if (!user_mode(regs)) {
21310 + unsigned long cs = regs->cs & 0xFFFF;
21311 + unsigned long ip = ktva_ktla(regs->ip);
21312 +
21313 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21314 + regs->ip = ip;
21315 + }
21316 +#endif
21317 +
21318 nmi_nesting_preprocess(regs);
21319
21320 nmi_enter();
21321 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21322 index 6d9582e..f746287 100644
21323 --- a/arch/x86/kernel/nmi_selftest.c
21324 +++ b/arch/x86/kernel/nmi_selftest.c
21325 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21326 {
21327 /* trap all the unknown NMIs we may generate */
21328 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21329 - __initdata);
21330 + __initconst);
21331 }
21332
21333 static void __init cleanup_nmi_testsuite(void)
21334 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21335 unsigned long timeout;
21336
21337 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21338 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21339 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21340 nmi_fail = FAILURE;
21341 return;
21342 }
21343 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21344 index 676b8c7..870ba04 100644
21345 --- a/arch/x86/kernel/paravirt-spinlocks.c
21346 +++ b/arch/x86/kernel/paravirt-spinlocks.c
21347 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21348 arch_spin_lock(lock);
21349 }
21350
21351 -struct pv_lock_ops pv_lock_ops = {
21352 +struct pv_lock_ops pv_lock_ops __read_only = {
21353 #ifdef CONFIG_SMP
21354 .spin_is_locked = __ticket_spin_is_locked,
21355 .spin_is_contended = __ticket_spin_is_contended,
21356 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21357 index 17fff18..5cfa0f4 100644
21358 --- a/arch/x86/kernel/paravirt.c
21359 +++ b/arch/x86/kernel/paravirt.c
21360 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21361 {
21362 return x;
21363 }
21364 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21365 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21366 +#endif
21367
21368 void __init default_banner(void)
21369 {
21370 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21371 if (opfunc == NULL)
21372 /* If there's no function, patch it with a ud2a (BUG) */
21373 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21374 - else if (opfunc == _paravirt_nop)
21375 + else if (opfunc == (void *)_paravirt_nop)
21376 /* If the operation is a nop, then nop the callsite */
21377 ret = paravirt_patch_nop();
21378
21379 /* identity functions just return their single argument */
21380 - else if (opfunc == _paravirt_ident_32)
21381 + else if (opfunc == (void *)_paravirt_ident_32)
21382 ret = paravirt_patch_ident_32(insnbuf, len);
21383 - else if (opfunc == _paravirt_ident_64)
21384 + else if (opfunc == (void *)_paravirt_ident_64)
21385 ret = paravirt_patch_ident_64(insnbuf, len);
21386 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21387 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21388 + ret = paravirt_patch_ident_64(insnbuf, len);
21389 +#endif
21390
21391 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21392 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21393 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21394 if (insn_len > len || start == NULL)
21395 insn_len = len;
21396 else
21397 - memcpy(insnbuf, start, insn_len);
21398 + memcpy(insnbuf, ktla_ktva(start), insn_len);
21399
21400 return insn_len;
21401 }
21402 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
21403 preempt_enable();
21404 }
21405
21406 -struct pv_info pv_info = {
21407 +struct pv_info pv_info __read_only = {
21408 .name = "bare hardware",
21409 .paravirt_enabled = 0,
21410 .kernel_rpl = 0,
21411 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
21412 #endif
21413 };
21414
21415 -struct pv_init_ops pv_init_ops = {
21416 +struct pv_init_ops pv_init_ops __read_only = {
21417 .patch = native_patch,
21418 };
21419
21420 -struct pv_time_ops pv_time_ops = {
21421 +struct pv_time_ops pv_time_ops __read_only = {
21422 .sched_clock = native_sched_clock,
21423 .steal_clock = native_steal_clock,
21424 };
21425
21426 -struct pv_irq_ops pv_irq_ops = {
21427 +struct pv_irq_ops pv_irq_ops __read_only = {
21428 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21429 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21430 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21431 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21432 #endif
21433 };
21434
21435 -struct pv_cpu_ops pv_cpu_ops = {
21436 +struct pv_cpu_ops pv_cpu_ops __read_only = {
21437 .cpuid = native_cpuid,
21438 .get_debugreg = native_get_debugreg,
21439 .set_debugreg = native_set_debugreg,
21440 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21441 .end_context_switch = paravirt_nop,
21442 };
21443
21444 -struct pv_apic_ops pv_apic_ops = {
21445 +struct pv_apic_ops pv_apic_ops __read_only= {
21446 #ifdef CONFIG_X86_LOCAL_APIC
21447 .startup_ipi_hook = paravirt_nop,
21448 #endif
21449 };
21450
21451 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21452 +#ifdef CONFIG_X86_32
21453 +#ifdef CONFIG_X86_PAE
21454 +/* 64-bit pagetable entries */
21455 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21456 +#else
21457 /* 32-bit pagetable entries */
21458 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21459 +#endif
21460 #else
21461 /* 64-bit pagetable entries */
21462 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21463 #endif
21464
21465 -struct pv_mmu_ops pv_mmu_ops = {
21466 +struct pv_mmu_ops pv_mmu_ops __read_only = {
21467
21468 .read_cr2 = native_read_cr2,
21469 .write_cr2 = native_write_cr2,
21470 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21471 .make_pud = PTE_IDENT,
21472
21473 .set_pgd = native_set_pgd,
21474 + .set_pgd_batched = native_set_pgd_batched,
21475 #endif
21476 #endif /* PAGETABLE_LEVELS >= 3 */
21477
21478 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21479 },
21480
21481 .set_fixmap = native_set_fixmap,
21482 +
21483 +#ifdef CONFIG_PAX_KERNEXEC
21484 + .pax_open_kernel = native_pax_open_kernel,
21485 + .pax_close_kernel = native_pax_close_kernel,
21486 +#endif
21487 +
21488 };
21489
21490 EXPORT_SYMBOL_GPL(pv_time_ops);
21491 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21492 index 35ccf75..7a15747 100644
21493 --- a/arch/x86/kernel/pci-iommu_table.c
21494 +++ b/arch/x86/kernel/pci-iommu_table.c
21495 @@ -2,7 +2,7 @@
21496 #include <asm/iommu_table.h>
21497 #include <linux/string.h>
21498 #include <linux/kallsyms.h>
21499 -
21500 +#include <linux/sched.h>
21501
21502 #define DEBUG 1
21503
21504 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
21505 index 6c483ba..d10ce2f 100644
21506 --- a/arch/x86/kernel/pci-swiotlb.c
21507 +++ b/arch/x86/kernel/pci-swiotlb.c
21508 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
21509 void *vaddr, dma_addr_t dma_addr,
21510 struct dma_attrs *attrs)
21511 {
21512 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
21513 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
21514 }
21515
21516 static struct dma_map_ops swiotlb_dma_ops = {
21517 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21518 index 2ed787f..f70c9f6 100644
21519 --- a/arch/x86/kernel/process.c
21520 +++ b/arch/x86/kernel/process.c
21521 @@ -36,7 +36,8 @@
21522 * section. Since TSS's are completely CPU-local, we want them
21523 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21524 */
21525 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21526 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21527 +EXPORT_SYMBOL(init_tss);
21528
21529 #ifdef CONFIG_X86_64
21530 static DEFINE_PER_CPU(unsigned char, is_idle);
21531 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21532 task_xstate_cachep =
21533 kmem_cache_create("task_xstate", xstate_size,
21534 __alignof__(union thread_xstate),
21535 - SLAB_PANIC | SLAB_NOTRACK, NULL);
21536 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21537 }
21538
21539 /*
21540 @@ -105,7 +106,7 @@ void exit_thread(void)
21541 unsigned long *bp = t->io_bitmap_ptr;
21542
21543 if (bp) {
21544 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21545 + struct tss_struct *tss = init_tss + get_cpu();
21546
21547 t->io_bitmap_ptr = NULL;
21548 clear_thread_flag(TIF_IO_BITMAP);
21549 @@ -136,7 +137,7 @@ void show_regs_common(void)
21550 board = dmi_get_system_info(DMI_BOARD_NAME);
21551
21552 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21553 - current->pid, current->comm, print_tainted(),
21554 + task_pid_nr(current), current->comm, print_tainted(),
21555 init_utsname()->release,
21556 (int)strcspn(init_utsname()->version, " "),
21557 init_utsname()->version,
21558 @@ -149,6 +150,9 @@ void flush_thread(void)
21559 {
21560 struct task_struct *tsk = current;
21561
21562 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21563 + loadsegment(gs, 0);
21564 +#endif
21565 flush_ptrace_hw_breakpoint(tsk);
21566 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21567 drop_init_fpu(tsk);
21568 @@ -301,7 +305,7 @@ static void __exit_idle(void)
21569 void exit_idle(void)
21570 {
21571 /* idle loop has pid 0 */
21572 - if (current->pid)
21573 + if (task_pid_nr(current))
21574 return;
21575 __exit_idle();
21576 }
21577 @@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
21578
21579 return ret;
21580 }
21581 -void stop_this_cpu(void *dummy)
21582 +__noreturn void stop_this_cpu(void *dummy)
21583 {
21584 local_irq_disable();
21585 /*
21586 @@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
21587 }
21588 early_param("idle", idle_setup);
21589
21590 -unsigned long arch_align_stack(unsigned long sp)
21591 +#ifdef CONFIG_PAX_RANDKSTACK
21592 +void pax_randomize_kstack(struct pt_regs *regs)
21593 {
21594 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
21595 - sp -= get_random_int() % 8192;
21596 - return sp & ~0xf;
21597 -}
21598 + struct thread_struct *thread = &current->thread;
21599 + unsigned long time;
21600
21601 -unsigned long arch_randomize_brk(struct mm_struct *mm)
21602 -{
21603 - unsigned long range_end = mm->brk + 0x02000000;
21604 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
21605 -}
21606 + if (!randomize_va_space)
21607 + return;
21608 +
21609 + if (v8086_mode(regs))
21610 + return;
21611
21612 + rdtscl(time);
21613 +
21614 + /* P4 seems to return a 0 LSB, ignore it */
21615 +#ifdef CONFIG_MPENTIUM4
21616 + time &= 0x3EUL;
21617 + time <<= 2;
21618 +#elif defined(CONFIG_X86_64)
21619 + time &= 0xFUL;
21620 + time <<= 4;
21621 +#else
21622 + time &= 0x1FUL;
21623 + time <<= 3;
21624 +#endif
21625 +
21626 + thread->sp0 ^= time;
21627 + load_sp0(init_tss + smp_processor_id(), thread);
21628 +
21629 +#ifdef CONFIG_X86_64
21630 + this_cpu_write(kernel_stack, thread->sp0);
21631 +#endif
21632 +}
21633 +#endif
21634 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
21635 index b5a8905..d9cacac 100644
21636 --- a/arch/x86/kernel/process_32.c
21637 +++ b/arch/x86/kernel/process_32.c
21638 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
21639 unsigned long thread_saved_pc(struct task_struct *tsk)
21640 {
21641 return ((unsigned long *)tsk->thread.sp)[3];
21642 +//XXX return tsk->thread.eip;
21643 }
21644
21645 void __show_regs(struct pt_regs *regs, int all)
21646 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
21647 unsigned long sp;
21648 unsigned short ss, gs;
21649
21650 - if (user_mode_vm(regs)) {
21651 + if (user_mode(regs)) {
21652 sp = regs->sp;
21653 ss = regs->ss & 0xffff;
21654 - gs = get_user_gs(regs);
21655 } else {
21656 sp = kernel_stack_pointer(regs);
21657 savesegment(ss, ss);
21658 - savesegment(gs, gs);
21659 }
21660 + gs = get_user_gs(regs);
21661
21662 show_regs_common();
21663
21664 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
21665 (u16)regs->cs, regs->ip, regs->flags,
21666 - smp_processor_id());
21667 + raw_smp_processor_id());
21668 print_symbol("EIP is at %s\n", regs->ip);
21669
21670 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
21671 @@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
21672 int copy_thread(unsigned long clone_flags, unsigned long sp,
21673 unsigned long arg, struct task_struct *p)
21674 {
21675 - struct pt_regs *childregs = task_pt_regs(p);
21676 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
21677 struct task_struct *tsk;
21678 int err;
21679
21680 p->thread.sp = (unsigned long) childregs;
21681 p->thread.sp0 = (unsigned long) (childregs+1);
21682 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21683
21684 if (unlikely(p->flags & PF_KTHREAD)) {
21685 /* kernel thread */
21686 memset(childregs, 0, sizeof(struct pt_regs));
21687 p->thread.ip = (unsigned long) ret_from_kernel_thread;
21688 - task_user_gs(p) = __KERNEL_STACK_CANARY;
21689 - childregs->ds = __USER_DS;
21690 - childregs->es = __USER_DS;
21691 + savesegment(gs, childregs->gs);
21692 + childregs->ds = __KERNEL_DS;
21693 + childregs->es = __KERNEL_DS;
21694 childregs->fs = __KERNEL_PERCPU;
21695 childregs->bx = sp; /* function */
21696 childregs->bp = arg;
21697 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21698 struct thread_struct *prev = &prev_p->thread,
21699 *next = &next_p->thread;
21700 int cpu = smp_processor_id();
21701 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21702 + struct tss_struct *tss = init_tss + cpu;
21703 fpu_switch_t fpu;
21704
21705 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
21706 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21707 */
21708 lazy_save_gs(prev->gs);
21709
21710 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21711 + __set_fs(task_thread_info(next_p)->addr_limit);
21712 +#endif
21713 +
21714 /*
21715 * Load the per-thread Thread-Local Storage descriptor.
21716 */
21717 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21718 */
21719 arch_end_context_switch(next_p);
21720
21721 + this_cpu_write(current_task, next_p);
21722 + this_cpu_write(current_tinfo, &next_p->tinfo);
21723 +
21724 /*
21725 * Restore %gs if needed (which is common)
21726 */
21727 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21728
21729 switch_fpu_finish(next_p, fpu);
21730
21731 - this_cpu_write(current_task, next_p);
21732 -
21733 return prev_p;
21734 }
21735
21736 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
21737 } while (count++ < 16);
21738 return 0;
21739 }
21740 -
21741 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
21742 index 6e68a61..955a9a5 100644
21743 --- a/arch/x86/kernel/process_64.c
21744 +++ b/arch/x86/kernel/process_64.c
21745 @@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
21746 struct pt_regs *childregs;
21747 struct task_struct *me = current;
21748
21749 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
21750 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
21751 childregs = task_pt_regs(p);
21752 p->thread.sp = (unsigned long) childregs;
21753 p->thread.usersp = me->thread.usersp;
21754 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21755 set_tsk_thread_flag(p, TIF_FORK);
21756 p->fpu_counter = 0;
21757 p->thread.io_bitmap_ptr = NULL;
21758 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21759 struct thread_struct *prev = &prev_p->thread;
21760 struct thread_struct *next = &next_p->thread;
21761 int cpu = smp_processor_id();
21762 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21763 + struct tss_struct *tss = init_tss + cpu;
21764 unsigned fsindex, gsindex;
21765 fpu_switch_t fpu;
21766
21767 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21768 prev->usersp = this_cpu_read(old_rsp);
21769 this_cpu_write(old_rsp, next->usersp);
21770 this_cpu_write(current_task, next_p);
21771 + this_cpu_write(current_tinfo, &next_p->tinfo);
21772
21773 - this_cpu_write(kernel_stack,
21774 - (unsigned long)task_stack_page(next_p) +
21775 - THREAD_SIZE - KERNEL_STACK_OFFSET);
21776 + this_cpu_write(kernel_stack, next->sp0);
21777
21778 /*
21779 * Now maybe reload the debug registers and handle I/O bitmaps
21780 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
21781 if (!p || p == current || p->state == TASK_RUNNING)
21782 return 0;
21783 stack = (unsigned long)task_stack_page(p);
21784 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
21785 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
21786 return 0;
21787 fp = *(u64 *)(p->thread.sp);
21788 do {
21789 - if (fp < (unsigned long)stack ||
21790 - fp >= (unsigned long)stack+THREAD_SIZE)
21791 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
21792 return 0;
21793 ip = *(u64 *)(fp+8);
21794 if (!in_sched_functions(ip))
21795 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
21796 index b629bbe..0fa615a 100644
21797 --- a/arch/x86/kernel/ptrace.c
21798 +++ b/arch/x86/kernel/ptrace.c
21799 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
21800 {
21801 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
21802 unsigned long sp = (unsigned long)&regs->sp;
21803 - struct thread_info *tinfo;
21804
21805 - if (context == (sp & ~(THREAD_SIZE - 1)))
21806 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
21807 return sp;
21808
21809 - tinfo = (struct thread_info *)context;
21810 - if (tinfo->previous_esp)
21811 - return tinfo->previous_esp;
21812 + sp = *(unsigned long *)context;
21813 + if (sp)
21814 + return sp;
21815
21816 return (unsigned long)regs;
21817 }
21818 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
21819 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
21820 {
21821 int i;
21822 - int dr7 = 0;
21823 + unsigned long dr7 = 0;
21824 struct arch_hw_breakpoint *info;
21825
21826 for (i = 0; i < HBP_NUM; i++) {
21827 @@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
21828 unsigned long addr, unsigned long data)
21829 {
21830 int ret;
21831 - unsigned long __user *datap = (unsigned long __user *)data;
21832 + unsigned long __user *datap = (__force unsigned long __user *)data;
21833
21834 switch (request) {
21835 /* read the word at location addr in the USER area. */
21836 @@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
21837 if ((int) addr < 0)
21838 return -EIO;
21839 ret = do_get_thread_area(child, addr,
21840 - (struct user_desc __user *)data);
21841 + (__force struct user_desc __user *) data);
21842 break;
21843
21844 case PTRACE_SET_THREAD_AREA:
21845 if ((int) addr < 0)
21846 return -EIO;
21847 ret = do_set_thread_area(child, addr,
21848 - (struct user_desc __user *)data, 0);
21849 + (__force struct user_desc __user *) data, 0);
21850 break;
21851 #endif
21852
21853 @@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
21854
21855 #ifdef CONFIG_X86_64
21856
21857 -static struct user_regset x86_64_regsets[] __read_mostly = {
21858 +static user_regset_no_const x86_64_regsets[] __read_only = {
21859 [REGSET_GENERAL] = {
21860 .core_note_type = NT_PRSTATUS,
21861 .n = sizeof(struct user_regs_struct) / sizeof(long),
21862 @@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
21863 #endif /* CONFIG_X86_64 */
21864
21865 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
21866 -static struct user_regset x86_32_regsets[] __read_mostly = {
21867 +static user_regset_no_const x86_32_regsets[] __read_only = {
21868 [REGSET_GENERAL] = {
21869 .core_note_type = NT_PRSTATUS,
21870 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
21871 @@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
21872 */
21873 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
21874
21875 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21876 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21877 {
21878 #ifdef CONFIG_X86_64
21879 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
21880 @@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
21881 memset(info, 0, sizeof(*info));
21882 info->si_signo = SIGTRAP;
21883 info->si_code = si_code;
21884 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
21885 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
21886 }
21887
21888 void user_single_step_siginfo(struct task_struct *tsk,
21889 @@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
21890 # define IS_IA32 0
21891 #endif
21892
21893 +#ifdef CONFIG_GRKERNSEC_SETXID
21894 +extern void gr_delayed_cred_worker(void);
21895 +#endif
21896 +
21897 /*
21898 * We must return the syscall number to actually look up in the table.
21899 * This can be -1L to skip running any syscall at all.
21900 @@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
21901
21902 user_exit();
21903
21904 +#ifdef CONFIG_GRKERNSEC_SETXID
21905 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21906 + gr_delayed_cred_worker();
21907 +#endif
21908 +
21909 /*
21910 * If we stepped into a sysenter/syscall insn, it trapped in
21911 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
21912 @@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
21913 */
21914 user_exit();
21915
21916 +#ifdef CONFIG_GRKERNSEC_SETXID
21917 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21918 + gr_delayed_cred_worker();
21919 +#endif
21920 +
21921 audit_syscall_exit(regs);
21922
21923 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
21924 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
21925 index 85c3959..76b89f9 100644
21926 --- a/arch/x86/kernel/pvclock.c
21927 +++ b/arch/x86/kernel/pvclock.c
21928 @@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
21929 return pv_tsc_khz;
21930 }
21931
21932 -static atomic64_t last_value = ATOMIC64_INIT(0);
21933 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
21934
21935 void pvclock_resume(void)
21936 {
21937 - atomic64_set(&last_value, 0);
21938 + atomic64_set_unchecked(&last_value, 0);
21939 }
21940
21941 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
21942 @@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
21943 * updating at the same time, and one of them could be slightly behind,
21944 * making the assumption that last_value always go forward fail to hold.
21945 */
21946 - last = atomic64_read(&last_value);
21947 + last = atomic64_read_unchecked(&last_value);
21948 do {
21949 if (ret < last)
21950 return last;
21951 - last = atomic64_cmpxchg(&last_value, last, ret);
21952 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
21953 } while (unlikely(last != ret));
21954
21955 return ret;
21956 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
21957 index 76fa1e9..abf09ea 100644
21958 --- a/arch/x86/kernel/reboot.c
21959 +++ b/arch/x86/kernel/reboot.c
21960 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
21961 EXPORT_SYMBOL(pm_power_off);
21962
21963 static const struct desc_ptr no_idt = {};
21964 -static int reboot_mode;
21965 +static unsigned short reboot_mode;
21966 enum reboot_type reboot_type = BOOT_ACPI;
21967 int reboot_force;
21968
21969 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
21970
21971 void __noreturn machine_real_restart(unsigned int type)
21972 {
21973 +
21974 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21975 + struct desc_struct *gdt;
21976 +#endif
21977 +
21978 local_irq_disable();
21979
21980 /*
21981 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
21982
21983 /* Jump to the identity-mapped low memory code */
21984 #ifdef CONFIG_X86_32
21985 - asm volatile("jmpl *%0" : :
21986 +
21987 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21988 + gdt = get_cpu_gdt_table(smp_processor_id());
21989 + pax_open_kernel();
21990 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21991 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
21992 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
21993 + loadsegment(ds, __KERNEL_DS);
21994 + loadsegment(es, __KERNEL_DS);
21995 + loadsegment(ss, __KERNEL_DS);
21996 +#endif
21997 +#ifdef CONFIG_PAX_KERNEXEC
21998 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
21999 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22000 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22001 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22002 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22003 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22004 +#endif
22005 + pax_close_kernel();
22006 +#endif
22007 +
22008 + asm volatile("ljmpl *%0" : :
22009 "rm" (real_mode_header->machine_real_restart_asm),
22010 "a" (type));
22011 #else
22012 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22013 * try to force a triple fault and then cycle between hitting the keyboard
22014 * controller and doing that
22015 */
22016 -static void native_machine_emergency_restart(void)
22017 +static void __noreturn native_machine_emergency_restart(void)
22018 {
22019 int i;
22020 int attempt = 0;
22021 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22022 #endif
22023 }
22024
22025 -static void __machine_emergency_restart(int emergency)
22026 +static void __noreturn __machine_emergency_restart(int emergency)
22027 {
22028 reboot_emergency = emergency;
22029 machine_ops.emergency_restart();
22030 }
22031
22032 -static void native_machine_restart(char *__unused)
22033 +static void __noreturn native_machine_restart(char *__unused)
22034 {
22035 pr_notice("machine restart\n");
22036
22037 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22038 __machine_emergency_restart(0);
22039 }
22040
22041 -static void native_machine_halt(void)
22042 +static void __noreturn native_machine_halt(void)
22043 {
22044 /* Stop other cpus and apics */
22045 machine_shutdown();
22046 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
22047 stop_this_cpu(NULL);
22048 }
22049
22050 -static void native_machine_power_off(void)
22051 +static void __noreturn native_machine_power_off(void)
22052 {
22053 if (pm_power_off) {
22054 if (!reboot_force)
22055 @@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22056 }
22057 /* A fallback in case there is no PM info available */
22058 tboot_shutdown(TB_SHUTDOWN_HALT);
22059 + unreachable();
22060 }
22061
22062 -struct machine_ops machine_ops = {
22063 +struct machine_ops machine_ops __read_only = {
22064 .power_off = native_machine_power_off,
22065 .shutdown = native_machine_shutdown,
22066 .emergency_restart = native_machine_emergency_restart,
22067 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22068 index 7a6f3b3..bed145d7 100644
22069 --- a/arch/x86/kernel/relocate_kernel_64.S
22070 +++ b/arch/x86/kernel/relocate_kernel_64.S
22071 @@ -11,6 +11,7 @@
22072 #include <asm/kexec.h>
22073 #include <asm/processor-flags.h>
22074 #include <asm/pgtable_types.h>
22075 +#include <asm/alternative-asm.h>
22076
22077 /*
22078 * Must be relocatable PIC code callable as a C function
22079 @@ -160,13 +161,14 @@ identity_mapped:
22080 xorq %rbp, %rbp
22081 xorq %r8, %r8
22082 xorq %r9, %r9
22083 - xorq %r10, %r9
22084 + xorq %r10, %r10
22085 xorq %r11, %r11
22086 xorq %r12, %r12
22087 xorq %r13, %r13
22088 xorq %r14, %r14
22089 xorq %r15, %r15
22090
22091 + pax_force_retaddr 0, 1
22092 ret
22093
22094 1:
22095 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22096 index 8b24289..d37b58b 100644
22097 --- a/arch/x86/kernel/setup.c
22098 +++ b/arch/x86/kernel/setup.c
22099 @@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
22100
22101 switch (data->type) {
22102 case SETUP_E820_EXT:
22103 - parse_e820_ext(data);
22104 + parse_e820_ext((struct setup_data __force_kernel *)data);
22105 break;
22106 case SETUP_DTB:
22107 add_dtb(pa_data);
22108 @@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
22109 * area (640->1Mb) as ram even though it is not.
22110 * take them out.
22111 */
22112 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22113 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22114
22115 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22116 }
22117 @@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
22118
22119 if (!boot_params.hdr.root_flags)
22120 root_mountflags &= ~MS_RDONLY;
22121 - init_mm.start_code = (unsigned long) _text;
22122 - init_mm.end_code = (unsigned long) _etext;
22123 + init_mm.start_code = ktla_ktva((unsigned long) _text);
22124 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
22125 init_mm.end_data = (unsigned long) _edata;
22126 init_mm.brk = _brk_end;
22127
22128 - code_resource.start = virt_to_phys(_text);
22129 - code_resource.end = virt_to_phys(_etext)-1;
22130 - data_resource.start = virt_to_phys(_etext);
22131 + code_resource.start = virt_to_phys(ktla_ktva(_text));
22132 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
22133 + data_resource.start = virt_to_phys(_sdata);
22134 data_resource.end = virt_to_phys(_edata)-1;
22135 bss_resource.start = virt_to_phys(&__bss_start);
22136 bss_resource.end = virt_to_phys(&__bss_stop)-1;
22137 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22138 index 5cdff03..5810740 100644
22139 --- a/arch/x86/kernel/setup_percpu.c
22140 +++ b/arch/x86/kernel/setup_percpu.c
22141 @@ -21,19 +21,17 @@
22142 #include <asm/cpu.h>
22143 #include <asm/stackprotector.h>
22144
22145 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22146 +#ifdef CONFIG_SMP
22147 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22148 EXPORT_PER_CPU_SYMBOL(cpu_number);
22149 +#endif
22150
22151 -#ifdef CONFIG_X86_64
22152 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22153 -#else
22154 -#define BOOT_PERCPU_OFFSET 0
22155 -#endif
22156
22157 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22158 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22159
22160 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22161 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22162 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22163 };
22164 EXPORT_SYMBOL(__per_cpu_offset);
22165 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22166 {
22167 #ifdef CONFIG_X86_32
22168 struct desc_struct gdt;
22169 + unsigned long base = per_cpu_offset(cpu);
22170
22171 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22172 - 0x2 | DESCTYPE_S, 0x8);
22173 - gdt.s = 1;
22174 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22175 + 0x83 | DESCTYPE_S, 0xC);
22176 write_gdt_entry(get_cpu_gdt_table(cpu),
22177 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22178 #endif
22179 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22180 /* alrighty, percpu areas up and running */
22181 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22182 for_each_possible_cpu(cpu) {
22183 +#ifdef CONFIG_CC_STACKPROTECTOR
22184 +#ifdef CONFIG_X86_32
22185 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
22186 +#endif
22187 +#endif
22188 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22189 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22190 per_cpu(cpu_number, cpu) = cpu;
22191 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22192 */
22193 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22194 #endif
22195 +#ifdef CONFIG_CC_STACKPROTECTOR
22196 +#ifdef CONFIG_X86_32
22197 + if (!cpu)
22198 + per_cpu(stack_canary.canary, cpu) = canary;
22199 +#endif
22200 +#endif
22201 /*
22202 * Up to this point, the boot CPU has been using .init.data
22203 * area. Reload any changed state for the boot CPU.
22204 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22205 index d6bf1f3..3ffce5a 100644
22206 --- a/arch/x86/kernel/signal.c
22207 +++ b/arch/x86/kernel/signal.c
22208 @@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22209 * Align the stack pointer according to the i386 ABI,
22210 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22211 */
22212 - sp = ((sp + 4) & -16ul) - 4;
22213 + sp = ((sp - 12) & -16ul) - 4;
22214 #else /* !CONFIG_X86_32 */
22215 sp = round_down(sp, 16) - 8;
22216 #endif
22217 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22218 }
22219
22220 if (current->mm->context.vdso)
22221 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22222 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22223 else
22224 - restorer = &frame->retcode;
22225 + restorer = (void __user *)&frame->retcode;
22226 if (ka->sa.sa_flags & SA_RESTORER)
22227 restorer = ka->sa.sa_restorer;
22228
22229 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22230 * reasons and because gdb uses it as a signature to notice
22231 * signal handler stack frames.
22232 */
22233 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22234 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22235
22236 if (err)
22237 return -EFAULT;
22238 @@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22239 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22240
22241 /* Set up to return from userspace. */
22242 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22243 + if (current->mm->context.vdso)
22244 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22245 + else
22246 + restorer = (void __user *)&frame->retcode;
22247 if (ka->sa.sa_flags & SA_RESTORER)
22248 restorer = ka->sa.sa_restorer;
22249 put_user_ex(restorer, &frame->pretcode);
22250 @@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22251 * reasons and because gdb uses it as a signature to notice
22252 * signal handler stack frames.
22253 */
22254 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22255 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22256 } put_user_catch(err);
22257
22258 err |= copy_siginfo_to_user(&frame->info, info);
22259 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22260 index 48d2b7d..90d328a 100644
22261 --- a/arch/x86/kernel/smp.c
22262 +++ b/arch/x86/kernel/smp.c
22263 @@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22264
22265 __setup("nonmi_ipi", nonmi_ipi_setup);
22266
22267 -struct smp_ops smp_ops = {
22268 +struct smp_ops smp_ops __read_only = {
22269 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22270 .smp_prepare_cpus = native_smp_prepare_cpus,
22271 .smp_cpus_done = native_smp_cpus_done,
22272 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22273 index ed0fe38..87fc692 100644
22274 --- a/arch/x86/kernel/smpboot.c
22275 +++ b/arch/x86/kernel/smpboot.c
22276 @@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22277 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22278 (THREAD_SIZE + task_stack_page(idle))) - 1);
22279 per_cpu(current_task, cpu) = idle;
22280 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
22281
22282 #ifdef CONFIG_X86_32
22283 /* Stack for startup_32 can be just as for start_secondary onwards */
22284 @@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22285 #else
22286 clear_tsk_thread_flag(idle, TIF_FORK);
22287 initial_gs = per_cpu_offset(cpu);
22288 - per_cpu(kernel_stack, cpu) =
22289 - (unsigned long)task_stack_page(idle) -
22290 - KERNEL_STACK_OFFSET + THREAD_SIZE;
22291 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22292 #endif
22293 +
22294 + pax_open_kernel();
22295 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22296 + pax_close_kernel();
22297 +
22298 initial_code = (unsigned long)start_secondary;
22299 stack_start = idle->thread.sp;
22300
22301 @@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22302 /* the FPU context is blank, nobody can own it */
22303 __cpu_disable_lazy_restore(cpu);
22304
22305 +#ifdef CONFIG_PAX_PER_CPU_PGD
22306 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22307 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22308 + KERNEL_PGD_PTRS);
22309 +#endif
22310 +
22311 + /* the FPU context is blank, nobody can own it */
22312 + __cpu_disable_lazy_restore(cpu);
22313 +
22314 err = do_boot_cpu(apicid, cpu, tidle);
22315 if (err) {
22316 pr_debug("do_boot_cpu failed %d\n", err);
22317 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22318 index 9b4d51d..5d28b58 100644
22319 --- a/arch/x86/kernel/step.c
22320 +++ b/arch/x86/kernel/step.c
22321 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22322 struct desc_struct *desc;
22323 unsigned long base;
22324
22325 - seg &= ~7UL;
22326 + seg >>= 3;
22327
22328 mutex_lock(&child->mm->context.lock);
22329 - if (unlikely((seg >> 3) >= child->mm->context.size))
22330 + if (unlikely(seg >= child->mm->context.size))
22331 addr = -1L; /* bogus selector, access would fault */
22332 else {
22333 desc = child->mm->context.ldt + seg;
22334 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22335 addr += base;
22336 }
22337 mutex_unlock(&child->mm->context.lock);
22338 - }
22339 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22340 + addr = ktla_ktva(addr);
22341
22342 return addr;
22343 }
22344 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22345 unsigned char opcode[15];
22346 unsigned long addr = convert_ip_to_linear(child, regs);
22347
22348 + if (addr == -EINVAL)
22349 + return 0;
22350 +
22351 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22352 for (i = 0; i < copied; i++) {
22353 switch (opcode[i]) {
22354 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22355 new file mode 100644
22356 index 0000000..207bec6
22357 --- /dev/null
22358 +++ b/arch/x86/kernel/sys_i386_32.c
22359 @@ -0,0 +1,250 @@
22360 +/*
22361 + * This file contains various random system calls that
22362 + * have a non-standard calling sequence on the Linux/i386
22363 + * platform.
22364 + */
22365 +
22366 +#include <linux/errno.h>
22367 +#include <linux/sched.h>
22368 +#include <linux/mm.h>
22369 +#include <linux/fs.h>
22370 +#include <linux/smp.h>
22371 +#include <linux/sem.h>
22372 +#include <linux/msg.h>
22373 +#include <linux/shm.h>
22374 +#include <linux/stat.h>
22375 +#include <linux/syscalls.h>
22376 +#include <linux/mman.h>
22377 +#include <linux/file.h>
22378 +#include <linux/utsname.h>
22379 +#include <linux/ipc.h>
22380 +
22381 +#include <linux/uaccess.h>
22382 +#include <linux/unistd.h>
22383 +
22384 +#include <asm/syscalls.h>
22385 +
22386 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22387 +{
22388 + unsigned long pax_task_size = TASK_SIZE;
22389 +
22390 +#ifdef CONFIG_PAX_SEGMEXEC
22391 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22392 + pax_task_size = SEGMEXEC_TASK_SIZE;
22393 +#endif
22394 +
22395 + if (flags & MAP_FIXED)
22396 + if (len > pax_task_size || addr > pax_task_size - len)
22397 + return -EINVAL;
22398 +
22399 + return 0;
22400 +}
22401 +
22402 +unsigned long
22403 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
22404 + unsigned long len, unsigned long pgoff, unsigned long flags)
22405 +{
22406 + struct mm_struct *mm = current->mm;
22407 + struct vm_area_struct *vma;
22408 + unsigned long start_addr, pax_task_size = TASK_SIZE;
22409 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22410 +
22411 +#ifdef CONFIG_PAX_SEGMEXEC
22412 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22413 + pax_task_size = SEGMEXEC_TASK_SIZE;
22414 +#endif
22415 +
22416 + pax_task_size -= PAGE_SIZE;
22417 +
22418 + if (len > pax_task_size)
22419 + return -ENOMEM;
22420 +
22421 + if (flags & MAP_FIXED)
22422 + return addr;
22423 +
22424 +#ifdef CONFIG_PAX_RANDMMAP
22425 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22426 +#endif
22427 +
22428 + if (addr) {
22429 + addr = PAGE_ALIGN(addr);
22430 + if (pax_task_size - len >= addr) {
22431 + vma = find_vma(mm, addr);
22432 + if (check_heap_stack_gap(vma, addr, len, offset))
22433 + return addr;
22434 + }
22435 + }
22436 + if (len > mm->cached_hole_size) {
22437 + start_addr = addr = mm->free_area_cache;
22438 + } else {
22439 + start_addr = addr = mm->mmap_base;
22440 + mm->cached_hole_size = 0;
22441 + }
22442 +
22443 +#ifdef CONFIG_PAX_PAGEEXEC
22444 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22445 + start_addr = 0x00110000UL;
22446 +
22447 +#ifdef CONFIG_PAX_RANDMMAP
22448 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22449 + start_addr += mm->delta_mmap & 0x03FFF000UL;
22450 +#endif
22451 +
22452 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22453 + start_addr = addr = mm->mmap_base;
22454 + else
22455 + addr = start_addr;
22456 + }
22457 +#endif
22458 +
22459 +full_search:
22460 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22461 + /* At this point: (!vma || addr < vma->vm_end). */
22462 + if (pax_task_size - len < addr) {
22463 + /*
22464 + * Start a new search - just in case we missed
22465 + * some holes.
22466 + */
22467 + if (start_addr != mm->mmap_base) {
22468 + start_addr = addr = mm->mmap_base;
22469 + mm->cached_hole_size = 0;
22470 + goto full_search;
22471 + }
22472 + return -ENOMEM;
22473 + }
22474 + if (check_heap_stack_gap(vma, addr, len, offset))
22475 + break;
22476 + if (addr + mm->cached_hole_size < vma->vm_start)
22477 + mm->cached_hole_size = vma->vm_start - addr;
22478 + addr = vma->vm_end;
22479 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
22480 + start_addr = addr = mm->mmap_base;
22481 + mm->cached_hole_size = 0;
22482 + goto full_search;
22483 + }
22484 + }
22485 +
22486 + /*
22487 + * Remember the place where we stopped the search:
22488 + */
22489 + mm->free_area_cache = addr + len;
22490 + return addr;
22491 +}
22492 +
22493 +unsigned long
22494 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22495 + const unsigned long len, const unsigned long pgoff,
22496 + const unsigned long flags)
22497 +{
22498 + struct vm_area_struct *vma;
22499 + struct mm_struct *mm = current->mm;
22500 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22501 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22502 +
22503 +#ifdef CONFIG_PAX_SEGMEXEC
22504 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22505 + pax_task_size = SEGMEXEC_TASK_SIZE;
22506 +#endif
22507 +
22508 + pax_task_size -= PAGE_SIZE;
22509 +
22510 + /* requested length too big for entire address space */
22511 + if (len > pax_task_size)
22512 + return -ENOMEM;
22513 +
22514 + if (flags & MAP_FIXED)
22515 + return addr;
22516 +
22517 +#ifdef CONFIG_PAX_PAGEEXEC
22518 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22519 + goto bottomup;
22520 +#endif
22521 +
22522 +#ifdef CONFIG_PAX_RANDMMAP
22523 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22524 +#endif
22525 +
22526 + /* requesting a specific address */
22527 + if (addr) {
22528 + addr = PAGE_ALIGN(addr);
22529 + if (pax_task_size - len >= addr) {
22530 + vma = find_vma(mm, addr);
22531 + if (check_heap_stack_gap(vma, addr, len, offset))
22532 + return addr;
22533 + }
22534 + }
22535 +
22536 + /* check if free_area_cache is useful for us */
22537 + if (len <= mm->cached_hole_size) {
22538 + mm->cached_hole_size = 0;
22539 + mm->free_area_cache = mm->mmap_base;
22540 + }
22541 +
22542 + /* either no address requested or can't fit in requested address hole */
22543 + addr = mm->free_area_cache;
22544 +
22545 + /* make sure it can fit in the remaining address space */
22546 + if (addr > len) {
22547 + vma = find_vma(mm, addr-len);
22548 + if (check_heap_stack_gap(vma, addr - len, len, offset))
22549 + /* remember the address as a hint for next time */
22550 + return (mm->free_area_cache = addr-len);
22551 + }
22552 +
22553 + if (mm->mmap_base < len)
22554 + goto bottomup;
22555 +
22556 + addr = mm->mmap_base-len;
22557 +
22558 + do {
22559 + /*
22560 + * Lookup failure means no vma is above this address,
22561 + * else if new region fits below vma->vm_start,
22562 + * return with success:
22563 + */
22564 + vma = find_vma(mm, addr);
22565 + if (check_heap_stack_gap(vma, addr, len, offset))
22566 + /* remember the address as a hint for next time */
22567 + return (mm->free_area_cache = addr);
22568 +
22569 + /* remember the largest hole we saw so far */
22570 + if (addr + mm->cached_hole_size < vma->vm_start)
22571 + mm->cached_hole_size = vma->vm_start - addr;
22572 +
22573 + /* try just below the current vma->vm_start */
22574 + addr = skip_heap_stack_gap(vma, len, offset);
22575 + } while (!IS_ERR_VALUE(addr));
22576 +
22577 +bottomup:
22578 + /*
22579 + * A failed mmap() very likely causes application failure,
22580 + * so fall back to the bottom-up function here. This scenario
22581 + * can happen with large stack limits and large mmap()
22582 + * allocations.
22583 + */
22584 +
22585 +#ifdef CONFIG_PAX_SEGMEXEC
22586 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22587 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22588 + else
22589 +#endif
22590 +
22591 + mm->mmap_base = TASK_UNMAPPED_BASE;
22592 +
22593 +#ifdef CONFIG_PAX_RANDMMAP
22594 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22595 + mm->mmap_base += mm->delta_mmap;
22596 +#endif
22597 +
22598 + mm->free_area_cache = mm->mmap_base;
22599 + mm->cached_hole_size = ~0UL;
22600 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
22601 + /*
22602 + * Restore the topdown base:
22603 + */
22604 + mm->mmap_base = base;
22605 + mm->free_area_cache = base;
22606 + mm->cached_hole_size = ~0UL;
22607 +
22608 + return addr;
22609 +}
22610 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
22611 index 97ef74b..57a1882 100644
22612 --- a/arch/x86/kernel/sys_x86_64.c
22613 +++ b/arch/x86/kernel/sys_x86_64.c
22614 @@ -81,8 +81,8 @@ out:
22615 return error;
22616 }
22617
22618 -static void find_start_end(unsigned long flags, unsigned long *begin,
22619 - unsigned long *end)
22620 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
22621 + unsigned long *begin, unsigned long *end)
22622 {
22623 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
22624 unsigned long new_begin;
22625 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
22626 *begin = new_begin;
22627 }
22628 } else {
22629 - *begin = TASK_UNMAPPED_BASE;
22630 + *begin = mm->mmap_base;
22631 *end = TASK_SIZE;
22632 }
22633 }
22634 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
22635 struct vm_area_struct *vma;
22636 struct vm_unmapped_area_info info;
22637 unsigned long begin, end;
22638 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22639
22640 if (flags & MAP_FIXED)
22641 return addr;
22642
22643 - find_start_end(flags, &begin, &end);
22644 + find_start_end(mm, flags, &begin, &end);
22645
22646 if (len > end)
22647 return -ENOMEM;
22648
22649 +#ifdef CONFIG_PAX_RANDMMAP
22650 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22651 +#endif
22652 +
22653 if (addr) {
22654 addr = PAGE_ALIGN(addr);
22655 vma = find_vma(mm, addr);
22656 - if (end - len >= addr &&
22657 - (!vma || addr + len <= vma->vm_start))
22658 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
22659 return addr;
22660 }
22661
22662 @@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22663 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
22664 goto bottomup;
22665
22666 +#ifdef CONFIG_PAX_RANDMMAP
22667 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22668 +#endif
22669 +
22670 /* requesting a specific address */
22671 if (addr) {
22672 addr = PAGE_ALIGN(addr);
22673 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
22674 index f84fe00..f41d9f1 100644
22675 --- a/arch/x86/kernel/tboot.c
22676 +++ b/arch/x86/kernel/tboot.c
22677 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
22678
22679 void tboot_shutdown(u32 shutdown_type)
22680 {
22681 - void (*shutdown)(void);
22682 + void (* __noreturn shutdown)(void);
22683
22684 if (!tboot_enabled())
22685 return;
22686 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
22687
22688 switch_to_tboot_pt();
22689
22690 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
22691 + shutdown = (void *)tboot->shutdown_entry;
22692 shutdown();
22693
22694 /* should not reach here */
22695 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
22696 return 0;
22697 }
22698
22699 -static atomic_t ap_wfs_count;
22700 +static atomic_unchecked_t ap_wfs_count;
22701
22702 static int tboot_wait_for_aps(int num_aps)
22703 {
22704 @@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
22705 {
22706 switch (action) {
22707 case CPU_DYING:
22708 - atomic_inc(&ap_wfs_count);
22709 + atomic_inc_unchecked(&ap_wfs_count);
22710 if (num_online_cpus() == 1)
22711 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
22712 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
22713 return NOTIFY_BAD;
22714 break;
22715 }
22716 return NOTIFY_OK;
22717 }
22718
22719 -static struct notifier_block tboot_cpu_notifier __cpuinitdata =
22720 +static struct notifier_block tboot_cpu_notifier =
22721 {
22722 .notifier_call = tboot_cpu_callback,
22723 };
22724 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
22725
22726 tboot_create_trampoline();
22727
22728 - atomic_set(&ap_wfs_count, 0);
22729 + atomic_set_unchecked(&ap_wfs_count, 0);
22730 register_hotcpu_notifier(&tboot_cpu_notifier);
22731
22732 acpi_os_set_prepare_sleep(&tboot_sleep);
22733 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
22734 index 24d3c91..d06b473 100644
22735 --- a/arch/x86/kernel/time.c
22736 +++ b/arch/x86/kernel/time.c
22737 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
22738 {
22739 unsigned long pc = instruction_pointer(regs);
22740
22741 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
22742 + if (!user_mode(regs) && in_lock_functions(pc)) {
22743 #ifdef CONFIG_FRAME_POINTER
22744 - return *(unsigned long *)(regs->bp + sizeof(long));
22745 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
22746 #else
22747 unsigned long *sp =
22748 (unsigned long *)kernel_stack_pointer(regs);
22749 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
22750 * or above a saved flags. Eflags has bits 22-31 zero,
22751 * kernel addresses don't.
22752 */
22753 +
22754 +#ifdef CONFIG_PAX_KERNEXEC
22755 + return ktla_ktva(sp[0]);
22756 +#else
22757 if (sp[0] >> 22)
22758 return sp[0];
22759 if (sp[1] >> 22)
22760 return sp[1];
22761 #endif
22762 +
22763 +#endif
22764 }
22765 return pc;
22766 }
22767 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
22768 index 9d9d2f9..cad418a 100644
22769 --- a/arch/x86/kernel/tls.c
22770 +++ b/arch/x86/kernel/tls.c
22771 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
22772 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
22773 return -EINVAL;
22774
22775 +#ifdef CONFIG_PAX_SEGMEXEC
22776 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
22777 + return -EINVAL;
22778 +#endif
22779 +
22780 set_tls_desc(p, idx, &info, 1);
22781
22782 return 0;
22783 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
22784
22785 if (kbuf)
22786 info = kbuf;
22787 - else if (__copy_from_user(infobuf, ubuf, count))
22788 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
22789 return -EFAULT;
22790 else
22791 info = infobuf;
22792 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
22793 index ecffca1..95c4d13 100644
22794 --- a/arch/x86/kernel/traps.c
22795 +++ b/arch/x86/kernel/traps.c
22796 @@ -68,12 +68,6 @@
22797 #include <asm/setup.h>
22798
22799 asmlinkage int system_call(void);
22800 -
22801 -/*
22802 - * The IDT has to be page-aligned to simplify the Pentium
22803 - * F0 0F bug workaround.
22804 - */
22805 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
22806 #endif
22807
22808 DECLARE_BITMAP(used_vectors, NR_VECTORS);
22809 @@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
22810 }
22811
22812 static int __kprobes
22813 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22814 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
22815 struct pt_regs *regs, long error_code)
22816 {
22817 #ifdef CONFIG_X86_32
22818 - if (regs->flags & X86_VM_MASK) {
22819 + if (v8086_mode(regs)) {
22820 /*
22821 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
22822 * On nmi (interrupt 2), do_trap should not be called.
22823 @@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22824 return -1;
22825 }
22826 #endif
22827 - if (!user_mode(regs)) {
22828 + if (!user_mode_novm(regs)) {
22829 if (!fixup_exception(regs)) {
22830 tsk->thread.error_code = error_code;
22831 tsk->thread.trap_nr = trapnr;
22832 +
22833 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22834 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
22835 + str = "PAX: suspicious stack segment fault";
22836 +#endif
22837 +
22838 die(str, regs, error_code);
22839 }
22840 +
22841 +#ifdef CONFIG_PAX_REFCOUNT
22842 + if (trapnr == 4)
22843 + pax_report_refcount_overflow(regs);
22844 +#endif
22845 +
22846 return 0;
22847 }
22848
22849 @@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22850 }
22851
22852 static void __kprobes
22853 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22854 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
22855 long error_code, siginfo_t *info)
22856 {
22857 struct task_struct *tsk = current;
22858 @@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22859 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
22860 printk_ratelimit()) {
22861 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
22862 - tsk->comm, tsk->pid, str,
22863 + tsk->comm, task_pid_nr(tsk), str,
22864 regs->ip, regs->sp, error_code);
22865 print_vma_addr(" in ", regs->ip);
22866 pr_cont("\n");
22867 @@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
22868 conditional_sti(regs);
22869
22870 #ifdef CONFIG_X86_32
22871 - if (regs->flags & X86_VM_MASK) {
22872 + if (v8086_mode(regs)) {
22873 local_irq_enable();
22874 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
22875 goto exit;
22876 @@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
22877 #endif
22878
22879 tsk = current;
22880 - if (!user_mode(regs)) {
22881 + if (!user_mode_novm(regs)) {
22882 if (fixup_exception(regs))
22883 goto exit;
22884
22885 tsk->thread.error_code = error_code;
22886 tsk->thread.trap_nr = X86_TRAP_GP;
22887 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
22888 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
22889 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
22890 +
22891 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22892 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
22893 + die("PAX: suspicious general protection fault", regs, error_code);
22894 + else
22895 +#endif
22896 +
22897 die("general protection fault", regs, error_code);
22898 + }
22899 goto exit;
22900 }
22901
22902 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22903 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
22904 + struct mm_struct *mm = tsk->mm;
22905 + unsigned long limit;
22906 +
22907 + down_write(&mm->mmap_sem);
22908 + limit = mm->context.user_cs_limit;
22909 + if (limit < TASK_SIZE) {
22910 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
22911 + up_write(&mm->mmap_sem);
22912 + return;
22913 + }
22914 + up_write(&mm->mmap_sem);
22915 + }
22916 +#endif
22917 +
22918 tsk->thread.error_code = error_code;
22919 tsk->thread.trap_nr = X86_TRAP_GP;
22920
22921 @@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22922 /* It's safe to allow irq's after DR6 has been saved */
22923 preempt_conditional_sti(regs);
22924
22925 - if (regs->flags & X86_VM_MASK) {
22926 + if (v8086_mode(regs)) {
22927 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
22928 X86_TRAP_DB);
22929 preempt_conditional_cli(regs);
22930 @@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22931 * We already checked v86 mode above, so we can check for kernel mode
22932 * by just checking the CPL of CS.
22933 */
22934 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
22935 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
22936 tsk->thread.debugreg6 &= ~DR_STEP;
22937 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
22938 regs->flags &= ~X86_EFLAGS_TF;
22939 @@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
22940 return;
22941 conditional_sti(regs);
22942
22943 - if (!user_mode_vm(regs))
22944 + if (!user_mode(regs))
22945 {
22946 if (!fixup_exception(regs)) {
22947 task->thread.error_code = error_code;
22948 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
22949 index c71025b..b117501 100644
22950 --- a/arch/x86/kernel/uprobes.c
22951 +++ b/arch/x86/kernel/uprobes.c
22952 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
22953 int ret = NOTIFY_DONE;
22954
22955 /* We are only interested in userspace traps */
22956 - if (regs && !user_mode_vm(regs))
22957 + if (regs && !user_mode(regs))
22958 return NOTIFY_DONE;
22959
22960 switch (val) {
22961 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
22962 index b9242ba..50c5edd 100644
22963 --- a/arch/x86/kernel/verify_cpu.S
22964 +++ b/arch/x86/kernel/verify_cpu.S
22965 @@ -20,6 +20,7 @@
22966 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
22967 * arch/x86/kernel/trampoline_64.S: secondary processor verification
22968 * arch/x86/kernel/head_32.S: processor startup
22969 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
22970 *
22971 * verify_cpu, returns the status of longmode and SSE in register %eax.
22972 * 0: Success 1: Failure
22973 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
22974 index 1dfe69c..a3df6f6 100644
22975 --- a/arch/x86/kernel/vm86_32.c
22976 +++ b/arch/x86/kernel/vm86_32.c
22977 @@ -43,6 +43,7 @@
22978 #include <linux/ptrace.h>
22979 #include <linux/audit.h>
22980 #include <linux/stddef.h>
22981 +#include <linux/grsecurity.h>
22982
22983 #include <asm/uaccess.h>
22984 #include <asm/io.h>
22985 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
22986 do_exit(SIGSEGV);
22987 }
22988
22989 - tss = &per_cpu(init_tss, get_cpu());
22990 + tss = init_tss + get_cpu();
22991 current->thread.sp0 = current->thread.saved_sp0;
22992 current->thread.sysenter_cs = __KERNEL_CS;
22993 load_sp0(tss, &current->thread);
22994 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
22995 struct task_struct *tsk;
22996 int tmp, ret = -EPERM;
22997
22998 +#ifdef CONFIG_GRKERNSEC_VM86
22999 + if (!capable(CAP_SYS_RAWIO)) {
23000 + gr_handle_vm86();
23001 + goto out;
23002 + }
23003 +#endif
23004 +
23005 tsk = current;
23006 if (tsk->thread.saved_sp0)
23007 goto out;
23008 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
23009 int tmp, ret;
23010 struct vm86plus_struct __user *v86;
23011
23012 +#ifdef CONFIG_GRKERNSEC_VM86
23013 + if (!capable(CAP_SYS_RAWIO)) {
23014 + gr_handle_vm86();
23015 + ret = -EPERM;
23016 + goto out;
23017 + }
23018 +#endif
23019 +
23020 tsk = current;
23021 switch (cmd) {
23022 case VM86_REQUEST_IRQ:
23023 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23024 tsk->thread.saved_fs = info->regs32->fs;
23025 tsk->thread.saved_gs = get_user_gs(info->regs32);
23026
23027 - tss = &per_cpu(init_tss, get_cpu());
23028 + tss = init_tss + get_cpu();
23029 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23030 if (cpu_has_sep)
23031 tsk->thread.sysenter_cs = 0;
23032 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23033 goto cannot_handle;
23034 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23035 goto cannot_handle;
23036 - intr_ptr = (unsigned long __user *) (i << 2);
23037 + intr_ptr = (__force unsigned long __user *) (i << 2);
23038 if (get_user(segoffs, intr_ptr))
23039 goto cannot_handle;
23040 if ((segoffs >> 16) == BIOSSEG)
23041 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23042 index 22a1530..8fbaaad 100644
23043 --- a/arch/x86/kernel/vmlinux.lds.S
23044 +++ b/arch/x86/kernel/vmlinux.lds.S
23045 @@ -26,6 +26,13 @@
23046 #include <asm/page_types.h>
23047 #include <asm/cache.h>
23048 #include <asm/boot.h>
23049 +#include <asm/segment.h>
23050 +
23051 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23052 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23053 +#else
23054 +#define __KERNEL_TEXT_OFFSET 0
23055 +#endif
23056
23057 #undef i386 /* in case the preprocessor is a 32bit one */
23058
23059 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23060
23061 PHDRS {
23062 text PT_LOAD FLAGS(5); /* R_E */
23063 +#ifdef CONFIG_X86_32
23064 + module PT_LOAD FLAGS(5); /* R_E */
23065 +#endif
23066 +#ifdef CONFIG_XEN
23067 + rodata PT_LOAD FLAGS(5); /* R_E */
23068 +#else
23069 + rodata PT_LOAD FLAGS(4); /* R__ */
23070 +#endif
23071 data PT_LOAD FLAGS(6); /* RW_ */
23072 -#ifdef CONFIG_X86_64
23073 + init.begin PT_LOAD FLAGS(6); /* RW_ */
23074 #ifdef CONFIG_SMP
23075 percpu PT_LOAD FLAGS(6); /* RW_ */
23076 #endif
23077 + text.init PT_LOAD FLAGS(5); /* R_E */
23078 + text.exit PT_LOAD FLAGS(5); /* R_E */
23079 init PT_LOAD FLAGS(7); /* RWE */
23080 -#endif
23081 note PT_NOTE FLAGS(0); /* ___ */
23082 }
23083
23084 SECTIONS
23085 {
23086 #ifdef CONFIG_X86_32
23087 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23088 - phys_startup_32 = startup_32 - LOAD_OFFSET;
23089 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23090 #else
23091 - . = __START_KERNEL;
23092 - phys_startup_64 = startup_64 - LOAD_OFFSET;
23093 + . = __START_KERNEL;
23094 #endif
23095
23096 /* Text and read-only data */
23097 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
23098 - _text = .;
23099 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23100 /* bootstrapping code */
23101 +#ifdef CONFIG_X86_32
23102 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23103 +#else
23104 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23105 +#endif
23106 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23107 + _text = .;
23108 HEAD_TEXT
23109 #ifdef CONFIG_X86_32
23110 . = ALIGN(PAGE_SIZE);
23111 @@ -108,13 +128,48 @@ SECTIONS
23112 IRQENTRY_TEXT
23113 *(.fixup)
23114 *(.gnu.warning)
23115 - /* End of text section */
23116 - _etext = .;
23117 } :text = 0x9090
23118
23119 - NOTES :text :note
23120 + . += __KERNEL_TEXT_OFFSET;
23121
23122 - EXCEPTION_TABLE(16) :text = 0x9090
23123 +#ifdef CONFIG_X86_32
23124 + . = ALIGN(PAGE_SIZE);
23125 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23126 +
23127 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
23128 + MODULES_EXEC_VADDR = .;
23129 + BYTE(0)
23130 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23131 + . = ALIGN(HPAGE_SIZE) - 1;
23132 + MODULES_EXEC_END = .;
23133 +#endif
23134 +
23135 + } :module
23136 +#endif
23137 +
23138 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23139 + /* End of text section */
23140 + BYTE(0)
23141 + _etext = . - __KERNEL_TEXT_OFFSET;
23142 + }
23143 +
23144 +#ifdef CONFIG_X86_32
23145 + . = ALIGN(PAGE_SIZE);
23146 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23147 + *(.idt)
23148 + . = ALIGN(PAGE_SIZE);
23149 + *(.empty_zero_page)
23150 + *(.initial_pg_fixmap)
23151 + *(.initial_pg_pmd)
23152 + *(.initial_page_table)
23153 + *(.swapper_pg_dir)
23154 + } :rodata
23155 +#endif
23156 +
23157 + . = ALIGN(PAGE_SIZE);
23158 + NOTES :rodata :note
23159 +
23160 + EXCEPTION_TABLE(16) :rodata
23161
23162 #if defined(CONFIG_DEBUG_RODATA)
23163 /* .text should occupy whole number of pages */
23164 @@ -126,16 +181,20 @@ SECTIONS
23165
23166 /* Data */
23167 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23168 +
23169 +#ifdef CONFIG_PAX_KERNEXEC
23170 + . = ALIGN(HPAGE_SIZE);
23171 +#else
23172 + . = ALIGN(PAGE_SIZE);
23173 +#endif
23174 +
23175 /* Start of data section */
23176 _sdata = .;
23177
23178 /* init_task */
23179 INIT_TASK_DATA(THREAD_SIZE)
23180
23181 -#ifdef CONFIG_X86_32
23182 - /* 32 bit has nosave before _edata */
23183 NOSAVE_DATA
23184 -#endif
23185
23186 PAGE_ALIGNED_DATA(PAGE_SIZE)
23187
23188 @@ -176,12 +235,19 @@ SECTIONS
23189 #endif /* CONFIG_X86_64 */
23190
23191 /* Init code and data - will be freed after init */
23192 - . = ALIGN(PAGE_SIZE);
23193 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23194 + BYTE(0)
23195 +
23196 +#ifdef CONFIG_PAX_KERNEXEC
23197 + . = ALIGN(HPAGE_SIZE);
23198 +#else
23199 + . = ALIGN(PAGE_SIZE);
23200 +#endif
23201 +
23202 __init_begin = .; /* paired with __init_end */
23203 - }
23204 + } :init.begin
23205
23206 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23207 +#ifdef CONFIG_SMP
23208 /*
23209 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23210 * output PHDR, so the next output section - .init.text - should
23211 @@ -190,12 +256,27 @@ SECTIONS
23212 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23213 #endif
23214
23215 - INIT_TEXT_SECTION(PAGE_SIZE)
23216 -#ifdef CONFIG_X86_64
23217 - :init
23218 -#endif
23219 + . = ALIGN(PAGE_SIZE);
23220 + init_begin = .;
23221 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23222 + VMLINUX_SYMBOL(_sinittext) = .;
23223 + INIT_TEXT
23224 + VMLINUX_SYMBOL(_einittext) = .;
23225 + . = ALIGN(PAGE_SIZE);
23226 + } :text.init
23227
23228 - INIT_DATA_SECTION(16)
23229 + /*
23230 + * .exit.text is discard at runtime, not link time, to deal with
23231 + * references from .altinstructions and .eh_frame
23232 + */
23233 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23234 + EXIT_TEXT
23235 + . = ALIGN(16);
23236 + } :text.exit
23237 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23238 +
23239 + . = ALIGN(PAGE_SIZE);
23240 + INIT_DATA_SECTION(16) :init
23241
23242 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23243 __x86_cpu_dev_start = .;
23244 @@ -257,19 +338,12 @@ SECTIONS
23245 }
23246
23247 . = ALIGN(8);
23248 - /*
23249 - * .exit.text is discard at runtime, not link time, to deal with
23250 - * references from .altinstructions and .eh_frame
23251 - */
23252 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23253 - EXIT_TEXT
23254 - }
23255
23256 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23257 EXIT_DATA
23258 }
23259
23260 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23261 +#ifndef CONFIG_SMP
23262 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23263 #endif
23264
23265 @@ -288,16 +362,10 @@ SECTIONS
23266 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23267 __smp_locks = .;
23268 *(.smp_locks)
23269 - . = ALIGN(PAGE_SIZE);
23270 __smp_locks_end = .;
23271 + . = ALIGN(PAGE_SIZE);
23272 }
23273
23274 -#ifdef CONFIG_X86_64
23275 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23276 - NOSAVE_DATA
23277 - }
23278 -#endif
23279 -
23280 /* BSS */
23281 . = ALIGN(PAGE_SIZE);
23282 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23283 @@ -313,6 +381,7 @@ SECTIONS
23284 __brk_base = .;
23285 . += 64 * 1024; /* 64k alignment slop space */
23286 *(.brk_reservation) /* areas brk users have reserved */
23287 + . = ALIGN(HPAGE_SIZE);
23288 __brk_limit = .;
23289 }
23290
23291 @@ -339,13 +408,12 @@ SECTIONS
23292 * for the boot processor.
23293 */
23294 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23295 -INIT_PER_CPU(gdt_page);
23296 INIT_PER_CPU(irq_stack_union);
23297
23298 /*
23299 * Build-time check on the image size:
23300 */
23301 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23302 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23303 "kernel image bigger than KERNEL_IMAGE_SIZE");
23304
23305 #ifdef CONFIG_SMP
23306 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23307 index 9a907a6..f83f921 100644
23308 --- a/arch/x86/kernel/vsyscall_64.c
23309 +++ b/arch/x86/kernel/vsyscall_64.c
23310 @@ -56,15 +56,13 @@
23311 DEFINE_VVAR(int, vgetcpu_mode);
23312 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23313
23314 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23315 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23316
23317 static int __init vsyscall_setup(char *str)
23318 {
23319 if (str) {
23320 if (!strcmp("emulate", str))
23321 vsyscall_mode = EMULATE;
23322 - else if (!strcmp("native", str))
23323 - vsyscall_mode = NATIVE;
23324 else if (!strcmp("none", str))
23325 vsyscall_mode = NONE;
23326 else
23327 @@ -323,8 +321,7 @@ do_ret:
23328 return true;
23329
23330 sigsegv:
23331 - force_sig(SIGSEGV, current);
23332 - return true;
23333 + do_group_exit(SIGKILL);
23334 }
23335
23336 /*
23337 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23338 extern char __vvar_page;
23339 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23340
23341 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23342 - vsyscall_mode == NATIVE
23343 - ? PAGE_KERNEL_VSYSCALL
23344 - : PAGE_KERNEL_VVAR);
23345 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23346 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23347 (unsigned long)VSYSCALL_START);
23348
23349 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23350 index 1330dd1..d220b99 100644
23351 --- a/arch/x86/kernel/x8664_ksyms_64.c
23352 +++ b/arch/x86/kernel/x8664_ksyms_64.c
23353 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23354 EXPORT_SYMBOL(copy_user_generic_unrolled);
23355 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23356 EXPORT_SYMBOL(__copy_user_nocache);
23357 -EXPORT_SYMBOL(_copy_from_user);
23358 -EXPORT_SYMBOL(_copy_to_user);
23359
23360 EXPORT_SYMBOL(copy_page);
23361 EXPORT_SYMBOL(clear_page);
23362 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23363 index 7a3d075..6cb373d 100644
23364 --- a/arch/x86/kernel/x86_init.c
23365 +++ b/arch/x86/kernel/x86_init.c
23366 @@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
23367 },
23368 };
23369
23370 -struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23371 +struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23372 .early_percpu_clock_init = x86_init_noop,
23373 .setup_percpu_clockev = setup_secondary_APIC_clock,
23374 };
23375 @@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23376 static void default_nmi_init(void) { };
23377 static int default_i8042_detect(void) { return 1; };
23378
23379 -struct x86_platform_ops x86_platform = {
23380 +struct x86_platform_ops x86_platform __read_only = {
23381 .calibrate_tsc = native_calibrate_tsc,
23382 .get_wallclock = mach_get_cmos_time,
23383 .set_wallclock = mach_set_rtc_mmss,
23384 @@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
23385 };
23386
23387 EXPORT_SYMBOL_GPL(x86_platform);
23388 -struct x86_msi_ops x86_msi = {
23389 +struct x86_msi_ops x86_msi __read_only = {
23390 .setup_msi_irqs = native_setup_msi_irqs,
23391 .teardown_msi_irq = native_teardown_msi_irq,
23392 .teardown_msi_irqs = default_teardown_msi_irqs,
23393 .restore_msi_irqs = default_restore_msi_irqs,
23394 };
23395
23396 -struct x86_io_apic_ops x86_io_apic_ops = {
23397 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23398 .init = native_io_apic_init_mappings,
23399 .read = native_io_apic_read,
23400 .write = native_io_apic_write,
23401 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23402 index ada87a3..afea76d 100644
23403 --- a/arch/x86/kernel/xsave.c
23404 +++ b/arch/x86/kernel/xsave.c
23405 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23406 {
23407 int err;
23408
23409 + buf = (struct xsave_struct __user *)____m(buf);
23410 if (use_xsave())
23411 err = xsave_user(buf);
23412 else if (use_fxsr())
23413 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23414 */
23415 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23416 {
23417 + buf = (void __user *)____m(buf);
23418 if (use_xsave()) {
23419 if ((unsigned long)buf % 64 || fx_only) {
23420 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23421 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23422 index a20ecb5..d0e2194 100644
23423 --- a/arch/x86/kvm/cpuid.c
23424 +++ b/arch/x86/kvm/cpuid.c
23425 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23426 struct kvm_cpuid2 *cpuid,
23427 struct kvm_cpuid_entry2 __user *entries)
23428 {
23429 - int r;
23430 + int r, i;
23431
23432 r = -E2BIG;
23433 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23434 goto out;
23435 r = -EFAULT;
23436 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23437 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23438 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23439 goto out;
23440 + for (i = 0; i < cpuid->nent; ++i) {
23441 + struct kvm_cpuid_entry2 cpuid_entry;
23442 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23443 + goto out;
23444 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
23445 + }
23446 vcpu->arch.cpuid_nent = cpuid->nent;
23447 kvm_apic_set_version(vcpu);
23448 kvm_x86_ops->cpuid_update(vcpu);
23449 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23450 struct kvm_cpuid2 *cpuid,
23451 struct kvm_cpuid_entry2 __user *entries)
23452 {
23453 - int r;
23454 + int r, i;
23455
23456 r = -E2BIG;
23457 if (cpuid->nent < vcpu->arch.cpuid_nent)
23458 goto out;
23459 r = -EFAULT;
23460 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23461 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23462 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23463 goto out;
23464 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23465 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23466 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23467 + goto out;
23468 + }
23469 return 0;
23470
23471 out:
23472 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23473 index a27e763..54bfe43 100644
23474 --- a/arch/x86/kvm/emulate.c
23475 +++ b/arch/x86/kvm/emulate.c
23476 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23477
23478 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23479 do { \
23480 + unsigned long _tmp; \
23481 __asm__ __volatile__ ( \
23482 _PRE_EFLAGS("0", "4", "2") \
23483 _op _suffix " %"_x"3,%1; " \
23484 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23485 /* Raw emulation: instruction has two explicit operands. */
23486 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23487 do { \
23488 - unsigned long _tmp; \
23489 - \
23490 switch ((ctxt)->dst.bytes) { \
23491 case 2: \
23492 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23493 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23494
23495 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23496 do { \
23497 - unsigned long _tmp; \
23498 switch ((ctxt)->dst.bytes) { \
23499 case 1: \
23500 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
23501 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
23502 index 9392f52..0e56d77 100644
23503 --- a/arch/x86/kvm/lapic.c
23504 +++ b/arch/x86/kvm/lapic.c
23505 @@ -55,7 +55,7 @@
23506 #define APIC_BUS_CYCLE_NS 1
23507
23508 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
23509 -#define apic_debug(fmt, arg...)
23510 +#define apic_debug(fmt, arg...) do {} while (0)
23511
23512 #define APIC_LVT_NUM 6
23513 /* 14 is the version for Xeon and Pentium 8.4.8*/
23514 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
23515 index 891eb6d..e027900 100644
23516 --- a/arch/x86/kvm/paging_tmpl.h
23517 +++ b/arch/x86/kvm/paging_tmpl.h
23518 @@ -208,7 +208,7 @@ retry_walk:
23519 if (unlikely(kvm_is_error_hva(host_addr)))
23520 goto error;
23521
23522 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
23523 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
23524 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
23525 goto error;
23526 walker->ptep_user[walker->level - 1] = ptep_user;
23527 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
23528 index d29d3cd..ec9d522 100644
23529 --- a/arch/x86/kvm/svm.c
23530 +++ b/arch/x86/kvm/svm.c
23531 @@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
23532 int cpu = raw_smp_processor_id();
23533
23534 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
23535 +
23536 + pax_open_kernel();
23537 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
23538 + pax_close_kernel();
23539 +
23540 load_TR_desc();
23541 }
23542
23543 @@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
23544 #endif
23545 #endif
23546
23547 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23548 + __set_fs(current_thread_info()->addr_limit);
23549 +#endif
23550 +
23551 reload_tss(vcpu);
23552
23553 local_irq_disable();
23554 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
23555 index 9120ae1..238abc0 100644
23556 --- a/arch/x86/kvm/vmx.c
23557 +++ b/arch/x86/kvm/vmx.c
23558 @@ -1370,7 +1370,11 @@ static void reload_tss(void)
23559 struct desc_struct *descs;
23560
23561 descs = (void *)gdt->address;
23562 +
23563 + pax_open_kernel();
23564 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
23565 + pax_close_kernel();
23566 +
23567 load_TR_desc();
23568 }
23569
23570 @@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
23571 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
23572 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
23573
23574 +#ifdef CONFIG_PAX_PER_CPU_PGD
23575 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23576 +#endif
23577 +
23578 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23579 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
23580 vmx->loaded_vmcs->cpu = cpu;
23581 @@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
23582 if (!cpu_has_vmx_flexpriority())
23583 flexpriority_enabled = 0;
23584
23585 - if (!cpu_has_vmx_tpr_shadow())
23586 - kvm_x86_ops->update_cr8_intercept = NULL;
23587 + if (!cpu_has_vmx_tpr_shadow()) {
23588 + pax_open_kernel();
23589 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
23590 + pax_close_kernel();
23591 + }
23592
23593 if (enable_ept && !cpu_has_vmx_ept_2m_page())
23594 kvm_disable_largepages();
23595 @@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
23596
23597 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
23598 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
23599 +
23600 +#ifndef CONFIG_PAX_PER_CPU_PGD
23601 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23602 +#endif
23603
23604 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
23605 #ifdef CONFIG_X86_64
23606 @@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
23607 native_store_idt(&dt);
23608 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
23609
23610 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
23611 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
23612
23613 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
23614 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
23615 @@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23616 "jmp 2f \n\t"
23617 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
23618 "2: "
23619 +
23620 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23621 + "ljmp %[cs],$3f\n\t"
23622 + "3: "
23623 +#endif
23624 +
23625 /* Save guest registers, load host registers, keep flags */
23626 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
23627 "pop %0 \n\t"
23628 @@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23629 #endif
23630 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
23631 [wordsize]"i"(sizeof(ulong))
23632 +
23633 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23634 + ,[cs]"i"(__KERNEL_CS)
23635 +#endif
23636 +
23637 : "cc", "memory"
23638 #ifdef CONFIG_X86_64
23639 , "rax", "rbx", "rdi", "rsi"
23640 @@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23641 if (debugctlmsr)
23642 update_debugctlmsr(debugctlmsr);
23643
23644 -#ifndef CONFIG_X86_64
23645 +#ifdef CONFIG_X86_32
23646 /*
23647 * The sysexit path does not restore ds/es, so we must set them to
23648 * a reasonable value ourselves.
23649 @@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23650 * may be executed in interrupt context, which saves and restore segments
23651 * around it, nullifying its effect.
23652 */
23653 - loadsegment(ds, __USER_DS);
23654 - loadsegment(es, __USER_DS);
23655 + loadsegment(ds, __KERNEL_DS);
23656 + loadsegment(es, __KERNEL_DS);
23657 + loadsegment(ss, __KERNEL_DS);
23658 +
23659 +#ifdef CONFIG_PAX_KERNEXEC
23660 + loadsegment(fs, __KERNEL_PERCPU);
23661 +#endif
23662 +
23663 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23664 + __set_fs(current_thread_info()->addr_limit);
23665 +#endif
23666 +
23667 #endif
23668
23669 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
23670 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
23671 index c243b81..9eb193f 100644
23672 --- a/arch/x86/kvm/x86.c
23673 +++ b/arch/x86/kvm/x86.c
23674 @@ -1692,8 +1692,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
23675 {
23676 struct kvm *kvm = vcpu->kvm;
23677 int lm = is_long_mode(vcpu);
23678 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23679 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23680 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23681 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23682 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
23683 : kvm->arch.xen_hvm_config.blob_size_32;
23684 u32 page_num = data & ~PAGE_MASK;
23685 @@ -2571,6 +2571,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
23686 if (n < msr_list.nmsrs)
23687 goto out;
23688 r = -EFAULT;
23689 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
23690 + goto out;
23691 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
23692 num_msrs_to_save * sizeof(u32)))
23693 goto out;
23694 @@ -2700,7 +2702,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
23695 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
23696 struct kvm_interrupt *irq)
23697 {
23698 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
23699 + if (irq->irq >= KVM_NR_INTERRUPTS)
23700 return -EINVAL;
23701 if (irqchip_in_kernel(vcpu->kvm))
23702 return -ENXIO;
23703 @@ -5213,7 +5215,7 @@ static struct notifier_block pvclock_gtod_notifier = {
23704 };
23705 #endif
23706
23707 -int kvm_arch_init(void *opaque)
23708 +int kvm_arch_init(const void *opaque)
23709 {
23710 int r;
23711 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
23712 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
23713 index df4176c..23ce092 100644
23714 --- a/arch/x86/lguest/boot.c
23715 +++ b/arch/x86/lguest/boot.c
23716 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
23717 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
23718 * Launcher to reboot us.
23719 */
23720 -static void lguest_restart(char *reason)
23721 +static __noreturn void lguest_restart(char *reason)
23722 {
23723 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
23724 + BUG();
23725 }
23726
23727 /*G:050
23728 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
23729 index 00933d5..3a64af9 100644
23730 --- a/arch/x86/lib/atomic64_386_32.S
23731 +++ b/arch/x86/lib/atomic64_386_32.S
23732 @@ -48,6 +48,10 @@ BEGIN(read)
23733 movl (v), %eax
23734 movl 4(v), %edx
23735 RET_ENDP
23736 +BEGIN(read_unchecked)
23737 + movl (v), %eax
23738 + movl 4(v), %edx
23739 +RET_ENDP
23740 #undef v
23741
23742 #define v %esi
23743 @@ -55,6 +59,10 @@ BEGIN(set)
23744 movl %ebx, (v)
23745 movl %ecx, 4(v)
23746 RET_ENDP
23747 +BEGIN(set_unchecked)
23748 + movl %ebx, (v)
23749 + movl %ecx, 4(v)
23750 +RET_ENDP
23751 #undef v
23752
23753 #define v %esi
23754 @@ -70,6 +78,20 @@ RET_ENDP
23755 BEGIN(add)
23756 addl %eax, (v)
23757 adcl %edx, 4(v)
23758 +
23759 +#ifdef CONFIG_PAX_REFCOUNT
23760 + jno 0f
23761 + subl %eax, (v)
23762 + sbbl %edx, 4(v)
23763 + int $4
23764 +0:
23765 + _ASM_EXTABLE(0b, 0b)
23766 +#endif
23767 +
23768 +RET_ENDP
23769 +BEGIN(add_unchecked)
23770 + addl %eax, (v)
23771 + adcl %edx, 4(v)
23772 RET_ENDP
23773 #undef v
23774
23775 @@ -77,6 +99,24 @@ RET_ENDP
23776 BEGIN(add_return)
23777 addl (v), %eax
23778 adcl 4(v), %edx
23779 +
23780 +#ifdef CONFIG_PAX_REFCOUNT
23781 + into
23782 +1234:
23783 + _ASM_EXTABLE(1234b, 2f)
23784 +#endif
23785 +
23786 + movl %eax, (v)
23787 + movl %edx, 4(v)
23788 +
23789 +#ifdef CONFIG_PAX_REFCOUNT
23790 +2:
23791 +#endif
23792 +
23793 +RET_ENDP
23794 +BEGIN(add_return_unchecked)
23795 + addl (v), %eax
23796 + adcl 4(v), %edx
23797 movl %eax, (v)
23798 movl %edx, 4(v)
23799 RET_ENDP
23800 @@ -86,6 +126,20 @@ RET_ENDP
23801 BEGIN(sub)
23802 subl %eax, (v)
23803 sbbl %edx, 4(v)
23804 +
23805 +#ifdef CONFIG_PAX_REFCOUNT
23806 + jno 0f
23807 + addl %eax, (v)
23808 + adcl %edx, 4(v)
23809 + int $4
23810 +0:
23811 + _ASM_EXTABLE(0b, 0b)
23812 +#endif
23813 +
23814 +RET_ENDP
23815 +BEGIN(sub_unchecked)
23816 + subl %eax, (v)
23817 + sbbl %edx, 4(v)
23818 RET_ENDP
23819 #undef v
23820
23821 @@ -96,6 +150,27 @@ BEGIN(sub_return)
23822 sbbl $0, %edx
23823 addl (v), %eax
23824 adcl 4(v), %edx
23825 +
23826 +#ifdef CONFIG_PAX_REFCOUNT
23827 + into
23828 +1234:
23829 + _ASM_EXTABLE(1234b, 2f)
23830 +#endif
23831 +
23832 + movl %eax, (v)
23833 + movl %edx, 4(v)
23834 +
23835 +#ifdef CONFIG_PAX_REFCOUNT
23836 +2:
23837 +#endif
23838 +
23839 +RET_ENDP
23840 +BEGIN(sub_return_unchecked)
23841 + negl %edx
23842 + negl %eax
23843 + sbbl $0, %edx
23844 + addl (v), %eax
23845 + adcl 4(v), %edx
23846 movl %eax, (v)
23847 movl %edx, 4(v)
23848 RET_ENDP
23849 @@ -105,6 +180,20 @@ RET_ENDP
23850 BEGIN(inc)
23851 addl $1, (v)
23852 adcl $0, 4(v)
23853 +
23854 +#ifdef CONFIG_PAX_REFCOUNT
23855 + jno 0f
23856 + subl $1, (v)
23857 + sbbl $0, 4(v)
23858 + int $4
23859 +0:
23860 + _ASM_EXTABLE(0b, 0b)
23861 +#endif
23862 +
23863 +RET_ENDP
23864 +BEGIN(inc_unchecked)
23865 + addl $1, (v)
23866 + adcl $0, 4(v)
23867 RET_ENDP
23868 #undef v
23869
23870 @@ -114,6 +203,26 @@ BEGIN(inc_return)
23871 movl 4(v), %edx
23872 addl $1, %eax
23873 adcl $0, %edx
23874 +
23875 +#ifdef CONFIG_PAX_REFCOUNT
23876 + into
23877 +1234:
23878 + _ASM_EXTABLE(1234b, 2f)
23879 +#endif
23880 +
23881 + movl %eax, (v)
23882 + movl %edx, 4(v)
23883 +
23884 +#ifdef CONFIG_PAX_REFCOUNT
23885 +2:
23886 +#endif
23887 +
23888 +RET_ENDP
23889 +BEGIN(inc_return_unchecked)
23890 + movl (v), %eax
23891 + movl 4(v), %edx
23892 + addl $1, %eax
23893 + adcl $0, %edx
23894 movl %eax, (v)
23895 movl %edx, 4(v)
23896 RET_ENDP
23897 @@ -123,6 +232,20 @@ RET_ENDP
23898 BEGIN(dec)
23899 subl $1, (v)
23900 sbbl $0, 4(v)
23901 +
23902 +#ifdef CONFIG_PAX_REFCOUNT
23903 + jno 0f
23904 + addl $1, (v)
23905 + adcl $0, 4(v)
23906 + int $4
23907 +0:
23908 + _ASM_EXTABLE(0b, 0b)
23909 +#endif
23910 +
23911 +RET_ENDP
23912 +BEGIN(dec_unchecked)
23913 + subl $1, (v)
23914 + sbbl $0, 4(v)
23915 RET_ENDP
23916 #undef v
23917
23918 @@ -132,6 +255,26 @@ BEGIN(dec_return)
23919 movl 4(v), %edx
23920 subl $1, %eax
23921 sbbl $0, %edx
23922 +
23923 +#ifdef CONFIG_PAX_REFCOUNT
23924 + into
23925 +1234:
23926 + _ASM_EXTABLE(1234b, 2f)
23927 +#endif
23928 +
23929 + movl %eax, (v)
23930 + movl %edx, 4(v)
23931 +
23932 +#ifdef CONFIG_PAX_REFCOUNT
23933 +2:
23934 +#endif
23935 +
23936 +RET_ENDP
23937 +BEGIN(dec_return_unchecked)
23938 + movl (v), %eax
23939 + movl 4(v), %edx
23940 + subl $1, %eax
23941 + sbbl $0, %edx
23942 movl %eax, (v)
23943 movl %edx, 4(v)
23944 RET_ENDP
23945 @@ -143,6 +286,13 @@ BEGIN(add_unless)
23946 adcl %edx, %edi
23947 addl (v), %eax
23948 adcl 4(v), %edx
23949 +
23950 +#ifdef CONFIG_PAX_REFCOUNT
23951 + into
23952 +1234:
23953 + _ASM_EXTABLE(1234b, 2f)
23954 +#endif
23955 +
23956 cmpl %eax, %ecx
23957 je 3f
23958 1:
23959 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
23960 1:
23961 addl $1, %eax
23962 adcl $0, %edx
23963 +
23964 +#ifdef CONFIG_PAX_REFCOUNT
23965 + into
23966 +1234:
23967 + _ASM_EXTABLE(1234b, 2f)
23968 +#endif
23969 +
23970 movl %eax, (v)
23971 movl %edx, 4(v)
23972 movl $1, %eax
23973 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
23974 movl 4(v), %edx
23975 subl $1, %eax
23976 sbbl $0, %edx
23977 +
23978 +#ifdef CONFIG_PAX_REFCOUNT
23979 + into
23980 +1234:
23981 + _ASM_EXTABLE(1234b, 1f)
23982 +#endif
23983 +
23984 js 1f
23985 movl %eax, (v)
23986 movl %edx, 4(v)
23987 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
23988 index f5cc9eb..51fa319 100644
23989 --- a/arch/x86/lib/atomic64_cx8_32.S
23990 +++ b/arch/x86/lib/atomic64_cx8_32.S
23991 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
23992 CFI_STARTPROC
23993
23994 read64 %ecx
23995 + pax_force_retaddr
23996 ret
23997 CFI_ENDPROC
23998 ENDPROC(atomic64_read_cx8)
23999
24000 +ENTRY(atomic64_read_unchecked_cx8)
24001 + CFI_STARTPROC
24002 +
24003 + read64 %ecx
24004 + pax_force_retaddr
24005 + ret
24006 + CFI_ENDPROC
24007 +ENDPROC(atomic64_read_unchecked_cx8)
24008 +
24009 ENTRY(atomic64_set_cx8)
24010 CFI_STARTPROC
24011
24012 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24013 cmpxchg8b (%esi)
24014 jne 1b
24015
24016 + pax_force_retaddr
24017 ret
24018 CFI_ENDPROC
24019 ENDPROC(atomic64_set_cx8)
24020
24021 +ENTRY(atomic64_set_unchecked_cx8)
24022 + CFI_STARTPROC
24023 +
24024 +1:
24025 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
24026 + * are atomic on 586 and newer */
24027 + cmpxchg8b (%esi)
24028 + jne 1b
24029 +
24030 + pax_force_retaddr
24031 + ret
24032 + CFI_ENDPROC
24033 +ENDPROC(atomic64_set_unchecked_cx8)
24034 +
24035 ENTRY(atomic64_xchg_cx8)
24036 CFI_STARTPROC
24037
24038 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24039 cmpxchg8b (%esi)
24040 jne 1b
24041
24042 + pax_force_retaddr
24043 ret
24044 CFI_ENDPROC
24045 ENDPROC(atomic64_xchg_cx8)
24046
24047 -.macro addsub_return func ins insc
24048 -ENTRY(atomic64_\func\()_return_cx8)
24049 +.macro addsub_return func ins insc unchecked=""
24050 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24051 CFI_STARTPROC
24052 SAVE ebp
24053 SAVE ebx
24054 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24055 movl %edx, %ecx
24056 \ins\()l %esi, %ebx
24057 \insc\()l %edi, %ecx
24058 +
24059 +.ifb \unchecked
24060 +#ifdef CONFIG_PAX_REFCOUNT
24061 + into
24062 +2:
24063 + _ASM_EXTABLE(2b, 3f)
24064 +#endif
24065 +.endif
24066 +
24067 LOCK_PREFIX
24068 cmpxchg8b (%ebp)
24069 jne 1b
24070 -
24071 -10:
24072 movl %ebx, %eax
24073 movl %ecx, %edx
24074 +
24075 +.ifb \unchecked
24076 +#ifdef CONFIG_PAX_REFCOUNT
24077 +3:
24078 +#endif
24079 +.endif
24080 +
24081 RESTORE edi
24082 RESTORE esi
24083 RESTORE ebx
24084 RESTORE ebp
24085 + pax_force_retaddr
24086 ret
24087 CFI_ENDPROC
24088 -ENDPROC(atomic64_\func\()_return_cx8)
24089 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24090 .endm
24091
24092 addsub_return add add adc
24093 addsub_return sub sub sbb
24094 +addsub_return add add adc _unchecked
24095 +addsub_return sub sub sbb _unchecked
24096
24097 -.macro incdec_return func ins insc
24098 -ENTRY(atomic64_\func\()_return_cx8)
24099 +.macro incdec_return func ins insc unchecked=""
24100 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24101 CFI_STARTPROC
24102 SAVE ebx
24103
24104 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24105 movl %edx, %ecx
24106 \ins\()l $1, %ebx
24107 \insc\()l $0, %ecx
24108 +
24109 +.ifb \unchecked
24110 +#ifdef CONFIG_PAX_REFCOUNT
24111 + into
24112 +2:
24113 + _ASM_EXTABLE(2b, 3f)
24114 +#endif
24115 +.endif
24116 +
24117 LOCK_PREFIX
24118 cmpxchg8b (%esi)
24119 jne 1b
24120
24121 -10:
24122 movl %ebx, %eax
24123 movl %ecx, %edx
24124 +
24125 +.ifb \unchecked
24126 +#ifdef CONFIG_PAX_REFCOUNT
24127 +3:
24128 +#endif
24129 +.endif
24130 +
24131 RESTORE ebx
24132 + pax_force_retaddr
24133 ret
24134 CFI_ENDPROC
24135 -ENDPROC(atomic64_\func\()_return_cx8)
24136 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24137 .endm
24138
24139 incdec_return inc add adc
24140 incdec_return dec sub sbb
24141 +incdec_return inc add adc _unchecked
24142 +incdec_return dec sub sbb _unchecked
24143
24144 ENTRY(atomic64_dec_if_positive_cx8)
24145 CFI_STARTPROC
24146 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24147 movl %edx, %ecx
24148 subl $1, %ebx
24149 sbb $0, %ecx
24150 +
24151 +#ifdef CONFIG_PAX_REFCOUNT
24152 + into
24153 +1234:
24154 + _ASM_EXTABLE(1234b, 2f)
24155 +#endif
24156 +
24157 js 2f
24158 LOCK_PREFIX
24159 cmpxchg8b (%esi)
24160 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24161 movl %ebx, %eax
24162 movl %ecx, %edx
24163 RESTORE ebx
24164 + pax_force_retaddr
24165 ret
24166 CFI_ENDPROC
24167 ENDPROC(atomic64_dec_if_positive_cx8)
24168 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24169 movl %edx, %ecx
24170 addl %ebp, %ebx
24171 adcl %edi, %ecx
24172 +
24173 +#ifdef CONFIG_PAX_REFCOUNT
24174 + into
24175 +1234:
24176 + _ASM_EXTABLE(1234b, 3f)
24177 +#endif
24178 +
24179 LOCK_PREFIX
24180 cmpxchg8b (%esi)
24181 jne 1b
24182 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24183 CFI_ADJUST_CFA_OFFSET -8
24184 RESTORE ebx
24185 RESTORE ebp
24186 + pax_force_retaddr
24187 ret
24188 4:
24189 cmpl %edx, 4(%esp)
24190 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24191 xorl %ecx, %ecx
24192 addl $1, %ebx
24193 adcl %edx, %ecx
24194 +
24195 +#ifdef CONFIG_PAX_REFCOUNT
24196 + into
24197 +1234:
24198 + _ASM_EXTABLE(1234b, 3f)
24199 +#endif
24200 +
24201 LOCK_PREFIX
24202 cmpxchg8b (%esi)
24203 jne 1b
24204 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24205 movl $1, %eax
24206 3:
24207 RESTORE ebx
24208 + pax_force_retaddr
24209 ret
24210 CFI_ENDPROC
24211 ENDPROC(atomic64_inc_not_zero_cx8)
24212 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24213 index 2af5df3..62b1a5a 100644
24214 --- a/arch/x86/lib/checksum_32.S
24215 +++ b/arch/x86/lib/checksum_32.S
24216 @@ -29,7 +29,8 @@
24217 #include <asm/dwarf2.h>
24218 #include <asm/errno.h>
24219 #include <asm/asm.h>
24220 -
24221 +#include <asm/segment.h>
24222 +
24223 /*
24224 * computes a partial checksum, e.g. for TCP/UDP fragments
24225 */
24226 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24227
24228 #define ARGBASE 16
24229 #define FP 12
24230 -
24231 -ENTRY(csum_partial_copy_generic)
24232 +
24233 +ENTRY(csum_partial_copy_generic_to_user)
24234 CFI_STARTPROC
24235 +
24236 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24237 + pushl_cfi %gs
24238 + popl_cfi %es
24239 + jmp csum_partial_copy_generic
24240 +#endif
24241 +
24242 +ENTRY(csum_partial_copy_generic_from_user)
24243 +
24244 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24245 + pushl_cfi %gs
24246 + popl_cfi %ds
24247 +#endif
24248 +
24249 +ENTRY(csum_partial_copy_generic)
24250 subl $4,%esp
24251 CFI_ADJUST_CFA_OFFSET 4
24252 pushl_cfi %edi
24253 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24254 jmp 4f
24255 SRC(1: movw (%esi), %bx )
24256 addl $2, %esi
24257 -DST( movw %bx, (%edi) )
24258 +DST( movw %bx, %es:(%edi) )
24259 addl $2, %edi
24260 addw %bx, %ax
24261 adcl $0, %eax
24262 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24263 SRC(1: movl (%esi), %ebx )
24264 SRC( movl 4(%esi), %edx )
24265 adcl %ebx, %eax
24266 -DST( movl %ebx, (%edi) )
24267 +DST( movl %ebx, %es:(%edi) )
24268 adcl %edx, %eax
24269 -DST( movl %edx, 4(%edi) )
24270 +DST( movl %edx, %es:4(%edi) )
24271
24272 SRC( movl 8(%esi), %ebx )
24273 SRC( movl 12(%esi), %edx )
24274 adcl %ebx, %eax
24275 -DST( movl %ebx, 8(%edi) )
24276 +DST( movl %ebx, %es:8(%edi) )
24277 adcl %edx, %eax
24278 -DST( movl %edx, 12(%edi) )
24279 +DST( movl %edx, %es:12(%edi) )
24280
24281 SRC( movl 16(%esi), %ebx )
24282 SRC( movl 20(%esi), %edx )
24283 adcl %ebx, %eax
24284 -DST( movl %ebx, 16(%edi) )
24285 +DST( movl %ebx, %es:16(%edi) )
24286 adcl %edx, %eax
24287 -DST( movl %edx, 20(%edi) )
24288 +DST( movl %edx, %es:20(%edi) )
24289
24290 SRC( movl 24(%esi), %ebx )
24291 SRC( movl 28(%esi), %edx )
24292 adcl %ebx, %eax
24293 -DST( movl %ebx, 24(%edi) )
24294 +DST( movl %ebx, %es:24(%edi) )
24295 adcl %edx, %eax
24296 -DST( movl %edx, 28(%edi) )
24297 +DST( movl %edx, %es:28(%edi) )
24298
24299 lea 32(%esi), %esi
24300 lea 32(%edi), %edi
24301 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24302 shrl $2, %edx # This clears CF
24303 SRC(3: movl (%esi), %ebx )
24304 adcl %ebx, %eax
24305 -DST( movl %ebx, (%edi) )
24306 +DST( movl %ebx, %es:(%edi) )
24307 lea 4(%esi), %esi
24308 lea 4(%edi), %edi
24309 dec %edx
24310 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24311 jb 5f
24312 SRC( movw (%esi), %cx )
24313 leal 2(%esi), %esi
24314 -DST( movw %cx, (%edi) )
24315 +DST( movw %cx, %es:(%edi) )
24316 leal 2(%edi), %edi
24317 je 6f
24318 shll $16,%ecx
24319 SRC(5: movb (%esi), %cl )
24320 -DST( movb %cl, (%edi) )
24321 +DST( movb %cl, %es:(%edi) )
24322 6: addl %ecx, %eax
24323 adcl $0, %eax
24324 7:
24325 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24326
24327 6001:
24328 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24329 - movl $-EFAULT, (%ebx)
24330 + movl $-EFAULT, %ss:(%ebx)
24331
24332 # zero the complete destination - computing the rest
24333 # is too much work
24334 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24335
24336 6002:
24337 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24338 - movl $-EFAULT,(%ebx)
24339 + movl $-EFAULT,%ss:(%ebx)
24340 jmp 5000b
24341
24342 .previous
24343
24344 + pushl_cfi %ss
24345 + popl_cfi %ds
24346 + pushl_cfi %ss
24347 + popl_cfi %es
24348 popl_cfi %ebx
24349 CFI_RESTORE ebx
24350 popl_cfi %esi
24351 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24352 popl_cfi %ecx # equivalent to addl $4,%esp
24353 ret
24354 CFI_ENDPROC
24355 -ENDPROC(csum_partial_copy_generic)
24356 +ENDPROC(csum_partial_copy_generic_to_user)
24357
24358 #else
24359
24360 /* Version for PentiumII/PPro */
24361
24362 #define ROUND1(x) \
24363 + nop; nop; nop; \
24364 SRC(movl x(%esi), %ebx ) ; \
24365 addl %ebx, %eax ; \
24366 - DST(movl %ebx, x(%edi) ) ;
24367 + DST(movl %ebx, %es:x(%edi)) ;
24368
24369 #define ROUND(x) \
24370 + nop; nop; nop; \
24371 SRC(movl x(%esi), %ebx ) ; \
24372 adcl %ebx, %eax ; \
24373 - DST(movl %ebx, x(%edi) ) ;
24374 + DST(movl %ebx, %es:x(%edi)) ;
24375
24376 #define ARGBASE 12
24377 -
24378 -ENTRY(csum_partial_copy_generic)
24379 +
24380 +ENTRY(csum_partial_copy_generic_to_user)
24381 CFI_STARTPROC
24382 +
24383 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24384 + pushl_cfi %gs
24385 + popl_cfi %es
24386 + jmp csum_partial_copy_generic
24387 +#endif
24388 +
24389 +ENTRY(csum_partial_copy_generic_from_user)
24390 +
24391 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24392 + pushl_cfi %gs
24393 + popl_cfi %ds
24394 +#endif
24395 +
24396 +ENTRY(csum_partial_copy_generic)
24397 pushl_cfi %ebx
24398 CFI_REL_OFFSET ebx, 0
24399 pushl_cfi %edi
24400 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24401 subl %ebx, %edi
24402 lea -1(%esi),%edx
24403 andl $-32,%edx
24404 - lea 3f(%ebx,%ebx), %ebx
24405 + lea 3f(%ebx,%ebx,2), %ebx
24406 testl %esi, %esi
24407 jmp *%ebx
24408 1: addl $64,%esi
24409 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24410 jb 5f
24411 SRC( movw (%esi), %dx )
24412 leal 2(%esi), %esi
24413 -DST( movw %dx, (%edi) )
24414 +DST( movw %dx, %es:(%edi) )
24415 leal 2(%edi), %edi
24416 je 6f
24417 shll $16,%edx
24418 5:
24419 SRC( movb (%esi), %dl )
24420 -DST( movb %dl, (%edi) )
24421 +DST( movb %dl, %es:(%edi) )
24422 6: addl %edx, %eax
24423 adcl $0, %eax
24424 7:
24425 .section .fixup, "ax"
24426 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24427 - movl $-EFAULT, (%ebx)
24428 + movl $-EFAULT, %ss:(%ebx)
24429 # zero the complete destination (computing the rest is too much work)
24430 movl ARGBASE+8(%esp),%edi # dst
24431 movl ARGBASE+12(%esp),%ecx # len
24432 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24433 rep; stosb
24434 jmp 7b
24435 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24436 - movl $-EFAULT, (%ebx)
24437 + movl $-EFAULT, %ss:(%ebx)
24438 jmp 7b
24439 .previous
24440
24441 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24442 + pushl_cfi %ss
24443 + popl_cfi %ds
24444 + pushl_cfi %ss
24445 + popl_cfi %es
24446 +#endif
24447 +
24448 popl_cfi %esi
24449 CFI_RESTORE esi
24450 popl_cfi %edi
24451 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24452 CFI_RESTORE ebx
24453 ret
24454 CFI_ENDPROC
24455 -ENDPROC(csum_partial_copy_generic)
24456 +ENDPROC(csum_partial_copy_generic_to_user)
24457
24458 #undef ROUND
24459 #undef ROUND1
24460 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24461 index f2145cf..cea889d 100644
24462 --- a/arch/x86/lib/clear_page_64.S
24463 +++ b/arch/x86/lib/clear_page_64.S
24464 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24465 movl $4096/8,%ecx
24466 xorl %eax,%eax
24467 rep stosq
24468 + pax_force_retaddr
24469 ret
24470 CFI_ENDPROC
24471 ENDPROC(clear_page_c)
24472 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
24473 movl $4096,%ecx
24474 xorl %eax,%eax
24475 rep stosb
24476 + pax_force_retaddr
24477 ret
24478 CFI_ENDPROC
24479 ENDPROC(clear_page_c_e)
24480 @@ -43,6 +45,7 @@ ENTRY(clear_page)
24481 leaq 64(%rdi),%rdi
24482 jnz .Lloop
24483 nop
24484 + pax_force_retaddr
24485 ret
24486 CFI_ENDPROC
24487 .Lclear_page_end:
24488 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
24489
24490 #include <asm/cpufeature.h>
24491
24492 - .section .altinstr_replacement,"ax"
24493 + .section .altinstr_replacement,"a"
24494 1: .byte 0xeb /* jmp <disp8> */
24495 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
24496 2: .byte 0xeb /* jmp <disp8> */
24497 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
24498 index 1e572c5..2a162cd 100644
24499 --- a/arch/x86/lib/cmpxchg16b_emu.S
24500 +++ b/arch/x86/lib/cmpxchg16b_emu.S
24501 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
24502
24503 popf
24504 mov $1, %al
24505 + pax_force_retaddr
24506 ret
24507
24508 not_same:
24509 popf
24510 xor %al,%al
24511 + pax_force_retaddr
24512 ret
24513
24514 CFI_ENDPROC
24515 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
24516 index 176cca6..1166c50 100644
24517 --- a/arch/x86/lib/copy_page_64.S
24518 +++ b/arch/x86/lib/copy_page_64.S
24519 @@ -9,6 +9,7 @@ copy_page_rep:
24520 CFI_STARTPROC
24521 movl $4096/8, %ecx
24522 rep movsq
24523 + pax_force_retaddr
24524 ret
24525 CFI_ENDPROC
24526 ENDPROC(copy_page_rep)
24527 @@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
24528
24529 ENTRY(copy_page)
24530 CFI_STARTPROC
24531 - subq $2*8, %rsp
24532 - CFI_ADJUST_CFA_OFFSET 2*8
24533 + subq $3*8, %rsp
24534 + CFI_ADJUST_CFA_OFFSET 3*8
24535 movq %rbx, (%rsp)
24536 CFI_REL_OFFSET rbx, 0
24537 movq %r12, 1*8(%rsp)
24538 CFI_REL_OFFSET r12, 1*8
24539 + movq %r13, 2*8(%rsp)
24540 + CFI_REL_OFFSET r13, 2*8
24541
24542 movl $(4096/64)-5, %ecx
24543 .p2align 4
24544 @@ -36,7 +39,7 @@ ENTRY(copy_page)
24545 movq 0x8*2(%rsi), %rdx
24546 movq 0x8*3(%rsi), %r8
24547 movq 0x8*4(%rsi), %r9
24548 - movq 0x8*5(%rsi), %r10
24549 + movq 0x8*5(%rsi), %r13
24550 movq 0x8*6(%rsi), %r11
24551 movq 0x8*7(%rsi), %r12
24552
24553 @@ -47,7 +50,7 @@ ENTRY(copy_page)
24554 movq %rdx, 0x8*2(%rdi)
24555 movq %r8, 0x8*3(%rdi)
24556 movq %r9, 0x8*4(%rdi)
24557 - movq %r10, 0x8*5(%rdi)
24558 + movq %r13, 0x8*5(%rdi)
24559 movq %r11, 0x8*6(%rdi)
24560 movq %r12, 0x8*7(%rdi)
24561
24562 @@ -66,7 +69,7 @@ ENTRY(copy_page)
24563 movq 0x8*2(%rsi), %rdx
24564 movq 0x8*3(%rsi), %r8
24565 movq 0x8*4(%rsi), %r9
24566 - movq 0x8*5(%rsi), %r10
24567 + movq 0x8*5(%rsi), %r13
24568 movq 0x8*6(%rsi), %r11
24569 movq 0x8*7(%rsi), %r12
24570
24571 @@ -75,7 +78,7 @@ ENTRY(copy_page)
24572 movq %rdx, 0x8*2(%rdi)
24573 movq %r8, 0x8*3(%rdi)
24574 movq %r9, 0x8*4(%rdi)
24575 - movq %r10, 0x8*5(%rdi)
24576 + movq %r13, 0x8*5(%rdi)
24577 movq %r11, 0x8*6(%rdi)
24578 movq %r12, 0x8*7(%rdi)
24579
24580 @@ -87,8 +90,11 @@ ENTRY(copy_page)
24581 CFI_RESTORE rbx
24582 movq 1*8(%rsp), %r12
24583 CFI_RESTORE r12
24584 - addq $2*8, %rsp
24585 - CFI_ADJUST_CFA_OFFSET -2*8
24586 + movq 2*8(%rsp), %r13
24587 + CFI_RESTORE r13
24588 + addq $3*8, %rsp
24589 + CFI_ADJUST_CFA_OFFSET -3*8
24590 + pax_force_retaddr
24591 ret
24592 .Lcopy_page_end:
24593 CFI_ENDPROC
24594 @@ -99,7 +105,7 @@ ENDPROC(copy_page)
24595
24596 #include <asm/cpufeature.h>
24597
24598 - .section .altinstr_replacement,"ax"
24599 + .section .altinstr_replacement,"a"
24600 1: .byte 0xeb /* jmp <disp8> */
24601 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
24602 2:
24603 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
24604 index a30ca15..d25fab6 100644
24605 --- a/arch/x86/lib/copy_user_64.S
24606 +++ b/arch/x86/lib/copy_user_64.S
24607 @@ -18,6 +18,7 @@
24608 #include <asm/alternative-asm.h>
24609 #include <asm/asm.h>
24610 #include <asm/smap.h>
24611 +#include <asm/pgtable.h>
24612
24613 /*
24614 * By placing feature2 after feature1 in altinstructions section, we logically
24615 @@ -31,7 +32,7 @@
24616 .byte 0xe9 /* 32bit jump */
24617 .long \orig-1f /* by default jump to orig */
24618 1:
24619 - .section .altinstr_replacement,"ax"
24620 + .section .altinstr_replacement,"a"
24621 2: .byte 0xe9 /* near jump with 32bit immediate */
24622 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
24623 3: .byte 0xe9 /* near jump with 32bit immediate */
24624 @@ -70,47 +71,20 @@
24625 #endif
24626 .endm
24627
24628 -/* Standard copy_to_user with segment limit checking */
24629 -ENTRY(_copy_to_user)
24630 - CFI_STARTPROC
24631 - GET_THREAD_INFO(%rax)
24632 - movq %rdi,%rcx
24633 - addq %rdx,%rcx
24634 - jc bad_to_user
24635 - cmpq TI_addr_limit(%rax),%rcx
24636 - ja bad_to_user
24637 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24638 - copy_user_generic_unrolled,copy_user_generic_string, \
24639 - copy_user_enhanced_fast_string
24640 - CFI_ENDPROC
24641 -ENDPROC(_copy_to_user)
24642 -
24643 -/* Standard copy_from_user with segment limit checking */
24644 -ENTRY(_copy_from_user)
24645 - CFI_STARTPROC
24646 - GET_THREAD_INFO(%rax)
24647 - movq %rsi,%rcx
24648 - addq %rdx,%rcx
24649 - jc bad_from_user
24650 - cmpq TI_addr_limit(%rax),%rcx
24651 - ja bad_from_user
24652 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24653 - copy_user_generic_unrolled,copy_user_generic_string, \
24654 - copy_user_enhanced_fast_string
24655 - CFI_ENDPROC
24656 -ENDPROC(_copy_from_user)
24657 -
24658 .section .fixup,"ax"
24659 /* must zero dest */
24660 ENTRY(bad_from_user)
24661 bad_from_user:
24662 CFI_STARTPROC
24663 + testl %edx,%edx
24664 + js bad_to_user
24665 movl %edx,%ecx
24666 xorl %eax,%eax
24667 rep
24668 stosb
24669 bad_to_user:
24670 movl %edx,%eax
24671 + pax_force_retaddr
24672 ret
24673 CFI_ENDPROC
24674 ENDPROC(bad_from_user)
24675 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
24676 jz 17f
24677 1: movq (%rsi),%r8
24678 2: movq 1*8(%rsi),%r9
24679 -3: movq 2*8(%rsi),%r10
24680 +3: movq 2*8(%rsi),%rax
24681 4: movq 3*8(%rsi),%r11
24682 5: movq %r8,(%rdi)
24683 6: movq %r9,1*8(%rdi)
24684 -7: movq %r10,2*8(%rdi)
24685 +7: movq %rax,2*8(%rdi)
24686 8: movq %r11,3*8(%rdi)
24687 9: movq 4*8(%rsi),%r8
24688 10: movq 5*8(%rsi),%r9
24689 -11: movq 6*8(%rsi),%r10
24690 +11: movq 6*8(%rsi),%rax
24691 12: movq 7*8(%rsi),%r11
24692 13: movq %r8,4*8(%rdi)
24693 14: movq %r9,5*8(%rdi)
24694 -15: movq %r10,6*8(%rdi)
24695 +15: movq %rax,6*8(%rdi)
24696 16: movq %r11,7*8(%rdi)
24697 leaq 64(%rsi),%rsi
24698 leaq 64(%rdi),%rdi
24699 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
24700 jnz 21b
24701 23: xor %eax,%eax
24702 ASM_CLAC
24703 + pax_force_retaddr
24704 ret
24705
24706 .section .fixup,"ax"
24707 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
24708 movsb
24709 4: xorl %eax,%eax
24710 ASM_CLAC
24711 + pax_force_retaddr
24712 ret
24713
24714 .section .fixup,"ax"
24715 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
24716 movsb
24717 2: xorl %eax,%eax
24718 ASM_CLAC
24719 + pax_force_retaddr
24720 ret
24721
24722 .section .fixup,"ax"
24723 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
24724 index 6a4f43c..f5f9e26 100644
24725 --- a/arch/x86/lib/copy_user_nocache_64.S
24726 +++ b/arch/x86/lib/copy_user_nocache_64.S
24727 @@ -8,6 +8,7 @@
24728
24729 #include <linux/linkage.h>
24730 #include <asm/dwarf2.h>
24731 +#include <asm/alternative-asm.h>
24732
24733 #define FIX_ALIGNMENT 1
24734
24735 @@ -16,6 +17,7 @@
24736 #include <asm/thread_info.h>
24737 #include <asm/asm.h>
24738 #include <asm/smap.h>
24739 +#include <asm/pgtable.h>
24740
24741 .macro ALIGN_DESTINATION
24742 #ifdef FIX_ALIGNMENT
24743 @@ -49,6 +51,15 @@
24744 */
24745 ENTRY(__copy_user_nocache)
24746 CFI_STARTPROC
24747 +
24748 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24749 + mov $PAX_USER_SHADOW_BASE,%rcx
24750 + cmp %rcx,%rsi
24751 + jae 1f
24752 + add %rcx,%rsi
24753 +1:
24754 +#endif
24755 +
24756 ASM_STAC
24757 cmpl $8,%edx
24758 jb 20f /* less then 8 bytes, go to byte copy loop */
24759 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
24760 jz 17f
24761 1: movq (%rsi),%r8
24762 2: movq 1*8(%rsi),%r9
24763 -3: movq 2*8(%rsi),%r10
24764 +3: movq 2*8(%rsi),%rax
24765 4: movq 3*8(%rsi),%r11
24766 5: movnti %r8,(%rdi)
24767 6: movnti %r9,1*8(%rdi)
24768 -7: movnti %r10,2*8(%rdi)
24769 +7: movnti %rax,2*8(%rdi)
24770 8: movnti %r11,3*8(%rdi)
24771 9: movq 4*8(%rsi),%r8
24772 10: movq 5*8(%rsi),%r9
24773 -11: movq 6*8(%rsi),%r10
24774 +11: movq 6*8(%rsi),%rax
24775 12: movq 7*8(%rsi),%r11
24776 13: movnti %r8,4*8(%rdi)
24777 14: movnti %r9,5*8(%rdi)
24778 -15: movnti %r10,6*8(%rdi)
24779 +15: movnti %rax,6*8(%rdi)
24780 16: movnti %r11,7*8(%rdi)
24781 leaq 64(%rsi),%rsi
24782 leaq 64(%rdi),%rdi
24783 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
24784 23: xorl %eax,%eax
24785 ASM_CLAC
24786 sfence
24787 + pax_force_retaddr
24788 ret
24789
24790 .section .fixup,"ax"
24791 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
24792 index 2419d5f..953ee51 100644
24793 --- a/arch/x86/lib/csum-copy_64.S
24794 +++ b/arch/x86/lib/csum-copy_64.S
24795 @@ -9,6 +9,7 @@
24796 #include <asm/dwarf2.h>
24797 #include <asm/errno.h>
24798 #include <asm/asm.h>
24799 +#include <asm/alternative-asm.h>
24800
24801 /*
24802 * Checksum copy with exception handling.
24803 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
24804 CFI_RESTORE rbp
24805 addq $7*8, %rsp
24806 CFI_ADJUST_CFA_OFFSET -7*8
24807 + pax_force_retaddr 0, 1
24808 ret
24809 CFI_RESTORE_STATE
24810
24811 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
24812 index 25b7ae8..169fafc 100644
24813 --- a/arch/x86/lib/csum-wrappers_64.c
24814 +++ b/arch/x86/lib/csum-wrappers_64.c
24815 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
24816 len -= 2;
24817 }
24818 }
24819 - isum = csum_partial_copy_generic((__force const void *)src,
24820 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
24821 dst, len, isum, errp, NULL);
24822 if (unlikely(*errp))
24823 goto out_err;
24824 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
24825 }
24826
24827 *errp = 0;
24828 - return csum_partial_copy_generic(src, (void __force *)dst,
24829 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
24830 len, isum, NULL, errp);
24831 }
24832 EXPORT_SYMBOL(csum_partial_copy_to_user);
24833 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
24834 index 156b9c8..b144132 100644
24835 --- a/arch/x86/lib/getuser.S
24836 +++ b/arch/x86/lib/getuser.S
24837 @@ -34,17 +34,40 @@
24838 #include <asm/thread_info.h>
24839 #include <asm/asm.h>
24840 #include <asm/smap.h>
24841 +#include <asm/segment.h>
24842 +#include <asm/pgtable.h>
24843 +#include <asm/alternative-asm.h>
24844 +
24845 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24846 +#define __copyuser_seg gs;
24847 +#else
24848 +#define __copyuser_seg
24849 +#endif
24850
24851 .text
24852 ENTRY(__get_user_1)
24853 CFI_STARTPROC
24854 +
24855 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24856 GET_THREAD_INFO(%_ASM_DX)
24857 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24858 jae bad_get_user
24859 ASM_STAC
24860 -1: movzb (%_ASM_AX),%edx
24861 +
24862 +#if defined(CONFIG_X86_64) && defined(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 +#endif
24871 +
24872 +1: __copyuser_seg movzb (%_ASM_AX),%edx
24873 xor %eax,%eax
24874 ASM_CLAC
24875 + pax_force_retaddr
24876 ret
24877 CFI_ENDPROC
24878 ENDPROC(__get_user_1)
24879 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
24880 ENTRY(__get_user_2)
24881 CFI_STARTPROC
24882 add $1,%_ASM_AX
24883 +
24884 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24885 jc bad_get_user
24886 GET_THREAD_INFO(%_ASM_DX)
24887 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24888 jae bad_get_user
24889 ASM_STAC
24890 -2: movzwl -1(%_ASM_AX),%edx
24891 +
24892 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24893 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24894 + cmp %_ASM_DX,%_ASM_AX
24895 + jae 1234f
24896 + add %_ASM_DX,%_ASM_AX
24897 +1234:
24898 +#endif
24899 +
24900 +#endif
24901 +
24902 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
24903 xor %eax,%eax
24904 ASM_CLAC
24905 + pax_force_retaddr
24906 ret
24907 CFI_ENDPROC
24908 ENDPROC(__get_user_2)
24909 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
24910 ENTRY(__get_user_4)
24911 CFI_STARTPROC
24912 add $3,%_ASM_AX
24913 +
24914 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24915 jc bad_get_user
24916 GET_THREAD_INFO(%_ASM_DX)
24917 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24918 jae bad_get_user
24919 ASM_STAC
24920 -3: mov -3(%_ASM_AX),%edx
24921 +
24922 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24923 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24924 + cmp %_ASM_DX,%_ASM_AX
24925 + jae 1234f
24926 + add %_ASM_DX,%_ASM_AX
24927 +1234:
24928 +#endif
24929 +
24930 +#endif
24931 +
24932 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
24933 xor %eax,%eax
24934 ASM_CLAC
24935 + pax_force_retaddr
24936 ret
24937 CFI_ENDPROC
24938 ENDPROC(__get_user_4)
24939 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
24940 GET_THREAD_INFO(%_ASM_DX)
24941 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24942 jae bad_get_user
24943 +
24944 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24945 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24946 + cmp %_ASM_DX,%_ASM_AX
24947 + jae 1234f
24948 + add %_ASM_DX,%_ASM_AX
24949 +1234:
24950 +#endif
24951 +
24952 ASM_STAC
24953 4: movq -7(%_ASM_AX),%_ASM_DX
24954 xor %eax,%eax
24955 ASM_CLAC
24956 + pax_force_retaddr
24957 ret
24958 CFI_ENDPROC
24959 ENDPROC(__get_user_8)
24960 @@ -101,6 +162,7 @@ bad_get_user:
24961 xor %edx,%edx
24962 mov $(-EFAULT),%_ASM_AX
24963 ASM_CLAC
24964 + pax_force_retaddr
24965 ret
24966 CFI_ENDPROC
24967 END(bad_get_user)
24968 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
24969 index 54fcffe..7be149e 100644
24970 --- a/arch/x86/lib/insn.c
24971 +++ b/arch/x86/lib/insn.c
24972 @@ -20,8 +20,10 @@
24973
24974 #ifdef __KERNEL__
24975 #include <linux/string.h>
24976 +#include <asm/pgtable_types.h>
24977 #else
24978 #include <string.h>
24979 +#define ktla_ktva(addr) addr
24980 #endif
24981 #include <asm/inat.h>
24982 #include <asm/insn.h>
24983 @@ -53,8 +55,8 @@
24984 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
24985 {
24986 memset(insn, 0, sizeof(*insn));
24987 - insn->kaddr = kaddr;
24988 - insn->next_byte = kaddr;
24989 + insn->kaddr = ktla_ktva(kaddr);
24990 + insn->next_byte = ktla_ktva(kaddr);
24991 insn->x86_64 = x86_64 ? 1 : 0;
24992 insn->opnd_bytes = 4;
24993 if (x86_64)
24994 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
24995 index 05a95e7..326f2fa 100644
24996 --- a/arch/x86/lib/iomap_copy_64.S
24997 +++ b/arch/x86/lib/iomap_copy_64.S
24998 @@ -17,6 +17,7 @@
24999
25000 #include <linux/linkage.h>
25001 #include <asm/dwarf2.h>
25002 +#include <asm/alternative-asm.h>
25003
25004 /*
25005 * override generic version in lib/iomap_copy.c
25006 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25007 CFI_STARTPROC
25008 movl %edx,%ecx
25009 rep movsd
25010 + pax_force_retaddr
25011 ret
25012 CFI_ENDPROC
25013 ENDPROC(__iowrite32_copy)
25014 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25015 index 1c273be..da9cc0e 100644
25016 --- a/arch/x86/lib/memcpy_64.S
25017 +++ b/arch/x86/lib/memcpy_64.S
25018 @@ -33,6 +33,7 @@
25019 rep movsq
25020 movl %edx, %ecx
25021 rep movsb
25022 + pax_force_retaddr
25023 ret
25024 .Lmemcpy_e:
25025 .previous
25026 @@ -49,6 +50,7 @@
25027 movq %rdi, %rax
25028 movq %rdx, %rcx
25029 rep movsb
25030 + pax_force_retaddr
25031 ret
25032 .Lmemcpy_e_e:
25033 .previous
25034 @@ -76,13 +78,13 @@ ENTRY(memcpy)
25035 */
25036 movq 0*8(%rsi), %r8
25037 movq 1*8(%rsi), %r9
25038 - movq 2*8(%rsi), %r10
25039 + movq 2*8(%rsi), %rcx
25040 movq 3*8(%rsi), %r11
25041 leaq 4*8(%rsi), %rsi
25042
25043 movq %r8, 0*8(%rdi)
25044 movq %r9, 1*8(%rdi)
25045 - movq %r10, 2*8(%rdi)
25046 + movq %rcx, 2*8(%rdi)
25047 movq %r11, 3*8(%rdi)
25048 leaq 4*8(%rdi), %rdi
25049 jae .Lcopy_forward_loop
25050 @@ -105,12 +107,12 @@ ENTRY(memcpy)
25051 subq $0x20, %rdx
25052 movq -1*8(%rsi), %r8
25053 movq -2*8(%rsi), %r9
25054 - movq -3*8(%rsi), %r10
25055 + movq -3*8(%rsi), %rcx
25056 movq -4*8(%rsi), %r11
25057 leaq -4*8(%rsi), %rsi
25058 movq %r8, -1*8(%rdi)
25059 movq %r9, -2*8(%rdi)
25060 - movq %r10, -3*8(%rdi)
25061 + movq %rcx, -3*8(%rdi)
25062 movq %r11, -4*8(%rdi)
25063 leaq -4*8(%rdi), %rdi
25064 jae .Lcopy_backward_loop
25065 @@ -130,12 +132,13 @@ ENTRY(memcpy)
25066 */
25067 movq 0*8(%rsi), %r8
25068 movq 1*8(%rsi), %r9
25069 - movq -2*8(%rsi, %rdx), %r10
25070 + movq -2*8(%rsi, %rdx), %rcx
25071 movq -1*8(%rsi, %rdx), %r11
25072 movq %r8, 0*8(%rdi)
25073 movq %r9, 1*8(%rdi)
25074 - movq %r10, -2*8(%rdi, %rdx)
25075 + movq %rcx, -2*8(%rdi, %rdx)
25076 movq %r11, -1*8(%rdi, %rdx)
25077 + pax_force_retaddr
25078 retq
25079 .p2align 4
25080 .Lless_16bytes:
25081 @@ -148,6 +151,7 @@ ENTRY(memcpy)
25082 movq -1*8(%rsi, %rdx), %r9
25083 movq %r8, 0*8(%rdi)
25084 movq %r9, -1*8(%rdi, %rdx)
25085 + pax_force_retaddr
25086 retq
25087 .p2align 4
25088 .Lless_8bytes:
25089 @@ -161,6 +165,7 @@ ENTRY(memcpy)
25090 movl -4(%rsi, %rdx), %r8d
25091 movl %ecx, (%rdi)
25092 movl %r8d, -4(%rdi, %rdx)
25093 + pax_force_retaddr
25094 retq
25095 .p2align 4
25096 .Lless_3bytes:
25097 @@ -179,6 +184,7 @@ ENTRY(memcpy)
25098 movb %cl, (%rdi)
25099
25100 .Lend:
25101 + pax_force_retaddr
25102 retq
25103 CFI_ENDPROC
25104 ENDPROC(memcpy)
25105 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25106 index ee16461..c39c199 100644
25107 --- a/arch/x86/lib/memmove_64.S
25108 +++ b/arch/x86/lib/memmove_64.S
25109 @@ -61,13 +61,13 @@ ENTRY(memmove)
25110 5:
25111 sub $0x20, %rdx
25112 movq 0*8(%rsi), %r11
25113 - movq 1*8(%rsi), %r10
25114 + movq 1*8(%rsi), %rcx
25115 movq 2*8(%rsi), %r9
25116 movq 3*8(%rsi), %r8
25117 leaq 4*8(%rsi), %rsi
25118
25119 movq %r11, 0*8(%rdi)
25120 - movq %r10, 1*8(%rdi)
25121 + movq %rcx, 1*8(%rdi)
25122 movq %r9, 2*8(%rdi)
25123 movq %r8, 3*8(%rdi)
25124 leaq 4*8(%rdi), %rdi
25125 @@ -81,10 +81,10 @@ ENTRY(memmove)
25126 4:
25127 movq %rdx, %rcx
25128 movq -8(%rsi, %rdx), %r11
25129 - lea -8(%rdi, %rdx), %r10
25130 + lea -8(%rdi, %rdx), %r9
25131 shrq $3, %rcx
25132 rep movsq
25133 - movq %r11, (%r10)
25134 + movq %r11, (%r9)
25135 jmp 13f
25136 .Lmemmove_end_forward:
25137
25138 @@ -95,14 +95,14 @@ ENTRY(memmove)
25139 7:
25140 movq %rdx, %rcx
25141 movq (%rsi), %r11
25142 - movq %rdi, %r10
25143 + movq %rdi, %r9
25144 leaq -8(%rsi, %rdx), %rsi
25145 leaq -8(%rdi, %rdx), %rdi
25146 shrq $3, %rcx
25147 std
25148 rep movsq
25149 cld
25150 - movq %r11, (%r10)
25151 + movq %r11, (%r9)
25152 jmp 13f
25153
25154 /*
25155 @@ -127,13 +127,13 @@ ENTRY(memmove)
25156 8:
25157 subq $0x20, %rdx
25158 movq -1*8(%rsi), %r11
25159 - movq -2*8(%rsi), %r10
25160 + movq -2*8(%rsi), %rcx
25161 movq -3*8(%rsi), %r9
25162 movq -4*8(%rsi), %r8
25163 leaq -4*8(%rsi), %rsi
25164
25165 movq %r11, -1*8(%rdi)
25166 - movq %r10, -2*8(%rdi)
25167 + movq %rcx, -2*8(%rdi)
25168 movq %r9, -3*8(%rdi)
25169 movq %r8, -4*8(%rdi)
25170 leaq -4*8(%rdi), %rdi
25171 @@ -151,11 +151,11 @@ ENTRY(memmove)
25172 * Move data from 16 bytes to 31 bytes.
25173 */
25174 movq 0*8(%rsi), %r11
25175 - movq 1*8(%rsi), %r10
25176 + movq 1*8(%rsi), %rcx
25177 movq -2*8(%rsi, %rdx), %r9
25178 movq -1*8(%rsi, %rdx), %r8
25179 movq %r11, 0*8(%rdi)
25180 - movq %r10, 1*8(%rdi)
25181 + movq %rcx, 1*8(%rdi)
25182 movq %r9, -2*8(%rdi, %rdx)
25183 movq %r8, -1*8(%rdi, %rdx)
25184 jmp 13f
25185 @@ -167,9 +167,9 @@ ENTRY(memmove)
25186 * Move data from 8 bytes to 15 bytes.
25187 */
25188 movq 0*8(%rsi), %r11
25189 - movq -1*8(%rsi, %rdx), %r10
25190 + movq -1*8(%rsi, %rdx), %r9
25191 movq %r11, 0*8(%rdi)
25192 - movq %r10, -1*8(%rdi, %rdx)
25193 + movq %r9, -1*8(%rdi, %rdx)
25194 jmp 13f
25195 10:
25196 cmpq $4, %rdx
25197 @@ -178,9 +178,9 @@ ENTRY(memmove)
25198 * Move data from 4 bytes to 7 bytes.
25199 */
25200 movl (%rsi), %r11d
25201 - movl -4(%rsi, %rdx), %r10d
25202 + movl -4(%rsi, %rdx), %r9d
25203 movl %r11d, (%rdi)
25204 - movl %r10d, -4(%rdi, %rdx)
25205 + movl %r9d, -4(%rdi, %rdx)
25206 jmp 13f
25207 11:
25208 cmp $2, %rdx
25209 @@ -189,9 +189,9 @@ ENTRY(memmove)
25210 * Move data from 2 bytes to 3 bytes.
25211 */
25212 movw (%rsi), %r11w
25213 - movw -2(%rsi, %rdx), %r10w
25214 + movw -2(%rsi, %rdx), %r9w
25215 movw %r11w, (%rdi)
25216 - movw %r10w, -2(%rdi, %rdx)
25217 + movw %r9w, -2(%rdi, %rdx)
25218 jmp 13f
25219 12:
25220 cmp $1, %rdx
25221 @@ -202,6 +202,7 @@ ENTRY(memmove)
25222 movb (%rsi), %r11b
25223 movb %r11b, (%rdi)
25224 13:
25225 + pax_force_retaddr
25226 retq
25227 CFI_ENDPROC
25228
25229 @@ -210,6 +211,7 @@ ENTRY(memmove)
25230 /* Forward moving data. */
25231 movq %rdx, %rcx
25232 rep movsb
25233 + pax_force_retaddr
25234 retq
25235 .Lmemmove_end_forward_efs:
25236 .previous
25237 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25238 index 2dcb380..963660a 100644
25239 --- a/arch/x86/lib/memset_64.S
25240 +++ b/arch/x86/lib/memset_64.S
25241 @@ -30,6 +30,7 @@
25242 movl %edx,%ecx
25243 rep stosb
25244 movq %r9,%rax
25245 + pax_force_retaddr
25246 ret
25247 .Lmemset_e:
25248 .previous
25249 @@ -52,6 +53,7 @@
25250 movq %rdx,%rcx
25251 rep stosb
25252 movq %r9,%rax
25253 + pax_force_retaddr
25254 ret
25255 .Lmemset_e_e:
25256 .previous
25257 @@ -59,7 +61,7 @@
25258 ENTRY(memset)
25259 ENTRY(__memset)
25260 CFI_STARTPROC
25261 - movq %rdi,%r10
25262 + movq %rdi,%r11
25263
25264 /* expand byte value */
25265 movzbl %sil,%ecx
25266 @@ -117,7 +119,8 @@ ENTRY(__memset)
25267 jnz .Lloop_1
25268
25269 .Lende:
25270 - movq %r10,%rax
25271 + movq %r11,%rax
25272 + pax_force_retaddr
25273 ret
25274
25275 CFI_RESTORE_STATE
25276 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25277 index c9f2d9b..e7fd2c0 100644
25278 --- a/arch/x86/lib/mmx_32.c
25279 +++ b/arch/x86/lib/mmx_32.c
25280 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25281 {
25282 void *p;
25283 int i;
25284 + unsigned long cr0;
25285
25286 if (unlikely(in_interrupt()))
25287 return __memcpy(to, from, len);
25288 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25289 kernel_fpu_begin();
25290
25291 __asm__ __volatile__ (
25292 - "1: prefetch (%0)\n" /* This set is 28 bytes */
25293 - " prefetch 64(%0)\n"
25294 - " prefetch 128(%0)\n"
25295 - " prefetch 192(%0)\n"
25296 - " prefetch 256(%0)\n"
25297 + "1: prefetch (%1)\n" /* This set is 28 bytes */
25298 + " prefetch 64(%1)\n"
25299 + " prefetch 128(%1)\n"
25300 + " prefetch 192(%1)\n"
25301 + " prefetch 256(%1)\n"
25302 "2: \n"
25303 ".section .fixup, \"ax\"\n"
25304 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25305 + "3: \n"
25306 +
25307 +#ifdef CONFIG_PAX_KERNEXEC
25308 + " movl %%cr0, %0\n"
25309 + " movl %0, %%eax\n"
25310 + " andl $0xFFFEFFFF, %%eax\n"
25311 + " movl %%eax, %%cr0\n"
25312 +#endif
25313 +
25314 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25315 +
25316 +#ifdef CONFIG_PAX_KERNEXEC
25317 + " movl %0, %%cr0\n"
25318 +#endif
25319 +
25320 " jmp 2b\n"
25321 ".previous\n"
25322 _ASM_EXTABLE(1b, 3b)
25323 - : : "r" (from));
25324 + : "=&r" (cr0) : "r" (from) : "ax");
25325
25326 for ( ; i > 5; i--) {
25327 __asm__ __volatile__ (
25328 - "1: prefetch 320(%0)\n"
25329 - "2: movq (%0), %%mm0\n"
25330 - " movq 8(%0), %%mm1\n"
25331 - " movq 16(%0), %%mm2\n"
25332 - " movq 24(%0), %%mm3\n"
25333 - " movq %%mm0, (%1)\n"
25334 - " movq %%mm1, 8(%1)\n"
25335 - " movq %%mm2, 16(%1)\n"
25336 - " movq %%mm3, 24(%1)\n"
25337 - " movq 32(%0), %%mm0\n"
25338 - " movq 40(%0), %%mm1\n"
25339 - " movq 48(%0), %%mm2\n"
25340 - " movq 56(%0), %%mm3\n"
25341 - " movq %%mm0, 32(%1)\n"
25342 - " movq %%mm1, 40(%1)\n"
25343 - " movq %%mm2, 48(%1)\n"
25344 - " movq %%mm3, 56(%1)\n"
25345 + "1: prefetch 320(%1)\n"
25346 + "2: movq (%1), %%mm0\n"
25347 + " movq 8(%1), %%mm1\n"
25348 + " movq 16(%1), %%mm2\n"
25349 + " movq 24(%1), %%mm3\n"
25350 + " movq %%mm0, (%2)\n"
25351 + " movq %%mm1, 8(%2)\n"
25352 + " movq %%mm2, 16(%2)\n"
25353 + " movq %%mm3, 24(%2)\n"
25354 + " movq 32(%1), %%mm0\n"
25355 + " movq 40(%1), %%mm1\n"
25356 + " movq 48(%1), %%mm2\n"
25357 + " movq 56(%1), %%mm3\n"
25358 + " movq %%mm0, 32(%2)\n"
25359 + " movq %%mm1, 40(%2)\n"
25360 + " movq %%mm2, 48(%2)\n"
25361 + " movq %%mm3, 56(%2)\n"
25362 ".section .fixup, \"ax\"\n"
25363 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25364 + "3:\n"
25365 +
25366 +#ifdef CONFIG_PAX_KERNEXEC
25367 + " movl %%cr0, %0\n"
25368 + " movl %0, %%eax\n"
25369 + " andl $0xFFFEFFFF, %%eax\n"
25370 + " movl %%eax, %%cr0\n"
25371 +#endif
25372 +
25373 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25374 +
25375 +#ifdef CONFIG_PAX_KERNEXEC
25376 + " movl %0, %%cr0\n"
25377 +#endif
25378 +
25379 " jmp 2b\n"
25380 ".previous\n"
25381 _ASM_EXTABLE(1b, 3b)
25382 - : : "r" (from), "r" (to) : "memory");
25383 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25384
25385 from += 64;
25386 to += 64;
25387 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25388 static void fast_copy_page(void *to, void *from)
25389 {
25390 int i;
25391 + unsigned long cr0;
25392
25393 kernel_fpu_begin();
25394
25395 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25396 * but that is for later. -AV
25397 */
25398 __asm__ __volatile__(
25399 - "1: prefetch (%0)\n"
25400 - " prefetch 64(%0)\n"
25401 - " prefetch 128(%0)\n"
25402 - " prefetch 192(%0)\n"
25403 - " prefetch 256(%0)\n"
25404 + "1: prefetch (%1)\n"
25405 + " prefetch 64(%1)\n"
25406 + " prefetch 128(%1)\n"
25407 + " prefetch 192(%1)\n"
25408 + " prefetch 256(%1)\n"
25409 "2: \n"
25410 ".section .fixup, \"ax\"\n"
25411 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25412 + "3: \n"
25413 +
25414 +#ifdef CONFIG_PAX_KERNEXEC
25415 + " movl %%cr0, %0\n"
25416 + " movl %0, %%eax\n"
25417 + " andl $0xFFFEFFFF, %%eax\n"
25418 + " movl %%eax, %%cr0\n"
25419 +#endif
25420 +
25421 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25422 +
25423 +#ifdef CONFIG_PAX_KERNEXEC
25424 + " movl %0, %%cr0\n"
25425 +#endif
25426 +
25427 " jmp 2b\n"
25428 ".previous\n"
25429 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
25430 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25431
25432 for (i = 0; i < (4096-320)/64; i++) {
25433 __asm__ __volatile__ (
25434 - "1: prefetch 320(%0)\n"
25435 - "2: movq (%0), %%mm0\n"
25436 - " movntq %%mm0, (%1)\n"
25437 - " movq 8(%0), %%mm1\n"
25438 - " movntq %%mm1, 8(%1)\n"
25439 - " movq 16(%0), %%mm2\n"
25440 - " movntq %%mm2, 16(%1)\n"
25441 - " movq 24(%0), %%mm3\n"
25442 - " movntq %%mm3, 24(%1)\n"
25443 - " movq 32(%0), %%mm4\n"
25444 - " movntq %%mm4, 32(%1)\n"
25445 - " movq 40(%0), %%mm5\n"
25446 - " movntq %%mm5, 40(%1)\n"
25447 - " movq 48(%0), %%mm6\n"
25448 - " movntq %%mm6, 48(%1)\n"
25449 - " movq 56(%0), %%mm7\n"
25450 - " movntq %%mm7, 56(%1)\n"
25451 + "1: prefetch 320(%1)\n"
25452 + "2: movq (%1), %%mm0\n"
25453 + " movntq %%mm0, (%2)\n"
25454 + " movq 8(%1), %%mm1\n"
25455 + " movntq %%mm1, 8(%2)\n"
25456 + " movq 16(%1), %%mm2\n"
25457 + " movntq %%mm2, 16(%2)\n"
25458 + " movq 24(%1), %%mm3\n"
25459 + " movntq %%mm3, 24(%2)\n"
25460 + " movq 32(%1), %%mm4\n"
25461 + " movntq %%mm4, 32(%2)\n"
25462 + " movq 40(%1), %%mm5\n"
25463 + " movntq %%mm5, 40(%2)\n"
25464 + " movq 48(%1), %%mm6\n"
25465 + " movntq %%mm6, 48(%2)\n"
25466 + " movq 56(%1), %%mm7\n"
25467 + " movntq %%mm7, 56(%2)\n"
25468 ".section .fixup, \"ax\"\n"
25469 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25470 + "3:\n"
25471 +
25472 +#ifdef CONFIG_PAX_KERNEXEC
25473 + " movl %%cr0, %0\n"
25474 + " movl %0, %%eax\n"
25475 + " andl $0xFFFEFFFF, %%eax\n"
25476 + " movl %%eax, %%cr0\n"
25477 +#endif
25478 +
25479 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25480 +
25481 +#ifdef CONFIG_PAX_KERNEXEC
25482 + " movl %0, %%cr0\n"
25483 +#endif
25484 +
25485 " jmp 2b\n"
25486 ".previous\n"
25487 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
25488 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25489
25490 from += 64;
25491 to += 64;
25492 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
25493 static void fast_copy_page(void *to, void *from)
25494 {
25495 int i;
25496 + unsigned long cr0;
25497
25498 kernel_fpu_begin();
25499
25500 __asm__ __volatile__ (
25501 - "1: prefetch (%0)\n"
25502 - " prefetch 64(%0)\n"
25503 - " prefetch 128(%0)\n"
25504 - " prefetch 192(%0)\n"
25505 - " prefetch 256(%0)\n"
25506 + "1: prefetch (%1)\n"
25507 + " prefetch 64(%1)\n"
25508 + " prefetch 128(%1)\n"
25509 + " prefetch 192(%1)\n"
25510 + " prefetch 256(%1)\n"
25511 "2: \n"
25512 ".section .fixup, \"ax\"\n"
25513 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25514 + "3: \n"
25515 +
25516 +#ifdef CONFIG_PAX_KERNEXEC
25517 + " movl %%cr0, %0\n"
25518 + " movl %0, %%eax\n"
25519 + " andl $0xFFFEFFFF, %%eax\n"
25520 + " movl %%eax, %%cr0\n"
25521 +#endif
25522 +
25523 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25524 +
25525 +#ifdef CONFIG_PAX_KERNEXEC
25526 + " movl %0, %%cr0\n"
25527 +#endif
25528 +
25529 " jmp 2b\n"
25530 ".previous\n"
25531 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
25532 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25533
25534 for (i = 0; i < 4096/64; i++) {
25535 __asm__ __volatile__ (
25536 - "1: prefetch 320(%0)\n"
25537 - "2: movq (%0), %%mm0\n"
25538 - " movq 8(%0), %%mm1\n"
25539 - " movq 16(%0), %%mm2\n"
25540 - " movq 24(%0), %%mm3\n"
25541 - " movq %%mm0, (%1)\n"
25542 - " movq %%mm1, 8(%1)\n"
25543 - " movq %%mm2, 16(%1)\n"
25544 - " movq %%mm3, 24(%1)\n"
25545 - " movq 32(%0), %%mm0\n"
25546 - " movq 40(%0), %%mm1\n"
25547 - " movq 48(%0), %%mm2\n"
25548 - " movq 56(%0), %%mm3\n"
25549 - " movq %%mm0, 32(%1)\n"
25550 - " movq %%mm1, 40(%1)\n"
25551 - " movq %%mm2, 48(%1)\n"
25552 - " movq %%mm3, 56(%1)\n"
25553 + "1: prefetch 320(%1)\n"
25554 + "2: movq (%1), %%mm0\n"
25555 + " movq 8(%1), %%mm1\n"
25556 + " movq 16(%1), %%mm2\n"
25557 + " movq 24(%1), %%mm3\n"
25558 + " movq %%mm0, (%2)\n"
25559 + " movq %%mm1, 8(%2)\n"
25560 + " movq %%mm2, 16(%2)\n"
25561 + " movq %%mm3, 24(%2)\n"
25562 + " movq 32(%1), %%mm0\n"
25563 + " movq 40(%1), %%mm1\n"
25564 + " movq 48(%1), %%mm2\n"
25565 + " movq 56(%1), %%mm3\n"
25566 + " movq %%mm0, 32(%2)\n"
25567 + " movq %%mm1, 40(%2)\n"
25568 + " movq %%mm2, 48(%2)\n"
25569 + " movq %%mm3, 56(%2)\n"
25570 ".section .fixup, \"ax\"\n"
25571 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25572 + "3:\n"
25573 +
25574 +#ifdef CONFIG_PAX_KERNEXEC
25575 + " movl %%cr0, %0\n"
25576 + " movl %0, %%eax\n"
25577 + " andl $0xFFFEFFFF, %%eax\n"
25578 + " movl %%eax, %%cr0\n"
25579 +#endif
25580 +
25581 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25582 +
25583 +#ifdef CONFIG_PAX_KERNEXEC
25584 + " movl %0, %%cr0\n"
25585 +#endif
25586 +
25587 " jmp 2b\n"
25588 ".previous\n"
25589 _ASM_EXTABLE(1b, 3b)
25590 - : : "r" (from), "r" (to) : "memory");
25591 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25592
25593 from += 64;
25594 to += 64;
25595 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
25596 index f6d13ee..aca5f0b 100644
25597 --- a/arch/x86/lib/msr-reg.S
25598 +++ b/arch/x86/lib/msr-reg.S
25599 @@ -3,6 +3,7 @@
25600 #include <asm/dwarf2.h>
25601 #include <asm/asm.h>
25602 #include <asm/msr.h>
25603 +#include <asm/alternative-asm.h>
25604
25605 #ifdef CONFIG_X86_64
25606 /*
25607 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
25608 CFI_STARTPROC
25609 pushq_cfi %rbx
25610 pushq_cfi %rbp
25611 - movq %rdi, %r10 /* Save pointer */
25612 + movq %rdi, %r9 /* Save pointer */
25613 xorl %r11d, %r11d /* Return value */
25614 movl (%rdi), %eax
25615 movl 4(%rdi), %ecx
25616 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
25617 movl 28(%rdi), %edi
25618 CFI_REMEMBER_STATE
25619 1: \op
25620 -2: movl %eax, (%r10)
25621 +2: movl %eax, (%r9)
25622 movl %r11d, %eax /* Return value */
25623 - movl %ecx, 4(%r10)
25624 - movl %edx, 8(%r10)
25625 - movl %ebx, 12(%r10)
25626 - movl %ebp, 20(%r10)
25627 - movl %esi, 24(%r10)
25628 - movl %edi, 28(%r10)
25629 + movl %ecx, 4(%r9)
25630 + movl %edx, 8(%r9)
25631 + movl %ebx, 12(%r9)
25632 + movl %ebp, 20(%r9)
25633 + movl %esi, 24(%r9)
25634 + movl %edi, 28(%r9)
25635 popq_cfi %rbp
25636 popq_cfi %rbx
25637 + pax_force_retaddr
25638 ret
25639 3:
25640 CFI_RESTORE_STATE
25641 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
25642 index fc6ba17..04471c5 100644
25643 --- a/arch/x86/lib/putuser.S
25644 +++ b/arch/x86/lib/putuser.S
25645 @@ -16,7 +16,9 @@
25646 #include <asm/errno.h>
25647 #include <asm/asm.h>
25648 #include <asm/smap.h>
25649 -
25650 +#include <asm/segment.h>
25651 +#include <asm/pgtable.h>
25652 +#include <asm/alternative-asm.h>
25653
25654 /*
25655 * __put_user_X
25656 @@ -30,57 +32,125 @@
25657 * as they get called from within inline assembly.
25658 */
25659
25660 -#define ENTER CFI_STARTPROC ; \
25661 - GET_THREAD_INFO(%_ASM_BX)
25662 -#define EXIT ASM_CLAC ; \
25663 - ret ; \
25664 +#define ENTER CFI_STARTPROC
25665 +#define EXIT ASM_CLAC ; \
25666 + pax_force_retaddr ; \
25667 + ret ; \
25668 CFI_ENDPROC
25669
25670 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25671 +#define _DEST %_ASM_CX,%_ASM_BX
25672 +#else
25673 +#define _DEST %_ASM_CX
25674 +#endif
25675 +
25676 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25677 +#define __copyuser_seg gs;
25678 +#else
25679 +#define __copyuser_seg
25680 +#endif
25681 +
25682 .text
25683 ENTRY(__put_user_1)
25684 ENTER
25685 +
25686 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25687 + GET_THREAD_INFO(%_ASM_BX)
25688 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
25689 jae bad_put_user
25690 ASM_STAC
25691 -1: movb %al,(%_ASM_CX)
25692 +
25693 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25694 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25695 + cmp %_ASM_BX,%_ASM_CX
25696 + jb 1234f
25697 + xor %ebx,%ebx
25698 +1234:
25699 +#endif
25700 +
25701 +#endif
25702 +
25703 +1: __copyuser_seg movb %al,(_DEST)
25704 xor %eax,%eax
25705 EXIT
25706 ENDPROC(__put_user_1)
25707
25708 ENTRY(__put_user_2)
25709 ENTER
25710 +
25711 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25712 + GET_THREAD_INFO(%_ASM_BX)
25713 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25714 sub $1,%_ASM_BX
25715 cmp %_ASM_BX,%_ASM_CX
25716 jae bad_put_user
25717 ASM_STAC
25718 -2: movw %ax,(%_ASM_CX)
25719 +
25720 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25721 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25722 + cmp %_ASM_BX,%_ASM_CX
25723 + jb 1234f
25724 + xor %ebx,%ebx
25725 +1234:
25726 +#endif
25727 +
25728 +#endif
25729 +
25730 +2: __copyuser_seg movw %ax,(_DEST)
25731 xor %eax,%eax
25732 EXIT
25733 ENDPROC(__put_user_2)
25734
25735 ENTRY(__put_user_4)
25736 ENTER
25737 +
25738 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25739 + GET_THREAD_INFO(%_ASM_BX)
25740 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25741 sub $3,%_ASM_BX
25742 cmp %_ASM_BX,%_ASM_CX
25743 jae bad_put_user
25744 ASM_STAC
25745 -3: movl %eax,(%_ASM_CX)
25746 +
25747 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25748 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25749 + cmp %_ASM_BX,%_ASM_CX
25750 + jb 1234f
25751 + xor %ebx,%ebx
25752 +1234:
25753 +#endif
25754 +
25755 +#endif
25756 +
25757 +3: __copyuser_seg movl %eax,(_DEST)
25758 xor %eax,%eax
25759 EXIT
25760 ENDPROC(__put_user_4)
25761
25762 ENTRY(__put_user_8)
25763 ENTER
25764 +
25765 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25766 + GET_THREAD_INFO(%_ASM_BX)
25767 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25768 sub $7,%_ASM_BX
25769 cmp %_ASM_BX,%_ASM_CX
25770 jae bad_put_user
25771 ASM_STAC
25772 -4: mov %_ASM_AX,(%_ASM_CX)
25773 +
25774 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25775 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25776 + cmp %_ASM_BX,%_ASM_CX
25777 + jb 1234f
25778 + xor %ebx,%ebx
25779 +1234:
25780 +#endif
25781 +
25782 +#endif
25783 +
25784 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
25785 #ifdef CONFIG_X86_32
25786 -5: movl %edx,4(%_ASM_CX)
25787 +5: __copyuser_seg movl %edx,4(_DEST)
25788 #endif
25789 xor %eax,%eax
25790 EXIT
25791 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
25792 index 1cad221..de671ee 100644
25793 --- a/arch/x86/lib/rwlock.S
25794 +++ b/arch/x86/lib/rwlock.S
25795 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
25796 FRAME
25797 0: LOCK_PREFIX
25798 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25799 +
25800 +#ifdef CONFIG_PAX_REFCOUNT
25801 + jno 1234f
25802 + LOCK_PREFIX
25803 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25804 + int $4
25805 +1234:
25806 + _ASM_EXTABLE(1234b, 1234b)
25807 +#endif
25808 +
25809 1: rep; nop
25810 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
25811 jne 1b
25812 LOCK_PREFIX
25813 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25814 +
25815 +#ifdef CONFIG_PAX_REFCOUNT
25816 + jno 1234f
25817 + LOCK_PREFIX
25818 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25819 + int $4
25820 +1234:
25821 + _ASM_EXTABLE(1234b, 1234b)
25822 +#endif
25823 +
25824 jnz 0b
25825 ENDFRAME
25826 + pax_force_retaddr
25827 ret
25828 CFI_ENDPROC
25829 END(__write_lock_failed)
25830 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
25831 FRAME
25832 0: LOCK_PREFIX
25833 READ_LOCK_SIZE(inc) (%__lock_ptr)
25834 +
25835 +#ifdef CONFIG_PAX_REFCOUNT
25836 + jno 1234f
25837 + LOCK_PREFIX
25838 + READ_LOCK_SIZE(dec) (%__lock_ptr)
25839 + int $4
25840 +1234:
25841 + _ASM_EXTABLE(1234b, 1234b)
25842 +#endif
25843 +
25844 1: rep; nop
25845 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
25846 js 1b
25847 LOCK_PREFIX
25848 READ_LOCK_SIZE(dec) (%__lock_ptr)
25849 +
25850 +#ifdef CONFIG_PAX_REFCOUNT
25851 + jno 1234f
25852 + LOCK_PREFIX
25853 + READ_LOCK_SIZE(inc) (%__lock_ptr)
25854 + int $4
25855 +1234:
25856 + _ASM_EXTABLE(1234b, 1234b)
25857 +#endif
25858 +
25859 js 0b
25860 ENDFRAME
25861 + pax_force_retaddr
25862 ret
25863 CFI_ENDPROC
25864 END(__read_lock_failed)
25865 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
25866 index 5dff5f0..cadebf4 100644
25867 --- a/arch/x86/lib/rwsem.S
25868 +++ b/arch/x86/lib/rwsem.S
25869 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
25870 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25871 CFI_RESTORE __ASM_REG(dx)
25872 restore_common_regs
25873 + pax_force_retaddr
25874 ret
25875 CFI_ENDPROC
25876 ENDPROC(call_rwsem_down_read_failed)
25877 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
25878 movq %rax,%rdi
25879 call rwsem_down_write_failed
25880 restore_common_regs
25881 + pax_force_retaddr
25882 ret
25883 CFI_ENDPROC
25884 ENDPROC(call_rwsem_down_write_failed)
25885 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
25886 movq %rax,%rdi
25887 call rwsem_wake
25888 restore_common_regs
25889 -1: ret
25890 +1: pax_force_retaddr
25891 + ret
25892 CFI_ENDPROC
25893 ENDPROC(call_rwsem_wake)
25894
25895 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
25896 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25897 CFI_RESTORE __ASM_REG(dx)
25898 restore_common_regs
25899 + pax_force_retaddr
25900 ret
25901 CFI_ENDPROC
25902 ENDPROC(call_rwsem_downgrade_wake)
25903 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
25904 index a63efd6..ccecad8 100644
25905 --- a/arch/x86/lib/thunk_64.S
25906 +++ b/arch/x86/lib/thunk_64.S
25907 @@ -8,6 +8,7 @@
25908 #include <linux/linkage.h>
25909 #include <asm/dwarf2.h>
25910 #include <asm/calling.h>
25911 +#include <asm/alternative-asm.h>
25912
25913 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
25914 .macro THUNK name, func, put_ret_addr_in_rdi=0
25915 @@ -41,5 +42,6 @@
25916 SAVE_ARGS
25917 restore:
25918 RESTORE_ARGS
25919 + pax_force_retaddr
25920 ret
25921 CFI_ENDPROC
25922 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
25923 index f0312d7..9c39d63 100644
25924 --- a/arch/x86/lib/usercopy_32.c
25925 +++ b/arch/x86/lib/usercopy_32.c
25926 @@ -42,11 +42,13 @@ do { \
25927 int __d0; \
25928 might_fault(); \
25929 __asm__ __volatile__( \
25930 + __COPYUSER_SET_ES \
25931 ASM_STAC "\n" \
25932 "0: rep; stosl\n" \
25933 " movl %2,%0\n" \
25934 "1: rep; stosb\n" \
25935 "2: " ASM_CLAC "\n" \
25936 + __COPYUSER_RESTORE_ES \
25937 ".section .fixup,\"ax\"\n" \
25938 "3: lea 0(%2,%0,4),%0\n" \
25939 " jmp 2b\n" \
25940 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
25941
25942 #ifdef CONFIG_X86_INTEL_USERCOPY
25943 static unsigned long
25944 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
25945 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
25946 {
25947 int d0, d1;
25948 __asm__ __volatile__(
25949 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25950 " .align 2,0x90\n"
25951 "3: movl 0(%4), %%eax\n"
25952 "4: movl 4(%4), %%edx\n"
25953 - "5: movl %%eax, 0(%3)\n"
25954 - "6: movl %%edx, 4(%3)\n"
25955 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
25956 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
25957 "7: movl 8(%4), %%eax\n"
25958 "8: movl 12(%4),%%edx\n"
25959 - "9: movl %%eax, 8(%3)\n"
25960 - "10: movl %%edx, 12(%3)\n"
25961 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
25962 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
25963 "11: movl 16(%4), %%eax\n"
25964 "12: movl 20(%4), %%edx\n"
25965 - "13: movl %%eax, 16(%3)\n"
25966 - "14: movl %%edx, 20(%3)\n"
25967 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
25968 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
25969 "15: movl 24(%4), %%eax\n"
25970 "16: movl 28(%4), %%edx\n"
25971 - "17: movl %%eax, 24(%3)\n"
25972 - "18: movl %%edx, 28(%3)\n"
25973 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
25974 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
25975 "19: movl 32(%4), %%eax\n"
25976 "20: movl 36(%4), %%edx\n"
25977 - "21: movl %%eax, 32(%3)\n"
25978 - "22: movl %%edx, 36(%3)\n"
25979 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
25980 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
25981 "23: movl 40(%4), %%eax\n"
25982 "24: movl 44(%4), %%edx\n"
25983 - "25: movl %%eax, 40(%3)\n"
25984 - "26: movl %%edx, 44(%3)\n"
25985 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
25986 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
25987 "27: movl 48(%4), %%eax\n"
25988 "28: movl 52(%4), %%edx\n"
25989 - "29: movl %%eax, 48(%3)\n"
25990 - "30: movl %%edx, 52(%3)\n"
25991 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
25992 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
25993 "31: movl 56(%4), %%eax\n"
25994 "32: movl 60(%4), %%edx\n"
25995 - "33: movl %%eax, 56(%3)\n"
25996 - "34: movl %%edx, 60(%3)\n"
25997 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
25998 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
25999 " addl $-64, %0\n"
26000 " addl $64, %4\n"
26001 " addl $64, %3\n"
26002 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26003 " shrl $2, %0\n"
26004 " andl $3, %%eax\n"
26005 " cld\n"
26006 + __COPYUSER_SET_ES
26007 "99: rep; movsl\n"
26008 "36: movl %%eax, %0\n"
26009 "37: rep; movsb\n"
26010 "100:\n"
26011 + __COPYUSER_RESTORE_ES
26012 ".section .fixup,\"ax\"\n"
26013 "101: lea 0(%%eax,%0,4),%0\n"
26014 " jmp 100b\n"
26015 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26016 }
26017
26018 static unsigned long
26019 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26020 +{
26021 + int d0, d1;
26022 + __asm__ __volatile__(
26023 + " .align 2,0x90\n"
26024 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26025 + " cmpl $67, %0\n"
26026 + " jbe 3f\n"
26027 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26028 + " .align 2,0x90\n"
26029 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26030 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26031 + "5: movl %%eax, 0(%3)\n"
26032 + "6: movl %%edx, 4(%3)\n"
26033 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26034 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26035 + "9: movl %%eax, 8(%3)\n"
26036 + "10: movl %%edx, 12(%3)\n"
26037 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26038 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26039 + "13: movl %%eax, 16(%3)\n"
26040 + "14: movl %%edx, 20(%3)\n"
26041 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26042 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26043 + "17: movl %%eax, 24(%3)\n"
26044 + "18: movl %%edx, 28(%3)\n"
26045 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26046 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26047 + "21: movl %%eax, 32(%3)\n"
26048 + "22: movl %%edx, 36(%3)\n"
26049 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26050 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26051 + "25: movl %%eax, 40(%3)\n"
26052 + "26: movl %%edx, 44(%3)\n"
26053 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26054 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26055 + "29: movl %%eax, 48(%3)\n"
26056 + "30: movl %%edx, 52(%3)\n"
26057 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26058 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26059 + "33: movl %%eax, 56(%3)\n"
26060 + "34: movl %%edx, 60(%3)\n"
26061 + " addl $-64, %0\n"
26062 + " addl $64, %4\n"
26063 + " addl $64, %3\n"
26064 + " cmpl $63, %0\n"
26065 + " ja 1b\n"
26066 + "35: movl %0, %%eax\n"
26067 + " shrl $2, %0\n"
26068 + " andl $3, %%eax\n"
26069 + " cld\n"
26070 + "99: rep; "__copyuser_seg" movsl\n"
26071 + "36: movl %%eax, %0\n"
26072 + "37: rep; "__copyuser_seg" movsb\n"
26073 + "100:\n"
26074 + ".section .fixup,\"ax\"\n"
26075 + "101: lea 0(%%eax,%0,4),%0\n"
26076 + " jmp 100b\n"
26077 + ".previous\n"
26078 + _ASM_EXTABLE(1b,100b)
26079 + _ASM_EXTABLE(2b,100b)
26080 + _ASM_EXTABLE(3b,100b)
26081 + _ASM_EXTABLE(4b,100b)
26082 + _ASM_EXTABLE(5b,100b)
26083 + _ASM_EXTABLE(6b,100b)
26084 + _ASM_EXTABLE(7b,100b)
26085 + _ASM_EXTABLE(8b,100b)
26086 + _ASM_EXTABLE(9b,100b)
26087 + _ASM_EXTABLE(10b,100b)
26088 + _ASM_EXTABLE(11b,100b)
26089 + _ASM_EXTABLE(12b,100b)
26090 + _ASM_EXTABLE(13b,100b)
26091 + _ASM_EXTABLE(14b,100b)
26092 + _ASM_EXTABLE(15b,100b)
26093 + _ASM_EXTABLE(16b,100b)
26094 + _ASM_EXTABLE(17b,100b)
26095 + _ASM_EXTABLE(18b,100b)
26096 + _ASM_EXTABLE(19b,100b)
26097 + _ASM_EXTABLE(20b,100b)
26098 + _ASM_EXTABLE(21b,100b)
26099 + _ASM_EXTABLE(22b,100b)
26100 + _ASM_EXTABLE(23b,100b)
26101 + _ASM_EXTABLE(24b,100b)
26102 + _ASM_EXTABLE(25b,100b)
26103 + _ASM_EXTABLE(26b,100b)
26104 + _ASM_EXTABLE(27b,100b)
26105 + _ASM_EXTABLE(28b,100b)
26106 + _ASM_EXTABLE(29b,100b)
26107 + _ASM_EXTABLE(30b,100b)
26108 + _ASM_EXTABLE(31b,100b)
26109 + _ASM_EXTABLE(32b,100b)
26110 + _ASM_EXTABLE(33b,100b)
26111 + _ASM_EXTABLE(34b,100b)
26112 + _ASM_EXTABLE(35b,100b)
26113 + _ASM_EXTABLE(36b,100b)
26114 + _ASM_EXTABLE(37b,100b)
26115 + _ASM_EXTABLE(99b,101b)
26116 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
26117 + : "1"(to), "2"(from), "0"(size)
26118 + : "eax", "edx", "memory");
26119 + return size;
26120 +}
26121 +
26122 +static unsigned long __size_overflow(3)
26123 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26124 {
26125 int d0, d1;
26126 __asm__ __volatile__(
26127 " .align 2,0x90\n"
26128 - "0: movl 32(%4), %%eax\n"
26129 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26130 " cmpl $67, %0\n"
26131 " jbe 2f\n"
26132 - "1: movl 64(%4), %%eax\n"
26133 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26134 " .align 2,0x90\n"
26135 - "2: movl 0(%4), %%eax\n"
26136 - "21: movl 4(%4), %%edx\n"
26137 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26138 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26139 " movl %%eax, 0(%3)\n"
26140 " movl %%edx, 4(%3)\n"
26141 - "3: movl 8(%4), %%eax\n"
26142 - "31: movl 12(%4),%%edx\n"
26143 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26144 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26145 " movl %%eax, 8(%3)\n"
26146 " movl %%edx, 12(%3)\n"
26147 - "4: movl 16(%4), %%eax\n"
26148 - "41: movl 20(%4), %%edx\n"
26149 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26150 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26151 " movl %%eax, 16(%3)\n"
26152 " movl %%edx, 20(%3)\n"
26153 - "10: movl 24(%4), %%eax\n"
26154 - "51: movl 28(%4), %%edx\n"
26155 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26156 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26157 " movl %%eax, 24(%3)\n"
26158 " movl %%edx, 28(%3)\n"
26159 - "11: movl 32(%4), %%eax\n"
26160 - "61: movl 36(%4), %%edx\n"
26161 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26162 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26163 " movl %%eax, 32(%3)\n"
26164 " movl %%edx, 36(%3)\n"
26165 - "12: movl 40(%4), %%eax\n"
26166 - "71: movl 44(%4), %%edx\n"
26167 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26168 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26169 " movl %%eax, 40(%3)\n"
26170 " movl %%edx, 44(%3)\n"
26171 - "13: movl 48(%4), %%eax\n"
26172 - "81: movl 52(%4), %%edx\n"
26173 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26174 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26175 " movl %%eax, 48(%3)\n"
26176 " movl %%edx, 52(%3)\n"
26177 - "14: movl 56(%4), %%eax\n"
26178 - "91: movl 60(%4), %%edx\n"
26179 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26180 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26181 " movl %%eax, 56(%3)\n"
26182 " movl %%edx, 60(%3)\n"
26183 " addl $-64, %0\n"
26184 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26185 " shrl $2, %0\n"
26186 " andl $3, %%eax\n"
26187 " cld\n"
26188 - "6: rep; movsl\n"
26189 + "6: rep; "__copyuser_seg" movsl\n"
26190 " movl %%eax,%0\n"
26191 - "7: rep; movsb\n"
26192 + "7: rep; "__copyuser_seg" movsb\n"
26193 "8:\n"
26194 ".section .fixup,\"ax\"\n"
26195 "9: lea 0(%%eax,%0,4),%0\n"
26196 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26197 * hyoshiok@miraclelinux.com
26198 */
26199
26200 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26201 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26202 const void __user *from, unsigned long size)
26203 {
26204 int d0, d1;
26205
26206 __asm__ __volatile__(
26207 " .align 2,0x90\n"
26208 - "0: movl 32(%4), %%eax\n"
26209 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26210 " cmpl $67, %0\n"
26211 " jbe 2f\n"
26212 - "1: movl 64(%4), %%eax\n"
26213 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26214 " .align 2,0x90\n"
26215 - "2: movl 0(%4), %%eax\n"
26216 - "21: movl 4(%4), %%edx\n"
26217 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26218 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26219 " movnti %%eax, 0(%3)\n"
26220 " movnti %%edx, 4(%3)\n"
26221 - "3: movl 8(%4), %%eax\n"
26222 - "31: movl 12(%4),%%edx\n"
26223 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26224 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26225 " movnti %%eax, 8(%3)\n"
26226 " movnti %%edx, 12(%3)\n"
26227 - "4: movl 16(%4), %%eax\n"
26228 - "41: movl 20(%4), %%edx\n"
26229 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26230 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26231 " movnti %%eax, 16(%3)\n"
26232 " movnti %%edx, 20(%3)\n"
26233 - "10: movl 24(%4), %%eax\n"
26234 - "51: movl 28(%4), %%edx\n"
26235 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26236 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26237 " movnti %%eax, 24(%3)\n"
26238 " movnti %%edx, 28(%3)\n"
26239 - "11: movl 32(%4), %%eax\n"
26240 - "61: movl 36(%4), %%edx\n"
26241 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26242 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26243 " movnti %%eax, 32(%3)\n"
26244 " movnti %%edx, 36(%3)\n"
26245 - "12: movl 40(%4), %%eax\n"
26246 - "71: movl 44(%4), %%edx\n"
26247 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26248 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26249 " movnti %%eax, 40(%3)\n"
26250 " movnti %%edx, 44(%3)\n"
26251 - "13: movl 48(%4), %%eax\n"
26252 - "81: movl 52(%4), %%edx\n"
26253 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26254 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26255 " movnti %%eax, 48(%3)\n"
26256 " movnti %%edx, 52(%3)\n"
26257 - "14: movl 56(%4), %%eax\n"
26258 - "91: movl 60(%4), %%edx\n"
26259 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26260 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26261 " movnti %%eax, 56(%3)\n"
26262 " movnti %%edx, 60(%3)\n"
26263 " addl $-64, %0\n"
26264 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26265 " shrl $2, %0\n"
26266 " andl $3, %%eax\n"
26267 " cld\n"
26268 - "6: rep; movsl\n"
26269 + "6: rep; "__copyuser_seg" movsl\n"
26270 " movl %%eax,%0\n"
26271 - "7: rep; movsb\n"
26272 + "7: rep; "__copyuser_seg" movsb\n"
26273 "8:\n"
26274 ".section .fixup,\"ax\"\n"
26275 "9: lea 0(%%eax,%0,4),%0\n"
26276 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26277 return size;
26278 }
26279
26280 -static unsigned long __copy_user_intel_nocache(void *to,
26281 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26282 const void __user *from, unsigned long size)
26283 {
26284 int d0, d1;
26285
26286 __asm__ __volatile__(
26287 " .align 2,0x90\n"
26288 - "0: movl 32(%4), %%eax\n"
26289 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26290 " cmpl $67, %0\n"
26291 " jbe 2f\n"
26292 - "1: movl 64(%4), %%eax\n"
26293 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26294 " .align 2,0x90\n"
26295 - "2: movl 0(%4), %%eax\n"
26296 - "21: movl 4(%4), %%edx\n"
26297 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26298 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26299 " movnti %%eax, 0(%3)\n"
26300 " movnti %%edx, 4(%3)\n"
26301 - "3: movl 8(%4), %%eax\n"
26302 - "31: movl 12(%4),%%edx\n"
26303 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26304 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26305 " movnti %%eax, 8(%3)\n"
26306 " movnti %%edx, 12(%3)\n"
26307 - "4: movl 16(%4), %%eax\n"
26308 - "41: movl 20(%4), %%edx\n"
26309 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26310 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26311 " movnti %%eax, 16(%3)\n"
26312 " movnti %%edx, 20(%3)\n"
26313 - "10: movl 24(%4), %%eax\n"
26314 - "51: movl 28(%4), %%edx\n"
26315 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26316 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26317 " movnti %%eax, 24(%3)\n"
26318 " movnti %%edx, 28(%3)\n"
26319 - "11: movl 32(%4), %%eax\n"
26320 - "61: movl 36(%4), %%edx\n"
26321 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26322 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26323 " movnti %%eax, 32(%3)\n"
26324 " movnti %%edx, 36(%3)\n"
26325 - "12: movl 40(%4), %%eax\n"
26326 - "71: movl 44(%4), %%edx\n"
26327 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26328 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26329 " movnti %%eax, 40(%3)\n"
26330 " movnti %%edx, 44(%3)\n"
26331 - "13: movl 48(%4), %%eax\n"
26332 - "81: movl 52(%4), %%edx\n"
26333 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26334 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26335 " movnti %%eax, 48(%3)\n"
26336 " movnti %%edx, 52(%3)\n"
26337 - "14: movl 56(%4), %%eax\n"
26338 - "91: movl 60(%4), %%edx\n"
26339 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26340 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26341 " movnti %%eax, 56(%3)\n"
26342 " movnti %%edx, 60(%3)\n"
26343 " addl $-64, %0\n"
26344 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26345 " shrl $2, %0\n"
26346 " andl $3, %%eax\n"
26347 " cld\n"
26348 - "6: rep; movsl\n"
26349 + "6: rep; "__copyuser_seg" movsl\n"
26350 " movl %%eax,%0\n"
26351 - "7: rep; movsb\n"
26352 + "7: rep; "__copyuser_seg" movsb\n"
26353 "8:\n"
26354 ".section .fixup,\"ax\"\n"
26355 "9: lea 0(%%eax,%0,4),%0\n"
26356 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26357 */
26358 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26359 unsigned long size);
26360 -unsigned long __copy_user_intel(void __user *to, const void *from,
26361 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26362 + unsigned long size);
26363 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26364 unsigned long size);
26365 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26366 const void __user *from, unsigned long size);
26367 #endif /* CONFIG_X86_INTEL_USERCOPY */
26368
26369 /* Generic arbitrary sized copy. */
26370 -#define __copy_user(to, from, size) \
26371 +#define __copy_user(to, from, size, prefix, set, restore) \
26372 do { \
26373 int __d0, __d1, __d2; \
26374 __asm__ __volatile__( \
26375 + set \
26376 " cmp $7,%0\n" \
26377 " jbe 1f\n" \
26378 " movl %1,%0\n" \
26379 " negl %0\n" \
26380 " andl $7,%0\n" \
26381 " subl %0,%3\n" \
26382 - "4: rep; movsb\n" \
26383 + "4: rep; "prefix"movsb\n" \
26384 " movl %3,%0\n" \
26385 " shrl $2,%0\n" \
26386 " andl $3,%3\n" \
26387 " .align 2,0x90\n" \
26388 - "0: rep; movsl\n" \
26389 + "0: rep; "prefix"movsl\n" \
26390 " movl %3,%0\n" \
26391 - "1: rep; movsb\n" \
26392 + "1: rep; "prefix"movsb\n" \
26393 "2:\n" \
26394 + restore \
26395 ".section .fixup,\"ax\"\n" \
26396 "5: addl %3,%0\n" \
26397 " jmp 2b\n" \
26398 @@ -538,14 +650,14 @@ do { \
26399 " negl %0\n" \
26400 " andl $7,%0\n" \
26401 " subl %0,%3\n" \
26402 - "4: rep; movsb\n" \
26403 + "4: rep; "__copyuser_seg"movsb\n" \
26404 " movl %3,%0\n" \
26405 " shrl $2,%0\n" \
26406 " andl $3,%3\n" \
26407 " .align 2,0x90\n" \
26408 - "0: rep; movsl\n" \
26409 + "0: rep; "__copyuser_seg"movsl\n" \
26410 " movl %3,%0\n" \
26411 - "1: rep; movsb\n" \
26412 + "1: rep; "__copyuser_seg"movsb\n" \
26413 "2:\n" \
26414 ".section .fixup,\"ax\"\n" \
26415 "5: addl %3,%0\n" \
26416 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26417 {
26418 stac();
26419 if (movsl_is_ok(to, from, n))
26420 - __copy_user(to, from, n);
26421 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26422 else
26423 - n = __copy_user_intel(to, from, n);
26424 + n = __generic_copy_to_user_intel(to, from, n);
26425 clac();
26426 return n;
26427 }
26428 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26429 {
26430 stac();
26431 if (movsl_is_ok(to, from, n))
26432 - __copy_user(to, from, n);
26433 + __copy_user(to, from, n, __copyuser_seg, "", "");
26434 else
26435 - n = __copy_user_intel((void __user *)to,
26436 - (const void *)from, n);
26437 + n = __generic_copy_from_user_intel(to, from, n);
26438 clac();
26439 return n;
26440 }
26441 @@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26442 if (n > 64 && cpu_has_xmm2)
26443 n = __copy_user_intel_nocache(to, from, n);
26444 else
26445 - __copy_user(to, from, n);
26446 + __copy_user(to, from, n, __copyuser_seg, "", "");
26447 #else
26448 - __copy_user(to, from, n);
26449 + __copy_user(to, from, n, __copyuser_seg, "", "");
26450 #endif
26451 clac();
26452 return n;
26453 }
26454 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
26455
26456 -/**
26457 - * copy_to_user: - Copy a block of data into user space.
26458 - * @to: Destination address, in user space.
26459 - * @from: Source address, in kernel space.
26460 - * @n: Number of bytes to copy.
26461 - *
26462 - * Context: User context only. This function may sleep.
26463 - *
26464 - * Copy data from kernel space to user space.
26465 - *
26466 - * Returns number of bytes that could not be copied.
26467 - * On success, this will be zero.
26468 - */
26469 -unsigned long
26470 -copy_to_user(void __user *to, const void *from, unsigned long n)
26471 -{
26472 - if (access_ok(VERIFY_WRITE, to, n))
26473 - n = __copy_to_user(to, from, n);
26474 - return n;
26475 -}
26476 -EXPORT_SYMBOL(copy_to_user);
26477 -
26478 -/**
26479 - * copy_from_user: - Copy a block of data from user space.
26480 - * @to: Destination address, in kernel space.
26481 - * @from: Source address, in user space.
26482 - * @n: Number of bytes to copy.
26483 - *
26484 - * Context: User context only. This function may sleep.
26485 - *
26486 - * Copy data from user space to kernel space.
26487 - *
26488 - * Returns number of bytes that could not be copied.
26489 - * On success, this will be zero.
26490 - *
26491 - * If some data could not be copied, this function will pad the copied
26492 - * data to the requested size using zero bytes.
26493 - */
26494 -unsigned long
26495 -_copy_from_user(void *to, const void __user *from, unsigned long n)
26496 -{
26497 - if (access_ok(VERIFY_READ, from, n))
26498 - n = __copy_from_user(to, from, n);
26499 - else
26500 - memset(to, 0, n);
26501 - return n;
26502 -}
26503 -EXPORT_SYMBOL(_copy_from_user);
26504 -
26505 void copy_from_user_overflow(void)
26506 {
26507 WARN(1, "Buffer overflow detected!\n");
26508 }
26509 EXPORT_SYMBOL(copy_from_user_overflow);
26510 +
26511 +void copy_to_user_overflow(void)
26512 +{
26513 + WARN(1, "Buffer overflow detected!\n");
26514 +}
26515 +EXPORT_SYMBOL(copy_to_user_overflow);
26516 +
26517 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26518 +void __set_fs(mm_segment_t x)
26519 +{
26520 + switch (x.seg) {
26521 + case 0:
26522 + loadsegment(gs, 0);
26523 + break;
26524 + case TASK_SIZE_MAX:
26525 + loadsegment(gs, __USER_DS);
26526 + break;
26527 + case -1UL:
26528 + loadsegment(gs, __KERNEL_DS);
26529 + break;
26530 + default:
26531 + BUG();
26532 + }
26533 + return;
26534 +}
26535 +EXPORT_SYMBOL(__set_fs);
26536 +
26537 +void set_fs(mm_segment_t x)
26538 +{
26539 + current_thread_info()->addr_limit = x;
26540 + __set_fs(x);
26541 +}
26542 +EXPORT_SYMBOL(set_fs);
26543 +#endif
26544 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
26545 index 05928aa..b33dea1 100644
26546 --- a/arch/x86/lib/usercopy_64.c
26547 +++ b/arch/x86/lib/usercopy_64.c
26548 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
26549 _ASM_EXTABLE(0b,3b)
26550 _ASM_EXTABLE(1b,2b)
26551 : [size8] "=&c"(size), [dst] "=&D" (__d0)
26552 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
26553 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
26554 [zero] "r" (0UL), [eight] "r" (8UL));
26555 clac();
26556 return size;
26557 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
26558 }
26559 EXPORT_SYMBOL(clear_user);
26560
26561 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
26562 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
26563 {
26564 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
26565 - return copy_user_generic((__force void *)to, (__force void *)from, len);
26566 - }
26567 - return len;
26568 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
26569 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
26570 + return len;
26571 }
26572 EXPORT_SYMBOL(copy_in_user);
26573
26574 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
26575 * it is not necessary to optimize tail handling.
26576 */
26577 unsigned long
26578 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26579 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
26580 {
26581 char c;
26582 unsigned zero_len;
26583 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26584 clac();
26585 return len;
26586 }
26587 +
26588 +void copy_from_user_overflow(void)
26589 +{
26590 + WARN(1, "Buffer overflow detected!\n");
26591 +}
26592 +EXPORT_SYMBOL(copy_from_user_overflow);
26593 +
26594 +void copy_to_user_overflow(void)
26595 +{
26596 + WARN(1, "Buffer overflow detected!\n");
26597 +}
26598 +EXPORT_SYMBOL(copy_to_user_overflow);
26599 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
26600 index 903ec1e..c4166b2 100644
26601 --- a/arch/x86/mm/extable.c
26602 +++ b/arch/x86/mm/extable.c
26603 @@ -6,12 +6,24 @@
26604 static inline unsigned long
26605 ex_insn_addr(const struct exception_table_entry *x)
26606 {
26607 - return (unsigned long)&x->insn + x->insn;
26608 + unsigned long reloc = 0;
26609 +
26610 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26611 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26612 +#endif
26613 +
26614 + return (unsigned long)&x->insn + x->insn + reloc;
26615 }
26616 static inline unsigned long
26617 ex_fixup_addr(const struct exception_table_entry *x)
26618 {
26619 - return (unsigned long)&x->fixup + x->fixup;
26620 + unsigned long reloc = 0;
26621 +
26622 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26623 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26624 +#endif
26625 +
26626 + return (unsigned long)&x->fixup + x->fixup + reloc;
26627 }
26628
26629 int fixup_exception(struct pt_regs *regs)
26630 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
26631 unsigned long new_ip;
26632
26633 #ifdef CONFIG_PNPBIOS
26634 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
26635 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
26636 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
26637 extern u32 pnp_bios_is_utter_crap;
26638 pnp_bios_is_utter_crap = 1;
26639 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
26640 i += 4;
26641 p->fixup -= i;
26642 i += 4;
26643 +
26644 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26645 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
26646 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26647 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26648 +#endif
26649 +
26650 }
26651 }
26652
26653 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
26654 index fb674fd..272f369 100644
26655 --- a/arch/x86/mm/fault.c
26656 +++ b/arch/x86/mm/fault.c
26657 @@ -13,12 +13,19 @@
26658 #include <linux/perf_event.h> /* perf_sw_event */
26659 #include <linux/hugetlb.h> /* hstate_index_to_shift */
26660 #include <linux/prefetch.h> /* prefetchw */
26661 +#include <linux/unistd.h>
26662 +#include <linux/compiler.h>
26663
26664 #include <asm/traps.h> /* dotraplinkage, ... */
26665 #include <asm/pgalloc.h> /* pgd_*(), ... */
26666 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
26667 #include <asm/fixmap.h> /* VSYSCALL_START */
26668 #include <asm/context_tracking.h> /* exception_enter(), ... */
26669 +#include <asm/tlbflush.h>
26670 +
26671 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26672 +#include <asm/stacktrace.h>
26673 +#endif
26674
26675 /*
26676 * Page fault error code bits:
26677 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
26678 int ret = 0;
26679
26680 /* kprobe_running() needs smp_processor_id() */
26681 - if (kprobes_built_in() && !user_mode_vm(regs)) {
26682 + if (kprobes_built_in() && !user_mode(regs)) {
26683 preempt_disable();
26684 if (kprobe_running() && kprobe_fault_handler(regs, 14))
26685 ret = 1;
26686 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
26687 return !instr_lo || (instr_lo>>1) == 1;
26688 case 0x00:
26689 /* Prefetch instruction is 0x0F0D or 0x0F18 */
26690 - if (probe_kernel_address(instr, opcode))
26691 + if (user_mode(regs)) {
26692 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26693 + return 0;
26694 + } else if (probe_kernel_address(instr, opcode))
26695 return 0;
26696
26697 *prefetch = (instr_lo == 0xF) &&
26698 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
26699 while (instr < max_instr) {
26700 unsigned char opcode;
26701
26702 - if (probe_kernel_address(instr, opcode))
26703 + if (user_mode(regs)) {
26704 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26705 + break;
26706 + } else if (probe_kernel_address(instr, opcode))
26707 break;
26708
26709 instr++;
26710 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
26711 force_sig_info(si_signo, &info, tsk);
26712 }
26713
26714 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26715 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
26716 +#endif
26717 +
26718 +#ifdef CONFIG_PAX_EMUTRAMP
26719 +static int pax_handle_fetch_fault(struct pt_regs *regs);
26720 +#endif
26721 +
26722 +#ifdef CONFIG_PAX_PAGEEXEC
26723 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
26724 +{
26725 + pgd_t *pgd;
26726 + pud_t *pud;
26727 + pmd_t *pmd;
26728 +
26729 + pgd = pgd_offset(mm, address);
26730 + if (!pgd_present(*pgd))
26731 + return NULL;
26732 + pud = pud_offset(pgd, address);
26733 + if (!pud_present(*pud))
26734 + return NULL;
26735 + pmd = pmd_offset(pud, address);
26736 + if (!pmd_present(*pmd))
26737 + return NULL;
26738 + return pmd;
26739 +}
26740 +#endif
26741 +
26742 DEFINE_SPINLOCK(pgd_lock);
26743 LIST_HEAD(pgd_list);
26744
26745 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
26746 for (address = VMALLOC_START & PMD_MASK;
26747 address >= TASK_SIZE && address < FIXADDR_TOP;
26748 address += PMD_SIZE) {
26749 +
26750 +#ifdef CONFIG_PAX_PER_CPU_PGD
26751 + unsigned long cpu;
26752 +#else
26753 struct page *page;
26754 +#endif
26755
26756 spin_lock(&pgd_lock);
26757 +
26758 +#ifdef CONFIG_PAX_PER_CPU_PGD
26759 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26760 + pgd_t *pgd = get_cpu_pgd(cpu);
26761 + pmd_t *ret;
26762 +#else
26763 list_for_each_entry(page, &pgd_list, lru) {
26764 + pgd_t *pgd = page_address(page);
26765 spinlock_t *pgt_lock;
26766 pmd_t *ret;
26767
26768 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
26769 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26770
26771 spin_lock(pgt_lock);
26772 - ret = vmalloc_sync_one(page_address(page), address);
26773 +#endif
26774 +
26775 + ret = vmalloc_sync_one(pgd, address);
26776 +
26777 +#ifndef CONFIG_PAX_PER_CPU_PGD
26778 spin_unlock(pgt_lock);
26779 +#endif
26780
26781 if (!ret)
26782 break;
26783 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26784 * an interrupt in the middle of a task switch..
26785 */
26786 pgd_paddr = read_cr3();
26787 +
26788 +#ifdef CONFIG_PAX_PER_CPU_PGD
26789 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
26790 +#endif
26791 +
26792 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
26793 if (!pmd_k)
26794 return -1;
26795 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26796 * happen within a race in page table update. In the later
26797 * case just flush:
26798 */
26799 +
26800 +#ifdef CONFIG_PAX_PER_CPU_PGD
26801 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
26802 + pgd = pgd_offset_cpu(smp_processor_id(), address);
26803 +#else
26804 pgd = pgd_offset(current->active_mm, address);
26805 +#endif
26806 +
26807 pgd_ref = pgd_offset_k(address);
26808 if (pgd_none(*pgd_ref))
26809 return -1;
26810 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
26811 static int is_errata100(struct pt_regs *regs, unsigned long address)
26812 {
26813 #ifdef CONFIG_X86_64
26814 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
26815 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
26816 return 1;
26817 #endif
26818 return 0;
26819 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
26820 }
26821
26822 static const char nx_warning[] = KERN_CRIT
26823 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
26824 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
26825
26826 static void
26827 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26828 @@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26829 if (!oops_may_print())
26830 return;
26831
26832 - if (error_code & PF_INSTR) {
26833 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
26834 unsigned int level;
26835
26836 pte_t *pte = lookup_address(address, &level);
26837
26838 if (pte && pte_present(*pte) && !pte_exec(*pte))
26839 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
26840 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
26841 }
26842
26843 +#ifdef CONFIG_PAX_KERNEXEC
26844 + if (init_mm.start_code <= address && address < init_mm.end_code) {
26845 + if (current->signal->curr_ip)
26846 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
26847 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
26848 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26849 + else
26850 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
26851 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26852 + }
26853 +#endif
26854 +
26855 printk(KERN_ALERT "BUG: unable to handle kernel ");
26856 if (address < PAGE_SIZE)
26857 printk(KERN_CONT "NULL pointer dereference");
26858 @@ -748,6 +830,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
26859 return;
26860 }
26861 #endif
26862 +
26863 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26864 + if (pax_is_fetch_fault(regs, error_code, address)) {
26865 +
26866 +#ifdef CONFIG_PAX_EMUTRAMP
26867 + switch (pax_handle_fetch_fault(regs)) {
26868 + case 2:
26869 + return;
26870 + }
26871 +#endif
26872 +
26873 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26874 + do_group_exit(SIGKILL);
26875 + }
26876 +#endif
26877 +
26878 /* Kernel addresses are always protection faults: */
26879 if (address >= TASK_SIZE)
26880 error_code |= PF_PROT;
26881 @@ -833,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
26882 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
26883 printk(KERN_ERR
26884 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
26885 - tsk->comm, tsk->pid, address);
26886 + tsk->comm, task_pid_nr(tsk), address);
26887 code = BUS_MCEERR_AR;
26888 }
26889 #endif
26890 @@ -896,6 +994,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
26891 return 1;
26892 }
26893
26894 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26895 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
26896 +{
26897 + pte_t *pte;
26898 + pmd_t *pmd;
26899 + spinlock_t *ptl;
26900 + unsigned char pte_mask;
26901 +
26902 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
26903 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
26904 + return 0;
26905 +
26906 + /* PaX: it's our fault, let's handle it if we can */
26907 +
26908 + /* PaX: take a look at read faults before acquiring any locks */
26909 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
26910 + /* instruction fetch attempt from a protected page in user mode */
26911 + up_read(&mm->mmap_sem);
26912 +
26913 +#ifdef CONFIG_PAX_EMUTRAMP
26914 + switch (pax_handle_fetch_fault(regs)) {
26915 + case 2:
26916 + return 1;
26917 + }
26918 +#endif
26919 +
26920 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26921 + do_group_exit(SIGKILL);
26922 + }
26923 +
26924 + pmd = pax_get_pmd(mm, address);
26925 + if (unlikely(!pmd))
26926 + return 0;
26927 +
26928 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
26929 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
26930 + pte_unmap_unlock(pte, ptl);
26931 + return 0;
26932 + }
26933 +
26934 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
26935 + /* write attempt to a protected page in user mode */
26936 + pte_unmap_unlock(pte, ptl);
26937 + return 0;
26938 + }
26939 +
26940 +#ifdef CONFIG_SMP
26941 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
26942 +#else
26943 + if (likely(address > get_limit(regs->cs)))
26944 +#endif
26945 + {
26946 + set_pte(pte, pte_mkread(*pte));
26947 + __flush_tlb_one(address);
26948 + pte_unmap_unlock(pte, ptl);
26949 + up_read(&mm->mmap_sem);
26950 + return 1;
26951 + }
26952 +
26953 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
26954 +
26955 + /*
26956 + * PaX: fill DTLB with user rights and retry
26957 + */
26958 + __asm__ __volatile__ (
26959 + "orb %2,(%1)\n"
26960 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
26961 +/*
26962 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
26963 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
26964 + * page fault when examined during a TLB load attempt. this is true not only
26965 + * for PTEs holding a non-present entry but also present entries that will
26966 + * raise a page fault (such as those set up by PaX, or the copy-on-write
26967 + * mechanism). in effect it means that we do *not* need to flush the TLBs
26968 + * for our target pages since their PTEs are simply not in the TLBs at all.
26969 +
26970 + * the best thing in omitting it is that we gain around 15-20% speed in the
26971 + * fast path of the page fault handler and can get rid of tracing since we
26972 + * can no longer flush unintended entries.
26973 + */
26974 + "invlpg (%0)\n"
26975 +#endif
26976 + __copyuser_seg"testb $0,(%0)\n"
26977 + "xorb %3,(%1)\n"
26978 + :
26979 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
26980 + : "memory", "cc");
26981 + pte_unmap_unlock(pte, ptl);
26982 + up_read(&mm->mmap_sem);
26983 + return 1;
26984 +}
26985 +#endif
26986 +
26987 /*
26988 * Handle a spurious fault caused by a stale TLB entry.
26989 *
26990 @@ -968,6 +1159,9 @@ int show_unhandled_signals = 1;
26991 static inline int
26992 access_error(unsigned long error_code, struct vm_area_struct *vma)
26993 {
26994 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
26995 + return 1;
26996 +
26997 if (error_code & PF_WRITE) {
26998 /* write, present and write, not present: */
26999 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27000 @@ -996,7 +1190,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27001 if (error_code & PF_USER)
27002 return false;
27003
27004 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27005 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27006 return false;
27007
27008 return true;
27009 @@ -1012,18 +1206,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27010 {
27011 struct vm_area_struct *vma;
27012 struct task_struct *tsk;
27013 - unsigned long address;
27014 struct mm_struct *mm;
27015 int fault;
27016 int write = error_code & PF_WRITE;
27017 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27018 (write ? FAULT_FLAG_WRITE : 0);
27019
27020 - tsk = current;
27021 - mm = tsk->mm;
27022 -
27023 /* Get the faulting address: */
27024 - address = read_cr2();
27025 + unsigned long address = read_cr2();
27026 +
27027 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27028 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
27029 + if (!search_exception_tables(regs->ip)) {
27030 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27031 + bad_area_nosemaphore(regs, error_code, address);
27032 + return;
27033 + }
27034 + if (address < PAX_USER_SHADOW_BASE) {
27035 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27036 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27037 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27038 + } else
27039 + address -= PAX_USER_SHADOW_BASE;
27040 + }
27041 +#endif
27042 +
27043 + tsk = current;
27044 + mm = tsk->mm;
27045
27046 /*
27047 * Detect and handle instructions that would cause a page fault for
27048 @@ -1084,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27049 * User-mode registers count as a user access even for any
27050 * potential system fault or CPU buglet:
27051 */
27052 - if (user_mode_vm(regs)) {
27053 + if (user_mode(regs)) {
27054 local_irq_enable();
27055 error_code |= PF_USER;
27056 } else {
27057 @@ -1146,6 +1355,11 @@ retry:
27058 might_sleep();
27059 }
27060
27061 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27062 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27063 + return;
27064 +#endif
27065 +
27066 vma = find_vma(mm, address);
27067 if (unlikely(!vma)) {
27068 bad_area(regs, error_code, address);
27069 @@ -1157,18 +1371,24 @@ retry:
27070 bad_area(regs, error_code, address);
27071 return;
27072 }
27073 - if (error_code & PF_USER) {
27074 - /*
27075 - * Accessing the stack below %sp is always a bug.
27076 - * The large cushion allows instructions like enter
27077 - * and pusha to work. ("enter $65535, $31" pushes
27078 - * 32 pointers and then decrements %sp by 65535.)
27079 - */
27080 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27081 - bad_area(regs, error_code, address);
27082 - return;
27083 - }
27084 + /*
27085 + * Accessing the stack below %sp is always a bug.
27086 + * The large cushion allows instructions like enter
27087 + * and pusha to work. ("enter $65535, $31" pushes
27088 + * 32 pointers and then decrements %sp by 65535.)
27089 + */
27090 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27091 + bad_area(regs, error_code, address);
27092 + return;
27093 }
27094 +
27095 +#ifdef CONFIG_PAX_SEGMEXEC
27096 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27097 + bad_area(regs, error_code, address);
27098 + return;
27099 + }
27100 +#endif
27101 +
27102 if (unlikely(expand_stack(vma, address))) {
27103 bad_area(regs, error_code, address);
27104 return;
27105 @@ -1232,3 +1452,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27106 __do_page_fault(regs, error_code);
27107 exception_exit(regs);
27108 }
27109 +
27110 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27111 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27112 +{
27113 + struct mm_struct *mm = current->mm;
27114 + unsigned long ip = regs->ip;
27115 +
27116 + if (v8086_mode(regs))
27117 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27118 +
27119 +#ifdef CONFIG_PAX_PAGEEXEC
27120 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27121 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27122 + return true;
27123 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27124 + return true;
27125 + return false;
27126 + }
27127 +#endif
27128 +
27129 +#ifdef CONFIG_PAX_SEGMEXEC
27130 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27131 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27132 + return true;
27133 + return false;
27134 + }
27135 +#endif
27136 +
27137 + return false;
27138 +}
27139 +#endif
27140 +
27141 +#ifdef CONFIG_PAX_EMUTRAMP
27142 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27143 +{
27144 + int err;
27145 +
27146 + do { /* PaX: libffi trampoline emulation */
27147 + unsigned char mov, jmp;
27148 + unsigned int addr1, addr2;
27149 +
27150 +#ifdef CONFIG_X86_64
27151 + if ((regs->ip + 9) >> 32)
27152 + break;
27153 +#endif
27154 +
27155 + err = get_user(mov, (unsigned char __user *)regs->ip);
27156 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27157 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27158 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27159 +
27160 + if (err)
27161 + break;
27162 +
27163 + if (mov == 0xB8 && jmp == 0xE9) {
27164 + regs->ax = addr1;
27165 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27166 + return 2;
27167 + }
27168 + } while (0);
27169 +
27170 + do { /* PaX: gcc trampoline emulation #1 */
27171 + unsigned char mov1, mov2;
27172 + unsigned short jmp;
27173 + unsigned int addr1, addr2;
27174 +
27175 +#ifdef CONFIG_X86_64
27176 + if ((regs->ip + 11) >> 32)
27177 + break;
27178 +#endif
27179 +
27180 + err = get_user(mov1, (unsigned char __user *)regs->ip);
27181 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27182 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27183 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27184 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27185 +
27186 + if (err)
27187 + break;
27188 +
27189 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27190 + regs->cx = addr1;
27191 + regs->ax = addr2;
27192 + regs->ip = addr2;
27193 + return 2;
27194 + }
27195 + } while (0);
27196 +
27197 + do { /* PaX: gcc trampoline emulation #2 */
27198 + unsigned char mov, jmp;
27199 + unsigned int addr1, addr2;
27200 +
27201 +#ifdef CONFIG_X86_64
27202 + if ((regs->ip + 9) >> 32)
27203 + break;
27204 +#endif
27205 +
27206 + err = get_user(mov, (unsigned char __user *)regs->ip);
27207 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27208 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27209 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27210 +
27211 + if (err)
27212 + break;
27213 +
27214 + if (mov == 0xB9 && jmp == 0xE9) {
27215 + regs->cx = addr1;
27216 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27217 + return 2;
27218 + }
27219 + } while (0);
27220 +
27221 + return 1; /* PaX in action */
27222 +}
27223 +
27224 +#ifdef CONFIG_X86_64
27225 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27226 +{
27227 + int err;
27228 +
27229 + do { /* PaX: libffi trampoline emulation */
27230 + unsigned short mov1, mov2, jmp1;
27231 + unsigned char stcclc, jmp2;
27232 + unsigned long addr1, addr2;
27233 +
27234 + err = get_user(mov1, (unsigned short __user *)regs->ip);
27235 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27236 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27237 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27238 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27239 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27240 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27241 +
27242 + if (err)
27243 + break;
27244 +
27245 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27246 + regs->r11 = addr1;
27247 + regs->r10 = addr2;
27248 + if (stcclc == 0xF8)
27249 + regs->flags &= ~X86_EFLAGS_CF;
27250 + else
27251 + regs->flags |= X86_EFLAGS_CF;
27252 + regs->ip = addr1;
27253 + return 2;
27254 + }
27255 + } while (0);
27256 +
27257 + do { /* PaX: gcc trampoline emulation #1 */
27258 + unsigned short mov1, mov2, jmp1;
27259 + unsigned char jmp2;
27260 + unsigned int addr1;
27261 + unsigned long addr2;
27262 +
27263 + err = get_user(mov1, (unsigned short __user *)regs->ip);
27264 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27265 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27266 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27267 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27268 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27269 +
27270 + if (err)
27271 + break;
27272 +
27273 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27274 + regs->r11 = addr1;
27275 + regs->r10 = addr2;
27276 + regs->ip = addr1;
27277 + return 2;
27278 + }
27279 + } while (0);
27280 +
27281 + do { /* PaX: gcc trampoline emulation #2 */
27282 + unsigned short mov1, mov2, jmp1;
27283 + unsigned char jmp2;
27284 + unsigned long addr1, addr2;
27285 +
27286 + err = get_user(mov1, (unsigned short __user *)regs->ip);
27287 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27288 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27289 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27290 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27291 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27292 +
27293 + if (err)
27294 + break;
27295 +
27296 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27297 + regs->r11 = addr1;
27298 + regs->r10 = addr2;
27299 + regs->ip = addr1;
27300 + return 2;
27301 + }
27302 + } while (0);
27303 +
27304 + return 1; /* PaX in action */
27305 +}
27306 +#endif
27307 +
27308 +/*
27309 + * PaX: decide what to do with offenders (regs->ip = fault address)
27310 + *
27311 + * returns 1 when task should be killed
27312 + * 2 when gcc trampoline was detected
27313 + */
27314 +static int pax_handle_fetch_fault(struct pt_regs *regs)
27315 +{
27316 + if (v8086_mode(regs))
27317 + return 1;
27318 +
27319 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27320 + return 1;
27321 +
27322 +#ifdef CONFIG_X86_32
27323 + return pax_handle_fetch_fault_32(regs);
27324 +#else
27325 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27326 + return pax_handle_fetch_fault_32(regs);
27327 + else
27328 + return pax_handle_fetch_fault_64(regs);
27329 +#endif
27330 +}
27331 +#endif
27332 +
27333 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27334 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27335 +{
27336 + long i;
27337 +
27338 + printk(KERN_ERR "PAX: bytes at PC: ");
27339 + for (i = 0; i < 20; i++) {
27340 + unsigned char c;
27341 + if (get_user(c, (unsigned char __force_user *)pc+i))
27342 + printk(KERN_CONT "?? ");
27343 + else
27344 + printk(KERN_CONT "%02x ", c);
27345 + }
27346 + printk("\n");
27347 +
27348 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27349 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
27350 + unsigned long c;
27351 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
27352 +#ifdef CONFIG_X86_32
27353 + printk(KERN_CONT "???????? ");
27354 +#else
27355 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27356 + printk(KERN_CONT "???????? ???????? ");
27357 + else
27358 + printk(KERN_CONT "???????????????? ");
27359 +#endif
27360 + } else {
27361 +#ifdef CONFIG_X86_64
27362 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27363 + printk(KERN_CONT "%08x ", (unsigned int)c);
27364 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27365 + } else
27366 +#endif
27367 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27368 + }
27369 + }
27370 + printk("\n");
27371 +}
27372 +#endif
27373 +
27374 +/**
27375 + * probe_kernel_write(): safely attempt to write to a location
27376 + * @dst: address to write to
27377 + * @src: pointer to the data that shall be written
27378 + * @size: size of the data chunk
27379 + *
27380 + * Safely write to address @dst from the buffer at @src. If a kernel fault
27381 + * happens, handle that and return -EFAULT.
27382 + */
27383 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27384 +{
27385 + long ret;
27386 + mm_segment_t old_fs = get_fs();
27387 +
27388 + set_fs(KERNEL_DS);
27389 + pagefault_disable();
27390 + pax_open_kernel();
27391 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27392 + pax_close_kernel();
27393 + pagefault_enable();
27394 + set_fs(old_fs);
27395 +
27396 + return ret ? -EFAULT : 0;
27397 +}
27398 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27399 index dd74e46..7d26398 100644
27400 --- a/arch/x86/mm/gup.c
27401 +++ b/arch/x86/mm/gup.c
27402 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27403 addr = start;
27404 len = (unsigned long) nr_pages << PAGE_SHIFT;
27405 end = start + len;
27406 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27407 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27408 (void __user *)start, len)))
27409 return 0;
27410
27411 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27412 index 6f31ee5..8ee4164 100644
27413 --- a/arch/x86/mm/highmem_32.c
27414 +++ b/arch/x86/mm/highmem_32.c
27415 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27416 idx = type + KM_TYPE_NR*smp_processor_id();
27417 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27418 BUG_ON(!pte_none(*(kmap_pte-idx)));
27419 +
27420 + pax_open_kernel();
27421 set_pte(kmap_pte-idx, mk_pte(page, prot));
27422 + pax_close_kernel();
27423 +
27424 arch_flush_lazy_mmu_mode();
27425
27426 return (void *)vaddr;
27427 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27428 index ae1aa71..56316db 100644
27429 --- a/arch/x86/mm/hugetlbpage.c
27430 +++ b/arch/x86/mm/hugetlbpage.c
27431 @@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27432 info.flags = 0;
27433 info.length = len;
27434 info.low_limit = TASK_UNMAPPED_BASE;
27435 +
27436 +#ifdef CONFIG_PAX_RANDMMAP
27437 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27438 + info.low_limit += current->mm->delta_mmap;
27439 +#endif
27440 +
27441 info.high_limit = TASK_SIZE;
27442 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27443 info.align_offset = 0;
27444 @@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
27445 VM_BUG_ON(addr != -ENOMEM);
27446 info.flags = 0;
27447 info.low_limit = TASK_UNMAPPED_BASE;
27448 +
27449 +#ifdef CONFIG_PAX_RANDMMAP
27450 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27451 + info.low_limit += current->mm->delta_mmap;
27452 +#endif
27453 +
27454 info.high_limit = TASK_SIZE;
27455 addr = vm_unmapped_area(&info);
27456 }
27457 @@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27458 struct hstate *h = hstate_file(file);
27459 struct mm_struct *mm = current->mm;
27460 struct vm_area_struct *vma;
27461 + unsigned long pax_task_size = TASK_SIZE;
27462 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
27463
27464 if (len & ~huge_page_mask(h))
27465 return -EINVAL;
27466 - if (len > TASK_SIZE)
27467 +
27468 +#ifdef CONFIG_PAX_SEGMEXEC
27469 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27470 + pax_task_size = SEGMEXEC_TASK_SIZE;
27471 +#endif
27472 +
27473 + pax_task_size -= PAGE_SIZE;
27474 +
27475 + if (len > pax_task_size)
27476 return -ENOMEM;
27477
27478 if (flags & MAP_FIXED) {
27479 @@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27480 return addr;
27481 }
27482
27483 +#ifdef CONFIG_PAX_RANDMMAP
27484 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27485 +#endif
27486 +
27487 if (addr) {
27488 addr = ALIGN(addr, huge_page_size(h));
27489 vma = find_vma(mm, addr);
27490 - if (TASK_SIZE - len >= addr &&
27491 - (!vma || addr + len <= vma->vm_start))
27492 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27493 return addr;
27494 }
27495 if (mm->get_unmapped_area == arch_get_unmapped_area)
27496 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
27497 index d7aea41..0fc945b 100644
27498 --- a/arch/x86/mm/init.c
27499 +++ b/arch/x86/mm/init.c
27500 @@ -4,6 +4,7 @@
27501 #include <linux/swap.h>
27502 #include <linux/memblock.h>
27503 #include <linux/bootmem.h> /* for max_low_pfn */
27504 +#include <linux/tboot.h>
27505
27506 #include <asm/cacheflush.h>
27507 #include <asm/e820.h>
27508 @@ -16,6 +17,8 @@
27509 #include <asm/tlb.h>
27510 #include <asm/proto.h>
27511 #include <asm/dma.h> /* for MAX_DMA_PFN */
27512 +#include <asm/desc.h>
27513 +#include <asm/bios_ebda.h>
27514
27515 unsigned long __initdata pgt_buf_start;
27516 unsigned long __meminitdata pgt_buf_end;
27517 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
27518 {
27519 int i;
27520 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
27521 - unsigned long start = 0, good_end;
27522 + unsigned long start = 0x100000, good_end;
27523 phys_addr_t base;
27524
27525 for (i = 0; i < nr_range; i++) {
27526 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
27527 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
27528 * mmio resources as well as potential bios/acpi data regions.
27529 */
27530 +
27531 +#ifdef CONFIG_GRKERNSEC_KMEM
27532 +static unsigned int ebda_start __read_only;
27533 +static unsigned int ebda_end __read_only;
27534 +#endif
27535 +
27536 int devmem_is_allowed(unsigned long pagenr)
27537 {
27538 - if (pagenr < 256)
27539 +#ifdef CONFIG_GRKERNSEC_KMEM
27540 + /* allow BDA */
27541 + if (!pagenr)
27542 return 1;
27543 + /* allow EBDA */
27544 + if (pagenr >= ebda_start && pagenr < ebda_end)
27545 + return 1;
27546 + /* if tboot is in use, allow access to its hardcoded serial log range */
27547 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
27548 + return 1;
27549 +#else
27550 + if (!pagenr)
27551 + return 1;
27552 +#ifdef CONFIG_VM86
27553 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
27554 + return 1;
27555 +#endif
27556 +#endif
27557 +
27558 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
27559 + return 1;
27560 +#ifdef CONFIG_GRKERNSEC_KMEM
27561 + /* throw out everything else below 1MB */
27562 + if (pagenr <= 256)
27563 + return 0;
27564 +#endif
27565 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
27566 return 0;
27567 if (!page_is_ram(pagenr))
27568 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
27569 #endif
27570 }
27571
27572 +#ifdef CONFIG_GRKERNSEC_KMEM
27573 +static inline void gr_init_ebda(void)
27574 +{
27575 + unsigned int ebda_addr;
27576 + unsigned int ebda_size = 0;
27577 +
27578 + ebda_addr = get_bios_ebda();
27579 + if (ebda_addr) {
27580 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
27581 + ebda_size <<= 10;
27582 + }
27583 + if (ebda_addr && ebda_size) {
27584 + ebda_start = ebda_addr >> PAGE_SHIFT;
27585 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
27586 + } else {
27587 + ebda_start = 0x9f000 >> PAGE_SHIFT;
27588 + ebda_end = 0xa0000 >> PAGE_SHIFT;
27589 + }
27590 +}
27591 +#else
27592 +static inline void gr_init_ebda(void) { }
27593 +#endif
27594 +
27595 void free_initmem(void)
27596 {
27597 +#ifdef CONFIG_PAX_KERNEXEC
27598 +#ifdef CONFIG_X86_32
27599 + /* PaX: limit KERNEL_CS to actual size */
27600 + unsigned long addr, limit;
27601 + struct desc_struct d;
27602 + int cpu;
27603 +#else
27604 + pgd_t *pgd;
27605 + pud_t *pud;
27606 + pmd_t *pmd;
27607 + unsigned long addr, end;
27608 +#endif
27609 +#endif
27610 +
27611 + gr_init_ebda();
27612 +
27613 +#ifdef CONFIG_PAX_KERNEXEC
27614 +#ifdef CONFIG_X86_32
27615 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
27616 + limit = (limit - 1UL) >> PAGE_SHIFT;
27617 +
27618 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
27619 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27620 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
27621 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
27622 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
27623 + }
27624 +
27625 + /* PaX: make KERNEL_CS read-only */
27626 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
27627 + if (!paravirt_enabled())
27628 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
27629 +/*
27630 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
27631 + pgd = pgd_offset_k(addr);
27632 + pud = pud_offset(pgd, addr);
27633 + pmd = pmd_offset(pud, addr);
27634 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27635 + }
27636 +*/
27637 +#ifdef CONFIG_X86_PAE
27638 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
27639 +/*
27640 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
27641 + pgd = pgd_offset_k(addr);
27642 + pud = pud_offset(pgd, addr);
27643 + pmd = pmd_offset(pud, addr);
27644 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27645 + }
27646 +*/
27647 +#endif
27648 +
27649 +#ifdef CONFIG_MODULES
27650 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
27651 +#endif
27652 +
27653 +#else
27654 + /* PaX: make kernel code/rodata read-only, rest non-executable */
27655 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
27656 + pgd = pgd_offset_k(addr);
27657 + pud = pud_offset(pgd, addr);
27658 + pmd = pmd_offset(pud, addr);
27659 + if (!pmd_present(*pmd))
27660 + continue;
27661 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
27662 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27663 + else
27664 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27665 + }
27666 +
27667 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
27668 + end = addr + KERNEL_IMAGE_SIZE;
27669 + for (; addr < end; addr += PMD_SIZE) {
27670 + pgd = pgd_offset_k(addr);
27671 + pud = pud_offset(pgd, addr);
27672 + pmd = pmd_offset(pud, addr);
27673 + if (!pmd_present(*pmd))
27674 + continue;
27675 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
27676 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27677 + }
27678 +#endif
27679 +
27680 + flush_tlb_all();
27681 +#endif
27682 +
27683 free_init_pages("unused kernel memory",
27684 (unsigned long)(&__init_begin),
27685 (unsigned long)(&__init_end));
27686 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
27687 index 745d66b..56bf568 100644
27688 --- a/arch/x86/mm/init_32.c
27689 +++ b/arch/x86/mm/init_32.c
27690 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
27691 }
27692
27693 /*
27694 - * Creates a middle page table and puts a pointer to it in the
27695 - * given global directory entry. This only returns the gd entry
27696 - * in non-PAE compilation mode, since the middle layer is folded.
27697 - */
27698 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
27699 -{
27700 - pud_t *pud;
27701 - pmd_t *pmd_table;
27702 -
27703 -#ifdef CONFIG_X86_PAE
27704 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
27705 - if (after_bootmem)
27706 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
27707 - else
27708 - pmd_table = (pmd_t *)alloc_low_page();
27709 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
27710 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
27711 - pud = pud_offset(pgd, 0);
27712 - BUG_ON(pmd_table != pmd_offset(pud, 0));
27713 -
27714 - return pmd_table;
27715 - }
27716 -#endif
27717 - pud = pud_offset(pgd, 0);
27718 - pmd_table = pmd_offset(pud, 0);
27719 -
27720 - return pmd_table;
27721 -}
27722 -
27723 -/*
27724 * Create a page table and place a pointer to it in a middle page
27725 * directory entry:
27726 */
27727 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
27728 page_table = (pte_t *)alloc_low_page();
27729
27730 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
27731 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27732 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
27733 +#else
27734 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
27735 +#endif
27736 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
27737 }
27738
27739 return pte_offset_kernel(pmd, 0);
27740 }
27741
27742 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
27743 +{
27744 + pud_t *pud;
27745 + pmd_t *pmd_table;
27746 +
27747 + pud = pud_offset(pgd, 0);
27748 + pmd_table = pmd_offset(pud, 0);
27749 +
27750 + return pmd_table;
27751 +}
27752 +
27753 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
27754 {
27755 int pgd_idx = pgd_index(vaddr);
27756 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27757 int pgd_idx, pmd_idx;
27758 unsigned long vaddr;
27759 pgd_t *pgd;
27760 + pud_t *pud;
27761 pmd_t *pmd;
27762 pte_t *pte = NULL;
27763
27764 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27765 pgd = pgd_base + pgd_idx;
27766
27767 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
27768 - pmd = one_md_table_init(pgd);
27769 - pmd = pmd + pmd_index(vaddr);
27770 + pud = pud_offset(pgd, vaddr);
27771 + pmd = pmd_offset(pud, vaddr);
27772 +
27773 +#ifdef CONFIG_X86_PAE
27774 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27775 +#endif
27776 +
27777 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
27778 pmd++, pmd_idx++) {
27779 pte = page_table_kmap_check(one_page_table_init(pmd),
27780 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27781 }
27782 }
27783
27784 -static inline int is_kernel_text(unsigned long addr)
27785 +static inline int is_kernel_text(unsigned long start, unsigned long end)
27786 {
27787 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
27788 - return 1;
27789 - return 0;
27790 + if ((start > ktla_ktva((unsigned long)_etext) ||
27791 + end <= ktla_ktva((unsigned long)_stext)) &&
27792 + (start > ktla_ktva((unsigned long)_einittext) ||
27793 + end <= ktla_ktva((unsigned long)_sinittext)) &&
27794 +
27795 +#ifdef CONFIG_ACPI_SLEEP
27796 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
27797 +#endif
27798 +
27799 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
27800 + return 0;
27801 + return 1;
27802 }
27803
27804 /*
27805 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
27806 unsigned long last_map_addr = end;
27807 unsigned long start_pfn, end_pfn;
27808 pgd_t *pgd_base = swapper_pg_dir;
27809 - int pgd_idx, pmd_idx, pte_ofs;
27810 + unsigned int pgd_idx, pmd_idx, pte_ofs;
27811 unsigned long pfn;
27812 pgd_t *pgd;
27813 + pud_t *pud;
27814 pmd_t *pmd;
27815 pte_t *pte;
27816 unsigned pages_2m, pages_4k;
27817 @@ -280,8 +281,13 @@ repeat:
27818 pfn = start_pfn;
27819 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27820 pgd = pgd_base + pgd_idx;
27821 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
27822 - pmd = one_md_table_init(pgd);
27823 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
27824 + pud = pud_offset(pgd, 0);
27825 + pmd = pmd_offset(pud, 0);
27826 +
27827 +#ifdef CONFIG_X86_PAE
27828 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27829 +#endif
27830
27831 if (pfn >= end_pfn)
27832 continue;
27833 @@ -293,14 +299,13 @@ repeat:
27834 #endif
27835 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
27836 pmd++, pmd_idx++) {
27837 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
27838 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
27839
27840 /*
27841 * Map with big pages if possible, otherwise
27842 * create normal page tables:
27843 */
27844 if (use_pse) {
27845 - unsigned int addr2;
27846 pgprot_t prot = PAGE_KERNEL_LARGE;
27847 /*
27848 * first pass will use the same initial
27849 @@ -310,11 +315,7 @@ repeat:
27850 __pgprot(PTE_IDENT_ATTR |
27851 _PAGE_PSE);
27852
27853 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
27854 - PAGE_OFFSET + PAGE_SIZE-1;
27855 -
27856 - if (is_kernel_text(addr) ||
27857 - is_kernel_text(addr2))
27858 + if (is_kernel_text(address, address + PMD_SIZE))
27859 prot = PAGE_KERNEL_LARGE_EXEC;
27860
27861 pages_2m++;
27862 @@ -331,7 +332,7 @@ repeat:
27863 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27864 pte += pte_ofs;
27865 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
27866 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
27867 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
27868 pgprot_t prot = PAGE_KERNEL;
27869 /*
27870 * first pass will use the same initial
27871 @@ -339,7 +340,7 @@ repeat:
27872 */
27873 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
27874
27875 - if (is_kernel_text(addr))
27876 + if (is_kernel_text(address, address + PAGE_SIZE))
27877 prot = PAGE_KERNEL_EXEC;
27878
27879 pages_4k++;
27880 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
27881
27882 pud = pud_offset(pgd, va);
27883 pmd = pmd_offset(pud, va);
27884 - if (!pmd_present(*pmd))
27885 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
27886 break;
27887
27888 pte = pte_offset_kernel(pmd, va);
27889 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
27890
27891 static void __init pagetable_init(void)
27892 {
27893 - pgd_t *pgd_base = swapper_pg_dir;
27894 -
27895 - permanent_kmaps_init(pgd_base);
27896 + permanent_kmaps_init(swapper_pg_dir);
27897 }
27898
27899 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27900 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27901 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27902
27903 /* user-defined highmem size */
27904 @@ -728,6 +727,12 @@ void __init mem_init(void)
27905
27906 pci_iommu_alloc();
27907
27908 +#ifdef CONFIG_PAX_PER_CPU_PGD
27909 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27910 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27911 + KERNEL_PGD_PTRS);
27912 +#endif
27913 +
27914 #ifdef CONFIG_FLATMEM
27915 BUG_ON(!mem_map);
27916 #endif
27917 @@ -754,7 +759,7 @@ void __init mem_init(void)
27918 reservedpages++;
27919
27920 codesize = (unsigned long) &_etext - (unsigned long) &_text;
27921 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
27922 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
27923 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
27924
27925 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
27926 @@ -795,10 +800,10 @@ void __init mem_init(void)
27927 ((unsigned long)&__init_end -
27928 (unsigned long)&__init_begin) >> 10,
27929
27930 - (unsigned long)&_etext, (unsigned long)&_edata,
27931 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
27932 + (unsigned long)&_sdata, (unsigned long)&_edata,
27933 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
27934
27935 - (unsigned long)&_text, (unsigned long)&_etext,
27936 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
27937 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
27938
27939 /*
27940 @@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
27941 if (!kernel_set_to_readonly)
27942 return;
27943
27944 + start = ktla_ktva(start);
27945 pr_debug("Set kernel text: %lx - %lx for read write\n",
27946 start, start+size);
27947
27948 @@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
27949 if (!kernel_set_to_readonly)
27950 return;
27951
27952 + start = ktla_ktva(start);
27953 pr_debug("Set kernel text: %lx - %lx for read only\n",
27954 start, start+size);
27955
27956 @@ -918,6 +925,7 @@ void mark_rodata_ro(void)
27957 unsigned long start = PFN_ALIGN(_text);
27958 unsigned long size = PFN_ALIGN(_etext) - start;
27959
27960 + start = ktla_ktva(start);
27961 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
27962 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
27963 size >> 10);
27964 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
27965 index 75c9a6a..498d677 100644
27966 --- a/arch/x86/mm/init_64.c
27967 +++ b/arch/x86/mm/init_64.c
27968 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
27969 * around without checking the pgd every time.
27970 */
27971
27972 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
27973 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
27974 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27975
27976 int force_personality32;
27977 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27978
27979 for (address = start; address <= end; address += PGDIR_SIZE) {
27980 const pgd_t *pgd_ref = pgd_offset_k(address);
27981 +
27982 +#ifdef CONFIG_PAX_PER_CPU_PGD
27983 + unsigned long cpu;
27984 +#else
27985 struct page *page;
27986 +#endif
27987
27988 if (pgd_none(*pgd_ref))
27989 continue;
27990
27991 spin_lock(&pgd_lock);
27992 +
27993 +#ifdef CONFIG_PAX_PER_CPU_PGD
27994 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27995 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
27996 +#else
27997 list_for_each_entry(page, &pgd_list, lru) {
27998 pgd_t *pgd;
27999 spinlock_t *pgt_lock;
28000 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28001 /* the pgt_lock only for Xen */
28002 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28003 spin_lock(pgt_lock);
28004 +#endif
28005
28006 if (pgd_none(*pgd))
28007 set_pgd(pgd, *pgd_ref);
28008 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28009 BUG_ON(pgd_page_vaddr(*pgd)
28010 != pgd_page_vaddr(*pgd_ref));
28011
28012 +#ifndef CONFIG_PAX_PER_CPU_PGD
28013 spin_unlock(pgt_lock);
28014 +#endif
28015 +
28016 }
28017 spin_unlock(&pgd_lock);
28018 }
28019 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28020 {
28021 if (pgd_none(*pgd)) {
28022 pud_t *pud = (pud_t *)spp_getpage();
28023 - pgd_populate(&init_mm, pgd, pud);
28024 + pgd_populate_kernel(&init_mm, pgd, pud);
28025 if (pud != pud_offset(pgd, 0))
28026 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28027 pud, pud_offset(pgd, 0));
28028 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28029 {
28030 if (pud_none(*pud)) {
28031 pmd_t *pmd = (pmd_t *) spp_getpage();
28032 - pud_populate(&init_mm, pud, pmd);
28033 + pud_populate_kernel(&init_mm, pud, pmd);
28034 if (pmd != pmd_offset(pud, 0))
28035 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28036 pmd, pmd_offset(pud, 0));
28037 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28038 pmd = fill_pmd(pud, vaddr);
28039 pte = fill_pte(pmd, vaddr);
28040
28041 + pax_open_kernel();
28042 set_pte(pte, new_pte);
28043 + pax_close_kernel();
28044
28045 /*
28046 * It's enough to flush this one mapping.
28047 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28048 pgd = pgd_offset_k((unsigned long)__va(phys));
28049 if (pgd_none(*pgd)) {
28050 pud = (pud_t *) spp_getpage();
28051 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28052 - _PAGE_USER));
28053 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28054 }
28055 pud = pud_offset(pgd, (unsigned long)__va(phys));
28056 if (pud_none(*pud)) {
28057 pmd = (pmd_t *) spp_getpage();
28058 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28059 - _PAGE_USER));
28060 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28061 }
28062 pmd = pmd_offset(pud, phys);
28063 BUG_ON(!pmd_none(*pmd));
28064 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
28065 if (pfn >= pgt_buf_top)
28066 panic("alloc_low_page: ran out of memory");
28067
28068 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28069 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28070 clear_page(adr);
28071 *phys = pfn * PAGE_SIZE;
28072 return adr;
28073 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
28074
28075 phys = __pa(virt);
28076 left = phys & (PAGE_SIZE - 1);
28077 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28078 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28079 adr = (void *)(((unsigned long)adr) | left);
28080
28081 return adr;
28082 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28083 unmap_low_page(pmd);
28084
28085 spin_lock(&init_mm.page_table_lock);
28086 - pud_populate(&init_mm, pud, __va(pmd_phys));
28087 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
28088 spin_unlock(&init_mm.page_table_lock);
28089 }
28090 __flush_tlb_all();
28091 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
28092 unmap_low_page(pud);
28093
28094 spin_lock(&init_mm.page_table_lock);
28095 - pgd_populate(&init_mm, pgd, __va(pud_phys));
28096 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
28097 spin_unlock(&init_mm.page_table_lock);
28098 pgd_changed = true;
28099 }
28100 @@ -693,6 +707,12 @@ void __init mem_init(void)
28101
28102 pci_iommu_alloc();
28103
28104 +#ifdef CONFIG_PAX_PER_CPU_PGD
28105 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28106 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28107 + KERNEL_PGD_PTRS);
28108 +#endif
28109 +
28110 /* clear_bss() already clear the empty_zero_page */
28111
28112 reservedpages = 0;
28113 @@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
28114 static struct vm_area_struct gate_vma = {
28115 .vm_start = VSYSCALL_START,
28116 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28117 - .vm_page_prot = PAGE_READONLY_EXEC,
28118 - .vm_flags = VM_READ | VM_EXEC
28119 + .vm_page_prot = PAGE_READONLY,
28120 + .vm_flags = VM_READ
28121 };
28122
28123 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28124 @@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
28125
28126 const char *arch_vma_name(struct vm_area_struct *vma)
28127 {
28128 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28129 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28130 return "[vdso]";
28131 if (vma == &gate_vma)
28132 return "[vsyscall]";
28133 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28134 index 7b179b4..6bd1777 100644
28135 --- a/arch/x86/mm/iomap_32.c
28136 +++ b/arch/x86/mm/iomap_32.c
28137 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28138 type = kmap_atomic_idx_push();
28139 idx = type + KM_TYPE_NR * smp_processor_id();
28140 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28141 +
28142 + pax_open_kernel();
28143 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28144 + pax_close_kernel();
28145 +
28146 arch_flush_lazy_mmu_mode();
28147
28148 return (void *)vaddr;
28149 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28150 index 78fe3f1..2f9433c 100644
28151 --- a/arch/x86/mm/ioremap.c
28152 +++ b/arch/x86/mm/ioremap.c
28153 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28154 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28155 int is_ram = page_is_ram(pfn);
28156
28157 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28158 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28159 return NULL;
28160 WARN_ON_ONCE(is_ram);
28161 }
28162 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28163 *
28164 * Caller must ensure there is only one unmapping for the same pointer.
28165 */
28166 -void iounmap(volatile void __iomem *addr)
28167 +void iounmap(const volatile void __iomem *addr)
28168 {
28169 struct vm_struct *p, *o;
28170
28171 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28172
28173 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28174 if (page_is_ram(start >> PAGE_SHIFT))
28175 +#ifdef CONFIG_HIGHMEM
28176 + if ((start >> PAGE_SHIFT) < max_low_pfn)
28177 +#endif
28178 return __va(phys);
28179
28180 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28181 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
28182 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28183
28184 static __initdata int after_paging_init;
28185 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28186 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28187
28188 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28189 {
28190 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
28191 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28192
28193 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28194 - memset(bm_pte, 0, sizeof(bm_pte));
28195 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
28196 + pmd_populate_user(&init_mm, pmd, bm_pte);
28197
28198 /*
28199 * The boot-ioremap range spans multiple pmds, for which
28200 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28201 index d87dd6d..bf3fa66 100644
28202 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
28203 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28204 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28205 * memory (e.g. tracked pages)? For now, we need this to avoid
28206 * invoking kmemcheck for PnP BIOS calls.
28207 */
28208 - if (regs->flags & X86_VM_MASK)
28209 + if (v8086_mode(regs))
28210 return false;
28211 - if (regs->cs != __KERNEL_CS)
28212 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28213 return false;
28214
28215 pte = kmemcheck_pte_lookup(address);
28216 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28217 index 845df68..1d8d29f 100644
28218 --- a/arch/x86/mm/mmap.c
28219 +++ b/arch/x86/mm/mmap.c
28220 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28221 * Leave an at least ~128 MB hole with possible stack randomization.
28222 */
28223 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28224 -#define MAX_GAP (TASK_SIZE/6*5)
28225 +#define MAX_GAP (pax_task_size/6*5)
28226
28227 static int mmap_is_legacy(void)
28228 {
28229 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28230 return rnd << PAGE_SHIFT;
28231 }
28232
28233 -static unsigned long mmap_base(void)
28234 +static unsigned long mmap_base(struct mm_struct *mm)
28235 {
28236 unsigned long gap = rlimit(RLIMIT_STACK);
28237 + unsigned long pax_task_size = TASK_SIZE;
28238 +
28239 +#ifdef CONFIG_PAX_SEGMEXEC
28240 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28241 + pax_task_size = SEGMEXEC_TASK_SIZE;
28242 +#endif
28243
28244 if (gap < MIN_GAP)
28245 gap = MIN_GAP;
28246 else if (gap > MAX_GAP)
28247 gap = MAX_GAP;
28248
28249 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28250 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28251 }
28252
28253 /*
28254 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28255 * does, but not when emulating X86_32
28256 */
28257 -static unsigned long mmap_legacy_base(void)
28258 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
28259 {
28260 - if (mmap_is_ia32())
28261 + if (mmap_is_ia32()) {
28262 +
28263 +#ifdef CONFIG_PAX_SEGMEXEC
28264 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28265 + return SEGMEXEC_TASK_UNMAPPED_BASE;
28266 + else
28267 +#endif
28268 +
28269 return TASK_UNMAPPED_BASE;
28270 - else
28271 + } else
28272 return TASK_UNMAPPED_BASE + mmap_rnd();
28273 }
28274
28275 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28276 void arch_pick_mmap_layout(struct mm_struct *mm)
28277 {
28278 if (mmap_is_legacy()) {
28279 - mm->mmap_base = mmap_legacy_base();
28280 + mm->mmap_base = mmap_legacy_base(mm);
28281 +
28282 +#ifdef CONFIG_PAX_RANDMMAP
28283 + if (mm->pax_flags & MF_PAX_RANDMMAP)
28284 + mm->mmap_base += mm->delta_mmap;
28285 +#endif
28286 +
28287 mm->get_unmapped_area = arch_get_unmapped_area;
28288 mm->unmap_area = arch_unmap_area;
28289 } else {
28290 - mm->mmap_base = mmap_base();
28291 + mm->mmap_base = mmap_base(mm);
28292 +
28293 +#ifdef CONFIG_PAX_RANDMMAP
28294 + if (mm->pax_flags & MF_PAX_RANDMMAP)
28295 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28296 +#endif
28297 +
28298 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28299 mm->unmap_area = arch_unmap_area_topdown;
28300 }
28301 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28302 index dc0b727..f612039 100644
28303 --- a/arch/x86/mm/mmio-mod.c
28304 +++ b/arch/x86/mm/mmio-mod.c
28305 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28306 break;
28307 default:
28308 {
28309 - unsigned char *ip = (unsigned char *)instptr;
28310 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28311 my_trace->opcode = MMIO_UNKNOWN_OP;
28312 my_trace->width = 0;
28313 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28314 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28315 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28316 void __iomem *addr)
28317 {
28318 - static atomic_t next_id;
28319 + static atomic_unchecked_t next_id;
28320 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28321 /* These are page-unaligned. */
28322 struct mmiotrace_map map = {
28323 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28324 .private = trace
28325 },
28326 .phys = offset,
28327 - .id = atomic_inc_return(&next_id)
28328 + .id = atomic_inc_return_unchecked(&next_id)
28329 };
28330 map.map_id = trace->id;
28331
28332 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28333 ioremap_trace_core(offset, size, addr);
28334 }
28335
28336 -static void iounmap_trace_core(volatile void __iomem *addr)
28337 +static void iounmap_trace_core(const volatile void __iomem *addr)
28338 {
28339 struct mmiotrace_map map = {
28340 .phys = 0,
28341 @@ -328,7 +328,7 @@ not_enabled:
28342 }
28343 }
28344
28345 -void mmiotrace_iounmap(volatile void __iomem *addr)
28346 +void mmiotrace_iounmap(const volatile void __iomem *addr)
28347 {
28348 might_sleep();
28349 if (is_enabled()) /* recheck and proper locking in *_core() */
28350 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28351 index b008656..773eac2 100644
28352 --- a/arch/x86/mm/pageattr-test.c
28353 +++ b/arch/x86/mm/pageattr-test.c
28354 @@ -36,7 +36,7 @@ enum {
28355
28356 static int pte_testbit(pte_t pte)
28357 {
28358 - return pte_flags(pte) & _PAGE_UNUSED1;
28359 + return pte_flags(pte) & _PAGE_CPA_TEST;
28360 }
28361
28362 struct split_state {
28363 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28364 index a718e0d..77419bc 100644
28365 --- a/arch/x86/mm/pageattr.c
28366 +++ b/arch/x86/mm/pageattr.c
28367 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28368 */
28369 #ifdef CONFIG_PCI_BIOS
28370 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28371 - pgprot_val(forbidden) |= _PAGE_NX;
28372 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28373 #endif
28374
28375 /*
28376 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28377 * Does not cover __inittext since that is gone later on. On
28378 * 64bit we do not enforce !NX on the low mapping
28379 */
28380 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
28381 - pgprot_val(forbidden) |= _PAGE_NX;
28382 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28383 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28384
28385 +#ifdef CONFIG_DEBUG_RODATA
28386 /*
28387 * The .rodata section needs to be read-only. Using the pfn
28388 * catches all aliases.
28389 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28390 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
28391 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
28392 pgprot_val(forbidden) |= _PAGE_RW;
28393 +#endif
28394
28395 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28396 /*
28397 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28398 }
28399 #endif
28400
28401 +#ifdef CONFIG_PAX_KERNEXEC
28402 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28403 + pgprot_val(forbidden) |= _PAGE_RW;
28404 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28405 + }
28406 +#endif
28407 +
28408 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28409
28410 return prot;
28411 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
28412 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28413 {
28414 /* change init_mm */
28415 + pax_open_kernel();
28416 set_pte_atomic(kpte, pte);
28417 +
28418 #ifdef CONFIG_X86_32
28419 if (!SHARED_KERNEL_PMD) {
28420 +
28421 +#ifdef CONFIG_PAX_PER_CPU_PGD
28422 + unsigned long cpu;
28423 +#else
28424 struct page *page;
28425 +#endif
28426
28427 +#ifdef CONFIG_PAX_PER_CPU_PGD
28428 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28429 + pgd_t *pgd = get_cpu_pgd(cpu);
28430 +#else
28431 list_for_each_entry(page, &pgd_list, lru) {
28432 - pgd_t *pgd;
28433 + pgd_t *pgd = (pgd_t *)page_address(page);
28434 +#endif
28435 +
28436 pud_t *pud;
28437 pmd_t *pmd;
28438
28439 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
28440 + pgd += pgd_index(address);
28441 pud = pud_offset(pgd, address);
28442 pmd = pmd_offset(pud, address);
28443 set_pte_atomic((pte_t *)pmd, pte);
28444 }
28445 }
28446 #endif
28447 + pax_close_kernel();
28448 }
28449
28450 static int
28451 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
28452 index 0eb572e..92f5c1e 100644
28453 --- a/arch/x86/mm/pat.c
28454 +++ b/arch/x86/mm/pat.c
28455 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
28456
28457 if (!entry) {
28458 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
28459 - current->comm, current->pid, start, end - 1);
28460 + current->comm, task_pid_nr(current), start, end - 1);
28461 return -EINVAL;
28462 }
28463
28464 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28465
28466 while (cursor < to) {
28467 if (!devmem_is_allowed(pfn)) {
28468 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
28469 - current->comm, from, to - 1);
28470 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
28471 + current->comm, from, to - 1, cursor);
28472 return 0;
28473 }
28474 cursor += PAGE_SIZE;
28475 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
28476 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
28477 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
28478 "for [mem %#010Lx-%#010Lx]\n",
28479 - current->comm, current->pid,
28480 + current->comm, task_pid_nr(current),
28481 cattr_name(flags),
28482 base, (unsigned long long)(base + size-1));
28483 return -EINVAL;
28484 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28485 flags = lookup_memtype(paddr);
28486 if (want_flags != flags) {
28487 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
28488 - current->comm, current->pid,
28489 + current->comm, task_pid_nr(current),
28490 cattr_name(want_flags),
28491 (unsigned long long)paddr,
28492 (unsigned long long)(paddr + size - 1),
28493 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28494 free_memtype(paddr, paddr + size);
28495 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
28496 " for [mem %#010Lx-%#010Lx], got %s\n",
28497 - current->comm, current->pid,
28498 + current->comm, task_pid_nr(current),
28499 cattr_name(want_flags),
28500 (unsigned long long)paddr,
28501 (unsigned long long)(paddr + size - 1),
28502 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
28503 index 9f0614d..92ae64a 100644
28504 --- a/arch/x86/mm/pf_in.c
28505 +++ b/arch/x86/mm/pf_in.c
28506 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
28507 int i;
28508 enum reason_type rv = OTHERS;
28509
28510 - p = (unsigned char *)ins_addr;
28511 + p = (unsigned char *)ktla_ktva(ins_addr);
28512 p += skip_prefix(p, &prf);
28513 p += get_opcode(p, &opcode);
28514
28515 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
28516 struct prefix_bits prf;
28517 int i;
28518
28519 - p = (unsigned char *)ins_addr;
28520 + p = (unsigned char *)ktla_ktva(ins_addr);
28521 p += skip_prefix(p, &prf);
28522 p += get_opcode(p, &opcode);
28523
28524 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
28525 struct prefix_bits prf;
28526 int i;
28527
28528 - p = (unsigned char *)ins_addr;
28529 + p = (unsigned char *)ktla_ktva(ins_addr);
28530 p += skip_prefix(p, &prf);
28531 p += get_opcode(p, &opcode);
28532
28533 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
28534 struct prefix_bits prf;
28535 int i;
28536
28537 - p = (unsigned char *)ins_addr;
28538 + p = (unsigned char *)ktla_ktva(ins_addr);
28539 p += skip_prefix(p, &prf);
28540 p += get_opcode(p, &opcode);
28541 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
28542 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
28543 struct prefix_bits prf;
28544 int i;
28545
28546 - p = (unsigned char *)ins_addr;
28547 + p = (unsigned char *)ktla_ktva(ins_addr);
28548 p += skip_prefix(p, &prf);
28549 p += get_opcode(p, &opcode);
28550 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
28551 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
28552 index e27fbf8..8b56dc9 100644
28553 --- a/arch/x86/mm/pgtable.c
28554 +++ b/arch/x86/mm/pgtable.c
28555 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
28556 list_del(&page->lru);
28557 }
28558
28559 -#define UNSHARED_PTRS_PER_PGD \
28560 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28561 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28562 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
28563
28564 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
28565 +{
28566 + unsigned int count = USER_PGD_PTRS;
28567
28568 + while (count--)
28569 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
28570 +}
28571 +#endif
28572 +
28573 +#ifdef CONFIG_PAX_PER_CPU_PGD
28574 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
28575 +{
28576 + unsigned int count = USER_PGD_PTRS;
28577 +
28578 + while (count--) {
28579 + pgd_t pgd;
28580 +
28581 +#ifdef CONFIG_X86_64
28582 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
28583 +#else
28584 + pgd = *src++;
28585 +#endif
28586 +
28587 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28588 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
28589 +#endif
28590 +
28591 + *dst++ = pgd;
28592 + }
28593 +
28594 +}
28595 +#endif
28596 +
28597 +#ifdef CONFIG_X86_64
28598 +#define pxd_t pud_t
28599 +#define pyd_t pgd_t
28600 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
28601 +#define pxd_free(mm, pud) pud_free((mm), (pud))
28602 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
28603 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
28604 +#define PYD_SIZE PGDIR_SIZE
28605 +#else
28606 +#define pxd_t pmd_t
28607 +#define pyd_t pud_t
28608 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
28609 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
28610 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
28611 +#define pyd_offset(mm, address) pud_offset((mm), (address))
28612 +#define PYD_SIZE PUD_SIZE
28613 +#endif
28614 +
28615 +#ifdef CONFIG_PAX_PER_CPU_PGD
28616 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
28617 +static inline void pgd_dtor(pgd_t *pgd) {}
28618 +#else
28619 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
28620 {
28621 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
28622 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
28623 pgd_list_del(pgd);
28624 spin_unlock(&pgd_lock);
28625 }
28626 +#endif
28627
28628 /*
28629 * List of all pgd's needed for non-PAE so it can invalidate entries
28630 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
28631 * -- nyc
28632 */
28633
28634 -#ifdef CONFIG_X86_PAE
28635 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
28636 /*
28637 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
28638 * updating the top-level pagetable entries to guarantee the
28639 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
28640 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
28641 * and initialize the kernel pmds here.
28642 */
28643 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
28644 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28645
28646 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28647 {
28648 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28649 */
28650 flush_tlb_mm(mm);
28651 }
28652 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
28653 +#define PREALLOCATED_PXDS USER_PGD_PTRS
28654 #else /* !CONFIG_X86_PAE */
28655
28656 /* No need to prepopulate any pagetable entries in non-PAE modes. */
28657 -#define PREALLOCATED_PMDS 0
28658 +#define PREALLOCATED_PXDS 0
28659
28660 #endif /* CONFIG_X86_PAE */
28661
28662 -static void free_pmds(pmd_t *pmds[])
28663 +static void free_pxds(pxd_t *pxds[])
28664 {
28665 int i;
28666
28667 - for(i = 0; i < PREALLOCATED_PMDS; i++)
28668 - if (pmds[i])
28669 - free_page((unsigned long)pmds[i]);
28670 + for(i = 0; i < PREALLOCATED_PXDS; i++)
28671 + if (pxds[i])
28672 + free_page((unsigned long)pxds[i]);
28673 }
28674
28675 -static int preallocate_pmds(pmd_t *pmds[])
28676 +static int preallocate_pxds(pxd_t *pxds[])
28677 {
28678 int i;
28679 bool failed = false;
28680
28681 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
28682 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
28683 - if (pmd == NULL)
28684 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
28685 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
28686 + if (pxd == NULL)
28687 failed = true;
28688 - pmds[i] = pmd;
28689 + pxds[i] = pxd;
28690 }
28691
28692 if (failed) {
28693 - free_pmds(pmds);
28694 + free_pxds(pxds);
28695 return -ENOMEM;
28696 }
28697
28698 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
28699 * preallocate which never got a corresponding vma will need to be
28700 * freed manually.
28701 */
28702 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
28703 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
28704 {
28705 int i;
28706
28707 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
28708 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
28709 pgd_t pgd = pgdp[i];
28710
28711 if (pgd_val(pgd) != 0) {
28712 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
28713 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
28714
28715 - pgdp[i] = native_make_pgd(0);
28716 + set_pgd(pgdp + i, native_make_pgd(0));
28717
28718 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
28719 - pmd_free(mm, pmd);
28720 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
28721 + pxd_free(mm, pxd);
28722 }
28723 }
28724 }
28725
28726 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
28727 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
28728 {
28729 - pud_t *pud;
28730 + pyd_t *pyd;
28731 unsigned long addr;
28732 int i;
28733
28734 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
28735 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
28736 return;
28737
28738 - pud = pud_offset(pgd, 0);
28739 +#ifdef CONFIG_X86_64
28740 + pyd = pyd_offset(mm, 0L);
28741 +#else
28742 + pyd = pyd_offset(pgd, 0L);
28743 +#endif
28744
28745 - for (addr = i = 0; i < PREALLOCATED_PMDS;
28746 - i++, pud++, addr += PUD_SIZE) {
28747 - pmd_t *pmd = pmds[i];
28748 + for (addr = i = 0; i < PREALLOCATED_PXDS;
28749 + i++, pyd++, addr += PYD_SIZE) {
28750 + pxd_t *pxd = pxds[i];
28751
28752 if (i >= KERNEL_PGD_BOUNDARY)
28753 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28754 - sizeof(pmd_t) * PTRS_PER_PMD);
28755 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28756 + sizeof(pxd_t) * PTRS_PER_PMD);
28757
28758 - pud_populate(mm, pud, pmd);
28759 + pyd_populate(mm, pyd, pxd);
28760 }
28761 }
28762
28763 pgd_t *pgd_alloc(struct mm_struct *mm)
28764 {
28765 pgd_t *pgd;
28766 - pmd_t *pmds[PREALLOCATED_PMDS];
28767 + pxd_t *pxds[PREALLOCATED_PXDS];
28768
28769 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
28770
28771 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28772
28773 mm->pgd = pgd;
28774
28775 - if (preallocate_pmds(pmds) != 0)
28776 + if (preallocate_pxds(pxds) != 0)
28777 goto out_free_pgd;
28778
28779 if (paravirt_pgd_alloc(mm) != 0)
28780 - goto out_free_pmds;
28781 + goto out_free_pxds;
28782
28783 /*
28784 * Make sure that pre-populating the pmds is atomic with
28785 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28786 spin_lock(&pgd_lock);
28787
28788 pgd_ctor(mm, pgd);
28789 - pgd_prepopulate_pmd(mm, pgd, pmds);
28790 + pgd_prepopulate_pxd(mm, pgd, pxds);
28791
28792 spin_unlock(&pgd_lock);
28793
28794 return pgd;
28795
28796 -out_free_pmds:
28797 - free_pmds(pmds);
28798 +out_free_pxds:
28799 + free_pxds(pxds);
28800 out_free_pgd:
28801 free_page((unsigned long)pgd);
28802 out:
28803 @@ -295,7 +356,7 @@ out:
28804
28805 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
28806 {
28807 - pgd_mop_up_pmds(mm, pgd);
28808 + pgd_mop_up_pxds(mm, pgd);
28809 pgd_dtor(pgd);
28810 paravirt_pgd_free(mm, pgd);
28811 free_page((unsigned long)pgd);
28812 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
28813 index a69bcb8..19068ab 100644
28814 --- a/arch/x86/mm/pgtable_32.c
28815 +++ b/arch/x86/mm/pgtable_32.c
28816 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
28817 return;
28818 }
28819 pte = pte_offset_kernel(pmd, vaddr);
28820 +
28821 + pax_open_kernel();
28822 if (pte_val(pteval))
28823 set_pte_at(&init_mm, vaddr, pte, pteval);
28824 else
28825 pte_clear(&init_mm, vaddr, pte);
28826 + pax_close_kernel();
28827
28828 /*
28829 * It's enough to flush this one mapping.
28830 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
28831 index 410531d..0f16030 100644
28832 --- a/arch/x86/mm/setup_nx.c
28833 +++ b/arch/x86/mm/setup_nx.c
28834 @@ -5,8 +5,10 @@
28835 #include <asm/pgtable.h>
28836 #include <asm/proto.h>
28837
28838 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28839 static int disable_nx __cpuinitdata;
28840
28841 +#ifndef CONFIG_PAX_PAGEEXEC
28842 /*
28843 * noexec = on|off
28844 *
28845 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
28846 return 0;
28847 }
28848 early_param("noexec", noexec_setup);
28849 +#endif
28850 +
28851 +#endif
28852
28853 void __cpuinit x86_configure_nx(void)
28854 {
28855 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28856 if (cpu_has_nx && !disable_nx)
28857 __supported_pte_mask |= _PAGE_NX;
28858 else
28859 +#endif
28860 __supported_pte_mask &= ~_PAGE_NX;
28861 }
28862
28863 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
28864 index 13a6b29..c2fff23 100644
28865 --- a/arch/x86/mm/tlb.c
28866 +++ b/arch/x86/mm/tlb.c
28867 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
28868 BUG();
28869 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
28870 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
28871 +
28872 +#ifndef CONFIG_PAX_PER_CPU_PGD
28873 load_cr3(swapper_pg_dir);
28874 +#endif
28875 +
28876 }
28877 }
28878 EXPORT_SYMBOL_GPL(leave_mm);
28879 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
28880 index 877b9a1..a8ecf42 100644
28881 --- a/arch/x86/net/bpf_jit.S
28882 +++ b/arch/x86/net/bpf_jit.S
28883 @@ -9,6 +9,7 @@
28884 */
28885 #include <linux/linkage.h>
28886 #include <asm/dwarf2.h>
28887 +#include <asm/alternative-asm.h>
28888
28889 /*
28890 * Calling convention :
28891 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
28892 jle bpf_slow_path_word
28893 mov (SKBDATA,%rsi),%eax
28894 bswap %eax /* ntohl() */
28895 + pax_force_retaddr
28896 ret
28897
28898 sk_load_half:
28899 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
28900 jle bpf_slow_path_half
28901 movzwl (SKBDATA,%rsi),%eax
28902 rol $8,%ax # ntohs()
28903 + pax_force_retaddr
28904 ret
28905
28906 sk_load_byte:
28907 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
28908 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
28909 jle bpf_slow_path_byte
28910 movzbl (SKBDATA,%rsi),%eax
28911 + pax_force_retaddr
28912 ret
28913
28914 /**
28915 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
28916 movzbl (SKBDATA,%rsi),%ebx
28917 and $15,%bl
28918 shl $2,%bl
28919 + pax_force_retaddr
28920 ret
28921
28922 /* rsi contains offset and can be scratched */
28923 @@ -109,6 +114,7 @@ bpf_slow_path_word:
28924 js bpf_error
28925 mov -12(%rbp),%eax
28926 bswap %eax
28927 + pax_force_retaddr
28928 ret
28929
28930 bpf_slow_path_half:
28931 @@ -117,12 +123,14 @@ bpf_slow_path_half:
28932 mov -12(%rbp),%ax
28933 rol $8,%ax
28934 movzwl %ax,%eax
28935 + pax_force_retaddr
28936 ret
28937
28938 bpf_slow_path_byte:
28939 bpf_slow_path_common(1)
28940 js bpf_error
28941 movzbl -12(%rbp),%eax
28942 + pax_force_retaddr
28943 ret
28944
28945 bpf_slow_path_byte_msh:
28946 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
28947 and $15,%al
28948 shl $2,%al
28949 xchg %eax,%ebx
28950 + pax_force_retaddr
28951 ret
28952
28953 #define sk_negative_common(SIZE) \
28954 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
28955 sk_negative_common(4)
28956 mov (%rax), %eax
28957 bswap %eax
28958 + pax_force_retaddr
28959 ret
28960
28961 bpf_slow_path_half_neg:
28962 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
28963 mov (%rax),%ax
28964 rol $8,%ax
28965 movzwl %ax,%eax
28966 + pax_force_retaddr
28967 ret
28968
28969 bpf_slow_path_byte_neg:
28970 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
28971 .globl sk_load_byte_negative_offset
28972 sk_negative_common(1)
28973 movzbl (%rax), %eax
28974 + pax_force_retaddr
28975 ret
28976
28977 bpf_slow_path_byte_msh_neg:
28978 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
28979 and $15,%al
28980 shl $2,%al
28981 xchg %eax,%ebx
28982 + pax_force_retaddr
28983 ret
28984
28985 bpf_error:
28986 @@ -197,4 +210,5 @@ bpf_error:
28987 xor %eax,%eax
28988 mov -8(%rbp),%rbx
28989 leaveq
28990 + pax_force_retaddr
28991 ret
28992 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
28993 index d11a470..3f9adff3 100644
28994 --- a/arch/x86/net/bpf_jit_comp.c
28995 +++ b/arch/x86/net/bpf_jit_comp.c
28996 @@ -12,6 +12,7 @@
28997 #include <linux/netdevice.h>
28998 #include <linux/filter.h>
28999 #include <linux/if_vlan.h>
29000 +#include <linux/random.h>
29001
29002 /*
29003 * Conventions :
29004 @@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29005 return ptr + len;
29006 }
29007
29008 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29009 +#define MAX_INSTR_CODE_SIZE 96
29010 +#else
29011 +#define MAX_INSTR_CODE_SIZE 64
29012 +#endif
29013 +
29014 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29015
29016 #define EMIT1(b1) EMIT(b1, 1)
29017 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29018 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29019 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29020 +
29021 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29022 +/* original constant will appear in ecx */
29023 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
29024 +do { \
29025 + /* mov ecx, randkey */ \
29026 + EMIT1(0xb9); \
29027 + EMIT(_key, 4); \
29028 + /* xor ecx, randkey ^ off */ \
29029 + EMIT2(0x81, 0xf1); \
29030 + EMIT((_key) ^ (_off), 4); \
29031 +} while (0)
29032 +
29033 +#define EMIT1_off32(b1, _off) \
29034 +do { \
29035 + switch (b1) { \
29036 + case 0x05: /* add eax, imm32 */ \
29037 + case 0x2d: /* sub eax, imm32 */ \
29038 + case 0x25: /* and eax, imm32 */ \
29039 + case 0x0d: /* or eax, imm32 */ \
29040 + case 0xb8: /* mov eax, imm32 */ \
29041 + case 0x3d: /* cmp eax, imm32 */ \
29042 + case 0xa9: /* test eax, imm32 */ \
29043 + DILUTE_CONST_SEQUENCE(_off, randkey); \
29044 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29045 + break; \
29046 + case 0xbb: /* mov ebx, imm32 */ \
29047 + DILUTE_CONST_SEQUENCE(_off, randkey); \
29048 + /* mov ebx, ecx */ \
29049 + EMIT2(0x89, 0xcb); \
29050 + break; \
29051 + case 0xbe: /* mov esi, imm32 */ \
29052 + DILUTE_CONST_SEQUENCE(_off, randkey); \
29053 + /* mov esi, ecx */ \
29054 + EMIT2(0x89, 0xce); \
29055 + break; \
29056 + case 0xe9: /* jmp rel imm32 */ \
29057 + EMIT1(b1); \
29058 + EMIT(_off, 4); \
29059 + /* prevent fall-through, we're not called if off = 0 */ \
29060 + EMIT(0xcccccccc, 4); \
29061 + EMIT(0xcccccccc, 4); \
29062 + break; \
29063 + default: \
29064 + EMIT1(b1); \
29065 + EMIT(_off, 4); \
29066 + } \
29067 +} while (0)
29068 +
29069 +#define EMIT2_off32(b1, b2, _off) \
29070 +do { \
29071 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29072 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29073 + EMIT(randkey, 4); \
29074 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29075 + EMIT((_off) - randkey, 4); \
29076 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29077 + DILUTE_CONST_SEQUENCE(_off, randkey); \
29078 + /* imul eax, ecx */ \
29079 + EMIT3(0x0f, 0xaf, 0xc1); \
29080 + } else { \
29081 + EMIT2(b1, b2); \
29082 + EMIT(_off, 4); \
29083 + } \
29084 +} while (0)
29085 +#else
29086 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29087 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29088 +#endif
29089
29090 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29091 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29092 @@ -90,6 +165,24 @@ do { \
29093 #define X86_JBE 0x76
29094 #define X86_JA 0x77
29095
29096 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29097 +#define APPEND_FLOW_VERIFY() \
29098 +do { \
29099 + /* mov ecx, randkey */ \
29100 + EMIT1(0xb9); \
29101 + EMIT(randkey, 4); \
29102 + /* cmp ecx, randkey */ \
29103 + EMIT2(0x81, 0xf9); \
29104 + EMIT(randkey, 4); \
29105 + /* jz after 8 int 3s */ \
29106 + EMIT2(0x74, 0x08); \
29107 + EMIT(0xcccccccc, 4); \
29108 + EMIT(0xcccccccc, 4); \
29109 +} while (0)
29110 +#else
29111 +#define APPEND_FLOW_VERIFY() do { } while (0)
29112 +#endif
29113 +
29114 #define EMIT_COND_JMP(op, offset) \
29115 do { \
29116 if (is_near(offset)) \
29117 @@ -97,6 +190,7 @@ do { \
29118 else { \
29119 EMIT2(0x0f, op + 0x10); \
29120 EMIT(offset, 4); /* jxx .+off32 */ \
29121 + APPEND_FLOW_VERIFY(); \
29122 } \
29123 } while (0)
29124
29125 @@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
29126 set_fs(old_fs);
29127 }
29128
29129 +struct bpf_jit_work {
29130 + struct work_struct work;
29131 + void *image;
29132 +};
29133 +
29134 #define CHOOSE_LOAD_FUNC(K, func) \
29135 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29136
29137 void bpf_jit_compile(struct sk_filter *fp)
29138 {
29139 - u8 temp[64];
29140 + u8 temp[MAX_INSTR_CODE_SIZE];
29141 u8 *prog;
29142 unsigned int proglen, oldproglen = 0;
29143 int ilen, i;
29144 @@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29145 unsigned int *addrs;
29146 const struct sock_filter *filter = fp->insns;
29147 int flen = fp->len;
29148 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29149 + unsigned int randkey;
29150 +#endif
29151
29152 if (!bpf_jit_enable)
29153 return;
29154 @@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29155 if (addrs == NULL)
29156 return;
29157
29158 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29159 + if (!fp->work)
29160 + goto out;
29161 +
29162 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29163 + randkey = get_random_int();
29164 +#endif
29165 +
29166 /* Before first pass, make a rough estimation of addrs[]
29167 - * each bpf instruction is translated to less than 64 bytes
29168 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29169 */
29170 for (proglen = 0, i = 0; i < flen; i++) {
29171 - proglen += 64;
29172 + proglen += MAX_INSTR_CODE_SIZE;
29173 addrs[i] = proglen;
29174 }
29175 cleanup_addr = proglen; /* epilogue address */
29176 @@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29177 case BPF_S_ALU_MUL_K: /* A *= K */
29178 if (is_imm8(K))
29179 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29180 - else {
29181 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29182 - EMIT(K, 4);
29183 - }
29184 + else
29185 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29186 break;
29187 case BPF_S_ALU_DIV_X: /* A /= X; */
29188 seen |= SEEN_XREG;
29189 @@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29190 break;
29191 case BPF_S_ALU_MOD_K: /* A %= K; */
29192 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29193 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29194 + DILUTE_CONST_SEQUENCE(K, randkey);
29195 +#else
29196 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29197 +#endif
29198 EMIT2(0xf7, 0xf1); /* div %ecx */
29199 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29200 break;
29201 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29202 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29203 + DILUTE_CONST_SEQUENCE(K, randkey);
29204 + // imul rax, rcx
29205 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29206 +#else
29207 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29208 EMIT(K, 4);
29209 +#endif
29210 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29211 break;
29212 case BPF_S_ALU_AND_X:
29213 @@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29214 if (is_imm8(K)) {
29215 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29216 } else {
29217 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29218 - EMIT(K, 4);
29219 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29220 }
29221 } else {
29222 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29223 @@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29224 break;
29225 default:
29226 /* hmm, too complex filter, give up with jit compiler */
29227 - goto out;
29228 + goto error;
29229 }
29230 ilen = prog - temp;
29231 if (image) {
29232 if (unlikely(proglen + ilen > oldproglen)) {
29233 pr_err("bpb_jit_compile fatal error\n");
29234 - kfree(addrs);
29235 - module_free(NULL, image);
29236 - return;
29237 + module_free_exec(NULL, image);
29238 + goto error;
29239 }
29240 + pax_open_kernel();
29241 memcpy(image + proglen, temp, ilen);
29242 + pax_close_kernel();
29243 }
29244 proglen += ilen;
29245 addrs[i] = proglen;
29246 @@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29247 break;
29248 }
29249 if (proglen == oldproglen) {
29250 - image = module_alloc(max_t(unsigned int,
29251 - proglen,
29252 - sizeof(struct work_struct)));
29253 + image = module_alloc_exec(proglen);
29254 if (!image)
29255 - goto out;
29256 + goto error;
29257 }
29258 oldproglen = proglen;
29259 }
29260 @@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29261 bpf_flush_icache(image, image + proglen);
29262
29263 fp->bpf_func = (void *)image;
29264 - }
29265 + } else
29266 +error:
29267 + kfree(fp->work);
29268 +
29269 out:
29270 kfree(addrs);
29271 return;
29272 @@ -707,18 +826,20 @@ out:
29273
29274 static void jit_free_defer(struct work_struct *arg)
29275 {
29276 - module_free(NULL, arg);
29277 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29278 + kfree(arg);
29279 }
29280
29281 /* run from softirq, we must use a work_struct to call
29282 - * module_free() from process context
29283 + * module_free_exec() from process context
29284 */
29285 void bpf_jit_free(struct sk_filter *fp)
29286 {
29287 if (fp->bpf_func != sk_run_filter) {
29288 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
29289 + struct work_struct *work = &fp->work->work;
29290
29291 INIT_WORK(work, jit_free_defer);
29292 + fp->work->image = fp->bpf_func;
29293 schedule_work(work);
29294 }
29295 }
29296 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29297 index d6aa6e8..266395a 100644
29298 --- a/arch/x86/oprofile/backtrace.c
29299 +++ b/arch/x86/oprofile/backtrace.c
29300 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29301 struct stack_frame_ia32 *fp;
29302 unsigned long bytes;
29303
29304 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29305 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29306 if (bytes != sizeof(bufhead))
29307 return NULL;
29308
29309 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29310 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29311
29312 oprofile_add_trace(bufhead[0].return_address);
29313
29314 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29315 struct stack_frame bufhead[2];
29316 unsigned long bytes;
29317
29318 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29319 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29320 if (bytes != sizeof(bufhead))
29321 return NULL;
29322
29323 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29324 {
29325 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29326
29327 - if (!user_mode_vm(regs)) {
29328 + if (!user_mode(regs)) {
29329 unsigned long stack = kernel_stack_pointer(regs);
29330 if (depth)
29331 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29332 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29333 index 48768df..ba9143c 100644
29334 --- a/arch/x86/oprofile/nmi_int.c
29335 +++ b/arch/x86/oprofile/nmi_int.c
29336 @@ -23,6 +23,7 @@
29337 #include <asm/nmi.h>
29338 #include <asm/msr.h>
29339 #include <asm/apic.h>
29340 +#include <asm/pgtable.h>
29341
29342 #include "op_counter.h"
29343 #include "op_x86_model.h"
29344 @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
29345 if (ret)
29346 return ret;
29347
29348 - if (!model->num_virt_counters)
29349 - model->num_virt_counters = model->num_counters;
29350 + if (!model->num_virt_counters) {
29351 + pax_open_kernel();
29352 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
29353 + pax_close_kernel();
29354 + }
29355
29356 mux_init(ops);
29357
29358 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
29359 index b2b9443..be58856 100644
29360 --- a/arch/x86/oprofile/op_model_amd.c
29361 +++ b/arch/x86/oprofile/op_model_amd.c
29362 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
29363 num_counters = AMD64_NUM_COUNTERS;
29364 }
29365
29366 - op_amd_spec.num_counters = num_counters;
29367 - op_amd_spec.num_controls = num_counters;
29368 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29369 + pax_open_kernel();
29370 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
29371 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
29372 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29373 + pax_close_kernel();
29374
29375 return 0;
29376 }
29377 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
29378 index d90528e..0127e2b 100644
29379 --- a/arch/x86/oprofile/op_model_ppro.c
29380 +++ b/arch/x86/oprofile/op_model_ppro.c
29381 @@ -19,6 +19,7 @@
29382 #include <asm/msr.h>
29383 #include <asm/apic.h>
29384 #include <asm/nmi.h>
29385 +#include <asm/pgtable.h>
29386
29387 #include "op_x86_model.h"
29388 #include "op_counter.h"
29389 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
29390
29391 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
29392
29393 - op_arch_perfmon_spec.num_counters = num_counters;
29394 - op_arch_perfmon_spec.num_controls = num_counters;
29395 + pax_open_kernel();
29396 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
29397 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
29398 + pax_close_kernel();
29399 }
29400
29401 static int arch_perfmon_init(struct oprofile_operations *ignore)
29402 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
29403 index 71e8a67..6a313bb 100644
29404 --- a/arch/x86/oprofile/op_x86_model.h
29405 +++ b/arch/x86/oprofile/op_x86_model.h
29406 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
29407 void (*switch_ctrl)(struct op_x86_model_spec const *model,
29408 struct op_msrs const * const msrs);
29409 #endif
29410 -};
29411 +} __do_const;
29412
29413 struct op_counter_config;
29414
29415 diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
29416 index e9e6ed5..e47ae67 100644
29417 --- a/arch/x86/pci/amd_bus.c
29418 +++ b/arch/x86/pci/amd_bus.c
29419 @@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
29420 return NOTIFY_OK;
29421 }
29422
29423 -static struct notifier_block __cpuinitdata amd_cpu_notifier = {
29424 +static struct notifier_block amd_cpu_notifier = {
29425 .notifier_call = amd_cpu_notify,
29426 };
29427
29428 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
29429 index 372e9b8..e775a6c 100644
29430 --- a/arch/x86/pci/irq.c
29431 +++ b/arch/x86/pci/irq.c
29432 @@ -50,7 +50,7 @@ struct irq_router {
29433 struct irq_router_handler {
29434 u16 vendor;
29435 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
29436 -};
29437 +} __do_const;
29438
29439 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
29440 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
29441 @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
29442 return 0;
29443 }
29444
29445 -static __initdata struct irq_router_handler pirq_routers[] = {
29446 +static __initconst const struct irq_router_handler pirq_routers[] = {
29447 { PCI_VENDOR_ID_INTEL, intel_router_probe },
29448 { PCI_VENDOR_ID_AL, ali_router_probe },
29449 { PCI_VENDOR_ID_ITE, ite_router_probe },
29450 @@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
29451 static void __init pirq_find_router(struct irq_router *r)
29452 {
29453 struct irq_routing_table *rt = pirq_table;
29454 - struct irq_router_handler *h;
29455 + const struct irq_router_handler *h;
29456
29457 #ifdef CONFIG_PCI_BIOS
29458 if (!rt->signature) {
29459 @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
29460 return 0;
29461 }
29462
29463 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
29464 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
29465 {
29466 .callback = fix_broken_hp_bios_irq9,
29467 .ident = "HP Pavilion N5400 Series Laptop",
29468 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
29469 index 6eb18c4..20d83de 100644
29470 --- a/arch/x86/pci/mrst.c
29471 +++ b/arch/x86/pci/mrst.c
29472 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
29473 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
29474 pci_mmcfg_late_init();
29475 pcibios_enable_irq = mrst_pci_irq_enable;
29476 - pci_root_ops = pci_mrst_ops;
29477 + pax_open_kernel();
29478 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
29479 + pax_close_kernel();
29480 pci_soc_mode = 1;
29481 /* Continue with standard init */
29482 return 1;
29483 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
29484 index c77b24a..c979855 100644
29485 --- a/arch/x86/pci/pcbios.c
29486 +++ b/arch/x86/pci/pcbios.c
29487 @@ -79,7 +79,7 @@ union bios32 {
29488 static struct {
29489 unsigned long address;
29490 unsigned short segment;
29491 -} bios32_indirect = { 0, __KERNEL_CS };
29492 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
29493
29494 /*
29495 * Returns the entry point for the given service, NULL on error
29496 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
29497 unsigned long length; /* %ecx */
29498 unsigned long entry; /* %edx */
29499 unsigned long flags;
29500 + struct desc_struct d, *gdt;
29501
29502 local_irq_save(flags);
29503 - __asm__("lcall *(%%edi); cld"
29504 +
29505 + gdt = get_cpu_gdt_table(smp_processor_id());
29506 +
29507 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
29508 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29509 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
29510 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29511 +
29512 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
29513 : "=a" (return_code),
29514 "=b" (address),
29515 "=c" (length),
29516 "=d" (entry)
29517 : "0" (service),
29518 "1" (0),
29519 - "D" (&bios32_indirect));
29520 + "D" (&bios32_indirect),
29521 + "r"(__PCIBIOS_DS)
29522 + : "memory");
29523 +
29524 + pax_open_kernel();
29525 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
29526 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
29527 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
29528 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
29529 + pax_close_kernel();
29530 +
29531 local_irq_restore(flags);
29532
29533 switch (return_code) {
29534 - case 0:
29535 - return address + entry;
29536 - case 0x80: /* Not present */
29537 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29538 - return 0;
29539 - default: /* Shouldn't happen */
29540 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29541 - service, return_code);
29542 + case 0: {
29543 + int cpu;
29544 + unsigned char flags;
29545 +
29546 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
29547 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
29548 + printk(KERN_WARNING "bios32_service: not valid\n");
29549 return 0;
29550 + }
29551 + address = address + PAGE_OFFSET;
29552 + length += 16UL; /* some BIOSs underreport this... */
29553 + flags = 4;
29554 + if (length >= 64*1024*1024) {
29555 + length >>= PAGE_SHIFT;
29556 + flags |= 8;
29557 + }
29558 +
29559 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
29560 + gdt = get_cpu_gdt_table(cpu);
29561 + pack_descriptor(&d, address, length, 0x9b, flags);
29562 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29563 + pack_descriptor(&d, address, length, 0x93, flags);
29564 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29565 + }
29566 + return entry;
29567 + }
29568 + case 0x80: /* Not present */
29569 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29570 + return 0;
29571 + default: /* Shouldn't happen */
29572 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29573 + service, return_code);
29574 + return 0;
29575 }
29576 }
29577
29578 static struct {
29579 unsigned long address;
29580 unsigned short segment;
29581 -} pci_indirect = { 0, __KERNEL_CS };
29582 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
29583
29584 -static int pci_bios_present;
29585 +static int pci_bios_present __read_only;
29586
29587 static int check_pcibios(void)
29588 {
29589 @@ -131,11 +174,13 @@ static int check_pcibios(void)
29590 unsigned long flags, pcibios_entry;
29591
29592 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
29593 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
29594 + pci_indirect.address = pcibios_entry;
29595
29596 local_irq_save(flags);
29597 - __asm__(
29598 - "lcall *(%%edi); cld\n\t"
29599 + __asm__("movw %w6, %%ds\n\t"
29600 + "lcall *%%ss:(%%edi); cld\n\t"
29601 + "push %%ss\n\t"
29602 + "pop %%ds\n\t"
29603 "jc 1f\n\t"
29604 "xor %%ah, %%ah\n"
29605 "1:"
29606 @@ -144,7 +189,8 @@ static int check_pcibios(void)
29607 "=b" (ebx),
29608 "=c" (ecx)
29609 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
29610 - "D" (&pci_indirect)
29611 + "D" (&pci_indirect),
29612 + "r" (__PCIBIOS_DS)
29613 : "memory");
29614 local_irq_restore(flags);
29615
29616 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29617
29618 switch (len) {
29619 case 1:
29620 - __asm__("lcall *(%%esi); cld\n\t"
29621 + __asm__("movw %w6, %%ds\n\t"
29622 + "lcall *%%ss:(%%esi); cld\n\t"
29623 + "push %%ss\n\t"
29624 + "pop %%ds\n\t"
29625 "jc 1f\n\t"
29626 "xor %%ah, %%ah\n"
29627 "1:"
29628 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29629 : "1" (PCIBIOS_READ_CONFIG_BYTE),
29630 "b" (bx),
29631 "D" ((long)reg),
29632 - "S" (&pci_indirect));
29633 + "S" (&pci_indirect),
29634 + "r" (__PCIBIOS_DS));
29635 /*
29636 * Zero-extend the result beyond 8 bits, do not trust the
29637 * BIOS having done it:
29638 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29639 *value &= 0xff;
29640 break;
29641 case 2:
29642 - __asm__("lcall *(%%esi); cld\n\t"
29643 + __asm__("movw %w6, %%ds\n\t"
29644 + "lcall *%%ss:(%%esi); cld\n\t"
29645 + "push %%ss\n\t"
29646 + "pop %%ds\n\t"
29647 "jc 1f\n\t"
29648 "xor %%ah, %%ah\n"
29649 "1:"
29650 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29651 : "1" (PCIBIOS_READ_CONFIG_WORD),
29652 "b" (bx),
29653 "D" ((long)reg),
29654 - "S" (&pci_indirect));
29655 + "S" (&pci_indirect),
29656 + "r" (__PCIBIOS_DS));
29657 /*
29658 * Zero-extend the result beyond 16 bits, do not trust the
29659 * BIOS having done it:
29660 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29661 *value &= 0xffff;
29662 break;
29663 case 4:
29664 - __asm__("lcall *(%%esi); cld\n\t"
29665 + __asm__("movw %w6, %%ds\n\t"
29666 + "lcall *%%ss:(%%esi); cld\n\t"
29667 + "push %%ss\n\t"
29668 + "pop %%ds\n\t"
29669 "jc 1f\n\t"
29670 "xor %%ah, %%ah\n"
29671 "1:"
29672 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29673 : "1" (PCIBIOS_READ_CONFIG_DWORD),
29674 "b" (bx),
29675 "D" ((long)reg),
29676 - "S" (&pci_indirect));
29677 + "S" (&pci_indirect),
29678 + "r" (__PCIBIOS_DS));
29679 break;
29680 }
29681
29682 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29683
29684 switch (len) {
29685 case 1:
29686 - __asm__("lcall *(%%esi); cld\n\t"
29687 + __asm__("movw %w6, %%ds\n\t"
29688 + "lcall *%%ss:(%%esi); cld\n\t"
29689 + "push %%ss\n\t"
29690 + "pop %%ds\n\t"
29691 "jc 1f\n\t"
29692 "xor %%ah, %%ah\n"
29693 "1:"
29694 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29695 "c" (value),
29696 "b" (bx),
29697 "D" ((long)reg),
29698 - "S" (&pci_indirect));
29699 + "S" (&pci_indirect),
29700 + "r" (__PCIBIOS_DS));
29701 break;
29702 case 2:
29703 - __asm__("lcall *(%%esi); cld\n\t"
29704 + __asm__("movw %w6, %%ds\n\t"
29705 + "lcall *%%ss:(%%esi); cld\n\t"
29706 + "push %%ss\n\t"
29707 + "pop %%ds\n\t"
29708 "jc 1f\n\t"
29709 "xor %%ah, %%ah\n"
29710 "1:"
29711 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29712 "c" (value),
29713 "b" (bx),
29714 "D" ((long)reg),
29715 - "S" (&pci_indirect));
29716 + "S" (&pci_indirect),
29717 + "r" (__PCIBIOS_DS));
29718 break;
29719 case 4:
29720 - __asm__("lcall *(%%esi); cld\n\t"
29721 + __asm__("movw %w6, %%ds\n\t"
29722 + "lcall *%%ss:(%%esi); cld\n\t"
29723 + "push %%ss\n\t"
29724 + "pop %%ds\n\t"
29725 "jc 1f\n\t"
29726 "xor %%ah, %%ah\n"
29727 "1:"
29728 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29729 "c" (value),
29730 "b" (bx),
29731 "D" ((long)reg),
29732 - "S" (&pci_indirect));
29733 + "S" (&pci_indirect),
29734 + "r" (__PCIBIOS_DS));
29735 break;
29736 }
29737
29738 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29739
29740 DBG("PCI: Fetching IRQ routing table... ");
29741 __asm__("push %%es\n\t"
29742 + "movw %w8, %%ds\n\t"
29743 "push %%ds\n\t"
29744 "pop %%es\n\t"
29745 - "lcall *(%%esi); cld\n\t"
29746 + "lcall *%%ss:(%%esi); cld\n\t"
29747 "pop %%es\n\t"
29748 + "push %%ss\n\t"
29749 + "pop %%ds\n"
29750 "jc 1f\n\t"
29751 "xor %%ah, %%ah\n"
29752 "1:"
29753 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29754 "1" (0),
29755 "D" ((long) &opt),
29756 "S" (&pci_indirect),
29757 - "m" (opt)
29758 + "m" (opt),
29759 + "r" (__PCIBIOS_DS)
29760 : "memory");
29761 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
29762 if (ret & 0xff00)
29763 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29764 {
29765 int ret;
29766
29767 - __asm__("lcall *(%%esi); cld\n\t"
29768 + __asm__("movw %w5, %%ds\n\t"
29769 + "lcall *%%ss:(%%esi); cld\n\t"
29770 + "push %%ss\n\t"
29771 + "pop %%ds\n"
29772 "jc 1f\n\t"
29773 "xor %%ah, %%ah\n"
29774 "1:"
29775 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29776 : "0" (PCIBIOS_SET_PCI_HW_INT),
29777 "b" ((dev->bus->number << 8) | dev->devfn),
29778 "c" ((irq << 8) | (pin + 10)),
29779 - "S" (&pci_indirect));
29780 + "S" (&pci_indirect),
29781 + "r" (__PCIBIOS_DS));
29782 return !(ret & 0xff00);
29783 }
29784 EXPORT_SYMBOL(pcibios_set_irq_routing);
29785 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
29786 index 40e4469..1ab536e 100644
29787 --- a/arch/x86/platform/efi/efi_32.c
29788 +++ b/arch/x86/platform/efi/efi_32.c
29789 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
29790 {
29791 struct desc_ptr gdt_descr;
29792
29793 +#ifdef CONFIG_PAX_KERNEXEC
29794 + struct desc_struct d;
29795 +#endif
29796 +
29797 local_irq_save(efi_rt_eflags);
29798
29799 load_cr3(initial_page_table);
29800 __flush_tlb_all();
29801
29802 +#ifdef CONFIG_PAX_KERNEXEC
29803 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
29804 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29805 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
29806 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29807 +#endif
29808 +
29809 gdt_descr.address = __pa(get_cpu_gdt_table(0));
29810 gdt_descr.size = GDT_SIZE - 1;
29811 load_gdt(&gdt_descr);
29812 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
29813 {
29814 struct desc_ptr gdt_descr;
29815
29816 +#ifdef CONFIG_PAX_KERNEXEC
29817 + struct desc_struct d;
29818 +
29819 + memset(&d, 0, sizeof d);
29820 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29821 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29822 +#endif
29823 +
29824 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
29825 gdt_descr.size = GDT_SIZE - 1;
29826 load_gdt(&gdt_descr);
29827 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
29828 index fbe66e6..eae5e38 100644
29829 --- a/arch/x86/platform/efi/efi_stub_32.S
29830 +++ b/arch/x86/platform/efi/efi_stub_32.S
29831 @@ -6,7 +6,9 @@
29832 */
29833
29834 #include <linux/linkage.h>
29835 +#include <linux/init.h>
29836 #include <asm/page_types.h>
29837 +#include <asm/segment.h>
29838
29839 /*
29840 * efi_call_phys(void *, ...) is a function with variable parameters.
29841 @@ -20,7 +22,7 @@
29842 * service functions will comply with gcc calling convention, too.
29843 */
29844
29845 -.text
29846 +__INIT
29847 ENTRY(efi_call_phys)
29848 /*
29849 * 0. The function can only be called in Linux kernel. So CS has been
29850 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
29851 * The mapping of lower virtual memory has been created in prelog and
29852 * epilog.
29853 */
29854 - movl $1f, %edx
29855 - subl $__PAGE_OFFSET, %edx
29856 - jmp *%edx
29857 +#ifdef CONFIG_PAX_KERNEXEC
29858 + movl $(__KERNEXEC_EFI_DS), %edx
29859 + mov %edx, %ds
29860 + mov %edx, %es
29861 + mov %edx, %ss
29862 + addl $2f,(1f)
29863 + ljmp *(1f)
29864 +
29865 +__INITDATA
29866 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
29867 +.previous
29868 +
29869 +2:
29870 + subl $2b,(1b)
29871 +#else
29872 + jmp 1f-__PAGE_OFFSET
29873 1:
29874 +#endif
29875
29876 /*
29877 * 2. Now on the top of stack is the return
29878 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
29879 * parameter 2, ..., param n. To make things easy, we save the return
29880 * address of efi_call_phys in a global variable.
29881 */
29882 - popl %edx
29883 - movl %edx, saved_return_addr
29884 - /* get the function pointer into ECX*/
29885 - popl %ecx
29886 - movl %ecx, efi_rt_function_ptr
29887 - movl $2f, %edx
29888 - subl $__PAGE_OFFSET, %edx
29889 - pushl %edx
29890 + popl (saved_return_addr)
29891 + popl (efi_rt_function_ptr)
29892
29893 /*
29894 * 3. Clear PG bit in %CR0.
29895 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
29896 /*
29897 * 5. Call the physical function.
29898 */
29899 - jmp *%ecx
29900 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
29901
29902 -2:
29903 /*
29904 * 6. After EFI runtime service returns, control will return to
29905 * following instruction. We'd better readjust stack pointer first.
29906 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
29907 movl %cr0, %edx
29908 orl $0x80000000, %edx
29909 movl %edx, %cr0
29910 - jmp 1f
29911 -1:
29912 +
29913 /*
29914 * 8. Now restore the virtual mode from flat mode by
29915 * adding EIP with PAGE_OFFSET.
29916 */
29917 - movl $1f, %edx
29918 - jmp *%edx
29919 +#ifdef CONFIG_PAX_KERNEXEC
29920 + movl $(__KERNEL_DS), %edx
29921 + mov %edx, %ds
29922 + mov %edx, %es
29923 + mov %edx, %ss
29924 + ljmp $(__KERNEL_CS),$1f
29925 +#else
29926 + jmp 1f+__PAGE_OFFSET
29927 +#endif
29928 1:
29929
29930 /*
29931 * 9. Balance the stack. And because EAX contain the return value,
29932 * we'd better not clobber it.
29933 */
29934 - leal efi_rt_function_ptr, %edx
29935 - movl (%edx), %ecx
29936 - pushl %ecx
29937 + pushl (efi_rt_function_ptr)
29938
29939 /*
29940 - * 10. Push the saved return address onto the stack and return.
29941 + * 10. Return to the saved return address.
29942 */
29943 - leal saved_return_addr, %edx
29944 - movl (%edx), %ecx
29945 - pushl %ecx
29946 - ret
29947 + jmpl *(saved_return_addr)
29948 ENDPROC(efi_call_phys)
29949 .previous
29950
29951 -.data
29952 +__INITDATA
29953 saved_return_addr:
29954 .long 0
29955 efi_rt_function_ptr:
29956 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
29957 index 4c07cca..2c8427d 100644
29958 --- a/arch/x86/platform/efi/efi_stub_64.S
29959 +++ b/arch/x86/platform/efi/efi_stub_64.S
29960 @@ -7,6 +7,7 @@
29961 */
29962
29963 #include <linux/linkage.h>
29964 +#include <asm/alternative-asm.h>
29965
29966 #define SAVE_XMM \
29967 mov %rsp, %rax; \
29968 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
29969 call *%rdi
29970 addq $32, %rsp
29971 RESTORE_XMM
29972 + pax_force_retaddr 0, 1
29973 ret
29974 ENDPROC(efi_call0)
29975
29976 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
29977 call *%rdi
29978 addq $32, %rsp
29979 RESTORE_XMM
29980 + pax_force_retaddr 0, 1
29981 ret
29982 ENDPROC(efi_call1)
29983
29984 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
29985 call *%rdi
29986 addq $32, %rsp
29987 RESTORE_XMM
29988 + pax_force_retaddr 0, 1
29989 ret
29990 ENDPROC(efi_call2)
29991
29992 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
29993 call *%rdi
29994 addq $32, %rsp
29995 RESTORE_XMM
29996 + pax_force_retaddr 0, 1
29997 ret
29998 ENDPROC(efi_call3)
29999
30000 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
30001 call *%rdi
30002 addq $32, %rsp
30003 RESTORE_XMM
30004 + pax_force_retaddr 0, 1
30005 ret
30006 ENDPROC(efi_call4)
30007
30008 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
30009 call *%rdi
30010 addq $48, %rsp
30011 RESTORE_XMM
30012 + pax_force_retaddr 0, 1
30013 ret
30014 ENDPROC(efi_call5)
30015
30016 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
30017 call *%rdi
30018 addq $48, %rsp
30019 RESTORE_XMM
30020 + pax_force_retaddr 0, 1
30021 ret
30022 ENDPROC(efi_call6)
30023 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30024 index e31bcd8..f12dc46 100644
30025 --- a/arch/x86/platform/mrst/mrst.c
30026 +++ b/arch/x86/platform/mrst/mrst.c
30027 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30028 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30029 int sfi_mrtc_num;
30030
30031 -static void mrst_power_off(void)
30032 +static __noreturn void mrst_power_off(void)
30033 {
30034 + BUG();
30035 }
30036
30037 -static void mrst_reboot(void)
30038 +static __noreturn void mrst_reboot(void)
30039 {
30040 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30041 + BUG();
30042 }
30043
30044 /* parse all the mtimer info to a static mtimer array */
30045 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30046 index d6ee929..3637cb5 100644
30047 --- a/arch/x86/platform/olpc/olpc_dt.c
30048 +++ b/arch/x86/platform/olpc/olpc_dt.c
30049 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30050 return res;
30051 }
30052
30053 -static struct of_pdt_ops prom_olpc_ops __initdata = {
30054 +static struct of_pdt_ops prom_olpc_ops __initconst = {
30055 .nextprop = olpc_dt_nextprop,
30056 .getproplen = olpc_dt_getproplen,
30057 .getproperty = olpc_dt_getproperty,
30058 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30059 index 120cee1..b2db75a 100644
30060 --- a/arch/x86/power/cpu.c
30061 +++ b/arch/x86/power/cpu.c
30062 @@ -133,7 +133,7 @@ static void do_fpu_end(void)
30063 static void fix_processor_context(void)
30064 {
30065 int cpu = smp_processor_id();
30066 - struct tss_struct *t = &per_cpu(init_tss, cpu);
30067 + struct tss_struct *t = init_tss + cpu;
30068
30069 set_tss_desc(cpu, t); /*
30070 * This just modifies memory; should not be
30071 @@ -143,8 +143,6 @@ static void fix_processor_context(void)
30072 */
30073
30074 #ifdef CONFIG_X86_64
30075 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30076 -
30077 syscall_init(); /* This sets MSR_*STAR and related */
30078 #endif
30079 load_TR_desc(); /* This does ltr */
30080 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30081 index cbca565..bae7133 100644
30082 --- a/arch/x86/realmode/init.c
30083 +++ b/arch/x86/realmode/init.c
30084 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
30085 __va(real_mode_header->trampoline_header);
30086
30087 #ifdef CONFIG_X86_32
30088 - trampoline_header->start = __pa(startup_32_smp);
30089 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
30090 +
30091 +#ifdef CONFIG_PAX_KERNEXEC
30092 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30093 +#endif
30094 +
30095 + trampoline_header->boot_cs = __BOOT_CS;
30096 trampoline_header->gdt_limit = __BOOT_DS + 7;
30097 trampoline_header->gdt_base = __pa(boot_gdt);
30098 #else
30099 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30100 index 8869287..d577672 100644
30101 --- a/arch/x86/realmode/rm/Makefile
30102 +++ b/arch/x86/realmode/rm/Makefile
30103 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30104 $(call cc-option, -fno-unit-at-a-time)) \
30105 $(call cc-option, -fno-stack-protector) \
30106 $(call cc-option, -mpreferred-stack-boundary=2)
30107 +ifdef CONSTIFY_PLUGIN
30108 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30109 +endif
30110 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30111 GCOV_PROFILE := n
30112 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30113 index a28221d..93c40f1 100644
30114 --- a/arch/x86/realmode/rm/header.S
30115 +++ b/arch/x86/realmode/rm/header.S
30116 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30117 #endif
30118 /* APM/BIOS reboot */
30119 .long pa_machine_real_restart_asm
30120 -#ifdef CONFIG_X86_64
30121 +#ifdef CONFIG_X86_32
30122 + .long __KERNEL_CS
30123 +#else
30124 .long __KERNEL32_CS
30125 #endif
30126 END(real_mode_header)
30127 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30128 index c1b2791..f9e31c7 100644
30129 --- a/arch/x86/realmode/rm/trampoline_32.S
30130 +++ b/arch/x86/realmode/rm/trampoline_32.S
30131 @@ -25,6 +25,12 @@
30132 #include <asm/page_types.h>
30133 #include "realmode.h"
30134
30135 +#ifdef CONFIG_PAX_KERNEXEC
30136 +#define ta(X) (X)
30137 +#else
30138 +#define ta(X) (pa_ ## X)
30139 +#endif
30140 +
30141 .text
30142 .code16
30143
30144 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30145
30146 cli # We should be safe anyway
30147
30148 - movl tr_start, %eax # where we need to go
30149 -
30150 movl $0xA5A5A5A5, trampoline_status
30151 # write marker for master knows we're running
30152
30153 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30154 movw $1, %dx # protected mode (PE) bit
30155 lmsw %dx # into protected mode
30156
30157 - ljmpl $__BOOT_CS, $pa_startup_32
30158 + ljmpl *(trampoline_header)
30159
30160 .section ".text32","ax"
30161 .code32
30162 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30163 .balign 8
30164 GLOBAL(trampoline_header)
30165 tr_start: .space 4
30166 - tr_gdt_pad: .space 2
30167 + tr_boot_cs: .space 2
30168 tr_gdt: .space 6
30169 END(trampoline_header)
30170
30171 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30172 index bb360dc..3e5945f 100644
30173 --- a/arch/x86/realmode/rm/trampoline_64.S
30174 +++ b/arch/x86/realmode/rm/trampoline_64.S
30175 @@ -107,7 +107,7 @@ ENTRY(startup_32)
30176 wrmsr
30177
30178 # Enable paging and in turn activate Long Mode
30179 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30180 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
30181 movl %eax, %cr0
30182
30183 /*
30184 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30185 index 79d67bd..c7e1b90 100644
30186 --- a/arch/x86/tools/relocs.c
30187 +++ b/arch/x86/tools/relocs.c
30188 @@ -12,10 +12,13 @@
30189 #include <regex.h>
30190 #include <tools/le_byteshift.h>
30191
30192 +#include "../../../include/generated/autoconf.h"
30193 +
30194 static void die(char *fmt, ...);
30195
30196 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
30197 static Elf32_Ehdr ehdr;
30198 +static Elf32_Phdr *phdr;
30199 static unsigned long reloc_count, reloc_idx;
30200 static unsigned long *relocs;
30201 static unsigned long reloc16_count, reloc16_idx;
30202 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
30203 }
30204 }
30205
30206 +static void read_phdrs(FILE *fp)
30207 +{
30208 + unsigned int i;
30209 +
30210 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
30211 + if (!phdr) {
30212 + die("Unable to allocate %d program headers\n",
30213 + ehdr.e_phnum);
30214 + }
30215 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30216 + die("Seek to %d failed: %s\n",
30217 + ehdr.e_phoff, strerror(errno));
30218 + }
30219 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30220 + die("Cannot read ELF program headers: %s\n",
30221 + strerror(errno));
30222 + }
30223 + for(i = 0; i < ehdr.e_phnum; i++) {
30224 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
30225 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
30226 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
30227 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
30228 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
30229 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
30230 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
30231 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
30232 + }
30233 +
30234 +}
30235 +
30236 static void read_shdrs(FILE *fp)
30237 {
30238 - int i;
30239 + unsigned int i;
30240 Elf32_Shdr shdr;
30241
30242 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30243 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
30244
30245 static void read_strtabs(FILE *fp)
30246 {
30247 - int i;
30248 + unsigned int i;
30249 for (i = 0; i < ehdr.e_shnum; i++) {
30250 struct section *sec = &secs[i];
30251 if (sec->shdr.sh_type != SHT_STRTAB) {
30252 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
30253
30254 static void read_symtabs(FILE *fp)
30255 {
30256 - int i,j;
30257 + unsigned int i,j;
30258 for (i = 0; i < ehdr.e_shnum; i++) {
30259 struct section *sec = &secs[i];
30260 if (sec->shdr.sh_type != SHT_SYMTAB) {
30261 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
30262 }
30263
30264
30265 -static void read_relocs(FILE *fp)
30266 +static void read_relocs(FILE *fp, int use_real_mode)
30267 {
30268 - int i,j;
30269 + unsigned int i,j;
30270 + uint32_t base;
30271 +
30272 for (i = 0; i < ehdr.e_shnum; i++) {
30273 struct section *sec = &secs[i];
30274 if (sec->shdr.sh_type != SHT_REL) {
30275 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
30276 die("Cannot read symbol table: %s\n",
30277 strerror(errno));
30278 }
30279 + base = 0;
30280 +
30281 +#ifdef CONFIG_X86_32
30282 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
30283 + if (phdr[j].p_type != PT_LOAD )
30284 + continue;
30285 + 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)
30286 + continue;
30287 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
30288 + break;
30289 + }
30290 +#endif
30291 +
30292 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
30293 Elf32_Rel *rel = &sec->reltab[j];
30294 - rel->r_offset = elf32_to_cpu(rel->r_offset);
30295 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
30296 rel->r_info = elf32_to_cpu(rel->r_info);
30297 }
30298 }
30299 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
30300
30301 static void print_absolute_symbols(void)
30302 {
30303 - int i;
30304 + unsigned int i;
30305 printf("Absolute symbols\n");
30306 printf(" Num: Value Size Type Bind Visibility Name\n");
30307 for (i = 0; i < ehdr.e_shnum; i++) {
30308 struct section *sec = &secs[i];
30309 char *sym_strtab;
30310 - int j;
30311 + unsigned int j;
30312
30313 if (sec->shdr.sh_type != SHT_SYMTAB) {
30314 continue;
30315 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
30316
30317 static void print_absolute_relocs(void)
30318 {
30319 - int i, printed = 0;
30320 + unsigned int i, printed = 0;
30321
30322 for (i = 0; i < ehdr.e_shnum; i++) {
30323 struct section *sec = &secs[i];
30324 struct section *sec_applies, *sec_symtab;
30325 char *sym_strtab;
30326 Elf32_Sym *sh_symtab;
30327 - int j;
30328 + unsigned int j;
30329 if (sec->shdr.sh_type != SHT_REL) {
30330 continue;
30331 }
30332 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
30333 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30334 int use_real_mode)
30335 {
30336 - int i;
30337 + unsigned int i;
30338 /* Walk through the relocations */
30339 for (i = 0; i < ehdr.e_shnum; i++) {
30340 char *sym_strtab;
30341 Elf32_Sym *sh_symtab;
30342 struct section *sec_applies, *sec_symtab;
30343 - int j;
30344 + unsigned int j;
30345 struct section *sec = &secs[i];
30346
30347 if (sec->shdr.sh_type != SHT_REL) {
30348 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30349 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
30350 r_type = ELF32_R_TYPE(rel->r_info);
30351
30352 + if (!use_real_mode) {
30353 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
30354 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
30355 + continue;
30356 +
30357 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
30358 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
30359 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
30360 + continue;
30361 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
30362 + continue;
30363 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
30364 + continue;
30365 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
30366 + continue;
30367 +#endif
30368 + }
30369 +
30370 shn_abs = sym->st_shndx == SHN_ABS;
30371
30372 switch (r_type) {
30373 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
30374
30375 static void emit_relocs(int as_text, int use_real_mode)
30376 {
30377 - int i;
30378 + unsigned int i;
30379 /* Count how many relocations I have and allocate space for them. */
30380 reloc_count = 0;
30381 walk_relocs(count_reloc, use_real_mode);
30382 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
30383 fname, strerror(errno));
30384 }
30385 read_ehdr(fp);
30386 + read_phdrs(fp);
30387 read_shdrs(fp);
30388 read_strtabs(fp);
30389 read_symtabs(fp);
30390 - read_relocs(fp);
30391 + read_relocs(fp, use_real_mode);
30392 if (show_absolute_syms) {
30393 print_absolute_symbols();
30394 goto out;
30395 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
30396 index fd14be1..e3c79c0 100644
30397 --- a/arch/x86/vdso/Makefile
30398 +++ b/arch/x86/vdso/Makefile
30399 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
30400 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
30401 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
30402
30403 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30404 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30405 GCOV_PROFILE := n
30406
30407 #
30408 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
30409 index 0faad64..39ef157 100644
30410 --- a/arch/x86/vdso/vdso32-setup.c
30411 +++ b/arch/x86/vdso/vdso32-setup.c
30412 @@ -25,6 +25,7 @@
30413 #include <asm/tlbflush.h>
30414 #include <asm/vdso.h>
30415 #include <asm/proto.h>
30416 +#include <asm/mman.h>
30417
30418 enum {
30419 VDSO_DISABLED = 0,
30420 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
30421 void enable_sep_cpu(void)
30422 {
30423 int cpu = get_cpu();
30424 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
30425 + struct tss_struct *tss = init_tss + cpu;
30426
30427 if (!boot_cpu_has(X86_FEATURE_SEP)) {
30428 put_cpu();
30429 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
30430 gate_vma.vm_start = FIXADDR_USER_START;
30431 gate_vma.vm_end = FIXADDR_USER_END;
30432 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
30433 - gate_vma.vm_page_prot = __P101;
30434 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
30435
30436 return 0;
30437 }
30438 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30439 if (compat)
30440 addr = VDSO_HIGH_BASE;
30441 else {
30442 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
30443 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
30444 if (IS_ERR_VALUE(addr)) {
30445 ret = addr;
30446 goto up_fail;
30447 }
30448 }
30449
30450 - current->mm->context.vdso = (void *)addr;
30451 + current->mm->context.vdso = addr;
30452
30453 if (compat_uses_vma || !compat) {
30454 /*
30455 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30456 }
30457
30458 current_thread_info()->sysenter_return =
30459 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30460 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30461
30462 up_fail:
30463 if (ret)
30464 - current->mm->context.vdso = NULL;
30465 + current->mm->context.vdso = 0;
30466
30467 up_write(&mm->mmap_sem);
30468
30469 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
30470
30471 const char *arch_vma_name(struct vm_area_struct *vma)
30472 {
30473 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30474 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30475 return "[vdso]";
30476 +
30477 +#ifdef CONFIG_PAX_SEGMEXEC
30478 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
30479 + return "[vdso]";
30480 +#endif
30481 +
30482 return NULL;
30483 }
30484
30485 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30486 * Check to see if the corresponding task was created in compat vdso
30487 * mode.
30488 */
30489 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
30490 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
30491 return &gate_vma;
30492 return NULL;
30493 }
30494 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
30495 index 431e875..cbb23f3 100644
30496 --- a/arch/x86/vdso/vma.c
30497 +++ b/arch/x86/vdso/vma.c
30498 @@ -16,8 +16,6 @@
30499 #include <asm/vdso.h>
30500 #include <asm/page.h>
30501
30502 -unsigned int __read_mostly vdso_enabled = 1;
30503 -
30504 extern char vdso_start[], vdso_end[];
30505 extern unsigned short vdso_sync_cpuid;
30506
30507 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
30508 * unaligned here as a result of stack start randomization.
30509 */
30510 addr = PAGE_ALIGN(addr);
30511 - addr = align_vdso_addr(addr);
30512
30513 return addr;
30514 }
30515 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
30516 unsigned size)
30517 {
30518 struct mm_struct *mm = current->mm;
30519 - unsigned long addr;
30520 + unsigned long addr = 0;
30521 int ret;
30522
30523 - if (!vdso_enabled)
30524 - return 0;
30525 -
30526 down_write(&mm->mmap_sem);
30527 +
30528 +#ifdef CONFIG_PAX_RANDMMAP
30529 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30530 +#endif
30531 +
30532 addr = vdso_addr(mm->start_stack, size);
30533 + addr = align_vdso_addr(addr);
30534 addr = get_unmapped_area(NULL, addr, size, 0, 0);
30535 if (IS_ERR_VALUE(addr)) {
30536 ret = addr;
30537 goto up_fail;
30538 }
30539
30540 - current->mm->context.vdso = (void *)addr;
30541 + mm->context.vdso = addr;
30542
30543 ret = install_special_mapping(mm, addr, size,
30544 VM_READ|VM_EXEC|
30545 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
30546 pages);
30547 - if (ret) {
30548 - current->mm->context.vdso = NULL;
30549 - goto up_fail;
30550 - }
30551 + if (ret)
30552 + mm->context.vdso = 0;
30553
30554 up_fail:
30555 up_write(&mm->mmap_sem);
30556 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30557 vdsox32_size);
30558 }
30559 #endif
30560 -
30561 -static __init int vdso_setup(char *s)
30562 -{
30563 - vdso_enabled = simple_strtoul(s, NULL, 0);
30564 - return 0;
30565 -}
30566 -__setup("vdso=", vdso_setup);
30567 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
30568 index e014092..c76ab69 100644
30569 --- a/arch/x86/xen/enlighten.c
30570 +++ b/arch/x86/xen/enlighten.c
30571 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
30572
30573 struct shared_info xen_dummy_shared_info;
30574
30575 -void *xen_initial_gdt;
30576 -
30577 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
30578 __read_mostly int xen_have_vector_callback;
30579 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
30580 @@ -495,8 +493,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
30581 {
30582 unsigned long va = dtr->address;
30583 unsigned int size = dtr->size + 1;
30584 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30585 - unsigned long frames[pages];
30586 + unsigned long frames[65536 / PAGE_SIZE];
30587 int f;
30588
30589 /*
30590 @@ -544,8 +541,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
30591 {
30592 unsigned long va = dtr->address;
30593 unsigned int size = dtr->size + 1;
30594 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30595 - unsigned long frames[pages];
30596 + unsigned long frames[65536 / PAGE_SIZE];
30597 int f;
30598
30599 /*
30600 @@ -938,7 +934,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
30601 return 0;
30602 }
30603
30604 -static void set_xen_basic_apic_ops(void)
30605 +static void __init set_xen_basic_apic_ops(void)
30606 {
30607 apic->read = xen_apic_read;
30608 apic->write = xen_apic_write;
30609 @@ -1244,30 +1240,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
30610 #endif
30611 };
30612
30613 -static void xen_reboot(int reason)
30614 +static __noreturn void xen_reboot(int reason)
30615 {
30616 struct sched_shutdown r = { .reason = reason };
30617
30618 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
30619 - BUG();
30620 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
30621 + BUG();
30622 }
30623
30624 -static void xen_restart(char *msg)
30625 +static __noreturn void xen_restart(char *msg)
30626 {
30627 xen_reboot(SHUTDOWN_reboot);
30628 }
30629
30630 -static void xen_emergency_restart(void)
30631 +static __noreturn void xen_emergency_restart(void)
30632 {
30633 xen_reboot(SHUTDOWN_reboot);
30634 }
30635
30636 -static void xen_machine_halt(void)
30637 +static __noreturn void xen_machine_halt(void)
30638 {
30639 xen_reboot(SHUTDOWN_poweroff);
30640 }
30641
30642 -static void xen_machine_power_off(void)
30643 +static __noreturn void xen_machine_power_off(void)
30644 {
30645 if (pm_power_off)
30646 pm_power_off();
30647 @@ -1369,7 +1365,17 @@ asmlinkage void __init xen_start_kernel(void)
30648 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
30649
30650 /* Work out if we support NX */
30651 - x86_configure_nx();
30652 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
30653 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
30654 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
30655 + unsigned l, h;
30656 +
30657 + __supported_pte_mask |= _PAGE_NX;
30658 + rdmsr(MSR_EFER, l, h);
30659 + l |= EFER_NX;
30660 + wrmsr(MSR_EFER, l, h);
30661 + }
30662 +#endif
30663
30664 xen_setup_features();
30665
30666 @@ -1398,14 +1404,7 @@ asmlinkage void __init xen_start_kernel(void)
30667 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
30668 }
30669
30670 - machine_ops = xen_machine_ops;
30671 -
30672 - /*
30673 - * The only reliable way to retain the initial address of the
30674 - * percpu gdt_page is to remember it here, so we can go and
30675 - * mark it RW later, when the initial percpu area is freed.
30676 - */
30677 - xen_initial_gdt = &per_cpu(gdt_page, 0);
30678 + memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
30679
30680 xen_smp_init();
30681
30682 @@ -1590,7 +1589,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
30683 return NOTIFY_OK;
30684 }
30685
30686 -static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
30687 +static struct notifier_block xen_hvm_cpu_notifier = {
30688 .notifier_call = xen_hvm_cpu_notify,
30689 };
30690
30691 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
30692 index 01de35c..0bda07b 100644
30693 --- a/arch/x86/xen/mmu.c
30694 +++ b/arch/x86/xen/mmu.c
30695 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30696 /* L3_k[510] -> level2_kernel_pgt
30697 * L3_i[511] -> level2_fixmap_pgt */
30698 convert_pfn_mfn(level3_kernel_pgt);
30699 + convert_pfn_mfn(level3_vmalloc_start_pgt);
30700 + convert_pfn_mfn(level3_vmalloc_end_pgt);
30701 + convert_pfn_mfn(level3_vmemmap_pgt);
30702
30703 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
30704 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
30705 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30706 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
30707 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
30708 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
30709 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
30710 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
30711 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
30712 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
30713 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
30714 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
30715 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
30716 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
30717
30718 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
30719 pv_mmu_ops.set_pud = xen_set_pud;
30720 #if PAGETABLE_LEVELS == 4
30721 pv_mmu_ops.set_pgd = xen_set_pgd;
30722 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
30723 #endif
30724
30725 /* This will work as long as patching hasn't happened yet
30726 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
30727 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
30728 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
30729 .set_pgd = xen_set_pgd_hyper,
30730 + .set_pgd_batched = xen_set_pgd_hyper,
30731
30732 .alloc_pud = xen_alloc_pmd_init,
30733 .release_pud = xen_release_pmd_init,
30734 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
30735 index 34bc4ce..c34aa24 100644
30736 --- a/arch/x86/xen/smp.c
30737 +++ b/arch/x86/xen/smp.c
30738 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
30739 {
30740 BUG_ON(smp_processor_id() != 0);
30741 native_smp_prepare_boot_cpu();
30742 -
30743 - /* We've switched to the "real" per-cpu gdt, so make sure the
30744 - old memory can be recycled */
30745 - make_lowmem_page_readwrite(xen_initial_gdt);
30746 -
30747 xen_filter_cpu_maps();
30748 xen_setup_vcpu_info_placement();
30749 }
30750 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
30751 gdt = get_cpu_gdt_table(cpu);
30752
30753 ctxt->flags = VGCF_IN_KERNEL;
30754 - ctxt->user_regs.ds = __USER_DS;
30755 - ctxt->user_regs.es = __USER_DS;
30756 + ctxt->user_regs.ds = __KERNEL_DS;
30757 + ctxt->user_regs.es = __KERNEL_DS;
30758 ctxt->user_regs.ss = __KERNEL_DS;
30759 #ifdef CONFIG_X86_32
30760 ctxt->user_regs.fs = __KERNEL_PERCPU;
30761 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
30762 + savesegment(gs, ctxt->user_regs.gs);
30763 #else
30764 ctxt->gs_base_kernel = per_cpu_offset(cpu);
30765 #endif
30766 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
30767 int rc;
30768
30769 per_cpu(current_task, cpu) = idle;
30770 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
30771 #ifdef CONFIG_X86_32
30772 irq_ctx_init(cpu);
30773 #else
30774 clear_tsk_thread_flag(idle, TIF_FORK);
30775 - per_cpu(kernel_stack, cpu) =
30776 - (unsigned long)task_stack_page(idle) -
30777 - KERNEL_STACK_OFFSET + THREAD_SIZE;
30778 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
30779 #endif
30780 xen_setup_runstate_info(cpu);
30781 xen_setup_timer(cpu);
30782 @@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
30783
30784 void __init xen_smp_init(void)
30785 {
30786 - smp_ops = xen_smp_ops;
30787 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
30788 xen_fill_possible_map();
30789 xen_init_spinlocks();
30790 }
30791 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
30792 index 33ca6e4..0ded929 100644
30793 --- a/arch/x86/xen/xen-asm_32.S
30794 +++ b/arch/x86/xen/xen-asm_32.S
30795 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
30796 ESP_OFFSET=4 # bytes pushed onto stack
30797
30798 /*
30799 - * Store vcpu_info pointer for easy access. Do it this way to
30800 - * avoid having to reload %fs
30801 + * Store vcpu_info pointer for easy access.
30802 */
30803 #ifdef CONFIG_SMP
30804 - GET_THREAD_INFO(%eax)
30805 - movl %ss:TI_cpu(%eax), %eax
30806 - movl %ss:__per_cpu_offset(,%eax,4), %eax
30807 - mov %ss:xen_vcpu(%eax), %eax
30808 + push %fs
30809 + mov $(__KERNEL_PERCPU), %eax
30810 + mov %eax, %fs
30811 + mov PER_CPU_VAR(xen_vcpu), %eax
30812 + pop %fs
30813 #else
30814 movl %ss:xen_vcpu, %eax
30815 #endif
30816 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
30817 index 7faed58..ba4427c 100644
30818 --- a/arch/x86/xen/xen-head.S
30819 +++ b/arch/x86/xen/xen-head.S
30820 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
30821 #ifdef CONFIG_X86_32
30822 mov %esi,xen_start_info
30823 mov $init_thread_union+THREAD_SIZE,%esp
30824 +#ifdef CONFIG_SMP
30825 + movl $cpu_gdt_table,%edi
30826 + movl $__per_cpu_load,%eax
30827 + movw %ax,__KERNEL_PERCPU + 2(%edi)
30828 + rorl $16,%eax
30829 + movb %al,__KERNEL_PERCPU + 4(%edi)
30830 + movb %ah,__KERNEL_PERCPU + 7(%edi)
30831 + movl $__per_cpu_end - 1,%eax
30832 + subl $__per_cpu_start,%eax
30833 + movw %ax,__KERNEL_PERCPU + 0(%edi)
30834 +#endif
30835 #else
30836 mov %rsi,xen_start_info
30837 mov $init_thread_union+THREAD_SIZE,%rsp
30838 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
30839 index a95b417..b6dbd0b 100644
30840 --- a/arch/x86/xen/xen-ops.h
30841 +++ b/arch/x86/xen/xen-ops.h
30842 @@ -10,8 +10,6 @@
30843 extern const char xen_hypervisor_callback[];
30844 extern const char xen_failsafe_callback[];
30845
30846 -extern void *xen_initial_gdt;
30847 -
30848 struct trap_info;
30849 void xen_copy_trap_info(struct trap_info *traps);
30850
30851 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
30852 index 525bd3d..ef888b1 100644
30853 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
30854 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
30855 @@ -119,9 +119,9 @@
30856 ----------------------------------------------------------------------*/
30857
30858 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
30859 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
30860 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
30861 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
30862 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30863
30864 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
30865 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
30866 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
30867 index 2f33760..835e50a 100644
30868 --- a/arch/xtensa/variants/fsf/include/variant/core.h
30869 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
30870 @@ -11,6 +11,7 @@
30871 #ifndef _XTENSA_CORE_H
30872 #define _XTENSA_CORE_H
30873
30874 +#include <linux/const.h>
30875
30876 /****************************************************************************
30877 Parameters Useful for Any Code, USER or PRIVILEGED
30878 @@ -112,9 +113,9 @@
30879 ----------------------------------------------------------------------*/
30880
30881 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30882 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30883 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30884 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30885 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30886
30887 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
30888 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
30889 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
30890 index af00795..2bb8105 100644
30891 --- a/arch/xtensa/variants/s6000/include/variant/core.h
30892 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
30893 @@ -11,6 +11,7 @@
30894 #ifndef _XTENSA_CORE_CONFIGURATION_H
30895 #define _XTENSA_CORE_CONFIGURATION_H
30896
30897 +#include <linux/const.h>
30898
30899 /****************************************************************************
30900 Parameters Useful for Any Code, USER or PRIVILEGED
30901 @@ -118,9 +119,9 @@
30902 ----------------------------------------------------------------------*/
30903
30904 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30905 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30906 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30907 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30908 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30909
30910 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
30911 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
30912 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
30913 index 58916af..eb9dbcf6 100644
30914 --- a/block/blk-iopoll.c
30915 +++ b/block/blk-iopoll.c
30916 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
30917 }
30918 EXPORT_SYMBOL(blk_iopoll_complete);
30919
30920 -static void blk_iopoll_softirq(struct softirq_action *h)
30921 +static void blk_iopoll_softirq(void)
30922 {
30923 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
30924 int rearm = 0, budget = blk_iopoll_budget;
30925 @@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
30926 return NOTIFY_OK;
30927 }
30928
30929 -static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
30930 +static struct notifier_block blk_iopoll_cpu_notifier = {
30931 .notifier_call = blk_iopoll_cpu_notify,
30932 };
30933
30934 diff --git a/block/blk-map.c b/block/blk-map.c
30935 index 623e1cd..ca1e109 100644
30936 --- a/block/blk-map.c
30937 +++ b/block/blk-map.c
30938 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
30939 if (!len || !kbuf)
30940 return -EINVAL;
30941
30942 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
30943 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
30944 if (do_copy)
30945 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
30946 else
30947 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
30948 index 467c8de..f3628c5 100644
30949 --- a/block/blk-softirq.c
30950 +++ b/block/blk-softirq.c
30951 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
30952 * Softirq action handler - move entries to local list and loop over them
30953 * while passing them to the queue registered handler.
30954 */
30955 -static void blk_done_softirq(struct softirq_action *h)
30956 +static void blk_done_softirq(void)
30957 {
30958 struct list_head *cpu_list, local_list;
30959
30960 @@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
30961 return NOTIFY_OK;
30962 }
30963
30964 -static struct notifier_block __cpuinitdata blk_cpu_notifier = {
30965 +static struct notifier_block blk_cpu_notifier = {
30966 .notifier_call = blk_cpu_notify,
30967 };
30968
30969 diff --git a/block/bsg.c b/block/bsg.c
30970 index ff64ae3..593560c 100644
30971 --- a/block/bsg.c
30972 +++ b/block/bsg.c
30973 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
30974 struct sg_io_v4 *hdr, struct bsg_device *bd,
30975 fmode_t has_write_perm)
30976 {
30977 + unsigned char tmpcmd[sizeof(rq->__cmd)];
30978 + unsigned char *cmdptr;
30979 +
30980 if (hdr->request_len > BLK_MAX_CDB) {
30981 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
30982 if (!rq->cmd)
30983 return -ENOMEM;
30984 - }
30985 + cmdptr = rq->cmd;
30986 + } else
30987 + cmdptr = tmpcmd;
30988
30989 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
30990 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
30991 hdr->request_len))
30992 return -EFAULT;
30993
30994 + if (cmdptr != rq->cmd)
30995 + memcpy(rq->cmd, cmdptr, hdr->request_len);
30996 +
30997 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
30998 if (blk_verify_command(rq->cmd, has_write_perm))
30999 return -EPERM;
31000 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31001 index 7c668c8..db3521c 100644
31002 --- a/block/compat_ioctl.c
31003 +++ b/block/compat_ioctl.c
31004 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31005 err |= __get_user(f->spec1, &uf->spec1);
31006 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31007 err |= __get_user(name, &uf->name);
31008 - f->name = compat_ptr(name);
31009 + f->name = (void __force_kernel *)compat_ptr(name);
31010 if (err) {
31011 err = -EFAULT;
31012 goto out;
31013 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31014 index b62fb88..bdab4c4 100644
31015 --- a/block/partitions/efi.c
31016 +++ b/block/partitions/efi.c
31017 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31018 if (!gpt)
31019 return NULL;
31020
31021 + if (!le32_to_cpu(gpt->num_partition_entries))
31022 + return NULL;
31023 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31024 + if (!pte)
31025 + return NULL;
31026 +
31027 count = le32_to_cpu(gpt->num_partition_entries) *
31028 le32_to_cpu(gpt->sizeof_partition_entry);
31029 - if (!count)
31030 - return NULL;
31031 - pte = kzalloc(count, GFP_KERNEL);
31032 - if (!pte)
31033 - return NULL;
31034 -
31035 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31036 (u8 *) pte,
31037 count) < count) {
31038 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31039 index 9a87daa..fb17486 100644
31040 --- a/block/scsi_ioctl.c
31041 +++ b/block/scsi_ioctl.c
31042 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
31043 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31044 struct sg_io_hdr *hdr, fmode_t mode)
31045 {
31046 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31047 + unsigned char tmpcmd[sizeof(rq->__cmd)];
31048 + unsigned char *cmdptr;
31049 +
31050 + if (rq->cmd != rq->__cmd)
31051 + cmdptr = rq->cmd;
31052 + else
31053 + cmdptr = tmpcmd;
31054 +
31055 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31056 return -EFAULT;
31057 +
31058 + if (cmdptr != rq->cmd)
31059 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31060 +
31061 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31062 return -EPERM;
31063
31064 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31065 int err;
31066 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31067 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31068 + unsigned char tmpcmd[sizeof(rq->__cmd)];
31069 + unsigned char *cmdptr;
31070
31071 if (!sic)
31072 return -EINVAL;
31073 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31074 */
31075 err = -EFAULT;
31076 rq->cmd_len = cmdlen;
31077 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
31078 +
31079 + if (rq->cmd != rq->__cmd)
31080 + cmdptr = rq->cmd;
31081 + else
31082 + cmdptr = tmpcmd;
31083 +
31084 + if (copy_from_user(cmdptr, sic->data, cmdlen))
31085 goto error;
31086
31087 + if (rq->cmd != cmdptr)
31088 + memcpy(rq->cmd, cmdptr, cmdlen);
31089 +
31090 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31091 goto error;
31092
31093 diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
31094 index 533de95..7d4a8d2 100644
31095 --- a/crypto/ablkcipher.c
31096 +++ b/crypto/ablkcipher.c
31097 @@ -388,9 +388,9 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
31098 {
31099 struct crypto_report_blkcipher rblkcipher;
31100
31101 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "ablkcipher");
31102 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
31103 - alg->cra_ablkcipher.geniv ?: "<default>");
31104 + strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
31105 + strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>",
31106 + sizeof(rblkcipher.geniv));
31107
31108 rblkcipher.blocksize = alg->cra_blocksize;
31109 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
31110 @@ -469,9 +469,9 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
31111 {
31112 struct crypto_report_blkcipher rblkcipher;
31113
31114 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "givcipher");
31115 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
31116 - alg->cra_ablkcipher.geniv ?: "<built-in>");
31117 + strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type));
31118 + strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>",
31119 + sizeof(rblkcipher.geniv));
31120
31121 rblkcipher.blocksize = alg->cra_blocksize;
31122 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
31123 diff --git a/crypto/aead.c b/crypto/aead.c
31124 index 0b8121e..27bc487 100644
31125 --- a/crypto/aead.c
31126 +++ b/crypto/aead.c
31127 @@ -117,9 +117,8 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
31128 struct crypto_report_aead raead;
31129 struct aead_alg *aead = &alg->cra_aead;
31130
31131 - snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "aead");
31132 - snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s",
31133 - aead->geniv ?: "<built-in>");
31134 + strncpy(raead.type, "aead", sizeof(raead.type));
31135 + strncpy(raead.geniv, aead->geniv ?: "<built-in>", sizeof(raead.geniv));
31136
31137 raead.blocksize = alg->cra_blocksize;
31138 raead.maxauthsize = aead->maxauthsize;
31139 @@ -203,8 +202,8 @@ static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
31140 struct crypto_report_aead raead;
31141 struct aead_alg *aead = &alg->cra_aead;
31142
31143 - snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "nivaead");
31144 - snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s", aead->geniv);
31145 + strncpy(raead.type, "nivaead", sizeof(raead.type));
31146 + strncpy(raead.geniv, aead->geniv, sizeof(raead.geniv));
31147
31148 raead.blocksize = alg->cra_blocksize;
31149 raead.maxauthsize = aead->maxauthsize;
31150 diff --git a/crypto/ahash.c b/crypto/ahash.c
31151 index 3887856..793a27f 100644
31152 --- a/crypto/ahash.c
31153 +++ b/crypto/ahash.c
31154 @@ -404,7 +404,7 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
31155 {
31156 struct crypto_report_hash rhash;
31157
31158 - snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "ahash");
31159 + strncpy(rhash.type, "ahash", sizeof(rhash.type));
31160
31161 rhash.blocksize = alg->cra_blocksize;
31162 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
31163 diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
31164 index a8d85a1..c44e014 100644
31165 --- a/crypto/blkcipher.c
31166 +++ b/crypto/blkcipher.c
31167 @@ -499,9 +499,9 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
31168 {
31169 struct crypto_report_blkcipher rblkcipher;
31170
31171 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "blkcipher");
31172 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
31173 - alg->cra_blkcipher.geniv ?: "<default>");
31174 + strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type));
31175 + strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>",
31176 + sizeof(rblkcipher.geniv));
31177
31178 rblkcipher.blocksize = alg->cra_blocksize;
31179 rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
31180 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31181 index 7bdd61b..afec999 100644
31182 --- a/crypto/cryptd.c
31183 +++ b/crypto/cryptd.c
31184 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31185
31186 struct cryptd_blkcipher_request_ctx {
31187 crypto_completion_t complete;
31188 -};
31189 +} __no_const;
31190
31191 struct cryptd_hash_ctx {
31192 struct crypto_shash *child;
31193 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31194
31195 struct cryptd_aead_request_ctx {
31196 crypto_completion_t complete;
31197 -};
31198 +} __no_const;
31199
31200 static void cryptd_queue_worker(struct work_struct *work);
31201
31202 diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
31203 index 35d700a..dfd511f 100644
31204 --- a/crypto/crypto_user.c
31205 +++ b/crypto/crypto_user.c
31206 @@ -30,6 +30,8 @@
31207
31208 #include "internal.h"
31209
31210 +#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
31211 +
31212 static DEFINE_MUTEX(crypto_cfg_mutex);
31213
31214 /* The crypto netlink socket */
31215 @@ -75,7 +77,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
31216 {
31217 struct crypto_report_cipher rcipher;
31218
31219 - snprintf(rcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "cipher");
31220 + strncpy(rcipher.type, "cipher", sizeof(rcipher.type));
31221
31222 rcipher.blocksize = alg->cra_blocksize;
31223 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
31224 @@ -94,8 +96,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
31225 {
31226 struct crypto_report_comp rcomp;
31227
31228 - snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression");
31229 -
31230 + strncpy(rcomp.type, "compression", sizeof(rcomp.type));
31231 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
31232 sizeof(struct crypto_report_comp), &rcomp))
31233 goto nla_put_failure;
31234 @@ -108,12 +109,14 @@ nla_put_failure:
31235 static int crypto_report_one(struct crypto_alg *alg,
31236 struct crypto_user_alg *ualg, struct sk_buff *skb)
31237 {
31238 - memcpy(&ualg->cru_name, &alg->cra_name, sizeof(ualg->cru_name));
31239 - memcpy(&ualg->cru_driver_name, &alg->cra_driver_name,
31240 - sizeof(ualg->cru_driver_name));
31241 - memcpy(&ualg->cru_module_name, module_name(alg->cra_module),
31242 - CRYPTO_MAX_ALG_NAME);
31243 + strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
31244 + strncpy(ualg->cru_driver_name, alg->cra_driver_name,
31245 + sizeof(ualg->cru_driver_name));
31246 + strncpy(ualg->cru_module_name, module_name(alg->cra_module),
31247 + sizeof(ualg->cru_module_name));
31248
31249 + ualg->cru_type = 0;
31250 + ualg->cru_mask = 0;
31251 ualg->cru_flags = alg->cra_flags;
31252 ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
31253
31254 @@ -122,8 +125,7 @@ static int crypto_report_one(struct crypto_alg *alg,
31255 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
31256 struct crypto_report_larval rl;
31257
31258 - snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval");
31259 -
31260 + strncpy(rl.type, "larval", sizeof(rl.type));
31261 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
31262 sizeof(struct crypto_report_larval), &rl))
31263 goto nla_put_failure;
31264 @@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
31265 struct crypto_dump_info info;
31266 int err;
31267
31268 - if (!p->cru_driver_name)
31269 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31270 + return -EINVAL;
31271 +
31272 + if (!p->cru_driver_name[0])
31273 return -EINVAL;
31274
31275 alg = crypto_alg_match(p, 1);
31276 @@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31277 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31278 LIST_HEAD(list);
31279
31280 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31281 + return -EINVAL;
31282 +
31283 if (priority && !strlen(p->cru_driver_name))
31284 return -EINVAL;
31285
31286 @@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31287 struct crypto_alg *alg;
31288 struct crypto_user_alg *p = nlmsg_data(nlh);
31289
31290 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31291 + return -EINVAL;
31292 +
31293 alg = crypto_alg_match(p, 1);
31294 if (!alg)
31295 return -ENOENT;
31296 @@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31297 struct crypto_user_alg *p = nlmsg_data(nlh);
31298 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31299
31300 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31301 + return -EINVAL;
31302 +
31303 if (strlen(p->cru_driver_name))
31304 exact = 1;
31305
31306 diff --git a/crypto/pcompress.c b/crypto/pcompress.c
31307 index 04e083f..7140fe7 100644
31308 --- a/crypto/pcompress.c
31309 +++ b/crypto/pcompress.c
31310 @@ -53,8 +53,7 @@ static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
31311 {
31312 struct crypto_report_comp rpcomp;
31313
31314 - snprintf(rpcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "pcomp");
31315 -
31316 + strncpy(rpcomp.type, "pcomp", sizeof(rpcomp.type));
31317 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
31318 sizeof(struct crypto_report_comp), &rpcomp))
31319 goto nla_put_failure;
31320 diff --git a/crypto/rng.c b/crypto/rng.c
31321 index f3b7894..e0a25c2 100644
31322 --- a/crypto/rng.c
31323 +++ b/crypto/rng.c
31324 @@ -65,7 +65,7 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
31325 {
31326 struct crypto_report_rng rrng;
31327
31328 - snprintf(rrng.type, CRYPTO_MAX_ALG_NAME, "%s", "rng");
31329 + strncpy(rrng.type, "rng", sizeof(rrng.type));
31330
31331 rrng.seedsize = alg->cra_rng.seedsize;
31332
31333 diff --git a/crypto/shash.c b/crypto/shash.c
31334 index f426330f..929058a 100644
31335 --- a/crypto/shash.c
31336 +++ b/crypto/shash.c
31337 @@ -530,7 +530,8 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
31338 struct crypto_report_hash rhash;
31339 struct shash_alg *salg = __crypto_shash_alg(alg);
31340
31341 - snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "shash");
31342 + strncpy(rhash.type, "shash", sizeof(rhash.type));
31343 +
31344 rhash.blocksize = alg->cra_blocksize;
31345 rhash.digestsize = salg->digestsize;
31346
31347 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31348 index f220d64..d359ad6 100644
31349 --- a/drivers/acpi/apei/apei-internal.h
31350 +++ b/drivers/acpi/apei/apei-internal.h
31351 @@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31352 struct apei_exec_ins_type {
31353 u32 flags;
31354 apei_exec_ins_func_t run;
31355 -};
31356 +} __do_const;
31357
31358 struct apei_exec_context {
31359 u32 ip;
31360 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31361 index e6defd8..c26a225 100644
31362 --- a/drivers/acpi/apei/cper.c
31363 +++ b/drivers/acpi/apei/cper.c
31364 @@ -38,12 +38,12 @@
31365 */
31366 u64 cper_next_record_id(void)
31367 {
31368 - static atomic64_t seq;
31369 + static atomic64_unchecked_t seq;
31370
31371 - if (!atomic64_read(&seq))
31372 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
31373 + if (!atomic64_read_unchecked(&seq))
31374 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31375
31376 - return atomic64_inc_return(&seq);
31377 + return atomic64_inc_return_unchecked(&seq);
31378 }
31379 EXPORT_SYMBOL_GPL(cper_next_record_id);
31380
31381 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31382 index be60399..778b33e8 100644
31383 --- a/drivers/acpi/bgrt.c
31384 +++ b/drivers/acpi/bgrt.c
31385 @@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31386 return -ENODEV;
31387
31388 sysfs_bin_attr_init(&image_attr);
31389 - image_attr.private = bgrt_image;
31390 - image_attr.size = bgrt_image_size;
31391 + pax_open_kernel();
31392 + *(void **)&image_attr.private = bgrt_image;
31393 + *(size_t *)&image_attr.size = bgrt_image_size;
31394 + pax_close_kernel();
31395
31396 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31397 if (!bgrt_kobj)
31398 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31399 index cb96296..b81293b 100644
31400 --- a/drivers/acpi/blacklist.c
31401 +++ b/drivers/acpi/blacklist.c
31402 @@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31403 u32 is_critical_error;
31404 };
31405
31406 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31407 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31408
31409 /*
31410 * POLICY: If *anything* doesn't work, put it on the blacklist.
31411 @@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31412 return 0;
31413 }
31414
31415 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
31416 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
31417 {
31418 .callback = dmi_disable_osi_vista,
31419 .ident = "Fujitsu Siemens",
31420 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31421 index 7586544..636a2f0 100644
31422 --- a/drivers/acpi/ec_sys.c
31423 +++ b/drivers/acpi/ec_sys.c
31424 @@ -12,6 +12,7 @@
31425 #include <linux/acpi.h>
31426 #include <linux/debugfs.h>
31427 #include <linux/module.h>
31428 +#include <linux/uaccess.h>
31429 #include "internal.h"
31430
31431 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31432 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31433 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31434 */
31435 unsigned int size = EC_SPACE_SIZE;
31436 - u8 *data = (u8 *) buf;
31437 + u8 data;
31438 loff_t init_off = *off;
31439 int err = 0;
31440
31441 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31442 size = count;
31443
31444 while (size) {
31445 - err = ec_read(*off, &data[*off - init_off]);
31446 + err = ec_read(*off, &data);
31447 if (err)
31448 return err;
31449 + if (put_user(data, &buf[*off - init_off]))
31450 + return -EFAULT;
31451 *off += 1;
31452 size--;
31453 }
31454 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31455
31456 unsigned int size = count;
31457 loff_t init_off = *off;
31458 - u8 *data = (u8 *) buf;
31459 int err = 0;
31460
31461 if (*off >= EC_SPACE_SIZE)
31462 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31463 }
31464
31465 while (size) {
31466 - u8 byte_write = data[*off - init_off];
31467 + u8 byte_write;
31468 + if (get_user(byte_write, &buf[*off - init_off]))
31469 + return -EFAULT;
31470 err = ec_write(*off, byte_write);
31471 if (err)
31472 return err;
31473 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
31474 index e83311b..142b5cc 100644
31475 --- a/drivers/acpi/processor_driver.c
31476 +++ b/drivers/acpi/processor_driver.c
31477 @@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
31478 return 0;
31479 #endif
31480
31481 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
31482 + BUG_ON(pr->id >= nr_cpu_ids);
31483
31484 /*
31485 * Buggy BIOS check
31486 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
31487 index ed9a1cc..f4a354c 100644
31488 --- a/drivers/acpi/processor_idle.c
31489 +++ b/drivers/acpi/processor_idle.c
31490 @@ -1005,7 +1005,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
31491 {
31492 int i, count = CPUIDLE_DRIVER_STATE_START;
31493 struct acpi_processor_cx *cx;
31494 - struct cpuidle_state *state;
31495 + cpuidle_state_no_const *state;
31496 struct cpuidle_driver *drv = &acpi_idle_driver;
31497
31498 if (!pr->flags.power_setup_done)
31499 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
31500 index ea61ca9..3fdd70d 100644
31501 --- a/drivers/acpi/sysfs.c
31502 +++ b/drivers/acpi/sysfs.c
31503 @@ -420,11 +420,11 @@ static u32 num_counters;
31504 static struct attribute **all_attrs;
31505 static u32 acpi_gpe_count;
31506
31507 -static struct attribute_group interrupt_stats_attr_group = {
31508 +static attribute_group_no_const interrupt_stats_attr_group = {
31509 .name = "interrupts",
31510 };
31511
31512 -static struct kobj_attribute *counter_attrs;
31513 +static kobj_attribute_no_const *counter_attrs;
31514
31515 static void delete_gpe_attr_array(void)
31516 {
31517 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
31518 index 46cd3f4..0871ad0 100644
31519 --- a/drivers/ata/libata-core.c
31520 +++ b/drivers/ata/libata-core.c
31521 @@ -4780,7 +4780,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
31522 struct ata_port *ap;
31523 unsigned int tag;
31524
31525 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31526 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31527 ap = qc->ap;
31528
31529 qc->flags = 0;
31530 @@ -4796,7 +4796,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
31531 struct ata_port *ap;
31532 struct ata_link *link;
31533
31534 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31535 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31536 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31537 ap = qc->ap;
31538 link = qc->dev->link;
31539 @@ -5892,6 +5892,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31540 return;
31541
31542 spin_lock(&lock);
31543 + pax_open_kernel();
31544
31545 for (cur = ops->inherits; cur; cur = cur->inherits) {
31546 void **inherit = (void **)cur;
31547 @@ -5905,8 +5906,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31548 if (IS_ERR(*pp))
31549 *pp = NULL;
31550
31551 - ops->inherits = NULL;
31552 + *(struct ata_port_operations **)&ops->inherits = NULL;
31553
31554 + pax_close_kernel();
31555 spin_unlock(&lock);
31556 }
31557
31558 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31559 index 405022d..fb70e53 100644
31560 --- a/drivers/ata/pata_arasan_cf.c
31561 +++ b/drivers/ata/pata_arasan_cf.c
31562 @@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31563 /* Handle platform specific quirks */
31564 if (pdata->quirk) {
31565 if (pdata->quirk & CF_BROKEN_PIO) {
31566 - ap->ops->set_piomode = NULL;
31567 + pax_open_kernel();
31568 + *(void **)&ap->ops->set_piomode = NULL;
31569 + pax_close_kernel();
31570 ap->pio_mask = 0;
31571 }
31572 if (pdata->quirk & CF_BROKEN_MWDMA)
31573 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31574 index f9b983a..887b9d8 100644
31575 --- a/drivers/atm/adummy.c
31576 +++ b/drivers/atm/adummy.c
31577 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31578 vcc->pop(vcc, skb);
31579 else
31580 dev_kfree_skb_any(skb);
31581 - atomic_inc(&vcc->stats->tx);
31582 + atomic_inc_unchecked(&vcc->stats->tx);
31583
31584 return 0;
31585 }
31586 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31587 index 77a7480..05cde58 100644
31588 --- a/drivers/atm/ambassador.c
31589 +++ b/drivers/atm/ambassador.c
31590 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31591 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31592
31593 // VC layer stats
31594 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31595 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31596
31597 // free the descriptor
31598 kfree (tx_descr);
31599 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31600 dump_skb ("<<<", vc, skb);
31601
31602 // VC layer stats
31603 - atomic_inc(&atm_vcc->stats->rx);
31604 + atomic_inc_unchecked(&atm_vcc->stats->rx);
31605 __net_timestamp(skb);
31606 // end of our responsibility
31607 atm_vcc->push (atm_vcc, skb);
31608 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31609 } else {
31610 PRINTK (KERN_INFO, "dropped over-size frame");
31611 // should we count this?
31612 - atomic_inc(&atm_vcc->stats->rx_drop);
31613 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31614 }
31615
31616 } else {
31617 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
31618 }
31619
31620 if (check_area (skb->data, skb->len)) {
31621 - atomic_inc(&atm_vcc->stats->tx_err);
31622 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
31623 return -ENOMEM; // ?
31624 }
31625
31626 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
31627 index b22d71c..d6e1049 100644
31628 --- a/drivers/atm/atmtcp.c
31629 +++ b/drivers/atm/atmtcp.c
31630 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31631 if (vcc->pop) vcc->pop(vcc,skb);
31632 else dev_kfree_skb(skb);
31633 if (dev_data) return 0;
31634 - atomic_inc(&vcc->stats->tx_err);
31635 + atomic_inc_unchecked(&vcc->stats->tx_err);
31636 return -ENOLINK;
31637 }
31638 size = skb->len+sizeof(struct atmtcp_hdr);
31639 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31640 if (!new_skb) {
31641 if (vcc->pop) vcc->pop(vcc,skb);
31642 else dev_kfree_skb(skb);
31643 - atomic_inc(&vcc->stats->tx_err);
31644 + atomic_inc_unchecked(&vcc->stats->tx_err);
31645 return -ENOBUFS;
31646 }
31647 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
31648 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31649 if (vcc->pop) vcc->pop(vcc,skb);
31650 else dev_kfree_skb(skb);
31651 out_vcc->push(out_vcc,new_skb);
31652 - atomic_inc(&vcc->stats->tx);
31653 - atomic_inc(&out_vcc->stats->rx);
31654 + atomic_inc_unchecked(&vcc->stats->tx);
31655 + atomic_inc_unchecked(&out_vcc->stats->rx);
31656 return 0;
31657 }
31658
31659 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31660 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
31661 read_unlock(&vcc_sklist_lock);
31662 if (!out_vcc) {
31663 - atomic_inc(&vcc->stats->tx_err);
31664 + atomic_inc_unchecked(&vcc->stats->tx_err);
31665 goto done;
31666 }
31667 skb_pull(skb,sizeof(struct atmtcp_hdr));
31668 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31669 __net_timestamp(new_skb);
31670 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
31671 out_vcc->push(out_vcc,new_skb);
31672 - atomic_inc(&vcc->stats->tx);
31673 - atomic_inc(&out_vcc->stats->rx);
31674 + atomic_inc_unchecked(&vcc->stats->tx);
31675 + atomic_inc_unchecked(&out_vcc->stats->rx);
31676 done:
31677 if (vcc->pop) vcc->pop(vcc,skb);
31678 else dev_kfree_skb(skb);
31679 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
31680 index c1eb6fa..4c71be9 100644
31681 --- a/drivers/atm/eni.c
31682 +++ b/drivers/atm/eni.c
31683 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
31684 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
31685 vcc->dev->number);
31686 length = 0;
31687 - atomic_inc(&vcc->stats->rx_err);
31688 + atomic_inc_unchecked(&vcc->stats->rx_err);
31689 }
31690 else {
31691 length = ATM_CELL_SIZE-1; /* no HEC */
31692 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31693 size);
31694 }
31695 eff = length = 0;
31696 - atomic_inc(&vcc->stats->rx_err);
31697 + atomic_inc_unchecked(&vcc->stats->rx_err);
31698 }
31699 else {
31700 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
31701 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31702 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
31703 vcc->dev->number,vcc->vci,length,size << 2,descr);
31704 length = eff = 0;
31705 - atomic_inc(&vcc->stats->rx_err);
31706 + atomic_inc_unchecked(&vcc->stats->rx_err);
31707 }
31708 }
31709 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
31710 @@ -767,7 +767,7 @@ rx_dequeued++;
31711 vcc->push(vcc,skb);
31712 pushed++;
31713 }
31714 - atomic_inc(&vcc->stats->rx);
31715 + atomic_inc_unchecked(&vcc->stats->rx);
31716 }
31717 wake_up(&eni_dev->rx_wait);
31718 }
31719 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
31720 PCI_DMA_TODEVICE);
31721 if (vcc->pop) vcc->pop(vcc,skb);
31722 else dev_kfree_skb_irq(skb);
31723 - atomic_inc(&vcc->stats->tx);
31724 + atomic_inc_unchecked(&vcc->stats->tx);
31725 wake_up(&eni_dev->tx_wait);
31726 dma_complete++;
31727 }
31728 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
31729 index b41c948..a002b17 100644
31730 --- a/drivers/atm/firestream.c
31731 +++ b/drivers/atm/firestream.c
31732 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
31733 }
31734 }
31735
31736 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31737 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31738
31739 fs_dprintk (FS_DEBUG_TXMEM, "i");
31740 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
31741 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31742 #endif
31743 skb_put (skb, qe->p1 & 0xffff);
31744 ATM_SKB(skb)->vcc = atm_vcc;
31745 - atomic_inc(&atm_vcc->stats->rx);
31746 + atomic_inc_unchecked(&atm_vcc->stats->rx);
31747 __net_timestamp(skb);
31748 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
31749 atm_vcc->push (atm_vcc, skb);
31750 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31751 kfree (pe);
31752 }
31753 if (atm_vcc)
31754 - atomic_inc(&atm_vcc->stats->rx_drop);
31755 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31756 break;
31757 case 0x1f: /* Reassembly abort: no buffers. */
31758 /* Silently increment error counter. */
31759 if (atm_vcc)
31760 - atomic_inc(&atm_vcc->stats->rx_drop);
31761 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31762 break;
31763 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
31764 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
31765 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
31766 index 204814e..cede831 100644
31767 --- a/drivers/atm/fore200e.c
31768 +++ b/drivers/atm/fore200e.c
31769 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
31770 #endif
31771 /* check error condition */
31772 if (*entry->status & STATUS_ERROR)
31773 - atomic_inc(&vcc->stats->tx_err);
31774 + atomic_inc_unchecked(&vcc->stats->tx_err);
31775 else
31776 - atomic_inc(&vcc->stats->tx);
31777 + atomic_inc_unchecked(&vcc->stats->tx);
31778 }
31779 }
31780
31781 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31782 if (skb == NULL) {
31783 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
31784
31785 - atomic_inc(&vcc->stats->rx_drop);
31786 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31787 return -ENOMEM;
31788 }
31789
31790 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31791
31792 dev_kfree_skb_any(skb);
31793
31794 - atomic_inc(&vcc->stats->rx_drop);
31795 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31796 return -ENOMEM;
31797 }
31798
31799 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31800
31801 vcc->push(vcc, skb);
31802 - atomic_inc(&vcc->stats->rx);
31803 + atomic_inc_unchecked(&vcc->stats->rx);
31804
31805 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31806
31807 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
31808 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
31809 fore200e->atm_dev->number,
31810 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
31811 - atomic_inc(&vcc->stats->rx_err);
31812 + atomic_inc_unchecked(&vcc->stats->rx_err);
31813 }
31814 }
31815
31816 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
31817 goto retry_here;
31818 }
31819
31820 - atomic_inc(&vcc->stats->tx_err);
31821 + atomic_inc_unchecked(&vcc->stats->tx_err);
31822
31823 fore200e->tx_sat++;
31824 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
31825 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
31826 index 72b6960..cf9167a 100644
31827 --- a/drivers/atm/he.c
31828 +++ b/drivers/atm/he.c
31829 @@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31830
31831 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
31832 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
31833 - atomic_inc(&vcc->stats->rx_drop);
31834 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31835 goto return_host_buffers;
31836 }
31837
31838 @@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31839 RBRQ_LEN_ERR(he_dev->rbrq_head)
31840 ? "LEN_ERR" : "",
31841 vcc->vpi, vcc->vci);
31842 - atomic_inc(&vcc->stats->rx_err);
31843 + atomic_inc_unchecked(&vcc->stats->rx_err);
31844 goto return_host_buffers;
31845 }
31846
31847 @@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31848 vcc->push(vcc, skb);
31849 spin_lock(&he_dev->global_lock);
31850
31851 - atomic_inc(&vcc->stats->rx);
31852 + atomic_inc_unchecked(&vcc->stats->rx);
31853
31854 return_host_buffers:
31855 ++pdus_assembled;
31856 @@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
31857 tpd->vcc->pop(tpd->vcc, tpd->skb);
31858 else
31859 dev_kfree_skb_any(tpd->skb);
31860 - atomic_inc(&tpd->vcc->stats->tx_err);
31861 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
31862 }
31863 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
31864 return;
31865 @@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31866 vcc->pop(vcc, skb);
31867 else
31868 dev_kfree_skb_any(skb);
31869 - atomic_inc(&vcc->stats->tx_err);
31870 + atomic_inc_unchecked(&vcc->stats->tx_err);
31871 return -EINVAL;
31872 }
31873
31874 @@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31875 vcc->pop(vcc, skb);
31876 else
31877 dev_kfree_skb_any(skb);
31878 - atomic_inc(&vcc->stats->tx_err);
31879 + atomic_inc_unchecked(&vcc->stats->tx_err);
31880 return -EINVAL;
31881 }
31882 #endif
31883 @@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31884 vcc->pop(vcc, skb);
31885 else
31886 dev_kfree_skb_any(skb);
31887 - atomic_inc(&vcc->stats->tx_err);
31888 + atomic_inc_unchecked(&vcc->stats->tx_err);
31889 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31890 return -ENOMEM;
31891 }
31892 @@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31893 vcc->pop(vcc, skb);
31894 else
31895 dev_kfree_skb_any(skb);
31896 - atomic_inc(&vcc->stats->tx_err);
31897 + atomic_inc_unchecked(&vcc->stats->tx_err);
31898 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31899 return -ENOMEM;
31900 }
31901 @@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31902 __enqueue_tpd(he_dev, tpd, cid);
31903 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31904
31905 - atomic_inc(&vcc->stats->tx);
31906 + atomic_inc_unchecked(&vcc->stats->tx);
31907
31908 return 0;
31909 }
31910 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
31911 index 1dc0519..1aadaf7 100644
31912 --- a/drivers/atm/horizon.c
31913 +++ b/drivers/atm/horizon.c
31914 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
31915 {
31916 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
31917 // VC layer stats
31918 - atomic_inc(&vcc->stats->rx);
31919 + atomic_inc_unchecked(&vcc->stats->rx);
31920 __net_timestamp(skb);
31921 // end of our responsibility
31922 vcc->push (vcc, skb);
31923 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
31924 dev->tx_iovec = NULL;
31925
31926 // VC layer stats
31927 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31928 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31929
31930 // free the skb
31931 hrz_kfree_skb (skb);
31932 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
31933 index 272f009..a18ba55 100644
31934 --- a/drivers/atm/idt77252.c
31935 +++ b/drivers/atm/idt77252.c
31936 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
31937 else
31938 dev_kfree_skb(skb);
31939
31940 - atomic_inc(&vcc->stats->tx);
31941 + atomic_inc_unchecked(&vcc->stats->tx);
31942 }
31943
31944 atomic_dec(&scq->used);
31945 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31946 if ((sb = dev_alloc_skb(64)) == NULL) {
31947 printk("%s: Can't allocate buffers for aal0.\n",
31948 card->name);
31949 - atomic_add(i, &vcc->stats->rx_drop);
31950 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
31951 break;
31952 }
31953 if (!atm_charge(vcc, sb->truesize)) {
31954 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
31955 card->name);
31956 - atomic_add(i - 1, &vcc->stats->rx_drop);
31957 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
31958 dev_kfree_skb(sb);
31959 break;
31960 }
31961 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31962 ATM_SKB(sb)->vcc = vcc;
31963 __net_timestamp(sb);
31964 vcc->push(vcc, sb);
31965 - atomic_inc(&vcc->stats->rx);
31966 + atomic_inc_unchecked(&vcc->stats->rx);
31967
31968 cell += ATM_CELL_PAYLOAD;
31969 }
31970 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31971 "(CDC: %08x)\n",
31972 card->name, len, rpp->len, readl(SAR_REG_CDC));
31973 recycle_rx_pool_skb(card, rpp);
31974 - atomic_inc(&vcc->stats->rx_err);
31975 + atomic_inc_unchecked(&vcc->stats->rx_err);
31976 return;
31977 }
31978 if (stat & SAR_RSQE_CRC) {
31979 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
31980 recycle_rx_pool_skb(card, rpp);
31981 - atomic_inc(&vcc->stats->rx_err);
31982 + atomic_inc_unchecked(&vcc->stats->rx_err);
31983 return;
31984 }
31985 if (skb_queue_len(&rpp->queue) > 1) {
31986 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31987 RXPRINTK("%s: Can't alloc RX skb.\n",
31988 card->name);
31989 recycle_rx_pool_skb(card, rpp);
31990 - atomic_inc(&vcc->stats->rx_err);
31991 + atomic_inc_unchecked(&vcc->stats->rx_err);
31992 return;
31993 }
31994 if (!atm_charge(vcc, skb->truesize)) {
31995 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31996 __net_timestamp(skb);
31997
31998 vcc->push(vcc, skb);
31999 - atomic_inc(&vcc->stats->rx);
32000 + atomic_inc_unchecked(&vcc->stats->rx);
32001
32002 return;
32003 }
32004 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32005 __net_timestamp(skb);
32006
32007 vcc->push(vcc, skb);
32008 - atomic_inc(&vcc->stats->rx);
32009 + atomic_inc_unchecked(&vcc->stats->rx);
32010
32011 if (skb->truesize > SAR_FB_SIZE_3)
32012 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32013 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32014 if (vcc->qos.aal != ATM_AAL0) {
32015 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32016 card->name, vpi, vci);
32017 - atomic_inc(&vcc->stats->rx_drop);
32018 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32019 goto drop;
32020 }
32021
32022 if ((sb = dev_alloc_skb(64)) == NULL) {
32023 printk("%s: Can't allocate buffers for AAL0.\n",
32024 card->name);
32025 - atomic_inc(&vcc->stats->rx_err);
32026 + atomic_inc_unchecked(&vcc->stats->rx_err);
32027 goto drop;
32028 }
32029
32030 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32031 ATM_SKB(sb)->vcc = vcc;
32032 __net_timestamp(sb);
32033 vcc->push(vcc, sb);
32034 - atomic_inc(&vcc->stats->rx);
32035 + atomic_inc_unchecked(&vcc->stats->rx);
32036
32037 drop:
32038 skb_pull(queue, 64);
32039 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32040
32041 if (vc == NULL) {
32042 printk("%s: NULL connection in send().\n", card->name);
32043 - atomic_inc(&vcc->stats->tx_err);
32044 + atomic_inc_unchecked(&vcc->stats->tx_err);
32045 dev_kfree_skb(skb);
32046 return -EINVAL;
32047 }
32048 if (!test_bit(VCF_TX, &vc->flags)) {
32049 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32050 - atomic_inc(&vcc->stats->tx_err);
32051 + atomic_inc_unchecked(&vcc->stats->tx_err);
32052 dev_kfree_skb(skb);
32053 return -EINVAL;
32054 }
32055 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32056 break;
32057 default:
32058 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32059 - atomic_inc(&vcc->stats->tx_err);
32060 + atomic_inc_unchecked(&vcc->stats->tx_err);
32061 dev_kfree_skb(skb);
32062 return -EINVAL;
32063 }
32064
32065 if (skb_shinfo(skb)->nr_frags != 0) {
32066 printk("%s: No scatter-gather yet.\n", card->name);
32067 - atomic_inc(&vcc->stats->tx_err);
32068 + atomic_inc_unchecked(&vcc->stats->tx_err);
32069 dev_kfree_skb(skb);
32070 return -EINVAL;
32071 }
32072 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32073
32074 err = queue_skb(card, vc, skb, oam);
32075 if (err) {
32076 - atomic_inc(&vcc->stats->tx_err);
32077 + atomic_inc_unchecked(&vcc->stats->tx_err);
32078 dev_kfree_skb(skb);
32079 return err;
32080 }
32081 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32082 skb = dev_alloc_skb(64);
32083 if (!skb) {
32084 printk("%s: Out of memory in send_oam().\n", card->name);
32085 - atomic_inc(&vcc->stats->tx_err);
32086 + atomic_inc_unchecked(&vcc->stats->tx_err);
32087 return -ENOMEM;
32088 }
32089 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32090 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32091 index 4217f29..88f547a 100644
32092 --- a/drivers/atm/iphase.c
32093 +++ b/drivers/atm/iphase.c
32094 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32095 status = (u_short) (buf_desc_ptr->desc_mode);
32096 if (status & (RX_CER | RX_PTE | RX_OFL))
32097 {
32098 - atomic_inc(&vcc->stats->rx_err);
32099 + atomic_inc_unchecked(&vcc->stats->rx_err);
32100 IF_ERR(printk("IA: bad packet, dropping it");)
32101 if (status & RX_CER) {
32102 IF_ERR(printk(" cause: packet CRC error\n");)
32103 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32104 len = dma_addr - buf_addr;
32105 if (len > iadev->rx_buf_sz) {
32106 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32107 - atomic_inc(&vcc->stats->rx_err);
32108 + atomic_inc_unchecked(&vcc->stats->rx_err);
32109 goto out_free_desc;
32110 }
32111
32112 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32113 ia_vcc = INPH_IA_VCC(vcc);
32114 if (ia_vcc == NULL)
32115 {
32116 - atomic_inc(&vcc->stats->rx_err);
32117 + atomic_inc_unchecked(&vcc->stats->rx_err);
32118 atm_return(vcc, skb->truesize);
32119 dev_kfree_skb_any(skb);
32120 goto INCR_DLE;
32121 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32122 if ((length > iadev->rx_buf_sz) || (length >
32123 (skb->len - sizeof(struct cpcs_trailer))))
32124 {
32125 - atomic_inc(&vcc->stats->rx_err);
32126 + atomic_inc_unchecked(&vcc->stats->rx_err);
32127 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32128 length, skb->len);)
32129 atm_return(vcc, skb->truesize);
32130 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32131
32132 IF_RX(printk("rx_dle_intr: skb push");)
32133 vcc->push(vcc,skb);
32134 - atomic_inc(&vcc->stats->rx);
32135 + atomic_inc_unchecked(&vcc->stats->rx);
32136 iadev->rx_pkt_cnt++;
32137 }
32138 INCR_DLE:
32139 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32140 {
32141 struct k_sonet_stats *stats;
32142 stats = &PRIV(_ia_dev[board])->sonet_stats;
32143 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32144 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32145 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32146 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32147 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32148 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32149 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32150 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32151 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32152 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32153 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32154 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32155 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32156 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32157 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32158 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32159 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32160 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32161 }
32162 ia_cmds.status = 0;
32163 break;
32164 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32165 if ((desc == 0) || (desc > iadev->num_tx_desc))
32166 {
32167 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32168 - atomic_inc(&vcc->stats->tx);
32169 + atomic_inc_unchecked(&vcc->stats->tx);
32170 if (vcc->pop)
32171 vcc->pop(vcc, skb);
32172 else
32173 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32174 ATM_DESC(skb) = vcc->vci;
32175 skb_queue_tail(&iadev->tx_dma_q, skb);
32176
32177 - atomic_inc(&vcc->stats->tx);
32178 + atomic_inc_unchecked(&vcc->stats->tx);
32179 iadev->tx_pkt_cnt++;
32180 /* Increment transaction counter */
32181 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32182
32183 #if 0
32184 /* add flow control logic */
32185 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32186 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32187 if (iavcc->vc_desc_cnt > 10) {
32188 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32189 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32190 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32191 index fa7d701..1e404c7 100644
32192 --- a/drivers/atm/lanai.c
32193 +++ b/drivers/atm/lanai.c
32194 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32195 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32196 lanai_endtx(lanai, lvcc);
32197 lanai_free_skb(lvcc->tx.atmvcc, skb);
32198 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32199 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32200 }
32201
32202 /* Try to fill the buffer - don't call unless there is backlog */
32203 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32204 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32205 __net_timestamp(skb);
32206 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32207 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32208 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32209 out:
32210 lvcc->rx.buf.ptr = end;
32211 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32212 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32213 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32214 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32215 lanai->stats.service_rxnotaal5++;
32216 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32217 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32218 return 0;
32219 }
32220 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32221 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32222 int bytes;
32223 read_unlock(&vcc_sklist_lock);
32224 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32225 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32226 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32227 lvcc->stats.x.aal5.service_trash++;
32228 bytes = (SERVICE_GET_END(s) * 16) -
32229 (((unsigned long) lvcc->rx.buf.ptr) -
32230 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32231 }
32232 if (s & SERVICE_STREAM) {
32233 read_unlock(&vcc_sklist_lock);
32234 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32235 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32236 lvcc->stats.x.aal5.service_stream++;
32237 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32238 "PDU on VCI %d!\n", lanai->number, vci);
32239 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32240 return 0;
32241 }
32242 DPRINTK("got rx crc error on vci %d\n", vci);
32243 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32244 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32245 lvcc->stats.x.aal5.service_rxcrc++;
32246 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32247 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32248 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32249 index ed1d2b7..8cffc1f 100644
32250 --- a/drivers/atm/nicstar.c
32251 +++ b/drivers/atm/nicstar.c
32252 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32253 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32254 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32255 card->index);
32256 - atomic_inc(&vcc->stats->tx_err);
32257 + atomic_inc_unchecked(&vcc->stats->tx_err);
32258 dev_kfree_skb_any(skb);
32259 return -EINVAL;
32260 }
32261 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32262 if (!vc->tx) {
32263 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32264 card->index);
32265 - atomic_inc(&vcc->stats->tx_err);
32266 + atomic_inc_unchecked(&vcc->stats->tx_err);
32267 dev_kfree_skb_any(skb);
32268 return -EINVAL;
32269 }
32270 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32271 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32272 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32273 card->index);
32274 - atomic_inc(&vcc->stats->tx_err);
32275 + atomic_inc_unchecked(&vcc->stats->tx_err);
32276 dev_kfree_skb_any(skb);
32277 return -EINVAL;
32278 }
32279
32280 if (skb_shinfo(skb)->nr_frags != 0) {
32281 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32282 - atomic_inc(&vcc->stats->tx_err);
32283 + atomic_inc_unchecked(&vcc->stats->tx_err);
32284 dev_kfree_skb_any(skb);
32285 return -EINVAL;
32286 }
32287 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32288 }
32289
32290 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32291 - atomic_inc(&vcc->stats->tx_err);
32292 + atomic_inc_unchecked(&vcc->stats->tx_err);
32293 dev_kfree_skb_any(skb);
32294 return -EIO;
32295 }
32296 - atomic_inc(&vcc->stats->tx);
32297 + atomic_inc_unchecked(&vcc->stats->tx);
32298
32299 return 0;
32300 }
32301 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32302 printk
32303 ("nicstar%d: Can't allocate buffers for aal0.\n",
32304 card->index);
32305 - atomic_add(i, &vcc->stats->rx_drop);
32306 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
32307 break;
32308 }
32309 if (!atm_charge(vcc, sb->truesize)) {
32310 RXPRINTK
32311 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32312 card->index);
32313 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32314 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32315 dev_kfree_skb_any(sb);
32316 break;
32317 }
32318 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32319 ATM_SKB(sb)->vcc = vcc;
32320 __net_timestamp(sb);
32321 vcc->push(vcc, sb);
32322 - atomic_inc(&vcc->stats->rx);
32323 + atomic_inc_unchecked(&vcc->stats->rx);
32324 cell += ATM_CELL_PAYLOAD;
32325 }
32326
32327 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32328 if (iovb == NULL) {
32329 printk("nicstar%d: Out of iovec buffers.\n",
32330 card->index);
32331 - atomic_inc(&vcc->stats->rx_drop);
32332 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32333 recycle_rx_buf(card, skb);
32334 return;
32335 }
32336 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32337 small or large buffer itself. */
32338 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32339 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32340 - atomic_inc(&vcc->stats->rx_err);
32341 + atomic_inc_unchecked(&vcc->stats->rx_err);
32342 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32343 NS_MAX_IOVECS);
32344 NS_PRV_IOVCNT(iovb) = 0;
32345 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32346 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32347 card->index);
32348 which_list(card, skb);
32349 - atomic_inc(&vcc->stats->rx_err);
32350 + atomic_inc_unchecked(&vcc->stats->rx_err);
32351 recycle_rx_buf(card, skb);
32352 vc->rx_iov = NULL;
32353 recycle_iov_buf(card, iovb);
32354 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32355 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32356 card->index);
32357 which_list(card, skb);
32358 - atomic_inc(&vcc->stats->rx_err);
32359 + atomic_inc_unchecked(&vcc->stats->rx_err);
32360 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32361 NS_PRV_IOVCNT(iovb));
32362 vc->rx_iov = NULL;
32363 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32364 printk(" - PDU size mismatch.\n");
32365 else
32366 printk(".\n");
32367 - atomic_inc(&vcc->stats->rx_err);
32368 + atomic_inc_unchecked(&vcc->stats->rx_err);
32369 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32370 NS_PRV_IOVCNT(iovb));
32371 vc->rx_iov = NULL;
32372 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32373 /* skb points to a small buffer */
32374 if (!atm_charge(vcc, skb->truesize)) {
32375 push_rxbufs(card, skb);
32376 - atomic_inc(&vcc->stats->rx_drop);
32377 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32378 } else {
32379 skb_put(skb, len);
32380 dequeue_sm_buf(card, skb);
32381 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32382 ATM_SKB(skb)->vcc = vcc;
32383 __net_timestamp(skb);
32384 vcc->push(vcc, skb);
32385 - atomic_inc(&vcc->stats->rx);
32386 + atomic_inc_unchecked(&vcc->stats->rx);
32387 }
32388 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32389 struct sk_buff *sb;
32390 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32391 if (len <= NS_SMBUFSIZE) {
32392 if (!atm_charge(vcc, sb->truesize)) {
32393 push_rxbufs(card, sb);
32394 - atomic_inc(&vcc->stats->rx_drop);
32395 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32396 } else {
32397 skb_put(sb, len);
32398 dequeue_sm_buf(card, sb);
32399 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32400 ATM_SKB(sb)->vcc = vcc;
32401 __net_timestamp(sb);
32402 vcc->push(vcc, sb);
32403 - atomic_inc(&vcc->stats->rx);
32404 + atomic_inc_unchecked(&vcc->stats->rx);
32405 }
32406
32407 push_rxbufs(card, skb);
32408 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32409
32410 if (!atm_charge(vcc, skb->truesize)) {
32411 push_rxbufs(card, skb);
32412 - atomic_inc(&vcc->stats->rx_drop);
32413 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32414 } else {
32415 dequeue_lg_buf(card, skb);
32416 #ifdef NS_USE_DESTRUCTORS
32417 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32418 ATM_SKB(skb)->vcc = vcc;
32419 __net_timestamp(skb);
32420 vcc->push(vcc, skb);
32421 - atomic_inc(&vcc->stats->rx);
32422 + atomic_inc_unchecked(&vcc->stats->rx);
32423 }
32424
32425 push_rxbufs(card, sb);
32426 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32427 printk
32428 ("nicstar%d: Out of huge buffers.\n",
32429 card->index);
32430 - atomic_inc(&vcc->stats->rx_drop);
32431 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32432 recycle_iovec_rx_bufs(card,
32433 (struct iovec *)
32434 iovb->data,
32435 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32436 card->hbpool.count++;
32437 } else
32438 dev_kfree_skb_any(hb);
32439 - atomic_inc(&vcc->stats->rx_drop);
32440 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32441 } else {
32442 /* Copy the small buffer to the huge buffer */
32443 sb = (struct sk_buff *)iov->iov_base;
32444 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32445 #endif /* NS_USE_DESTRUCTORS */
32446 __net_timestamp(hb);
32447 vcc->push(vcc, hb);
32448 - atomic_inc(&vcc->stats->rx);
32449 + atomic_inc_unchecked(&vcc->stats->rx);
32450 }
32451 }
32452
32453 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32454 index 0474a89..06ea4a1 100644
32455 --- a/drivers/atm/solos-pci.c
32456 +++ b/drivers/atm/solos-pci.c
32457 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32458 }
32459 atm_charge(vcc, skb->truesize);
32460 vcc->push(vcc, skb);
32461 - atomic_inc(&vcc->stats->rx);
32462 + atomic_inc_unchecked(&vcc->stats->rx);
32463 break;
32464
32465 case PKT_STATUS:
32466 @@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
32467 vcc = SKB_CB(oldskb)->vcc;
32468
32469 if (vcc) {
32470 - atomic_inc(&vcc->stats->tx);
32471 + atomic_inc_unchecked(&vcc->stats->tx);
32472 solos_pop(vcc, oldskb);
32473 } else {
32474 dev_kfree_skb_irq(oldskb);
32475 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
32476 index 0215934..ce9f5b1 100644
32477 --- a/drivers/atm/suni.c
32478 +++ b/drivers/atm/suni.c
32479 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
32480
32481
32482 #define ADD_LIMITED(s,v) \
32483 - atomic_add((v),&stats->s); \
32484 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
32485 + atomic_add_unchecked((v),&stats->s); \
32486 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
32487
32488
32489 static void suni_hz(unsigned long from_timer)
32490 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
32491 index 5120a96..e2572bd 100644
32492 --- a/drivers/atm/uPD98402.c
32493 +++ b/drivers/atm/uPD98402.c
32494 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
32495 struct sonet_stats tmp;
32496 int error = 0;
32497
32498 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32499 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32500 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
32501 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
32502 if (zero && !error) {
32503 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
32504
32505
32506 #define ADD_LIMITED(s,v) \
32507 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
32508 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
32509 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32510 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
32511 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
32512 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32513
32514
32515 static void stat_event(struct atm_dev *dev)
32516 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
32517 if (reason & uPD98402_INT_PFM) stat_event(dev);
32518 if (reason & uPD98402_INT_PCO) {
32519 (void) GET(PCOCR); /* clear interrupt cause */
32520 - atomic_add(GET(HECCT),
32521 + atomic_add_unchecked(GET(HECCT),
32522 &PRIV(dev)->sonet_stats.uncorr_hcs);
32523 }
32524 if ((reason & uPD98402_INT_RFO) &&
32525 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
32526 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
32527 uPD98402_INT_LOS),PIMR); /* enable them */
32528 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
32529 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32530 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
32531 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
32532 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32533 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
32534 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
32535 return 0;
32536 }
32537
32538 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32539 index 969c3c2..9b72956 100644
32540 --- a/drivers/atm/zatm.c
32541 +++ b/drivers/atm/zatm.c
32542 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32543 }
32544 if (!size) {
32545 dev_kfree_skb_irq(skb);
32546 - if (vcc) atomic_inc(&vcc->stats->rx_err);
32547 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32548 continue;
32549 }
32550 if (!atm_charge(vcc,skb->truesize)) {
32551 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32552 skb->len = size;
32553 ATM_SKB(skb)->vcc = vcc;
32554 vcc->push(vcc,skb);
32555 - atomic_inc(&vcc->stats->rx);
32556 + atomic_inc_unchecked(&vcc->stats->rx);
32557 }
32558 zout(pos & 0xffff,MTA(mbx));
32559 #if 0 /* probably a stupid idea */
32560 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32561 skb_queue_head(&zatm_vcc->backlog,skb);
32562 break;
32563 }
32564 - atomic_inc(&vcc->stats->tx);
32565 + atomic_inc_unchecked(&vcc->stats->tx);
32566 wake_up(&zatm_vcc->tx_wait);
32567 }
32568
32569 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
32570 index 6856303..0602d70 100644
32571 --- a/drivers/base/bus.c
32572 +++ b/drivers/base/bus.c
32573 @@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
32574 return -EINVAL;
32575
32576 mutex_lock(&subsys->p->mutex);
32577 - list_add_tail(&sif->node, &subsys->p->interfaces);
32578 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
32579 if (sif->add_dev) {
32580 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32581 while ((dev = subsys_dev_iter_next(&iter)))
32582 @@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
32583 subsys = sif->subsys;
32584
32585 mutex_lock(&subsys->p->mutex);
32586 - list_del_init(&sif->node);
32587 + pax_list_del_init((struct list_head *)&sif->node);
32588 if (sif->remove_dev) {
32589 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32590 while ((dev = subsys_dev_iter_next(&iter)))
32591 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32592 index 17cf7ca..7e553e1 100644
32593 --- a/drivers/base/devtmpfs.c
32594 +++ b/drivers/base/devtmpfs.c
32595 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
32596 if (!thread)
32597 return 0;
32598
32599 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
32600 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
32601 if (err)
32602 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
32603 else
32604 diff --git a/drivers/base/node.c b/drivers/base/node.c
32605 index fac124a..66bd4ab 100644
32606 --- a/drivers/base/node.c
32607 +++ b/drivers/base/node.c
32608 @@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
32609 struct node_attr {
32610 struct device_attribute attr;
32611 enum node_states state;
32612 -};
32613 +} __do_const;
32614
32615 static ssize_t show_node_state(struct device *dev,
32616 struct device_attribute *attr, char *buf)
32617 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
32618 index acc3a8d..981c236 100644
32619 --- a/drivers/base/power/domain.c
32620 +++ b/drivers/base/power/domain.c
32621 @@ -1851,7 +1851,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
32622 {
32623 struct cpuidle_driver *cpuidle_drv;
32624 struct gpd_cpu_data *cpu_data;
32625 - struct cpuidle_state *idle_state;
32626 + cpuidle_state_no_const *idle_state;
32627 int ret = 0;
32628
32629 if (IS_ERR_OR_NULL(genpd) || state < 0)
32630 @@ -1919,7 +1919,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
32631 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
32632 {
32633 struct gpd_cpu_data *cpu_data;
32634 - struct cpuidle_state *idle_state;
32635 + cpuidle_state_no_const *idle_state;
32636 int ret = 0;
32637
32638 if (IS_ERR_OR_NULL(genpd))
32639 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
32640 index e6ee5e8..98ad7fc 100644
32641 --- a/drivers/base/power/wakeup.c
32642 +++ b/drivers/base/power/wakeup.c
32643 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
32644 * They need to be modified together atomically, so it's better to use one
32645 * atomic variable to hold them both.
32646 */
32647 -static atomic_t combined_event_count = ATOMIC_INIT(0);
32648 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
32649
32650 #define IN_PROGRESS_BITS (sizeof(int) * 4)
32651 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
32652
32653 static void split_counters(unsigned int *cnt, unsigned int *inpr)
32654 {
32655 - unsigned int comb = atomic_read(&combined_event_count);
32656 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
32657
32658 *cnt = (comb >> IN_PROGRESS_BITS);
32659 *inpr = comb & MAX_IN_PROGRESS;
32660 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
32661 ws->start_prevent_time = ws->last_time;
32662
32663 /* Increment the counter of events in progress. */
32664 - cec = atomic_inc_return(&combined_event_count);
32665 + cec = atomic_inc_return_unchecked(&combined_event_count);
32666
32667 trace_wakeup_source_activate(ws->name, cec);
32668 }
32669 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
32670 * Increment the counter of registered wakeup events and decrement the
32671 * couter of wakeup events in progress simultaneously.
32672 */
32673 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
32674 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
32675 trace_wakeup_source_deactivate(ws->name, cec);
32676
32677 split_counters(&cnt, &inpr);
32678 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
32679 index e8d11b6..7b1b36f 100644
32680 --- a/drivers/base/syscore.c
32681 +++ b/drivers/base/syscore.c
32682 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
32683 void register_syscore_ops(struct syscore_ops *ops)
32684 {
32685 mutex_lock(&syscore_ops_lock);
32686 - list_add_tail(&ops->node, &syscore_ops_list);
32687 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
32688 mutex_unlock(&syscore_ops_lock);
32689 }
32690 EXPORT_SYMBOL_GPL(register_syscore_ops);
32691 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
32692 void unregister_syscore_ops(struct syscore_ops *ops)
32693 {
32694 mutex_lock(&syscore_ops_lock);
32695 - list_del(&ops->node);
32696 + pax_list_del((struct list_head *)&ops->node);
32697 mutex_unlock(&syscore_ops_lock);
32698 }
32699 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
32700 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
32701 index ade58bc..867143d 100644
32702 --- a/drivers/block/cciss.c
32703 +++ b/drivers/block/cciss.c
32704 @@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
32705 int err;
32706 u32 cp;
32707
32708 + memset(&arg64, 0, sizeof(arg64));
32709 +
32710 err = 0;
32711 err |=
32712 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
32713 @@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
32714 while (!list_empty(&h->reqQ)) {
32715 c = list_entry(h->reqQ.next, CommandList_struct, list);
32716 /* can't do anything if fifo is full */
32717 - if ((h->access.fifo_full(h))) {
32718 + if ((h->access->fifo_full(h))) {
32719 dev_warn(&h->pdev->dev, "fifo full\n");
32720 break;
32721 }
32722 @@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
32723 h->Qdepth--;
32724
32725 /* Tell the controller execute command */
32726 - h->access.submit_command(h, c);
32727 + h->access->submit_command(h, c);
32728
32729 /* Put job onto the completed Q */
32730 addQ(&h->cmpQ, c);
32731 @@ -3441,17 +3443,17 @@ startio:
32732
32733 static inline unsigned long get_next_completion(ctlr_info_t *h)
32734 {
32735 - return h->access.command_completed(h);
32736 + return h->access->command_completed(h);
32737 }
32738
32739 static inline int interrupt_pending(ctlr_info_t *h)
32740 {
32741 - return h->access.intr_pending(h);
32742 + return h->access->intr_pending(h);
32743 }
32744
32745 static inline long interrupt_not_for_us(ctlr_info_t *h)
32746 {
32747 - return ((h->access.intr_pending(h) == 0) ||
32748 + return ((h->access->intr_pending(h) == 0) ||
32749 (h->interrupts_enabled == 0));
32750 }
32751
32752 @@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
32753 u32 a;
32754
32755 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
32756 - return h->access.command_completed(h);
32757 + return h->access->command_completed(h);
32758
32759 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
32760 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
32761 @@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
32762 trans_support & CFGTBL_Trans_use_short_tags);
32763
32764 /* Change the access methods to the performant access methods */
32765 - h->access = SA5_performant_access;
32766 + h->access = &SA5_performant_access;
32767 h->transMethod = CFGTBL_Trans_Performant;
32768
32769 return;
32770 @@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
32771 if (prod_index < 0)
32772 return -ENODEV;
32773 h->product_name = products[prod_index].product_name;
32774 - h->access = *(products[prod_index].access);
32775 + h->access = products[prod_index].access;
32776
32777 if (cciss_board_disabled(h)) {
32778 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
32779 @@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
32780 }
32781
32782 /* make sure the board interrupts are off */
32783 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32784 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32785 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
32786 if (rc)
32787 goto clean2;
32788 @@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
32789 * fake ones to scoop up any residual completions.
32790 */
32791 spin_lock_irqsave(&h->lock, flags);
32792 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32793 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32794 spin_unlock_irqrestore(&h->lock, flags);
32795 free_irq(h->intr[h->intr_mode], h);
32796 rc = cciss_request_irq(h, cciss_msix_discard_completions,
32797 @@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
32798 dev_info(&h->pdev->dev, "Board READY.\n");
32799 dev_info(&h->pdev->dev,
32800 "Waiting for stale completions to drain.\n");
32801 - h->access.set_intr_mask(h, CCISS_INTR_ON);
32802 + h->access->set_intr_mask(h, CCISS_INTR_ON);
32803 msleep(10000);
32804 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32805 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32806
32807 rc = controller_reset_failed(h->cfgtable);
32808 if (rc)
32809 @@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
32810 cciss_scsi_setup(h);
32811
32812 /* Turn the interrupts on so we can service requests */
32813 - h->access.set_intr_mask(h, CCISS_INTR_ON);
32814 + h->access->set_intr_mask(h, CCISS_INTR_ON);
32815
32816 /* Get the firmware version */
32817 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
32818 @@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
32819 kfree(flush_buf);
32820 if (return_code != IO_OK)
32821 dev_warn(&h->pdev->dev, "Error flushing cache\n");
32822 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32823 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32824 free_irq(h->intr[h->intr_mode], h);
32825 }
32826
32827 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
32828 index 7fda30e..eb5dfe0 100644
32829 --- a/drivers/block/cciss.h
32830 +++ b/drivers/block/cciss.h
32831 @@ -101,7 +101,7 @@ struct ctlr_info
32832 /* information about each logical volume */
32833 drive_info_struct *drv[CISS_MAX_LUN];
32834
32835 - struct access_method access;
32836 + struct access_method *access;
32837
32838 /* queue and queue Info */
32839 struct list_head reqQ;
32840 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
32841 index 3f08713..56a586a 100644
32842 --- a/drivers/block/cpqarray.c
32843 +++ b/drivers/block/cpqarray.c
32844 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32845 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
32846 goto Enomem4;
32847 }
32848 - hba[i]->access.set_intr_mask(hba[i], 0);
32849 + hba[i]->access->set_intr_mask(hba[i], 0);
32850 if (request_irq(hba[i]->intr, do_ida_intr,
32851 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
32852 {
32853 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32854 add_timer(&hba[i]->timer);
32855
32856 /* Enable IRQ now that spinlock and rate limit timer are set up */
32857 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32858 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32859
32860 for(j=0; j<NWD; j++) {
32861 struct gendisk *disk = ida_gendisk[i][j];
32862 @@ -694,7 +694,7 @@ DBGINFO(
32863 for(i=0; i<NR_PRODUCTS; i++) {
32864 if (board_id == products[i].board_id) {
32865 c->product_name = products[i].product_name;
32866 - c->access = *(products[i].access);
32867 + c->access = products[i].access;
32868 break;
32869 }
32870 }
32871 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
32872 hba[ctlr]->intr = intr;
32873 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
32874 hba[ctlr]->product_name = products[j].product_name;
32875 - hba[ctlr]->access = *(products[j].access);
32876 + hba[ctlr]->access = products[j].access;
32877 hba[ctlr]->ctlr = ctlr;
32878 hba[ctlr]->board_id = board_id;
32879 hba[ctlr]->pci_dev = NULL; /* not PCI */
32880 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
32881
32882 while((c = h->reqQ) != NULL) {
32883 /* Can't do anything if we're busy */
32884 - if (h->access.fifo_full(h) == 0)
32885 + if (h->access->fifo_full(h) == 0)
32886 return;
32887
32888 /* Get the first entry from the request Q */
32889 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
32890 h->Qdepth--;
32891
32892 /* Tell the controller to do our bidding */
32893 - h->access.submit_command(h, c);
32894 + h->access->submit_command(h, c);
32895
32896 /* Get onto the completion Q */
32897 addQ(&h->cmpQ, c);
32898 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32899 unsigned long flags;
32900 __u32 a,a1;
32901
32902 - istat = h->access.intr_pending(h);
32903 + istat = h->access->intr_pending(h);
32904 /* Is this interrupt for us? */
32905 if (istat == 0)
32906 return IRQ_NONE;
32907 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32908 */
32909 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
32910 if (istat & FIFO_NOT_EMPTY) {
32911 - while((a = h->access.command_completed(h))) {
32912 + while((a = h->access->command_completed(h))) {
32913 a1 = a; a &= ~3;
32914 if ((c = h->cmpQ) == NULL)
32915 {
32916 @@ -1449,11 +1449,11 @@ static int sendcmd(
32917 /*
32918 * Disable interrupt
32919 */
32920 - info_p->access.set_intr_mask(info_p, 0);
32921 + info_p->access->set_intr_mask(info_p, 0);
32922 /* Make sure there is room in the command FIFO */
32923 /* Actually it should be completely empty at this time. */
32924 for (i = 200000; i > 0; i--) {
32925 - temp = info_p->access.fifo_full(info_p);
32926 + temp = info_p->access->fifo_full(info_p);
32927 if (temp != 0) {
32928 break;
32929 }
32930 @@ -1466,7 +1466,7 @@ DBG(
32931 /*
32932 * Send the cmd
32933 */
32934 - info_p->access.submit_command(info_p, c);
32935 + info_p->access->submit_command(info_p, c);
32936 complete = pollcomplete(ctlr);
32937
32938 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
32939 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
32940 * we check the new geometry. Then turn interrupts back on when
32941 * we're done.
32942 */
32943 - host->access.set_intr_mask(host, 0);
32944 + host->access->set_intr_mask(host, 0);
32945 getgeometry(ctlr);
32946 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
32947 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
32948
32949 for(i=0; i<NWD; i++) {
32950 struct gendisk *disk = ida_gendisk[ctlr][i];
32951 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
32952 /* Wait (up to 2 seconds) for a command to complete */
32953
32954 for (i = 200000; i > 0; i--) {
32955 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
32956 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
32957 if (done == 0) {
32958 udelay(10); /* a short fixed delay */
32959 } else
32960 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
32961 index be73e9d..7fbf140 100644
32962 --- a/drivers/block/cpqarray.h
32963 +++ b/drivers/block/cpqarray.h
32964 @@ -99,7 +99,7 @@ struct ctlr_info {
32965 drv_info_t drv[NWD];
32966 struct proc_dir_entry *proc;
32967
32968 - struct access_method access;
32969 + struct access_method *access;
32970
32971 cmdlist_t *reqQ;
32972 cmdlist_t *cmpQ;
32973 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
32974 index 6b51afa..17e1191 100644
32975 --- a/drivers/block/drbd/drbd_int.h
32976 +++ b/drivers/block/drbd/drbd_int.h
32977 @@ -582,7 +582,7 @@ struct drbd_epoch {
32978 struct drbd_tconn *tconn;
32979 struct list_head list;
32980 unsigned int barrier_nr;
32981 - atomic_t epoch_size; /* increased on every request added. */
32982 + atomic_unchecked_t epoch_size; /* increased on every request added. */
32983 atomic_t active; /* increased on every req. added, and dec on every finished. */
32984 unsigned long flags;
32985 };
32986 @@ -1011,7 +1011,7 @@ struct drbd_conf {
32987 int al_tr_cycle;
32988 int al_tr_pos; /* position of the next transaction in the journal */
32989 wait_queue_head_t seq_wait;
32990 - atomic_t packet_seq;
32991 + atomic_unchecked_t packet_seq;
32992 unsigned int peer_seq;
32993 spinlock_t peer_seq_lock;
32994 unsigned int minor;
32995 @@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
32996 char __user *uoptval;
32997 int err;
32998
32999 - uoptval = (char __user __force *)optval;
33000 + uoptval = (char __force_user *)optval;
33001
33002 set_fs(KERNEL_DS);
33003 if (level == SOL_SOCKET)
33004 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33005 index 8c13eeb..217adee 100644
33006 --- a/drivers/block/drbd/drbd_main.c
33007 +++ b/drivers/block/drbd/drbd_main.c
33008 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33009 p->sector = sector;
33010 p->block_id = block_id;
33011 p->blksize = blksize;
33012 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33013 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33014 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33015 }
33016
33017 @@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33018 return -EIO;
33019 p->sector = cpu_to_be64(req->i.sector);
33020 p->block_id = (unsigned long)req;
33021 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33022 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33023 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33024 if (mdev->state.conn >= C_SYNC_SOURCE &&
33025 mdev->state.conn <= C_PAUSED_SYNC_T)
33026 @@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33027 {
33028 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33029
33030 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33031 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33032 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33033 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33034 kfree(tconn->current_epoch);
33035
33036 idr_destroy(&tconn->volumes);
33037 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33038 index a9eccfc..f5efe87 100644
33039 --- a/drivers/block/drbd/drbd_receiver.c
33040 +++ b/drivers/block/drbd/drbd_receiver.c
33041 @@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
33042 {
33043 int err;
33044
33045 - atomic_set(&mdev->packet_seq, 0);
33046 + atomic_set_unchecked(&mdev->packet_seq, 0);
33047 mdev->peer_seq = 0;
33048
33049 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33050 @@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33051 do {
33052 next_epoch = NULL;
33053
33054 - epoch_size = atomic_read(&epoch->epoch_size);
33055 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33056
33057 switch (ev & ~EV_CLEANUP) {
33058 case EV_PUT:
33059 @@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33060 rv = FE_DESTROYED;
33061 } else {
33062 epoch->flags = 0;
33063 - atomic_set(&epoch->epoch_size, 0);
33064 + atomic_set_unchecked(&epoch->epoch_size, 0);
33065 /* atomic_set(&epoch->active, 0); is already zero */
33066 if (rv == FE_STILL_LIVE)
33067 rv = FE_RECYCLED;
33068 @@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33069 conn_wait_active_ee_empty(tconn);
33070 drbd_flush(tconn);
33071
33072 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
33073 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33074 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33075 if (epoch)
33076 break;
33077 @@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33078 }
33079
33080 epoch->flags = 0;
33081 - atomic_set(&epoch->epoch_size, 0);
33082 + atomic_set_unchecked(&epoch->epoch_size, 0);
33083 atomic_set(&epoch->active, 0);
33084
33085 spin_lock(&tconn->epoch_lock);
33086 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
33087 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33088 list_add(&epoch->list, &tconn->current_epoch->list);
33089 tconn->current_epoch = epoch;
33090 tconn->epochs++;
33091 @@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33092
33093 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33094 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33095 - atomic_inc(&tconn->current_epoch->epoch_size);
33096 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33097 err2 = drbd_drain_block(mdev, pi->size);
33098 if (!err)
33099 err = err2;
33100 @@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33101
33102 spin_lock(&tconn->epoch_lock);
33103 peer_req->epoch = tconn->current_epoch;
33104 - atomic_inc(&peer_req->epoch->epoch_size);
33105 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33106 atomic_inc(&peer_req->epoch->active);
33107 spin_unlock(&tconn->epoch_lock);
33108
33109 @@ -4346,7 +4346,7 @@ struct data_cmd {
33110 int expect_payload;
33111 size_t pkt_size;
33112 int (*fn)(struct drbd_tconn *, struct packet_info *);
33113 -};
33114 +} __do_const;
33115
33116 static struct data_cmd drbd_cmd_handler[] = {
33117 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33118 @@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33119 if (!list_empty(&tconn->current_epoch->list))
33120 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33121 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33122 - atomic_set(&tconn->current_epoch->epoch_size, 0);
33123 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33124 tconn->send.seen_any_write_yet = false;
33125
33126 conn_info(tconn, "Connection closed\n");
33127 @@ -5222,7 +5222,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33128 struct asender_cmd {
33129 size_t pkt_size;
33130 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33131 -};
33132 +} __do_const;
33133
33134 static struct asender_cmd asender_tbl[] = {
33135 [P_PING] = { 0, got_Ping },
33136 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33137 index ae12512..37fa397 100644
33138 --- a/drivers/block/loop.c
33139 +++ b/drivers/block/loop.c
33140 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
33141 mm_segment_t old_fs = get_fs();
33142
33143 set_fs(get_ds());
33144 - bw = file->f_op->write(file, buf, len, &pos);
33145 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33146 set_fs(old_fs);
33147 if (likely(bw == len))
33148 return 0;
33149 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33150 index d620b44..587561e 100644
33151 --- a/drivers/cdrom/cdrom.c
33152 +++ b/drivers/cdrom/cdrom.c
33153 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33154 ENSURE(reset, CDC_RESET);
33155 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33156 cdi->mc_flags = 0;
33157 - cdo->n_minors = 0;
33158 cdi->options = CDO_USE_FFLAGS;
33159
33160 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33161 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33162 else
33163 cdi->cdda_method = CDDA_OLD;
33164
33165 - if (!cdo->generic_packet)
33166 - cdo->generic_packet = cdrom_dummy_generic_packet;
33167 + if (!cdo->generic_packet) {
33168 + pax_open_kernel();
33169 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33170 + pax_close_kernel();
33171 + }
33172
33173 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33174 mutex_lock(&cdrom_mutex);
33175 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33176 if (cdi->exit)
33177 cdi->exit(cdi);
33178
33179 - cdi->ops->n_minors--;
33180 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33181 }
33182
33183 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33184 index d59cdcb..11afddf 100644
33185 --- a/drivers/cdrom/gdrom.c
33186 +++ b/drivers/cdrom/gdrom.c
33187 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33188 .audio_ioctl = gdrom_audio_ioctl,
33189 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33190 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33191 - .n_minors = 1,
33192 };
33193
33194 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33195 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33196 index 72bedad..8181ce1 100644
33197 --- a/drivers/char/Kconfig
33198 +++ b/drivers/char/Kconfig
33199 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33200
33201 config DEVKMEM
33202 bool "/dev/kmem virtual device support"
33203 - default y
33204 + default n
33205 + depends on !GRKERNSEC_KMEM
33206 help
33207 Say Y here if you want to support the /dev/kmem device. The
33208 /dev/kmem device is rarely used, but can be used for certain
33209 @@ -581,6 +582,7 @@ config DEVPORT
33210 bool
33211 depends on !M68K
33212 depends on ISA || PCI
33213 + depends on !GRKERNSEC_KMEM
33214 default y
33215
33216 source "drivers/s390/char/Kconfig"
33217 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33218 index 2e04433..22afc64 100644
33219 --- a/drivers/char/agp/frontend.c
33220 +++ b/drivers/char/agp/frontend.c
33221 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33222 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33223 return -EFAULT;
33224
33225 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33226 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33227 return -EFAULT;
33228
33229 client = agp_find_client_by_pid(reserve.pid);
33230 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33231 index 21cb980..f15107c 100644
33232 --- a/drivers/char/genrtc.c
33233 +++ b/drivers/char/genrtc.c
33234 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
33235 switch (cmd) {
33236
33237 case RTC_PLL_GET:
33238 + memset(&pll, 0, sizeof(pll));
33239 if (get_rtc_pll(&pll))
33240 return -EINVAL;
33241 else
33242 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33243 index fe6d4be..89f32100 100644
33244 --- a/drivers/char/hpet.c
33245 +++ b/drivers/char/hpet.c
33246 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33247 }
33248
33249 static int
33250 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33251 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33252 struct hpet_info *info)
33253 {
33254 struct hpet_timer __iomem *timer;
33255 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33256 index 053201b0..8335cce 100644
33257 --- a/drivers/char/ipmi/ipmi_msghandler.c
33258 +++ b/drivers/char/ipmi/ipmi_msghandler.c
33259 @@ -420,7 +420,7 @@ struct ipmi_smi {
33260 struct proc_dir_entry *proc_dir;
33261 char proc_dir_name[10];
33262
33263 - atomic_t stats[IPMI_NUM_STATS];
33264 + atomic_unchecked_t stats[IPMI_NUM_STATS];
33265
33266 /*
33267 * run_to_completion duplicate of smb_info, smi_info
33268 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33269
33270
33271 #define ipmi_inc_stat(intf, stat) \
33272 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33273 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33274 #define ipmi_get_stat(intf, stat) \
33275 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33276 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33277
33278 static int is_lan_addr(struct ipmi_addr *addr)
33279 {
33280 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33281 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33282 init_waitqueue_head(&intf->waitq);
33283 for (i = 0; i < IPMI_NUM_STATS; i++)
33284 - atomic_set(&intf->stats[i], 0);
33285 + atomic_set_unchecked(&intf->stats[i], 0);
33286
33287 intf->proc_dir = NULL;
33288
33289 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33290 index 1c7fdcd..4899100 100644
33291 --- a/drivers/char/ipmi/ipmi_si_intf.c
33292 +++ b/drivers/char/ipmi/ipmi_si_intf.c
33293 @@ -275,7 +275,7 @@ struct smi_info {
33294 unsigned char slave_addr;
33295
33296 /* Counters and things for the proc filesystem. */
33297 - atomic_t stats[SI_NUM_STATS];
33298 + atomic_unchecked_t stats[SI_NUM_STATS];
33299
33300 struct task_struct *thread;
33301
33302 @@ -284,9 +284,9 @@ struct smi_info {
33303 };
33304
33305 #define smi_inc_stat(smi, stat) \
33306 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
33307 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
33308 #define smi_get_stat(smi, stat) \
33309 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
33310 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
33311
33312 #define SI_MAX_PARMS 4
33313
33314 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
33315 atomic_set(&new_smi->req_events, 0);
33316 new_smi->run_to_completion = 0;
33317 for (i = 0; i < SI_NUM_STATS; i++)
33318 - atomic_set(&new_smi->stats[i], 0);
33319 + atomic_set_unchecked(&new_smi->stats[i], 0);
33320
33321 new_smi->interrupt_disabled = 1;
33322 atomic_set(&new_smi->stop_operation, 0);
33323 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
33324 index c6fa3bc..4ca3e42 100644
33325 --- a/drivers/char/mem.c
33326 +++ b/drivers/char/mem.c
33327 @@ -18,6 +18,7 @@
33328 #include <linux/raw.h>
33329 #include <linux/tty.h>
33330 #include <linux/capability.h>
33331 +#include <linux/security.h>
33332 #include <linux/ptrace.h>
33333 #include <linux/device.h>
33334 #include <linux/highmem.h>
33335 @@ -37,6 +38,10 @@
33336
33337 #define DEVPORT_MINOR 4
33338
33339 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33340 +extern const struct file_operations grsec_fops;
33341 +#endif
33342 +
33343 static inline unsigned long size_inside_page(unsigned long start,
33344 unsigned long size)
33345 {
33346 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33347
33348 while (cursor < to) {
33349 if (!devmem_is_allowed(pfn)) {
33350 +#ifdef CONFIG_GRKERNSEC_KMEM
33351 + gr_handle_mem_readwrite(from, to);
33352 +#else
33353 printk(KERN_INFO
33354 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
33355 current->comm, from, to);
33356 +#endif
33357 return 0;
33358 }
33359 cursor += PAGE_SIZE;
33360 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33361 }
33362 return 1;
33363 }
33364 +#elif defined(CONFIG_GRKERNSEC_KMEM)
33365 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33366 +{
33367 + return 0;
33368 +}
33369 #else
33370 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33371 {
33372 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33373
33374 while (count > 0) {
33375 unsigned long remaining;
33376 + char *temp;
33377
33378 sz = size_inside_page(p, count);
33379
33380 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33381 if (!ptr)
33382 return -EFAULT;
33383
33384 - remaining = copy_to_user(buf, ptr, sz);
33385 +#ifdef CONFIG_PAX_USERCOPY
33386 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33387 + if (!temp) {
33388 + unxlate_dev_mem_ptr(p, ptr);
33389 + return -ENOMEM;
33390 + }
33391 + memcpy(temp, ptr, sz);
33392 +#else
33393 + temp = ptr;
33394 +#endif
33395 +
33396 + remaining = copy_to_user(buf, temp, sz);
33397 +
33398 +#ifdef CONFIG_PAX_USERCOPY
33399 + kfree(temp);
33400 +#endif
33401 +
33402 unxlate_dev_mem_ptr(p, ptr);
33403 if (remaining)
33404 return -EFAULT;
33405 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33406 size_t count, loff_t *ppos)
33407 {
33408 unsigned long p = *ppos;
33409 - ssize_t low_count, read, sz;
33410 + ssize_t low_count, read, sz, err = 0;
33411 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
33412 - int err = 0;
33413
33414 read = 0;
33415 if (p < (unsigned long) high_memory) {
33416 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33417 }
33418 #endif
33419 while (low_count > 0) {
33420 + char *temp;
33421 +
33422 sz = size_inside_page(p, low_count);
33423
33424 /*
33425 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33426 */
33427 kbuf = xlate_dev_kmem_ptr((char *)p);
33428
33429 - if (copy_to_user(buf, kbuf, sz))
33430 +#ifdef CONFIG_PAX_USERCOPY
33431 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33432 + if (!temp)
33433 + return -ENOMEM;
33434 + memcpy(temp, kbuf, sz);
33435 +#else
33436 + temp = kbuf;
33437 +#endif
33438 +
33439 + err = copy_to_user(buf, temp, sz);
33440 +
33441 +#ifdef CONFIG_PAX_USERCOPY
33442 + kfree(temp);
33443 +#endif
33444 +
33445 + if (err)
33446 return -EFAULT;
33447 buf += sz;
33448 p += sz;
33449 @@ -833,6 +880,9 @@ static const struct memdev {
33450 #ifdef CONFIG_CRASH_DUMP
33451 [12] = { "oldmem", 0, &oldmem_fops, NULL },
33452 #endif
33453 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33454 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
33455 +#endif
33456 };
33457
33458 static int memory_open(struct inode *inode, struct file *filp)
33459 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
33460 index 9df78e2..01ba9ae 100644
33461 --- a/drivers/char/nvram.c
33462 +++ b/drivers/char/nvram.c
33463 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
33464
33465 spin_unlock_irq(&rtc_lock);
33466
33467 - if (copy_to_user(buf, contents, tmp - contents))
33468 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
33469 return -EFAULT;
33470
33471 *ppos = i;
33472 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
33473 index b66eaa0..2619d1b 100644
33474 --- a/drivers/char/pcmcia/synclink_cs.c
33475 +++ b/drivers/char/pcmcia/synclink_cs.c
33476 @@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33477
33478 if (debug_level >= DEBUG_LEVEL_INFO)
33479 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
33480 - __FILE__,__LINE__, info->device_name, port->count);
33481 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
33482
33483 - WARN_ON(!port->count);
33484 + WARN_ON(!atomic_read(&port->count));
33485
33486 if (tty_port_close_start(port, tty, filp) == 0)
33487 goto cleanup;
33488 @@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33489 cleanup:
33490 if (debug_level >= DEBUG_LEVEL_INFO)
33491 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
33492 - tty->driver->name, port->count);
33493 + tty->driver->name, atomic_read(&port->count));
33494 }
33495
33496 /* Wait until the transmitter is empty.
33497 @@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33498
33499 if (debug_level >= DEBUG_LEVEL_INFO)
33500 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
33501 - __FILE__,__LINE__,tty->driver->name, port->count);
33502 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
33503
33504 /* If port is closing, signal caller to try again */
33505 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
33506 @@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33507 goto cleanup;
33508 }
33509 spin_lock(&port->lock);
33510 - port->count++;
33511 + atomic_inc(&port->count);
33512 spin_unlock(&port->lock);
33513 spin_unlock_irqrestore(&info->netlock, flags);
33514
33515 - if (port->count == 1) {
33516 + if (atomic_read(&port->count) == 1) {
33517 /* 1st open on this device, init hardware */
33518 retval = startup(info, tty);
33519 if (retval < 0)
33520 @@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
33521 unsigned short new_crctype;
33522
33523 /* return error if TTY interface open */
33524 - if (info->port.count)
33525 + if (atomic_read(&info->port.count))
33526 return -EBUSY;
33527
33528 switch (encoding)
33529 @@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
33530
33531 /* arbitrate between network and tty opens */
33532 spin_lock_irqsave(&info->netlock, flags);
33533 - if (info->port.count != 0 || info->netcount != 0) {
33534 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
33535 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
33536 spin_unlock_irqrestore(&info->netlock, flags);
33537 return -EBUSY;
33538 @@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
33539 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
33540
33541 /* return error if TTY interface open */
33542 - if (info->port.count)
33543 + if (atomic_read(&info->port.count))
33544 return -EBUSY;
33545
33546 if (cmd != SIOCWANDEV)
33547 diff --git a/drivers/char/random.c b/drivers/char/random.c
33548 index 85e81ec..a129a39 100644
33549 --- a/drivers/char/random.c
33550 +++ b/drivers/char/random.c
33551 @@ -272,8 +272,13 @@
33552 /*
33553 * Configuration information
33554 */
33555 +#ifdef CONFIG_GRKERNSEC_RANDNET
33556 +#define INPUT_POOL_WORDS 512
33557 +#define OUTPUT_POOL_WORDS 128
33558 +#else
33559 #define INPUT_POOL_WORDS 128
33560 #define OUTPUT_POOL_WORDS 32
33561 +#endif
33562 #define SEC_XFER_SIZE 512
33563 #define EXTRACT_SIZE 10
33564
33565 @@ -313,10 +318,17 @@ static struct poolinfo {
33566 int poolwords;
33567 int tap1, tap2, tap3, tap4, tap5;
33568 } poolinfo_table[] = {
33569 +#ifdef CONFIG_GRKERNSEC_RANDNET
33570 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
33571 + { 512, 411, 308, 208, 104, 1 },
33572 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
33573 + { 128, 103, 76, 51, 25, 1 },
33574 +#else
33575 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
33576 { 128, 103, 76, 51, 25, 1 },
33577 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
33578 { 32, 26, 20, 14, 7, 1 },
33579 +#endif
33580 #if 0
33581 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
33582 { 2048, 1638, 1231, 819, 411, 1 },
33583 @@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
33584 input_rotate += i ? 7 : 14;
33585 }
33586
33587 - ACCESS_ONCE(r->input_rotate) = input_rotate;
33588 - ACCESS_ONCE(r->add_ptr) = i;
33589 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
33590 + ACCESS_ONCE_RW(r->add_ptr) = i;
33591 smp_wmb();
33592
33593 if (out)
33594 @@ -1020,7 +1032,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
33595
33596 extract_buf(r, tmp);
33597 i = min_t(int, nbytes, EXTRACT_SIZE);
33598 - if (copy_to_user(buf, tmp, i)) {
33599 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
33600 ret = -EFAULT;
33601 break;
33602 }
33603 @@ -1356,7 +1368,7 @@ EXPORT_SYMBOL(generate_random_uuid);
33604 #include <linux/sysctl.h>
33605
33606 static int min_read_thresh = 8, min_write_thresh;
33607 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
33608 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
33609 static int max_write_thresh = INPUT_POOL_WORDS * 32;
33610 static char sysctl_bootid[16];
33611
33612 @@ -1372,7 +1384,7 @@ static char sysctl_bootid[16];
33613 static int proc_do_uuid(ctl_table *table, int write,
33614 void __user *buffer, size_t *lenp, loff_t *ppos)
33615 {
33616 - ctl_table fake_table;
33617 + ctl_table_no_const fake_table;
33618 unsigned char buf[64], tmp_uuid[16], *uuid;
33619
33620 uuid = table->data;
33621 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
33622 index d780295..b29f3a8 100644
33623 --- a/drivers/char/sonypi.c
33624 +++ b/drivers/char/sonypi.c
33625 @@ -54,6 +54,7 @@
33626
33627 #include <asm/uaccess.h>
33628 #include <asm/io.h>
33629 +#include <asm/local.h>
33630
33631 #include <linux/sonypi.h>
33632
33633 @@ -490,7 +491,7 @@ static struct sonypi_device {
33634 spinlock_t fifo_lock;
33635 wait_queue_head_t fifo_proc_list;
33636 struct fasync_struct *fifo_async;
33637 - int open_count;
33638 + local_t open_count;
33639 int model;
33640 struct input_dev *input_jog_dev;
33641 struct input_dev *input_key_dev;
33642 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
33643 static int sonypi_misc_release(struct inode *inode, struct file *file)
33644 {
33645 mutex_lock(&sonypi_device.lock);
33646 - sonypi_device.open_count--;
33647 + local_dec(&sonypi_device.open_count);
33648 mutex_unlock(&sonypi_device.lock);
33649 return 0;
33650 }
33651 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
33652 {
33653 mutex_lock(&sonypi_device.lock);
33654 /* Flush input queue on first open */
33655 - if (!sonypi_device.open_count)
33656 + if (!local_read(&sonypi_device.open_count))
33657 kfifo_reset(&sonypi_device.fifo);
33658 - sonypi_device.open_count++;
33659 + local_inc(&sonypi_device.open_count);
33660 mutex_unlock(&sonypi_device.lock);
33661
33662 return 0;
33663 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
33664 index 93211df..c7805f7 100644
33665 --- a/drivers/char/tpm/tpm.c
33666 +++ b/drivers/char/tpm/tpm.c
33667 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
33668 chip->vendor.req_complete_val)
33669 goto out_recv;
33670
33671 - if ((status == chip->vendor.req_canceled)) {
33672 + if (status == chip->vendor.req_canceled) {
33673 dev_err(chip->dev, "Operation Canceled\n");
33674 rc = -ECANCELED;
33675 goto out;
33676 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
33677 index 56051d0..11cf3b7 100644
33678 --- a/drivers/char/tpm/tpm_acpi.c
33679 +++ b/drivers/char/tpm/tpm_acpi.c
33680 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
33681 virt = acpi_os_map_memory(start, len);
33682 if (!virt) {
33683 kfree(log->bios_event_log);
33684 + log->bios_event_log = NULL;
33685 printk("%s: ERROR - Unable to map memory\n", __func__);
33686 return -EIO;
33687 }
33688
33689 - memcpy_fromio(log->bios_event_log, virt, len);
33690 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
33691
33692 acpi_os_unmap_memory(virt, len);
33693 return 0;
33694 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
33695 index 84ddc55..1d32f1e 100644
33696 --- a/drivers/char/tpm/tpm_eventlog.c
33697 +++ b/drivers/char/tpm/tpm_eventlog.c
33698 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
33699 event = addr;
33700
33701 if ((event->event_type == 0 && event->event_size == 0) ||
33702 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
33703 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
33704 return NULL;
33705
33706 return addr;
33707 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
33708 return NULL;
33709
33710 if ((event->event_type == 0 && event->event_size == 0) ||
33711 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
33712 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
33713 return NULL;
33714
33715 (*pos)++;
33716 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
33717 int i;
33718
33719 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
33720 - seq_putc(m, data[i]);
33721 + if (!seq_putc(m, data[i]))
33722 + return -EFAULT;
33723
33724 return 0;
33725 }
33726 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
33727 index ee4dbea..69c817b 100644
33728 --- a/drivers/char/virtio_console.c
33729 +++ b/drivers/char/virtio_console.c
33730 @@ -681,7 +681,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
33731 if (to_user) {
33732 ssize_t ret;
33733
33734 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
33735 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
33736 if (ret)
33737 return -EFAULT;
33738 } else {
33739 @@ -780,7 +780,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
33740 if (!port_has_data(port) && !port->host_connected)
33741 return 0;
33742
33743 - return fill_readbuf(port, ubuf, count, true);
33744 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
33745 }
33746
33747 static int wait_port_writable(struct port *port, bool nonblock)
33748 diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
33749 index 8ae1a61..9c00613 100644
33750 --- a/drivers/clocksource/arm_generic.c
33751 +++ b/drivers/clocksource/arm_generic.c
33752 @@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
33753 return NOTIFY_OK;
33754 }
33755
33756 -static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
33757 +static struct notifier_block arch_timer_cpu_nb = {
33758 .notifier_call = arch_timer_cpu_notify,
33759 };
33760
33761 diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
33762 index fce2000..1110478 100644
33763 --- a/drivers/connector/cn_proc.c
33764 +++ b/drivers/connector/cn_proc.c
33765 @@ -313,6 +313,12 @@ static void cn_proc_mcast_ctl(struct cn_msg *msg,
33766 (task_active_pid_ns(current) != &init_pid_ns))
33767 return;
33768
33769 + /* Can only change if privileged. */
33770 + if (!capable(CAP_NET_ADMIN)) {
33771 + err = EPERM;
33772 + goto out;
33773 + }
33774 +
33775 mc_op = (enum proc_cn_mcast_op *)msg->data;
33776 switch (*mc_op) {
33777 case PROC_CN_MCAST_LISTEN:
33778 @@ -325,6 +331,8 @@ static void cn_proc_mcast_ctl(struct cn_msg *msg,
33779 err = EINVAL;
33780 break;
33781 }
33782 +
33783 +out:
33784 cn_proc_ack(err, msg->seq, msg->ack);
33785 }
33786
33787 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
33788 index 7b0d49d..134fac9 100644
33789 --- a/drivers/cpufreq/acpi-cpufreq.c
33790 +++ b/drivers/cpufreq/acpi-cpufreq.c
33791 @@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
33792 return sprintf(buf, "%u\n", boost_enabled);
33793 }
33794
33795 -static struct global_attr global_boost = __ATTR(boost, 0644,
33796 +static global_attr_no_const global_boost = __ATTR(boost, 0644,
33797 show_global_boost,
33798 store_global_boost);
33799
33800 @@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33801 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
33802 per_cpu(acfreq_data, cpu) = data;
33803
33804 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
33805 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
33806 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
33807 + pax_open_kernel();
33808 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
33809 + pax_close_kernel();
33810 + }
33811
33812 result = acpi_processor_register_performance(data->acpi_data, cpu);
33813 if (result)
33814 @@ -835,7 +838,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33815 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
33816 break;
33817 case ACPI_ADR_SPACE_FIXED_HARDWARE:
33818 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
33819 + pax_open_kernel();
33820 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
33821 + pax_close_kernel();
33822 policy->cur = get_cur_freq_on_cpu(cpu);
33823 break;
33824 default:
33825 @@ -846,8 +851,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33826 acpi_processor_notify_smm(THIS_MODULE);
33827
33828 /* Check for APERF/MPERF support in hardware */
33829 - if (boot_cpu_has(X86_FEATURE_APERFMPERF))
33830 - acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
33831 + if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
33832 + pax_open_kernel();
33833 + *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
33834 + pax_close_kernel();
33835 + }
33836
33837 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
33838 for (i = 0; i < perf->state_count; i++)
33839 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
33840 index 1f93dbd..305cef1 100644
33841 --- a/drivers/cpufreq/cpufreq.c
33842 +++ b/drivers/cpufreq/cpufreq.c
33843 @@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
33844 return NOTIFY_OK;
33845 }
33846
33847 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
33848 +static struct notifier_block cpufreq_cpu_notifier = {
33849 .notifier_call = cpufreq_cpu_callback,
33850 };
33851
33852 @@ -1875,8 +1875,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
33853
33854 pr_debug("trying to register driver %s\n", driver_data->name);
33855
33856 - if (driver_data->setpolicy)
33857 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
33858 + if (driver_data->setpolicy) {
33859 + pax_open_kernel();
33860 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
33861 + pax_close_kernel();
33862 + }
33863
33864 spin_lock_irqsave(&cpufreq_driver_lock, flags);
33865 if (cpufreq_driver) {
33866 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
33867 index 6c5f1d3..c7e2f35e 100644
33868 --- a/drivers/cpufreq/cpufreq_governor.c
33869 +++ b/drivers/cpufreq/cpufreq_governor.c
33870 @@ -243,7 +243,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
33871 * governor, thus we are bound to jiffes/HZ
33872 */
33873 if (dbs_data->governor == GOV_CONSERVATIVE) {
33874 - struct cs_ops *ops = dbs_data->gov_ops;
33875 + const struct cs_ops *ops = dbs_data->gov_ops;
33876
33877 cpufreq_register_notifier(ops->notifier_block,
33878 CPUFREQ_TRANSITION_NOTIFIER);
33879 @@ -251,7 +251,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
33880 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
33881 jiffies_to_usecs(10);
33882 } else {
33883 - struct od_ops *ops = dbs_data->gov_ops;
33884 + const struct od_ops *ops = dbs_data->gov_ops;
33885
33886 od_tuners->io_is_busy = ops->io_busy();
33887 }
33888 @@ -268,7 +268,7 @@ second_time:
33889 cs_dbs_info->enable = 1;
33890 cs_dbs_info->requested_freq = policy->cur;
33891 } else {
33892 - struct od_ops *ops = dbs_data->gov_ops;
33893 + const struct od_ops *ops = dbs_data->gov_ops;
33894 od_dbs_info->rate_mult = 1;
33895 od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
33896 ops->powersave_bias_init_cpu(cpu);
33897 @@ -289,7 +289,7 @@ second_time:
33898 mutex_destroy(&cpu_cdbs->timer_mutex);
33899 dbs_data->enable--;
33900 if (!dbs_data->enable) {
33901 - struct cs_ops *ops = dbs_data->gov_ops;
33902 + const struct cs_ops *ops = dbs_data->gov_ops;
33903
33904 sysfs_remove_group(cpufreq_global_kobject,
33905 dbs_data->attr_group);
33906 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
33907 index f661654..6c8e638 100644
33908 --- a/drivers/cpufreq/cpufreq_governor.h
33909 +++ b/drivers/cpufreq/cpufreq_governor.h
33910 @@ -142,7 +142,7 @@ struct dbs_data {
33911 void (*gov_check_cpu)(int cpu, unsigned int load);
33912
33913 /* Governor specific ops, see below */
33914 - void *gov_ops;
33915 + const void *gov_ops;
33916 };
33917
33918 /* Governor specific ops, will be passed to dbs_data->gov_ops */
33919 diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
33920 index 9d7732b..0b1a793 100644
33921 --- a/drivers/cpufreq/cpufreq_stats.c
33922 +++ b/drivers/cpufreq/cpufreq_stats.c
33923 @@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
33924 }
33925
33926 /* priority=1 so this will get called before cpufreq_remove_dev */
33927 -static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
33928 +static struct notifier_block cpufreq_stat_cpu_notifier = {
33929 .notifier_call = cpufreq_stat_cpu_callback,
33930 .priority = 1,
33931 };
33932 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
33933 index 827629c9..0bc6a03 100644
33934 --- a/drivers/cpufreq/p4-clockmod.c
33935 +++ b/drivers/cpufreq/p4-clockmod.c
33936 @@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
33937 case 0x0F: /* Core Duo */
33938 case 0x16: /* Celeron Core */
33939 case 0x1C: /* Atom */
33940 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33941 + pax_open_kernel();
33942 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33943 + pax_close_kernel();
33944 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
33945 case 0x0D: /* Pentium M (Dothan) */
33946 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33947 + pax_open_kernel();
33948 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33949 + pax_close_kernel();
33950 /* fall through */
33951 case 0x09: /* Pentium M (Banias) */
33952 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
33953 @@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
33954
33955 /* on P-4s, the TSC runs with constant frequency independent whether
33956 * throttling is active or not. */
33957 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33958 + pax_open_kernel();
33959 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33960 + pax_close_kernel();
33961
33962 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
33963 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
33964 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
33965 index 3a953d5..f5993f6 100644
33966 --- a/drivers/cpufreq/speedstep-centrino.c
33967 +++ b/drivers/cpufreq/speedstep-centrino.c
33968 @@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
33969 !cpu_has(cpu, X86_FEATURE_EST))
33970 return -ENODEV;
33971
33972 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
33973 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
33974 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
33975 + pax_open_kernel();
33976 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
33977 + pax_close_kernel();
33978 + }
33979
33980 if (policy->cpu != 0)
33981 return -ENODEV;
33982 diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
33983 index e1f6860..f8de20b 100644
33984 --- a/drivers/cpuidle/cpuidle.c
33985 +++ b/drivers/cpuidle/cpuidle.c
33986 @@ -279,7 +279,7 @@ static int poll_idle(struct cpuidle_device *dev,
33987
33988 static void poll_idle_init(struct cpuidle_driver *drv)
33989 {
33990 - struct cpuidle_state *state = &drv->states[0];
33991 + cpuidle_state_no_const *state = &drv->states[0];
33992
33993 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
33994 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
33995 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
33996 index ea2f8e7..70ac501 100644
33997 --- a/drivers/cpuidle/governor.c
33998 +++ b/drivers/cpuidle/governor.c
33999 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34000 mutex_lock(&cpuidle_lock);
34001 if (__cpuidle_find_governor(gov->name) == NULL) {
34002 ret = 0;
34003 - list_add_tail(&gov->governor_list, &cpuidle_governors);
34004 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34005 if (!cpuidle_curr_governor ||
34006 cpuidle_curr_governor->rating < gov->rating)
34007 cpuidle_switch_governor(gov);
34008 @@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34009 new_gov = cpuidle_replace_governor(gov->rating);
34010 cpuidle_switch_governor(new_gov);
34011 }
34012 - list_del(&gov->governor_list);
34013 + pax_list_del((struct list_head *)&gov->governor_list);
34014 mutex_unlock(&cpuidle_lock);
34015 }
34016
34017 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34018 index 428754a..8bdf9cc 100644
34019 --- a/drivers/cpuidle/sysfs.c
34020 +++ b/drivers/cpuidle/sysfs.c
34021 @@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34022 NULL
34023 };
34024
34025 -static struct attribute_group cpuidle_attr_group = {
34026 +static attribute_group_no_const cpuidle_attr_group = {
34027 .attrs = cpuidle_default_attrs,
34028 .name = "cpuidle",
34029 };
34030 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34031 index 3b36797..289c16a 100644
34032 --- a/drivers/devfreq/devfreq.c
34033 +++ b/drivers/devfreq/devfreq.c
34034 @@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34035 goto err_out;
34036 }
34037
34038 - list_add(&governor->node, &devfreq_governor_list);
34039 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34040
34041 list_for_each_entry(devfreq, &devfreq_list, node) {
34042 int ret = 0;
34043 @@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34044 }
34045 }
34046
34047 - list_del(&governor->node);
34048 + pax_list_del((struct list_head *)&governor->node);
34049 err_out:
34050 mutex_unlock(&devfreq_list_lock);
34051
34052 diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34053 index b70709b..1d8d02a 100644
34054 --- a/drivers/dma/sh/shdma.c
34055 +++ b/drivers/dma/sh/shdma.c
34056 @@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34057 return ret;
34058 }
34059
34060 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34061 +static struct notifier_block sh_dmae_nmi_notifier = {
34062 .notifier_call = sh_dmae_nmi_handler,
34063
34064 /* Run before NMI debug handler and KGDB */
34065 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34066 index 0ca1ca7..6e6f454 100644
34067 --- a/drivers/edac/edac_mc_sysfs.c
34068 +++ b/drivers/edac/edac_mc_sysfs.c
34069 @@ -148,7 +148,7 @@ static const char *edac_caps[] = {
34070 struct dev_ch_attribute {
34071 struct device_attribute attr;
34072 int channel;
34073 -};
34074 +} __do_const;
34075
34076 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34077 struct dev_ch_attribute dev_attr_legacy_##_name = \
34078 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34079 index 0056c4d..23b54d9 100644
34080 --- a/drivers/edac/edac_pci_sysfs.c
34081 +++ b/drivers/edac/edac_pci_sysfs.c
34082 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34083 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34084 static int edac_pci_poll_msec = 1000; /* one second workq period */
34085
34086 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
34087 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34088 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34089 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34090
34091 static struct kobject *edac_pci_top_main_kobj;
34092 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34093 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34094 void *value;
34095 ssize_t(*show) (void *, char *);
34096 ssize_t(*store) (void *, const char *, size_t);
34097 -};
34098 +} __do_const;
34099
34100 /* Set of show/store abstract level functions for PCI Parity object */
34101 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34102 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34103 edac_printk(KERN_CRIT, EDAC_PCI,
34104 "Signaled System Error on %s\n",
34105 pci_name(dev));
34106 - atomic_inc(&pci_nonparity_count);
34107 + atomic_inc_unchecked(&pci_nonparity_count);
34108 }
34109
34110 if (status & (PCI_STATUS_PARITY)) {
34111 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34112 "Master Data Parity Error on %s\n",
34113 pci_name(dev));
34114
34115 - atomic_inc(&pci_parity_count);
34116 + atomic_inc_unchecked(&pci_parity_count);
34117 }
34118
34119 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34120 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34121 "Detected Parity Error on %s\n",
34122 pci_name(dev));
34123
34124 - atomic_inc(&pci_parity_count);
34125 + atomic_inc_unchecked(&pci_parity_count);
34126 }
34127 }
34128
34129 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34130 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34131 "Signaled System Error on %s\n",
34132 pci_name(dev));
34133 - atomic_inc(&pci_nonparity_count);
34134 + atomic_inc_unchecked(&pci_nonparity_count);
34135 }
34136
34137 if (status & (PCI_STATUS_PARITY)) {
34138 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34139 "Master Data Parity Error on "
34140 "%s\n", pci_name(dev));
34141
34142 - atomic_inc(&pci_parity_count);
34143 + atomic_inc_unchecked(&pci_parity_count);
34144 }
34145
34146 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34147 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34148 "Detected Parity Error on %s\n",
34149 pci_name(dev));
34150
34151 - atomic_inc(&pci_parity_count);
34152 + atomic_inc_unchecked(&pci_parity_count);
34153 }
34154 }
34155 }
34156 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34157 if (!check_pci_errors)
34158 return;
34159
34160 - before_count = atomic_read(&pci_parity_count);
34161 + before_count = atomic_read_unchecked(&pci_parity_count);
34162
34163 /* scan all PCI devices looking for a Parity Error on devices and
34164 * bridges.
34165 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34166 /* Only if operator has selected panic on PCI Error */
34167 if (edac_pci_get_panic_on_pe()) {
34168 /* If the count is different 'after' from 'before' */
34169 - if (before_count != atomic_read(&pci_parity_count))
34170 + if (before_count != atomic_read_unchecked(&pci_parity_count))
34171 panic("EDAC: PCI Parity Error");
34172 }
34173 }
34174 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34175 index 6796799..99e8377 100644
34176 --- a/drivers/edac/mce_amd.h
34177 +++ b/drivers/edac/mce_amd.h
34178 @@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
34179 struct amd_decoder_ops {
34180 bool (*mc0_mce)(u16, u8);
34181 bool (*mc1_mce)(u16, u8);
34182 -};
34183 +} __no_const;
34184
34185 void amd_report_gart_errors(bool);
34186 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34187 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34188 index 57ea7f4..789e3c3 100644
34189 --- a/drivers/firewire/core-card.c
34190 +++ b/drivers/firewire/core-card.c
34191 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34192
34193 void fw_core_remove_card(struct fw_card *card)
34194 {
34195 - struct fw_card_driver dummy_driver = dummy_driver_template;
34196 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
34197
34198 card->driver->update_phy_reg(card, 4,
34199 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34200 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34201 index f8d2287..5aaf4db 100644
34202 --- a/drivers/firewire/core-cdev.c
34203 +++ b/drivers/firewire/core-cdev.c
34204 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
34205 int ret;
34206
34207 if ((request->channels == 0 && request->bandwidth == 0) ||
34208 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34209 - request->bandwidth < 0)
34210 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34211 return -EINVAL;
34212
34213 r = kmalloc(sizeof(*r), GFP_KERNEL);
34214 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34215 index af3e8aa..eb2f227 100644
34216 --- a/drivers/firewire/core-device.c
34217 +++ b/drivers/firewire/core-device.c
34218 @@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
34219 struct config_rom_attribute {
34220 struct device_attribute attr;
34221 u32 key;
34222 -};
34223 +} __do_const;
34224
34225 static ssize_t show_immediate(struct device *dev,
34226 struct device_attribute *dattr, char *buf)
34227 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
34228 index 28a94c7..58da63a 100644
34229 --- a/drivers/firewire/core-transaction.c
34230 +++ b/drivers/firewire/core-transaction.c
34231 @@ -38,6 +38,7 @@
34232 #include <linux/timer.h>
34233 #include <linux/types.h>
34234 #include <linux/workqueue.h>
34235 +#include <linux/sched.h>
34236
34237 #include <asm/byteorder.h>
34238
34239 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
34240 index 515a42c..5ecf3ba 100644
34241 --- a/drivers/firewire/core.h
34242 +++ b/drivers/firewire/core.h
34243 @@ -111,6 +111,7 @@ struct fw_card_driver {
34244
34245 int (*stop_iso)(struct fw_iso_context *ctx);
34246 };
34247 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
34248
34249 void fw_card_initialize(struct fw_card *card,
34250 const struct fw_card_driver *driver, struct device *device);
34251 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
34252 index 94a58a0..f5eba42 100644
34253 --- a/drivers/firmware/dmi-id.c
34254 +++ b/drivers/firmware/dmi-id.c
34255 @@ -16,7 +16,7 @@
34256 struct dmi_device_attribute{
34257 struct device_attribute dev_attr;
34258 int field;
34259 -};
34260 +} __do_const;
34261 #define to_dmi_dev_attr(_dev_attr) \
34262 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
34263
34264 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
34265 index 982f1f5..d21e5da 100644
34266 --- a/drivers/firmware/dmi_scan.c
34267 +++ b/drivers/firmware/dmi_scan.c
34268 @@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
34269 }
34270 }
34271 else {
34272 - /*
34273 - * no iounmap() for that ioremap(); it would be a no-op, but
34274 - * it's so early in setup that sucker gets confused into doing
34275 - * what it shouldn't if we actually call it.
34276 - */
34277 p = dmi_ioremap(0xF0000, 0x10000);
34278 if (p == NULL)
34279 goto error;
34280 @@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
34281 if (buf == NULL)
34282 return -1;
34283
34284 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
34285 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
34286
34287 iounmap(buf);
34288 return 0;
34289 diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
34290 index bcb201c..4fd34dd 100644
34291 --- a/drivers/firmware/efivars.c
34292 +++ b/drivers/firmware/efivars.c
34293 @@ -133,7 +133,7 @@ struct efivar_attribute {
34294 };
34295
34296 static struct efivars __efivars;
34297 -static struct efivar_operations ops;
34298 +static efivar_operations_no_const ops __read_only;
34299
34300 #define PSTORE_EFI_ATTRIBUTES \
34301 (EFI_VARIABLE_NON_VOLATILE | \
34302 @@ -1734,7 +1734,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
34303 static int
34304 create_efivars_bin_attributes(struct efivars *efivars)
34305 {
34306 - struct bin_attribute *attr;
34307 + bin_attribute_no_const *attr;
34308 int error;
34309
34310 /* new_var */
34311 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
34312 index 2a90ba6..07f3733 100644
34313 --- a/drivers/firmware/google/memconsole.c
34314 +++ b/drivers/firmware/google/memconsole.c
34315 @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
34316 if (!found_memconsole())
34317 return -ENODEV;
34318
34319 - memconsole_bin_attr.size = memconsole_length;
34320 + pax_open_kernel();
34321 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
34322 + pax_close_kernel();
34323
34324 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
34325
34326 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
34327 index 6f2306d..af9476a 100644
34328 --- a/drivers/gpio/gpio-ich.c
34329 +++ b/drivers/gpio/gpio-ich.c
34330 @@ -69,7 +69,7 @@ struct ichx_desc {
34331 /* Some chipsets have quirks, let these use their own request/get */
34332 int (*request)(struct gpio_chip *chip, unsigned offset);
34333 int (*get)(struct gpio_chip *chip, unsigned offset);
34334 -};
34335 +} __do_const;
34336
34337 static struct {
34338 spinlock_t lock;
34339 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
34340 index 9902732..64b62dd 100644
34341 --- a/drivers/gpio/gpio-vr41xx.c
34342 +++ b/drivers/gpio/gpio-vr41xx.c
34343 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
34344 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
34345 maskl, pendl, maskh, pendh);
34346
34347 - atomic_inc(&irq_err_count);
34348 + atomic_inc_unchecked(&irq_err_count);
34349
34350 return -EINVAL;
34351 }
34352 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
34353 index 7b2d378..cc947ea 100644
34354 --- a/drivers/gpu/drm/drm_crtc_helper.c
34355 +++ b/drivers/gpu/drm/drm_crtc_helper.c
34356 @@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
34357 struct drm_crtc *tmp;
34358 int crtc_mask = 1;
34359
34360 - WARN(!crtc, "checking null crtc?\n");
34361 + BUG_ON(!crtc);
34362
34363 dev = crtc->dev;
34364
34365 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
34366 index be174ca..7f38143 100644
34367 --- a/drivers/gpu/drm/drm_drv.c
34368 +++ b/drivers/gpu/drm/drm_drv.c
34369 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
34370 /**
34371 * Copy and IOCTL return string to user space
34372 */
34373 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
34374 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
34375 {
34376 int len;
34377
34378 @@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
34379 struct drm_file *file_priv = filp->private_data;
34380 struct drm_device *dev;
34381 struct drm_ioctl_desc *ioctl;
34382 - drm_ioctl_t *func;
34383 + drm_ioctl_no_const_t func;
34384 unsigned int nr = DRM_IOCTL_NR(cmd);
34385 int retcode = -EINVAL;
34386 char stack_kdata[128];
34387 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
34388 return -ENODEV;
34389
34390 atomic_inc(&dev->ioctl_count);
34391 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
34392 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
34393 ++file_priv->ioctl_count;
34394
34395 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
34396 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
34397 index 133b413..fd68225 100644
34398 --- a/drivers/gpu/drm/drm_fops.c
34399 +++ b/drivers/gpu/drm/drm_fops.c
34400 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
34401 }
34402
34403 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
34404 - atomic_set(&dev->counts[i], 0);
34405 + atomic_set_unchecked(&dev->counts[i], 0);
34406
34407 dev->sigdata.lock = NULL;
34408
34409 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
34410 if (drm_device_is_unplugged(dev))
34411 return -ENODEV;
34412
34413 - if (!dev->open_count++)
34414 + if (local_inc_return(&dev->open_count) == 1)
34415 need_setup = 1;
34416 mutex_lock(&dev->struct_mutex);
34417 old_mapping = dev->dev_mapping;
34418 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
34419 retcode = drm_open_helper(inode, filp, dev);
34420 if (retcode)
34421 goto err_undo;
34422 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
34423 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
34424 if (need_setup) {
34425 retcode = drm_setup(dev);
34426 if (retcode)
34427 @@ -164,7 +164,7 @@ err_undo:
34428 iput(container_of(dev->dev_mapping, struct inode, i_data));
34429 dev->dev_mapping = old_mapping;
34430 mutex_unlock(&dev->struct_mutex);
34431 - dev->open_count--;
34432 + local_dec(&dev->open_count);
34433 return retcode;
34434 }
34435 EXPORT_SYMBOL(drm_open);
34436 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
34437
34438 mutex_lock(&drm_global_mutex);
34439
34440 - DRM_DEBUG("open_count = %d\n", dev->open_count);
34441 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
34442
34443 if (dev->driver->preclose)
34444 dev->driver->preclose(dev, file_priv);
34445 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
34446 * Begin inline drm_release
34447 */
34448
34449 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
34450 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
34451 task_pid_nr(current),
34452 (long)old_encode_dev(file_priv->minor->device),
34453 - dev->open_count);
34454 + local_read(&dev->open_count));
34455
34456 /* Release any auth tokens that might point to this file_priv,
34457 (do that under the drm_global_mutex) */
34458 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
34459 * End inline drm_release
34460 */
34461
34462 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
34463 - if (!--dev->open_count) {
34464 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
34465 + if (local_dec_and_test(&dev->open_count)) {
34466 if (atomic_read(&dev->ioctl_count)) {
34467 DRM_ERROR("Device busy: %d\n",
34468 atomic_read(&dev->ioctl_count));
34469 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
34470 index f731116..629842c 100644
34471 --- a/drivers/gpu/drm/drm_global.c
34472 +++ b/drivers/gpu/drm/drm_global.c
34473 @@ -36,7 +36,7 @@
34474 struct drm_global_item {
34475 struct mutex mutex;
34476 void *object;
34477 - int refcount;
34478 + atomic_t refcount;
34479 };
34480
34481 static struct drm_global_item glob[DRM_GLOBAL_NUM];
34482 @@ -49,7 +49,7 @@ void drm_global_init(void)
34483 struct drm_global_item *item = &glob[i];
34484 mutex_init(&item->mutex);
34485 item->object = NULL;
34486 - item->refcount = 0;
34487 + atomic_set(&item->refcount, 0);
34488 }
34489 }
34490
34491 @@ -59,7 +59,7 @@ void drm_global_release(void)
34492 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
34493 struct drm_global_item *item = &glob[i];
34494 BUG_ON(item->object != NULL);
34495 - BUG_ON(item->refcount != 0);
34496 + BUG_ON(atomic_read(&item->refcount) != 0);
34497 }
34498 }
34499
34500 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34501 void *object;
34502
34503 mutex_lock(&item->mutex);
34504 - if (item->refcount == 0) {
34505 + if (atomic_read(&item->refcount) == 0) {
34506 item->object = kzalloc(ref->size, GFP_KERNEL);
34507 if (unlikely(item->object == NULL)) {
34508 ret = -ENOMEM;
34509 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34510 goto out_err;
34511
34512 }
34513 - ++item->refcount;
34514 + atomic_inc(&item->refcount);
34515 ref->object = item->object;
34516 object = item->object;
34517 mutex_unlock(&item->mutex);
34518 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
34519 struct drm_global_item *item = &glob[ref->global_type];
34520
34521 mutex_lock(&item->mutex);
34522 - BUG_ON(item->refcount == 0);
34523 + BUG_ON(atomic_read(&item->refcount) == 0);
34524 BUG_ON(ref->object != item->object);
34525 - if (--item->refcount == 0) {
34526 + if (atomic_dec_and_test(&item->refcount)) {
34527 ref->release(ref);
34528 item->object = NULL;
34529 }
34530 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
34531 index d4b20ce..77a8d41 100644
34532 --- a/drivers/gpu/drm/drm_info.c
34533 +++ b/drivers/gpu/drm/drm_info.c
34534 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
34535 struct drm_local_map *map;
34536 struct drm_map_list *r_list;
34537
34538 - /* Hardcoded from _DRM_FRAME_BUFFER,
34539 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
34540 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
34541 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
34542 + static const char * const types[] = {
34543 + [_DRM_FRAME_BUFFER] = "FB",
34544 + [_DRM_REGISTERS] = "REG",
34545 + [_DRM_SHM] = "SHM",
34546 + [_DRM_AGP] = "AGP",
34547 + [_DRM_SCATTER_GATHER] = "SG",
34548 + [_DRM_CONSISTENT] = "PCI",
34549 + [_DRM_GEM] = "GEM" };
34550 const char *type;
34551 int i;
34552
34553 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
34554 map = r_list->map;
34555 if (!map)
34556 continue;
34557 - if (map->type < 0 || map->type > 5)
34558 + if (map->type >= ARRAY_SIZE(types))
34559 type = "??";
34560 else
34561 type = types[map->type];
34562 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
34563 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
34564 vma->vm_flags & VM_LOCKED ? 'l' : '-',
34565 vma->vm_flags & VM_IO ? 'i' : '-',
34566 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34567 + 0);
34568 +#else
34569 vma->vm_pgoff);
34570 +#endif
34571
34572 #if defined(__i386__)
34573 pgprot = pgprot_val(vma->vm_page_prot);
34574 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
34575 index 2f4c434..dd12cd2 100644
34576 --- a/drivers/gpu/drm/drm_ioc32.c
34577 +++ b/drivers/gpu/drm/drm_ioc32.c
34578 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
34579 request = compat_alloc_user_space(nbytes);
34580 if (!access_ok(VERIFY_WRITE, request, nbytes))
34581 return -EFAULT;
34582 - list = (struct drm_buf_desc *) (request + 1);
34583 + list = (struct drm_buf_desc __user *) (request + 1);
34584
34585 if (__put_user(count, &request->count)
34586 || __put_user(list, &request->list))
34587 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
34588 request = compat_alloc_user_space(nbytes);
34589 if (!access_ok(VERIFY_WRITE, request, nbytes))
34590 return -EFAULT;
34591 - list = (struct drm_buf_pub *) (request + 1);
34592 + list = (struct drm_buf_pub __user *) (request + 1);
34593
34594 if (__put_user(count, &request->count)
34595 || __put_user(list, &request->list))
34596 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
34597 return 0;
34598 }
34599
34600 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
34601 +drm_ioctl_compat_t drm_compat_ioctls[] = {
34602 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
34603 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
34604 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
34605 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
34606 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34607 {
34608 unsigned int nr = DRM_IOCTL_NR(cmd);
34609 - drm_ioctl_compat_t *fn;
34610 int ret;
34611
34612 /* Assume that ioctls without an explicit compat routine will just
34613 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34614 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
34615 return drm_ioctl(filp, cmd, arg);
34616
34617 - fn = drm_compat_ioctls[nr];
34618 -
34619 - if (fn != NULL)
34620 - ret = (*fn) (filp, cmd, arg);
34621 + if (drm_compat_ioctls[nr] != NULL)
34622 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
34623 else
34624 ret = drm_ioctl(filp, cmd, arg);
34625
34626 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
34627 index e77bd8b..1571b85 100644
34628 --- a/drivers/gpu/drm/drm_ioctl.c
34629 +++ b/drivers/gpu/drm/drm_ioctl.c
34630 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
34631 stats->data[i].value =
34632 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
34633 else
34634 - stats->data[i].value = atomic_read(&dev->counts[i]);
34635 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
34636 stats->data[i].type = dev->types[i];
34637 }
34638
34639 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
34640 index d752c96..fe08455 100644
34641 --- a/drivers/gpu/drm/drm_lock.c
34642 +++ b/drivers/gpu/drm/drm_lock.c
34643 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34644 if (drm_lock_take(&master->lock, lock->context)) {
34645 master->lock.file_priv = file_priv;
34646 master->lock.lock_time = jiffies;
34647 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
34648 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
34649 break; /* Got lock */
34650 }
34651
34652 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34653 return -EINVAL;
34654 }
34655
34656 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
34657 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
34658
34659 if (drm_lock_free(&master->lock, lock->context)) {
34660 /* FIXME: Should really bail out here. */
34661 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
34662 index 200e104..59facda 100644
34663 --- a/drivers/gpu/drm/drm_stub.c
34664 +++ b/drivers/gpu/drm/drm_stub.c
34665 @@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
34666
34667 drm_device_set_unplugged(dev);
34668
34669 - if (dev->open_count == 0) {
34670 + if (local_read(&dev->open_count) == 0) {
34671 drm_put_dev(dev);
34672 }
34673 mutex_unlock(&drm_global_mutex);
34674 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
34675 index 004ecdf..db1f6e0 100644
34676 --- a/drivers/gpu/drm/i810/i810_dma.c
34677 +++ b/drivers/gpu/drm/i810/i810_dma.c
34678 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
34679 dma->buflist[vertex->idx],
34680 vertex->discard, vertex->used);
34681
34682 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34683 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34684 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34685 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34686 sarea_priv->last_enqueue = dev_priv->counter - 1;
34687 sarea_priv->last_dispatch = (int)hw_status[5];
34688
34689 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
34690 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
34691 mc->last_render);
34692
34693 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34694 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34695 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34696 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34697 sarea_priv->last_enqueue = dev_priv->counter - 1;
34698 sarea_priv->last_dispatch = (int)hw_status[5];
34699
34700 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
34701 index 6e0acad..93c8289 100644
34702 --- a/drivers/gpu/drm/i810/i810_drv.h
34703 +++ b/drivers/gpu/drm/i810/i810_drv.h
34704 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
34705 int page_flipping;
34706
34707 wait_queue_head_t irq_queue;
34708 - atomic_t irq_received;
34709 - atomic_t irq_emitted;
34710 + atomic_unchecked_t irq_received;
34711 + atomic_unchecked_t irq_emitted;
34712
34713 int front_offset;
34714 } drm_i810_private_t;
34715 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
34716 index 8a7c48b..72effc2 100644
34717 --- a/drivers/gpu/drm/i915/i915_debugfs.c
34718 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
34719 @@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
34720 I915_READ(GTIMR));
34721 }
34722 seq_printf(m, "Interrupts received: %d\n",
34723 - atomic_read(&dev_priv->irq_received));
34724 + atomic_read_unchecked(&dev_priv->irq_received));
34725 for_each_ring(ring, dev_priv, i) {
34726 if (IS_GEN6(dev) || IS_GEN7(dev)) {
34727 seq_printf(m,
34728 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
34729 index 99daa89..84ebd44 100644
34730 --- a/drivers/gpu/drm/i915/i915_dma.c
34731 +++ b/drivers/gpu/drm/i915/i915_dma.c
34732 @@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
34733 bool can_switch;
34734
34735 spin_lock(&dev->count_lock);
34736 - can_switch = (dev->open_count == 0);
34737 + can_switch = (local_read(&dev->open_count) == 0);
34738 spin_unlock(&dev->count_lock);
34739 return can_switch;
34740 }
34741 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
34742 index 7339a4b..445aaba 100644
34743 --- a/drivers/gpu/drm/i915/i915_drv.h
34744 +++ b/drivers/gpu/drm/i915/i915_drv.h
34745 @@ -656,7 +656,7 @@ typedef struct drm_i915_private {
34746 drm_dma_handle_t *status_page_dmah;
34747 struct resource mch_res;
34748
34749 - atomic_t irq_received;
34750 + atomic_unchecked_t irq_received;
34751
34752 /* protects the irq masks */
34753 spinlock_t irq_lock;
34754 @@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
34755 * will be page flipped away on the next vblank. When it
34756 * reaches 0, dev_priv->pending_flip_queue will be woken up.
34757 */
34758 - atomic_t pending_flip;
34759 + atomic_unchecked_t pending_flip;
34760 };
34761 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
34762
34763 @@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
34764 struct drm_i915_private *dev_priv, unsigned port);
34765 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
34766 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
34767 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
34768 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
34769 {
34770 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
34771 }
34772 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34773 index 26d08bb..fccb984 100644
34774 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34775 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34776 @@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
34777 i915_gem_clflush_object(obj);
34778
34779 if (obj->base.pending_write_domain)
34780 - flips |= atomic_read(&obj->pending_flip);
34781 + flips |= atomic_read_unchecked(&obj->pending_flip);
34782
34783 flush_domains |= obj->base.write_domain;
34784 }
34785 @@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
34786
34787 static int
34788 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
34789 - int count)
34790 + unsigned int count)
34791 {
34792 - int i;
34793 + unsigned int i;
34794
34795 for (i = 0; i < count; i++) {
34796 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
34797 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
34798 index 3c59584..500f2e9 100644
34799 --- a/drivers/gpu/drm/i915/i915_ioc32.c
34800 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
34801 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
34802 (unsigned long)request);
34803 }
34804
34805 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
34806 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
34807 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
34808 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
34809 [DRM_I915_GETPARAM] = compat_i915_getparam,
34810 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
34811 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34812 {
34813 unsigned int nr = DRM_IOCTL_NR(cmd);
34814 - drm_ioctl_compat_t *fn = NULL;
34815 int ret;
34816
34817 if (nr < DRM_COMMAND_BASE)
34818 return drm_compat_ioctl(filp, cmd, arg);
34819
34820 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
34821 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
34822 -
34823 - if (fn != NULL)
34824 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
34825 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
34826 ret = (*fn) (filp, cmd, arg);
34827 - else
34828 + } else
34829 ret = drm_ioctl(filp, cmd, arg);
34830
34831 return ret;
34832 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
34833 index fe84338..a863190 100644
34834 --- a/drivers/gpu/drm/i915/i915_irq.c
34835 +++ b/drivers/gpu/drm/i915/i915_irq.c
34836 @@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
34837 u32 pipe_stats[I915_MAX_PIPES];
34838 bool blc_event;
34839
34840 - atomic_inc(&dev_priv->irq_received);
34841 + atomic_inc_unchecked(&dev_priv->irq_received);
34842
34843 while (true) {
34844 iir = I915_READ(VLV_IIR);
34845 @@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
34846 irqreturn_t ret = IRQ_NONE;
34847 int i;
34848
34849 - atomic_inc(&dev_priv->irq_received);
34850 + atomic_inc_unchecked(&dev_priv->irq_received);
34851
34852 /* disable master interrupt before clearing iir */
34853 de_ier = I915_READ(DEIER);
34854 @@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
34855 int ret = IRQ_NONE;
34856 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
34857
34858 - atomic_inc(&dev_priv->irq_received);
34859 + atomic_inc_unchecked(&dev_priv->irq_received);
34860
34861 /* disable master interrupt before clearing iir */
34862 de_ier = I915_READ(DEIER);
34863 @@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
34864 {
34865 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34866
34867 - atomic_set(&dev_priv->irq_received, 0);
34868 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34869
34870 I915_WRITE(HWSTAM, 0xeffe);
34871
34872 @@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
34873 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34874 int pipe;
34875
34876 - atomic_set(&dev_priv->irq_received, 0);
34877 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34878
34879 /* VLV magic */
34880 I915_WRITE(VLV_IMR, 0);
34881 @@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
34882 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34883 int pipe;
34884
34885 - atomic_set(&dev_priv->irq_received, 0);
34886 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34887
34888 for_each_pipe(pipe)
34889 I915_WRITE(PIPESTAT(pipe), 0);
34890 @@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
34891 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
34892 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
34893
34894 - atomic_inc(&dev_priv->irq_received);
34895 + atomic_inc_unchecked(&dev_priv->irq_received);
34896
34897 iir = I915_READ16(IIR);
34898 if (iir == 0)
34899 @@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
34900 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34901 int pipe;
34902
34903 - atomic_set(&dev_priv->irq_received, 0);
34904 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34905
34906 if (I915_HAS_HOTPLUG(dev)) {
34907 I915_WRITE(PORT_HOTPLUG_EN, 0);
34908 @@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
34909 };
34910 int pipe, ret = IRQ_NONE;
34911
34912 - atomic_inc(&dev_priv->irq_received);
34913 + atomic_inc_unchecked(&dev_priv->irq_received);
34914
34915 iir = I915_READ(IIR);
34916 do {
34917 @@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
34918 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34919 int pipe;
34920
34921 - atomic_set(&dev_priv->irq_received, 0);
34922 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34923
34924 I915_WRITE(PORT_HOTPLUG_EN, 0);
34925 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
34926 @@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
34927 int irq_received;
34928 int ret = IRQ_NONE, pipe;
34929
34930 - atomic_inc(&dev_priv->irq_received);
34931 + atomic_inc_unchecked(&dev_priv->irq_received);
34932
34933 iir = I915_READ(IIR);
34934
34935 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
34936 index 80aa1fc..85cfce3 100644
34937 --- a/drivers/gpu/drm/i915/intel_display.c
34938 +++ b/drivers/gpu/drm/i915/intel_display.c
34939 @@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
34940
34941 wait_event(dev_priv->pending_flip_queue,
34942 atomic_read(&dev_priv->mm.wedged) ||
34943 - atomic_read(&obj->pending_flip) == 0);
34944 + atomic_read_unchecked(&obj->pending_flip) == 0);
34945
34946 /* Big Hammer, we also need to ensure that any pending
34947 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
34948 @@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
34949
34950 obj = work->old_fb_obj;
34951
34952 - atomic_clear_mask(1 << intel_crtc->plane,
34953 - &obj->pending_flip.counter);
34954 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
34955 wake_up(&dev_priv->pending_flip_queue);
34956
34957 queue_work(dev_priv->wq, &work->work);
34958 @@ -7490,7 +7489,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
34959 /* Block clients from rendering to the new back buffer until
34960 * the flip occurs and the object is no longer visible.
34961 */
34962 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34963 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34964 atomic_inc(&intel_crtc->unpin_work_count);
34965
34966 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
34967 @@ -7507,7 +7506,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
34968
34969 cleanup_pending:
34970 atomic_dec(&intel_crtc->unpin_work_count);
34971 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34972 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34973 drm_gem_object_unreference(&work->old_fb_obj->base);
34974 drm_gem_object_unreference(&obj->base);
34975 mutex_unlock(&dev->struct_mutex);
34976 @@ -8849,13 +8848,13 @@ struct intel_quirk {
34977 int subsystem_vendor;
34978 int subsystem_device;
34979 void (*hook)(struct drm_device *dev);
34980 -};
34981 +} __do_const;
34982
34983 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
34984 struct intel_dmi_quirk {
34985 void (*hook)(struct drm_device *dev);
34986 const struct dmi_system_id (*dmi_id_list)[];
34987 -};
34988 +} __do_const;
34989
34990 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
34991 {
34992 @@ -8863,18 +8862,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
34993 return 1;
34994 }
34995
34996 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
34997 + {
34998 + .callback = intel_dmi_reverse_brightness,
34999 + .ident = "NCR Corporation",
35000 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35001 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
35002 + },
35003 + },
35004 + { } /* terminating entry */
35005 +};
35006 +
35007 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35008 {
35009 - .dmi_id_list = &(const struct dmi_system_id[]) {
35010 - {
35011 - .callback = intel_dmi_reverse_brightness,
35012 - .ident = "NCR Corporation",
35013 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35014 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
35015 - },
35016 - },
35017 - { } /* terminating entry */
35018 - },
35019 + .dmi_id_list = &intel_dmi_quirks_table,
35020 .hook = quirk_invert_brightness,
35021 },
35022 };
35023 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35024 index 54558a0..2d97005 100644
35025 --- a/drivers/gpu/drm/mga/mga_drv.h
35026 +++ b/drivers/gpu/drm/mga/mga_drv.h
35027 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35028 u32 clear_cmd;
35029 u32 maccess;
35030
35031 - atomic_t vbl_received; /**< Number of vblanks received. */
35032 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35033 wait_queue_head_t fence_queue;
35034 - atomic_t last_fence_retired;
35035 + atomic_unchecked_t last_fence_retired;
35036 u32 next_fence_to_post;
35037
35038 unsigned int fb_cpp;
35039 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35040 index 709e90d..89a1c0d 100644
35041 --- a/drivers/gpu/drm/mga/mga_ioc32.c
35042 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
35043 @@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35044 return 0;
35045 }
35046
35047 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
35048 +drm_ioctl_compat_t mga_compat_ioctls[] = {
35049 [DRM_MGA_INIT] = compat_mga_init,
35050 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35051 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35052 @@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35053 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35054 {
35055 unsigned int nr = DRM_IOCTL_NR(cmd);
35056 - drm_ioctl_compat_t *fn = NULL;
35057 int ret;
35058
35059 if (nr < DRM_COMMAND_BASE)
35060 return drm_compat_ioctl(filp, cmd, arg);
35061
35062 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35063 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35064 -
35065 - if (fn != NULL)
35066 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35067 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35068 ret = (*fn) (filp, cmd, arg);
35069 - else
35070 + } else
35071 ret = drm_ioctl(filp, cmd, arg);
35072
35073 return ret;
35074 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35075 index 598c281..60d590e 100644
35076 --- a/drivers/gpu/drm/mga/mga_irq.c
35077 +++ b/drivers/gpu/drm/mga/mga_irq.c
35078 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35079 if (crtc != 0)
35080 return 0;
35081
35082 - return atomic_read(&dev_priv->vbl_received);
35083 + return atomic_read_unchecked(&dev_priv->vbl_received);
35084 }
35085
35086
35087 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35088 /* VBLANK interrupt */
35089 if (status & MGA_VLINEPEN) {
35090 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35091 - atomic_inc(&dev_priv->vbl_received);
35092 + atomic_inc_unchecked(&dev_priv->vbl_received);
35093 drm_handle_vblank(dev, 0);
35094 handled = 1;
35095 }
35096 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35097 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35098 MGA_WRITE(MGA_PRIMEND, prim_end);
35099
35100 - atomic_inc(&dev_priv->last_fence_retired);
35101 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
35102 DRM_WAKEUP(&dev_priv->fence_queue);
35103 handled = 1;
35104 }
35105 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35106 * using fences.
35107 */
35108 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35109 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35110 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35111 - *sequence) <= (1 << 23)));
35112
35113 *sequence = cur_fence;
35114 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35115 index 865eddf..62c4cc3 100644
35116 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35117 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35118 @@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35119 struct bit_table {
35120 const char id;
35121 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35122 -};
35123 +} __no_const;
35124
35125 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35126
35127 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35128 index aa89eb9..d45d38b 100644
35129 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35130 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35131 @@ -80,7 +80,7 @@ struct nouveau_drm {
35132 struct drm_global_reference mem_global_ref;
35133 struct ttm_bo_global_ref bo_global_ref;
35134 struct ttm_bo_device bdev;
35135 - atomic_t validate_sequence;
35136 + atomic_unchecked_t validate_sequence;
35137 int (*move)(struct nouveau_channel *,
35138 struct ttm_buffer_object *,
35139 struct ttm_mem_reg *, struct ttm_mem_reg *);
35140 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
35141 index cdb83ac..27f0a16 100644
35142 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
35143 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
35144 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
35145 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
35146 struct nouveau_channel *);
35147 u32 (*read)(struct nouveau_channel *);
35148 -};
35149 +} __no_const;
35150
35151 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
35152
35153 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35154 index 8bf695c..9fbc90a 100644
35155 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35156 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35157 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35158 int trycnt = 0;
35159 int ret, i;
35160
35161 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35162 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35163 retry:
35164 if (++trycnt > 100000) {
35165 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
35166 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35167 index 08214bc..9208577 100644
35168 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35169 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35170 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35171 unsigned long arg)
35172 {
35173 unsigned int nr = DRM_IOCTL_NR(cmd);
35174 - drm_ioctl_compat_t *fn = NULL;
35175 + drm_ioctl_compat_t fn = NULL;
35176 int ret;
35177
35178 if (nr < DRM_COMMAND_BASE)
35179 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35180 index 25d3495..d81aaf6 100644
35181 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35182 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35183 @@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35184 bool can_switch;
35185
35186 spin_lock(&dev->count_lock);
35187 - can_switch = (dev->open_count == 0);
35188 + can_switch = (local_read(&dev->open_count) == 0);
35189 spin_unlock(&dev->count_lock);
35190 return can_switch;
35191 }
35192 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35193 index d4660cf..70dbe65 100644
35194 --- a/drivers/gpu/drm/r128/r128_cce.c
35195 +++ b/drivers/gpu/drm/r128/r128_cce.c
35196 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35197
35198 /* GH: Simple idle check.
35199 */
35200 - atomic_set(&dev_priv->idle_count, 0);
35201 + atomic_set_unchecked(&dev_priv->idle_count, 0);
35202
35203 /* We don't support anything other than bus-mastering ring mode,
35204 * but the ring can be in either AGP or PCI space for the ring
35205 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35206 index 930c71b..499aded 100644
35207 --- a/drivers/gpu/drm/r128/r128_drv.h
35208 +++ b/drivers/gpu/drm/r128/r128_drv.h
35209 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35210 int is_pci;
35211 unsigned long cce_buffers_offset;
35212
35213 - atomic_t idle_count;
35214 + atomic_unchecked_t idle_count;
35215
35216 int page_flipping;
35217 int current_page;
35218 u32 crtc_offset;
35219 u32 crtc_offset_cntl;
35220
35221 - atomic_t vbl_received;
35222 + atomic_unchecked_t vbl_received;
35223
35224 u32 color_fmt;
35225 unsigned int front_offset;
35226 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35227 index a954c54..9cc595c 100644
35228 --- a/drivers/gpu/drm/r128/r128_ioc32.c
35229 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
35230 @@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35231 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
35232 }
35233
35234 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
35235 +drm_ioctl_compat_t r128_compat_ioctls[] = {
35236 [DRM_R128_INIT] = compat_r128_init,
35237 [DRM_R128_DEPTH] = compat_r128_depth,
35238 [DRM_R128_STIPPLE] = compat_r128_stipple,
35239 @@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
35240 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35241 {
35242 unsigned int nr = DRM_IOCTL_NR(cmd);
35243 - drm_ioctl_compat_t *fn = NULL;
35244 int ret;
35245
35246 if (nr < DRM_COMMAND_BASE)
35247 return drm_compat_ioctl(filp, cmd, arg);
35248
35249 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
35250 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35251 -
35252 - if (fn != NULL)
35253 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
35254 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35255 ret = (*fn) (filp, cmd, arg);
35256 - else
35257 + } else
35258 ret = drm_ioctl(filp, cmd, arg);
35259
35260 return ret;
35261 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
35262 index 2ea4f09..d391371 100644
35263 --- a/drivers/gpu/drm/r128/r128_irq.c
35264 +++ b/drivers/gpu/drm/r128/r128_irq.c
35265 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
35266 if (crtc != 0)
35267 return 0;
35268
35269 - return atomic_read(&dev_priv->vbl_received);
35270 + return atomic_read_unchecked(&dev_priv->vbl_received);
35271 }
35272
35273 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35274 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35275 /* VBLANK interrupt */
35276 if (status & R128_CRTC_VBLANK_INT) {
35277 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
35278 - atomic_inc(&dev_priv->vbl_received);
35279 + atomic_inc_unchecked(&dev_priv->vbl_received);
35280 drm_handle_vblank(dev, 0);
35281 return IRQ_HANDLED;
35282 }
35283 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
35284 index 19bb7e6..de7e2a2 100644
35285 --- a/drivers/gpu/drm/r128/r128_state.c
35286 +++ b/drivers/gpu/drm/r128/r128_state.c
35287 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
35288
35289 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
35290 {
35291 - if (atomic_read(&dev_priv->idle_count) == 0)
35292 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
35293 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
35294 else
35295 - atomic_set(&dev_priv->idle_count, 0);
35296 + atomic_set_unchecked(&dev_priv->idle_count, 0);
35297 }
35298
35299 #endif
35300 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
35301 index 5a82b6b..9e69c73 100644
35302 --- a/drivers/gpu/drm/radeon/mkregtable.c
35303 +++ b/drivers/gpu/drm/radeon/mkregtable.c
35304 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
35305 regex_t mask_rex;
35306 regmatch_t match[4];
35307 char buf[1024];
35308 - size_t end;
35309 + long end;
35310 int len;
35311 int done = 0;
35312 int r;
35313 unsigned o;
35314 struct offset *offset;
35315 char last_reg_s[10];
35316 - int last_reg;
35317 + unsigned long last_reg;
35318
35319 if (regcomp
35320 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
35321 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
35322 index 0d6562b..a154330 100644
35323 --- a/drivers/gpu/drm/radeon/radeon_device.c
35324 +++ b/drivers/gpu/drm/radeon/radeon_device.c
35325 @@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
35326 bool can_switch;
35327
35328 spin_lock(&dev->count_lock);
35329 - can_switch = (dev->open_count == 0);
35330 + can_switch = (local_read(&dev->open_count) == 0);
35331 spin_unlock(&dev->count_lock);
35332 return can_switch;
35333 }
35334 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
35335 index e7fdf16..f4f6490 100644
35336 --- a/drivers/gpu/drm/radeon/radeon_drv.h
35337 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
35338 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
35339
35340 /* SW interrupt */
35341 wait_queue_head_t swi_queue;
35342 - atomic_t swi_emitted;
35343 + atomic_unchecked_t swi_emitted;
35344 int vblank_crtc;
35345 uint32_t irq_enable_reg;
35346 uint32_t r500_disp_irq_reg;
35347 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
35348 index c180df8..5fd8186 100644
35349 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
35350 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
35351 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35352 request = compat_alloc_user_space(sizeof(*request));
35353 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
35354 || __put_user(req32.param, &request->param)
35355 - || __put_user((void __user *)(unsigned long)req32.value,
35356 + || __put_user((unsigned long)req32.value,
35357 &request->value))
35358 return -EFAULT;
35359
35360 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35361 #define compat_radeon_cp_setparam NULL
35362 #endif /* X86_64 || IA64 */
35363
35364 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35365 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
35366 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
35367 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
35368 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
35369 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35370 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35371 {
35372 unsigned int nr = DRM_IOCTL_NR(cmd);
35373 - drm_ioctl_compat_t *fn = NULL;
35374 int ret;
35375
35376 if (nr < DRM_COMMAND_BASE)
35377 return drm_compat_ioctl(filp, cmd, arg);
35378
35379 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
35380 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35381 -
35382 - if (fn != NULL)
35383 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
35384 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35385 ret = (*fn) (filp, cmd, arg);
35386 - else
35387 + } else
35388 ret = drm_ioctl(filp, cmd, arg);
35389
35390 return ret;
35391 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
35392 index e771033..a0bc6b3 100644
35393 --- a/drivers/gpu/drm/radeon/radeon_irq.c
35394 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
35395 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
35396 unsigned int ret;
35397 RING_LOCALS;
35398
35399 - atomic_inc(&dev_priv->swi_emitted);
35400 - ret = atomic_read(&dev_priv->swi_emitted);
35401 + atomic_inc_unchecked(&dev_priv->swi_emitted);
35402 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
35403
35404 BEGIN_RING(4);
35405 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
35406 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
35407 drm_radeon_private_t *dev_priv =
35408 (drm_radeon_private_t *) dev->dev_private;
35409
35410 - atomic_set(&dev_priv->swi_emitted, 0);
35411 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
35412 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
35413
35414 dev->max_vblank_count = 0x001fffff;
35415 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
35416 index 8e9057b..af6dacb 100644
35417 --- a/drivers/gpu/drm/radeon/radeon_state.c
35418 +++ b/drivers/gpu/drm/radeon/radeon_state.c
35419 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
35420 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
35421 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
35422
35423 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35424 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35425 sarea_priv->nbox * sizeof(depth_boxes[0])))
35426 return -EFAULT;
35427
35428 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
35429 {
35430 drm_radeon_private_t *dev_priv = dev->dev_private;
35431 drm_radeon_getparam_t *param = data;
35432 - int value;
35433 + int value = 0;
35434
35435 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
35436
35437 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
35438 index 93f760e..8088227 100644
35439 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
35440 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
35441 @@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
35442 man->size = size >> PAGE_SHIFT;
35443 }
35444
35445 -static struct vm_operations_struct radeon_ttm_vm_ops;
35446 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
35447 static const struct vm_operations_struct *ttm_vm_ops = NULL;
35448
35449 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
35450 @@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
35451 }
35452 if (unlikely(ttm_vm_ops == NULL)) {
35453 ttm_vm_ops = vma->vm_ops;
35454 + pax_open_kernel();
35455 radeon_ttm_vm_ops = *ttm_vm_ops;
35456 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
35457 + pax_close_kernel();
35458 }
35459 vma->vm_ops = &radeon_ttm_vm_ops;
35460 return 0;
35461 @@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
35462 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
35463 else
35464 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
35465 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35466 - radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35467 - radeon_mem_types_list[i].driver_features = 0;
35468 + pax_open_kernel();
35469 + *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35470 + *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35471 + *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35472 if (i == 0)
35473 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35474 + *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35475 else
35476 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35477 -
35478 + *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35479 + pax_close_kernel();
35480 }
35481 /* Add ttm page pool to debugfs */
35482 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
35483 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35484 - radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35485 - radeon_mem_types_list[i].driver_features = 0;
35486 - radeon_mem_types_list[i++].data = NULL;
35487 + pax_open_kernel();
35488 + *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35489 + *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35490 + *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35491 + *(void **)&radeon_mem_types_list[i++].data = NULL;
35492 + pax_close_kernel();
35493 #ifdef CONFIG_SWIOTLB
35494 if (swiotlb_nr_tbl()) {
35495 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
35496 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35497 - radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35498 - radeon_mem_types_list[i].driver_features = 0;
35499 - radeon_mem_types_list[i++].data = NULL;
35500 + pax_open_kernel();
35501 + *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35502 + *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35503 + *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35504 + *(void **)&radeon_mem_types_list[i++].data = NULL;
35505 + pax_close_kernel();
35506 }
35507 #endif
35508 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
35509 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
35510 index 5706d2a..17aedaa 100644
35511 --- a/drivers/gpu/drm/radeon/rs690.c
35512 +++ b/drivers/gpu/drm/radeon/rs690.c
35513 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
35514 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
35515 rdev->pm.sideport_bandwidth.full)
35516 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
35517 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
35518 + read_delay_latency.full = dfixed_const(800 * 1000);
35519 read_delay_latency.full = dfixed_div(read_delay_latency,
35520 rdev->pm.igp_sideport_mclk);
35521 + a.full = dfixed_const(370);
35522 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
35523 } else {
35524 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
35525 rdev->pm.k8_bandwidth.full)
35526 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35527 index bd2a3b4..122d9ad 100644
35528 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
35529 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35530 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
35531 static int ttm_pool_mm_shrink(struct shrinker *shrink,
35532 struct shrink_control *sc)
35533 {
35534 - static atomic_t start_pool = ATOMIC_INIT(0);
35535 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
35536 unsigned i;
35537 - unsigned pool_offset = atomic_add_return(1, &start_pool);
35538 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
35539 struct ttm_page_pool *pool;
35540 int shrink_pages = sc->nr_to_scan;
35541
35542 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
35543 index 1eb060c..188b1fc 100644
35544 --- a/drivers/gpu/drm/udl/udl_fb.c
35545 +++ b/drivers/gpu/drm/udl/udl_fb.c
35546 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
35547 fb_deferred_io_cleanup(info);
35548 kfree(info->fbdefio);
35549 info->fbdefio = NULL;
35550 - info->fbops->fb_mmap = udl_fb_mmap;
35551 }
35552
35553 pr_warn("released /dev/fb%d user=%d count=%d\n",
35554 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
35555 index 893a650..6190d3b 100644
35556 --- a/drivers/gpu/drm/via/via_drv.h
35557 +++ b/drivers/gpu/drm/via/via_drv.h
35558 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
35559 typedef uint32_t maskarray_t[5];
35560
35561 typedef struct drm_via_irq {
35562 - atomic_t irq_received;
35563 + atomic_unchecked_t irq_received;
35564 uint32_t pending_mask;
35565 uint32_t enable_mask;
35566 wait_queue_head_t irq_queue;
35567 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
35568 struct timeval last_vblank;
35569 int last_vblank_valid;
35570 unsigned usec_per_vblank;
35571 - atomic_t vbl_received;
35572 + atomic_unchecked_t vbl_received;
35573 drm_via_state_t hc_state;
35574 char pci_buf[VIA_PCI_BUF_SIZE];
35575 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
35576 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
35577 index ac98964..5dbf512 100644
35578 --- a/drivers/gpu/drm/via/via_irq.c
35579 +++ b/drivers/gpu/drm/via/via_irq.c
35580 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
35581 if (crtc != 0)
35582 return 0;
35583
35584 - return atomic_read(&dev_priv->vbl_received);
35585 + return atomic_read_unchecked(&dev_priv->vbl_received);
35586 }
35587
35588 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35589 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35590
35591 status = VIA_READ(VIA_REG_INTERRUPT);
35592 if (status & VIA_IRQ_VBLANK_PENDING) {
35593 - atomic_inc(&dev_priv->vbl_received);
35594 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
35595 + atomic_inc_unchecked(&dev_priv->vbl_received);
35596 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
35597 do_gettimeofday(&cur_vblank);
35598 if (dev_priv->last_vblank_valid) {
35599 dev_priv->usec_per_vblank =
35600 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35601 dev_priv->last_vblank = cur_vblank;
35602 dev_priv->last_vblank_valid = 1;
35603 }
35604 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
35605 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
35606 DRM_DEBUG("US per vblank is: %u\n",
35607 dev_priv->usec_per_vblank);
35608 }
35609 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35610
35611 for (i = 0; i < dev_priv->num_irqs; ++i) {
35612 if (status & cur_irq->pending_mask) {
35613 - atomic_inc(&cur_irq->irq_received);
35614 + atomic_inc_unchecked(&cur_irq->irq_received);
35615 DRM_WAKEUP(&cur_irq->irq_queue);
35616 handled = 1;
35617 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
35618 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
35619 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35620 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
35621 masks[irq][4]));
35622 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
35623 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
35624 } else {
35625 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35626 (((cur_irq_sequence =
35627 - atomic_read(&cur_irq->irq_received)) -
35628 + atomic_read_unchecked(&cur_irq->irq_received)) -
35629 *sequence) <= (1 << 23)));
35630 }
35631 *sequence = cur_irq_sequence;
35632 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
35633 }
35634
35635 for (i = 0; i < dev_priv->num_irqs; ++i) {
35636 - atomic_set(&cur_irq->irq_received, 0);
35637 + atomic_set_unchecked(&cur_irq->irq_received, 0);
35638 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
35639 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
35640 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
35641 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
35642 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
35643 case VIA_IRQ_RELATIVE:
35644 irqwait->request.sequence +=
35645 - atomic_read(&cur_irq->irq_received);
35646 + atomic_read_unchecked(&cur_irq->irq_received);
35647 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
35648 case VIA_IRQ_ABSOLUTE:
35649 break;
35650 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35651 index 13aeda7..4a952d1 100644
35652 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35653 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35654 @@ -290,7 +290,7 @@ struct vmw_private {
35655 * Fencing and IRQs.
35656 */
35657
35658 - atomic_t marker_seq;
35659 + atomic_unchecked_t marker_seq;
35660 wait_queue_head_t fence_queue;
35661 wait_queue_head_t fifo_queue;
35662 int fence_queue_waiters; /* Protected by hw_mutex */
35663 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35664 index 3eb1486..0a47ee9 100644
35665 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35666 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35667 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
35668 (unsigned int) min,
35669 (unsigned int) fifo->capabilities);
35670
35671 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35672 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35673 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
35674 vmw_marker_queue_init(&fifo->marker_queue);
35675 return vmw_fifo_send_fence(dev_priv, &dummy);
35676 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
35677 if (reserveable)
35678 iowrite32(bytes, fifo_mem +
35679 SVGA_FIFO_RESERVED);
35680 - return fifo_mem + (next_cmd >> 2);
35681 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
35682 } else {
35683 need_bounce = true;
35684 }
35685 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
35686
35687 fm = vmw_fifo_reserve(dev_priv, bytes);
35688 if (unlikely(fm == NULL)) {
35689 - *seqno = atomic_read(&dev_priv->marker_seq);
35690 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
35691 ret = -ENOMEM;
35692 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
35693 false, 3*HZ);
35694 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
35695 }
35696
35697 do {
35698 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
35699 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
35700 } while (*seqno == 0);
35701
35702 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
35703 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35704 index 4640adb..e1384ed 100644
35705 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35706 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35707 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
35708 * emitted. Then the fence is stale and signaled.
35709 */
35710
35711 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
35712 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
35713 > VMW_FENCE_WRAP);
35714
35715 return ret;
35716 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
35717
35718 if (fifo_idle)
35719 down_read(&fifo_state->rwsem);
35720 - signal_seq = atomic_read(&dev_priv->marker_seq);
35721 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
35722 ret = 0;
35723
35724 for (;;) {
35725 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35726 index 8a8725c..afed796 100644
35727 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35728 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35729 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
35730 while (!vmw_lag_lt(queue, us)) {
35731 spin_lock(&queue->lock);
35732 if (list_empty(&queue->head))
35733 - seqno = atomic_read(&dev_priv->marker_seq);
35734 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
35735 else {
35736 marker = list_first_entry(&queue->head,
35737 struct vmw_marker, head);
35738 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
35739 index ceb3040..6160c5c 100644
35740 --- a/drivers/hid/hid-core.c
35741 +++ b/drivers/hid/hid-core.c
35742 @@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
35743
35744 int hid_add_device(struct hid_device *hdev)
35745 {
35746 - static atomic_t id = ATOMIC_INIT(0);
35747 + static atomic_unchecked_t id = ATOMIC_INIT(0);
35748 int ret;
35749
35750 if (WARN_ON(hdev->status & HID_STAT_ADDED))
35751 @@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
35752 /* XXX hack, any other cleaner solution after the driver core
35753 * is converted to allow more than 20 bytes as the device name? */
35754 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
35755 - hdev->vendor, hdev->product, atomic_inc_return(&id));
35756 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
35757
35758 hid_debug_register(hdev, dev_name(&hdev->dev));
35759 ret = device_add(&hdev->dev);
35760 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
35761 index eec3291..8ed706b 100644
35762 --- a/drivers/hid/hid-wiimote-debug.c
35763 +++ b/drivers/hid/hid-wiimote-debug.c
35764 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
35765 else if (size == 0)
35766 return -EIO;
35767
35768 - if (copy_to_user(u, buf, size))
35769 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
35770 return -EFAULT;
35771
35772 *off += size;
35773 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
35774 index 773a2f2..7ce08bc 100644
35775 --- a/drivers/hv/channel.c
35776 +++ b/drivers/hv/channel.c
35777 @@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
35778 int ret = 0;
35779 int t;
35780
35781 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
35782 - atomic_inc(&vmbus_connection.next_gpadl_handle);
35783 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
35784 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
35785
35786 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
35787 if (ret)
35788 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
35789 index 3648f8f..30ef30d 100644
35790 --- a/drivers/hv/hv.c
35791 +++ b/drivers/hv/hv.c
35792 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
35793 u64 output_address = (output) ? virt_to_phys(output) : 0;
35794 u32 output_address_hi = output_address >> 32;
35795 u32 output_address_lo = output_address & 0xFFFFFFFF;
35796 - void *hypercall_page = hv_context.hypercall_page;
35797 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
35798
35799 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
35800 "=a"(hv_status_lo) : "d" (control_hi),
35801 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
35802 index d8d1fad..b91caf7 100644
35803 --- a/drivers/hv/hyperv_vmbus.h
35804 +++ b/drivers/hv/hyperv_vmbus.h
35805 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
35806 struct vmbus_connection {
35807 enum vmbus_connect_state conn_state;
35808
35809 - atomic_t next_gpadl_handle;
35810 + atomic_unchecked_t next_gpadl_handle;
35811
35812 /*
35813 * Represents channel interrupts. Each bit position represents a
35814 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
35815 index 8e1a9ec..4687821 100644
35816 --- a/drivers/hv/vmbus_drv.c
35817 +++ b/drivers/hv/vmbus_drv.c
35818 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
35819 {
35820 int ret = 0;
35821
35822 - static atomic_t device_num = ATOMIC_INIT(0);
35823 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
35824
35825 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
35826 - atomic_inc_return(&device_num));
35827 + atomic_inc_return_unchecked(&device_num));
35828
35829 child_device_obj->device.bus = &hv_bus;
35830 child_device_obj->device.parent = &hv_acpi_dev->dev;
35831 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
35832 index 1672e2a..4a6297c 100644
35833 --- a/drivers/hwmon/acpi_power_meter.c
35834 +++ b/drivers/hwmon/acpi_power_meter.c
35835 @@ -117,7 +117,7 @@ struct sensor_template {
35836 struct device_attribute *devattr,
35837 const char *buf, size_t count);
35838 int index;
35839 -};
35840 +} __do_const;
35841
35842 /* Averaging interval */
35843 static int update_avg_interval(struct acpi_power_meter_resource *resource)
35844 @@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
35845 struct sensor_template *attrs)
35846 {
35847 struct device *dev = &resource->acpi_dev->dev;
35848 - struct sensor_device_attribute *sensors =
35849 + sensor_device_attribute_no_const *sensors =
35850 &resource->sensors[resource->num_sensors];
35851 int res = 0;
35852
35853 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
35854 index b41baff..4953e4d 100644
35855 --- a/drivers/hwmon/applesmc.c
35856 +++ b/drivers/hwmon/applesmc.c
35857 @@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
35858 {
35859 struct applesmc_node_group *grp;
35860 struct applesmc_dev_attr *node;
35861 - struct attribute *attr;
35862 + attribute_no_const *attr;
35863 int ret, i;
35864
35865 for (grp = groups; grp->format; grp++) {
35866 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
35867 index 56dbcfb..9874bf1 100644
35868 --- a/drivers/hwmon/asus_atk0110.c
35869 +++ b/drivers/hwmon/asus_atk0110.c
35870 @@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
35871 struct atk_sensor_data {
35872 struct list_head list;
35873 struct atk_data *data;
35874 - struct device_attribute label_attr;
35875 - struct device_attribute input_attr;
35876 - struct device_attribute limit1_attr;
35877 - struct device_attribute limit2_attr;
35878 + device_attribute_no_const label_attr;
35879 + device_attribute_no_const input_attr;
35880 + device_attribute_no_const limit1_attr;
35881 + device_attribute_no_const limit2_attr;
35882 char label_attr_name[ATTR_NAME_SIZE];
35883 char input_attr_name[ATTR_NAME_SIZE];
35884 char limit1_attr_name[ATTR_NAME_SIZE];
35885 @@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
35886 static struct device_attribute atk_name_attr =
35887 __ATTR(name, 0444, atk_name_show, NULL);
35888
35889 -static void atk_init_attribute(struct device_attribute *attr, char *name,
35890 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
35891 sysfs_show_func show)
35892 {
35893 sysfs_attr_init(&attr->attr);
35894 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
35895 index d64923d..72591e8 100644
35896 --- a/drivers/hwmon/coretemp.c
35897 +++ b/drivers/hwmon/coretemp.c
35898 @@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
35899 return NOTIFY_OK;
35900 }
35901
35902 -static struct notifier_block coretemp_cpu_notifier __refdata = {
35903 +static struct notifier_block coretemp_cpu_notifier = {
35904 .notifier_call = coretemp_cpu_callback,
35905 };
35906
35907 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
35908 index a14f634..2916ee2 100644
35909 --- a/drivers/hwmon/ibmaem.c
35910 +++ b/drivers/hwmon/ibmaem.c
35911 @@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
35912 struct aem_rw_sensor_template *rw)
35913 {
35914 struct device *dev = &data->pdev->dev;
35915 - struct sensor_device_attribute *sensors = data->sensors;
35916 + sensor_device_attribute_no_const *sensors = data->sensors;
35917 int err;
35918
35919 /* Set up read-only sensors */
35920 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
35921 index 7d19b1b..8fdaaac 100644
35922 --- a/drivers/hwmon/pmbus/pmbus_core.c
35923 +++ b/drivers/hwmon/pmbus/pmbus_core.c
35924 @@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
35925
35926 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
35927 do { \
35928 - struct sensor_device_attribute *a \
35929 + sensor_device_attribute_no_const *a \
35930 = &data->_type##s[data->num_##_type##s].attribute; \
35931 BUG_ON(data->num_attributes >= data->max_attributes); \
35932 sysfs_attr_init(&a->dev_attr.attr); \
35933 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
35934 index 1c85d39..55ed3cf 100644
35935 --- a/drivers/hwmon/sht15.c
35936 +++ b/drivers/hwmon/sht15.c
35937 @@ -169,7 +169,7 @@ struct sht15_data {
35938 int supply_uV;
35939 bool supply_uV_valid;
35940 struct work_struct update_supply_work;
35941 - atomic_t interrupt_handled;
35942 + atomic_unchecked_t interrupt_handled;
35943 };
35944
35945 /**
35946 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
35947 return ret;
35948
35949 gpio_direction_input(data->pdata->gpio_data);
35950 - atomic_set(&data->interrupt_handled, 0);
35951 + atomic_set_unchecked(&data->interrupt_handled, 0);
35952
35953 enable_irq(gpio_to_irq(data->pdata->gpio_data));
35954 if (gpio_get_value(data->pdata->gpio_data) == 0) {
35955 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
35956 /* Only relevant if the interrupt hasn't occurred. */
35957 - if (!atomic_read(&data->interrupt_handled))
35958 + if (!atomic_read_unchecked(&data->interrupt_handled))
35959 schedule_work(&data->read_work);
35960 }
35961 ret = wait_event_timeout(data->wait_queue,
35962 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
35963
35964 /* First disable the interrupt */
35965 disable_irq_nosync(irq);
35966 - atomic_inc(&data->interrupt_handled);
35967 + atomic_inc_unchecked(&data->interrupt_handled);
35968 /* Then schedule a reading work struct */
35969 if (data->state != SHT15_READING_NOTHING)
35970 schedule_work(&data->read_work);
35971 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
35972 * If not, then start the interrupt again - care here as could
35973 * have gone low in meantime so verify it hasn't!
35974 */
35975 - atomic_set(&data->interrupt_handled, 0);
35976 + atomic_set_unchecked(&data->interrupt_handled, 0);
35977 enable_irq(gpio_to_irq(data->pdata->gpio_data));
35978 /* If still not occurred or another handler was scheduled */
35979 if (gpio_get_value(data->pdata->gpio_data)
35980 - || atomic_read(&data->interrupt_handled))
35981 + || atomic_read_unchecked(&data->interrupt_handled))
35982 return;
35983 }
35984
35985 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
35986 index 76f157b..9c0db1b 100644
35987 --- a/drivers/hwmon/via-cputemp.c
35988 +++ b/drivers/hwmon/via-cputemp.c
35989 @@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
35990 return NOTIFY_OK;
35991 }
35992
35993 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
35994 +static struct notifier_block via_cputemp_cpu_notifier = {
35995 .notifier_call = via_cputemp_cpu_callback,
35996 };
35997
35998 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
35999 index 378fcb5..5e91fa8 100644
36000 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
36001 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36002 @@ -43,7 +43,7 @@
36003 extern struct i2c_adapter amd756_smbus;
36004
36005 static struct i2c_adapter *s4882_adapter;
36006 -static struct i2c_algorithm *s4882_algo;
36007 +static i2c_algorithm_no_const *s4882_algo;
36008
36009 /* Wrapper access functions for multiplexed SMBus */
36010 static DEFINE_MUTEX(amd756_lock);
36011 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36012 index 29015eb..af2d8e9 100644
36013 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36014 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36015 @@ -41,7 +41,7 @@
36016 extern struct i2c_adapter *nforce2_smbus;
36017
36018 static struct i2c_adapter *s4985_adapter;
36019 -static struct i2c_algorithm *s4985_algo;
36020 +static i2c_algorithm_no_const *s4985_algo;
36021
36022 /* Wrapper access functions for multiplexed SMBus */
36023 static DEFINE_MUTEX(nforce2_lock);
36024 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36025 index 8126824..55a2798 100644
36026 --- a/drivers/ide/ide-cd.c
36027 +++ b/drivers/ide/ide-cd.c
36028 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36029 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36030 if ((unsigned long)buf & alignment
36031 || blk_rq_bytes(rq) & q->dma_pad_mask
36032 - || object_is_on_stack(buf))
36033 + || object_starts_on_stack(buf))
36034 drive->dma = 0;
36035 }
36036 }
36037 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36038 index 8848f16..f8e6dd8 100644
36039 --- a/drivers/iio/industrialio-core.c
36040 +++ b/drivers/iio/industrialio-core.c
36041 @@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36042 }
36043
36044 static
36045 -int __iio_device_attr_init(struct device_attribute *dev_attr,
36046 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36047 const char *postfix,
36048 struct iio_chan_spec const *chan,
36049 ssize_t (*readfunc)(struct device *dev,
36050 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36051 index 394fea2..c833880 100644
36052 --- a/drivers/infiniband/core/cm.c
36053 +++ b/drivers/infiniband/core/cm.c
36054 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36055
36056 struct cm_counter_group {
36057 struct kobject obj;
36058 - atomic_long_t counter[CM_ATTR_COUNT];
36059 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36060 };
36061
36062 struct cm_counter_attribute {
36063 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36064 struct ib_mad_send_buf *msg = NULL;
36065 int ret;
36066
36067 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36068 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36069 counter[CM_REQ_COUNTER]);
36070
36071 /* Quick state check to discard duplicate REQs. */
36072 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36073 if (!cm_id_priv)
36074 return;
36075
36076 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36077 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36078 counter[CM_REP_COUNTER]);
36079 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36080 if (ret)
36081 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
36082 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36083 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36084 spin_unlock_irq(&cm_id_priv->lock);
36085 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36086 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36087 counter[CM_RTU_COUNTER]);
36088 goto out;
36089 }
36090 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
36091 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36092 dreq_msg->local_comm_id);
36093 if (!cm_id_priv) {
36094 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36095 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36096 counter[CM_DREQ_COUNTER]);
36097 cm_issue_drep(work->port, work->mad_recv_wc);
36098 return -EINVAL;
36099 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
36100 case IB_CM_MRA_REP_RCVD:
36101 break;
36102 case IB_CM_TIMEWAIT:
36103 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36104 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36105 counter[CM_DREQ_COUNTER]);
36106 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36107 goto unlock;
36108 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
36109 cm_free_msg(msg);
36110 goto deref;
36111 case IB_CM_DREQ_RCVD:
36112 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36113 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36114 counter[CM_DREQ_COUNTER]);
36115 goto unlock;
36116 default:
36117 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
36118 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36119 cm_id_priv->msg, timeout)) {
36120 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36121 - atomic_long_inc(&work->port->
36122 + atomic_long_inc_unchecked(&work->port->
36123 counter_group[CM_RECV_DUPLICATES].
36124 counter[CM_MRA_COUNTER]);
36125 goto out;
36126 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
36127 break;
36128 case IB_CM_MRA_REQ_RCVD:
36129 case IB_CM_MRA_REP_RCVD:
36130 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36131 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36132 counter[CM_MRA_COUNTER]);
36133 /* fall through */
36134 default:
36135 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
36136 case IB_CM_LAP_IDLE:
36137 break;
36138 case IB_CM_MRA_LAP_SENT:
36139 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36140 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36141 counter[CM_LAP_COUNTER]);
36142 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36143 goto unlock;
36144 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
36145 cm_free_msg(msg);
36146 goto deref;
36147 case IB_CM_LAP_RCVD:
36148 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36149 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36150 counter[CM_LAP_COUNTER]);
36151 goto unlock;
36152 default:
36153 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36154 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36155 if (cur_cm_id_priv) {
36156 spin_unlock_irq(&cm.lock);
36157 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36158 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36159 counter[CM_SIDR_REQ_COUNTER]);
36160 goto out; /* Duplicate message. */
36161 }
36162 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36163 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36164 msg->retries = 1;
36165
36166 - atomic_long_add(1 + msg->retries,
36167 + atomic_long_add_unchecked(1 + msg->retries,
36168 &port->counter_group[CM_XMIT].counter[attr_index]);
36169 if (msg->retries)
36170 - atomic_long_add(msg->retries,
36171 + atomic_long_add_unchecked(msg->retries,
36172 &port->counter_group[CM_XMIT_RETRIES].
36173 counter[attr_index]);
36174
36175 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36176 }
36177
36178 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36179 - atomic_long_inc(&port->counter_group[CM_RECV].
36180 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36181 counter[attr_id - CM_ATTR_ID_OFFSET]);
36182
36183 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36184 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36185 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36186
36187 return sprintf(buf, "%ld\n",
36188 - atomic_long_read(&group->counter[cm_attr->index]));
36189 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36190 }
36191
36192 static const struct sysfs_ops cm_counter_ops = {
36193 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36194 index 176c8f9..2627b62 100644
36195 --- a/drivers/infiniband/core/fmr_pool.c
36196 +++ b/drivers/infiniband/core/fmr_pool.c
36197 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
36198
36199 struct task_struct *thread;
36200
36201 - atomic_t req_ser;
36202 - atomic_t flush_ser;
36203 + atomic_unchecked_t req_ser;
36204 + atomic_unchecked_t flush_ser;
36205
36206 wait_queue_head_t force_wait;
36207 };
36208 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36209 struct ib_fmr_pool *pool = pool_ptr;
36210
36211 do {
36212 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
36213 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
36214 ib_fmr_batch_release(pool);
36215
36216 - atomic_inc(&pool->flush_ser);
36217 + atomic_inc_unchecked(&pool->flush_ser);
36218 wake_up_interruptible(&pool->force_wait);
36219
36220 if (pool->flush_function)
36221 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36222 }
36223
36224 set_current_state(TASK_INTERRUPTIBLE);
36225 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
36226 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
36227 !kthread_should_stop())
36228 schedule();
36229 __set_current_state(TASK_RUNNING);
36230 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
36231 pool->dirty_watermark = params->dirty_watermark;
36232 pool->dirty_len = 0;
36233 spin_lock_init(&pool->pool_lock);
36234 - atomic_set(&pool->req_ser, 0);
36235 - atomic_set(&pool->flush_ser, 0);
36236 + atomic_set_unchecked(&pool->req_ser, 0);
36237 + atomic_set_unchecked(&pool->flush_ser, 0);
36238 init_waitqueue_head(&pool->force_wait);
36239
36240 pool->thread = kthread_run(ib_fmr_cleanup_thread,
36241 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
36242 }
36243 spin_unlock_irq(&pool->pool_lock);
36244
36245 - serial = atomic_inc_return(&pool->req_ser);
36246 + serial = atomic_inc_return_unchecked(&pool->req_ser);
36247 wake_up_process(pool->thread);
36248
36249 if (wait_event_interruptible(pool->force_wait,
36250 - atomic_read(&pool->flush_ser) - serial >= 0))
36251 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
36252 return -EINTR;
36253
36254 return 0;
36255 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
36256 } else {
36257 list_add_tail(&fmr->list, &pool->dirty_list);
36258 if (++pool->dirty_len >= pool->dirty_watermark) {
36259 - atomic_inc(&pool->req_ser);
36260 + atomic_inc_unchecked(&pool->req_ser);
36261 wake_up_process(pool->thread);
36262 }
36263 }
36264 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
36265 index afd8179..598063f 100644
36266 --- a/drivers/infiniband/hw/cxgb4/mem.c
36267 +++ b/drivers/infiniband/hw/cxgb4/mem.c
36268 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36269 int err;
36270 struct fw_ri_tpte tpt;
36271 u32 stag_idx;
36272 - static atomic_t key;
36273 + static atomic_unchecked_t key;
36274
36275 if (c4iw_fatal_error(rdev))
36276 return -EIO;
36277 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36278 if (rdev->stats.stag.cur > rdev->stats.stag.max)
36279 rdev->stats.stag.max = rdev->stats.stag.cur;
36280 mutex_unlock(&rdev->stats.lock);
36281 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
36282 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
36283 }
36284 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
36285 __func__, stag_state, type, pdid, stag_idx);
36286 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
36287 index 79b3dbc..96e5fcc 100644
36288 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
36289 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
36290 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36291 struct ib_atomic_eth *ateth;
36292 struct ipath_ack_entry *e;
36293 u64 vaddr;
36294 - atomic64_t *maddr;
36295 + atomic64_unchecked_t *maddr;
36296 u64 sdata;
36297 u32 rkey;
36298 u8 next;
36299 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36300 IB_ACCESS_REMOTE_ATOMIC)))
36301 goto nack_acc_unlck;
36302 /* Perform atomic OP and save result. */
36303 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36304 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36305 sdata = be64_to_cpu(ateth->swap_data);
36306 e = &qp->s_ack_queue[qp->r_head_ack_queue];
36307 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
36308 - (u64) atomic64_add_return(sdata, maddr) - sdata :
36309 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36310 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36311 be64_to_cpu(ateth->compare_data),
36312 sdata);
36313 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
36314 index 1f95bba..9530f87 100644
36315 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
36316 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
36317 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
36318 unsigned long flags;
36319 struct ib_wc wc;
36320 u64 sdata;
36321 - atomic64_t *maddr;
36322 + atomic64_unchecked_t *maddr;
36323 enum ib_wc_status send_status;
36324
36325 /*
36326 @@ -382,11 +382,11 @@ again:
36327 IB_ACCESS_REMOTE_ATOMIC)))
36328 goto acc_err;
36329 /* Perform atomic OP and save result. */
36330 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36331 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36332 sdata = wqe->wr.wr.atomic.compare_add;
36333 *(u64 *) sqp->s_sge.sge.vaddr =
36334 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
36335 - (u64) atomic64_add_return(sdata, maddr) - sdata :
36336 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36337 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36338 sdata, wqe->wr.wr.atomic.swap);
36339 goto send_comp;
36340 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
36341 index 5b152a3..c1f3e83 100644
36342 --- a/drivers/infiniband/hw/nes/nes.c
36343 +++ b/drivers/infiniband/hw/nes/nes.c
36344 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
36345 LIST_HEAD(nes_adapter_list);
36346 static LIST_HEAD(nes_dev_list);
36347
36348 -atomic_t qps_destroyed;
36349 +atomic_unchecked_t qps_destroyed;
36350
36351 static unsigned int ee_flsh_adapter;
36352 static unsigned int sysfs_nonidx_addr;
36353 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
36354 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
36355 struct nes_adapter *nesadapter = nesdev->nesadapter;
36356
36357 - atomic_inc(&qps_destroyed);
36358 + atomic_inc_unchecked(&qps_destroyed);
36359
36360 /* Free the control structures */
36361
36362 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
36363 index 33cc589..3bd6538 100644
36364 --- a/drivers/infiniband/hw/nes/nes.h
36365 +++ b/drivers/infiniband/hw/nes/nes.h
36366 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
36367 extern unsigned int wqm_quanta;
36368 extern struct list_head nes_adapter_list;
36369
36370 -extern atomic_t cm_connects;
36371 -extern atomic_t cm_accepts;
36372 -extern atomic_t cm_disconnects;
36373 -extern atomic_t cm_closes;
36374 -extern atomic_t cm_connecteds;
36375 -extern atomic_t cm_connect_reqs;
36376 -extern atomic_t cm_rejects;
36377 -extern atomic_t mod_qp_timouts;
36378 -extern atomic_t qps_created;
36379 -extern atomic_t qps_destroyed;
36380 -extern atomic_t sw_qps_destroyed;
36381 +extern atomic_unchecked_t cm_connects;
36382 +extern atomic_unchecked_t cm_accepts;
36383 +extern atomic_unchecked_t cm_disconnects;
36384 +extern atomic_unchecked_t cm_closes;
36385 +extern atomic_unchecked_t cm_connecteds;
36386 +extern atomic_unchecked_t cm_connect_reqs;
36387 +extern atomic_unchecked_t cm_rejects;
36388 +extern atomic_unchecked_t mod_qp_timouts;
36389 +extern atomic_unchecked_t qps_created;
36390 +extern atomic_unchecked_t qps_destroyed;
36391 +extern atomic_unchecked_t sw_qps_destroyed;
36392 extern u32 mh_detected;
36393 extern u32 mh_pauses_sent;
36394 extern u32 cm_packets_sent;
36395 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
36396 extern u32 cm_packets_received;
36397 extern u32 cm_packets_dropped;
36398 extern u32 cm_packets_retrans;
36399 -extern atomic_t cm_listens_created;
36400 -extern atomic_t cm_listens_destroyed;
36401 +extern atomic_unchecked_t cm_listens_created;
36402 +extern atomic_unchecked_t cm_listens_destroyed;
36403 extern u32 cm_backlog_drops;
36404 -extern atomic_t cm_loopbacks;
36405 -extern atomic_t cm_nodes_created;
36406 -extern atomic_t cm_nodes_destroyed;
36407 -extern atomic_t cm_accel_dropped_pkts;
36408 -extern atomic_t cm_resets_recvd;
36409 -extern atomic_t pau_qps_created;
36410 -extern atomic_t pau_qps_destroyed;
36411 +extern atomic_unchecked_t cm_loopbacks;
36412 +extern atomic_unchecked_t cm_nodes_created;
36413 +extern atomic_unchecked_t cm_nodes_destroyed;
36414 +extern atomic_unchecked_t cm_accel_dropped_pkts;
36415 +extern atomic_unchecked_t cm_resets_recvd;
36416 +extern atomic_unchecked_t pau_qps_created;
36417 +extern atomic_unchecked_t pau_qps_destroyed;
36418
36419 extern u32 int_mod_timer_init;
36420 extern u32 int_mod_cq_depth_256;
36421 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
36422 index 22ea67e..dcbe3bc 100644
36423 --- a/drivers/infiniband/hw/nes/nes_cm.c
36424 +++ b/drivers/infiniband/hw/nes/nes_cm.c
36425 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
36426 u32 cm_packets_retrans;
36427 u32 cm_packets_created;
36428 u32 cm_packets_received;
36429 -atomic_t cm_listens_created;
36430 -atomic_t cm_listens_destroyed;
36431 +atomic_unchecked_t cm_listens_created;
36432 +atomic_unchecked_t cm_listens_destroyed;
36433 u32 cm_backlog_drops;
36434 -atomic_t cm_loopbacks;
36435 -atomic_t cm_nodes_created;
36436 -atomic_t cm_nodes_destroyed;
36437 -atomic_t cm_accel_dropped_pkts;
36438 -atomic_t cm_resets_recvd;
36439 +atomic_unchecked_t cm_loopbacks;
36440 +atomic_unchecked_t cm_nodes_created;
36441 +atomic_unchecked_t cm_nodes_destroyed;
36442 +atomic_unchecked_t cm_accel_dropped_pkts;
36443 +atomic_unchecked_t cm_resets_recvd;
36444
36445 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
36446 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
36447 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
36448
36449 static struct nes_cm_core *g_cm_core;
36450
36451 -atomic_t cm_connects;
36452 -atomic_t cm_accepts;
36453 -atomic_t cm_disconnects;
36454 -atomic_t cm_closes;
36455 -atomic_t cm_connecteds;
36456 -atomic_t cm_connect_reqs;
36457 -atomic_t cm_rejects;
36458 +atomic_unchecked_t cm_connects;
36459 +atomic_unchecked_t cm_accepts;
36460 +atomic_unchecked_t cm_disconnects;
36461 +atomic_unchecked_t cm_closes;
36462 +atomic_unchecked_t cm_connecteds;
36463 +atomic_unchecked_t cm_connect_reqs;
36464 +atomic_unchecked_t cm_rejects;
36465
36466 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
36467 {
36468 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
36469 kfree(listener);
36470 listener = NULL;
36471 ret = 0;
36472 - atomic_inc(&cm_listens_destroyed);
36473 + atomic_inc_unchecked(&cm_listens_destroyed);
36474 } else {
36475 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
36476 }
36477 @@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
36478 cm_node->rem_mac);
36479
36480 add_hte_node(cm_core, cm_node);
36481 - atomic_inc(&cm_nodes_created);
36482 + atomic_inc_unchecked(&cm_nodes_created);
36483
36484 return cm_node;
36485 }
36486 @@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
36487 }
36488
36489 atomic_dec(&cm_core->node_cnt);
36490 - atomic_inc(&cm_nodes_destroyed);
36491 + atomic_inc_unchecked(&cm_nodes_destroyed);
36492 nesqp = cm_node->nesqp;
36493 if (nesqp) {
36494 nesqp->cm_node = NULL;
36495 @@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
36496
36497 static void drop_packet(struct sk_buff *skb)
36498 {
36499 - atomic_inc(&cm_accel_dropped_pkts);
36500 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
36501 dev_kfree_skb_any(skb);
36502 }
36503
36504 @@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
36505 {
36506
36507 int reset = 0; /* whether to send reset in case of err.. */
36508 - atomic_inc(&cm_resets_recvd);
36509 + atomic_inc_unchecked(&cm_resets_recvd);
36510 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
36511 " refcnt=%d\n", cm_node, cm_node->state,
36512 atomic_read(&cm_node->ref_count));
36513 @@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
36514 rem_ref_cm_node(cm_node->cm_core, cm_node);
36515 return NULL;
36516 }
36517 - atomic_inc(&cm_loopbacks);
36518 + atomic_inc_unchecked(&cm_loopbacks);
36519 loopbackremotenode->loopbackpartner = cm_node;
36520 loopbackremotenode->tcp_cntxt.rcv_wscale =
36521 NES_CM_DEFAULT_RCV_WND_SCALE;
36522 @@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
36523 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
36524 else {
36525 rem_ref_cm_node(cm_core, cm_node);
36526 - atomic_inc(&cm_accel_dropped_pkts);
36527 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
36528 dev_kfree_skb_any(skb);
36529 }
36530 break;
36531 @@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36532
36533 if ((cm_id) && (cm_id->event_handler)) {
36534 if (issue_disconn) {
36535 - atomic_inc(&cm_disconnects);
36536 + atomic_inc_unchecked(&cm_disconnects);
36537 cm_event.event = IW_CM_EVENT_DISCONNECT;
36538 cm_event.status = disconn_status;
36539 cm_event.local_addr = cm_id->local_addr;
36540 @@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36541 }
36542
36543 if (issue_close) {
36544 - atomic_inc(&cm_closes);
36545 + atomic_inc_unchecked(&cm_closes);
36546 nes_disconnect(nesqp, 1);
36547
36548 cm_id->provider_data = nesqp;
36549 @@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36550
36551 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
36552 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
36553 - atomic_inc(&cm_accepts);
36554 + atomic_inc_unchecked(&cm_accepts);
36555
36556 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
36557 netdev_refcnt_read(nesvnic->netdev));
36558 @@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
36559 struct nes_cm_core *cm_core;
36560 u8 *start_buff;
36561
36562 - atomic_inc(&cm_rejects);
36563 + atomic_inc_unchecked(&cm_rejects);
36564 cm_node = (struct nes_cm_node *)cm_id->provider_data;
36565 loopback = cm_node->loopbackpartner;
36566 cm_core = cm_node->cm_core;
36567 @@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36568 ntohl(cm_id->local_addr.sin_addr.s_addr),
36569 ntohs(cm_id->local_addr.sin_port));
36570
36571 - atomic_inc(&cm_connects);
36572 + atomic_inc_unchecked(&cm_connects);
36573 nesqp->active_conn = 1;
36574
36575 /* cache the cm_id in the qp */
36576 @@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
36577 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
36578 return err;
36579 }
36580 - atomic_inc(&cm_listens_created);
36581 + atomic_inc_unchecked(&cm_listens_created);
36582 }
36583
36584 cm_id->add_ref(cm_id);
36585 @@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
36586
36587 if (nesqp->destroyed)
36588 return;
36589 - atomic_inc(&cm_connecteds);
36590 + atomic_inc_unchecked(&cm_connecteds);
36591 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
36592 " local port 0x%04X. jiffies = %lu.\n",
36593 nesqp->hwqp.qp_id,
36594 @@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
36595
36596 cm_id->add_ref(cm_id);
36597 ret = cm_id->event_handler(cm_id, &cm_event);
36598 - atomic_inc(&cm_closes);
36599 + atomic_inc_unchecked(&cm_closes);
36600 cm_event.event = IW_CM_EVENT_CLOSE;
36601 cm_event.status = 0;
36602 cm_event.provider_data = cm_id->provider_data;
36603 @@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
36604 return;
36605 cm_id = cm_node->cm_id;
36606
36607 - atomic_inc(&cm_connect_reqs);
36608 + atomic_inc_unchecked(&cm_connect_reqs);
36609 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36610 cm_node, cm_id, jiffies);
36611
36612 @@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
36613 return;
36614 cm_id = cm_node->cm_id;
36615
36616 - atomic_inc(&cm_connect_reqs);
36617 + atomic_inc_unchecked(&cm_connect_reqs);
36618 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36619 cm_node, cm_id, jiffies);
36620
36621 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
36622 index 4166452..fc952c3 100644
36623 --- a/drivers/infiniband/hw/nes/nes_mgt.c
36624 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
36625 @@ -40,8 +40,8 @@
36626 #include "nes.h"
36627 #include "nes_mgt.h"
36628
36629 -atomic_t pau_qps_created;
36630 -atomic_t pau_qps_destroyed;
36631 +atomic_unchecked_t pau_qps_created;
36632 +atomic_unchecked_t pau_qps_destroyed;
36633
36634 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
36635 {
36636 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
36637 {
36638 struct sk_buff *skb;
36639 unsigned long flags;
36640 - atomic_inc(&pau_qps_destroyed);
36641 + atomic_inc_unchecked(&pau_qps_destroyed);
36642
36643 /* Free packets that have not yet been forwarded */
36644 /* Lock is acquired by skb_dequeue when removing the skb */
36645 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
36646 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
36647 skb_queue_head_init(&nesqp->pau_list);
36648 spin_lock_init(&nesqp->pau_lock);
36649 - atomic_inc(&pau_qps_created);
36650 + atomic_inc_unchecked(&pau_qps_created);
36651 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
36652 }
36653
36654 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
36655 index 9542e16..a008c40 100644
36656 --- a/drivers/infiniband/hw/nes/nes_nic.c
36657 +++ b/drivers/infiniband/hw/nes/nes_nic.c
36658 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
36659 target_stat_values[++index] = mh_detected;
36660 target_stat_values[++index] = mh_pauses_sent;
36661 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
36662 - target_stat_values[++index] = atomic_read(&cm_connects);
36663 - target_stat_values[++index] = atomic_read(&cm_accepts);
36664 - target_stat_values[++index] = atomic_read(&cm_disconnects);
36665 - target_stat_values[++index] = atomic_read(&cm_connecteds);
36666 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
36667 - target_stat_values[++index] = atomic_read(&cm_rejects);
36668 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
36669 - target_stat_values[++index] = atomic_read(&qps_created);
36670 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
36671 - target_stat_values[++index] = atomic_read(&qps_destroyed);
36672 - target_stat_values[++index] = atomic_read(&cm_closes);
36673 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
36674 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
36675 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
36676 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
36677 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
36678 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
36679 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
36680 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
36681 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
36682 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
36683 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
36684 target_stat_values[++index] = cm_packets_sent;
36685 target_stat_values[++index] = cm_packets_bounced;
36686 target_stat_values[++index] = cm_packets_created;
36687 target_stat_values[++index] = cm_packets_received;
36688 target_stat_values[++index] = cm_packets_dropped;
36689 target_stat_values[++index] = cm_packets_retrans;
36690 - target_stat_values[++index] = atomic_read(&cm_listens_created);
36691 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
36692 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
36693 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
36694 target_stat_values[++index] = cm_backlog_drops;
36695 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
36696 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
36697 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
36698 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
36699 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
36700 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
36701 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
36702 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
36703 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
36704 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
36705 target_stat_values[++index] = nesadapter->free_4kpbl;
36706 target_stat_values[++index] = nesadapter->free_256pbl;
36707 target_stat_values[++index] = int_mod_timer_init;
36708 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
36709 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
36710 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
36711 - target_stat_values[++index] = atomic_read(&pau_qps_created);
36712 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
36713 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
36714 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
36715 }
36716
36717 /**
36718 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
36719 index 07e4fba..685f041 100644
36720 --- a/drivers/infiniband/hw/nes/nes_verbs.c
36721 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
36722 @@ -46,9 +46,9 @@
36723
36724 #include <rdma/ib_umem.h>
36725
36726 -atomic_t mod_qp_timouts;
36727 -atomic_t qps_created;
36728 -atomic_t sw_qps_destroyed;
36729 +atomic_unchecked_t mod_qp_timouts;
36730 +atomic_unchecked_t qps_created;
36731 +atomic_unchecked_t sw_qps_destroyed;
36732
36733 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
36734
36735 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
36736 if (init_attr->create_flags)
36737 return ERR_PTR(-EINVAL);
36738
36739 - atomic_inc(&qps_created);
36740 + atomic_inc_unchecked(&qps_created);
36741 switch (init_attr->qp_type) {
36742 case IB_QPT_RC:
36743 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
36744 @@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
36745 struct iw_cm_event cm_event;
36746 int ret = 0;
36747
36748 - atomic_inc(&sw_qps_destroyed);
36749 + atomic_inc_unchecked(&sw_qps_destroyed);
36750 nesqp->destroyed = 1;
36751
36752 /* Blow away the connection if it exists. */
36753 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
36754 index 4d11575..3e890e5 100644
36755 --- a/drivers/infiniband/hw/qib/qib.h
36756 +++ b/drivers/infiniband/hw/qib/qib.h
36757 @@ -51,6 +51,7 @@
36758 #include <linux/completion.h>
36759 #include <linux/kref.h>
36760 #include <linux/sched.h>
36761 +#include <linux/slab.h>
36762
36763 #include "qib_common.h"
36764 #include "qib_verbs.h"
36765 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
36766 index da739d9..da1c7f4 100644
36767 --- a/drivers/input/gameport/gameport.c
36768 +++ b/drivers/input/gameport/gameport.c
36769 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
36770 */
36771 static void gameport_init_port(struct gameport *gameport)
36772 {
36773 - static atomic_t gameport_no = ATOMIC_INIT(0);
36774 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
36775
36776 __module_get(THIS_MODULE);
36777
36778 mutex_init(&gameport->drv_mutex);
36779 device_initialize(&gameport->dev);
36780 dev_set_name(&gameport->dev, "gameport%lu",
36781 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
36782 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
36783 gameport->dev.bus = &gameport_bus;
36784 gameport->dev.release = gameport_release_port;
36785 if (gameport->parent)
36786 diff --git a/drivers/input/input.c b/drivers/input/input.c
36787 index c044699..174d71a 100644
36788 --- a/drivers/input/input.c
36789 +++ b/drivers/input/input.c
36790 @@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
36791 */
36792 int input_register_device(struct input_dev *dev)
36793 {
36794 - static atomic_t input_no = ATOMIC_INIT(0);
36795 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
36796 struct input_devres *devres = NULL;
36797 struct input_handler *handler;
36798 unsigned int packet_size;
36799 @@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
36800 dev->setkeycode = input_default_setkeycode;
36801
36802 dev_set_name(&dev->dev, "input%ld",
36803 - (unsigned long) atomic_inc_return(&input_no) - 1);
36804 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
36805
36806 error = device_add(&dev->dev);
36807 if (error)
36808 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
36809 index 04c69af..5f92d00 100644
36810 --- a/drivers/input/joystick/sidewinder.c
36811 +++ b/drivers/input/joystick/sidewinder.c
36812 @@ -30,6 +30,7 @@
36813 #include <linux/kernel.h>
36814 #include <linux/module.h>
36815 #include <linux/slab.h>
36816 +#include <linux/sched.h>
36817 #include <linux/init.h>
36818 #include <linux/input.h>
36819 #include <linux/gameport.h>
36820 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
36821 index d6cbfe9..6225402 100644
36822 --- a/drivers/input/joystick/xpad.c
36823 +++ b/drivers/input/joystick/xpad.c
36824 @@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
36825
36826 static int xpad_led_probe(struct usb_xpad *xpad)
36827 {
36828 - static atomic_t led_seq = ATOMIC_INIT(0);
36829 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
36830 long led_no;
36831 struct xpad_led *led;
36832 struct led_classdev *led_cdev;
36833 @@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
36834 if (!led)
36835 return -ENOMEM;
36836
36837 - led_no = (long)atomic_inc_return(&led_seq) - 1;
36838 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
36839
36840 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
36841 led->xpad = xpad;
36842 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
36843 index fe1df23..5b710f3 100644
36844 --- a/drivers/input/mouse/psmouse.h
36845 +++ b/drivers/input/mouse/psmouse.h
36846 @@ -115,7 +115,7 @@ struct psmouse_attribute {
36847 ssize_t (*set)(struct psmouse *psmouse, void *data,
36848 const char *buf, size_t count);
36849 bool protect;
36850 -};
36851 +} __do_const;
36852 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
36853
36854 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
36855 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
36856 index 4c842c3..590b0bf 100644
36857 --- a/drivers/input/mousedev.c
36858 +++ b/drivers/input/mousedev.c
36859 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
36860
36861 spin_unlock_irq(&client->packet_lock);
36862
36863 - if (copy_to_user(buffer, data, count))
36864 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
36865 return -EFAULT;
36866
36867 return count;
36868 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
36869 index 25fc597..558bf3b 100644
36870 --- a/drivers/input/serio/serio.c
36871 +++ b/drivers/input/serio/serio.c
36872 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
36873 */
36874 static void serio_init_port(struct serio *serio)
36875 {
36876 - static atomic_t serio_no = ATOMIC_INIT(0);
36877 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
36878
36879 __module_get(THIS_MODULE);
36880
36881 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
36882 mutex_init(&serio->drv_mutex);
36883 device_initialize(&serio->dev);
36884 dev_set_name(&serio->dev, "serio%ld",
36885 - (long)atomic_inc_return(&serio_no) - 1);
36886 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
36887 serio->dev.bus = &serio_bus;
36888 serio->dev.release = serio_release_port;
36889 serio->dev.groups = serio_device_attr_groups;
36890 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
36891 index ddbdaca..be18a78 100644
36892 --- a/drivers/iommu/iommu.c
36893 +++ b/drivers/iommu/iommu.c
36894 @@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
36895 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
36896 {
36897 bus_register_notifier(bus, &iommu_bus_nb);
36898 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
36899 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
36900 }
36901
36902 /**
36903 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
36904 index 89562a8..218999b 100644
36905 --- a/drivers/isdn/capi/capi.c
36906 +++ b/drivers/isdn/capi/capi.c
36907 @@ -81,8 +81,8 @@ struct capiminor {
36908
36909 struct capi20_appl *ap;
36910 u32 ncci;
36911 - atomic_t datahandle;
36912 - atomic_t msgid;
36913 + atomic_unchecked_t datahandle;
36914 + atomic_unchecked_t msgid;
36915
36916 struct tty_port port;
36917 int ttyinstop;
36918 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
36919 capimsg_setu16(s, 2, mp->ap->applid);
36920 capimsg_setu8 (s, 4, CAPI_DATA_B3);
36921 capimsg_setu8 (s, 5, CAPI_RESP);
36922 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
36923 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
36924 capimsg_setu32(s, 8, mp->ncci);
36925 capimsg_setu16(s, 12, datahandle);
36926 }
36927 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
36928 mp->outbytes -= len;
36929 spin_unlock_bh(&mp->outlock);
36930
36931 - datahandle = atomic_inc_return(&mp->datahandle);
36932 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
36933 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
36934 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
36935 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
36936 capimsg_setu16(skb->data, 2, mp->ap->applid);
36937 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
36938 capimsg_setu8 (skb->data, 5, CAPI_REQ);
36939 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
36940 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
36941 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
36942 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
36943 capimsg_setu16(skb->data, 16, len); /* Data length */
36944 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
36945 index 67abf3f..076b3a6 100644
36946 --- a/drivers/isdn/gigaset/interface.c
36947 +++ b/drivers/isdn/gigaset/interface.c
36948 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
36949 }
36950 tty->driver_data = cs;
36951
36952 - ++cs->port.count;
36953 + atomic_inc(&cs->port.count);
36954
36955 - if (cs->port.count == 1) {
36956 + if (atomic_read(&cs->port.count) == 1) {
36957 tty_port_tty_set(&cs->port, tty);
36958 tty->low_latency = 1;
36959 }
36960 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
36961
36962 if (!cs->connected)
36963 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
36964 - else if (!cs->port.count)
36965 + else if (!atomic_read(&cs->port.count))
36966 dev_warn(cs->dev, "%s: device not opened\n", __func__);
36967 - else if (!--cs->port.count)
36968 + else if (!atomic_dec_return(&cs->port.count))
36969 tty_port_tty_set(&cs->port, NULL);
36970
36971 mutex_unlock(&cs->mutex);
36972 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
36973 index 821f7ac..28d4030 100644
36974 --- a/drivers/isdn/hardware/avm/b1.c
36975 +++ b/drivers/isdn/hardware/avm/b1.c
36976 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
36977 }
36978 if (left) {
36979 if (t4file->user) {
36980 - if (copy_from_user(buf, dp, left))
36981 + if (left > sizeof buf || copy_from_user(buf, dp, left))
36982 return -EFAULT;
36983 } else {
36984 memcpy(buf, dp, left);
36985 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
36986 }
36987 if (left) {
36988 if (config->user) {
36989 - if (copy_from_user(buf, dp, left))
36990 + if (left > sizeof buf || copy_from_user(buf, dp, left))
36991 return -EFAULT;
36992 } else {
36993 memcpy(buf, dp, left);
36994 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
36995 index e09dc8a..15e2efb 100644
36996 --- a/drivers/isdn/i4l/isdn_tty.c
36997 +++ b/drivers/isdn/i4l/isdn_tty.c
36998 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
36999
37000 #ifdef ISDN_DEBUG_MODEM_OPEN
37001 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37002 - port->count);
37003 + atomic_read(&port->count));
37004 #endif
37005 - port->count++;
37006 + atomic_inc(&port->count);
37007 port->tty = tty;
37008 /*
37009 * Start up serial port
37010 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37011 #endif
37012 return;
37013 }
37014 - if ((tty->count == 1) && (port->count != 1)) {
37015 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37016 /*
37017 * Uh, oh. tty->count is 1, which means that the tty
37018 * structure will be freed. Info->count should always
37019 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37020 * serial port won't be shutdown.
37021 */
37022 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37023 - "info->count is %d\n", port->count);
37024 - port->count = 1;
37025 + "info->count is %d\n", atomic_read(&port->count));
37026 + atomic_set(&port->count, 1);
37027 }
37028 - if (--port->count < 0) {
37029 + if (atomic_dec_return(&port->count) < 0) {
37030 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37031 - info->line, port->count);
37032 - port->count = 0;
37033 + info->line, atomic_read(&port->count));
37034 + atomic_set(&port->count, 0);
37035 }
37036 - if (port->count) {
37037 + if (atomic_read(&port->count)) {
37038 #ifdef ISDN_DEBUG_MODEM_OPEN
37039 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37040 #endif
37041 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37042 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37043 return;
37044 isdn_tty_shutdown(info);
37045 - port->count = 0;
37046 + atomic_set(&port->count, 0);
37047 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37048 port->tty = NULL;
37049 wake_up_interruptible(&port->open_wait);
37050 @@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37051 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37052 modem_info *info = &dev->mdm.info[i];
37053
37054 - if (info->port.count == 0)
37055 + if (atomic_read(&info->port.count) == 0)
37056 continue;
37057 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37058 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37059 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37060 index e74df7c..03a03ba 100644
37061 --- a/drivers/isdn/icn/icn.c
37062 +++ b/drivers/isdn/icn/icn.c
37063 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37064 if (count > len)
37065 count = len;
37066 if (user) {
37067 - if (copy_from_user(msg, buf, count))
37068 + if (count > sizeof msg || copy_from_user(msg, buf, count))
37069 return -EFAULT;
37070 } else
37071 memcpy(msg, buf, count);
37072 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37073 index 6a8405d..0bd1c7e 100644
37074 --- a/drivers/leds/leds-clevo-mail.c
37075 +++ b/drivers/leds/leds-clevo-mail.c
37076 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
37077 * detected as working, but in reality it is not) as low as
37078 * possible.
37079 */
37080 -static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
37081 +static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
37082 {
37083 .callback = clevo_mail_led_dmi_callback,
37084 .ident = "Clevo D410J",
37085 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
37086 index ec9b287..65c9bf4 100644
37087 --- a/drivers/leds/leds-ss4200.c
37088 +++ b/drivers/leds/leds-ss4200.c
37089 @@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
37090 * detected as working, but in reality it is not) as low as
37091 * possible.
37092 */
37093 -static struct dmi_system_id __initdata nas_led_whitelist[] = {
37094 +static const struct dmi_system_id __initconst nas_led_whitelist[] = {
37095 {
37096 .callback = ss4200_led_dmi_callback,
37097 .ident = "Intel SS4200-E",
37098 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
37099 index a5ebc00..982886f 100644
37100 --- a/drivers/lguest/core.c
37101 +++ b/drivers/lguest/core.c
37102 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
37103 * it's worked so far. The end address needs +1 because __get_vm_area
37104 * allocates an extra guard page, so we need space for that.
37105 */
37106 +
37107 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37108 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37109 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
37110 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37111 +#else
37112 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37113 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
37114 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37115 +#endif
37116 +
37117 if (!switcher_vma) {
37118 err = -ENOMEM;
37119 printk("lguest: could not map switcher pages high\n");
37120 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
37121 * Now the Switcher is mapped at the right address, we can't fail!
37122 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37123 */
37124 - memcpy(switcher_vma->addr, start_switcher_text,
37125 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37126 end_switcher_text - start_switcher_text);
37127
37128 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37129 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37130 index 4af12e1..0e89afe 100644
37131 --- a/drivers/lguest/x86/core.c
37132 +++ b/drivers/lguest/x86/core.c
37133 @@ -59,7 +59,7 @@ static struct {
37134 /* Offset from where switcher.S was compiled to where we've copied it */
37135 static unsigned long switcher_offset(void)
37136 {
37137 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37138 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37139 }
37140
37141 /* This cpu's struct lguest_pages. */
37142 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37143 * These copies are pretty cheap, so we do them unconditionally: */
37144 /* Save the current Host top-level page directory.
37145 */
37146 +
37147 +#ifdef CONFIG_PAX_PER_CPU_PGD
37148 + pages->state.host_cr3 = read_cr3();
37149 +#else
37150 pages->state.host_cr3 = __pa(current->mm->pgd);
37151 +#endif
37152 +
37153 /*
37154 * Set up the Guest's page tables to see this CPU's pages (and no
37155 * other CPU's pages).
37156 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37157 * compiled-in switcher code and the high-mapped copy we just made.
37158 */
37159 for (i = 0; i < IDT_ENTRIES; i++)
37160 - default_idt_entries[i] += switcher_offset();
37161 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37162
37163 /*
37164 * Set up the Switcher's per-cpu areas.
37165 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37166 * it will be undisturbed when we switch. To change %cs and jump we
37167 * need this structure to feed to Intel's "lcall" instruction.
37168 */
37169 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
37170 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
37171 lguest_entry.segment = LGUEST_CS;
37172
37173 /*
37174 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
37175 index 40634b0..4f5855e 100644
37176 --- a/drivers/lguest/x86/switcher_32.S
37177 +++ b/drivers/lguest/x86/switcher_32.S
37178 @@ -87,6 +87,7 @@
37179 #include <asm/page.h>
37180 #include <asm/segment.h>
37181 #include <asm/lguest.h>
37182 +#include <asm/processor-flags.h>
37183
37184 // We mark the start of the code to copy
37185 // It's placed in .text tho it's never run here
37186 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
37187 // Changes type when we load it: damn Intel!
37188 // For after we switch over our page tables
37189 // That entry will be read-only: we'd crash.
37190 +
37191 +#ifdef CONFIG_PAX_KERNEXEC
37192 + mov %cr0, %edx
37193 + xor $X86_CR0_WP, %edx
37194 + mov %edx, %cr0
37195 +#endif
37196 +
37197 movl $(GDT_ENTRY_TSS*8), %edx
37198 ltr %dx
37199
37200 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
37201 // Let's clear it again for our return.
37202 // The GDT descriptor of the Host
37203 // Points to the table after two "size" bytes
37204 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
37205 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
37206 // Clear "used" from type field (byte 5, bit 2)
37207 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
37208 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
37209 +
37210 +#ifdef CONFIG_PAX_KERNEXEC
37211 + mov %cr0, %eax
37212 + xor $X86_CR0_WP, %eax
37213 + mov %eax, %cr0
37214 +#endif
37215
37216 // Once our page table's switched, the Guest is live!
37217 // The Host fades as we run this final step.
37218 @@ -295,13 +309,12 @@ deliver_to_host:
37219 // I consulted gcc, and it gave
37220 // These instructions, which I gladly credit:
37221 leal (%edx,%ebx,8), %eax
37222 - movzwl (%eax),%edx
37223 - movl 4(%eax), %eax
37224 - xorw %ax, %ax
37225 - orl %eax, %edx
37226 + movl 4(%eax), %edx
37227 + movw (%eax), %dx
37228 // Now the address of the handler's in %edx
37229 // We call it now: its "iret" drops us home.
37230 - jmp *%edx
37231 + ljmp $__KERNEL_CS, $1f
37232 +1: jmp *%edx
37233
37234 // Every interrupt can come to us here
37235 // But we must truly tell each apart.
37236 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
37237 index 7155945..4bcc562 100644
37238 --- a/drivers/md/bitmap.c
37239 +++ b/drivers/md/bitmap.c
37240 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
37241 chunk_kb ? "KB" : "B");
37242 if (bitmap->storage.file) {
37243 seq_printf(seq, ", file: ");
37244 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
37245 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
37246 }
37247
37248 seq_printf(seq, "\n");
37249 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
37250 index 0666b5d..ed82cb4 100644
37251 --- a/drivers/md/dm-ioctl.c
37252 +++ b/drivers/md/dm-ioctl.c
37253 @@ -1628,7 +1628,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
37254 cmd == DM_LIST_VERSIONS_CMD)
37255 return 0;
37256
37257 - if ((cmd == DM_DEV_CREATE_CMD)) {
37258 + if (cmd == DM_DEV_CREATE_CMD) {
37259 if (!*param->name) {
37260 DMWARN("name not supplied when creating device");
37261 return -EINVAL;
37262 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
37263 index fa51918..c26253c 100644
37264 --- a/drivers/md/dm-raid1.c
37265 +++ b/drivers/md/dm-raid1.c
37266 @@ -40,7 +40,7 @@ enum dm_raid1_error {
37267
37268 struct mirror {
37269 struct mirror_set *ms;
37270 - atomic_t error_count;
37271 + atomic_unchecked_t error_count;
37272 unsigned long error_type;
37273 struct dm_dev *dev;
37274 sector_t offset;
37275 @@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
37276 struct mirror *m;
37277
37278 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
37279 - if (!atomic_read(&m->error_count))
37280 + if (!atomic_read_unchecked(&m->error_count))
37281 return m;
37282
37283 return NULL;
37284 @@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
37285 * simple way to tell if a device has encountered
37286 * errors.
37287 */
37288 - atomic_inc(&m->error_count);
37289 + atomic_inc_unchecked(&m->error_count);
37290
37291 if (test_and_set_bit(error_type, &m->error_type))
37292 return;
37293 @@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
37294 struct mirror *m = get_default_mirror(ms);
37295
37296 do {
37297 - if (likely(!atomic_read(&m->error_count)))
37298 + if (likely(!atomic_read_unchecked(&m->error_count)))
37299 return m;
37300
37301 if (m-- == ms->mirror)
37302 @@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
37303 {
37304 struct mirror *default_mirror = get_default_mirror(m->ms);
37305
37306 - return !atomic_read(&default_mirror->error_count);
37307 + return !atomic_read_unchecked(&default_mirror->error_count);
37308 }
37309
37310 static int mirror_available(struct mirror_set *ms, struct bio *bio)
37311 @@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
37312 */
37313 if (likely(region_in_sync(ms, region, 1)))
37314 m = choose_mirror(ms, bio->bi_sector);
37315 - else if (m && atomic_read(&m->error_count))
37316 + else if (m && atomic_read_unchecked(&m->error_count))
37317 m = NULL;
37318
37319 if (likely(m))
37320 @@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
37321 }
37322
37323 ms->mirror[mirror].ms = ms;
37324 - atomic_set(&(ms->mirror[mirror].error_count), 0);
37325 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
37326 ms->mirror[mirror].error_type = 0;
37327 ms->mirror[mirror].offset = offset;
37328
37329 @@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
37330 */
37331 static char device_status_char(struct mirror *m)
37332 {
37333 - if (!atomic_read(&(m->error_count)))
37334 + if (!atomic_read_unchecked(&(m->error_count)))
37335 return 'A';
37336
37337 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
37338 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
37339 index c89cde8..9d184cf 100644
37340 --- a/drivers/md/dm-stripe.c
37341 +++ b/drivers/md/dm-stripe.c
37342 @@ -20,7 +20,7 @@ struct stripe {
37343 struct dm_dev *dev;
37344 sector_t physical_start;
37345
37346 - atomic_t error_count;
37347 + atomic_unchecked_t error_count;
37348 };
37349
37350 struct stripe_c {
37351 @@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
37352 kfree(sc);
37353 return r;
37354 }
37355 - atomic_set(&(sc->stripe[i].error_count), 0);
37356 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
37357 }
37358
37359 ti->private = sc;
37360 @@ -325,7 +325,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
37361 DMEMIT("%d ", sc->stripes);
37362 for (i = 0; i < sc->stripes; i++) {
37363 DMEMIT("%s ", sc->stripe[i].dev->name);
37364 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
37365 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
37366 'D' : 'A';
37367 }
37368 buffer[i] = '\0';
37369 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
37370 */
37371 for (i = 0; i < sc->stripes; i++)
37372 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
37373 - atomic_inc(&(sc->stripe[i].error_count));
37374 - if (atomic_read(&(sc->stripe[i].error_count)) <
37375 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
37376 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
37377 DM_IO_ERROR_THRESHOLD)
37378 schedule_work(&sc->trigger_event);
37379 }
37380 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
37381 index daf25d0..d74f49f 100644
37382 --- a/drivers/md/dm-table.c
37383 +++ b/drivers/md/dm-table.c
37384 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
37385 if (!dev_size)
37386 return 0;
37387
37388 - if ((start >= dev_size) || (start + len > dev_size)) {
37389 + if ((start >= dev_size) || (len > dev_size - start)) {
37390 DMWARN("%s: %s too small for target: "
37391 "start=%llu, len=%llu, dev_size=%llu",
37392 dm_device_name(ti->table->md), bdevname(bdev, b),
37393 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
37394 index 4d6e853..a234157 100644
37395 --- a/drivers/md/dm-thin-metadata.c
37396 +++ b/drivers/md/dm-thin-metadata.c
37397 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37398 {
37399 pmd->info.tm = pmd->tm;
37400 pmd->info.levels = 2;
37401 - pmd->info.value_type.context = pmd->data_sm;
37402 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37403 pmd->info.value_type.size = sizeof(__le64);
37404 pmd->info.value_type.inc = data_block_inc;
37405 pmd->info.value_type.dec = data_block_dec;
37406 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37407
37408 pmd->bl_info.tm = pmd->tm;
37409 pmd->bl_info.levels = 1;
37410 - pmd->bl_info.value_type.context = pmd->data_sm;
37411 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37412 pmd->bl_info.value_type.size = sizeof(__le64);
37413 pmd->bl_info.value_type.inc = data_block_inc;
37414 pmd->bl_info.value_type.dec = data_block_dec;
37415 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
37416 index 314a0e2..1376406 100644
37417 --- a/drivers/md/dm.c
37418 +++ b/drivers/md/dm.c
37419 @@ -170,9 +170,9 @@ struct mapped_device {
37420 /*
37421 * Event handling.
37422 */
37423 - atomic_t event_nr;
37424 + atomic_unchecked_t event_nr;
37425 wait_queue_head_t eventq;
37426 - atomic_t uevent_seq;
37427 + atomic_unchecked_t uevent_seq;
37428 struct list_head uevent_list;
37429 spinlock_t uevent_lock; /* Protect access to uevent_list */
37430
37431 @@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
37432 rwlock_init(&md->map_lock);
37433 atomic_set(&md->holders, 1);
37434 atomic_set(&md->open_count, 0);
37435 - atomic_set(&md->event_nr, 0);
37436 - atomic_set(&md->uevent_seq, 0);
37437 + atomic_set_unchecked(&md->event_nr, 0);
37438 + atomic_set_unchecked(&md->uevent_seq, 0);
37439 INIT_LIST_HEAD(&md->uevent_list);
37440 spin_lock_init(&md->uevent_lock);
37441
37442 @@ -2014,7 +2014,7 @@ static void event_callback(void *context)
37443
37444 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
37445
37446 - atomic_inc(&md->event_nr);
37447 + atomic_inc_unchecked(&md->event_nr);
37448 wake_up(&md->eventq);
37449 }
37450
37451 @@ -2669,18 +2669,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
37452
37453 uint32_t dm_next_uevent_seq(struct mapped_device *md)
37454 {
37455 - return atomic_add_return(1, &md->uevent_seq);
37456 + return atomic_add_return_unchecked(1, &md->uevent_seq);
37457 }
37458
37459 uint32_t dm_get_event_nr(struct mapped_device *md)
37460 {
37461 - return atomic_read(&md->event_nr);
37462 + return atomic_read_unchecked(&md->event_nr);
37463 }
37464
37465 int dm_wait_event(struct mapped_device *md, int event_nr)
37466 {
37467 return wait_event_interruptible(md->eventq,
37468 - (event_nr != atomic_read(&md->event_nr)));
37469 + (event_nr != atomic_read_unchecked(&md->event_nr)));
37470 }
37471
37472 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
37473 diff --git a/drivers/md/md.c b/drivers/md/md.c
37474 index 3db3d1b..9487468 100644
37475 --- a/drivers/md/md.c
37476 +++ b/drivers/md/md.c
37477 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
37478 * start build, activate spare
37479 */
37480 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
37481 -static atomic_t md_event_count;
37482 +static atomic_unchecked_t md_event_count;
37483 void md_new_event(struct mddev *mddev)
37484 {
37485 - atomic_inc(&md_event_count);
37486 + atomic_inc_unchecked(&md_event_count);
37487 wake_up(&md_event_waiters);
37488 }
37489 EXPORT_SYMBOL_GPL(md_new_event);
37490 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
37491 */
37492 static void md_new_event_inintr(struct mddev *mddev)
37493 {
37494 - atomic_inc(&md_event_count);
37495 + atomic_inc_unchecked(&md_event_count);
37496 wake_up(&md_event_waiters);
37497 }
37498
37499 @@ -1503,7 +1503,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
37500 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
37501 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
37502 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
37503 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37504 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37505
37506 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
37507 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
37508 @@ -1747,7 +1747,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
37509 else
37510 sb->resync_offset = cpu_to_le64(0);
37511
37512 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
37513 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
37514
37515 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
37516 sb->size = cpu_to_le64(mddev->dev_sectors);
37517 @@ -2747,7 +2747,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
37518 static ssize_t
37519 errors_show(struct md_rdev *rdev, char *page)
37520 {
37521 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
37522 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
37523 }
37524
37525 static ssize_t
37526 @@ -2756,7 +2756,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
37527 char *e;
37528 unsigned long n = simple_strtoul(buf, &e, 10);
37529 if (*buf && (*e == 0 || *e == '\n')) {
37530 - atomic_set(&rdev->corrected_errors, n);
37531 + atomic_set_unchecked(&rdev->corrected_errors, n);
37532 return len;
37533 }
37534 return -EINVAL;
37535 @@ -3203,8 +3203,8 @@ int md_rdev_init(struct md_rdev *rdev)
37536 rdev->sb_loaded = 0;
37537 rdev->bb_page = NULL;
37538 atomic_set(&rdev->nr_pending, 0);
37539 - atomic_set(&rdev->read_errors, 0);
37540 - atomic_set(&rdev->corrected_errors, 0);
37541 + atomic_set_unchecked(&rdev->read_errors, 0);
37542 + atomic_set_unchecked(&rdev->corrected_errors, 0);
37543
37544 INIT_LIST_HEAD(&rdev->same_set);
37545 init_waitqueue_head(&rdev->blocked_wait);
37546 @@ -6980,7 +6980,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
37547
37548 spin_unlock(&pers_lock);
37549 seq_printf(seq, "\n");
37550 - seq->poll_event = atomic_read(&md_event_count);
37551 + seq->poll_event = atomic_read_unchecked(&md_event_count);
37552 return 0;
37553 }
37554 if (v == (void*)2) {
37555 @@ -7083,7 +7083,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
37556 return error;
37557
37558 seq = file->private_data;
37559 - seq->poll_event = atomic_read(&md_event_count);
37560 + seq->poll_event = atomic_read_unchecked(&md_event_count);
37561 return error;
37562 }
37563
37564 @@ -7097,7 +7097,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
37565 /* always allow read */
37566 mask = POLLIN | POLLRDNORM;
37567
37568 - if (seq->poll_event != atomic_read(&md_event_count))
37569 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
37570 mask |= POLLERR | POLLPRI;
37571 return mask;
37572 }
37573 @@ -7141,7 +7141,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
37574 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
37575 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
37576 (int)part_stat_read(&disk->part0, sectors[1]) -
37577 - atomic_read(&disk->sync_io);
37578 + atomic_read_unchecked(&disk->sync_io);
37579 /* sync IO will cause sync_io to increase before the disk_stats
37580 * as sync_io is counted when a request starts, and
37581 * disk_stats is counted when it completes.
37582 diff --git a/drivers/md/md.h b/drivers/md/md.h
37583 index eca59c3..7c42285 100644
37584 --- a/drivers/md/md.h
37585 +++ b/drivers/md/md.h
37586 @@ -94,13 +94,13 @@ struct md_rdev {
37587 * only maintained for arrays that
37588 * support hot removal
37589 */
37590 - atomic_t read_errors; /* number of consecutive read errors that
37591 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
37592 * we have tried to ignore.
37593 */
37594 struct timespec last_read_error; /* monotonic time since our
37595 * last read error
37596 */
37597 - atomic_t corrected_errors; /* number of corrected read errors,
37598 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
37599 * for reporting to userspace and storing
37600 * in superblock.
37601 */
37602 @@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
37603
37604 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
37605 {
37606 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37607 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37608 }
37609
37610 struct md_personality
37611 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
37612 index 1cbfc6b..56e1dbb 100644
37613 --- a/drivers/md/persistent-data/dm-space-map.h
37614 +++ b/drivers/md/persistent-data/dm-space-map.h
37615 @@ -60,6 +60,7 @@ struct dm_space_map {
37616 int (*root_size)(struct dm_space_map *sm, size_t *result);
37617 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
37618 };
37619 +typedef struct dm_space_map __no_const dm_space_map_no_const;
37620
37621 /*----------------------------------------------------------------*/
37622
37623 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
37624 index d5bddfc..b079b4b 100644
37625 --- a/drivers/md/raid1.c
37626 +++ b/drivers/md/raid1.c
37627 @@ -1818,7 +1818,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
37628 if (r1_sync_page_io(rdev, sect, s,
37629 bio->bi_io_vec[idx].bv_page,
37630 READ) != 0)
37631 - atomic_add(s, &rdev->corrected_errors);
37632 + atomic_add_unchecked(s, &rdev->corrected_errors);
37633 }
37634 sectors -= s;
37635 sect += s;
37636 @@ -2040,7 +2040,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
37637 test_bit(In_sync, &rdev->flags)) {
37638 if (r1_sync_page_io(rdev, sect, s,
37639 conf->tmppage, READ)) {
37640 - atomic_add(s, &rdev->corrected_errors);
37641 + atomic_add_unchecked(s, &rdev->corrected_errors);
37642 printk(KERN_INFO
37643 "md/raid1:%s: read error corrected "
37644 "(%d sectors at %llu on %s)\n",
37645 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
37646 index 64d4824..8b9ea57 100644
37647 --- a/drivers/md/raid10.c
37648 +++ b/drivers/md/raid10.c
37649 @@ -1877,7 +1877,7 @@ static void end_sync_read(struct bio *bio, int error)
37650 /* The write handler will notice the lack of
37651 * R10BIO_Uptodate and record any errors etc
37652 */
37653 - atomic_add(r10_bio->sectors,
37654 + atomic_add_unchecked(r10_bio->sectors,
37655 &conf->mirrors[d].rdev->corrected_errors);
37656
37657 /* for reconstruct, we always reschedule after a read.
37658 @@ -2226,7 +2226,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
37659 {
37660 struct timespec cur_time_mon;
37661 unsigned long hours_since_last;
37662 - unsigned int read_errors = atomic_read(&rdev->read_errors);
37663 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
37664
37665 ktime_get_ts(&cur_time_mon);
37666
37667 @@ -2248,9 +2248,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
37668 * overflowing the shift of read_errors by hours_since_last.
37669 */
37670 if (hours_since_last >= 8 * sizeof(read_errors))
37671 - atomic_set(&rdev->read_errors, 0);
37672 + atomic_set_unchecked(&rdev->read_errors, 0);
37673 else
37674 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
37675 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
37676 }
37677
37678 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
37679 @@ -2304,8 +2304,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37680 return;
37681
37682 check_decay_read_errors(mddev, rdev);
37683 - atomic_inc(&rdev->read_errors);
37684 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
37685 + atomic_inc_unchecked(&rdev->read_errors);
37686 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
37687 char b[BDEVNAME_SIZE];
37688 bdevname(rdev->bdev, b);
37689
37690 @@ -2313,7 +2313,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37691 "md/raid10:%s: %s: Raid device exceeded "
37692 "read_error threshold [cur %d:max %d]\n",
37693 mdname(mddev), b,
37694 - atomic_read(&rdev->read_errors), max_read_errors);
37695 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
37696 printk(KERN_NOTICE
37697 "md/raid10:%s: %s: Failing raid device\n",
37698 mdname(mddev), b);
37699 @@ -2468,7 +2468,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37700 sect +
37701 choose_data_offset(r10_bio, rdev)),
37702 bdevname(rdev->bdev, b));
37703 - atomic_add(s, &rdev->corrected_errors);
37704 + atomic_add_unchecked(s, &rdev->corrected_errors);
37705 }
37706
37707 rdev_dec_pending(rdev, mddev);
37708 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
37709 index 19d77a0..56051b92 100644
37710 --- a/drivers/md/raid5.c
37711 +++ b/drivers/md/raid5.c
37712 @@ -1797,21 +1797,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
37713 mdname(conf->mddev), STRIPE_SECTORS,
37714 (unsigned long long)s,
37715 bdevname(rdev->bdev, b));
37716 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
37717 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
37718 clear_bit(R5_ReadError, &sh->dev[i].flags);
37719 clear_bit(R5_ReWrite, &sh->dev[i].flags);
37720 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
37721 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
37722
37723 - if (atomic_read(&rdev->read_errors))
37724 - atomic_set(&rdev->read_errors, 0);
37725 + if (atomic_read_unchecked(&rdev->read_errors))
37726 + atomic_set_unchecked(&rdev->read_errors, 0);
37727 } else {
37728 const char *bdn = bdevname(rdev->bdev, b);
37729 int retry = 0;
37730 int set_bad = 0;
37731
37732 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
37733 - atomic_inc(&rdev->read_errors);
37734 + atomic_inc_unchecked(&rdev->read_errors);
37735 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
37736 printk_ratelimited(
37737 KERN_WARNING
37738 @@ -1839,7 +1839,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
37739 mdname(conf->mddev),
37740 (unsigned long long)s,
37741 bdn);
37742 - } else if (atomic_read(&rdev->read_errors)
37743 + } else if (atomic_read_unchecked(&rdev->read_errors)
37744 > conf->max_nr_stripes)
37745 printk(KERN_WARNING
37746 "md/raid:%s: Too many read errors, failing device %s.\n",
37747 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
37748 index d33101a..6b13069 100644
37749 --- a/drivers/media/dvb-core/dvbdev.c
37750 +++ b/drivers/media/dvb-core/dvbdev.c
37751 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
37752 const struct dvb_device *template, void *priv, int type)
37753 {
37754 struct dvb_device *dvbdev;
37755 - struct file_operations *dvbdevfops;
37756 + file_operations_no_const *dvbdevfops;
37757 struct device *clsdev;
37758 int minor;
37759 int id;
37760 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
37761 index 404f63a..4796533 100644
37762 --- a/drivers/media/dvb-frontends/dib3000.h
37763 +++ b/drivers/media/dvb-frontends/dib3000.h
37764 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
37765 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
37766 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
37767 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
37768 -};
37769 +} __no_const;
37770
37771 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
37772 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
37773 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
37774 index 8e9a668..78d6310 100644
37775 --- a/drivers/media/platform/omap/omap_vout.c
37776 +++ b/drivers/media/platform/omap/omap_vout.c
37777 @@ -63,7 +63,6 @@ enum omap_vout_channels {
37778 OMAP_VIDEO2,
37779 };
37780
37781 -static struct videobuf_queue_ops video_vbq_ops;
37782 /* Variables configurable through module params*/
37783 static u32 video1_numbuffers = 3;
37784 static u32 video2_numbuffers = 3;
37785 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
37786 {
37787 struct videobuf_queue *q;
37788 struct omap_vout_device *vout = NULL;
37789 + static struct videobuf_queue_ops video_vbq_ops = {
37790 + .buf_setup = omap_vout_buffer_setup,
37791 + .buf_prepare = omap_vout_buffer_prepare,
37792 + .buf_release = omap_vout_buffer_release,
37793 + .buf_queue = omap_vout_buffer_queue,
37794 + };
37795
37796 vout = video_drvdata(file);
37797 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
37798 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
37799 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
37800
37801 q = &vout->vbq;
37802 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
37803 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
37804 - video_vbq_ops.buf_release = omap_vout_buffer_release;
37805 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
37806 spin_lock_init(&vout->vbq_lock);
37807
37808 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
37809 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
37810 index b671e20..34088b7 100644
37811 --- a/drivers/media/platform/s5p-tv/mixer.h
37812 +++ b/drivers/media/platform/s5p-tv/mixer.h
37813 @@ -155,7 +155,7 @@ struct mxr_layer {
37814 /** layer index (unique identifier) */
37815 int idx;
37816 /** callbacks for layer methods */
37817 - struct mxr_layer_ops ops;
37818 + struct mxr_layer_ops *ops;
37819 /** format array */
37820 const struct mxr_format **fmt_array;
37821 /** size of format array */
37822 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
37823 index b93a21f..2535195 100644
37824 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
37825 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
37826 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
37827 {
37828 struct mxr_layer *layer;
37829 int ret;
37830 - struct mxr_layer_ops ops = {
37831 + static struct mxr_layer_ops ops = {
37832 .release = mxr_graph_layer_release,
37833 .buffer_set = mxr_graph_buffer_set,
37834 .stream_set = mxr_graph_stream_set,
37835 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
37836 index 3b1670a..595c939 100644
37837 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
37838 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
37839 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
37840 layer->update_buf = next;
37841 }
37842
37843 - layer->ops.buffer_set(layer, layer->update_buf);
37844 + layer->ops->buffer_set(layer, layer->update_buf);
37845
37846 if (done && done != layer->shadow_buf)
37847 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
37848 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
37849 index 1f3b743..e839271 100644
37850 --- a/drivers/media/platform/s5p-tv/mixer_video.c
37851 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
37852 @@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
37853 layer->geo.src.height = layer->geo.src.full_height;
37854
37855 mxr_geometry_dump(mdev, &layer->geo);
37856 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37857 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37858 mxr_geometry_dump(mdev, &layer->geo);
37859 }
37860
37861 @@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
37862 layer->geo.dst.full_width = mbus_fmt.width;
37863 layer->geo.dst.full_height = mbus_fmt.height;
37864 layer->geo.dst.field = mbus_fmt.field;
37865 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37866 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37867
37868 mxr_geometry_dump(mdev, &layer->geo);
37869 }
37870 @@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
37871 /* set source size to highest accepted value */
37872 geo->src.full_width = max(geo->dst.full_width, pix->width);
37873 geo->src.full_height = max(geo->dst.full_height, pix->height);
37874 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37875 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37876 mxr_geometry_dump(mdev, &layer->geo);
37877 /* set cropping to total visible screen */
37878 geo->src.width = pix->width;
37879 @@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
37880 geo->src.x_offset = 0;
37881 geo->src.y_offset = 0;
37882 /* assure consistency of geometry */
37883 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
37884 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
37885 mxr_geometry_dump(mdev, &layer->geo);
37886 /* set full size to lowest possible value */
37887 geo->src.full_width = 0;
37888 geo->src.full_height = 0;
37889 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37890 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37891 mxr_geometry_dump(mdev, &layer->geo);
37892
37893 /* returning results */
37894 @@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
37895 target->width = s->r.width;
37896 target->height = s->r.height;
37897
37898 - layer->ops.fix_geometry(layer, stage, s->flags);
37899 + layer->ops->fix_geometry(layer, stage, s->flags);
37900
37901 /* retrieve update selection rectangle */
37902 res.left = target->x_offset;
37903 @@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
37904 mxr_output_get(mdev);
37905
37906 mxr_layer_update_output(layer);
37907 - layer->ops.format_set(layer);
37908 + layer->ops->format_set(layer);
37909 /* enabling layer in hardware */
37910 spin_lock_irqsave(&layer->enq_slock, flags);
37911 layer->state = MXR_LAYER_STREAMING;
37912 spin_unlock_irqrestore(&layer->enq_slock, flags);
37913
37914 - layer->ops.stream_set(layer, MXR_ENABLE);
37915 + layer->ops->stream_set(layer, MXR_ENABLE);
37916 mxr_streamer_get(mdev);
37917
37918 return 0;
37919 @@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
37920 spin_unlock_irqrestore(&layer->enq_slock, flags);
37921
37922 /* disabling layer in hardware */
37923 - layer->ops.stream_set(layer, MXR_DISABLE);
37924 + layer->ops->stream_set(layer, MXR_DISABLE);
37925 /* remove one streamer */
37926 mxr_streamer_put(mdev);
37927 /* allow changes in output configuration */
37928 @@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
37929
37930 void mxr_layer_release(struct mxr_layer *layer)
37931 {
37932 - if (layer->ops.release)
37933 - layer->ops.release(layer);
37934 + if (layer->ops->release)
37935 + layer->ops->release(layer);
37936 }
37937
37938 void mxr_base_layer_release(struct mxr_layer *layer)
37939 @@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
37940
37941 layer->mdev = mdev;
37942 layer->idx = idx;
37943 - layer->ops = *ops;
37944 + layer->ops = ops;
37945
37946 spin_lock_init(&layer->enq_slock);
37947 INIT_LIST_HEAD(&layer->enq_list);
37948 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
37949 index 3d13a63..da31bf1 100644
37950 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
37951 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
37952 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
37953 {
37954 struct mxr_layer *layer;
37955 int ret;
37956 - struct mxr_layer_ops ops = {
37957 + static struct mxr_layer_ops ops = {
37958 .release = mxr_vp_layer_release,
37959 .buffer_set = mxr_vp_buffer_set,
37960 .stream_set = mxr_vp_stream_set,
37961 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
37962 index 643d80a..56bb96b 100644
37963 --- a/drivers/media/radio/radio-cadet.c
37964 +++ b/drivers/media/radio/radio-cadet.c
37965 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
37966 unsigned char readbuf[RDS_BUFFER];
37967 int i = 0;
37968
37969 + if (count > RDS_BUFFER)
37970 + return -EFAULT;
37971 mutex_lock(&dev->lock);
37972 if (dev->rdsstat == 0)
37973 cadet_start_rds(dev);
37974 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
37975 while (i < count && dev->rdsin != dev->rdsout)
37976 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
37977
37978 - if (i && copy_to_user(data, readbuf, i))
37979 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
37980 i = -EFAULT;
37981 unlock:
37982 mutex_unlock(&dev->lock);
37983 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
37984 index 3940bb0..fb3952a 100644
37985 --- a/drivers/media/usb/dvb-usb/cxusb.c
37986 +++ b/drivers/media/usb/dvb-usb/cxusb.c
37987 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
37988
37989 struct dib0700_adapter_state {
37990 int (*set_param_save) (struct dvb_frontend *);
37991 -};
37992 +} __no_const;
37993
37994 static int dib7070_set_param_override(struct dvb_frontend *fe)
37995 {
37996 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
37997 index 9382895..ac8093c 100644
37998 --- a/drivers/media/usb/dvb-usb/dw2102.c
37999 +++ b/drivers/media/usb/dvb-usb/dw2102.c
38000 @@ -95,7 +95,7 @@ struct su3000_state {
38001
38002 struct s6x0_state {
38003 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38004 -};
38005 +} __no_const;
38006
38007 /* debug */
38008 static int dvb_usb_dw2102_debug;
38009 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38010 index aa6e7c7..4cd8061 100644
38011 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
38012 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38013 @@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
38014 struct file *file, void *fh, void *p);
38015 } u;
38016 void (*debug)(const void *arg, bool write_only);
38017 -};
38018 +} __do_const;
38019 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
38020
38021 /* This control needs a priority check */
38022 #define INFO_FL_PRIO (1 << 0)
38023 @@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
38024 struct video_device *vfd = video_devdata(file);
38025 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
38026 bool write_only = false;
38027 - struct v4l2_ioctl_info default_info;
38028 + v4l2_ioctl_info_no_const default_info;
38029 const struct v4l2_ioctl_info *info;
38030 void *fh = file->private_data;
38031 struct v4l2_fh *vfh = NULL;
38032 diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
38033 index 29b2172..a7c5b31 100644
38034 --- a/drivers/memstick/host/r592.c
38035 +++ b/drivers/memstick/host/r592.c
38036 @@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
38037 /* Executes one TPC (data is read/written from small or large fifo) */
38038 static void r592_execute_tpc(struct r592_device *dev)
38039 {
38040 - bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38041 + bool is_write;
38042 int len, error;
38043 u32 status, reg;
38044
38045 @@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
38046 return;
38047 }
38048
38049 + is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38050 len = dev->req->long_data ?
38051 dev->req->sg.length : dev->req->data_len;
38052
38053 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
38054 index fb69baa..cf7ad22 100644
38055 --- a/drivers/message/fusion/mptbase.c
38056 +++ b/drivers/message/fusion/mptbase.c
38057 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38058 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
38059 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
38060
38061 +#ifdef CONFIG_GRKERNSEC_HIDESYM
38062 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
38063 +#else
38064 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
38065 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
38066 +#endif
38067 +
38068 /*
38069 * Rounding UP to nearest 4-kB boundary here...
38070 */
38071 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
38072 index fa43c39..daeb158 100644
38073 --- a/drivers/message/fusion/mptsas.c
38074 +++ b/drivers/message/fusion/mptsas.c
38075 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
38076 return 0;
38077 }
38078
38079 +static inline void
38080 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38081 +{
38082 + if (phy_info->port_details) {
38083 + phy_info->port_details->rphy = rphy;
38084 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38085 + ioc->name, rphy));
38086 + }
38087 +
38088 + if (rphy) {
38089 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38090 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38091 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38092 + ioc->name, rphy, rphy->dev.release));
38093 + }
38094 +}
38095 +
38096 /* no mutex */
38097 static void
38098 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
38099 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
38100 return NULL;
38101 }
38102
38103 -static inline void
38104 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38105 -{
38106 - if (phy_info->port_details) {
38107 - phy_info->port_details->rphy = rphy;
38108 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38109 - ioc->name, rphy));
38110 - }
38111 -
38112 - if (rphy) {
38113 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38114 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38115 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38116 - ioc->name, rphy, rphy->dev.release));
38117 - }
38118 -}
38119 -
38120 static inline struct sas_port *
38121 mptsas_get_port(struct mptsas_phyinfo *phy_info)
38122 {
38123 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
38124 index 164afa7..b6b2e74 100644
38125 --- a/drivers/message/fusion/mptscsih.c
38126 +++ b/drivers/message/fusion/mptscsih.c
38127 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
38128
38129 h = shost_priv(SChost);
38130
38131 - if (h) {
38132 - if (h->info_kbuf == NULL)
38133 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38134 - return h->info_kbuf;
38135 - h->info_kbuf[0] = '\0';
38136 + if (!h)
38137 + return NULL;
38138
38139 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38140 - h->info_kbuf[size-1] = '\0';
38141 - }
38142 + if (h->info_kbuf == NULL)
38143 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38144 + return h->info_kbuf;
38145 + h->info_kbuf[0] = '\0';
38146 +
38147 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38148 + h->info_kbuf[size-1] = '\0';
38149
38150 return h->info_kbuf;
38151 }
38152 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
38153 index 8001aa6..b137580 100644
38154 --- a/drivers/message/i2o/i2o_proc.c
38155 +++ b/drivers/message/i2o/i2o_proc.c
38156 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
38157 "Array Controller Device"
38158 };
38159
38160 -static char *chtostr(char *tmp, u8 *chars, int n)
38161 -{
38162 - tmp[0] = 0;
38163 - return strncat(tmp, (char *)chars, n);
38164 -}
38165 -
38166 static int i2o_report_query_status(struct seq_file *seq, int block_status,
38167 char *group)
38168 {
38169 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38170 } *result;
38171
38172 i2o_exec_execute_ddm_table ddm_table;
38173 - char tmp[28 + 1];
38174
38175 result = kmalloc(sizeof(*result), GFP_KERNEL);
38176 if (!result)
38177 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38178
38179 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
38180 seq_printf(seq, "%-#8x", ddm_table.module_id);
38181 - seq_printf(seq, "%-29s",
38182 - chtostr(tmp, ddm_table.module_name_version, 28));
38183 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
38184 seq_printf(seq, "%9d ", ddm_table.data_size);
38185 seq_printf(seq, "%8d", ddm_table.code_size);
38186
38187 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38188
38189 i2o_driver_result_table *result;
38190 i2o_driver_store_table *dst;
38191 - char tmp[28 + 1];
38192
38193 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
38194 if (result == NULL)
38195 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38196
38197 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
38198 seq_printf(seq, "%-#8x", dst->module_id);
38199 - seq_printf(seq, "%-29s",
38200 - chtostr(tmp, dst->module_name_version, 28));
38201 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
38202 + seq_printf(seq, "%-.28s", dst->module_name_version);
38203 + seq_printf(seq, "%-.8s", dst->date);
38204 seq_printf(seq, "%8d ", dst->module_size);
38205 seq_printf(seq, "%8d ", dst->mpb_size);
38206 seq_printf(seq, "0x%04x", dst->module_flags);
38207 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38208 // == (allow) 512d bytes (max)
38209 static u16 *work16 = (u16 *) work32;
38210 int token;
38211 - char tmp[16 + 1];
38212
38213 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
38214
38215 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38216 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
38217 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
38218 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
38219 - seq_printf(seq, "Vendor info : %s\n",
38220 - chtostr(tmp, (u8 *) (work32 + 2), 16));
38221 - seq_printf(seq, "Product info : %s\n",
38222 - chtostr(tmp, (u8 *) (work32 + 6), 16));
38223 - seq_printf(seq, "Description : %s\n",
38224 - chtostr(tmp, (u8 *) (work32 + 10), 16));
38225 - seq_printf(seq, "Product rev. : %s\n",
38226 - chtostr(tmp, (u8 *) (work32 + 14), 8));
38227 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
38228 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
38229 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
38230 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
38231
38232 seq_printf(seq, "Serial number : ");
38233 print_serial_number(seq, (u8 *) (work32 + 16),
38234 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38235 u8 pad[256]; // allow up to 256 byte (max) serial number
38236 } result;
38237
38238 - char tmp[24 + 1];
38239 -
38240 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
38241
38242 if (token < 0) {
38243 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38244 }
38245
38246 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
38247 - seq_printf(seq, "Module name : %s\n",
38248 - chtostr(tmp, result.module_name, 24));
38249 - seq_printf(seq, "Module revision : %s\n",
38250 - chtostr(tmp, result.module_rev, 8));
38251 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
38252 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
38253
38254 seq_printf(seq, "Serial number : ");
38255 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
38256 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38257 u8 instance_number[4];
38258 } result;
38259
38260 - char tmp[64 + 1];
38261 -
38262 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
38263
38264 if (token < 0) {
38265 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38266 return 0;
38267 }
38268
38269 - seq_printf(seq, "Device name : %s\n",
38270 - chtostr(tmp, result.device_name, 64));
38271 - seq_printf(seq, "Service name : %s\n",
38272 - chtostr(tmp, result.service_name, 64));
38273 - seq_printf(seq, "Physical name : %s\n",
38274 - chtostr(tmp, result.physical_location, 64));
38275 - seq_printf(seq, "Instance number : %s\n",
38276 - chtostr(tmp, result.instance_number, 4));
38277 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
38278 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
38279 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
38280 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
38281
38282 return 0;
38283 }
38284 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
38285 index a8c08f3..155fe3d 100644
38286 --- a/drivers/message/i2o/iop.c
38287 +++ b/drivers/message/i2o/iop.c
38288 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
38289
38290 spin_lock_irqsave(&c->context_list_lock, flags);
38291
38292 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
38293 - atomic_inc(&c->context_list_counter);
38294 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
38295 + atomic_inc_unchecked(&c->context_list_counter);
38296
38297 - entry->context = atomic_read(&c->context_list_counter);
38298 + entry->context = atomic_read_unchecked(&c->context_list_counter);
38299
38300 list_add(&entry->list, &c->context_list);
38301
38302 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
38303
38304 #if BITS_PER_LONG == 64
38305 spin_lock_init(&c->context_list_lock);
38306 - atomic_set(&c->context_list_counter, 0);
38307 + atomic_set_unchecked(&c->context_list_counter, 0);
38308 INIT_LIST_HEAD(&c->context_list);
38309 #endif
38310
38311 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
38312 index 45ece11..8efa218 100644
38313 --- a/drivers/mfd/janz-cmodio.c
38314 +++ b/drivers/mfd/janz-cmodio.c
38315 @@ -13,6 +13,7 @@
38316
38317 #include <linux/kernel.h>
38318 #include <linux/module.h>
38319 +#include <linux/slab.h>
38320 #include <linux/init.h>
38321 #include <linux/pci.h>
38322 #include <linux/interrupt.h>
38323 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
38324 index a5f9888..1c0ed56 100644
38325 --- a/drivers/mfd/twl4030-irq.c
38326 +++ b/drivers/mfd/twl4030-irq.c
38327 @@ -35,6 +35,7 @@
38328 #include <linux/of.h>
38329 #include <linux/irqdomain.h>
38330 #include <linux/i2c/twl.h>
38331 +#include <asm/pgtable.h>
38332
38333 #include "twl-core.h"
38334
38335 @@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
38336 * Install an irq handler for each of the SIH modules;
38337 * clone dummy irq_chip since PIH can't *do* anything
38338 */
38339 - twl4030_irq_chip = dummy_irq_chip;
38340 - twl4030_irq_chip.name = "twl4030";
38341 + pax_open_kernel();
38342 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
38343 + *(const char **)&twl4030_irq_chip.name = "twl4030";
38344
38345 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38346 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38347 + pax_close_kernel();
38348
38349 for (i = irq_base; i < irq_end; i++) {
38350 irq_set_chip_and_handler(i, &twl4030_irq_chip,
38351 diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
38352 index 277a8db..0e0b754 100644
38353 --- a/drivers/mfd/twl6030-irq.c
38354 +++ b/drivers/mfd/twl6030-irq.c
38355 @@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
38356 * install an irq handler for each of the modules;
38357 * clone dummy irq_chip since PIH can't *do* anything
38358 */
38359 - twl6030_irq_chip = dummy_irq_chip;
38360 - twl6030_irq_chip.name = "twl6030";
38361 - twl6030_irq_chip.irq_set_type = NULL;
38362 - twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38363 + pax_open_kernel();
38364 + memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
38365 + *(const char **)&twl6030_irq_chip.name = "twl6030";
38366 + *(void **)&twl6030_irq_chip.irq_set_type = NULL;
38367 + *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38368 + pax_close_kernel();
38369
38370 for (i = irq_base; i < irq_end; i++) {
38371 irq_set_chip_and_handler(i, &twl6030_irq_chip,
38372 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
38373 index f428d86..274c368 100644
38374 --- a/drivers/misc/c2port/core.c
38375 +++ b/drivers/misc/c2port/core.c
38376 @@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
38377 mutex_init(&c2dev->mutex);
38378
38379 /* Create binary file */
38380 - c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38381 + pax_open_kernel();
38382 + *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38383 + pax_close_kernel();
38384 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
38385 if (unlikely(ret))
38386 goto error_device_create_bin_file;
38387 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
38388 index 3aa9a96..59cf685 100644
38389 --- a/drivers/misc/kgdbts.c
38390 +++ b/drivers/misc/kgdbts.c
38391 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
38392 char before[BREAK_INSTR_SIZE];
38393 char after[BREAK_INSTR_SIZE];
38394
38395 - probe_kernel_read(before, (char *)kgdbts_break_test,
38396 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
38397 BREAK_INSTR_SIZE);
38398 init_simple_test();
38399 ts.tst = plant_and_detach_test;
38400 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
38401 /* Activate test with initial breakpoint */
38402 if (!is_early)
38403 kgdb_breakpoint();
38404 - probe_kernel_read(after, (char *)kgdbts_break_test,
38405 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
38406 BREAK_INSTR_SIZE);
38407 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
38408 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
38409 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
38410 index 4a87e5c..76bdf5c 100644
38411 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
38412 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
38413 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
38414 * the lid is closed. This leads to interrupts as soon as a little move
38415 * is done.
38416 */
38417 - atomic_inc(&lis3->count);
38418 + atomic_inc_unchecked(&lis3->count);
38419
38420 wake_up_interruptible(&lis3->misc_wait);
38421 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
38422 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
38423 if (lis3->pm_dev)
38424 pm_runtime_get_sync(lis3->pm_dev);
38425
38426 - atomic_set(&lis3->count, 0);
38427 + atomic_set_unchecked(&lis3->count, 0);
38428 return 0;
38429 }
38430
38431 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
38432 add_wait_queue(&lis3->misc_wait, &wait);
38433 while (true) {
38434 set_current_state(TASK_INTERRUPTIBLE);
38435 - data = atomic_xchg(&lis3->count, 0);
38436 + data = atomic_xchg_unchecked(&lis3->count, 0);
38437 if (data)
38438 break;
38439
38440 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
38441 struct lis3lv02d, miscdev);
38442
38443 poll_wait(file, &lis3->misc_wait, wait);
38444 - if (atomic_read(&lis3->count))
38445 + if (atomic_read_unchecked(&lis3->count))
38446 return POLLIN | POLLRDNORM;
38447 return 0;
38448 }
38449 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
38450 index c439c82..1f20f57 100644
38451 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
38452 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
38453 @@ -297,7 +297,7 @@ struct lis3lv02d {
38454 struct input_polled_dev *idev; /* input device */
38455 struct platform_device *pdev; /* platform device */
38456 struct regulator_bulk_data regulators[2];
38457 - atomic_t count; /* interrupt count after last read */
38458 + atomic_unchecked_t count; /* interrupt count after last read */
38459 union axis_conversion ac; /* hw -> logical axis */
38460 int mapped_btns[3];
38461
38462 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
38463 index 2f30bad..c4c13d0 100644
38464 --- a/drivers/misc/sgi-gru/gruhandles.c
38465 +++ b/drivers/misc/sgi-gru/gruhandles.c
38466 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
38467 unsigned long nsec;
38468
38469 nsec = CLKS2NSEC(clks);
38470 - atomic_long_inc(&mcs_op_statistics[op].count);
38471 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
38472 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
38473 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
38474 if (mcs_op_statistics[op].max < nsec)
38475 mcs_op_statistics[op].max = nsec;
38476 }
38477 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
38478 index 950dbe9..eeef0f8 100644
38479 --- a/drivers/misc/sgi-gru/gruprocfs.c
38480 +++ b/drivers/misc/sgi-gru/gruprocfs.c
38481 @@ -32,9 +32,9 @@
38482
38483 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
38484
38485 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
38486 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
38487 {
38488 - unsigned long val = atomic_long_read(v);
38489 + unsigned long val = atomic_long_read_unchecked(v);
38490
38491 seq_printf(s, "%16lu %s\n", val, id);
38492 }
38493 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
38494
38495 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
38496 for (op = 0; op < mcsop_last; op++) {
38497 - count = atomic_long_read(&mcs_op_statistics[op].count);
38498 - total = atomic_long_read(&mcs_op_statistics[op].total);
38499 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
38500 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
38501 max = mcs_op_statistics[op].max;
38502 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
38503 count ? total / count : 0, max);
38504 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
38505 index 5c3ce24..4915ccb 100644
38506 --- a/drivers/misc/sgi-gru/grutables.h
38507 +++ b/drivers/misc/sgi-gru/grutables.h
38508 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
38509 * GRU statistics.
38510 */
38511 struct gru_stats_s {
38512 - atomic_long_t vdata_alloc;
38513 - atomic_long_t vdata_free;
38514 - atomic_long_t gts_alloc;
38515 - atomic_long_t gts_free;
38516 - atomic_long_t gms_alloc;
38517 - atomic_long_t gms_free;
38518 - atomic_long_t gts_double_allocate;
38519 - atomic_long_t assign_context;
38520 - atomic_long_t assign_context_failed;
38521 - atomic_long_t free_context;
38522 - atomic_long_t load_user_context;
38523 - atomic_long_t load_kernel_context;
38524 - atomic_long_t lock_kernel_context;
38525 - atomic_long_t unlock_kernel_context;
38526 - atomic_long_t steal_user_context;
38527 - atomic_long_t steal_kernel_context;
38528 - atomic_long_t steal_context_failed;
38529 - atomic_long_t nopfn;
38530 - atomic_long_t asid_new;
38531 - atomic_long_t asid_next;
38532 - atomic_long_t asid_wrap;
38533 - atomic_long_t asid_reuse;
38534 - atomic_long_t intr;
38535 - atomic_long_t intr_cbr;
38536 - atomic_long_t intr_tfh;
38537 - atomic_long_t intr_spurious;
38538 - atomic_long_t intr_mm_lock_failed;
38539 - atomic_long_t call_os;
38540 - atomic_long_t call_os_wait_queue;
38541 - atomic_long_t user_flush_tlb;
38542 - atomic_long_t user_unload_context;
38543 - atomic_long_t user_exception;
38544 - atomic_long_t set_context_option;
38545 - atomic_long_t check_context_retarget_intr;
38546 - atomic_long_t check_context_unload;
38547 - atomic_long_t tlb_dropin;
38548 - atomic_long_t tlb_preload_page;
38549 - atomic_long_t tlb_dropin_fail_no_asid;
38550 - atomic_long_t tlb_dropin_fail_upm;
38551 - atomic_long_t tlb_dropin_fail_invalid;
38552 - atomic_long_t tlb_dropin_fail_range_active;
38553 - atomic_long_t tlb_dropin_fail_idle;
38554 - atomic_long_t tlb_dropin_fail_fmm;
38555 - atomic_long_t tlb_dropin_fail_no_exception;
38556 - atomic_long_t tfh_stale_on_fault;
38557 - atomic_long_t mmu_invalidate_range;
38558 - atomic_long_t mmu_invalidate_page;
38559 - atomic_long_t flush_tlb;
38560 - atomic_long_t flush_tlb_gru;
38561 - atomic_long_t flush_tlb_gru_tgh;
38562 - atomic_long_t flush_tlb_gru_zero_asid;
38563 + atomic_long_unchecked_t vdata_alloc;
38564 + atomic_long_unchecked_t vdata_free;
38565 + atomic_long_unchecked_t gts_alloc;
38566 + atomic_long_unchecked_t gts_free;
38567 + atomic_long_unchecked_t gms_alloc;
38568 + atomic_long_unchecked_t gms_free;
38569 + atomic_long_unchecked_t gts_double_allocate;
38570 + atomic_long_unchecked_t assign_context;
38571 + atomic_long_unchecked_t assign_context_failed;
38572 + atomic_long_unchecked_t free_context;
38573 + atomic_long_unchecked_t load_user_context;
38574 + atomic_long_unchecked_t load_kernel_context;
38575 + atomic_long_unchecked_t lock_kernel_context;
38576 + atomic_long_unchecked_t unlock_kernel_context;
38577 + atomic_long_unchecked_t steal_user_context;
38578 + atomic_long_unchecked_t steal_kernel_context;
38579 + atomic_long_unchecked_t steal_context_failed;
38580 + atomic_long_unchecked_t nopfn;
38581 + atomic_long_unchecked_t asid_new;
38582 + atomic_long_unchecked_t asid_next;
38583 + atomic_long_unchecked_t asid_wrap;
38584 + atomic_long_unchecked_t asid_reuse;
38585 + atomic_long_unchecked_t intr;
38586 + atomic_long_unchecked_t intr_cbr;
38587 + atomic_long_unchecked_t intr_tfh;
38588 + atomic_long_unchecked_t intr_spurious;
38589 + atomic_long_unchecked_t intr_mm_lock_failed;
38590 + atomic_long_unchecked_t call_os;
38591 + atomic_long_unchecked_t call_os_wait_queue;
38592 + atomic_long_unchecked_t user_flush_tlb;
38593 + atomic_long_unchecked_t user_unload_context;
38594 + atomic_long_unchecked_t user_exception;
38595 + atomic_long_unchecked_t set_context_option;
38596 + atomic_long_unchecked_t check_context_retarget_intr;
38597 + atomic_long_unchecked_t check_context_unload;
38598 + atomic_long_unchecked_t tlb_dropin;
38599 + atomic_long_unchecked_t tlb_preload_page;
38600 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
38601 + atomic_long_unchecked_t tlb_dropin_fail_upm;
38602 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
38603 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
38604 + atomic_long_unchecked_t tlb_dropin_fail_idle;
38605 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
38606 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
38607 + atomic_long_unchecked_t tfh_stale_on_fault;
38608 + atomic_long_unchecked_t mmu_invalidate_range;
38609 + atomic_long_unchecked_t mmu_invalidate_page;
38610 + atomic_long_unchecked_t flush_tlb;
38611 + atomic_long_unchecked_t flush_tlb_gru;
38612 + atomic_long_unchecked_t flush_tlb_gru_tgh;
38613 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
38614
38615 - atomic_long_t copy_gpa;
38616 - atomic_long_t read_gpa;
38617 + atomic_long_unchecked_t copy_gpa;
38618 + atomic_long_unchecked_t read_gpa;
38619
38620 - atomic_long_t mesq_receive;
38621 - atomic_long_t mesq_receive_none;
38622 - atomic_long_t mesq_send;
38623 - atomic_long_t mesq_send_failed;
38624 - atomic_long_t mesq_noop;
38625 - atomic_long_t mesq_send_unexpected_error;
38626 - atomic_long_t mesq_send_lb_overflow;
38627 - atomic_long_t mesq_send_qlimit_reached;
38628 - atomic_long_t mesq_send_amo_nacked;
38629 - atomic_long_t mesq_send_put_nacked;
38630 - atomic_long_t mesq_page_overflow;
38631 - atomic_long_t mesq_qf_locked;
38632 - atomic_long_t mesq_qf_noop_not_full;
38633 - atomic_long_t mesq_qf_switch_head_failed;
38634 - atomic_long_t mesq_qf_unexpected_error;
38635 - atomic_long_t mesq_noop_unexpected_error;
38636 - atomic_long_t mesq_noop_lb_overflow;
38637 - atomic_long_t mesq_noop_qlimit_reached;
38638 - atomic_long_t mesq_noop_amo_nacked;
38639 - atomic_long_t mesq_noop_put_nacked;
38640 - atomic_long_t mesq_noop_page_overflow;
38641 + atomic_long_unchecked_t mesq_receive;
38642 + atomic_long_unchecked_t mesq_receive_none;
38643 + atomic_long_unchecked_t mesq_send;
38644 + atomic_long_unchecked_t mesq_send_failed;
38645 + atomic_long_unchecked_t mesq_noop;
38646 + atomic_long_unchecked_t mesq_send_unexpected_error;
38647 + atomic_long_unchecked_t mesq_send_lb_overflow;
38648 + atomic_long_unchecked_t mesq_send_qlimit_reached;
38649 + atomic_long_unchecked_t mesq_send_amo_nacked;
38650 + atomic_long_unchecked_t mesq_send_put_nacked;
38651 + atomic_long_unchecked_t mesq_page_overflow;
38652 + atomic_long_unchecked_t mesq_qf_locked;
38653 + atomic_long_unchecked_t mesq_qf_noop_not_full;
38654 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
38655 + atomic_long_unchecked_t mesq_qf_unexpected_error;
38656 + atomic_long_unchecked_t mesq_noop_unexpected_error;
38657 + atomic_long_unchecked_t mesq_noop_lb_overflow;
38658 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
38659 + atomic_long_unchecked_t mesq_noop_amo_nacked;
38660 + atomic_long_unchecked_t mesq_noop_put_nacked;
38661 + atomic_long_unchecked_t mesq_noop_page_overflow;
38662
38663 };
38664
38665 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
38666 tghop_invalidate, mcsop_last};
38667
38668 struct mcs_op_statistic {
38669 - atomic_long_t count;
38670 - atomic_long_t total;
38671 + atomic_long_unchecked_t count;
38672 + atomic_long_unchecked_t total;
38673 unsigned long max;
38674 };
38675
38676 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
38677
38678 #define STAT(id) do { \
38679 if (gru_options & OPT_STATS) \
38680 - atomic_long_inc(&gru_stats.id); \
38681 + atomic_long_inc_unchecked(&gru_stats.id); \
38682 } while (0)
38683
38684 #ifdef CONFIG_SGI_GRU_DEBUG
38685 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
38686 index c862cd4..0d176fe 100644
38687 --- a/drivers/misc/sgi-xp/xp.h
38688 +++ b/drivers/misc/sgi-xp/xp.h
38689 @@ -288,7 +288,7 @@ struct xpc_interface {
38690 xpc_notify_func, void *);
38691 void (*received) (short, int, void *);
38692 enum xp_retval (*partid_to_nasids) (short, void *);
38693 -};
38694 +} __no_const;
38695
38696 extern struct xpc_interface xpc_interface;
38697
38698 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
38699 index b94d5f7..7f494c5 100644
38700 --- a/drivers/misc/sgi-xp/xpc.h
38701 +++ b/drivers/misc/sgi-xp/xpc.h
38702 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
38703 void (*received_payload) (struct xpc_channel *, void *);
38704 void (*notify_senders_of_disconnect) (struct xpc_channel *);
38705 };
38706 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
38707
38708 /* struct xpc_partition act_state values (for XPC HB) */
38709
38710 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
38711 /* found in xpc_main.c */
38712 extern struct device *xpc_part;
38713 extern struct device *xpc_chan;
38714 -extern struct xpc_arch_operations xpc_arch_ops;
38715 +extern xpc_arch_operations_no_const xpc_arch_ops;
38716 extern int xpc_disengage_timelimit;
38717 extern int xpc_disengage_timedout;
38718 extern int xpc_activate_IRQ_rcvd;
38719 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
38720 index d971817..33bdca5 100644
38721 --- a/drivers/misc/sgi-xp/xpc_main.c
38722 +++ b/drivers/misc/sgi-xp/xpc_main.c
38723 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
38724 .notifier_call = xpc_system_die,
38725 };
38726
38727 -struct xpc_arch_operations xpc_arch_ops;
38728 +xpc_arch_operations_no_const xpc_arch_ops;
38729
38730 /*
38731 * Timer function to enforce the timelimit on the partition disengage.
38732 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
38733
38734 if (((die_args->trapnr == X86_TRAP_MF) ||
38735 (die_args->trapnr == X86_TRAP_XF)) &&
38736 - !user_mode_vm(die_args->regs))
38737 + !user_mode(die_args->regs))
38738 xpc_die_deactivate();
38739
38740 break;
38741 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
38742 index 6d8f701..35b6369 100644
38743 --- a/drivers/mmc/core/mmc_ops.c
38744 +++ b/drivers/mmc/core/mmc_ops.c
38745 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
38746 void *data_buf;
38747 int is_on_stack;
38748
38749 - is_on_stack = object_is_on_stack(buf);
38750 + is_on_stack = object_starts_on_stack(buf);
38751 if (is_on_stack) {
38752 /*
38753 * dma onto stack is unsafe/nonportable, but callers to this
38754 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
38755 index 53b8fd9..615b462 100644
38756 --- a/drivers/mmc/host/dw_mmc.h
38757 +++ b/drivers/mmc/host/dw_mmc.h
38758 @@ -205,5 +205,5 @@ struct dw_mci_drv_data {
38759 int (*parse_dt)(struct dw_mci *host);
38760 int (*setup_bus)(struct dw_mci *host,
38761 struct device_node *slot_np, u8 bus_width);
38762 -};
38763 +} __do_const;
38764 #endif /* _DW_MMC_H_ */
38765 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
38766 index 82a8de1..3c56ccb 100644
38767 --- a/drivers/mmc/host/sdhci-s3c.c
38768 +++ b/drivers/mmc/host/sdhci-s3c.c
38769 @@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
38770 * we can use overriding functions instead of default.
38771 */
38772 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
38773 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
38774 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
38775 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
38776 + pax_open_kernel();
38777 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
38778 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
38779 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
38780 + pax_close_kernel();
38781 }
38782
38783 /* It supports additional host capabilities if needed */
38784 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
38785 index a4eb8b5..8c0628f 100644
38786 --- a/drivers/mtd/devices/doc2000.c
38787 +++ b/drivers/mtd/devices/doc2000.c
38788 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
38789
38790 /* The ECC will not be calculated correctly if less than 512 is written */
38791 /* DBB-
38792 - if (len != 0x200 && eccbuf)
38793 + if (len != 0x200)
38794 printk(KERN_WARNING
38795 "ECC needs a full sector write (adr: %lx size %lx)\n",
38796 (long) to, (long) len);
38797 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
38798 index 0c8bb6b..6f35deb 100644
38799 --- a/drivers/mtd/nand/denali.c
38800 +++ b/drivers/mtd/nand/denali.c
38801 @@ -24,6 +24,7 @@
38802 #include <linux/slab.h>
38803 #include <linux/mtd/mtd.h>
38804 #include <linux/module.h>
38805 +#include <linux/slab.h>
38806
38807 #include "denali.h"
38808
38809 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
38810 index 51b9d6a..52af9a7 100644
38811 --- a/drivers/mtd/nftlmount.c
38812 +++ b/drivers/mtd/nftlmount.c
38813 @@ -24,6 +24,7 @@
38814 #include <asm/errno.h>
38815 #include <linux/delay.h>
38816 #include <linux/slab.h>
38817 +#include <linux/sched.h>
38818 #include <linux/mtd/mtd.h>
38819 #include <linux/mtd/nand.h>
38820 #include <linux/mtd/nftl.h>
38821 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
38822 index 8dd6ba5..419cc1d 100644
38823 --- a/drivers/mtd/sm_ftl.c
38824 +++ b/drivers/mtd/sm_ftl.c
38825 @@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
38826 #define SM_CIS_VENDOR_OFFSET 0x59
38827 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
38828 {
38829 - struct attribute_group *attr_group;
38830 + attribute_group_no_const *attr_group;
38831 struct attribute **attributes;
38832 struct sm_sysfs_attribute *vendor_attribute;
38833
38834 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
38835 index b7d45f3..b5c89d9 100644
38836 --- a/drivers/net/bonding/bond_main.c
38837 +++ b/drivers/net/bonding/bond_main.c
38838 @@ -4861,7 +4861,7 @@ static unsigned int bond_get_num_tx_queues(void)
38839 return tx_queues;
38840 }
38841
38842 -static struct rtnl_link_ops bond_link_ops __read_mostly = {
38843 +static struct rtnl_link_ops bond_link_ops = {
38844 .kind = "bond",
38845 .priv_size = sizeof(struct bonding),
38846 .setup = bond_setup,
38847 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
38848 index 70dba5d..11a0919 100644
38849 --- a/drivers/net/ethernet/8390/ax88796.c
38850 +++ b/drivers/net/ethernet/8390/ax88796.c
38851 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
38852 if (ax->plat->reg_offsets)
38853 ei_local->reg_offset = ax->plat->reg_offsets;
38854 else {
38855 + resource_size_t _mem_size = mem_size;
38856 + do_div(_mem_size, 0x18);
38857 ei_local->reg_offset = ax->reg_offsets;
38858 for (ret = 0; ret < 0x18; ret++)
38859 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
38860 + ax->reg_offsets[ret] = _mem_size * ret;
38861 }
38862
38863 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
38864 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
38865 index 0991534..8098e92 100644
38866 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
38867 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
38868 @@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
38869 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
38870 {
38871 /* RX_MODE controlling object */
38872 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
38873 + bnx2x_init_rx_mode_obj(bp);
38874
38875 /* multicast configuration controlling object */
38876 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
38877 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
38878 index 09b625e..15b16fe 100644
38879 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
38880 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
38881 @@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
38882 return rc;
38883 }
38884
38885 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
38886 - struct bnx2x_rx_mode_obj *o)
38887 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
38888 {
38889 if (CHIP_IS_E1x(bp)) {
38890 - o->wait_comp = bnx2x_empty_rx_mode_wait;
38891 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
38892 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
38893 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
38894 } else {
38895 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
38896 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
38897 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
38898 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
38899 }
38900 }
38901
38902 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
38903 index adbd91b..58ec94a 100644
38904 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
38905 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
38906 @@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
38907
38908 /********************* RX MODE ****************/
38909
38910 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
38911 - struct bnx2x_rx_mode_obj *o);
38912 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
38913
38914 /**
38915 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
38916 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
38917 index d330e81..ce1fb9a 100644
38918 --- a/drivers/net/ethernet/broadcom/tg3.h
38919 +++ b/drivers/net/ethernet/broadcom/tg3.h
38920 @@ -146,6 +146,7 @@
38921 #define CHIPREV_ID_5750_A0 0x4000
38922 #define CHIPREV_ID_5750_A1 0x4001
38923 #define CHIPREV_ID_5750_A3 0x4003
38924 +#define CHIPREV_ID_5750_C1 0x4201
38925 #define CHIPREV_ID_5750_C2 0x4202
38926 #define CHIPREV_ID_5752_A0_HW 0x5000
38927 #define CHIPREV_ID_5752_A0 0x6000
38928 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
38929 index 8cffcdf..aadf043 100644
38930 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
38931 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
38932 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
38933 */
38934 struct l2t_skb_cb {
38935 arp_failure_handler_func arp_failure_handler;
38936 -};
38937 +} __no_const;
38938
38939 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
38940
38941 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
38942 index 4c83003..2a2a5b9 100644
38943 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
38944 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
38945 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38946 for (i=0; i<ETH_ALEN; i++) {
38947 tmp.addr[i] = dev->dev_addr[i];
38948 }
38949 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38950 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38951 break;
38952
38953 case DE4X5_SET_HWADDR: /* Set the hardware address */
38954 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38955 spin_lock_irqsave(&lp->lock, flags);
38956 memcpy(&statbuf, &lp->pktStats, ioc->len);
38957 spin_unlock_irqrestore(&lp->lock, flags);
38958 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
38959 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
38960 return -EFAULT;
38961 break;
38962 }
38963 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
38964 index 4d6f3c5..6169e60 100644
38965 --- a/drivers/net/ethernet/emulex/benet/be_main.c
38966 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
38967 @@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
38968
38969 if (wrapped)
38970 newacc += 65536;
38971 - ACCESS_ONCE(*acc) = newacc;
38972 + ACCESS_ONCE_RW(*acc) = newacc;
38973 }
38974
38975 void be_parse_stats(struct be_adapter *adapter)
38976 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
38977 index 74d749e..eefb1bd 100644
38978 --- a/drivers/net/ethernet/faraday/ftgmac100.c
38979 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
38980 @@ -31,6 +31,8 @@
38981 #include <linux/netdevice.h>
38982 #include <linux/phy.h>
38983 #include <linux/platform_device.h>
38984 +#include <linux/interrupt.h>
38985 +#include <linux/irqreturn.h>
38986 #include <net/ip.h>
38987
38988 #include "ftgmac100.h"
38989 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
38990 index b901a01..1ff32ee 100644
38991 --- a/drivers/net/ethernet/faraday/ftmac100.c
38992 +++ b/drivers/net/ethernet/faraday/ftmac100.c
38993 @@ -31,6 +31,8 @@
38994 #include <linux/module.h>
38995 #include <linux/netdevice.h>
38996 #include <linux/platform_device.h>
38997 +#include <linux/interrupt.h>
38998 +#include <linux/irqreturn.h>
38999
39000 #include "ftmac100.h"
39001
39002 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39003 index bb9256a..56d8752 100644
39004 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39005 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39006 @@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
39007 }
39008
39009 /* update the base incval used to calculate frequency adjustment */
39010 - ACCESS_ONCE(adapter->base_incval) = incval;
39011 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
39012 smp_mb();
39013
39014 /* need lock to prevent incorrect read while modifying cyclecounter */
39015 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39016 index fbe5363..266b4e3 100644
39017 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
39018 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39019 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39020 struct __vxge_hw_fifo *fifo;
39021 struct vxge_hw_fifo_config *config;
39022 u32 txdl_size, txdl_per_memblock;
39023 - struct vxge_hw_mempool_cbs fifo_mp_callback;
39024 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
39025 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
39026 + };
39027 +
39028 struct __vxge_hw_virtualpath *vpath;
39029
39030 if ((vp == NULL) || (attr == NULL)) {
39031 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39032 goto exit;
39033 }
39034
39035 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
39036 -
39037 fifo->mempool =
39038 __vxge_hw_mempool_create(vpath->hldev,
39039 fifo->config->memblock_size,
39040 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
39041 index 998974f..ecd26db 100644
39042 --- a/drivers/net/ethernet/realtek/r8169.c
39043 +++ b/drivers/net/ethernet/realtek/r8169.c
39044 @@ -741,22 +741,22 @@ struct rtl8169_private {
39045 struct mdio_ops {
39046 void (*write)(struct rtl8169_private *, int, int);
39047 int (*read)(struct rtl8169_private *, int);
39048 - } mdio_ops;
39049 + } __no_const mdio_ops;
39050
39051 struct pll_power_ops {
39052 void (*down)(struct rtl8169_private *);
39053 void (*up)(struct rtl8169_private *);
39054 - } pll_power_ops;
39055 + } __no_const pll_power_ops;
39056
39057 struct jumbo_ops {
39058 void (*enable)(struct rtl8169_private *);
39059 void (*disable)(struct rtl8169_private *);
39060 - } jumbo_ops;
39061 + } __no_const jumbo_ops;
39062
39063 struct csi_ops {
39064 void (*write)(struct rtl8169_private *, int, int);
39065 u32 (*read)(struct rtl8169_private *, int);
39066 - } csi_ops;
39067 + } __no_const csi_ops;
39068
39069 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
39070 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
39071 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
39072 index 0767043f..08c2553 100644
39073 --- a/drivers/net/ethernet/sfc/ptp.c
39074 +++ b/drivers/net/ethernet/sfc/ptp.c
39075 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
39076 (u32)((u64)ptp->start.dma_addr >> 32));
39077
39078 /* Clear flag that signals MC ready */
39079 - ACCESS_ONCE(*start) = 0;
39080 + ACCESS_ONCE_RW(*start) = 0;
39081 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
39082 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
39083
39084 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39085 index 0c74a70..3bc6f68 100644
39086 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39087 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39088 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
39089
39090 writel(value, ioaddr + MMC_CNTRL);
39091
39092 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39093 - MMC_CNTRL, value);
39094 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39095 +// MMC_CNTRL, value);
39096 }
39097
39098 /* To mask all all interrupts.*/
39099 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
39100 index e6fe0d8..2b7d752 100644
39101 --- a/drivers/net/hyperv/hyperv_net.h
39102 +++ b/drivers/net/hyperv/hyperv_net.h
39103 @@ -101,7 +101,7 @@ struct rndis_device {
39104
39105 enum rndis_device_state state;
39106 bool link_state;
39107 - atomic_t new_req_id;
39108 + atomic_unchecked_t new_req_id;
39109
39110 spinlock_t request_lock;
39111 struct list_head req_list;
39112 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
39113 index 2b657d4..9903bc0 100644
39114 --- a/drivers/net/hyperv/rndis_filter.c
39115 +++ b/drivers/net/hyperv/rndis_filter.c
39116 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
39117 * template
39118 */
39119 set = &rndis_msg->msg.set_req;
39120 - set->req_id = atomic_inc_return(&dev->new_req_id);
39121 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39122
39123 /* Add to the request list */
39124 spin_lock_irqsave(&dev->request_lock, flags);
39125 @@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
39126
39127 /* Setup the rndis set */
39128 halt = &request->request_msg.msg.halt_req;
39129 - halt->req_id = atomic_inc_return(&dev->new_req_id);
39130 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39131
39132 /* Ignore return since this msg is optional. */
39133 rndis_filter_send_request(dev, request);
39134 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
39135 index 1e9cb0b..7839125 100644
39136 --- a/drivers/net/ieee802154/fakehard.c
39137 +++ b/drivers/net/ieee802154/fakehard.c
39138 @@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
39139 phy->transmit_power = 0xbf;
39140
39141 dev->netdev_ops = &fake_ops;
39142 - dev->ml_priv = &fake_mlme;
39143 + dev->ml_priv = (void *)&fake_mlme;
39144
39145 priv = netdev_priv(dev);
39146 priv->phy = phy;
39147 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
39148 index d3fb97d..19520c7 100644
39149 --- a/drivers/net/macvlan.c
39150 +++ b/drivers/net/macvlan.c
39151 @@ -851,13 +851,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
39152 int macvlan_link_register(struct rtnl_link_ops *ops)
39153 {
39154 /* common fields */
39155 - ops->priv_size = sizeof(struct macvlan_dev);
39156 - ops->validate = macvlan_validate;
39157 - ops->maxtype = IFLA_MACVLAN_MAX;
39158 - ops->policy = macvlan_policy;
39159 - ops->changelink = macvlan_changelink;
39160 - ops->get_size = macvlan_get_size;
39161 - ops->fill_info = macvlan_fill_info;
39162 + pax_open_kernel();
39163 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
39164 + *(void **)&ops->validate = macvlan_validate;
39165 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
39166 + *(const void **)&ops->policy = macvlan_policy;
39167 + *(void **)&ops->changelink = macvlan_changelink;
39168 + *(void **)&ops->get_size = macvlan_get_size;
39169 + *(void **)&ops->fill_info = macvlan_fill_info;
39170 + pax_close_kernel();
39171
39172 return rtnl_link_register(ops);
39173 };
39174 @@ -913,7 +915,7 @@ static int macvlan_device_event(struct notifier_block *unused,
39175 return NOTIFY_DONE;
39176 }
39177
39178 -static struct notifier_block macvlan_notifier_block __read_mostly = {
39179 +static struct notifier_block macvlan_notifier_block = {
39180 .notifier_call = macvlan_device_event,
39181 };
39182
39183 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
39184 index 0f0f9ce..0ca5819 100644
39185 --- a/drivers/net/macvtap.c
39186 +++ b/drivers/net/macvtap.c
39187 @@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
39188 return NOTIFY_DONE;
39189 }
39190
39191 -static struct notifier_block macvtap_notifier_block __read_mostly = {
39192 +static struct notifier_block macvtap_notifier_block = {
39193 .notifier_call = macvtap_device_event,
39194 };
39195
39196 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
39197 index daec9b0..6428fcb 100644
39198 --- a/drivers/net/phy/mdio-bitbang.c
39199 +++ b/drivers/net/phy/mdio-bitbang.c
39200 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
39201 struct mdiobb_ctrl *ctrl = bus->priv;
39202
39203 module_put(ctrl->ops->owner);
39204 + mdiobus_unregister(bus);
39205 mdiobus_free(bus);
39206 }
39207 EXPORT_SYMBOL(free_mdio_bitbang);
39208 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
39209 index 508570e..f706dc7 100644
39210 --- a/drivers/net/ppp/ppp_generic.c
39211 +++ b/drivers/net/ppp/ppp_generic.c
39212 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39213 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
39214 struct ppp_stats stats;
39215 struct ppp_comp_stats cstats;
39216 - char *vers;
39217
39218 switch (cmd) {
39219 case SIOCGPPPSTATS:
39220 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39221 break;
39222
39223 case SIOCGPPPVER:
39224 - vers = PPP_VERSION;
39225 - if (copy_to_user(addr, vers, strlen(vers) + 1))
39226 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
39227 break;
39228 err = 0;
39229 break;
39230 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
39231 index ad86660..9fd0884 100644
39232 --- a/drivers/net/team/team.c
39233 +++ b/drivers/net/team/team.c
39234 @@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
39235 return NOTIFY_DONE;
39236 }
39237
39238 -static struct notifier_block team_notifier_block __read_mostly = {
39239 +static struct notifier_block team_notifier_block = {
39240 .notifier_call = team_device_event,
39241 };
39242
39243 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
39244 index 2917a86..edd463f 100644
39245 --- a/drivers/net/tun.c
39246 +++ b/drivers/net/tun.c
39247 @@ -1836,7 +1836,7 @@ unlock:
39248 }
39249
39250 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39251 - unsigned long arg, int ifreq_len)
39252 + unsigned long arg, size_t ifreq_len)
39253 {
39254 struct tun_file *tfile = file->private_data;
39255 struct tun_struct *tun;
39256 @@ -1848,6 +1848,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39257 int vnet_hdr_sz;
39258 int ret;
39259
39260 + if (ifreq_len > sizeof ifr)
39261 + return -EFAULT;
39262 +
39263 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
39264 if (copy_from_user(&ifr, argp, ifreq_len))
39265 return -EFAULT;
39266 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39267 index cd8ccb2..cff5144 100644
39268 --- a/drivers/net/usb/hso.c
39269 +++ b/drivers/net/usb/hso.c
39270 @@ -71,7 +71,7 @@
39271 #include <asm/byteorder.h>
39272 #include <linux/serial_core.h>
39273 #include <linux/serial.h>
39274 -
39275 +#include <asm/local.h>
39276
39277 #define MOD_AUTHOR "Option Wireless"
39278 #define MOD_DESCRIPTION "USB High Speed Option driver"
39279 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39280 struct urb *urb;
39281
39282 urb = serial->rx_urb[0];
39283 - if (serial->port.count > 0) {
39284 + if (atomic_read(&serial->port.count) > 0) {
39285 count = put_rxbuf_data(urb, serial);
39286 if (count == -1)
39287 return;
39288 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39289 DUMP1(urb->transfer_buffer, urb->actual_length);
39290
39291 /* Anyone listening? */
39292 - if (serial->port.count == 0)
39293 + if (atomic_read(&serial->port.count) == 0)
39294 return;
39295
39296 if (status == 0) {
39297 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39298 tty_port_tty_set(&serial->port, tty);
39299
39300 /* check for port already opened, if not set the termios */
39301 - serial->port.count++;
39302 - if (serial->port.count == 1) {
39303 + if (atomic_inc_return(&serial->port.count) == 1) {
39304 serial->rx_state = RX_IDLE;
39305 /* Force default termio settings */
39306 _hso_serial_set_termios(tty, NULL);
39307 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39308 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39309 if (result) {
39310 hso_stop_serial_device(serial->parent);
39311 - serial->port.count--;
39312 + atomic_dec(&serial->port.count);
39313 kref_put(&serial->parent->ref, hso_serial_ref_free);
39314 }
39315 } else {
39316 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39317
39318 /* reset the rts and dtr */
39319 /* do the actual close */
39320 - serial->port.count--;
39321 + atomic_dec(&serial->port.count);
39322
39323 - if (serial->port.count <= 0) {
39324 - serial->port.count = 0;
39325 + if (atomic_read(&serial->port.count) <= 0) {
39326 + atomic_set(&serial->port.count, 0);
39327 tty_port_tty_set(&serial->port, NULL);
39328 if (!usb_gone)
39329 hso_stop_serial_device(serial->parent);
39330 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39331
39332 /* the actual setup */
39333 spin_lock_irqsave(&serial->serial_lock, flags);
39334 - if (serial->port.count)
39335 + if (atomic_read(&serial->port.count))
39336 _hso_serial_set_termios(tty, old);
39337 else
39338 tty->termios = *old;
39339 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
39340 D1("Pending read interrupt on port %d\n", i);
39341 spin_lock(&serial->serial_lock);
39342 if (serial->rx_state == RX_IDLE &&
39343 - serial->port.count > 0) {
39344 + atomic_read(&serial->port.count) > 0) {
39345 /* Setup and send a ctrl req read on
39346 * port i */
39347 if (!serial->rx_urb_filled[0]) {
39348 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
39349 /* Start all serial ports */
39350 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39351 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39352 - if (dev2ser(serial_table[i])->port.count) {
39353 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
39354 result =
39355 hso_start_serial_device(serial_table[i], GFP_NOIO);
39356 hso_kick_transmit(dev2ser(serial_table[i]));
39357 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
39358 index 656230e..15525a8 100644
39359 --- a/drivers/net/vxlan.c
39360 +++ b/drivers/net/vxlan.c
39361 @@ -1428,7 +1428,7 @@ nla_put_failure:
39362 return -EMSGSIZE;
39363 }
39364
39365 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
39366 +static struct rtnl_link_ops vxlan_link_ops = {
39367 .kind = "vxlan",
39368 .maxtype = IFLA_VXLAN_MAX,
39369 .policy = vxlan_policy,
39370 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39371 index 8d78253..bebbb68 100644
39372 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39373 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39374 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39375 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
39376 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
39377
39378 - ACCESS_ONCE(ads->ds_link) = i->link;
39379 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
39380 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
39381 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
39382
39383 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
39384 ctl6 = SM(i->keytype, AR_EncrType);
39385 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39386
39387 if ((i->is_first || i->is_last) &&
39388 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
39389 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
39390 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
39391 | set11nTries(i->rates, 1)
39392 | set11nTries(i->rates, 2)
39393 | set11nTries(i->rates, 3)
39394 | (i->dur_update ? AR_DurUpdateEna : 0)
39395 | SM(0, AR_BurstDur);
39396
39397 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
39398 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
39399 | set11nRate(i->rates, 1)
39400 | set11nRate(i->rates, 2)
39401 | set11nRate(i->rates, 3);
39402 } else {
39403 - ACCESS_ONCE(ads->ds_ctl2) = 0;
39404 - ACCESS_ONCE(ads->ds_ctl3) = 0;
39405 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
39406 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
39407 }
39408
39409 if (!i->is_first) {
39410 - ACCESS_ONCE(ads->ds_ctl0) = 0;
39411 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39412 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39413 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
39414 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39415 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39416 return;
39417 }
39418
39419 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39420 break;
39421 }
39422
39423 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39424 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39425 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39426 | SM(i->txpower, AR_XmitPower)
39427 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39428 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39429 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
39430 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
39431
39432 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39433 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39434 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39435 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39436
39437 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
39438 return;
39439
39440 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39441 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39442 | set11nPktDurRTSCTS(i->rates, 1);
39443
39444 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39445 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39446 | set11nPktDurRTSCTS(i->rates, 3);
39447
39448 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39449 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39450 | set11nRateFlags(i->rates, 1)
39451 | set11nRateFlags(i->rates, 2)
39452 | set11nRateFlags(i->rates, 3)
39453 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39454 index 301bf72..3f5654f 100644
39455 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39456 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39457 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39458 (i->qcu << AR_TxQcuNum_S) | desc_len;
39459
39460 checksum += val;
39461 - ACCESS_ONCE(ads->info) = val;
39462 + ACCESS_ONCE_RW(ads->info) = val;
39463
39464 checksum += i->link;
39465 - ACCESS_ONCE(ads->link) = i->link;
39466 + ACCESS_ONCE_RW(ads->link) = i->link;
39467
39468 checksum += i->buf_addr[0];
39469 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
39470 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
39471 checksum += i->buf_addr[1];
39472 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
39473 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
39474 checksum += i->buf_addr[2];
39475 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
39476 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
39477 checksum += i->buf_addr[3];
39478 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
39479 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
39480
39481 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
39482 - ACCESS_ONCE(ads->ctl3) = val;
39483 + ACCESS_ONCE_RW(ads->ctl3) = val;
39484 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
39485 - ACCESS_ONCE(ads->ctl5) = val;
39486 + ACCESS_ONCE_RW(ads->ctl5) = val;
39487 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
39488 - ACCESS_ONCE(ads->ctl7) = val;
39489 + ACCESS_ONCE_RW(ads->ctl7) = val;
39490 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
39491 - ACCESS_ONCE(ads->ctl9) = val;
39492 + ACCESS_ONCE_RW(ads->ctl9) = val;
39493
39494 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
39495 - ACCESS_ONCE(ads->ctl10) = checksum;
39496 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
39497
39498 if (i->is_first || i->is_last) {
39499 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
39500 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
39501 | set11nTries(i->rates, 1)
39502 | set11nTries(i->rates, 2)
39503 | set11nTries(i->rates, 3)
39504 | (i->dur_update ? AR_DurUpdateEna : 0)
39505 | SM(0, AR_BurstDur);
39506
39507 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
39508 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
39509 | set11nRate(i->rates, 1)
39510 | set11nRate(i->rates, 2)
39511 | set11nRate(i->rates, 3);
39512 } else {
39513 - ACCESS_ONCE(ads->ctl13) = 0;
39514 - ACCESS_ONCE(ads->ctl14) = 0;
39515 + ACCESS_ONCE_RW(ads->ctl13) = 0;
39516 + ACCESS_ONCE_RW(ads->ctl14) = 0;
39517 }
39518
39519 ads->ctl20 = 0;
39520 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39521
39522 ctl17 = SM(i->keytype, AR_EncrType);
39523 if (!i->is_first) {
39524 - ACCESS_ONCE(ads->ctl11) = 0;
39525 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39526 - ACCESS_ONCE(ads->ctl15) = 0;
39527 - ACCESS_ONCE(ads->ctl16) = 0;
39528 - ACCESS_ONCE(ads->ctl17) = ctl17;
39529 - ACCESS_ONCE(ads->ctl18) = 0;
39530 - ACCESS_ONCE(ads->ctl19) = 0;
39531 + ACCESS_ONCE_RW(ads->ctl11) = 0;
39532 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39533 + ACCESS_ONCE_RW(ads->ctl15) = 0;
39534 + ACCESS_ONCE_RW(ads->ctl16) = 0;
39535 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39536 + ACCESS_ONCE_RW(ads->ctl18) = 0;
39537 + ACCESS_ONCE_RW(ads->ctl19) = 0;
39538 return;
39539 }
39540
39541 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39542 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39543 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39544 | SM(i->txpower, AR_XmitPower)
39545 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39546 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39547 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
39548 ctl12 |= SM(val, AR_PAPRDChainMask);
39549
39550 - ACCESS_ONCE(ads->ctl12) = ctl12;
39551 - ACCESS_ONCE(ads->ctl17) = ctl17;
39552 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
39553 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39554
39555 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39556 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39557 | set11nPktDurRTSCTS(i->rates, 1);
39558
39559 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39560 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39561 | set11nPktDurRTSCTS(i->rates, 3);
39562
39563 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
39564 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
39565 | set11nRateFlags(i->rates, 1)
39566 | set11nRateFlags(i->rates, 2)
39567 | set11nRateFlags(i->rates, 3)
39568 | SM(i->rtscts_rate, AR_RTSCTSRate);
39569
39570 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
39571 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
39572 }
39573
39574 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
39575 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
39576 index 9d26fc5..60d9f14 100644
39577 --- a/drivers/net/wireless/ath/ath9k/hw.h
39578 +++ b/drivers/net/wireless/ath/ath9k/hw.h
39579 @@ -658,7 +658,7 @@ struct ath_hw_private_ops {
39580
39581 /* ANI */
39582 void (*ani_cache_ini_regs)(struct ath_hw *ah);
39583 -};
39584 +} __no_const;
39585
39586 /**
39587 * struct ath_hw_ops - callbacks used by hardware code and driver code
39588 @@ -688,7 +688,7 @@ struct ath_hw_ops {
39589 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
39590 struct ath_hw_antcomb_conf *antconf);
39591 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
39592 -};
39593 +} __no_const;
39594
39595 struct ath_nf_limits {
39596 s16 max;
39597 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
39598 index 3726cd6..b655808 100644
39599 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
39600 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
39601 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39602 */
39603 if (il3945_mod_params.disable_hw_scan) {
39604 D_INFO("Disabling hw_scan\n");
39605 - il3945_mac_ops.hw_scan = NULL;
39606 + pax_open_kernel();
39607 + *(void **)&il3945_mac_ops.hw_scan = NULL;
39608 + pax_close_kernel();
39609 }
39610
39611 D_INFO("*** LOAD DRIVER ***\n");
39612 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39613 index 5b9533e..7733880 100644
39614 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39615 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39616 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
39617 {
39618 struct iwl_priv *priv = file->private_data;
39619 char buf[64];
39620 - int buf_size;
39621 + size_t buf_size;
39622 u32 offset, len;
39623
39624 memset(buf, 0, sizeof(buf));
39625 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
39626 struct iwl_priv *priv = file->private_data;
39627
39628 char buf[8];
39629 - int buf_size;
39630 + size_t buf_size;
39631 u32 reset_flag;
39632
39633 memset(buf, 0, sizeof(buf));
39634 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
39635 {
39636 struct iwl_priv *priv = file->private_data;
39637 char buf[8];
39638 - int buf_size;
39639 + size_t buf_size;
39640 int ht40;
39641
39642 memset(buf, 0, sizeof(buf));
39643 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
39644 {
39645 struct iwl_priv *priv = file->private_data;
39646 char buf[8];
39647 - int buf_size;
39648 + size_t buf_size;
39649 int value;
39650
39651 memset(buf, 0, sizeof(buf));
39652 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
39653 {
39654 struct iwl_priv *priv = file->private_data;
39655 char buf[8];
39656 - int buf_size;
39657 + size_t buf_size;
39658 int clear;
39659
39660 memset(buf, 0, sizeof(buf));
39661 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
39662 {
39663 struct iwl_priv *priv = file->private_data;
39664 char buf[8];
39665 - int buf_size;
39666 + size_t buf_size;
39667 int trace;
39668
39669 memset(buf, 0, sizeof(buf));
39670 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
39671 {
39672 struct iwl_priv *priv = file->private_data;
39673 char buf[8];
39674 - int buf_size;
39675 + size_t buf_size;
39676 int missed;
39677
39678 memset(buf, 0, sizeof(buf));
39679 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
39680
39681 struct iwl_priv *priv = file->private_data;
39682 char buf[8];
39683 - int buf_size;
39684 + size_t buf_size;
39685 int plcp;
39686
39687 memset(buf, 0, sizeof(buf));
39688 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
39689
39690 struct iwl_priv *priv = file->private_data;
39691 char buf[8];
39692 - int buf_size;
39693 + size_t buf_size;
39694 int flush;
39695
39696 memset(buf, 0, sizeof(buf));
39697 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
39698
39699 struct iwl_priv *priv = file->private_data;
39700 char buf[8];
39701 - int buf_size;
39702 + size_t buf_size;
39703 int rts;
39704
39705 if (!priv->cfg->ht_params)
39706 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
39707 {
39708 struct iwl_priv *priv = file->private_data;
39709 char buf[8];
39710 - int buf_size;
39711 + size_t buf_size;
39712
39713 memset(buf, 0, sizeof(buf));
39714 buf_size = min(count, sizeof(buf) - 1);
39715 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
39716 struct iwl_priv *priv = file->private_data;
39717 u32 event_log_flag;
39718 char buf[8];
39719 - int buf_size;
39720 + size_t buf_size;
39721
39722 /* check that the interface is up */
39723 if (!iwl_is_ready(priv))
39724 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
39725 struct iwl_priv *priv = file->private_data;
39726 char buf[8];
39727 u32 calib_disabled;
39728 - int buf_size;
39729 + size_t buf_size;
39730
39731 memset(buf, 0, sizeof(buf));
39732 buf_size = min(count, sizeof(buf) - 1);
39733 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
39734 index 35708b9..31f7754 100644
39735 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
39736 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
39737 @@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
39738 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
39739
39740 char buf[8];
39741 - int buf_size;
39742 + size_t buf_size;
39743 u32 reset_flag;
39744
39745 memset(buf, 0, sizeof(buf));
39746 @@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
39747 {
39748 struct iwl_trans *trans = file->private_data;
39749 char buf[8];
39750 - int buf_size;
39751 + size_t buf_size;
39752 int csr;
39753
39754 memset(buf, 0, sizeof(buf));
39755 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
39756 index ff90855..e46d223 100644
39757 --- a/drivers/net/wireless/mac80211_hwsim.c
39758 +++ b/drivers/net/wireless/mac80211_hwsim.c
39759 @@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
39760
39761 if (channels > 1) {
39762 hwsim_if_comb.num_different_channels = channels;
39763 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
39764 - mac80211_hwsim_ops.cancel_hw_scan =
39765 - mac80211_hwsim_cancel_hw_scan;
39766 - mac80211_hwsim_ops.sw_scan_start = NULL;
39767 - mac80211_hwsim_ops.sw_scan_complete = NULL;
39768 - mac80211_hwsim_ops.remain_on_channel =
39769 - mac80211_hwsim_roc;
39770 - mac80211_hwsim_ops.cancel_remain_on_channel =
39771 - mac80211_hwsim_croc;
39772 - mac80211_hwsim_ops.add_chanctx =
39773 - mac80211_hwsim_add_chanctx;
39774 - mac80211_hwsim_ops.remove_chanctx =
39775 - mac80211_hwsim_remove_chanctx;
39776 - mac80211_hwsim_ops.change_chanctx =
39777 - mac80211_hwsim_change_chanctx;
39778 - mac80211_hwsim_ops.assign_vif_chanctx =
39779 - mac80211_hwsim_assign_vif_chanctx;
39780 - mac80211_hwsim_ops.unassign_vif_chanctx =
39781 - mac80211_hwsim_unassign_vif_chanctx;
39782 + pax_open_kernel();
39783 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
39784 + *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
39785 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
39786 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
39787 + *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
39788 + *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
39789 + *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
39790 + *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
39791 + *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
39792 + *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
39793 + *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
39794 + pax_close_kernel();
39795 }
39796
39797 spin_lock_init(&hwsim_radio_lock);
39798 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
39799 index abe1d03..fb02c22 100644
39800 --- a/drivers/net/wireless/rndis_wlan.c
39801 +++ b/drivers/net/wireless/rndis_wlan.c
39802 @@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
39803
39804 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
39805
39806 - if (rts_threshold < 0 || rts_threshold > 2347)
39807 + if (rts_threshold > 2347)
39808 rts_threshold = 2347;
39809
39810 tmp = cpu_to_le32(rts_threshold);
39811 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
39812 index 0751b35..246ba3e 100644
39813 --- a/drivers/net/wireless/rt2x00/rt2x00.h
39814 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
39815 @@ -398,7 +398,7 @@ struct rt2x00_intf {
39816 * for hardware which doesn't support hardware
39817 * sequence counting.
39818 */
39819 - atomic_t seqno;
39820 + atomic_unchecked_t seqno;
39821 };
39822
39823 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
39824 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
39825 index e488b94..14b6a0c 100644
39826 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
39827 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
39828 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
39829 * sequence counter given by mac80211.
39830 */
39831 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
39832 - seqno = atomic_add_return(0x10, &intf->seqno);
39833 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
39834 else
39835 - seqno = atomic_read(&intf->seqno);
39836 + seqno = atomic_read_unchecked(&intf->seqno);
39837
39838 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
39839 hdr->seq_ctrl |= cpu_to_le16(seqno);
39840 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
39841 index e57ee48..541cf6c 100644
39842 --- a/drivers/net/wireless/ti/wl1251/sdio.c
39843 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
39844 @@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
39845
39846 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
39847
39848 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
39849 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
39850 + pax_open_kernel();
39851 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
39852 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
39853 + pax_close_kernel();
39854
39855 wl1251_info("using dedicated interrupt line");
39856 } else {
39857 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
39858 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
39859 + pax_open_kernel();
39860 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
39861 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
39862 + pax_close_kernel();
39863
39864 wl1251_info("using SDIO interrupt");
39865 }
39866 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
39867 index e5f5f8f..fdf15b7 100644
39868 --- a/drivers/net/wireless/ti/wl12xx/main.c
39869 +++ b/drivers/net/wireless/ti/wl12xx/main.c
39870 @@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
39871 sizeof(wl->conf.mem));
39872
39873 /* read data preparation is only needed by wl127x */
39874 - wl->ops->prepare_read = wl127x_prepare_read;
39875 + pax_open_kernel();
39876 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
39877 + pax_close_kernel();
39878
39879 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
39880 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
39881 @@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
39882 sizeof(wl->conf.mem));
39883
39884 /* read data preparation is only needed by wl127x */
39885 - wl->ops->prepare_read = wl127x_prepare_read;
39886 + pax_open_kernel();
39887 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
39888 + pax_close_kernel();
39889
39890 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
39891 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
39892 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
39893 index 8d8c1f8..e754844 100644
39894 --- a/drivers/net/wireless/ti/wl18xx/main.c
39895 +++ b/drivers/net/wireless/ti/wl18xx/main.c
39896 @@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
39897 }
39898
39899 if (!checksum_param) {
39900 - wl18xx_ops.set_rx_csum = NULL;
39901 - wl18xx_ops.init_vif = NULL;
39902 + pax_open_kernel();
39903 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
39904 + *(void **)&wl18xx_ops.init_vif = NULL;
39905 + pax_close_kernel();
39906 }
39907
39908 /* Enable 11a Band only if we have 5G antennas */
39909 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
39910 index d93b2b6..ae50401 100644
39911 --- a/drivers/oprofile/buffer_sync.c
39912 +++ b/drivers/oprofile/buffer_sync.c
39913 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
39914 if (cookie == NO_COOKIE)
39915 offset = pc;
39916 if (cookie == INVALID_COOKIE) {
39917 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39918 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39919 offset = pc;
39920 }
39921 if (cookie != last_cookie) {
39922 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
39923 /* add userspace sample */
39924
39925 if (!mm) {
39926 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
39927 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
39928 return 0;
39929 }
39930
39931 cookie = lookup_dcookie(mm, s->eip, &offset);
39932
39933 if (cookie == INVALID_COOKIE) {
39934 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39935 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39936 return 0;
39937 }
39938
39939 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
39940 /* ignore backtraces if failed to add a sample */
39941 if (state == sb_bt_start) {
39942 state = sb_bt_ignore;
39943 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
39944 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
39945 }
39946 }
39947 release_mm(mm);
39948 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
39949 index c0cc4e7..44d4e54 100644
39950 --- a/drivers/oprofile/event_buffer.c
39951 +++ b/drivers/oprofile/event_buffer.c
39952 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
39953 }
39954
39955 if (buffer_pos == buffer_size) {
39956 - atomic_inc(&oprofile_stats.event_lost_overflow);
39957 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
39958 return;
39959 }
39960
39961 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
39962 index ed2c3ec..deda85a 100644
39963 --- a/drivers/oprofile/oprof.c
39964 +++ b/drivers/oprofile/oprof.c
39965 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
39966 if (oprofile_ops.switch_events())
39967 return;
39968
39969 - atomic_inc(&oprofile_stats.multiplex_counter);
39970 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
39971 start_switch_worker();
39972 }
39973
39974 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
39975 index 917d28e..d62d981 100644
39976 --- a/drivers/oprofile/oprofile_stats.c
39977 +++ b/drivers/oprofile/oprofile_stats.c
39978 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
39979 cpu_buf->sample_invalid_eip = 0;
39980 }
39981
39982 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
39983 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
39984 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
39985 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
39986 - atomic_set(&oprofile_stats.multiplex_counter, 0);
39987 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
39988 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
39989 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
39990 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
39991 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
39992 }
39993
39994
39995 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
39996 index 38b6fc0..b5cbfce 100644
39997 --- a/drivers/oprofile/oprofile_stats.h
39998 +++ b/drivers/oprofile/oprofile_stats.h
39999 @@ -13,11 +13,11 @@
40000 #include <linux/atomic.h>
40001
40002 struct oprofile_stat_struct {
40003 - atomic_t sample_lost_no_mm;
40004 - atomic_t sample_lost_no_mapping;
40005 - atomic_t bt_lost_no_mapping;
40006 - atomic_t event_lost_overflow;
40007 - atomic_t multiplex_counter;
40008 + atomic_unchecked_t sample_lost_no_mm;
40009 + atomic_unchecked_t sample_lost_no_mapping;
40010 + atomic_unchecked_t bt_lost_no_mapping;
40011 + atomic_unchecked_t event_lost_overflow;
40012 + atomic_unchecked_t multiplex_counter;
40013 };
40014
40015 extern struct oprofile_stat_struct oprofile_stats;
40016 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
40017 index 849357c..b83c1e0 100644
40018 --- a/drivers/oprofile/oprofilefs.c
40019 +++ b/drivers/oprofile/oprofilefs.c
40020 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
40021
40022
40023 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
40024 - char const *name, atomic_t *val)
40025 + char const *name, atomic_unchecked_t *val)
40026 {
40027 return __oprofilefs_create_file(sb, root, name,
40028 &atomic_ro_fops, 0444, val);
40029 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
40030 index 93404f7..4a313d8 100644
40031 --- a/drivers/oprofile/timer_int.c
40032 +++ b/drivers/oprofile/timer_int.c
40033 @@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
40034 return NOTIFY_OK;
40035 }
40036
40037 -static struct notifier_block __refdata oprofile_cpu_notifier = {
40038 +static struct notifier_block oprofile_cpu_notifier = {
40039 .notifier_call = oprofile_cpu_notify,
40040 };
40041
40042 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
40043 index 3f56bc0..707d642 100644
40044 --- a/drivers/parport/procfs.c
40045 +++ b/drivers/parport/procfs.c
40046 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
40047
40048 *ppos += len;
40049
40050 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
40051 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
40052 }
40053
40054 #ifdef CONFIG_PARPORT_1284
40055 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
40056
40057 *ppos += len;
40058
40059 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
40060 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
40061 }
40062 #endif /* IEEE1284.3 support. */
40063
40064 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
40065 index c35e8ad..fc33beb 100644
40066 --- a/drivers/pci/hotplug/acpiphp_ibm.c
40067 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
40068 @@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
40069 goto init_cleanup;
40070 }
40071
40072 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40073 + pax_open_kernel();
40074 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40075 + pax_close_kernel();
40076 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
40077
40078 return retval;
40079 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
40080 index a6a71c4..c91097b 100644
40081 --- a/drivers/pci/hotplug/cpcihp_generic.c
40082 +++ b/drivers/pci/hotplug/cpcihp_generic.c
40083 @@ -73,7 +73,6 @@ static u16 port;
40084 static unsigned int enum_bit;
40085 static u8 enum_mask;
40086
40087 -static struct cpci_hp_controller_ops generic_hpc_ops;
40088 static struct cpci_hp_controller generic_hpc;
40089
40090 static int __init validate_parameters(void)
40091 @@ -139,6 +138,10 @@ static int query_enum(void)
40092 return ((value & enum_mask) == enum_mask);
40093 }
40094
40095 +static struct cpci_hp_controller_ops generic_hpc_ops = {
40096 + .query_enum = query_enum,
40097 +};
40098 +
40099 static int __init cpcihp_generic_init(void)
40100 {
40101 int status;
40102 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
40103 pci_dev_put(dev);
40104
40105 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
40106 - generic_hpc_ops.query_enum = query_enum;
40107 generic_hpc.ops = &generic_hpc_ops;
40108
40109 status = cpci_hp_register_controller(&generic_hpc);
40110 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
40111 index 449b4bb..257e2e8 100644
40112 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
40113 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
40114 @@ -59,7 +59,6 @@
40115 /* local variables */
40116 static bool debug;
40117 static bool poll;
40118 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
40119 static struct cpci_hp_controller zt5550_hpc;
40120
40121 /* Primary cPCI bus bridge device */
40122 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
40123 return 0;
40124 }
40125
40126 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
40127 + .query_enum = zt5550_hc_query_enum,
40128 +};
40129 +
40130 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
40131 {
40132 int status;
40133 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
40134 dbg("returned from zt5550_hc_config");
40135
40136 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
40137 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
40138 zt5550_hpc.ops = &zt5550_hpc_ops;
40139 if(!poll) {
40140 zt5550_hpc.irq = hc_dev->irq;
40141 zt5550_hpc.irq_flags = IRQF_SHARED;
40142 zt5550_hpc.dev_id = hc_dev;
40143
40144 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40145 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40146 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40147 + pax_open_kernel();
40148 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40149 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40150 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40151 + pax_open_kernel();
40152 } else {
40153 info("using ENUM# polling mode");
40154 }
40155 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
40156 index 76ba8a1..20ca857 100644
40157 --- a/drivers/pci/hotplug/cpqphp_nvram.c
40158 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
40159 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
40160
40161 void compaq_nvram_init (void __iomem *rom_start)
40162 {
40163 +
40164 +#ifndef CONFIG_PAX_KERNEXEC
40165 if (rom_start) {
40166 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
40167 }
40168 +#endif
40169 +
40170 dbg("int15 entry = %p\n", compaq_int15_entry_point);
40171
40172 /* initialize our int15 lock */
40173 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
40174 index 202f4a9..8ee47d0 100644
40175 --- a/drivers/pci/hotplug/pci_hotplug_core.c
40176 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
40177 @@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
40178 return -EINVAL;
40179 }
40180
40181 - slot->ops->owner = owner;
40182 - slot->ops->mod_name = mod_name;
40183 + pax_open_kernel();
40184 + *(struct module **)&slot->ops->owner = owner;
40185 + *(const char **)&slot->ops->mod_name = mod_name;
40186 + pax_close_kernel();
40187
40188 mutex_lock(&pci_hp_mutex);
40189 /*
40190 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
40191 index 939bd1d..a1459c9 100644
40192 --- a/drivers/pci/hotplug/pciehp_core.c
40193 +++ b/drivers/pci/hotplug/pciehp_core.c
40194 @@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
40195 struct slot *slot = ctrl->slot;
40196 struct hotplug_slot *hotplug = NULL;
40197 struct hotplug_slot_info *info = NULL;
40198 - struct hotplug_slot_ops *ops = NULL;
40199 + hotplug_slot_ops_no_const *ops = NULL;
40200 char name[SLOT_NAME_SIZE];
40201 int retval = -ENOMEM;
40202
40203 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
40204 index 9c6e9bb..2916736 100644
40205 --- a/drivers/pci/pci-sysfs.c
40206 +++ b/drivers/pci/pci-sysfs.c
40207 @@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
40208 {
40209 /* allocate attribute structure, piggyback attribute name */
40210 int name_len = write_combine ? 13 : 10;
40211 - struct bin_attribute *res_attr;
40212 + bin_attribute_no_const *res_attr;
40213 int retval;
40214
40215 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
40216 @@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
40217 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
40218 {
40219 int retval;
40220 - struct bin_attribute *attr;
40221 + bin_attribute_no_const *attr;
40222
40223 /* If the device has VPD, try to expose it in sysfs. */
40224 if (dev->vpd) {
40225 @@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
40226 {
40227 int retval;
40228 int rom_size = 0;
40229 - struct bin_attribute *attr;
40230 + bin_attribute_no_const *attr;
40231
40232 if (!sysfs_initialized)
40233 return -EACCES;
40234 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
40235 index e851829..a1a7196 100644
40236 --- a/drivers/pci/pci.h
40237 +++ b/drivers/pci/pci.h
40238 @@ -98,7 +98,7 @@ struct pci_vpd_ops {
40239 struct pci_vpd {
40240 unsigned int len;
40241 const struct pci_vpd_ops *ops;
40242 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
40243 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
40244 };
40245
40246 extern int pci_vpd_pci22_init(struct pci_dev *dev);
40247 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
40248 index 8474b6a..ee81993 100644
40249 --- a/drivers/pci/pcie/aspm.c
40250 +++ b/drivers/pci/pcie/aspm.c
40251 @@ -27,9 +27,9 @@
40252 #define MODULE_PARAM_PREFIX "pcie_aspm."
40253
40254 /* Note: those are not register definitions */
40255 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
40256 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
40257 -#define ASPM_STATE_L1 (4) /* L1 state */
40258 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
40259 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
40260 +#define ASPM_STATE_L1 (4U) /* L1 state */
40261 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
40262 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
40263
40264 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
40265 index 6186f03..1a78714 100644
40266 --- a/drivers/pci/probe.c
40267 +++ b/drivers/pci/probe.c
40268 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
40269 struct pci_bus_region region;
40270 bool bar_too_big = false, bar_disabled = false;
40271
40272 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
40273 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
40274
40275 /* No printks while decoding is disabled! */
40276 if (!dev->mmio_always_on) {
40277 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
40278 index 9b8505c..f00870a 100644
40279 --- a/drivers/pci/proc.c
40280 +++ b/drivers/pci/proc.c
40281 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
40282 static int __init pci_proc_init(void)
40283 {
40284 struct pci_dev *dev = NULL;
40285 +
40286 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
40287 +#ifdef CONFIG_GRKERNSEC_PROC_USER
40288 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
40289 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
40290 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
40291 +#endif
40292 +#else
40293 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
40294 +#endif
40295 proc_create("devices", 0, proc_bus_pci_dir,
40296 &proc_bus_pci_dev_operations);
40297 proc_initialized = 1;
40298 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40299 index 2111dbb..79e434b 100644
40300 --- a/drivers/platform/x86/msi-laptop.c
40301 +++ b/drivers/platform/x86/msi-laptop.c
40302 @@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
40303 int result;
40304
40305 /* allow userland write sysfs file */
40306 - dev_attr_bluetooth.store = store_bluetooth;
40307 - dev_attr_wlan.store = store_wlan;
40308 - dev_attr_threeg.store = store_threeg;
40309 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
40310 - dev_attr_wlan.attr.mode |= S_IWUSR;
40311 - dev_attr_threeg.attr.mode |= S_IWUSR;
40312 + pax_open_kernel();
40313 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
40314 + *(void **)&dev_attr_wlan.store = store_wlan;
40315 + *(void **)&dev_attr_threeg.store = store_threeg;
40316 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
40317 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
40318 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
40319 + pax_close_kernel();
40320
40321 /* disable hardware control by fn key */
40322 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
40323 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40324 index b8ad71f..3ec9bb4 100644
40325 --- a/drivers/platform/x86/sony-laptop.c
40326 +++ b/drivers/platform/x86/sony-laptop.c
40327 @@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
40328 }
40329
40330 /* High speed charging function */
40331 -static struct device_attribute *hsc_handle;
40332 +static device_attribute_no_const *hsc_handle;
40333
40334 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
40335 struct device_attribute *attr,
40336 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40337 index f946ca7..f25c833 100644
40338 --- a/drivers/platform/x86/thinkpad_acpi.c
40339 +++ b/drivers/platform/x86/thinkpad_acpi.c
40340 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
40341 return 0;
40342 }
40343
40344 -void static hotkey_mask_warn_incomplete_mask(void)
40345 +static void hotkey_mask_warn_incomplete_mask(void)
40346 {
40347 /* log only what the user can fix... */
40348 const u32 wantedmask = hotkey_driver_mask &
40349 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
40350 }
40351 }
40352
40353 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40354 - struct tp_nvram_state *newn,
40355 - const u32 event_mask)
40356 -{
40357 -
40358 #define TPACPI_COMPARE_KEY(__scancode, __member) \
40359 do { \
40360 if ((event_mask & (1 << __scancode)) && \
40361 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40362 tpacpi_hotkey_send_key(__scancode); \
40363 } while (0)
40364
40365 - void issue_volchange(const unsigned int oldvol,
40366 - const unsigned int newvol)
40367 - {
40368 - unsigned int i = oldvol;
40369 +static void issue_volchange(const unsigned int oldvol,
40370 + const unsigned int newvol,
40371 + const u32 event_mask)
40372 +{
40373 + unsigned int i = oldvol;
40374
40375 - while (i > newvol) {
40376 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40377 - i--;
40378 - }
40379 - while (i < newvol) {
40380 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40381 - i++;
40382 - }
40383 + while (i > newvol) {
40384 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40385 + i--;
40386 }
40387 + while (i < newvol) {
40388 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40389 + i++;
40390 + }
40391 +}
40392
40393 - void issue_brightnesschange(const unsigned int oldbrt,
40394 - const unsigned int newbrt)
40395 - {
40396 - unsigned int i = oldbrt;
40397 +static void issue_brightnesschange(const unsigned int oldbrt,
40398 + const unsigned int newbrt,
40399 + const u32 event_mask)
40400 +{
40401 + unsigned int i = oldbrt;
40402
40403 - while (i > newbrt) {
40404 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40405 - i--;
40406 - }
40407 - while (i < newbrt) {
40408 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40409 - i++;
40410 - }
40411 + while (i > newbrt) {
40412 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40413 + i--;
40414 + }
40415 + while (i < newbrt) {
40416 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40417 + i++;
40418 }
40419 +}
40420
40421 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40422 + struct tp_nvram_state *newn,
40423 + const u32 event_mask)
40424 +{
40425 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
40426 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
40427 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
40428 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40429 oldn->volume_level != newn->volume_level) {
40430 /* recently muted, or repeated mute keypress, or
40431 * multiple presses ending in mute */
40432 - issue_volchange(oldn->volume_level, newn->volume_level);
40433 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40434 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
40435 }
40436 } else {
40437 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40438 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40439 }
40440 if (oldn->volume_level != newn->volume_level) {
40441 - issue_volchange(oldn->volume_level, newn->volume_level);
40442 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40443 } else if (oldn->volume_toggle != newn->volume_toggle) {
40444 /* repeated vol up/down keypress at end of scale ? */
40445 if (newn->volume_level == 0)
40446 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40447 /* handle brightness */
40448 if (oldn->brightness_level != newn->brightness_level) {
40449 issue_brightnesschange(oldn->brightness_level,
40450 - newn->brightness_level);
40451 + newn->brightness_level,
40452 + event_mask);
40453 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
40454 /* repeated key presses that didn't change state */
40455 if (newn->brightness_level == 0)
40456 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40457 && !tp_features.bright_unkfw)
40458 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40459 }
40460 +}
40461
40462 #undef TPACPI_COMPARE_KEY
40463 #undef TPACPI_MAY_SEND_KEY
40464 -}
40465
40466 /*
40467 * Polling driver
40468 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40469 index 769d265..a3a05ca 100644
40470 --- a/drivers/pnp/pnpbios/bioscalls.c
40471 +++ b/drivers/pnp/pnpbios/bioscalls.c
40472 @@ -58,7 +58,7 @@ do { \
40473 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40474 } while(0)
40475
40476 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40477 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40478 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40479
40480 /*
40481 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40482
40483 cpu = get_cpu();
40484 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40485 +
40486 + pax_open_kernel();
40487 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40488 + pax_close_kernel();
40489
40490 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40491 spin_lock_irqsave(&pnp_bios_lock, flags);
40492 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40493 :"memory");
40494 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40495
40496 + pax_open_kernel();
40497 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40498 + pax_close_kernel();
40499 +
40500 put_cpu();
40501
40502 /* If we get here and this is set then the PnP BIOS faulted on us. */
40503 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40504 return status;
40505 }
40506
40507 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
40508 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40509 {
40510 int i;
40511
40512 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40513 pnp_bios_callpoint.offset = header->fields.pm16offset;
40514 pnp_bios_callpoint.segment = PNP_CS16;
40515
40516 + pax_open_kernel();
40517 +
40518 for_each_possible_cpu(i) {
40519 struct desc_struct *gdt = get_cpu_gdt_table(i);
40520 if (!gdt)
40521 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40522 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40523 (unsigned long)__va(header->fields.pm16dseg));
40524 }
40525 +
40526 + pax_close_kernel();
40527 }
40528 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40529 index 3e6db1c..1fbbdae 100644
40530 --- a/drivers/pnp/resource.c
40531 +++ b/drivers/pnp/resource.c
40532 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40533 return 1;
40534
40535 /* check if the resource is valid */
40536 - if (*irq < 0 || *irq > 15)
40537 + if (*irq > 15)
40538 return 0;
40539
40540 /* check if the resource is reserved */
40541 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40542 return 1;
40543
40544 /* check if the resource is valid */
40545 - if (*dma < 0 || *dma == 4 || *dma > 7)
40546 + if (*dma == 4 || *dma > 7)
40547 return 0;
40548
40549 /* check if the resource is reserved */
40550 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
40551 index 7df7c5f..bd48c47 100644
40552 --- a/drivers/power/pda_power.c
40553 +++ b/drivers/power/pda_power.c
40554 @@ -37,7 +37,11 @@ static int polling;
40555
40556 #ifdef CONFIG_USB_OTG_UTILS
40557 static struct usb_phy *transceiver;
40558 -static struct notifier_block otg_nb;
40559 +static int otg_handle_notification(struct notifier_block *nb,
40560 + unsigned long event, void *unused);
40561 +static struct notifier_block otg_nb = {
40562 + .notifier_call = otg_handle_notification
40563 +};
40564 #endif
40565
40566 static struct regulator *ac_draw;
40567 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
40568
40569 #ifdef CONFIG_USB_OTG_UTILS
40570 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
40571 - otg_nb.notifier_call = otg_handle_notification;
40572 ret = usb_register_notifier(transceiver, &otg_nb);
40573 if (ret) {
40574 dev_err(dev, "failure to register otg notifier\n");
40575 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
40576 index cc439fd..8fa30df 100644
40577 --- a/drivers/power/power_supply.h
40578 +++ b/drivers/power/power_supply.h
40579 @@ -16,12 +16,12 @@ struct power_supply;
40580
40581 #ifdef CONFIG_SYSFS
40582
40583 -extern void power_supply_init_attrs(struct device_type *dev_type);
40584 +extern void power_supply_init_attrs(void);
40585 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
40586
40587 #else
40588
40589 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
40590 +static inline void power_supply_init_attrs(void) {}
40591 #define power_supply_uevent NULL
40592
40593 #endif /* CONFIG_SYSFS */
40594 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
40595 index 8a7cfb3..493e0a2 100644
40596 --- a/drivers/power/power_supply_core.c
40597 +++ b/drivers/power/power_supply_core.c
40598 @@ -24,7 +24,10 @@
40599 struct class *power_supply_class;
40600 EXPORT_SYMBOL_GPL(power_supply_class);
40601
40602 -static struct device_type power_supply_dev_type;
40603 +extern const struct attribute_group *power_supply_attr_groups[];
40604 +static struct device_type power_supply_dev_type = {
40605 + .groups = power_supply_attr_groups,
40606 +};
40607
40608 static int __power_supply_changed_work(struct device *dev, void *data)
40609 {
40610 @@ -393,7 +396,6 @@ static int __init power_supply_class_init(void)
40611 return PTR_ERR(power_supply_class);
40612
40613 power_supply_class->dev_uevent = power_supply_uevent;
40614 - power_supply_init_attrs(&power_supply_dev_type);
40615
40616 return 0;
40617 }
40618 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
40619 index 40fa3b7..d9c2e0e 100644
40620 --- a/drivers/power/power_supply_sysfs.c
40621 +++ b/drivers/power/power_supply_sysfs.c
40622 @@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
40623 .is_visible = power_supply_attr_is_visible,
40624 };
40625
40626 -static const struct attribute_group *power_supply_attr_groups[] = {
40627 +const struct attribute_group *power_supply_attr_groups[] = {
40628 &power_supply_attr_group,
40629 NULL,
40630 };
40631
40632 -void power_supply_init_attrs(struct device_type *dev_type)
40633 +void power_supply_init_attrs(void)
40634 {
40635 int i;
40636
40637 - dev_type->groups = power_supply_attr_groups;
40638 -
40639 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
40640 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
40641 }
40642 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
40643 index 4d7c635..9860196 100644
40644 --- a/drivers/regulator/max8660.c
40645 +++ b/drivers/regulator/max8660.c
40646 @@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
40647 max8660->shadow_regs[MAX8660_OVER1] = 5;
40648 } else {
40649 /* Otherwise devices can be toggled via software */
40650 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
40651 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
40652 + pax_open_kernel();
40653 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
40654 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
40655 + pax_close_kernel();
40656 }
40657
40658 /*
40659 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
40660 index 9a8ea91..c483dd9 100644
40661 --- a/drivers/regulator/max8973-regulator.c
40662 +++ b/drivers/regulator/max8973-regulator.c
40663 @@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
40664 if (!pdata->enable_ext_control) {
40665 max->desc.enable_reg = MAX8973_VOUT;
40666 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
40667 - max8973_dcdc_ops.enable = regulator_enable_regmap;
40668 - max8973_dcdc_ops.disable = regulator_disable_regmap;
40669 - max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
40670 + pax_open_kernel();
40671 + *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
40672 + *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
40673 + *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
40674 + pax_close_kernel();
40675 }
40676
40677 max->enable_external_control = pdata->enable_ext_control;
40678 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
40679 index 0d84b1f..c2da6ac 100644
40680 --- a/drivers/regulator/mc13892-regulator.c
40681 +++ b/drivers/regulator/mc13892-regulator.c
40682 @@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
40683 }
40684 mc13xxx_unlock(mc13892);
40685
40686 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
40687 + pax_open_kernel();
40688 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
40689 = mc13892_vcam_set_mode;
40690 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
40691 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
40692 = mc13892_vcam_get_mode;
40693 + pax_close_kernel();
40694
40695 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
40696 ARRAY_SIZE(mc13892_regulators));
40697 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
40698 index 16630aa..6afc992 100644
40699 --- a/drivers/rtc/rtc-cmos.c
40700 +++ b/drivers/rtc/rtc-cmos.c
40701 @@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
40702 hpet_rtc_timer_init();
40703
40704 /* export at least the first block of NVRAM */
40705 - nvram.size = address_space - NVRAM_OFFSET;
40706 + pax_open_kernel();
40707 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
40708 + pax_close_kernel();
40709 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
40710 if (retval < 0) {
40711 dev_dbg(dev, "can't create nvram file? %d\n", retval);
40712 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
40713 index 9a86b4b..3a383dc 100644
40714 --- a/drivers/rtc/rtc-dev.c
40715 +++ b/drivers/rtc/rtc-dev.c
40716 @@ -14,6 +14,7 @@
40717 #include <linux/module.h>
40718 #include <linux/rtc.h>
40719 #include <linux/sched.h>
40720 +#include <linux/grsecurity.h>
40721 #include "rtc-core.h"
40722
40723 static dev_t rtc_devt;
40724 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
40725 if (copy_from_user(&tm, uarg, sizeof(tm)))
40726 return -EFAULT;
40727
40728 + gr_log_timechange();
40729 +
40730 return rtc_set_time(rtc, &tm);
40731
40732 case RTC_PIE_ON:
40733 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
40734 index e0d0ba4..3c65868 100644
40735 --- a/drivers/rtc/rtc-ds1307.c
40736 +++ b/drivers/rtc/rtc-ds1307.c
40737 @@ -106,7 +106,7 @@ struct ds1307 {
40738 u8 offset; /* register's offset */
40739 u8 regs[11];
40740 u16 nvram_offset;
40741 - struct bin_attribute *nvram;
40742 + bin_attribute_no_const *nvram;
40743 enum ds_type type;
40744 unsigned long flags;
40745 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
40746 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
40747 index 130f29a..6179d03 100644
40748 --- a/drivers/rtc/rtc-m48t59.c
40749 +++ b/drivers/rtc/rtc-m48t59.c
40750 @@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
40751 goto out;
40752 }
40753
40754 - m48t59_nvram_attr.size = pdata->offset;
40755 + pax_open_kernel();
40756 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
40757 + pax_close_kernel();
40758
40759 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
40760 if (ret) {
40761 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
40762 index e693af6..2e525b6 100644
40763 --- a/drivers/scsi/bfa/bfa_fcpim.h
40764 +++ b/drivers/scsi/bfa/bfa_fcpim.h
40765 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
40766
40767 struct bfa_itn_s {
40768 bfa_isr_func_t isr;
40769 -};
40770 +} __no_const;
40771
40772 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
40773 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
40774 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
40775 index 23a90e7..9cf04ee 100644
40776 --- a/drivers/scsi/bfa/bfa_ioc.h
40777 +++ b/drivers/scsi/bfa/bfa_ioc.h
40778 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
40779 bfa_ioc_disable_cbfn_t disable_cbfn;
40780 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
40781 bfa_ioc_reset_cbfn_t reset_cbfn;
40782 -};
40783 +} __no_const;
40784
40785 /*
40786 * IOC event notification mechanism.
40787 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
40788 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
40789 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
40790 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
40791 -};
40792 +} __no_const;
40793
40794 /*
40795 * Queue element to wait for room in request queue. FIFO order is
40796 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
40797 index 593085a..47aa999 100644
40798 --- a/drivers/scsi/hosts.c
40799 +++ b/drivers/scsi/hosts.c
40800 @@ -42,7 +42,7 @@
40801 #include "scsi_logging.h"
40802
40803
40804 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
40805 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
40806
40807
40808 static void scsi_host_cls_release(struct device *dev)
40809 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
40810 * subtract one because we increment first then return, but we need to
40811 * know what the next host number was before increment
40812 */
40813 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
40814 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
40815 shost->dma_channel = 0xff;
40816
40817 /* These three are default values which can be overridden */
40818 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
40819 index 4f33806..afd6f60 100644
40820 --- a/drivers/scsi/hpsa.c
40821 +++ b/drivers/scsi/hpsa.c
40822 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
40823 unsigned long flags;
40824
40825 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
40826 - return h->access.command_completed(h, q);
40827 + return h->access->command_completed(h, q);
40828
40829 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
40830 a = rq->head[rq->current_entry];
40831 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
40832 while (!list_empty(&h->reqQ)) {
40833 c = list_entry(h->reqQ.next, struct CommandList, list);
40834 /* can't do anything if fifo is full */
40835 - if ((h->access.fifo_full(h))) {
40836 + if ((h->access->fifo_full(h))) {
40837 dev_warn(&h->pdev->dev, "fifo full\n");
40838 break;
40839 }
40840 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
40841
40842 /* Tell the controller execute command */
40843 spin_unlock_irqrestore(&h->lock, flags);
40844 - h->access.submit_command(h, c);
40845 + h->access->submit_command(h, c);
40846 spin_lock_irqsave(&h->lock, flags);
40847 }
40848 spin_unlock_irqrestore(&h->lock, flags);
40849 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
40850
40851 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
40852 {
40853 - return h->access.command_completed(h, q);
40854 + return h->access->command_completed(h, q);
40855 }
40856
40857 static inline bool interrupt_pending(struct ctlr_info *h)
40858 {
40859 - return h->access.intr_pending(h);
40860 + return h->access->intr_pending(h);
40861 }
40862
40863 static inline long interrupt_not_for_us(struct ctlr_info *h)
40864 {
40865 - return (h->access.intr_pending(h) == 0) ||
40866 + return (h->access->intr_pending(h) == 0) ||
40867 (h->interrupts_enabled == 0);
40868 }
40869
40870 @@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
40871 if (prod_index < 0)
40872 return -ENODEV;
40873 h->product_name = products[prod_index].product_name;
40874 - h->access = *(products[prod_index].access);
40875 + h->access = products[prod_index].access;
40876
40877 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
40878 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
40879 @@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
40880
40881 assert_spin_locked(&lockup_detector_lock);
40882 remove_ctlr_from_lockup_detector_list(h);
40883 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40884 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40885 spin_lock_irqsave(&h->lock, flags);
40886 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
40887 spin_unlock_irqrestore(&h->lock, flags);
40888 @@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
40889 }
40890
40891 /* make sure the board interrupts are off */
40892 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40893 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40894
40895 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
40896 goto clean2;
40897 @@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
40898 * fake ones to scoop up any residual completions.
40899 */
40900 spin_lock_irqsave(&h->lock, flags);
40901 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40902 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40903 spin_unlock_irqrestore(&h->lock, flags);
40904 free_irqs(h);
40905 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
40906 @@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
40907 dev_info(&h->pdev->dev, "Board READY.\n");
40908 dev_info(&h->pdev->dev,
40909 "Waiting for stale completions to drain.\n");
40910 - h->access.set_intr_mask(h, HPSA_INTR_ON);
40911 + h->access->set_intr_mask(h, HPSA_INTR_ON);
40912 msleep(10000);
40913 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40914 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40915
40916 rc = controller_reset_failed(h->cfgtable);
40917 if (rc)
40918 @@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
40919 }
40920
40921 /* Turn the interrupts on so we can service requests */
40922 - h->access.set_intr_mask(h, HPSA_INTR_ON);
40923 + h->access->set_intr_mask(h, HPSA_INTR_ON);
40924
40925 hpsa_hba_inquiry(h);
40926 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
40927 @@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
40928 * To write all data in the battery backed cache to disks
40929 */
40930 hpsa_flush_cache(h);
40931 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40932 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40933 hpsa_free_irqs_and_disable_msix(h);
40934 }
40935
40936 @@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
40937 return;
40938 }
40939 /* Change the access methods to the performant access methods */
40940 - h->access = SA5_performant_access;
40941 + h->access = &SA5_performant_access;
40942 h->transMethod = CFGTBL_Trans_Performant;
40943 }
40944
40945 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
40946 index 9816479..c5d4e97 100644
40947 --- a/drivers/scsi/hpsa.h
40948 +++ b/drivers/scsi/hpsa.h
40949 @@ -79,7 +79,7 @@ struct ctlr_info {
40950 unsigned int msix_vector;
40951 unsigned int msi_vector;
40952 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
40953 - struct access_method access;
40954 + struct access_method *access;
40955
40956 /* queue and queue Info */
40957 struct list_head reqQ;
40958 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
40959 index c772d8d..35c362c 100644
40960 --- a/drivers/scsi/libfc/fc_exch.c
40961 +++ b/drivers/scsi/libfc/fc_exch.c
40962 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
40963 u16 pool_max_index;
40964
40965 struct {
40966 - atomic_t no_free_exch;
40967 - atomic_t no_free_exch_xid;
40968 - atomic_t xid_not_found;
40969 - atomic_t xid_busy;
40970 - atomic_t seq_not_found;
40971 - atomic_t non_bls_resp;
40972 + atomic_unchecked_t no_free_exch;
40973 + atomic_unchecked_t no_free_exch_xid;
40974 + atomic_unchecked_t xid_not_found;
40975 + atomic_unchecked_t xid_busy;
40976 + atomic_unchecked_t seq_not_found;
40977 + atomic_unchecked_t non_bls_resp;
40978 } stats;
40979 };
40980
40981 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
40982 /* allocate memory for exchange */
40983 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
40984 if (!ep) {
40985 - atomic_inc(&mp->stats.no_free_exch);
40986 + atomic_inc_unchecked(&mp->stats.no_free_exch);
40987 goto out;
40988 }
40989 memset(ep, 0, sizeof(*ep));
40990 @@ -786,7 +786,7 @@ out:
40991 return ep;
40992 err:
40993 spin_unlock_bh(&pool->lock);
40994 - atomic_inc(&mp->stats.no_free_exch_xid);
40995 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
40996 mempool_free(ep, mp->ep_pool);
40997 return NULL;
40998 }
40999 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41000 xid = ntohs(fh->fh_ox_id); /* we originated exch */
41001 ep = fc_exch_find(mp, xid);
41002 if (!ep) {
41003 - atomic_inc(&mp->stats.xid_not_found);
41004 + atomic_inc_unchecked(&mp->stats.xid_not_found);
41005 reject = FC_RJT_OX_ID;
41006 goto out;
41007 }
41008 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41009 ep = fc_exch_find(mp, xid);
41010 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
41011 if (ep) {
41012 - atomic_inc(&mp->stats.xid_busy);
41013 + atomic_inc_unchecked(&mp->stats.xid_busy);
41014 reject = FC_RJT_RX_ID;
41015 goto rel;
41016 }
41017 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41018 }
41019 xid = ep->xid; /* get our XID */
41020 } else if (!ep) {
41021 - atomic_inc(&mp->stats.xid_not_found);
41022 + atomic_inc_unchecked(&mp->stats.xid_not_found);
41023 reject = FC_RJT_RX_ID; /* XID not found */
41024 goto out;
41025 }
41026 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41027 } else {
41028 sp = &ep->seq;
41029 if (sp->id != fh->fh_seq_id) {
41030 - atomic_inc(&mp->stats.seq_not_found);
41031 + atomic_inc_unchecked(&mp->stats.seq_not_found);
41032 if (f_ctl & FC_FC_END_SEQ) {
41033 /*
41034 * Update sequence_id based on incoming last
41035 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41036
41037 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
41038 if (!ep) {
41039 - atomic_inc(&mp->stats.xid_not_found);
41040 + atomic_inc_unchecked(&mp->stats.xid_not_found);
41041 goto out;
41042 }
41043 if (ep->esb_stat & ESB_ST_COMPLETE) {
41044 - atomic_inc(&mp->stats.xid_not_found);
41045 + atomic_inc_unchecked(&mp->stats.xid_not_found);
41046 goto rel;
41047 }
41048 if (ep->rxid == FC_XID_UNKNOWN)
41049 ep->rxid = ntohs(fh->fh_rx_id);
41050 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
41051 - atomic_inc(&mp->stats.xid_not_found);
41052 + atomic_inc_unchecked(&mp->stats.xid_not_found);
41053 goto rel;
41054 }
41055 if (ep->did != ntoh24(fh->fh_s_id) &&
41056 ep->did != FC_FID_FLOGI) {
41057 - atomic_inc(&mp->stats.xid_not_found);
41058 + atomic_inc_unchecked(&mp->stats.xid_not_found);
41059 goto rel;
41060 }
41061 sof = fr_sof(fp);
41062 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41063 sp->ssb_stat |= SSB_ST_RESP;
41064 sp->id = fh->fh_seq_id;
41065 } else if (sp->id != fh->fh_seq_id) {
41066 - atomic_inc(&mp->stats.seq_not_found);
41067 + atomic_inc_unchecked(&mp->stats.seq_not_found);
41068 goto rel;
41069 }
41070
41071 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41072 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
41073
41074 if (!sp)
41075 - atomic_inc(&mp->stats.xid_not_found);
41076 + atomic_inc_unchecked(&mp->stats.xid_not_found);
41077 else
41078 - atomic_inc(&mp->stats.non_bls_resp);
41079 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
41080
41081 fc_frame_free(fp);
41082 }
41083 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
41084
41085 list_for_each_entry(ema, &lport->ema_list, ema_list) {
41086 mp = ema->mp;
41087 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
41088 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
41089 st->fc_no_free_exch_xid +=
41090 - atomic_read(&mp->stats.no_free_exch_xid);
41091 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
41092 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
41093 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
41094 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
41095 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
41096 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
41097 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
41098 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
41099 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
41100 }
41101 }
41102 EXPORT_SYMBOL(fc_exch_update_stats);
41103 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
41104 index bdb81cd..d3c7c2c 100644
41105 --- a/drivers/scsi/libsas/sas_ata.c
41106 +++ b/drivers/scsi/libsas/sas_ata.c
41107 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
41108 .postreset = ata_std_postreset,
41109 .error_handler = ata_std_error_handler,
41110 .post_internal_cmd = sas_ata_post_internal,
41111 - .qc_defer = ata_std_qc_defer,
41112 + .qc_defer = ata_std_qc_defer,
41113 .qc_prep = ata_noop_qc_prep,
41114 .qc_issue = sas_ata_qc_issue,
41115 .qc_fill_rtf = sas_ata_qc_fill_rtf,
41116 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
41117 index df4c13a..a51e90c 100644
41118 --- a/drivers/scsi/lpfc/lpfc.h
41119 +++ b/drivers/scsi/lpfc/lpfc.h
41120 @@ -424,7 +424,7 @@ struct lpfc_vport {
41121 struct dentry *debug_nodelist;
41122 struct dentry *vport_debugfs_root;
41123 struct lpfc_debugfs_trc *disc_trc;
41124 - atomic_t disc_trc_cnt;
41125 + atomic_unchecked_t disc_trc_cnt;
41126 #endif
41127 uint8_t stat_data_enabled;
41128 uint8_t stat_data_blocked;
41129 @@ -842,8 +842,8 @@ struct lpfc_hba {
41130 struct timer_list fabric_block_timer;
41131 unsigned long bit_flags;
41132 #define FABRIC_COMANDS_BLOCKED 0
41133 - atomic_t num_rsrc_err;
41134 - atomic_t num_cmd_success;
41135 + atomic_unchecked_t num_rsrc_err;
41136 + atomic_unchecked_t num_cmd_success;
41137 unsigned long last_rsrc_error_time;
41138 unsigned long last_ramp_down_time;
41139 unsigned long last_ramp_up_time;
41140 @@ -879,7 +879,7 @@ struct lpfc_hba {
41141
41142 struct dentry *debug_slow_ring_trc;
41143 struct lpfc_debugfs_trc *slow_ring_trc;
41144 - atomic_t slow_ring_trc_cnt;
41145 + atomic_unchecked_t slow_ring_trc_cnt;
41146 /* iDiag debugfs sub-directory */
41147 struct dentry *idiag_root;
41148 struct dentry *idiag_pci_cfg;
41149 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
41150 index f63f5ff..de29189 100644
41151 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
41152 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
41153 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
41154
41155 #include <linux/debugfs.h>
41156
41157 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41158 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41159 static unsigned long lpfc_debugfs_start_time = 0L;
41160
41161 /* iDiag */
41162 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
41163 lpfc_debugfs_enable = 0;
41164
41165 len = 0;
41166 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
41167 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
41168 (lpfc_debugfs_max_disc_trc - 1);
41169 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
41170 dtp = vport->disc_trc + i;
41171 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
41172 lpfc_debugfs_enable = 0;
41173
41174 len = 0;
41175 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
41176 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
41177 (lpfc_debugfs_max_slow_ring_trc - 1);
41178 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
41179 dtp = phba->slow_ring_trc + i;
41180 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
41181 !vport || !vport->disc_trc)
41182 return;
41183
41184 - index = atomic_inc_return(&vport->disc_trc_cnt) &
41185 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
41186 (lpfc_debugfs_max_disc_trc - 1);
41187 dtp = vport->disc_trc + index;
41188 dtp->fmt = fmt;
41189 dtp->data1 = data1;
41190 dtp->data2 = data2;
41191 dtp->data3 = data3;
41192 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41193 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41194 dtp->jif = jiffies;
41195 #endif
41196 return;
41197 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
41198 !phba || !phba->slow_ring_trc)
41199 return;
41200
41201 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
41202 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
41203 (lpfc_debugfs_max_slow_ring_trc - 1);
41204 dtp = phba->slow_ring_trc + index;
41205 dtp->fmt = fmt;
41206 dtp->data1 = data1;
41207 dtp->data2 = data2;
41208 dtp->data3 = data3;
41209 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41210 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41211 dtp->jif = jiffies;
41212 #endif
41213 return;
41214 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41215 "slow_ring buffer\n");
41216 goto debug_failed;
41217 }
41218 - atomic_set(&phba->slow_ring_trc_cnt, 0);
41219 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
41220 memset(phba->slow_ring_trc, 0,
41221 (sizeof(struct lpfc_debugfs_trc) *
41222 lpfc_debugfs_max_slow_ring_trc));
41223 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41224 "buffer\n");
41225 goto debug_failed;
41226 }
41227 - atomic_set(&vport->disc_trc_cnt, 0);
41228 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
41229
41230 snprintf(name, sizeof(name), "discovery_trace");
41231 vport->debug_disc_trc =
41232 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
41233 index 89ad558..76956c4 100644
41234 --- a/drivers/scsi/lpfc/lpfc_init.c
41235 +++ b/drivers/scsi/lpfc/lpfc_init.c
41236 @@ -10618,8 +10618,10 @@ lpfc_init(void)
41237 "misc_register returned with status %d", error);
41238
41239 if (lpfc_enable_npiv) {
41240 - lpfc_transport_functions.vport_create = lpfc_vport_create;
41241 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41242 + pax_open_kernel();
41243 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
41244 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41245 + pax_close_kernel();
41246 }
41247 lpfc_transport_template =
41248 fc_attach_transport(&lpfc_transport_functions);
41249 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
41250 index 60e5a17..ff7a793 100644
41251 --- a/drivers/scsi/lpfc/lpfc_scsi.c
41252 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
41253 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
41254 uint32_t evt_posted;
41255
41256 spin_lock_irqsave(&phba->hbalock, flags);
41257 - atomic_inc(&phba->num_rsrc_err);
41258 + atomic_inc_unchecked(&phba->num_rsrc_err);
41259 phba->last_rsrc_error_time = jiffies;
41260
41261 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
41262 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
41263 unsigned long flags;
41264 struct lpfc_hba *phba = vport->phba;
41265 uint32_t evt_posted;
41266 - atomic_inc(&phba->num_cmd_success);
41267 + atomic_inc_unchecked(&phba->num_cmd_success);
41268
41269 if (vport->cfg_lun_queue_depth <= queue_depth)
41270 return;
41271 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41272 unsigned long num_rsrc_err, num_cmd_success;
41273 int i;
41274
41275 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
41276 - num_cmd_success = atomic_read(&phba->num_cmd_success);
41277 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
41278 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
41279
41280 /*
41281 * The error and success command counters are global per
41282 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41283 }
41284 }
41285 lpfc_destroy_vport_work_array(phba, vports);
41286 - atomic_set(&phba->num_rsrc_err, 0);
41287 - atomic_set(&phba->num_cmd_success, 0);
41288 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
41289 + atomic_set_unchecked(&phba->num_cmd_success, 0);
41290 }
41291
41292 /**
41293 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
41294 }
41295 }
41296 lpfc_destroy_vport_work_array(phba, vports);
41297 - atomic_set(&phba->num_rsrc_err, 0);
41298 - atomic_set(&phba->num_cmd_success, 0);
41299 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
41300 + atomic_set_unchecked(&phba->num_cmd_success, 0);
41301 }
41302
41303 /**
41304 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41305 index b46f5e9..c4c4ccb 100644
41306 --- a/drivers/scsi/pmcraid.c
41307 +++ b/drivers/scsi/pmcraid.c
41308 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41309 res->scsi_dev = scsi_dev;
41310 scsi_dev->hostdata = res;
41311 res->change_detected = 0;
41312 - atomic_set(&res->read_failures, 0);
41313 - atomic_set(&res->write_failures, 0);
41314 + atomic_set_unchecked(&res->read_failures, 0);
41315 + atomic_set_unchecked(&res->write_failures, 0);
41316 rc = 0;
41317 }
41318 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41319 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41320
41321 /* If this was a SCSI read/write command keep count of errors */
41322 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41323 - atomic_inc(&res->read_failures);
41324 + atomic_inc_unchecked(&res->read_failures);
41325 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41326 - atomic_inc(&res->write_failures);
41327 + atomic_inc_unchecked(&res->write_failures);
41328
41329 if (!RES_IS_GSCSI(res->cfg_entry) &&
41330 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41331 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
41332 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41333 * hrrq_id assigned here in queuecommand
41334 */
41335 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41336 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41337 pinstance->num_hrrq;
41338 cmd->cmd_done = pmcraid_io_done;
41339
41340 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
41341 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41342 * hrrq_id assigned here in queuecommand
41343 */
41344 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41345 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41346 pinstance->num_hrrq;
41347
41348 if (request_size) {
41349 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41350
41351 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41352 /* add resources only after host is added into system */
41353 - if (!atomic_read(&pinstance->expose_resources))
41354 + if (!atomic_read_unchecked(&pinstance->expose_resources))
41355 return;
41356
41357 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
41358 @@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
41359 init_waitqueue_head(&pinstance->reset_wait_q);
41360
41361 atomic_set(&pinstance->outstanding_cmds, 0);
41362 - atomic_set(&pinstance->last_message_id, 0);
41363 - atomic_set(&pinstance->expose_resources, 0);
41364 + atomic_set_unchecked(&pinstance->last_message_id, 0);
41365 + atomic_set_unchecked(&pinstance->expose_resources, 0);
41366
41367 INIT_LIST_HEAD(&pinstance->free_res_q);
41368 INIT_LIST_HEAD(&pinstance->used_res_q);
41369 @@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
41370 /* Schedule worker thread to handle CCN and take care of adding and
41371 * removing devices to OS
41372 */
41373 - atomic_set(&pinstance->expose_resources, 1);
41374 + atomic_set_unchecked(&pinstance->expose_resources, 1);
41375 schedule_work(&pinstance->worker_q);
41376 return rc;
41377
41378 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41379 index e1d150f..6c6df44 100644
41380 --- a/drivers/scsi/pmcraid.h
41381 +++ b/drivers/scsi/pmcraid.h
41382 @@ -748,7 +748,7 @@ struct pmcraid_instance {
41383 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
41384
41385 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
41386 - atomic_t last_message_id;
41387 + atomic_unchecked_t last_message_id;
41388
41389 /* configuration table */
41390 struct pmcraid_config_table *cfg_table;
41391 @@ -777,7 +777,7 @@ struct pmcraid_instance {
41392 atomic_t outstanding_cmds;
41393
41394 /* should add/delete resources to mid-layer now ?*/
41395 - atomic_t expose_resources;
41396 + atomic_unchecked_t expose_resources;
41397
41398
41399
41400 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
41401 struct pmcraid_config_table_entry_ext cfg_entry_ext;
41402 };
41403 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41404 - atomic_t read_failures; /* count of failed READ commands */
41405 - atomic_t write_failures; /* count of failed WRITE commands */
41406 + atomic_unchecked_t read_failures; /* count of failed READ commands */
41407 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41408
41409 /* To indicate add/delete/modify during CCN */
41410 u8 change_detected;
41411 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
41412 index 83d7984..a27d947 100644
41413 --- a/drivers/scsi/qla2xxx/qla_attr.c
41414 +++ b/drivers/scsi/qla2xxx/qla_attr.c
41415 @@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
41416 return 0;
41417 }
41418
41419 -struct fc_function_template qla2xxx_transport_functions = {
41420 +fc_function_template_no_const qla2xxx_transport_functions = {
41421
41422 .show_host_node_name = 1,
41423 .show_host_port_name = 1,
41424 @@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
41425 .bsg_timeout = qla24xx_bsg_timeout,
41426 };
41427
41428 -struct fc_function_template qla2xxx_transport_vport_functions = {
41429 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
41430
41431 .show_host_node_name = 1,
41432 .show_host_port_name = 1,
41433 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
41434 index 2411d1a..4673766 100644
41435 --- a/drivers/scsi/qla2xxx/qla_gbl.h
41436 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
41437 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
41438 struct device_attribute;
41439 extern struct device_attribute *qla2x00_host_attrs[];
41440 struct fc_function_template;
41441 -extern struct fc_function_template qla2xxx_transport_functions;
41442 -extern struct fc_function_template qla2xxx_transport_vport_functions;
41443 +extern fc_function_template_no_const qla2xxx_transport_functions;
41444 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
41445 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
41446 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
41447 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
41448 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
41449 index 10d23f8..a7d5d4c 100644
41450 --- a/drivers/scsi/qla2xxx/qla_os.c
41451 +++ b/drivers/scsi/qla2xxx/qla_os.c
41452 @@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
41453 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
41454 /* Ok, a 64bit DMA mask is applicable. */
41455 ha->flags.enable_64bit_addressing = 1;
41456 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41457 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41458 + pax_open_kernel();
41459 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41460 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41461 + pax_close_kernel();
41462 return;
41463 }
41464 }
41465 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41466 index 329d553..f20d31d 100644
41467 --- a/drivers/scsi/qla4xxx/ql4_def.h
41468 +++ b/drivers/scsi/qla4xxx/ql4_def.h
41469 @@ -273,7 +273,7 @@ struct ddb_entry {
41470 * (4000 only) */
41471 atomic_t relogin_timer; /* Max Time to wait for
41472 * relogin to complete */
41473 - atomic_t relogin_retry_count; /* Num of times relogin has been
41474 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41475 * retried */
41476 uint32_t default_time2wait; /* Default Min time between
41477 * relogins (+aens) */
41478 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41479 index 4cec123..7c1329f 100644
41480 --- a/drivers/scsi/qla4xxx/ql4_os.c
41481 +++ b/drivers/scsi/qla4xxx/ql4_os.c
41482 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
41483 */
41484 if (!iscsi_is_session_online(cls_sess)) {
41485 /* Reset retry relogin timer */
41486 - atomic_inc(&ddb_entry->relogin_retry_count);
41487 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41488 DEBUG2(ql4_printk(KERN_INFO, ha,
41489 "%s: index[%d] relogin timed out-retrying"
41490 " relogin (%d), retry (%d)\n", __func__,
41491 ddb_entry->fw_ddb_index,
41492 - atomic_read(&ddb_entry->relogin_retry_count),
41493 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
41494 ddb_entry->default_time2wait + 4));
41495 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
41496 atomic_set(&ddb_entry->retry_relogin_timer,
41497 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
41498
41499 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41500 atomic_set(&ddb_entry->relogin_timer, 0);
41501 - atomic_set(&ddb_entry->relogin_retry_count, 0);
41502 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41503 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
41504 ddb_entry->default_relogin_timeout =
41505 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
41506 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41507 index 2c0d0ec..4e8681a 100644
41508 --- a/drivers/scsi/scsi.c
41509 +++ b/drivers/scsi/scsi.c
41510 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41511 unsigned long timeout;
41512 int rtn = 0;
41513
41514 - atomic_inc(&cmd->device->iorequest_cnt);
41515 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41516
41517 /* check if the device is still usable */
41518 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41519 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41520 index f1bf5af..f67e943 100644
41521 --- a/drivers/scsi/scsi_lib.c
41522 +++ b/drivers/scsi/scsi_lib.c
41523 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41524 shost = sdev->host;
41525 scsi_init_cmd_errh(cmd);
41526 cmd->result = DID_NO_CONNECT << 16;
41527 - atomic_inc(&cmd->device->iorequest_cnt);
41528 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41529
41530 /*
41531 * SCSI request completion path will do scsi_device_unbusy(),
41532 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
41533
41534 INIT_LIST_HEAD(&cmd->eh_entry);
41535
41536 - atomic_inc(&cmd->device->iodone_cnt);
41537 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
41538 if (cmd->result)
41539 - atomic_inc(&cmd->device->ioerr_cnt);
41540 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41541
41542 disposition = scsi_decide_disposition(cmd);
41543 if (disposition != SUCCESS &&
41544 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41545 index 931a7d9..0c2a754 100644
41546 --- a/drivers/scsi/scsi_sysfs.c
41547 +++ b/drivers/scsi/scsi_sysfs.c
41548 @@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41549 char *buf) \
41550 { \
41551 struct scsi_device *sdev = to_scsi_device(dev); \
41552 - unsigned long long count = atomic_read(&sdev->field); \
41553 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
41554 return snprintf(buf, 20, "0x%llx\n", count); \
41555 } \
41556 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41557 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41558 index 84a1fdf..693b0d6 100644
41559 --- a/drivers/scsi/scsi_tgt_lib.c
41560 +++ b/drivers/scsi/scsi_tgt_lib.c
41561 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41562 int err;
41563
41564 dprintk("%lx %u\n", uaddr, len);
41565 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41566 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41567 if (err) {
41568 /*
41569 * TODO: need to fixup sg_tablesize, max_segment_size,
41570 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
41571 index e894ca7..de9d7660 100644
41572 --- a/drivers/scsi/scsi_transport_fc.c
41573 +++ b/drivers/scsi/scsi_transport_fc.c
41574 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
41575 * Netlink Infrastructure
41576 */
41577
41578 -static atomic_t fc_event_seq;
41579 +static atomic_unchecked_t fc_event_seq;
41580
41581 /**
41582 * fc_get_event_number - Obtain the next sequential FC event number
41583 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
41584 u32
41585 fc_get_event_number(void)
41586 {
41587 - return atomic_add_return(1, &fc_event_seq);
41588 + return atomic_add_return_unchecked(1, &fc_event_seq);
41589 }
41590 EXPORT_SYMBOL(fc_get_event_number);
41591
41592 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
41593 {
41594 int error;
41595
41596 - atomic_set(&fc_event_seq, 0);
41597 + atomic_set_unchecked(&fc_event_seq, 0);
41598
41599 error = transport_class_register(&fc_host_class);
41600 if (error)
41601 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
41602 char *cp;
41603
41604 *val = simple_strtoul(buf, &cp, 0);
41605 - if ((*cp && (*cp != '\n')) || (*val < 0))
41606 + if (*cp && (*cp != '\n'))
41607 return -EINVAL;
41608 /*
41609 * Check for overflow; dev_loss_tmo is u32
41610 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
41611 index 31969f2..2b348f0 100644
41612 --- a/drivers/scsi/scsi_transport_iscsi.c
41613 +++ b/drivers/scsi/scsi_transport_iscsi.c
41614 @@ -79,7 +79,7 @@ struct iscsi_internal {
41615 struct transport_container session_cont;
41616 };
41617
41618 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
41619 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
41620 static struct workqueue_struct *iscsi_eh_timer_workq;
41621
41622 static DEFINE_IDA(iscsi_sess_ida);
41623 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
41624 int err;
41625
41626 ihost = shost->shost_data;
41627 - session->sid = atomic_add_return(1, &iscsi_session_nr);
41628 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
41629
41630 if (target_id == ISCSI_MAX_TARGET) {
41631 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
41632 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
41633 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
41634 ISCSI_TRANSPORT_VERSION);
41635
41636 - atomic_set(&iscsi_session_nr, 0);
41637 + atomic_set_unchecked(&iscsi_session_nr, 0);
41638
41639 err = class_register(&iscsi_transport_class);
41640 if (err)
41641 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
41642 index f379c7f..e8fc69c 100644
41643 --- a/drivers/scsi/scsi_transport_srp.c
41644 +++ b/drivers/scsi/scsi_transport_srp.c
41645 @@ -33,7 +33,7 @@
41646 #include "scsi_transport_srp_internal.h"
41647
41648 struct srp_host_attrs {
41649 - atomic_t next_port_id;
41650 + atomic_unchecked_t next_port_id;
41651 };
41652 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
41653
41654 @@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
41655 struct Scsi_Host *shost = dev_to_shost(dev);
41656 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
41657
41658 - atomic_set(&srp_host->next_port_id, 0);
41659 + atomic_set_unchecked(&srp_host->next_port_id, 0);
41660 return 0;
41661 }
41662
41663 @@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
41664 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
41665 rport->roles = ids->roles;
41666
41667 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
41668 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
41669 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
41670
41671 transport_setup_device(&rport->dev);
41672 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
41673 index 7992635..609faf8 100644
41674 --- a/drivers/scsi/sd.c
41675 +++ b/drivers/scsi/sd.c
41676 @@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
41677 sdkp->disk = gd;
41678 sdkp->index = index;
41679 atomic_set(&sdkp->openers, 0);
41680 - atomic_set(&sdkp->device->ioerr_cnt, 0);
41681 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
41682
41683 if (!sdp->request_queue->rq_timeout) {
41684 if (sdp->type != TYPE_MOD)
41685 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
41686 index be2c9a6..275525c 100644
41687 --- a/drivers/scsi/sg.c
41688 +++ b/drivers/scsi/sg.c
41689 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
41690 sdp->disk->disk_name,
41691 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
41692 NULL,
41693 - (char *)arg);
41694 + (char __user *)arg);
41695 case BLKTRACESTART:
41696 return blk_trace_startstop(sdp->device->request_queue, 1);
41697 case BLKTRACESTOP:
41698 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
41699 index 19ee901..6e8c2ef 100644
41700 --- a/drivers/spi/spi.c
41701 +++ b/drivers/spi/spi.c
41702 @@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
41703 EXPORT_SYMBOL_GPL(spi_bus_unlock);
41704
41705 /* portable code must never pass more than 32 bytes */
41706 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
41707 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
41708
41709 static u8 *buf;
41710
41711 diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
41712 index c7a5f97..71ecd35 100644
41713 --- a/drivers/staging/iio/iio_hwmon.c
41714 +++ b/drivers/staging/iio/iio_hwmon.c
41715 @@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
41716 static int iio_hwmon_probe(struct platform_device *pdev)
41717 {
41718 struct iio_hwmon_state *st;
41719 - struct sensor_device_attribute *a;
41720 + sensor_device_attribute_no_const *a;
41721 int ret, i;
41722 int in_i = 1, temp_i = 1, curr_i = 1;
41723 enum iio_chan_type type;
41724 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
41725 index 34afc16..ffe44dd 100644
41726 --- a/drivers/staging/octeon/ethernet-rx.c
41727 +++ b/drivers/staging/octeon/ethernet-rx.c
41728 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
41729 /* Increment RX stats for virtual ports */
41730 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
41731 #ifdef CONFIG_64BIT
41732 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
41733 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
41734 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
41735 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
41736 #else
41737 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
41738 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
41739 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
41740 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
41741 #endif
41742 }
41743 netif_receive_skb(skb);
41744 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
41745 dev->name);
41746 */
41747 #ifdef CONFIG_64BIT
41748 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
41749 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
41750 #else
41751 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
41752 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
41753 #endif
41754 dev_kfree_skb_irq(skb);
41755 }
41756 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
41757 index ef32dc1..a159d68 100644
41758 --- a/drivers/staging/octeon/ethernet.c
41759 +++ b/drivers/staging/octeon/ethernet.c
41760 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
41761 * since the RX tasklet also increments it.
41762 */
41763 #ifdef CONFIG_64BIT
41764 - atomic64_add(rx_status.dropped_packets,
41765 - (atomic64_t *)&priv->stats.rx_dropped);
41766 + atomic64_add_unchecked(rx_status.dropped_packets,
41767 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
41768 #else
41769 - atomic_add(rx_status.dropped_packets,
41770 - (atomic_t *)&priv->stats.rx_dropped);
41771 + atomic_add_unchecked(rx_status.dropped_packets,
41772 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
41773 #endif
41774 }
41775
41776 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
41777 index a2b7e03..aaf3630 100644
41778 --- a/drivers/staging/ramster/tmem.c
41779 +++ b/drivers/staging/ramster/tmem.c
41780 @@ -50,25 +50,25 @@
41781 * A tmem host implementation must use this function to register callbacks
41782 * for memory allocation.
41783 */
41784 -static struct tmem_hostops tmem_hostops;
41785 +static struct tmem_hostops *tmem_hostops;
41786
41787 static void tmem_objnode_tree_init(void);
41788
41789 void tmem_register_hostops(struct tmem_hostops *m)
41790 {
41791 tmem_objnode_tree_init();
41792 - tmem_hostops = *m;
41793 + tmem_hostops = m;
41794 }
41795
41796 /*
41797 * A tmem host implementation must use this function to register
41798 * callbacks for a page-accessible memory (PAM) implementation.
41799 */
41800 -static struct tmem_pamops tmem_pamops;
41801 +static struct tmem_pamops *tmem_pamops;
41802
41803 void tmem_register_pamops(struct tmem_pamops *m)
41804 {
41805 - tmem_pamops = *m;
41806 + tmem_pamops = m;
41807 }
41808
41809 /*
41810 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
41811 obj->pampd_count = 0;
41812 #ifdef CONFIG_RAMSTER
41813 if (tmem_pamops.new_obj != NULL)
41814 - (*tmem_pamops.new_obj)(obj);
41815 + (tmem_pamops->new_obj)(obj);
41816 #endif
41817 SET_SENTINEL(obj, OBJ);
41818
41819 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
41820 rbnode = rb_next(rbnode);
41821 tmem_pampd_destroy_all_in_obj(obj, true);
41822 tmem_obj_free(obj, hb);
41823 - (*tmem_hostops.obj_free)(obj, pool);
41824 + (tmem_hostops->obj_free)(obj, pool);
41825 }
41826 spin_unlock(&hb->lock);
41827 }
41828 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
41829 ASSERT_SENTINEL(obj, OBJ);
41830 BUG_ON(obj->pool == NULL);
41831 ASSERT_SENTINEL(obj->pool, POOL);
41832 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
41833 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
41834 if (unlikely(objnode == NULL))
41835 goto out;
41836 objnode->obj = obj;
41837 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
41838 ASSERT_SENTINEL(pool, POOL);
41839 objnode->obj->objnode_count--;
41840 objnode->obj = NULL;
41841 - (*tmem_hostops.objnode_free)(objnode, pool);
41842 + (tmem_hostops->objnode_free)(objnode, pool);
41843 }
41844
41845 /*
41846 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
41847 void *old_pampd = *(void **)slot;
41848 *(void **)slot = new_pampd;
41849 if (!no_free)
41850 - (*tmem_pamops.free)(old_pampd, obj->pool,
41851 + (tmem_pamops->free)(old_pampd, obj->pool,
41852 NULL, 0, false);
41853 ret = new_pampd;
41854 }
41855 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
41856 if (objnode->slots[i]) {
41857 if (ht == 1) {
41858 obj->pampd_count--;
41859 - (*tmem_pamops.free)(objnode->slots[i],
41860 + (tmem_pamops->free)(objnode->slots[i],
41861 obj->pool, NULL, 0, true);
41862 objnode->slots[i] = NULL;
41863 continue;
41864 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
41865 return;
41866 if (obj->objnode_tree_height == 0) {
41867 obj->pampd_count--;
41868 - (*tmem_pamops.free)(obj->objnode_tree_root,
41869 + (tmem_pamops->free)(obj->objnode_tree_root,
41870 obj->pool, NULL, 0, true);
41871 } else {
41872 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
41873 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
41874 obj->objnode_tree_root = NULL;
41875 #ifdef CONFIG_RAMSTER
41876 if (tmem_pamops.free_obj != NULL)
41877 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
41878 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
41879 #endif
41880 }
41881
41882 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41883 /* if found, is a dup put, flush the old one */
41884 pampd_del = tmem_pampd_delete_from_obj(obj, index);
41885 BUG_ON(pampd_del != pampd);
41886 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
41887 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
41888 if (obj->pampd_count == 0) {
41889 objnew = obj;
41890 objfound = NULL;
41891 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41892 pampd = NULL;
41893 }
41894 } else {
41895 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
41896 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
41897 if (unlikely(obj == NULL)) {
41898 ret = -ENOMEM;
41899 goto out;
41900 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41901 if (unlikely(ret == -ENOMEM))
41902 /* may have partially built objnode tree ("stump") */
41903 goto delete_and_free;
41904 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
41905 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
41906 goto out;
41907
41908 delete_and_free:
41909 (void)tmem_pampd_delete_from_obj(obj, index);
41910 if (pampd)
41911 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
41912 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
41913 if (objnew) {
41914 tmem_obj_free(objnew, hb);
41915 - (*tmem_hostops.obj_free)(objnew, pool);
41916 + (tmem_hostops->obj_free)(objnew, pool);
41917 }
41918 out:
41919 spin_unlock(&hb->lock);
41920 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
41921 if (pampd != NULL) {
41922 BUG_ON(obj == NULL);
41923 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
41924 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
41925 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
41926 } else if (delete) {
41927 BUG_ON(obj == NULL);
41928 (void)tmem_pampd_delete_from_obj(obj, index);
41929 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
41930 int ret = 0;
41931
41932 if (!is_ephemeral(pool))
41933 - new_pampd = (*tmem_pamops.repatriate_preload)(
41934 + new_pampd = (tmem_pamops->repatriate_preload)(
41935 old_pampd, pool, oidp, index, &intransit);
41936 if (intransit)
41937 ret = -EAGAIN;
41938 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
41939 /* must release the hb->lock else repatriate can't sleep */
41940 spin_unlock(&hb->lock);
41941 if (!intransit)
41942 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
41943 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
41944 oidp, index, free, data);
41945 if (ret == -EAGAIN) {
41946 /* rare I think, but should cond_resched()??? */
41947 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
41948 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
41949 /* if we bug here, pamops wasn't properly set up for ramster */
41950 BUG_ON(tmem_pamops.replace_in_obj == NULL);
41951 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
41952 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
41953 out:
41954 spin_unlock(&hb->lock);
41955 return ret;
41956 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41957 if (free) {
41958 if (obj->pampd_count == 0) {
41959 tmem_obj_free(obj, hb);
41960 - (*tmem_hostops.obj_free)(obj, pool);
41961 + (tmem_hostops->obj_free)(obj, pool);
41962 obj = NULL;
41963 }
41964 }
41965 if (free)
41966 - ret = (*tmem_pamops.get_data_and_free)(
41967 + ret = (tmem_pamops->get_data_and_free)(
41968 data, sizep, raw, pampd, pool, oidp, index);
41969 else
41970 - ret = (*tmem_pamops.get_data)(
41971 + ret = (tmem_pamops->get_data)(
41972 data, sizep, raw, pampd, pool, oidp, index);
41973 if (ret < 0)
41974 goto out;
41975 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
41976 pampd = tmem_pampd_delete_from_obj(obj, index);
41977 if (pampd == NULL)
41978 goto out;
41979 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
41980 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
41981 if (obj->pampd_count == 0) {
41982 tmem_obj_free(obj, hb);
41983 - (*tmem_hostops.obj_free)(obj, pool);
41984 + (tmem_hostops->obj_free)(obj, pool);
41985 }
41986 ret = 0;
41987
41988 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
41989 goto out;
41990 tmem_pampd_destroy_all_in_obj(obj, false);
41991 tmem_obj_free(obj, hb);
41992 - (*tmem_hostops.obj_free)(obj, pool);
41993 + (tmem_hostops->obj_free)(obj, pool);
41994 ret = 0;
41995
41996 out:
41997 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
41998 index dc23395..cf7e9b1 100644
41999 --- a/drivers/staging/rtl8712/rtl871x_io.h
42000 +++ b/drivers/staging/rtl8712/rtl871x_io.h
42001 @@ -108,7 +108,7 @@ struct _io_ops {
42002 u8 *pmem);
42003 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
42004 u8 *pmem);
42005 -};
42006 +} __no_const;
42007
42008 struct io_req {
42009 struct list_head list;
42010 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
42011 index 1f5088b..0e59820 100644
42012 --- a/drivers/staging/sbe-2t3e3/netdev.c
42013 +++ b/drivers/staging/sbe-2t3e3/netdev.c
42014 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42015 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
42016
42017 if (rlen)
42018 - if (copy_to_user(data, &resp, rlen))
42019 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
42020 return -EFAULT;
42021
42022 return 0;
42023 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42024 index 5dddc4d..34fcb2f 100644
42025 --- a/drivers/staging/usbip/vhci.h
42026 +++ b/drivers/staging/usbip/vhci.h
42027 @@ -83,7 +83,7 @@ struct vhci_hcd {
42028 unsigned resuming:1;
42029 unsigned long re_timeout;
42030
42031 - atomic_t seqnum;
42032 + atomic_unchecked_t seqnum;
42033
42034 /*
42035 * NOTE:
42036 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42037 index c3aa219..bf8b3de 100644
42038 --- a/drivers/staging/usbip/vhci_hcd.c
42039 +++ b/drivers/staging/usbip/vhci_hcd.c
42040 @@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
42041 return;
42042 }
42043
42044 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42045 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42046 if (priv->seqnum == 0xffff)
42047 dev_info(&urb->dev->dev, "seqnum max\n");
42048
42049 @@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42050 return -ENOMEM;
42051 }
42052
42053 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42054 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42055 if (unlink->seqnum == 0xffff)
42056 pr_info("seqnum max\n");
42057
42058 @@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
42059 vdev->rhport = rhport;
42060 }
42061
42062 - atomic_set(&vhci->seqnum, 0);
42063 + atomic_set_unchecked(&vhci->seqnum, 0);
42064 spin_lock_init(&vhci->lock);
42065
42066 hcd->power_budget = 0; /* no limit */
42067 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42068 index ba5f1c0..11d8122 100644
42069 --- a/drivers/staging/usbip/vhci_rx.c
42070 +++ b/drivers/staging/usbip/vhci_rx.c
42071 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42072 if (!urb) {
42073 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
42074 pr_info("max seqnum %d\n",
42075 - atomic_read(&the_controller->seqnum));
42076 + atomic_read_unchecked(&the_controller->seqnum));
42077 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42078 return;
42079 }
42080 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42081 index 5f13890..36a044b 100644
42082 --- a/drivers/staging/vt6655/hostap.c
42083 +++ b/drivers/staging/vt6655/hostap.c
42084 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
42085 *
42086 */
42087
42088 +static net_device_ops_no_const apdev_netdev_ops;
42089 +
42090 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42091 {
42092 PSDevice apdev_priv;
42093 struct net_device *dev = pDevice->dev;
42094 int ret;
42095 - const struct net_device_ops apdev_netdev_ops = {
42096 - .ndo_start_xmit = pDevice->tx_80211,
42097 - };
42098
42099 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42100
42101 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42102 *apdev_priv = *pDevice;
42103 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42104
42105 + /* only half broken now */
42106 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42107 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42108
42109 pDevice->apdev->type = ARPHRD_IEEE80211;
42110 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42111 index 26a7d0e..897b083 100644
42112 --- a/drivers/staging/vt6656/hostap.c
42113 +++ b/drivers/staging/vt6656/hostap.c
42114 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
42115 *
42116 */
42117
42118 +static net_device_ops_no_const apdev_netdev_ops;
42119 +
42120 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42121 {
42122 PSDevice apdev_priv;
42123 struct net_device *dev = pDevice->dev;
42124 int ret;
42125 - const struct net_device_ops apdev_netdev_ops = {
42126 - .ndo_start_xmit = pDevice->tx_80211,
42127 - };
42128
42129 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42130
42131 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42132 *apdev_priv = *pDevice;
42133 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42134
42135 + /* only half broken now */
42136 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42137 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42138
42139 pDevice->apdev->type = ARPHRD_IEEE80211;
42140 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
42141 index 56c8e60..1920c63 100644
42142 --- a/drivers/staging/zcache/tmem.c
42143 +++ b/drivers/staging/zcache/tmem.c
42144 @@ -39,7 +39,7 @@
42145 * A tmem host implementation must use this function to register callbacks
42146 * for memory allocation.
42147 */
42148 -static struct tmem_hostops tmem_hostops;
42149 +static tmem_hostops_no_const tmem_hostops;
42150
42151 static void tmem_objnode_tree_init(void);
42152
42153 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
42154 * A tmem host implementation must use this function to register
42155 * callbacks for a page-accessible memory (PAM) implementation
42156 */
42157 -static struct tmem_pamops tmem_pamops;
42158 +static tmem_pamops_no_const tmem_pamops;
42159
42160 void tmem_register_pamops(struct tmem_pamops *m)
42161 {
42162 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
42163 index 0d4aa82..f7832d4 100644
42164 --- a/drivers/staging/zcache/tmem.h
42165 +++ b/drivers/staging/zcache/tmem.h
42166 @@ -180,6 +180,7 @@ struct tmem_pamops {
42167 void (*new_obj)(struct tmem_obj *);
42168 int (*replace_in_obj)(void *, struct tmem_obj *);
42169 };
42170 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
42171 extern void tmem_register_pamops(struct tmem_pamops *m);
42172
42173 /* memory allocation methods provided by the host implementation */
42174 @@ -189,6 +190,7 @@ struct tmem_hostops {
42175 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
42176 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
42177 };
42178 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
42179 extern void tmem_register_hostops(struct tmem_hostops *m);
42180
42181 /* core tmem accessor functions */
42182 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
42183 index 96f4981..4daaa7e 100644
42184 --- a/drivers/target/target_core_device.c
42185 +++ b/drivers/target/target_core_device.c
42186 @@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
42187 spin_lock_init(&dev->se_port_lock);
42188 spin_lock_init(&dev->se_tmr_lock);
42189 spin_lock_init(&dev->qf_cmd_lock);
42190 - atomic_set(&dev->dev_ordered_id, 0);
42191 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
42192 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
42193 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
42194 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
42195 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
42196 index bd587b7..173daf3 100644
42197 --- a/drivers/target/target_core_transport.c
42198 +++ b/drivers/target/target_core_transport.c
42199 @@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
42200 * Used to determine when ORDERED commands should go from
42201 * Dormant to Active status.
42202 */
42203 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
42204 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
42205 smp_mb__after_atomic_inc();
42206 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
42207 cmd->se_ordered_id, cmd->sam_task_attr,
42208 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
42209 index b09c8d1f..c4225c0 100644
42210 --- a/drivers/tty/cyclades.c
42211 +++ b/drivers/tty/cyclades.c
42212 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
42213 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
42214 info->port.count);
42215 #endif
42216 - info->port.count++;
42217 + atomic_inc(&info->port.count);
42218 #ifdef CY_DEBUG_COUNT
42219 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
42220 - current->pid, info->port.count);
42221 + current->pid, atomic_read(&info->port.count));
42222 #endif
42223
42224 /*
42225 @@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
42226 for (j = 0; j < cy_card[i].nports; j++) {
42227 info = &cy_card[i].ports[j];
42228
42229 - if (info->port.count) {
42230 + if (atomic_read(&info->port.count)) {
42231 /* XXX is the ldisc num worth this? */
42232 struct tty_struct *tty;
42233 struct tty_ldisc *ld;
42234 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
42235 index 13ee53b..418d164 100644
42236 --- a/drivers/tty/hvc/hvc_console.c
42237 +++ b/drivers/tty/hvc/hvc_console.c
42238 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
42239
42240 spin_lock_irqsave(&hp->port.lock, flags);
42241 /* Check and then increment for fast path open. */
42242 - if (hp->port.count++ > 0) {
42243 + if (atomic_inc_return(&hp->port.count) > 1) {
42244 spin_unlock_irqrestore(&hp->port.lock, flags);
42245 hvc_kick();
42246 return 0;
42247 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42248
42249 spin_lock_irqsave(&hp->port.lock, flags);
42250
42251 - if (--hp->port.count == 0) {
42252 + if (atomic_dec_return(&hp->port.count) == 0) {
42253 spin_unlock_irqrestore(&hp->port.lock, flags);
42254 /* We are done with the tty pointer now. */
42255 tty_port_tty_set(&hp->port, NULL);
42256 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42257 */
42258 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
42259 } else {
42260 - if (hp->port.count < 0)
42261 + if (atomic_read(&hp->port.count) < 0)
42262 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
42263 - hp->vtermno, hp->port.count);
42264 + hp->vtermno, atomic_read(&hp->port.count));
42265 spin_unlock_irqrestore(&hp->port.lock, flags);
42266 }
42267 }
42268 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
42269 * open->hangup case this can be called after the final close so prevent
42270 * that from happening for now.
42271 */
42272 - if (hp->port.count <= 0) {
42273 + if (atomic_read(&hp->port.count) <= 0) {
42274 spin_unlock_irqrestore(&hp->port.lock, flags);
42275 return;
42276 }
42277
42278 - hp->port.count = 0;
42279 + atomic_set(&hp->port.count, 0);
42280 spin_unlock_irqrestore(&hp->port.lock, flags);
42281 tty_port_tty_set(&hp->port, NULL);
42282
42283 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
42284 return -EPIPE;
42285
42286 /* FIXME what's this (unprotected) check for? */
42287 - if (hp->port.count <= 0)
42288 + if (atomic_read(&hp->port.count) <= 0)
42289 return -EIO;
42290
42291 spin_lock_irqsave(&hp->lock, flags);
42292 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
42293 index 8776357..b2d4afd 100644
42294 --- a/drivers/tty/hvc/hvcs.c
42295 +++ b/drivers/tty/hvc/hvcs.c
42296 @@ -83,6 +83,7 @@
42297 #include <asm/hvcserver.h>
42298 #include <asm/uaccess.h>
42299 #include <asm/vio.h>
42300 +#include <asm/local.h>
42301
42302 /*
42303 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
42304 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
42305
42306 spin_lock_irqsave(&hvcsd->lock, flags);
42307
42308 - if (hvcsd->port.count > 0) {
42309 + if (atomic_read(&hvcsd->port.count) > 0) {
42310 spin_unlock_irqrestore(&hvcsd->lock, flags);
42311 printk(KERN_INFO "HVCS: vterm state unchanged. "
42312 "The hvcs device node is still in use.\n");
42313 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
42314 }
42315 }
42316
42317 - hvcsd->port.count = 0;
42318 + atomic_set(&hvcsd->port.count, 0);
42319 hvcsd->port.tty = tty;
42320 tty->driver_data = hvcsd;
42321
42322 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
42323 unsigned long flags;
42324
42325 spin_lock_irqsave(&hvcsd->lock, flags);
42326 - hvcsd->port.count++;
42327 + atomic_inc(&hvcsd->port.count);
42328 hvcsd->todo_mask |= HVCS_SCHED_READ;
42329 spin_unlock_irqrestore(&hvcsd->lock, flags);
42330
42331 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42332 hvcsd = tty->driver_data;
42333
42334 spin_lock_irqsave(&hvcsd->lock, flags);
42335 - if (--hvcsd->port.count == 0) {
42336 + if (atomic_dec_and_test(&hvcsd->port.count)) {
42337
42338 vio_disable_interrupts(hvcsd->vdev);
42339
42340 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42341
42342 free_irq(irq, hvcsd);
42343 return;
42344 - } else if (hvcsd->port.count < 0) {
42345 + } else if (atomic_read(&hvcsd->port.count) < 0) {
42346 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
42347 " is missmanaged.\n",
42348 - hvcsd->vdev->unit_address, hvcsd->port.count);
42349 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
42350 }
42351
42352 spin_unlock_irqrestore(&hvcsd->lock, flags);
42353 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42354
42355 spin_lock_irqsave(&hvcsd->lock, flags);
42356 /* Preserve this so that we know how many kref refs to put */
42357 - temp_open_count = hvcsd->port.count;
42358 + temp_open_count = atomic_read(&hvcsd->port.count);
42359
42360 /*
42361 * Don't kref put inside the spinlock because the destruction
42362 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42363 tty->driver_data = NULL;
42364 hvcsd->port.tty = NULL;
42365
42366 - hvcsd->port.count = 0;
42367 + atomic_set(&hvcsd->port.count, 0);
42368
42369 /* This will drop any buffered data on the floor which is OK in a hangup
42370 * scenario. */
42371 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
42372 * the middle of a write operation? This is a crummy place to do this
42373 * but we want to keep it all in the spinlock.
42374 */
42375 - if (hvcsd->port.count <= 0) {
42376 + if (atomic_read(&hvcsd->port.count) <= 0) {
42377 spin_unlock_irqrestore(&hvcsd->lock, flags);
42378 return -ENODEV;
42379 }
42380 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
42381 {
42382 struct hvcs_struct *hvcsd = tty->driver_data;
42383
42384 - if (!hvcsd || hvcsd->port.count <= 0)
42385 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
42386 return 0;
42387
42388 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
42389 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
42390 index 2cde13d..645d78f 100644
42391 --- a/drivers/tty/ipwireless/tty.c
42392 +++ b/drivers/tty/ipwireless/tty.c
42393 @@ -29,6 +29,7 @@
42394 #include <linux/tty_driver.h>
42395 #include <linux/tty_flip.h>
42396 #include <linux/uaccess.h>
42397 +#include <asm/local.h>
42398
42399 #include "tty.h"
42400 #include "network.h"
42401 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42402 mutex_unlock(&tty->ipw_tty_mutex);
42403 return -ENODEV;
42404 }
42405 - if (tty->port.count == 0)
42406 + if (atomic_read(&tty->port.count) == 0)
42407 tty->tx_bytes_queued = 0;
42408
42409 - tty->port.count++;
42410 + atomic_inc(&tty->port.count);
42411
42412 tty->port.tty = linux_tty;
42413 linux_tty->driver_data = tty;
42414 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42415
42416 static void do_ipw_close(struct ipw_tty *tty)
42417 {
42418 - tty->port.count--;
42419 -
42420 - if (tty->port.count == 0) {
42421 + if (atomic_dec_return(&tty->port.count) == 0) {
42422 struct tty_struct *linux_tty = tty->port.tty;
42423
42424 if (linux_tty != NULL) {
42425 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
42426 return;
42427
42428 mutex_lock(&tty->ipw_tty_mutex);
42429 - if (tty->port.count == 0) {
42430 + if (atomic_read(&tty->port.count) == 0) {
42431 mutex_unlock(&tty->ipw_tty_mutex);
42432 return;
42433 }
42434 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
42435 return;
42436 }
42437
42438 - if (!tty->port.count) {
42439 + if (!atomic_read(&tty->port.count)) {
42440 mutex_unlock(&tty->ipw_tty_mutex);
42441 return;
42442 }
42443 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
42444 return -ENODEV;
42445
42446 mutex_lock(&tty->ipw_tty_mutex);
42447 - if (!tty->port.count) {
42448 + if (!atomic_read(&tty->port.count)) {
42449 mutex_unlock(&tty->ipw_tty_mutex);
42450 return -EINVAL;
42451 }
42452 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
42453 if (!tty)
42454 return -ENODEV;
42455
42456 - if (!tty->port.count)
42457 + if (!atomic_read(&tty->port.count))
42458 return -EINVAL;
42459
42460 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
42461 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
42462 if (!tty)
42463 return 0;
42464
42465 - if (!tty->port.count)
42466 + if (!atomic_read(&tty->port.count))
42467 return 0;
42468
42469 return tty->tx_bytes_queued;
42470 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
42471 if (!tty)
42472 return -ENODEV;
42473
42474 - if (!tty->port.count)
42475 + if (!atomic_read(&tty->port.count))
42476 return -EINVAL;
42477
42478 return get_control_lines(tty);
42479 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
42480 if (!tty)
42481 return -ENODEV;
42482
42483 - if (!tty->port.count)
42484 + if (!atomic_read(&tty->port.count))
42485 return -EINVAL;
42486
42487 return set_control_lines(tty, set, clear);
42488 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
42489 if (!tty)
42490 return -ENODEV;
42491
42492 - if (!tty->port.count)
42493 + if (!atomic_read(&tty->port.count))
42494 return -EINVAL;
42495
42496 /* FIXME: Exactly how is the tty object locked here .. */
42497 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
42498 * are gone */
42499 mutex_lock(&ttyj->ipw_tty_mutex);
42500 }
42501 - while (ttyj->port.count)
42502 + while (atomic_read(&ttyj->port.count))
42503 do_ipw_close(ttyj);
42504 ipwireless_disassociate_network_ttys(network,
42505 ttyj->channel_idx);
42506 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
42507 index f9d2850..b006f04 100644
42508 --- a/drivers/tty/moxa.c
42509 +++ b/drivers/tty/moxa.c
42510 @@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
42511 }
42512
42513 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
42514 - ch->port.count++;
42515 + atomic_inc(&ch->port.count);
42516 tty->driver_data = ch;
42517 tty_port_tty_set(&ch->port, tty);
42518 mutex_lock(&ch->port.mutex);
42519 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
42520 index bfd6771..e0d93c4 100644
42521 --- a/drivers/tty/n_gsm.c
42522 +++ b/drivers/tty/n_gsm.c
42523 @@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
42524 spin_lock_init(&dlci->lock);
42525 mutex_init(&dlci->mutex);
42526 dlci->fifo = &dlci->_fifo;
42527 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
42528 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
42529 kfree(dlci);
42530 return NULL;
42531 }
42532 @@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
42533 struct gsm_dlci *dlci = tty->driver_data;
42534 struct tty_port *port = &dlci->port;
42535
42536 - port->count++;
42537 + atomic_inc(&port->count);
42538 dlci_get(dlci);
42539 dlci_get(dlci->gsm->dlci[0]);
42540 mux_get(dlci->gsm);
42541 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
42542 index 19083ef..6e34e97 100644
42543 --- a/drivers/tty/n_tty.c
42544 +++ b/drivers/tty/n_tty.c
42545 @@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
42546 {
42547 *ops = tty_ldisc_N_TTY;
42548 ops->owner = NULL;
42549 - ops->refcount = ops->flags = 0;
42550 + atomic_set(&ops->refcount, 0);
42551 + ops->flags = 0;
42552 }
42553 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
42554 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
42555 index 79ff3a5..1fe9399 100644
42556 --- a/drivers/tty/pty.c
42557 +++ b/drivers/tty/pty.c
42558 @@ -791,8 +791,10 @@ static void __init unix98_pty_init(void)
42559 panic("Couldn't register Unix98 pts driver");
42560
42561 /* Now create the /dev/ptmx special device */
42562 + pax_open_kernel();
42563 tty_default_fops(&ptmx_fops);
42564 - ptmx_fops.open = ptmx_open;
42565 + *(void **)&ptmx_fops.open = ptmx_open;
42566 + pax_close_kernel();
42567
42568 cdev_init(&ptmx_cdev, &ptmx_fops);
42569 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
42570 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
42571 index e42009a..566a036 100644
42572 --- a/drivers/tty/rocket.c
42573 +++ b/drivers/tty/rocket.c
42574 @@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42575 tty->driver_data = info;
42576 tty_port_tty_set(port, tty);
42577
42578 - if (port->count++ == 0) {
42579 + if (atomic_inc_return(&port->count) == 1) {
42580 atomic_inc(&rp_num_ports_open);
42581
42582 #ifdef ROCKET_DEBUG_OPEN
42583 @@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42584 #endif
42585 }
42586 #ifdef ROCKET_DEBUG_OPEN
42587 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
42588 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
42589 #endif
42590
42591 /*
42592 @@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
42593 spin_unlock_irqrestore(&info->port.lock, flags);
42594 return;
42595 }
42596 - if (info->port.count)
42597 + if (atomic_read(&info->port.count))
42598 atomic_dec(&rp_num_ports_open);
42599 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
42600 spin_unlock_irqrestore(&info->port.lock, flags);
42601 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
42602 index 1002054..dd644a8 100644
42603 --- a/drivers/tty/serial/kgdboc.c
42604 +++ b/drivers/tty/serial/kgdboc.c
42605 @@ -24,8 +24,9 @@
42606 #define MAX_CONFIG_LEN 40
42607
42608 static struct kgdb_io kgdboc_io_ops;
42609 +static struct kgdb_io kgdboc_io_ops_console;
42610
42611 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
42612 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
42613 static int configured = -1;
42614
42615 static char config[MAX_CONFIG_LEN];
42616 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
42617 kgdboc_unregister_kbd();
42618 if (configured == 1)
42619 kgdb_unregister_io_module(&kgdboc_io_ops);
42620 + else if (configured == 2)
42621 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
42622 }
42623
42624 static int configure_kgdboc(void)
42625 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
42626 int err;
42627 char *cptr = config;
42628 struct console *cons;
42629 + int is_console = 0;
42630
42631 err = kgdboc_option_setup(config);
42632 if (err || !strlen(config) || isspace(config[0]))
42633 goto noconfig;
42634
42635 err = -ENODEV;
42636 - kgdboc_io_ops.is_console = 0;
42637 kgdb_tty_driver = NULL;
42638
42639 kgdboc_use_kms = 0;
42640 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
42641 int idx;
42642 if (cons->device && cons->device(cons, &idx) == p &&
42643 idx == tty_line) {
42644 - kgdboc_io_ops.is_console = 1;
42645 + is_console = 1;
42646 break;
42647 }
42648 cons = cons->next;
42649 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
42650 kgdb_tty_line = tty_line;
42651
42652 do_register:
42653 - err = kgdb_register_io_module(&kgdboc_io_ops);
42654 + if (is_console) {
42655 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
42656 + configured = 2;
42657 + } else {
42658 + err = kgdb_register_io_module(&kgdboc_io_ops);
42659 + configured = 1;
42660 + }
42661 if (err)
42662 goto noconfig;
42663
42664 @@ -205,8 +214,6 @@ do_register:
42665 if (err)
42666 goto nmi_con_failed;
42667
42668 - configured = 1;
42669 -
42670 return 0;
42671
42672 nmi_con_failed:
42673 @@ -223,7 +230,7 @@ noconfig:
42674 static int __init init_kgdboc(void)
42675 {
42676 /* Already configured? */
42677 - if (configured == 1)
42678 + if (configured >= 1)
42679 return 0;
42680
42681 return configure_kgdboc();
42682 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
42683 if (config[len - 1] == '\n')
42684 config[len - 1] = '\0';
42685
42686 - if (configured == 1)
42687 + if (configured >= 1)
42688 cleanup_kgdboc();
42689
42690 /* Go and configure with the new params. */
42691 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
42692 .post_exception = kgdboc_post_exp_handler,
42693 };
42694
42695 +static struct kgdb_io kgdboc_io_ops_console = {
42696 + .name = "kgdboc",
42697 + .read_char = kgdboc_get_char,
42698 + .write_char = kgdboc_put_char,
42699 + .pre_exception = kgdboc_pre_exp_handler,
42700 + .post_exception = kgdboc_post_exp_handler,
42701 + .is_console = 1
42702 +};
42703 +
42704 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
42705 /* This is only available if kgdboc is a built in for early debugging */
42706 static int __init kgdboc_early_init(char *opt)
42707 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
42708 index e514b3a..c73d614 100644
42709 --- a/drivers/tty/serial/samsung.c
42710 +++ b/drivers/tty/serial/samsung.c
42711 @@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
42712 }
42713 }
42714
42715 +static int s3c64xx_serial_startup(struct uart_port *port);
42716 static int s3c24xx_serial_startup(struct uart_port *port)
42717 {
42718 struct s3c24xx_uart_port *ourport = to_ourport(port);
42719 int ret;
42720
42721 + /* Startup sequence is different for s3c64xx and higher SoC's */
42722 + if (s3c24xx_serial_has_interrupt_mask(port))
42723 + return s3c64xx_serial_startup(port);
42724 +
42725 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
42726 port->mapbase, port->membase);
42727
42728 @@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
42729 /* setup info for port */
42730 port->dev = &platdev->dev;
42731
42732 - /* Startup sequence is different for s3c64xx and higher SoC's */
42733 - if (s3c24xx_serial_has_interrupt_mask(port))
42734 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
42735 -
42736 port->uartclk = 1;
42737
42738 if (cfg->uart_flags & UPF_CONS_FLOW) {
42739 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
42740 index 2c7230a..2104f16 100644
42741 --- a/drivers/tty/serial/serial_core.c
42742 +++ b/drivers/tty/serial/serial_core.c
42743 @@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
42744 uart_flush_buffer(tty);
42745 uart_shutdown(tty, state);
42746 spin_lock_irqsave(&port->lock, flags);
42747 - port->count = 0;
42748 + atomic_set(&port->count, 0);
42749 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
42750 spin_unlock_irqrestore(&port->lock, flags);
42751 tty_port_tty_set(port, NULL);
42752 @@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
42753 goto end;
42754 }
42755
42756 - port->count++;
42757 + atomic_inc(&port->count);
42758 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
42759 retval = -ENXIO;
42760 goto err_dec_count;
42761 @@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
42762 /*
42763 * Make sure the device is in D0 state.
42764 */
42765 - if (port->count == 1)
42766 + if (atomic_read(&port->count) == 1)
42767 uart_change_pm(state, 0);
42768
42769 /*
42770 @@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
42771 end:
42772 return retval;
42773 err_dec_count:
42774 - port->count--;
42775 + atomic_inc(&port->count);
42776 mutex_unlock(&port->mutex);
42777 goto end;
42778 }
42779 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
42780 index 9e071f6..f30ae69 100644
42781 --- a/drivers/tty/synclink.c
42782 +++ b/drivers/tty/synclink.c
42783 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
42784
42785 if (debug_level >= DEBUG_LEVEL_INFO)
42786 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
42787 - __FILE__,__LINE__, info->device_name, info->port.count);
42788 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
42789
42790 if (tty_port_close_start(&info->port, tty, filp) == 0)
42791 goto cleanup;
42792 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
42793 cleanup:
42794 if (debug_level >= DEBUG_LEVEL_INFO)
42795 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
42796 - tty->driver->name, info->port.count);
42797 + tty->driver->name, atomic_read(&info->port.count));
42798
42799 } /* end of mgsl_close() */
42800
42801 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
42802
42803 mgsl_flush_buffer(tty);
42804 shutdown(info);
42805 -
42806 - info->port.count = 0;
42807 +
42808 + atomic_set(&info->port.count, 0);
42809 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
42810 info->port.tty = NULL;
42811
42812 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
42813
42814 if (debug_level >= DEBUG_LEVEL_INFO)
42815 printk("%s(%d):block_til_ready before block on %s count=%d\n",
42816 - __FILE__,__LINE__, tty->driver->name, port->count );
42817 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
42818
42819 spin_lock_irqsave(&info->irq_spinlock, flags);
42820 if (!tty_hung_up_p(filp)) {
42821 extra_count = true;
42822 - port->count--;
42823 + atomic_dec(&port->count);
42824 }
42825 spin_unlock_irqrestore(&info->irq_spinlock, flags);
42826 port->blocked_open++;
42827 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
42828
42829 if (debug_level >= DEBUG_LEVEL_INFO)
42830 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
42831 - __FILE__,__LINE__, tty->driver->name, port->count );
42832 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
42833
42834 tty_unlock(tty);
42835 schedule();
42836 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
42837
42838 /* FIXME: Racy on hangup during close wait */
42839 if (extra_count)
42840 - port->count++;
42841 + atomic_inc(&port->count);
42842 port->blocked_open--;
42843
42844 if (debug_level >= DEBUG_LEVEL_INFO)
42845 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
42846 - __FILE__,__LINE__, tty->driver->name, port->count );
42847 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
42848
42849 if (!retval)
42850 port->flags |= ASYNC_NORMAL_ACTIVE;
42851 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
42852
42853 if (debug_level >= DEBUG_LEVEL_INFO)
42854 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
42855 - __FILE__,__LINE__,tty->driver->name, info->port.count);
42856 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
42857
42858 /* If port is closing, signal caller to try again */
42859 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
42860 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
42861 spin_unlock_irqrestore(&info->netlock, flags);
42862 goto cleanup;
42863 }
42864 - info->port.count++;
42865 + atomic_inc(&info->port.count);
42866 spin_unlock_irqrestore(&info->netlock, flags);
42867
42868 - if (info->port.count == 1) {
42869 + if (atomic_read(&info->port.count) == 1) {
42870 /* 1st open on this device, init hardware */
42871 retval = startup(info);
42872 if (retval < 0)
42873 @@ -3451,8 +3451,8 @@ cleanup:
42874 if (retval) {
42875 if (tty->count == 1)
42876 info->port.tty = NULL; /* tty layer will release tty struct */
42877 - if(info->port.count)
42878 - info->port.count--;
42879 + if (atomic_read(&info->port.count))
42880 + atomic_dec(&info->port.count);
42881 }
42882
42883 return retval;
42884 @@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
42885 unsigned short new_crctype;
42886
42887 /* return error if TTY interface open */
42888 - if (info->port.count)
42889 + if (atomic_read(&info->port.count))
42890 return -EBUSY;
42891
42892 switch (encoding)
42893 @@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
42894
42895 /* arbitrate between network and tty opens */
42896 spin_lock_irqsave(&info->netlock, flags);
42897 - if (info->port.count != 0 || info->netcount != 0) {
42898 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
42899 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
42900 spin_unlock_irqrestore(&info->netlock, flags);
42901 return -EBUSY;
42902 @@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42903 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
42904
42905 /* return error if TTY interface open */
42906 - if (info->port.count)
42907 + if (atomic_read(&info->port.count))
42908 return -EBUSY;
42909
42910 if (cmd != SIOCWANDEV)
42911 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
42912 index aba1e59..877ac33 100644
42913 --- a/drivers/tty/synclink_gt.c
42914 +++ b/drivers/tty/synclink_gt.c
42915 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
42916 tty->driver_data = info;
42917 info->port.tty = tty;
42918
42919 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
42920 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
42921
42922 /* If port is closing, signal caller to try again */
42923 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
42924 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
42925 mutex_unlock(&info->port.mutex);
42926 goto cleanup;
42927 }
42928 - info->port.count++;
42929 + atomic_inc(&info->port.count);
42930 spin_unlock_irqrestore(&info->netlock, flags);
42931
42932 - if (info->port.count == 1) {
42933 + if (atomic_read(&info->port.count) == 1) {
42934 /* 1st open on this device, init hardware */
42935 retval = startup(info);
42936 if (retval < 0) {
42937 @@ -716,8 +716,8 @@ cleanup:
42938 if (retval) {
42939 if (tty->count == 1)
42940 info->port.tty = NULL; /* tty layer will release tty struct */
42941 - if(info->port.count)
42942 - info->port.count--;
42943 + if(atomic_read(&info->port.count))
42944 + atomic_dec(&info->port.count);
42945 }
42946
42947 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
42948 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
42949
42950 if (sanity_check(info, tty->name, "close"))
42951 return;
42952 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
42953 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
42954
42955 if (tty_port_close_start(&info->port, tty, filp) == 0)
42956 goto cleanup;
42957 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
42958 tty_port_close_end(&info->port, tty);
42959 info->port.tty = NULL;
42960 cleanup:
42961 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
42962 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
42963 }
42964
42965 static void hangup(struct tty_struct *tty)
42966 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
42967 shutdown(info);
42968
42969 spin_lock_irqsave(&info->port.lock, flags);
42970 - info->port.count = 0;
42971 + atomic_set(&info->port.count, 0);
42972 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
42973 info->port.tty = NULL;
42974 spin_unlock_irqrestore(&info->port.lock, flags);
42975 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
42976 unsigned short new_crctype;
42977
42978 /* return error if TTY interface open */
42979 - if (info->port.count)
42980 + if (atomic_read(&info->port.count))
42981 return -EBUSY;
42982
42983 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
42984 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
42985
42986 /* arbitrate between network and tty opens */
42987 spin_lock_irqsave(&info->netlock, flags);
42988 - if (info->port.count != 0 || info->netcount != 0) {
42989 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
42990 DBGINFO(("%s hdlc_open busy\n", dev->name));
42991 spin_unlock_irqrestore(&info->netlock, flags);
42992 return -EBUSY;
42993 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42994 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
42995
42996 /* return error if TTY interface open */
42997 - if (info->port.count)
42998 + if (atomic_read(&info->port.count))
42999 return -EBUSY;
43000
43001 if (cmd != SIOCWANDEV)
43002 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
43003 if (port == NULL)
43004 continue;
43005 spin_lock(&port->lock);
43006 - if ((port->port.count || port->netcount) &&
43007 + if ((atomic_read(&port->port.count) || port->netcount) &&
43008 port->pending_bh && !port->bh_running &&
43009 !port->bh_requested) {
43010 DBGISR(("%s bh queued\n", port->device_name));
43011 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43012 spin_lock_irqsave(&info->lock, flags);
43013 if (!tty_hung_up_p(filp)) {
43014 extra_count = true;
43015 - port->count--;
43016 + atomic_dec(&port->count);
43017 }
43018 spin_unlock_irqrestore(&info->lock, flags);
43019 port->blocked_open++;
43020 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43021 remove_wait_queue(&port->open_wait, &wait);
43022
43023 if (extra_count)
43024 - port->count++;
43025 + atomic_inc(&port->count);
43026 port->blocked_open--;
43027
43028 if (!retval)
43029 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
43030 index fd43fb6..34704ad 100644
43031 --- a/drivers/tty/synclinkmp.c
43032 +++ b/drivers/tty/synclinkmp.c
43033 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43034
43035 if (debug_level >= DEBUG_LEVEL_INFO)
43036 printk("%s(%d):%s open(), old ref count = %d\n",
43037 - __FILE__,__LINE__,tty->driver->name, info->port.count);
43038 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43039
43040 /* If port is closing, signal caller to try again */
43041 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43042 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43043 spin_unlock_irqrestore(&info->netlock, flags);
43044 goto cleanup;
43045 }
43046 - info->port.count++;
43047 + atomic_inc(&info->port.count);
43048 spin_unlock_irqrestore(&info->netlock, flags);
43049
43050 - if (info->port.count == 1) {
43051 + if (atomic_read(&info->port.count) == 1) {
43052 /* 1st open on this device, init hardware */
43053 retval = startup(info);
43054 if (retval < 0)
43055 @@ -797,8 +797,8 @@ cleanup:
43056 if (retval) {
43057 if (tty->count == 1)
43058 info->port.tty = NULL; /* tty layer will release tty struct */
43059 - if(info->port.count)
43060 - info->port.count--;
43061 + if(atomic_read(&info->port.count))
43062 + atomic_dec(&info->port.count);
43063 }
43064
43065 return retval;
43066 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43067
43068 if (debug_level >= DEBUG_LEVEL_INFO)
43069 printk("%s(%d):%s close() entry, count=%d\n",
43070 - __FILE__,__LINE__, info->device_name, info->port.count);
43071 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43072
43073 if (tty_port_close_start(&info->port, tty, filp) == 0)
43074 goto cleanup;
43075 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43076 cleanup:
43077 if (debug_level >= DEBUG_LEVEL_INFO)
43078 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
43079 - tty->driver->name, info->port.count);
43080 + tty->driver->name, atomic_read(&info->port.count));
43081 }
43082
43083 /* Called by tty_hangup() when a hangup is signaled.
43084 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
43085 shutdown(info);
43086
43087 spin_lock_irqsave(&info->port.lock, flags);
43088 - info->port.count = 0;
43089 + atomic_set(&info->port.count, 0);
43090 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43091 info->port.tty = NULL;
43092 spin_unlock_irqrestore(&info->port.lock, flags);
43093 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43094 unsigned short new_crctype;
43095
43096 /* return error if TTY interface open */
43097 - if (info->port.count)
43098 + if (atomic_read(&info->port.count))
43099 return -EBUSY;
43100
43101 switch (encoding)
43102 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
43103
43104 /* arbitrate between network and tty opens */
43105 spin_lock_irqsave(&info->netlock, flags);
43106 - if (info->port.count != 0 || info->netcount != 0) {
43107 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43108 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43109 spin_unlock_irqrestore(&info->netlock, flags);
43110 return -EBUSY;
43111 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43112 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43113
43114 /* return error if TTY interface open */
43115 - if (info->port.count)
43116 + if (atomic_read(&info->port.count))
43117 return -EBUSY;
43118
43119 if (cmd != SIOCWANDEV)
43120 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
43121 * do not request bottom half processing if the
43122 * device is not open in a normal mode.
43123 */
43124 - if ( port && (port->port.count || port->netcount) &&
43125 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
43126 port->pending_bh && !port->bh_running &&
43127 !port->bh_requested ) {
43128 if ( debug_level >= DEBUG_LEVEL_ISR )
43129 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43130
43131 if (debug_level >= DEBUG_LEVEL_INFO)
43132 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
43133 - __FILE__,__LINE__, tty->driver->name, port->count );
43134 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43135
43136 spin_lock_irqsave(&info->lock, flags);
43137 if (!tty_hung_up_p(filp)) {
43138 extra_count = true;
43139 - port->count--;
43140 + atomic_dec(&port->count);
43141 }
43142 spin_unlock_irqrestore(&info->lock, flags);
43143 port->blocked_open++;
43144 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43145
43146 if (debug_level >= DEBUG_LEVEL_INFO)
43147 printk("%s(%d):%s block_til_ready() count=%d\n",
43148 - __FILE__,__LINE__, tty->driver->name, port->count );
43149 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43150
43151 tty_unlock(tty);
43152 schedule();
43153 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43154 remove_wait_queue(&port->open_wait, &wait);
43155
43156 if (extra_count)
43157 - port->count++;
43158 + atomic_inc(&port->count);
43159 port->blocked_open--;
43160
43161 if (debug_level >= DEBUG_LEVEL_INFO)
43162 printk("%s(%d):%s block_til_ready() after, count=%d\n",
43163 - __FILE__,__LINE__, tty->driver->name, port->count );
43164 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43165
43166 if (!retval)
43167 port->flags |= ASYNC_NORMAL_ACTIVE;
43168 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
43169 index b3c4a25..723916f 100644
43170 --- a/drivers/tty/sysrq.c
43171 +++ b/drivers/tty/sysrq.c
43172 @@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
43173 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
43174 size_t count, loff_t *ppos)
43175 {
43176 - if (count) {
43177 + if (count && capable(CAP_SYS_ADMIN)) {
43178 char c;
43179
43180 if (get_user(c, buf))
43181 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
43182 index da9fde8..c07975f 100644
43183 --- a/drivers/tty/tty_io.c
43184 +++ b/drivers/tty/tty_io.c
43185 @@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
43186
43187 void tty_default_fops(struct file_operations *fops)
43188 {
43189 - *fops = tty_fops;
43190 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
43191 }
43192
43193 /*
43194 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
43195 index c578229..45aa9ee 100644
43196 --- a/drivers/tty/tty_ldisc.c
43197 +++ b/drivers/tty/tty_ldisc.c
43198 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
43199 if (atomic_dec_and_test(&ld->users)) {
43200 struct tty_ldisc_ops *ldo = ld->ops;
43201
43202 - ldo->refcount--;
43203 + atomic_dec(&ldo->refcount);
43204 module_put(ldo->owner);
43205 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43206
43207 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
43208 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43209 tty_ldiscs[disc] = new_ldisc;
43210 new_ldisc->num = disc;
43211 - new_ldisc->refcount = 0;
43212 + atomic_set(&new_ldisc->refcount, 0);
43213 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43214
43215 return ret;
43216 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
43217 return -EINVAL;
43218
43219 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43220 - if (tty_ldiscs[disc]->refcount)
43221 + if (atomic_read(&tty_ldiscs[disc]->refcount))
43222 ret = -EBUSY;
43223 else
43224 tty_ldiscs[disc] = NULL;
43225 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
43226 if (ldops) {
43227 ret = ERR_PTR(-EAGAIN);
43228 if (try_module_get(ldops->owner)) {
43229 - ldops->refcount++;
43230 + atomic_inc(&ldops->refcount);
43231 ret = ldops;
43232 }
43233 }
43234 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
43235 unsigned long flags;
43236
43237 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43238 - ldops->refcount--;
43239 + atomic_dec(&ldops->refcount);
43240 module_put(ldops->owner);
43241 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43242 }
43243 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
43244 index b7ff59d..7c6105e 100644
43245 --- a/drivers/tty/tty_port.c
43246 +++ b/drivers/tty/tty_port.c
43247 @@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
43248 unsigned long flags;
43249
43250 spin_lock_irqsave(&port->lock, flags);
43251 - port->count = 0;
43252 + atomic_set(&port->count, 0);
43253 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43254 if (port->tty) {
43255 set_bit(TTY_IO_ERROR, &port->tty->flags);
43256 @@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43257 /* The port lock protects the port counts */
43258 spin_lock_irqsave(&port->lock, flags);
43259 if (!tty_hung_up_p(filp))
43260 - port->count--;
43261 + atomic_dec(&port->count);
43262 port->blocked_open++;
43263 spin_unlock_irqrestore(&port->lock, flags);
43264
43265 @@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43266 we must not mess that up further */
43267 spin_lock_irqsave(&port->lock, flags);
43268 if (!tty_hung_up_p(filp))
43269 - port->count++;
43270 + atomic_inc(&port->count);
43271 port->blocked_open--;
43272 if (retval == 0)
43273 port->flags |= ASYNC_NORMAL_ACTIVE;
43274 @@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
43275 return 0;
43276 }
43277
43278 - if (tty->count == 1 && port->count != 1) {
43279 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
43280 printk(KERN_WARNING
43281 "tty_port_close_start: tty->count = 1 port count = %d.\n",
43282 - port->count);
43283 - port->count = 1;
43284 + atomic_read(&port->count));
43285 + atomic_set(&port->count, 1);
43286 }
43287 - if (--port->count < 0) {
43288 + if (atomic_dec_return(&port->count) < 0) {
43289 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
43290 - port->count);
43291 - port->count = 0;
43292 + atomic_read(&port->count));
43293 + atomic_set(&port->count, 0);
43294 }
43295
43296 - if (port->count) {
43297 + if (atomic_read(&port->count)) {
43298 spin_unlock_irqrestore(&port->lock, flags);
43299 if (port->ops->drop)
43300 port->ops->drop(port);
43301 @@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
43302 {
43303 spin_lock_irq(&port->lock);
43304 if (!tty_hung_up_p(filp))
43305 - ++port->count;
43306 + atomic_inc(&port->count);
43307 spin_unlock_irq(&port->lock);
43308 tty_port_tty_set(port, tty);
43309
43310 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
43311 index 681765b..d3ccdf2 100644
43312 --- a/drivers/tty/vt/keyboard.c
43313 +++ b/drivers/tty/vt/keyboard.c
43314 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
43315 kbd->kbdmode == VC_OFF) &&
43316 value != KVAL(K_SAK))
43317 return; /* SAK is allowed even in raw mode */
43318 +
43319 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
43320 + {
43321 + void *func = fn_handler[value];
43322 + if (func == fn_show_state || func == fn_show_ptregs ||
43323 + func == fn_show_mem)
43324 + return;
43325 + }
43326 +#endif
43327 +
43328 fn_handler[value](vc);
43329 }
43330
43331 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43332 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
43333 return -EFAULT;
43334
43335 - if (!capable(CAP_SYS_TTY_CONFIG))
43336 - perm = 0;
43337 -
43338 switch (cmd) {
43339 case KDGKBENT:
43340 /* Ensure another thread doesn't free it under us */
43341 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43342 spin_unlock_irqrestore(&kbd_event_lock, flags);
43343 return put_user(val, &user_kbe->kb_value);
43344 case KDSKBENT:
43345 + if (!capable(CAP_SYS_TTY_CONFIG))
43346 + perm = 0;
43347 +
43348 if (!perm)
43349 return -EPERM;
43350 if (!i && v == K_NOSUCHMAP) {
43351 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43352 int i, j, k;
43353 int ret;
43354
43355 - if (!capable(CAP_SYS_TTY_CONFIG))
43356 - perm = 0;
43357 -
43358 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
43359 if (!kbs) {
43360 ret = -ENOMEM;
43361 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43362 kfree(kbs);
43363 return ((p && *p) ? -EOVERFLOW : 0);
43364 case KDSKBSENT:
43365 + if (!capable(CAP_SYS_TTY_CONFIG))
43366 + perm = 0;
43367 +
43368 if (!perm) {
43369 ret = -EPERM;
43370 goto reterr;
43371 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
43372 index 5110f36..8dc0a74 100644
43373 --- a/drivers/uio/uio.c
43374 +++ b/drivers/uio/uio.c
43375 @@ -25,6 +25,7 @@
43376 #include <linux/kobject.h>
43377 #include <linux/cdev.h>
43378 #include <linux/uio_driver.h>
43379 +#include <asm/local.h>
43380
43381 #define UIO_MAX_DEVICES (1U << MINORBITS)
43382
43383 @@ -32,10 +33,10 @@ struct uio_device {
43384 struct module *owner;
43385 struct device *dev;
43386 int minor;
43387 - atomic_t event;
43388 + atomic_unchecked_t event;
43389 struct fasync_struct *async_queue;
43390 wait_queue_head_t wait;
43391 - int vma_count;
43392 + local_t vma_count;
43393 struct uio_info *info;
43394 struct kobject *map_dir;
43395 struct kobject *portio_dir;
43396 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
43397 struct device_attribute *attr, char *buf)
43398 {
43399 struct uio_device *idev = dev_get_drvdata(dev);
43400 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
43401 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
43402 }
43403
43404 static struct device_attribute uio_class_attributes[] = {
43405 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
43406 {
43407 struct uio_device *idev = info->uio_dev;
43408
43409 - atomic_inc(&idev->event);
43410 + atomic_inc_unchecked(&idev->event);
43411 wake_up_interruptible(&idev->wait);
43412 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
43413 }
43414 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
43415 }
43416
43417 listener->dev = idev;
43418 - listener->event_count = atomic_read(&idev->event);
43419 + listener->event_count = atomic_read_unchecked(&idev->event);
43420 filep->private_data = listener;
43421
43422 if (idev->info->open) {
43423 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
43424 return -EIO;
43425
43426 poll_wait(filep, &idev->wait, wait);
43427 - if (listener->event_count != atomic_read(&idev->event))
43428 + if (listener->event_count != atomic_read_unchecked(&idev->event))
43429 return POLLIN | POLLRDNORM;
43430 return 0;
43431 }
43432 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
43433 do {
43434 set_current_state(TASK_INTERRUPTIBLE);
43435
43436 - event_count = atomic_read(&idev->event);
43437 + event_count = atomic_read_unchecked(&idev->event);
43438 if (event_count != listener->event_count) {
43439 if (copy_to_user(buf, &event_count, count))
43440 retval = -EFAULT;
43441 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
43442 static void uio_vma_open(struct vm_area_struct *vma)
43443 {
43444 struct uio_device *idev = vma->vm_private_data;
43445 - idev->vma_count++;
43446 + local_inc(&idev->vma_count);
43447 }
43448
43449 static void uio_vma_close(struct vm_area_struct *vma)
43450 {
43451 struct uio_device *idev = vma->vm_private_data;
43452 - idev->vma_count--;
43453 + local_dec(&idev->vma_count);
43454 }
43455
43456 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
43457 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
43458 idev->owner = owner;
43459 idev->info = info;
43460 init_waitqueue_head(&idev->wait);
43461 - atomic_set(&idev->event, 0);
43462 + atomic_set_unchecked(&idev->event, 0);
43463
43464 ret = uio_get_minor(idev);
43465 if (ret)
43466 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
43467 index b7eb86a..36d28af 100644
43468 --- a/drivers/usb/atm/cxacru.c
43469 +++ b/drivers/usb/atm/cxacru.c
43470 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
43471 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
43472 if (ret < 2)
43473 return -EINVAL;
43474 - if (index < 0 || index > 0x7f)
43475 + if (index > 0x7f)
43476 return -EINVAL;
43477 pos += tmp;
43478
43479 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
43480 index 35f10bf..6a38a0b 100644
43481 --- a/drivers/usb/atm/usbatm.c
43482 +++ b/drivers/usb/atm/usbatm.c
43483 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43484 if (printk_ratelimit())
43485 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
43486 __func__, vpi, vci);
43487 - atomic_inc(&vcc->stats->rx_err);
43488 + atomic_inc_unchecked(&vcc->stats->rx_err);
43489 return;
43490 }
43491
43492 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43493 if (length > ATM_MAX_AAL5_PDU) {
43494 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
43495 __func__, length, vcc);
43496 - atomic_inc(&vcc->stats->rx_err);
43497 + atomic_inc_unchecked(&vcc->stats->rx_err);
43498 goto out;
43499 }
43500
43501 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43502 if (sarb->len < pdu_length) {
43503 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
43504 __func__, pdu_length, sarb->len, vcc);
43505 - atomic_inc(&vcc->stats->rx_err);
43506 + atomic_inc_unchecked(&vcc->stats->rx_err);
43507 goto out;
43508 }
43509
43510 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
43511 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
43512 __func__, vcc);
43513 - atomic_inc(&vcc->stats->rx_err);
43514 + atomic_inc_unchecked(&vcc->stats->rx_err);
43515 goto out;
43516 }
43517
43518 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43519 if (printk_ratelimit())
43520 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
43521 __func__, length);
43522 - atomic_inc(&vcc->stats->rx_drop);
43523 + atomic_inc_unchecked(&vcc->stats->rx_drop);
43524 goto out;
43525 }
43526
43527 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43528
43529 vcc->push(vcc, skb);
43530
43531 - atomic_inc(&vcc->stats->rx);
43532 + atomic_inc_unchecked(&vcc->stats->rx);
43533 out:
43534 skb_trim(sarb, 0);
43535 }
43536 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
43537 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
43538
43539 usbatm_pop(vcc, skb);
43540 - atomic_inc(&vcc->stats->tx);
43541 + atomic_inc_unchecked(&vcc->stats->tx);
43542
43543 skb = skb_dequeue(&instance->sndqueue);
43544 }
43545 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
43546 if (!left--)
43547 return sprintf(page,
43548 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
43549 - atomic_read(&atm_dev->stats.aal5.tx),
43550 - atomic_read(&atm_dev->stats.aal5.tx_err),
43551 - atomic_read(&atm_dev->stats.aal5.rx),
43552 - atomic_read(&atm_dev->stats.aal5.rx_err),
43553 - atomic_read(&atm_dev->stats.aal5.rx_drop));
43554 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
43555 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
43556 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
43557 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
43558 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
43559
43560 if (!left--) {
43561 if (instance->disconnected)
43562 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
43563 index cbacea9..246cccd 100644
43564 --- a/drivers/usb/core/devices.c
43565 +++ b/drivers/usb/core/devices.c
43566 @@ -126,7 +126,7 @@ static const char format_endpt[] =
43567 * time it gets called.
43568 */
43569 static struct device_connect_event {
43570 - atomic_t count;
43571 + atomic_unchecked_t count;
43572 wait_queue_head_t wait;
43573 } device_event = {
43574 .count = ATOMIC_INIT(1),
43575 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
43576
43577 void usbfs_conn_disc_event(void)
43578 {
43579 - atomic_add(2, &device_event.count);
43580 + atomic_add_unchecked(2, &device_event.count);
43581 wake_up(&device_event.wait);
43582 }
43583
43584 @@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
43585
43586 poll_wait(file, &device_event.wait, wait);
43587
43588 - event_count = atomic_read(&device_event.count);
43589 + event_count = atomic_read_unchecked(&device_event.count);
43590 if (file->f_version != event_count) {
43591 file->f_version = event_count;
43592 return POLLIN | POLLRDNORM;
43593 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
43594 index 8e64adf..9a33a3c 100644
43595 --- a/drivers/usb/core/hcd.c
43596 +++ b/drivers/usb/core/hcd.c
43597 @@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43598 */
43599 usb_get_urb(urb);
43600 atomic_inc(&urb->use_count);
43601 - atomic_inc(&urb->dev->urbnum);
43602 + atomic_inc_unchecked(&urb->dev->urbnum);
43603 usbmon_urb_submit(&hcd->self, urb);
43604
43605 /* NOTE requirements on root-hub callers (usbfs and the hub
43606 @@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43607 urb->hcpriv = NULL;
43608 INIT_LIST_HEAD(&urb->urb_list);
43609 atomic_dec(&urb->use_count);
43610 - atomic_dec(&urb->dev->urbnum);
43611 + atomic_dec_unchecked(&urb->dev->urbnum);
43612 if (atomic_read(&urb->reject))
43613 wake_up(&usb_kill_urb_queue);
43614 usb_put_urb(urb);
43615 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
43616 index 818e4a0..0fc9589 100644
43617 --- a/drivers/usb/core/sysfs.c
43618 +++ b/drivers/usb/core/sysfs.c
43619 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
43620 struct usb_device *udev;
43621
43622 udev = to_usb_device(dev);
43623 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
43624 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
43625 }
43626 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
43627
43628 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
43629 index f81b925..78d22ec 100644
43630 --- a/drivers/usb/core/usb.c
43631 +++ b/drivers/usb/core/usb.c
43632 @@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
43633 set_dev_node(&dev->dev, dev_to_node(bus->controller));
43634 dev->state = USB_STATE_ATTACHED;
43635 dev->lpm_disable_count = 1;
43636 - atomic_set(&dev->urbnum, 0);
43637 + atomic_set_unchecked(&dev->urbnum, 0);
43638
43639 INIT_LIST_HEAD(&dev->ep0.urb_list);
43640 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
43641 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
43642 index 5e29dde..eca992f 100644
43643 --- a/drivers/usb/early/ehci-dbgp.c
43644 +++ b/drivers/usb/early/ehci-dbgp.c
43645 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
43646
43647 #ifdef CONFIG_KGDB
43648 static struct kgdb_io kgdbdbgp_io_ops;
43649 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
43650 +static struct kgdb_io kgdbdbgp_io_ops_console;
43651 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
43652 #else
43653 #define dbgp_kgdb_mode (0)
43654 #endif
43655 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
43656 .write_char = kgdbdbgp_write_char,
43657 };
43658
43659 +static struct kgdb_io kgdbdbgp_io_ops_console = {
43660 + .name = "kgdbdbgp",
43661 + .read_char = kgdbdbgp_read_char,
43662 + .write_char = kgdbdbgp_write_char,
43663 + .is_console = 1
43664 +};
43665 +
43666 static int kgdbdbgp_wait_time;
43667
43668 static int __init kgdbdbgp_parse_config(char *str)
43669 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
43670 ptr++;
43671 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
43672 }
43673 - kgdb_register_io_module(&kgdbdbgp_io_ops);
43674 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
43675 + if (early_dbgp_console.index != -1)
43676 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
43677 + else
43678 + kgdb_register_io_module(&kgdbdbgp_io_ops);
43679
43680 return 0;
43681 }
43682 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
43683 index 598dcc1..032dd4f 100644
43684 --- a/drivers/usb/gadget/u_serial.c
43685 +++ b/drivers/usb/gadget/u_serial.c
43686 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
43687 spin_lock_irq(&port->port_lock);
43688
43689 /* already open? Great. */
43690 - if (port->port.count) {
43691 + if (atomic_read(&port->port.count)) {
43692 status = 0;
43693 - port->port.count++;
43694 + atomic_inc(&port->port.count);
43695
43696 /* currently opening/closing? wait ... */
43697 } else if (port->openclose) {
43698 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
43699 tty->driver_data = port;
43700 port->port.tty = tty;
43701
43702 - port->port.count = 1;
43703 + atomic_set(&port->port.count, 1);
43704 port->openclose = false;
43705
43706 /* if connected, start the I/O stream */
43707 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
43708
43709 spin_lock_irq(&port->port_lock);
43710
43711 - if (port->port.count != 1) {
43712 - if (port->port.count == 0)
43713 + if (atomic_read(&port->port.count) != 1) {
43714 + if (atomic_read(&port->port.count) == 0)
43715 WARN_ON(1);
43716 else
43717 - --port->port.count;
43718 + atomic_dec(&port->port.count);
43719 goto exit;
43720 }
43721
43722 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
43723 * and sleep if necessary
43724 */
43725 port->openclose = true;
43726 - port->port.count = 0;
43727 + atomic_set(&port->port.count, 0);
43728
43729 gser = port->port_usb;
43730 if (gser && gser->disconnect)
43731 @@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
43732 int cond;
43733
43734 spin_lock_irq(&port->port_lock);
43735 - cond = (port->port.count == 0) && !port->openclose;
43736 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
43737 spin_unlock_irq(&port->port_lock);
43738 return cond;
43739 }
43740 @@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
43741 /* if it's already open, start I/O ... and notify the serial
43742 * protocol about open/close status (connect/disconnect).
43743 */
43744 - if (port->port.count) {
43745 + if (atomic_read(&port->port.count)) {
43746 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
43747 gs_start_io(port);
43748 if (gser->connect)
43749 @@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
43750
43751 port->port_usb = NULL;
43752 gser->ioport = NULL;
43753 - if (port->port.count > 0 || port->openclose) {
43754 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
43755 wake_up_interruptible(&port->drain_wait);
43756 if (port->port.tty)
43757 tty_hangup(port->port.tty);
43758 @@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
43759
43760 /* finally, free any unused/unusable I/O buffers */
43761 spin_lock_irqsave(&port->port_lock, flags);
43762 - if (port->port.count == 0 && !port->openclose)
43763 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
43764 gs_buf_free(&port->port_write_buf);
43765 gs_free_requests(gser->out, &port->read_pool, NULL);
43766 gs_free_requests(gser->out, &port->read_queue, NULL);
43767 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
43768 index 5f3bcd3..bfca43f 100644
43769 --- a/drivers/usb/serial/console.c
43770 +++ b/drivers/usb/serial/console.c
43771 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
43772
43773 info->port = port;
43774
43775 - ++port->port.count;
43776 + atomic_inc(&port->port.count);
43777 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
43778 if (serial->type->set_termios) {
43779 /*
43780 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
43781 }
43782 /* Now that any required fake tty operations are completed restore
43783 * the tty port count */
43784 - --port->port.count;
43785 + atomic_dec(&port->port.count);
43786 /* The console is special in terms of closing the device so
43787 * indicate this port is now acting as a system console. */
43788 port->port.console = 1;
43789 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
43790 free_tty:
43791 kfree(tty);
43792 reset_open_count:
43793 - port->port.count = 0;
43794 + atomic_set(&port->port.count, 0);
43795 usb_autopm_put_interface(serial->interface);
43796 error_get_interface:
43797 usb_serial_put(serial);
43798 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
43799 index 75f70f0..d467e1a 100644
43800 --- a/drivers/usb/storage/usb.h
43801 +++ b/drivers/usb/storage/usb.h
43802 @@ -63,7 +63,7 @@ struct us_unusual_dev {
43803 __u8 useProtocol;
43804 __u8 useTransport;
43805 int (*initFunction)(struct us_data *);
43806 -};
43807 +} __do_const;
43808
43809
43810 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
43811 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
43812 index d6bea3e..60b250e 100644
43813 --- a/drivers/usb/wusbcore/wa-hc.h
43814 +++ b/drivers/usb/wusbcore/wa-hc.h
43815 @@ -192,7 +192,7 @@ struct wahc {
43816 struct list_head xfer_delayed_list;
43817 spinlock_t xfer_list_lock;
43818 struct work_struct xfer_work;
43819 - atomic_t xfer_id_count;
43820 + atomic_unchecked_t xfer_id_count;
43821 };
43822
43823
43824 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
43825 INIT_LIST_HEAD(&wa->xfer_delayed_list);
43826 spin_lock_init(&wa->xfer_list_lock);
43827 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
43828 - atomic_set(&wa->xfer_id_count, 1);
43829 + atomic_set_unchecked(&wa->xfer_id_count, 1);
43830 }
43831
43832 /**
43833 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
43834 index 57c01ab..8a05959 100644
43835 --- a/drivers/usb/wusbcore/wa-xfer.c
43836 +++ b/drivers/usb/wusbcore/wa-xfer.c
43837 @@ -296,7 +296,7 @@ out:
43838 */
43839 static void wa_xfer_id_init(struct wa_xfer *xfer)
43840 {
43841 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
43842 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
43843 }
43844
43845 /*
43846 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
43847 index 8c55011..eed4ae1a 100644
43848 --- a/drivers/video/aty/aty128fb.c
43849 +++ b/drivers/video/aty/aty128fb.c
43850 @@ -149,7 +149,7 @@ enum {
43851 };
43852
43853 /* Must match above enum */
43854 -static char * const r128_family[] = {
43855 +static const char * const r128_family[] = {
43856 "AGP",
43857 "PCI",
43858 "PRO AGP",
43859 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
43860 index 4f27fdc..d3537e6 100644
43861 --- a/drivers/video/aty/atyfb_base.c
43862 +++ b/drivers/video/aty/atyfb_base.c
43863 @@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
43864 par->accel_flags = var->accel_flags; /* hack */
43865
43866 if (var->accel_flags) {
43867 - info->fbops->fb_sync = atyfb_sync;
43868 + pax_open_kernel();
43869 + *(void **)&info->fbops->fb_sync = atyfb_sync;
43870 + pax_close_kernel();
43871 info->flags &= ~FBINFO_HWACCEL_DISABLED;
43872 } else {
43873 - info->fbops->fb_sync = NULL;
43874 + pax_open_kernel();
43875 + *(void **)&info->fbops->fb_sync = NULL;
43876 + pax_close_kernel();
43877 info->flags |= FBINFO_HWACCEL_DISABLED;
43878 }
43879
43880 diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
43881 index 95ec042..e6affdd 100644
43882 --- a/drivers/video/aty/mach64_cursor.c
43883 +++ b/drivers/video/aty/mach64_cursor.c
43884 @@ -7,6 +7,7 @@
43885 #include <linux/string.h>
43886
43887 #include <asm/io.h>
43888 +#include <asm/pgtable.h>
43889
43890 #ifdef __sparc__
43891 #include <asm/fbio.h>
43892 @@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
43893 info->sprite.buf_align = 16; /* and 64 lines tall. */
43894 info->sprite.flags = FB_PIXMAP_IO;
43895
43896 - info->fbops->fb_cursor = atyfb_cursor;
43897 + pax_open_kernel();
43898 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
43899 + pax_close_kernel();
43900
43901 return 0;
43902 }
43903 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
43904 index 6c5ed6b..b727c88 100644
43905 --- a/drivers/video/backlight/kb3886_bl.c
43906 +++ b/drivers/video/backlight/kb3886_bl.c
43907 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
43908 static unsigned long kb3886bl_flags;
43909 #define KB3886BL_SUSPENDED 0x01
43910
43911 -static struct dmi_system_id __initdata kb3886bl_device_table[] = {
43912 +static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
43913 {
43914 .ident = "Sahara Touch-iT",
43915 .matches = {
43916 diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
43917 index 88cad6b..dd746c7 100644
43918 --- a/drivers/video/fb_defio.c
43919 +++ b/drivers/video/fb_defio.c
43920 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
43921
43922 BUG_ON(!fbdefio);
43923 mutex_init(&fbdefio->lock);
43924 - info->fbops->fb_mmap = fb_deferred_io_mmap;
43925 + pax_open_kernel();
43926 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
43927 + pax_close_kernel();
43928 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
43929 INIT_LIST_HEAD(&fbdefio->pagelist);
43930 if (fbdefio->delay == 0) /* set a default of 1 s */
43931 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
43932 page->mapping = NULL;
43933 }
43934
43935 - info->fbops->fb_mmap = NULL;
43936 + *(void **)&info->fbops->fb_mmap = NULL;
43937 mutex_destroy(&fbdefio->lock);
43938 }
43939 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
43940 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
43941 index 5c3960d..15cf8fc 100644
43942 --- a/drivers/video/fbcmap.c
43943 +++ b/drivers/video/fbcmap.c
43944 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
43945 rc = -ENODEV;
43946 goto out;
43947 }
43948 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
43949 - !info->fbops->fb_setcmap)) {
43950 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
43951 rc = -EINVAL;
43952 goto out1;
43953 }
43954 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
43955 index dc61c12..e29796e 100644
43956 --- a/drivers/video/fbmem.c
43957 +++ b/drivers/video/fbmem.c
43958 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
43959 image->dx += image->width + 8;
43960 }
43961 } else if (rotate == FB_ROTATE_UD) {
43962 - for (x = 0; x < num && image->dx >= 0; x++) {
43963 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
43964 info->fbops->fb_imageblit(info, image);
43965 image->dx -= image->width + 8;
43966 }
43967 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
43968 image->dy += image->height + 8;
43969 }
43970 } else if (rotate == FB_ROTATE_CCW) {
43971 - for (x = 0; x < num && image->dy >= 0; x++) {
43972 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
43973 info->fbops->fb_imageblit(info, image);
43974 image->dy -= image->height + 8;
43975 }
43976 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
43977 return -EFAULT;
43978 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
43979 return -EINVAL;
43980 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
43981 + if (con2fb.framebuffer >= FB_MAX)
43982 return -EINVAL;
43983 if (!registered_fb[con2fb.framebuffer])
43984 request_module("fb%d", con2fb.framebuffer);
43985 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
43986 index 7672d2e..b56437f 100644
43987 --- a/drivers/video/i810/i810_accel.c
43988 +++ b/drivers/video/i810/i810_accel.c
43989 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
43990 }
43991 }
43992 printk("ringbuffer lockup!!!\n");
43993 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
43994 i810_report_error(mmio);
43995 par->dev_flags |= LOCKUP;
43996 info->pixmap.scan_align = 1;
43997 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
43998 index 3c14e43..eafa544 100644
43999 --- a/drivers/video/logo/logo_linux_clut224.ppm
44000 +++ b/drivers/video/logo/logo_linux_clut224.ppm
44001 @@ -1,1604 +1,1123 @@
44002 P3
44003 -# Standard 224-color Linux logo
44004 80 80
44005 255
44006 - 0 0 0 0 0 0 0 0 0 0 0 0
44007 - 0 0 0 0 0 0 0 0 0 0 0 0
44008 - 0 0 0 0 0 0 0 0 0 0 0 0
44009 - 0 0 0 0 0 0 0 0 0 0 0 0
44010 - 0 0 0 0 0 0 0 0 0 0 0 0
44011 - 0 0 0 0 0 0 0 0 0 0 0 0
44012 - 0 0 0 0 0 0 0 0 0 0 0 0
44013 - 0 0 0 0 0 0 0 0 0 0 0 0
44014 - 0 0 0 0 0 0 0 0 0 0 0 0
44015 - 6 6 6 6 6 6 10 10 10 10 10 10
44016 - 10 10 10 6 6 6 6 6 6 6 6 6
44017 - 0 0 0 0 0 0 0 0 0 0 0 0
44018 - 0 0 0 0 0 0 0 0 0 0 0 0
44019 - 0 0 0 0 0 0 0 0 0 0 0 0
44020 - 0 0 0 0 0 0 0 0 0 0 0 0
44021 - 0 0 0 0 0 0 0 0 0 0 0 0
44022 - 0 0 0 0 0 0 0 0 0 0 0 0
44023 - 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
44035 - 22 22 22 26 26 26 30 30 30 34 34 34
44036 - 30 30 30 30 30 30 26 26 26 18 18 18
44037 - 14 14 14 10 10 10 6 6 6 0 0 0
44038 - 0 0 0 0 0 0 0 0 0 0 0 0
44039 - 0 0 0 0 0 0 0 0 0 0 0 0
44040 - 0 0 0 0 0 0 0 0 0 0 0 0
44041 - 0 0 0 0 0 0 0 0 0 0 0 0
44042 - 0 0 0 0 0 0 0 0 0 0 0 0
44043 - 0 0 0 0 0 0 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 1 0 0 1 0 0 0
44048 - 0 0 0 0 0 0 0 0 0 0 0 0
44049 - 0 0 0 0 0 0 0 0 0 0 0 0
44050 - 0 0 0 0 0 0 0 0 0 0 0 0
44051 - 0 0 0 0 0 0 0 0 0 0 0 0
44052 - 0 0 0 0 0 0 0 0 0 0 0 0
44053 - 0 0 0 0 0 0 0 0 0 0 0 0
44054 - 6 6 6 14 14 14 26 26 26 42 42 42
44055 - 54 54 54 66 66 66 78 78 78 78 78 78
44056 - 78 78 78 74 74 74 66 66 66 54 54 54
44057 - 42 42 42 26 26 26 18 18 18 10 10 10
44058 - 6 6 6 0 0 0 0 0 0 0 0 0
44059 - 0 0 0 0 0 0 0 0 0 0 0 0
44060 - 0 0 0 0 0 0 0 0 0 0 0 0
44061 - 0 0 0 0 0 0 0 0 0 0 0 0
44062 - 0 0 0 0 0 0 0 0 0 0 0 0
44063 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
44068 - 0 0 0 0 0 0 0 0 0 0 0 0
44069 - 0 0 0 0 0 0 0 0 0 0 0 0
44070 - 0 0 0 0 0 0 0 0 0 0 0 0
44071 - 0 0 0 0 0 0 0 0 0 0 0 0
44072 - 0 0 0 0 0 0 0 0 0 0 0 0
44073 - 0 0 0 0 0 0 0 0 0 10 10 10
44074 - 22 22 22 42 42 42 66 66 66 86 86 86
44075 - 66 66 66 38 38 38 38 38 38 22 22 22
44076 - 26 26 26 34 34 34 54 54 54 66 66 66
44077 - 86 86 86 70 70 70 46 46 46 26 26 26
44078 - 14 14 14 6 6 6 0 0 0 0 0 0
44079 - 0 0 0 0 0 0 0 0 0 0 0 0
44080 - 0 0 0 0 0 0 0 0 0 0 0 0
44081 - 0 0 0 0 0 0 0 0 0 0 0 0
44082 - 0 0 0 0 0 0 0 0 0 0 0 0
44083 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
44088 - 0 0 0 0 0 0 0 0 0 0 0 0
44089 - 0 0 0 0 0 0 0 0 0 0 0 0
44090 - 0 0 0 0 0 0 0 0 0 0 0 0
44091 - 0 0 0 0 0 0 0 0 0 0 0 0
44092 - 0 0 0 0 0 0 0 0 0 0 0 0
44093 - 0 0 0 0 0 0 10 10 10 26 26 26
44094 - 50 50 50 82 82 82 58 58 58 6 6 6
44095 - 2 2 6 2 2 6 2 2 6 2 2 6
44096 - 2 2 6 2 2 6 2 2 6 2 2 6
44097 - 6 6 6 54 54 54 86 86 86 66 66 66
44098 - 38 38 38 18 18 18 6 6 6 0 0 0
44099 - 0 0 0 0 0 0 0 0 0 0 0 0
44100 - 0 0 0 0 0 0 0 0 0 0 0 0
44101 - 0 0 0 0 0 0 0 0 0 0 0 0
44102 - 0 0 0 0 0 0 0 0 0 0 0 0
44103 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0
44112 - 0 0 0 0 0 0 0 0 0 0 0 0
44113 - 0 0 0 6 6 6 22 22 22 50 50 50
44114 - 78 78 78 34 34 34 2 2 6 2 2 6
44115 - 2 2 6 2 2 6 2 2 6 2 2 6
44116 - 2 2 6 2 2 6 2 2 6 2 2 6
44117 - 2 2 6 2 2 6 6 6 6 70 70 70
44118 - 78 78 78 46 46 46 22 22 22 6 6 6
44119 - 0 0 0 0 0 0 0 0 0 0 0 0
44120 - 0 0 0 0 0 0 0 0 0 0 0 0
44121 - 0 0 0 0 0 0 0 0 0 0 0 0
44122 - 0 0 0 0 0 0 0 0 0 0 0 0
44123 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
44128 - 0 0 0 0 0 0 0 0 0 0 0 0
44129 - 0 0 0 0 0 0 0 0 0 0 0 0
44130 - 0 0 0 0 0 0 0 0 0 0 0 0
44131 - 0 0 0 0 0 0 0 0 0 0 0 0
44132 - 0 0 0 0 0 0 0 0 0 0 0 0
44133 - 6 6 6 18 18 18 42 42 42 82 82 82
44134 - 26 26 26 2 2 6 2 2 6 2 2 6
44135 - 2 2 6 2 2 6 2 2 6 2 2 6
44136 - 2 2 6 2 2 6 2 2 6 14 14 14
44137 - 46 46 46 34 34 34 6 6 6 2 2 6
44138 - 42 42 42 78 78 78 42 42 42 18 18 18
44139 - 6 6 6 0 0 0 0 0 0 0 0 0
44140 - 0 0 0 0 0 0 0 0 0 0 0 0
44141 - 0 0 0 0 0 0 0 0 0 0 0 0
44142 - 0 0 0 0 0 0 0 0 0 0 0 0
44143 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 1 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 - 10 10 10 30 30 30 66 66 66 58 58 58
44154 - 2 2 6 2 2 6 2 2 6 2 2 6
44155 - 2 2 6 2 2 6 2 2 6 2 2 6
44156 - 2 2 6 2 2 6 2 2 6 26 26 26
44157 - 86 86 86 101 101 101 46 46 46 10 10 10
44158 - 2 2 6 58 58 58 70 70 70 34 34 34
44159 - 10 10 10 0 0 0 0 0 0 0 0 0
44160 - 0 0 0 0 0 0 0 0 0 0 0 0
44161 - 0 0 0 0 0 0 0 0 0 0 0 0
44162 - 0 0 0 0 0 0 0 0 0 0 0 0
44163 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 0 0 0
44168 - 0 0 0 0 0 0 0 0 0 0 0 0
44169 - 0 0 0 0 0 0 0 0 0 0 0 0
44170 - 0 0 0 0 0 0 0 0 0 0 0 0
44171 - 0 0 0 0 0 0 0 0 0 0 0 0
44172 - 0 0 0 0 0 0 0 0 0 0 0 0
44173 - 14 14 14 42 42 42 86 86 86 10 10 10
44174 - 2 2 6 2 2 6 2 2 6 2 2 6
44175 - 2 2 6 2 2 6 2 2 6 2 2 6
44176 - 2 2 6 2 2 6 2 2 6 30 30 30
44177 - 94 94 94 94 94 94 58 58 58 26 26 26
44178 - 2 2 6 6 6 6 78 78 78 54 54 54
44179 - 22 22 22 6 6 6 0 0 0 0 0 0
44180 - 0 0 0 0 0 0 0 0 0 0 0 0
44181 - 0 0 0 0 0 0 0 0 0 0 0 0
44182 - 0 0 0 0 0 0 0 0 0 0 0 0
44183 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
44193 - 22 22 22 62 62 62 62 62 62 2 2 6
44194 - 2 2 6 2 2 6 2 2 6 2 2 6
44195 - 2 2 6 2 2 6 2 2 6 2 2 6
44196 - 2 2 6 2 2 6 2 2 6 26 26 26
44197 - 54 54 54 38 38 38 18 18 18 10 10 10
44198 - 2 2 6 2 2 6 34 34 34 82 82 82
44199 - 38 38 38 14 14 14 0 0 0 0 0 0
44200 - 0 0 0 0 0 0 0 0 0 0 0 0
44201 - 0 0 0 0 0 0 0 0 0 0 0 0
44202 - 0 0 0 0 0 0 0 0 0 0 0 0
44203 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 0
44208 - 0 0 0 0 0 0 0 0 0 0 0 0
44209 - 0 0 0 0 0 0 0 0 0 0 0 0
44210 - 0 0 0 0 0 0 0 0 0 0 0 0
44211 - 0 0 0 0 0 0 0 0 0 0 0 0
44212 - 0 0 0 0 0 0 0 0 0 6 6 6
44213 - 30 30 30 78 78 78 30 30 30 2 2 6
44214 - 2 2 6 2 2 6 2 2 6 2 2 6
44215 - 2 2 6 2 2 6 2 2 6 2 2 6
44216 - 2 2 6 2 2 6 2 2 6 10 10 10
44217 - 10 10 10 2 2 6 2 2 6 2 2 6
44218 - 2 2 6 2 2 6 2 2 6 78 78 78
44219 - 50 50 50 18 18 18 6 6 6 0 0 0
44220 - 0 0 0 0 0 0 0 0 0 0 0 0
44221 - 0 0 0 0 0 0 0 0 0 0 0 0
44222 - 0 0 0 0 0 0 0 0 0 0 0 0
44223 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0 0 0 0 0 0 0
44228 - 0 0 0 0 0 0 0 0 0 0 0 0
44229 - 0 0 0 0 0 0 0 0 0 0 0 0
44230 - 0 0 0 0 0 0 0 0 0 0 0 0
44231 - 0 0 0 0 0 0 0 0 0 0 0 0
44232 - 0 0 0 0 0 0 0 0 0 10 10 10
44233 - 38 38 38 86 86 86 14 14 14 2 2 6
44234 - 2 2 6 2 2 6 2 2 6 2 2 6
44235 - 2 2 6 2 2 6 2 2 6 2 2 6
44236 - 2 2 6 2 2 6 2 2 6 2 2 6
44237 - 2 2 6 2 2 6 2 2 6 2 2 6
44238 - 2 2 6 2 2 6 2 2 6 54 54 54
44239 - 66 66 66 26 26 26 6 6 6 0 0 0
44240 - 0 0 0 0 0 0 0 0 0 0 0 0
44241 - 0 0 0 0 0 0 0 0 0 0 0 0
44242 - 0 0 0 0 0 0 0 0 0 0 0 0
44243 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 0
44248 - 0 0 0 0 0 0 0 0 0 0 0 0
44249 - 0 0 0 0 0 0 0 0 0 0 0 0
44250 - 0 0 0 0 0 0 0 0 0 0 0 0
44251 - 0 0 0 0 0 0 0 0 0 0 0 0
44252 - 0 0 0 0 0 0 0 0 0 14 14 14
44253 - 42 42 42 82 82 82 2 2 6 2 2 6
44254 - 2 2 6 6 6 6 10 10 10 2 2 6
44255 - 2 2 6 2 2 6 2 2 6 2 2 6
44256 - 2 2 6 2 2 6 2 2 6 6 6 6
44257 - 14 14 14 10 10 10 2 2 6 2 2 6
44258 - 2 2 6 2 2 6 2 2 6 18 18 18
44259 - 82 82 82 34 34 34 10 10 10 0 0 0
44260 - 0 0 0 0 0 0 0 0 0 0 0 0
44261 - 0 0 0 0 0 0 0 0 0 0 0 0
44262 - 0 0 0 0 0 0 0 0 0 0 0 0
44263 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 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 14 14 14
44273 - 46 46 46 86 86 86 2 2 6 2 2 6
44274 - 6 6 6 6 6 6 22 22 22 34 34 34
44275 - 6 6 6 2 2 6 2 2 6 2 2 6
44276 - 2 2 6 2 2 6 18 18 18 34 34 34
44277 - 10 10 10 50 50 50 22 22 22 2 2 6
44278 - 2 2 6 2 2 6 2 2 6 10 10 10
44279 - 86 86 86 42 42 42 14 14 14 0 0 0
44280 - 0 0 0 0 0 0 0 0 0 0 0 0
44281 - 0 0 0 0 0 0 0 0 0 0 0 0
44282 - 0 0 0 0 0 0 0 0 0 0 0 0
44283 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 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 14 14 14
44293 - 46 46 46 86 86 86 2 2 6 2 2 6
44294 - 38 38 38 116 116 116 94 94 94 22 22 22
44295 - 22 22 22 2 2 6 2 2 6 2 2 6
44296 - 14 14 14 86 86 86 138 138 138 162 162 162
44297 -154 154 154 38 38 38 26 26 26 6 6 6
44298 - 2 2 6 2 2 6 2 2 6 2 2 6
44299 - 86 86 86 46 46 46 14 14 14 0 0 0
44300 - 0 0 0 0 0 0 0 0 0 0 0 0
44301 - 0 0 0 0 0 0 0 0 0 0 0 0
44302 - 0 0 0 0 0 0 0 0 0 0 0 0
44303 - 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
44313 - 46 46 46 86 86 86 2 2 6 14 14 14
44314 -134 134 134 198 198 198 195 195 195 116 116 116
44315 - 10 10 10 2 2 6 2 2 6 6 6 6
44316 -101 98 89 187 187 187 210 210 210 218 218 218
44317 -214 214 214 134 134 134 14 14 14 6 6 6
44318 - 2 2 6 2 2 6 2 2 6 2 2 6
44319 - 86 86 86 50 50 50 18 18 18 6 6 6
44320 - 0 0 0 0 0 0 0 0 0 0 0 0
44321 - 0 0 0 0 0 0 0 0 0 0 0 0
44322 - 0 0 0 0 0 0 0 0 0 0 0 0
44323 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0
44327 - 0 0 1 0 0 1 0 0 1 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 14 14 14
44333 - 46 46 46 86 86 86 2 2 6 54 54 54
44334 -218 218 218 195 195 195 226 226 226 246 246 246
44335 - 58 58 58 2 2 6 2 2 6 30 30 30
44336 -210 210 210 253 253 253 174 174 174 123 123 123
44337 -221 221 221 234 234 234 74 74 74 2 2 6
44338 - 2 2 6 2 2 6 2 2 6 2 2 6
44339 - 70 70 70 58 58 58 22 22 22 6 6 6
44340 - 0 0 0 0 0 0 0 0 0 0 0 0
44341 - 0 0 0 0 0 0 0 0 0 0 0 0
44342 - 0 0 0 0 0 0 0 0 0 0 0 0
44343 - 0 0 0 0 0 0 0 0 0 0 0 0
44344 - 0 0 0 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 14 14 14
44353 - 46 46 46 82 82 82 2 2 6 106 106 106
44354 -170 170 170 26 26 26 86 86 86 226 226 226
44355 -123 123 123 10 10 10 14 14 14 46 46 46
44356 -231 231 231 190 190 190 6 6 6 70 70 70
44357 - 90 90 90 238 238 238 158 158 158 2 2 6
44358 - 2 2 6 2 2 6 2 2 6 2 2 6
44359 - 70 70 70 58 58 58 22 22 22 6 6 6
44360 - 0 0 0 0 0 0 0 0 0 0 0 0
44361 - 0 0 0 0 0 0 0 0 0 0 0 0
44362 - 0 0 0 0 0 0 0 0 0 0 0 0
44363 - 0 0 0 0 0 0 0 0 0 0 0 0
44364 - 0 0 0 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 1 0 0 0
44367 - 0 0 1 0 0 1 0 0 1 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 14 14 14
44373 - 42 42 42 86 86 86 6 6 6 116 116 116
44374 -106 106 106 6 6 6 70 70 70 149 149 149
44375 -128 128 128 18 18 18 38 38 38 54 54 54
44376 -221 221 221 106 106 106 2 2 6 14 14 14
44377 - 46 46 46 190 190 190 198 198 198 2 2 6
44378 - 2 2 6 2 2 6 2 2 6 2 2 6
44379 - 74 74 74 62 62 62 22 22 22 6 6 6
44380 - 0 0 0 0 0 0 0 0 0 0 0 0
44381 - 0 0 0 0 0 0 0 0 0 0 0 0
44382 - 0 0 0 0 0 0 0 0 0 0 0 0
44383 - 0 0 0 0 0 0 0 0 0 0 0 0
44384 - 0 0 0 0 0 0 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 1 0 0 0
44387 - 0 0 1 0 0 0 0 0 1 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 14 14 14
44393 - 42 42 42 94 94 94 14 14 14 101 101 101
44394 -128 128 128 2 2 6 18 18 18 116 116 116
44395 -118 98 46 121 92 8 121 92 8 98 78 10
44396 -162 162 162 106 106 106 2 2 6 2 2 6
44397 - 2 2 6 195 195 195 195 195 195 6 6 6
44398 - 2 2 6 2 2 6 2 2 6 2 2 6
44399 - 74 74 74 62 62 62 22 22 22 6 6 6
44400 - 0 0 0 0 0 0 0 0 0 0 0 0
44401 - 0 0 0 0 0 0 0 0 0 0 0 0
44402 - 0 0 0 0 0 0 0 0 0 0 0 0
44403 - 0 0 0 0 0 0 0 0 0 0 0 0
44404 - 0 0 0 0 0 0 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 1 0 0 1
44407 - 0 0 1 0 0 0 0 0 1 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 10 10 10
44413 - 38 38 38 90 90 90 14 14 14 58 58 58
44414 -210 210 210 26 26 26 54 38 6 154 114 10
44415 -226 170 11 236 186 11 225 175 15 184 144 12
44416 -215 174 15 175 146 61 37 26 9 2 2 6
44417 - 70 70 70 246 246 246 138 138 138 2 2 6
44418 - 2 2 6 2 2 6 2 2 6 2 2 6
44419 - 70 70 70 66 66 66 26 26 26 6 6 6
44420 - 0 0 0 0 0 0 0 0 0 0 0 0
44421 - 0 0 0 0 0 0 0 0 0 0 0 0
44422 - 0 0 0 0 0 0 0 0 0 0 0 0
44423 - 0 0 0 0 0 0 0 0 0 0 0 0
44424 - 0 0 0 0 0 0 0 0 0 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 10 10 10
44433 - 38 38 38 86 86 86 14 14 14 10 10 10
44434 -195 195 195 188 164 115 192 133 9 225 175 15
44435 -239 182 13 234 190 10 232 195 16 232 200 30
44436 -245 207 45 241 208 19 232 195 16 184 144 12
44437 -218 194 134 211 206 186 42 42 42 2 2 6
44438 - 2 2 6 2 2 6 2 2 6 2 2 6
44439 - 50 50 50 74 74 74 30 30 30 6 6 6
44440 - 0 0 0 0 0 0 0 0 0 0 0 0
44441 - 0 0 0 0 0 0 0 0 0 0 0 0
44442 - 0 0 0 0 0 0 0 0 0 0 0 0
44443 - 0 0 0 0 0 0 0 0 0 0 0 0
44444 - 0 0 0 0 0 0 0 0 0 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 10 10 10
44453 - 34 34 34 86 86 86 14 14 14 2 2 6
44454 -121 87 25 192 133 9 219 162 10 239 182 13
44455 -236 186 11 232 195 16 241 208 19 244 214 54
44456 -246 218 60 246 218 38 246 215 20 241 208 19
44457 -241 208 19 226 184 13 121 87 25 2 2 6
44458 - 2 2 6 2 2 6 2 2 6 2 2 6
44459 - 50 50 50 82 82 82 34 34 34 10 10 10
44460 - 0 0 0 0 0 0 0 0 0 0 0 0
44461 - 0 0 0 0 0 0 0 0 0 0 0 0
44462 - 0 0 0 0 0 0 0 0 0 0 0 0
44463 - 0 0 0 0 0 0 0 0 0 0 0 0
44464 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
44473 - 34 34 34 82 82 82 30 30 30 61 42 6
44474 -180 123 7 206 145 10 230 174 11 239 182 13
44475 -234 190 10 238 202 15 241 208 19 246 218 74
44476 -246 218 38 246 215 20 246 215 20 246 215 20
44477 -226 184 13 215 174 15 184 144 12 6 6 6
44478 - 2 2 6 2 2 6 2 2 6 2 2 6
44479 - 26 26 26 94 94 94 42 42 42 14 14 14
44480 - 0 0 0 0 0 0 0 0 0 0 0 0
44481 - 0 0 0 0 0 0 0 0 0 0 0 0
44482 - 0 0 0 0 0 0 0 0 0 0 0 0
44483 - 0 0 0 0 0 0 0 0 0 0 0 0
44484 - 0 0 0 0 0 0 0 0 0 0 0 0
44485 - 0 0 0 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 10 10 10
44493 - 30 30 30 78 78 78 50 50 50 104 69 6
44494 -192 133 9 216 158 10 236 178 12 236 186 11
44495 -232 195 16 241 208 19 244 214 54 245 215 43
44496 -246 215 20 246 215 20 241 208 19 198 155 10
44497 -200 144 11 216 158 10 156 118 10 2 2 6
44498 - 2 2 6 2 2 6 2 2 6 2 2 6
44499 - 6 6 6 90 90 90 54 54 54 18 18 18
44500 - 6 6 6 0 0 0 0 0 0 0 0 0
44501 - 0 0 0 0 0 0 0 0 0 0 0 0
44502 - 0 0 0 0 0 0 0 0 0 0 0 0
44503 - 0 0 0 0 0 0 0 0 0 0 0 0
44504 - 0 0 0 0 0 0 0 0 0 0 0 0
44505 - 0 0 0 0 0 0 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 10 10 10
44513 - 30 30 30 78 78 78 46 46 46 22 22 22
44514 -137 92 6 210 162 10 239 182 13 238 190 10
44515 -238 202 15 241 208 19 246 215 20 246 215 20
44516 -241 208 19 203 166 17 185 133 11 210 150 10
44517 -216 158 10 210 150 10 102 78 10 2 2 6
44518 - 6 6 6 54 54 54 14 14 14 2 2 6
44519 - 2 2 6 62 62 62 74 74 74 30 30 30
44520 - 10 10 10 0 0 0 0 0 0 0 0 0
44521 - 0 0 0 0 0 0 0 0 0 0 0 0
44522 - 0 0 0 0 0 0 0 0 0 0 0 0
44523 - 0 0 0 0 0 0 0 0 0 0 0 0
44524 - 0 0 0 0 0 0 0 0 0 0 0 0
44525 - 0 0 0 0 0 0 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 10 10 10
44533 - 34 34 34 78 78 78 50 50 50 6 6 6
44534 - 94 70 30 139 102 15 190 146 13 226 184 13
44535 -232 200 30 232 195 16 215 174 15 190 146 13
44536 -168 122 10 192 133 9 210 150 10 213 154 11
44537 -202 150 34 182 157 106 101 98 89 2 2 6
44538 - 2 2 6 78 78 78 116 116 116 58 58 58
44539 - 2 2 6 22 22 22 90 90 90 46 46 46
44540 - 18 18 18 6 6 6 0 0 0 0 0 0
44541 - 0 0 0 0 0 0 0 0 0 0 0 0
44542 - 0 0 0 0 0 0 0 0 0 0 0 0
44543 - 0 0 0 0 0 0 0 0 0 0 0 0
44544 - 0 0 0 0 0 0 0 0 0 0 0 0
44545 - 0 0 0 0 0 0 0 0 0 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 10 10 10
44553 - 38 38 38 86 86 86 50 50 50 6 6 6
44554 -128 128 128 174 154 114 156 107 11 168 122 10
44555 -198 155 10 184 144 12 197 138 11 200 144 11
44556 -206 145 10 206 145 10 197 138 11 188 164 115
44557 -195 195 195 198 198 198 174 174 174 14 14 14
44558 - 2 2 6 22 22 22 116 116 116 116 116 116
44559 - 22 22 22 2 2 6 74 74 74 70 70 70
44560 - 30 30 30 10 10 10 0 0 0 0 0 0
44561 - 0 0 0 0 0 0 0 0 0 0 0 0
44562 - 0 0 0 0 0 0 0 0 0 0 0 0
44563 - 0 0 0 0 0 0 0 0 0 0 0 0
44564 - 0 0 0 0 0 0 0 0 0 0 0 0
44565 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
44573 - 50 50 50 101 101 101 26 26 26 10 10 10
44574 -138 138 138 190 190 190 174 154 114 156 107 11
44575 -197 138 11 200 144 11 197 138 11 192 133 9
44576 -180 123 7 190 142 34 190 178 144 187 187 187
44577 -202 202 202 221 221 221 214 214 214 66 66 66
44578 - 2 2 6 2 2 6 50 50 50 62 62 62
44579 - 6 6 6 2 2 6 10 10 10 90 90 90
44580 - 50 50 50 18 18 18 6 6 6 0 0 0
44581 - 0 0 0 0 0 0 0 0 0 0 0 0
44582 - 0 0 0 0 0 0 0 0 0 0 0 0
44583 - 0 0 0 0 0 0 0 0 0 0 0 0
44584 - 0 0 0 0 0 0 0 0 0 0 0 0
44585 - 0 0 0 0 0 0 0 0 0 0 0 0
44586 - 0 0 0 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 10 10 10 34 34 34
44593 - 74 74 74 74 74 74 2 2 6 6 6 6
44594 -144 144 144 198 198 198 190 190 190 178 166 146
44595 -154 121 60 156 107 11 156 107 11 168 124 44
44596 -174 154 114 187 187 187 190 190 190 210 210 210
44597 -246 246 246 253 253 253 253 253 253 182 182 182
44598 - 6 6 6 2 2 6 2 2 6 2 2 6
44599 - 2 2 6 2 2 6 2 2 6 62 62 62
44600 - 74 74 74 34 34 34 14 14 14 0 0 0
44601 - 0 0 0 0 0 0 0 0 0 0 0 0
44602 - 0 0 0 0 0 0 0 0 0 0 0 0
44603 - 0 0 0 0 0 0 0 0 0 0 0 0
44604 - 0 0 0 0 0 0 0 0 0 0 0 0
44605 - 0 0 0 0 0 0 0 0 0 0 0 0
44606 - 0 0 0 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 10 10 10 22 22 22 54 54 54
44613 - 94 94 94 18 18 18 2 2 6 46 46 46
44614 -234 234 234 221 221 221 190 190 190 190 190 190
44615 -190 190 190 187 187 187 187 187 187 190 190 190
44616 -190 190 190 195 195 195 214 214 214 242 242 242
44617 -253 253 253 253 253 253 253 253 253 253 253 253
44618 - 82 82 82 2 2 6 2 2 6 2 2 6
44619 - 2 2 6 2 2 6 2 2 6 14 14 14
44620 - 86 86 86 54 54 54 22 22 22 6 6 6
44621 - 0 0 0 0 0 0 0 0 0 0 0 0
44622 - 0 0 0 0 0 0 0 0 0 0 0 0
44623 - 0 0 0 0 0 0 0 0 0 0 0 0
44624 - 0 0 0 0 0 0 0 0 0 0 0 0
44625 - 0 0 0 0 0 0 0 0 0 0 0 0
44626 - 0 0 0 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
44633 - 46 46 46 18 18 18 6 6 6 182 182 182
44634 -253 253 253 246 246 246 206 206 206 190 190 190
44635 -190 190 190 190 190 190 190 190 190 190 190 190
44636 -206 206 206 231 231 231 250 250 250 253 253 253
44637 -253 253 253 253 253 253 253 253 253 253 253 253
44638 -202 202 202 14 14 14 2 2 6 2 2 6
44639 - 2 2 6 2 2 6 2 2 6 2 2 6
44640 - 42 42 42 86 86 86 42 42 42 18 18 18
44641 - 6 6 6 0 0 0 0 0 0 0 0 0
44642 - 0 0 0 0 0 0 0 0 0 0 0 0
44643 - 0 0 0 0 0 0 0 0 0 0 0 0
44644 - 0 0 0 0 0 0 0 0 0 0 0 0
44645 - 0 0 0 0 0 0 0 0 0 0 0 0
44646 - 0 0 0 0 0 0 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 6 6 6
44652 - 14 14 14 38 38 38 74 74 74 66 66 66
44653 - 2 2 6 6 6 6 90 90 90 250 250 250
44654 -253 253 253 253 253 253 238 238 238 198 198 198
44655 -190 190 190 190 190 190 195 195 195 221 221 221
44656 -246 246 246 253 253 253 253 253 253 253 253 253
44657 -253 253 253 253 253 253 253 253 253 253 253 253
44658 -253 253 253 82 82 82 2 2 6 2 2 6
44659 - 2 2 6 2 2 6 2 2 6 2 2 6
44660 - 2 2 6 78 78 78 70 70 70 34 34 34
44661 - 14 14 14 6 6 6 0 0 0 0 0 0
44662 - 0 0 0 0 0 0 0 0 0 0 0 0
44663 - 0 0 0 0 0 0 0 0 0 0 0 0
44664 - 0 0 0 0 0 0 0 0 0 0 0 0
44665 - 0 0 0 0 0 0 0 0 0 0 0 0
44666 - 0 0 0 0 0 0 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 14 14 14
44672 - 34 34 34 66 66 66 78 78 78 6 6 6
44673 - 2 2 6 18 18 18 218 218 218 253 253 253
44674 -253 253 253 253 253 253 253 253 253 246 246 246
44675 -226 226 226 231 231 231 246 246 246 253 253 253
44676 -253 253 253 253 253 253 253 253 253 253 253 253
44677 -253 253 253 253 253 253 253 253 253 253 253 253
44678 -253 253 253 178 178 178 2 2 6 2 2 6
44679 - 2 2 6 2 2 6 2 2 6 2 2 6
44680 - 2 2 6 18 18 18 90 90 90 62 62 62
44681 - 30 30 30 10 10 10 0 0 0 0 0 0
44682 - 0 0 0 0 0 0 0 0 0 0 0 0
44683 - 0 0 0 0 0 0 0 0 0 0 0 0
44684 - 0 0 0 0 0 0 0 0 0 0 0 0
44685 - 0 0 0 0 0 0 0 0 0 0 0 0
44686 - 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
44692 - 58 58 58 90 90 90 18 18 18 2 2 6
44693 - 2 2 6 110 110 110 253 253 253 253 253 253
44694 -253 253 253 253 253 253 253 253 253 253 253 253
44695 -250 250 250 253 253 253 253 253 253 253 253 253
44696 -253 253 253 253 253 253 253 253 253 253 253 253
44697 -253 253 253 253 253 253 253 253 253 253 253 253
44698 -253 253 253 231 231 231 18 18 18 2 2 6
44699 - 2 2 6 2 2 6 2 2 6 2 2 6
44700 - 2 2 6 2 2 6 18 18 18 94 94 94
44701 - 54 54 54 26 26 26 10 10 10 0 0 0
44702 - 0 0 0 0 0 0 0 0 0 0 0 0
44703 - 0 0 0 0 0 0 0 0 0 0 0 0
44704 - 0 0 0 0 0 0 0 0 0 0 0 0
44705 - 0 0 0 0 0 0 0 0 0 0 0 0
44706 - 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
44712 - 90 90 90 26 26 26 2 2 6 2 2 6
44713 - 14 14 14 195 195 195 250 250 250 253 253 253
44714 -253 253 253 253 253 253 253 253 253 253 253 253
44715 -253 253 253 253 253 253 253 253 253 253 253 253
44716 -253 253 253 253 253 253 253 253 253 253 253 253
44717 -253 253 253 253 253 253 253 253 253 253 253 253
44718 -250 250 250 242 242 242 54 54 54 2 2 6
44719 - 2 2 6 2 2 6 2 2 6 2 2 6
44720 - 2 2 6 2 2 6 2 2 6 38 38 38
44721 - 86 86 86 50 50 50 22 22 22 6 6 6
44722 - 0 0 0 0 0 0 0 0 0 0 0 0
44723 - 0 0 0 0 0 0 0 0 0 0 0 0
44724 - 0 0 0 0 0 0 0 0 0 0 0 0
44725 - 0 0 0 0 0 0 0 0 0 0 0 0
44726 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 14 14 14 38 38 38 82 82 82
44732 - 34 34 34 2 2 6 2 2 6 2 2 6
44733 - 42 42 42 195 195 195 246 246 246 253 253 253
44734 -253 253 253 253 253 253 253 253 253 250 250 250
44735 -242 242 242 242 242 242 250 250 250 253 253 253
44736 -253 253 253 253 253 253 253 253 253 253 253 253
44737 -253 253 253 250 250 250 246 246 246 238 238 238
44738 -226 226 226 231 231 231 101 101 101 6 6 6
44739 - 2 2 6 2 2 6 2 2 6 2 2 6
44740 - 2 2 6 2 2 6 2 2 6 2 2 6
44741 - 38 38 38 82 82 82 42 42 42 14 14 14
44742 - 6 6 6 0 0 0 0 0 0 0 0 0
44743 - 0 0 0 0 0 0 0 0 0 0 0 0
44744 - 0 0 0 0 0 0 0 0 0 0 0 0
44745 - 0 0 0 0 0 0 0 0 0 0 0 0
44746 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 10 10 10 26 26 26 62 62 62 66 66 66
44752 - 2 2 6 2 2 6 2 2 6 6 6 6
44753 - 70 70 70 170 170 170 206 206 206 234 234 234
44754 -246 246 246 250 250 250 250 250 250 238 238 238
44755 -226 226 226 231 231 231 238 238 238 250 250 250
44756 -250 250 250 250 250 250 246 246 246 231 231 231
44757 -214 214 214 206 206 206 202 202 202 202 202 202
44758 -198 198 198 202 202 202 182 182 182 18 18 18
44759 - 2 2 6 2 2 6 2 2 6 2 2 6
44760 - 2 2 6 2 2 6 2 2 6 2 2 6
44761 - 2 2 6 62 62 62 66 66 66 30 30 30
44762 - 10 10 10 0 0 0 0 0 0 0 0 0
44763 - 0 0 0 0 0 0 0 0 0 0 0 0
44764 - 0 0 0 0 0 0 0 0 0 0 0 0
44765 - 0 0 0 0 0 0 0 0 0 0 0 0
44766 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 14 14 14 42 42 42 82 82 82 18 18 18
44772 - 2 2 6 2 2 6 2 2 6 10 10 10
44773 - 94 94 94 182 182 182 218 218 218 242 242 242
44774 -250 250 250 253 253 253 253 253 253 250 250 250
44775 -234 234 234 253 253 253 253 253 253 253 253 253
44776 -253 253 253 253 253 253 253 253 253 246 246 246
44777 -238 238 238 226 226 226 210 210 210 202 202 202
44778 -195 195 195 195 195 195 210 210 210 158 158 158
44779 - 6 6 6 14 14 14 50 50 50 14 14 14
44780 - 2 2 6 2 2 6 2 2 6 2 2 6
44781 - 2 2 6 6 6 6 86 86 86 46 46 46
44782 - 18 18 18 6 6 6 0 0 0 0 0 0
44783 - 0 0 0 0 0 0 0 0 0 0 0 0
44784 - 0 0 0 0 0 0 0 0 0 0 0 0
44785 - 0 0 0 0 0 0 0 0 0 0 0 0
44786 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
44791 - 22 22 22 54 54 54 70 70 70 2 2 6
44792 - 2 2 6 10 10 10 2 2 6 22 22 22
44793 -166 166 166 231 231 231 250 250 250 253 253 253
44794 -253 253 253 253 253 253 253 253 253 250 250 250
44795 -242 242 242 253 253 253 253 253 253 253 253 253
44796 -253 253 253 253 253 253 253 253 253 253 253 253
44797 -253 253 253 253 253 253 253 253 253 246 246 246
44798 -231 231 231 206 206 206 198 198 198 226 226 226
44799 - 94 94 94 2 2 6 6 6 6 38 38 38
44800 - 30 30 30 2 2 6 2 2 6 2 2 6
44801 - 2 2 6 2 2 6 62 62 62 66 66 66
44802 - 26 26 26 10 10 10 0 0 0 0 0 0
44803 - 0 0 0 0 0 0 0 0 0 0 0 0
44804 - 0 0 0 0 0 0 0 0 0 0 0 0
44805 - 0 0 0 0 0 0 0 0 0 0 0 0
44806 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
44811 - 30 30 30 74 74 74 50 50 50 2 2 6
44812 - 26 26 26 26 26 26 2 2 6 106 106 106
44813 -238 238 238 253 253 253 253 253 253 253 253 253
44814 -253 253 253 253 253 253 253 253 253 253 253 253
44815 -253 253 253 253 253 253 253 253 253 253 253 253
44816 -253 253 253 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 246 246 246 218 218 218 202 202 202
44819 -210 210 210 14 14 14 2 2 6 2 2 6
44820 - 30 30 30 22 22 22 2 2 6 2 2 6
44821 - 2 2 6 2 2 6 18 18 18 86 86 86
44822 - 42 42 42 14 14 14 0 0 0 0 0 0
44823 - 0 0 0 0 0 0 0 0 0 0 0 0
44824 - 0 0 0 0 0 0 0 0 0 0 0 0
44825 - 0 0 0 0 0 0 0 0 0 0 0 0
44826 - 0 0 0 0 0 0 0 0 0 0 0 0
44827 - 0 0 0 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 14 14 14
44831 - 42 42 42 90 90 90 22 22 22 2 2 6
44832 - 42 42 42 2 2 6 18 18 18 218 218 218
44833 -253 253 253 253 253 253 253 253 253 253 253 253
44834 -253 253 253 253 253 253 253 253 253 253 253 253
44835 -253 253 253 253 253 253 253 253 253 253 253 253
44836 -253 253 253 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 250 250 250 221 221 221
44839 -218 218 218 101 101 101 2 2 6 14 14 14
44840 - 18 18 18 38 38 38 10 10 10 2 2 6
44841 - 2 2 6 2 2 6 2 2 6 78 78 78
44842 - 58 58 58 22 22 22 6 6 6 0 0 0
44843 - 0 0 0 0 0 0 0 0 0 0 0 0
44844 - 0 0 0 0 0 0 0 0 0 0 0 0
44845 - 0 0 0 0 0 0 0 0 0 0 0 0
44846 - 0 0 0 0 0 0 0 0 0 0 0 0
44847 - 0 0 0 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 6 6 6 18 18 18
44851 - 54 54 54 82 82 82 2 2 6 26 26 26
44852 - 22 22 22 2 2 6 123 123 123 253 253 253
44853 -253 253 253 253 253 253 253 253 253 253 253 253
44854 -253 253 253 253 253 253 253 253 253 253 253 253
44855 -253 253 253 253 253 253 253 253 253 253 253 253
44856 -253 253 253 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 253 253 253 250 250 250
44859 -238 238 238 198 198 198 6 6 6 38 38 38
44860 - 58 58 58 26 26 26 38 38 38 2 2 6
44861 - 2 2 6 2 2 6 2 2 6 46 46 46
44862 - 78 78 78 30 30 30 10 10 10 0 0 0
44863 - 0 0 0 0 0 0 0 0 0 0 0 0
44864 - 0 0 0 0 0 0 0 0 0 0 0 0
44865 - 0 0 0 0 0 0 0 0 0 0 0 0
44866 - 0 0 0 0 0 0 0 0 0 0 0 0
44867 - 0 0 0 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 10 10 10 30 30 30
44871 - 74 74 74 58 58 58 2 2 6 42 42 42
44872 - 2 2 6 22 22 22 231 231 231 253 253 253
44873 -253 253 253 253 253 253 253 253 253 253 253 253
44874 -253 253 253 253 253 253 253 253 253 250 250 250
44875 -253 253 253 253 253 253 253 253 253 253 253 253
44876 -253 253 253 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 253 253 253 253 253 253
44879 -253 253 253 246 246 246 46 46 46 38 38 38
44880 - 42 42 42 14 14 14 38 38 38 14 14 14
44881 - 2 2 6 2 2 6 2 2 6 6 6 6
44882 - 86 86 86 46 46 46 14 14 14 0 0 0
44883 - 0 0 0 0 0 0 0 0 0 0 0 0
44884 - 0 0 0 0 0 0 0 0 0 0 0 0
44885 - 0 0 0 0 0 0 0 0 0 0 0 0
44886 - 0 0 0 0 0 0 0 0 0 0 0 0
44887 - 0 0 0 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 6 6 6 14 14 14 42 42 42
44891 - 90 90 90 18 18 18 18 18 18 26 26 26
44892 - 2 2 6 116 116 116 253 253 253 253 253 253
44893 -253 253 253 253 253 253 253 253 253 253 253 253
44894 -253 253 253 253 253 253 250 250 250 238 238 238
44895 -253 253 253 253 253 253 253 253 253 253 253 253
44896 -253 253 253 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 253 253 253 253 253 253
44899 -253 253 253 253 253 253 94 94 94 6 6 6
44900 - 2 2 6 2 2 6 10 10 10 34 34 34
44901 - 2 2 6 2 2 6 2 2 6 2 2 6
44902 - 74 74 74 58 58 58 22 22 22 6 6 6
44903 - 0 0 0 0 0 0 0 0 0 0 0 0
44904 - 0 0 0 0 0 0 0 0 0 0 0 0
44905 - 0 0 0 0 0 0 0 0 0 0 0 0
44906 - 0 0 0 0 0 0 0 0 0 0 0 0
44907 - 0 0 0 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 10 10 10 26 26 26 66 66 66
44911 - 82 82 82 2 2 6 38 38 38 6 6 6
44912 - 14 14 14 210 210 210 253 253 253 253 253 253
44913 -253 253 253 253 253 253 253 253 253 253 253 253
44914 -253 253 253 253 253 253 246 246 246 242 242 242
44915 -253 253 253 253 253 253 253 253 253 253 253 253
44916 -253 253 253 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 253 253 253 253 253 253
44919 -253 253 253 253 253 253 144 144 144 2 2 6
44920 - 2 2 6 2 2 6 2 2 6 46 46 46
44921 - 2 2 6 2 2 6 2 2 6 2 2 6
44922 - 42 42 42 74 74 74 30 30 30 10 10 10
44923 - 0 0 0 0 0 0 0 0 0 0 0 0
44924 - 0 0 0 0 0 0 0 0 0 0 0 0
44925 - 0 0 0 0 0 0 0 0 0 0 0 0
44926 - 0 0 0 0 0 0 0 0 0 0 0 0
44927 - 0 0 0 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 - 6 6 6 14 14 14 42 42 42 90 90 90
44931 - 26 26 26 6 6 6 42 42 42 2 2 6
44932 - 74 74 74 250 250 250 253 253 253 253 253 253
44933 -253 253 253 253 253 253 253 253 253 253 253 253
44934 -253 253 253 253 253 253 242 242 242 242 242 242
44935 -253 253 253 253 253 253 253 253 253 253 253 253
44936 -253 253 253 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 253 253 253 253 253 253
44939 -253 253 253 253 253 253 182 182 182 2 2 6
44940 - 2 2 6 2 2 6 2 2 6 46 46 46
44941 - 2 2 6 2 2 6 2 2 6 2 2 6
44942 - 10 10 10 86 86 86 38 38 38 10 10 10
44943 - 0 0 0 0 0 0 0 0 0 0 0 0
44944 - 0 0 0 0 0 0 0 0 0 0 0 0
44945 - 0 0 0 0 0 0 0 0 0 0 0 0
44946 - 0 0 0 0 0 0 0 0 0 0 0 0
44947 - 0 0 0 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 - 10 10 10 26 26 26 66 66 66 82 82 82
44951 - 2 2 6 22 22 22 18 18 18 2 2 6
44952 -149 149 149 253 253 253 253 253 253 253 253 253
44953 -253 253 253 253 253 253 253 253 253 253 253 253
44954 -253 253 253 253 253 253 234 234 234 242 242 242
44955 -253 253 253 253 253 253 253 253 253 253 253 253
44956 -253 253 253 253 253 253 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 253 253 253 253 253 253
44959 -253 253 253 253 253 253 206 206 206 2 2 6
44960 - 2 2 6 2 2 6 2 2 6 38 38 38
44961 - 2 2 6 2 2 6 2 2 6 2 2 6
44962 - 6 6 6 86 86 86 46 46 46 14 14 14
44963 - 0 0 0 0 0 0 0 0 0 0 0 0
44964 - 0 0 0 0 0 0 0 0 0 0 0 0
44965 - 0 0 0 0 0 0 0 0 0 0 0 0
44966 - 0 0 0 0 0 0 0 0 0 0 0 0
44967 - 0 0 0 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 6 6 6
44970 - 18 18 18 46 46 46 86 86 86 18 18 18
44971 - 2 2 6 34 34 34 10 10 10 6 6 6
44972 -210 210 210 253 253 253 253 253 253 253 253 253
44973 -253 253 253 253 253 253 253 253 253 253 253 253
44974 -253 253 253 253 253 253 234 234 234 242 242 242
44975 -253 253 253 253 253 253 253 253 253 253 253 253
44976 -253 253 253 253 253 253 253 253 253 253 253 253
44977 -253 253 253 253 253 253 253 253 253 253 253 253
44978 -253 253 253 253 253 253 253 253 253 253 253 253
44979 -253 253 253 253 253 253 221 221 221 6 6 6
44980 - 2 2 6 2 2 6 6 6 6 30 30 30
44981 - 2 2 6 2 2 6 2 2 6 2 2 6
44982 - 2 2 6 82 82 82 54 54 54 18 18 18
44983 - 6 6 6 0 0 0 0 0 0 0 0 0
44984 - 0 0 0 0 0 0 0 0 0 0 0 0
44985 - 0 0 0 0 0 0 0 0 0 0 0 0
44986 - 0 0 0 0 0 0 0 0 0 0 0 0
44987 - 0 0 0 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 10 10 10
44990 - 26 26 26 66 66 66 62 62 62 2 2 6
44991 - 2 2 6 38 38 38 10 10 10 26 26 26
44992 -238 238 238 253 253 253 253 253 253 253 253 253
44993 -253 253 253 253 253 253 253 253 253 253 253 253
44994 -253 253 253 253 253 253 231 231 231 238 238 238
44995 -253 253 253 253 253 253 253 253 253 253 253 253
44996 -253 253 253 253 253 253 253 253 253 253 253 253
44997 -253 253 253 253 253 253 253 253 253 253 253 253
44998 -253 253 253 253 253 253 253 253 253 253 253 253
44999 -253 253 253 253 253 253 231 231 231 6 6 6
45000 - 2 2 6 2 2 6 10 10 10 30 30 30
45001 - 2 2 6 2 2 6 2 2 6 2 2 6
45002 - 2 2 6 66 66 66 58 58 58 22 22 22
45003 - 6 6 6 0 0 0 0 0 0 0 0 0
45004 - 0 0 0 0 0 0 0 0 0 0 0 0
45005 - 0 0 0 0 0 0 0 0 0 0 0 0
45006 - 0 0 0 0 0 0 0 0 0 0 0 0
45007 - 0 0 0 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 10 10 10
45010 - 38 38 38 78 78 78 6 6 6 2 2 6
45011 - 2 2 6 46 46 46 14 14 14 42 42 42
45012 -246 246 246 253 253 253 253 253 253 253 253 253
45013 -253 253 253 253 253 253 253 253 253 253 253 253
45014 -253 253 253 253 253 253 231 231 231 242 242 242
45015 -253 253 253 253 253 253 253 253 253 253 253 253
45016 -253 253 253 253 253 253 253 253 253 253 253 253
45017 -253 253 253 253 253 253 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 234 234 234 10 10 10
45020 - 2 2 6 2 2 6 22 22 22 14 14 14
45021 - 2 2 6 2 2 6 2 2 6 2 2 6
45022 - 2 2 6 66 66 66 62 62 62 22 22 22
45023 - 6 6 6 0 0 0 0 0 0 0 0 0
45024 - 0 0 0 0 0 0 0 0 0 0 0 0
45025 - 0 0 0 0 0 0 0 0 0 0 0 0
45026 - 0 0 0 0 0 0 0 0 0 0 0 0
45027 - 0 0 0 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 6 6 6 18 18 18
45030 - 50 50 50 74 74 74 2 2 6 2 2 6
45031 - 14 14 14 70 70 70 34 34 34 62 62 62
45032 -250 250 250 253 253 253 253 253 253 253 253 253
45033 -253 253 253 253 253 253 253 253 253 253 253 253
45034 -253 253 253 253 253 253 231 231 231 246 246 246
45035 -253 253 253 253 253 253 253 253 253 253 253 253
45036 -253 253 253 253 253 253 253 253 253 253 253 253
45037 -253 253 253 253 253 253 253 253 253 253 253 253
45038 -253 253 253 253 253 253 253 253 253 253 253 253
45039 -253 253 253 253 253 253 234 234 234 14 14 14
45040 - 2 2 6 2 2 6 30 30 30 2 2 6
45041 - 2 2 6 2 2 6 2 2 6 2 2 6
45042 - 2 2 6 66 66 66 62 62 62 22 22 22
45043 - 6 6 6 0 0 0 0 0 0 0 0 0
45044 - 0 0 0 0 0 0 0 0 0 0 0 0
45045 - 0 0 0 0 0 0 0 0 0 0 0 0
45046 - 0 0 0 0 0 0 0 0 0 0 0 0
45047 - 0 0 0 0 0 0 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 6 6 6 18 18 18
45050 - 54 54 54 62 62 62 2 2 6 2 2 6
45051 - 2 2 6 30 30 30 46 46 46 70 70 70
45052 -250 250 250 253 253 253 253 253 253 253 253 253
45053 -253 253 253 253 253 253 253 253 253 253 253 253
45054 -253 253 253 253 253 253 231 231 231 246 246 246
45055 -253 253 253 253 253 253 253 253 253 253 253 253
45056 -253 253 253 253 253 253 253 253 253 253 253 253
45057 -253 253 253 253 253 253 253 253 253 253 253 253
45058 -253 253 253 253 253 253 253 253 253 253 253 253
45059 -253 253 253 253 253 253 226 226 226 10 10 10
45060 - 2 2 6 6 6 6 30 30 30 2 2 6
45061 - 2 2 6 2 2 6 2 2 6 2 2 6
45062 - 2 2 6 66 66 66 58 58 58 22 22 22
45063 - 6 6 6 0 0 0 0 0 0 0 0 0
45064 - 0 0 0 0 0 0 0 0 0 0 0 0
45065 - 0 0 0 0 0 0 0 0 0 0 0 0
45066 - 0 0 0 0 0 0 0 0 0 0 0 0
45067 - 0 0 0 0 0 0 0 0 0 0 0 0
45068 - 0 0 0 0 0 0 0 0 0 0 0 0
45069 - 0 0 0 0 0 0 6 6 6 22 22 22
45070 - 58 58 58 62 62 62 2 2 6 2 2 6
45071 - 2 2 6 2 2 6 30 30 30 78 78 78
45072 -250 250 250 253 253 253 253 253 253 253 253 253
45073 -253 253 253 253 253 253 253 253 253 253 253 253
45074 -253 253 253 253 253 253 231 231 231 246 246 246
45075 -253 253 253 253 253 253 253 253 253 253 253 253
45076 -253 253 253 253 253 253 253 253 253 253 253 253
45077 -253 253 253 253 253 253 253 253 253 253 253 253
45078 -253 253 253 253 253 253 253 253 253 253 253 253
45079 -253 253 253 253 253 253 206 206 206 2 2 6
45080 - 22 22 22 34 34 34 18 14 6 22 22 22
45081 - 26 26 26 18 18 18 6 6 6 2 2 6
45082 - 2 2 6 82 82 82 54 54 54 18 18 18
45083 - 6 6 6 0 0 0 0 0 0 0 0 0
45084 - 0 0 0 0 0 0 0 0 0 0 0 0
45085 - 0 0 0 0 0 0 0 0 0 0 0 0
45086 - 0 0 0 0 0 0 0 0 0 0 0 0
45087 - 0 0 0 0 0 0 0 0 0 0 0 0
45088 - 0 0 0 0 0 0 0 0 0 0 0 0
45089 - 0 0 0 0 0 0 6 6 6 26 26 26
45090 - 62 62 62 106 106 106 74 54 14 185 133 11
45091 -210 162 10 121 92 8 6 6 6 62 62 62
45092 -238 238 238 253 253 253 253 253 253 253 253 253
45093 -253 253 253 253 253 253 253 253 253 253 253 253
45094 -253 253 253 253 253 253 231 231 231 246 246 246
45095 -253 253 253 253 253 253 253 253 253 253 253 253
45096 -253 253 253 253 253 253 253 253 253 253 253 253
45097 -253 253 253 253 253 253 253 253 253 253 253 253
45098 -253 253 253 253 253 253 253 253 253 253 253 253
45099 -253 253 253 253 253 253 158 158 158 18 18 18
45100 - 14 14 14 2 2 6 2 2 6 2 2 6
45101 - 6 6 6 18 18 18 66 66 66 38 38 38
45102 - 6 6 6 94 94 94 50 50 50 18 18 18
45103 - 6 6 6 0 0 0 0 0 0 0 0 0
45104 - 0 0 0 0 0 0 0 0 0 0 0 0
45105 - 0 0 0 0 0 0 0 0 0 0 0 0
45106 - 0 0 0 0 0 0 0 0 0 0 0 0
45107 - 0 0 0 0 0 0 0 0 0 0 0 0
45108 - 0 0 0 0 0 0 0 0 0 6 6 6
45109 - 10 10 10 10 10 10 18 18 18 38 38 38
45110 - 78 78 78 142 134 106 216 158 10 242 186 14
45111 -246 190 14 246 190 14 156 118 10 10 10 10
45112 - 90 90 90 238 238 238 253 253 253 253 253 253
45113 -253 253 253 253 253 253 253 253 253 253 253 253
45114 -253 253 253 253 253 253 231 231 231 250 250 250
45115 -253 253 253 253 253 253 253 253 253 253 253 253
45116 -253 253 253 253 253 253 253 253 253 253 253 253
45117 -253 253 253 253 253 253 253 253 253 253 253 253
45118 -253 253 253 253 253 253 253 253 253 246 230 190
45119 -238 204 91 238 204 91 181 142 44 37 26 9
45120 - 2 2 6 2 2 6 2 2 6 2 2 6
45121 - 2 2 6 2 2 6 38 38 38 46 46 46
45122 - 26 26 26 106 106 106 54 54 54 18 18 18
45123 - 6 6 6 0 0 0 0 0 0 0 0 0
45124 - 0 0 0 0 0 0 0 0 0 0 0 0
45125 - 0 0 0 0 0 0 0 0 0 0 0 0
45126 - 0 0 0 0 0 0 0 0 0 0 0 0
45127 - 0 0 0 0 0 0 0 0 0 0 0 0
45128 - 0 0 0 6 6 6 14 14 14 22 22 22
45129 - 30 30 30 38 38 38 50 50 50 70 70 70
45130 -106 106 106 190 142 34 226 170 11 242 186 14
45131 -246 190 14 246 190 14 246 190 14 154 114 10
45132 - 6 6 6 74 74 74 226 226 226 253 253 253
45133 -253 253 253 253 253 253 253 253 253 253 253 253
45134 -253 253 253 253 253 253 231 231 231 250 250 250
45135 -253 253 253 253 253 253 253 253 253 253 253 253
45136 -253 253 253 253 253 253 253 253 253 253 253 253
45137 -253 253 253 253 253 253 253 253 253 253 253 253
45138 -253 253 253 253 253 253 253 253 253 228 184 62
45139 -241 196 14 241 208 19 232 195 16 38 30 10
45140 - 2 2 6 2 2 6 2 2 6 2 2 6
45141 - 2 2 6 6 6 6 30 30 30 26 26 26
45142 -203 166 17 154 142 90 66 66 66 26 26 26
45143 - 6 6 6 0 0 0 0 0 0 0 0 0
45144 - 0 0 0 0 0 0 0 0 0 0 0 0
45145 - 0 0 0 0 0 0 0 0 0 0 0 0
45146 - 0 0 0 0 0 0 0 0 0 0 0 0
45147 - 0 0 0 0 0 0 0 0 0 0 0 0
45148 - 6 6 6 18 18 18 38 38 38 58 58 58
45149 - 78 78 78 86 86 86 101 101 101 123 123 123
45150 -175 146 61 210 150 10 234 174 13 246 186 14
45151 -246 190 14 246 190 14 246 190 14 238 190 10
45152 -102 78 10 2 2 6 46 46 46 198 198 198
45153 -253 253 253 253 253 253 253 253 253 253 253 253
45154 -253 253 253 253 253 253 234 234 234 242 242 242
45155 -253 253 253 253 253 253 253 253 253 253 253 253
45156 -253 253 253 253 253 253 253 253 253 253 253 253
45157 -253 253 253 253 253 253 253 253 253 253 253 253
45158 -253 253 253 253 253 253 253 253 253 224 178 62
45159 -242 186 14 241 196 14 210 166 10 22 18 6
45160 - 2 2 6 2 2 6 2 2 6 2 2 6
45161 - 2 2 6 2 2 6 6 6 6 121 92 8
45162 -238 202 15 232 195 16 82 82 82 34 34 34
45163 - 10 10 10 0 0 0 0 0 0 0 0 0
45164 - 0 0 0 0 0 0 0 0 0 0 0 0
45165 - 0 0 0 0 0 0 0 0 0 0 0 0
45166 - 0 0 0 0 0 0 0 0 0 0 0 0
45167 - 0 0 0 0 0 0 0 0 0 0 0 0
45168 - 14 14 14 38 38 38 70 70 70 154 122 46
45169 -190 142 34 200 144 11 197 138 11 197 138 11
45170 -213 154 11 226 170 11 242 186 14 246 190 14
45171 -246 190 14 246 190 14 246 190 14 246 190 14
45172 -225 175 15 46 32 6 2 2 6 22 22 22
45173 -158 158 158 250 250 250 253 253 253 253 253 253
45174 -253 253 253 253 253 253 253 253 253 253 253 253
45175 -253 253 253 253 253 253 253 253 253 253 253 253
45176 -253 253 253 253 253 253 253 253 253 253 253 253
45177 -253 253 253 253 253 253 253 253 253 253 253 253
45178 -253 253 253 250 250 250 242 242 242 224 178 62
45179 -239 182 13 236 186 11 213 154 11 46 32 6
45180 - 2 2 6 2 2 6 2 2 6 2 2 6
45181 - 2 2 6 2 2 6 61 42 6 225 175 15
45182 -238 190 10 236 186 11 112 100 78 42 42 42
45183 - 14 14 14 0 0 0 0 0 0 0 0 0
45184 - 0 0 0 0 0 0 0 0 0 0 0 0
45185 - 0 0 0 0 0 0 0 0 0 0 0 0
45186 - 0 0 0 0 0 0 0 0 0 0 0 0
45187 - 0 0 0 0 0 0 0 0 0 6 6 6
45188 - 22 22 22 54 54 54 154 122 46 213 154 11
45189 -226 170 11 230 174 11 226 170 11 226 170 11
45190 -236 178 12 242 186 14 246 190 14 246 190 14
45191 -246 190 14 246 190 14 246 190 14 246 190 14
45192 -241 196 14 184 144 12 10 10 10 2 2 6
45193 - 6 6 6 116 116 116 242 242 242 253 253 253
45194 -253 253 253 253 253 253 253 253 253 253 253 253
45195 -253 253 253 253 253 253 253 253 253 253 253 253
45196 -253 253 253 253 253 253 253 253 253 253 253 253
45197 -253 253 253 253 253 253 253 253 253 253 253 253
45198 -253 253 253 231 231 231 198 198 198 214 170 54
45199 -236 178 12 236 178 12 210 150 10 137 92 6
45200 - 18 14 6 2 2 6 2 2 6 2 2 6
45201 - 6 6 6 70 47 6 200 144 11 236 178 12
45202 -239 182 13 239 182 13 124 112 88 58 58 58
45203 - 22 22 22 6 6 6 0 0 0 0 0 0
45204 - 0 0 0 0 0 0 0 0 0 0 0 0
45205 - 0 0 0 0 0 0 0 0 0 0 0 0
45206 - 0 0 0 0 0 0 0 0 0 0 0 0
45207 - 0 0 0 0 0 0 0 0 0 10 10 10
45208 - 30 30 30 70 70 70 180 133 36 226 170 11
45209 -239 182 13 242 186 14 242 186 14 246 186 14
45210 -246 190 14 246 190 14 246 190 14 246 190 14
45211 -246 190 14 246 190 14 246 190 14 246 190 14
45212 -246 190 14 232 195 16 98 70 6 2 2 6
45213 - 2 2 6 2 2 6 66 66 66 221 221 221
45214 -253 253 253 253 253 253 253 253 253 253 253 253
45215 -253 253 253 253 253 253 253 253 253 253 253 253
45216 -253 253 253 253 253 253 253 253 253 253 253 253
45217 -253 253 253 253 253 253 253 253 253 253 253 253
45218 -253 253 253 206 206 206 198 198 198 214 166 58
45219 -230 174 11 230 174 11 216 158 10 192 133 9
45220 -163 110 8 116 81 8 102 78 10 116 81 8
45221 -167 114 7 197 138 11 226 170 11 239 182 13
45222 -242 186 14 242 186 14 162 146 94 78 78 78
45223 - 34 34 34 14 14 14 6 6 6 0 0 0
45224 - 0 0 0 0 0 0 0 0 0 0 0 0
45225 - 0 0 0 0 0 0 0 0 0 0 0 0
45226 - 0 0 0 0 0 0 0 0 0 0 0 0
45227 - 0 0 0 0 0 0 0 0 0 6 6 6
45228 - 30 30 30 78 78 78 190 142 34 226 170 11
45229 -239 182 13 246 190 14 246 190 14 246 190 14
45230 -246 190 14 246 190 14 246 190 14 246 190 14
45231 -246 190 14 246 190 14 246 190 14 246 190 14
45232 -246 190 14 241 196 14 203 166 17 22 18 6
45233 - 2 2 6 2 2 6 2 2 6 38 38 38
45234 -218 218 218 253 253 253 253 253 253 253 253 253
45235 -253 253 253 253 253 253 253 253 253 253 253 253
45236 -253 253 253 253 253 253 253 253 253 253 253 253
45237 -253 253 253 253 253 253 253 253 253 253 253 253
45238 -250 250 250 206 206 206 198 198 198 202 162 69
45239 -226 170 11 236 178 12 224 166 10 210 150 10
45240 -200 144 11 197 138 11 192 133 9 197 138 11
45241 -210 150 10 226 170 11 242 186 14 246 190 14
45242 -246 190 14 246 186 14 225 175 15 124 112 88
45243 - 62 62 62 30 30 30 14 14 14 6 6 6
45244 - 0 0 0 0 0 0 0 0 0 0 0 0
45245 - 0 0 0 0 0 0 0 0 0 0 0 0
45246 - 0 0 0 0 0 0 0 0 0 0 0 0
45247 - 0 0 0 0 0 0 0 0 0 10 10 10
45248 - 30 30 30 78 78 78 174 135 50 224 166 10
45249 -239 182 13 246 190 14 246 190 14 246 190 14
45250 -246 190 14 246 190 14 246 190 14 246 190 14
45251 -246 190 14 246 190 14 246 190 14 246 190 14
45252 -246 190 14 246 190 14 241 196 14 139 102 15
45253 - 2 2 6 2 2 6 2 2 6 2 2 6
45254 - 78 78 78 250 250 250 253 253 253 253 253 253
45255 -253 253 253 253 253 253 253 253 253 253 253 253
45256 -253 253 253 253 253 253 253 253 253 253 253 253
45257 -253 253 253 253 253 253 253 253 253 253 253 253
45258 -250 250 250 214 214 214 198 198 198 190 150 46
45259 -219 162 10 236 178 12 234 174 13 224 166 10
45260 -216 158 10 213 154 11 213 154 11 216 158 10
45261 -226 170 11 239 182 13 246 190 14 246 190 14
45262 -246 190 14 246 190 14 242 186 14 206 162 42
45263 -101 101 101 58 58 58 30 30 30 14 14 14
45264 - 6 6 6 0 0 0 0 0 0 0 0 0
45265 - 0 0 0 0 0 0 0 0 0 0 0 0
45266 - 0 0 0 0 0 0 0 0 0 0 0 0
45267 - 0 0 0 0 0 0 0 0 0 10 10 10
45268 - 30 30 30 74 74 74 174 135 50 216 158 10
45269 -236 178 12 246 190 14 246 190 14 246 190 14
45270 -246 190 14 246 190 14 246 190 14 246 190 14
45271 -246 190 14 246 190 14 246 190 14 246 190 14
45272 -246 190 14 246 190 14 241 196 14 226 184 13
45273 - 61 42 6 2 2 6 2 2 6 2 2 6
45274 - 22 22 22 238 238 238 253 253 253 253 253 253
45275 -253 253 253 253 253 253 253 253 253 253 253 253
45276 -253 253 253 253 253 253 253 253 253 253 253 253
45277 -253 253 253 253 253 253 253 253 253 253 253 253
45278 -253 253 253 226 226 226 187 187 187 180 133 36
45279 -216 158 10 236 178 12 239 182 13 236 178 12
45280 -230 174 11 226 170 11 226 170 11 230 174 11
45281 -236 178 12 242 186 14 246 190 14 246 190 14
45282 -246 190 14 246 190 14 246 186 14 239 182 13
45283 -206 162 42 106 106 106 66 66 66 34 34 34
45284 - 14 14 14 6 6 6 0 0 0 0 0 0
45285 - 0 0 0 0 0 0 0 0 0 0 0 0
45286 - 0 0 0 0 0 0 0 0 0 0 0 0
45287 - 0 0 0 0 0 0 0 0 0 6 6 6
45288 - 26 26 26 70 70 70 163 133 67 213 154 11
45289 -236 178 12 246 190 14 246 190 14 246 190 14
45290 -246 190 14 246 190 14 246 190 14 246 190 14
45291 -246 190 14 246 190 14 246 190 14 246 190 14
45292 -246 190 14 246 190 14 246 190 14 241 196 14
45293 -190 146 13 18 14 6 2 2 6 2 2 6
45294 - 46 46 46 246 246 246 253 253 253 253 253 253
45295 -253 253 253 253 253 253 253 253 253 253 253 253
45296 -253 253 253 253 253 253 253 253 253 253 253 253
45297 -253 253 253 253 253 253 253 253 253 253 253 253
45298 -253 253 253 221 221 221 86 86 86 156 107 11
45299 -216 158 10 236 178 12 242 186 14 246 186 14
45300 -242 186 14 239 182 13 239 182 13 242 186 14
45301 -242 186 14 246 186 14 246 190 14 246 190 14
45302 -246 190 14 246 190 14 246 190 14 246 190 14
45303 -242 186 14 225 175 15 142 122 72 66 66 66
45304 - 30 30 30 10 10 10 0 0 0 0 0 0
45305 - 0 0 0 0 0 0 0 0 0 0 0 0
45306 - 0 0 0 0 0 0 0 0 0 0 0 0
45307 - 0 0 0 0 0 0 0 0 0 6 6 6
45308 - 26 26 26 70 70 70 163 133 67 210 150 10
45309 -236 178 12 246 190 14 246 190 14 246 190 14
45310 -246 190 14 246 190 14 246 190 14 246 190 14
45311 -246 190 14 246 190 14 246 190 14 246 190 14
45312 -246 190 14 246 190 14 246 190 14 246 190 14
45313 -232 195 16 121 92 8 34 34 34 106 106 106
45314 -221 221 221 253 253 253 253 253 253 253 253 253
45315 -253 253 253 253 253 253 253 253 253 253 253 253
45316 -253 253 253 253 253 253 253 253 253 253 253 253
45317 -253 253 253 253 253 253 253 253 253 253 253 253
45318 -242 242 242 82 82 82 18 14 6 163 110 8
45319 -216 158 10 236 178 12 242 186 14 246 190 14
45320 -246 190 14 246 190 14 246 190 14 246 190 14
45321 -246 190 14 246 190 14 246 190 14 246 190 14
45322 -246 190 14 246 190 14 246 190 14 246 190 14
45323 -246 190 14 246 190 14 242 186 14 163 133 67
45324 - 46 46 46 18 18 18 6 6 6 0 0 0
45325 - 0 0 0 0 0 0 0 0 0 0 0 0
45326 - 0 0 0 0 0 0 0 0 0 0 0 0
45327 - 0 0 0 0 0 0 0 0 0 10 10 10
45328 - 30 30 30 78 78 78 163 133 67 210 150 10
45329 -236 178 12 246 186 14 246 190 14 246 190 14
45330 -246 190 14 246 190 14 246 190 14 246 190 14
45331 -246 190 14 246 190 14 246 190 14 246 190 14
45332 -246 190 14 246 190 14 246 190 14 246 190 14
45333 -241 196 14 215 174 15 190 178 144 253 253 253
45334 -253 253 253 253 253 253 253 253 253 253 253 253
45335 -253 253 253 253 253 253 253 253 253 253 253 253
45336 -253 253 253 253 253 253 253 253 253 253 253 253
45337 -253 253 253 253 253 253 253 253 253 218 218 218
45338 - 58 58 58 2 2 6 22 18 6 167 114 7
45339 -216 158 10 236 178 12 246 186 14 246 190 14
45340 -246 190 14 246 190 14 246 190 14 246 190 14
45341 -246 190 14 246 190 14 246 190 14 246 190 14
45342 -246 190 14 246 190 14 246 190 14 246 190 14
45343 -246 190 14 246 186 14 242 186 14 190 150 46
45344 - 54 54 54 22 22 22 6 6 6 0 0 0
45345 - 0 0 0 0 0 0 0 0 0 0 0 0
45346 - 0 0 0 0 0 0 0 0 0 0 0 0
45347 - 0 0 0 0 0 0 0 0 0 14 14 14
45348 - 38 38 38 86 86 86 180 133 36 213 154 11
45349 -236 178 12 246 186 14 246 190 14 246 190 14
45350 -246 190 14 246 190 14 246 190 14 246 190 14
45351 -246 190 14 246 190 14 246 190 14 246 190 14
45352 -246 190 14 246 190 14 246 190 14 246 190 14
45353 -246 190 14 232 195 16 190 146 13 214 214 214
45354 -253 253 253 253 253 253 253 253 253 253 253 253
45355 -253 253 253 253 253 253 253 253 253 253 253 253
45356 -253 253 253 253 253 253 253 253 253 253 253 253
45357 -253 253 253 250 250 250 170 170 170 26 26 26
45358 - 2 2 6 2 2 6 37 26 9 163 110 8
45359 -219 162 10 239 182 13 246 186 14 246 190 14
45360 -246 190 14 246 190 14 246 190 14 246 190 14
45361 -246 190 14 246 190 14 246 190 14 246 190 14
45362 -246 190 14 246 190 14 246 190 14 246 190 14
45363 -246 186 14 236 178 12 224 166 10 142 122 72
45364 - 46 46 46 18 18 18 6 6 6 0 0 0
45365 - 0 0 0 0 0 0 0 0 0 0 0 0
45366 - 0 0 0 0 0 0 0 0 0 0 0 0
45367 - 0 0 0 0 0 0 6 6 6 18 18 18
45368 - 50 50 50 109 106 95 192 133 9 224 166 10
45369 -242 186 14 246 190 14 246 190 14 246 190 14
45370 -246 190 14 246 190 14 246 190 14 246 190 14
45371 -246 190 14 246 190 14 246 190 14 246 190 14
45372 -246 190 14 246 190 14 246 190 14 246 190 14
45373 -242 186 14 226 184 13 210 162 10 142 110 46
45374 -226 226 226 253 253 253 253 253 253 253 253 253
45375 -253 253 253 253 253 253 253 253 253 253 253 253
45376 -253 253 253 253 253 253 253 253 253 253 253 253
45377 -198 198 198 66 66 66 2 2 6 2 2 6
45378 - 2 2 6 2 2 6 50 34 6 156 107 11
45379 -219 162 10 239 182 13 246 186 14 246 190 14
45380 -246 190 14 246 190 14 246 190 14 246 190 14
45381 -246 190 14 246 190 14 246 190 14 246 190 14
45382 -246 190 14 246 190 14 246 190 14 242 186 14
45383 -234 174 13 213 154 11 154 122 46 66 66 66
45384 - 30 30 30 10 10 10 0 0 0 0 0 0
45385 - 0 0 0 0 0 0 0 0 0 0 0 0
45386 - 0 0 0 0 0 0 0 0 0 0 0 0
45387 - 0 0 0 0 0 0 6 6 6 22 22 22
45388 - 58 58 58 154 121 60 206 145 10 234 174 13
45389 -242 186 14 246 186 14 246 190 14 246 190 14
45390 -246 190 14 246 190 14 246 190 14 246 190 14
45391 -246 190 14 246 190 14 246 190 14 246 190 14
45392 -246 190 14 246 190 14 246 190 14 246 190 14
45393 -246 186 14 236 178 12 210 162 10 163 110 8
45394 - 61 42 6 138 138 138 218 218 218 250 250 250
45395 -253 253 253 253 253 253 253 253 253 250 250 250
45396 -242 242 242 210 210 210 144 144 144 66 66 66
45397 - 6 6 6 2 2 6 2 2 6 2 2 6
45398 - 2 2 6 2 2 6 61 42 6 163 110 8
45399 -216 158 10 236 178 12 246 190 14 246 190 14
45400 -246 190 14 246 190 14 246 190 14 246 190 14
45401 -246 190 14 246 190 14 246 190 14 246 190 14
45402 -246 190 14 239 182 13 230 174 11 216 158 10
45403 -190 142 34 124 112 88 70 70 70 38 38 38
45404 - 18 18 18 6 6 6 0 0 0 0 0 0
45405 - 0 0 0 0 0 0 0 0 0 0 0 0
45406 - 0 0 0 0 0 0 0 0 0 0 0 0
45407 - 0 0 0 0 0 0 6 6 6 22 22 22
45408 - 62 62 62 168 124 44 206 145 10 224 166 10
45409 -236 178 12 239 182 13 242 186 14 242 186 14
45410 -246 186 14 246 190 14 246 190 14 246 190 14
45411 -246 190 14 246 190 14 246 190 14 246 190 14
45412 -246 190 14 246 190 14 246 190 14 246 190 14
45413 -246 190 14 236 178 12 216 158 10 175 118 6
45414 - 80 54 7 2 2 6 6 6 6 30 30 30
45415 - 54 54 54 62 62 62 50 50 50 38 38 38
45416 - 14 14 14 2 2 6 2 2 6 2 2 6
45417 - 2 2 6 2 2 6 2 2 6 2 2 6
45418 - 2 2 6 6 6 6 80 54 7 167 114 7
45419 -213 154 11 236 178 12 246 190 14 246 190 14
45420 -246 190 14 246 190 14 246 190 14 246 190 14
45421 -246 190 14 242 186 14 239 182 13 239 182 13
45422 -230 174 11 210 150 10 174 135 50 124 112 88
45423 - 82 82 82 54 54 54 34 34 34 18 18 18
45424 - 6 6 6 0 0 0 0 0 0 0 0 0
45425 - 0 0 0 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 6 6 6 18 18 18
45428 - 50 50 50 158 118 36 192 133 9 200 144 11
45429 -216 158 10 219 162 10 224 166 10 226 170 11
45430 -230 174 11 236 178 12 239 182 13 239 182 13
45431 -242 186 14 246 186 14 246 190 14 246 190 14
45432 -246 190 14 246 190 14 246 190 14 246 190 14
45433 -246 186 14 230 174 11 210 150 10 163 110 8
45434 -104 69 6 10 10 10 2 2 6 2 2 6
45435 - 2 2 6 2 2 6 2 2 6 2 2 6
45436 - 2 2 6 2 2 6 2 2 6 2 2 6
45437 - 2 2 6 2 2 6 2 2 6 2 2 6
45438 - 2 2 6 6 6 6 91 60 6 167 114 7
45439 -206 145 10 230 174 11 242 186 14 246 190 14
45440 -246 190 14 246 190 14 246 186 14 242 186 14
45441 -239 182 13 230 174 11 224 166 10 213 154 11
45442 -180 133 36 124 112 88 86 86 86 58 58 58
45443 - 38 38 38 22 22 22 10 10 10 6 6 6
45444 - 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
45448 - 34 34 34 70 70 70 138 110 50 158 118 36
45449 -167 114 7 180 123 7 192 133 9 197 138 11
45450 -200 144 11 206 145 10 213 154 11 219 162 10
45451 -224 166 10 230 174 11 239 182 13 242 186 14
45452 -246 186 14 246 186 14 246 186 14 246 186 14
45453 -239 182 13 216 158 10 185 133 11 152 99 6
45454 -104 69 6 18 14 6 2 2 6 2 2 6
45455 - 2 2 6 2 2 6 2 2 6 2 2 6
45456 - 2 2 6 2 2 6 2 2 6 2 2 6
45457 - 2 2 6 2 2 6 2 2 6 2 2 6
45458 - 2 2 6 6 6 6 80 54 7 152 99 6
45459 -192 133 9 219 162 10 236 178 12 239 182 13
45460 -246 186 14 242 186 14 239 182 13 236 178 12
45461 -224 166 10 206 145 10 192 133 9 154 121 60
45462 - 94 94 94 62 62 62 42 42 42 22 22 22
45463 - 14 14 14 6 6 6 0 0 0 0 0 0
45464 - 0 0 0 0 0 0 0 0 0 0 0 0
45465 - 0 0 0 0 0 0 0 0 0 0 0 0
45466 - 0 0 0 0 0 0 0 0 0 0 0 0
45467 - 0 0 0 0 0 0 0 0 0 6 6 6
45468 - 18 18 18 34 34 34 58 58 58 78 78 78
45469 -101 98 89 124 112 88 142 110 46 156 107 11
45470 -163 110 8 167 114 7 175 118 6 180 123 7
45471 -185 133 11 197 138 11 210 150 10 219 162 10
45472 -226 170 11 236 178 12 236 178 12 234 174 13
45473 -219 162 10 197 138 11 163 110 8 130 83 6
45474 - 91 60 6 10 10 10 2 2 6 2 2 6
45475 - 18 18 18 38 38 38 38 38 38 38 38 38
45476 - 38 38 38 38 38 38 38 38 38 38 38 38
45477 - 38 38 38 38 38 38 26 26 26 2 2 6
45478 - 2 2 6 6 6 6 70 47 6 137 92 6
45479 -175 118 6 200 144 11 219 162 10 230 174 11
45480 -234 174 13 230 174 11 219 162 10 210 150 10
45481 -192 133 9 163 110 8 124 112 88 82 82 82
45482 - 50 50 50 30 30 30 14 14 14 6 6 6
45483 - 0 0 0 0 0 0 0 0 0 0 0 0
45484 - 0 0 0 0 0 0 0 0 0 0 0 0
45485 - 0 0 0 0 0 0 0 0 0 0 0 0
45486 - 0 0 0 0 0 0 0 0 0 0 0 0
45487 - 0 0 0 0 0 0 0 0 0 0 0 0
45488 - 6 6 6 14 14 14 22 22 22 34 34 34
45489 - 42 42 42 58 58 58 74 74 74 86 86 86
45490 -101 98 89 122 102 70 130 98 46 121 87 25
45491 -137 92 6 152 99 6 163 110 8 180 123 7
45492 -185 133 11 197 138 11 206 145 10 200 144 11
45493 -180 123 7 156 107 11 130 83 6 104 69 6
45494 - 50 34 6 54 54 54 110 110 110 101 98 89
45495 - 86 86 86 82 82 82 78 78 78 78 78 78
45496 - 78 78 78 78 78 78 78 78 78 78 78 78
45497 - 78 78 78 82 82 82 86 86 86 94 94 94
45498 -106 106 106 101 101 101 86 66 34 124 80 6
45499 -156 107 11 180 123 7 192 133 9 200 144 11
45500 -206 145 10 200 144 11 192 133 9 175 118 6
45501 -139 102 15 109 106 95 70 70 70 42 42 42
45502 - 22 22 22 10 10 10 0 0 0 0 0 0
45503 - 0 0 0 0 0 0 0 0 0 0 0 0
45504 - 0 0 0 0 0 0 0 0 0 0 0 0
45505 - 0 0 0 0 0 0 0 0 0 0 0 0
45506 - 0 0 0 0 0 0 0 0 0 0 0 0
45507 - 0 0 0 0 0 0 0 0 0 0 0 0
45508 - 0 0 0 0 0 0 6 6 6 10 10 10
45509 - 14 14 14 22 22 22 30 30 30 38 38 38
45510 - 50 50 50 62 62 62 74 74 74 90 90 90
45511 -101 98 89 112 100 78 121 87 25 124 80 6
45512 -137 92 6 152 99 6 152 99 6 152 99 6
45513 -138 86 6 124 80 6 98 70 6 86 66 30
45514 -101 98 89 82 82 82 58 58 58 46 46 46
45515 - 38 38 38 34 34 34 34 34 34 34 34 34
45516 - 34 34 34 34 34 34 34 34 34 34 34 34
45517 - 34 34 34 34 34 34 38 38 38 42 42 42
45518 - 54 54 54 82 82 82 94 86 76 91 60 6
45519 -134 86 6 156 107 11 167 114 7 175 118 6
45520 -175 118 6 167 114 7 152 99 6 121 87 25
45521 -101 98 89 62 62 62 34 34 34 18 18 18
45522 - 6 6 6 0 0 0 0 0 0 0 0 0
45523 - 0 0 0 0 0 0 0 0 0 0 0 0
45524 - 0 0 0 0 0 0 0 0 0 0 0 0
45525 - 0 0 0 0 0 0 0 0 0 0 0 0
45526 - 0 0 0 0 0 0 0 0 0 0 0 0
45527 - 0 0 0 0 0 0 0 0 0 0 0 0
45528 - 0 0 0 0 0 0 0 0 0 0 0 0
45529 - 0 0 0 6 6 6 6 6 6 10 10 10
45530 - 18 18 18 22 22 22 30 30 30 42 42 42
45531 - 50 50 50 66 66 66 86 86 86 101 98 89
45532 -106 86 58 98 70 6 104 69 6 104 69 6
45533 -104 69 6 91 60 6 82 62 34 90 90 90
45534 - 62 62 62 38 38 38 22 22 22 14 14 14
45535 - 10 10 10 10 10 10 10 10 10 10 10 10
45536 - 10 10 10 10 10 10 6 6 6 10 10 10
45537 - 10 10 10 10 10 10 10 10 10 14 14 14
45538 - 22 22 22 42 42 42 70 70 70 89 81 66
45539 - 80 54 7 104 69 6 124 80 6 137 92 6
45540 -134 86 6 116 81 8 100 82 52 86 86 86
45541 - 58 58 58 30 30 30 14 14 14 6 6 6
45542 - 0 0 0 0 0 0 0 0 0 0 0 0
45543 - 0 0 0 0 0 0 0 0 0 0 0 0
45544 - 0 0 0 0 0 0 0 0 0 0 0 0
45545 - 0 0 0 0 0 0 0 0 0 0 0 0
45546 - 0 0 0 0 0 0 0 0 0 0 0 0
45547 - 0 0 0 0 0 0 0 0 0 0 0 0
45548 - 0 0 0 0 0 0 0 0 0 0 0 0
45549 - 0 0 0 0 0 0 0 0 0 0 0 0
45550 - 0 0 0 6 6 6 10 10 10 14 14 14
45551 - 18 18 18 26 26 26 38 38 38 54 54 54
45552 - 70 70 70 86 86 86 94 86 76 89 81 66
45553 - 89 81 66 86 86 86 74 74 74 50 50 50
45554 - 30 30 30 14 14 14 6 6 6 0 0 0
45555 - 0 0 0 0 0 0 0 0 0 0 0 0
45556 - 0 0 0 0 0 0 0 0 0 0 0 0
45557 - 0 0 0 0 0 0 0 0 0 0 0 0
45558 - 6 6 6 18 18 18 34 34 34 58 58 58
45559 - 82 82 82 89 81 66 89 81 66 89 81 66
45560 - 94 86 66 94 86 76 74 74 74 50 50 50
45561 - 26 26 26 14 14 14 6 6 6 0 0 0
45562 - 0 0 0 0 0 0 0 0 0 0 0 0
45563 - 0 0 0 0 0 0 0 0 0 0 0 0
45564 - 0 0 0 0 0 0 0 0 0 0 0 0
45565 - 0 0 0 0 0 0 0 0 0 0 0 0
45566 - 0 0 0 0 0 0 0 0 0 0 0 0
45567 - 0 0 0 0 0 0 0 0 0 0 0 0
45568 - 0 0 0 0 0 0 0 0 0 0 0 0
45569 - 0 0 0 0 0 0 0 0 0 0 0 0
45570 - 0 0 0 0 0 0 0 0 0 0 0 0
45571 - 6 6 6 6 6 6 14 14 14 18 18 18
45572 - 30 30 30 38 38 38 46 46 46 54 54 54
45573 - 50 50 50 42 42 42 30 30 30 18 18 18
45574 - 10 10 10 0 0 0 0 0 0 0 0 0
45575 - 0 0 0 0 0 0 0 0 0 0 0 0
45576 - 0 0 0 0 0 0 0 0 0 0 0 0
45577 - 0 0 0 0 0 0 0 0 0 0 0 0
45578 - 0 0 0 6 6 6 14 14 14 26 26 26
45579 - 38 38 38 50 50 50 58 58 58 58 58 58
45580 - 54 54 54 42 42 42 30 30 30 18 18 18
45581 - 10 10 10 0 0 0 0 0 0 0 0 0
45582 - 0 0 0 0 0 0 0 0 0 0 0 0
45583 - 0 0 0 0 0 0 0 0 0 0 0 0
45584 - 0 0 0 0 0 0 0 0 0 0 0 0
45585 - 0 0 0 0 0 0 0 0 0 0 0 0
45586 - 0 0 0 0 0 0 0 0 0 0 0 0
45587 - 0 0 0 0 0 0 0 0 0 0 0 0
45588 - 0 0 0 0 0 0 0 0 0 0 0 0
45589 - 0 0 0 0 0 0 0 0 0 0 0 0
45590 - 0 0 0 0 0 0 0 0 0 0 0 0
45591 - 0 0 0 0 0 0 0 0 0 6 6 6
45592 - 6 6 6 10 10 10 14 14 14 18 18 18
45593 - 18 18 18 14 14 14 10 10 10 6 6 6
45594 - 0 0 0 0 0 0 0 0 0 0 0 0
45595 - 0 0 0 0 0 0 0 0 0 0 0 0
45596 - 0 0 0 0 0 0 0 0 0 0 0 0
45597 - 0 0 0 0 0 0 0 0 0 0 0 0
45598 - 0 0 0 0 0 0 0 0 0 6 6 6
45599 - 14 14 14 18 18 18 22 22 22 22 22 22
45600 - 18 18 18 14 14 14 10 10 10 6 6 6
45601 - 0 0 0 0 0 0 0 0 0 0 0 0
45602 - 0 0 0 0 0 0 0 0 0 0 0 0
45603 - 0 0 0 0 0 0 0 0 0 0 0 0
45604 - 0 0 0 0 0 0 0 0 0 0 0 0
45605 - 0 0 0 0 0 0 0 0 0 0 0 0
45606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45619 +4 4 4 4 4 4
45620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45633 +4 4 4 4 4 4
45634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45645 +4 4 4 4 4 4 4 4 4 4 4 4 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
45648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45659 +4 4 4 4 4 4 4 4 4 4 4 4 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
45662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45673 +4 4 4 4 4 4 4 4 4 4 4 4 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
45676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45687 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
45690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45694 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
45695 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
45696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45699 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
45700 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
45701 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
45702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45703 +4 4 4 4 4 4
45704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45708 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
45709 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
45710 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45713 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
45714 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
45715 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
45716 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45717 +4 4 4 4 4 4
45718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45722 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
45723 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
45724 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
45725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45727 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
45728 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
45729 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
45730 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
45731 +4 4 4 4 4 4
45732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45735 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
45736 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
45737 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
45738 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
45739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45740 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
45741 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
45742 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
45743 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
45744 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
45745 +4 4 4 4 4 4
45746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45749 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
45750 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
45751 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
45752 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
45753 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45754 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
45755 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
45756 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
45757 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
45758 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
45759 +4 4 4 4 4 4
45760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45763 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
45764 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
45765 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
45766 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
45767 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
45768 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
45769 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
45770 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
45771 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
45772 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
45773 +4 4 4 4 4 4
45774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45776 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
45777 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
45778 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
45779 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
45780 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
45781 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
45782 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
45783 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
45784 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
45785 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
45786 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
45787 +4 4 4 4 4 4
45788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45790 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
45791 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
45792 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
45793 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
45794 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
45795 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
45796 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
45797 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
45798 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
45799 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
45800 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
45801 +4 4 4 4 4 4
45802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45803 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45804 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
45805 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
45806 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
45807 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
45808 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
45809 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
45810 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
45811 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
45812 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
45813 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
45814 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
45815 +4 4 4 4 4 4
45816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45817 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45818 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
45819 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
45820 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
45821 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
45822 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
45823 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
45824 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
45825 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
45826 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
45827 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
45828 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
45829 +4 4 4 4 4 4
45830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45831 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
45832 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
45833 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
45834 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
45835 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
45836 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
45837 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
45838 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
45839 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
45840 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
45841 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
45842 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
45843 +4 4 4 4 4 4
45844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45845 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
45846 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
45847 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
45848 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
45849 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
45850 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
45851 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
45852 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
45853 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
45854 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
45855 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
45856 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
45857 +0 0 0 4 4 4
45858 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
45859 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
45860 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
45861 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
45862 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
45863 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
45864 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
45865 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
45866 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
45867 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
45868 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
45869 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
45870 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
45871 +2 0 0 0 0 0
45872 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
45873 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
45874 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
45875 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
45876 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
45877 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
45878 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
45879 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
45880 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
45881 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
45882 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
45883 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
45884 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
45885 +37 38 37 0 0 0
45886 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
45887 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
45888 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
45889 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
45890 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
45891 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
45892 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
45893 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
45894 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
45895 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
45896 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
45897 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
45898 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
45899 +85 115 134 4 0 0
45900 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
45901 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
45902 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
45903 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
45904 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
45905 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
45906 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
45907 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
45908 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
45909 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
45910 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
45911 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
45912 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
45913 +60 73 81 4 0 0
45914 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
45915 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
45916 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
45917 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
45918 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
45919 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
45920 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
45921 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
45922 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
45923 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
45924 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
45925 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
45926 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
45927 +16 19 21 4 0 0
45928 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
45929 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
45930 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
45931 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
45932 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
45933 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
45934 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
45935 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
45936 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
45937 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
45938 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
45939 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
45940 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
45941 +4 0 0 4 3 3
45942 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
45943 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
45944 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
45945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
45946 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
45947 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
45948 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
45949 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
45950 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
45951 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
45952 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
45953 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
45954 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
45955 +3 2 2 4 4 4
45956 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
45957 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
45958 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
45959 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
45960 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
45961 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
45962 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
45963 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
45964 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
45965 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
45966 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
45967 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
45968 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
45969 +4 4 4 4 4 4
45970 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
45971 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
45972 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
45973 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
45974 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
45975 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
45976 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
45977 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
45978 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
45979 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
45980 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
45981 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
45982 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
45983 +4 4 4 4 4 4
45984 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
45985 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
45986 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
45987 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
45988 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
45989 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
45990 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
45991 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
45992 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
45993 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
45994 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
45995 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
45996 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
45997 +5 5 5 5 5 5
45998 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
45999 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
46000 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
46001 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
46002 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
46003 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46004 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
46005 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
46006 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
46007 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
46008 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
46009 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
46010 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46011 +5 5 5 4 4 4
46012 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
46013 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
46014 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
46015 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
46016 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46017 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
46018 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
46019 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
46020 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
46021 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
46022 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
46023 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46025 +4 4 4 4 4 4
46026 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
46027 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
46028 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
46029 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
46030 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
46031 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46032 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46033 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
46034 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
46035 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
46036 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
46037 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
46038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46039 +4 4 4 4 4 4
46040 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
46041 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
46042 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
46043 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
46044 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46045 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
46046 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
46047 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
46048 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
46049 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
46050 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
46051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46053 +4 4 4 4 4 4
46054 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
46055 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
46056 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
46057 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
46058 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46059 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46060 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46061 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
46062 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
46063 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
46064 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
46065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46067 +4 4 4 4 4 4
46068 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
46069 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
46070 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
46071 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
46072 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46073 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
46074 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46075 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
46076 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
46077 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
46078 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46081 +4 4 4 4 4 4
46082 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
46083 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
46084 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
46085 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
46086 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46087 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
46088 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
46089 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
46090 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
46091 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
46092 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
46093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46095 +4 4 4 4 4 4
46096 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
46097 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
46098 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
46099 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
46100 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46101 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
46102 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
46103 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
46104 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
46105 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
46106 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
46107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46109 +4 4 4 4 4 4
46110 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
46111 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
46112 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
46113 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46114 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
46115 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
46116 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
46117 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
46118 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
46119 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
46120 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46123 +4 4 4 4 4 4
46124 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
46125 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
46126 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
46127 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46128 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46129 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
46130 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
46131 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
46132 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
46133 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
46134 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46137 +4 4 4 4 4 4
46138 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
46139 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
46140 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46141 +18 97 151 18 97 151 18 97 151 26 108 161 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 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
46144 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
46145 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
46146 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
46147 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
46148 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46151 +4 4 4 4 4 4
46152 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
46153 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
46154 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46155 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46156 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46157 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
46158 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
46159 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
46160 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46161 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46162 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46165 +4 4 4 4 4 4
46166 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46167 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
46168 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46169 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
46170 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
46171 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
46172 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
46173 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
46174 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46175 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46176 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46179 +4 4 4 4 4 4
46180 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46181 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
46182 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46183 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
46184 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46185 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
46186 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
46187 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
46188 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46189 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46190 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46193 +4 4 4 4 4 4
46194 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
46195 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
46196 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46197 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
46198 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
46199 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
46200 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
46201 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
46202 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46203 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46204 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46207 +4 4 4 4 4 4
46208 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
46209 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
46210 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46211 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
46212 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
46213 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
46214 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
46215 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
46216 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46217 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46218 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46221 +4 4 4 4 4 4
46222 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46223 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
46224 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46225 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
46226 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
46227 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
46228 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
46229 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
46230 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46231 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46232 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46235 +4 4 4 4 4 4
46236 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
46237 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
46238 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46239 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
46240 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
46241 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
46242 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
46243 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
46244 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
46245 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46246 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46249 +4 4 4 4 4 4
46250 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46251 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
46252 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
46253 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
46254 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
46255 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
46256 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
46257 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
46258 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46259 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46260 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46263 +4 4 4 4 4 4
46264 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46265 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
46266 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46267 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
46268 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
46269 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
46270 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
46271 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
46272 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46273 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46274 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46277 +4 4 4 4 4 4
46278 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46279 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
46280 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
46281 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
46282 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
46283 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
46284 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46285 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
46286 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46287 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46288 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46291 +4 4 4 4 4 4
46292 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46293 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
46294 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
46295 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46296 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
46297 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
46298 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46299 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
46300 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46301 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46302 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46305 +4 4 4 4 4 4
46306 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46307 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
46308 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
46309 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
46310 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
46311 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
46312 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
46313 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
46314 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
46315 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46316 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46319 +4 4 4 4 4 4
46320 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46321 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
46322 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
46323 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
46324 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
46325 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
46326 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
46327 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
46328 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
46329 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46330 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46333 +4 4 4 4 4 4
46334 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
46335 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
46336 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
46337 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
46338 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46339 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
46340 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
46341 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
46342 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
46343 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46344 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46347 +4 4 4 4 4 4
46348 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46349 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
46350 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
46351 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
46352 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
46353 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
46354 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
46355 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
46356 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
46357 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46358 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46361 +4 4 4 4 4 4
46362 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
46363 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
46364 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
46365 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
46366 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
46367 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
46368 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
46369 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
46370 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
46371 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
46372 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46375 +4 4 4 4 4 4
46376 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
46377 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46378 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
46379 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
46380 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
46381 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
46382 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
46383 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
46384 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
46385 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
46386 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46389 +4 4 4 4 4 4
46390 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
46391 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46392 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
46393 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
46394 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
46395 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
46396 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46397 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
46398 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
46399 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
46400 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46403 +4 4 4 4 4 4
46404 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
46405 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
46406 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
46407 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
46408 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
46409 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
46410 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
46411 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
46412 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
46413 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
46414 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46417 +4 4 4 4 4 4
46418 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
46419 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
46420 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46421 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
46422 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
46423 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
46424 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
46425 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
46426 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
46427 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
46430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46431 +4 4 4 4 4 4
46432 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46433 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
46434 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
46435 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
46436 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
46437 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
46438 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
46439 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
46440 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
46441 +13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
46444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46445 +4 4 4 4 4 4
46446 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
46447 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
46448 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
46449 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
46450 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
46451 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
46452 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
46453 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
46454 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
46455 +4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
46458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46459 +4 4 4 4 4 4
46460 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
46461 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
46462 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
46463 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
46464 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
46465 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
46466 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
46467 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
46468 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46469 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
46472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46473 +4 4 4 4 4 4
46474 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
46475 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46476 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
46477 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46478 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
46479 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
46480 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
46481 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
46482 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
46486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46487 +4 4 4 4 4 4
46488 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
46489 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
46490 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
46491 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
46492 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
46493 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
46494 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
46495 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
46496 +4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
46500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46501 +4 4 4 4 4 4
46502 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
46503 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
46504 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
46505 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
46506 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
46507 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
46508 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
46509 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
46510 +4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
46514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46515 +4 4 4 4 4 4
46516 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
46517 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
46518 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46519 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
46520 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
46521 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
46522 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
46523 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
46528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46529 +4 4 4 4 4 4
46530 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
46531 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
46532 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
46533 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
46534 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
46535 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
46536 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
46537 +6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
46542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46543 +4 4 4 4 4 4
46544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46545 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
46546 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46547 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
46548 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
46549 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
46550 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
46551 +4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
46556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46557 +4 4 4 4 4 4
46558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46559 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
46560 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
46561 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
46562 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
46563 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
46564 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
46565 +6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
46570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46571 +4 4 4 4 4 4
46572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46573 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46574 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
46575 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
46576 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
46577 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
46578 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
46579 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46580 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46585 +4 4 4 4 4 4
46586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46588 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
46589 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
46590 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
46591 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
46592 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
46593 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46599 +4 4 4 4 4 4
46600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46603 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46604 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
46605 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
46606 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
46607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46613 +4 4 4 4 4 4
46614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46617 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
46618 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46619 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
46620 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
46621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46627 +4 4 4 4 4 4
46628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46631 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
46632 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46633 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
46634 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
46635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46641 +4 4 4 4 4 4
46642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46645 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
46646 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
46647 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
46648 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
46649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46655 +4 4 4 4 4 4
46656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46660 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
46661 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46662 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46669 +4 4 4 4 4 4
46670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46674 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
46675 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
46676 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46683 +4 4 4 4 4 4
46684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46688 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
46689 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
46690 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46697 +4 4 4 4 4 4
46698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46702 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
46703 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
46704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46711 +4 4 4 4 4 4
46712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46716 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
46717 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
46718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46725 +4 4 4 4 4 4
46726 diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
46727 index fe92eed..106e085 100644
46728 --- a/drivers/video/mb862xx/mb862xxfb_accel.c
46729 +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
46730 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
46731 struct mb862xxfb_par *par = info->par;
46732
46733 if (info->var.bits_per_pixel == 32) {
46734 - info->fbops->fb_fillrect = cfb_fillrect;
46735 - info->fbops->fb_copyarea = cfb_copyarea;
46736 - info->fbops->fb_imageblit = cfb_imageblit;
46737 + pax_open_kernel();
46738 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
46739 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
46740 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
46741 + pax_close_kernel();
46742 } else {
46743 outreg(disp, GC_L0EM, 3);
46744 - info->fbops->fb_fillrect = mb86290fb_fillrect;
46745 - info->fbops->fb_copyarea = mb86290fb_copyarea;
46746 - info->fbops->fb_imageblit = mb86290fb_imageblit;
46747 + pax_open_kernel();
46748 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
46749 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
46750 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
46751 + pax_close_kernel();
46752 }
46753 outreg(draw, GDC_REG_DRAW_BASE, 0);
46754 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
46755 diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
46756 index ff22871..b129bed 100644
46757 --- a/drivers/video/nvidia/nvidia.c
46758 +++ b/drivers/video/nvidia/nvidia.c
46759 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
46760 info->fix.line_length = (info->var.xres_virtual *
46761 info->var.bits_per_pixel) >> 3;
46762 if (info->var.accel_flags) {
46763 - info->fbops->fb_imageblit = nvidiafb_imageblit;
46764 - info->fbops->fb_fillrect = nvidiafb_fillrect;
46765 - info->fbops->fb_copyarea = nvidiafb_copyarea;
46766 - info->fbops->fb_sync = nvidiafb_sync;
46767 + pax_open_kernel();
46768 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
46769 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
46770 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
46771 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
46772 + pax_close_kernel();
46773 info->pixmap.scan_align = 4;
46774 info->flags &= ~FBINFO_HWACCEL_DISABLED;
46775 info->flags |= FBINFO_READS_FAST;
46776 NVResetGraphics(info);
46777 } else {
46778 - info->fbops->fb_imageblit = cfb_imageblit;
46779 - info->fbops->fb_fillrect = cfb_fillrect;
46780 - info->fbops->fb_copyarea = cfb_copyarea;
46781 - info->fbops->fb_sync = NULL;
46782 + pax_open_kernel();
46783 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
46784 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
46785 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
46786 + *(void **)&info->fbops->fb_sync = NULL;
46787 + pax_close_kernel();
46788 info->pixmap.scan_align = 1;
46789 info->flags |= FBINFO_HWACCEL_DISABLED;
46790 info->flags &= ~FBINFO_READS_FAST;
46791 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
46792 info->pixmap.size = 8 * 1024;
46793 info->pixmap.flags = FB_PIXMAP_SYSTEM;
46794
46795 - if (!hwcur)
46796 - info->fbops->fb_cursor = NULL;
46797 + if (!hwcur) {
46798 + pax_open_kernel();
46799 + *(void **)&info->fbops->fb_cursor = NULL;
46800 + pax_close_kernel();
46801 + }
46802
46803 info->var.accel_flags = (!noaccel);
46804
46805 diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
46806 index 76d9053..dec2bfd 100644
46807 --- a/drivers/video/s1d13xxxfb.c
46808 +++ b/drivers/video/s1d13xxxfb.c
46809 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
46810
46811 switch(prod_id) {
46812 case S1D13506_PROD_ID: /* activate acceleration */
46813 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
46814 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
46815 + pax_open_kernel();
46816 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
46817 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
46818 + pax_close_kernel();
46819 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
46820 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
46821 break;
46822 diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
46823 index 97bd662..39fab85 100644
46824 --- a/drivers/video/smscufx.c
46825 +++ b/drivers/video/smscufx.c
46826 @@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
46827 fb_deferred_io_cleanup(info);
46828 kfree(info->fbdefio);
46829 info->fbdefio = NULL;
46830 - info->fbops->fb_mmap = ufx_ops_mmap;
46831 + pax_open_kernel();
46832 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
46833 + pax_close_kernel();
46834 }
46835
46836 pr_debug("released /dev/fb%d user=%d count=%d",
46837 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
46838 index 86d449e..8e04dc5 100644
46839 --- a/drivers/video/udlfb.c
46840 +++ b/drivers/video/udlfb.c
46841 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
46842 dlfb_urb_completion(urb);
46843
46844 error:
46845 - atomic_add(bytes_sent, &dev->bytes_sent);
46846 - atomic_add(bytes_identical, &dev->bytes_identical);
46847 - atomic_add(width*height*2, &dev->bytes_rendered);
46848 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
46849 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
46850 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
46851 end_cycles = get_cycles();
46852 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
46853 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
46854 >> 10)), /* Kcycles */
46855 &dev->cpu_kcycles_used);
46856
46857 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
46858 dlfb_urb_completion(urb);
46859
46860 error:
46861 - atomic_add(bytes_sent, &dev->bytes_sent);
46862 - atomic_add(bytes_identical, &dev->bytes_identical);
46863 - atomic_add(bytes_rendered, &dev->bytes_rendered);
46864 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
46865 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
46866 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
46867 end_cycles = get_cycles();
46868 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
46869 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
46870 >> 10)), /* Kcycles */
46871 &dev->cpu_kcycles_used);
46872 }
46873 @@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
46874 fb_deferred_io_cleanup(info);
46875 kfree(info->fbdefio);
46876 info->fbdefio = NULL;
46877 - info->fbops->fb_mmap = dlfb_ops_mmap;
46878 + pax_open_kernel();
46879 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
46880 + pax_close_kernel();
46881 }
46882
46883 pr_warn("released /dev/fb%d user=%d count=%d\n",
46884 @@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
46885 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46886 struct dlfb_data *dev = fb_info->par;
46887 return snprintf(buf, PAGE_SIZE, "%u\n",
46888 - atomic_read(&dev->bytes_rendered));
46889 + atomic_read_unchecked(&dev->bytes_rendered));
46890 }
46891
46892 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
46893 @@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
46894 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46895 struct dlfb_data *dev = fb_info->par;
46896 return snprintf(buf, PAGE_SIZE, "%u\n",
46897 - atomic_read(&dev->bytes_identical));
46898 + atomic_read_unchecked(&dev->bytes_identical));
46899 }
46900
46901 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
46902 @@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
46903 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46904 struct dlfb_data *dev = fb_info->par;
46905 return snprintf(buf, PAGE_SIZE, "%u\n",
46906 - atomic_read(&dev->bytes_sent));
46907 + atomic_read_unchecked(&dev->bytes_sent));
46908 }
46909
46910 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
46911 @@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
46912 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46913 struct dlfb_data *dev = fb_info->par;
46914 return snprintf(buf, PAGE_SIZE, "%u\n",
46915 - atomic_read(&dev->cpu_kcycles_used));
46916 + atomic_read_unchecked(&dev->cpu_kcycles_used));
46917 }
46918
46919 static ssize_t edid_show(
46920 @@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
46921 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46922 struct dlfb_data *dev = fb_info->par;
46923
46924 - atomic_set(&dev->bytes_rendered, 0);
46925 - atomic_set(&dev->bytes_identical, 0);
46926 - atomic_set(&dev->bytes_sent, 0);
46927 - atomic_set(&dev->cpu_kcycles_used, 0);
46928 + atomic_set_unchecked(&dev->bytes_rendered, 0);
46929 + atomic_set_unchecked(&dev->bytes_identical, 0);
46930 + atomic_set_unchecked(&dev->bytes_sent, 0);
46931 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
46932
46933 return count;
46934 }
46935 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
46936 index b75db01..ad2f34a 100644
46937 --- a/drivers/video/uvesafb.c
46938 +++ b/drivers/video/uvesafb.c
46939 @@ -19,6 +19,7 @@
46940 #include <linux/io.h>
46941 #include <linux/mutex.h>
46942 #include <linux/slab.h>
46943 +#include <linux/moduleloader.h>
46944 #include <video/edid.h>
46945 #include <video/uvesafb.h>
46946 #ifdef CONFIG_X86
46947 @@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
46948 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
46949 par->pmi_setpal = par->ypan = 0;
46950 } else {
46951 +
46952 +#ifdef CONFIG_PAX_KERNEXEC
46953 +#ifdef CONFIG_MODULES
46954 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
46955 +#endif
46956 + if (!par->pmi_code) {
46957 + par->pmi_setpal = par->ypan = 0;
46958 + return 0;
46959 + }
46960 +#endif
46961 +
46962 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
46963 + task->t.regs.edi);
46964 +
46965 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46966 + pax_open_kernel();
46967 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
46968 + pax_close_kernel();
46969 +
46970 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
46971 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
46972 +#else
46973 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
46974 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
46975 +#endif
46976 +
46977 printk(KERN_INFO "uvesafb: protected mode interface info at "
46978 "%04x:%04x\n",
46979 (u16)task->t.regs.es, (u16)task->t.regs.edi);
46980 @@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
46981 par->ypan = ypan;
46982
46983 if (par->pmi_setpal || par->ypan) {
46984 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
46985 if (__supported_pte_mask & _PAGE_NX) {
46986 par->pmi_setpal = par->ypan = 0;
46987 printk(KERN_WARNING "uvesafb: NX protection is actively."
46988 "We have better not to use the PMI.\n");
46989 - } else {
46990 + } else
46991 +#endif
46992 uvesafb_vbe_getpmi(task, par);
46993 - }
46994 }
46995 #else
46996 /* The protected mode interface is not available on non-x86. */
46997 @@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
46998 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
46999
47000 /* Disable blanking if the user requested so. */
47001 - if (!blank)
47002 - info->fbops->fb_blank = NULL;
47003 + if (!blank) {
47004 + pax_open_kernel();
47005 + *(void **)&info->fbops->fb_blank = NULL;
47006 + pax_close_kernel();
47007 + }
47008
47009 /*
47010 * Find out how much IO memory is required for the mode with
47011 @@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47012 info->flags = FBINFO_FLAG_DEFAULT |
47013 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
47014
47015 - if (!par->ypan)
47016 - info->fbops->fb_pan_display = NULL;
47017 + if (!par->ypan) {
47018 + pax_open_kernel();
47019 + *(void **)&info->fbops->fb_pan_display = NULL;
47020 + pax_close_kernel();
47021 + }
47022 }
47023
47024 static void uvesafb_init_mtrr(struct fb_info *info)
47025 @@ -1836,6 +1866,11 @@ out:
47026 if (par->vbe_modes)
47027 kfree(par->vbe_modes);
47028
47029 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47030 + if (par->pmi_code)
47031 + module_free_exec(NULL, par->pmi_code);
47032 +#endif
47033 +
47034 framebuffer_release(info);
47035 return err;
47036 }
47037 @@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
47038 kfree(par->vbe_state_orig);
47039 if (par->vbe_state_saved)
47040 kfree(par->vbe_state_saved);
47041 +
47042 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47043 + if (par->pmi_code)
47044 + module_free_exec(NULL, par->pmi_code);
47045 +#endif
47046 +
47047 }
47048
47049 framebuffer_release(info);
47050 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
47051 index 501b340..d80aa17 100644
47052 --- a/drivers/video/vesafb.c
47053 +++ b/drivers/video/vesafb.c
47054 @@ -9,6 +9,7 @@
47055 */
47056
47057 #include <linux/module.h>
47058 +#include <linux/moduleloader.h>
47059 #include <linux/kernel.h>
47060 #include <linux/errno.h>
47061 #include <linux/string.h>
47062 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
47063 static int vram_total __initdata; /* Set total amount of memory */
47064 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
47065 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
47066 -static void (*pmi_start)(void) __read_mostly;
47067 -static void (*pmi_pal) (void) __read_mostly;
47068 +static void (*pmi_start)(void) __read_only;
47069 +static void (*pmi_pal) (void) __read_only;
47070 static int depth __read_mostly;
47071 static int vga_compat __read_mostly;
47072 /* --------------------------------------------------------------------- */
47073 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
47074 unsigned int size_vmode;
47075 unsigned int size_remap;
47076 unsigned int size_total;
47077 + void *pmi_code = NULL;
47078
47079 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
47080 return -ENODEV;
47081 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
47082 size_remap = size_total;
47083 vesafb_fix.smem_len = size_remap;
47084
47085 -#ifndef __i386__
47086 - screen_info.vesapm_seg = 0;
47087 -#endif
47088 -
47089 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
47090 printk(KERN_WARNING
47091 "vesafb: cannot reserve video memory at 0x%lx\n",
47092 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
47093 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
47094 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
47095
47096 +#ifdef __i386__
47097 +
47098 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47099 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
47100 + if (!pmi_code)
47101 +#elif !defined(CONFIG_PAX_KERNEXEC)
47102 + if (0)
47103 +#endif
47104 +
47105 +#endif
47106 + screen_info.vesapm_seg = 0;
47107 +
47108 if (screen_info.vesapm_seg) {
47109 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
47110 - screen_info.vesapm_seg,screen_info.vesapm_off);
47111 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
47112 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
47113 }
47114
47115 if (screen_info.vesapm_seg < 0xc000)
47116 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
47117
47118 if (ypan || pmi_setpal) {
47119 unsigned short *pmi_base;
47120 +
47121 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
47122 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
47123 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
47124 +
47125 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47126 + pax_open_kernel();
47127 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
47128 +#else
47129 + pmi_code = pmi_base;
47130 +#endif
47131 +
47132 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
47133 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
47134 +
47135 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47136 + pmi_start = ktva_ktla(pmi_start);
47137 + pmi_pal = ktva_ktla(pmi_pal);
47138 + pax_close_kernel();
47139 +#endif
47140 +
47141 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
47142 if (pmi_base[3]) {
47143 printk(KERN_INFO "vesafb: pmi: ports = ");
47144 @@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47145 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
47146 (ypan ? FBINFO_HWACCEL_YPAN : 0);
47147
47148 - if (!ypan)
47149 - info->fbops->fb_pan_display = NULL;
47150 + if (!ypan) {
47151 + pax_open_kernel();
47152 + *(void **)&info->fbops->fb_pan_display = NULL;
47153 + pax_close_kernel();
47154 + }
47155
47156 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
47157 err = -ENOMEM;
47158 @@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47159 info->node, info->fix.id);
47160 return 0;
47161 err:
47162 +
47163 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47164 + module_free_exec(NULL, pmi_code);
47165 +#endif
47166 +
47167 if (info->screen_base)
47168 iounmap(info->screen_base);
47169 framebuffer_release(info);
47170 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
47171 index 88714ae..16c2e11 100644
47172 --- a/drivers/video/via/via_clock.h
47173 +++ b/drivers/video/via/via_clock.h
47174 @@ -56,7 +56,7 @@ struct via_clock {
47175
47176 void (*set_engine_pll_state)(u8 state);
47177 void (*set_engine_pll)(struct via_pll_config config);
47178 -};
47179 +} __no_const;
47180
47181
47182 static inline u32 get_pll_internal_frequency(u32 ref_freq,
47183 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
47184 index fef20db..d28b1ab 100644
47185 --- a/drivers/xen/xenfs/xenstored.c
47186 +++ b/drivers/xen/xenfs/xenstored.c
47187 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
47188 static int xsd_kva_open(struct inode *inode, struct file *file)
47189 {
47190 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
47191 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47192 + NULL);
47193 +#else
47194 xen_store_interface);
47195 +#endif
47196 +
47197 if (!file->private_data)
47198 return -ENOMEM;
47199 return 0;
47200 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
47201 index 890bed5..17ae73e 100644
47202 --- a/fs/9p/vfs_inode.c
47203 +++ b/fs/9p/vfs_inode.c
47204 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47205 void
47206 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47207 {
47208 - char *s = nd_get_link(nd);
47209 + const char *s = nd_get_link(nd);
47210
47211 p9_debug(P9_DEBUG_VFS, " %s %s\n",
47212 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
47213 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
47214 index 0efd152..b5802ad 100644
47215 --- a/fs/Kconfig.binfmt
47216 +++ b/fs/Kconfig.binfmt
47217 @@ -89,7 +89,7 @@ config HAVE_AOUT
47218
47219 config BINFMT_AOUT
47220 tristate "Kernel support for a.out and ECOFF binaries"
47221 - depends on HAVE_AOUT
47222 + depends on HAVE_AOUT && BROKEN
47223 ---help---
47224 A.out (Assembler.OUTput) is a set of formats for libraries and
47225 executables used in the earliest versions of UNIX. Linux used
47226 diff --git a/fs/aio.c b/fs/aio.c
47227 index 71f613c..9d01f1f 100644
47228 --- a/fs/aio.c
47229 +++ b/fs/aio.c
47230 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
47231 size += sizeof(struct io_event) * nr_events;
47232 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
47233
47234 - if (nr_pages < 0)
47235 + if (nr_pages <= 0)
47236 return -EINVAL;
47237
47238 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
47239 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
47240 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47241 {
47242 ssize_t ret;
47243 + struct iovec iovstack;
47244
47245 #ifdef CONFIG_COMPAT
47246 if (compat)
47247 ret = compat_rw_copy_check_uvector(type,
47248 (struct compat_iovec __user *)kiocb->ki_buf,
47249 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47250 + kiocb->ki_nbytes, 1, &iovstack,
47251 &kiocb->ki_iovec);
47252 else
47253 #endif
47254 ret = rw_copy_check_uvector(type,
47255 (struct iovec __user *)kiocb->ki_buf,
47256 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47257 + kiocb->ki_nbytes, 1, &iovstack,
47258 &kiocb->ki_iovec);
47259 if (ret < 0)
47260 goto out;
47261 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47262 if (ret < 0)
47263 goto out;
47264
47265 + if (kiocb->ki_iovec == &iovstack) {
47266 + kiocb->ki_inline_vec = iovstack;
47267 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
47268 + }
47269 kiocb->ki_nr_segs = kiocb->ki_nbytes;
47270 kiocb->ki_cur_seg = 0;
47271 /* ki_nbytes/left now reflect bytes instead of segs */
47272 diff --git a/fs/attr.c b/fs/attr.c
47273 index 1449adb..a2038c2 100644
47274 --- a/fs/attr.c
47275 +++ b/fs/attr.c
47276 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
47277 unsigned long limit;
47278
47279 limit = rlimit(RLIMIT_FSIZE);
47280 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
47281 if (limit != RLIM_INFINITY && offset > limit)
47282 goto out_sig;
47283 if (offset > inode->i_sb->s_maxbytes)
47284 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
47285 index 03bc1d3..6205356 100644
47286 --- a/fs/autofs4/waitq.c
47287 +++ b/fs/autofs4/waitq.c
47288 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
47289 {
47290 unsigned long sigpipe, flags;
47291 mm_segment_t fs;
47292 - const char *data = (const char *)addr;
47293 + const char __user *data = (const char __force_user *)addr;
47294 ssize_t wr = 0;
47295
47296 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
47297 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
47298 return 1;
47299 }
47300
47301 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47302 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
47303 +#endif
47304 +
47305 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47306 enum autofs_notify notify)
47307 {
47308 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47309
47310 /* If this is a direct mount request create a dummy name */
47311 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
47312 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47313 + /* this name does get written to userland via autofs4_write() */
47314 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
47315 +#else
47316 qstr.len = sprintf(name, "%p", dentry);
47317 +#endif
47318 else {
47319 qstr.len = autofs4_getpath(sbi, dentry, &name);
47320 if (!qstr.len) {
47321 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
47322 index 2b3bda8..6a2d4be 100644
47323 --- a/fs/befs/linuxvfs.c
47324 +++ b/fs/befs/linuxvfs.c
47325 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47326 {
47327 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
47328 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
47329 - char *link = nd_get_link(nd);
47330 + const char *link = nd_get_link(nd);
47331 if (!IS_ERR(link))
47332 kfree(link);
47333 }
47334 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
47335 index 6043567..16a9239 100644
47336 --- a/fs/binfmt_aout.c
47337 +++ b/fs/binfmt_aout.c
47338 @@ -16,6 +16,7 @@
47339 #include <linux/string.h>
47340 #include <linux/fs.h>
47341 #include <linux/file.h>
47342 +#include <linux/security.h>
47343 #include <linux/stat.h>
47344 #include <linux/fcntl.h>
47345 #include <linux/ptrace.h>
47346 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
47347 #endif
47348 # define START_STACK(u) ((void __user *)u.start_stack)
47349
47350 + memset(&dump, 0, sizeof(dump));
47351 +
47352 fs = get_fs();
47353 set_fs(KERNEL_DS);
47354 has_dumped = 1;
47355 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
47356
47357 /* If the size of the dump file exceeds the rlimit, then see what would happen
47358 if we wrote the stack, but not the data area. */
47359 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
47360 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
47361 dump.u_dsize = 0;
47362
47363 /* Make sure we have enough room to write the stack and data areas. */
47364 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
47365 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
47366 dump.u_ssize = 0;
47367
47368 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
47369 rlim = rlimit(RLIMIT_DATA);
47370 if (rlim >= RLIM_INFINITY)
47371 rlim = ~0;
47372 +
47373 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
47374 if (ex.a_data + ex.a_bss > rlim)
47375 return -ENOMEM;
47376
47377 @@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
47378
47379 install_exec_creds(bprm);
47380
47381 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47382 + current->mm->pax_flags = 0UL;
47383 +#endif
47384 +
47385 +#ifdef CONFIG_PAX_PAGEEXEC
47386 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
47387 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
47388 +
47389 +#ifdef CONFIG_PAX_EMUTRAMP
47390 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
47391 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
47392 +#endif
47393 +
47394 +#ifdef CONFIG_PAX_MPROTECT
47395 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
47396 + current->mm->pax_flags |= MF_PAX_MPROTECT;
47397 +#endif
47398 +
47399 + }
47400 +#endif
47401 +
47402 if (N_MAGIC(ex) == OMAGIC) {
47403 unsigned long text_addr, map_size;
47404 loff_t pos;
47405 @@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
47406 }
47407
47408 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
47409 - PROT_READ | PROT_WRITE | PROT_EXEC,
47410 + PROT_READ | PROT_WRITE,
47411 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
47412 fd_offset + ex.a_text);
47413 if (error != N_DATADDR(ex)) {
47414 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
47415 index 0c42cdb..f4be023 100644
47416 --- a/fs/binfmt_elf.c
47417 +++ b/fs/binfmt_elf.c
47418 @@ -33,6 +33,7 @@
47419 #include <linux/elf.h>
47420 #include <linux/utsname.h>
47421 #include <linux/coredump.h>
47422 +#include <linux/xattr.h>
47423 #include <asm/uaccess.h>
47424 #include <asm/param.h>
47425 #include <asm/page.h>
47426 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
47427 #define elf_core_dump NULL
47428 #endif
47429
47430 +#ifdef CONFIG_PAX_MPROTECT
47431 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
47432 +#endif
47433 +
47434 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
47435 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
47436 #else
47437 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
47438 .load_binary = load_elf_binary,
47439 .load_shlib = load_elf_library,
47440 .core_dump = elf_core_dump,
47441 +
47442 +#ifdef CONFIG_PAX_MPROTECT
47443 + .handle_mprotect= elf_handle_mprotect,
47444 +#endif
47445 +
47446 .min_coredump = ELF_EXEC_PAGESIZE,
47447 };
47448
47449 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
47450
47451 static int set_brk(unsigned long start, unsigned long end)
47452 {
47453 + unsigned long e = end;
47454 +
47455 start = ELF_PAGEALIGN(start);
47456 end = ELF_PAGEALIGN(end);
47457 if (end > start) {
47458 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
47459 if (BAD_ADDR(addr))
47460 return addr;
47461 }
47462 - current->mm->start_brk = current->mm->brk = end;
47463 + current->mm->start_brk = current->mm->brk = e;
47464 return 0;
47465 }
47466
47467 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47468 elf_addr_t __user *u_rand_bytes;
47469 const char *k_platform = ELF_PLATFORM;
47470 const char *k_base_platform = ELF_BASE_PLATFORM;
47471 - unsigned char k_rand_bytes[16];
47472 + u32 k_rand_bytes[4];
47473 int items;
47474 elf_addr_t *elf_info;
47475 int ei_index = 0;
47476 const struct cred *cred = current_cred();
47477 struct vm_area_struct *vma;
47478 + unsigned long saved_auxv[AT_VECTOR_SIZE];
47479
47480 /*
47481 * In some cases (e.g. Hyper-Threading), we want to avoid L1
47482 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47483 * Generate 16 random bytes for userspace PRNG seeding.
47484 */
47485 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
47486 - u_rand_bytes = (elf_addr_t __user *)
47487 - STACK_ALLOC(p, sizeof(k_rand_bytes));
47488 + srandom32(k_rand_bytes[0] ^ random32());
47489 + srandom32(k_rand_bytes[1] ^ random32());
47490 + srandom32(k_rand_bytes[2] ^ random32());
47491 + srandom32(k_rand_bytes[3] ^ random32());
47492 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
47493 + u_rand_bytes = (elf_addr_t __user *) p;
47494 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
47495 return -EFAULT;
47496
47497 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47498 return -EFAULT;
47499 current->mm->env_end = p;
47500
47501 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
47502 +
47503 /* Put the elf_info on the stack in the right place. */
47504 sp = (elf_addr_t __user *)envp + 1;
47505 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
47506 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
47507 return -EFAULT;
47508 return 0;
47509 }
47510 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
47511 an ELF header */
47512
47513 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47514 - struct file *interpreter, unsigned long *interp_map_addr,
47515 - unsigned long no_base)
47516 + struct file *interpreter, unsigned long no_base)
47517 {
47518 struct elf_phdr *elf_phdata;
47519 struct elf_phdr *eppnt;
47520 - unsigned long load_addr = 0;
47521 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
47522 int load_addr_set = 0;
47523 unsigned long last_bss = 0, elf_bss = 0;
47524 - unsigned long error = ~0UL;
47525 + unsigned long error = -EINVAL;
47526 unsigned long total_size;
47527 int retval, i, size;
47528
47529 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47530 goto out_close;
47531 }
47532
47533 +#ifdef CONFIG_PAX_SEGMEXEC
47534 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
47535 + pax_task_size = SEGMEXEC_TASK_SIZE;
47536 +#endif
47537 +
47538 eppnt = elf_phdata;
47539 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
47540 if (eppnt->p_type == PT_LOAD) {
47541 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47542 map_addr = elf_map(interpreter, load_addr + vaddr,
47543 eppnt, elf_prot, elf_type, total_size);
47544 total_size = 0;
47545 - if (!*interp_map_addr)
47546 - *interp_map_addr = map_addr;
47547 error = map_addr;
47548 if (BAD_ADDR(map_addr))
47549 goto out_close;
47550 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47551 k = load_addr + eppnt->p_vaddr;
47552 if (BAD_ADDR(k) ||
47553 eppnt->p_filesz > eppnt->p_memsz ||
47554 - eppnt->p_memsz > TASK_SIZE ||
47555 - TASK_SIZE - eppnt->p_memsz < k) {
47556 + eppnt->p_memsz > pax_task_size ||
47557 + pax_task_size - eppnt->p_memsz < k) {
47558 error = -ENOMEM;
47559 goto out_close;
47560 }
47561 @@ -530,6 +551,315 @@ out:
47562 return error;
47563 }
47564
47565 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
47566 +#ifdef CONFIG_PAX_SOFTMODE
47567 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
47568 +{
47569 + unsigned long pax_flags = 0UL;
47570 +
47571 +#ifdef CONFIG_PAX_PAGEEXEC
47572 + if (elf_phdata->p_flags & PF_PAGEEXEC)
47573 + pax_flags |= MF_PAX_PAGEEXEC;
47574 +#endif
47575 +
47576 +#ifdef CONFIG_PAX_SEGMEXEC
47577 + if (elf_phdata->p_flags & PF_SEGMEXEC)
47578 + pax_flags |= MF_PAX_SEGMEXEC;
47579 +#endif
47580 +
47581 +#ifdef CONFIG_PAX_EMUTRAMP
47582 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
47583 + pax_flags |= MF_PAX_EMUTRAMP;
47584 +#endif
47585 +
47586 +#ifdef CONFIG_PAX_MPROTECT
47587 + if (elf_phdata->p_flags & PF_MPROTECT)
47588 + pax_flags |= MF_PAX_MPROTECT;
47589 +#endif
47590 +
47591 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47592 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
47593 + pax_flags |= MF_PAX_RANDMMAP;
47594 +#endif
47595 +
47596 + return pax_flags;
47597 +}
47598 +#endif
47599 +
47600 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
47601 +{
47602 + unsigned long pax_flags = 0UL;
47603 +
47604 +#ifdef CONFIG_PAX_PAGEEXEC
47605 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
47606 + pax_flags |= MF_PAX_PAGEEXEC;
47607 +#endif
47608 +
47609 +#ifdef CONFIG_PAX_SEGMEXEC
47610 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
47611 + pax_flags |= MF_PAX_SEGMEXEC;
47612 +#endif
47613 +
47614 +#ifdef CONFIG_PAX_EMUTRAMP
47615 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
47616 + pax_flags |= MF_PAX_EMUTRAMP;
47617 +#endif
47618 +
47619 +#ifdef CONFIG_PAX_MPROTECT
47620 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
47621 + pax_flags |= MF_PAX_MPROTECT;
47622 +#endif
47623 +
47624 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47625 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
47626 + pax_flags |= MF_PAX_RANDMMAP;
47627 +#endif
47628 +
47629 + return pax_flags;
47630 +}
47631 +#endif
47632 +
47633 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
47634 +#ifdef CONFIG_PAX_SOFTMODE
47635 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
47636 +{
47637 + unsigned long pax_flags = 0UL;
47638 +
47639 +#ifdef CONFIG_PAX_PAGEEXEC
47640 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
47641 + pax_flags |= MF_PAX_PAGEEXEC;
47642 +#endif
47643 +
47644 +#ifdef CONFIG_PAX_SEGMEXEC
47645 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
47646 + pax_flags |= MF_PAX_SEGMEXEC;
47647 +#endif
47648 +
47649 +#ifdef CONFIG_PAX_EMUTRAMP
47650 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
47651 + pax_flags |= MF_PAX_EMUTRAMP;
47652 +#endif
47653 +
47654 +#ifdef CONFIG_PAX_MPROTECT
47655 + if (pax_flags_softmode & MF_PAX_MPROTECT)
47656 + pax_flags |= MF_PAX_MPROTECT;
47657 +#endif
47658 +
47659 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47660 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
47661 + pax_flags |= MF_PAX_RANDMMAP;
47662 +#endif
47663 +
47664 + return pax_flags;
47665 +}
47666 +#endif
47667 +
47668 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
47669 +{
47670 + unsigned long pax_flags = 0UL;
47671 +
47672 +#ifdef CONFIG_PAX_PAGEEXEC
47673 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
47674 + pax_flags |= MF_PAX_PAGEEXEC;
47675 +#endif
47676 +
47677 +#ifdef CONFIG_PAX_SEGMEXEC
47678 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
47679 + pax_flags |= MF_PAX_SEGMEXEC;
47680 +#endif
47681 +
47682 +#ifdef CONFIG_PAX_EMUTRAMP
47683 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
47684 + pax_flags |= MF_PAX_EMUTRAMP;
47685 +#endif
47686 +
47687 +#ifdef CONFIG_PAX_MPROTECT
47688 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
47689 + pax_flags |= MF_PAX_MPROTECT;
47690 +#endif
47691 +
47692 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47693 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
47694 + pax_flags |= MF_PAX_RANDMMAP;
47695 +#endif
47696 +
47697 + return pax_flags;
47698 +}
47699 +#endif
47700 +
47701 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47702 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
47703 +{
47704 + unsigned long pax_flags = 0UL;
47705 +
47706 +#ifdef CONFIG_PAX_EI_PAX
47707 +
47708 +#ifdef CONFIG_PAX_PAGEEXEC
47709 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
47710 + pax_flags |= MF_PAX_PAGEEXEC;
47711 +#endif
47712 +
47713 +#ifdef CONFIG_PAX_SEGMEXEC
47714 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
47715 + pax_flags |= MF_PAX_SEGMEXEC;
47716 +#endif
47717 +
47718 +#ifdef CONFIG_PAX_EMUTRAMP
47719 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
47720 + pax_flags |= MF_PAX_EMUTRAMP;
47721 +#endif
47722 +
47723 +#ifdef CONFIG_PAX_MPROTECT
47724 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
47725 + pax_flags |= MF_PAX_MPROTECT;
47726 +#endif
47727 +
47728 +#ifdef CONFIG_PAX_ASLR
47729 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
47730 + pax_flags |= MF_PAX_RANDMMAP;
47731 +#endif
47732 +
47733 +#else
47734 +
47735 +#ifdef CONFIG_PAX_PAGEEXEC
47736 + pax_flags |= MF_PAX_PAGEEXEC;
47737 +#endif
47738 +
47739 +#ifdef CONFIG_PAX_SEGMEXEC
47740 + pax_flags |= MF_PAX_SEGMEXEC;
47741 +#endif
47742 +
47743 +#ifdef CONFIG_PAX_MPROTECT
47744 + pax_flags |= MF_PAX_MPROTECT;
47745 +#endif
47746 +
47747 +#ifdef CONFIG_PAX_RANDMMAP
47748 + if (randomize_va_space)
47749 + pax_flags |= MF_PAX_RANDMMAP;
47750 +#endif
47751 +
47752 +#endif
47753 +
47754 + return pax_flags;
47755 +}
47756 +
47757 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
47758 +{
47759 +
47760 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
47761 + unsigned long i;
47762 +
47763 + for (i = 0UL; i < elf_ex->e_phnum; i++)
47764 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
47765 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
47766 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
47767 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
47768 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
47769 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
47770 + return ~0UL;
47771 +
47772 +#ifdef CONFIG_PAX_SOFTMODE
47773 + if (pax_softmode)
47774 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
47775 + else
47776 +#endif
47777 +
47778 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
47779 + break;
47780 + }
47781 +#endif
47782 +
47783 + return ~0UL;
47784 +}
47785 +
47786 +static unsigned long pax_parse_xattr_pax(struct file * const file)
47787 +{
47788 +
47789 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
47790 + ssize_t xattr_size, i;
47791 + unsigned char xattr_value[5];
47792 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
47793 +
47794 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
47795 + if (xattr_size <= 0 || xattr_size > 5)
47796 + return ~0UL;
47797 +
47798 + for (i = 0; i < xattr_size; i++)
47799 + switch (xattr_value[i]) {
47800 + default:
47801 + return ~0UL;
47802 +
47803 +#define parse_flag(option1, option2, flag) \
47804 + case option1: \
47805 + if (pax_flags_hardmode & MF_PAX_##flag) \
47806 + return ~0UL; \
47807 + pax_flags_hardmode |= MF_PAX_##flag; \
47808 + break; \
47809 + case option2: \
47810 + if (pax_flags_softmode & MF_PAX_##flag) \
47811 + return ~0UL; \
47812 + pax_flags_softmode |= MF_PAX_##flag; \
47813 + break;
47814 +
47815 + parse_flag('p', 'P', PAGEEXEC);
47816 + parse_flag('e', 'E', EMUTRAMP);
47817 + parse_flag('m', 'M', MPROTECT);
47818 + parse_flag('r', 'R', RANDMMAP);
47819 + parse_flag('s', 'S', SEGMEXEC);
47820 +
47821 +#undef parse_flag
47822 + }
47823 +
47824 + if (pax_flags_hardmode & pax_flags_softmode)
47825 + return ~0UL;
47826 +
47827 +#ifdef CONFIG_PAX_SOFTMODE
47828 + if (pax_softmode)
47829 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
47830 + else
47831 +#endif
47832 +
47833 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
47834 +#else
47835 + return ~0UL;
47836 +#endif
47837 +
47838 +}
47839 +
47840 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
47841 +{
47842 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
47843 +
47844 + pax_flags = pax_parse_ei_pax(elf_ex);
47845 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
47846 + xattr_pax_flags = pax_parse_xattr_pax(file);
47847 +
47848 + if (pt_pax_flags == ~0UL)
47849 + pt_pax_flags = xattr_pax_flags;
47850 + else if (xattr_pax_flags == ~0UL)
47851 + xattr_pax_flags = pt_pax_flags;
47852 + if (pt_pax_flags != xattr_pax_flags)
47853 + return -EINVAL;
47854 + if (pt_pax_flags != ~0UL)
47855 + pax_flags = pt_pax_flags;
47856 +
47857 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
47858 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47859 + if ((__supported_pte_mask & _PAGE_NX))
47860 + pax_flags &= ~MF_PAX_SEGMEXEC;
47861 + else
47862 + pax_flags &= ~MF_PAX_PAGEEXEC;
47863 + }
47864 +#endif
47865 +
47866 + if (0 > pax_check_flags(&pax_flags))
47867 + return -EINVAL;
47868 +
47869 + current->mm->pax_flags = pax_flags;
47870 + return 0;
47871 +}
47872 +#endif
47873 +
47874 /*
47875 * These are the functions used to load ELF style executables and shared
47876 * libraries. There is no binary dependent code anywhere else.
47877 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
47878 {
47879 unsigned int random_variable = 0;
47880
47881 +#ifdef CONFIG_PAX_RANDUSTACK
47882 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
47883 + return stack_top - current->mm->delta_stack;
47884 +#endif
47885 +
47886 if ((current->flags & PF_RANDOMIZE) &&
47887 !(current->personality & ADDR_NO_RANDOMIZE)) {
47888 random_variable = get_random_int() & STACK_RND_MASK;
47889 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
47890 unsigned long load_addr = 0, load_bias = 0;
47891 int load_addr_set = 0;
47892 char * elf_interpreter = NULL;
47893 - unsigned long error;
47894 + unsigned long error = 0;
47895 struct elf_phdr *elf_ppnt, *elf_phdata;
47896 unsigned long elf_bss, elf_brk;
47897 int retval, i;
47898 @@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
47899 unsigned long start_code, end_code, start_data, end_data;
47900 unsigned long reloc_func_desc __maybe_unused = 0;
47901 int executable_stack = EXSTACK_DEFAULT;
47902 - unsigned long def_flags = 0;
47903 struct pt_regs *regs = current_pt_regs();
47904 struct {
47905 struct elfhdr elf_ex;
47906 struct elfhdr interp_elf_ex;
47907 } *loc;
47908 + unsigned long pax_task_size = TASK_SIZE;
47909
47910 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
47911 if (!loc) {
47912 @@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
47913 goto out_free_dentry;
47914
47915 /* OK, This is the point of no return */
47916 - current->mm->def_flags = def_flags;
47917 +
47918 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47919 + current->mm->pax_flags = 0UL;
47920 +#endif
47921 +
47922 +#ifdef CONFIG_PAX_DLRESOLVE
47923 + current->mm->call_dl_resolve = 0UL;
47924 +#endif
47925 +
47926 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
47927 + current->mm->call_syscall = 0UL;
47928 +#endif
47929 +
47930 +#ifdef CONFIG_PAX_ASLR
47931 + current->mm->delta_mmap = 0UL;
47932 + current->mm->delta_stack = 0UL;
47933 +#endif
47934 +
47935 + current->mm->def_flags = 0;
47936 +
47937 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47938 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
47939 + send_sig(SIGKILL, current, 0);
47940 + goto out_free_dentry;
47941 + }
47942 +#endif
47943 +
47944 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
47945 + pax_set_initial_flags(bprm);
47946 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
47947 + if (pax_set_initial_flags_func)
47948 + (pax_set_initial_flags_func)(bprm);
47949 +#endif
47950 +
47951 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
47952 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
47953 + current->mm->context.user_cs_limit = PAGE_SIZE;
47954 + current->mm->def_flags |= VM_PAGEEXEC;
47955 + }
47956 +#endif
47957 +
47958 +#ifdef CONFIG_PAX_SEGMEXEC
47959 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
47960 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
47961 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
47962 + pax_task_size = SEGMEXEC_TASK_SIZE;
47963 + current->mm->def_flags |= VM_NOHUGEPAGE;
47964 + }
47965 +#endif
47966 +
47967 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
47968 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47969 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
47970 + put_cpu();
47971 + }
47972 +#endif
47973
47974 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
47975 may depend on the personality. */
47976 SET_PERSONALITY(loc->elf_ex);
47977 +
47978 +#ifdef CONFIG_PAX_ASLR
47979 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
47980 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
47981 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
47982 + }
47983 +#endif
47984 +
47985 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47986 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47987 + executable_stack = EXSTACK_DISABLE_X;
47988 + current->personality &= ~READ_IMPLIES_EXEC;
47989 + } else
47990 +#endif
47991 +
47992 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
47993 current->personality |= READ_IMPLIES_EXEC;
47994
47995 @@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
47996 #else
47997 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
47998 #endif
47999 +
48000 +#ifdef CONFIG_PAX_RANDMMAP
48001 + /* PaX: randomize base address at the default exe base if requested */
48002 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
48003 +#ifdef CONFIG_SPARC64
48004 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
48005 +#else
48006 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
48007 +#endif
48008 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
48009 + elf_flags |= MAP_FIXED;
48010 + }
48011 +#endif
48012 +
48013 }
48014
48015 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
48016 @@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
48017 * allowed task size. Note that p_filesz must always be
48018 * <= p_memsz so it is only necessary to check p_memsz.
48019 */
48020 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48021 - elf_ppnt->p_memsz > TASK_SIZE ||
48022 - TASK_SIZE - elf_ppnt->p_memsz < k) {
48023 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48024 + elf_ppnt->p_memsz > pax_task_size ||
48025 + pax_task_size - elf_ppnt->p_memsz < k) {
48026 /* set_brk can never work. Avoid overflows. */
48027 send_sig(SIGKILL, current, 0);
48028 retval = -EINVAL;
48029 @@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
48030 goto out_free_dentry;
48031 }
48032 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
48033 - send_sig(SIGSEGV, current, 0);
48034 - retval = -EFAULT; /* Nobody gets to see this, but.. */
48035 - goto out_free_dentry;
48036 + /*
48037 + * This bss-zeroing can fail if the ELF
48038 + * file specifies odd protections. So
48039 + * we don't check the return value
48040 + */
48041 }
48042
48043 +#ifdef CONFIG_PAX_RANDMMAP
48044 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48045 + unsigned long start, size;
48046 +
48047 + start = ELF_PAGEALIGN(elf_brk);
48048 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
48049 + down_read(&current->mm->mmap_sem);
48050 + retval = -ENOMEM;
48051 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
48052 + unsigned long prot = PROT_NONE;
48053 +
48054 + up_read(&current->mm->mmap_sem);
48055 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
48056 +// if (current->personality & ADDR_NO_RANDOMIZE)
48057 +// prot = PROT_READ;
48058 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
48059 + retval = IS_ERR_VALUE(start) ? start : 0;
48060 + } else
48061 + up_read(&current->mm->mmap_sem);
48062 + if (retval == 0)
48063 + retval = set_brk(start + size, start + size + PAGE_SIZE);
48064 + if (retval < 0) {
48065 + send_sig(SIGKILL, current, 0);
48066 + goto out_free_dentry;
48067 + }
48068 + }
48069 +#endif
48070 +
48071 if (elf_interpreter) {
48072 - unsigned long interp_map_addr = 0;
48073 -
48074 elf_entry = load_elf_interp(&loc->interp_elf_ex,
48075 interpreter,
48076 - &interp_map_addr,
48077 load_bias);
48078 if (!IS_ERR((void *)elf_entry)) {
48079 /*
48080 @@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
48081 * Decide what to dump of a segment, part, all or none.
48082 */
48083 static unsigned long vma_dump_size(struct vm_area_struct *vma,
48084 - unsigned long mm_flags)
48085 + unsigned long mm_flags, long signr)
48086 {
48087 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
48088
48089 @@ -1152,7 +1598,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
48090 if (vma->vm_file == NULL)
48091 return 0;
48092
48093 - if (FILTER(MAPPED_PRIVATE))
48094 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
48095 goto whole;
48096
48097 /*
48098 @@ -1374,9 +1820,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
48099 {
48100 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
48101 int i = 0;
48102 - do
48103 + do {
48104 i += 2;
48105 - while (auxv[i - 2] != AT_NULL);
48106 + } while (auxv[i - 2] != AT_NULL);
48107 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
48108 }
48109
48110 @@ -2006,14 +2452,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
48111 }
48112
48113 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
48114 - unsigned long mm_flags)
48115 + struct coredump_params *cprm)
48116 {
48117 struct vm_area_struct *vma;
48118 size_t size = 0;
48119
48120 for (vma = first_vma(current, gate_vma); vma != NULL;
48121 vma = next_vma(vma, gate_vma))
48122 - size += vma_dump_size(vma, mm_flags);
48123 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48124 return size;
48125 }
48126
48127 @@ -2107,7 +2553,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48128
48129 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
48130
48131 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
48132 + offset += elf_core_vma_data_size(gate_vma, cprm);
48133 offset += elf_core_extra_data_size();
48134 e_shoff = offset;
48135
48136 @@ -2121,10 +2567,12 @@ static int elf_core_dump(struct coredump_params *cprm)
48137 offset = dataoff;
48138
48139 size += sizeof(*elf);
48140 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48141 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
48142 goto end_coredump;
48143
48144 size += sizeof(*phdr4note);
48145 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48146 if (size > cprm->limit
48147 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
48148 goto end_coredump;
48149 @@ -2138,7 +2586,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48150 phdr.p_offset = offset;
48151 phdr.p_vaddr = vma->vm_start;
48152 phdr.p_paddr = 0;
48153 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
48154 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48155 phdr.p_memsz = vma->vm_end - vma->vm_start;
48156 offset += phdr.p_filesz;
48157 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
48158 @@ -2149,6 +2597,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48159 phdr.p_align = ELF_EXEC_PAGESIZE;
48160
48161 size += sizeof(phdr);
48162 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48163 if (size > cprm->limit
48164 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
48165 goto end_coredump;
48166 @@ -2173,7 +2622,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48167 unsigned long addr;
48168 unsigned long end;
48169
48170 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
48171 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48172
48173 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
48174 struct page *page;
48175 @@ -2182,6 +2631,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48176 page = get_dump_page(addr);
48177 if (page) {
48178 void *kaddr = kmap(page);
48179 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
48180 stop = ((size += PAGE_SIZE) > cprm->limit) ||
48181 !dump_write(cprm->file, kaddr,
48182 PAGE_SIZE);
48183 @@ -2199,6 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48184
48185 if (e_phnum == PN_XNUM) {
48186 size += sizeof(*shdr4extnum);
48187 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48188 if (size > cprm->limit
48189 || !dump_write(cprm->file, shdr4extnum,
48190 sizeof(*shdr4extnum)))
48191 @@ -2219,6 +2670,97 @@ out:
48192
48193 #endif /* CONFIG_ELF_CORE */
48194
48195 +#ifdef CONFIG_PAX_MPROTECT
48196 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
48197 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
48198 + * we'll remove VM_MAYWRITE for good on RELRO segments.
48199 + *
48200 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
48201 + * basis because we want to allow the common case and not the special ones.
48202 + */
48203 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
48204 +{
48205 + struct elfhdr elf_h;
48206 + struct elf_phdr elf_p;
48207 + unsigned long i;
48208 + unsigned long oldflags;
48209 + bool is_textrel_rw, is_textrel_rx, is_relro;
48210 +
48211 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
48212 + return;
48213 +
48214 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
48215 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
48216 +
48217 +#ifdef CONFIG_PAX_ELFRELOCS
48218 + /* possible TEXTREL */
48219 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
48220 + 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);
48221 +#else
48222 + is_textrel_rw = false;
48223 + is_textrel_rx = false;
48224 +#endif
48225 +
48226 + /* possible RELRO */
48227 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
48228 +
48229 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
48230 + return;
48231 +
48232 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
48233 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
48234 +
48235 +#ifdef CONFIG_PAX_ETEXECRELOCS
48236 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48237 +#else
48238 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
48239 +#endif
48240 +
48241 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48242 + !elf_check_arch(&elf_h) ||
48243 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
48244 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
48245 + return;
48246 +
48247 + for (i = 0UL; i < elf_h.e_phnum; i++) {
48248 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
48249 + return;
48250 + switch (elf_p.p_type) {
48251 + case PT_DYNAMIC:
48252 + if (!is_textrel_rw && !is_textrel_rx)
48253 + continue;
48254 + i = 0UL;
48255 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
48256 + elf_dyn dyn;
48257 +
48258 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
48259 + return;
48260 + if (dyn.d_tag == DT_NULL)
48261 + return;
48262 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
48263 + gr_log_textrel(vma);
48264 + if (is_textrel_rw)
48265 + vma->vm_flags |= VM_MAYWRITE;
48266 + else
48267 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
48268 + vma->vm_flags &= ~VM_MAYWRITE;
48269 + return;
48270 + }
48271 + i++;
48272 + }
48273 + return;
48274 +
48275 + case PT_GNU_RELRO:
48276 + if (!is_relro)
48277 + continue;
48278 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
48279 + vma->vm_flags &= ~VM_MAYWRITE;
48280 + return;
48281 + }
48282 + }
48283 +}
48284 +#endif
48285 +
48286 static int __init init_elf_binfmt(void)
48287 {
48288 register_binfmt(&elf_format);
48289 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
48290 index b563719..3868998 100644
48291 --- a/fs/binfmt_flat.c
48292 +++ b/fs/binfmt_flat.c
48293 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
48294 realdatastart = (unsigned long) -ENOMEM;
48295 printk("Unable to allocate RAM for process data, errno %d\n",
48296 (int)-realdatastart);
48297 + down_write(&current->mm->mmap_sem);
48298 vm_munmap(textpos, text_len);
48299 + up_write(&current->mm->mmap_sem);
48300 ret = realdatastart;
48301 goto err;
48302 }
48303 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48304 }
48305 if (IS_ERR_VALUE(result)) {
48306 printk("Unable to read data+bss, errno %d\n", (int)-result);
48307 + down_write(&current->mm->mmap_sem);
48308 vm_munmap(textpos, text_len);
48309 vm_munmap(realdatastart, len);
48310 + up_write(&current->mm->mmap_sem);
48311 ret = result;
48312 goto err;
48313 }
48314 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48315 }
48316 if (IS_ERR_VALUE(result)) {
48317 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
48318 + down_write(&current->mm->mmap_sem);
48319 vm_munmap(textpos, text_len + data_len + extra +
48320 MAX_SHARED_LIBS * sizeof(unsigned long));
48321 + up_write(&current->mm->mmap_sem);
48322 ret = result;
48323 goto err;
48324 }
48325 diff --git a/fs/bio.c b/fs/bio.c
48326 index b96fc6c..431d628 100644
48327 --- a/fs/bio.c
48328 +++ b/fs/bio.c
48329 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
48330 /*
48331 * Overflow, abort
48332 */
48333 - if (end < start)
48334 + if (end < start || end - start > INT_MAX - nr_pages)
48335 return ERR_PTR(-EINVAL);
48336
48337 nr_pages += end - start;
48338 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
48339 /*
48340 * Overflow, abort
48341 */
48342 - if (end < start)
48343 + if (end < start || end - start > INT_MAX - nr_pages)
48344 return ERR_PTR(-EINVAL);
48345
48346 nr_pages += end - start;
48347 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
48348 const int read = bio_data_dir(bio) == READ;
48349 struct bio_map_data *bmd = bio->bi_private;
48350 int i;
48351 - char *p = bmd->sgvecs[0].iov_base;
48352 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
48353
48354 __bio_for_each_segment(bvec, bio, i, 0) {
48355 char *addr = page_address(bvec->bv_page);
48356 diff --git a/fs/block_dev.c b/fs/block_dev.c
48357 index 78333a3..23dcb4d 100644
48358 --- a/fs/block_dev.c
48359 +++ b/fs/block_dev.c
48360 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
48361 else if (bdev->bd_contains == bdev)
48362 return true; /* is a whole device which isn't held */
48363
48364 - else if (whole->bd_holder == bd_may_claim)
48365 + else if (whole->bd_holder == (void *)bd_may_claim)
48366 return true; /* is a partition of a device that is being partitioned */
48367 else if (whole->bd_holder != NULL)
48368 return false; /* is a partition of a held device */
48369 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
48370 index eea5da7..88fead70 100644
48371 --- a/fs/btrfs/ctree.c
48372 +++ b/fs/btrfs/ctree.c
48373 @@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
48374 free_extent_buffer(buf);
48375 add_root_to_dirty_list(root);
48376 } else {
48377 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
48378 - parent_start = parent->start;
48379 - else
48380 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
48381 + if (parent)
48382 + parent_start = parent->start;
48383 + else
48384 + parent_start = 0;
48385 + } else
48386 parent_start = 0;
48387
48388 WARN_ON(trans->transid != btrfs_header_generation(parent));
48389 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
48390 index cc93b23..f3c42bf 100644
48391 --- a/fs/btrfs/inode.c
48392 +++ b/fs/btrfs/inode.c
48393 @@ -7296,7 +7296,7 @@ fail:
48394 return -ENOMEM;
48395 }
48396
48397 -static int btrfs_getattr(struct vfsmount *mnt,
48398 +int btrfs_getattr(struct vfsmount *mnt,
48399 struct dentry *dentry, struct kstat *stat)
48400 {
48401 struct inode *inode = dentry->d_inode;
48402 @@ -7310,6 +7310,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
48403 return 0;
48404 }
48405
48406 +EXPORT_SYMBOL(btrfs_getattr);
48407 +
48408 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
48409 +{
48410 + return BTRFS_I(inode)->root->anon_dev;
48411 +}
48412 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
48413 +
48414 /*
48415 * If a file is moved, it will inherit the cow and compression flags of the new
48416 * directory.
48417 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
48418 index 338f259..b657640 100644
48419 --- a/fs/btrfs/ioctl.c
48420 +++ b/fs/btrfs/ioctl.c
48421 @@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48422 for (i = 0; i < num_types; i++) {
48423 struct btrfs_space_info *tmp;
48424
48425 + /* Don't copy in more than we allocated */
48426 if (!slot_count)
48427 break;
48428
48429 + slot_count--;
48430 +
48431 info = NULL;
48432 rcu_read_lock();
48433 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
48434 @@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48435 memcpy(dest, &space, sizeof(space));
48436 dest++;
48437 space_args.total_spaces++;
48438 - slot_count--;
48439 }
48440 - if (!slot_count)
48441 - break;
48442 }
48443 up_read(&info->groups_sem);
48444 }
48445 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
48446 index 300e09a..9fe4539 100644
48447 --- a/fs/btrfs/relocation.c
48448 +++ b/fs/btrfs/relocation.c
48449 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
48450 }
48451 spin_unlock(&rc->reloc_root_tree.lock);
48452
48453 - BUG_ON((struct btrfs_root *)node->data != root);
48454 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
48455
48456 if (!del) {
48457 spin_lock(&rc->reloc_root_tree.lock);
48458 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
48459 index d8982e9..29a85fa 100644
48460 --- a/fs/btrfs/super.c
48461 +++ b/fs/btrfs/super.c
48462 @@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
48463 function, line, errstr);
48464 return;
48465 }
48466 - ACCESS_ONCE(trans->transaction->aborted) = errno;
48467 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
48468 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
48469 }
48470 /*
48471 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
48472 index 622f469..e8d2d55 100644
48473 --- a/fs/cachefiles/bind.c
48474 +++ b/fs/cachefiles/bind.c
48475 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
48476 args);
48477
48478 /* start by checking things over */
48479 - ASSERT(cache->fstop_percent >= 0 &&
48480 - cache->fstop_percent < cache->fcull_percent &&
48481 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
48482 cache->fcull_percent < cache->frun_percent &&
48483 cache->frun_percent < 100);
48484
48485 - ASSERT(cache->bstop_percent >= 0 &&
48486 - cache->bstop_percent < cache->bcull_percent &&
48487 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
48488 cache->bcull_percent < cache->brun_percent &&
48489 cache->brun_percent < 100);
48490
48491 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
48492 index 0a1467b..6a53245 100644
48493 --- a/fs/cachefiles/daemon.c
48494 +++ b/fs/cachefiles/daemon.c
48495 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
48496 if (n > buflen)
48497 return -EMSGSIZE;
48498
48499 - if (copy_to_user(_buffer, buffer, n) != 0)
48500 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
48501 return -EFAULT;
48502
48503 return n;
48504 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
48505 if (test_bit(CACHEFILES_DEAD, &cache->flags))
48506 return -EIO;
48507
48508 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
48509 + if (datalen > PAGE_SIZE - 1)
48510 return -EOPNOTSUPP;
48511
48512 /* drag the command string into the kernel so we can parse it */
48513 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
48514 if (args[0] != '%' || args[1] != '\0')
48515 return -EINVAL;
48516
48517 - if (fstop < 0 || fstop >= cache->fcull_percent)
48518 + if (fstop >= cache->fcull_percent)
48519 return cachefiles_daemon_range_error(cache, args);
48520
48521 cache->fstop_percent = fstop;
48522 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
48523 if (args[0] != '%' || args[1] != '\0')
48524 return -EINVAL;
48525
48526 - if (bstop < 0 || bstop >= cache->bcull_percent)
48527 + if (bstop >= cache->bcull_percent)
48528 return cachefiles_daemon_range_error(cache, args);
48529
48530 cache->bstop_percent = bstop;
48531 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
48532 index 4938251..7e01445 100644
48533 --- a/fs/cachefiles/internal.h
48534 +++ b/fs/cachefiles/internal.h
48535 @@ -59,7 +59,7 @@ struct cachefiles_cache {
48536 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
48537 struct rb_root active_nodes; /* active nodes (can't be culled) */
48538 rwlock_t active_lock; /* lock for active_nodes */
48539 - atomic_t gravecounter; /* graveyard uniquifier */
48540 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
48541 unsigned frun_percent; /* when to stop culling (% files) */
48542 unsigned fcull_percent; /* when to start culling (% files) */
48543 unsigned fstop_percent; /* when to stop allocating (% files) */
48544 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
48545 * proc.c
48546 */
48547 #ifdef CONFIG_CACHEFILES_HISTOGRAM
48548 -extern atomic_t cachefiles_lookup_histogram[HZ];
48549 -extern atomic_t cachefiles_mkdir_histogram[HZ];
48550 -extern atomic_t cachefiles_create_histogram[HZ];
48551 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48552 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48553 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
48554
48555 extern int __init cachefiles_proc_init(void);
48556 extern void cachefiles_proc_cleanup(void);
48557 static inline
48558 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
48559 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
48560 {
48561 unsigned long jif = jiffies - start_jif;
48562 if (jif >= HZ)
48563 jif = HZ - 1;
48564 - atomic_inc(&histogram[jif]);
48565 + atomic_inc_unchecked(&histogram[jif]);
48566 }
48567
48568 #else
48569 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
48570 index 8c01c5fc..15f982e 100644
48571 --- a/fs/cachefiles/namei.c
48572 +++ b/fs/cachefiles/namei.c
48573 @@ -317,7 +317,7 @@ try_again:
48574 /* first step is to make up a grave dentry in the graveyard */
48575 sprintf(nbuffer, "%08x%08x",
48576 (uint32_t) get_seconds(),
48577 - (uint32_t) atomic_inc_return(&cache->gravecounter));
48578 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
48579
48580 /* do the multiway lock magic */
48581 trap = lock_rename(cache->graveyard, dir);
48582 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
48583 index eccd339..4c1d995 100644
48584 --- a/fs/cachefiles/proc.c
48585 +++ b/fs/cachefiles/proc.c
48586 @@ -14,9 +14,9 @@
48587 #include <linux/seq_file.h>
48588 #include "internal.h"
48589
48590 -atomic_t cachefiles_lookup_histogram[HZ];
48591 -atomic_t cachefiles_mkdir_histogram[HZ];
48592 -atomic_t cachefiles_create_histogram[HZ];
48593 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48594 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48595 +atomic_unchecked_t cachefiles_create_histogram[HZ];
48596
48597 /*
48598 * display the latency histogram
48599 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
48600 return 0;
48601 default:
48602 index = (unsigned long) v - 3;
48603 - x = atomic_read(&cachefiles_lookup_histogram[index]);
48604 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
48605 - z = atomic_read(&cachefiles_create_histogram[index]);
48606 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
48607 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
48608 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
48609 if (x == 0 && y == 0 && z == 0)
48610 return 0;
48611
48612 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
48613 index 4809922..aab2c39 100644
48614 --- a/fs/cachefiles/rdwr.c
48615 +++ b/fs/cachefiles/rdwr.c
48616 @@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
48617 old_fs = get_fs();
48618 set_fs(KERNEL_DS);
48619 ret = file->f_op->write(
48620 - file, (const void __user *) data, len, &pos);
48621 + file, (const void __force_user *) data, len, &pos);
48622 set_fs(old_fs);
48623 kunmap(page);
48624 if (ret != len)
48625 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
48626 index 8c1aabe..bbf856a 100644
48627 --- a/fs/ceph/dir.c
48628 +++ b/fs/ceph/dir.c
48629 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
48630 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
48631 struct ceph_mds_client *mdsc = fsc->mdsc;
48632 unsigned frag = fpos_frag(filp->f_pos);
48633 - int off = fpos_off(filp->f_pos);
48634 + unsigned int off = fpos_off(filp->f_pos);
48635 int err;
48636 u32 ftype;
48637 struct ceph_mds_reply_info_parsed *rinfo;
48638 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
48639 index d9ea6ed..1e6c8ac 100644
48640 --- a/fs/cifs/cifs_debug.c
48641 +++ b/fs/cifs/cifs_debug.c
48642 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
48643
48644 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
48645 #ifdef CONFIG_CIFS_STATS2
48646 - atomic_set(&totBufAllocCount, 0);
48647 - atomic_set(&totSmBufAllocCount, 0);
48648 + atomic_set_unchecked(&totBufAllocCount, 0);
48649 + atomic_set_unchecked(&totSmBufAllocCount, 0);
48650 #endif /* CONFIG_CIFS_STATS2 */
48651 spin_lock(&cifs_tcp_ses_lock);
48652 list_for_each(tmp1, &cifs_tcp_ses_list) {
48653 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
48654 tcon = list_entry(tmp3,
48655 struct cifs_tcon,
48656 tcon_list);
48657 - atomic_set(&tcon->num_smbs_sent, 0);
48658 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
48659 if (server->ops->clear_stats)
48660 server->ops->clear_stats(tcon);
48661 }
48662 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
48663 smBufAllocCount.counter, cifs_min_small);
48664 #ifdef CONFIG_CIFS_STATS2
48665 seq_printf(m, "Total Large %d Small %d Allocations\n",
48666 - atomic_read(&totBufAllocCount),
48667 - atomic_read(&totSmBufAllocCount));
48668 + atomic_read_unchecked(&totBufAllocCount),
48669 + atomic_read_unchecked(&totSmBufAllocCount));
48670 #endif /* CONFIG_CIFS_STATS2 */
48671
48672 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
48673 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
48674 if (tcon->need_reconnect)
48675 seq_puts(m, "\tDISCONNECTED ");
48676 seq_printf(m, "\nSMBs: %d",
48677 - atomic_read(&tcon->num_smbs_sent));
48678 + atomic_read_unchecked(&tcon->num_smbs_sent));
48679 if (server->ops->print_stats)
48680 server->ops->print_stats(m, tcon);
48681 }
48682 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
48683 index de7f916..6cb22a9 100644
48684 --- a/fs/cifs/cifsfs.c
48685 +++ b/fs/cifs/cifsfs.c
48686 @@ -997,7 +997,7 @@ cifs_init_request_bufs(void)
48687 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
48688 cifs_req_cachep = kmem_cache_create("cifs_request",
48689 CIFSMaxBufSize + max_hdr_size, 0,
48690 - SLAB_HWCACHE_ALIGN, NULL);
48691 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
48692 if (cifs_req_cachep == NULL)
48693 return -ENOMEM;
48694
48695 @@ -1024,7 +1024,7 @@ cifs_init_request_bufs(void)
48696 efficient to alloc 1 per page off the slab compared to 17K (5page)
48697 alloc of large cifs buffers even when page debugging is on */
48698 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
48699 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
48700 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
48701 NULL);
48702 if (cifs_sm_req_cachep == NULL) {
48703 mempool_destroy(cifs_req_poolp);
48704 @@ -1109,8 +1109,8 @@ init_cifs(void)
48705 atomic_set(&bufAllocCount, 0);
48706 atomic_set(&smBufAllocCount, 0);
48707 #ifdef CONFIG_CIFS_STATS2
48708 - atomic_set(&totBufAllocCount, 0);
48709 - atomic_set(&totSmBufAllocCount, 0);
48710 + atomic_set_unchecked(&totBufAllocCount, 0);
48711 + atomic_set_unchecked(&totSmBufAllocCount, 0);
48712 #endif /* CONFIG_CIFS_STATS2 */
48713
48714 atomic_set(&midCount, 0);
48715 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
48716 index e6899ce..d6b2920 100644
48717 --- a/fs/cifs/cifsglob.h
48718 +++ b/fs/cifs/cifsglob.h
48719 @@ -751,35 +751,35 @@ struct cifs_tcon {
48720 __u16 Flags; /* optional support bits */
48721 enum statusEnum tidStatus;
48722 #ifdef CONFIG_CIFS_STATS
48723 - atomic_t num_smbs_sent;
48724 + atomic_unchecked_t num_smbs_sent;
48725 union {
48726 struct {
48727 - atomic_t num_writes;
48728 - atomic_t num_reads;
48729 - atomic_t num_flushes;
48730 - atomic_t num_oplock_brks;
48731 - atomic_t num_opens;
48732 - atomic_t num_closes;
48733 - atomic_t num_deletes;
48734 - atomic_t num_mkdirs;
48735 - atomic_t num_posixopens;
48736 - atomic_t num_posixmkdirs;
48737 - atomic_t num_rmdirs;
48738 - atomic_t num_renames;
48739 - atomic_t num_t2renames;
48740 - atomic_t num_ffirst;
48741 - atomic_t num_fnext;
48742 - atomic_t num_fclose;
48743 - atomic_t num_hardlinks;
48744 - atomic_t num_symlinks;
48745 - atomic_t num_locks;
48746 - atomic_t num_acl_get;
48747 - atomic_t num_acl_set;
48748 + atomic_unchecked_t num_writes;
48749 + atomic_unchecked_t num_reads;
48750 + atomic_unchecked_t num_flushes;
48751 + atomic_unchecked_t num_oplock_brks;
48752 + atomic_unchecked_t num_opens;
48753 + atomic_unchecked_t num_closes;
48754 + atomic_unchecked_t num_deletes;
48755 + atomic_unchecked_t num_mkdirs;
48756 + atomic_unchecked_t num_posixopens;
48757 + atomic_unchecked_t num_posixmkdirs;
48758 + atomic_unchecked_t num_rmdirs;
48759 + atomic_unchecked_t num_renames;
48760 + atomic_unchecked_t num_t2renames;
48761 + atomic_unchecked_t num_ffirst;
48762 + atomic_unchecked_t num_fnext;
48763 + atomic_unchecked_t num_fclose;
48764 + atomic_unchecked_t num_hardlinks;
48765 + atomic_unchecked_t num_symlinks;
48766 + atomic_unchecked_t num_locks;
48767 + atomic_unchecked_t num_acl_get;
48768 + atomic_unchecked_t num_acl_set;
48769 } cifs_stats;
48770 #ifdef CONFIG_CIFS_SMB2
48771 struct {
48772 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
48773 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
48774 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
48775 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
48776 } smb2_stats;
48777 #endif /* CONFIG_CIFS_SMB2 */
48778 } stats;
48779 @@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
48780 }
48781
48782 #ifdef CONFIG_CIFS_STATS
48783 -#define cifs_stats_inc atomic_inc
48784 +#define cifs_stats_inc atomic_inc_unchecked
48785
48786 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
48787 unsigned int bytes)
48788 @@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
48789 /* Various Debug counters */
48790 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
48791 #ifdef CONFIG_CIFS_STATS2
48792 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
48793 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
48794 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
48795 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
48796 #endif
48797 GLOBAL_EXTERN atomic_t smBufAllocCount;
48798 GLOBAL_EXTERN atomic_t midCount;
48799 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
48800 index 51dc2fb..1e12a33 100644
48801 --- a/fs/cifs/link.c
48802 +++ b/fs/cifs/link.c
48803 @@ -616,7 +616,7 @@ symlink_exit:
48804
48805 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
48806 {
48807 - char *p = nd_get_link(nd);
48808 + const char *p = nd_get_link(nd);
48809 if (!IS_ERR(p))
48810 kfree(p);
48811 }
48812 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
48813 index 3a00c0d..42d901c 100644
48814 --- a/fs/cifs/misc.c
48815 +++ b/fs/cifs/misc.c
48816 @@ -169,7 +169,7 @@ cifs_buf_get(void)
48817 memset(ret_buf, 0, buf_size + 3);
48818 atomic_inc(&bufAllocCount);
48819 #ifdef CONFIG_CIFS_STATS2
48820 - atomic_inc(&totBufAllocCount);
48821 + atomic_inc_unchecked(&totBufAllocCount);
48822 #endif /* CONFIG_CIFS_STATS2 */
48823 }
48824
48825 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
48826 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
48827 atomic_inc(&smBufAllocCount);
48828 #ifdef CONFIG_CIFS_STATS2
48829 - atomic_inc(&totSmBufAllocCount);
48830 + atomic_inc_unchecked(&totSmBufAllocCount);
48831 #endif /* CONFIG_CIFS_STATS2 */
48832
48833 }
48834 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
48835 index 47bc5a8..10decbe 100644
48836 --- a/fs/cifs/smb1ops.c
48837 +++ b/fs/cifs/smb1ops.c
48838 @@ -586,27 +586,27 @@ static void
48839 cifs_clear_stats(struct cifs_tcon *tcon)
48840 {
48841 #ifdef CONFIG_CIFS_STATS
48842 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
48843 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
48844 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
48845 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
48846 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
48847 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
48848 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
48849 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
48850 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
48851 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
48852 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
48853 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
48854 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
48855 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
48856 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
48857 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
48858 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
48859 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
48860 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
48861 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
48862 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
48863 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
48864 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
48865 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
48866 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
48867 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
48868 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
48869 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
48870 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
48871 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
48872 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
48873 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
48874 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
48875 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
48876 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
48877 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
48878 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
48879 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
48880 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
48881 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
48882 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
48883 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
48884 #endif
48885 }
48886
48887 @@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
48888 {
48889 #ifdef CONFIG_CIFS_STATS
48890 seq_printf(m, " Oplocks breaks: %d",
48891 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
48892 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
48893 seq_printf(m, "\nReads: %d Bytes: %llu",
48894 - atomic_read(&tcon->stats.cifs_stats.num_reads),
48895 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
48896 (long long)(tcon->bytes_read));
48897 seq_printf(m, "\nWrites: %d Bytes: %llu",
48898 - atomic_read(&tcon->stats.cifs_stats.num_writes),
48899 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
48900 (long long)(tcon->bytes_written));
48901 seq_printf(m, "\nFlushes: %d",
48902 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
48903 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
48904 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
48905 - atomic_read(&tcon->stats.cifs_stats.num_locks),
48906 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
48907 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
48908 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
48909 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
48910 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
48911 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
48912 - atomic_read(&tcon->stats.cifs_stats.num_opens),
48913 - atomic_read(&tcon->stats.cifs_stats.num_closes),
48914 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
48915 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
48916 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
48917 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
48918 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
48919 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
48920 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
48921 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
48922 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
48923 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
48924 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
48925 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
48926 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
48927 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
48928 seq_printf(m, "\nRenames: %d T2 Renames %d",
48929 - atomic_read(&tcon->stats.cifs_stats.num_renames),
48930 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
48931 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
48932 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
48933 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
48934 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
48935 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
48936 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
48937 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
48938 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
48939 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
48940 #endif
48941 }
48942
48943 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
48944 index c9c7aa7..065056a 100644
48945 --- a/fs/cifs/smb2ops.c
48946 +++ b/fs/cifs/smb2ops.c
48947 @@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
48948 #ifdef CONFIG_CIFS_STATS
48949 int i;
48950 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
48951 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
48952 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
48953 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
48954 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
48955 }
48956 #endif
48957 }
48958 @@ -284,66 +284,66 @@ static void
48959 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
48960 {
48961 #ifdef CONFIG_CIFS_STATS
48962 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
48963 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
48964 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
48965 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
48966 seq_printf(m, "\nNegotiates: %d sent %d failed",
48967 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
48968 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
48969 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
48970 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
48971 seq_printf(m, "\nSessionSetups: %d sent %d failed",
48972 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
48973 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
48974 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
48975 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
48976 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
48977 seq_printf(m, "\nLogoffs: %d sent %d failed",
48978 - atomic_read(&sent[SMB2_LOGOFF_HE]),
48979 - atomic_read(&failed[SMB2_LOGOFF_HE]));
48980 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
48981 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
48982 seq_printf(m, "\nTreeConnects: %d sent %d failed",
48983 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
48984 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
48985 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
48986 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
48987 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
48988 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
48989 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
48990 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
48991 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
48992 seq_printf(m, "\nCreates: %d sent %d failed",
48993 - atomic_read(&sent[SMB2_CREATE_HE]),
48994 - atomic_read(&failed[SMB2_CREATE_HE]));
48995 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
48996 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
48997 seq_printf(m, "\nCloses: %d sent %d failed",
48998 - atomic_read(&sent[SMB2_CLOSE_HE]),
48999 - atomic_read(&failed[SMB2_CLOSE_HE]));
49000 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
49001 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
49002 seq_printf(m, "\nFlushes: %d sent %d failed",
49003 - atomic_read(&sent[SMB2_FLUSH_HE]),
49004 - atomic_read(&failed[SMB2_FLUSH_HE]));
49005 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
49006 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
49007 seq_printf(m, "\nReads: %d sent %d failed",
49008 - atomic_read(&sent[SMB2_READ_HE]),
49009 - atomic_read(&failed[SMB2_READ_HE]));
49010 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
49011 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
49012 seq_printf(m, "\nWrites: %d sent %d failed",
49013 - atomic_read(&sent[SMB2_WRITE_HE]),
49014 - atomic_read(&failed[SMB2_WRITE_HE]));
49015 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
49016 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
49017 seq_printf(m, "\nLocks: %d sent %d failed",
49018 - atomic_read(&sent[SMB2_LOCK_HE]),
49019 - atomic_read(&failed[SMB2_LOCK_HE]));
49020 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
49021 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
49022 seq_printf(m, "\nIOCTLs: %d sent %d failed",
49023 - atomic_read(&sent[SMB2_IOCTL_HE]),
49024 - atomic_read(&failed[SMB2_IOCTL_HE]));
49025 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
49026 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
49027 seq_printf(m, "\nCancels: %d sent %d failed",
49028 - atomic_read(&sent[SMB2_CANCEL_HE]),
49029 - atomic_read(&failed[SMB2_CANCEL_HE]));
49030 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
49031 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
49032 seq_printf(m, "\nEchos: %d sent %d failed",
49033 - atomic_read(&sent[SMB2_ECHO_HE]),
49034 - atomic_read(&failed[SMB2_ECHO_HE]));
49035 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
49036 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
49037 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
49038 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
49039 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
49040 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
49041 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
49042 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
49043 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
49044 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
49045 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
49046 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
49047 seq_printf(m, "\nQueryInfos: %d sent %d failed",
49048 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
49049 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
49050 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
49051 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
49052 seq_printf(m, "\nSetInfos: %d sent %d failed",
49053 - atomic_read(&sent[SMB2_SET_INFO_HE]),
49054 - atomic_read(&failed[SMB2_SET_INFO_HE]));
49055 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
49056 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
49057 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
49058 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
49059 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
49060 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
49061 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
49062 #endif
49063 }
49064
49065 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
49066 index 41d9d07..dbb4772 100644
49067 --- a/fs/cifs/smb2pdu.c
49068 +++ b/fs/cifs/smb2pdu.c
49069 @@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
49070 default:
49071 cERROR(1, "info level %u isn't supported",
49072 srch_inf->info_level);
49073 - rc = -EINVAL;
49074 - goto qdir_exit;
49075 + return -EINVAL;
49076 }
49077
49078 req->FileIndex = cpu_to_le32(index);
49079 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
49080 index 958ae0e..505c9d0 100644
49081 --- a/fs/coda/cache.c
49082 +++ b/fs/coda/cache.c
49083 @@ -24,7 +24,7 @@
49084 #include "coda_linux.h"
49085 #include "coda_cache.h"
49086
49087 -static atomic_t permission_epoch = ATOMIC_INIT(0);
49088 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
49089
49090 /* replace or extend an acl cache hit */
49091 void coda_cache_enter(struct inode *inode, int mask)
49092 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
49093 struct coda_inode_info *cii = ITOC(inode);
49094
49095 spin_lock(&cii->c_lock);
49096 - cii->c_cached_epoch = atomic_read(&permission_epoch);
49097 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
49098 if (cii->c_uid != current_fsuid()) {
49099 cii->c_uid = current_fsuid();
49100 cii->c_cached_perm = mask;
49101 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
49102 {
49103 struct coda_inode_info *cii = ITOC(inode);
49104 spin_lock(&cii->c_lock);
49105 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
49106 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
49107 spin_unlock(&cii->c_lock);
49108 }
49109
49110 /* remove all acl caches */
49111 void coda_cache_clear_all(struct super_block *sb)
49112 {
49113 - atomic_inc(&permission_epoch);
49114 + atomic_inc_unchecked(&permission_epoch);
49115 }
49116
49117
49118 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
49119 spin_lock(&cii->c_lock);
49120 hit = (mask & cii->c_cached_perm) == mask &&
49121 cii->c_uid == current_fsuid() &&
49122 - cii->c_cached_epoch == atomic_read(&permission_epoch);
49123 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
49124 spin_unlock(&cii->c_lock);
49125
49126 return hit;
49127 diff --git a/fs/compat.c b/fs/compat.c
49128 index 015e1e1..b8966ac 100644
49129 --- a/fs/compat.c
49130 +++ b/fs/compat.c
49131 @@ -54,7 +54,7 @@
49132 #include <asm/ioctls.h>
49133 #include "internal.h"
49134
49135 -int compat_log = 1;
49136 +int compat_log = 0;
49137
49138 int compat_printk(const char *fmt, ...)
49139 {
49140 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
49141
49142 set_fs(KERNEL_DS);
49143 /* The __user pointer cast is valid because of the set_fs() */
49144 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
49145 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
49146 set_fs(oldfs);
49147 /* truncating is ok because it's a user address */
49148 if (!ret)
49149 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
49150 goto out;
49151
49152 ret = -EINVAL;
49153 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
49154 + if (nr_segs > UIO_MAXIOV)
49155 goto out;
49156 if (nr_segs > fast_segs) {
49157 ret = -ENOMEM;
49158 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
49159
49160 struct compat_readdir_callback {
49161 struct compat_old_linux_dirent __user *dirent;
49162 + struct file * file;
49163 int result;
49164 };
49165
49166 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
49167 buf->result = -EOVERFLOW;
49168 return -EOVERFLOW;
49169 }
49170 +
49171 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49172 + return 0;
49173 +
49174 buf->result++;
49175 dirent = buf->dirent;
49176 if (!access_ok(VERIFY_WRITE, dirent,
49177 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
49178
49179 buf.result = 0;
49180 buf.dirent = dirent;
49181 + buf.file = f.file;
49182
49183 error = vfs_readdir(f.file, compat_fillonedir, &buf);
49184 if (buf.result)
49185 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
49186 struct compat_getdents_callback {
49187 struct compat_linux_dirent __user *current_dir;
49188 struct compat_linux_dirent __user *previous;
49189 + struct file * file;
49190 int count;
49191 int error;
49192 };
49193 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
49194 buf->error = -EOVERFLOW;
49195 return -EOVERFLOW;
49196 }
49197 +
49198 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49199 + return 0;
49200 +
49201 dirent = buf->previous;
49202 if (dirent) {
49203 if (__put_user(offset, &dirent->d_off))
49204 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49205 buf.previous = NULL;
49206 buf.count = count;
49207 buf.error = 0;
49208 + buf.file = f.file;
49209
49210 error = vfs_readdir(f.file, compat_filldir, &buf);
49211 if (error >= 0)
49212 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49213 struct compat_getdents_callback64 {
49214 struct linux_dirent64 __user *current_dir;
49215 struct linux_dirent64 __user *previous;
49216 + struct file * file;
49217 int count;
49218 int error;
49219 };
49220 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
49221 buf->error = -EINVAL; /* only used if we fail.. */
49222 if (reclen > buf->count)
49223 return -EINVAL;
49224 +
49225 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49226 + return 0;
49227 +
49228 dirent = buf->previous;
49229
49230 if (dirent) {
49231 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
49232 buf.previous = NULL;
49233 buf.count = count;
49234 buf.error = 0;
49235 + buf.file = f.file;
49236
49237 error = vfs_readdir(f.file, compat_filldir64, &buf);
49238 if (error >= 0)
49239 error = buf.error;
49240 lastdirent = buf.previous;
49241 if (lastdirent) {
49242 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
49243 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
49244 if (__put_user_unaligned(d_off, &lastdirent->d_off))
49245 error = -EFAULT;
49246 else
49247 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
49248 index a81147e..20bf2b5 100644
49249 --- a/fs/compat_binfmt_elf.c
49250 +++ b/fs/compat_binfmt_elf.c
49251 @@ -30,11 +30,13 @@
49252 #undef elf_phdr
49253 #undef elf_shdr
49254 #undef elf_note
49255 +#undef elf_dyn
49256 #undef elf_addr_t
49257 #define elfhdr elf32_hdr
49258 #define elf_phdr elf32_phdr
49259 #define elf_shdr elf32_shdr
49260 #define elf_note elf32_note
49261 +#define elf_dyn Elf32_Dyn
49262 #define elf_addr_t Elf32_Addr
49263
49264 /*
49265 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
49266 index e2f57a0..3c78771 100644
49267 --- a/fs/compat_ioctl.c
49268 +++ b/fs/compat_ioctl.c
49269 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
49270 return -EFAULT;
49271 if (__get_user(udata, &ss32->iomem_base))
49272 return -EFAULT;
49273 - ss.iomem_base = compat_ptr(udata);
49274 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
49275 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
49276 __get_user(ss.port_high, &ss32->port_high))
49277 return -EFAULT;
49278 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
49279 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
49280 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
49281 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
49282 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49283 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49284 return -EFAULT;
49285
49286 return ioctl_preallocate(file, p);
49287 @@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
49288 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
49289 {
49290 unsigned int a, b;
49291 - a = *(unsigned int *)p;
49292 - b = *(unsigned int *)q;
49293 + a = *(const unsigned int *)p;
49294 + b = *(const unsigned int *)q;
49295 if (a > b)
49296 return 1;
49297 if (a < b)
49298 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
49299 index 712b10f..c33c4ca 100644
49300 --- a/fs/configfs/dir.c
49301 +++ b/fs/configfs/dir.c
49302 @@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
49303 static int configfs_depend_prep(struct dentry *origin,
49304 struct config_item *target)
49305 {
49306 - struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
49307 + struct configfs_dirent *child_sd, *sd;
49308 int ret = 0;
49309
49310 - BUG_ON(!origin || !sd);
49311 + BUG_ON(!origin || !origin->d_fsdata);
49312 + sd = origin->d_fsdata;
49313
49314 if (sd->s_element == target) /* Boo-yah */
49315 goto out;
49316 @@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49317 }
49318 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
49319 struct configfs_dirent *next;
49320 - const char * name;
49321 + const unsigned char * name;
49322 + char d_name[sizeof(next->s_dentry->d_iname)];
49323 int len;
49324 struct inode *inode = NULL;
49325
49326 @@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49327 continue;
49328
49329 name = configfs_get_name(next);
49330 - len = strlen(name);
49331 + if (next->s_dentry && name == next->s_dentry->d_iname) {
49332 + len = next->s_dentry->d_name.len;
49333 + memcpy(d_name, name, len);
49334 + name = d_name;
49335 + } else
49336 + len = strlen(name);
49337
49338 /*
49339 * We'll have a dentry and an inode for
49340 diff --git a/fs/coredump.c b/fs/coredump.c
49341 index 1774932..5812106 100644
49342 --- a/fs/coredump.c
49343 +++ b/fs/coredump.c
49344 @@ -52,7 +52,7 @@ struct core_name {
49345 char *corename;
49346 int used, size;
49347 };
49348 -static atomic_t call_count = ATOMIC_INIT(1);
49349 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
49350
49351 /* The maximal length of core_pattern is also specified in sysctl.c */
49352
49353 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
49354 {
49355 char *old_corename = cn->corename;
49356
49357 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
49358 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
49359 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
49360
49361 if (!cn->corename) {
49362 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
49363 int pid_in_pattern = 0;
49364 int err = 0;
49365
49366 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
49367 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
49368 cn->corename = kmalloc(cn->size, GFP_KERNEL);
49369 cn->used = 0;
49370
49371 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
49372 pipe = file->f_path.dentry->d_inode->i_pipe;
49373
49374 pipe_lock(pipe);
49375 - pipe->readers++;
49376 - pipe->writers--;
49377 + atomic_inc(&pipe->readers);
49378 + atomic_dec(&pipe->writers);
49379
49380 - while ((pipe->readers > 1) && (!signal_pending(current))) {
49381 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
49382 wake_up_interruptible_sync(&pipe->wait);
49383 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49384 pipe_wait(pipe);
49385 }
49386
49387 - pipe->readers--;
49388 - pipe->writers++;
49389 + atomic_dec(&pipe->readers);
49390 + atomic_inc(&pipe->writers);
49391 pipe_unlock(pipe);
49392
49393 }
49394 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
49395 int ispipe;
49396 struct files_struct *displaced;
49397 bool need_nonrelative = false;
49398 - static atomic_t core_dump_count = ATOMIC_INIT(0);
49399 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
49400 + long signr = siginfo->si_signo;
49401 struct coredump_params cprm = {
49402 .siginfo = siginfo,
49403 .regs = signal_pt_regs(),
49404 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
49405 .mm_flags = mm->flags,
49406 };
49407
49408 - audit_core_dumps(siginfo->si_signo);
49409 + audit_core_dumps(signr);
49410 +
49411 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
49412 + gr_handle_brute_attach(cprm.mm_flags);
49413
49414 binfmt = mm->binfmt;
49415 if (!binfmt || !binfmt->core_dump)
49416 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
49417 need_nonrelative = true;
49418 }
49419
49420 - retval = coredump_wait(siginfo->si_signo, &core_state);
49421 + retval = coredump_wait(signr, &core_state);
49422 if (retval < 0)
49423 goto fail_creds;
49424
49425 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
49426 }
49427 cprm.limit = RLIM_INFINITY;
49428
49429 - dump_count = atomic_inc_return(&core_dump_count);
49430 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
49431 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
49432 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
49433 task_tgid_vnr(current), current->comm);
49434 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
49435 } else {
49436 struct inode *inode;
49437
49438 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
49439 +
49440 if (cprm.limit < binfmt->min_coredump)
49441 goto fail_unlock;
49442
49443 @@ -640,7 +646,7 @@ close_fail:
49444 filp_close(cprm.file, NULL);
49445 fail_dropcount:
49446 if (ispipe)
49447 - atomic_dec(&core_dump_count);
49448 + atomic_dec_unchecked(&core_dump_count);
49449 fail_unlock:
49450 kfree(cn.corename);
49451 fail_corename:
49452 @@ -659,7 +665,7 @@ fail:
49453 */
49454 int dump_write(struct file *file, const void *addr, int nr)
49455 {
49456 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
49457 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
49458 }
49459 EXPORT_SYMBOL(dump_write);
49460
49461 diff --git a/fs/dcache.c b/fs/dcache.c
49462 index 19153a0..428c2f5 100644
49463 --- a/fs/dcache.c
49464 +++ b/fs/dcache.c
49465 @@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
49466 mempages -= reserve;
49467
49468 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
49469 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
49470 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
49471
49472 dcache_init();
49473 inode_init();
49474 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
49475 index a5f12b7..4ee8a6f 100644
49476 --- a/fs/debugfs/inode.c
49477 +++ b/fs/debugfs/inode.c
49478 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
49479 */
49480 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
49481 {
49482 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49483 + return __create_file(name, S_IFDIR | S_IRWXU,
49484 +#else
49485 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
49486 +#endif
49487 parent, NULL, NULL);
49488 }
49489 EXPORT_SYMBOL_GPL(debugfs_create_dir);
49490 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
49491 index cc7709e..7e7211f 100644
49492 --- a/fs/ecryptfs/inode.c
49493 +++ b/fs/ecryptfs/inode.c
49494 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
49495 old_fs = get_fs();
49496 set_fs(get_ds());
49497 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
49498 - (char __user *)lower_buf,
49499 + (char __force_user *)lower_buf,
49500 PATH_MAX);
49501 set_fs(old_fs);
49502 if (rc < 0)
49503 @@ -706,7 +706,7 @@ out:
49504 static void
49505 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
49506 {
49507 - char *buf = nd_get_link(nd);
49508 + const char *buf = nd_get_link(nd);
49509 if (!IS_ERR(buf)) {
49510 /* Free the char* */
49511 kfree(buf);
49512 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
49513 index 412e6ed..4292d22 100644
49514 --- a/fs/ecryptfs/miscdev.c
49515 +++ b/fs/ecryptfs/miscdev.c
49516 @@ -315,7 +315,7 @@ check_list:
49517 goto out_unlock_msg_ctx;
49518 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
49519 if (msg_ctx->msg) {
49520 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
49521 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
49522 goto out_unlock_msg_ctx;
49523 i += packet_length_size;
49524 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
49525 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
49526 index b2a34a1..162fa69 100644
49527 --- a/fs/ecryptfs/read_write.c
49528 +++ b/fs/ecryptfs/read_write.c
49529 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
49530 return -EIO;
49531 fs_save = get_fs();
49532 set_fs(get_ds());
49533 - rc = vfs_write(lower_file, data, size, &offset);
49534 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
49535 set_fs(fs_save);
49536 mark_inode_dirty_sync(ecryptfs_inode);
49537 return rc;
49538 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
49539 return -EIO;
49540 fs_save = get_fs();
49541 set_fs(get_ds());
49542 - rc = vfs_read(lower_file, data, size, &offset);
49543 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
49544 set_fs(fs_save);
49545 return rc;
49546 }
49547 diff --git a/fs/exec.c b/fs/exec.c
49548 index 20df02c..9b8f78d 100644
49549 --- a/fs/exec.c
49550 +++ b/fs/exec.c
49551 @@ -55,6 +55,17 @@
49552 #include <linux/pipe_fs_i.h>
49553 #include <linux/oom.h>
49554 #include <linux/compat.h>
49555 +#include <linux/random.h>
49556 +#include <linux/seq_file.h>
49557 +#include <linux/coredump.h>
49558 +#include <linux/mman.h>
49559 +
49560 +#ifdef CONFIG_PAX_REFCOUNT
49561 +#include <linux/kallsyms.h>
49562 +#include <linux/kdebug.h>
49563 +#endif
49564 +
49565 +#include <trace/events/fs.h>
49566
49567 #include <asm/uaccess.h>
49568 #include <asm/mmu_context.h>
49569 @@ -66,6 +77,18 @@
49570
49571 #include <trace/events/sched.h>
49572
49573 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49574 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
49575 +{
49576 + 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");
49577 +}
49578 +#endif
49579 +
49580 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
49581 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
49582 +EXPORT_SYMBOL(pax_set_initial_flags_func);
49583 +#endif
49584 +
49585 int suid_dumpable = 0;
49586
49587 static LIST_HEAD(formats);
49588 @@ -75,8 +98,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
49589 {
49590 BUG_ON(!fmt);
49591 write_lock(&binfmt_lock);
49592 - insert ? list_add(&fmt->lh, &formats) :
49593 - list_add_tail(&fmt->lh, &formats);
49594 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
49595 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
49596 write_unlock(&binfmt_lock);
49597 }
49598
49599 @@ -85,7 +108,7 @@ EXPORT_SYMBOL(__register_binfmt);
49600 void unregister_binfmt(struct linux_binfmt * fmt)
49601 {
49602 write_lock(&binfmt_lock);
49603 - list_del(&fmt->lh);
49604 + pax_list_del((struct list_head *)&fmt->lh);
49605 write_unlock(&binfmt_lock);
49606 }
49607
49608 @@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
49609 int write)
49610 {
49611 struct page *page;
49612 - int ret;
49613
49614 -#ifdef CONFIG_STACK_GROWSUP
49615 - if (write) {
49616 - ret = expand_downwards(bprm->vma, pos);
49617 - if (ret < 0)
49618 - return NULL;
49619 - }
49620 -#endif
49621 - ret = get_user_pages(current, bprm->mm, pos,
49622 - 1, write, 1, &page, NULL);
49623 - if (ret <= 0)
49624 + if (0 > expand_downwards(bprm->vma, pos))
49625 + return NULL;
49626 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
49627 return NULL;
49628
49629 if (write) {
49630 @@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
49631 if (size <= ARG_MAX)
49632 return page;
49633
49634 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49635 + // only allow 512KB for argv+env on suid/sgid binaries
49636 + // to prevent easy ASLR exhaustion
49637 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
49638 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
49639 + (size > (512 * 1024))) {
49640 + put_page(page);
49641 + return NULL;
49642 + }
49643 +#endif
49644 +
49645 /*
49646 * Limit to 1/4-th the stack size for the argv+env strings.
49647 * This ensures that:
49648 @@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
49649 vma->vm_end = STACK_TOP_MAX;
49650 vma->vm_start = vma->vm_end - PAGE_SIZE;
49651 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
49652 +
49653 +#ifdef CONFIG_PAX_SEGMEXEC
49654 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
49655 +#endif
49656 +
49657 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
49658 INIT_LIST_HEAD(&vma->anon_vma_chain);
49659
49660 @@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
49661 mm->stack_vm = mm->total_vm = 1;
49662 up_write(&mm->mmap_sem);
49663 bprm->p = vma->vm_end - sizeof(void *);
49664 +
49665 +#ifdef CONFIG_PAX_RANDUSTACK
49666 + if (randomize_va_space)
49667 + bprm->p ^= random32() & ~PAGE_MASK;
49668 +#endif
49669 +
49670 return 0;
49671 err:
49672 up_write(&mm->mmap_sem);
49673 @@ -384,19 +421,7 @@ err:
49674 return err;
49675 }
49676
49677 -struct user_arg_ptr {
49678 -#ifdef CONFIG_COMPAT
49679 - bool is_compat;
49680 -#endif
49681 - union {
49682 - const char __user *const __user *native;
49683 -#ifdef CONFIG_COMPAT
49684 - const compat_uptr_t __user *compat;
49685 -#endif
49686 - } ptr;
49687 -};
49688 -
49689 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49690 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49691 {
49692 const char __user *native;
49693
49694 @@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49695 compat_uptr_t compat;
49696
49697 if (get_user(compat, argv.ptr.compat + nr))
49698 - return ERR_PTR(-EFAULT);
49699 + return (const char __force_user *)ERR_PTR(-EFAULT);
49700
49701 return compat_ptr(compat);
49702 }
49703 #endif
49704
49705 if (get_user(native, argv.ptr.native + nr))
49706 - return ERR_PTR(-EFAULT);
49707 + return (const char __force_user *)ERR_PTR(-EFAULT);
49708
49709 return native;
49710 }
49711 @@ -431,7 +456,7 @@ static int count(struct user_arg_ptr argv, int max)
49712 if (!p)
49713 break;
49714
49715 - if (IS_ERR(p))
49716 + if (IS_ERR((const char __force_kernel *)p))
49717 return -EFAULT;
49718
49719 if (i >= max)
49720 @@ -466,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
49721
49722 ret = -EFAULT;
49723 str = get_user_arg_ptr(argv, argc);
49724 - if (IS_ERR(str))
49725 + if (IS_ERR((const char __force_kernel *)str))
49726 goto out;
49727
49728 len = strnlen_user(str, MAX_ARG_STRLEN);
49729 @@ -548,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
49730 int r;
49731 mm_segment_t oldfs = get_fs();
49732 struct user_arg_ptr argv = {
49733 - .ptr.native = (const char __user *const __user *)__argv,
49734 + .ptr.native = (const char __force_user *const __force_user *)__argv,
49735 };
49736
49737 set_fs(KERNEL_DS);
49738 @@ -583,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
49739 unsigned long new_end = old_end - shift;
49740 struct mmu_gather tlb;
49741
49742 - BUG_ON(new_start > new_end);
49743 + if (new_start >= new_end || new_start < mmap_min_addr)
49744 + return -ENOMEM;
49745
49746 /*
49747 * ensure there are no vmas between where we want to go
49748 @@ -592,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
49749 if (vma != find_vma(mm, new_start))
49750 return -EFAULT;
49751
49752 +#ifdef CONFIG_PAX_SEGMEXEC
49753 + BUG_ON(pax_find_mirror_vma(vma));
49754 +#endif
49755 +
49756 /*
49757 * cover the whole range: [new_start, old_end)
49758 */
49759 @@ -672,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
49760 stack_top = arch_align_stack(stack_top);
49761 stack_top = PAGE_ALIGN(stack_top);
49762
49763 - if (unlikely(stack_top < mmap_min_addr) ||
49764 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
49765 - return -ENOMEM;
49766 -
49767 stack_shift = vma->vm_end - stack_top;
49768
49769 bprm->p -= stack_shift;
49770 @@ -687,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
49771 bprm->exec -= stack_shift;
49772
49773 down_write(&mm->mmap_sem);
49774 +
49775 + /* Move stack pages down in memory. */
49776 + if (stack_shift) {
49777 + ret = shift_arg_pages(vma, stack_shift);
49778 + if (ret)
49779 + goto out_unlock;
49780 + }
49781 +
49782 vm_flags = VM_STACK_FLAGS;
49783
49784 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49785 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49786 + vm_flags &= ~VM_EXEC;
49787 +
49788 +#ifdef CONFIG_PAX_MPROTECT
49789 + if (mm->pax_flags & MF_PAX_MPROTECT)
49790 + vm_flags &= ~VM_MAYEXEC;
49791 +#endif
49792 +
49793 + }
49794 +#endif
49795 +
49796 /*
49797 * Adjust stack execute permissions; explicitly enable for
49798 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
49799 @@ -707,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
49800 goto out_unlock;
49801 BUG_ON(prev != vma);
49802
49803 - /* Move stack pages down in memory. */
49804 - if (stack_shift) {
49805 - ret = shift_arg_pages(vma, stack_shift);
49806 - if (ret)
49807 - goto out_unlock;
49808 - }
49809 -
49810 /* mprotect_fixup is overkill to remove the temporary stack flags */
49811 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
49812
49813 @@ -737,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
49814 #endif
49815 current->mm->start_stack = bprm->p;
49816 ret = expand_stack(vma, stack_base);
49817 +
49818 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
49819 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
49820 + unsigned long size, flags, vm_flags;
49821 +
49822 + size = STACK_TOP - vma->vm_end;
49823 + flags = MAP_FIXED | MAP_PRIVATE;
49824 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
49825 +
49826 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
49827 +
49828 +#ifdef CONFIG_X86
49829 + if (!ret) {
49830 + size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
49831 + ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
49832 + }
49833 +#endif
49834 +
49835 + }
49836 +#endif
49837 +
49838 if (ret)
49839 ret = -EFAULT;
49840
49841 @@ -772,6 +832,8 @@ struct file *open_exec(const char *name)
49842
49843 fsnotify_open(file);
49844
49845 + trace_open_exec(name);
49846 +
49847 err = deny_write_access(file);
49848 if (err)
49849 goto exit;
49850 @@ -795,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
49851 old_fs = get_fs();
49852 set_fs(get_ds());
49853 /* The cast to a user pointer is valid due to the set_fs() */
49854 - result = vfs_read(file, (void __user *)addr, count, &pos);
49855 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
49856 set_fs(old_fs);
49857 return result;
49858 }
49859 @@ -1247,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
49860 }
49861 rcu_read_unlock();
49862
49863 - if (p->fs->users > n_fs) {
49864 + if (atomic_read(&p->fs->users) > n_fs) {
49865 bprm->unsafe |= LSM_UNSAFE_SHARE;
49866 } else {
49867 res = -EAGAIN;
49868 @@ -1447,6 +1509,28 @@ int search_binary_handler(struct linux_binprm *bprm)
49869
49870 EXPORT_SYMBOL(search_binary_handler);
49871
49872 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49873 +static DEFINE_PER_CPU(u64, exec_counter);
49874 +static int __init init_exec_counters(void)
49875 +{
49876 + unsigned int cpu;
49877 +
49878 + for_each_possible_cpu(cpu) {
49879 + per_cpu(exec_counter, cpu) = (u64)cpu;
49880 + }
49881 +
49882 + return 0;
49883 +}
49884 +early_initcall(init_exec_counters);
49885 +static inline void increment_exec_counter(void)
49886 +{
49887 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
49888 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
49889 +}
49890 +#else
49891 +static inline void increment_exec_counter(void) {}
49892 +#endif
49893 +
49894 /*
49895 * sys_execve() executes a new program.
49896 */
49897 @@ -1454,6 +1538,11 @@ static int do_execve_common(const char *filename,
49898 struct user_arg_ptr argv,
49899 struct user_arg_ptr envp)
49900 {
49901 +#ifdef CONFIG_GRKERNSEC
49902 + struct file *old_exec_file;
49903 + struct acl_subject_label *old_acl;
49904 + struct rlimit old_rlim[RLIM_NLIMITS];
49905 +#endif
49906 struct linux_binprm *bprm;
49907 struct file *file;
49908 struct files_struct *displaced;
49909 @@ -1461,6 +1550,8 @@ static int do_execve_common(const char *filename,
49910 int retval;
49911 const struct cred *cred = current_cred();
49912
49913 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
49914 +
49915 /*
49916 * We move the actual failure in case of RLIMIT_NPROC excess from
49917 * set*uid() to execve() because too many poorly written programs
49918 @@ -1501,12 +1592,27 @@ static int do_execve_common(const char *filename,
49919 if (IS_ERR(file))
49920 goto out_unmark;
49921
49922 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
49923 + retval = -EPERM;
49924 + goto out_file;
49925 + }
49926 +
49927 sched_exec();
49928
49929 bprm->file = file;
49930 bprm->filename = filename;
49931 bprm->interp = filename;
49932
49933 + if (gr_process_user_ban()) {
49934 + retval = -EPERM;
49935 + goto out_file;
49936 + }
49937 +
49938 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
49939 + retval = -EACCES;
49940 + goto out_file;
49941 + }
49942 +
49943 retval = bprm_mm_init(bprm);
49944 if (retval)
49945 goto out_file;
49946 @@ -1523,24 +1629,65 @@ static int do_execve_common(const char *filename,
49947 if (retval < 0)
49948 goto out;
49949
49950 +#ifdef CONFIG_GRKERNSEC
49951 + old_acl = current->acl;
49952 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
49953 + old_exec_file = current->exec_file;
49954 + get_file(file);
49955 + current->exec_file = file;
49956 +#endif
49957 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49958 + /* limit suid stack to 8MB
49959 + * we saved the old limits above and will restore them if this exec fails
49960 + */
49961 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
49962 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
49963 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
49964 +#endif
49965 +
49966 + if (!gr_tpe_allow(file)) {
49967 + retval = -EACCES;
49968 + goto out_fail;
49969 + }
49970 +
49971 + if (gr_check_crash_exec(file)) {
49972 + retval = -EACCES;
49973 + goto out_fail;
49974 + }
49975 +
49976 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
49977 + bprm->unsafe);
49978 + if (retval < 0)
49979 + goto out_fail;
49980 +
49981 retval = copy_strings_kernel(1, &bprm->filename, bprm);
49982 if (retval < 0)
49983 - goto out;
49984 + goto out_fail;
49985
49986 bprm->exec = bprm->p;
49987 retval = copy_strings(bprm->envc, envp, bprm);
49988 if (retval < 0)
49989 - goto out;
49990 + goto out_fail;
49991
49992 retval = copy_strings(bprm->argc, argv, bprm);
49993 if (retval < 0)
49994 - goto out;
49995 + goto out_fail;
49996 +
49997 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
49998 +
49999 + gr_handle_exec_args(bprm, argv);
50000
50001 retval = search_binary_handler(bprm);
50002 if (retval < 0)
50003 - goto out;
50004 + goto out_fail;
50005 +#ifdef CONFIG_GRKERNSEC
50006 + if (old_exec_file)
50007 + fput(old_exec_file);
50008 +#endif
50009
50010 /* execve succeeded */
50011 +
50012 + increment_exec_counter();
50013 current->fs->in_exec = 0;
50014 current->in_execve = 0;
50015 acct_update_integrals(current);
50016 @@ -1549,6 +1696,14 @@ static int do_execve_common(const char *filename,
50017 put_files_struct(displaced);
50018 return retval;
50019
50020 +out_fail:
50021 +#ifdef CONFIG_GRKERNSEC
50022 + current->acl = old_acl;
50023 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
50024 + fput(current->exec_file);
50025 + current->exec_file = old_exec_file;
50026 +#endif
50027 +
50028 out:
50029 if (bprm->mm) {
50030 acct_arg_size(bprm, 0);
50031 @@ -1697,3 +1852,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
50032 return error;
50033 }
50034 #endif
50035 +
50036 +int pax_check_flags(unsigned long *flags)
50037 +{
50038 + int retval = 0;
50039 +
50040 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
50041 + if (*flags & MF_PAX_SEGMEXEC)
50042 + {
50043 + *flags &= ~MF_PAX_SEGMEXEC;
50044 + retval = -EINVAL;
50045 + }
50046 +#endif
50047 +
50048 + if ((*flags & MF_PAX_PAGEEXEC)
50049 +
50050 +#ifdef CONFIG_PAX_PAGEEXEC
50051 + && (*flags & MF_PAX_SEGMEXEC)
50052 +#endif
50053 +
50054 + )
50055 + {
50056 + *flags &= ~MF_PAX_PAGEEXEC;
50057 + retval = -EINVAL;
50058 + }
50059 +
50060 + if ((*flags & MF_PAX_MPROTECT)
50061 +
50062 +#ifdef CONFIG_PAX_MPROTECT
50063 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50064 +#endif
50065 +
50066 + )
50067 + {
50068 + *flags &= ~MF_PAX_MPROTECT;
50069 + retval = -EINVAL;
50070 + }
50071 +
50072 + if ((*flags & MF_PAX_EMUTRAMP)
50073 +
50074 +#ifdef CONFIG_PAX_EMUTRAMP
50075 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50076 +#endif
50077 +
50078 + )
50079 + {
50080 + *flags &= ~MF_PAX_EMUTRAMP;
50081 + retval = -EINVAL;
50082 + }
50083 +
50084 + return retval;
50085 +}
50086 +
50087 +EXPORT_SYMBOL(pax_check_flags);
50088 +
50089 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50090 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
50091 +{
50092 + struct task_struct *tsk = current;
50093 + struct mm_struct *mm = current->mm;
50094 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
50095 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
50096 + char *path_exec = NULL;
50097 + char *path_fault = NULL;
50098 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
50099 + siginfo_t info = { };
50100 +
50101 + if (buffer_exec && buffer_fault) {
50102 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
50103 +
50104 + down_read(&mm->mmap_sem);
50105 + vma = mm->mmap;
50106 + while (vma && (!vma_exec || !vma_fault)) {
50107 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
50108 + vma_exec = vma;
50109 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
50110 + vma_fault = vma;
50111 + vma = vma->vm_next;
50112 + }
50113 + if (vma_exec) {
50114 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
50115 + if (IS_ERR(path_exec))
50116 + path_exec = "<path too long>";
50117 + else {
50118 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
50119 + if (path_exec) {
50120 + *path_exec = 0;
50121 + path_exec = buffer_exec;
50122 + } else
50123 + path_exec = "<path too long>";
50124 + }
50125 + }
50126 + if (vma_fault) {
50127 + start = vma_fault->vm_start;
50128 + end = vma_fault->vm_end;
50129 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
50130 + if (vma_fault->vm_file) {
50131 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
50132 + if (IS_ERR(path_fault))
50133 + path_fault = "<path too long>";
50134 + else {
50135 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
50136 + if (path_fault) {
50137 + *path_fault = 0;
50138 + path_fault = buffer_fault;
50139 + } else
50140 + path_fault = "<path too long>";
50141 + }
50142 + } else
50143 + path_fault = "<anonymous mapping>";
50144 + }
50145 + up_read(&mm->mmap_sem);
50146 + }
50147 + if (tsk->signal->curr_ip)
50148 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
50149 + else
50150 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
50151 + 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),
50152 + from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
50153 + free_page((unsigned long)buffer_exec);
50154 + free_page((unsigned long)buffer_fault);
50155 + pax_report_insns(regs, pc, sp);
50156 + info.si_signo = SIGKILL;
50157 + info.si_errno = 0;
50158 + info.si_code = SI_KERNEL;
50159 + info.si_pid = 0;
50160 + info.si_uid = 0;
50161 + do_coredump(&info);
50162 +}
50163 +#endif
50164 +
50165 +#ifdef CONFIG_PAX_REFCOUNT
50166 +void pax_report_refcount_overflow(struct pt_regs *regs)
50167 +{
50168 + if (current->signal->curr_ip)
50169 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
50170 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
50171 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
50172 + else
50173 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
50174 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
50175 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
50176 + show_regs(regs);
50177 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
50178 +}
50179 +#endif
50180 +
50181 +#ifdef CONFIG_PAX_USERCOPY
50182 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
50183 +static noinline int check_stack_object(const void *obj, unsigned long len)
50184 +{
50185 + const void * const stack = task_stack_page(current);
50186 + const void * const stackend = stack + THREAD_SIZE;
50187 +
50188 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50189 + const void *frame = NULL;
50190 + const void *oldframe;
50191 +#endif
50192 +
50193 + if (obj + len < obj)
50194 + return -1;
50195 +
50196 + if (obj + len <= stack || stackend <= obj)
50197 + return 0;
50198 +
50199 + if (obj < stack || stackend < obj + len)
50200 + return -1;
50201 +
50202 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50203 + oldframe = __builtin_frame_address(1);
50204 + if (oldframe)
50205 + frame = __builtin_frame_address(2);
50206 + /*
50207 + low ----------------------------------------------> high
50208 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
50209 + ^----------------^
50210 + allow copies only within here
50211 + */
50212 + while (stack <= frame && frame < stackend) {
50213 + /* if obj + len extends past the last frame, this
50214 + check won't pass and the next frame will be 0,
50215 + causing us to bail out and correctly report
50216 + the copy as invalid
50217 + */
50218 + if (obj + len <= frame)
50219 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
50220 + oldframe = frame;
50221 + frame = *(const void * const *)frame;
50222 + }
50223 + return -1;
50224 +#else
50225 + return 1;
50226 +#endif
50227 +}
50228 +
50229 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
50230 +{
50231 + if (current->signal->curr_ip)
50232 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50233 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50234 + else
50235 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50236 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50237 + dump_stack();
50238 + gr_handle_kernel_exploit();
50239 + do_group_exit(SIGKILL);
50240 +}
50241 +#endif
50242 +
50243 +void __check_object_size(const void *ptr, unsigned long n, bool to)
50244 +{
50245 +
50246 +#ifdef CONFIG_PAX_USERCOPY
50247 + const char *type;
50248 +
50249 + if (!n)
50250 + return;
50251 +
50252 + type = check_heap_object(ptr, n);
50253 + if (!type) {
50254 + if (check_stack_object(ptr, n) != -1)
50255 + return;
50256 + type = "<process stack>";
50257 + }
50258 +
50259 + pax_report_usercopy(ptr, n, to, type);
50260 +#endif
50261 +
50262 +}
50263 +EXPORT_SYMBOL(__check_object_size);
50264 +
50265 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
50266 +void pax_track_stack(void)
50267 +{
50268 + unsigned long sp = (unsigned long)&sp;
50269 + if (sp < current_thread_info()->lowest_stack &&
50270 + sp > (unsigned long)task_stack_page(current))
50271 + current_thread_info()->lowest_stack = sp;
50272 +}
50273 +EXPORT_SYMBOL(pax_track_stack);
50274 +#endif
50275 +
50276 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
50277 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
50278 +{
50279 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
50280 + dump_stack();
50281 + do_group_exit(SIGKILL);
50282 +}
50283 +EXPORT_SYMBOL(report_size_overflow);
50284 +#endif
50285 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
50286 index 2616d0e..2ffdec9 100644
50287 --- a/fs/ext2/balloc.c
50288 +++ b/fs/ext2/balloc.c
50289 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
50290
50291 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50292 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50293 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50294 + if (free_blocks < root_blocks + 1 &&
50295 !uid_eq(sbi->s_resuid, current_fsuid()) &&
50296 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50297 - !in_group_p (sbi->s_resgid))) {
50298 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50299 return 0;
50300 }
50301 return 1;
50302 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
50303 index 22548f5..41521d8 100644
50304 --- a/fs/ext3/balloc.c
50305 +++ b/fs/ext3/balloc.c
50306 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
50307
50308 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50309 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50310 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50311 + if (free_blocks < root_blocks + 1 &&
50312 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
50313 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50314 - !in_group_p (sbi->s_resgid))) {
50315 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50316 return 0;
50317 }
50318 return 1;
50319 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
50320 index 2f2e0da..89b113a 100644
50321 --- a/fs/ext4/balloc.c
50322 +++ b/fs/ext4/balloc.c
50323 @@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
50324 /* Hm, nope. Are (enough) root reserved clusters available? */
50325 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
50326 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
50327 - capable(CAP_SYS_RESOURCE) ||
50328 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
50329 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
50330 + capable_nolog(CAP_SYS_RESOURCE)) {
50331
50332 if (free_clusters >= (nclusters + dirty_clusters))
50333 return 1;
50334 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
50335 index 8462eb3..4a71af6 100644
50336 --- a/fs/ext4/ext4.h
50337 +++ b/fs/ext4/ext4.h
50338 @@ -1265,19 +1265,19 @@ struct ext4_sb_info {
50339 unsigned long s_mb_last_start;
50340
50341 /* stats for buddy allocator */
50342 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
50343 - atomic_t s_bal_success; /* we found long enough chunks */
50344 - atomic_t s_bal_allocated; /* in blocks */
50345 - atomic_t s_bal_ex_scanned; /* total extents scanned */
50346 - atomic_t s_bal_goals; /* goal hits */
50347 - atomic_t s_bal_breaks; /* too long searches */
50348 - atomic_t s_bal_2orders; /* 2^order hits */
50349 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
50350 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
50351 + atomic_unchecked_t s_bal_allocated; /* in blocks */
50352 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
50353 + atomic_unchecked_t s_bal_goals; /* goal hits */
50354 + atomic_unchecked_t s_bal_breaks; /* too long searches */
50355 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
50356 spinlock_t s_bal_lock;
50357 unsigned long s_mb_buddies_generated;
50358 unsigned long long s_mb_generation_time;
50359 - atomic_t s_mb_lost_chunks;
50360 - atomic_t s_mb_preallocated;
50361 - atomic_t s_mb_discarded;
50362 + atomic_unchecked_t s_mb_lost_chunks;
50363 + atomic_unchecked_t s_mb_preallocated;
50364 + atomic_unchecked_t s_mb_discarded;
50365 atomic_t s_lock_busy;
50366
50367 /* locality groups */
50368 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
50369 index 061727a..7622abf 100644
50370 --- a/fs/ext4/mballoc.c
50371 +++ b/fs/ext4/mballoc.c
50372 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
50373 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
50374
50375 if (EXT4_SB(sb)->s_mb_stats)
50376 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
50377 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
50378
50379 break;
50380 }
50381 @@ -2044,7 +2044,7 @@ repeat:
50382 ac->ac_status = AC_STATUS_CONTINUE;
50383 ac->ac_flags |= EXT4_MB_HINT_FIRST;
50384 cr = 3;
50385 - atomic_inc(&sbi->s_mb_lost_chunks);
50386 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
50387 goto repeat;
50388 }
50389 }
50390 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
50391 if (sbi->s_mb_stats) {
50392 ext4_msg(sb, KERN_INFO,
50393 "mballoc: %u blocks %u reqs (%u success)",
50394 - atomic_read(&sbi->s_bal_allocated),
50395 - atomic_read(&sbi->s_bal_reqs),
50396 - atomic_read(&sbi->s_bal_success));
50397 + atomic_read_unchecked(&sbi->s_bal_allocated),
50398 + atomic_read_unchecked(&sbi->s_bal_reqs),
50399 + atomic_read_unchecked(&sbi->s_bal_success));
50400 ext4_msg(sb, KERN_INFO,
50401 "mballoc: %u extents scanned, %u goal hits, "
50402 "%u 2^N hits, %u breaks, %u lost",
50403 - atomic_read(&sbi->s_bal_ex_scanned),
50404 - atomic_read(&sbi->s_bal_goals),
50405 - atomic_read(&sbi->s_bal_2orders),
50406 - atomic_read(&sbi->s_bal_breaks),
50407 - atomic_read(&sbi->s_mb_lost_chunks));
50408 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
50409 + atomic_read_unchecked(&sbi->s_bal_goals),
50410 + atomic_read_unchecked(&sbi->s_bal_2orders),
50411 + atomic_read_unchecked(&sbi->s_bal_breaks),
50412 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
50413 ext4_msg(sb, KERN_INFO,
50414 "mballoc: %lu generated and it took %Lu",
50415 sbi->s_mb_buddies_generated,
50416 sbi->s_mb_generation_time);
50417 ext4_msg(sb, KERN_INFO,
50418 "mballoc: %u preallocated, %u discarded",
50419 - atomic_read(&sbi->s_mb_preallocated),
50420 - atomic_read(&sbi->s_mb_discarded));
50421 + atomic_read_unchecked(&sbi->s_mb_preallocated),
50422 + atomic_read_unchecked(&sbi->s_mb_discarded));
50423 }
50424
50425 free_percpu(sbi->s_locality_groups);
50426 @@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
50427 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
50428
50429 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
50430 - atomic_inc(&sbi->s_bal_reqs);
50431 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50432 + atomic_inc_unchecked(&sbi->s_bal_reqs);
50433 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50434 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
50435 - atomic_inc(&sbi->s_bal_success);
50436 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
50437 + atomic_inc_unchecked(&sbi->s_bal_success);
50438 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
50439 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
50440 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
50441 - atomic_inc(&sbi->s_bal_goals);
50442 + atomic_inc_unchecked(&sbi->s_bal_goals);
50443 if (ac->ac_found > sbi->s_mb_max_to_scan)
50444 - atomic_inc(&sbi->s_bal_breaks);
50445 + atomic_inc_unchecked(&sbi->s_bal_breaks);
50446 }
50447
50448 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
50449 @@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
50450 trace_ext4_mb_new_inode_pa(ac, pa);
50451
50452 ext4_mb_use_inode_pa(ac, pa);
50453 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
50454 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
50455
50456 ei = EXT4_I(ac->ac_inode);
50457 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50458 @@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
50459 trace_ext4_mb_new_group_pa(ac, pa);
50460
50461 ext4_mb_use_group_pa(ac, pa);
50462 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50463 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50464
50465 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50466 lg = ac->ac_lg;
50467 @@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
50468 * from the bitmap and continue.
50469 */
50470 }
50471 - atomic_add(free, &sbi->s_mb_discarded);
50472 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
50473
50474 return err;
50475 }
50476 @@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
50477 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
50478 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
50479 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
50480 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50481 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50482 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
50483
50484 return 0;
50485 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
50486 index 0465f36..99a003a 100644
50487 --- a/fs/ext4/super.c
50488 +++ b/fs/ext4/super.c
50489 @@ -2429,7 +2429,7 @@ struct ext4_attr {
50490 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
50491 const char *, size_t);
50492 int offset;
50493 -};
50494 +} __do_const;
50495
50496 static int parse_strtoul(const char *buf,
50497 unsigned long max, unsigned long *value)
50498 diff --git a/fs/fcntl.c b/fs/fcntl.c
50499 index 71a600a..20d87b1 100644
50500 --- a/fs/fcntl.c
50501 +++ b/fs/fcntl.c
50502 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
50503 if (err)
50504 return err;
50505
50506 + if (gr_handle_chroot_fowner(pid, type))
50507 + return -ENOENT;
50508 + if (gr_check_protected_task_fowner(pid, type))
50509 + return -EACCES;
50510 +
50511 f_modown(filp, pid, type, force);
50512 return 0;
50513 }
50514 diff --git a/fs/fhandle.c b/fs/fhandle.c
50515 index 999ff5c..41f4109 100644
50516 --- a/fs/fhandle.c
50517 +++ b/fs/fhandle.c
50518 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
50519 } else
50520 retval = 0;
50521 /* copy the mount id */
50522 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
50523 - sizeof(*mnt_id)) ||
50524 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
50525 copy_to_user(ufh, handle,
50526 sizeof(struct file_handle) + handle_bytes))
50527 retval = -EFAULT;
50528 diff --git a/fs/fifo.c b/fs/fifo.c
50529 index cf6f434..3d7942c 100644
50530 --- a/fs/fifo.c
50531 +++ b/fs/fifo.c
50532 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
50533 */
50534 filp->f_op = &read_pipefifo_fops;
50535 pipe->r_counter++;
50536 - if (pipe->readers++ == 0)
50537 + if (atomic_inc_return(&pipe->readers) == 1)
50538 wake_up_partner(inode);
50539
50540 - if (!pipe->writers) {
50541 + if (!atomic_read(&pipe->writers)) {
50542 if ((filp->f_flags & O_NONBLOCK)) {
50543 /* suppress POLLHUP until we have
50544 * seen a writer */
50545 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
50546 * errno=ENXIO when there is no process reading the FIFO.
50547 */
50548 ret = -ENXIO;
50549 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
50550 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
50551 goto err;
50552
50553 filp->f_op = &write_pipefifo_fops;
50554 pipe->w_counter++;
50555 - if (!pipe->writers++)
50556 + if (atomic_inc_return(&pipe->writers) == 1)
50557 wake_up_partner(inode);
50558
50559 - if (!pipe->readers) {
50560 + if (!atomic_read(&pipe->readers)) {
50561 if (wait_for_partner(inode, &pipe->r_counter))
50562 goto err_wr;
50563 }
50564 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
50565 */
50566 filp->f_op = &rdwr_pipefifo_fops;
50567
50568 - pipe->readers++;
50569 - pipe->writers++;
50570 + atomic_inc(&pipe->readers);
50571 + atomic_inc(&pipe->writers);
50572 pipe->r_counter++;
50573 pipe->w_counter++;
50574 - if (pipe->readers == 1 || pipe->writers == 1)
50575 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
50576 wake_up_partner(inode);
50577 break;
50578
50579 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
50580 return 0;
50581
50582 err_rd:
50583 - if (!--pipe->readers)
50584 + if (atomic_dec_and_test(&pipe->readers))
50585 wake_up_interruptible(&pipe->wait);
50586 ret = -ERESTARTSYS;
50587 goto err;
50588
50589 err_wr:
50590 - if (!--pipe->writers)
50591 + if (atomic_dec_and_test(&pipe->writers))
50592 wake_up_interruptible(&pipe->wait);
50593 ret = -ERESTARTSYS;
50594 goto err;
50595
50596 err:
50597 - if (!pipe->readers && !pipe->writers)
50598 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
50599 free_pipe_info(inode);
50600
50601 err_nocleanup:
50602 diff --git a/fs/file.c b/fs/file.c
50603 index 2b3570b..c57924b 100644
50604 --- a/fs/file.c
50605 +++ b/fs/file.c
50606 @@ -16,6 +16,7 @@
50607 #include <linux/slab.h>
50608 #include <linux/vmalloc.h>
50609 #include <linux/file.h>
50610 +#include <linux/security.h>
50611 #include <linux/fdtable.h>
50612 #include <linux/bitops.h>
50613 #include <linux/interrupt.h>
50614 @@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
50615 if (!file)
50616 return __close_fd(files, fd);
50617
50618 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
50619 if (fd >= rlimit(RLIMIT_NOFILE))
50620 return -EBADF;
50621
50622 @@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
50623 if (unlikely(oldfd == newfd))
50624 return -EINVAL;
50625
50626 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
50627 if (newfd >= rlimit(RLIMIT_NOFILE))
50628 return -EBADF;
50629
50630 @@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
50631 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
50632 {
50633 int err;
50634 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
50635 if (from >= rlimit(RLIMIT_NOFILE))
50636 return -EINVAL;
50637 err = alloc_fd(from, flags);
50638 diff --git a/fs/filesystems.c b/fs/filesystems.c
50639 index da165f6..3671bdb 100644
50640 --- a/fs/filesystems.c
50641 +++ b/fs/filesystems.c
50642 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
50643 int len = dot ? dot - name : strlen(name);
50644
50645 fs = __get_fs_type(name, len);
50646 +
50647 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
50648 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
50649 +#else
50650 if (!fs && (request_module("%.*s", len, name) == 0))
50651 +#endif
50652 fs = __get_fs_type(name, len);
50653
50654 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
50655 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
50656 index fe6ca58..65318cf 100644
50657 --- a/fs/fs_struct.c
50658 +++ b/fs/fs_struct.c
50659 @@ -4,6 +4,7 @@
50660 #include <linux/path.h>
50661 #include <linux/slab.h>
50662 #include <linux/fs_struct.h>
50663 +#include <linux/grsecurity.h>
50664 #include "internal.h"
50665
50666 /*
50667 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
50668 write_seqcount_begin(&fs->seq);
50669 old_root = fs->root;
50670 fs->root = *path;
50671 + gr_set_chroot_entries(current, path);
50672 write_seqcount_end(&fs->seq);
50673 spin_unlock(&fs->lock);
50674 if (old_root.dentry)
50675 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
50676 return 1;
50677 }
50678
50679 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
50680 +{
50681 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
50682 + return 0;
50683 + *p = *new;
50684 +
50685 + /* This function is only called from pivot_root(). Leave our
50686 + gr_chroot_dentry and is_chrooted flags as-is, so that a
50687 + pivoted root isn't treated as a chroot
50688 + */
50689 + //gr_set_chroot_entries(task, new);
50690 +
50691 + return 1;
50692 +}
50693 +
50694 void chroot_fs_refs(struct path *old_root, struct path *new_root)
50695 {
50696 struct task_struct *g, *p;
50697 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
50698 int hits = 0;
50699 spin_lock(&fs->lock);
50700 write_seqcount_begin(&fs->seq);
50701 - hits += replace_path(&fs->root, old_root, new_root);
50702 + hits += replace_root_path(p, &fs->root, old_root, new_root);
50703 hits += replace_path(&fs->pwd, old_root, new_root);
50704 write_seqcount_end(&fs->seq);
50705 while (hits--) {
50706 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
50707 task_lock(tsk);
50708 spin_lock(&fs->lock);
50709 tsk->fs = NULL;
50710 - kill = !--fs->users;
50711 + gr_clear_chroot_entries(tsk);
50712 + kill = !atomic_dec_return(&fs->users);
50713 spin_unlock(&fs->lock);
50714 task_unlock(tsk);
50715 if (kill)
50716 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
50717 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
50718 /* We don't need to lock fs - think why ;-) */
50719 if (fs) {
50720 - fs->users = 1;
50721 + atomic_set(&fs->users, 1);
50722 fs->in_exec = 0;
50723 spin_lock_init(&fs->lock);
50724 seqcount_init(&fs->seq);
50725 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
50726 spin_lock(&old->lock);
50727 fs->root = old->root;
50728 path_get(&fs->root);
50729 + /* instead of calling gr_set_chroot_entries here,
50730 + we call it from every caller of this function
50731 + */
50732 fs->pwd = old->pwd;
50733 path_get(&fs->pwd);
50734 spin_unlock(&old->lock);
50735 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
50736
50737 task_lock(current);
50738 spin_lock(&fs->lock);
50739 - kill = !--fs->users;
50740 + kill = !atomic_dec_return(&fs->users);
50741 current->fs = new_fs;
50742 + gr_set_chroot_entries(current, &new_fs->root);
50743 spin_unlock(&fs->lock);
50744 task_unlock(current);
50745
50746 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
50747
50748 int current_umask(void)
50749 {
50750 - return current->fs->umask;
50751 + return current->fs->umask | gr_acl_umask();
50752 }
50753 EXPORT_SYMBOL(current_umask);
50754
50755 /* to be mentioned only in INIT_TASK */
50756 struct fs_struct init_fs = {
50757 - .users = 1,
50758 + .users = ATOMIC_INIT(1),
50759 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
50760 .seq = SEQCNT_ZERO,
50761 .umask = 0022,
50762 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
50763 index 8dcb114..b1072e2 100644
50764 --- a/fs/fscache/cookie.c
50765 +++ b/fs/fscache/cookie.c
50766 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
50767 parent ? (char *) parent->def->name : "<no-parent>",
50768 def->name, netfs_data);
50769
50770 - fscache_stat(&fscache_n_acquires);
50771 + fscache_stat_unchecked(&fscache_n_acquires);
50772
50773 /* if there's no parent cookie, then we don't create one here either */
50774 if (!parent) {
50775 - fscache_stat(&fscache_n_acquires_null);
50776 + fscache_stat_unchecked(&fscache_n_acquires_null);
50777 _leave(" [no parent]");
50778 return NULL;
50779 }
50780 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
50781 /* allocate and initialise a cookie */
50782 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
50783 if (!cookie) {
50784 - fscache_stat(&fscache_n_acquires_oom);
50785 + fscache_stat_unchecked(&fscache_n_acquires_oom);
50786 _leave(" [ENOMEM]");
50787 return NULL;
50788 }
50789 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
50790
50791 switch (cookie->def->type) {
50792 case FSCACHE_COOKIE_TYPE_INDEX:
50793 - fscache_stat(&fscache_n_cookie_index);
50794 + fscache_stat_unchecked(&fscache_n_cookie_index);
50795 break;
50796 case FSCACHE_COOKIE_TYPE_DATAFILE:
50797 - fscache_stat(&fscache_n_cookie_data);
50798 + fscache_stat_unchecked(&fscache_n_cookie_data);
50799 break;
50800 default:
50801 - fscache_stat(&fscache_n_cookie_special);
50802 + fscache_stat_unchecked(&fscache_n_cookie_special);
50803 break;
50804 }
50805
50806 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
50807 if (fscache_acquire_non_index_cookie(cookie) < 0) {
50808 atomic_dec(&parent->n_children);
50809 __fscache_cookie_put(cookie);
50810 - fscache_stat(&fscache_n_acquires_nobufs);
50811 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
50812 _leave(" = NULL");
50813 return NULL;
50814 }
50815 }
50816
50817 - fscache_stat(&fscache_n_acquires_ok);
50818 + fscache_stat_unchecked(&fscache_n_acquires_ok);
50819 _leave(" = %p", cookie);
50820 return cookie;
50821 }
50822 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
50823 cache = fscache_select_cache_for_object(cookie->parent);
50824 if (!cache) {
50825 up_read(&fscache_addremove_sem);
50826 - fscache_stat(&fscache_n_acquires_no_cache);
50827 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
50828 _leave(" = -ENOMEDIUM [no cache]");
50829 return -ENOMEDIUM;
50830 }
50831 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
50832 object = cache->ops->alloc_object(cache, cookie);
50833 fscache_stat_d(&fscache_n_cop_alloc_object);
50834 if (IS_ERR(object)) {
50835 - fscache_stat(&fscache_n_object_no_alloc);
50836 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
50837 ret = PTR_ERR(object);
50838 goto error;
50839 }
50840
50841 - fscache_stat(&fscache_n_object_alloc);
50842 + fscache_stat_unchecked(&fscache_n_object_alloc);
50843
50844 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
50845
50846 @@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
50847
50848 _enter("{%s}", cookie->def->name);
50849
50850 - fscache_stat(&fscache_n_invalidates);
50851 + fscache_stat_unchecked(&fscache_n_invalidates);
50852
50853 /* Only permit invalidation of data files. Invalidating an index will
50854 * require the caller to release all its attachments to the tree rooted
50855 @@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
50856 struct fscache_object *object;
50857 struct hlist_node *_p;
50858
50859 - fscache_stat(&fscache_n_updates);
50860 + fscache_stat_unchecked(&fscache_n_updates);
50861
50862 if (!cookie) {
50863 - fscache_stat(&fscache_n_updates_null);
50864 + fscache_stat_unchecked(&fscache_n_updates_null);
50865 _leave(" [no cookie]");
50866 return;
50867 }
50868 @@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
50869 struct fscache_object *object;
50870 unsigned long event;
50871
50872 - fscache_stat(&fscache_n_relinquishes);
50873 + fscache_stat_unchecked(&fscache_n_relinquishes);
50874 if (retire)
50875 - fscache_stat(&fscache_n_relinquishes_retire);
50876 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
50877
50878 if (!cookie) {
50879 - fscache_stat(&fscache_n_relinquishes_null);
50880 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
50881 _leave(" [no cookie]");
50882 return;
50883 }
50884 @@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
50885
50886 /* wait for the cookie to finish being instantiated (or to fail) */
50887 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
50888 - fscache_stat(&fscache_n_relinquishes_waitcrt);
50889 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
50890 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
50891 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
50892 }
50893 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
50894 index ee38fef..0a326d4 100644
50895 --- a/fs/fscache/internal.h
50896 +++ b/fs/fscache/internal.h
50897 @@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
50898 * stats.c
50899 */
50900 #ifdef CONFIG_FSCACHE_STATS
50901 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
50902 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
50903 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
50904 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
50905
50906 -extern atomic_t fscache_n_op_pend;
50907 -extern atomic_t fscache_n_op_run;
50908 -extern atomic_t fscache_n_op_enqueue;
50909 -extern atomic_t fscache_n_op_deferred_release;
50910 -extern atomic_t fscache_n_op_release;
50911 -extern atomic_t fscache_n_op_gc;
50912 -extern atomic_t fscache_n_op_cancelled;
50913 -extern atomic_t fscache_n_op_rejected;
50914 +extern atomic_unchecked_t fscache_n_op_pend;
50915 +extern atomic_unchecked_t fscache_n_op_run;
50916 +extern atomic_unchecked_t fscache_n_op_enqueue;
50917 +extern atomic_unchecked_t fscache_n_op_deferred_release;
50918 +extern atomic_unchecked_t fscache_n_op_release;
50919 +extern atomic_unchecked_t fscache_n_op_gc;
50920 +extern atomic_unchecked_t fscache_n_op_cancelled;
50921 +extern atomic_unchecked_t fscache_n_op_rejected;
50922
50923 -extern atomic_t fscache_n_attr_changed;
50924 -extern atomic_t fscache_n_attr_changed_ok;
50925 -extern atomic_t fscache_n_attr_changed_nobufs;
50926 -extern atomic_t fscache_n_attr_changed_nomem;
50927 -extern atomic_t fscache_n_attr_changed_calls;
50928 +extern atomic_unchecked_t fscache_n_attr_changed;
50929 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
50930 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
50931 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
50932 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
50933
50934 -extern atomic_t fscache_n_allocs;
50935 -extern atomic_t fscache_n_allocs_ok;
50936 -extern atomic_t fscache_n_allocs_wait;
50937 -extern atomic_t fscache_n_allocs_nobufs;
50938 -extern atomic_t fscache_n_allocs_intr;
50939 -extern atomic_t fscache_n_allocs_object_dead;
50940 -extern atomic_t fscache_n_alloc_ops;
50941 -extern atomic_t fscache_n_alloc_op_waits;
50942 +extern atomic_unchecked_t fscache_n_allocs;
50943 +extern atomic_unchecked_t fscache_n_allocs_ok;
50944 +extern atomic_unchecked_t fscache_n_allocs_wait;
50945 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
50946 +extern atomic_unchecked_t fscache_n_allocs_intr;
50947 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
50948 +extern atomic_unchecked_t fscache_n_alloc_ops;
50949 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
50950
50951 -extern atomic_t fscache_n_retrievals;
50952 -extern atomic_t fscache_n_retrievals_ok;
50953 -extern atomic_t fscache_n_retrievals_wait;
50954 -extern atomic_t fscache_n_retrievals_nodata;
50955 -extern atomic_t fscache_n_retrievals_nobufs;
50956 -extern atomic_t fscache_n_retrievals_intr;
50957 -extern atomic_t fscache_n_retrievals_nomem;
50958 -extern atomic_t fscache_n_retrievals_object_dead;
50959 -extern atomic_t fscache_n_retrieval_ops;
50960 -extern atomic_t fscache_n_retrieval_op_waits;
50961 +extern atomic_unchecked_t fscache_n_retrievals;
50962 +extern atomic_unchecked_t fscache_n_retrievals_ok;
50963 +extern atomic_unchecked_t fscache_n_retrievals_wait;
50964 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
50965 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
50966 +extern atomic_unchecked_t fscache_n_retrievals_intr;
50967 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
50968 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
50969 +extern atomic_unchecked_t fscache_n_retrieval_ops;
50970 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
50971
50972 -extern atomic_t fscache_n_stores;
50973 -extern atomic_t fscache_n_stores_ok;
50974 -extern atomic_t fscache_n_stores_again;
50975 -extern atomic_t fscache_n_stores_nobufs;
50976 -extern atomic_t fscache_n_stores_oom;
50977 -extern atomic_t fscache_n_store_ops;
50978 -extern atomic_t fscache_n_store_calls;
50979 -extern atomic_t fscache_n_store_pages;
50980 -extern atomic_t fscache_n_store_radix_deletes;
50981 -extern atomic_t fscache_n_store_pages_over_limit;
50982 +extern atomic_unchecked_t fscache_n_stores;
50983 +extern atomic_unchecked_t fscache_n_stores_ok;
50984 +extern atomic_unchecked_t fscache_n_stores_again;
50985 +extern atomic_unchecked_t fscache_n_stores_nobufs;
50986 +extern atomic_unchecked_t fscache_n_stores_oom;
50987 +extern atomic_unchecked_t fscache_n_store_ops;
50988 +extern atomic_unchecked_t fscache_n_store_calls;
50989 +extern atomic_unchecked_t fscache_n_store_pages;
50990 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
50991 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
50992
50993 -extern atomic_t fscache_n_store_vmscan_not_storing;
50994 -extern atomic_t fscache_n_store_vmscan_gone;
50995 -extern atomic_t fscache_n_store_vmscan_busy;
50996 -extern atomic_t fscache_n_store_vmscan_cancelled;
50997 -extern atomic_t fscache_n_store_vmscan_wait;
50998 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
50999 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
51000 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
51001 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51002 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
51003
51004 -extern atomic_t fscache_n_marks;
51005 -extern atomic_t fscache_n_uncaches;
51006 +extern atomic_unchecked_t fscache_n_marks;
51007 +extern atomic_unchecked_t fscache_n_uncaches;
51008
51009 -extern atomic_t fscache_n_acquires;
51010 -extern atomic_t fscache_n_acquires_null;
51011 -extern atomic_t fscache_n_acquires_no_cache;
51012 -extern atomic_t fscache_n_acquires_ok;
51013 -extern atomic_t fscache_n_acquires_nobufs;
51014 -extern atomic_t fscache_n_acquires_oom;
51015 +extern atomic_unchecked_t fscache_n_acquires;
51016 +extern atomic_unchecked_t fscache_n_acquires_null;
51017 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
51018 +extern atomic_unchecked_t fscache_n_acquires_ok;
51019 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
51020 +extern atomic_unchecked_t fscache_n_acquires_oom;
51021
51022 -extern atomic_t fscache_n_invalidates;
51023 -extern atomic_t fscache_n_invalidates_run;
51024 +extern atomic_unchecked_t fscache_n_invalidates;
51025 +extern atomic_unchecked_t fscache_n_invalidates_run;
51026
51027 -extern atomic_t fscache_n_updates;
51028 -extern atomic_t fscache_n_updates_null;
51029 -extern atomic_t fscache_n_updates_run;
51030 +extern atomic_unchecked_t fscache_n_updates;
51031 +extern atomic_unchecked_t fscache_n_updates_null;
51032 +extern atomic_unchecked_t fscache_n_updates_run;
51033
51034 -extern atomic_t fscache_n_relinquishes;
51035 -extern atomic_t fscache_n_relinquishes_null;
51036 -extern atomic_t fscache_n_relinquishes_waitcrt;
51037 -extern atomic_t fscache_n_relinquishes_retire;
51038 +extern atomic_unchecked_t fscache_n_relinquishes;
51039 +extern atomic_unchecked_t fscache_n_relinquishes_null;
51040 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51041 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
51042
51043 -extern atomic_t fscache_n_cookie_index;
51044 -extern atomic_t fscache_n_cookie_data;
51045 -extern atomic_t fscache_n_cookie_special;
51046 +extern atomic_unchecked_t fscache_n_cookie_index;
51047 +extern atomic_unchecked_t fscache_n_cookie_data;
51048 +extern atomic_unchecked_t fscache_n_cookie_special;
51049
51050 -extern atomic_t fscache_n_object_alloc;
51051 -extern atomic_t fscache_n_object_no_alloc;
51052 -extern atomic_t fscache_n_object_lookups;
51053 -extern atomic_t fscache_n_object_lookups_negative;
51054 -extern atomic_t fscache_n_object_lookups_positive;
51055 -extern atomic_t fscache_n_object_lookups_timed_out;
51056 -extern atomic_t fscache_n_object_created;
51057 -extern atomic_t fscache_n_object_avail;
51058 -extern atomic_t fscache_n_object_dead;
51059 +extern atomic_unchecked_t fscache_n_object_alloc;
51060 +extern atomic_unchecked_t fscache_n_object_no_alloc;
51061 +extern atomic_unchecked_t fscache_n_object_lookups;
51062 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
51063 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
51064 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
51065 +extern atomic_unchecked_t fscache_n_object_created;
51066 +extern atomic_unchecked_t fscache_n_object_avail;
51067 +extern atomic_unchecked_t fscache_n_object_dead;
51068
51069 -extern atomic_t fscache_n_checkaux_none;
51070 -extern atomic_t fscache_n_checkaux_okay;
51071 -extern atomic_t fscache_n_checkaux_update;
51072 -extern atomic_t fscache_n_checkaux_obsolete;
51073 +extern atomic_unchecked_t fscache_n_checkaux_none;
51074 +extern atomic_unchecked_t fscache_n_checkaux_okay;
51075 +extern atomic_unchecked_t fscache_n_checkaux_update;
51076 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
51077
51078 extern atomic_t fscache_n_cop_alloc_object;
51079 extern atomic_t fscache_n_cop_lookup_object;
51080 @@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
51081 atomic_inc(stat);
51082 }
51083
51084 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
51085 +{
51086 + atomic_inc_unchecked(stat);
51087 +}
51088 +
51089 static inline void fscache_stat_d(atomic_t *stat)
51090 {
51091 atomic_dec(stat);
51092 @@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
51093
51094 #define __fscache_stat(stat) (NULL)
51095 #define fscache_stat(stat) do {} while (0)
51096 +#define fscache_stat_unchecked(stat) do {} while (0)
51097 #define fscache_stat_d(stat) do {} while (0)
51098 #endif
51099
51100 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
51101 index 50d41c1..10ee117 100644
51102 --- a/fs/fscache/object.c
51103 +++ b/fs/fscache/object.c
51104 @@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51105 /* Invalidate an object on disk */
51106 case FSCACHE_OBJECT_INVALIDATING:
51107 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
51108 - fscache_stat(&fscache_n_invalidates_run);
51109 + fscache_stat_unchecked(&fscache_n_invalidates_run);
51110 fscache_stat(&fscache_n_cop_invalidate_object);
51111 fscache_invalidate_object(object);
51112 fscache_stat_d(&fscache_n_cop_invalidate_object);
51113 @@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51114 /* update the object metadata on disk */
51115 case FSCACHE_OBJECT_UPDATING:
51116 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
51117 - fscache_stat(&fscache_n_updates_run);
51118 + fscache_stat_unchecked(&fscache_n_updates_run);
51119 fscache_stat(&fscache_n_cop_update_object);
51120 object->cache->ops->update_object(object);
51121 fscache_stat_d(&fscache_n_cop_update_object);
51122 @@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51123 spin_lock(&object->lock);
51124 object->state = FSCACHE_OBJECT_DEAD;
51125 spin_unlock(&object->lock);
51126 - fscache_stat(&fscache_n_object_dead);
51127 + fscache_stat_unchecked(&fscache_n_object_dead);
51128 goto terminal_transit;
51129
51130 /* handle the parent cache of this object being withdrawn from
51131 @@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51132 spin_lock(&object->lock);
51133 object->state = FSCACHE_OBJECT_DEAD;
51134 spin_unlock(&object->lock);
51135 - fscache_stat(&fscache_n_object_dead);
51136 + fscache_stat_unchecked(&fscache_n_object_dead);
51137 goto terminal_transit;
51138
51139 /* complain about the object being woken up once it is
51140 @@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51141 parent->cookie->def->name, cookie->def->name,
51142 object->cache->tag->name);
51143
51144 - fscache_stat(&fscache_n_object_lookups);
51145 + fscache_stat_unchecked(&fscache_n_object_lookups);
51146 fscache_stat(&fscache_n_cop_lookup_object);
51147 ret = object->cache->ops->lookup_object(object);
51148 fscache_stat_d(&fscache_n_cop_lookup_object);
51149 @@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51150 if (ret == -ETIMEDOUT) {
51151 /* probably stuck behind another object, so move this one to
51152 * the back of the queue */
51153 - fscache_stat(&fscache_n_object_lookups_timed_out);
51154 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
51155 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51156 }
51157
51158 @@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
51159
51160 spin_lock(&object->lock);
51161 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51162 - fscache_stat(&fscache_n_object_lookups_negative);
51163 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
51164
51165 /* transit here to allow write requests to begin stacking up
51166 * and read requests to begin returning ENODATA */
51167 @@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
51168 * result, in which case there may be data available */
51169 spin_lock(&object->lock);
51170 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51171 - fscache_stat(&fscache_n_object_lookups_positive);
51172 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
51173
51174 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
51175
51176 @@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
51177 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51178 } else {
51179 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
51180 - fscache_stat(&fscache_n_object_created);
51181 + fscache_stat_unchecked(&fscache_n_object_created);
51182
51183 object->state = FSCACHE_OBJECT_AVAILABLE;
51184 spin_unlock(&object->lock);
51185 @@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
51186 fscache_enqueue_dependents(object);
51187
51188 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
51189 - fscache_stat(&fscache_n_object_avail);
51190 + fscache_stat_unchecked(&fscache_n_object_avail);
51191
51192 _leave("");
51193 }
51194 @@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51195 enum fscache_checkaux result;
51196
51197 if (!object->cookie->def->check_aux) {
51198 - fscache_stat(&fscache_n_checkaux_none);
51199 + fscache_stat_unchecked(&fscache_n_checkaux_none);
51200 return FSCACHE_CHECKAUX_OKAY;
51201 }
51202
51203 @@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51204 switch (result) {
51205 /* entry okay as is */
51206 case FSCACHE_CHECKAUX_OKAY:
51207 - fscache_stat(&fscache_n_checkaux_okay);
51208 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
51209 break;
51210
51211 /* entry requires update */
51212 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
51213 - fscache_stat(&fscache_n_checkaux_update);
51214 + fscache_stat_unchecked(&fscache_n_checkaux_update);
51215 break;
51216
51217 /* entry requires deletion */
51218 case FSCACHE_CHECKAUX_OBSOLETE:
51219 - fscache_stat(&fscache_n_checkaux_obsolete);
51220 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
51221 break;
51222
51223 default:
51224 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
51225 index 762a9ec..2023284 100644
51226 --- a/fs/fscache/operation.c
51227 +++ b/fs/fscache/operation.c
51228 @@ -17,7 +17,7 @@
51229 #include <linux/slab.h>
51230 #include "internal.h"
51231
51232 -atomic_t fscache_op_debug_id;
51233 +atomic_unchecked_t fscache_op_debug_id;
51234 EXPORT_SYMBOL(fscache_op_debug_id);
51235
51236 /**
51237 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
51238 ASSERTCMP(atomic_read(&op->usage), >, 0);
51239 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
51240
51241 - fscache_stat(&fscache_n_op_enqueue);
51242 + fscache_stat_unchecked(&fscache_n_op_enqueue);
51243 switch (op->flags & FSCACHE_OP_TYPE) {
51244 case FSCACHE_OP_ASYNC:
51245 _debug("queue async");
51246 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
51247 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
51248 if (op->processor)
51249 fscache_enqueue_operation(op);
51250 - fscache_stat(&fscache_n_op_run);
51251 + fscache_stat_unchecked(&fscache_n_op_run);
51252 }
51253
51254 /*
51255 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51256 if (object->n_in_progress > 0) {
51257 atomic_inc(&op->usage);
51258 list_add_tail(&op->pend_link, &object->pending_ops);
51259 - fscache_stat(&fscache_n_op_pend);
51260 + fscache_stat_unchecked(&fscache_n_op_pend);
51261 } else if (!list_empty(&object->pending_ops)) {
51262 atomic_inc(&op->usage);
51263 list_add_tail(&op->pend_link, &object->pending_ops);
51264 - fscache_stat(&fscache_n_op_pend);
51265 + fscache_stat_unchecked(&fscache_n_op_pend);
51266 fscache_start_operations(object);
51267 } else {
51268 ASSERTCMP(object->n_in_progress, ==, 0);
51269 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51270 object->n_exclusive++; /* reads and writes must wait */
51271 atomic_inc(&op->usage);
51272 list_add_tail(&op->pend_link, &object->pending_ops);
51273 - fscache_stat(&fscache_n_op_pend);
51274 + fscache_stat_unchecked(&fscache_n_op_pend);
51275 ret = 0;
51276 } else {
51277 /* If we're in any other state, there must have been an I/O
51278 @@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
51279 if (object->n_exclusive > 0) {
51280 atomic_inc(&op->usage);
51281 list_add_tail(&op->pend_link, &object->pending_ops);
51282 - fscache_stat(&fscache_n_op_pend);
51283 + fscache_stat_unchecked(&fscache_n_op_pend);
51284 } else if (!list_empty(&object->pending_ops)) {
51285 atomic_inc(&op->usage);
51286 list_add_tail(&op->pend_link, &object->pending_ops);
51287 - fscache_stat(&fscache_n_op_pend);
51288 + fscache_stat_unchecked(&fscache_n_op_pend);
51289 fscache_start_operations(object);
51290 } else {
51291 ASSERTCMP(object->n_exclusive, ==, 0);
51292 @@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
51293 object->n_ops++;
51294 atomic_inc(&op->usage);
51295 list_add_tail(&op->pend_link, &object->pending_ops);
51296 - fscache_stat(&fscache_n_op_pend);
51297 + fscache_stat_unchecked(&fscache_n_op_pend);
51298 ret = 0;
51299 } else if (object->state == FSCACHE_OBJECT_DYING ||
51300 object->state == FSCACHE_OBJECT_LC_DYING ||
51301 object->state == FSCACHE_OBJECT_WITHDRAWING) {
51302 - fscache_stat(&fscache_n_op_rejected);
51303 + fscache_stat_unchecked(&fscache_n_op_rejected);
51304 op->state = FSCACHE_OP_ST_CANCELLED;
51305 ret = -ENOBUFS;
51306 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
51307 @@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
51308 ret = -EBUSY;
51309 if (op->state == FSCACHE_OP_ST_PENDING) {
51310 ASSERT(!list_empty(&op->pend_link));
51311 - fscache_stat(&fscache_n_op_cancelled);
51312 + fscache_stat_unchecked(&fscache_n_op_cancelled);
51313 list_del_init(&op->pend_link);
51314 if (do_cancel)
51315 do_cancel(op);
51316 @@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
51317 while (!list_empty(&object->pending_ops)) {
51318 op = list_entry(object->pending_ops.next,
51319 struct fscache_operation, pend_link);
51320 - fscache_stat(&fscache_n_op_cancelled);
51321 + fscache_stat_unchecked(&fscache_n_op_cancelled);
51322 list_del_init(&op->pend_link);
51323
51324 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
51325 @@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
51326 op->state, ==, FSCACHE_OP_ST_CANCELLED);
51327 op->state = FSCACHE_OP_ST_DEAD;
51328
51329 - fscache_stat(&fscache_n_op_release);
51330 + fscache_stat_unchecked(&fscache_n_op_release);
51331
51332 if (op->release) {
51333 op->release(op);
51334 @@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
51335 * lock, and defer it otherwise */
51336 if (!spin_trylock(&object->lock)) {
51337 _debug("defer put");
51338 - fscache_stat(&fscache_n_op_deferred_release);
51339 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
51340
51341 cache = object->cache;
51342 spin_lock(&cache->op_gc_list_lock);
51343 @@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
51344
51345 _debug("GC DEFERRED REL OBJ%x OP%x",
51346 object->debug_id, op->debug_id);
51347 - fscache_stat(&fscache_n_op_gc);
51348 + fscache_stat_unchecked(&fscache_n_op_gc);
51349
51350 ASSERTCMP(atomic_read(&op->usage), ==, 0);
51351 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
51352 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
51353 index ff000e5..c44ec6d 100644
51354 --- a/fs/fscache/page.c
51355 +++ b/fs/fscache/page.c
51356 @@ -61,7 +61,7 @@ try_again:
51357 val = radix_tree_lookup(&cookie->stores, page->index);
51358 if (!val) {
51359 rcu_read_unlock();
51360 - fscache_stat(&fscache_n_store_vmscan_not_storing);
51361 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
51362 __fscache_uncache_page(cookie, page);
51363 return true;
51364 }
51365 @@ -91,11 +91,11 @@ try_again:
51366 spin_unlock(&cookie->stores_lock);
51367
51368 if (xpage) {
51369 - fscache_stat(&fscache_n_store_vmscan_cancelled);
51370 - fscache_stat(&fscache_n_store_radix_deletes);
51371 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
51372 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51373 ASSERTCMP(xpage, ==, page);
51374 } else {
51375 - fscache_stat(&fscache_n_store_vmscan_gone);
51376 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
51377 }
51378
51379 wake_up_bit(&cookie->flags, 0);
51380 @@ -110,11 +110,11 @@ page_busy:
51381 * sleeping on memory allocation, so we may need to impose a timeout
51382 * too. */
51383 if (!(gfp & __GFP_WAIT)) {
51384 - fscache_stat(&fscache_n_store_vmscan_busy);
51385 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
51386 return false;
51387 }
51388
51389 - fscache_stat(&fscache_n_store_vmscan_wait);
51390 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
51391 __fscache_wait_on_page_write(cookie, page);
51392 gfp &= ~__GFP_WAIT;
51393 goto try_again;
51394 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
51395 FSCACHE_COOKIE_STORING_TAG);
51396 if (!radix_tree_tag_get(&cookie->stores, page->index,
51397 FSCACHE_COOKIE_PENDING_TAG)) {
51398 - fscache_stat(&fscache_n_store_radix_deletes);
51399 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51400 xpage = radix_tree_delete(&cookie->stores, page->index);
51401 }
51402 spin_unlock(&cookie->stores_lock);
51403 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
51404
51405 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
51406
51407 - fscache_stat(&fscache_n_attr_changed_calls);
51408 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
51409
51410 if (fscache_object_is_active(object)) {
51411 fscache_stat(&fscache_n_cop_attr_changed);
51412 @@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51413
51414 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51415
51416 - fscache_stat(&fscache_n_attr_changed);
51417 + fscache_stat_unchecked(&fscache_n_attr_changed);
51418
51419 op = kzalloc(sizeof(*op), GFP_KERNEL);
51420 if (!op) {
51421 - fscache_stat(&fscache_n_attr_changed_nomem);
51422 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
51423 _leave(" = -ENOMEM");
51424 return -ENOMEM;
51425 }
51426 @@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51427 if (fscache_submit_exclusive_op(object, op) < 0)
51428 goto nobufs;
51429 spin_unlock(&cookie->lock);
51430 - fscache_stat(&fscache_n_attr_changed_ok);
51431 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
51432 fscache_put_operation(op);
51433 _leave(" = 0");
51434 return 0;
51435 @@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51436 nobufs:
51437 spin_unlock(&cookie->lock);
51438 kfree(op);
51439 - fscache_stat(&fscache_n_attr_changed_nobufs);
51440 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
51441 _leave(" = %d", -ENOBUFS);
51442 return -ENOBUFS;
51443 }
51444 @@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
51445 /* allocate a retrieval operation and attempt to submit it */
51446 op = kzalloc(sizeof(*op), GFP_NOIO);
51447 if (!op) {
51448 - fscache_stat(&fscache_n_retrievals_nomem);
51449 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51450 return NULL;
51451 }
51452
51453 @@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
51454 return 0;
51455 }
51456
51457 - fscache_stat(&fscache_n_retrievals_wait);
51458 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
51459
51460 jif = jiffies;
51461 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
51462 fscache_wait_bit_interruptible,
51463 TASK_INTERRUPTIBLE) != 0) {
51464 - fscache_stat(&fscache_n_retrievals_intr);
51465 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
51466 _leave(" = -ERESTARTSYS");
51467 return -ERESTARTSYS;
51468 }
51469 @@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
51470 */
51471 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51472 struct fscache_retrieval *op,
51473 - atomic_t *stat_op_waits,
51474 - atomic_t *stat_object_dead)
51475 + atomic_unchecked_t *stat_op_waits,
51476 + atomic_unchecked_t *stat_object_dead)
51477 {
51478 int ret;
51479
51480 @@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51481 goto check_if_dead;
51482
51483 _debug(">>> WT");
51484 - fscache_stat(stat_op_waits);
51485 + fscache_stat_unchecked(stat_op_waits);
51486 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
51487 fscache_wait_bit_interruptible,
51488 TASK_INTERRUPTIBLE) != 0) {
51489 @@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51490
51491 check_if_dead:
51492 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
51493 - fscache_stat(stat_object_dead);
51494 + fscache_stat_unchecked(stat_object_dead);
51495 _leave(" = -ENOBUFS [cancelled]");
51496 return -ENOBUFS;
51497 }
51498 if (unlikely(fscache_object_is_dead(object))) {
51499 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
51500 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
51501 - fscache_stat(stat_object_dead);
51502 + fscache_stat_unchecked(stat_object_dead);
51503 return -ENOBUFS;
51504 }
51505 return 0;
51506 @@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51507
51508 _enter("%p,%p,,,", cookie, page);
51509
51510 - fscache_stat(&fscache_n_retrievals);
51511 + fscache_stat_unchecked(&fscache_n_retrievals);
51512
51513 if (hlist_empty(&cookie->backing_objects))
51514 goto nobufs;
51515 @@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51516 goto nobufs_unlock_dec;
51517 spin_unlock(&cookie->lock);
51518
51519 - fscache_stat(&fscache_n_retrieval_ops);
51520 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
51521
51522 /* pin the netfs read context in case we need to do the actual netfs
51523 * read because we've encountered a cache read failure */
51524 @@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51525
51526 error:
51527 if (ret == -ENOMEM)
51528 - fscache_stat(&fscache_n_retrievals_nomem);
51529 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51530 else if (ret == -ERESTARTSYS)
51531 - fscache_stat(&fscache_n_retrievals_intr);
51532 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
51533 else if (ret == -ENODATA)
51534 - fscache_stat(&fscache_n_retrievals_nodata);
51535 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51536 else if (ret < 0)
51537 - fscache_stat(&fscache_n_retrievals_nobufs);
51538 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51539 else
51540 - fscache_stat(&fscache_n_retrievals_ok);
51541 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
51542
51543 fscache_put_retrieval(op);
51544 _leave(" = %d", ret);
51545 @@ -467,7 +467,7 @@ nobufs_unlock:
51546 spin_unlock(&cookie->lock);
51547 kfree(op);
51548 nobufs:
51549 - fscache_stat(&fscache_n_retrievals_nobufs);
51550 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51551 _leave(" = -ENOBUFS");
51552 return -ENOBUFS;
51553 }
51554 @@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51555
51556 _enter("%p,,%d,,,", cookie, *nr_pages);
51557
51558 - fscache_stat(&fscache_n_retrievals);
51559 + fscache_stat_unchecked(&fscache_n_retrievals);
51560
51561 if (hlist_empty(&cookie->backing_objects))
51562 goto nobufs;
51563 @@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51564 goto nobufs_unlock_dec;
51565 spin_unlock(&cookie->lock);
51566
51567 - fscache_stat(&fscache_n_retrieval_ops);
51568 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
51569
51570 /* pin the netfs read context in case we need to do the actual netfs
51571 * read because we've encountered a cache read failure */
51572 @@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51573
51574 error:
51575 if (ret == -ENOMEM)
51576 - fscache_stat(&fscache_n_retrievals_nomem);
51577 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51578 else if (ret == -ERESTARTSYS)
51579 - fscache_stat(&fscache_n_retrievals_intr);
51580 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
51581 else if (ret == -ENODATA)
51582 - fscache_stat(&fscache_n_retrievals_nodata);
51583 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51584 else if (ret < 0)
51585 - fscache_stat(&fscache_n_retrievals_nobufs);
51586 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51587 else
51588 - fscache_stat(&fscache_n_retrievals_ok);
51589 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
51590
51591 fscache_put_retrieval(op);
51592 _leave(" = %d", ret);
51593 @@ -591,7 +591,7 @@ nobufs_unlock:
51594 spin_unlock(&cookie->lock);
51595 kfree(op);
51596 nobufs:
51597 - fscache_stat(&fscache_n_retrievals_nobufs);
51598 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51599 _leave(" = -ENOBUFS");
51600 return -ENOBUFS;
51601 }
51602 @@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51603
51604 _enter("%p,%p,,,", cookie, page);
51605
51606 - fscache_stat(&fscache_n_allocs);
51607 + fscache_stat_unchecked(&fscache_n_allocs);
51608
51609 if (hlist_empty(&cookie->backing_objects))
51610 goto nobufs;
51611 @@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51612 goto nobufs_unlock;
51613 spin_unlock(&cookie->lock);
51614
51615 - fscache_stat(&fscache_n_alloc_ops);
51616 + fscache_stat_unchecked(&fscache_n_alloc_ops);
51617
51618 ret = fscache_wait_for_retrieval_activation(
51619 object, op,
51620 @@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51621
51622 error:
51623 if (ret == -ERESTARTSYS)
51624 - fscache_stat(&fscache_n_allocs_intr);
51625 + fscache_stat_unchecked(&fscache_n_allocs_intr);
51626 else if (ret < 0)
51627 - fscache_stat(&fscache_n_allocs_nobufs);
51628 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
51629 else
51630 - fscache_stat(&fscache_n_allocs_ok);
51631 + fscache_stat_unchecked(&fscache_n_allocs_ok);
51632
51633 fscache_put_retrieval(op);
51634 _leave(" = %d", ret);
51635 @@ -677,7 +677,7 @@ nobufs_unlock:
51636 spin_unlock(&cookie->lock);
51637 kfree(op);
51638 nobufs:
51639 - fscache_stat(&fscache_n_allocs_nobufs);
51640 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
51641 _leave(" = -ENOBUFS");
51642 return -ENOBUFS;
51643 }
51644 @@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51645
51646 spin_lock(&cookie->stores_lock);
51647
51648 - fscache_stat(&fscache_n_store_calls);
51649 + fscache_stat_unchecked(&fscache_n_store_calls);
51650
51651 /* find a page to store */
51652 page = NULL;
51653 @@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51654 page = results[0];
51655 _debug("gang %d [%lx]", n, page->index);
51656 if (page->index > op->store_limit) {
51657 - fscache_stat(&fscache_n_store_pages_over_limit);
51658 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
51659 goto superseded;
51660 }
51661
51662 @@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51663 spin_unlock(&cookie->stores_lock);
51664 spin_unlock(&object->lock);
51665
51666 - fscache_stat(&fscache_n_store_pages);
51667 + fscache_stat_unchecked(&fscache_n_store_pages);
51668 fscache_stat(&fscache_n_cop_write_page);
51669 ret = object->cache->ops->write_page(op, page);
51670 fscache_stat_d(&fscache_n_cop_write_page);
51671 @@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51672 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51673 ASSERT(PageFsCache(page));
51674
51675 - fscache_stat(&fscache_n_stores);
51676 + fscache_stat_unchecked(&fscache_n_stores);
51677
51678 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
51679 _leave(" = -ENOBUFS [invalidating]");
51680 @@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51681 spin_unlock(&cookie->stores_lock);
51682 spin_unlock(&object->lock);
51683
51684 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
51685 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
51686 op->store_limit = object->store_limit;
51687
51688 if (fscache_submit_op(object, &op->op) < 0)
51689 @@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51690
51691 spin_unlock(&cookie->lock);
51692 radix_tree_preload_end();
51693 - fscache_stat(&fscache_n_store_ops);
51694 - fscache_stat(&fscache_n_stores_ok);
51695 + fscache_stat_unchecked(&fscache_n_store_ops);
51696 + fscache_stat_unchecked(&fscache_n_stores_ok);
51697
51698 /* the work queue now carries its own ref on the object */
51699 fscache_put_operation(&op->op);
51700 @@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51701 return 0;
51702
51703 already_queued:
51704 - fscache_stat(&fscache_n_stores_again);
51705 + fscache_stat_unchecked(&fscache_n_stores_again);
51706 already_pending:
51707 spin_unlock(&cookie->stores_lock);
51708 spin_unlock(&object->lock);
51709 spin_unlock(&cookie->lock);
51710 radix_tree_preload_end();
51711 kfree(op);
51712 - fscache_stat(&fscache_n_stores_ok);
51713 + fscache_stat_unchecked(&fscache_n_stores_ok);
51714 _leave(" = 0");
51715 return 0;
51716
51717 @@ -959,14 +959,14 @@ nobufs:
51718 spin_unlock(&cookie->lock);
51719 radix_tree_preload_end();
51720 kfree(op);
51721 - fscache_stat(&fscache_n_stores_nobufs);
51722 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
51723 _leave(" = -ENOBUFS");
51724 return -ENOBUFS;
51725
51726 nomem_free:
51727 kfree(op);
51728 nomem:
51729 - fscache_stat(&fscache_n_stores_oom);
51730 + fscache_stat_unchecked(&fscache_n_stores_oom);
51731 _leave(" = -ENOMEM");
51732 return -ENOMEM;
51733 }
51734 @@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
51735 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51736 ASSERTCMP(page, !=, NULL);
51737
51738 - fscache_stat(&fscache_n_uncaches);
51739 + fscache_stat_unchecked(&fscache_n_uncaches);
51740
51741 /* cache withdrawal may beat us to it */
51742 if (!PageFsCache(page))
51743 @@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
51744 struct fscache_cookie *cookie = op->op.object->cookie;
51745
51746 #ifdef CONFIG_FSCACHE_STATS
51747 - atomic_inc(&fscache_n_marks);
51748 + atomic_inc_unchecked(&fscache_n_marks);
51749 #endif
51750
51751 _debug("- mark %p{%lx}", page, page->index);
51752 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
51753 index 8179e8b..5072cc7 100644
51754 --- a/fs/fscache/stats.c
51755 +++ b/fs/fscache/stats.c
51756 @@ -18,99 +18,99 @@
51757 /*
51758 * operation counters
51759 */
51760 -atomic_t fscache_n_op_pend;
51761 -atomic_t fscache_n_op_run;
51762 -atomic_t fscache_n_op_enqueue;
51763 -atomic_t fscache_n_op_requeue;
51764 -atomic_t fscache_n_op_deferred_release;
51765 -atomic_t fscache_n_op_release;
51766 -atomic_t fscache_n_op_gc;
51767 -atomic_t fscache_n_op_cancelled;
51768 -atomic_t fscache_n_op_rejected;
51769 +atomic_unchecked_t fscache_n_op_pend;
51770 +atomic_unchecked_t fscache_n_op_run;
51771 +atomic_unchecked_t fscache_n_op_enqueue;
51772 +atomic_unchecked_t fscache_n_op_requeue;
51773 +atomic_unchecked_t fscache_n_op_deferred_release;
51774 +atomic_unchecked_t fscache_n_op_release;
51775 +atomic_unchecked_t fscache_n_op_gc;
51776 +atomic_unchecked_t fscache_n_op_cancelled;
51777 +atomic_unchecked_t fscache_n_op_rejected;
51778
51779 -atomic_t fscache_n_attr_changed;
51780 -atomic_t fscache_n_attr_changed_ok;
51781 -atomic_t fscache_n_attr_changed_nobufs;
51782 -atomic_t fscache_n_attr_changed_nomem;
51783 -atomic_t fscache_n_attr_changed_calls;
51784 +atomic_unchecked_t fscache_n_attr_changed;
51785 +atomic_unchecked_t fscache_n_attr_changed_ok;
51786 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
51787 +atomic_unchecked_t fscache_n_attr_changed_nomem;
51788 +atomic_unchecked_t fscache_n_attr_changed_calls;
51789
51790 -atomic_t fscache_n_allocs;
51791 -atomic_t fscache_n_allocs_ok;
51792 -atomic_t fscache_n_allocs_wait;
51793 -atomic_t fscache_n_allocs_nobufs;
51794 -atomic_t fscache_n_allocs_intr;
51795 -atomic_t fscache_n_allocs_object_dead;
51796 -atomic_t fscache_n_alloc_ops;
51797 -atomic_t fscache_n_alloc_op_waits;
51798 +atomic_unchecked_t fscache_n_allocs;
51799 +atomic_unchecked_t fscache_n_allocs_ok;
51800 +atomic_unchecked_t fscache_n_allocs_wait;
51801 +atomic_unchecked_t fscache_n_allocs_nobufs;
51802 +atomic_unchecked_t fscache_n_allocs_intr;
51803 +atomic_unchecked_t fscache_n_allocs_object_dead;
51804 +atomic_unchecked_t fscache_n_alloc_ops;
51805 +atomic_unchecked_t fscache_n_alloc_op_waits;
51806
51807 -atomic_t fscache_n_retrievals;
51808 -atomic_t fscache_n_retrievals_ok;
51809 -atomic_t fscache_n_retrievals_wait;
51810 -atomic_t fscache_n_retrievals_nodata;
51811 -atomic_t fscache_n_retrievals_nobufs;
51812 -atomic_t fscache_n_retrievals_intr;
51813 -atomic_t fscache_n_retrievals_nomem;
51814 -atomic_t fscache_n_retrievals_object_dead;
51815 -atomic_t fscache_n_retrieval_ops;
51816 -atomic_t fscache_n_retrieval_op_waits;
51817 +atomic_unchecked_t fscache_n_retrievals;
51818 +atomic_unchecked_t fscache_n_retrievals_ok;
51819 +atomic_unchecked_t fscache_n_retrievals_wait;
51820 +atomic_unchecked_t fscache_n_retrievals_nodata;
51821 +atomic_unchecked_t fscache_n_retrievals_nobufs;
51822 +atomic_unchecked_t fscache_n_retrievals_intr;
51823 +atomic_unchecked_t fscache_n_retrievals_nomem;
51824 +atomic_unchecked_t fscache_n_retrievals_object_dead;
51825 +atomic_unchecked_t fscache_n_retrieval_ops;
51826 +atomic_unchecked_t fscache_n_retrieval_op_waits;
51827
51828 -atomic_t fscache_n_stores;
51829 -atomic_t fscache_n_stores_ok;
51830 -atomic_t fscache_n_stores_again;
51831 -atomic_t fscache_n_stores_nobufs;
51832 -atomic_t fscache_n_stores_oom;
51833 -atomic_t fscache_n_store_ops;
51834 -atomic_t fscache_n_store_calls;
51835 -atomic_t fscache_n_store_pages;
51836 -atomic_t fscache_n_store_radix_deletes;
51837 -atomic_t fscache_n_store_pages_over_limit;
51838 +atomic_unchecked_t fscache_n_stores;
51839 +atomic_unchecked_t fscache_n_stores_ok;
51840 +atomic_unchecked_t fscache_n_stores_again;
51841 +atomic_unchecked_t fscache_n_stores_nobufs;
51842 +atomic_unchecked_t fscache_n_stores_oom;
51843 +atomic_unchecked_t fscache_n_store_ops;
51844 +atomic_unchecked_t fscache_n_store_calls;
51845 +atomic_unchecked_t fscache_n_store_pages;
51846 +atomic_unchecked_t fscache_n_store_radix_deletes;
51847 +atomic_unchecked_t fscache_n_store_pages_over_limit;
51848
51849 -atomic_t fscache_n_store_vmscan_not_storing;
51850 -atomic_t fscache_n_store_vmscan_gone;
51851 -atomic_t fscache_n_store_vmscan_busy;
51852 -atomic_t fscache_n_store_vmscan_cancelled;
51853 -atomic_t fscache_n_store_vmscan_wait;
51854 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51855 +atomic_unchecked_t fscache_n_store_vmscan_gone;
51856 +atomic_unchecked_t fscache_n_store_vmscan_busy;
51857 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51858 +atomic_unchecked_t fscache_n_store_vmscan_wait;
51859
51860 -atomic_t fscache_n_marks;
51861 -atomic_t fscache_n_uncaches;
51862 +atomic_unchecked_t fscache_n_marks;
51863 +atomic_unchecked_t fscache_n_uncaches;
51864
51865 -atomic_t fscache_n_acquires;
51866 -atomic_t fscache_n_acquires_null;
51867 -atomic_t fscache_n_acquires_no_cache;
51868 -atomic_t fscache_n_acquires_ok;
51869 -atomic_t fscache_n_acquires_nobufs;
51870 -atomic_t fscache_n_acquires_oom;
51871 +atomic_unchecked_t fscache_n_acquires;
51872 +atomic_unchecked_t fscache_n_acquires_null;
51873 +atomic_unchecked_t fscache_n_acquires_no_cache;
51874 +atomic_unchecked_t fscache_n_acquires_ok;
51875 +atomic_unchecked_t fscache_n_acquires_nobufs;
51876 +atomic_unchecked_t fscache_n_acquires_oom;
51877
51878 -atomic_t fscache_n_invalidates;
51879 -atomic_t fscache_n_invalidates_run;
51880 +atomic_unchecked_t fscache_n_invalidates;
51881 +atomic_unchecked_t fscache_n_invalidates_run;
51882
51883 -atomic_t fscache_n_updates;
51884 -atomic_t fscache_n_updates_null;
51885 -atomic_t fscache_n_updates_run;
51886 +atomic_unchecked_t fscache_n_updates;
51887 +atomic_unchecked_t fscache_n_updates_null;
51888 +atomic_unchecked_t fscache_n_updates_run;
51889
51890 -atomic_t fscache_n_relinquishes;
51891 -atomic_t fscache_n_relinquishes_null;
51892 -atomic_t fscache_n_relinquishes_waitcrt;
51893 -atomic_t fscache_n_relinquishes_retire;
51894 +atomic_unchecked_t fscache_n_relinquishes;
51895 +atomic_unchecked_t fscache_n_relinquishes_null;
51896 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51897 +atomic_unchecked_t fscache_n_relinquishes_retire;
51898
51899 -atomic_t fscache_n_cookie_index;
51900 -atomic_t fscache_n_cookie_data;
51901 -atomic_t fscache_n_cookie_special;
51902 +atomic_unchecked_t fscache_n_cookie_index;
51903 +atomic_unchecked_t fscache_n_cookie_data;
51904 +atomic_unchecked_t fscache_n_cookie_special;
51905
51906 -atomic_t fscache_n_object_alloc;
51907 -atomic_t fscache_n_object_no_alloc;
51908 -atomic_t fscache_n_object_lookups;
51909 -atomic_t fscache_n_object_lookups_negative;
51910 -atomic_t fscache_n_object_lookups_positive;
51911 -atomic_t fscache_n_object_lookups_timed_out;
51912 -atomic_t fscache_n_object_created;
51913 -atomic_t fscache_n_object_avail;
51914 -atomic_t fscache_n_object_dead;
51915 +atomic_unchecked_t fscache_n_object_alloc;
51916 +atomic_unchecked_t fscache_n_object_no_alloc;
51917 +atomic_unchecked_t fscache_n_object_lookups;
51918 +atomic_unchecked_t fscache_n_object_lookups_negative;
51919 +atomic_unchecked_t fscache_n_object_lookups_positive;
51920 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
51921 +atomic_unchecked_t fscache_n_object_created;
51922 +atomic_unchecked_t fscache_n_object_avail;
51923 +atomic_unchecked_t fscache_n_object_dead;
51924
51925 -atomic_t fscache_n_checkaux_none;
51926 -atomic_t fscache_n_checkaux_okay;
51927 -atomic_t fscache_n_checkaux_update;
51928 -atomic_t fscache_n_checkaux_obsolete;
51929 +atomic_unchecked_t fscache_n_checkaux_none;
51930 +atomic_unchecked_t fscache_n_checkaux_okay;
51931 +atomic_unchecked_t fscache_n_checkaux_update;
51932 +atomic_unchecked_t fscache_n_checkaux_obsolete;
51933
51934 atomic_t fscache_n_cop_alloc_object;
51935 atomic_t fscache_n_cop_lookup_object;
51936 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
51937 seq_puts(m, "FS-Cache statistics\n");
51938
51939 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
51940 - atomic_read(&fscache_n_cookie_index),
51941 - atomic_read(&fscache_n_cookie_data),
51942 - atomic_read(&fscache_n_cookie_special));
51943 + atomic_read_unchecked(&fscache_n_cookie_index),
51944 + atomic_read_unchecked(&fscache_n_cookie_data),
51945 + atomic_read_unchecked(&fscache_n_cookie_special));
51946
51947 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
51948 - atomic_read(&fscache_n_object_alloc),
51949 - atomic_read(&fscache_n_object_no_alloc),
51950 - atomic_read(&fscache_n_object_avail),
51951 - atomic_read(&fscache_n_object_dead));
51952 + atomic_read_unchecked(&fscache_n_object_alloc),
51953 + atomic_read_unchecked(&fscache_n_object_no_alloc),
51954 + atomic_read_unchecked(&fscache_n_object_avail),
51955 + atomic_read_unchecked(&fscache_n_object_dead));
51956 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
51957 - atomic_read(&fscache_n_checkaux_none),
51958 - atomic_read(&fscache_n_checkaux_okay),
51959 - atomic_read(&fscache_n_checkaux_update),
51960 - atomic_read(&fscache_n_checkaux_obsolete));
51961 + atomic_read_unchecked(&fscache_n_checkaux_none),
51962 + atomic_read_unchecked(&fscache_n_checkaux_okay),
51963 + atomic_read_unchecked(&fscache_n_checkaux_update),
51964 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
51965
51966 seq_printf(m, "Pages : mrk=%u unc=%u\n",
51967 - atomic_read(&fscache_n_marks),
51968 - atomic_read(&fscache_n_uncaches));
51969 + atomic_read_unchecked(&fscache_n_marks),
51970 + atomic_read_unchecked(&fscache_n_uncaches));
51971
51972 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
51973 " oom=%u\n",
51974 - atomic_read(&fscache_n_acquires),
51975 - atomic_read(&fscache_n_acquires_null),
51976 - atomic_read(&fscache_n_acquires_no_cache),
51977 - atomic_read(&fscache_n_acquires_ok),
51978 - atomic_read(&fscache_n_acquires_nobufs),
51979 - atomic_read(&fscache_n_acquires_oom));
51980 + atomic_read_unchecked(&fscache_n_acquires),
51981 + atomic_read_unchecked(&fscache_n_acquires_null),
51982 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
51983 + atomic_read_unchecked(&fscache_n_acquires_ok),
51984 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
51985 + atomic_read_unchecked(&fscache_n_acquires_oom));
51986
51987 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
51988 - atomic_read(&fscache_n_object_lookups),
51989 - atomic_read(&fscache_n_object_lookups_negative),
51990 - atomic_read(&fscache_n_object_lookups_positive),
51991 - atomic_read(&fscache_n_object_created),
51992 - atomic_read(&fscache_n_object_lookups_timed_out));
51993 + atomic_read_unchecked(&fscache_n_object_lookups),
51994 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
51995 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
51996 + atomic_read_unchecked(&fscache_n_object_created),
51997 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
51998
51999 seq_printf(m, "Invals : n=%u run=%u\n",
52000 - atomic_read(&fscache_n_invalidates),
52001 - atomic_read(&fscache_n_invalidates_run));
52002 + atomic_read_unchecked(&fscache_n_invalidates),
52003 + atomic_read_unchecked(&fscache_n_invalidates_run));
52004
52005 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
52006 - atomic_read(&fscache_n_updates),
52007 - atomic_read(&fscache_n_updates_null),
52008 - atomic_read(&fscache_n_updates_run));
52009 + atomic_read_unchecked(&fscache_n_updates),
52010 + atomic_read_unchecked(&fscache_n_updates_null),
52011 + atomic_read_unchecked(&fscache_n_updates_run));
52012
52013 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
52014 - atomic_read(&fscache_n_relinquishes),
52015 - atomic_read(&fscache_n_relinquishes_null),
52016 - atomic_read(&fscache_n_relinquishes_waitcrt),
52017 - atomic_read(&fscache_n_relinquishes_retire));
52018 + atomic_read_unchecked(&fscache_n_relinquishes),
52019 + atomic_read_unchecked(&fscache_n_relinquishes_null),
52020 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
52021 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
52022
52023 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
52024 - atomic_read(&fscache_n_attr_changed),
52025 - atomic_read(&fscache_n_attr_changed_ok),
52026 - atomic_read(&fscache_n_attr_changed_nobufs),
52027 - atomic_read(&fscache_n_attr_changed_nomem),
52028 - atomic_read(&fscache_n_attr_changed_calls));
52029 + atomic_read_unchecked(&fscache_n_attr_changed),
52030 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
52031 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
52032 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
52033 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
52034
52035 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
52036 - atomic_read(&fscache_n_allocs),
52037 - atomic_read(&fscache_n_allocs_ok),
52038 - atomic_read(&fscache_n_allocs_wait),
52039 - atomic_read(&fscache_n_allocs_nobufs),
52040 - atomic_read(&fscache_n_allocs_intr));
52041 + atomic_read_unchecked(&fscache_n_allocs),
52042 + atomic_read_unchecked(&fscache_n_allocs_ok),
52043 + atomic_read_unchecked(&fscache_n_allocs_wait),
52044 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
52045 + atomic_read_unchecked(&fscache_n_allocs_intr));
52046 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
52047 - atomic_read(&fscache_n_alloc_ops),
52048 - atomic_read(&fscache_n_alloc_op_waits),
52049 - atomic_read(&fscache_n_allocs_object_dead));
52050 + atomic_read_unchecked(&fscache_n_alloc_ops),
52051 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
52052 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
52053
52054 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
52055 " int=%u oom=%u\n",
52056 - atomic_read(&fscache_n_retrievals),
52057 - atomic_read(&fscache_n_retrievals_ok),
52058 - atomic_read(&fscache_n_retrievals_wait),
52059 - atomic_read(&fscache_n_retrievals_nodata),
52060 - atomic_read(&fscache_n_retrievals_nobufs),
52061 - atomic_read(&fscache_n_retrievals_intr),
52062 - atomic_read(&fscache_n_retrievals_nomem));
52063 + atomic_read_unchecked(&fscache_n_retrievals),
52064 + atomic_read_unchecked(&fscache_n_retrievals_ok),
52065 + atomic_read_unchecked(&fscache_n_retrievals_wait),
52066 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
52067 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
52068 + atomic_read_unchecked(&fscache_n_retrievals_intr),
52069 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
52070 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
52071 - atomic_read(&fscache_n_retrieval_ops),
52072 - atomic_read(&fscache_n_retrieval_op_waits),
52073 - atomic_read(&fscache_n_retrievals_object_dead));
52074 + atomic_read_unchecked(&fscache_n_retrieval_ops),
52075 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
52076 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
52077
52078 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
52079 - atomic_read(&fscache_n_stores),
52080 - atomic_read(&fscache_n_stores_ok),
52081 - atomic_read(&fscache_n_stores_again),
52082 - atomic_read(&fscache_n_stores_nobufs),
52083 - atomic_read(&fscache_n_stores_oom));
52084 + atomic_read_unchecked(&fscache_n_stores),
52085 + atomic_read_unchecked(&fscache_n_stores_ok),
52086 + atomic_read_unchecked(&fscache_n_stores_again),
52087 + atomic_read_unchecked(&fscache_n_stores_nobufs),
52088 + atomic_read_unchecked(&fscache_n_stores_oom));
52089 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
52090 - atomic_read(&fscache_n_store_ops),
52091 - atomic_read(&fscache_n_store_calls),
52092 - atomic_read(&fscache_n_store_pages),
52093 - atomic_read(&fscache_n_store_radix_deletes),
52094 - atomic_read(&fscache_n_store_pages_over_limit));
52095 + atomic_read_unchecked(&fscache_n_store_ops),
52096 + atomic_read_unchecked(&fscache_n_store_calls),
52097 + atomic_read_unchecked(&fscache_n_store_pages),
52098 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
52099 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
52100
52101 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
52102 - atomic_read(&fscache_n_store_vmscan_not_storing),
52103 - atomic_read(&fscache_n_store_vmscan_gone),
52104 - atomic_read(&fscache_n_store_vmscan_busy),
52105 - atomic_read(&fscache_n_store_vmscan_cancelled),
52106 - atomic_read(&fscache_n_store_vmscan_wait));
52107 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
52108 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
52109 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
52110 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
52111 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
52112
52113 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
52114 - atomic_read(&fscache_n_op_pend),
52115 - atomic_read(&fscache_n_op_run),
52116 - atomic_read(&fscache_n_op_enqueue),
52117 - atomic_read(&fscache_n_op_cancelled),
52118 - atomic_read(&fscache_n_op_rejected));
52119 + atomic_read_unchecked(&fscache_n_op_pend),
52120 + atomic_read_unchecked(&fscache_n_op_run),
52121 + atomic_read_unchecked(&fscache_n_op_enqueue),
52122 + atomic_read_unchecked(&fscache_n_op_cancelled),
52123 + atomic_read_unchecked(&fscache_n_op_rejected));
52124 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
52125 - atomic_read(&fscache_n_op_deferred_release),
52126 - atomic_read(&fscache_n_op_release),
52127 - atomic_read(&fscache_n_op_gc));
52128 + atomic_read_unchecked(&fscache_n_op_deferred_release),
52129 + atomic_read_unchecked(&fscache_n_op_release),
52130 + atomic_read_unchecked(&fscache_n_op_gc));
52131
52132 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
52133 atomic_read(&fscache_n_cop_alloc_object),
52134 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
52135 index e397b67..b0d8709 100644
52136 --- a/fs/fuse/cuse.c
52137 +++ b/fs/fuse/cuse.c
52138 @@ -593,10 +593,12 @@ static int __init cuse_init(void)
52139 INIT_LIST_HEAD(&cuse_conntbl[i]);
52140
52141 /* inherit and extend fuse_dev_operations */
52142 - cuse_channel_fops = fuse_dev_operations;
52143 - cuse_channel_fops.owner = THIS_MODULE;
52144 - cuse_channel_fops.open = cuse_channel_open;
52145 - cuse_channel_fops.release = cuse_channel_release;
52146 + pax_open_kernel();
52147 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
52148 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
52149 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
52150 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
52151 + pax_close_kernel();
52152
52153 cuse_class = class_create(THIS_MODULE, "cuse");
52154 if (IS_ERR(cuse_class))
52155 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
52156 index e83351a..41e3c9c 100644
52157 --- a/fs/fuse/dev.c
52158 +++ b/fs/fuse/dev.c
52159 @@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
52160 ret = 0;
52161 pipe_lock(pipe);
52162
52163 - if (!pipe->readers) {
52164 + if (!atomic_read(&pipe->readers)) {
52165 send_sig(SIGPIPE, current, 0);
52166 if (!ret)
52167 ret = -EPIPE;
52168 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
52169 index 315e1f8..91f890c 100644
52170 --- a/fs/fuse/dir.c
52171 +++ b/fs/fuse/dir.c
52172 @@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
52173 return link;
52174 }
52175
52176 -static void free_link(char *link)
52177 +static void free_link(const char *link)
52178 {
52179 if (!IS_ERR(link))
52180 free_page((unsigned long) link);
52181 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
52182 index 2b6f569..fcb4d1f 100644
52183 --- a/fs/gfs2/inode.c
52184 +++ b/fs/gfs2/inode.c
52185 @@ -1499,7 +1499,7 @@ out:
52186
52187 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52188 {
52189 - char *s = nd_get_link(nd);
52190 + const char *s = nd_get_link(nd);
52191 if (!IS_ERR(s))
52192 kfree(s);
52193 }
52194 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
52195 index 78bde32..767e906 100644
52196 --- a/fs/hugetlbfs/inode.c
52197 +++ b/fs/hugetlbfs/inode.c
52198 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52199 struct mm_struct *mm = current->mm;
52200 struct vm_area_struct *vma;
52201 struct hstate *h = hstate_file(file);
52202 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
52203 struct vm_unmapped_area_info info;
52204
52205 if (len & ~huge_page_mask(h))
52206 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52207 return addr;
52208 }
52209
52210 +#ifdef CONFIG_PAX_RANDMMAP
52211 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
52212 +#endif
52213 +
52214 if (addr) {
52215 addr = ALIGN(addr, huge_page_size(h));
52216 vma = find_vma(mm, addr);
52217 - if (TASK_SIZE - len >= addr &&
52218 - (!vma || addr + len <= vma->vm_start))
52219 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
52220 return addr;
52221 }
52222
52223 info.flags = 0;
52224 info.length = len;
52225 info.low_limit = TASK_UNMAPPED_BASE;
52226 +
52227 +#ifdef CONFIG_PAX_RANDMMAP
52228 + if (mm->pax_flags & MF_PAX_RANDMMAP)
52229 + info.low_limit += mm->delta_mmap;
52230 +#endif
52231 +
52232 info.high_limit = TASK_SIZE;
52233 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
52234 info.align_offset = 0;
52235 @@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
52236 .kill_sb = kill_litter_super,
52237 };
52238
52239 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52240 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52241
52242 static int can_do_hugetlb_shm(void)
52243 {
52244 diff --git a/fs/inode.c b/fs/inode.c
52245 index 14084b7..29af1d9 100644
52246 --- a/fs/inode.c
52247 +++ b/fs/inode.c
52248 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
52249
52250 #ifdef CONFIG_SMP
52251 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
52252 - static atomic_t shared_last_ino;
52253 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
52254 + static atomic_unchecked_t shared_last_ino;
52255 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
52256
52257 res = next - LAST_INO_BATCH;
52258 }
52259 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
52260 index 4a6cf28..d3a29d3 100644
52261 --- a/fs/jffs2/erase.c
52262 +++ b/fs/jffs2/erase.c
52263 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
52264 struct jffs2_unknown_node marker = {
52265 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
52266 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52267 - .totlen = cpu_to_je32(c->cleanmarker_size)
52268 + .totlen = cpu_to_je32(c->cleanmarker_size),
52269 + .hdr_crc = cpu_to_je32(0)
52270 };
52271
52272 jffs2_prealloc_raw_node_refs(c, jeb, 1);
52273 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
52274 index a6597d6..41b30ec 100644
52275 --- a/fs/jffs2/wbuf.c
52276 +++ b/fs/jffs2/wbuf.c
52277 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
52278 {
52279 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
52280 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52281 - .totlen = constant_cpu_to_je32(8)
52282 + .totlen = constant_cpu_to_je32(8),
52283 + .hdr_crc = constant_cpu_to_je32(0)
52284 };
52285
52286 /*
52287 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
52288 index 1a543be..a4e1363 100644
52289 --- a/fs/jfs/super.c
52290 +++ b/fs/jfs/super.c
52291 @@ -225,7 +225,7 @@ static const match_table_t tokens = {
52292 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52293 int *flag)
52294 {
52295 - void *nls_map = (void *)-1; /* -1: no change; NULL: none */
52296 + const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
52297 char *p;
52298 struct jfs_sb_info *sbi = JFS_SBI(sb);
52299
52300 @@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52301 /* Don't do anything ;-) */
52302 break;
52303 case Opt_iocharset:
52304 - if (nls_map && nls_map != (void *) -1)
52305 + if (nls_map && nls_map != (const void *) -1)
52306 unload_nls(nls_map);
52307 if (!strcmp(args[0].from, "none"))
52308 nls_map = NULL;
52309 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
52310
52311 jfs_inode_cachep =
52312 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
52313 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
52314 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
52315 init_once);
52316 if (jfs_inode_cachep == NULL)
52317 return -ENOMEM;
52318 diff --git a/fs/libfs.c b/fs/libfs.c
52319 index 916da8c..1588998 100644
52320 --- a/fs/libfs.c
52321 +++ b/fs/libfs.c
52322 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52323
52324 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
52325 struct dentry *next;
52326 + char d_name[sizeof(next->d_iname)];
52327 + const unsigned char *name;
52328 +
52329 next = list_entry(p, struct dentry, d_u.d_child);
52330 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
52331 if (!simple_positive(next)) {
52332 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52333
52334 spin_unlock(&next->d_lock);
52335 spin_unlock(&dentry->d_lock);
52336 - if (filldir(dirent, next->d_name.name,
52337 + name = next->d_name.name;
52338 + if (name == next->d_iname) {
52339 + memcpy(d_name, name, next->d_name.len);
52340 + name = d_name;
52341 + }
52342 + if (filldir(dirent, name,
52343 next->d_name.len, filp->f_pos,
52344 next->d_inode->i_ino,
52345 dt_type(next->d_inode)) < 0)
52346 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
52347 index 52e5120..808936e 100644
52348 --- a/fs/lockd/clntproc.c
52349 +++ b/fs/lockd/clntproc.c
52350 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
52351 /*
52352 * Cookie counter for NLM requests
52353 */
52354 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
52355 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
52356
52357 void nlmclnt_next_cookie(struct nlm_cookie *c)
52358 {
52359 - u32 cookie = atomic_inc_return(&nlm_cookie);
52360 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
52361
52362 memcpy(c->data, &cookie, 4);
52363 c->len=4;
52364 diff --git a/fs/locks.c b/fs/locks.c
52365 index a94e331..060bce3 100644
52366 --- a/fs/locks.c
52367 +++ b/fs/locks.c
52368 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
52369 return;
52370
52371 if (filp->f_op && filp->f_op->flock) {
52372 - struct file_lock fl = {
52373 + struct file_lock flock = {
52374 .fl_pid = current->tgid,
52375 .fl_file = filp,
52376 .fl_flags = FL_FLOCK,
52377 .fl_type = F_UNLCK,
52378 .fl_end = OFFSET_MAX,
52379 };
52380 - filp->f_op->flock(filp, F_SETLKW, &fl);
52381 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
52382 - fl.fl_ops->fl_release_private(&fl);
52383 + filp->f_op->flock(filp, F_SETLKW, &flock);
52384 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
52385 + flock.fl_ops->fl_release_private(&flock);
52386 }
52387
52388 lock_flocks();
52389 diff --git a/fs/namei.c b/fs/namei.c
52390 index 43a97ee..4e585fd 100644
52391 --- a/fs/namei.c
52392 +++ b/fs/namei.c
52393 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
52394 if (ret != -EACCES)
52395 return ret;
52396
52397 +#ifdef CONFIG_GRKERNSEC
52398 + /* we'll block if we have to log due to a denied capability use */
52399 + if (mask & MAY_NOT_BLOCK)
52400 + return -ECHILD;
52401 +#endif
52402 +
52403 if (S_ISDIR(inode->i_mode)) {
52404 /* DACs are overridable for directories */
52405 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
52406 - return 0;
52407 if (!(mask & MAY_WRITE))
52408 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52409 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52410 + inode_capable(inode, CAP_DAC_READ_SEARCH))
52411 return 0;
52412 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
52413 + return 0;
52414 return -EACCES;
52415 }
52416 /*
52417 + * Searching includes executable on directories, else just read.
52418 + */
52419 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52420 + if (mask == MAY_READ)
52421 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52422 + inode_capable(inode, CAP_DAC_READ_SEARCH))
52423 + return 0;
52424 +
52425 + /*
52426 * Read/write DACs are always overridable.
52427 * Executable DACs are overridable when there is
52428 * at least one exec bit set.
52429 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
52430 if (inode_capable(inode, CAP_DAC_OVERRIDE))
52431 return 0;
52432
52433 - /*
52434 - * Searching includes executable on directories, else just read.
52435 - */
52436 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52437 - if (mask == MAY_READ)
52438 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52439 - return 0;
52440 -
52441 return -EACCES;
52442 }
52443
52444 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52445 {
52446 struct dentry *dentry = link->dentry;
52447 int error;
52448 - char *s;
52449 + const char *s;
52450
52451 BUG_ON(nd->flags & LOOKUP_RCU);
52452
52453 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52454 if (error)
52455 goto out_put_nd_path;
52456
52457 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
52458 + dentry->d_inode, dentry, nd->path.mnt)) {
52459 + error = -EACCES;
52460 + goto out_put_nd_path;
52461 + }
52462 +
52463 nd->last_type = LAST_BIND;
52464 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
52465 error = PTR_ERR(*p);
52466 @@ -1596,6 +1610,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
52467 break;
52468 res = walk_component(nd, path, &nd->last,
52469 nd->last_type, LOOKUP_FOLLOW);
52470 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
52471 + res = -EACCES;
52472 put_link(nd, &link, cookie);
52473 } while (res > 0);
52474
52475 @@ -1694,7 +1710,7 @@ EXPORT_SYMBOL(full_name_hash);
52476 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
52477 {
52478 unsigned long a, b, adata, bdata, mask, hash, len;
52479 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52480 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52481
52482 hash = a = 0;
52483 len = -sizeof(unsigned long);
52484 @@ -1979,6 +1995,8 @@ static int path_lookupat(int dfd, const char *name,
52485 if (err)
52486 break;
52487 err = lookup_last(nd, &path);
52488 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
52489 + err = -EACCES;
52490 put_link(nd, &link, cookie);
52491 }
52492 }
52493 @@ -1986,6 +2004,19 @@ static int path_lookupat(int dfd, const char *name,
52494 if (!err)
52495 err = complete_walk(nd);
52496
52497 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
52498 +#ifdef CONFIG_GRKERNSEC
52499 + if (flags & LOOKUP_RCU) {
52500 + path_put(&nd->path);
52501 + err = -ECHILD;
52502 + } else
52503 +#endif
52504 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52505 + path_put(&nd->path);
52506 + err = -ENOENT;
52507 + }
52508 + }
52509 +
52510 if (!err && nd->flags & LOOKUP_DIRECTORY) {
52511 if (!nd->inode->i_op->lookup) {
52512 path_put(&nd->path);
52513 @@ -2013,8 +2044,17 @@ static int filename_lookup(int dfd, struct filename *name,
52514 retval = path_lookupat(dfd, name->name,
52515 flags | LOOKUP_REVAL, nd);
52516
52517 - if (likely(!retval))
52518 + if (likely(!retval)) {
52519 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
52520 +#ifdef CONFIG_GRKERNSEC
52521 + if (flags & LOOKUP_RCU)
52522 + return -ECHILD;
52523 +#endif
52524 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
52525 + return -ENOENT;
52526 + }
52527 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
52528 + }
52529 return retval;
52530 }
52531
52532 @@ -2392,6 +2432,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
52533 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
52534 return -EPERM;
52535
52536 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
52537 + return -EPERM;
52538 + if (gr_handle_rawio(inode))
52539 + return -EPERM;
52540 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
52541 + return -EACCES;
52542 +
52543 return 0;
52544 }
52545
52546 @@ -2613,7 +2660,7 @@ looked_up:
52547 * cleared otherwise prior to returning.
52548 */
52549 static int lookup_open(struct nameidata *nd, struct path *path,
52550 - struct file *file,
52551 + struct path *link, struct file *file,
52552 const struct open_flags *op,
52553 bool got_write, int *opened)
52554 {
52555 @@ -2648,6 +2695,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52556 /* Negative dentry, just create the file */
52557 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
52558 umode_t mode = op->mode;
52559 +
52560 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
52561 + error = -EACCES;
52562 + goto out_dput;
52563 + }
52564 +
52565 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
52566 + error = -EACCES;
52567 + goto out_dput;
52568 + }
52569 +
52570 if (!IS_POSIXACL(dir->d_inode))
52571 mode &= ~current_umask();
52572 /*
52573 @@ -2669,6 +2727,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52574 nd->flags & LOOKUP_EXCL);
52575 if (error)
52576 goto out_dput;
52577 + else
52578 + gr_handle_create(dentry, nd->path.mnt);
52579 }
52580 out_no_open:
52581 path->dentry = dentry;
52582 @@ -2683,7 +2743,7 @@ out_dput:
52583 /*
52584 * Handle the last step of open()
52585 */
52586 -static int do_last(struct nameidata *nd, struct path *path,
52587 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
52588 struct file *file, const struct open_flags *op,
52589 int *opened, struct filename *name)
52590 {
52591 @@ -2712,16 +2772,44 @@ static int do_last(struct nameidata *nd, struct path *path,
52592 error = complete_walk(nd);
52593 if (error)
52594 return error;
52595 +#ifdef CONFIG_GRKERNSEC
52596 + if (nd->flags & LOOKUP_RCU) {
52597 + error = -ECHILD;
52598 + goto out;
52599 + }
52600 +#endif
52601 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52602 + error = -ENOENT;
52603 + goto out;
52604 + }
52605 audit_inode(name, nd->path.dentry, 0);
52606 if (open_flag & O_CREAT) {
52607 error = -EISDIR;
52608 goto out;
52609 }
52610 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
52611 + error = -EACCES;
52612 + goto out;
52613 + }
52614 goto finish_open;
52615 case LAST_BIND:
52616 error = complete_walk(nd);
52617 if (error)
52618 return error;
52619 +#ifdef CONFIG_GRKERNSEC
52620 + if (nd->flags & LOOKUP_RCU) {
52621 + error = -ECHILD;
52622 + goto out;
52623 + }
52624 +#endif
52625 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
52626 + error = -ENOENT;
52627 + goto out;
52628 + }
52629 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
52630 + error = -EACCES;
52631 + goto out;
52632 + }
52633 audit_inode(name, dir, 0);
52634 goto finish_open;
52635 }
52636 @@ -2770,7 +2858,7 @@ retry_lookup:
52637 */
52638 }
52639 mutex_lock(&dir->d_inode->i_mutex);
52640 - error = lookup_open(nd, path, file, op, got_write, opened);
52641 + error = lookup_open(nd, path, link, file, op, got_write, opened);
52642 mutex_unlock(&dir->d_inode->i_mutex);
52643
52644 if (error <= 0) {
52645 @@ -2794,11 +2882,28 @@ retry_lookup:
52646 goto finish_open_created;
52647 }
52648
52649 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
52650 + error = -ENOENT;
52651 + goto exit_dput;
52652 + }
52653 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
52654 + error = -EACCES;
52655 + goto exit_dput;
52656 + }
52657 +
52658 /*
52659 * create/update audit record if it already exists.
52660 */
52661 - if (path->dentry->d_inode)
52662 + if (path->dentry->d_inode) {
52663 + /* only check if O_CREAT is specified, all other checks need to go
52664 + into may_open */
52665 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
52666 + error = -EACCES;
52667 + goto exit_dput;
52668 + }
52669 +
52670 audit_inode(name, path->dentry, 0);
52671 + }
52672
52673 /*
52674 * If atomic_open() acquired write access it is dropped now due to
52675 @@ -2839,6 +2944,11 @@ finish_lookup:
52676 }
52677 }
52678 BUG_ON(inode != path->dentry->d_inode);
52679 + /* if we're resolving a symlink to another symlink */
52680 + if (link && gr_handle_symlink_owner(link, inode)) {
52681 + error = -EACCES;
52682 + goto out;
52683 + }
52684 return 1;
52685 }
52686
52687 @@ -2848,7 +2958,6 @@ finish_lookup:
52688 save_parent.dentry = nd->path.dentry;
52689 save_parent.mnt = mntget(path->mnt);
52690 nd->path.dentry = path->dentry;
52691 -
52692 }
52693 nd->inode = inode;
52694 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
52695 @@ -2857,6 +2966,22 @@ finish_lookup:
52696 path_put(&save_parent);
52697 return error;
52698 }
52699 +
52700 +#ifdef CONFIG_GRKERNSEC
52701 + if (nd->flags & LOOKUP_RCU) {
52702 + error = -ECHILD;
52703 + goto out;
52704 + }
52705 +#endif
52706 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52707 + error = -ENOENT;
52708 + goto out;
52709 + }
52710 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
52711 + error = -EACCES;
52712 + goto out;
52713 + }
52714 +
52715 error = -EISDIR;
52716 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
52717 goto out;
52718 @@ -2955,7 +3080,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
52719 if (unlikely(error))
52720 goto out;
52721
52722 - error = do_last(nd, &path, file, op, &opened, pathname);
52723 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
52724 while (unlikely(error > 0)) { /* trailing symlink */
52725 struct path link = path;
52726 void *cookie;
52727 @@ -2973,7 +3098,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
52728 error = follow_link(&link, nd, &cookie);
52729 if (unlikely(error))
52730 break;
52731 - error = do_last(nd, &path, file, op, &opened, pathname);
52732 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
52733 put_link(nd, &link, cookie);
52734 }
52735 out:
52736 @@ -3073,8 +3198,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
52737 goto unlock;
52738
52739 error = -EEXIST;
52740 - if (dentry->d_inode)
52741 + if (dentry->d_inode) {
52742 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
52743 + error = -ENOENT;
52744 + }
52745 goto fail;
52746 + }
52747 /*
52748 * Special case - lookup gave negative, but... we had foo/bar/
52749 * From the vfs_mknod() POV we just have a negative dentry -
52750 @@ -3126,6 +3255,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
52751 }
52752 EXPORT_SYMBOL(user_path_create);
52753
52754 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
52755 +{
52756 + struct filename *tmp = getname(pathname);
52757 + struct dentry *res;
52758 + if (IS_ERR(tmp))
52759 + return ERR_CAST(tmp);
52760 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
52761 + if (IS_ERR(res))
52762 + putname(tmp);
52763 + else
52764 + *to = tmp;
52765 + return res;
52766 +}
52767 +
52768 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
52769 {
52770 int error = may_create(dir, dentry);
52771 @@ -3188,6 +3331,17 @@ retry:
52772
52773 if (!IS_POSIXACL(path.dentry->d_inode))
52774 mode &= ~current_umask();
52775 +
52776 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
52777 + error = -EPERM;
52778 + goto out;
52779 + }
52780 +
52781 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
52782 + error = -EACCES;
52783 + goto out;
52784 + }
52785 +
52786 error = security_path_mknod(&path, dentry, mode, dev);
52787 if (error)
52788 goto out;
52789 @@ -3204,6 +3358,8 @@ retry:
52790 break;
52791 }
52792 out:
52793 + if (!error)
52794 + gr_handle_create(dentry, path.mnt);
52795 done_path_create(&path, dentry);
52796 if (retry_estale(error, lookup_flags)) {
52797 lookup_flags |= LOOKUP_REVAL;
52798 @@ -3256,9 +3412,16 @@ retry:
52799
52800 if (!IS_POSIXACL(path.dentry->d_inode))
52801 mode &= ~current_umask();
52802 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
52803 + error = -EACCES;
52804 + goto out;
52805 + }
52806 error = security_path_mkdir(&path, dentry, mode);
52807 if (!error)
52808 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
52809 + if (!error)
52810 + gr_handle_create(dentry, path.mnt);
52811 +out:
52812 done_path_create(&path, dentry);
52813 if (retry_estale(error, lookup_flags)) {
52814 lookup_flags |= LOOKUP_REVAL;
52815 @@ -3339,6 +3502,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
52816 struct filename *name;
52817 struct dentry *dentry;
52818 struct nameidata nd;
52819 + ino_t saved_ino = 0;
52820 + dev_t saved_dev = 0;
52821 unsigned int lookup_flags = 0;
52822 retry:
52823 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
52824 @@ -3371,10 +3536,21 @@ retry:
52825 error = -ENOENT;
52826 goto exit3;
52827 }
52828 +
52829 + saved_ino = dentry->d_inode->i_ino;
52830 + saved_dev = gr_get_dev_from_dentry(dentry);
52831 +
52832 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
52833 + error = -EACCES;
52834 + goto exit3;
52835 + }
52836 +
52837 error = security_path_rmdir(&nd.path, dentry);
52838 if (error)
52839 goto exit3;
52840 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
52841 + if (!error && (saved_dev || saved_ino))
52842 + gr_handle_delete(saved_ino, saved_dev);
52843 exit3:
52844 dput(dentry);
52845 exit2:
52846 @@ -3440,6 +3616,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
52847 struct dentry *dentry;
52848 struct nameidata nd;
52849 struct inode *inode = NULL;
52850 + ino_t saved_ino = 0;
52851 + dev_t saved_dev = 0;
52852 unsigned int lookup_flags = 0;
52853 retry:
52854 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
52855 @@ -3466,10 +3644,22 @@ retry:
52856 if (!inode)
52857 goto slashes;
52858 ihold(inode);
52859 +
52860 + if (inode->i_nlink <= 1) {
52861 + saved_ino = inode->i_ino;
52862 + saved_dev = gr_get_dev_from_dentry(dentry);
52863 + }
52864 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
52865 + error = -EACCES;
52866 + goto exit2;
52867 + }
52868 +
52869 error = security_path_unlink(&nd.path, dentry);
52870 if (error)
52871 goto exit2;
52872 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
52873 + if (!error && (saved_ino || saved_dev))
52874 + gr_handle_delete(saved_ino, saved_dev);
52875 exit2:
52876 dput(dentry);
52877 }
52878 @@ -3547,9 +3737,17 @@ retry:
52879 if (IS_ERR(dentry))
52880 goto out_putname;
52881
52882 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
52883 + error = -EACCES;
52884 + goto out;
52885 + }
52886 +
52887 error = security_path_symlink(&path, dentry, from->name);
52888 if (!error)
52889 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
52890 + if (!error)
52891 + gr_handle_create(dentry, path.mnt);
52892 +out:
52893 done_path_create(&path, dentry);
52894 if (retry_estale(error, lookup_flags)) {
52895 lookup_flags |= LOOKUP_REVAL;
52896 @@ -3623,6 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
52897 {
52898 struct dentry *new_dentry;
52899 struct path old_path, new_path;
52900 + struct filename *to = NULL;
52901 int how = 0;
52902 int error;
52903
52904 @@ -3646,7 +3845,7 @@ retry:
52905 if (error)
52906 return error;
52907
52908 - new_dentry = user_path_create(newdfd, newname, &new_path,
52909 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
52910 (how & LOOKUP_REVAL));
52911 error = PTR_ERR(new_dentry);
52912 if (IS_ERR(new_dentry))
52913 @@ -3658,11 +3857,28 @@ retry:
52914 error = may_linkat(&old_path);
52915 if (unlikely(error))
52916 goto out_dput;
52917 +
52918 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
52919 + old_path.dentry->d_inode,
52920 + old_path.dentry->d_inode->i_mode, to)) {
52921 + error = -EACCES;
52922 + goto out_dput;
52923 + }
52924 +
52925 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
52926 + old_path.dentry, old_path.mnt, to)) {
52927 + error = -EACCES;
52928 + goto out_dput;
52929 + }
52930 +
52931 error = security_path_link(old_path.dentry, &new_path, new_dentry);
52932 if (error)
52933 goto out_dput;
52934 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
52935 + if (!error)
52936 + gr_handle_create(new_dentry, new_path.mnt);
52937 out_dput:
52938 + putname(to);
52939 done_path_create(&new_path, new_dentry);
52940 if (retry_estale(error, how)) {
52941 how |= LOOKUP_REVAL;
52942 @@ -3908,12 +4124,21 @@ retry:
52943 if (new_dentry == trap)
52944 goto exit5;
52945
52946 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
52947 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
52948 + to);
52949 + if (error)
52950 + goto exit5;
52951 +
52952 error = security_path_rename(&oldnd.path, old_dentry,
52953 &newnd.path, new_dentry);
52954 if (error)
52955 goto exit5;
52956 error = vfs_rename(old_dir->d_inode, old_dentry,
52957 new_dir->d_inode, new_dentry);
52958 + if (!error)
52959 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
52960 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
52961 exit5:
52962 dput(new_dentry);
52963 exit4:
52964 @@ -3945,6 +4170,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
52965
52966 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
52967 {
52968 + char tmpbuf[64];
52969 + const char *newlink;
52970 int len;
52971
52972 len = PTR_ERR(link);
52973 @@ -3954,7 +4181,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
52974 len = strlen(link);
52975 if (len > (unsigned) buflen)
52976 len = buflen;
52977 - if (copy_to_user(buffer, link, len))
52978 +
52979 + if (len < sizeof(tmpbuf)) {
52980 + memcpy(tmpbuf, link, len);
52981 + newlink = tmpbuf;
52982 + } else
52983 + newlink = link;
52984 +
52985 + if (copy_to_user(buffer, newlink, len))
52986 len = -EFAULT;
52987 out:
52988 return len;
52989 diff --git a/fs/namespace.c b/fs/namespace.c
52990 index a51054f..f9b53e5 100644
52991 --- a/fs/namespace.c
52992 +++ b/fs/namespace.c
52993 @@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
52994 if (!(sb->s_flags & MS_RDONLY))
52995 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
52996 up_write(&sb->s_umount);
52997 +
52998 + gr_log_remount(mnt->mnt_devname, retval);
52999 +
53000 return retval;
53001 }
53002
53003 @@ -1234,6 +1237,9 @@ static int do_umount(struct mount *mnt, int flags)
53004 br_write_unlock(&vfsmount_lock);
53005 up_write(&namespace_sem);
53006 release_mounts(&umount_list);
53007 +
53008 + gr_log_unmount(mnt->mnt_devname, retval);
53009 +
53010 return retval;
53011 }
53012
53013 @@ -2287,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
53014 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
53015 MS_STRICTATIME);
53016
53017 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
53018 + retval = -EPERM;
53019 + goto dput_out;
53020 + }
53021 +
53022 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
53023 + retval = -EPERM;
53024 + goto dput_out;
53025 + }
53026 +
53027 if (flags & MS_REMOUNT)
53028 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
53029 data_page);
53030 @@ -2301,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
53031 dev_name, data_page);
53032 dput_out:
53033 path_put(&path);
53034 +
53035 + gr_log_mount(dev_name, dir_name, retval);
53036 +
53037 return retval;
53038 }
53039
53040 @@ -2587,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
53041 if (error)
53042 goto out2;
53043
53044 + if (gr_handle_chroot_pivot()) {
53045 + error = -EPERM;
53046 + goto out2;
53047 + }
53048 +
53049 get_fs_root(current->fs, &root);
53050 error = lock_mount(&old);
53051 if (error)
53052 @@ -2790,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
53053 !nsown_capable(CAP_SYS_ADMIN))
53054 return -EPERM;
53055
53056 - if (fs->users != 1)
53057 + if (atomic_read(&fs->users) != 1)
53058 return -EINVAL;
53059
53060 get_mnt_ns(mnt_ns);
53061 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
53062 index 59461c9..b17c57e 100644
53063 --- a/fs/nfs/callback_xdr.c
53064 +++ b/fs/nfs/callback_xdr.c
53065 @@ -51,7 +51,7 @@ struct callback_op {
53066 callback_decode_arg_t decode_args;
53067 callback_encode_res_t encode_res;
53068 long res_maxsize;
53069 -};
53070 +} __do_const;
53071
53072 static struct callback_op callback_ops[];
53073
53074 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
53075 index ebeb94c..ff35337 100644
53076 --- a/fs/nfs/inode.c
53077 +++ b/fs/nfs/inode.c
53078 @@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
53079 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
53080 }
53081
53082 -static atomic_long_t nfs_attr_generation_counter;
53083 +static atomic_long_unchecked_t nfs_attr_generation_counter;
53084
53085 static unsigned long nfs_read_attr_generation_counter(void)
53086 {
53087 - return atomic_long_read(&nfs_attr_generation_counter);
53088 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
53089 }
53090
53091 unsigned long nfs_inc_attr_generation_counter(void)
53092 {
53093 - return atomic_long_inc_return(&nfs_attr_generation_counter);
53094 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
53095 }
53096
53097 void nfs_fattr_init(struct nfs_fattr *fattr)
53098 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
53099 index 9d1c5db..1e13db8 100644
53100 --- a/fs/nfsd/nfs4proc.c
53101 +++ b/fs/nfsd/nfs4proc.c
53102 @@ -1097,7 +1097,7 @@ struct nfsd4_operation {
53103 nfsd4op_rsize op_rsize_bop;
53104 stateid_getter op_get_currentstateid;
53105 stateid_setter op_set_currentstateid;
53106 -};
53107 +} __do_const;
53108
53109 static struct nfsd4_operation nfsd4_ops[];
53110
53111 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
53112 index 0dc1158..ccf0338 100644
53113 --- a/fs/nfsd/nfs4xdr.c
53114 +++ b/fs/nfsd/nfs4xdr.c
53115 @@ -1456,7 +1456,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
53116
53117 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
53118
53119 -static nfsd4_dec nfsd4_dec_ops[] = {
53120 +static const nfsd4_dec nfsd4_dec_ops[] = {
53121 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53122 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53123 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53124 @@ -1496,7 +1496,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
53125 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
53126 };
53127
53128 -static nfsd4_dec nfsd41_dec_ops[] = {
53129 +static const nfsd4_dec nfsd41_dec_ops[] = {
53130 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53131 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53132 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53133 @@ -1558,7 +1558,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
53134 };
53135
53136 struct nfsd4_minorversion_ops {
53137 - nfsd4_dec *decoders;
53138 + const nfsd4_dec *decoders;
53139 int nops;
53140 };
53141
53142 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
53143 index d586117..143d568 100644
53144 --- a/fs/nfsd/vfs.c
53145 +++ b/fs/nfsd/vfs.c
53146 @@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53147 } else {
53148 oldfs = get_fs();
53149 set_fs(KERNEL_DS);
53150 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
53151 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
53152 set_fs(oldfs);
53153 }
53154
53155 @@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53156
53157 /* Write the data. */
53158 oldfs = get_fs(); set_fs(KERNEL_DS);
53159 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
53160 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
53161 set_fs(oldfs);
53162 if (host_err < 0)
53163 goto out_nfserr;
53164 @@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
53165 */
53166
53167 oldfs = get_fs(); set_fs(KERNEL_DS);
53168 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
53169 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
53170 set_fs(oldfs);
53171
53172 if (host_err < 0)
53173 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
53174 index fea6bd5..8ee9d81 100644
53175 --- a/fs/nls/nls_base.c
53176 +++ b/fs/nls/nls_base.c
53177 @@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
53178
53179 int register_nls(struct nls_table * nls)
53180 {
53181 - struct nls_table ** tmp = &tables;
53182 + struct nls_table *tmp = tables;
53183
53184 if (nls->next)
53185 return -EBUSY;
53186
53187 spin_lock(&nls_lock);
53188 - while (*tmp) {
53189 - if (nls == *tmp) {
53190 + while (tmp) {
53191 + if (nls == tmp) {
53192 spin_unlock(&nls_lock);
53193 return -EBUSY;
53194 }
53195 - tmp = &(*tmp)->next;
53196 + tmp = tmp->next;
53197 }
53198 - nls->next = tables;
53199 + pax_open_kernel();
53200 + *(struct nls_table **)&nls->next = tables;
53201 + pax_close_kernel();
53202 tables = nls;
53203 spin_unlock(&nls_lock);
53204 return 0;
53205 @@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
53206
53207 int unregister_nls(struct nls_table * nls)
53208 {
53209 - struct nls_table ** tmp = &tables;
53210 + struct nls_table * const * tmp = &tables;
53211
53212 spin_lock(&nls_lock);
53213 while (*tmp) {
53214 if (nls == *tmp) {
53215 - *tmp = nls->next;
53216 + pax_open_kernel();
53217 + *(struct nls_table **)tmp = nls->next;
53218 + pax_close_kernel();
53219 spin_unlock(&nls_lock);
53220 return 0;
53221 }
53222 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
53223 index 7424929..35f6be5 100644
53224 --- a/fs/nls/nls_euc-jp.c
53225 +++ b/fs/nls/nls_euc-jp.c
53226 @@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
53227 p_nls = load_nls("cp932");
53228
53229 if (p_nls) {
53230 - table.charset2upper = p_nls->charset2upper;
53231 - table.charset2lower = p_nls->charset2lower;
53232 + pax_open_kernel();
53233 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53234 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53235 + pax_close_kernel();
53236 return register_nls(&table);
53237 }
53238
53239 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
53240 index e7bc1d7..06bd4bb 100644
53241 --- a/fs/nls/nls_koi8-ru.c
53242 +++ b/fs/nls/nls_koi8-ru.c
53243 @@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
53244 p_nls = load_nls("koi8-u");
53245
53246 if (p_nls) {
53247 - table.charset2upper = p_nls->charset2upper;
53248 - table.charset2lower = p_nls->charset2lower;
53249 + pax_open_kernel();
53250 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53251 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53252 + pax_close_kernel();
53253 return register_nls(&table);
53254 }
53255
53256 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
53257 index 9ff4a5e..deb1f0f 100644
53258 --- a/fs/notify/fanotify/fanotify_user.c
53259 +++ b/fs/notify/fanotify/fanotify_user.c
53260 @@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
53261
53262 fd = fanotify_event_metadata.fd;
53263 ret = -EFAULT;
53264 - if (copy_to_user(buf, &fanotify_event_metadata,
53265 - fanotify_event_metadata.event_len))
53266 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
53267 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
53268 goto out_close_fd;
53269
53270 ret = prepare_for_access_response(group, event, fd);
53271 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
53272 index 7b51b05..5ea5ef6 100644
53273 --- a/fs/notify/notification.c
53274 +++ b/fs/notify/notification.c
53275 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
53276 * get set to 0 so it will never get 'freed'
53277 */
53278 static struct fsnotify_event *q_overflow_event;
53279 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53280 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53281
53282 /**
53283 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
53284 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53285 */
53286 u32 fsnotify_get_cookie(void)
53287 {
53288 - return atomic_inc_return(&fsnotify_sync_cookie);
53289 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
53290 }
53291 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
53292
53293 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
53294 index 99e3610..02c1068 100644
53295 --- a/fs/ntfs/dir.c
53296 +++ b/fs/ntfs/dir.c
53297 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
53298 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
53299 ~(s64)(ndir->itype.index.block_size - 1)));
53300 /* Bounds checks. */
53301 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53302 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53303 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
53304 "inode 0x%lx or driver bug.", vdir->i_ino);
53305 goto err_out;
53306 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
53307 index 5b2d4f0..c6de396 100644
53308 --- a/fs/ntfs/file.c
53309 +++ b/fs/ntfs/file.c
53310 @@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
53311 #endif /* NTFS_RW */
53312 };
53313
53314 -const struct file_operations ntfs_empty_file_ops = {};
53315 +const struct file_operations ntfs_empty_file_ops __read_only;
53316
53317 -const struct inode_operations ntfs_empty_inode_ops = {};
53318 +const struct inode_operations ntfs_empty_inode_ops __read_only;
53319 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
53320 index a9f78c7..ed8a381 100644
53321 --- a/fs/ocfs2/localalloc.c
53322 +++ b/fs/ocfs2/localalloc.c
53323 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
53324 goto bail;
53325 }
53326
53327 - atomic_inc(&osb->alloc_stats.moves);
53328 + atomic_inc_unchecked(&osb->alloc_stats.moves);
53329
53330 bail:
53331 if (handle)
53332 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
53333 index d355e6e..578d905 100644
53334 --- a/fs/ocfs2/ocfs2.h
53335 +++ b/fs/ocfs2/ocfs2.h
53336 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
53337
53338 struct ocfs2_alloc_stats
53339 {
53340 - atomic_t moves;
53341 - atomic_t local_data;
53342 - atomic_t bitmap_data;
53343 - atomic_t bg_allocs;
53344 - atomic_t bg_extends;
53345 + atomic_unchecked_t moves;
53346 + atomic_unchecked_t local_data;
53347 + atomic_unchecked_t bitmap_data;
53348 + atomic_unchecked_t bg_allocs;
53349 + atomic_unchecked_t bg_extends;
53350 };
53351
53352 enum ocfs2_local_alloc_state
53353 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
53354 index b7e74b5..19c6536 100644
53355 --- a/fs/ocfs2/suballoc.c
53356 +++ b/fs/ocfs2/suballoc.c
53357 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
53358 mlog_errno(status);
53359 goto bail;
53360 }
53361 - atomic_inc(&osb->alloc_stats.bg_extends);
53362 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
53363
53364 /* You should never ask for this much metadata */
53365 BUG_ON(bits_wanted >
53366 @@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
53367 mlog_errno(status);
53368 goto bail;
53369 }
53370 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53371 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53372
53373 *suballoc_loc = res.sr_bg_blkno;
53374 *suballoc_bit_start = res.sr_bit_offset;
53375 @@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
53376 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
53377 res->sr_bits);
53378
53379 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53380 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53381
53382 BUG_ON(res->sr_bits != 1);
53383
53384 @@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
53385 mlog_errno(status);
53386 goto bail;
53387 }
53388 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53389 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53390
53391 BUG_ON(res.sr_bits != 1);
53392
53393 @@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53394 cluster_start,
53395 num_clusters);
53396 if (!status)
53397 - atomic_inc(&osb->alloc_stats.local_data);
53398 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
53399 } else {
53400 if (min_clusters > (osb->bitmap_cpg - 1)) {
53401 /* The only paths asking for contiguousness
53402 @@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53403 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
53404 res.sr_bg_blkno,
53405 res.sr_bit_offset);
53406 - atomic_inc(&osb->alloc_stats.bitmap_data);
53407 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
53408 *num_clusters = res.sr_bits;
53409 }
53410 }
53411 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
53412 index 0e91ec2..f4b3fc6 100644
53413 --- a/fs/ocfs2/super.c
53414 +++ b/fs/ocfs2/super.c
53415 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
53416 "%10s => GlobalAllocs: %d LocalAllocs: %d "
53417 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
53418 "Stats",
53419 - atomic_read(&osb->alloc_stats.bitmap_data),
53420 - atomic_read(&osb->alloc_stats.local_data),
53421 - atomic_read(&osb->alloc_stats.bg_allocs),
53422 - atomic_read(&osb->alloc_stats.moves),
53423 - atomic_read(&osb->alloc_stats.bg_extends));
53424 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
53425 + atomic_read_unchecked(&osb->alloc_stats.local_data),
53426 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
53427 + atomic_read_unchecked(&osb->alloc_stats.moves),
53428 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
53429
53430 out += snprintf(buf + out, len - out,
53431 "%10s => State: %u Descriptor: %llu Size: %u bits "
53432 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
53433 spin_lock_init(&osb->osb_xattr_lock);
53434 ocfs2_init_steal_slots(osb);
53435
53436 - atomic_set(&osb->alloc_stats.moves, 0);
53437 - atomic_set(&osb->alloc_stats.local_data, 0);
53438 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
53439 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
53440 - atomic_set(&osb->alloc_stats.bg_extends, 0);
53441 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
53442 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
53443 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
53444 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
53445 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
53446
53447 /* Copy the blockcheck stats from the superblock probe */
53448 osb->osb_ecc_stats = *stats;
53449 diff --git a/fs/open.c b/fs/open.c
53450 index 9b33c0c..2ffcca2 100644
53451 --- a/fs/open.c
53452 +++ b/fs/open.c
53453 @@ -31,6 +31,8 @@
53454 #include <linux/ima.h>
53455 #include <linux/dnotify.h>
53456
53457 +#define CREATE_TRACE_POINTS
53458 +#include <trace/events/fs.h>
53459 #include "internal.h"
53460
53461 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
53462 @@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
53463 error = locks_verify_truncate(inode, NULL, length);
53464 if (!error)
53465 error = security_path_truncate(path);
53466 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
53467 + error = -EACCES;
53468 if (!error)
53469 error = do_truncate(path->dentry, length, 0, NULL);
53470
53471 @@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
53472 error = locks_verify_truncate(inode, f.file, length);
53473 if (!error)
53474 error = security_path_truncate(&f.file->f_path);
53475 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
53476 + error = -EACCES;
53477 if (!error)
53478 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
53479 sb_end_write(inode->i_sb);
53480 @@ -373,6 +379,9 @@ retry:
53481 if (__mnt_is_readonly(path.mnt))
53482 res = -EROFS;
53483
53484 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
53485 + res = -EACCES;
53486 +
53487 out_path_release:
53488 path_put(&path);
53489 if (retry_estale(res, lookup_flags)) {
53490 @@ -404,6 +413,8 @@ retry:
53491 if (error)
53492 goto dput_and_out;
53493
53494 + gr_log_chdir(path.dentry, path.mnt);
53495 +
53496 set_fs_pwd(current->fs, &path);
53497
53498 dput_and_out:
53499 @@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
53500 goto out_putf;
53501
53502 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
53503 +
53504 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
53505 + error = -EPERM;
53506 +
53507 + if (!error)
53508 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
53509 +
53510 if (!error)
53511 set_fs_pwd(current->fs, &f.file->f_path);
53512 out_putf:
53513 @@ -462,7 +480,13 @@ retry:
53514 if (error)
53515 goto dput_and_out;
53516
53517 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
53518 + goto dput_and_out;
53519 +
53520 set_fs_root(current->fs, &path);
53521 +
53522 + gr_handle_chroot_chdir(&path);
53523 +
53524 error = 0;
53525 dput_and_out:
53526 path_put(&path);
53527 @@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
53528 if (error)
53529 return error;
53530 mutex_lock(&inode->i_mutex);
53531 +
53532 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
53533 + error = -EACCES;
53534 + goto out_unlock;
53535 + }
53536 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
53537 + error = -EACCES;
53538 + goto out_unlock;
53539 + }
53540 +
53541 error = security_path_chmod(path, mode);
53542 if (error)
53543 goto out_unlock;
53544 @@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
53545 uid = make_kuid(current_user_ns(), user);
53546 gid = make_kgid(current_user_ns(), group);
53547
53548 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
53549 + return -EACCES;
53550 +
53551 newattrs.ia_valid = ATTR_CTIME;
53552 if (user != (uid_t) -1) {
53553 if (!uid_valid(uid))
53554 @@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
53555 } else {
53556 fsnotify_open(f);
53557 fd_install(fd, f);
53558 + trace_do_sys_open(tmp->name, flags, mode);
53559 }
53560 }
53561 putname(tmp);
53562 diff --git a/fs/pipe.c b/fs/pipe.c
53563 index bd3479d..fb92c4d 100644
53564 --- a/fs/pipe.c
53565 +++ b/fs/pipe.c
53566 @@ -438,9 +438,9 @@ redo:
53567 }
53568 if (bufs) /* More to do? */
53569 continue;
53570 - if (!pipe->writers)
53571 + if (!atomic_read(&pipe->writers))
53572 break;
53573 - if (!pipe->waiting_writers) {
53574 + if (!atomic_read(&pipe->waiting_writers)) {
53575 /* syscall merging: Usually we must not sleep
53576 * if O_NONBLOCK is set, or if we got some data.
53577 * But if a writer sleeps in kernel space, then
53578 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
53579 mutex_lock(&inode->i_mutex);
53580 pipe = inode->i_pipe;
53581
53582 - if (!pipe->readers) {
53583 + if (!atomic_read(&pipe->readers)) {
53584 send_sig(SIGPIPE, current, 0);
53585 ret = -EPIPE;
53586 goto out;
53587 @@ -553,7 +553,7 @@ redo1:
53588 for (;;) {
53589 int bufs;
53590
53591 - if (!pipe->readers) {
53592 + if (!atomic_read(&pipe->readers)) {
53593 send_sig(SIGPIPE, current, 0);
53594 if (!ret)
53595 ret = -EPIPE;
53596 @@ -644,9 +644,9 @@ redo2:
53597 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
53598 do_wakeup = 0;
53599 }
53600 - pipe->waiting_writers++;
53601 + atomic_inc(&pipe->waiting_writers);
53602 pipe_wait(pipe);
53603 - pipe->waiting_writers--;
53604 + atomic_dec(&pipe->waiting_writers);
53605 }
53606 out:
53607 mutex_unlock(&inode->i_mutex);
53608 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
53609 mask = 0;
53610 if (filp->f_mode & FMODE_READ) {
53611 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
53612 - if (!pipe->writers && filp->f_version != pipe->w_counter)
53613 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
53614 mask |= POLLHUP;
53615 }
53616
53617 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
53618 * Most Unices do not set POLLERR for FIFOs but on Linux they
53619 * behave exactly like pipes for poll().
53620 */
53621 - if (!pipe->readers)
53622 + if (!atomic_read(&pipe->readers))
53623 mask |= POLLERR;
53624 }
53625
53626 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
53627
53628 mutex_lock(&inode->i_mutex);
53629 pipe = inode->i_pipe;
53630 - pipe->readers -= decr;
53631 - pipe->writers -= decw;
53632 + atomic_sub(decr, &pipe->readers);
53633 + atomic_sub(decw, &pipe->writers);
53634
53635 - if (!pipe->readers && !pipe->writers) {
53636 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
53637 free_pipe_info(inode);
53638 } else {
53639 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
53640 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
53641
53642 if (inode->i_pipe) {
53643 ret = 0;
53644 - inode->i_pipe->readers++;
53645 + atomic_inc(&inode->i_pipe->readers);
53646 }
53647
53648 mutex_unlock(&inode->i_mutex);
53649 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
53650
53651 if (inode->i_pipe) {
53652 ret = 0;
53653 - inode->i_pipe->writers++;
53654 + atomic_inc(&inode->i_pipe->writers);
53655 }
53656
53657 mutex_unlock(&inode->i_mutex);
53658 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
53659 if (inode->i_pipe) {
53660 ret = 0;
53661 if (filp->f_mode & FMODE_READ)
53662 - inode->i_pipe->readers++;
53663 + atomic_inc(&inode->i_pipe->readers);
53664 if (filp->f_mode & FMODE_WRITE)
53665 - inode->i_pipe->writers++;
53666 + atomic_inc(&inode->i_pipe->writers);
53667 }
53668
53669 mutex_unlock(&inode->i_mutex);
53670 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
53671 inode->i_pipe = NULL;
53672 }
53673
53674 -static struct vfsmount *pipe_mnt __read_mostly;
53675 +struct vfsmount *pipe_mnt __read_mostly;
53676
53677 /*
53678 * pipefs_dname() is called from d_path().
53679 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
53680 goto fail_iput;
53681 inode->i_pipe = pipe;
53682
53683 - pipe->readers = pipe->writers = 1;
53684 + atomic_set(&pipe->readers, 1);
53685 + atomic_set(&pipe->writers, 1);
53686 inode->i_fop = &rdwr_pipefifo_fops;
53687
53688 /*
53689 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
53690 index 15af622..0e9f4467 100644
53691 --- a/fs/proc/Kconfig
53692 +++ b/fs/proc/Kconfig
53693 @@ -30,12 +30,12 @@ config PROC_FS
53694
53695 config PROC_KCORE
53696 bool "/proc/kcore support" if !ARM
53697 - depends on PROC_FS && MMU
53698 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
53699
53700 config PROC_VMCORE
53701 bool "/proc/vmcore support"
53702 - depends on PROC_FS && CRASH_DUMP
53703 - default y
53704 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
53705 + default n
53706 help
53707 Exports the dump image of crashed kernel in ELF format.
53708
53709 @@ -59,8 +59,8 @@ config PROC_SYSCTL
53710 limited in memory.
53711
53712 config PROC_PAGE_MONITOR
53713 - default y
53714 - depends on PROC_FS && MMU
53715 + default n
53716 + depends on PROC_FS && MMU && !GRKERNSEC
53717 bool "Enable /proc page monitoring" if EXPERT
53718 help
53719 Various /proc files exist to monitor process memory utilization:
53720 diff --git a/fs/proc/array.c b/fs/proc/array.c
53721 index 6a91e6f..e54dbc14 100644
53722 --- a/fs/proc/array.c
53723 +++ b/fs/proc/array.c
53724 @@ -60,6 +60,7 @@
53725 #include <linux/tty.h>
53726 #include <linux/string.h>
53727 #include <linux/mman.h>
53728 +#include <linux/grsecurity.h>
53729 #include <linux/proc_fs.h>
53730 #include <linux/ioport.h>
53731 #include <linux/uaccess.h>
53732 @@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
53733 seq_putc(m, '\n');
53734 }
53735
53736 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53737 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
53738 +{
53739 + if (p->mm)
53740 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
53741 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
53742 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
53743 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
53744 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
53745 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
53746 + else
53747 + seq_printf(m, "PaX:\t-----\n");
53748 +}
53749 +#endif
53750 +
53751 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
53752 struct pid *pid, struct task_struct *task)
53753 {
53754 @@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
53755 task_cpus_allowed(m, task);
53756 cpuset_task_status_allowed(m, task);
53757 task_context_switch_counts(m, task);
53758 +
53759 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53760 + task_pax(m, task);
53761 +#endif
53762 +
53763 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
53764 + task_grsec_rbac(m, task);
53765 +#endif
53766 +
53767 return 0;
53768 }
53769
53770 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53771 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53772 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
53773 + _mm->pax_flags & MF_PAX_SEGMEXEC))
53774 +#endif
53775 +
53776 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53777 struct pid *pid, struct task_struct *task, int whole)
53778 {
53779 @@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53780 char tcomm[sizeof(task->comm)];
53781 unsigned long flags;
53782
53783 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53784 + if (current->exec_id != m->exec_id) {
53785 + gr_log_badprocpid("stat");
53786 + return 0;
53787 + }
53788 +#endif
53789 +
53790 state = *get_task_state(task);
53791 vsize = eip = esp = 0;
53792 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
53793 @@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53794 gtime = task->gtime;
53795 }
53796
53797 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53798 + if (PAX_RAND_FLAGS(mm)) {
53799 + eip = 0;
53800 + esp = 0;
53801 + wchan = 0;
53802 + }
53803 +#endif
53804 +#ifdef CONFIG_GRKERNSEC_HIDESYM
53805 + wchan = 0;
53806 + eip =0;
53807 + esp =0;
53808 +#endif
53809 +
53810 /* scale priority and nice values from timeslices to -20..20 */
53811 /* to make it look like a "normal" Unix priority/nice value */
53812 priority = task_prio(task);
53813 @@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53814 seq_put_decimal_ull(m, ' ', vsize);
53815 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
53816 seq_put_decimal_ull(m, ' ', rsslim);
53817 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53818 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
53819 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
53820 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
53821 +#else
53822 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
53823 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
53824 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
53825 +#endif
53826 seq_put_decimal_ull(m, ' ', esp);
53827 seq_put_decimal_ull(m, ' ', eip);
53828 /* The signal information here is obsolete.
53829 @@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53830 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
53831 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
53832
53833 - if (mm && permitted) {
53834 + if (mm && permitted
53835 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53836 + && !PAX_RAND_FLAGS(mm)
53837 +#endif
53838 + ) {
53839 seq_put_decimal_ull(m, ' ', mm->start_data);
53840 seq_put_decimal_ull(m, ' ', mm->end_data);
53841 seq_put_decimal_ull(m, ' ', mm->start_brk);
53842 @@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
53843 struct pid *pid, struct task_struct *task)
53844 {
53845 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
53846 - struct mm_struct *mm = get_task_mm(task);
53847 + struct mm_struct *mm;
53848
53849 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53850 + if (current->exec_id != m->exec_id) {
53851 + gr_log_badprocpid("statm");
53852 + return 0;
53853 + }
53854 +#endif
53855 + mm = get_task_mm(task);
53856 if (mm) {
53857 size = task_statm(mm, &shared, &text, &data, &resident);
53858 mmput(mm);
53859 @@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
53860 return 0;
53861 }
53862
53863 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
53864 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
53865 +{
53866 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
53867 +}
53868 +#endif
53869 +
53870 #ifdef CONFIG_CHECKPOINT_RESTORE
53871 static struct pid *
53872 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
53873 diff --git a/fs/proc/base.c b/fs/proc/base.c
53874 index 9b43ff77..ba3e990 100644
53875 --- a/fs/proc/base.c
53876 +++ b/fs/proc/base.c
53877 @@ -111,6 +111,14 @@ struct pid_entry {
53878 union proc_op op;
53879 };
53880
53881 +struct getdents_callback {
53882 + struct linux_dirent __user * current_dir;
53883 + struct linux_dirent __user * previous;
53884 + struct file * file;
53885 + int count;
53886 + int error;
53887 +};
53888 +
53889 #define NOD(NAME, MODE, IOP, FOP, OP) { \
53890 .name = (NAME), \
53891 .len = sizeof(NAME) - 1, \
53892 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
53893 if (!mm->arg_end)
53894 goto out_mm; /* Shh! No looking before we're done */
53895
53896 + if (gr_acl_handle_procpidmem(task))
53897 + goto out_mm;
53898 +
53899 len = mm->arg_end - mm->arg_start;
53900
53901 if (len > PAGE_SIZE)
53902 @@ -235,12 +246,28 @@ out:
53903 return res;
53904 }
53905
53906 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53907 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53908 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
53909 + _mm->pax_flags & MF_PAX_SEGMEXEC))
53910 +#endif
53911 +
53912 static int proc_pid_auxv(struct task_struct *task, char *buffer)
53913 {
53914 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
53915 int res = PTR_ERR(mm);
53916 if (mm && !IS_ERR(mm)) {
53917 unsigned int nwords = 0;
53918 +
53919 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53920 + /* allow if we're currently ptracing this task */
53921 + if (PAX_RAND_FLAGS(mm) &&
53922 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
53923 + mmput(mm);
53924 + return 0;
53925 + }
53926 +#endif
53927 +
53928 do {
53929 nwords += 2;
53930 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
53931 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
53932 }
53933
53934
53935 -#ifdef CONFIG_KALLSYMS
53936 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53937 /*
53938 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
53939 * Returns the resolved symbol. If that fails, simply return the address.
53940 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
53941 mutex_unlock(&task->signal->cred_guard_mutex);
53942 }
53943
53944 -#ifdef CONFIG_STACKTRACE
53945 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53946
53947 #define MAX_STACK_TRACE_DEPTH 64
53948
53949 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
53950 return count;
53951 }
53952
53953 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
53954 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
53955 static int proc_pid_syscall(struct task_struct *task, char *buffer)
53956 {
53957 long nr;
53958 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
53959 /************************************************************************/
53960
53961 /* permission checks */
53962 -static int proc_fd_access_allowed(struct inode *inode)
53963 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
53964 {
53965 struct task_struct *task;
53966 int allowed = 0;
53967 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
53968 */
53969 task = get_proc_task(inode);
53970 if (task) {
53971 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
53972 + if (log)
53973 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
53974 + else
53975 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
53976 put_task_struct(task);
53977 }
53978 return allowed;
53979 @@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
53980 struct task_struct *task,
53981 int hide_pid_min)
53982 {
53983 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
53984 + return false;
53985 +
53986 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53987 + rcu_read_lock();
53988 + {
53989 + const struct cred *tmpcred = current_cred();
53990 + const struct cred *cred = __task_cred(task);
53991 +
53992 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
53993 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
53994 + || in_group_p(grsec_proc_gid)
53995 +#endif
53996 + ) {
53997 + rcu_read_unlock();
53998 + return true;
53999 + }
54000 + }
54001 + rcu_read_unlock();
54002 +
54003 + if (!pid->hide_pid)
54004 + return false;
54005 +#endif
54006 +
54007 if (pid->hide_pid < hide_pid_min)
54008 return true;
54009 if (in_group_p(pid->pid_gid))
54010 return true;
54011 +
54012 return ptrace_may_access(task, PTRACE_MODE_READ);
54013 }
54014
54015 @@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
54016 put_task_struct(task);
54017
54018 if (!has_perms) {
54019 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54020 + {
54021 +#else
54022 if (pid->hide_pid == 2) {
54023 +#endif
54024 /*
54025 * Let's make getdents(), stat(), and open()
54026 * consistent with each other. If a process
54027 @@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54028 if (!task)
54029 return -ESRCH;
54030
54031 + if (gr_acl_handle_procpidmem(task)) {
54032 + put_task_struct(task);
54033 + return -EPERM;
54034 + }
54035 +
54036 mm = mm_access(task, mode);
54037 put_task_struct(task);
54038
54039 @@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54040
54041 file->private_data = mm;
54042
54043 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54044 + file->f_version = current->exec_id;
54045 +#endif
54046 +
54047 return 0;
54048 }
54049
54050 @@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
54051 ssize_t copied;
54052 char *page;
54053
54054 +#ifdef CONFIG_GRKERNSEC
54055 + if (write)
54056 + return -EPERM;
54057 +#endif
54058 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54059 + if (file->f_version != current->exec_id) {
54060 + gr_log_badprocpid("mem");
54061 + return 0;
54062 + }
54063 +#endif
54064 +
54065 if (!mm)
54066 return 0;
54067
54068 @@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
54069 if (!mm)
54070 return 0;
54071
54072 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54073 + if (file->f_version != current->exec_id) {
54074 + gr_log_badprocpid("environ");
54075 + return 0;
54076 + }
54077 +#endif
54078 +
54079 page = (char *)__get_free_page(GFP_TEMPORARY);
54080 if (!page)
54081 return -ENOMEM;
54082 @@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
54083 int error = -EACCES;
54084
54085 /* Are we allowed to snoop on the tasks file descriptors? */
54086 - if (!proc_fd_access_allowed(inode))
54087 + if (!proc_fd_access_allowed(inode, 0))
54088 goto out;
54089
54090 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54091 @@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
54092 struct path path;
54093
54094 /* Are we allowed to snoop on the tasks file descriptors? */
54095 - if (!proc_fd_access_allowed(inode))
54096 - goto out;
54097 + /* logging this is needed for learning on chromium to work properly,
54098 + but we don't want to flood the logs from 'ps' which does a readlink
54099 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
54100 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
54101 + */
54102 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
54103 + if (!proc_fd_access_allowed(inode,0))
54104 + goto out;
54105 + } else {
54106 + if (!proc_fd_access_allowed(inode,1))
54107 + goto out;
54108 + }
54109
54110 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54111 if (error)
54112 @@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
54113 rcu_read_lock();
54114 cred = __task_cred(task);
54115 inode->i_uid = cred->euid;
54116 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54117 + inode->i_gid = grsec_proc_gid;
54118 +#else
54119 inode->i_gid = cred->egid;
54120 +#endif
54121 rcu_read_unlock();
54122 }
54123 security_task_to_inode(task, inode);
54124 @@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
54125 return -ENOENT;
54126 }
54127 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54128 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54129 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54130 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54131 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54132 +#endif
54133 task_dumpable(task)) {
54134 cred = __task_cred(task);
54135 stat->uid = cred->euid;
54136 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54137 + stat->gid = grsec_proc_gid;
54138 +#else
54139 stat->gid = cred->egid;
54140 +#endif
54141 }
54142 }
54143 rcu_read_unlock();
54144 @@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
54145
54146 if (task) {
54147 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54148 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54149 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54150 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54151 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54152 +#endif
54153 task_dumpable(task)) {
54154 rcu_read_lock();
54155 cred = __task_cred(task);
54156 inode->i_uid = cred->euid;
54157 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54158 + inode->i_gid = grsec_proc_gid;
54159 +#else
54160 inode->i_gid = cred->egid;
54161 +#endif
54162 rcu_read_unlock();
54163 } else {
54164 inode->i_uid = GLOBAL_ROOT_UID;
54165 @@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
54166 if (!task)
54167 goto out_no_task;
54168
54169 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54170 + goto out;
54171 +
54172 /*
54173 * Yes, it does not scale. And it should not. Don't add
54174 * new entries into /proc/<tgid>/ without very good reasons.
54175 @@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
54176 if (!task)
54177 goto out_no_task;
54178
54179 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54180 + goto out;
54181 +
54182 ret = 0;
54183 i = filp->f_pos;
54184 switch (i) {
54185 @@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
54186 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
54187 #endif
54188 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54189 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54190 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54191 INF("syscall", S_IRUGO, proc_pid_syscall),
54192 #endif
54193 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54194 @@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
54195 #ifdef CONFIG_SECURITY
54196 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54197 #endif
54198 -#ifdef CONFIG_KALLSYMS
54199 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54200 INF("wchan", S_IRUGO, proc_pid_wchan),
54201 #endif
54202 -#ifdef CONFIG_STACKTRACE
54203 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54204 ONE("stack", S_IRUGO, proc_pid_stack),
54205 #endif
54206 #ifdef CONFIG_SCHEDSTATS
54207 @@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
54208 #ifdef CONFIG_HARDWALL
54209 INF("hardwall", S_IRUGO, proc_pid_hardwall),
54210 #endif
54211 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54212 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
54213 +#endif
54214 #ifdef CONFIG_USER_NS
54215 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
54216 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
54217 @@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
54218 if (!inode)
54219 goto out;
54220
54221 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54222 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
54223 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54224 + inode->i_gid = grsec_proc_gid;
54225 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
54226 +#else
54227 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
54228 +#endif
54229 inode->i_op = &proc_tgid_base_inode_operations;
54230 inode->i_fop = &proc_tgid_base_operations;
54231 inode->i_flags|=S_IMMUTABLE;
54232 @@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
54233 if (!task)
54234 goto out;
54235
54236 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54237 + goto out_put_task;
54238 +
54239 result = proc_pid_instantiate(dir, dentry, task, NULL);
54240 +out_put_task:
54241 put_task_struct(task);
54242 out:
54243 return result;
54244 @@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
54245 static int fake_filldir(void *buf, const char *name, int namelen,
54246 loff_t offset, u64 ino, unsigned d_type)
54247 {
54248 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
54249 + __buf->error = -EINVAL;
54250 return 0;
54251 }
54252
54253 @@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
54254 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
54255 #endif
54256 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54257 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54258 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54259 INF("syscall", S_IRUGO, proc_pid_syscall),
54260 #endif
54261 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54262 @@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
54263 #ifdef CONFIG_SECURITY
54264 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54265 #endif
54266 -#ifdef CONFIG_KALLSYMS
54267 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54268 INF("wchan", S_IRUGO, proc_pid_wchan),
54269 #endif
54270 -#ifdef CONFIG_STACKTRACE
54271 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54272 ONE("stack", S_IRUGO, proc_pid_stack),
54273 #endif
54274 #ifdef CONFIG_SCHEDSTATS
54275 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
54276 index 82676e3..5f8518a 100644
54277 --- a/fs/proc/cmdline.c
54278 +++ b/fs/proc/cmdline.c
54279 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
54280
54281 static int __init proc_cmdline_init(void)
54282 {
54283 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54284 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
54285 +#else
54286 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
54287 +#endif
54288 return 0;
54289 }
54290 module_init(proc_cmdline_init);
54291 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
54292 index b143471..bb105e5 100644
54293 --- a/fs/proc/devices.c
54294 +++ b/fs/proc/devices.c
54295 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
54296
54297 static int __init proc_devices_init(void)
54298 {
54299 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54300 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
54301 +#else
54302 proc_create("devices", 0, NULL, &proc_devinfo_operations);
54303 +#endif
54304 return 0;
54305 }
54306 module_init(proc_devices_init);
54307 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
54308 index d7a4a28..0201742 100644
54309 --- a/fs/proc/fd.c
54310 +++ b/fs/proc/fd.c
54311 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
54312 if (!task)
54313 return -ENOENT;
54314
54315 - files = get_files_struct(task);
54316 + if (!gr_acl_handle_procpidmem(task))
54317 + files = get_files_struct(task);
54318 put_task_struct(task);
54319
54320 if (files) {
54321 @@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
54322 */
54323 int proc_fd_permission(struct inode *inode, int mask)
54324 {
54325 + struct task_struct *task;
54326 int rv = generic_permission(inode, mask);
54327 - if (rv == 0)
54328 - return 0;
54329 +
54330 if (task_pid(current) == proc_pid(inode))
54331 rv = 0;
54332 +
54333 + task = get_proc_task(inode);
54334 + if (task == NULL)
54335 + return rv;
54336 +
54337 + if (gr_acl_handle_procpidmem(task))
54338 + rv = -EACCES;
54339 +
54340 + put_task_struct(task);
54341 +
54342 return rv;
54343 }
54344
54345 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
54346 index 439ae688..c21ac36 100644
54347 --- a/fs/proc/inode.c
54348 +++ b/fs/proc/inode.c
54349 @@ -21,11 +21,17 @@
54350 #include <linux/seq_file.h>
54351 #include <linux/slab.h>
54352 #include <linux/mount.h>
54353 +#include <linux/grsecurity.h>
54354
54355 #include <asm/uaccess.h>
54356
54357 #include "internal.h"
54358
54359 +#ifdef CONFIG_PROC_SYSCTL
54360 +extern const struct inode_operations proc_sys_inode_operations;
54361 +extern const struct inode_operations proc_sys_dir_operations;
54362 +#endif
54363 +
54364 static void proc_evict_inode(struct inode *inode)
54365 {
54366 struct proc_dir_entry *de;
54367 @@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
54368 ns = PROC_I(inode)->ns;
54369 if (ns_ops && ns)
54370 ns_ops->put(ns);
54371 +
54372 +#ifdef CONFIG_PROC_SYSCTL
54373 + if (inode->i_op == &proc_sys_inode_operations ||
54374 + inode->i_op == &proc_sys_dir_operations)
54375 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
54376 +#endif
54377 +
54378 }
54379
54380 static struct kmem_cache * proc_inode_cachep;
54381 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
54382 if (de->mode) {
54383 inode->i_mode = de->mode;
54384 inode->i_uid = de->uid;
54385 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54386 + inode->i_gid = grsec_proc_gid;
54387 +#else
54388 inode->i_gid = de->gid;
54389 +#endif
54390 }
54391 if (de->size)
54392 inode->i_size = de->size;
54393 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
54394 index 252544c..04395b9 100644
54395 --- a/fs/proc/internal.h
54396 +++ b/fs/proc/internal.h
54397 @@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54398 struct pid *pid, struct task_struct *task);
54399 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54400 struct pid *pid, struct task_struct *task);
54401 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54402 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
54403 +#endif
54404 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
54405
54406 extern const struct file_operations proc_tid_children_operations;
54407 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
54408 index e96d4f1..8b116ed 100644
54409 --- a/fs/proc/kcore.c
54410 +++ b/fs/proc/kcore.c
54411 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54412 * the addresses in the elf_phdr on our list.
54413 */
54414 start = kc_offset_to_vaddr(*fpos - elf_buflen);
54415 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
54416 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
54417 + if (tsz > buflen)
54418 tsz = buflen;
54419 -
54420 +
54421 while (buflen) {
54422 struct kcore_list *m;
54423
54424 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54425 kfree(elf_buf);
54426 } else {
54427 if (kern_addr_valid(start)) {
54428 - unsigned long n;
54429 + char *elf_buf;
54430 + mm_segment_t oldfs;
54431
54432 - n = copy_to_user(buffer, (char *)start, tsz);
54433 - /*
54434 - * We cannot distinguish between fault on source
54435 - * and fault on destination. When this happens
54436 - * we clear too and hope it will trigger the
54437 - * EFAULT again.
54438 - */
54439 - if (n) {
54440 - if (clear_user(buffer + tsz - n,
54441 - n))
54442 + elf_buf = kmalloc(tsz, GFP_KERNEL);
54443 + if (!elf_buf)
54444 + return -ENOMEM;
54445 + oldfs = get_fs();
54446 + set_fs(KERNEL_DS);
54447 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
54448 + set_fs(oldfs);
54449 + if (copy_to_user(buffer, elf_buf, tsz)) {
54450 + kfree(elf_buf);
54451 return -EFAULT;
54452 + }
54453 }
54454 + set_fs(oldfs);
54455 + kfree(elf_buf);
54456 } else {
54457 if (clear_user(buffer, tsz))
54458 return -EFAULT;
54459 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54460
54461 static int open_kcore(struct inode *inode, struct file *filp)
54462 {
54463 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
54464 + return -EPERM;
54465 +#endif
54466 if (!capable(CAP_SYS_RAWIO))
54467 return -EPERM;
54468 if (kcore_need_update)
54469 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
54470 index 80e4645..53e5fcf 100644
54471 --- a/fs/proc/meminfo.c
54472 +++ b/fs/proc/meminfo.c
54473 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
54474 vmi.used >> 10,
54475 vmi.largest_chunk >> 10
54476 #ifdef CONFIG_MEMORY_FAILURE
54477 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
54478 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
54479 #endif
54480 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
54481 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
54482 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
54483 index b1822dd..df622cb 100644
54484 --- a/fs/proc/nommu.c
54485 +++ b/fs/proc/nommu.c
54486 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
54487 if (len < 1)
54488 len = 1;
54489 seq_printf(m, "%*c", len, ' ');
54490 - seq_path(m, &file->f_path, "");
54491 + seq_path(m, &file->f_path, "\n\\");
54492 }
54493
54494 seq_putc(m, '\n');
54495 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
54496 index fe72cd0..21b52ff 100644
54497 --- a/fs/proc/proc_net.c
54498 +++ b/fs/proc/proc_net.c
54499 @@ -23,6 +23,7 @@
54500 #include <linux/nsproxy.h>
54501 #include <net/net_namespace.h>
54502 #include <linux/seq_file.h>
54503 +#include <linux/grsecurity.h>
54504
54505 #include "internal.h"
54506
54507 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
54508 struct task_struct *task;
54509 struct nsproxy *ns;
54510 struct net *net = NULL;
54511 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54512 + const struct cred *cred = current_cred();
54513 +#endif
54514 +
54515 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54516 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
54517 + return net;
54518 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54519 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
54520 + return net;
54521 +#endif
54522
54523 rcu_read_lock();
54524 task = pid_task(proc_pid(dir), PIDTYPE_PID);
54525 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
54526 index 1827d88..43b0279 100644
54527 --- a/fs/proc/proc_sysctl.c
54528 +++ b/fs/proc/proc_sysctl.c
54529 @@ -12,11 +12,15 @@
54530 #include <linux/module.h>
54531 #include "internal.h"
54532
54533 +extern int gr_handle_chroot_sysctl(const int op);
54534 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
54535 + const int op);
54536 +
54537 static const struct dentry_operations proc_sys_dentry_operations;
54538 static const struct file_operations proc_sys_file_operations;
54539 -static const struct inode_operations proc_sys_inode_operations;
54540 +const struct inode_operations proc_sys_inode_operations;
54541 static const struct file_operations proc_sys_dir_file_operations;
54542 -static const struct inode_operations proc_sys_dir_operations;
54543 +const struct inode_operations proc_sys_dir_operations;
54544
54545 void proc_sys_poll_notify(struct ctl_table_poll *poll)
54546 {
54547 @@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
54548
54549 err = NULL;
54550 d_set_d_op(dentry, &proc_sys_dentry_operations);
54551 +
54552 + gr_handle_proc_create(dentry, inode);
54553 +
54554 d_add(dentry, inode);
54555
54556 out:
54557 @@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54558 struct inode *inode = filp->f_path.dentry->d_inode;
54559 struct ctl_table_header *head = grab_header(inode);
54560 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
54561 + int op = write ? MAY_WRITE : MAY_READ;
54562 ssize_t error;
54563 size_t res;
54564
54565 @@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54566 * and won't be until we finish.
54567 */
54568 error = -EPERM;
54569 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
54570 + if (sysctl_perm(head, table, op))
54571 goto out;
54572
54573 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
54574 @@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54575 if (!table->proc_handler)
54576 goto out;
54577
54578 +#ifdef CONFIG_GRKERNSEC
54579 + error = -EPERM;
54580 + if (gr_handle_chroot_sysctl(op))
54581 + goto out;
54582 + dget(filp->f_path.dentry);
54583 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
54584 + dput(filp->f_path.dentry);
54585 + goto out;
54586 + }
54587 + dput(filp->f_path.dentry);
54588 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
54589 + goto out;
54590 + if (write && !capable(CAP_SYS_ADMIN))
54591 + goto out;
54592 +#endif
54593 +
54594 /* careful: calling conventions are nasty here */
54595 res = count;
54596 error = table->proc_handler(table, write, buf, &res, ppos);
54597 @@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
54598 return -ENOMEM;
54599 } else {
54600 d_set_d_op(child, &proc_sys_dentry_operations);
54601 +
54602 + gr_handle_proc_create(child, inode);
54603 +
54604 d_add(child, inode);
54605 }
54606 } else {
54607 @@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
54608 if ((*pos)++ < file->f_pos)
54609 return 0;
54610
54611 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
54612 + return 0;
54613 +
54614 if (unlikely(S_ISLNK(table->mode)))
54615 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
54616 else
54617 @@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
54618 if (IS_ERR(head))
54619 return PTR_ERR(head);
54620
54621 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
54622 + return -ENOENT;
54623 +
54624 generic_fillattr(inode, stat);
54625 if (table)
54626 stat->mode = (stat->mode & S_IFMT) | table->mode;
54627 @@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
54628 .llseek = generic_file_llseek,
54629 };
54630
54631 -static const struct inode_operations proc_sys_inode_operations = {
54632 +const struct inode_operations proc_sys_inode_operations = {
54633 .permission = proc_sys_permission,
54634 .setattr = proc_sys_setattr,
54635 .getattr = proc_sys_getattr,
54636 };
54637
54638 -static const struct inode_operations proc_sys_dir_operations = {
54639 +const struct inode_operations proc_sys_dir_operations = {
54640 .lookup = proc_sys_lookup,
54641 .permission = proc_sys_permission,
54642 .setattr = proc_sys_setattr,
54643 @@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
54644 static struct ctl_dir *new_dir(struct ctl_table_set *set,
54645 const char *name, int namelen)
54646 {
54647 - struct ctl_table *table;
54648 + ctl_table_no_const *table;
54649 struct ctl_dir *new;
54650 struct ctl_node *node;
54651 char *new_name;
54652 @@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
54653 return NULL;
54654
54655 node = (struct ctl_node *)(new + 1);
54656 - table = (struct ctl_table *)(node + 1);
54657 + table = (ctl_table_no_const *)(node + 1);
54658 new_name = (char *)(table + 2);
54659 memcpy(new_name, name, namelen);
54660 new_name[namelen] = '\0';
54661 @@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
54662 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
54663 struct ctl_table_root *link_root)
54664 {
54665 - struct ctl_table *link_table, *entry, *link;
54666 + ctl_table_no_const *link_table, *link;
54667 + struct ctl_table *entry;
54668 struct ctl_table_header *links;
54669 struct ctl_node *node;
54670 char *link_name;
54671 @@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
54672 return NULL;
54673
54674 node = (struct ctl_node *)(links + 1);
54675 - link_table = (struct ctl_table *)(node + nr_entries);
54676 + link_table = (ctl_table_no_const *)(node + nr_entries);
54677 link_name = (char *)&link_table[nr_entries + 1];
54678
54679 for (link = link_table, entry = table; entry->procname; link++, entry++) {
54680 @@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54681 struct ctl_table_header ***subheader, struct ctl_table_set *set,
54682 struct ctl_table *table)
54683 {
54684 - struct ctl_table *ctl_table_arg = NULL;
54685 - struct ctl_table *entry, *files;
54686 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
54687 + struct ctl_table *entry;
54688 int nr_files = 0;
54689 int nr_dirs = 0;
54690 int err = -ENOMEM;
54691 @@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54692 nr_files++;
54693 }
54694
54695 - files = table;
54696 /* If there are mixed files and directories we need a new table */
54697 if (nr_dirs && nr_files) {
54698 - struct ctl_table *new;
54699 + ctl_table_no_const *new;
54700 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
54701 GFP_KERNEL);
54702 if (!files)
54703 @@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54704 /* Register everything except a directory full of subdirectories */
54705 if (nr_files || !nr_dirs) {
54706 struct ctl_table_header *header;
54707 - header = __register_sysctl_table(set, path, files);
54708 + header = __register_sysctl_table(set, path, files ? files : table);
54709 if (!header) {
54710 kfree(ctl_table_arg);
54711 goto out;
54712 diff --git a/fs/proc/root.c b/fs/proc/root.c
54713 index c6e9fac..a740964 100644
54714 --- a/fs/proc/root.c
54715 +++ b/fs/proc/root.c
54716 @@ -176,7 +176,15 @@ void __init proc_root_init(void)
54717 #ifdef CONFIG_PROC_DEVICETREE
54718 proc_device_tree_init();
54719 #endif
54720 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54721 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54722 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
54723 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54724 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
54725 +#endif
54726 +#else
54727 proc_mkdir("bus", NULL);
54728 +#endif
54729 proc_sys_init();
54730 }
54731
54732 diff --git a/fs/proc/self.c b/fs/proc/self.c
54733 index aa5cc3b..c91a5d0 100644
54734 --- a/fs/proc/self.c
54735 +++ b/fs/proc/self.c
54736 @@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
54737 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
54738 void *cookie)
54739 {
54740 - char *s = nd_get_link(nd);
54741 + const char *s = nd_get_link(nd);
54742 if (!IS_ERR(s))
54743 kfree(s);
54744 }
54745 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
54746 index ca5ce7f..02c1cf0 100644
54747 --- a/fs/proc/task_mmu.c
54748 +++ b/fs/proc/task_mmu.c
54749 @@ -11,12 +11,19 @@
54750 #include <linux/rmap.h>
54751 #include <linux/swap.h>
54752 #include <linux/swapops.h>
54753 +#include <linux/grsecurity.h>
54754
54755 #include <asm/elf.h>
54756 #include <asm/uaccess.h>
54757 #include <asm/tlbflush.h>
54758 #include "internal.h"
54759
54760 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54761 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54762 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
54763 + _mm->pax_flags & MF_PAX_SEGMEXEC))
54764 +#endif
54765 +
54766 void task_mem(struct seq_file *m, struct mm_struct *mm)
54767 {
54768 unsigned long data, text, lib, swap;
54769 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54770 "VmExe:\t%8lu kB\n"
54771 "VmLib:\t%8lu kB\n"
54772 "VmPTE:\t%8lu kB\n"
54773 - "VmSwap:\t%8lu kB\n",
54774 - hiwater_vm << (PAGE_SHIFT-10),
54775 + "VmSwap:\t%8lu kB\n"
54776 +
54777 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54778 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
54779 +#endif
54780 +
54781 + ,hiwater_vm << (PAGE_SHIFT-10),
54782 total_vm << (PAGE_SHIFT-10),
54783 mm->locked_vm << (PAGE_SHIFT-10),
54784 mm->pinned_vm << (PAGE_SHIFT-10),
54785 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54786 data << (PAGE_SHIFT-10),
54787 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
54788 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
54789 - swap << (PAGE_SHIFT-10));
54790 + swap << (PAGE_SHIFT-10)
54791 +
54792 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54793 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54794 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
54795 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
54796 +#else
54797 + , mm->context.user_cs_base
54798 + , mm->context.user_cs_limit
54799 +#endif
54800 +#endif
54801 +
54802 + );
54803 }
54804
54805 unsigned long task_vsize(struct mm_struct *mm)
54806 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54807 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
54808 }
54809
54810 - /* We don't show the stack guard page in /proc/maps */
54811 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54812 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
54813 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
54814 +#else
54815 start = vma->vm_start;
54816 - if (stack_guard_page_start(vma, start))
54817 - start += PAGE_SIZE;
54818 end = vma->vm_end;
54819 - if (stack_guard_page_end(vma, end))
54820 - end -= PAGE_SIZE;
54821 +#endif
54822
54823 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
54824 start,
54825 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54826 flags & VM_WRITE ? 'w' : '-',
54827 flags & VM_EXEC ? 'x' : '-',
54828 flags & VM_MAYSHARE ? 's' : 'p',
54829 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54830 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
54831 +#else
54832 pgoff,
54833 +#endif
54834 MAJOR(dev), MINOR(dev), ino, &len);
54835
54836 /*
54837 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54838 */
54839 if (file) {
54840 pad_len_spaces(m, len);
54841 - seq_path(m, &file->f_path, "\n");
54842 + seq_path(m, &file->f_path, "\n\\");
54843 goto done;
54844 }
54845
54846 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54847 * Thread stack in /proc/PID/task/TID/maps or
54848 * the main process stack.
54849 */
54850 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
54851 - vma->vm_end >= mm->start_stack)) {
54852 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
54853 + (vma->vm_start <= mm->start_stack &&
54854 + vma->vm_end >= mm->start_stack)) {
54855 name = "[stack]";
54856 } else {
54857 /* Thread stack in /proc/PID/maps */
54858 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
54859 struct proc_maps_private *priv = m->private;
54860 struct task_struct *task = priv->task;
54861
54862 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54863 + if (current->exec_id != m->exec_id) {
54864 + gr_log_badprocpid("maps");
54865 + return 0;
54866 + }
54867 +#endif
54868 +
54869 show_map_vma(m, vma, is_pid);
54870
54871 if (m->count < m->size) /* vma is copied successfully */
54872 @@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
54873 .private = &mss,
54874 };
54875
54876 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54877 + if (current->exec_id != m->exec_id) {
54878 + gr_log_badprocpid("smaps");
54879 + return 0;
54880 + }
54881 +#endif
54882 memset(&mss, 0, sizeof mss);
54883 - mss.vma = vma;
54884 - /* mmap_sem is held in m_start */
54885 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
54886 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
54887 -
54888 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54889 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
54890 +#endif
54891 + mss.vma = vma;
54892 + /* mmap_sem is held in m_start */
54893 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
54894 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
54895 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54896 + }
54897 +#endif
54898 show_map_vma(m, vma, is_pid);
54899
54900 seq_printf(m,
54901 @@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
54902 "KernelPageSize: %8lu kB\n"
54903 "MMUPageSize: %8lu kB\n"
54904 "Locked: %8lu kB\n",
54905 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54906 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
54907 +#else
54908 (vma->vm_end - vma->vm_start) >> 10,
54909 +#endif
54910 mss.resident >> 10,
54911 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
54912 mss.shared_clean >> 10,
54913 @@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
54914 int n;
54915 char buffer[50];
54916
54917 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54918 + if (current->exec_id != m->exec_id) {
54919 + gr_log_badprocpid("numa_maps");
54920 + return 0;
54921 + }
54922 +#endif
54923 +
54924 if (!mm)
54925 return 0;
54926
54927 @@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
54928 mpol_to_str(buffer, sizeof(buffer), pol);
54929 mpol_cond_put(pol);
54930
54931 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54932 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
54933 +#else
54934 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
54935 +#endif
54936
54937 if (file) {
54938 seq_printf(m, " file=");
54939 - seq_path(m, &file->f_path, "\n\t= ");
54940 + seq_path(m, &file->f_path, "\n\t\\= ");
54941 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
54942 seq_printf(m, " heap");
54943 } else {
54944 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
54945 index 1ccfa53..0848f95 100644
54946 --- a/fs/proc/task_nommu.c
54947 +++ b/fs/proc/task_nommu.c
54948 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54949 else
54950 bytes += kobjsize(mm);
54951
54952 - if (current->fs && current->fs->users > 1)
54953 + if (current->fs && atomic_read(&current->fs->users) > 1)
54954 sbytes += kobjsize(current->fs);
54955 else
54956 bytes += kobjsize(current->fs);
54957 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
54958
54959 if (file) {
54960 pad_len_spaces(m, len);
54961 - seq_path(m, &file->f_path, "");
54962 + seq_path(m, &file->f_path, "\n\\");
54963 } else if (mm) {
54964 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
54965
54966 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
54967 index 16e8abb..2dcf914 100644
54968 --- a/fs/quota/netlink.c
54969 +++ b/fs/quota/netlink.c
54970 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
54971 void quota_send_warning(struct kqid qid, dev_t dev,
54972 const char warntype)
54973 {
54974 - static atomic_t seq;
54975 + static atomic_unchecked_t seq;
54976 struct sk_buff *skb;
54977 void *msg_head;
54978 int ret;
54979 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
54980 "VFS: Not enough memory to send quota warning.\n");
54981 return;
54982 }
54983 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
54984 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
54985 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
54986 if (!msg_head) {
54987 printk(KERN_ERR
54988 diff --git a/fs/readdir.c b/fs/readdir.c
54989 index 5e69ef5..e5d9099 100644
54990 --- a/fs/readdir.c
54991 +++ b/fs/readdir.c
54992 @@ -17,6 +17,7 @@
54993 #include <linux/security.h>
54994 #include <linux/syscalls.h>
54995 #include <linux/unistd.h>
54996 +#include <linux/namei.h>
54997
54998 #include <asm/uaccess.h>
54999
55000 @@ -67,6 +68,7 @@ struct old_linux_dirent {
55001
55002 struct readdir_callback {
55003 struct old_linux_dirent __user * dirent;
55004 + struct file * file;
55005 int result;
55006 };
55007
55008 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
55009 buf->result = -EOVERFLOW;
55010 return -EOVERFLOW;
55011 }
55012 +
55013 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55014 + return 0;
55015 +
55016 buf->result++;
55017 dirent = buf->dirent;
55018 if (!access_ok(VERIFY_WRITE, dirent,
55019 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
55020
55021 buf.result = 0;
55022 buf.dirent = dirent;
55023 + buf.file = f.file;
55024
55025 error = vfs_readdir(f.file, fillonedir, &buf);
55026 if (buf.result)
55027 @@ -139,6 +146,7 @@ struct linux_dirent {
55028 struct getdents_callback {
55029 struct linux_dirent __user * current_dir;
55030 struct linux_dirent __user * previous;
55031 + struct file * file;
55032 int count;
55033 int error;
55034 };
55035 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
55036 buf->error = -EOVERFLOW;
55037 return -EOVERFLOW;
55038 }
55039 +
55040 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55041 + return 0;
55042 +
55043 dirent = buf->previous;
55044 if (dirent) {
55045 if (__put_user(offset, &dirent->d_off))
55046 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55047 buf.previous = NULL;
55048 buf.count = count;
55049 buf.error = 0;
55050 + buf.file = f.file;
55051
55052 error = vfs_readdir(f.file, filldir, &buf);
55053 if (error >= 0)
55054 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55055 struct getdents_callback64 {
55056 struct linux_dirent64 __user * current_dir;
55057 struct linux_dirent64 __user * previous;
55058 + struct file *file;
55059 int count;
55060 int error;
55061 };
55062 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
55063 buf->error = -EINVAL; /* only used if we fail.. */
55064 if (reclen > buf->count)
55065 return -EINVAL;
55066 +
55067 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55068 + return 0;
55069 +
55070 dirent = buf->previous;
55071 if (dirent) {
55072 if (__put_user(offset, &dirent->d_off))
55073 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55074
55075 buf.current_dir = dirent;
55076 buf.previous = NULL;
55077 + buf.file = f.file;
55078 buf.count = count;
55079 buf.error = 0;
55080
55081 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55082 error = buf.error;
55083 lastdirent = buf.previous;
55084 if (lastdirent) {
55085 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
55086 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
55087 if (__put_user(d_off, &lastdirent->d_off))
55088 error = -EFAULT;
55089 else
55090 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
55091 index 2b7882b..1c5ef48 100644
55092 --- a/fs/reiserfs/do_balan.c
55093 +++ b/fs/reiserfs/do_balan.c
55094 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
55095 return;
55096 }
55097
55098 - atomic_inc(&(fs_generation(tb->tb_sb)));
55099 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
55100 do_balance_starts(tb);
55101
55102 /* balance leaf returns 0 except if combining L R and S into
55103 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
55104 index e60e870..f40ac16 100644
55105 --- a/fs/reiserfs/procfs.c
55106 +++ b/fs/reiserfs/procfs.c
55107 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
55108 "SMALL_TAILS " : "NO_TAILS ",
55109 replay_only(sb) ? "REPLAY_ONLY " : "",
55110 convert_reiserfs(sb) ? "CONV " : "",
55111 - atomic_read(&r->s_generation_counter),
55112 + atomic_read_unchecked(&r->s_generation_counter),
55113 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
55114 SF(s_do_balance), SF(s_unneeded_left_neighbor),
55115 SF(s_good_search_by_key_reada), SF(s_bmaps),
55116 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
55117 index 157e474..65a6114 100644
55118 --- a/fs/reiserfs/reiserfs.h
55119 +++ b/fs/reiserfs/reiserfs.h
55120 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
55121 /* Comment? -Hans */
55122 wait_queue_head_t s_wait;
55123 /* To be obsoleted soon by per buffer seals.. -Hans */
55124 - atomic_t s_generation_counter; // increased by one every time the
55125 + atomic_unchecked_t s_generation_counter; // increased by one every time the
55126 // tree gets re-balanced
55127 unsigned long s_properties; /* File system properties. Currently holds
55128 on-disk FS format */
55129 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
55130 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
55131
55132 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
55133 -#define get_generation(s) atomic_read (&fs_generation(s))
55134 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
55135 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
55136 #define __fs_changed(gen,s) (gen != get_generation (s))
55137 #define fs_changed(gen,s) \
55138 diff --git a/fs/select.c b/fs/select.c
55139 index 2ef72d9..f213b17 100644
55140 --- a/fs/select.c
55141 +++ b/fs/select.c
55142 @@ -20,6 +20,7 @@
55143 #include <linux/export.h>
55144 #include <linux/slab.h>
55145 #include <linux/poll.h>
55146 +#include <linux/security.h>
55147 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
55148 #include <linux/file.h>
55149 #include <linux/fdtable.h>
55150 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
55151 struct poll_list *walk = head;
55152 unsigned long todo = nfds;
55153
55154 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
55155 if (nfds > rlimit(RLIMIT_NOFILE))
55156 return -EINVAL;
55157
55158 diff --git a/fs/seq_file.c b/fs/seq_file.c
55159 index f2bc3df..239d4f6 100644
55160 --- a/fs/seq_file.c
55161 +++ b/fs/seq_file.c
55162 @@ -10,6 +10,7 @@
55163 #include <linux/seq_file.h>
55164 #include <linux/slab.h>
55165 #include <linux/cred.h>
55166 +#include <linux/sched.h>
55167
55168 #include <asm/uaccess.h>
55169 #include <asm/page.h>
55170 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
55171 #ifdef CONFIG_USER_NS
55172 p->user_ns = file->f_cred->user_ns;
55173 #endif
55174 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55175 + p->exec_id = current->exec_id;
55176 +#endif
55177
55178 /*
55179 * Wrappers around seq_open(e.g. swaps_open) need to be
55180 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55181 return 0;
55182 }
55183 if (!m->buf) {
55184 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55185 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55186 if (!m->buf)
55187 return -ENOMEM;
55188 }
55189 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55190 Eoverflow:
55191 m->op->stop(m, p);
55192 kfree(m->buf);
55193 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55194 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55195 return !m->buf ? -ENOMEM : -EAGAIN;
55196 }
55197
55198 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55199
55200 /* grab buffer if we didn't have one */
55201 if (!m->buf) {
55202 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55203 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55204 if (!m->buf)
55205 goto Enomem;
55206 }
55207 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55208 goto Fill;
55209 m->op->stop(m, p);
55210 kfree(m->buf);
55211 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55212 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55213 if (!m->buf)
55214 goto Enomem;
55215 m->count = 0;
55216 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
55217 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
55218 void *data)
55219 {
55220 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
55221 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
55222 int res = -ENOMEM;
55223
55224 if (op) {
55225 diff --git a/fs/splice.c b/fs/splice.c
55226 index 6909d89..5b2e8f9 100644
55227 --- a/fs/splice.c
55228 +++ b/fs/splice.c
55229 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55230 pipe_lock(pipe);
55231
55232 for (;;) {
55233 - if (!pipe->readers) {
55234 + if (!atomic_read(&pipe->readers)) {
55235 send_sig(SIGPIPE, current, 0);
55236 if (!ret)
55237 ret = -EPIPE;
55238 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55239 do_wakeup = 0;
55240 }
55241
55242 - pipe->waiting_writers++;
55243 + atomic_inc(&pipe->waiting_writers);
55244 pipe_wait(pipe);
55245 - pipe->waiting_writers--;
55246 + atomic_dec(&pipe->waiting_writers);
55247 }
55248
55249 pipe_unlock(pipe);
55250 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
55251 old_fs = get_fs();
55252 set_fs(get_ds());
55253 /* The cast to a user pointer is valid due to the set_fs() */
55254 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
55255 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
55256 set_fs(old_fs);
55257
55258 return res;
55259 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
55260 old_fs = get_fs();
55261 set_fs(get_ds());
55262 /* The cast to a user pointer is valid due to the set_fs() */
55263 - res = vfs_write(file, (const char __user *)buf, count, &pos);
55264 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
55265 set_fs(old_fs);
55266
55267 return res;
55268 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
55269 goto err;
55270
55271 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
55272 - vec[i].iov_base = (void __user *) page_address(page);
55273 + vec[i].iov_base = (void __force_user *) page_address(page);
55274 vec[i].iov_len = this_len;
55275 spd.pages[i] = page;
55276 spd.nr_pages++;
55277 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
55278 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
55279 {
55280 while (!pipe->nrbufs) {
55281 - if (!pipe->writers)
55282 + if (!atomic_read(&pipe->writers))
55283 return 0;
55284
55285 - if (!pipe->waiting_writers && sd->num_spliced)
55286 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
55287 return 0;
55288
55289 if (sd->flags & SPLICE_F_NONBLOCK)
55290 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
55291 * out of the pipe right after the splice_to_pipe(). So set
55292 * PIPE_READERS appropriately.
55293 */
55294 - pipe->readers = 1;
55295 + atomic_set(&pipe->readers, 1);
55296
55297 current->splice_pipe = pipe;
55298 }
55299 @@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55300 ret = -ERESTARTSYS;
55301 break;
55302 }
55303 - if (!pipe->writers)
55304 + if (!atomic_read(&pipe->writers))
55305 break;
55306 - if (!pipe->waiting_writers) {
55307 + if (!atomic_read(&pipe->waiting_writers)) {
55308 if (flags & SPLICE_F_NONBLOCK) {
55309 ret = -EAGAIN;
55310 break;
55311 @@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55312 pipe_lock(pipe);
55313
55314 while (pipe->nrbufs >= pipe->buffers) {
55315 - if (!pipe->readers) {
55316 + if (!atomic_read(&pipe->readers)) {
55317 send_sig(SIGPIPE, current, 0);
55318 ret = -EPIPE;
55319 break;
55320 @@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55321 ret = -ERESTARTSYS;
55322 break;
55323 }
55324 - pipe->waiting_writers++;
55325 + atomic_inc(&pipe->waiting_writers);
55326 pipe_wait(pipe);
55327 - pipe->waiting_writers--;
55328 + atomic_dec(&pipe->waiting_writers);
55329 }
55330
55331 pipe_unlock(pipe);
55332 @@ -1823,14 +1823,14 @@ retry:
55333 pipe_double_lock(ipipe, opipe);
55334
55335 do {
55336 - if (!opipe->readers) {
55337 + if (!atomic_read(&opipe->readers)) {
55338 send_sig(SIGPIPE, current, 0);
55339 if (!ret)
55340 ret = -EPIPE;
55341 break;
55342 }
55343
55344 - if (!ipipe->nrbufs && !ipipe->writers)
55345 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
55346 break;
55347
55348 /*
55349 @@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55350 pipe_double_lock(ipipe, opipe);
55351
55352 do {
55353 - if (!opipe->readers) {
55354 + if (!atomic_read(&opipe->readers)) {
55355 send_sig(SIGPIPE, current, 0);
55356 if (!ret)
55357 ret = -EPIPE;
55358 @@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55359 * return EAGAIN if we have the potential of some data in the
55360 * future, otherwise just return 0
55361 */
55362 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
55363 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
55364 ret = -EAGAIN;
55365
55366 pipe_unlock(ipipe);
55367 diff --git a/fs/stat.c b/fs/stat.c
55368 index 14f4545..9b7f55b 100644
55369 --- a/fs/stat.c
55370 +++ b/fs/stat.c
55371 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
55372 stat->gid = inode->i_gid;
55373 stat->rdev = inode->i_rdev;
55374 stat->size = i_size_read(inode);
55375 - stat->atime = inode->i_atime;
55376 - stat->mtime = inode->i_mtime;
55377 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55378 + stat->atime = inode->i_ctime;
55379 + stat->mtime = inode->i_ctime;
55380 + } else {
55381 + stat->atime = inode->i_atime;
55382 + stat->mtime = inode->i_mtime;
55383 + }
55384 stat->ctime = inode->i_ctime;
55385 stat->blksize = (1 << inode->i_blkbits);
55386 stat->blocks = inode->i_blocks;
55387 @@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55388 if (retval)
55389 return retval;
55390
55391 - if (inode->i_op->getattr)
55392 - return inode->i_op->getattr(mnt, dentry, stat);
55393 + if (inode->i_op->getattr) {
55394 + retval = inode->i_op->getattr(mnt, dentry, stat);
55395 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55396 + stat->atime = stat->ctime;
55397 + stat->mtime = stat->ctime;
55398 + }
55399 + return retval;
55400 + }
55401
55402 generic_fillattr(inode, stat);
55403 return 0;
55404 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
55405 index 2fbdff6..5530a61 100644
55406 --- a/fs/sysfs/dir.c
55407 +++ b/fs/sysfs/dir.c
55408 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
55409 struct sysfs_dirent *sd;
55410 int rc;
55411
55412 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55413 + const char *parent_name = parent_sd->s_name;
55414 +
55415 + mode = S_IFDIR | S_IRWXU;
55416 +
55417 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
55418 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
55419 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
55420 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
55421 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
55422 +#endif
55423 +
55424 /* allocate */
55425 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
55426 if (!sd)
55427 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
55428 index 602f56d..6853db8 100644
55429 --- a/fs/sysfs/file.c
55430 +++ b/fs/sysfs/file.c
55431 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
55432
55433 struct sysfs_open_dirent {
55434 atomic_t refcnt;
55435 - atomic_t event;
55436 + atomic_unchecked_t event;
55437 wait_queue_head_t poll;
55438 struct list_head buffers; /* goes through sysfs_buffer.list */
55439 };
55440 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
55441 if (!sysfs_get_active(attr_sd))
55442 return -ENODEV;
55443
55444 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
55445 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
55446 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
55447
55448 sysfs_put_active(attr_sd);
55449 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
55450 return -ENOMEM;
55451
55452 atomic_set(&new_od->refcnt, 0);
55453 - atomic_set(&new_od->event, 1);
55454 + atomic_set_unchecked(&new_od->event, 1);
55455 init_waitqueue_head(&new_od->poll);
55456 INIT_LIST_HEAD(&new_od->buffers);
55457 goto retry;
55458 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
55459
55460 sysfs_put_active(attr_sd);
55461
55462 - if (buffer->event != atomic_read(&od->event))
55463 + if (buffer->event != atomic_read_unchecked(&od->event))
55464 goto trigger;
55465
55466 return DEFAULT_POLLMASK;
55467 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
55468
55469 od = sd->s_attr.open;
55470 if (od) {
55471 - atomic_inc(&od->event);
55472 + atomic_inc_unchecked(&od->event);
55473 wake_up_interruptible(&od->poll);
55474 }
55475
55476 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
55477 index 3c9eb56..9dea5be 100644
55478 --- a/fs/sysfs/symlink.c
55479 +++ b/fs/sysfs/symlink.c
55480 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55481
55482 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
55483 {
55484 - char *page = nd_get_link(nd);
55485 + const char *page = nd_get_link(nd);
55486 if (!IS_ERR(page))
55487 free_page((unsigned long)page);
55488 }
55489 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
55490 index c175b4d..8f36a16 100644
55491 --- a/fs/udf/misc.c
55492 +++ b/fs/udf/misc.c
55493 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
55494
55495 u8 udf_tag_checksum(const struct tag *t)
55496 {
55497 - u8 *data = (u8 *)t;
55498 + const u8 *data = (const u8 *)t;
55499 u8 checksum = 0;
55500 int i;
55501 for (i = 0; i < sizeof(struct tag); ++i)
55502 diff --git a/fs/utimes.c b/fs/utimes.c
55503 index f4fb7ec..3fe03c0 100644
55504 --- a/fs/utimes.c
55505 +++ b/fs/utimes.c
55506 @@ -1,6 +1,7 @@
55507 #include <linux/compiler.h>
55508 #include <linux/file.h>
55509 #include <linux/fs.h>
55510 +#include <linux/security.h>
55511 #include <linux/linkage.h>
55512 #include <linux/mount.h>
55513 #include <linux/namei.h>
55514 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
55515 goto mnt_drop_write_and_out;
55516 }
55517 }
55518 +
55519 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
55520 + error = -EACCES;
55521 + goto mnt_drop_write_and_out;
55522 + }
55523 +
55524 mutex_lock(&inode->i_mutex);
55525 error = notify_change(path->dentry, &newattrs);
55526 mutex_unlock(&inode->i_mutex);
55527 diff --git a/fs/xattr.c b/fs/xattr.c
55528 index 3377dff..4feded6 100644
55529 --- a/fs/xattr.c
55530 +++ b/fs/xattr.c
55531 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
55532 * Extended attribute SET operations
55533 */
55534 static long
55535 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
55536 +setxattr(struct path *path, const char __user *name, const void __user *value,
55537 size_t size, int flags)
55538 {
55539 int error;
55540 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
55541 posix_acl_fix_xattr_from_user(kvalue, size);
55542 }
55543
55544 - error = vfs_setxattr(d, kname, kvalue, size, flags);
55545 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
55546 + error = -EACCES;
55547 + goto out;
55548 + }
55549 +
55550 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
55551 out:
55552 if (vvalue)
55553 vfree(vvalue);
55554 @@ -377,7 +382,7 @@ retry:
55555 return error;
55556 error = mnt_want_write(path.mnt);
55557 if (!error) {
55558 - error = setxattr(path.dentry, name, value, size, flags);
55559 + error = setxattr(&path, name, value, size, flags);
55560 mnt_drop_write(path.mnt);
55561 }
55562 path_put(&path);
55563 @@ -401,7 +406,7 @@ retry:
55564 return error;
55565 error = mnt_want_write(path.mnt);
55566 if (!error) {
55567 - error = setxattr(path.dentry, name, value, size, flags);
55568 + error = setxattr(&path, name, value, size, flags);
55569 mnt_drop_write(path.mnt);
55570 }
55571 path_put(&path);
55572 @@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
55573 const void __user *,value, size_t, size, int, flags)
55574 {
55575 struct fd f = fdget(fd);
55576 - struct dentry *dentry;
55577 int error = -EBADF;
55578
55579 if (!f.file)
55580 return error;
55581 - dentry = f.file->f_path.dentry;
55582 - audit_inode(NULL, dentry, 0);
55583 + audit_inode(NULL, f.file->f_path.dentry, 0);
55584 error = mnt_want_write_file(f.file);
55585 if (!error) {
55586 - error = setxattr(dentry, name, value, size, flags);
55587 + error = setxattr(&f.file->f_path, name, value, size, flags);
55588 mnt_drop_write_file(f.file);
55589 }
55590 fdput(f);
55591 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
55592 index 9fbea87..6b19972 100644
55593 --- a/fs/xattr_acl.c
55594 +++ b/fs/xattr_acl.c
55595 @@ -76,8 +76,8 @@ struct posix_acl *
55596 posix_acl_from_xattr(struct user_namespace *user_ns,
55597 const void *value, size_t size)
55598 {
55599 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
55600 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
55601 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
55602 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
55603 int count;
55604 struct posix_acl *acl;
55605 struct posix_acl_entry *acl_e;
55606 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
55607 index 572a858..12a9b0d 100644
55608 --- a/fs/xfs/xfs_bmap.c
55609 +++ b/fs/xfs/xfs_bmap.c
55610 @@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
55611 int nmap,
55612 int ret_nmap);
55613 #else
55614 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
55615 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
55616 #endif /* DEBUG */
55617
55618 STATIC int
55619 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
55620 index 1b9fc3e..e1bdde0 100644
55621 --- a/fs/xfs/xfs_dir2_sf.c
55622 +++ b/fs/xfs/xfs_dir2_sf.c
55623 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
55624 }
55625
55626 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
55627 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
55628 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
55629 + char name[sfep->namelen];
55630 + memcpy(name, sfep->name, sfep->namelen);
55631 + if (filldir(dirent, name, sfep->namelen,
55632 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
55633 + *offset = off & 0x7fffffff;
55634 + return 0;
55635 + }
55636 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
55637 off & 0x7fffffff, ino, DT_UNKNOWN)) {
55638 *offset = off & 0x7fffffff;
55639 return 0;
55640 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
55641 index c1c3ef8..0952438 100644
55642 --- a/fs/xfs/xfs_ioctl.c
55643 +++ b/fs/xfs/xfs_ioctl.c
55644 @@ -127,7 +127,7 @@ xfs_find_handle(
55645 }
55646
55647 error = -EFAULT;
55648 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
55649 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
55650 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
55651 goto out_put;
55652
55653 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
55654 index d82efaa..0904a8e 100644
55655 --- a/fs/xfs/xfs_iops.c
55656 +++ b/fs/xfs/xfs_iops.c
55657 @@ -395,7 +395,7 @@ xfs_vn_put_link(
55658 struct nameidata *nd,
55659 void *p)
55660 {
55661 - char *s = nd_get_link(nd);
55662 + const char *s = nd_get_link(nd);
55663
55664 if (!IS_ERR(s))
55665 kfree(s);
55666 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
55667 new file mode 100644
55668 index 0000000..92247e4
55669 --- /dev/null
55670 +++ b/grsecurity/Kconfig
55671 @@ -0,0 +1,1021 @@
55672 +#
55673 +# grecurity configuration
55674 +#
55675 +menu "Memory Protections"
55676 +depends on GRKERNSEC
55677 +
55678 +config GRKERNSEC_KMEM
55679 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
55680 + default y if GRKERNSEC_CONFIG_AUTO
55681 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
55682 + help
55683 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
55684 + be written to or read from to modify or leak the contents of the running
55685 + kernel. /dev/port will also not be allowed to be opened and support
55686 + for /dev/cpu/*/msr will be removed. If you have module
55687 + support disabled, enabling this will close up five ways that are
55688 + currently used to insert malicious code into the running kernel.
55689 +
55690 + Even with all these features enabled, we still highly recommend that
55691 + you use the RBAC system, as it is still possible for an attacker to
55692 + modify the running kernel through privileged I/O granted by ioperm/iopl.
55693 +
55694 + If you are not using XFree86, you may be able to stop this additional
55695 + case by enabling the 'Disable privileged I/O' option. Though nothing
55696 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
55697 + but only to video memory, which is the only writing we allow in this
55698 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
55699 + not be allowed to mprotect it with PROT_WRITE later.
55700 + Enabling this feature will prevent the "cpupower" and "powertop" tools
55701 + from working.
55702 +
55703 + It is highly recommended that you say Y here if you meet all the
55704 + conditions above.
55705 +
55706 +config GRKERNSEC_VM86
55707 + bool "Restrict VM86 mode"
55708 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
55709 + depends on X86_32
55710 +
55711 + help
55712 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
55713 + make use of a special execution mode on 32bit x86 processors called
55714 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
55715 + video cards and will still work with this option enabled. The purpose
55716 + of the option is to prevent exploitation of emulation errors in
55717 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
55718 + Nearly all users should be able to enable this option.
55719 +
55720 +config GRKERNSEC_IO
55721 + bool "Disable privileged I/O"
55722 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
55723 + depends on X86
55724 + select RTC_CLASS
55725 + select RTC_INTF_DEV
55726 + select RTC_DRV_CMOS
55727 +
55728 + help
55729 + If you say Y here, all ioperm and iopl calls will return an error.
55730 + Ioperm and iopl can be used to modify the running kernel.
55731 + Unfortunately, some programs need this access to operate properly,
55732 + the most notable of which are XFree86 and hwclock. hwclock can be
55733 + remedied by having RTC support in the kernel, so real-time
55734 + clock support is enabled if this option is enabled, to ensure
55735 + that hwclock operates correctly. XFree86 still will not
55736 + operate correctly with this option enabled, so DO NOT CHOOSE Y
55737 + IF YOU USE XFree86. If you use XFree86 and you still want to
55738 + protect your kernel against modification, use the RBAC system.
55739 +
55740 +config GRKERNSEC_JIT_HARDEN
55741 + bool "Harden BPF JIT against spray attacks"
55742 + default y if GRKERNSEC_CONFIG_AUTO
55743 + depends on BPF_JIT
55744 + help
55745 + If you say Y here, the native code generated by the kernel's Berkeley
55746 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
55747 + attacks that attempt to fit attacker-beneficial instructions in
55748 + 32bit immediate fields of JIT-generated native instructions. The
55749 + attacker will generally aim to cause an unintended instruction sequence
55750 + of JIT-generated native code to execute by jumping into the middle of
55751 + a generated instruction. This feature effectively randomizes the 32bit
55752 + immediate constants present in the generated code to thwart such attacks.
55753 +
55754 + If you're using KERNEXEC, it's recommended that you enable this option
55755 + to supplement the hardening of the kernel.
55756 +
55757 +config GRKERNSEC_RAND_THREADSTACK
55758 + bool "Insert random gaps between thread stacks"
55759 + default y if GRKERNSEC_CONFIG_AUTO
55760 + depends on PAX_RANDMMAP && !PPC
55761 + help
55762 + If you say Y here, a random-sized gap will be enforced between allocated
55763 + thread stacks. Glibc's NPTL and other threading libraries that
55764 + pass MAP_STACK to the kernel for thread stack allocation are supported.
55765 + The implementation currently provides 8 bits of entropy for the gap.
55766 +
55767 + Many distributions do not compile threaded remote services with the
55768 + -fstack-check argument to GCC, causing the variable-sized stack-based
55769 + allocator, alloca(), to not probe the stack on allocation. This
55770 + permits an unbounded alloca() to skip over any guard page and potentially
55771 + modify another thread's stack reliably. An enforced random gap
55772 + reduces the reliability of such an attack and increases the chance
55773 + that such a read/write to another thread's stack instead lands in
55774 + an unmapped area, causing a crash and triggering grsecurity's
55775 + anti-bruteforcing logic.
55776 +
55777 +config GRKERNSEC_PROC_MEMMAP
55778 + bool "Harden ASLR against information leaks and entropy reduction"
55779 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
55780 + depends on PAX_NOEXEC || PAX_ASLR
55781 + help
55782 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
55783 + give no information about the addresses of its mappings if
55784 + PaX features that rely on random addresses are enabled on the task.
55785 + In addition to sanitizing this information and disabling other
55786 + dangerous sources of information, this option causes reads of sensitive
55787 + /proc/<pid> entries where the file descriptor was opened in a different
55788 + task than the one performing the read. Such attempts are logged.
55789 + This option also limits argv/env strings for suid/sgid binaries
55790 + to 512KB to prevent a complete exhaustion of the stack entropy provided
55791 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
55792 + binaries to prevent alternative mmap layouts from being abused.
55793 +
55794 + If you use PaX it is essential that you say Y here as it closes up
55795 + several holes that make full ASLR useless locally.
55796 +
55797 +config GRKERNSEC_BRUTE
55798 + bool "Deter exploit bruteforcing"
55799 + default y if GRKERNSEC_CONFIG_AUTO
55800 + help
55801 + If you say Y here, attempts to bruteforce exploits against forking
55802 + daemons such as apache or sshd, as well as against suid/sgid binaries
55803 + will be deterred. When a child of a forking daemon is killed by PaX
55804 + or crashes due to an illegal instruction or other suspicious signal,
55805 + the parent process will be delayed 30 seconds upon every subsequent
55806 + fork until the administrator is able to assess the situation and
55807 + restart the daemon.
55808 + In the suid/sgid case, the attempt is logged, the user has all their
55809 + processes terminated, and they are prevented from executing any further
55810 + processes for 15 minutes.
55811 + It is recommended that you also enable signal logging in the auditing
55812 + section so that logs are generated when a process triggers a suspicious
55813 + signal.
55814 + If the sysctl option is enabled, a sysctl option with name
55815 + "deter_bruteforce" is created.
55816 +
55817 +
55818 +config GRKERNSEC_MODHARDEN
55819 + bool "Harden module auto-loading"
55820 + default y if GRKERNSEC_CONFIG_AUTO
55821 + depends on MODULES
55822 + help
55823 + If you say Y here, module auto-loading in response to use of some
55824 + feature implemented by an unloaded module will be restricted to
55825 + root users. Enabling this option helps defend against attacks
55826 + by unprivileged users who abuse the auto-loading behavior to
55827 + cause a vulnerable module to load that is then exploited.
55828 +
55829 + If this option prevents a legitimate use of auto-loading for a
55830 + non-root user, the administrator can execute modprobe manually
55831 + with the exact name of the module mentioned in the alert log.
55832 + Alternatively, the administrator can add the module to the list
55833 + of modules loaded at boot by modifying init scripts.
55834 +
55835 + Modification of init scripts will most likely be needed on
55836 + Ubuntu servers with encrypted home directory support enabled,
55837 + as the first non-root user logging in will cause the ecb(aes),
55838 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
55839 +
55840 +config GRKERNSEC_HIDESYM
55841 + bool "Hide kernel symbols"
55842 + default y if GRKERNSEC_CONFIG_AUTO
55843 + select PAX_USERCOPY_SLABS
55844 + help
55845 + If you say Y here, getting information on loaded modules, and
55846 + displaying all kernel symbols through a syscall will be restricted
55847 + to users with CAP_SYS_MODULE. For software compatibility reasons,
55848 + /proc/kallsyms will be restricted to the root user. The RBAC
55849 + system can hide that entry even from root.
55850 +
55851 + This option also prevents leaking of kernel addresses through
55852 + several /proc entries.
55853 +
55854 + Note that this option is only effective provided the following
55855 + conditions are met:
55856 + 1) The kernel using grsecurity is not precompiled by some distribution
55857 + 2) You have also enabled GRKERNSEC_DMESG
55858 + 3) You are using the RBAC system and hiding other files such as your
55859 + kernel image and System.map. Alternatively, enabling this option
55860 + causes the permissions on /boot, /lib/modules, and the kernel
55861 + source directory to change at compile time to prevent
55862 + reading by non-root users.
55863 + If the above conditions are met, this option will aid in providing a
55864 + useful protection against local kernel exploitation of overflows
55865 + and arbitrary read/write vulnerabilities.
55866 +
55867 +config GRKERNSEC_KERN_LOCKOUT
55868 + bool "Active kernel exploit response"
55869 + default y if GRKERNSEC_CONFIG_AUTO
55870 + depends on X86 || ARM || PPC || SPARC
55871 + help
55872 + If you say Y here, when a PaX alert is triggered due to suspicious
55873 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
55874 + or an OOPS occurs due to bad memory accesses, instead of just
55875 + terminating the offending process (and potentially allowing
55876 + a subsequent exploit from the same user), we will take one of two
55877 + actions:
55878 + If the user was root, we will panic the system
55879 + If the user was non-root, we will log the attempt, terminate
55880 + all processes owned by the user, then prevent them from creating
55881 + any new processes until the system is restarted
55882 + This deters repeated kernel exploitation/bruteforcing attempts
55883 + and is useful for later forensics.
55884 +
55885 +endmenu
55886 +menu "Role Based Access Control Options"
55887 +depends on GRKERNSEC
55888 +
55889 +config GRKERNSEC_RBAC_DEBUG
55890 + bool
55891 +
55892 +config GRKERNSEC_NO_RBAC
55893 + bool "Disable RBAC system"
55894 + help
55895 + If you say Y here, the /dev/grsec device will be removed from the kernel,
55896 + preventing the RBAC system from being enabled. You should only say Y
55897 + here if you have no intention of using the RBAC system, so as to prevent
55898 + an attacker with root access from misusing the RBAC system to hide files
55899 + and processes when loadable module support and /dev/[k]mem have been
55900 + locked down.
55901 +
55902 +config GRKERNSEC_ACL_HIDEKERN
55903 + bool "Hide kernel processes"
55904 + help
55905 + If you say Y here, all kernel threads will be hidden to all
55906 + processes but those whose subject has the "view hidden processes"
55907 + flag.
55908 +
55909 +config GRKERNSEC_ACL_MAXTRIES
55910 + int "Maximum tries before password lockout"
55911 + default 3
55912 + help
55913 + This option enforces the maximum number of times a user can attempt
55914 + to authorize themselves with the grsecurity RBAC system before being
55915 + denied the ability to attempt authorization again for a specified time.
55916 + The lower the number, the harder it will be to brute-force a password.
55917 +
55918 +config GRKERNSEC_ACL_TIMEOUT
55919 + int "Time to wait after max password tries, in seconds"
55920 + default 30
55921 + help
55922 + This option specifies the time the user must wait after attempting to
55923 + authorize to the RBAC system with the maximum number of invalid
55924 + passwords. The higher the number, the harder it will be to brute-force
55925 + a password.
55926 +
55927 +endmenu
55928 +menu "Filesystem Protections"
55929 +depends on GRKERNSEC
55930 +
55931 +config GRKERNSEC_PROC
55932 + bool "Proc restrictions"
55933 + default y if GRKERNSEC_CONFIG_AUTO
55934 + help
55935 + If you say Y here, the permissions of the /proc filesystem
55936 + will be altered to enhance system security and privacy. You MUST
55937 + choose either a user only restriction or a user and group restriction.
55938 + Depending upon the option you choose, you can either restrict users to
55939 + see only the processes they themselves run, or choose a group that can
55940 + view all processes and files normally restricted to root if you choose
55941 + the "restrict to user only" option. NOTE: If you're running identd or
55942 + ntpd as a non-root user, you will have to run it as the group you
55943 + specify here.
55944 +
55945 +config GRKERNSEC_PROC_USER
55946 + bool "Restrict /proc to user only"
55947 + depends on GRKERNSEC_PROC
55948 + help
55949 + If you say Y here, non-root users will only be able to view their own
55950 + processes, and restricts them from viewing network-related information,
55951 + and viewing kernel symbol and module information.
55952 +
55953 +config GRKERNSEC_PROC_USERGROUP
55954 + bool "Allow special group"
55955 + default y if GRKERNSEC_CONFIG_AUTO
55956 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
55957 + help
55958 + If you say Y here, you will be able to select a group that will be
55959 + able to view all processes and network-related information. If you've
55960 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
55961 + remain hidden. This option is useful if you want to run identd as
55962 + a non-root user. The group you select may also be chosen at boot time
55963 + via "grsec_proc_gid=" on the kernel commandline.
55964 +
55965 +config GRKERNSEC_PROC_GID
55966 + int "GID for special group"
55967 + depends on GRKERNSEC_PROC_USERGROUP
55968 + default 1001
55969 +
55970 +config GRKERNSEC_PROC_ADD
55971 + bool "Additional restrictions"
55972 + default y if GRKERNSEC_CONFIG_AUTO
55973 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
55974 + help
55975 + If you say Y here, additional restrictions will be placed on
55976 + /proc that keep normal users from viewing device information and
55977 + slabinfo information that could be useful for exploits.
55978 +
55979 +config GRKERNSEC_LINK
55980 + bool "Linking restrictions"
55981 + default y if GRKERNSEC_CONFIG_AUTO
55982 + help
55983 + If you say Y here, /tmp race exploits will be prevented, since users
55984 + will no longer be able to follow symlinks owned by other users in
55985 + world-writable +t directories (e.g. /tmp), unless the owner of the
55986 + symlink is the owner of the directory. users will also not be
55987 + able to hardlink to files they do not own. If the sysctl option is
55988 + enabled, a sysctl option with name "linking_restrictions" is created.
55989 +
55990 +config GRKERNSEC_SYMLINKOWN
55991 + bool "Kernel-enforced SymlinksIfOwnerMatch"
55992 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
55993 + help
55994 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
55995 + that prevents it from being used as a security feature. As Apache
55996 + verifies the symlink by performing a stat() against the target of
55997 + the symlink before it is followed, an attacker can setup a symlink
55998 + to point to a same-owned file, then replace the symlink with one
55999 + that targets another user's file just after Apache "validates" the
56000 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
56001 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
56002 + will be in place for the group you specify. If the sysctl option
56003 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
56004 + created.
56005 +
56006 +config GRKERNSEC_SYMLINKOWN_GID
56007 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
56008 + depends on GRKERNSEC_SYMLINKOWN
56009 + default 1006
56010 + help
56011 + Setting this GID determines what group kernel-enforced
56012 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
56013 + is enabled, a sysctl option with name "symlinkown_gid" is created.
56014 +
56015 +config GRKERNSEC_FIFO
56016 + bool "FIFO restrictions"
56017 + default y if GRKERNSEC_CONFIG_AUTO
56018 + help
56019 + If you say Y here, users will not be able to write to FIFOs they don't
56020 + own in world-writable +t directories (e.g. /tmp), unless the owner of
56021 + the FIFO is the same owner of the directory it's held in. If the sysctl
56022 + option is enabled, a sysctl option with name "fifo_restrictions" is
56023 + created.
56024 +
56025 +config GRKERNSEC_SYSFS_RESTRICT
56026 + bool "Sysfs/debugfs restriction"
56027 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56028 + depends on SYSFS
56029 + help
56030 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
56031 + any filesystem normally mounted under it (e.g. debugfs) will be
56032 + mostly accessible only by root. These filesystems generally provide access
56033 + to hardware and debug information that isn't appropriate for unprivileged
56034 + users of the system. Sysfs and debugfs have also become a large source
56035 + of new vulnerabilities, ranging from infoleaks to local compromise.
56036 + There has been very little oversight with an eye toward security involved
56037 + in adding new exporters of information to these filesystems, so their
56038 + use is discouraged.
56039 + For reasons of compatibility, a few directories have been whitelisted
56040 + for access by non-root users:
56041 + /sys/fs/selinux
56042 + /sys/fs/fuse
56043 + /sys/devices/system/cpu
56044 +
56045 +config GRKERNSEC_ROFS
56046 + bool "Runtime read-only mount protection"
56047 + help
56048 + If you say Y here, a sysctl option with name "romount_protect" will
56049 + be created. By setting this option to 1 at runtime, filesystems
56050 + will be protected in the following ways:
56051 + * No new writable mounts will be allowed
56052 + * Existing read-only mounts won't be able to be remounted read/write
56053 + * Write operations will be denied on all block devices
56054 + This option acts independently of grsec_lock: once it is set to 1,
56055 + it cannot be turned off. Therefore, please be mindful of the resulting
56056 + behavior if this option is enabled in an init script on a read-only
56057 + filesystem. This feature is mainly intended for secure embedded systems.
56058 +
56059 +config GRKERNSEC_DEVICE_SIDECHANNEL
56060 + bool "Eliminate stat/notify-based device sidechannels"
56061 + default y if GRKERNSEC_CONFIG_AUTO
56062 + help
56063 + If you say Y here, timing analyses on block or character
56064 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
56065 + will be thwarted for unprivileged users. If a process without
56066 + CAP_MKNOD stats such a device, the last access and last modify times
56067 + will match the device's create time. No access or modify events
56068 + will be triggered through inotify/dnotify/fanotify for such devices.
56069 + This feature will prevent attacks that may at a minimum
56070 + allow an attacker to determine the administrator's password length.
56071 +
56072 +config GRKERNSEC_CHROOT
56073 + bool "Chroot jail restrictions"
56074 + default y if GRKERNSEC_CONFIG_AUTO
56075 + help
56076 + If you say Y here, you will be able to choose several options that will
56077 + make breaking out of a chrooted jail much more difficult. If you
56078 + encounter no software incompatibilities with the following options, it
56079 + is recommended that you enable each one.
56080 +
56081 +config GRKERNSEC_CHROOT_MOUNT
56082 + bool "Deny mounts"
56083 + default y if GRKERNSEC_CONFIG_AUTO
56084 + depends on GRKERNSEC_CHROOT
56085 + help
56086 + If you say Y here, processes inside a chroot will not be able to
56087 + mount or remount filesystems. If the sysctl option is enabled, a
56088 + sysctl option with name "chroot_deny_mount" is created.
56089 +
56090 +config GRKERNSEC_CHROOT_DOUBLE
56091 + bool "Deny double-chroots"
56092 + default y if GRKERNSEC_CONFIG_AUTO
56093 + depends on GRKERNSEC_CHROOT
56094 + help
56095 + If you say Y here, processes inside a chroot will not be able to chroot
56096 + again outside the chroot. This is a widely used method of breaking
56097 + out of a chroot jail and should not be allowed. If the sysctl
56098 + option is enabled, a sysctl option with name
56099 + "chroot_deny_chroot" is created.
56100 +
56101 +config GRKERNSEC_CHROOT_PIVOT
56102 + bool "Deny pivot_root in chroot"
56103 + default y if GRKERNSEC_CONFIG_AUTO
56104 + depends on GRKERNSEC_CHROOT
56105 + help
56106 + If you say Y here, processes inside a chroot will not be able to use
56107 + a function called pivot_root() that was introduced in Linux 2.3.41. It
56108 + works similar to chroot in that it changes the root filesystem. This
56109 + function could be misused in a chrooted process to attempt to break out
56110 + of the chroot, and therefore should not be allowed. If the sysctl
56111 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
56112 + created.
56113 +
56114 +config GRKERNSEC_CHROOT_CHDIR
56115 + bool "Enforce chdir(\"/\") on all chroots"
56116 + default y if GRKERNSEC_CONFIG_AUTO
56117 + depends on GRKERNSEC_CHROOT
56118 + help
56119 + If you say Y here, the current working directory of all newly-chrooted
56120 + applications will be set to the the root directory of the chroot.
56121 + The man page on chroot(2) states:
56122 + Note that this call does not change the current working
56123 + directory, so that `.' can be outside the tree rooted at
56124 + `/'. In particular, the super-user can escape from a
56125 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
56126 +
56127 + It is recommended that you say Y here, since it's not known to break
56128 + any software. If the sysctl option is enabled, a sysctl option with
56129 + name "chroot_enforce_chdir" is created.
56130 +
56131 +config GRKERNSEC_CHROOT_CHMOD
56132 + bool "Deny (f)chmod +s"
56133 + default y if GRKERNSEC_CONFIG_AUTO
56134 + depends on GRKERNSEC_CHROOT
56135 + help
56136 + If you say Y here, processes inside a chroot will not be able to chmod
56137 + or fchmod files to make them have suid or sgid bits. This protects
56138 + against another published method of breaking a chroot. If the sysctl
56139 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
56140 + created.
56141 +
56142 +config GRKERNSEC_CHROOT_FCHDIR
56143 + bool "Deny fchdir out of chroot"
56144 + default y if GRKERNSEC_CONFIG_AUTO
56145 + depends on GRKERNSEC_CHROOT
56146 + help
56147 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
56148 + to a file descriptor of the chrooting process that points to a directory
56149 + outside the filesystem will be stopped. If the sysctl option
56150 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
56151 +
56152 +config GRKERNSEC_CHROOT_MKNOD
56153 + bool "Deny mknod"
56154 + default y if GRKERNSEC_CONFIG_AUTO
56155 + depends on GRKERNSEC_CHROOT
56156 + help
56157 + If you say Y here, processes inside a chroot will not be allowed to
56158 + mknod. The problem with using mknod inside a chroot is that it
56159 + would allow an attacker to create a device entry that is the same
56160 + as one on the physical root of your system, which could range from
56161 + anything from the console device to a device for your harddrive (which
56162 + they could then use to wipe the drive or steal data). It is recommended
56163 + that you say Y here, unless you run into software incompatibilities.
56164 + If the sysctl option is enabled, a sysctl option with name
56165 + "chroot_deny_mknod" is created.
56166 +
56167 +config GRKERNSEC_CHROOT_SHMAT
56168 + bool "Deny shmat() out of chroot"
56169 + default y if GRKERNSEC_CONFIG_AUTO
56170 + depends on GRKERNSEC_CHROOT
56171 + help
56172 + If you say Y here, processes inside a chroot will not be able to attach
56173 + to shared memory segments that were created outside of the chroot jail.
56174 + It is recommended that you say Y here. If the sysctl option is enabled,
56175 + a sysctl option with name "chroot_deny_shmat" is created.
56176 +
56177 +config GRKERNSEC_CHROOT_UNIX
56178 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
56179 + default y if GRKERNSEC_CONFIG_AUTO
56180 + depends on GRKERNSEC_CHROOT
56181 + help
56182 + If you say Y here, processes inside a chroot will not be able to
56183 + connect to abstract (meaning not belonging to a filesystem) Unix
56184 + domain sockets that were bound outside of a chroot. It is recommended
56185 + that you say Y here. If the sysctl option is enabled, a sysctl option
56186 + with name "chroot_deny_unix" is created.
56187 +
56188 +config GRKERNSEC_CHROOT_FINDTASK
56189 + bool "Protect outside processes"
56190 + default y if GRKERNSEC_CONFIG_AUTO
56191 + depends on GRKERNSEC_CHROOT
56192 + help
56193 + If you say Y here, processes inside a chroot will not be able to
56194 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
56195 + getsid, or view any process outside of the chroot. If the sysctl
56196 + option is enabled, a sysctl option with name "chroot_findtask" is
56197 + created.
56198 +
56199 +config GRKERNSEC_CHROOT_NICE
56200 + bool "Restrict priority changes"
56201 + default y if GRKERNSEC_CONFIG_AUTO
56202 + depends on GRKERNSEC_CHROOT
56203 + help
56204 + If you say Y here, processes inside a chroot will not be able to raise
56205 + the priority of processes in the chroot, or alter the priority of
56206 + processes outside the chroot. This provides more security than simply
56207 + removing CAP_SYS_NICE from the process' capability set. If the
56208 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
56209 + is created.
56210 +
56211 +config GRKERNSEC_CHROOT_SYSCTL
56212 + bool "Deny sysctl writes"
56213 + default y if GRKERNSEC_CONFIG_AUTO
56214 + depends on GRKERNSEC_CHROOT
56215 + help
56216 + If you say Y here, an attacker in a chroot will not be able to
56217 + write to sysctl entries, either by sysctl(2) or through a /proc
56218 + interface. It is strongly recommended that you say Y here. If the
56219 + sysctl option is enabled, a sysctl option with name
56220 + "chroot_deny_sysctl" is created.
56221 +
56222 +config GRKERNSEC_CHROOT_CAPS
56223 + bool "Capability restrictions"
56224 + default y if GRKERNSEC_CONFIG_AUTO
56225 + depends on GRKERNSEC_CHROOT
56226 + help
56227 + If you say Y here, the capabilities on all processes within a
56228 + chroot jail will be lowered to stop module insertion, raw i/o,
56229 + system and net admin tasks, rebooting the system, modifying immutable
56230 + files, modifying IPC owned by another, and changing the system time.
56231 + This is left an option because it can break some apps. Disable this
56232 + if your chrooted apps are having problems performing those kinds of
56233 + tasks. If the sysctl option is enabled, a sysctl option with
56234 + name "chroot_caps" is created.
56235 +
56236 +endmenu
56237 +menu "Kernel Auditing"
56238 +depends on GRKERNSEC
56239 +
56240 +config GRKERNSEC_AUDIT_GROUP
56241 + bool "Single group for auditing"
56242 + help
56243 + If you say Y here, the exec and chdir logging features will only operate
56244 + on a group you specify. This option is recommended if you only want to
56245 + watch certain users instead of having a large amount of logs from the
56246 + entire system. If the sysctl option is enabled, a sysctl option with
56247 + name "audit_group" is created.
56248 +
56249 +config GRKERNSEC_AUDIT_GID
56250 + int "GID for auditing"
56251 + depends on GRKERNSEC_AUDIT_GROUP
56252 + default 1007
56253 +
56254 +config GRKERNSEC_EXECLOG
56255 + bool "Exec logging"
56256 + help
56257 + If you say Y here, all execve() calls will be logged (since the
56258 + other exec*() calls are frontends to execve(), all execution
56259 + will be logged). Useful for shell-servers that like to keep track
56260 + of their users. If the sysctl option is enabled, a sysctl option with
56261 + name "exec_logging" is created.
56262 + WARNING: This option when enabled will produce a LOT of logs, especially
56263 + on an active system.
56264 +
56265 +config GRKERNSEC_RESLOG
56266 + bool "Resource logging"
56267 + default y if GRKERNSEC_CONFIG_AUTO
56268 + help
56269 + If you say Y here, all attempts to overstep resource limits will
56270 + be logged with the resource name, the requested size, and the current
56271 + limit. It is highly recommended that you say Y here. If the sysctl
56272 + option is enabled, a sysctl option with name "resource_logging" is
56273 + created. If the RBAC system is enabled, the sysctl value is ignored.
56274 +
56275 +config GRKERNSEC_CHROOT_EXECLOG
56276 + bool "Log execs within chroot"
56277 + help
56278 + If you say Y here, all executions inside a chroot jail will be logged
56279 + to syslog. This can cause a large amount of logs if certain
56280 + applications (eg. djb's daemontools) are installed on the system, and
56281 + is therefore left as an option. If the sysctl option is enabled, a
56282 + sysctl option with name "chroot_execlog" is created.
56283 +
56284 +config GRKERNSEC_AUDIT_PTRACE
56285 + bool "Ptrace logging"
56286 + help
56287 + If you say Y here, all attempts to attach to a process via ptrace
56288 + will be logged. If the sysctl option is enabled, a sysctl option
56289 + with name "audit_ptrace" is created.
56290 +
56291 +config GRKERNSEC_AUDIT_CHDIR
56292 + bool "Chdir logging"
56293 + help
56294 + If you say Y here, all chdir() calls will be logged. If the sysctl
56295 + option is enabled, a sysctl option with name "audit_chdir" is created.
56296 +
56297 +config GRKERNSEC_AUDIT_MOUNT
56298 + bool "(Un)Mount logging"
56299 + help
56300 + If you say Y here, all mounts and unmounts will be logged. If the
56301 + sysctl option is enabled, a sysctl option with name "audit_mount" is
56302 + created.
56303 +
56304 +config GRKERNSEC_SIGNAL
56305 + bool "Signal logging"
56306 + default y if GRKERNSEC_CONFIG_AUTO
56307 + help
56308 + If you say Y here, certain important signals will be logged, such as
56309 + SIGSEGV, which will as a result inform you of when a error in a program
56310 + occurred, which in some cases could mean a possible exploit attempt.
56311 + If the sysctl option is enabled, a sysctl option with name
56312 + "signal_logging" is created.
56313 +
56314 +config GRKERNSEC_FORKFAIL
56315 + bool "Fork failure logging"
56316 + help
56317 + If you say Y here, all failed fork() attempts will be logged.
56318 + This could suggest a fork bomb, or someone attempting to overstep
56319 + their process limit. If the sysctl option is enabled, a sysctl option
56320 + with name "forkfail_logging" is created.
56321 +
56322 +config GRKERNSEC_TIME
56323 + bool "Time change logging"
56324 + default y if GRKERNSEC_CONFIG_AUTO
56325 + help
56326 + If you say Y here, any changes of the system clock will be logged.
56327 + If the sysctl option is enabled, a sysctl option with name
56328 + "timechange_logging" is created.
56329 +
56330 +config GRKERNSEC_PROC_IPADDR
56331 + bool "/proc/<pid>/ipaddr support"
56332 + default y if GRKERNSEC_CONFIG_AUTO
56333 + help
56334 + If you say Y here, a new entry will be added to each /proc/<pid>
56335 + directory that contains the IP address of the person using the task.
56336 + The IP is carried across local TCP and AF_UNIX stream sockets.
56337 + This information can be useful for IDS/IPSes to perform remote response
56338 + to a local attack. The entry is readable by only the owner of the
56339 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
56340 + the RBAC system), and thus does not create privacy concerns.
56341 +
56342 +config GRKERNSEC_RWXMAP_LOG
56343 + bool 'Denied RWX mmap/mprotect logging'
56344 + default y if GRKERNSEC_CONFIG_AUTO
56345 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
56346 + help
56347 + If you say Y here, calls to mmap() and mprotect() with explicit
56348 + usage of PROT_WRITE and PROT_EXEC together will be logged when
56349 + denied by the PAX_MPROTECT feature. If the sysctl option is
56350 + enabled, a sysctl option with name "rwxmap_logging" is created.
56351 +
56352 +config GRKERNSEC_AUDIT_TEXTREL
56353 + bool 'ELF text relocations logging (READ HELP)'
56354 + depends on PAX_MPROTECT
56355 + help
56356 + If you say Y here, text relocations will be logged with the filename
56357 + of the offending library or binary. The purpose of the feature is
56358 + to help Linux distribution developers get rid of libraries and
56359 + binaries that need text relocations which hinder the future progress
56360 + of PaX. Only Linux distribution developers should say Y here, and
56361 + never on a production machine, as this option creates an information
56362 + leak that could aid an attacker in defeating the randomization of
56363 + a single memory region. If the sysctl option is enabled, a sysctl
56364 + option with name "audit_textrel" is created.
56365 +
56366 +endmenu
56367 +
56368 +menu "Executable Protections"
56369 +depends on GRKERNSEC
56370 +
56371 +config GRKERNSEC_DMESG
56372 + bool "Dmesg(8) restriction"
56373 + default y if GRKERNSEC_CONFIG_AUTO
56374 + help
56375 + If you say Y here, non-root users will not be able to use dmesg(8)
56376 + to view the contents of the kernel's circular log buffer.
56377 + The kernel's log buffer often contains kernel addresses and other
56378 + identifying information useful to an attacker in fingerprinting a
56379 + system for a targeted exploit.
56380 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
56381 + created.
56382 +
56383 +config GRKERNSEC_HARDEN_PTRACE
56384 + bool "Deter ptrace-based process snooping"
56385 + default y if GRKERNSEC_CONFIG_AUTO
56386 + help
56387 + If you say Y here, TTY sniffers and other malicious monitoring
56388 + programs implemented through ptrace will be defeated. If you
56389 + have been using the RBAC system, this option has already been
56390 + enabled for several years for all users, with the ability to make
56391 + fine-grained exceptions.
56392 +
56393 + This option only affects the ability of non-root users to ptrace
56394 + processes that are not a descendent of the ptracing process.
56395 + This means that strace ./binary and gdb ./binary will still work,
56396 + but attaching to arbitrary processes will not. If the sysctl
56397 + option is enabled, a sysctl option with name "harden_ptrace" is
56398 + created.
56399 +
56400 +config GRKERNSEC_PTRACE_READEXEC
56401 + bool "Require read access to ptrace sensitive binaries"
56402 + default y if GRKERNSEC_CONFIG_AUTO
56403 + help
56404 + If you say Y here, unprivileged users will not be able to ptrace unreadable
56405 + binaries. This option is useful in environments that
56406 + remove the read bits (e.g. file mode 4711) from suid binaries to
56407 + prevent infoleaking of their contents. This option adds
56408 + consistency to the use of that file mode, as the binary could normally
56409 + be read out when run without privileges while ptracing.
56410 +
56411 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
56412 + is created.
56413 +
56414 +config GRKERNSEC_SETXID
56415 + bool "Enforce consistent multithreaded privileges"
56416 + default y if GRKERNSEC_CONFIG_AUTO
56417 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
56418 + help
56419 + If you say Y here, a change from a root uid to a non-root uid
56420 + in a multithreaded application will cause the resulting uids,
56421 + gids, supplementary groups, and capabilities in that thread
56422 + to be propagated to the other threads of the process. In most
56423 + cases this is unnecessary, as glibc will emulate this behavior
56424 + on behalf of the application. Other libcs do not act in the
56425 + same way, allowing the other threads of the process to continue
56426 + running with root privileges. If the sysctl option is enabled,
56427 + a sysctl option with name "consistent_setxid" is created.
56428 +
56429 +config GRKERNSEC_TPE
56430 + bool "Trusted Path Execution (TPE)"
56431 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56432 + help
56433 + If you say Y here, you will be able to choose a gid to add to the
56434 + supplementary groups of users you want to mark as "untrusted."
56435 + These users will not be able to execute any files that are not in
56436 + root-owned directories writable only by root. If the sysctl option
56437 + is enabled, a sysctl option with name "tpe" is created.
56438 +
56439 +config GRKERNSEC_TPE_ALL
56440 + bool "Partially restrict all non-root users"
56441 + depends on GRKERNSEC_TPE
56442 + help
56443 + If you say Y here, all non-root users will be covered under
56444 + a weaker TPE restriction. This is separate from, and in addition to,
56445 + the main TPE options that you have selected elsewhere. Thus, if a
56446 + "trusted" GID is chosen, this restriction applies to even that GID.
56447 + Under this restriction, all non-root users will only be allowed to
56448 + execute files in directories they own that are not group or
56449 + world-writable, or in directories owned by root and writable only by
56450 + root. If the sysctl option is enabled, a sysctl option with name
56451 + "tpe_restrict_all" is created.
56452 +
56453 +config GRKERNSEC_TPE_INVERT
56454 + bool "Invert GID option"
56455 + depends on GRKERNSEC_TPE
56456 + help
56457 + If you say Y here, the group you specify in the TPE configuration will
56458 + decide what group TPE restrictions will be *disabled* for. This
56459 + option is useful if you want TPE restrictions to be applied to most
56460 + users on the system. If the sysctl option is enabled, a sysctl option
56461 + with name "tpe_invert" is created. Unlike other sysctl options, this
56462 + entry will default to on for backward-compatibility.
56463 +
56464 +config GRKERNSEC_TPE_GID
56465 + int
56466 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
56467 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
56468 +
56469 +config GRKERNSEC_TPE_UNTRUSTED_GID
56470 + int "GID for TPE-untrusted users"
56471 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
56472 + default 1005
56473 + help
56474 + Setting this GID determines what group TPE restrictions will be
56475 + *enabled* for. If the sysctl option is enabled, a sysctl option
56476 + with name "tpe_gid" is created.
56477 +
56478 +config GRKERNSEC_TPE_TRUSTED_GID
56479 + int "GID for TPE-trusted users"
56480 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
56481 + default 1005
56482 + help
56483 + Setting this GID determines what group TPE restrictions will be
56484 + *disabled* for. If the sysctl option is enabled, a sysctl option
56485 + with name "tpe_gid" is created.
56486 +
56487 +endmenu
56488 +menu "Network Protections"
56489 +depends on GRKERNSEC
56490 +
56491 +config GRKERNSEC_RANDNET
56492 + bool "Larger entropy pools"
56493 + default y if GRKERNSEC_CONFIG_AUTO
56494 + help
56495 + If you say Y here, the entropy pools used for many features of Linux
56496 + and grsecurity will be doubled in size. Since several grsecurity
56497 + features use additional randomness, it is recommended that you say Y
56498 + here. Saying Y here has a similar effect as modifying
56499 + /proc/sys/kernel/random/poolsize.
56500 +
56501 +config GRKERNSEC_BLACKHOLE
56502 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
56503 + default y if GRKERNSEC_CONFIG_AUTO
56504 + depends on NET
56505 + help
56506 + If you say Y here, neither TCP resets nor ICMP
56507 + destination-unreachable packets will be sent in response to packets
56508 + sent to ports for which no associated listening process exists.
56509 + This feature supports both IPV4 and IPV6 and exempts the
56510 + loopback interface from blackholing. Enabling this feature
56511 + makes a host more resilient to DoS attacks and reduces network
56512 + visibility against scanners.
56513 +
56514 + The blackhole feature as-implemented is equivalent to the FreeBSD
56515 + blackhole feature, as it prevents RST responses to all packets, not
56516 + just SYNs. Under most application behavior this causes no
56517 + problems, but applications (like haproxy) may not close certain
56518 + connections in a way that cleanly terminates them on the remote
56519 + end, leaving the remote host in LAST_ACK state. Because of this
56520 + side-effect and to prevent intentional LAST_ACK DoSes, this
56521 + feature also adds automatic mitigation against such attacks.
56522 + The mitigation drastically reduces the amount of time a socket
56523 + can spend in LAST_ACK state. If you're using haproxy and not
56524 + all servers it connects to have this option enabled, consider
56525 + disabling this feature on the haproxy host.
56526 +
56527 + If the sysctl option is enabled, two sysctl options with names
56528 + "ip_blackhole" and "lastack_retries" will be created.
56529 + While "ip_blackhole" takes the standard zero/non-zero on/off
56530 + toggle, "lastack_retries" uses the same kinds of values as
56531 + "tcp_retries1" and "tcp_retries2". The default value of 4
56532 + prevents a socket from lasting more than 45 seconds in LAST_ACK
56533 + state.
56534 +
56535 +config GRKERNSEC_NO_SIMULT_CONNECT
56536 + bool "Disable TCP Simultaneous Connect"
56537 + default y if GRKERNSEC_CONFIG_AUTO
56538 + depends on NET
56539 + help
56540 + If you say Y here, a feature by Willy Tarreau will be enabled that
56541 + removes a weakness in Linux's strict implementation of TCP that
56542 + allows two clients to connect to each other without either entering
56543 + a listening state. The weakness allows an attacker to easily prevent
56544 + a client from connecting to a known server provided the source port
56545 + for the connection is guessed correctly.
56546 +
56547 + As the weakness could be used to prevent an antivirus or IPS from
56548 + fetching updates, or prevent an SSL gateway from fetching a CRL,
56549 + it should be eliminated by enabling this option. Though Linux is
56550 + one of few operating systems supporting simultaneous connect, it
56551 + has no legitimate use in practice and is rarely supported by firewalls.
56552 +
56553 +config GRKERNSEC_SOCKET
56554 + bool "Socket restrictions"
56555 + depends on NET
56556 + help
56557 + If you say Y here, you will be able to choose from several options.
56558 + If you assign a GID on your system and add it to the supplementary
56559 + groups of users you want to restrict socket access to, this patch
56560 + will perform up to three things, based on the option(s) you choose.
56561 +
56562 +config GRKERNSEC_SOCKET_ALL
56563 + bool "Deny any sockets to group"
56564 + depends on GRKERNSEC_SOCKET
56565 + help
56566 + If you say Y here, you will be able to choose a GID of whose users will
56567 + be unable to connect to other hosts from your machine or run server
56568 + applications from your machine. If the sysctl option is enabled, a
56569 + sysctl option with name "socket_all" is created.
56570 +
56571 +config GRKERNSEC_SOCKET_ALL_GID
56572 + int "GID to deny all sockets for"
56573 + depends on GRKERNSEC_SOCKET_ALL
56574 + default 1004
56575 + help
56576 + Here you can choose the GID to disable socket access for. Remember to
56577 + add the users you want socket access disabled for to the GID
56578 + specified here. If the sysctl option is enabled, a sysctl option
56579 + with name "socket_all_gid" is created.
56580 +
56581 +config GRKERNSEC_SOCKET_CLIENT
56582 + bool "Deny client sockets to group"
56583 + depends on GRKERNSEC_SOCKET
56584 + help
56585 + If you say Y here, you will be able to choose a GID of whose users will
56586 + be unable to connect to other hosts from your machine, but will be
56587 + able to run servers. If this option is enabled, all users in the group
56588 + you specify will have to use passive mode when initiating ftp transfers
56589 + from the shell on your machine. If the sysctl option is enabled, a
56590 + sysctl option with name "socket_client" is created.
56591 +
56592 +config GRKERNSEC_SOCKET_CLIENT_GID
56593 + int "GID to deny client sockets for"
56594 + depends on GRKERNSEC_SOCKET_CLIENT
56595 + default 1003
56596 + help
56597 + Here you can choose the GID to disable client socket access for.
56598 + Remember to add the users you want client socket access disabled for to
56599 + the GID specified here. If the sysctl option is enabled, a sysctl
56600 + option with name "socket_client_gid" is created.
56601 +
56602 +config GRKERNSEC_SOCKET_SERVER
56603 + bool "Deny server sockets to group"
56604 + depends on GRKERNSEC_SOCKET
56605 + help
56606 + If you say Y here, you will be able to choose a GID of whose users will
56607 + be unable to run server applications from your machine. If the sysctl
56608 + option is enabled, a sysctl option with name "socket_server" is created.
56609 +
56610 +config GRKERNSEC_SOCKET_SERVER_GID
56611 + int "GID to deny server sockets for"
56612 + depends on GRKERNSEC_SOCKET_SERVER
56613 + default 1002
56614 + help
56615 + Here you can choose the GID to disable server socket access for.
56616 + Remember to add the users you want server socket access disabled for to
56617 + the GID specified here. If the sysctl option is enabled, a sysctl
56618 + option with name "socket_server_gid" is created.
56619 +
56620 +endmenu
56621 +menu "Sysctl Support"
56622 +depends on GRKERNSEC && SYSCTL
56623 +
56624 +config GRKERNSEC_SYSCTL
56625 + bool "Sysctl support"
56626 + default y if GRKERNSEC_CONFIG_AUTO
56627 + help
56628 + If you say Y here, you will be able to change the options that
56629 + grsecurity runs with at bootup, without having to recompile your
56630 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
56631 + to enable (1) or disable (0) various features. All the sysctl entries
56632 + are mutable until the "grsec_lock" entry is set to a non-zero value.
56633 + All features enabled in the kernel configuration are disabled at boot
56634 + if you do not say Y to the "Turn on features by default" option.
56635 + All options should be set at startup, and the grsec_lock entry should
56636 + be set to a non-zero value after all the options are set.
56637 + *THIS IS EXTREMELY IMPORTANT*
56638 +
56639 +config GRKERNSEC_SYSCTL_DISTRO
56640 + bool "Extra sysctl support for distro makers (READ HELP)"
56641 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
56642 + help
56643 + If you say Y here, additional sysctl options will be created
56644 + for features that affect processes running as root. Therefore,
56645 + it is critical when using this option that the grsec_lock entry be
56646 + enabled after boot. Only distros with prebuilt kernel packages
56647 + with this option enabled that can ensure grsec_lock is enabled
56648 + after boot should use this option.
56649 + *Failure to set grsec_lock after boot makes all grsec features
56650 + this option covers useless*
56651 +
56652 + Currently this option creates the following sysctl entries:
56653 + "Disable Privileged I/O": "disable_priv_io"
56654 +
56655 +config GRKERNSEC_SYSCTL_ON
56656 + bool "Turn on features by default"
56657 + default y if GRKERNSEC_CONFIG_AUTO
56658 + depends on GRKERNSEC_SYSCTL
56659 + help
56660 + If you say Y here, instead of having all features enabled in the
56661 + kernel configuration disabled at boot time, the features will be
56662 + enabled at boot time. It is recommended you say Y here unless
56663 + there is some reason you would want all sysctl-tunable features to
56664 + be disabled by default. As mentioned elsewhere, it is important
56665 + to enable the grsec_lock entry once you have finished modifying
56666 + the sysctl entries.
56667 +
56668 +endmenu
56669 +menu "Logging Options"
56670 +depends on GRKERNSEC
56671 +
56672 +config GRKERNSEC_FLOODTIME
56673 + int "Seconds in between log messages (minimum)"
56674 + default 10
56675 + help
56676 + This option allows you to enforce the number of seconds between
56677 + grsecurity log messages. The default should be suitable for most
56678 + people, however, if you choose to change it, choose a value small enough
56679 + to allow informative logs to be produced, but large enough to
56680 + prevent flooding.
56681 +
56682 +config GRKERNSEC_FLOODBURST
56683 + int "Number of messages in a burst (maximum)"
56684 + default 6
56685 + help
56686 + This option allows you to choose the maximum number of messages allowed
56687 + within the flood time interval you chose in a separate option. The
56688 + default should be suitable for most people, however if you find that
56689 + many of your logs are being interpreted as flooding, you may want to
56690 + raise this value.
56691 +
56692 +endmenu
56693 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
56694 new file mode 100644
56695 index 0000000..1b9afa9
56696 --- /dev/null
56697 +++ b/grsecurity/Makefile
56698 @@ -0,0 +1,38 @@
56699 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
56700 +# during 2001-2009 it has been completely redesigned by Brad Spengler
56701 +# into an RBAC system
56702 +#
56703 +# All code in this directory and various hooks inserted throughout the kernel
56704 +# are copyright Brad Spengler - Open Source Security, Inc., and released
56705 +# under the GPL v2 or higher
56706 +
56707 +KBUILD_CFLAGS += -Werror
56708 +
56709 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
56710 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
56711 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
56712 +
56713 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
56714 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
56715 + gracl_learn.o grsec_log.o
56716 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
56717 +
56718 +ifdef CONFIG_NET
56719 +obj-y += grsec_sock.o
56720 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
56721 +endif
56722 +
56723 +ifndef CONFIG_GRKERNSEC
56724 +obj-y += grsec_disabled.o
56725 +endif
56726 +
56727 +ifdef CONFIG_GRKERNSEC_HIDESYM
56728 +extra-y := grsec_hidesym.o
56729 +$(obj)/grsec_hidesym.o:
56730 + @-chmod -f 500 /boot
56731 + @-chmod -f 500 /lib/modules
56732 + @-chmod -f 500 /lib64/modules
56733 + @-chmod -f 500 /lib32/modules
56734 + @-chmod -f 700 .
56735 + @echo ' grsec: protected kernel image paths'
56736 +endif
56737 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
56738 new file mode 100644
56739 index 0000000..0767b2e
56740 --- /dev/null
56741 +++ b/grsecurity/gracl.c
56742 @@ -0,0 +1,4067 @@
56743 +#include <linux/kernel.h>
56744 +#include <linux/module.h>
56745 +#include <linux/sched.h>
56746 +#include <linux/mm.h>
56747 +#include <linux/file.h>
56748 +#include <linux/fs.h>
56749 +#include <linux/namei.h>
56750 +#include <linux/mount.h>
56751 +#include <linux/tty.h>
56752 +#include <linux/proc_fs.h>
56753 +#include <linux/lglock.h>
56754 +#include <linux/slab.h>
56755 +#include <linux/vmalloc.h>
56756 +#include <linux/types.h>
56757 +#include <linux/sysctl.h>
56758 +#include <linux/netdevice.h>
56759 +#include <linux/ptrace.h>
56760 +#include <linux/gracl.h>
56761 +#include <linux/gralloc.h>
56762 +#include <linux/security.h>
56763 +#include <linux/grinternal.h>
56764 +#include <linux/pid_namespace.h>
56765 +#include <linux/stop_machine.h>
56766 +#include <linux/fdtable.h>
56767 +#include <linux/percpu.h>
56768 +#include <linux/lglock.h>
56769 +#include <linux/hugetlb.h>
56770 +#include "../fs/mount.h"
56771 +
56772 +#include <asm/uaccess.h>
56773 +#include <asm/errno.h>
56774 +#include <asm/mman.h>
56775 +
56776 +extern struct lglock vfsmount_lock;
56777 +
56778 +static struct acl_role_db acl_role_set;
56779 +static struct name_db name_set;
56780 +static struct inodev_db inodev_set;
56781 +
56782 +/* for keeping track of userspace pointers used for subjects, so we
56783 + can share references in the kernel as well
56784 +*/
56785 +
56786 +static struct path real_root;
56787 +
56788 +static struct acl_subj_map_db subj_map_set;
56789 +
56790 +static struct acl_role_label *default_role;
56791 +
56792 +static struct acl_role_label *role_list;
56793 +
56794 +static u16 acl_sp_role_value;
56795 +
56796 +extern char *gr_shared_page[4];
56797 +static DEFINE_MUTEX(gr_dev_mutex);
56798 +DEFINE_RWLOCK(gr_inode_lock);
56799 +
56800 +struct gr_arg *gr_usermode;
56801 +
56802 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
56803 +
56804 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
56805 +extern void gr_clear_learn_entries(void);
56806 +
56807 +unsigned char *gr_system_salt;
56808 +unsigned char *gr_system_sum;
56809 +
56810 +static struct sprole_pw **acl_special_roles = NULL;
56811 +static __u16 num_sprole_pws = 0;
56812 +
56813 +static struct acl_role_label *kernel_role = NULL;
56814 +
56815 +static unsigned int gr_auth_attempts = 0;
56816 +static unsigned long gr_auth_expires = 0UL;
56817 +
56818 +#ifdef CONFIG_NET
56819 +extern struct vfsmount *sock_mnt;
56820 +#endif
56821 +
56822 +extern struct vfsmount *pipe_mnt;
56823 +extern struct vfsmount *shm_mnt;
56824 +
56825 +#ifdef CONFIG_HUGETLBFS
56826 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
56827 +#endif
56828 +
56829 +static struct acl_object_label *fakefs_obj_rw;
56830 +static struct acl_object_label *fakefs_obj_rwx;
56831 +
56832 +extern int gr_init_uidset(void);
56833 +extern void gr_free_uidset(void);
56834 +extern void gr_remove_uid(uid_t uid);
56835 +extern int gr_find_uid(uid_t uid);
56836 +
56837 +__inline__ int
56838 +gr_acl_is_enabled(void)
56839 +{
56840 + return (gr_status & GR_READY);
56841 +}
56842 +
56843 +#ifdef CONFIG_BTRFS_FS
56844 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56845 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56846 +#endif
56847 +
56848 +static inline dev_t __get_dev(const struct dentry *dentry)
56849 +{
56850 +#ifdef CONFIG_BTRFS_FS
56851 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56852 + return get_btrfs_dev_from_inode(dentry->d_inode);
56853 + else
56854 +#endif
56855 + return dentry->d_inode->i_sb->s_dev;
56856 +}
56857 +
56858 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56859 +{
56860 + return __get_dev(dentry);
56861 +}
56862 +
56863 +static char gr_task_roletype_to_char(struct task_struct *task)
56864 +{
56865 + switch (task->role->roletype &
56866 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
56867 + GR_ROLE_SPECIAL)) {
56868 + case GR_ROLE_DEFAULT:
56869 + return 'D';
56870 + case GR_ROLE_USER:
56871 + return 'U';
56872 + case GR_ROLE_GROUP:
56873 + return 'G';
56874 + case GR_ROLE_SPECIAL:
56875 + return 'S';
56876 + }
56877 +
56878 + return 'X';
56879 +}
56880 +
56881 +char gr_roletype_to_char(void)
56882 +{
56883 + return gr_task_roletype_to_char(current);
56884 +}
56885 +
56886 +__inline__ int
56887 +gr_acl_tpe_check(void)
56888 +{
56889 + if (unlikely(!(gr_status & GR_READY)))
56890 + return 0;
56891 + if (current->role->roletype & GR_ROLE_TPE)
56892 + return 1;
56893 + else
56894 + return 0;
56895 +}
56896 +
56897 +int
56898 +gr_handle_rawio(const struct inode *inode)
56899 +{
56900 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56901 + if (inode && S_ISBLK(inode->i_mode) &&
56902 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56903 + !capable(CAP_SYS_RAWIO))
56904 + return 1;
56905 +#endif
56906 + return 0;
56907 +}
56908 +
56909 +static int
56910 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
56911 +{
56912 + if (likely(lena != lenb))
56913 + return 0;
56914 +
56915 + return !memcmp(a, b, lena);
56916 +}
56917 +
56918 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
56919 +{
56920 + *buflen -= namelen;
56921 + if (*buflen < 0)
56922 + return -ENAMETOOLONG;
56923 + *buffer -= namelen;
56924 + memcpy(*buffer, str, namelen);
56925 + return 0;
56926 +}
56927 +
56928 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
56929 +{
56930 + return prepend(buffer, buflen, name->name, name->len);
56931 +}
56932 +
56933 +static int prepend_path(const struct path *path, struct path *root,
56934 + char **buffer, int *buflen)
56935 +{
56936 + struct dentry *dentry = path->dentry;
56937 + struct vfsmount *vfsmnt = path->mnt;
56938 + struct mount *mnt = real_mount(vfsmnt);
56939 + bool slash = false;
56940 + int error = 0;
56941 +
56942 + while (dentry != root->dentry || vfsmnt != root->mnt) {
56943 + struct dentry * parent;
56944 +
56945 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
56946 + /* Global root? */
56947 + if (!mnt_has_parent(mnt)) {
56948 + goto out;
56949 + }
56950 + dentry = mnt->mnt_mountpoint;
56951 + mnt = mnt->mnt_parent;
56952 + vfsmnt = &mnt->mnt;
56953 + continue;
56954 + }
56955 + parent = dentry->d_parent;
56956 + prefetch(parent);
56957 + spin_lock(&dentry->d_lock);
56958 + error = prepend_name(buffer, buflen, &dentry->d_name);
56959 + spin_unlock(&dentry->d_lock);
56960 + if (!error)
56961 + error = prepend(buffer, buflen, "/", 1);
56962 + if (error)
56963 + break;
56964 +
56965 + slash = true;
56966 + dentry = parent;
56967 + }
56968 +
56969 +out:
56970 + if (!error && !slash)
56971 + error = prepend(buffer, buflen, "/", 1);
56972 +
56973 + return error;
56974 +}
56975 +
56976 +/* this must be called with vfsmount_lock and rename_lock held */
56977 +
56978 +static char *__our_d_path(const struct path *path, struct path *root,
56979 + char *buf, int buflen)
56980 +{
56981 + char *res = buf + buflen;
56982 + int error;
56983 +
56984 + prepend(&res, &buflen, "\0", 1);
56985 + error = prepend_path(path, root, &res, &buflen);
56986 + if (error)
56987 + return ERR_PTR(error);
56988 +
56989 + return res;
56990 +}
56991 +
56992 +static char *
56993 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
56994 +{
56995 + char *retval;
56996 +
56997 + retval = __our_d_path(path, root, buf, buflen);
56998 + if (unlikely(IS_ERR(retval)))
56999 + retval = strcpy(buf, "<path too long>");
57000 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
57001 + retval[1] = '\0';
57002 +
57003 + return retval;
57004 +}
57005 +
57006 +static char *
57007 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57008 + char *buf, int buflen)
57009 +{
57010 + struct path path;
57011 + char *res;
57012 +
57013 + path.dentry = (struct dentry *)dentry;
57014 + path.mnt = (struct vfsmount *)vfsmnt;
57015 +
57016 + /* we can use real_root.dentry, real_root.mnt, because this is only called
57017 + by the RBAC system */
57018 + res = gen_full_path(&path, &real_root, buf, buflen);
57019 +
57020 + return res;
57021 +}
57022 +
57023 +static char *
57024 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57025 + char *buf, int buflen)
57026 +{
57027 + char *res;
57028 + struct path path;
57029 + struct path root;
57030 + struct task_struct *reaper = init_pid_ns.child_reaper;
57031 +
57032 + path.dentry = (struct dentry *)dentry;
57033 + path.mnt = (struct vfsmount *)vfsmnt;
57034 +
57035 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
57036 + get_fs_root(reaper->fs, &root);
57037 +
57038 + write_seqlock(&rename_lock);
57039 + br_read_lock(&vfsmount_lock);
57040 + res = gen_full_path(&path, &root, buf, buflen);
57041 + br_read_unlock(&vfsmount_lock);
57042 + write_sequnlock(&rename_lock);
57043 +
57044 + path_put(&root);
57045 + return res;
57046 +}
57047 +
57048 +static char *
57049 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57050 +{
57051 + char *ret;
57052 + write_seqlock(&rename_lock);
57053 + br_read_lock(&vfsmount_lock);
57054 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57055 + PAGE_SIZE);
57056 + br_read_unlock(&vfsmount_lock);
57057 + write_sequnlock(&rename_lock);
57058 + return ret;
57059 +}
57060 +
57061 +static char *
57062 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57063 +{
57064 + char *ret;
57065 + char *buf;
57066 + int buflen;
57067 +
57068 + write_seqlock(&rename_lock);
57069 + br_read_lock(&vfsmount_lock);
57070 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
57071 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
57072 + buflen = (int)(ret - buf);
57073 + if (buflen >= 5)
57074 + prepend(&ret, &buflen, "/proc", 5);
57075 + else
57076 + ret = strcpy(buf, "<path too long>");
57077 + br_read_unlock(&vfsmount_lock);
57078 + write_sequnlock(&rename_lock);
57079 + return ret;
57080 +}
57081 +
57082 +char *
57083 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
57084 +{
57085 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57086 + PAGE_SIZE);
57087 +}
57088 +
57089 +char *
57090 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
57091 +{
57092 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57093 + PAGE_SIZE);
57094 +}
57095 +
57096 +char *
57097 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
57098 +{
57099 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
57100 + PAGE_SIZE);
57101 +}
57102 +
57103 +char *
57104 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
57105 +{
57106 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
57107 + PAGE_SIZE);
57108 +}
57109 +
57110 +char *
57111 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
57112 +{
57113 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
57114 + PAGE_SIZE);
57115 +}
57116 +
57117 +__inline__ __u32
57118 +to_gr_audit(const __u32 reqmode)
57119 +{
57120 + /* masks off auditable permission flags, then shifts them to create
57121 + auditing flags, and adds the special case of append auditing if
57122 + we're requesting write */
57123 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
57124 +}
57125 +
57126 +struct acl_subject_label *
57127 +lookup_subject_map(const struct acl_subject_label *userp)
57128 +{
57129 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
57130 + struct subject_map *match;
57131 +
57132 + match = subj_map_set.s_hash[index];
57133 +
57134 + while (match && match->user != userp)
57135 + match = match->next;
57136 +
57137 + if (match != NULL)
57138 + return match->kernel;
57139 + else
57140 + return NULL;
57141 +}
57142 +
57143 +static void
57144 +insert_subj_map_entry(struct subject_map *subjmap)
57145 +{
57146 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
57147 + struct subject_map **curr;
57148 +
57149 + subjmap->prev = NULL;
57150 +
57151 + curr = &subj_map_set.s_hash[index];
57152 + if (*curr != NULL)
57153 + (*curr)->prev = subjmap;
57154 +
57155 + subjmap->next = *curr;
57156 + *curr = subjmap;
57157 +
57158 + return;
57159 +}
57160 +
57161 +static struct acl_role_label *
57162 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
57163 + const gid_t gid)
57164 +{
57165 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
57166 + struct acl_role_label *match;
57167 + struct role_allowed_ip *ipp;
57168 + unsigned int x;
57169 + u32 curr_ip = task->signal->curr_ip;
57170 +
57171 + task->signal->saved_ip = curr_ip;
57172 +
57173 + match = acl_role_set.r_hash[index];
57174 +
57175 + while (match) {
57176 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
57177 + for (x = 0; x < match->domain_child_num; x++) {
57178 + if (match->domain_children[x] == uid)
57179 + goto found;
57180 + }
57181 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
57182 + break;
57183 + match = match->next;
57184 + }
57185 +found:
57186 + if (match == NULL) {
57187 + try_group:
57188 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
57189 + match = acl_role_set.r_hash[index];
57190 +
57191 + while (match) {
57192 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
57193 + for (x = 0; x < match->domain_child_num; x++) {
57194 + if (match->domain_children[x] == gid)
57195 + goto found2;
57196 + }
57197 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
57198 + break;
57199 + match = match->next;
57200 + }
57201 +found2:
57202 + if (match == NULL)
57203 + match = default_role;
57204 + if (match->allowed_ips == NULL)
57205 + return match;
57206 + else {
57207 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57208 + if (likely
57209 + ((ntohl(curr_ip) & ipp->netmask) ==
57210 + (ntohl(ipp->addr) & ipp->netmask)))
57211 + return match;
57212 + }
57213 + match = default_role;
57214 + }
57215 + } else if (match->allowed_ips == NULL) {
57216 + return match;
57217 + } else {
57218 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57219 + if (likely
57220 + ((ntohl(curr_ip) & ipp->netmask) ==
57221 + (ntohl(ipp->addr) & ipp->netmask)))
57222 + return match;
57223 + }
57224 + goto try_group;
57225 + }
57226 +
57227 + return match;
57228 +}
57229 +
57230 +struct acl_subject_label *
57231 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
57232 + const struct acl_role_label *role)
57233 +{
57234 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57235 + struct acl_subject_label *match;
57236 +
57237 + match = role->subj_hash[index];
57238 +
57239 + while (match && (match->inode != ino || match->device != dev ||
57240 + (match->mode & GR_DELETED))) {
57241 + match = match->next;
57242 + }
57243 +
57244 + if (match && !(match->mode & GR_DELETED))
57245 + return match;
57246 + else
57247 + return NULL;
57248 +}
57249 +
57250 +struct acl_subject_label *
57251 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
57252 + const struct acl_role_label *role)
57253 +{
57254 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57255 + struct acl_subject_label *match;
57256 +
57257 + match = role->subj_hash[index];
57258 +
57259 + while (match && (match->inode != ino || match->device != dev ||
57260 + !(match->mode & GR_DELETED))) {
57261 + match = match->next;
57262 + }
57263 +
57264 + if (match && (match->mode & GR_DELETED))
57265 + return match;
57266 + else
57267 + return NULL;
57268 +}
57269 +
57270 +static struct acl_object_label *
57271 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
57272 + const struct acl_subject_label *subj)
57273 +{
57274 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57275 + struct acl_object_label *match;
57276 +
57277 + match = subj->obj_hash[index];
57278 +
57279 + while (match && (match->inode != ino || match->device != dev ||
57280 + (match->mode & GR_DELETED))) {
57281 + match = match->next;
57282 + }
57283 +
57284 + if (match && !(match->mode & GR_DELETED))
57285 + return match;
57286 + else
57287 + return NULL;
57288 +}
57289 +
57290 +static struct acl_object_label *
57291 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
57292 + const struct acl_subject_label *subj)
57293 +{
57294 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57295 + struct acl_object_label *match;
57296 +
57297 + match = subj->obj_hash[index];
57298 +
57299 + while (match && (match->inode != ino || match->device != dev ||
57300 + !(match->mode & GR_DELETED))) {
57301 + match = match->next;
57302 + }
57303 +
57304 + if (match && (match->mode & GR_DELETED))
57305 + return match;
57306 +
57307 + match = subj->obj_hash[index];
57308 +
57309 + while (match && (match->inode != ino || match->device != dev ||
57310 + (match->mode & GR_DELETED))) {
57311 + match = match->next;
57312 + }
57313 +
57314 + if (match && !(match->mode & GR_DELETED))
57315 + return match;
57316 + else
57317 + return NULL;
57318 +}
57319 +
57320 +static struct name_entry *
57321 +lookup_name_entry(const char *name)
57322 +{
57323 + unsigned int len = strlen(name);
57324 + unsigned int key = full_name_hash(name, len);
57325 + unsigned int index = key % name_set.n_size;
57326 + struct name_entry *match;
57327 +
57328 + match = name_set.n_hash[index];
57329 +
57330 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
57331 + match = match->next;
57332 +
57333 + return match;
57334 +}
57335 +
57336 +static struct name_entry *
57337 +lookup_name_entry_create(const char *name)
57338 +{
57339 + unsigned int len = strlen(name);
57340 + unsigned int key = full_name_hash(name, len);
57341 + unsigned int index = key % name_set.n_size;
57342 + struct name_entry *match;
57343 +
57344 + match = name_set.n_hash[index];
57345 +
57346 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57347 + !match->deleted))
57348 + match = match->next;
57349 +
57350 + if (match && match->deleted)
57351 + return match;
57352 +
57353 + match = name_set.n_hash[index];
57354 +
57355 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57356 + match->deleted))
57357 + match = match->next;
57358 +
57359 + if (match && !match->deleted)
57360 + return match;
57361 + else
57362 + return NULL;
57363 +}
57364 +
57365 +static struct inodev_entry *
57366 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
57367 +{
57368 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
57369 + struct inodev_entry *match;
57370 +
57371 + match = inodev_set.i_hash[index];
57372 +
57373 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
57374 + match = match->next;
57375 +
57376 + return match;
57377 +}
57378 +
57379 +static void
57380 +insert_inodev_entry(struct inodev_entry *entry)
57381 +{
57382 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
57383 + inodev_set.i_size);
57384 + struct inodev_entry **curr;
57385 +
57386 + entry->prev = NULL;
57387 +
57388 + curr = &inodev_set.i_hash[index];
57389 + if (*curr != NULL)
57390 + (*curr)->prev = entry;
57391 +
57392 + entry->next = *curr;
57393 + *curr = entry;
57394 +
57395 + return;
57396 +}
57397 +
57398 +static void
57399 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
57400 +{
57401 + unsigned int index =
57402 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
57403 + struct acl_role_label **curr;
57404 + struct acl_role_label *tmp, *tmp2;
57405 +
57406 + curr = &acl_role_set.r_hash[index];
57407 +
57408 + /* simple case, slot is empty, just set it to our role */
57409 + if (*curr == NULL) {
57410 + *curr = role;
57411 + } else {
57412 + /* example:
57413 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
57414 + 2 -> 3
57415 + */
57416 + /* first check to see if we can already be reached via this slot */
57417 + tmp = *curr;
57418 + while (tmp && tmp != role)
57419 + tmp = tmp->next;
57420 + if (tmp == role) {
57421 + /* we don't need to add ourselves to this slot's chain */
57422 + return;
57423 + }
57424 + /* we need to add ourselves to this chain, two cases */
57425 + if (role->next == NULL) {
57426 + /* simple case, append the current chain to our role */
57427 + role->next = *curr;
57428 + *curr = role;
57429 + } else {
57430 + /* 1 -> 2 -> 3 -> 4
57431 + 2 -> 3 -> 4
57432 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
57433 + */
57434 + /* trickier case: walk our role's chain until we find
57435 + the role for the start of the current slot's chain */
57436 + tmp = role;
57437 + tmp2 = *curr;
57438 + while (tmp->next && tmp->next != tmp2)
57439 + tmp = tmp->next;
57440 + if (tmp->next == tmp2) {
57441 + /* from example above, we found 3, so just
57442 + replace this slot's chain with ours */
57443 + *curr = role;
57444 + } else {
57445 + /* we didn't find a subset of our role's chain
57446 + in the current slot's chain, so append their
57447 + chain to ours, and set us as the first role in
57448 + the slot's chain
57449 +
57450 + we could fold this case with the case above,
57451 + but making it explicit for clarity
57452 + */
57453 + tmp->next = tmp2;
57454 + *curr = role;
57455 + }
57456 + }
57457 + }
57458 +
57459 + return;
57460 +}
57461 +
57462 +static void
57463 +insert_acl_role_label(struct acl_role_label *role)
57464 +{
57465 + int i;
57466 +
57467 + if (role_list == NULL) {
57468 + role_list = role;
57469 + role->prev = NULL;
57470 + } else {
57471 + role->prev = role_list;
57472 + role_list = role;
57473 + }
57474 +
57475 + /* used for hash chains */
57476 + role->next = NULL;
57477 +
57478 + if (role->roletype & GR_ROLE_DOMAIN) {
57479 + for (i = 0; i < role->domain_child_num; i++)
57480 + __insert_acl_role_label(role, role->domain_children[i]);
57481 + } else
57482 + __insert_acl_role_label(role, role->uidgid);
57483 +}
57484 +
57485 +static int
57486 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
57487 +{
57488 + struct name_entry **curr, *nentry;
57489 + struct inodev_entry *ientry;
57490 + unsigned int len = strlen(name);
57491 + unsigned int key = full_name_hash(name, len);
57492 + unsigned int index = key % name_set.n_size;
57493 +
57494 + curr = &name_set.n_hash[index];
57495 +
57496 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
57497 + curr = &((*curr)->next);
57498 +
57499 + if (*curr != NULL)
57500 + return 1;
57501 +
57502 + nentry = acl_alloc(sizeof (struct name_entry));
57503 + if (nentry == NULL)
57504 + return 0;
57505 + ientry = acl_alloc(sizeof (struct inodev_entry));
57506 + if (ientry == NULL)
57507 + return 0;
57508 + ientry->nentry = nentry;
57509 +
57510 + nentry->key = key;
57511 + nentry->name = name;
57512 + nentry->inode = inode;
57513 + nentry->device = device;
57514 + nentry->len = len;
57515 + nentry->deleted = deleted;
57516 +
57517 + nentry->prev = NULL;
57518 + curr = &name_set.n_hash[index];
57519 + if (*curr != NULL)
57520 + (*curr)->prev = nentry;
57521 + nentry->next = *curr;
57522 + *curr = nentry;
57523 +
57524 + /* insert us into the table searchable by inode/dev */
57525 + insert_inodev_entry(ientry);
57526 +
57527 + return 1;
57528 +}
57529 +
57530 +static void
57531 +insert_acl_obj_label(struct acl_object_label *obj,
57532 + struct acl_subject_label *subj)
57533 +{
57534 + unsigned int index =
57535 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
57536 + struct acl_object_label **curr;
57537 +
57538 +
57539 + obj->prev = NULL;
57540 +
57541 + curr = &subj->obj_hash[index];
57542 + if (*curr != NULL)
57543 + (*curr)->prev = obj;
57544 +
57545 + obj->next = *curr;
57546 + *curr = obj;
57547 +
57548 + return;
57549 +}
57550 +
57551 +static void
57552 +insert_acl_subj_label(struct acl_subject_label *obj,
57553 + struct acl_role_label *role)
57554 +{
57555 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
57556 + struct acl_subject_label **curr;
57557 +
57558 + obj->prev = NULL;
57559 +
57560 + curr = &role->subj_hash[index];
57561 + if (*curr != NULL)
57562 + (*curr)->prev = obj;
57563 +
57564 + obj->next = *curr;
57565 + *curr = obj;
57566 +
57567 + return;
57568 +}
57569 +
57570 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
57571 +
57572 +static void *
57573 +create_table(__u32 * len, int elementsize)
57574 +{
57575 + unsigned int table_sizes[] = {
57576 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
57577 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
57578 + 4194301, 8388593, 16777213, 33554393, 67108859
57579 + };
57580 + void *newtable = NULL;
57581 + unsigned int pwr = 0;
57582 +
57583 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
57584 + table_sizes[pwr] <= *len)
57585 + pwr++;
57586 +
57587 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
57588 + return newtable;
57589 +
57590 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
57591 + newtable =
57592 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
57593 + else
57594 + newtable = vmalloc(table_sizes[pwr] * elementsize);
57595 +
57596 + *len = table_sizes[pwr];
57597 +
57598 + return newtable;
57599 +}
57600 +
57601 +static int
57602 +init_variables(const struct gr_arg *arg)
57603 +{
57604 + struct task_struct *reaper = init_pid_ns.child_reaper;
57605 + unsigned int stacksize;
57606 +
57607 + subj_map_set.s_size = arg->role_db.num_subjects;
57608 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
57609 + name_set.n_size = arg->role_db.num_objects;
57610 + inodev_set.i_size = arg->role_db.num_objects;
57611 +
57612 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
57613 + !name_set.n_size || !inodev_set.i_size)
57614 + return 1;
57615 +
57616 + if (!gr_init_uidset())
57617 + return 1;
57618 +
57619 + /* set up the stack that holds allocation info */
57620 +
57621 + stacksize = arg->role_db.num_pointers + 5;
57622 +
57623 + if (!acl_alloc_stack_init(stacksize))
57624 + return 1;
57625 +
57626 + /* grab reference for the real root dentry and vfsmount */
57627 + get_fs_root(reaper->fs, &real_root);
57628 +
57629 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57630 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
57631 +#endif
57632 +
57633 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
57634 + if (fakefs_obj_rw == NULL)
57635 + return 1;
57636 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
57637 +
57638 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
57639 + if (fakefs_obj_rwx == NULL)
57640 + return 1;
57641 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
57642 +
57643 + subj_map_set.s_hash =
57644 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
57645 + acl_role_set.r_hash =
57646 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
57647 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
57648 + inodev_set.i_hash =
57649 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
57650 +
57651 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
57652 + !name_set.n_hash || !inodev_set.i_hash)
57653 + return 1;
57654 +
57655 + memset(subj_map_set.s_hash, 0,
57656 + sizeof(struct subject_map *) * subj_map_set.s_size);
57657 + memset(acl_role_set.r_hash, 0,
57658 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
57659 + memset(name_set.n_hash, 0,
57660 + sizeof (struct name_entry *) * name_set.n_size);
57661 + memset(inodev_set.i_hash, 0,
57662 + sizeof (struct inodev_entry *) * inodev_set.i_size);
57663 +
57664 + return 0;
57665 +}
57666 +
57667 +/* free information not needed after startup
57668 + currently contains user->kernel pointer mappings for subjects
57669 +*/
57670 +
57671 +static void
57672 +free_init_variables(void)
57673 +{
57674 + __u32 i;
57675 +
57676 + if (subj_map_set.s_hash) {
57677 + for (i = 0; i < subj_map_set.s_size; i++) {
57678 + if (subj_map_set.s_hash[i]) {
57679 + kfree(subj_map_set.s_hash[i]);
57680 + subj_map_set.s_hash[i] = NULL;
57681 + }
57682 + }
57683 +
57684 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
57685 + PAGE_SIZE)
57686 + kfree(subj_map_set.s_hash);
57687 + else
57688 + vfree(subj_map_set.s_hash);
57689 + }
57690 +
57691 + return;
57692 +}
57693 +
57694 +static void
57695 +free_variables(void)
57696 +{
57697 + struct acl_subject_label *s;
57698 + struct acl_role_label *r;
57699 + struct task_struct *task, *task2;
57700 + unsigned int x;
57701 +
57702 + gr_clear_learn_entries();
57703 +
57704 + read_lock(&tasklist_lock);
57705 + do_each_thread(task2, task) {
57706 + task->acl_sp_role = 0;
57707 + task->acl_role_id = 0;
57708 + task->acl = NULL;
57709 + task->role = NULL;
57710 + } while_each_thread(task2, task);
57711 + read_unlock(&tasklist_lock);
57712 +
57713 + /* release the reference to the real root dentry and vfsmount */
57714 + path_put(&real_root);
57715 + memset(&real_root, 0, sizeof(real_root));
57716 +
57717 + /* free all object hash tables */
57718 +
57719 + FOR_EACH_ROLE_START(r)
57720 + if (r->subj_hash == NULL)
57721 + goto next_role;
57722 + FOR_EACH_SUBJECT_START(r, s, x)
57723 + if (s->obj_hash == NULL)
57724 + break;
57725 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
57726 + kfree(s->obj_hash);
57727 + else
57728 + vfree(s->obj_hash);
57729 + FOR_EACH_SUBJECT_END(s, x)
57730 + FOR_EACH_NESTED_SUBJECT_START(r, s)
57731 + if (s->obj_hash == NULL)
57732 + break;
57733 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
57734 + kfree(s->obj_hash);
57735 + else
57736 + vfree(s->obj_hash);
57737 + FOR_EACH_NESTED_SUBJECT_END(s)
57738 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
57739 + kfree(r->subj_hash);
57740 + else
57741 + vfree(r->subj_hash);
57742 + r->subj_hash = NULL;
57743 +next_role:
57744 + FOR_EACH_ROLE_END(r)
57745 +
57746 + acl_free_all();
57747 +
57748 + if (acl_role_set.r_hash) {
57749 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
57750 + PAGE_SIZE)
57751 + kfree(acl_role_set.r_hash);
57752 + else
57753 + vfree(acl_role_set.r_hash);
57754 + }
57755 + if (name_set.n_hash) {
57756 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
57757 + PAGE_SIZE)
57758 + kfree(name_set.n_hash);
57759 + else
57760 + vfree(name_set.n_hash);
57761 + }
57762 +
57763 + if (inodev_set.i_hash) {
57764 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
57765 + PAGE_SIZE)
57766 + kfree(inodev_set.i_hash);
57767 + else
57768 + vfree(inodev_set.i_hash);
57769 + }
57770 +
57771 + gr_free_uidset();
57772 +
57773 + memset(&name_set, 0, sizeof (struct name_db));
57774 + memset(&inodev_set, 0, sizeof (struct inodev_db));
57775 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
57776 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
57777 +
57778 + default_role = NULL;
57779 + kernel_role = NULL;
57780 + role_list = NULL;
57781 +
57782 + return;
57783 +}
57784 +
57785 +static __u32
57786 +count_user_objs(struct acl_object_label *userp)
57787 +{
57788 + struct acl_object_label o_tmp;
57789 + __u32 num = 0;
57790 +
57791 + while (userp) {
57792 + if (copy_from_user(&o_tmp, userp,
57793 + sizeof (struct acl_object_label)))
57794 + break;
57795 +
57796 + userp = o_tmp.prev;
57797 + num++;
57798 + }
57799 +
57800 + return num;
57801 +}
57802 +
57803 +static struct acl_subject_label *
57804 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
57805 +
57806 +static int
57807 +copy_user_glob(struct acl_object_label *obj)
57808 +{
57809 + struct acl_object_label *g_tmp, **guser;
57810 + unsigned int len;
57811 + char *tmp;
57812 +
57813 + if (obj->globbed == NULL)
57814 + return 0;
57815 +
57816 + guser = &obj->globbed;
57817 + while (*guser) {
57818 + g_tmp = (struct acl_object_label *)
57819 + acl_alloc(sizeof (struct acl_object_label));
57820 + if (g_tmp == NULL)
57821 + return -ENOMEM;
57822 +
57823 + if (copy_from_user(g_tmp, *guser,
57824 + sizeof (struct acl_object_label)))
57825 + return -EFAULT;
57826 +
57827 + len = strnlen_user(g_tmp->filename, PATH_MAX);
57828 +
57829 + if (!len || len >= PATH_MAX)
57830 + return -EINVAL;
57831 +
57832 + if ((tmp = (char *) acl_alloc(len)) == NULL)
57833 + return -ENOMEM;
57834 +
57835 + if (copy_from_user(tmp, g_tmp->filename, len))
57836 + return -EFAULT;
57837 + tmp[len-1] = '\0';
57838 + g_tmp->filename = tmp;
57839 +
57840 + *guser = g_tmp;
57841 + guser = &(g_tmp->next);
57842 + }
57843 +
57844 + return 0;
57845 +}
57846 +
57847 +static int
57848 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
57849 + struct acl_role_label *role)
57850 +{
57851 + struct acl_object_label *o_tmp;
57852 + unsigned int len;
57853 + int ret;
57854 + char *tmp;
57855 +
57856 + while (userp) {
57857 + if ((o_tmp = (struct acl_object_label *)
57858 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
57859 + return -ENOMEM;
57860 +
57861 + if (copy_from_user(o_tmp, userp,
57862 + sizeof (struct acl_object_label)))
57863 + return -EFAULT;
57864 +
57865 + userp = o_tmp->prev;
57866 +
57867 + len = strnlen_user(o_tmp->filename, PATH_MAX);
57868 +
57869 + if (!len || len >= PATH_MAX)
57870 + return -EINVAL;
57871 +
57872 + if ((tmp = (char *) acl_alloc(len)) == NULL)
57873 + return -ENOMEM;
57874 +
57875 + if (copy_from_user(tmp, o_tmp->filename, len))
57876 + return -EFAULT;
57877 + tmp[len-1] = '\0';
57878 + o_tmp->filename = tmp;
57879 +
57880 + insert_acl_obj_label(o_tmp, subj);
57881 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
57882 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
57883 + return -ENOMEM;
57884 +
57885 + ret = copy_user_glob(o_tmp);
57886 + if (ret)
57887 + return ret;
57888 +
57889 + if (o_tmp->nested) {
57890 + int already_copied;
57891 +
57892 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
57893 + if (IS_ERR(o_tmp->nested))
57894 + return PTR_ERR(o_tmp->nested);
57895 +
57896 + /* insert into nested subject list if we haven't copied this one yet
57897 + to prevent duplicate entries */
57898 + if (!already_copied) {
57899 + o_tmp->nested->next = role->hash->first;
57900 + role->hash->first = o_tmp->nested;
57901 + }
57902 + }
57903 + }
57904 +
57905 + return 0;
57906 +}
57907 +
57908 +static __u32
57909 +count_user_subjs(struct acl_subject_label *userp)
57910 +{
57911 + struct acl_subject_label s_tmp;
57912 + __u32 num = 0;
57913 +
57914 + while (userp) {
57915 + if (copy_from_user(&s_tmp, userp,
57916 + sizeof (struct acl_subject_label)))
57917 + break;
57918 +
57919 + userp = s_tmp.prev;
57920 + }
57921 +
57922 + return num;
57923 +}
57924 +
57925 +static int
57926 +copy_user_allowedips(struct acl_role_label *rolep)
57927 +{
57928 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
57929 +
57930 + ruserip = rolep->allowed_ips;
57931 +
57932 + while (ruserip) {
57933 + rlast = rtmp;
57934 +
57935 + if ((rtmp = (struct role_allowed_ip *)
57936 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
57937 + return -ENOMEM;
57938 +
57939 + if (copy_from_user(rtmp, ruserip,
57940 + sizeof (struct role_allowed_ip)))
57941 + return -EFAULT;
57942 +
57943 + ruserip = rtmp->prev;
57944 +
57945 + if (!rlast) {
57946 + rtmp->prev = NULL;
57947 + rolep->allowed_ips = rtmp;
57948 + } else {
57949 + rlast->next = rtmp;
57950 + rtmp->prev = rlast;
57951 + }
57952 +
57953 + if (!ruserip)
57954 + rtmp->next = NULL;
57955 + }
57956 +
57957 + return 0;
57958 +}
57959 +
57960 +static int
57961 +copy_user_transitions(struct acl_role_label *rolep)
57962 +{
57963 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
57964 +
57965 + unsigned int len;
57966 + char *tmp;
57967 +
57968 + rusertp = rolep->transitions;
57969 +
57970 + while (rusertp) {
57971 + rlast = rtmp;
57972 +
57973 + if ((rtmp = (struct role_transition *)
57974 + acl_alloc(sizeof (struct role_transition))) == NULL)
57975 + return -ENOMEM;
57976 +
57977 + if (copy_from_user(rtmp, rusertp,
57978 + sizeof (struct role_transition)))
57979 + return -EFAULT;
57980 +
57981 + rusertp = rtmp->prev;
57982 +
57983 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
57984 +
57985 + if (!len || len >= GR_SPROLE_LEN)
57986 + return -EINVAL;
57987 +
57988 + if ((tmp = (char *) acl_alloc(len)) == NULL)
57989 + return -ENOMEM;
57990 +
57991 + if (copy_from_user(tmp, rtmp->rolename, len))
57992 + return -EFAULT;
57993 + tmp[len-1] = '\0';
57994 + rtmp->rolename = tmp;
57995 +
57996 + if (!rlast) {
57997 + rtmp->prev = NULL;
57998 + rolep->transitions = rtmp;
57999 + } else {
58000 + rlast->next = rtmp;
58001 + rtmp->prev = rlast;
58002 + }
58003 +
58004 + if (!rusertp)
58005 + rtmp->next = NULL;
58006 + }
58007 +
58008 + return 0;
58009 +}
58010 +
58011 +static struct acl_subject_label *
58012 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
58013 +{
58014 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
58015 + unsigned int len;
58016 + char *tmp;
58017 + __u32 num_objs;
58018 + struct acl_ip_label **i_tmp, *i_utmp2;
58019 + struct gr_hash_struct ghash;
58020 + struct subject_map *subjmap;
58021 + unsigned int i_num;
58022 + int err;
58023 +
58024 + if (already_copied != NULL)
58025 + *already_copied = 0;
58026 +
58027 + s_tmp = lookup_subject_map(userp);
58028 +
58029 + /* we've already copied this subject into the kernel, just return
58030 + the reference to it, and don't copy it over again
58031 + */
58032 + if (s_tmp) {
58033 + if (already_copied != NULL)
58034 + *already_copied = 1;
58035 + return(s_tmp);
58036 + }
58037 +
58038 + if ((s_tmp = (struct acl_subject_label *)
58039 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
58040 + return ERR_PTR(-ENOMEM);
58041 +
58042 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
58043 + if (subjmap == NULL)
58044 + return ERR_PTR(-ENOMEM);
58045 +
58046 + subjmap->user = userp;
58047 + subjmap->kernel = s_tmp;
58048 + insert_subj_map_entry(subjmap);
58049 +
58050 + if (copy_from_user(s_tmp, userp,
58051 + sizeof (struct acl_subject_label)))
58052 + return ERR_PTR(-EFAULT);
58053 +
58054 + len = strnlen_user(s_tmp->filename, PATH_MAX);
58055 +
58056 + if (!len || len >= PATH_MAX)
58057 + return ERR_PTR(-EINVAL);
58058 +
58059 + if ((tmp = (char *) acl_alloc(len)) == NULL)
58060 + return ERR_PTR(-ENOMEM);
58061 +
58062 + if (copy_from_user(tmp, s_tmp->filename, len))
58063 + return ERR_PTR(-EFAULT);
58064 + tmp[len-1] = '\0';
58065 + s_tmp->filename = tmp;
58066 +
58067 + if (!strcmp(s_tmp->filename, "/"))
58068 + role->root_label = s_tmp;
58069 +
58070 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
58071 + return ERR_PTR(-EFAULT);
58072 +
58073 + /* copy user and group transition tables */
58074 +
58075 + if (s_tmp->user_trans_num) {
58076 + uid_t *uidlist;
58077 +
58078 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
58079 + if (uidlist == NULL)
58080 + return ERR_PTR(-ENOMEM);
58081 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
58082 + return ERR_PTR(-EFAULT);
58083 +
58084 + s_tmp->user_transitions = uidlist;
58085 + }
58086 +
58087 + if (s_tmp->group_trans_num) {
58088 + gid_t *gidlist;
58089 +
58090 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
58091 + if (gidlist == NULL)
58092 + return ERR_PTR(-ENOMEM);
58093 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
58094 + return ERR_PTR(-EFAULT);
58095 +
58096 + s_tmp->group_transitions = gidlist;
58097 + }
58098 +
58099 + /* set up object hash table */
58100 + num_objs = count_user_objs(ghash.first);
58101 +
58102 + s_tmp->obj_hash_size = num_objs;
58103 + s_tmp->obj_hash =
58104 + (struct acl_object_label **)
58105 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
58106 +
58107 + if (!s_tmp->obj_hash)
58108 + return ERR_PTR(-ENOMEM);
58109 +
58110 + memset(s_tmp->obj_hash, 0,
58111 + s_tmp->obj_hash_size *
58112 + sizeof (struct acl_object_label *));
58113 +
58114 + /* add in objects */
58115 + err = copy_user_objs(ghash.first, s_tmp, role);
58116 +
58117 + if (err)
58118 + return ERR_PTR(err);
58119 +
58120 + /* set pointer for parent subject */
58121 + if (s_tmp->parent_subject) {
58122 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
58123 +
58124 + if (IS_ERR(s_tmp2))
58125 + return s_tmp2;
58126 +
58127 + s_tmp->parent_subject = s_tmp2;
58128 + }
58129 +
58130 + /* add in ip acls */
58131 +
58132 + if (!s_tmp->ip_num) {
58133 + s_tmp->ips = NULL;
58134 + goto insert;
58135 + }
58136 +
58137 + i_tmp =
58138 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
58139 + sizeof (struct acl_ip_label *));
58140 +
58141 + if (!i_tmp)
58142 + return ERR_PTR(-ENOMEM);
58143 +
58144 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
58145 + *(i_tmp + i_num) =
58146 + (struct acl_ip_label *)
58147 + acl_alloc(sizeof (struct acl_ip_label));
58148 + if (!*(i_tmp + i_num))
58149 + return ERR_PTR(-ENOMEM);
58150 +
58151 + if (copy_from_user
58152 + (&i_utmp2, s_tmp->ips + i_num,
58153 + sizeof (struct acl_ip_label *)))
58154 + return ERR_PTR(-EFAULT);
58155 +
58156 + if (copy_from_user
58157 + (*(i_tmp + i_num), i_utmp2,
58158 + sizeof (struct acl_ip_label)))
58159 + return ERR_PTR(-EFAULT);
58160 +
58161 + if ((*(i_tmp + i_num))->iface == NULL)
58162 + continue;
58163 +
58164 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
58165 + if (!len || len >= IFNAMSIZ)
58166 + return ERR_PTR(-EINVAL);
58167 + tmp = acl_alloc(len);
58168 + if (tmp == NULL)
58169 + return ERR_PTR(-ENOMEM);
58170 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
58171 + return ERR_PTR(-EFAULT);
58172 + (*(i_tmp + i_num))->iface = tmp;
58173 + }
58174 +
58175 + s_tmp->ips = i_tmp;
58176 +
58177 +insert:
58178 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
58179 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
58180 + return ERR_PTR(-ENOMEM);
58181 +
58182 + return s_tmp;
58183 +}
58184 +
58185 +static int
58186 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
58187 +{
58188 + struct acl_subject_label s_pre;
58189 + struct acl_subject_label * ret;
58190 + int err;
58191 +
58192 + while (userp) {
58193 + if (copy_from_user(&s_pre, userp,
58194 + sizeof (struct acl_subject_label)))
58195 + return -EFAULT;
58196 +
58197 + ret = do_copy_user_subj(userp, role, NULL);
58198 +
58199 + err = PTR_ERR(ret);
58200 + if (IS_ERR(ret))
58201 + return err;
58202 +
58203 + insert_acl_subj_label(ret, role);
58204 +
58205 + userp = s_pre.prev;
58206 + }
58207 +
58208 + return 0;
58209 +}
58210 +
58211 +static int
58212 +copy_user_acl(struct gr_arg *arg)
58213 +{
58214 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
58215 + struct acl_subject_label *subj_list;
58216 + struct sprole_pw *sptmp;
58217 + struct gr_hash_struct *ghash;
58218 + uid_t *domainlist;
58219 + unsigned int r_num;
58220 + unsigned int len;
58221 + char *tmp;
58222 + int err = 0;
58223 + __u16 i;
58224 + __u32 num_subjs;
58225 +
58226 + /* we need a default and kernel role */
58227 + if (arg->role_db.num_roles < 2)
58228 + return -EINVAL;
58229 +
58230 + /* copy special role authentication info from userspace */
58231 +
58232 + num_sprole_pws = arg->num_sprole_pws;
58233 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
58234 +
58235 + if (!acl_special_roles && num_sprole_pws)
58236 + return -ENOMEM;
58237 +
58238 + for (i = 0; i < num_sprole_pws; i++) {
58239 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
58240 + if (!sptmp)
58241 + return -ENOMEM;
58242 + if (copy_from_user(sptmp, arg->sprole_pws + i,
58243 + sizeof (struct sprole_pw)))
58244 + return -EFAULT;
58245 +
58246 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
58247 +
58248 + if (!len || len >= GR_SPROLE_LEN)
58249 + return -EINVAL;
58250 +
58251 + if ((tmp = (char *) acl_alloc(len)) == NULL)
58252 + return -ENOMEM;
58253 +
58254 + if (copy_from_user(tmp, sptmp->rolename, len))
58255 + return -EFAULT;
58256 +
58257 + tmp[len-1] = '\0';
58258 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58259 + printk(KERN_ALERT "Copying special role %s\n", tmp);
58260 +#endif
58261 + sptmp->rolename = tmp;
58262 + acl_special_roles[i] = sptmp;
58263 + }
58264 +
58265 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
58266 +
58267 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
58268 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
58269 +
58270 + if (!r_tmp)
58271 + return -ENOMEM;
58272 +
58273 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
58274 + sizeof (struct acl_role_label *)))
58275 + return -EFAULT;
58276 +
58277 + if (copy_from_user(r_tmp, r_utmp2,
58278 + sizeof (struct acl_role_label)))
58279 + return -EFAULT;
58280 +
58281 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
58282 +
58283 + if (!len || len >= PATH_MAX)
58284 + return -EINVAL;
58285 +
58286 + if ((tmp = (char *) acl_alloc(len)) == NULL)
58287 + return -ENOMEM;
58288 +
58289 + if (copy_from_user(tmp, r_tmp->rolename, len))
58290 + return -EFAULT;
58291 +
58292 + tmp[len-1] = '\0';
58293 + r_tmp->rolename = tmp;
58294 +
58295 + if (!strcmp(r_tmp->rolename, "default")
58296 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
58297 + default_role = r_tmp;
58298 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
58299 + kernel_role = r_tmp;
58300 + }
58301 +
58302 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
58303 + return -ENOMEM;
58304 +
58305 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
58306 + return -EFAULT;
58307 +
58308 + r_tmp->hash = ghash;
58309 +
58310 + num_subjs = count_user_subjs(r_tmp->hash->first);
58311 +
58312 + r_tmp->subj_hash_size = num_subjs;
58313 + r_tmp->subj_hash =
58314 + (struct acl_subject_label **)
58315 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
58316 +
58317 + if (!r_tmp->subj_hash)
58318 + return -ENOMEM;
58319 +
58320 + err = copy_user_allowedips(r_tmp);
58321 + if (err)
58322 + return err;
58323 +
58324 + /* copy domain info */
58325 + if (r_tmp->domain_children != NULL) {
58326 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
58327 + if (domainlist == NULL)
58328 + return -ENOMEM;
58329 +
58330 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
58331 + return -EFAULT;
58332 +
58333 + r_tmp->domain_children = domainlist;
58334 + }
58335 +
58336 + err = copy_user_transitions(r_tmp);
58337 + if (err)
58338 + return err;
58339 +
58340 + memset(r_tmp->subj_hash, 0,
58341 + r_tmp->subj_hash_size *
58342 + sizeof (struct acl_subject_label *));
58343 +
58344 + /* acquire the list of subjects, then NULL out
58345 + the list prior to parsing the subjects for this role,
58346 + as during this parsing the list is replaced with a list
58347 + of *nested* subjects for the role
58348 + */
58349 + subj_list = r_tmp->hash->first;
58350 +
58351 + /* set nested subject list to null */
58352 + r_tmp->hash->first = NULL;
58353 +
58354 + err = copy_user_subjs(subj_list, r_tmp);
58355 +
58356 + if (err)
58357 + return err;
58358 +
58359 + insert_acl_role_label(r_tmp);
58360 + }
58361 +
58362 + if (default_role == NULL || kernel_role == NULL)
58363 + return -EINVAL;
58364 +
58365 + return err;
58366 +}
58367 +
58368 +static int
58369 +gracl_init(struct gr_arg *args)
58370 +{
58371 + int error = 0;
58372 +
58373 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
58374 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
58375 +
58376 + if (init_variables(args)) {
58377 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
58378 + error = -ENOMEM;
58379 + free_variables();
58380 + goto out;
58381 + }
58382 +
58383 + error = copy_user_acl(args);
58384 + free_init_variables();
58385 + if (error) {
58386 + free_variables();
58387 + goto out;
58388 + }
58389 +
58390 + if ((error = gr_set_acls(0))) {
58391 + free_variables();
58392 + goto out;
58393 + }
58394 +
58395 + pax_open_kernel();
58396 + gr_status |= GR_READY;
58397 + pax_close_kernel();
58398 +
58399 + out:
58400 + return error;
58401 +}
58402 +
58403 +/* derived from glibc fnmatch() 0: match, 1: no match*/
58404 +
58405 +static int
58406 +glob_match(const char *p, const char *n)
58407 +{
58408 + char c;
58409 +
58410 + while ((c = *p++) != '\0') {
58411 + switch (c) {
58412 + case '?':
58413 + if (*n == '\0')
58414 + return 1;
58415 + else if (*n == '/')
58416 + return 1;
58417 + break;
58418 + case '\\':
58419 + if (*n != c)
58420 + return 1;
58421 + break;
58422 + case '*':
58423 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
58424 + if (*n == '/')
58425 + return 1;
58426 + else if (c == '?') {
58427 + if (*n == '\0')
58428 + return 1;
58429 + else
58430 + ++n;
58431 + }
58432 + }
58433 + if (c == '\0') {
58434 + return 0;
58435 + } else {
58436 + const char *endp;
58437 +
58438 + if ((endp = strchr(n, '/')) == NULL)
58439 + endp = n + strlen(n);
58440 +
58441 + if (c == '[') {
58442 + for (--p; n < endp; ++n)
58443 + if (!glob_match(p, n))
58444 + return 0;
58445 + } else if (c == '/') {
58446 + while (*n != '\0' && *n != '/')
58447 + ++n;
58448 + if (*n == '/' && !glob_match(p, n + 1))
58449 + return 0;
58450 + } else {
58451 + for (--p; n < endp; ++n)
58452 + if (*n == c && !glob_match(p, n))
58453 + return 0;
58454 + }
58455 +
58456 + return 1;
58457 + }
58458 + case '[':
58459 + {
58460 + int not;
58461 + char cold;
58462 +
58463 + if (*n == '\0' || *n == '/')
58464 + return 1;
58465 +
58466 + not = (*p == '!' || *p == '^');
58467 + if (not)
58468 + ++p;
58469 +
58470 + c = *p++;
58471 + for (;;) {
58472 + unsigned char fn = (unsigned char)*n;
58473 +
58474 + if (c == '\0')
58475 + return 1;
58476 + else {
58477 + if (c == fn)
58478 + goto matched;
58479 + cold = c;
58480 + c = *p++;
58481 +
58482 + if (c == '-' && *p != ']') {
58483 + unsigned char cend = *p++;
58484 +
58485 + if (cend == '\0')
58486 + return 1;
58487 +
58488 + if (cold <= fn && fn <= cend)
58489 + goto matched;
58490 +
58491 + c = *p++;
58492 + }
58493 + }
58494 +
58495 + if (c == ']')
58496 + break;
58497 + }
58498 + if (!not)
58499 + return 1;
58500 + break;
58501 + matched:
58502 + while (c != ']') {
58503 + if (c == '\0')
58504 + return 1;
58505 +
58506 + c = *p++;
58507 + }
58508 + if (not)
58509 + return 1;
58510 + }
58511 + break;
58512 + default:
58513 + if (c != *n)
58514 + return 1;
58515 + }
58516 +
58517 + ++n;
58518 + }
58519 +
58520 + if (*n == '\0')
58521 + return 0;
58522 +
58523 + if (*n == '/')
58524 + return 0;
58525 +
58526 + return 1;
58527 +}
58528 +
58529 +static struct acl_object_label *
58530 +chk_glob_label(struct acl_object_label *globbed,
58531 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
58532 +{
58533 + struct acl_object_label *tmp;
58534 +
58535 + if (*path == NULL)
58536 + *path = gr_to_filename_nolock(dentry, mnt);
58537 +
58538 + tmp = globbed;
58539 +
58540 + while (tmp) {
58541 + if (!glob_match(tmp->filename, *path))
58542 + return tmp;
58543 + tmp = tmp->next;
58544 + }
58545 +
58546 + return NULL;
58547 +}
58548 +
58549 +static struct acl_object_label *
58550 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
58551 + const ino_t curr_ino, const dev_t curr_dev,
58552 + const struct acl_subject_label *subj, char **path, const int checkglob)
58553 +{
58554 + struct acl_subject_label *tmpsubj;
58555 + struct acl_object_label *retval;
58556 + struct acl_object_label *retval2;
58557 +
58558 + tmpsubj = (struct acl_subject_label *) subj;
58559 + read_lock(&gr_inode_lock);
58560 + do {
58561 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
58562 + if (retval) {
58563 + if (checkglob && retval->globbed) {
58564 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
58565 + if (retval2)
58566 + retval = retval2;
58567 + }
58568 + break;
58569 + }
58570 + } while ((tmpsubj = tmpsubj->parent_subject));
58571 + read_unlock(&gr_inode_lock);
58572 +
58573 + return retval;
58574 +}
58575 +
58576 +static __inline__ struct acl_object_label *
58577 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
58578 + struct dentry *curr_dentry,
58579 + const struct acl_subject_label *subj, char **path, const int checkglob)
58580 +{
58581 + int newglob = checkglob;
58582 + ino_t inode;
58583 + dev_t device;
58584 +
58585 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
58586 + as we don't want a / * rule to match instead of the / object
58587 + don't do this for create lookups that call this function though, since they're looking up
58588 + on the parent and thus need globbing checks on all paths
58589 + */
58590 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
58591 + newglob = GR_NO_GLOB;
58592 +
58593 + spin_lock(&curr_dentry->d_lock);
58594 + inode = curr_dentry->d_inode->i_ino;
58595 + device = __get_dev(curr_dentry);
58596 + spin_unlock(&curr_dentry->d_lock);
58597 +
58598 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
58599 +}
58600 +
58601 +#ifdef CONFIG_HUGETLBFS
58602 +static inline bool
58603 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
58604 +{
58605 + int i;
58606 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
58607 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
58608 + return true;
58609 + }
58610 +
58611 + return false;
58612 +}
58613 +#endif
58614 +
58615 +static struct acl_object_label *
58616 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58617 + const struct acl_subject_label *subj, char *path, const int checkglob)
58618 +{
58619 + struct dentry *dentry = (struct dentry *) l_dentry;
58620 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
58621 + struct mount *real_mnt = real_mount(mnt);
58622 + struct acl_object_label *retval;
58623 + struct dentry *parent;
58624 +
58625 + write_seqlock(&rename_lock);
58626 + br_read_lock(&vfsmount_lock);
58627 +
58628 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
58629 +#ifdef CONFIG_NET
58630 + mnt == sock_mnt ||
58631 +#endif
58632 +#ifdef CONFIG_HUGETLBFS
58633 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
58634 +#endif
58635 + /* ignore Eric Biederman */
58636 + IS_PRIVATE(l_dentry->d_inode))) {
58637 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
58638 + goto out;
58639 + }
58640 +
58641 + for (;;) {
58642 + if (dentry == real_root.dentry && mnt == real_root.mnt)
58643 + break;
58644 +
58645 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
58646 + if (!mnt_has_parent(real_mnt))
58647 + break;
58648 +
58649 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58650 + if (retval != NULL)
58651 + goto out;
58652 +
58653 + dentry = real_mnt->mnt_mountpoint;
58654 + real_mnt = real_mnt->mnt_parent;
58655 + mnt = &real_mnt->mnt;
58656 + continue;
58657 + }
58658 +
58659 + parent = dentry->d_parent;
58660 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58661 + if (retval != NULL)
58662 + goto out;
58663 +
58664 + dentry = parent;
58665 + }
58666 +
58667 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58668 +
58669 + /* real_root is pinned so we don't have to hold a reference */
58670 + if (retval == NULL)
58671 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
58672 +out:
58673 + br_read_unlock(&vfsmount_lock);
58674 + write_sequnlock(&rename_lock);
58675 +
58676 + BUG_ON(retval == NULL);
58677 +
58678 + return retval;
58679 +}
58680 +
58681 +static __inline__ struct acl_object_label *
58682 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58683 + const struct acl_subject_label *subj)
58684 +{
58685 + char *path = NULL;
58686 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
58687 +}
58688 +
58689 +static __inline__ struct acl_object_label *
58690 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58691 + const struct acl_subject_label *subj)
58692 +{
58693 + char *path = NULL;
58694 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
58695 +}
58696 +
58697 +static __inline__ struct acl_object_label *
58698 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58699 + const struct acl_subject_label *subj, char *path)
58700 +{
58701 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
58702 +}
58703 +
58704 +static struct acl_subject_label *
58705 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58706 + const struct acl_role_label *role)
58707 +{
58708 + struct dentry *dentry = (struct dentry *) l_dentry;
58709 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
58710 + struct mount *real_mnt = real_mount(mnt);
58711 + struct acl_subject_label *retval;
58712 + struct dentry *parent;
58713 +
58714 + write_seqlock(&rename_lock);
58715 + br_read_lock(&vfsmount_lock);
58716 +
58717 + for (;;) {
58718 + if (dentry == real_root.dentry && mnt == real_root.mnt)
58719 + break;
58720 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
58721 + if (!mnt_has_parent(real_mnt))
58722 + break;
58723 +
58724 + spin_lock(&dentry->d_lock);
58725 + read_lock(&gr_inode_lock);
58726 + retval =
58727 + lookup_acl_subj_label(dentry->d_inode->i_ino,
58728 + __get_dev(dentry), role);
58729 + read_unlock(&gr_inode_lock);
58730 + spin_unlock(&dentry->d_lock);
58731 + if (retval != NULL)
58732 + goto out;
58733 +
58734 + dentry = real_mnt->mnt_mountpoint;
58735 + real_mnt = real_mnt->mnt_parent;
58736 + mnt = &real_mnt->mnt;
58737 + continue;
58738 + }
58739 +
58740 + spin_lock(&dentry->d_lock);
58741 + read_lock(&gr_inode_lock);
58742 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
58743 + __get_dev(dentry), role);
58744 + read_unlock(&gr_inode_lock);
58745 + parent = dentry->d_parent;
58746 + spin_unlock(&dentry->d_lock);
58747 +
58748 + if (retval != NULL)
58749 + goto out;
58750 +
58751 + dentry = parent;
58752 + }
58753 +
58754 + spin_lock(&dentry->d_lock);
58755 + read_lock(&gr_inode_lock);
58756 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
58757 + __get_dev(dentry), role);
58758 + read_unlock(&gr_inode_lock);
58759 + spin_unlock(&dentry->d_lock);
58760 +
58761 + if (unlikely(retval == NULL)) {
58762 + /* real_root is pinned, we don't need to hold a reference */
58763 + read_lock(&gr_inode_lock);
58764 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
58765 + __get_dev(real_root.dentry), role);
58766 + read_unlock(&gr_inode_lock);
58767 + }
58768 +out:
58769 + br_read_unlock(&vfsmount_lock);
58770 + write_sequnlock(&rename_lock);
58771 +
58772 + BUG_ON(retval == NULL);
58773 +
58774 + return retval;
58775 +}
58776 +
58777 +static void
58778 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
58779 +{
58780 + struct task_struct *task = current;
58781 + const struct cred *cred = current_cred();
58782 +
58783 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
58784 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58785 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58786 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
58787 +
58788 + return;
58789 +}
58790 +
58791 +static void
58792 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
58793 +{
58794 + struct task_struct *task = current;
58795 + const struct cred *cred = current_cred();
58796 +
58797 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
58798 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58799 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58800 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
58801 +
58802 + return;
58803 +}
58804 +
58805 +static void
58806 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
58807 +{
58808 + struct task_struct *task = current;
58809 + const struct cred *cred = current_cred();
58810 +
58811 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
58812 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58813 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58814 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
58815 +
58816 + return;
58817 +}
58818 +
58819 +__u32
58820 +gr_search_file(const struct dentry * dentry, const __u32 mode,
58821 + const struct vfsmount * mnt)
58822 +{
58823 + __u32 retval = mode;
58824 + struct acl_subject_label *curracl;
58825 + struct acl_object_label *currobj;
58826 +
58827 + if (unlikely(!(gr_status & GR_READY)))
58828 + return (mode & ~GR_AUDITS);
58829 +
58830 + curracl = current->acl;
58831 +
58832 + currobj = chk_obj_label(dentry, mnt, curracl);
58833 + retval = currobj->mode & mode;
58834 +
58835 + /* if we're opening a specified transfer file for writing
58836 + (e.g. /dev/initctl), then transfer our role to init
58837 + */
58838 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
58839 + current->role->roletype & GR_ROLE_PERSIST)) {
58840 + struct task_struct *task = init_pid_ns.child_reaper;
58841 +
58842 + if (task->role != current->role) {
58843 + task->acl_sp_role = 0;
58844 + task->acl_role_id = current->acl_role_id;
58845 + task->role = current->role;
58846 + rcu_read_lock();
58847 + read_lock(&grsec_exec_file_lock);
58848 + gr_apply_subject_to_task(task);
58849 + read_unlock(&grsec_exec_file_lock);
58850 + rcu_read_unlock();
58851 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
58852 + }
58853 + }
58854 +
58855 + if (unlikely
58856 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
58857 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
58858 + __u32 new_mode = mode;
58859 +
58860 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
58861 +
58862 + retval = new_mode;
58863 +
58864 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
58865 + new_mode |= GR_INHERIT;
58866 +
58867 + if (!(mode & GR_NOLEARN))
58868 + gr_log_learn(dentry, mnt, new_mode);
58869 + }
58870 +
58871 + return retval;
58872 +}
58873 +
58874 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
58875 + const struct dentry *parent,
58876 + const struct vfsmount *mnt)
58877 +{
58878 + struct name_entry *match;
58879 + struct acl_object_label *matchpo;
58880 + struct acl_subject_label *curracl;
58881 + char *path;
58882 +
58883 + if (unlikely(!(gr_status & GR_READY)))
58884 + return NULL;
58885 +
58886 + preempt_disable();
58887 + path = gr_to_filename_rbac(new_dentry, mnt);
58888 + match = lookup_name_entry_create(path);
58889 +
58890 + curracl = current->acl;
58891 +
58892 + if (match) {
58893 + read_lock(&gr_inode_lock);
58894 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
58895 + read_unlock(&gr_inode_lock);
58896 +
58897 + if (matchpo) {
58898 + preempt_enable();
58899 + return matchpo;
58900 + }
58901 + }
58902 +
58903 + // lookup parent
58904 +
58905 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
58906 +
58907 + preempt_enable();
58908 + return matchpo;
58909 +}
58910 +
58911 +__u32
58912 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
58913 + const struct vfsmount * mnt, const __u32 mode)
58914 +{
58915 + struct acl_object_label *matchpo;
58916 + __u32 retval;
58917 +
58918 + if (unlikely(!(gr_status & GR_READY)))
58919 + return (mode & ~GR_AUDITS);
58920 +
58921 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
58922 +
58923 + retval = matchpo->mode & mode;
58924 +
58925 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
58926 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
58927 + __u32 new_mode = mode;
58928 +
58929 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
58930 +
58931 + gr_log_learn(new_dentry, mnt, new_mode);
58932 + return new_mode;
58933 + }
58934 +
58935 + return retval;
58936 +}
58937 +
58938 +__u32
58939 +gr_check_link(const struct dentry * new_dentry,
58940 + const struct dentry * parent_dentry,
58941 + const struct vfsmount * parent_mnt,
58942 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
58943 +{
58944 + struct acl_object_label *obj;
58945 + __u32 oldmode, newmode;
58946 + __u32 needmode;
58947 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
58948 + GR_DELETE | GR_INHERIT;
58949 +
58950 + if (unlikely(!(gr_status & GR_READY)))
58951 + return (GR_CREATE | GR_LINK);
58952 +
58953 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
58954 + oldmode = obj->mode;
58955 +
58956 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
58957 + newmode = obj->mode;
58958 +
58959 + needmode = newmode & checkmodes;
58960 +
58961 + // old name for hardlink must have at least the permissions of the new name
58962 + if ((oldmode & needmode) != needmode)
58963 + goto bad;
58964 +
58965 + // if old name had restrictions/auditing, make sure the new name does as well
58966 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
58967 +
58968 + // don't allow hardlinking of suid/sgid/fcapped files without permission
58969 + if (is_privileged_binary(old_dentry))
58970 + needmode |= GR_SETID;
58971 +
58972 + if ((newmode & needmode) != needmode)
58973 + goto bad;
58974 +
58975 + // enforce minimum permissions
58976 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
58977 + return newmode;
58978 +bad:
58979 + needmode = oldmode;
58980 + if (is_privileged_binary(old_dentry))
58981 + needmode |= GR_SETID;
58982 +
58983 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
58984 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
58985 + return (GR_CREATE | GR_LINK);
58986 + } else if (newmode & GR_SUPPRESS)
58987 + return GR_SUPPRESS;
58988 + else
58989 + return 0;
58990 +}
58991 +
58992 +int
58993 +gr_check_hidden_task(const struct task_struct *task)
58994 +{
58995 + if (unlikely(!(gr_status & GR_READY)))
58996 + return 0;
58997 +
58998 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
58999 + return 1;
59000 +
59001 + return 0;
59002 +}
59003 +
59004 +int
59005 +gr_check_protected_task(const struct task_struct *task)
59006 +{
59007 + if (unlikely(!(gr_status & GR_READY) || !task))
59008 + return 0;
59009 +
59010 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59011 + task->acl != current->acl)
59012 + return 1;
59013 +
59014 + return 0;
59015 +}
59016 +
59017 +int
59018 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59019 +{
59020 + struct task_struct *p;
59021 + int ret = 0;
59022 +
59023 + if (unlikely(!(gr_status & GR_READY) || !pid))
59024 + return ret;
59025 +
59026 + read_lock(&tasklist_lock);
59027 + do_each_pid_task(pid, type, p) {
59028 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59029 + p->acl != current->acl) {
59030 + ret = 1;
59031 + goto out;
59032 + }
59033 + } while_each_pid_task(pid, type, p);
59034 +out:
59035 + read_unlock(&tasklist_lock);
59036 +
59037 + return ret;
59038 +}
59039 +
59040 +void
59041 +gr_copy_label(struct task_struct *tsk)
59042 +{
59043 + tsk->signal->used_accept = 0;
59044 + tsk->acl_sp_role = 0;
59045 + tsk->acl_role_id = current->acl_role_id;
59046 + tsk->acl = current->acl;
59047 + tsk->role = current->role;
59048 + tsk->signal->curr_ip = current->signal->curr_ip;
59049 + tsk->signal->saved_ip = current->signal->saved_ip;
59050 + if (current->exec_file)
59051 + get_file(current->exec_file);
59052 + tsk->exec_file = current->exec_file;
59053 + tsk->is_writable = current->is_writable;
59054 + if (unlikely(current->signal->used_accept)) {
59055 + current->signal->curr_ip = 0;
59056 + current->signal->saved_ip = 0;
59057 + }
59058 +
59059 + return;
59060 +}
59061 +
59062 +static void
59063 +gr_set_proc_res(struct task_struct *task)
59064 +{
59065 + struct acl_subject_label *proc;
59066 + unsigned short i;
59067 +
59068 + proc = task->acl;
59069 +
59070 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
59071 + return;
59072 +
59073 + for (i = 0; i < RLIM_NLIMITS; i++) {
59074 + if (!(proc->resmask & (1 << i)))
59075 + continue;
59076 +
59077 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
59078 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
59079 + }
59080 +
59081 + return;
59082 +}
59083 +
59084 +extern int __gr_process_user_ban(struct user_struct *user);
59085 +
59086 +int
59087 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
59088 +{
59089 + unsigned int i;
59090 + __u16 num;
59091 + uid_t *uidlist;
59092 + uid_t curuid;
59093 + int realok = 0;
59094 + int effectiveok = 0;
59095 + int fsok = 0;
59096 + uid_t globalreal, globaleffective, globalfs;
59097 +
59098 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59099 + struct user_struct *user;
59100 +
59101 + if (!uid_valid(real))
59102 + goto skipit;
59103 +
59104 + /* find user based on global namespace */
59105 +
59106 + globalreal = GR_GLOBAL_UID(real);
59107 +
59108 + user = find_user(make_kuid(&init_user_ns, globalreal));
59109 + if (user == NULL)
59110 + goto skipit;
59111 +
59112 + if (__gr_process_user_ban(user)) {
59113 + /* for find_user */
59114 + free_uid(user);
59115 + return 1;
59116 + }
59117 +
59118 + /* for find_user */
59119 + free_uid(user);
59120 +
59121 +skipit:
59122 +#endif
59123 +
59124 + if (unlikely(!(gr_status & GR_READY)))
59125 + return 0;
59126 +
59127 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59128 + gr_log_learn_uid_change(real, effective, fs);
59129 +
59130 + num = current->acl->user_trans_num;
59131 + uidlist = current->acl->user_transitions;
59132 +
59133 + if (uidlist == NULL)
59134 + return 0;
59135 +
59136 + if (!uid_valid(real)) {
59137 + realok = 1;
59138 + globalreal = (uid_t)-1;
59139 + } else {
59140 + globalreal = GR_GLOBAL_UID(real);
59141 + }
59142 + if (!uid_valid(effective)) {
59143 + effectiveok = 1;
59144 + globaleffective = (uid_t)-1;
59145 + } else {
59146 + globaleffective = GR_GLOBAL_UID(effective);
59147 + }
59148 + if (!uid_valid(fs)) {
59149 + fsok = 1;
59150 + globalfs = (uid_t)-1;
59151 + } else {
59152 + globalfs = GR_GLOBAL_UID(fs);
59153 + }
59154 +
59155 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
59156 + for (i = 0; i < num; i++) {
59157 + curuid = uidlist[i];
59158 + if (globalreal == curuid)
59159 + realok = 1;
59160 + if (globaleffective == curuid)
59161 + effectiveok = 1;
59162 + if (globalfs == curuid)
59163 + fsok = 1;
59164 + }
59165 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
59166 + for (i = 0; i < num; i++) {
59167 + curuid = uidlist[i];
59168 + if (globalreal == curuid)
59169 + break;
59170 + if (globaleffective == curuid)
59171 + break;
59172 + if (globalfs == curuid)
59173 + break;
59174 + }
59175 + /* not in deny list */
59176 + if (i == num) {
59177 + realok = 1;
59178 + effectiveok = 1;
59179 + fsok = 1;
59180 + }
59181 + }
59182 +
59183 + if (realok && effectiveok && fsok)
59184 + return 0;
59185 + else {
59186 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59187 + return 1;
59188 + }
59189 +}
59190 +
59191 +int
59192 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
59193 +{
59194 + unsigned int i;
59195 + __u16 num;
59196 + gid_t *gidlist;
59197 + gid_t curgid;
59198 + int realok = 0;
59199 + int effectiveok = 0;
59200 + int fsok = 0;
59201 + gid_t globalreal, globaleffective, globalfs;
59202 +
59203 + if (unlikely(!(gr_status & GR_READY)))
59204 + return 0;
59205 +
59206 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59207 + gr_log_learn_gid_change(real, effective, fs);
59208 +
59209 + num = current->acl->group_trans_num;
59210 + gidlist = current->acl->group_transitions;
59211 +
59212 + if (gidlist == NULL)
59213 + return 0;
59214 +
59215 + if (!gid_valid(real)) {
59216 + realok = 1;
59217 + globalreal = (gid_t)-1;
59218 + } else {
59219 + globalreal = GR_GLOBAL_GID(real);
59220 + }
59221 + if (!gid_valid(effective)) {
59222 + effectiveok = 1;
59223 + globaleffective = (gid_t)-1;
59224 + } else {
59225 + globaleffective = GR_GLOBAL_GID(effective);
59226 + }
59227 + if (!gid_valid(fs)) {
59228 + fsok = 1;
59229 + globalfs = (gid_t)-1;
59230 + } else {
59231 + globalfs = GR_GLOBAL_GID(fs);
59232 + }
59233 +
59234 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
59235 + for (i = 0; i < num; i++) {
59236 + curgid = gidlist[i];
59237 + if (globalreal == curgid)
59238 + realok = 1;
59239 + if (globaleffective == curgid)
59240 + effectiveok = 1;
59241 + if (globalfs == curgid)
59242 + fsok = 1;
59243 + }
59244 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
59245 + for (i = 0; i < num; i++) {
59246 + curgid = gidlist[i];
59247 + if (globalreal == curgid)
59248 + break;
59249 + if (globaleffective == curgid)
59250 + break;
59251 + if (globalfs == curgid)
59252 + break;
59253 + }
59254 + /* not in deny list */
59255 + if (i == num) {
59256 + realok = 1;
59257 + effectiveok = 1;
59258 + fsok = 1;
59259 + }
59260 + }
59261 +
59262 + if (realok && effectiveok && fsok)
59263 + return 0;
59264 + else {
59265 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59266 + return 1;
59267 + }
59268 +}
59269 +
59270 +extern int gr_acl_is_capable(const int cap);
59271 +
59272 +void
59273 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
59274 +{
59275 + struct acl_role_label *role = task->role;
59276 + struct acl_subject_label *subj = NULL;
59277 + struct acl_object_label *obj;
59278 + struct file *filp;
59279 + uid_t uid;
59280 + gid_t gid;
59281 +
59282 + if (unlikely(!(gr_status & GR_READY)))
59283 + return;
59284 +
59285 + uid = GR_GLOBAL_UID(kuid);
59286 + gid = GR_GLOBAL_GID(kgid);
59287 +
59288 + filp = task->exec_file;
59289 +
59290 + /* kernel process, we'll give them the kernel role */
59291 + if (unlikely(!filp)) {
59292 + task->role = kernel_role;
59293 + task->acl = kernel_role->root_label;
59294 + return;
59295 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
59296 + role = lookup_acl_role_label(task, uid, gid);
59297 +
59298 + /* don't change the role if we're not a privileged process */
59299 + if (role && task->role != role &&
59300 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
59301 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
59302 + return;
59303 +
59304 + /* perform subject lookup in possibly new role
59305 + we can use this result below in the case where role == task->role
59306 + */
59307 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
59308 +
59309 + /* if we changed uid/gid, but result in the same role
59310 + and are using inheritance, don't lose the inherited subject
59311 + if current subject is other than what normal lookup
59312 + would result in, we arrived via inheritance, don't
59313 + lose subject
59314 + */
59315 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
59316 + (subj == task->acl)))
59317 + task->acl = subj;
59318 +
59319 + task->role = role;
59320 +
59321 + task->is_writable = 0;
59322 +
59323 + /* ignore additional mmap checks for processes that are writable
59324 + by the default ACL */
59325 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59326 + if (unlikely(obj->mode & GR_WRITE))
59327 + task->is_writable = 1;
59328 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
59329 + if (unlikely(obj->mode & GR_WRITE))
59330 + task->is_writable = 1;
59331 +
59332 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59333 + 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);
59334 +#endif
59335 +
59336 + gr_set_proc_res(task);
59337 +
59338 + return;
59339 +}
59340 +
59341 +int
59342 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59343 + const int unsafe_flags)
59344 +{
59345 + struct task_struct *task = current;
59346 + struct acl_subject_label *newacl;
59347 + struct acl_object_label *obj;
59348 + __u32 retmode;
59349 +
59350 + if (unlikely(!(gr_status & GR_READY)))
59351 + return 0;
59352 +
59353 + newacl = chk_subj_label(dentry, mnt, task->role);
59354 +
59355 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
59356 + did an exec
59357 + */
59358 + rcu_read_lock();
59359 + read_lock(&tasklist_lock);
59360 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
59361 + (task->parent->acl->mode & GR_POVERRIDE))) {
59362 + read_unlock(&tasklist_lock);
59363 + rcu_read_unlock();
59364 + goto skip_check;
59365 + }
59366 + read_unlock(&tasklist_lock);
59367 + rcu_read_unlock();
59368 +
59369 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
59370 + !(task->role->roletype & GR_ROLE_GOD) &&
59371 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
59372 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59373 + if (unsafe_flags & LSM_UNSAFE_SHARE)
59374 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
59375 + else
59376 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
59377 + return -EACCES;
59378 + }
59379 +
59380 +skip_check:
59381 +
59382 + obj = chk_obj_label(dentry, mnt, task->acl);
59383 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
59384 +
59385 + if (!(task->acl->mode & GR_INHERITLEARN) &&
59386 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
59387 + if (obj->nested)
59388 + task->acl = obj->nested;
59389 + else
59390 + task->acl = newacl;
59391 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
59392 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
59393 +
59394 + task->is_writable = 0;
59395 +
59396 + /* ignore additional mmap checks for processes that are writable
59397 + by the default ACL */
59398 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
59399 + if (unlikely(obj->mode & GR_WRITE))
59400 + task->is_writable = 1;
59401 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
59402 + if (unlikely(obj->mode & GR_WRITE))
59403 + task->is_writable = 1;
59404 +
59405 + gr_set_proc_res(task);
59406 +
59407 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59408 + 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);
59409 +#endif
59410 + return 0;
59411 +}
59412 +
59413 +/* always called with valid inodev ptr */
59414 +static void
59415 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
59416 +{
59417 + struct acl_object_label *matchpo;
59418 + struct acl_subject_label *matchps;
59419 + struct acl_subject_label *subj;
59420 + struct acl_role_label *role;
59421 + unsigned int x;
59422 +
59423 + FOR_EACH_ROLE_START(role)
59424 + FOR_EACH_SUBJECT_START(role, subj, x)
59425 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59426 + matchpo->mode |= GR_DELETED;
59427 + FOR_EACH_SUBJECT_END(subj,x)
59428 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
59429 + /* nested subjects aren't in the role's subj_hash table */
59430 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59431 + matchpo->mode |= GR_DELETED;
59432 + FOR_EACH_NESTED_SUBJECT_END(subj)
59433 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
59434 + matchps->mode |= GR_DELETED;
59435 + FOR_EACH_ROLE_END(role)
59436 +
59437 + inodev->nentry->deleted = 1;
59438 +
59439 + return;
59440 +}
59441 +
59442 +void
59443 +gr_handle_delete(const ino_t ino, const dev_t dev)
59444 +{
59445 + struct inodev_entry *inodev;
59446 +
59447 + if (unlikely(!(gr_status & GR_READY)))
59448 + return;
59449 +
59450 + write_lock(&gr_inode_lock);
59451 + inodev = lookup_inodev_entry(ino, dev);
59452 + if (inodev != NULL)
59453 + do_handle_delete(inodev, ino, dev);
59454 + write_unlock(&gr_inode_lock);
59455 +
59456 + return;
59457 +}
59458 +
59459 +static void
59460 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
59461 + const ino_t newinode, const dev_t newdevice,
59462 + struct acl_subject_label *subj)
59463 +{
59464 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
59465 + struct acl_object_label *match;
59466 +
59467 + match = subj->obj_hash[index];
59468 +
59469 + while (match && (match->inode != oldinode ||
59470 + match->device != olddevice ||
59471 + !(match->mode & GR_DELETED)))
59472 + match = match->next;
59473 +
59474 + if (match && (match->inode == oldinode)
59475 + && (match->device == olddevice)
59476 + && (match->mode & GR_DELETED)) {
59477 + if (match->prev == NULL) {
59478 + subj->obj_hash[index] = match->next;
59479 + if (match->next != NULL)
59480 + match->next->prev = NULL;
59481 + } else {
59482 + match->prev->next = match->next;
59483 + if (match->next != NULL)
59484 + match->next->prev = match->prev;
59485 + }
59486 + match->prev = NULL;
59487 + match->next = NULL;
59488 + match->inode = newinode;
59489 + match->device = newdevice;
59490 + match->mode &= ~GR_DELETED;
59491 +
59492 + insert_acl_obj_label(match, subj);
59493 + }
59494 +
59495 + return;
59496 +}
59497 +
59498 +static void
59499 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
59500 + const ino_t newinode, const dev_t newdevice,
59501 + struct acl_role_label *role)
59502 +{
59503 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
59504 + struct acl_subject_label *match;
59505 +
59506 + match = role->subj_hash[index];
59507 +
59508 + while (match && (match->inode != oldinode ||
59509 + match->device != olddevice ||
59510 + !(match->mode & GR_DELETED)))
59511 + match = match->next;
59512 +
59513 + if (match && (match->inode == oldinode)
59514 + && (match->device == olddevice)
59515 + && (match->mode & GR_DELETED)) {
59516 + if (match->prev == NULL) {
59517 + role->subj_hash[index] = match->next;
59518 + if (match->next != NULL)
59519 + match->next->prev = NULL;
59520 + } else {
59521 + match->prev->next = match->next;
59522 + if (match->next != NULL)
59523 + match->next->prev = match->prev;
59524 + }
59525 + match->prev = NULL;
59526 + match->next = NULL;
59527 + match->inode = newinode;
59528 + match->device = newdevice;
59529 + match->mode &= ~GR_DELETED;
59530 +
59531 + insert_acl_subj_label(match, role);
59532 + }
59533 +
59534 + return;
59535 +}
59536 +
59537 +static void
59538 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
59539 + const ino_t newinode, const dev_t newdevice)
59540 +{
59541 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
59542 + struct inodev_entry *match;
59543 +
59544 + match = inodev_set.i_hash[index];
59545 +
59546 + while (match && (match->nentry->inode != oldinode ||
59547 + match->nentry->device != olddevice || !match->nentry->deleted))
59548 + match = match->next;
59549 +
59550 + if (match && (match->nentry->inode == oldinode)
59551 + && (match->nentry->device == olddevice) &&
59552 + match->nentry->deleted) {
59553 + if (match->prev == NULL) {
59554 + inodev_set.i_hash[index] = match->next;
59555 + if (match->next != NULL)
59556 + match->next->prev = NULL;
59557 + } else {
59558 + match->prev->next = match->next;
59559 + if (match->next != NULL)
59560 + match->next->prev = match->prev;
59561 + }
59562 + match->prev = NULL;
59563 + match->next = NULL;
59564 + match->nentry->inode = newinode;
59565 + match->nentry->device = newdevice;
59566 + match->nentry->deleted = 0;
59567 +
59568 + insert_inodev_entry(match);
59569 + }
59570 +
59571 + return;
59572 +}
59573 +
59574 +static void
59575 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
59576 +{
59577 + struct acl_subject_label *subj;
59578 + struct acl_role_label *role;
59579 + unsigned int x;
59580 +
59581 + FOR_EACH_ROLE_START(role)
59582 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
59583 +
59584 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
59585 + if ((subj->inode == ino) && (subj->device == dev)) {
59586 + subj->inode = ino;
59587 + subj->device = dev;
59588 + }
59589 + /* nested subjects aren't in the role's subj_hash table */
59590 + update_acl_obj_label(matchn->inode, matchn->device,
59591 + ino, dev, subj);
59592 + FOR_EACH_NESTED_SUBJECT_END(subj)
59593 + FOR_EACH_SUBJECT_START(role, subj, x)
59594 + update_acl_obj_label(matchn->inode, matchn->device,
59595 + ino, dev, subj);
59596 + FOR_EACH_SUBJECT_END(subj,x)
59597 + FOR_EACH_ROLE_END(role)
59598 +
59599 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
59600 +
59601 + return;
59602 +}
59603 +
59604 +static void
59605 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
59606 + const struct vfsmount *mnt)
59607 +{
59608 + ino_t ino = dentry->d_inode->i_ino;
59609 + dev_t dev = __get_dev(dentry);
59610 +
59611 + __do_handle_create(matchn, ino, dev);
59612 +
59613 + return;
59614 +}
59615 +
59616 +void
59617 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59618 +{
59619 + struct name_entry *matchn;
59620 +
59621 + if (unlikely(!(gr_status & GR_READY)))
59622 + return;
59623 +
59624 + preempt_disable();
59625 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
59626 +
59627 + if (unlikely((unsigned long)matchn)) {
59628 + write_lock(&gr_inode_lock);
59629 + do_handle_create(matchn, dentry, mnt);
59630 + write_unlock(&gr_inode_lock);
59631 + }
59632 + preempt_enable();
59633 +
59634 + return;
59635 +}
59636 +
59637 +void
59638 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59639 +{
59640 + struct name_entry *matchn;
59641 +
59642 + if (unlikely(!(gr_status & GR_READY)))
59643 + return;
59644 +
59645 + preempt_disable();
59646 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
59647 +
59648 + if (unlikely((unsigned long)matchn)) {
59649 + write_lock(&gr_inode_lock);
59650 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
59651 + write_unlock(&gr_inode_lock);
59652 + }
59653 + preempt_enable();
59654 +
59655 + return;
59656 +}
59657 +
59658 +void
59659 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59660 + struct dentry *old_dentry,
59661 + struct dentry *new_dentry,
59662 + struct vfsmount *mnt, const __u8 replace)
59663 +{
59664 + struct name_entry *matchn;
59665 + struct inodev_entry *inodev;
59666 + struct inode *inode = new_dentry->d_inode;
59667 + ino_t old_ino = old_dentry->d_inode->i_ino;
59668 + dev_t old_dev = __get_dev(old_dentry);
59669 +
59670 + /* vfs_rename swaps the name and parent link for old_dentry and
59671 + new_dentry
59672 + at this point, old_dentry has the new name, parent link, and inode
59673 + for the renamed file
59674 + if a file is being replaced by a rename, new_dentry has the inode
59675 + and name for the replaced file
59676 + */
59677 +
59678 + if (unlikely(!(gr_status & GR_READY)))
59679 + return;
59680 +
59681 + preempt_disable();
59682 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
59683 +
59684 + /* we wouldn't have to check d_inode if it weren't for
59685 + NFS silly-renaming
59686 + */
59687 +
59688 + write_lock(&gr_inode_lock);
59689 + if (unlikely(replace && inode)) {
59690 + ino_t new_ino = inode->i_ino;
59691 + dev_t new_dev = __get_dev(new_dentry);
59692 +
59693 + inodev = lookup_inodev_entry(new_ino, new_dev);
59694 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
59695 + do_handle_delete(inodev, new_ino, new_dev);
59696 + }
59697 +
59698 + inodev = lookup_inodev_entry(old_ino, old_dev);
59699 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
59700 + do_handle_delete(inodev, old_ino, old_dev);
59701 +
59702 + if (unlikely((unsigned long)matchn))
59703 + do_handle_create(matchn, old_dentry, mnt);
59704 +
59705 + write_unlock(&gr_inode_lock);
59706 + preempt_enable();
59707 +
59708 + return;
59709 +}
59710 +
59711 +static int
59712 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
59713 + unsigned char **sum)
59714 +{
59715 + struct acl_role_label *r;
59716 + struct role_allowed_ip *ipp;
59717 + struct role_transition *trans;
59718 + unsigned int i;
59719 + int found = 0;
59720 + u32 curr_ip = current->signal->curr_ip;
59721 +
59722 + current->signal->saved_ip = curr_ip;
59723 +
59724 + /* check transition table */
59725 +
59726 + for (trans = current->role->transitions; trans; trans = trans->next) {
59727 + if (!strcmp(rolename, trans->rolename)) {
59728 + found = 1;
59729 + break;
59730 + }
59731 + }
59732 +
59733 + if (!found)
59734 + return 0;
59735 +
59736 + /* handle special roles that do not require authentication
59737 + and check ip */
59738 +
59739 + FOR_EACH_ROLE_START(r)
59740 + if (!strcmp(rolename, r->rolename) &&
59741 + (r->roletype & GR_ROLE_SPECIAL)) {
59742 + found = 0;
59743 + if (r->allowed_ips != NULL) {
59744 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
59745 + if ((ntohl(curr_ip) & ipp->netmask) ==
59746 + (ntohl(ipp->addr) & ipp->netmask))
59747 + found = 1;
59748 + }
59749 + } else
59750 + found = 2;
59751 + if (!found)
59752 + return 0;
59753 +
59754 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
59755 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
59756 + *salt = NULL;
59757 + *sum = NULL;
59758 + return 1;
59759 + }
59760 + }
59761 + FOR_EACH_ROLE_END(r)
59762 +
59763 + for (i = 0; i < num_sprole_pws; i++) {
59764 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
59765 + *salt = acl_special_roles[i]->salt;
59766 + *sum = acl_special_roles[i]->sum;
59767 + return 1;
59768 + }
59769 + }
59770 +
59771 + return 0;
59772 +}
59773 +
59774 +static void
59775 +assign_special_role(char *rolename)
59776 +{
59777 + struct acl_object_label *obj;
59778 + struct acl_role_label *r;
59779 + struct acl_role_label *assigned = NULL;
59780 + struct task_struct *tsk;
59781 + struct file *filp;
59782 +
59783 + FOR_EACH_ROLE_START(r)
59784 + if (!strcmp(rolename, r->rolename) &&
59785 + (r->roletype & GR_ROLE_SPECIAL)) {
59786 + assigned = r;
59787 + break;
59788 + }
59789 + FOR_EACH_ROLE_END(r)
59790 +
59791 + if (!assigned)
59792 + return;
59793 +
59794 + read_lock(&tasklist_lock);
59795 + read_lock(&grsec_exec_file_lock);
59796 +
59797 + tsk = current->real_parent;
59798 + if (tsk == NULL)
59799 + goto out_unlock;
59800 +
59801 + filp = tsk->exec_file;
59802 + if (filp == NULL)
59803 + goto out_unlock;
59804 +
59805 + tsk->is_writable = 0;
59806 +
59807 + tsk->acl_sp_role = 1;
59808 + tsk->acl_role_id = ++acl_sp_role_value;
59809 + tsk->role = assigned;
59810 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
59811 +
59812 + /* ignore additional mmap checks for processes that are writable
59813 + by the default ACL */
59814 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59815 + if (unlikely(obj->mode & GR_WRITE))
59816 + tsk->is_writable = 1;
59817 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
59818 + if (unlikely(obj->mode & GR_WRITE))
59819 + tsk->is_writable = 1;
59820 +
59821 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59822 + 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));
59823 +#endif
59824 +
59825 +out_unlock:
59826 + read_unlock(&grsec_exec_file_lock);
59827 + read_unlock(&tasklist_lock);
59828 + return;
59829 +}
59830 +
59831 +int gr_check_secure_terminal(struct task_struct *task)
59832 +{
59833 + struct task_struct *p, *p2, *p3;
59834 + struct files_struct *files;
59835 + struct fdtable *fdt;
59836 + struct file *our_file = NULL, *file;
59837 + int i;
59838 +
59839 + if (task->signal->tty == NULL)
59840 + return 1;
59841 +
59842 + files = get_files_struct(task);
59843 + if (files != NULL) {
59844 + rcu_read_lock();
59845 + fdt = files_fdtable(files);
59846 + for (i=0; i < fdt->max_fds; i++) {
59847 + file = fcheck_files(files, i);
59848 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
59849 + get_file(file);
59850 + our_file = file;
59851 + }
59852 + }
59853 + rcu_read_unlock();
59854 + put_files_struct(files);
59855 + }
59856 +
59857 + if (our_file == NULL)
59858 + return 1;
59859 +
59860 + read_lock(&tasklist_lock);
59861 + do_each_thread(p2, p) {
59862 + files = get_files_struct(p);
59863 + if (files == NULL ||
59864 + (p->signal && p->signal->tty == task->signal->tty)) {
59865 + if (files != NULL)
59866 + put_files_struct(files);
59867 + continue;
59868 + }
59869 + rcu_read_lock();
59870 + fdt = files_fdtable(files);
59871 + for (i=0; i < fdt->max_fds; i++) {
59872 + file = fcheck_files(files, i);
59873 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
59874 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
59875 + p3 = task;
59876 + while (task_pid_nr(p3) > 0) {
59877 + if (p3 == p)
59878 + break;
59879 + p3 = p3->real_parent;
59880 + }
59881 + if (p3 == p)
59882 + break;
59883 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
59884 + gr_handle_alertkill(p);
59885 + rcu_read_unlock();
59886 + put_files_struct(files);
59887 + read_unlock(&tasklist_lock);
59888 + fput(our_file);
59889 + return 0;
59890 + }
59891 + }
59892 + rcu_read_unlock();
59893 + put_files_struct(files);
59894 + } while_each_thread(p2, p);
59895 + read_unlock(&tasklist_lock);
59896 +
59897 + fput(our_file);
59898 + return 1;
59899 +}
59900 +
59901 +static int gr_rbac_disable(void *unused)
59902 +{
59903 + pax_open_kernel();
59904 + gr_status &= ~GR_READY;
59905 + pax_close_kernel();
59906 +
59907 + return 0;
59908 +}
59909 +
59910 +ssize_t
59911 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
59912 +{
59913 + struct gr_arg_wrapper uwrap;
59914 + unsigned char *sprole_salt = NULL;
59915 + unsigned char *sprole_sum = NULL;
59916 + int error = sizeof (struct gr_arg_wrapper);
59917 + int error2 = 0;
59918 +
59919 + mutex_lock(&gr_dev_mutex);
59920 +
59921 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
59922 + error = -EPERM;
59923 + goto out;
59924 + }
59925 +
59926 + if (count != sizeof (struct gr_arg_wrapper)) {
59927 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
59928 + error = -EINVAL;
59929 + goto out;
59930 + }
59931 +
59932 +
59933 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
59934 + gr_auth_expires = 0;
59935 + gr_auth_attempts = 0;
59936 + }
59937 +
59938 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
59939 + error = -EFAULT;
59940 + goto out;
59941 + }
59942 +
59943 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
59944 + error = -EINVAL;
59945 + goto out;
59946 + }
59947 +
59948 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
59949 + error = -EFAULT;
59950 + goto out;
59951 + }
59952 +
59953 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
59954 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
59955 + time_after(gr_auth_expires, get_seconds())) {
59956 + error = -EBUSY;
59957 + goto out;
59958 + }
59959 +
59960 + /* if non-root trying to do anything other than use a special role,
59961 + do not attempt authentication, do not count towards authentication
59962 + locking
59963 + */
59964 +
59965 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
59966 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
59967 + gr_is_global_nonroot(current_uid())) {
59968 + error = -EPERM;
59969 + goto out;
59970 + }
59971 +
59972 + /* ensure pw and special role name are null terminated */
59973 +
59974 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
59975 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
59976 +
59977 + /* Okay.
59978 + * We have our enough of the argument structure..(we have yet
59979 + * to copy_from_user the tables themselves) . Copy the tables
59980 + * only if we need them, i.e. for loading operations. */
59981 +
59982 + switch (gr_usermode->mode) {
59983 + case GR_STATUS:
59984 + if (gr_status & GR_READY) {
59985 + error = 1;
59986 + if (!gr_check_secure_terminal(current))
59987 + error = 3;
59988 + } else
59989 + error = 2;
59990 + goto out;
59991 + case GR_SHUTDOWN:
59992 + if ((gr_status & GR_READY)
59993 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
59994 + stop_machine(gr_rbac_disable, NULL, NULL);
59995 + free_variables();
59996 + memset(gr_usermode, 0, sizeof (struct gr_arg));
59997 + memset(gr_system_salt, 0, GR_SALT_LEN);
59998 + memset(gr_system_sum, 0, GR_SHA_LEN);
59999 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
60000 + } else if (gr_status & GR_READY) {
60001 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
60002 + error = -EPERM;
60003 + } else {
60004 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
60005 + error = -EAGAIN;
60006 + }
60007 + break;
60008 + case GR_ENABLE:
60009 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
60010 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
60011 + else {
60012 + if (gr_status & GR_READY)
60013 + error = -EAGAIN;
60014 + else
60015 + error = error2;
60016 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
60017 + }
60018 + break;
60019 + case GR_RELOAD:
60020 + if (!(gr_status & GR_READY)) {
60021 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
60022 + error = -EAGAIN;
60023 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60024 + stop_machine(gr_rbac_disable, NULL, NULL);
60025 + free_variables();
60026 + error2 = gracl_init(gr_usermode);
60027 + if (!error2)
60028 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
60029 + else {
60030 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60031 + error = error2;
60032 + }
60033 + } else {
60034 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60035 + error = -EPERM;
60036 + }
60037 + break;
60038 + case GR_SEGVMOD:
60039 + if (unlikely(!(gr_status & GR_READY))) {
60040 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
60041 + error = -EAGAIN;
60042 + break;
60043 + }
60044 +
60045 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60046 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
60047 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
60048 + struct acl_subject_label *segvacl;
60049 + segvacl =
60050 + lookup_acl_subj_label(gr_usermode->segv_inode,
60051 + gr_usermode->segv_device,
60052 + current->role);
60053 + if (segvacl) {
60054 + segvacl->crashes = 0;
60055 + segvacl->expires = 0;
60056 + }
60057 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
60058 + gr_remove_uid(gr_usermode->segv_uid);
60059 + }
60060 + } else {
60061 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
60062 + error = -EPERM;
60063 + }
60064 + break;
60065 + case GR_SPROLE:
60066 + case GR_SPROLEPAM:
60067 + if (unlikely(!(gr_status & GR_READY))) {
60068 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
60069 + error = -EAGAIN;
60070 + break;
60071 + }
60072 +
60073 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
60074 + current->role->expires = 0;
60075 + current->role->auth_attempts = 0;
60076 + }
60077 +
60078 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60079 + time_after(current->role->expires, get_seconds())) {
60080 + error = -EBUSY;
60081 + goto out;
60082 + }
60083 +
60084 + if (lookup_special_role_auth
60085 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
60086 + && ((!sprole_salt && !sprole_sum)
60087 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
60088 + char *p = "";
60089 + assign_special_role(gr_usermode->sp_role);
60090 + read_lock(&tasklist_lock);
60091 + if (current->real_parent)
60092 + p = current->real_parent->role->rolename;
60093 + read_unlock(&tasklist_lock);
60094 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
60095 + p, acl_sp_role_value);
60096 + } else {
60097 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
60098 + error = -EPERM;
60099 + if(!(current->role->auth_attempts++))
60100 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60101 +
60102 + goto out;
60103 + }
60104 + break;
60105 + case GR_UNSPROLE:
60106 + if (unlikely(!(gr_status & GR_READY))) {
60107 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
60108 + error = -EAGAIN;
60109 + break;
60110 + }
60111 +
60112 + if (current->role->roletype & GR_ROLE_SPECIAL) {
60113 + char *p = "";
60114 + int i = 0;
60115 +
60116 + read_lock(&tasklist_lock);
60117 + if (current->real_parent) {
60118 + p = current->real_parent->role->rolename;
60119 + i = current->real_parent->acl_role_id;
60120 + }
60121 + read_unlock(&tasklist_lock);
60122 +
60123 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
60124 + gr_set_acls(1);
60125 + } else {
60126 + error = -EPERM;
60127 + goto out;
60128 + }
60129 + break;
60130 + default:
60131 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
60132 + error = -EINVAL;
60133 + break;
60134 + }
60135 +
60136 + if (error != -EPERM)
60137 + goto out;
60138 +
60139 + if(!(gr_auth_attempts++))
60140 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60141 +
60142 + out:
60143 + mutex_unlock(&gr_dev_mutex);
60144 + return error;
60145 +}
60146 +
60147 +/* must be called with
60148 + rcu_read_lock();
60149 + read_lock(&tasklist_lock);
60150 + read_lock(&grsec_exec_file_lock);
60151 +*/
60152 +int gr_apply_subject_to_task(struct task_struct *task)
60153 +{
60154 + struct acl_object_label *obj;
60155 + char *tmpname;
60156 + struct acl_subject_label *tmpsubj;
60157 + struct file *filp;
60158 + struct name_entry *nmatch;
60159 +
60160 + filp = task->exec_file;
60161 + if (filp == NULL)
60162 + return 0;
60163 +
60164 + /* the following is to apply the correct subject
60165 + on binaries running when the RBAC system
60166 + is enabled, when the binaries have been
60167 + replaced or deleted since their execution
60168 + -----
60169 + when the RBAC system starts, the inode/dev
60170 + from exec_file will be one the RBAC system
60171 + is unaware of. It only knows the inode/dev
60172 + of the present file on disk, or the absence
60173 + of it.
60174 + */
60175 + preempt_disable();
60176 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
60177 +
60178 + nmatch = lookup_name_entry(tmpname);
60179 + preempt_enable();
60180 + tmpsubj = NULL;
60181 + if (nmatch) {
60182 + if (nmatch->deleted)
60183 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
60184 + else
60185 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
60186 + if (tmpsubj != NULL)
60187 + task->acl = tmpsubj;
60188 + }
60189 + if (tmpsubj == NULL)
60190 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
60191 + task->role);
60192 + if (task->acl) {
60193 + task->is_writable = 0;
60194 + /* ignore additional mmap checks for processes that are writable
60195 + by the default ACL */
60196 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60197 + if (unlikely(obj->mode & GR_WRITE))
60198 + task->is_writable = 1;
60199 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60200 + if (unlikely(obj->mode & GR_WRITE))
60201 + task->is_writable = 1;
60202 +
60203 + gr_set_proc_res(task);
60204 +
60205 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60206 + 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);
60207 +#endif
60208 + } else {
60209 + return 1;
60210 + }
60211 +
60212 + return 0;
60213 +}
60214 +
60215 +int
60216 +gr_set_acls(const int type)
60217 +{
60218 + struct task_struct *task, *task2;
60219 + struct acl_role_label *role = current->role;
60220 + __u16 acl_role_id = current->acl_role_id;
60221 + const struct cred *cred;
60222 + int ret;
60223 +
60224 + rcu_read_lock();
60225 + read_lock(&tasklist_lock);
60226 + read_lock(&grsec_exec_file_lock);
60227 + do_each_thread(task2, task) {
60228 + /* check to see if we're called from the exit handler,
60229 + if so, only replace ACLs that have inherited the admin
60230 + ACL */
60231 +
60232 + if (type && (task->role != role ||
60233 + task->acl_role_id != acl_role_id))
60234 + continue;
60235 +
60236 + task->acl_role_id = 0;
60237 + task->acl_sp_role = 0;
60238 +
60239 + if (task->exec_file) {
60240 + cred = __task_cred(task);
60241 + task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
60242 + ret = gr_apply_subject_to_task(task);
60243 + if (ret) {
60244 + read_unlock(&grsec_exec_file_lock);
60245 + read_unlock(&tasklist_lock);
60246 + rcu_read_unlock();
60247 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
60248 + return ret;
60249 + }
60250 + } else {
60251 + // it's a kernel process
60252 + task->role = kernel_role;
60253 + task->acl = kernel_role->root_label;
60254 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
60255 + task->acl->mode &= ~GR_PROCFIND;
60256 +#endif
60257 + }
60258 + } while_each_thread(task2, task);
60259 + read_unlock(&grsec_exec_file_lock);
60260 + read_unlock(&tasklist_lock);
60261 + rcu_read_unlock();
60262 +
60263 + return 0;
60264 +}
60265 +
60266 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
60267 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
60268 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
60269 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
60270 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
60271 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
60272 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
60273 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
60274 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
60275 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
60276 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
60277 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
60278 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
60279 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
60280 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
60281 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
60282 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
60283 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
60284 +};
60285 +
60286 +void
60287 +gr_learn_resource(const struct task_struct *task,
60288 + const int res, const unsigned long wanted, const int gt)
60289 +{
60290 + struct acl_subject_label *acl;
60291 + const struct cred *cred;
60292 +
60293 + if (unlikely((gr_status & GR_READY) &&
60294 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
60295 + goto skip_reslog;
60296 +
60297 + gr_log_resource(task, res, wanted, gt);
60298 +skip_reslog:
60299 +
60300 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
60301 + return;
60302 +
60303 + acl = task->acl;
60304 +
60305 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
60306 + !(acl->resmask & (1 << (unsigned short) res))))
60307 + return;
60308 +
60309 + if (wanted >= acl->res[res].rlim_cur) {
60310 + unsigned long res_add;
60311 +
60312 + res_add = wanted + res_learn_bumps[res];
60313 +
60314 + acl->res[res].rlim_cur = res_add;
60315 +
60316 + if (wanted > acl->res[res].rlim_max)
60317 + acl->res[res].rlim_max = res_add;
60318 +
60319 + /* only log the subject filename, since resource logging is supported for
60320 + single-subject learning only */
60321 + rcu_read_lock();
60322 + cred = __task_cred(task);
60323 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60324 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
60325 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
60326 + "", (unsigned long) res, &task->signal->saved_ip);
60327 + rcu_read_unlock();
60328 + }
60329 +
60330 + return;
60331 +}
60332 +EXPORT_SYMBOL(gr_learn_resource);
60333 +#endif
60334 +
60335 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
60336 +void
60337 +pax_set_initial_flags(struct linux_binprm *bprm)
60338 +{
60339 + struct task_struct *task = current;
60340 + struct acl_subject_label *proc;
60341 + unsigned long flags;
60342 +
60343 + if (unlikely(!(gr_status & GR_READY)))
60344 + return;
60345 +
60346 + flags = pax_get_flags(task);
60347 +
60348 + proc = task->acl;
60349 +
60350 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
60351 + flags &= ~MF_PAX_PAGEEXEC;
60352 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
60353 + flags &= ~MF_PAX_SEGMEXEC;
60354 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
60355 + flags &= ~MF_PAX_RANDMMAP;
60356 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
60357 + flags &= ~MF_PAX_EMUTRAMP;
60358 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
60359 + flags &= ~MF_PAX_MPROTECT;
60360 +
60361 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
60362 + flags |= MF_PAX_PAGEEXEC;
60363 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
60364 + flags |= MF_PAX_SEGMEXEC;
60365 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
60366 + flags |= MF_PAX_RANDMMAP;
60367 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
60368 + flags |= MF_PAX_EMUTRAMP;
60369 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
60370 + flags |= MF_PAX_MPROTECT;
60371 +
60372 + pax_set_flags(task, flags);
60373 +
60374 + return;
60375 +}
60376 +#endif
60377 +
60378 +int
60379 +gr_handle_proc_ptrace(struct task_struct *task)
60380 +{
60381 + struct file *filp;
60382 + struct task_struct *tmp = task;
60383 + struct task_struct *curtemp = current;
60384 + __u32 retmode;
60385 +
60386 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60387 + if (unlikely(!(gr_status & GR_READY)))
60388 + return 0;
60389 +#endif
60390 +
60391 + read_lock(&tasklist_lock);
60392 + read_lock(&grsec_exec_file_lock);
60393 + filp = task->exec_file;
60394 +
60395 + while (task_pid_nr(tmp) > 0) {
60396 + if (tmp == curtemp)
60397 + break;
60398 + tmp = tmp->real_parent;
60399 + }
60400 +
60401 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60402 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
60403 + read_unlock(&grsec_exec_file_lock);
60404 + read_unlock(&tasklist_lock);
60405 + return 1;
60406 + }
60407 +
60408 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60409 + if (!(gr_status & GR_READY)) {
60410 + read_unlock(&grsec_exec_file_lock);
60411 + read_unlock(&tasklist_lock);
60412 + return 0;
60413 + }
60414 +#endif
60415 +
60416 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
60417 + read_unlock(&grsec_exec_file_lock);
60418 + read_unlock(&tasklist_lock);
60419 +
60420 + if (retmode & GR_NOPTRACE)
60421 + return 1;
60422 +
60423 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
60424 + && (current->acl != task->acl || (current->acl != current->role->root_label
60425 + && task_pid_nr(current) != task_pid_nr(task))))
60426 + return 1;
60427 +
60428 + return 0;
60429 +}
60430 +
60431 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
60432 +{
60433 + if (unlikely(!(gr_status & GR_READY)))
60434 + return;
60435 +
60436 + if (!(current->role->roletype & GR_ROLE_GOD))
60437 + return;
60438 +
60439 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
60440 + p->role->rolename, gr_task_roletype_to_char(p),
60441 + p->acl->filename);
60442 +}
60443 +
60444 +int
60445 +gr_handle_ptrace(struct task_struct *task, const long request)
60446 +{
60447 + struct task_struct *tmp = task;
60448 + struct task_struct *curtemp = current;
60449 + __u32 retmode;
60450 +
60451 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60452 + if (unlikely(!(gr_status & GR_READY)))
60453 + return 0;
60454 +#endif
60455 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
60456 + read_lock(&tasklist_lock);
60457 + while (task_pid_nr(tmp) > 0) {
60458 + if (tmp == curtemp)
60459 + break;
60460 + tmp = tmp->real_parent;
60461 + }
60462 +
60463 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60464 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
60465 + read_unlock(&tasklist_lock);
60466 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60467 + return 1;
60468 + }
60469 + read_unlock(&tasklist_lock);
60470 + }
60471 +
60472 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60473 + if (!(gr_status & GR_READY))
60474 + return 0;
60475 +#endif
60476 +
60477 + read_lock(&grsec_exec_file_lock);
60478 + if (unlikely(!task->exec_file)) {
60479 + read_unlock(&grsec_exec_file_lock);
60480 + return 0;
60481 + }
60482 +
60483 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
60484 + read_unlock(&grsec_exec_file_lock);
60485 +
60486 + if (retmode & GR_NOPTRACE) {
60487 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60488 + return 1;
60489 + }
60490 +
60491 + if (retmode & GR_PTRACERD) {
60492 + switch (request) {
60493 + case PTRACE_SEIZE:
60494 + case PTRACE_POKETEXT:
60495 + case PTRACE_POKEDATA:
60496 + case PTRACE_POKEUSR:
60497 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
60498 + case PTRACE_SETREGS:
60499 + case PTRACE_SETFPREGS:
60500 +#endif
60501 +#ifdef CONFIG_X86
60502 + case PTRACE_SETFPXREGS:
60503 +#endif
60504 +#ifdef CONFIG_ALTIVEC
60505 + case PTRACE_SETVRREGS:
60506 +#endif
60507 + return 1;
60508 + default:
60509 + return 0;
60510 + }
60511 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
60512 + !(current->role->roletype & GR_ROLE_GOD) &&
60513 + (current->acl != task->acl)) {
60514 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60515 + return 1;
60516 + }
60517 +
60518 + return 0;
60519 +}
60520 +
60521 +static int is_writable_mmap(const struct file *filp)
60522 +{
60523 + struct task_struct *task = current;
60524 + struct acl_object_label *obj, *obj2;
60525 +
60526 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
60527 + !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))) {
60528 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60529 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
60530 + task->role->root_label);
60531 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
60532 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
60533 + return 1;
60534 + }
60535 + }
60536 + return 0;
60537 +}
60538 +
60539 +int
60540 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
60541 +{
60542 + __u32 mode;
60543 +
60544 + if (unlikely(!file || !(prot & PROT_EXEC)))
60545 + return 1;
60546 +
60547 + if (is_writable_mmap(file))
60548 + return 0;
60549 +
60550 + mode =
60551 + gr_search_file(file->f_path.dentry,
60552 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
60553 + file->f_path.mnt);
60554 +
60555 + if (!gr_tpe_allow(file))
60556 + return 0;
60557 +
60558 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
60559 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60560 + return 0;
60561 + } else if (unlikely(!(mode & GR_EXEC))) {
60562 + return 0;
60563 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
60564 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60565 + return 1;
60566 + }
60567 +
60568 + return 1;
60569 +}
60570 +
60571 +int
60572 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60573 +{
60574 + __u32 mode;
60575 +
60576 + if (unlikely(!file || !(prot & PROT_EXEC)))
60577 + return 1;
60578 +
60579 + if (is_writable_mmap(file))
60580 + return 0;
60581 +
60582 + mode =
60583 + gr_search_file(file->f_path.dentry,
60584 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
60585 + file->f_path.mnt);
60586 +
60587 + if (!gr_tpe_allow(file))
60588 + return 0;
60589 +
60590 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
60591 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60592 + return 0;
60593 + } else if (unlikely(!(mode & GR_EXEC))) {
60594 + return 0;
60595 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
60596 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60597 + return 1;
60598 + }
60599 +
60600 + return 1;
60601 +}
60602 +
60603 +void
60604 +gr_acl_handle_psacct(struct task_struct *task, const long code)
60605 +{
60606 + unsigned long runtime;
60607 + unsigned long cputime;
60608 + unsigned int wday, cday;
60609 + __u8 whr, chr;
60610 + __u8 wmin, cmin;
60611 + __u8 wsec, csec;
60612 + struct timespec timeval;
60613 +
60614 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
60615 + !(task->acl->mode & GR_PROCACCT)))
60616 + return;
60617 +
60618 + do_posix_clock_monotonic_gettime(&timeval);
60619 + runtime = timeval.tv_sec - task->start_time.tv_sec;
60620 + wday = runtime / (3600 * 24);
60621 + runtime -= wday * (3600 * 24);
60622 + whr = runtime / 3600;
60623 + runtime -= whr * 3600;
60624 + wmin = runtime / 60;
60625 + runtime -= wmin * 60;
60626 + wsec = runtime;
60627 +
60628 + cputime = (task->utime + task->stime) / HZ;
60629 + cday = cputime / (3600 * 24);
60630 + cputime -= cday * (3600 * 24);
60631 + chr = cputime / 3600;
60632 + cputime -= chr * 3600;
60633 + cmin = cputime / 60;
60634 + cputime -= cmin * 60;
60635 + csec = cputime;
60636 +
60637 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
60638 +
60639 + return;
60640 +}
60641 +
60642 +void gr_set_kernel_label(struct task_struct *task)
60643 +{
60644 + if (gr_status & GR_READY) {
60645 + task->role = kernel_role;
60646 + task->acl = kernel_role->root_label;
60647 + }
60648 + return;
60649 +}
60650 +
60651 +#ifdef CONFIG_TASKSTATS
60652 +int gr_is_taskstats_denied(int pid)
60653 +{
60654 + struct task_struct *task;
60655 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60656 + const struct cred *cred;
60657 +#endif
60658 + int ret = 0;
60659 +
60660 + /* restrict taskstats viewing to un-chrooted root users
60661 + who have the 'view' subject flag if the RBAC system is enabled
60662 + */
60663 +
60664 + rcu_read_lock();
60665 + read_lock(&tasklist_lock);
60666 + task = find_task_by_vpid(pid);
60667 + if (task) {
60668 +#ifdef CONFIG_GRKERNSEC_CHROOT
60669 + if (proc_is_chrooted(task))
60670 + ret = -EACCES;
60671 +#endif
60672 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60673 + cred = __task_cred(task);
60674 +#ifdef CONFIG_GRKERNSEC_PROC_USER
60675 + if (gr_is_global_nonroot(cred->uid))
60676 + ret = -EACCES;
60677 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60678 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
60679 + ret = -EACCES;
60680 +#endif
60681 +#endif
60682 + if (gr_status & GR_READY) {
60683 + if (!(task->acl->mode & GR_VIEW))
60684 + ret = -EACCES;
60685 + }
60686 + } else
60687 + ret = -ENOENT;
60688 +
60689 + read_unlock(&tasklist_lock);
60690 + rcu_read_unlock();
60691 +
60692 + return ret;
60693 +}
60694 +#endif
60695 +
60696 +/* AUXV entries are filled via a descendant of search_binary_handler
60697 + after we've already applied the subject for the target
60698 +*/
60699 +int gr_acl_enable_at_secure(void)
60700 +{
60701 + if (unlikely(!(gr_status & GR_READY)))
60702 + return 0;
60703 +
60704 + if (current->acl->mode & GR_ATSECURE)
60705 + return 1;
60706 +
60707 + return 0;
60708 +}
60709 +
60710 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
60711 +{
60712 + struct task_struct *task = current;
60713 + struct dentry *dentry = file->f_path.dentry;
60714 + struct vfsmount *mnt = file->f_path.mnt;
60715 + struct acl_object_label *obj, *tmp;
60716 + struct acl_subject_label *subj;
60717 + unsigned int bufsize;
60718 + int is_not_root;
60719 + char *path;
60720 + dev_t dev = __get_dev(dentry);
60721 +
60722 + if (unlikely(!(gr_status & GR_READY)))
60723 + return 1;
60724 +
60725 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60726 + return 1;
60727 +
60728 + /* ignore Eric Biederman */
60729 + if (IS_PRIVATE(dentry->d_inode))
60730 + return 1;
60731 +
60732 + subj = task->acl;
60733 + read_lock(&gr_inode_lock);
60734 + do {
60735 + obj = lookup_acl_obj_label(ino, dev, subj);
60736 + if (obj != NULL) {
60737 + read_unlock(&gr_inode_lock);
60738 + return (obj->mode & GR_FIND) ? 1 : 0;
60739 + }
60740 + } while ((subj = subj->parent_subject));
60741 + read_unlock(&gr_inode_lock);
60742 +
60743 + /* this is purely an optimization since we're looking for an object
60744 + for the directory we're doing a readdir on
60745 + if it's possible for any globbed object to match the entry we're
60746 + filling into the directory, then the object we find here will be
60747 + an anchor point with attached globbed objects
60748 + */
60749 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
60750 + if (obj->globbed == NULL)
60751 + return (obj->mode & GR_FIND) ? 1 : 0;
60752 +
60753 + is_not_root = ((obj->filename[0] == '/') &&
60754 + (obj->filename[1] == '\0')) ? 0 : 1;
60755 + bufsize = PAGE_SIZE - namelen - is_not_root;
60756 +
60757 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
60758 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
60759 + return 1;
60760 +
60761 + preempt_disable();
60762 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
60763 + bufsize);
60764 +
60765 + bufsize = strlen(path);
60766 +
60767 + /* if base is "/", don't append an additional slash */
60768 + if (is_not_root)
60769 + *(path + bufsize) = '/';
60770 + memcpy(path + bufsize + is_not_root, name, namelen);
60771 + *(path + bufsize + namelen + is_not_root) = '\0';
60772 +
60773 + tmp = obj->globbed;
60774 + while (tmp) {
60775 + if (!glob_match(tmp->filename, path)) {
60776 + preempt_enable();
60777 + return (tmp->mode & GR_FIND) ? 1 : 0;
60778 + }
60779 + tmp = tmp->next;
60780 + }
60781 + preempt_enable();
60782 + return (obj->mode & GR_FIND) ? 1 : 0;
60783 +}
60784 +
60785 +void gr_put_exec_file(struct task_struct *task)
60786 +{
60787 + struct file *filp;
60788 +
60789 + write_lock(&grsec_exec_file_lock);
60790 + filp = task->exec_file;
60791 + task->exec_file = NULL;
60792 + write_unlock(&grsec_exec_file_lock);
60793 +
60794 + if (filp)
60795 + fput(filp);
60796 +
60797 + return;
60798 +}
60799 +
60800 +
60801 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
60802 +EXPORT_SYMBOL(gr_acl_is_enabled);
60803 +#endif
60804 +EXPORT_SYMBOL(gr_set_kernel_label);
60805 +#ifdef CONFIG_SECURITY
60806 +EXPORT_SYMBOL(gr_check_user_change);
60807 +EXPORT_SYMBOL(gr_check_group_change);
60808 +#endif
60809 +
60810 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
60811 new file mode 100644
60812 index 0000000..34fefda
60813 --- /dev/null
60814 +++ b/grsecurity/gracl_alloc.c
60815 @@ -0,0 +1,105 @@
60816 +#include <linux/kernel.h>
60817 +#include <linux/mm.h>
60818 +#include <linux/slab.h>
60819 +#include <linux/vmalloc.h>
60820 +#include <linux/gracl.h>
60821 +#include <linux/grsecurity.h>
60822 +
60823 +static unsigned long alloc_stack_next = 1;
60824 +static unsigned long alloc_stack_size = 1;
60825 +static void **alloc_stack;
60826 +
60827 +static __inline__ int
60828 +alloc_pop(void)
60829 +{
60830 + if (alloc_stack_next == 1)
60831 + return 0;
60832 +
60833 + kfree(alloc_stack[alloc_stack_next - 2]);
60834 +
60835 + alloc_stack_next--;
60836 +
60837 + return 1;
60838 +}
60839 +
60840 +static __inline__ int
60841 +alloc_push(void *buf)
60842 +{
60843 + if (alloc_stack_next >= alloc_stack_size)
60844 + return 1;
60845 +
60846 + alloc_stack[alloc_stack_next - 1] = buf;
60847 +
60848 + alloc_stack_next++;
60849 +
60850 + return 0;
60851 +}
60852 +
60853 +void *
60854 +acl_alloc(unsigned long len)
60855 +{
60856 + void *ret = NULL;
60857 +
60858 + if (!len || len > PAGE_SIZE)
60859 + goto out;
60860 +
60861 + ret = kmalloc(len, GFP_KERNEL);
60862 +
60863 + if (ret) {
60864 + if (alloc_push(ret)) {
60865 + kfree(ret);
60866 + ret = NULL;
60867 + }
60868 + }
60869 +
60870 +out:
60871 + return ret;
60872 +}
60873 +
60874 +void *
60875 +acl_alloc_num(unsigned long num, unsigned long len)
60876 +{
60877 + if (!len || (num > (PAGE_SIZE / len)))
60878 + return NULL;
60879 +
60880 + return acl_alloc(num * len);
60881 +}
60882 +
60883 +void
60884 +acl_free_all(void)
60885 +{
60886 + if (gr_acl_is_enabled() || !alloc_stack)
60887 + return;
60888 +
60889 + while (alloc_pop()) ;
60890 +
60891 + if (alloc_stack) {
60892 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
60893 + kfree(alloc_stack);
60894 + else
60895 + vfree(alloc_stack);
60896 + }
60897 +
60898 + alloc_stack = NULL;
60899 + alloc_stack_size = 1;
60900 + alloc_stack_next = 1;
60901 +
60902 + return;
60903 +}
60904 +
60905 +int
60906 +acl_alloc_stack_init(unsigned long size)
60907 +{
60908 + if ((size * sizeof (void *)) <= PAGE_SIZE)
60909 + alloc_stack =
60910 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
60911 + else
60912 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
60913 +
60914 + alloc_stack_size = size;
60915 +
60916 + if (!alloc_stack)
60917 + return 0;
60918 + else
60919 + return 1;
60920 +}
60921 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
60922 new file mode 100644
60923 index 0000000..bdd51ea
60924 --- /dev/null
60925 +++ b/grsecurity/gracl_cap.c
60926 @@ -0,0 +1,110 @@
60927 +#include <linux/kernel.h>
60928 +#include <linux/module.h>
60929 +#include <linux/sched.h>
60930 +#include <linux/gracl.h>
60931 +#include <linux/grsecurity.h>
60932 +#include <linux/grinternal.h>
60933 +
60934 +extern const char *captab_log[];
60935 +extern int captab_log_entries;
60936 +
60937 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60938 +{
60939 + struct acl_subject_label *curracl;
60940 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
60941 + kernel_cap_t cap_audit = __cap_empty_set;
60942 +
60943 + if (!gr_acl_is_enabled())
60944 + return 1;
60945 +
60946 + curracl = task->acl;
60947 +
60948 + cap_drop = curracl->cap_lower;
60949 + cap_mask = curracl->cap_mask;
60950 + cap_audit = curracl->cap_invert_audit;
60951 +
60952 + while ((curracl = curracl->parent_subject)) {
60953 + /* if the cap isn't specified in the current computed mask but is specified in the
60954 + current level subject, and is lowered in the current level subject, then add
60955 + it to the set of dropped capabilities
60956 + otherwise, add the current level subject's mask to the current computed mask
60957 + */
60958 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
60959 + cap_raise(cap_mask, cap);
60960 + if (cap_raised(curracl->cap_lower, cap))
60961 + cap_raise(cap_drop, cap);
60962 + if (cap_raised(curracl->cap_invert_audit, cap))
60963 + cap_raise(cap_audit, cap);
60964 + }
60965 + }
60966 +
60967 + if (!cap_raised(cap_drop, cap)) {
60968 + if (cap_raised(cap_audit, cap))
60969 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
60970 + return 1;
60971 + }
60972 +
60973 + curracl = task->acl;
60974 +
60975 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
60976 + && cap_raised(cred->cap_effective, cap)) {
60977 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60978 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
60979 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
60980 + gr_to_filename(task->exec_file->f_path.dentry,
60981 + task->exec_file->f_path.mnt) : curracl->filename,
60982 + curracl->filename, 0UL,
60983 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
60984 + return 1;
60985 + }
60986 +
60987 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
60988 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
60989 +
60990 + return 0;
60991 +}
60992 +
60993 +int
60994 +gr_acl_is_capable(const int cap)
60995 +{
60996 + return gr_task_acl_is_capable(current, current_cred(), cap);
60997 +}
60998 +
60999 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
61000 +{
61001 + struct acl_subject_label *curracl;
61002 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61003 +
61004 + if (!gr_acl_is_enabled())
61005 + return 1;
61006 +
61007 + curracl = task->acl;
61008 +
61009 + cap_drop = curracl->cap_lower;
61010 + cap_mask = curracl->cap_mask;
61011 +
61012 + while ((curracl = curracl->parent_subject)) {
61013 + /* if the cap isn't specified in the current computed mask but is specified in the
61014 + current level subject, and is lowered in the current level subject, then add
61015 + it to the set of dropped capabilities
61016 + otherwise, add the current level subject's mask to the current computed mask
61017 + */
61018 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61019 + cap_raise(cap_mask, cap);
61020 + if (cap_raised(curracl->cap_lower, cap))
61021 + cap_raise(cap_drop, cap);
61022 + }
61023 + }
61024 +
61025 + if (!cap_raised(cap_drop, cap))
61026 + return 1;
61027 +
61028 + return 0;
61029 +}
61030 +
61031 +int
61032 +gr_acl_is_capable_nolog(const int cap)
61033 +{
61034 + return gr_task_acl_is_capable_nolog(current, cap);
61035 +}
61036 +
61037 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
61038 new file mode 100644
61039 index 0000000..a340c17
61040 --- /dev/null
61041 +++ b/grsecurity/gracl_fs.c
61042 @@ -0,0 +1,431 @@
61043 +#include <linux/kernel.h>
61044 +#include <linux/sched.h>
61045 +#include <linux/types.h>
61046 +#include <linux/fs.h>
61047 +#include <linux/file.h>
61048 +#include <linux/stat.h>
61049 +#include <linux/grsecurity.h>
61050 +#include <linux/grinternal.h>
61051 +#include <linux/gracl.h>
61052 +
61053 +umode_t
61054 +gr_acl_umask(void)
61055 +{
61056 + if (unlikely(!gr_acl_is_enabled()))
61057 + return 0;
61058 +
61059 + return current->role->umask;
61060 +}
61061 +
61062 +__u32
61063 +gr_acl_handle_hidden_file(const struct dentry * dentry,
61064 + const struct vfsmount * mnt)
61065 +{
61066 + __u32 mode;
61067 +
61068 + if (unlikely(!dentry->d_inode))
61069 + return GR_FIND;
61070 +
61071 + mode =
61072 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
61073 +
61074 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
61075 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61076 + return mode;
61077 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
61078 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61079 + return 0;
61080 + } else if (unlikely(!(mode & GR_FIND)))
61081 + return 0;
61082 +
61083 + return GR_FIND;
61084 +}
61085 +
61086 +__u32
61087 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
61088 + int acc_mode)
61089 +{
61090 + __u32 reqmode = GR_FIND;
61091 + __u32 mode;
61092 +
61093 + if (unlikely(!dentry->d_inode))
61094 + return reqmode;
61095 +
61096 + if (acc_mode & MAY_APPEND)
61097 + reqmode |= GR_APPEND;
61098 + else if (acc_mode & MAY_WRITE)
61099 + reqmode |= GR_WRITE;
61100 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
61101 + reqmode |= GR_READ;
61102 +
61103 + mode =
61104 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61105 + mnt);
61106 +
61107 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61108 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61109 + reqmode & GR_READ ? " reading" : "",
61110 + reqmode & GR_WRITE ? " writing" : reqmode &
61111 + GR_APPEND ? " appending" : "");
61112 + return reqmode;
61113 + } else
61114 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61115 + {
61116 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61117 + reqmode & GR_READ ? " reading" : "",
61118 + reqmode & GR_WRITE ? " writing" : reqmode &
61119 + GR_APPEND ? " appending" : "");
61120 + return 0;
61121 + } else if (unlikely((mode & reqmode) != reqmode))
61122 + return 0;
61123 +
61124 + return reqmode;
61125 +}
61126 +
61127 +__u32
61128 +gr_acl_handle_creat(const struct dentry * dentry,
61129 + const struct dentry * p_dentry,
61130 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
61131 + const int imode)
61132 +{
61133 + __u32 reqmode = GR_WRITE | GR_CREATE;
61134 + __u32 mode;
61135 +
61136 + if (acc_mode & MAY_APPEND)
61137 + reqmode |= GR_APPEND;
61138 + // if a directory was required or the directory already exists, then
61139 + // don't count this open as a read
61140 + if ((acc_mode & MAY_READ) &&
61141 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
61142 + reqmode |= GR_READ;
61143 + if ((open_flags & O_CREAT) &&
61144 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61145 + reqmode |= GR_SETID;
61146 +
61147 + mode =
61148 + gr_check_create(dentry, p_dentry, p_mnt,
61149 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61150 +
61151 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61152 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61153 + reqmode & GR_READ ? " reading" : "",
61154 + reqmode & GR_WRITE ? " writing" : reqmode &
61155 + GR_APPEND ? " appending" : "");
61156 + return reqmode;
61157 + } else
61158 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61159 + {
61160 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61161 + reqmode & GR_READ ? " reading" : "",
61162 + reqmode & GR_WRITE ? " writing" : reqmode &
61163 + GR_APPEND ? " appending" : "");
61164 + return 0;
61165 + } else if (unlikely((mode & reqmode) != reqmode))
61166 + return 0;
61167 +
61168 + return reqmode;
61169 +}
61170 +
61171 +__u32
61172 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
61173 + const int fmode)
61174 +{
61175 + __u32 mode, reqmode = GR_FIND;
61176 +
61177 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
61178 + reqmode |= GR_EXEC;
61179 + if (fmode & S_IWOTH)
61180 + reqmode |= GR_WRITE;
61181 + if (fmode & S_IROTH)
61182 + reqmode |= GR_READ;
61183 +
61184 + mode =
61185 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61186 + mnt);
61187 +
61188 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61189 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61190 + reqmode & GR_READ ? " reading" : "",
61191 + reqmode & GR_WRITE ? " writing" : "",
61192 + reqmode & GR_EXEC ? " executing" : "");
61193 + return reqmode;
61194 + } else
61195 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61196 + {
61197 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61198 + reqmode & GR_READ ? " reading" : "",
61199 + reqmode & GR_WRITE ? " writing" : "",
61200 + reqmode & GR_EXEC ? " executing" : "");
61201 + return 0;
61202 + } else if (unlikely((mode & reqmode) != reqmode))
61203 + return 0;
61204 +
61205 + return reqmode;
61206 +}
61207 +
61208 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
61209 +{
61210 + __u32 mode;
61211 +
61212 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
61213 +
61214 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61215 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
61216 + return mode;
61217 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61218 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
61219 + return 0;
61220 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
61221 + return 0;
61222 +
61223 + return (reqmode);
61224 +}
61225 +
61226 +__u32
61227 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
61228 +{
61229 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
61230 +}
61231 +
61232 +__u32
61233 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
61234 +{
61235 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
61236 +}
61237 +
61238 +__u32
61239 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
61240 +{
61241 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
61242 +}
61243 +
61244 +__u32
61245 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
61246 +{
61247 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
61248 +}
61249 +
61250 +__u32
61251 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
61252 + umode_t *modeptr)
61253 +{
61254 + umode_t mode;
61255 +
61256 + *modeptr &= ~gr_acl_umask();
61257 + mode = *modeptr;
61258 +
61259 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
61260 + return 1;
61261 +
61262 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
61263 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
61264 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
61265 + GR_CHMOD_ACL_MSG);
61266 + } else {
61267 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
61268 + }
61269 +}
61270 +
61271 +__u32
61272 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
61273 +{
61274 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
61275 +}
61276 +
61277 +__u32
61278 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
61279 +{
61280 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
61281 +}
61282 +
61283 +__u32
61284 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
61285 +{
61286 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
61287 +}
61288 +
61289 +__u32
61290 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
61291 +{
61292 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
61293 + GR_UNIXCONNECT_ACL_MSG);
61294 +}
61295 +
61296 +/* hardlinks require at minimum create and link permission,
61297 + any additional privilege required is based on the
61298 + privilege of the file being linked to
61299 +*/
61300 +__u32
61301 +gr_acl_handle_link(const struct dentry * new_dentry,
61302 + const struct dentry * parent_dentry,
61303 + const struct vfsmount * parent_mnt,
61304 + const struct dentry * old_dentry,
61305 + const struct vfsmount * old_mnt, const struct filename *to)
61306 +{
61307 + __u32 mode;
61308 + __u32 needmode = GR_CREATE | GR_LINK;
61309 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
61310 +
61311 + mode =
61312 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
61313 + old_mnt);
61314 +
61315 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
61316 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61317 + return mode;
61318 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61319 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61320 + return 0;
61321 + } else if (unlikely((mode & needmode) != needmode))
61322 + return 0;
61323 +
61324 + return 1;
61325 +}
61326 +
61327 +__u32
61328 +gr_acl_handle_symlink(const struct dentry * new_dentry,
61329 + const struct dentry * parent_dentry,
61330 + const struct vfsmount * parent_mnt, const struct filename *from)
61331 +{
61332 + __u32 needmode = GR_WRITE | GR_CREATE;
61333 + __u32 mode;
61334 +
61335 + mode =
61336 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
61337 + GR_CREATE | GR_AUDIT_CREATE |
61338 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
61339 +
61340 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
61341 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61342 + return mode;
61343 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61344 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61345 + return 0;
61346 + } else if (unlikely((mode & needmode) != needmode))
61347 + return 0;
61348 +
61349 + return (GR_WRITE | GR_CREATE);
61350 +}
61351 +
61352 +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)
61353 +{
61354 + __u32 mode;
61355 +
61356 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61357 +
61358 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61359 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
61360 + return mode;
61361 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61362 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
61363 + return 0;
61364 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
61365 + return 0;
61366 +
61367 + return (reqmode);
61368 +}
61369 +
61370 +__u32
61371 +gr_acl_handle_mknod(const struct dentry * new_dentry,
61372 + const struct dentry * parent_dentry,
61373 + const struct vfsmount * parent_mnt,
61374 + const int mode)
61375 +{
61376 + __u32 reqmode = GR_WRITE | GR_CREATE;
61377 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61378 + reqmode |= GR_SETID;
61379 +
61380 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61381 + reqmode, GR_MKNOD_ACL_MSG);
61382 +}
61383 +
61384 +__u32
61385 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
61386 + const struct dentry *parent_dentry,
61387 + const struct vfsmount *parent_mnt)
61388 +{
61389 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61390 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
61391 +}
61392 +
61393 +#define RENAME_CHECK_SUCCESS(old, new) \
61394 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
61395 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
61396 +
61397 +int
61398 +gr_acl_handle_rename(struct dentry *new_dentry,
61399 + struct dentry *parent_dentry,
61400 + const struct vfsmount *parent_mnt,
61401 + struct dentry *old_dentry,
61402 + struct inode *old_parent_inode,
61403 + struct vfsmount *old_mnt, const struct filename *newname)
61404 +{
61405 + __u32 comp1, comp2;
61406 + int error = 0;
61407 +
61408 + if (unlikely(!gr_acl_is_enabled()))
61409 + return 0;
61410 +
61411 + if (!new_dentry->d_inode) {
61412 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
61413 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
61414 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
61415 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
61416 + GR_DELETE | GR_AUDIT_DELETE |
61417 + GR_AUDIT_READ | GR_AUDIT_WRITE |
61418 + GR_SUPPRESS, old_mnt);
61419 + } else {
61420 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
61421 + GR_CREATE | GR_DELETE |
61422 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
61423 + GR_AUDIT_READ | GR_AUDIT_WRITE |
61424 + GR_SUPPRESS, parent_mnt);
61425 + comp2 =
61426 + gr_search_file(old_dentry,
61427 + GR_READ | GR_WRITE | GR_AUDIT_READ |
61428 + GR_DELETE | GR_AUDIT_DELETE |
61429 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
61430 + }
61431 +
61432 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
61433 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
61434 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61435 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
61436 + && !(comp2 & GR_SUPPRESS)) {
61437 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61438 + error = -EACCES;
61439 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
61440 + error = -EACCES;
61441 +
61442 + return error;
61443 +}
61444 +
61445 +void
61446 +gr_acl_handle_exit(void)
61447 +{
61448 + u16 id;
61449 + char *rolename;
61450 +
61451 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
61452 + !(current->role->roletype & GR_ROLE_PERSIST))) {
61453 + id = current->acl_role_id;
61454 + rolename = current->role->rolename;
61455 + gr_set_acls(1);
61456 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
61457 + }
61458 +
61459 + gr_put_exec_file(current);
61460 + return;
61461 +}
61462 +
61463 +int
61464 +gr_acl_handle_procpidmem(const struct task_struct *task)
61465 +{
61466 + if (unlikely(!gr_acl_is_enabled()))
61467 + return 0;
61468 +
61469 + if (task != current && task->acl->mode & GR_PROTPROCFD)
61470 + return -EACCES;
61471 +
61472 + return 0;
61473 +}
61474 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
61475 new file mode 100644
61476 index 0000000..4699807
61477 --- /dev/null
61478 +++ b/grsecurity/gracl_ip.c
61479 @@ -0,0 +1,384 @@
61480 +#include <linux/kernel.h>
61481 +#include <asm/uaccess.h>
61482 +#include <asm/errno.h>
61483 +#include <net/sock.h>
61484 +#include <linux/file.h>
61485 +#include <linux/fs.h>
61486 +#include <linux/net.h>
61487 +#include <linux/in.h>
61488 +#include <linux/skbuff.h>
61489 +#include <linux/ip.h>
61490 +#include <linux/udp.h>
61491 +#include <linux/types.h>
61492 +#include <linux/sched.h>
61493 +#include <linux/netdevice.h>
61494 +#include <linux/inetdevice.h>
61495 +#include <linux/gracl.h>
61496 +#include <linux/grsecurity.h>
61497 +#include <linux/grinternal.h>
61498 +
61499 +#define GR_BIND 0x01
61500 +#define GR_CONNECT 0x02
61501 +#define GR_INVERT 0x04
61502 +#define GR_BINDOVERRIDE 0x08
61503 +#define GR_CONNECTOVERRIDE 0x10
61504 +#define GR_SOCK_FAMILY 0x20
61505 +
61506 +static const char * gr_protocols[IPPROTO_MAX] = {
61507 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
61508 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
61509 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
61510 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
61511 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
61512 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
61513 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
61514 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
61515 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
61516 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
61517 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
61518 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
61519 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
61520 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
61521 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
61522 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
61523 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
61524 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
61525 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
61526 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
61527 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
61528 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
61529 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
61530 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
61531 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
61532 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
61533 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
61534 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
61535 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
61536 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
61537 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
61538 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
61539 + };
61540 +
61541 +static const char * gr_socktypes[SOCK_MAX] = {
61542 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
61543 + "unknown:7", "unknown:8", "unknown:9", "packet"
61544 + };
61545 +
61546 +static const char * gr_sockfamilies[AF_MAX+1] = {
61547 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
61548 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
61549 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
61550 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
61551 + };
61552 +
61553 +const char *
61554 +gr_proto_to_name(unsigned char proto)
61555 +{
61556 + return gr_protocols[proto];
61557 +}
61558 +
61559 +const char *
61560 +gr_socktype_to_name(unsigned char type)
61561 +{
61562 + return gr_socktypes[type];
61563 +}
61564 +
61565 +const char *
61566 +gr_sockfamily_to_name(unsigned char family)
61567 +{
61568 + return gr_sockfamilies[family];
61569 +}
61570 +
61571 +int
61572 +gr_search_socket(const int domain, const int type, const int protocol)
61573 +{
61574 + struct acl_subject_label *curr;
61575 + const struct cred *cred = current_cred();
61576 +
61577 + if (unlikely(!gr_acl_is_enabled()))
61578 + goto exit;
61579 +
61580 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
61581 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
61582 + goto exit; // let the kernel handle it
61583 +
61584 + curr = current->acl;
61585 +
61586 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
61587 + /* the family is allowed, if this is PF_INET allow it only if
61588 + the extra sock type/protocol checks pass */
61589 + if (domain == PF_INET)
61590 + goto inet_check;
61591 + goto exit;
61592 + } else {
61593 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61594 + __u32 fakeip = 0;
61595 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61596 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61597 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61598 + gr_to_filename(current->exec_file->f_path.dentry,
61599 + current->exec_file->f_path.mnt) :
61600 + curr->filename, curr->filename,
61601 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
61602 + &current->signal->saved_ip);
61603 + goto exit;
61604 + }
61605 + goto exit_fail;
61606 + }
61607 +
61608 +inet_check:
61609 + /* the rest of this checking is for IPv4 only */
61610 + if (!curr->ips)
61611 + goto exit;
61612 +
61613 + if ((curr->ip_type & (1 << type)) &&
61614 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
61615 + goto exit;
61616 +
61617 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61618 + /* we don't place acls on raw sockets , and sometimes
61619 + dgram/ip sockets are opened for ioctl and not
61620 + bind/connect, so we'll fake a bind learn log */
61621 + if (type == SOCK_RAW || type == SOCK_PACKET) {
61622 + __u32 fakeip = 0;
61623 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61624 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61625 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61626 + gr_to_filename(current->exec_file->f_path.dentry,
61627 + current->exec_file->f_path.mnt) :
61628 + curr->filename, curr->filename,
61629 + &fakeip, 0, type,
61630 + protocol, GR_CONNECT, &current->signal->saved_ip);
61631 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
61632 + __u32 fakeip = 0;
61633 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61634 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61635 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61636 + gr_to_filename(current->exec_file->f_path.dentry,
61637 + current->exec_file->f_path.mnt) :
61638 + curr->filename, curr->filename,
61639 + &fakeip, 0, type,
61640 + protocol, GR_BIND, &current->signal->saved_ip);
61641 + }
61642 + /* we'll log when they use connect or bind */
61643 + goto exit;
61644 + }
61645 +
61646 +exit_fail:
61647 + if (domain == PF_INET)
61648 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
61649 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
61650 + else
61651 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
61652 + gr_socktype_to_name(type), protocol);
61653 +
61654 + return 0;
61655 +exit:
61656 + return 1;
61657 +}
61658 +
61659 +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)
61660 +{
61661 + if ((ip->mode & mode) &&
61662 + (ip_port >= ip->low) &&
61663 + (ip_port <= ip->high) &&
61664 + ((ntohl(ip_addr) & our_netmask) ==
61665 + (ntohl(our_addr) & our_netmask))
61666 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
61667 + && (ip->type & (1 << type))) {
61668 + if (ip->mode & GR_INVERT)
61669 + return 2; // specifically denied
61670 + else
61671 + return 1; // allowed
61672 + }
61673 +
61674 + return 0; // not specifically allowed, may continue parsing
61675 +}
61676 +
61677 +static int
61678 +gr_search_connectbind(const int full_mode, struct sock *sk,
61679 + struct sockaddr_in *addr, const int type)
61680 +{
61681 + char iface[IFNAMSIZ] = {0};
61682 + struct acl_subject_label *curr;
61683 + struct acl_ip_label *ip;
61684 + struct inet_sock *isk;
61685 + struct net_device *dev;
61686 + struct in_device *idev;
61687 + unsigned long i;
61688 + int ret;
61689 + int mode = full_mode & (GR_BIND | GR_CONNECT);
61690 + __u32 ip_addr = 0;
61691 + __u32 our_addr;
61692 + __u32 our_netmask;
61693 + char *p;
61694 + __u16 ip_port = 0;
61695 + const struct cred *cred = current_cred();
61696 +
61697 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
61698 + return 0;
61699 +
61700 + curr = current->acl;
61701 + isk = inet_sk(sk);
61702 +
61703 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
61704 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
61705 + addr->sin_addr.s_addr = curr->inaddr_any_override;
61706 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
61707 + struct sockaddr_in saddr;
61708 + int err;
61709 +
61710 + saddr.sin_family = AF_INET;
61711 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
61712 + saddr.sin_port = isk->inet_sport;
61713 +
61714 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
61715 + if (err)
61716 + return err;
61717 +
61718 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
61719 + if (err)
61720 + return err;
61721 + }
61722 +
61723 + if (!curr->ips)
61724 + return 0;
61725 +
61726 + ip_addr = addr->sin_addr.s_addr;
61727 + ip_port = ntohs(addr->sin_port);
61728 +
61729 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61730 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61731 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61732 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61733 + gr_to_filename(current->exec_file->f_path.dentry,
61734 + current->exec_file->f_path.mnt) :
61735 + curr->filename, curr->filename,
61736 + &ip_addr, ip_port, type,
61737 + sk->sk_protocol, mode, &current->signal->saved_ip);
61738 + return 0;
61739 + }
61740 +
61741 + for (i = 0; i < curr->ip_num; i++) {
61742 + ip = *(curr->ips + i);
61743 + if (ip->iface != NULL) {
61744 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
61745 + p = strchr(iface, ':');
61746 + if (p != NULL)
61747 + *p = '\0';
61748 + dev = dev_get_by_name(sock_net(sk), iface);
61749 + if (dev == NULL)
61750 + continue;
61751 + idev = in_dev_get(dev);
61752 + if (idev == NULL) {
61753 + dev_put(dev);
61754 + continue;
61755 + }
61756 + rcu_read_lock();
61757 + for_ifa(idev) {
61758 + if (!strcmp(ip->iface, ifa->ifa_label)) {
61759 + our_addr = ifa->ifa_address;
61760 + our_netmask = 0xffffffff;
61761 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
61762 + if (ret == 1) {
61763 + rcu_read_unlock();
61764 + in_dev_put(idev);
61765 + dev_put(dev);
61766 + return 0;
61767 + } else if (ret == 2) {
61768 + rcu_read_unlock();
61769 + in_dev_put(idev);
61770 + dev_put(dev);
61771 + goto denied;
61772 + }
61773 + }
61774 + } endfor_ifa(idev);
61775 + rcu_read_unlock();
61776 + in_dev_put(idev);
61777 + dev_put(dev);
61778 + } else {
61779 + our_addr = ip->addr;
61780 + our_netmask = ip->netmask;
61781 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
61782 + if (ret == 1)
61783 + return 0;
61784 + else if (ret == 2)
61785 + goto denied;
61786 + }
61787 + }
61788 +
61789 +denied:
61790 + if (mode == GR_BIND)
61791 + 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));
61792 + else if (mode == GR_CONNECT)
61793 + 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));
61794 +
61795 + return -EACCES;
61796 +}
61797 +
61798 +int
61799 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
61800 +{
61801 + /* always allow disconnection of dgram sockets with connect */
61802 + if (addr->sin_family == AF_UNSPEC)
61803 + return 0;
61804 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
61805 +}
61806 +
61807 +int
61808 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
61809 +{
61810 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
61811 +}
61812 +
61813 +int gr_search_listen(struct socket *sock)
61814 +{
61815 + struct sock *sk = sock->sk;
61816 + struct sockaddr_in addr;
61817 +
61818 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
61819 + addr.sin_port = inet_sk(sk)->inet_sport;
61820 +
61821 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
61822 +}
61823 +
61824 +int gr_search_accept(struct socket *sock)
61825 +{
61826 + struct sock *sk = sock->sk;
61827 + struct sockaddr_in addr;
61828 +
61829 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
61830 + addr.sin_port = inet_sk(sk)->inet_sport;
61831 +
61832 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
61833 +}
61834 +
61835 +int
61836 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
61837 +{
61838 + if (addr)
61839 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
61840 + else {
61841 + struct sockaddr_in sin;
61842 + const struct inet_sock *inet = inet_sk(sk);
61843 +
61844 + sin.sin_addr.s_addr = inet->inet_daddr;
61845 + sin.sin_port = inet->inet_dport;
61846 +
61847 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
61848 + }
61849 +}
61850 +
61851 +int
61852 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
61853 +{
61854 + struct sockaddr_in sin;
61855 +
61856 + if (unlikely(skb->len < sizeof (struct udphdr)))
61857 + return 0; // skip this packet
61858 +
61859 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
61860 + sin.sin_port = udp_hdr(skb)->source;
61861 +
61862 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
61863 +}
61864 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
61865 new file mode 100644
61866 index 0000000..25f54ef
61867 --- /dev/null
61868 +++ b/grsecurity/gracl_learn.c
61869 @@ -0,0 +1,207 @@
61870 +#include <linux/kernel.h>
61871 +#include <linux/mm.h>
61872 +#include <linux/sched.h>
61873 +#include <linux/poll.h>
61874 +#include <linux/string.h>
61875 +#include <linux/file.h>
61876 +#include <linux/types.h>
61877 +#include <linux/vmalloc.h>
61878 +#include <linux/grinternal.h>
61879 +
61880 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
61881 + size_t count, loff_t *ppos);
61882 +extern int gr_acl_is_enabled(void);
61883 +
61884 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
61885 +static int gr_learn_attached;
61886 +
61887 +/* use a 512k buffer */
61888 +#define LEARN_BUFFER_SIZE (512 * 1024)
61889 +
61890 +static DEFINE_SPINLOCK(gr_learn_lock);
61891 +static DEFINE_MUTEX(gr_learn_user_mutex);
61892 +
61893 +/* we need to maintain two buffers, so that the kernel context of grlearn
61894 + uses a semaphore around the userspace copying, and the other kernel contexts
61895 + use a spinlock when copying into the buffer, since they cannot sleep
61896 +*/
61897 +static char *learn_buffer;
61898 +static char *learn_buffer_user;
61899 +static int learn_buffer_len;
61900 +static int learn_buffer_user_len;
61901 +
61902 +static ssize_t
61903 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
61904 +{
61905 + DECLARE_WAITQUEUE(wait, current);
61906 + ssize_t retval = 0;
61907 +
61908 + add_wait_queue(&learn_wait, &wait);
61909 + set_current_state(TASK_INTERRUPTIBLE);
61910 + do {
61911 + mutex_lock(&gr_learn_user_mutex);
61912 + spin_lock(&gr_learn_lock);
61913 + if (learn_buffer_len)
61914 + break;
61915 + spin_unlock(&gr_learn_lock);
61916 + mutex_unlock(&gr_learn_user_mutex);
61917 + if (file->f_flags & O_NONBLOCK) {
61918 + retval = -EAGAIN;
61919 + goto out;
61920 + }
61921 + if (signal_pending(current)) {
61922 + retval = -ERESTARTSYS;
61923 + goto out;
61924 + }
61925 +
61926 + schedule();
61927 + } while (1);
61928 +
61929 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
61930 + learn_buffer_user_len = learn_buffer_len;
61931 + retval = learn_buffer_len;
61932 + learn_buffer_len = 0;
61933 +
61934 + spin_unlock(&gr_learn_lock);
61935 +
61936 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
61937 + retval = -EFAULT;
61938 +
61939 + mutex_unlock(&gr_learn_user_mutex);
61940 +out:
61941 + set_current_state(TASK_RUNNING);
61942 + remove_wait_queue(&learn_wait, &wait);
61943 + return retval;
61944 +}
61945 +
61946 +static unsigned int
61947 +poll_learn(struct file * file, poll_table * wait)
61948 +{
61949 + poll_wait(file, &learn_wait, wait);
61950 +
61951 + if (learn_buffer_len)
61952 + return (POLLIN | POLLRDNORM);
61953 +
61954 + return 0;
61955 +}
61956 +
61957 +void
61958 +gr_clear_learn_entries(void)
61959 +{
61960 + char *tmp;
61961 +
61962 + mutex_lock(&gr_learn_user_mutex);
61963 + spin_lock(&gr_learn_lock);
61964 + tmp = learn_buffer;
61965 + learn_buffer = NULL;
61966 + spin_unlock(&gr_learn_lock);
61967 + if (tmp)
61968 + vfree(tmp);
61969 + if (learn_buffer_user != NULL) {
61970 + vfree(learn_buffer_user);
61971 + learn_buffer_user = NULL;
61972 + }
61973 + learn_buffer_len = 0;
61974 + mutex_unlock(&gr_learn_user_mutex);
61975 +
61976 + return;
61977 +}
61978 +
61979 +void
61980 +gr_add_learn_entry(const char *fmt, ...)
61981 +{
61982 + va_list args;
61983 + unsigned int len;
61984 +
61985 + if (!gr_learn_attached)
61986 + return;
61987 +
61988 + spin_lock(&gr_learn_lock);
61989 +
61990 + /* leave a gap at the end so we know when it's "full" but don't have to
61991 + compute the exact length of the string we're trying to append
61992 + */
61993 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
61994 + spin_unlock(&gr_learn_lock);
61995 + wake_up_interruptible(&learn_wait);
61996 + return;
61997 + }
61998 + if (learn_buffer == NULL) {
61999 + spin_unlock(&gr_learn_lock);
62000 + return;
62001 + }
62002 +
62003 + va_start(args, fmt);
62004 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
62005 + va_end(args);
62006 +
62007 + learn_buffer_len += len + 1;
62008 +
62009 + spin_unlock(&gr_learn_lock);
62010 + wake_up_interruptible(&learn_wait);
62011 +
62012 + return;
62013 +}
62014 +
62015 +static int
62016 +open_learn(struct inode *inode, struct file *file)
62017 +{
62018 + if (file->f_mode & FMODE_READ && gr_learn_attached)
62019 + return -EBUSY;
62020 + if (file->f_mode & FMODE_READ) {
62021 + int retval = 0;
62022 + mutex_lock(&gr_learn_user_mutex);
62023 + if (learn_buffer == NULL)
62024 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
62025 + if (learn_buffer_user == NULL)
62026 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
62027 + if (learn_buffer == NULL) {
62028 + retval = -ENOMEM;
62029 + goto out_error;
62030 + }
62031 + if (learn_buffer_user == NULL) {
62032 + retval = -ENOMEM;
62033 + goto out_error;
62034 + }
62035 + learn_buffer_len = 0;
62036 + learn_buffer_user_len = 0;
62037 + gr_learn_attached = 1;
62038 +out_error:
62039 + mutex_unlock(&gr_learn_user_mutex);
62040 + return retval;
62041 + }
62042 + return 0;
62043 +}
62044 +
62045 +static int
62046 +close_learn(struct inode *inode, struct file *file)
62047 +{
62048 + if (file->f_mode & FMODE_READ) {
62049 + char *tmp = NULL;
62050 + mutex_lock(&gr_learn_user_mutex);
62051 + spin_lock(&gr_learn_lock);
62052 + tmp = learn_buffer;
62053 + learn_buffer = NULL;
62054 + spin_unlock(&gr_learn_lock);
62055 + if (tmp)
62056 + vfree(tmp);
62057 + if (learn_buffer_user != NULL) {
62058 + vfree(learn_buffer_user);
62059 + learn_buffer_user = NULL;
62060 + }
62061 + learn_buffer_len = 0;
62062 + learn_buffer_user_len = 0;
62063 + gr_learn_attached = 0;
62064 + mutex_unlock(&gr_learn_user_mutex);
62065 + }
62066 +
62067 + return 0;
62068 +}
62069 +
62070 +const struct file_operations grsec_fops = {
62071 + .read = read_learn,
62072 + .write = write_grsec_handler,
62073 + .open = open_learn,
62074 + .release = close_learn,
62075 + .poll = poll_learn,
62076 +};
62077 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
62078 new file mode 100644
62079 index 0000000..39645c9
62080 --- /dev/null
62081 +++ b/grsecurity/gracl_res.c
62082 @@ -0,0 +1,68 @@
62083 +#include <linux/kernel.h>
62084 +#include <linux/sched.h>
62085 +#include <linux/gracl.h>
62086 +#include <linux/grinternal.h>
62087 +
62088 +static const char *restab_log[] = {
62089 + [RLIMIT_CPU] = "RLIMIT_CPU",
62090 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
62091 + [RLIMIT_DATA] = "RLIMIT_DATA",
62092 + [RLIMIT_STACK] = "RLIMIT_STACK",
62093 + [RLIMIT_CORE] = "RLIMIT_CORE",
62094 + [RLIMIT_RSS] = "RLIMIT_RSS",
62095 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
62096 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
62097 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
62098 + [RLIMIT_AS] = "RLIMIT_AS",
62099 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
62100 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
62101 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
62102 + [RLIMIT_NICE] = "RLIMIT_NICE",
62103 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
62104 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
62105 + [GR_CRASH_RES] = "RLIMIT_CRASH"
62106 +};
62107 +
62108 +void
62109 +gr_log_resource(const struct task_struct *task,
62110 + const int res, const unsigned long wanted, const int gt)
62111 +{
62112 + const struct cred *cred;
62113 + unsigned long rlim;
62114 +
62115 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
62116 + return;
62117 +
62118 + // not yet supported resource
62119 + if (unlikely(!restab_log[res]))
62120 + return;
62121 +
62122 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
62123 + rlim = task_rlimit_max(task, res);
62124 + else
62125 + rlim = task_rlimit(task, res);
62126 +
62127 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
62128 + return;
62129 +
62130 + rcu_read_lock();
62131 + cred = __task_cred(task);
62132 +
62133 + if (res == RLIMIT_NPROC &&
62134 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
62135 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
62136 + goto out_rcu_unlock;
62137 + else if (res == RLIMIT_MEMLOCK &&
62138 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
62139 + goto out_rcu_unlock;
62140 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
62141 + goto out_rcu_unlock;
62142 + rcu_read_unlock();
62143 +
62144 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
62145 +
62146 + return;
62147 +out_rcu_unlock:
62148 + rcu_read_unlock();
62149 + return;
62150 +}
62151 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
62152 new file mode 100644
62153 index 0000000..8c8fc9d
62154 --- /dev/null
62155 +++ b/grsecurity/gracl_segv.c
62156 @@ -0,0 +1,303 @@
62157 +#include <linux/kernel.h>
62158 +#include <linux/mm.h>
62159 +#include <asm/uaccess.h>
62160 +#include <asm/errno.h>
62161 +#include <asm/mman.h>
62162 +#include <net/sock.h>
62163 +#include <linux/file.h>
62164 +#include <linux/fs.h>
62165 +#include <linux/net.h>
62166 +#include <linux/in.h>
62167 +#include <linux/slab.h>
62168 +#include <linux/types.h>
62169 +#include <linux/sched.h>
62170 +#include <linux/timer.h>
62171 +#include <linux/gracl.h>
62172 +#include <linux/grsecurity.h>
62173 +#include <linux/grinternal.h>
62174 +
62175 +static struct crash_uid *uid_set;
62176 +static unsigned short uid_used;
62177 +static DEFINE_SPINLOCK(gr_uid_lock);
62178 +extern rwlock_t gr_inode_lock;
62179 +extern struct acl_subject_label *
62180 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
62181 + struct acl_role_label *role);
62182 +
62183 +#ifdef CONFIG_BTRFS_FS
62184 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
62185 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
62186 +#endif
62187 +
62188 +static inline dev_t __get_dev(const struct dentry *dentry)
62189 +{
62190 +#ifdef CONFIG_BTRFS_FS
62191 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
62192 + return get_btrfs_dev_from_inode(dentry->d_inode);
62193 + else
62194 +#endif
62195 + return dentry->d_inode->i_sb->s_dev;
62196 +}
62197 +
62198 +int
62199 +gr_init_uidset(void)
62200 +{
62201 + uid_set =
62202 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
62203 + uid_used = 0;
62204 +
62205 + return uid_set ? 1 : 0;
62206 +}
62207 +
62208 +void
62209 +gr_free_uidset(void)
62210 +{
62211 + if (uid_set)
62212 + kfree(uid_set);
62213 +
62214 + return;
62215 +}
62216 +
62217 +int
62218 +gr_find_uid(const uid_t uid)
62219 +{
62220 + struct crash_uid *tmp = uid_set;
62221 + uid_t buid;
62222 + int low = 0, high = uid_used - 1, mid;
62223 +
62224 + while (high >= low) {
62225 + mid = (low + high) >> 1;
62226 + buid = tmp[mid].uid;
62227 + if (buid == uid)
62228 + return mid;
62229 + if (buid > uid)
62230 + high = mid - 1;
62231 + if (buid < uid)
62232 + low = mid + 1;
62233 + }
62234 +
62235 + return -1;
62236 +}
62237 +
62238 +static __inline__ void
62239 +gr_insertsort(void)
62240 +{
62241 + unsigned short i, j;
62242 + struct crash_uid index;
62243 +
62244 + for (i = 1; i < uid_used; i++) {
62245 + index = uid_set[i];
62246 + j = i;
62247 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
62248 + uid_set[j] = uid_set[j - 1];
62249 + j--;
62250 + }
62251 + uid_set[j] = index;
62252 + }
62253 +
62254 + return;
62255 +}
62256 +
62257 +static __inline__ void
62258 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
62259 +{
62260 + int loc;
62261 + uid_t uid = GR_GLOBAL_UID(kuid);
62262 +
62263 + if (uid_used == GR_UIDTABLE_MAX)
62264 + return;
62265 +
62266 + loc = gr_find_uid(uid);
62267 +
62268 + if (loc >= 0) {
62269 + uid_set[loc].expires = expires;
62270 + return;
62271 + }
62272 +
62273 + uid_set[uid_used].uid = uid;
62274 + uid_set[uid_used].expires = expires;
62275 + uid_used++;
62276 +
62277 + gr_insertsort();
62278 +
62279 + return;
62280 +}
62281 +
62282 +void
62283 +gr_remove_uid(const unsigned short loc)
62284 +{
62285 + unsigned short i;
62286 +
62287 + for (i = loc + 1; i < uid_used; i++)
62288 + uid_set[i - 1] = uid_set[i];
62289 +
62290 + uid_used--;
62291 +
62292 + return;
62293 +}
62294 +
62295 +int
62296 +gr_check_crash_uid(const kuid_t kuid)
62297 +{
62298 + int loc;
62299 + int ret = 0;
62300 + uid_t uid;
62301 +
62302 + if (unlikely(!gr_acl_is_enabled()))
62303 + return 0;
62304 +
62305 + uid = GR_GLOBAL_UID(kuid);
62306 +
62307 + spin_lock(&gr_uid_lock);
62308 + loc = gr_find_uid(uid);
62309 +
62310 + if (loc < 0)
62311 + goto out_unlock;
62312 +
62313 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
62314 + gr_remove_uid(loc);
62315 + else
62316 + ret = 1;
62317 +
62318 +out_unlock:
62319 + spin_unlock(&gr_uid_lock);
62320 + return ret;
62321 +}
62322 +
62323 +static __inline__ int
62324 +proc_is_setxid(const struct cred *cred)
62325 +{
62326 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
62327 + !uid_eq(cred->uid, cred->fsuid))
62328 + return 1;
62329 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
62330 + !gid_eq(cred->gid, cred->fsgid))
62331 + return 1;
62332 +
62333 + return 0;
62334 +}
62335 +
62336 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
62337 +
62338 +void
62339 +gr_handle_crash(struct task_struct *task, const int sig)
62340 +{
62341 + struct acl_subject_label *curr;
62342 + struct task_struct *tsk, *tsk2;
62343 + const struct cred *cred;
62344 + const struct cred *cred2;
62345 +
62346 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
62347 + return;
62348 +
62349 + if (unlikely(!gr_acl_is_enabled()))
62350 + return;
62351 +
62352 + curr = task->acl;
62353 +
62354 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
62355 + return;
62356 +
62357 + if (time_before_eq(curr->expires, get_seconds())) {
62358 + curr->expires = 0;
62359 + curr->crashes = 0;
62360 + }
62361 +
62362 + curr->crashes++;
62363 +
62364 + if (!curr->expires)
62365 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
62366 +
62367 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62368 + time_after(curr->expires, get_seconds())) {
62369 + rcu_read_lock();
62370 + cred = __task_cred(task);
62371 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
62372 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62373 + spin_lock(&gr_uid_lock);
62374 + gr_insert_uid(cred->uid, curr->expires);
62375 + spin_unlock(&gr_uid_lock);
62376 + curr->expires = 0;
62377 + curr->crashes = 0;
62378 + read_lock(&tasklist_lock);
62379 + do_each_thread(tsk2, tsk) {
62380 + cred2 = __task_cred(tsk);
62381 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
62382 + gr_fake_force_sig(SIGKILL, tsk);
62383 + } while_each_thread(tsk2, tsk);
62384 + read_unlock(&tasklist_lock);
62385 + } else {
62386 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62387 + read_lock(&tasklist_lock);
62388 + read_lock(&grsec_exec_file_lock);
62389 + do_each_thread(tsk2, tsk) {
62390 + if (likely(tsk != task)) {
62391 + // if this thread has the same subject as the one that triggered
62392 + // RES_CRASH and it's the same binary, kill it
62393 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
62394 + gr_fake_force_sig(SIGKILL, tsk);
62395 + }
62396 + } while_each_thread(tsk2, tsk);
62397 + read_unlock(&grsec_exec_file_lock);
62398 + read_unlock(&tasklist_lock);
62399 + }
62400 + rcu_read_unlock();
62401 + }
62402 +
62403 + return;
62404 +}
62405 +
62406 +int
62407 +gr_check_crash_exec(const struct file *filp)
62408 +{
62409 + struct acl_subject_label *curr;
62410 +
62411 + if (unlikely(!gr_acl_is_enabled()))
62412 + return 0;
62413 +
62414 + read_lock(&gr_inode_lock);
62415 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
62416 + __get_dev(filp->f_path.dentry),
62417 + current->role);
62418 + read_unlock(&gr_inode_lock);
62419 +
62420 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
62421 + (!curr->crashes && !curr->expires))
62422 + return 0;
62423 +
62424 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62425 + time_after(curr->expires, get_seconds()))
62426 + return 1;
62427 + else if (time_before_eq(curr->expires, get_seconds())) {
62428 + curr->crashes = 0;
62429 + curr->expires = 0;
62430 + }
62431 +
62432 + return 0;
62433 +}
62434 +
62435 +void
62436 +gr_handle_alertkill(struct task_struct *task)
62437 +{
62438 + struct acl_subject_label *curracl;
62439 + __u32 curr_ip;
62440 + struct task_struct *p, *p2;
62441 +
62442 + if (unlikely(!gr_acl_is_enabled()))
62443 + return;
62444 +
62445 + curracl = task->acl;
62446 + curr_ip = task->signal->curr_ip;
62447 +
62448 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
62449 + read_lock(&tasklist_lock);
62450 + do_each_thread(p2, p) {
62451 + if (p->signal->curr_ip == curr_ip)
62452 + gr_fake_force_sig(SIGKILL, p);
62453 + } while_each_thread(p2, p);
62454 + read_unlock(&tasklist_lock);
62455 + } else if (curracl->mode & GR_KILLPROC)
62456 + gr_fake_force_sig(SIGKILL, task);
62457 +
62458 + return;
62459 +}
62460 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
62461 new file mode 100644
62462 index 0000000..98011b0
62463 --- /dev/null
62464 +++ b/grsecurity/gracl_shm.c
62465 @@ -0,0 +1,40 @@
62466 +#include <linux/kernel.h>
62467 +#include <linux/mm.h>
62468 +#include <linux/sched.h>
62469 +#include <linux/file.h>
62470 +#include <linux/ipc.h>
62471 +#include <linux/gracl.h>
62472 +#include <linux/grsecurity.h>
62473 +#include <linux/grinternal.h>
62474 +
62475 +int
62476 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62477 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
62478 +{
62479 + struct task_struct *task;
62480 +
62481 + if (!gr_acl_is_enabled())
62482 + return 1;
62483 +
62484 + rcu_read_lock();
62485 + read_lock(&tasklist_lock);
62486 +
62487 + task = find_task_by_vpid(shm_cprid);
62488 +
62489 + if (unlikely(!task))
62490 + task = find_task_by_vpid(shm_lapid);
62491 +
62492 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
62493 + (task_pid_nr(task) == shm_lapid)) &&
62494 + (task->acl->mode & GR_PROTSHM) &&
62495 + (task->acl != current->acl))) {
62496 + read_unlock(&tasklist_lock);
62497 + rcu_read_unlock();
62498 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
62499 + return 0;
62500 + }
62501 + read_unlock(&tasklist_lock);
62502 + rcu_read_unlock();
62503 +
62504 + return 1;
62505 +}
62506 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
62507 new file mode 100644
62508 index 0000000..bc0be01
62509 --- /dev/null
62510 +++ b/grsecurity/grsec_chdir.c
62511 @@ -0,0 +1,19 @@
62512 +#include <linux/kernel.h>
62513 +#include <linux/sched.h>
62514 +#include <linux/fs.h>
62515 +#include <linux/file.h>
62516 +#include <linux/grsecurity.h>
62517 +#include <linux/grinternal.h>
62518 +
62519 +void
62520 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
62521 +{
62522 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62523 + if ((grsec_enable_chdir && grsec_enable_group &&
62524 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
62525 + !grsec_enable_group)) {
62526 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
62527 + }
62528 +#endif
62529 + return;
62530 +}
62531 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
62532 new file mode 100644
62533 index 0000000..6d2de57
62534 --- /dev/null
62535 +++ b/grsecurity/grsec_chroot.c
62536 @@ -0,0 +1,357 @@
62537 +#include <linux/kernel.h>
62538 +#include <linux/module.h>
62539 +#include <linux/sched.h>
62540 +#include <linux/file.h>
62541 +#include <linux/fs.h>
62542 +#include <linux/mount.h>
62543 +#include <linux/types.h>
62544 +#include "../fs/mount.h"
62545 +#include <linux/grsecurity.h>
62546 +#include <linux/grinternal.h>
62547 +
62548 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
62549 +{
62550 +#ifdef CONFIG_GRKERNSEC
62551 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
62552 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
62553 + task->gr_is_chrooted = 1;
62554 + else
62555 + task->gr_is_chrooted = 0;
62556 +
62557 + task->gr_chroot_dentry = path->dentry;
62558 +#endif
62559 + return;
62560 +}
62561 +
62562 +void gr_clear_chroot_entries(struct task_struct *task)
62563 +{
62564 +#ifdef CONFIG_GRKERNSEC
62565 + task->gr_is_chrooted = 0;
62566 + task->gr_chroot_dentry = NULL;
62567 +#endif
62568 + return;
62569 +}
62570 +
62571 +int
62572 +gr_handle_chroot_unix(const pid_t pid)
62573 +{
62574 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62575 + struct task_struct *p;
62576 +
62577 + if (unlikely(!grsec_enable_chroot_unix))
62578 + return 1;
62579 +
62580 + if (likely(!proc_is_chrooted(current)))
62581 + return 1;
62582 +
62583 + rcu_read_lock();
62584 + read_lock(&tasklist_lock);
62585 + p = find_task_by_vpid_unrestricted(pid);
62586 + if (unlikely(p && !have_same_root(current, p))) {
62587 + read_unlock(&tasklist_lock);
62588 + rcu_read_unlock();
62589 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
62590 + return 0;
62591 + }
62592 + read_unlock(&tasklist_lock);
62593 + rcu_read_unlock();
62594 +#endif
62595 + return 1;
62596 +}
62597 +
62598 +int
62599 +gr_handle_chroot_nice(void)
62600 +{
62601 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62602 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
62603 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
62604 + return -EPERM;
62605 + }
62606 +#endif
62607 + return 0;
62608 +}
62609 +
62610 +int
62611 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
62612 +{
62613 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62614 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
62615 + && proc_is_chrooted(current)) {
62616 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
62617 + return -EACCES;
62618 + }
62619 +#endif
62620 + return 0;
62621 +}
62622 +
62623 +int
62624 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
62625 +{
62626 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62627 + struct task_struct *p;
62628 + int ret = 0;
62629 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
62630 + return ret;
62631 +
62632 + read_lock(&tasklist_lock);
62633 + do_each_pid_task(pid, type, p) {
62634 + if (!have_same_root(current, p)) {
62635 + ret = 1;
62636 + goto out;
62637 + }
62638 + } while_each_pid_task(pid, type, p);
62639 +out:
62640 + read_unlock(&tasklist_lock);
62641 + return ret;
62642 +#endif
62643 + return 0;
62644 +}
62645 +
62646 +int
62647 +gr_pid_is_chrooted(struct task_struct *p)
62648 +{
62649 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62650 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
62651 + return 0;
62652 +
62653 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
62654 + !have_same_root(current, p)) {
62655 + return 1;
62656 + }
62657 +#endif
62658 + return 0;
62659 +}
62660 +
62661 +EXPORT_SYMBOL(gr_pid_is_chrooted);
62662 +
62663 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
62664 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
62665 +{
62666 + struct path path, currentroot;
62667 + int ret = 0;
62668 +
62669 + path.dentry = (struct dentry *)u_dentry;
62670 + path.mnt = (struct vfsmount *)u_mnt;
62671 + get_fs_root(current->fs, &currentroot);
62672 + if (path_is_under(&path, &currentroot))
62673 + ret = 1;
62674 + path_put(&currentroot);
62675 +
62676 + return ret;
62677 +}
62678 +#endif
62679 +
62680 +int
62681 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
62682 +{
62683 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62684 + if (!grsec_enable_chroot_fchdir)
62685 + return 1;
62686 +
62687 + if (!proc_is_chrooted(current))
62688 + return 1;
62689 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
62690 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
62691 + return 0;
62692 + }
62693 +#endif
62694 + return 1;
62695 +}
62696 +
62697 +int
62698 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62699 + const time_t shm_createtime)
62700 +{
62701 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62702 + struct task_struct *p;
62703 + time_t starttime;
62704 +
62705 + if (unlikely(!grsec_enable_chroot_shmat))
62706 + return 1;
62707 +
62708 + if (likely(!proc_is_chrooted(current)))
62709 + return 1;
62710 +
62711 + rcu_read_lock();
62712 + read_lock(&tasklist_lock);
62713 +
62714 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
62715 + starttime = p->start_time.tv_sec;
62716 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
62717 + if (have_same_root(current, p)) {
62718 + goto allow;
62719 + } else {
62720 + read_unlock(&tasklist_lock);
62721 + rcu_read_unlock();
62722 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
62723 + return 0;
62724 + }
62725 + }
62726 + /* creator exited, pid reuse, fall through to next check */
62727 + }
62728 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
62729 + if (unlikely(!have_same_root(current, p))) {
62730 + read_unlock(&tasklist_lock);
62731 + rcu_read_unlock();
62732 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
62733 + return 0;
62734 + }
62735 + }
62736 +
62737 +allow:
62738 + read_unlock(&tasklist_lock);
62739 + rcu_read_unlock();
62740 +#endif
62741 + return 1;
62742 +}
62743 +
62744 +void
62745 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
62746 +{
62747 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62748 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
62749 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
62750 +#endif
62751 + return;
62752 +}
62753 +
62754 +int
62755 +gr_handle_chroot_mknod(const struct dentry *dentry,
62756 + const struct vfsmount *mnt, const int mode)
62757 +{
62758 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62759 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
62760 + proc_is_chrooted(current)) {
62761 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
62762 + return -EPERM;
62763 + }
62764 +#endif
62765 + return 0;
62766 +}
62767 +
62768 +int
62769 +gr_handle_chroot_mount(const struct dentry *dentry,
62770 + const struct vfsmount *mnt, const char *dev_name)
62771 +{
62772 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62773 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
62774 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
62775 + return -EPERM;
62776 + }
62777 +#endif
62778 + return 0;
62779 +}
62780 +
62781 +int
62782 +gr_handle_chroot_pivot(void)
62783 +{
62784 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62785 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
62786 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
62787 + return -EPERM;
62788 + }
62789 +#endif
62790 + return 0;
62791 +}
62792 +
62793 +int
62794 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
62795 +{
62796 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62797 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
62798 + !gr_is_outside_chroot(dentry, mnt)) {
62799 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
62800 + return -EPERM;
62801 + }
62802 +#endif
62803 + return 0;
62804 +}
62805 +
62806 +extern const char *captab_log[];
62807 +extern int captab_log_entries;
62808 +
62809 +int
62810 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62811 +{
62812 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62813 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
62814 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
62815 + if (cap_raised(chroot_caps, cap)) {
62816 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
62817 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
62818 + }
62819 + return 0;
62820 + }
62821 + }
62822 +#endif
62823 + return 1;
62824 +}
62825 +
62826 +int
62827 +gr_chroot_is_capable(const int cap)
62828 +{
62829 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62830 + return gr_task_chroot_is_capable(current, current_cred(), cap);
62831 +#endif
62832 + return 1;
62833 +}
62834 +
62835 +int
62836 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
62837 +{
62838 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62839 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
62840 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
62841 + if (cap_raised(chroot_caps, cap)) {
62842 + return 0;
62843 + }
62844 + }
62845 +#endif
62846 + return 1;
62847 +}
62848 +
62849 +int
62850 +gr_chroot_is_capable_nolog(const int cap)
62851 +{
62852 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62853 + return gr_task_chroot_is_capable_nolog(current, cap);
62854 +#endif
62855 + return 1;
62856 +}
62857 +
62858 +int
62859 +gr_handle_chroot_sysctl(const int op)
62860 +{
62861 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62862 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
62863 + proc_is_chrooted(current))
62864 + return -EACCES;
62865 +#endif
62866 + return 0;
62867 +}
62868 +
62869 +void
62870 +gr_handle_chroot_chdir(struct path *path)
62871 +{
62872 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62873 + if (grsec_enable_chroot_chdir)
62874 + set_fs_pwd(current->fs, path);
62875 +#endif
62876 + return;
62877 +}
62878 +
62879 +int
62880 +gr_handle_chroot_chmod(const struct dentry *dentry,
62881 + const struct vfsmount *mnt, const int mode)
62882 +{
62883 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62884 + /* allow chmod +s on directories, but not files */
62885 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
62886 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
62887 + proc_is_chrooted(current)) {
62888 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
62889 + return -EPERM;
62890 + }
62891 +#endif
62892 + return 0;
62893 +}
62894 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
62895 new file mode 100644
62896 index 0000000..207d409
62897 --- /dev/null
62898 +++ b/grsecurity/grsec_disabled.c
62899 @@ -0,0 +1,434 @@
62900 +#include <linux/kernel.h>
62901 +#include <linux/module.h>
62902 +#include <linux/sched.h>
62903 +#include <linux/file.h>
62904 +#include <linux/fs.h>
62905 +#include <linux/kdev_t.h>
62906 +#include <linux/net.h>
62907 +#include <linux/in.h>
62908 +#include <linux/ip.h>
62909 +#include <linux/skbuff.h>
62910 +#include <linux/sysctl.h>
62911 +
62912 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62913 +void
62914 +pax_set_initial_flags(struct linux_binprm *bprm)
62915 +{
62916 + return;
62917 +}
62918 +#endif
62919 +
62920 +#ifdef CONFIG_SYSCTL
62921 +__u32
62922 +gr_handle_sysctl(const struct ctl_table * table, const int op)
62923 +{
62924 + return 0;
62925 +}
62926 +#endif
62927 +
62928 +#ifdef CONFIG_TASKSTATS
62929 +int gr_is_taskstats_denied(int pid)
62930 +{
62931 + return 0;
62932 +}
62933 +#endif
62934 +
62935 +int
62936 +gr_acl_is_enabled(void)
62937 +{
62938 + return 0;
62939 +}
62940 +
62941 +void
62942 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
62943 +{
62944 + return;
62945 +}
62946 +
62947 +int
62948 +gr_handle_rawio(const struct inode *inode)
62949 +{
62950 + return 0;
62951 +}
62952 +
62953 +void
62954 +gr_acl_handle_psacct(struct task_struct *task, const long code)
62955 +{
62956 + return;
62957 +}
62958 +
62959 +int
62960 +gr_handle_ptrace(struct task_struct *task, const long request)
62961 +{
62962 + return 0;
62963 +}
62964 +
62965 +int
62966 +gr_handle_proc_ptrace(struct task_struct *task)
62967 +{
62968 + return 0;
62969 +}
62970 +
62971 +int
62972 +gr_set_acls(const int type)
62973 +{
62974 + return 0;
62975 +}
62976 +
62977 +int
62978 +gr_check_hidden_task(const struct task_struct *tsk)
62979 +{
62980 + return 0;
62981 +}
62982 +
62983 +int
62984 +gr_check_protected_task(const struct task_struct *task)
62985 +{
62986 + return 0;
62987 +}
62988 +
62989 +int
62990 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
62991 +{
62992 + return 0;
62993 +}
62994 +
62995 +void
62996 +gr_copy_label(struct task_struct *tsk)
62997 +{
62998 + return;
62999 +}
63000 +
63001 +void
63002 +gr_set_pax_flags(struct task_struct *task)
63003 +{
63004 + return;
63005 +}
63006 +
63007 +int
63008 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
63009 + const int unsafe_share)
63010 +{
63011 + return 0;
63012 +}
63013 +
63014 +void
63015 +gr_handle_delete(const ino_t ino, const dev_t dev)
63016 +{
63017 + return;
63018 +}
63019 +
63020 +void
63021 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
63022 +{
63023 + return;
63024 +}
63025 +
63026 +void
63027 +gr_handle_crash(struct task_struct *task, const int sig)
63028 +{
63029 + return;
63030 +}
63031 +
63032 +int
63033 +gr_check_crash_exec(const struct file *filp)
63034 +{
63035 + return 0;
63036 +}
63037 +
63038 +int
63039 +gr_check_crash_uid(const kuid_t uid)
63040 +{
63041 + return 0;
63042 +}
63043 +
63044 +void
63045 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63046 + struct dentry *old_dentry,
63047 + struct dentry *new_dentry,
63048 + struct vfsmount *mnt, const __u8 replace)
63049 +{
63050 + return;
63051 +}
63052 +
63053 +int
63054 +gr_search_socket(const int family, const int type, const int protocol)
63055 +{
63056 + return 1;
63057 +}
63058 +
63059 +int
63060 +gr_search_connectbind(const int mode, const struct socket *sock,
63061 + const struct sockaddr_in *addr)
63062 +{
63063 + return 0;
63064 +}
63065 +
63066 +void
63067 +gr_handle_alertkill(struct task_struct *task)
63068 +{
63069 + return;
63070 +}
63071 +
63072 +__u32
63073 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
63074 +{
63075 + return 1;
63076 +}
63077 +
63078 +__u32
63079 +gr_acl_handle_hidden_file(const struct dentry * dentry,
63080 + const struct vfsmount * mnt)
63081 +{
63082 + return 1;
63083 +}
63084 +
63085 +__u32
63086 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
63087 + int acc_mode)
63088 +{
63089 + return 1;
63090 +}
63091 +
63092 +__u32
63093 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
63094 +{
63095 + return 1;
63096 +}
63097 +
63098 +__u32
63099 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
63100 +{
63101 + return 1;
63102 +}
63103 +
63104 +int
63105 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
63106 + unsigned int *vm_flags)
63107 +{
63108 + return 1;
63109 +}
63110 +
63111 +__u32
63112 +gr_acl_handle_truncate(const struct dentry * dentry,
63113 + const struct vfsmount * mnt)
63114 +{
63115 + return 1;
63116 +}
63117 +
63118 +__u32
63119 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
63120 +{
63121 + return 1;
63122 +}
63123 +
63124 +__u32
63125 +gr_acl_handle_access(const struct dentry * dentry,
63126 + const struct vfsmount * mnt, const int fmode)
63127 +{
63128 + return 1;
63129 +}
63130 +
63131 +__u32
63132 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
63133 + umode_t *mode)
63134 +{
63135 + return 1;
63136 +}
63137 +
63138 +__u32
63139 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
63140 +{
63141 + return 1;
63142 +}
63143 +
63144 +__u32
63145 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
63146 +{
63147 + return 1;
63148 +}
63149 +
63150 +void
63151 +grsecurity_init(void)
63152 +{
63153 + return;
63154 +}
63155 +
63156 +umode_t gr_acl_umask(void)
63157 +{
63158 + return 0;
63159 +}
63160 +
63161 +__u32
63162 +gr_acl_handle_mknod(const struct dentry * new_dentry,
63163 + const struct dentry * parent_dentry,
63164 + const struct vfsmount * parent_mnt,
63165 + const int mode)
63166 +{
63167 + return 1;
63168 +}
63169 +
63170 +__u32
63171 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
63172 + const struct dentry * parent_dentry,
63173 + const struct vfsmount * parent_mnt)
63174 +{
63175 + return 1;
63176 +}
63177 +
63178 +__u32
63179 +gr_acl_handle_symlink(const struct dentry * new_dentry,
63180 + const struct dentry * parent_dentry,
63181 + const struct vfsmount * parent_mnt, const struct filename *from)
63182 +{
63183 + return 1;
63184 +}
63185 +
63186 +__u32
63187 +gr_acl_handle_link(const struct dentry * new_dentry,
63188 + const struct dentry * parent_dentry,
63189 + const struct vfsmount * parent_mnt,
63190 + const struct dentry * old_dentry,
63191 + const struct vfsmount * old_mnt, const struct filename *to)
63192 +{
63193 + return 1;
63194 +}
63195 +
63196 +int
63197 +gr_acl_handle_rename(const struct dentry *new_dentry,
63198 + const struct dentry *parent_dentry,
63199 + const struct vfsmount *parent_mnt,
63200 + const struct dentry *old_dentry,
63201 + const struct inode *old_parent_inode,
63202 + const struct vfsmount *old_mnt, const struct filename *newname)
63203 +{
63204 + return 0;
63205 +}
63206 +
63207 +int
63208 +gr_acl_handle_filldir(const struct file *file, const char *name,
63209 + const int namelen, const ino_t ino)
63210 +{
63211 + return 1;
63212 +}
63213 +
63214 +int
63215 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63216 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
63217 +{
63218 + return 1;
63219 +}
63220 +
63221 +int
63222 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
63223 +{
63224 + return 0;
63225 +}
63226 +
63227 +int
63228 +gr_search_accept(const struct socket *sock)
63229 +{
63230 + return 0;
63231 +}
63232 +
63233 +int
63234 +gr_search_listen(const struct socket *sock)
63235 +{
63236 + return 0;
63237 +}
63238 +
63239 +int
63240 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
63241 +{
63242 + return 0;
63243 +}
63244 +
63245 +__u32
63246 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
63247 +{
63248 + return 1;
63249 +}
63250 +
63251 +__u32
63252 +gr_acl_handle_creat(const struct dentry * dentry,
63253 + const struct dentry * p_dentry,
63254 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
63255 + const int imode)
63256 +{
63257 + return 1;
63258 +}
63259 +
63260 +void
63261 +gr_acl_handle_exit(void)
63262 +{
63263 + return;
63264 +}
63265 +
63266 +int
63267 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
63268 +{
63269 + return 1;
63270 +}
63271 +
63272 +void
63273 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
63274 +{
63275 + return;
63276 +}
63277 +
63278 +int
63279 +gr_acl_handle_procpidmem(const struct task_struct *task)
63280 +{
63281 + return 0;
63282 +}
63283 +
63284 +int
63285 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
63286 +{
63287 + return 0;
63288 +}
63289 +
63290 +int
63291 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
63292 +{
63293 + return 0;
63294 +}
63295 +
63296 +void
63297 +gr_set_kernel_label(struct task_struct *task)
63298 +{
63299 + return;
63300 +}
63301 +
63302 +int
63303 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
63304 +{
63305 + return 0;
63306 +}
63307 +
63308 +int
63309 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
63310 +{
63311 + return 0;
63312 +}
63313 +
63314 +int gr_acl_enable_at_secure(void)
63315 +{
63316 + return 0;
63317 +}
63318 +
63319 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63320 +{
63321 + return dentry->d_inode->i_sb->s_dev;
63322 +}
63323 +
63324 +void gr_put_exec_file(struct task_struct *task)
63325 +{
63326 + return;
63327 +}
63328 +
63329 +EXPORT_SYMBOL(gr_set_kernel_label);
63330 +#ifdef CONFIG_SECURITY
63331 +EXPORT_SYMBOL(gr_check_user_change);
63332 +EXPORT_SYMBOL(gr_check_group_change);
63333 +#endif
63334 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
63335 new file mode 100644
63336 index 0000000..abfa971
63337 --- /dev/null
63338 +++ b/grsecurity/grsec_exec.c
63339 @@ -0,0 +1,174 @@
63340 +#include <linux/kernel.h>
63341 +#include <linux/sched.h>
63342 +#include <linux/file.h>
63343 +#include <linux/binfmts.h>
63344 +#include <linux/fs.h>
63345 +#include <linux/types.h>
63346 +#include <linux/grdefs.h>
63347 +#include <linux/grsecurity.h>
63348 +#include <linux/grinternal.h>
63349 +#include <linux/capability.h>
63350 +#include <linux/module.h>
63351 +
63352 +#include <asm/uaccess.h>
63353 +
63354 +#ifdef CONFIG_GRKERNSEC_EXECLOG
63355 +static char gr_exec_arg_buf[132];
63356 +static DEFINE_MUTEX(gr_exec_arg_mutex);
63357 +#endif
63358 +
63359 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
63360 +
63361 +void
63362 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
63363 +{
63364 +#ifdef CONFIG_GRKERNSEC_EXECLOG
63365 + char *grarg = gr_exec_arg_buf;
63366 + unsigned int i, x, execlen = 0;
63367 + char c;
63368 +
63369 + if (!((grsec_enable_execlog && grsec_enable_group &&
63370 + in_group_p(grsec_audit_gid))
63371 + || (grsec_enable_execlog && !grsec_enable_group)))
63372 + return;
63373 +
63374 + mutex_lock(&gr_exec_arg_mutex);
63375 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
63376 +
63377 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
63378 + const char __user *p;
63379 + unsigned int len;
63380 +
63381 + p = get_user_arg_ptr(argv, i);
63382 + if (IS_ERR(p))
63383 + goto log;
63384 +
63385 + len = strnlen_user(p, 128 - execlen);
63386 + if (len > 128 - execlen)
63387 + len = 128 - execlen;
63388 + else if (len > 0)
63389 + len--;
63390 + if (copy_from_user(grarg + execlen, p, len))
63391 + goto log;
63392 +
63393 + /* rewrite unprintable characters */
63394 + for (x = 0; x < len; x++) {
63395 + c = *(grarg + execlen + x);
63396 + if (c < 32 || c > 126)
63397 + *(grarg + execlen + x) = ' ';
63398 + }
63399 +
63400 + execlen += len;
63401 + *(grarg + execlen) = ' ';
63402 + *(grarg + execlen + 1) = '\0';
63403 + execlen++;
63404 + }
63405 +
63406 + log:
63407 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
63408 + bprm->file->f_path.mnt, grarg);
63409 + mutex_unlock(&gr_exec_arg_mutex);
63410 +#endif
63411 + return;
63412 +}
63413 +
63414 +#ifdef CONFIG_GRKERNSEC
63415 +extern int gr_acl_is_capable(const int cap);
63416 +extern int gr_acl_is_capable_nolog(const int cap);
63417 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63418 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
63419 +extern int gr_chroot_is_capable(const int cap);
63420 +extern int gr_chroot_is_capable_nolog(const int cap);
63421 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63422 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
63423 +#endif
63424 +
63425 +const char *captab_log[] = {
63426 + "CAP_CHOWN",
63427 + "CAP_DAC_OVERRIDE",
63428 + "CAP_DAC_READ_SEARCH",
63429 + "CAP_FOWNER",
63430 + "CAP_FSETID",
63431 + "CAP_KILL",
63432 + "CAP_SETGID",
63433 + "CAP_SETUID",
63434 + "CAP_SETPCAP",
63435 + "CAP_LINUX_IMMUTABLE",
63436 + "CAP_NET_BIND_SERVICE",
63437 + "CAP_NET_BROADCAST",
63438 + "CAP_NET_ADMIN",
63439 + "CAP_NET_RAW",
63440 + "CAP_IPC_LOCK",
63441 + "CAP_IPC_OWNER",
63442 + "CAP_SYS_MODULE",
63443 + "CAP_SYS_RAWIO",
63444 + "CAP_SYS_CHROOT",
63445 + "CAP_SYS_PTRACE",
63446 + "CAP_SYS_PACCT",
63447 + "CAP_SYS_ADMIN",
63448 + "CAP_SYS_BOOT",
63449 + "CAP_SYS_NICE",
63450 + "CAP_SYS_RESOURCE",
63451 + "CAP_SYS_TIME",
63452 + "CAP_SYS_TTY_CONFIG",
63453 + "CAP_MKNOD",
63454 + "CAP_LEASE",
63455 + "CAP_AUDIT_WRITE",
63456 + "CAP_AUDIT_CONTROL",
63457 + "CAP_SETFCAP",
63458 + "CAP_MAC_OVERRIDE",
63459 + "CAP_MAC_ADMIN",
63460 + "CAP_SYSLOG",
63461 + "CAP_WAKE_ALARM"
63462 +};
63463 +
63464 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
63465 +
63466 +int gr_is_capable(const int cap)
63467 +{
63468 +#ifdef CONFIG_GRKERNSEC
63469 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
63470 + return 1;
63471 + return 0;
63472 +#else
63473 + return 1;
63474 +#endif
63475 +}
63476 +
63477 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63478 +{
63479 +#ifdef CONFIG_GRKERNSEC
63480 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
63481 + return 1;
63482 + return 0;
63483 +#else
63484 + return 1;
63485 +#endif
63486 +}
63487 +
63488 +int gr_is_capable_nolog(const int cap)
63489 +{
63490 +#ifdef CONFIG_GRKERNSEC
63491 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
63492 + return 1;
63493 + return 0;
63494 +#else
63495 + return 1;
63496 +#endif
63497 +}
63498 +
63499 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
63500 +{
63501 +#ifdef CONFIG_GRKERNSEC
63502 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
63503 + return 1;
63504 + return 0;
63505 +#else
63506 + return 1;
63507 +#endif
63508 +}
63509 +
63510 +EXPORT_SYMBOL(gr_is_capable);
63511 +EXPORT_SYMBOL(gr_is_capable_nolog);
63512 +EXPORT_SYMBOL(gr_task_is_capable);
63513 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
63514 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
63515 new file mode 100644
63516 index 0000000..06cc6ea
63517 --- /dev/null
63518 +++ b/grsecurity/grsec_fifo.c
63519 @@ -0,0 +1,24 @@
63520 +#include <linux/kernel.h>
63521 +#include <linux/sched.h>
63522 +#include <linux/fs.h>
63523 +#include <linux/file.h>
63524 +#include <linux/grinternal.h>
63525 +
63526 +int
63527 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
63528 + const struct dentry *dir, const int flag, const int acc_mode)
63529 +{
63530 +#ifdef CONFIG_GRKERNSEC_FIFO
63531 + const struct cred *cred = current_cred();
63532 +
63533 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
63534 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
63535 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
63536 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
63537 + if (!inode_permission(dentry->d_inode, acc_mode))
63538 + 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));
63539 + return -EACCES;
63540 + }
63541 +#endif
63542 + return 0;
63543 +}
63544 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
63545 new file mode 100644
63546 index 0000000..8ca18bf
63547 --- /dev/null
63548 +++ b/grsecurity/grsec_fork.c
63549 @@ -0,0 +1,23 @@
63550 +#include <linux/kernel.h>
63551 +#include <linux/sched.h>
63552 +#include <linux/grsecurity.h>
63553 +#include <linux/grinternal.h>
63554 +#include <linux/errno.h>
63555 +
63556 +void
63557 +gr_log_forkfail(const int retval)
63558 +{
63559 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
63560 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
63561 + switch (retval) {
63562 + case -EAGAIN:
63563 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
63564 + break;
63565 + case -ENOMEM:
63566 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
63567 + break;
63568 + }
63569 + }
63570 +#endif
63571 + return;
63572 +}
63573 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
63574 new file mode 100644
63575 index 0000000..a862e9f
63576 --- /dev/null
63577 +++ b/grsecurity/grsec_init.c
63578 @@ -0,0 +1,283 @@
63579 +#include <linux/kernel.h>
63580 +#include <linux/sched.h>
63581 +#include <linux/mm.h>
63582 +#include <linux/gracl.h>
63583 +#include <linux/slab.h>
63584 +#include <linux/vmalloc.h>
63585 +#include <linux/percpu.h>
63586 +#include <linux/module.h>
63587 +
63588 +int grsec_enable_ptrace_readexec;
63589 +int grsec_enable_setxid;
63590 +int grsec_enable_symlinkown;
63591 +kgid_t grsec_symlinkown_gid;
63592 +int grsec_enable_brute;
63593 +int grsec_enable_link;
63594 +int grsec_enable_dmesg;
63595 +int grsec_enable_harden_ptrace;
63596 +int grsec_enable_fifo;
63597 +int grsec_enable_execlog;
63598 +int grsec_enable_signal;
63599 +int grsec_enable_forkfail;
63600 +int grsec_enable_audit_ptrace;
63601 +int grsec_enable_time;
63602 +int grsec_enable_audit_textrel;
63603 +int grsec_enable_group;
63604 +kgid_t grsec_audit_gid;
63605 +int grsec_enable_chdir;
63606 +int grsec_enable_mount;
63607 +int grsec_enable_rofs;
63608 +int grsec_enable_chroot_findtask;
63609 +int grsec_enable_chroot_mount;
63610 +int grsec_enable_chroot_shmat;
63611 +int grsec_enable_chroot_fchdir;
63612 +int grsec_enable_chroot_double;
63613 +int grsec_enable_chroot_pivot;
63614 +int grsec_enable_chroot_chdir;
63615 +int grsec_enable_chroot_chmod;
63616 +int grsec_enable_chroot_mknod;
63617 +int grsec_enable_chroot_nice;
63618 +int grsec_enable_chroot_execlog;
63619 +int grsec_enable_chroot_caps;
63620 +int grsec_enable_chroot_sysctl;
63621 +int grsec_enable_chroot_unix;
63622 +int grsec_enable_tpe;
63623 +kgid_t grsec_tpe_gid;
63624 +int grsec_enable_blackhole;
63625 +#ifdef CONFIG_IPV6_MODULE
63626 +EXPORT_SYMBOL(grsec_enable_blackhole);
63627 +#endif
63628 +int grsec_lastack_retries;
63629 +int grsec_enable_tpe_all;
63630 +int grsec_enable_tpe_invert;
63631 +int grsec_enable_socket_all;
63632 +kgid_t grsec_socket_all_gid;
63633 +int grsec_enable_socket_client;
63634 +kgid_t grsec_socket_client_gid;
63635 +int grsec_enable_socket_server;
63636 +kgid_t grsec_socket_server_gid;
63637 +int grsec_resource_logging;
63638 +int grsec_disable_privio;
63639 +int grsec_enable_log_rwxmaps;
63640 +int grsec_lock;
63641 +
63642 +DEFINE_SPINLOCK(grsec_alert_lock);
63643 +unsigned long grsec_alert_wtime = 0;
63644 +unsigned long grsec_alert_fyet = 0;
63645 +
63646 +DEFINE_SPINLOCK(grsec_audit_lock);
63647 +
63648 +DEFINE_RWLOCK(grsec_exec_file_lock);
63649 +
63650 +char *gr_shared_page[4];
63651 +
63652 +char *gr_alert_log_fmt;
63653 +char *gr_audit_log_fmt;
63654 +char *gr_alert_log_buf;
63655 +char *gr_audit_log_buf;
63656 +
63657 +extern struct gr_arg *gr_usermode;
63658 +extern unsigned char *gr_system_salt;
63659 +extern unsigned char *gr_system_sum;
63660 +
63661 +void __init
63662 +grsecurity_init(void)
63663 +{
63664 + int j;
63665 + /* create the per-cpu shared pages */
63666 +
63667 +#ifdef CONFIG_X86
63668 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
63669 +#endif
63670 +
63671 + for (j = 0; j < 4; j++) {
63672 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
63673 + if (gr_shared_page[j] == NULL) {
63674 + panic("Unable to allocate grsecurity shared page");
63675 + return;
63676 + }
63677 + }
63678 +
63679 + /* allocate log buffers */
63680 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
63681 + if (!gr_alert_log_fmt) {
63682 + panic("Unable to allocate grsecurity alert log format buffer");
63683 + return;
63684 + }
63685 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
63686 + if (!gr_audit_log_fmt) {
63687 + panic("Unable to allocate grsecurity audit log format buffer");
63688 + return;
63689 + }
63690 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
63691 + if (!gr_alert_log_buf) {
63692 + panic("Unable to allocate grsecurity alert log buffer");
63693 + return;
63694 + }
63695 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
63696 + if (!gr_audit_log_buf) {
63697 + panic("Unable to allocate grsecurity audit log buffer");
63698 + return;
63699 + }
63700 +
63701 + /* allocate memory for authentication structure */
63702 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
63703 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
63704 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
63705 +
63706 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
63707 + panic("Unable to allocate grsecurity authentication structure");
63708 + return;
63709 + }
63710 +
63711 +
63712 +#ifdef CONFIG_GRKERNSEC_IO
63713 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
63714 + grsec_disable_privio = 1;
63715 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
63716 + grsec_disable_privio = 1;
63717 +#else
63718 + grsec_disable_privio = 0;
63719 +#endif
63720 +#endif
63721 +
63722 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63723 + /* for backward compatibility, tpe_invert always defaults to on if
63724 + enabled in the kernel
63725 + */
63726 + grsec_enable_tpe_invert = 1;
63727 +#endif
63728 +
63729 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
63730 +#ifndef CONFIG_GRKERNSEC_SYSCTL
63731 + grsec_lock = 1;
63732 +#endif
63733 +
63734 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
63735 + grsec_enable_audit_textrel = 1;
63736 +#endif
63737 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63738 + grsec_enable_log_rwxmaps = 1;
63739 +#endif
63740 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
63741 + grsec_enable_group = 1;
63742 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
63743 +#endif
63744 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
63745 + grsec_enable_ptrace_readexec = 1;
63746 +#endif
63747 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63748 + grsec_enable_chdir = 1;
63749 +#endif
63750 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
63751 + grsec_enable_harden_ptrace = 1;
63752 +#endif
63753 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63754 + grsec_enable_mount = 1;
63755 +#endif
63756 +#ifdef CONFIG_GRKERNSEC_LINK
63757 + grsec_enable_link = 1;
63758 +#endif
63759 +#ifdef CONFIG_GRKERNSEC_BRUTE
63760 + grsec_enable_brute = 1;
63761 +#endif
63762 +#ifdef CONFIG_GRKERNSEC_DMESG
63763 + grsec_enable_dmesg = 1;
63764 +#endif
63765 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
63766 + grsec_enable_blackhole = 1;
63767 + grsec_lastack_retries = 4;
63768 +#endif
63769 +#ifdef CONFIG_GRKERNSEC_FIFO
63770 + grsec_enable_fifo = 1;
63771 +#endif
63772 +#ifdef CONFIG_GRKERNSEC_EXECLOG
63773 + grsec_enable_execlog = 1;
63774 +#endif
63775 +#ifdef CONFIG_GRKERNSEC_SETXID
63776 + grsec_enable_setxid = 1;
63777 +#endif
63778 +#ifdef CONFIG_GRKERNSEC_SIGNAL
63779 + grsec_enable_signal = 1;
63780 +#endif
63781 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
63782 + grsec_enable_forkfail = 1;
63783 +#endif
63784 +#ifdef CONFIG_GRKERNSEC_TIME
63785 + grsec_enable_time = 1;
63786 +#endif
63787 +#ifdef CONFIG_GRKERNSEC_RESLOG
63788 + grsec_resource_logging = 1;
63789 +#endif
63790 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63791 + grsec_enable_chroot_findtask = 1;
63792 +#endif
63793 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63794 + grsec_enable_chroot_unix = 1;
63795 +#endif
63796 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63797 + grsec_enable_chroot_mount = 1;
63798 +#endif
63799 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63800 + grsec_enable_chroot_fchdir = 1;
63801 +#endif
63802 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63803 + grsec_enable_chroot_shmat = 1;
63804 +#endif
63805 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63806 + grsec_enable_audit_ptrace = 1;
63807 +#endif
63808 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63809 + grsec_enable_chroot_double = 1;
63810 +#endif
63811 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63812 + grsec_enable_chroot_pivot = 1;
63813 +#endif
63814 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63815 + grsec_enable_chroot_chdir = 1;
63816 +#endif
63817 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63818 + grsec_enable_chroot_chmod = 1;
63819 +#endif
63820 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63821 + grsec_enable_chroot_mknod = 1;
63822 +#endif
63823 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63824 + grsec_enable_chroot_nice = 1;
63825 +#endif
63826 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63827 + grsec_enable_chroot_execlog = 1;
63828 +#endif
63829 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63830 + grsec_enable_chroot_caps = 1;
63831 +#endif
63832 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63833 + grsec_enable_chroot_sysctl = 1;
63834 +#endif
63835 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
63836 + grsec_enable_symlinkown = 1;
63837 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
63838 +#endif
63839 +#ifdef CONFIG_GRKERNSEC_TPE
63840 + grsec_enable_tpe = 1;
63841 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
63842 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
63843 + grsec_enable_tpe_all = 1;
63844 +#endif
63845 +#endif
63846 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
63847 + grsec_enable_socket_all = 1;
63848 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
63849 +#endif
63850 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
63851 + grsec_enable_socket_client = 1;
63852 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
63853 +#endif
63854 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63855 + grsec_enable_socket_server = 1;
63856 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
63857 +#endif
63858 +#endif
63859 +
63860 + return;
63861 +}
63862 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
63863 new file mode 100644
63864 index 0000000..5e05e20
63865 --- /dev/null
63866 +++ b/grsecurity/grsec_link.c
63867 @@ -0,0 +1,58 @@
63868 +#include <linux/kernel.h>
63869 +#include <linux/sched.h>
63870 +#include <linux/fs.h>
63871 +#include <linux/file.h>
63872 +#include <linux/grinternal.h>
63873 +
63874 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
63875 +{
63876 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
63877 + const struct inode *link_inode = link->dentry->d_inode;
63878 +
63879 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
63880 + /* ignore root-owned links, e.g. /proc/self */
63881 + gr_is_global_nonroot(link_inode->i_uid) && target &&
63882 + !uid_eq(link_inode->i_uid, target->i_uid)) {
63883 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
63884 + return 1;
63885 + }
63886 +#endif
63887 + return 0;
63888 +}
63889 +
63890 +int
63891 +gr_handle_follow_link(const struct inode *parent,
63892 + const struct inode *inode,
63893 + const struct dentry *dentry, const struct vfsmount *mnt)
63894 +{
63895 +#ifdef CONFIG_GRKERNSEC_LINK
63896 + const struct cred *cred = current_cred();
63897 +
63898 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
63899 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
63900 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
63901 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
63902 + return -EACCES;
63903 + }
63904 +#endif
63905 + return 0;
63906 +}
63907 +
63908 +int
63909 +gr_handle_hardlink(const struct dentry *dentry,
63910 + const struct vfsmount *mnt,
63911 + struct inode *inode, const int mode, const struct filename *to)
63912 +{
63913 +#ifdef CONFIG_GRKERNSEC_LINK
63914 + const struct cred *cred = current_cred();
63915 +
63916 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
63917 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
63918 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
63919 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
63920 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
63921 + return -EPERM;
63922 + }
63923 +#endif
63924 + return 0;
63925 +}
63926 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
63927 new file mode 100644
63928 index 0000000..7c06085
63929 --- /dev/null
63930 +++ b/grsecurity/grsec_log.c
63931 @@ -0,0 +1,326 @@
63932 +#include <linux/kernel.h>
63933 +#include <linux/sched.h>
63934 +#include <linux/file.h>
63935 +#include <linux/tty.h>
63936 +#include <linux/fs.h>
63937 +#include <linux/grinternal.h>
63938 +
63939 +#ifdef CONFIG_TREE_PREEMPT_RCU
63940 +#define DISABLE_PREEMPT() preempt_disable()
63941 +#define ENABLE_PREEMPT() preempt_enable()
63942 +#else
63943 +#define DISABLE_PREEMPT()
63944 +#define ENABLE_PREEMPT()
63945 +#endif
63946 +
63947 +#define BEGIN_LOCKS(x) \
63948 + DISABLE_PREEMPT(); \
63949 + rcu_read_lock(); \
63950 + read_lock(&tasklist_lock); \
63951 + read_lock(&grsec_exec_file_lock); \
63952 + if (x != GR_DO_AUDIT) \
63953 + spin_lock(&grsec_alert_lock); \
63954 + else \
63955 + spin_lock(&grsec_audit_lock)
63956 +
63957 +#define END_LOCKS(x) \
63958 + if (x != GR_DO_AUDIT) \
63959 + spin_unlock(&grsec_alert_lock); \
63960 + else \
63961 + spin_unlock(&grsec_audit_lock); \
63962 + read_unlock(&grsec_exec_file_lock); \
63963 + read_unlock(&tasklist_lock); \
63964 + rcu_read_unlock(); \
63965 + ENABLE_PREEMPT(); \
63966 + if (x == GR_DONT_AUDIT) \
63967 + gr_handle_alertkill(current)
63968 +
63969 +enum {
63970 + FLOODING,
63971 + NO_FLOODING
63972 +};
63973 +
63974 +extern char *gr_alert_log_fmt;
63975 +extern char *gr_audit_log_fmt;
63976 +extern char *gr_alert_log_buf;
63977 +extern char *gr_audit_log_buf;
63978 +
63979 +static int gr_log_start(int audit)
63980 +{
63981 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
63982 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
63983 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63984 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
63985 + unsigned long curr_secs = get_seconds();
63986 +
63987 + if (audit == GR_DO_AUDIT)
63988 + goto set_fmt;
63989 +
63990 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
63991 + grsec_alert_wtime = curr_secs;
63992 + grsec_alert_fyet = 0;
63993 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
63994 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
63995 + grsec_alert_fyet++;
63996 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
63997 + grsec_alert_wtime = curr_secs;
63998 + grsec_alert_fyet++;
63999 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
64000 + return FLOODING;
64001 + }
64002 + else return FLOODING;
64003 +
64004 +set_fmt:
64005 +#endif
64006 + memset(buf, 0, PAGE_SIZE);
64007 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
64008 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
64009 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64010 + } else if (current->signal->curr_ip) {
64011 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
64012 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
64013 + } else if (gr_acl_is_enabled()) {
64014 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
64015 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64016 + } else {
64017 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
64018 + strcpy(buf, fmt);
64019 + }
64020 +
64021 + return NO_FLOODING;
64022 +}
64023 +
64024 +static void gr_log_middle(int audit, const char *msg, va_list ap)
64025 + __attribute__ ((format (printf, 2, 0)));
64026 +
64027 +static void gr_log_middle(int audit, const char *msg, va_list ap)
64028 +{
64029 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64030 + unsigned int len = strlen(buf);
64031 +
64032 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64033 +
64034 + return;
64035 +}
64036 +
64037 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
64038 + __attribute__ ((format (printf, 2, 3)));
64039 +
64040 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
64041 +{
64042 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64043 + unsigned int len = strlen(buf);
64044 + va_list ap;
64045 +
64046 + va_start(ap, msg);
64047 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64048 + va_end(ap);
64049 +
64050 + return;
64051 +}
64052 +
64053 +static void gr_log_end(int audit, int append_default)
64054 +{
64055 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64056 + if (append_default) {
64057 + struct task_struct *task = current;
64058 + struct task_struct *parent = task->real_parent;
64059 + const struct cred *cred = __task_cred(task);
64060 + const struct cred *pcred = __task_cred(parent);
64061 + unsigned int len = strlen(buf);
64062 +
64063 + 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));
64064 + }
64065 +
64066 + printk("%s\n", buf);
64067 +
64068 + return;
64069 +}
64070 +
64071 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
64072 +{
64073 + int logtype;
64074 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
64075 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
64076 + void *voidptr = NULL;
64077 + int num1 = 0, num2 = 0;
64078 + unsigned long ulong1 = 0, ulong2 = 0;
64079 + struct dentry *dentry = NULL;
64080 + struct vfsmount *mnt = NULL;
64081 + struct file *file = NULL;
64082 + struct task_struct *task = NULL;
64083 + const struct cred *cred, *pcred;
64084 + va_list ap;
64085 +
64086 + BEGIN_LOCKS(audit);
64087 + logtype = gr_log_start(audit);
64088 + if (logtype == FLOODING) {
64089 + END_LOCKS(audit);
64090 + return;
64091 + }
64092 + va_start(ap, argtypes);
64093 + switch (argtypes) {
64094 + case GR_TTYSNIFF:
64095 + task = va_arg(ap, struct task_struct *);
64096 + 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));
64097 + break;
64098 + case GR_SYSCTL_HIDDEN:
64099 + str1 = va_arg(ap, char *);
64100 + gr_log_middle_varargs(audit, msg, result, str1);
64101 + break;
64102 + case GR_RBAC:
64103 + dentry = va_arg(ap, struct dentry *);
64104 + mnt = va_arg(ap, struct vfsmount *);
64105 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
64106 + break;
64107 + case GR_RBAC_STR:
64108 + dentry = va_arg(ap, struct dentry *);
64109 + mnt = va_arg(ap, struct vfsmount *);
64110 + str1 = va_arg(ap, char *);
64111 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
64112 + break;
64113 + case GR_STR_RBAC:
64114 + str1 = va_arg(ap, char *);
64115 + dentry = va_arg(ap, struct dentry *);
64116 + mnt = va_arg(ap, struct vfsmount *);
64117 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
64118 + break;
64119 + case GR_RBAC_MODE2:
64120 + dentry = va_arg(ap, struct dentry *);
64121 + mnt = va_arg(ap, struct vfsmount *);
64122 + str1 = va_arg(ap, char *);
64123 + str2 = va_arg(ap, char *);
64124 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
64125 + break;
64126 + case GR_RBAC_MODE3:
64127 + dentry = va_arg(ap, struct dentry *);
64128 + mnt = va_arg(ap, struct vfsmount *);
64129 + str1 = va_arg(ap, char *);
64130 + str2 = va_arg(ap, char *);
64131 + str3 = va_arg(ap, char *);
64132 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
64133 + break;
64134 + case GR_FILENAME:
64135 + dentry = va_arg(ap, struct dentry *);
64136 + mnt = va_arg(ap, struct vfsmount *);
64137 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
64138 + break;
64139 + case GR_STR_FILENAME:
64140 + str1 = va_arg(ap, char *);
64141 + dentry = va_arg(ap, struct dentry *);
64142 + mnt = va_arg(ap, struct vfsmount *);
64143 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
64144 + break;
64145 + case GR_FILENAME_STR:
64146 + dentry = va_arg(ap, struct dentry *);
64147 + mnt = va_arg(ap, struct vfsmount *);
64148 + str1 = va_arg(ap, char *);
64149 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
64150 + break;
64151 + case GR_FILENAME_TWO_INT:
64152 + dentry = va_arg(ap, struct dentry *);
64153 + mnt = va_arg(ap, struct vfsmount *);
64154 + num1 = va_arg(ap, int);
64155 + num2 = va_arg(ap, int);
64156 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
64157 + break;
64158 + case GR_FILENAME_TWO_INT_STR:
64159 + dentry = va_arg(ap, struct dentry *);
64160 + mnt = va_arg(ap, struct vfsmount *);
64161 + num1 = va_arg(ap, int);
64162 + num2 = va_arg(ap, int);
64163 + str1 = va_arg(ap, char *);
64164 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
64165 + break;
64166 + case GR_TEXTREL:
64167 + file = va_arg(ap, struct file *);
64168 + ulong1 = va_arg(ap, unsigned long);
64169 + ulong2 = va_arg(ap, unsigned long);
64170 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
64171 + break;
64172 + case GR_PTRACE:
64173 + task = va_arg(ap, struct task_struct *);
64174 + 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));
64175 + break;
64176 + case GR_RESOURCE:
64177 + task = va_arg(ap, struct task_struct *);
64178 + cred = __task_cred(task);
64179 + pcred = __task_cred(task->real_parent);
64180 + ulong1 = va_arg(ap, unsigned long);
64181 + str1 = va_arg(ap, char *);
64182 + ulong2 = va_arg(ap, unsigned long);
64183 + 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));
64184 + break;
64185 + case GR_CAP:
64186 + task = va_arg(ap, struct task_struct *);
64187 + cred = __task_cred(task);
64188 + pcred = __task_cred(task->real_parent);
64189 + str1 = va_arg(ap, char *);
64190 + 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));
64191 + break;
64192 + case GR_SIG:
64193 + str1 = va_arg(ap, char *);
64194 + voidptr = va_arg(ap, void *);
64195 + gr_log_middle_varargs(audit, msg, str1, voidptr);
64196 + break;
64197 + case GR_SIG2:
64198 + task = va_arg(ap, struct task_struct *);
64199 + cred = __task_cred(task);
64200 + pcred = __task_cred(task->real_parent);
64201 + num1 = va_arg(ap, int);
64202 + 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));
64203 + break;
64204 + case GR_CRASH1:
64205 + task = va_arg(ap, struct task_struct *);
64206 + cred = __task_cred(task);
64207 + pcred = __task_cred(task->real_parent);
64208 + ulong1 = va_arg(ap, unsigned long);
64209 + 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);
64210 + break;
64211 + case GR_CRASH2:
64212 + task = va_arg(ap, struct task_struct *);
64213 + cred = __task_cred(task);
64214 + pcred = __task_cred(task->real_parent);
64215 + ulong1 = va_arg(ap, unsigned long);
64216 + 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);
64217 + break;
64218 + case GR_RWXMAP:
64219 + file = va_arg(ap, struct file *);
64220 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
64221 + break;
64222 + case GR_PSACCT:
64223 + {
64224 + unsigned int wday, cday;
64225 + __u8 whr, chr;
64226 + __u8 wmin, cmin;
64227 + __u8 wsec, csec;
64228 + char cur_tty[64] = { 0 };
64229 + char parent_tty[64] = { 0 };
64230 +
64231 + task = va_arg(ap, struct task_struct *);
64232 + wday = va_arg(ap, unsigned int);
64233 + cday = va_arg(ap, unsigned int);
64234 + whr = va_arg(ap, int);
64235 + chr = va_arg(ap, int);
64236 + wmin = va_arg(ap, int);
64237 + cmin = va_arg(ap, int);
64238 + wsec = va_arg(ap, int);
64239 + csec = va_arg(ap, int);
64240 + ulong1 = va_arg(ap, unsigned long);
64241 + cred = __task_cred(task);
64242 + pcred = __task_cred(task->real_parent);
64243 +
64244 + 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));
64245 + }
64246 + break;
64247 + default:
64248 + gr_log_middle(audit, msg, ap);
64249 + }
64250 + va_end(ap);
64251 + // these don't need DEFAULTSECARGS printed on the end
64252 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
64253 + gr_log_end(audit, 0);
64254 + else
64255 + gr_log_end(audit, 1);
64256 + END_LOCKS(audit);
64257 +}
64258 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
64259 new file mode 100644
64260 index 0000000..f536303
64261 --- /dev/null
64262 +++ b/grsecurity/grsec_mem.c
64263 @@ -0,0 +1,40 @@
64264 +#include <linux/kernel.h>
64265 +#include <linux/sched.h>
64266 +#include <linux/mm.h>
64267 +#include <linux/mman.h>
64268 +#include <linux/grinternal.h>
64269 +
64270 +void
64271 +gr_handle_ioperm(void)
64272 +{
64273 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
64274 + return;
64275 +}
64276 +
64277 +void
64278 +gr_handle_iopl(void)
64279 +{
64280 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
64281 + return;
64282 +}
64283 +
64284 +void
64285 +gr_handle_mem_readwrite(u64 from, u64 to)
64286 +{
64287 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
64288 + return;
64289 +}
64290 +
64291 +void
64292 +gr_handle_vm86(void)
64293 +{
64294 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
64295 + return;
64296 +}
64297 +
64298 +void
64299 +gr_log_badprocpid(const char *entry)
64300 +{
64301 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
64302 + return;
64303 +}
64304 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
64305 new file mode 100644
64306 index 0000000..2131422
64307 --- /dev/null
64308 +++ b/grsecurity/grsec_mount.c
64309 @@ -0,0 +1,62 @@
64310 +#include <linux/kernel.h>
64311 +#include <linux/sched.h>
64312 +#include <linux/mount.h>
64313 +#include <linux/grsecurity.h>
64314 +#include <linux/grinternal.h>
64315 +
64316 +void
64317 +gr_log_remount(const char *devname, const int retval)
64318 +{
64319 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64320 + if (grsec_enable_mount && (retval >= 0))
64321 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
64322 +#endif
64323 + return;
64324 +}
64325 +
64326 +void
64327 +gr_log_unmount(const char *devname, const int retval)
64328 +{
64329 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64330 + if (grsec_enable_mount && (retval >= 0))
64331 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
64332 +#endif
64333 + return;
64334 +}
64335 +
64336 +void
64337 +gr_log_mount(const char *from, const char *to, const int retval)
64338 +{
64339 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64340 + if (grsec_enable_mount && (retval >= 0))
64341 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
64342 +#endif
64343 + return;
64344 +}
64345 +
64346 +int
64347 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
64348 +{
64349 +#ifdef CONFIG_GRKERNSEC_ROFS
64350 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
64351 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
64352 + return -EPERM;
64353 + } else
64354 + return 0;
64355 +#endif
64356 + return 0;
64357 +}
64358 +
64359 +int
64360 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
64361 +{
64362 +#ifdef CONFIG_GRKERNSEC_ROFS
64363 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
64364 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
64365 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
64366 + return -EPERM;
64367 + } else
64368 + return 0;
64369 +#endif
64370 + return 0;
64371 +}
64372 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
64373 new file mode 100644
64374 index 0000000..a3b12a0
64375 --- /dev/null
64376 +++ b/grsecurity/grsec_pax.c
64377 @@ -0,0 +1,36 @@
64378 +#include <linux/kernel.h>
64379 +#include <linux/sched.h>
64380 +#include <linux/mm.h>
64381 +#include <linux/file.h>
64382 +#include <linux/grinternal.h>
64383 +#include <linux/grsecurity.h>
64384 +
64385 +void
64386 +gr_log_textrel(struct vm_area_struct * vma)
64387 +{
64388 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64389 + if (grsec_enable_audit_textrel)
64390 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
64391 +#endif
64392 + return;
64393 +}
64394 +
64395 +void
64396 +gr_log_rwxmmap(struct file *file)
64397 +{
64398 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64399 + if (grsec_enable_log_rwxmaps)
64400 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
64401 +#endif
64402 + return;
64403 +}
64404 +
64405 +void
64406 +gr_log_rwxmprotect(struct file *file)
64407 +{
64408 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64409 + if (grsec_enable_log_rwxmaps)
64410 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
64411 +#endif
64412 + return;
64413 +}
64414 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
64415 new file mode 100644
64416 index 0000000..f7f29aa
64417 --- /dev/null
64418 +++ b/grsecurity/grsec_ptrace.c
64419 @@ -0,0 +1,30 @@
64420 +#include <linux/kernel.h>
64421 +#include <linux/sched.h>
64422 +#include <linux/grinternal.h>
64423 +#include <linux/security.h>
64424 +
64425 +void
64426 +gr_audit_ptrace(struct task_struct *task)
64427 +{
64428 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64429 + if (grsec_enable_audit_ptrace)
64430 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
64431 +#endif
64432 + return;
64433 +}
64434 +
64435 +int
64436 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
64437 +{
64438 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64439 + const struct dentry *dentry = file->f_path.dentry;
64440 + const struct vfsmount *mnt = file->f_path.mnt;
64441 +
64442 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
64443 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
64444 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
64445 + return -EACCES;
64446 + }
64447 +#endif
64448 + return 0;
64449 +}
64450 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
64451 new file mode 100644
64452 index 0000000..e09715a
64453 --- /dev/null
64454 +++ b/grsecurity/grsec_sig.c
64455 @@ -0,0 +1,222 @@
64456 +#include <linux/kernel.h>
64457 +#include <linux/sched.h>
64458 +#include <linux/delay.h>
64459 +#include <linux/grsecurity.h>
64460 +#include <linux/grinternal.h>
64461 +#include <linux/hardirq.h>
64462 +
64463 +char *signames[] = {
64464 + [SIGSEGV] = "Segmentation fault",
64465 + [SIGILL] = "Illegal instruction",
64466 + [SIGABRT] = "Abort",
64467 + [SIGBUS] = "Invalid alignment/Bus error"
64468 +};
64469 +
64470 +void
64471 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
64472 +{
64473 +#ifdef CONFIG_GRKERNSEC_SIGNAL
64474 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
64475 + (sig == SIGABRT) || (sig == SIGBUS))) {
64476 + if (task_pid_nr(t) == task_pid_nr(current)) {
64477 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
64478 + } else {
64479 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
64480 + }
64481 + }
64482 +#endif
64483 + return;
64484 +}
64485 +
64486 +int
64487 +gr_handle_signal(const struct task_struct *p, const int sig)
64488 +{
64489 +#ifdef CONFIG_GRKERNSEC
64490 + /* ignore the 0 signal for protected task checks */
64491 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
64492 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
64493 + return -EPERM;
64494 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
64495 + return -EPERM;
64496 + }
64497 +#endif
64498 + return 0;
64499 +}
64500 +
64501 +#ifdef CONFIG_GRKERNSEC
64502 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
64503 +
64504 +int gr_fake_force_sig(int sig, struct task_struct *t)
64505 +{
64506 + unsigned long int flags;
64507 + int ret, blocked, ignored;
64508 + struct k_sigaction *action;
64509 +
64510 + spin_lock_irqsave(&t->sighand->siglock, flags);
64511 + action = &t->sighand->action[sig-1];
64512 + ignored = action->sa.sa_handler == SIG_IGN;
64513 + blocked = sigismember(&t->blocked, sig);
64514 + if (blocked || ignored) {
64515 + action->sa.sa_handler = SIG_DFL;
64516 + if (blocked) {
64517 + sigdelset(&t->blocked, sig);
64518 + recalc_sigpending_and_wake(t);
64519 + }
64520 + }
64521 + if (action->sa.sa_handler == SIG_DFL)
64522 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
64523 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
64524 +
64525 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
64526 +
64527 + return ret;
64528 +}
64529 +#endif
64530 +
64531 +#ifdef CONFIG_GRKERNSEC_BRUTE
64532 +#define GR_USER_BAN_TIME (15 * 60)
64533 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
64534 +
64535 +static int __get_dumpable(unsigned long mm_flags)
64536 +{
64537 + int ret;
64538 +
64539 + ret = mm_flags & MMF_DUMPABLE_MASK;
64540 + return (ret >= 2) ? 2 : ret;
64541 +}
64542 +#endif
64543 +
64544 +void gr_handle_brute_attach(unsigned long mm_flags)
64545 +{
64546 +#ifdef CONFIG_GRKERNSEC_BRUTE
64547 + struct task_struct *p = current;
64548 + kuid_t uid = GLOBAL_ROOT_UID;
64549 + int daemon = 0;
64550 +
64551 + if (!grsec_enable_brute)
64552 + return;
64553 +
64554 + rcu_read_lock();
64555 + read_lock(&tasklist_lock);
64556 + read_lock(&grsec_exec_file_lock);
64557 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
64558 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
64559 + p->real_parent->brute = 1;
64560 + daemon = 1;
64561 + } else {
64562 + const struct cred *cred = __task_cred(p), *cred2;
64563 + struct task_struct *tsk, *tsk2;
64564 +
64565 + if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
64566 + struct user_struct *user;
64567 +
64568 + uid = cred->uid;
64569 +
64570 + /* this is put upon execution past expiration */
64571 + user = find_user(uid);
64572 + if (user == NULL)
64573 + goto unlock;
64574 + user->banned = 1;
64575 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
64576 + if (user->ban_expires == ~0UL)
64577 + user->ban_expires--;
64578 +
64579 + do_each_thread(tsk2, tsk) {
64580 + cred2 = __task_cred(tsk);
64581 + if (tsk != p && uid_eq(cred2->uid, uid))
64582 + gr_fake_force_sig(SIGKILL, tsk);
64583 + } while_each_thread(tsk2, tsk);
64584 + }
64585 + }
64586 +unlock:
64587 + read_unlock(&grsec_exec_file_lock);
64588 + read_unlock(&tasklist_lock);
64589 + rcu_read_unlock();
64590 +
64591 + if (gr_is_global_nonroot(uid))
64592 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
64593 + GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
64594 + else if (daemon)
64595 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
64596 +
64597 +#endif
64598 + return;
64599 +}
64600 +
64601 +void gr_handle_brute_check(void)
64602 +{
64603 +#ifdef CONFIG_GRKERNSEC_BRUTE
64604 + struct task_struct *p = current;
64605 +
64606 + if (unlikely(p->brute)) {
64607 + if (!grsec_enable_brute)
64608 + p->brute = 0;
64609 + else if (time_before(get_seconds(), p->brute_expires))
64610 + msleep(30 * 1000);
64611 + }
64612 +#endif
64613 + return;
64614 +}
64615 +
64616 +void gr_handle_kernel_exploit(void)
64617 +{
64618 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
64619 + const struct cred *cred;
64620 + struct task_struct *tsk, *tsk2;
64621 + struct user_struct *user;
64622 + kuid_t uid;
64623 +
64624 + if (in_irq() || in_serving_softirq() || in_nmi())
64625 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
64626 +
64627 + uid = current_uid();
64628 +
64629 + if (gr_is_global_root(uid))
64630 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
64631 + else {
64632 + /* kill all the processes of this user, hold a reference
64633 + to their creds struct, and prevent them from creating
64634 + another process until system reset
64635 + */
64636 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
64637 + GR_GLOBAL_UID(uid));
64638 + /* we intentionally leak this ref */
64639 + user = get_uid(current->cred->user);
64640 + if (user) {
64641 + user->banned = 1;
64642 + user->ban_expires = ~0UL;
64643 + }
64644 +
64645 + read_lock(&tasklist_lock);
64646 + do_each_thread(tsk2, tsk) {
64647 + cred = __task_cred(tsk);
64648 + if (uid_eq(cred->uid, uid))
64649 + gr_fake_force_sig(SIGKILL, tsk);
64650 + } while_each_thread(tsk2, tsk);
64651 + read_unlock(&tasklist_lock);
64652 + }
64653 +#endif
64654 +}
64655 +
64656 +int __gr_process_user_ban(struct user_struct *user)
64657 +{
64658 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64659 + if (unlikely(user->banned)) {
64660 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
64661 + user->banned = 0;
64662 + user->ban_expires = 0;
64663 + free_uid(user);
64664 + } else
64665 + return -EPERM;
64666 + }
64667 +#endif
64668 + return 0;
64669 +}
64670 +
64671 +int gr_process_user_ban(void)
64672 +{
64673 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64674 + return __gr_process_user_ban(current->cred->user);
64675 +#endif
64676 + return 0;
64677 +}
64678 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
64679 new file mode 100644
64680 index 0000000..4030d57
64681 --- /dev/null
64682 +++ b/grsecurity/grsec_sock.c
64683 @@ -0,0 +1,244 @@
64684 +#include <linux/kernel.h>
64685 +#include <linux/module.h>
64686 +#include <linux/sched.h>
64687 +#include <linux/file.h>
64688 +#include <linux/net.h>
64689 +#include <linux/in.h>
64690 +#include <linux/ip.h>
64691 +#include <net/sock.h>
64692 +#include <net/inet_sock.h>
64693 +#include <linux/grsecurity.h>
64694 +#include <linux/grinternal.h>
64695 +#include <linux/gracl.h>
64696 +
64697 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
64698 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
64699 +
64700 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
64701 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
64702 +
64703 +#ifdef CONFIG_UNIX_MODULE
64704 +EXPORT_SYMBOL(gr_acl_handle_unix);
64705 +EXPORT_SYMBOL(gr_acl_handle_mknod);
64706 +EXPORT_SYMBOL(gr_handle_chroot_unix);
64707 +EXPORT_SYMBOL(gr_handle_create);
64708 +#endif
64709 +
64710 +#ifdef CONFIG_GRKERNSEC
64711 +#define gr_conn_table_size 32749
64712 +struct conn_table_entry {
64713 + struct conn_table_entry *next;
64714 + struct signal_struct *sig;
64715 +};
64716 +
64717 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
64718 +DEFINE_SPINLOCK(gr_conn_table_lock);
64719 +
64720 +extern const char * gr_socktype_to_name(unsigned char type);
64721 +extern const char * gr_proto_to_name(unsigned char proto);
64722 +extern const char * gr_sockfamily_to_name(unsigned char family);
64723 +
64724 +static __inline__ int
64725 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
64726 +{
64727 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
64728 +}
64729 +
64730 +static __inline__ int
64731 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
64732 + __u16 sport, __u16 dport)
64733 +{
64734 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
64735 + sig->gr_sport == sport && sig->gr_dport == dport))
64736 + return 1;
64737 + else
64738 + return 0;
64739 +}
64740 +
64741 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
64742 +{
64743 + struct conn_table_entry **match;
64744 + unsigned int index;
64745 +
64746 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
64747 + sig->gr_sport, sig->gr_dport,
64748 + gr_conn_table_size);
64749 +
64750 + newent->sig = sig;
64751 +
64752 + match = &gr_conn_table[index];
64753 + newent->next = *match;
64754 + *match = newent;
64755 +
64756 + return;
64757 +}
64758 +
64759 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
64760 +{
64761 + struct conn_table_entry *match, *last = NULL;
64762 + unsigned int index;
64763 +
64764 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
64765 + sig->gr_sport, sig->gr_dport,
64766 + gr_conn_table_size);
64767 +
64768 + match = gr_conn_table[index];
64769 + while (match && !conn_match(match->sig,
64770 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
64771 + sig->gr_dport)) {
64772 + last = match;
64773 + match = match->next;
64774 + }
64775 +
64776 + if (match) {
64777 + if (last)
64778 + last->next = match->next;
64779 + else
64780 + gr_conn_table[index] = NULL;
64781 + kfree(match);
64782 + }
64783 +
64784 + return;
64785 +}
64786 +
64787 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
64788 + __u16 sport, __u16 dport)
64789 +{
64790 + struct conn_table_entry *match;
64791 + unsigned int index;
64792 +
64793 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
64794 +
64795 + match = gr_conn_table[index];
64796 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
64797 + match = match->next;
64798 +
64799 + if (match)
64800 + return match->sig;
64801 + else
64802 + return NULL;
64803 +}
64804 +
64805 +#endif
64806 +
64807 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
64808 +{
64809 +#ifdef CONFIG_GRKERNSEC
64810 + struct signal_struct *sig = task->signal;
64811 + struct conn_table_entry *newent;
64812 +
64813 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
64814 + if (newent == NULL)
64815 + return;
64816 + /* no bh lock needed since we are called with bh disabled */
64817 + spin_lock(&gr_conn_table_lock);
64818 + gr_del_task_from_ip_table_nolock(sig);
64819 + sig->gr_saddr = inet->inet_rcv_saddr;
64820 + sig->gr_daddr = inet->inet_daddr;
64821 + sig->gr_sport = inet->inet_sport;
64822 + sig->gr_dport = inet->inet_dport;
64823 + gr_add_to_task_ip_table_nolock(sig, newent);
64824 + spin_unlock(&gr_conn_table_lock);
64825 +#endif
64826 + return;
64827 +}
64828 +
64829 +void gr_del_task_from_ip_table(struct task_struct *task)
64830 +{
64831 +#ifdef CONFIG_GRKERNSEC
64832 + spin_lock_bh(&gr_conn_table_lock);
64833 + gr_del_task_from_ip_table_nolock(task->signal);
64834 + spin_unlock_bh(&gr_conn_table_lock);
64835 +#endif
64836 + return;
64837 +}
64838 +
64839 +void
64840 +gr_attach_curr_ip(const struct sock *sk)
64841 +{
64842 +#ifdef CONFIG_GRKERNSEC
64843 + struct signal_struct *p, *set;
64844 + const struct inet_sock *inet = inet_sk(sk);
64845 +
64846 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
64847 + return;
64848 +
64849 + set = current->signal;
64850 +
64851 + spin_lock_bh(&gr_conn_table_lock);
64852 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
64853 + inet->inet_dport, inet->inet_sport);
64854 + if (unlikely(p != NULL)) {
64855 + set->curr_ip = p->curr_ip;
64856 + set->used_accept = 1;
64857 + gr_del_task_from_ip_table_nolock(p);
64858 + spin_unlock_bh(&gr_conn_table_lock);
64859 + return;
64860 + }
64861 + spin_unlock_bh(&gr_conn_table_lock);
64862 +
64863 + set->curr_ip = inet->inet_daddr;
64864 + set->used_accept = 1;
64865 +#endif
64866 + return;
64867 +}
64868 +
64869 +int
64870 +gr_handle_sock_all(const int family, const int type, const int protocol)
64871 +{
64872 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64873 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
64874 + (family != AF_UNIX)) {
64875 + if (family == AF_INET)
64876 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
64877 + else
64878 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
64879 + return -EACCES;
64880 + }
64881 +#endif
64882 + return 0;
64883 +}
64884 +
64885 +int
64886 +gr_handle_sock_server(const struct sockaddr *sck)
64887 +{
64888 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64889 + if (grsec_enable_socket_server &&
64890 + in_group_p(grsec_socket_server_gid) &&
64891 + sck && (sck->sa_family != AF_UNIX) &&
64892 + (sck->sa_family != AF_LOCAL)) {
64893 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
64894 + return -EACCES;
64895 + }
64896 +#endif
64897 + return 0;
64898 +}
64899 +
64900 +int
64901 +gr_handle_sock_server_other(const struct sock *sck)
64902 +{
64903 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64904 + if (grsec_enable_socket_server &&
64905 + in_group_p(grsec_socket_server_gid) &&
64906 + sck && (sck->sk_family != AF_UNIX) &&
64907 + (sck->sk_family != AF_LOCAL)) {
64908 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
64909 + return -EACCES;
64910 + }
64911 +#endif
64912 + return 0;
64913 +}
64914 +
64915 +int
64916 +gr_handle_sock_client(const struct sockaddr *sck)
64917 +{
64918 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64919 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
64920 + sck && (sck->sa_family != AF_UNIX) &&
64921 + (sck->sa_family != AF_LOCAL)) {
64922 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
64923 + return -EACCES;
64924 + }
64925 +#endif
64926 + return 0;
64927 +}
64928 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
64929 new file mode 100644
64930 index 0000000..f55ef0f
64931 --- /dev/null
64932 +++ b/grsecurity/grsec_sysctl.c
64933 @@ -0,0 +1,469 @@
64934 +#include <linux/kernel.h>
64935 +#include <linux/sched.h>
64936 +#include <linux/sysctl.h>
64937 +#include <linux/grsecurity.h>
64938 +#include <linux/grinternal.h>
64939 +
64940 +int
64941 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
64942 +{
64943 +#ifdef CONFIG_GRKERNSEC_SYSCTL
64944 + if (dirname == NULL || name == NULL)
64945 + return 0;
64946 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
64947 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
64948 + return -EACCES;
64949 + }
64950 +#endif
64951 + return 0;
64952 +}
64953 +
64954 +#ifdef CONFIG_GRKERNSEC_ROFS
64955 +static int __maybe_unused one = 1;
64956 +#endif
64957 +
64958 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
64959 +struct ctl_table grsecurity_table[] = {
64960 +#ifdef CONFIG_GRKERNSEC_SYSCTL
64961 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
64962 +#ifdef CONFIG_GRKERNSEC_IO
64963 + {
64964 + .procname = "disable_priv_io",
64965 + .data = &grsec_disable_privio,
64966 + .maxlen = sizeof(int),
64967 + .mode = 0600,
64968 + .proc_handler = &proc_dointvec,
64969 + },
64970 +#endif
64971 +#endif
64972 +#ifdef CONFIG_GRKERNSEC_LINK
64973 + {
64974 + .procname = "linking_restrictions",
64975 + .data = &grsec_enable_link,
64976 + .maxlen = sizeof(int),
64977 + .mode = 0600,
64978 + .proc_handler = &proc_dointvec,
64979 + },
64980 +#endif
64981 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64982 + {
64983 + .procname = "enforce_symlinksifowner",
64984 + .data = &grsec_enable_symlinkown,
64985 + .maxlen = sizeof(int),
64986 + .mode = 0600,
64987 + .proc_handler = &proc_dointvec,
64988 + },
64989 + {
64990 + .procname = "symlinkown_gid",
64991 + .data = &grsec_symlinkown_gid,
64992 + .maxlen = sizeof(int),
64993 + .mode = 0600,
64994 + .proc_handler = &proc_dointvec,
64995 + },
64996 +#endif
64997 +#ifdef CONFIG_GRKERNSEC_BRUTE
64998 + {
64999 + .procname = "deter_bruteforce",
65000 + .data = &grsec_enable_brute,
65001 + .maxlen = sizeof(int),
65002 + .mode = 0600,
65003 + .proc_handler = &proc_dointvec,
65004 + },
65005 +#endif
65006 +#ifdef CONFIG_GRKERNSEC_FIFO
65007 + {
65008 + .procname = "fifo_restrictions",
65009 + .data = &grsec_enable_fifo,
65010 + .maxlen = sizeof(int),
65011 + .mode = 0600,
65012 + .proc_handler = &proc_dointvec,
65013 + },
65014 +#endif
65015 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65016 + {
65017 + .procname = "ptrace_readexec",
65018 + .data = &grsec_enable_ptrace_readexec,
65019 + .maxlen = sizeof(int),
65020 + .mode = 0600,
65021 + .proc_handler = &proc_dointvec,
65022 + },
65023 +#endif
65024 +#ifdef CONFIG_GRKERNSEC_SETXID
65025 + {
65026 + .procname = "consistent_setxid",
65027 + .data = &grsec_enable_setxid,
65028 + .maxlen = sizeof(int),
65029 + .mode = 0600,
65030 + .proc_handler = &proc_dointvec,
65031 + },
65032 +#endif
65033 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65034 + {
65035 + .procname = "ip_blackhole",
65036 + .data = &grsec_enable_blackhole,
65037 + .maxlen = sizeof(int),
65038 + .mode = 0600,
65039 + .proc_handler = &proc_dointvec,
65040 + },
65041 + {
65042 + .procname = "lastack_retries",
65043 + .data = &grsec_lastack_retries,
65044 + .maxlen = sizeof(int),
65045 + .mode = 0600,
65046 + .proc_handler = &proc_dointvec,
65047 + },
65048 +#endif
65049 +#ifdef CONFIG_GRKERNSEC_EXECLOG
65050 + {
65051 + .procname = "exec_logging",
65052 + .data = &grsec_enable_execlog,
65053 + .maxlen = sizeof(int),
65054 + .mode = 0600,
65055 + .proc_handler = &proc_dointvec,
65056 + },
65057 +#endif
65058 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65059 + {
65060 + .procname = "rwxmap_logging",
65061 + .data = &grsec_enable_log_rwxmaps,
65062 + .maxlen = sizeof(int),
65063 + .mode = 0600,
65064 + .proc_handler = &proc_dointvec,
65065 + },
65066 +#endif
65067 +#ifdef CONFIG_GRKERNSEC_SIGNAL
65068 + {
65069 + .procname = "signal_logging",
65070 + .data = &grsec_enable_signal,
65071 + .maxlen = sizeof(int),
65072 + .mode = 0600,
65073 + .proc_handler = &proc_dointvec,
65074 + },
65075 +#endif
65076 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
65077 + {
65078 + .procname = "forkfail_logging",
65079 + .data = &grsec_enable_forkfail,
65080 + .maxlen = sizeof(int),
65081 + .mode = 0600,
65082 + .proc_handler = &proc_dointvec,
65083 + },
65084 +#endif
65085 +#ifdef CONFIG_GRKERNSEC_TIME
65086 + {
65087 + .procname = "timechange_logging",
65088 + .data = &grsec_enable_time,
65089 + .maxlen = sizeof(int),
65090 + .mode = 0600,
65091 + .proc_handler = &proc_dointvec,
65092 + },
65093 +#endif
65094 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65095 + {
65096 + .procname = "chroot_deny_shmat",
65097 + .data = &grsec_enable_chroot_shmat,
65098 + .maxlen = sizeof(int),
65099 + .mode = 0600,
65100 + .proc_handler = &proc_dointvec,
65101 + },
65102 +#endif
65103 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65104 + {
65105 + .procname = "chroot_deny_unix",
65106 + .data = &grsec_enable_chroot_unix,
65107 + .maxlen = sizeof(int),
65108 + .mode = 0600,
65109 + .proc_handler = &proc_dointvec,
65110 + },
65111 +#endif
65112 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65113 + {
65114 + .procname = "chroot_deny_mount",
65115 + .data = &grsec_enable_chroot_mount,
65116 + .maxlen = sizeof(int),
65117 + .mode = 0600,
65118 + .proc_handler = &proc_dointvec,
65119 + },
65120 +#endif
65121 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65122 + {
65123 + .procname = "chroot_deny_fchdir",
65124 + .data = &grsec_enable_chroot_fchdir,
65125 + .maxlen = sizeof(int),
65126 + .mode = 0600,
65127 + .proc_handler = &proc_dointvec,
65128 + },
65129 +#endif
65130 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65131 + {
65132 + .procname = "chroot_deny_chroot",
65133 + .data = &grsec_enable_chroot_double,
65134 + .maxlen = sizeof(int),
65135 + .mode = 0600,
65136 + .proc_handler = &proc_dointvec,
65137 + },
65138 +#endif
65139 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65140 + {
65141 + .procname = "chroot_deny_pivot",
65142 + .data = &grsec_enable_chroot_pivot,
65143 + .maxlen = sizeof(int),
65144 + .mode = 0600,
65145 + .proc_handler = &proc_dointvec,
65146 + },
65147 +#endif
65148 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65149 + {
65150 + .procname = "chroot_enforce_chdir",
65151 + .data = &grsec_enable_chroot_chdir,
65152 + .maxlen = sizeof(int),
65153 + .mode = 0600,
65154 + .proc_handler = &proc_dointvec,
65155 + },
65156 +#endif
65157 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65158 + {
65159 + .procname = "chroot_deny_chmod",
65160 + .data = &grsec_enable_chroot_chmod,
65161 + .maxlen = sizeof(int),
65162 + .mode = 0600,
65163 + .proc_handler = &proc_dointvec,
65164 + },
65165 +#endif
65166 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65167 + {
65168 + .procname = "chroot_deny_mknod",
65169 + .data = &grsec_enable_chroot_mknod,
65170 + .maxlen = sizeof(int),
65171 + .mode = 0600,
65172 + .proc_handler = &proc_dointvec,
65173 + },
65174 +#endif
65175 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65176 + {
65177 + .procname = "chroot_restrict_nice",
65178 + .data = &grsec_enable_chroot_nice,
65179 + .maxlen = sizeof(int),
65180 + .mode = 0600,
65181 + .proc_handler = &proc_dointvec,
65182 + },
65183 +#endif
65184 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65185 + {
65186 + .procname = "chroot_execlog",
65187 + .data = &grsec_enable_chroot_execlog,
65188 + .maxlen = sizeof(int),
65189 + .mode = 0600,
65190 + .proc_handler = &proc_dointvec,
65191 + },
65192 +#endif
65193 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65194 + {
65195 + .procname = "chroot_caps",
65196 + .data = &grsec_enable_chroot_caps,
65197 + .maxlen = sizeof(int),
65198 + .mode = 0600,
65199 + .proc_handler = &proc_dointvec,
65200 + },
65201 +#endif
65202 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65203 + {
65204 + .procname = "chroot_deny_sysctl",
65205 + .data = &grsec_enable_chroot_sysctl,
65206 + .maxlen = sizeof(int),
65207 + .mode = 0600,
65208 + .proc_handler = &proc_dointvec,
65209 + },
65210 +#endif
65211 +#ifdef CONFIG_GRKERNSEC_TPE
65212 + {
65213 + .procname = "tpe",
65214 + .data = &grsec_enable_tpe,
65215 + .maxlen = sizeof(int),
65216 + .mode = 0600,
65217 + .proc_handler = &proc_dointvec,
65218 + },
65219 + {
65220 + .procname = "tpe_gid",
65221 + .data = &grsec_tpe_gid,
65222 + .maxlen = sizeof(int),
65223 + .mode = 0600,
65224 + .proc_handler = &proc_dointvec,
65225 + },
65226 +#endif
65227 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65228 + {
65229 + .procname = "tpe_invert",
65230 + .data = &grsec_enable_tpe_invert,
65231 + .maxlen = sizeof(int),
65232 + .mode = 0600,
65233 + .proc_handler = &proc_dointvec,
65234 + },
65235 +#endif
65236 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
65237 + {
65238 + .procname = "tpe_restrict_all",
65239 + .data = &grsec_enable_tpe_all,
65240 + .maxlen = sizeof(int),
65241 + .mode = 0600,
65242 + .proc_handler = &proc_dointvec,
65243 + },
65244 +#endif
65245 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65246 + {
65247 + .procname = "socket_all",
65248 + .data = &grsec_enable_socket_all,
65249 + .maxlen = sizeof(int),
65250 + .mode = 0600,
65251 + .proc_handler = &proc_dointvec,
65252 + },
65253 + {
65254 + .procname = "socket_all_gid",
65255 + .data = &grsec_socket_all_gid,
65256 + .maxlen = sizeof(int),
65257 + .mode = 0600,
65258 + .proc_handler = &proc_dointvec,
65259 + },
65260 +#endif
65261 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65262 + {
65263 + .procname = "socket_client",
65264 + .data = &grsec_enable_socket_client,
65265 + .maxlen = sizeof(int),
65266 + .mode = 0600,
65267 + .proc_handler = &proc_dointvec,
65268 + },
65269 + {
65270 + .procname = "socket_client_gid",
65271 + .data = &grsec_socket_client_gid,
65272 + .maxlen = sizeof(int),
65273 + .mode = 0600,
65274 + .proc_handler = &proc_dointvec,
65275 + },
65276 +#endif
65277 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65278 + {
65279 + .procname = "socket_server",
65280 + .data = &grsec_enable_socket_server,
65281 + .maxlen = sizeof(int),
65282 + .mode = 0600,
65283 + .proc_handler = &proc_dointvec,
65284 + },
65285 + {
65286 + .procname = "socket_server_gid",
65287 + .data = &grsec_socket_server_gid,
65288 + .maxlen = sizeof(int),
65289 + .mode = 0600,
65290 + .proc_handler = &proc_dointvec,
65291 + },
65292 +#endif
65293 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65294 + {
65295 + .procname = "audit_group",
65296 + .data = &grsec_enable_group,
65297 + .maxlen = sizeof(int),
65298 + .mode = 0600,
65299 + .proc_handler = &proc_dointvec,
65300 + },
65301 + {
65302 + .procname = "audit_gid",
65303 + .data = &grsec_audit_gid,
65304 + .maxlen = sizeof(int),
65305 + .mode = 0600,
65306 + .proc_handler = &proc_dointvec,
65307 + },
65308 +#endif
65309 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65310 + {
65311 + .procname = "audit_chdir",
65312 + .data = &grsec_enable_chdir,
65313 + .maxlen = sizeof(int),
65314 + .mode = 0600,
65315 + .proc_handler = &proc_dointvec,
65316 + },
65317 +#endif
65318 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65319 + {
65320 + .procname = "audit_mount",
65321 + .data = &grsec_enable_mount,
65322 + .maxlen = sizeof(int),
65323 + .mode = 0600,
65324 + .proc_handler = &proc_dointvec,
65325 + },
65326 +#endif
65327 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65328 + {
65329 + .procname = "audit_textrel",
65330 + .data = &grsec_enable_audit_textrel,
65331 + .maxlen = sizeof(int),
65332 + .mode = 0600,
65333 + .proc_handler = &proc_dointvec,
65334 + },
65335 +#endif
65336 +#ifdef CONFIG_GRKERNSEC_DMESG
65337 + {
65338 + .procname = "dmesg",
65339 + .data = &grsec_enable_dmesg,
65340 + .maxlen = sizeof(int),
65341 + .mode = 0600,
65342 + .proc_handler = &proc_dointvec,
65343 + },
65344 +#endif
65345 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65346 + {
65347 + .procname = "chroot_findtask",
65348 + .data = &grsec_enable_chroot_findtask,
65349 + .maxlen = sizeof(int),
65350 + .mode = 0600,
65351 + .proc_handler = &proc_dointvec,
65352 + },
65353 +#endif
65354 +#ifdef CONFIG_GRKERNSEC_RESLOG
65355 + {
65356 + .procname = "resource_logging",
65357 + .data = &grsec_resource_logging,
65358 + .maxlen = sizeof(int),
65359 + .mode = 0600,
65360 + .proc_handler = &proc_dointvec,
65361 + },
65362 +#endif
65363 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65364 + {
65365 + .procname = "audit_ptrace",
65366 + .data = &grsec_enable_audit_ptrace,
65367 + .maxlen = sizeof(int),
65368 + .mode = 0600,
65369 + .proc_handler = &proc_dointvec,
65370 + },
65371 +#endif
65372 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65373 + {
65374 + .procname = "harden_ptrace",
65375 + .data = &grsec_enable_harden_ptrace,
65376 + .maxlen = sizeof(int),
65377 + .mode = 0600,
65378 + .proc_handler = &proc_dointvec,
65379 + },
65380 +#endif
65381 + {
65382 + .procname = "grsec_lock",
65383 + .data = &grsec_lock,
65384 + .maxlen = sizeof(int),
65385 + .mode = 0600,
65386 + .proc_handler = &proc_dointvec,
65387 + },
65388 +#endif
65389 +#ifdef CONFIG_GRKERNSEC_ROFS
65390 + {
65391 + .procname = "romount_protect",
65392 + .data = &grsec_enable_rofs,
65393 + .maxlen = sizeof(int),
65394 + .mode = 0600,
65395 + .proc_handler = &proc_dointvec_minmax,
65396 + .extra1 = &one,
65397 + .extra2 = &one,
65398 + },
65399 +#endif
65400 + { }
65401 +};
65402 +#endif
65403 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
65404 new file mode 100644
65405 index 0000000..0dc13c3
65406 --- /dev/null
65407 +++ b/grsecurity/grsec_time.c
65408 @@ -0,0 +1,16 @@
65409 +#include <linux/kernel.h>
65410 +#include <linux/sched.h>
65411 +#include <linux/grinternal.h>
65412 +#include <linux/module.h>
65413 +
65414 +void
65415 +gr_log_timechange(void)
65416 +{
65417 +#ifdef CONFIG_GRKERNSEC_TIME
65418 + if (grsec_enable_time)
65419 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
65420 +#endif
65421 + return;
65422 +}
65423 +
65424 +EXPORT_SYMBOL(gr_log_timechange);
65425 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
65426 new file mode 100644
65427 index 0000000..ee57dcf
65428 --- /dev/null
65429 +++ b/grsecurity/grsec_tpe.c
65430 @@ -0,0 +1,73 @@
65431 +#include <linux/kernel.h>
65432 +#include <linux/sched.h>
65433 +#include <linux/file.h>
65434 +#include <linux/fs.h>
65435 +#include <linux/grinternal.h>
65436 +
65437 +extern int gr_acl_tpe_check(void);
65438 +
65439 +int
65440 +gr_tpe_allow(const struct file *file)
65441 +{
65442 +#ifdef CONFIG_GRKERNSEC
65443 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
65444 + const struct cred *cred = current_cred();
65445 + char *msg = NULL;
65446 + char *msg2 = NULL;
65447 +
65448 + // never restrict root
65449 + if (gr_is_global_root(cred->uid))
65450 + return 1;
65451 +
65452 + if (grsec_enable_tpe) {
65453 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65454 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
65455 + msg = "not being in trusted group";
65456 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
65457 + msg = "being in untrusted group";
65458 +#else
65459 + if (in_group_p(grsec_tpe_gid))
65460 + msg = "being in untrusted group";
65461 +#endif
65462 + }
65463 + if (!msg && gr_acl_tpe_check())
65464 + msg = "being in untrusted role";
65465 +
65466 + // not in any affected group/role
65467 + if (!msg)
65468 + goto next_check;
65469 +
65470 + if (gr_is_global_nonroot(inode->i_uid))
65471 + msg2 = "file in non-root-owned directory";
65472 + else if (inode->i_mode & S_IWOTH)
65473 + msg2 = "file in world-writable directory";
65474 + else if (inode->i_mode & S_IWGRP)
65475 + msg2 = "file in group-writable directory";
65476 +
65477 + if (msg && msg2) {
65478 + char fullmsg[70] = {0};
65479 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
65480 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
65481 + return 0;
65482 + }
65483 + msg = NULL;
65484 +next_check:
65485 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
65486 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
65487 + return 1;
65488 +
65489 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
65490 + msg = "directory not owned by user";
65491 + else if (inode->i_mode & S_IWOTH)
65492 + msg = "file in world-writable directory";
65493 + else if (inode->i_mode & S_IWGRP)
65494 + msg = "file in group-writable directory";
65495 +
65496 + if (msg) {
65497 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
65498 + return 0;
65499 + }
65500 +#endif
65501 +#endif
65502 + return 1;
65503 +}
65504 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
65505 new file mode 100644
65506 index 0000000..9f7b1ac
65507 --- /dev/null
65508 +++ b/grsecurity/grsum.c
65509 @@ -0,0 +1,61 @@
65510 +#include <linux/err.h>
65511 +#include <linux/kernel.h>
65512 +#include <linux/sched.h>
65513 +#include <linux/mm.h>
65514 +#include <linux/scatterlist.h>
65515 +#include <linux/crypto.h>
65516 +#include <linux/gracl.h>
65517 +
65518 +
65519 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
65520 +#error "crypto and sha256 must be built into the kernel"
65521 +#endif
65522 +
65523 +int
65524 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
65525 +{
65526 + char *p;
65527 + struct crypto_hash *tfm;
65528 + struct hash_desc desc;
65529 + struct scatterlist sg;
65530 + unsigned char temp_sum[GR_SHA_LEN];
65531 + volatile int retval = 0;
65532 + volatile int dummy = 0;
65533 + unsigned int i;
65534 +
65535 + sg_init_table(&sg, 1);
65536 +
65537 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
65538 + if (IS_ERR(tfm)) {
65539 + /* should never happen, since sha256 should be built in */
65540 + return 1;
65541 + }
65542 +
65543 + desc.tfm = tfm;
65544 + desc.flags = 0;
65545 +
65546 + crypto_hash_init(&desc);
65547 +
65548 + p = salt;
65549 + sg_set_buf(&sg, p, GR_SALT_LEN);
65550 + crypto_hash_update(&desc, &sg, sg.length);
65551 +
65552 + p = entry->pw;
65553 + sg_set_buf(&sg, p, strlen(p));
65554 +
65555 + crypto_hash_update(&desc, &sg, sg.length);
65556 +
65557 + crypto_hash_final(&desc, temp_sum);
65558 +
65559 + memset(entry->pw, 0, GR_PW_LEN);
65560 +
65561 + for (i = 0; i < GR_SHA_LEN; i++)
65562 + if (sum[i] != temp_sum[i])
65563 + retval = 1;
65564 + else
65565 + dummy = 1; // waste a cycle
65566 +
65567 + crypto_free_hash(tfm);
65568 +
65569 + return retval;
65570 +}
65571 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
65572 index 77ff547..181834f 100644
65573 --- a/include/asm-generic/4level-fixup.h
65574 +++ b/include/asm-generic/4level-fixup.h
65575 @@ -13,8 +13,10 @@
65576 #define pmd_alloc(mm, pud, address) \
65577 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
65578 NULL: pmd_offset(pud, address))
65579 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
65580
65581 #define pud_alloc(mm, pgd, address) (pgd)
65582 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
65583 #define pud_offset(pgd, start) (pgd)
65584 #define pud_none(pud) 0
65585 #define pud_bad(pud) 0
65586 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
65587 index b7babf0..04ad282 100644
65588 --- a/include/asm-generic/atomic-long.h
65589 +++ b/include/asm-generic/atomic-long.h
65590 @@ -22,6 +22,12 @@
65591
65592 typedef atomic64_t atomic_long_t;
65593
65594 +#ifdef CONFIG_PAX_REFCOUNT
65595 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
65596 +#else
65597 +typedef atomic64_t atomic_long_unchecked_t;
65598 +#endif
65599 +
65600 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
65601
65602 static inline long atomic_long_read(atomic_long_t *l)
65603 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
65604 return (long)atomic64_read(v);
65605 }
65606
65607 +#ifdef CONFIG_PAX_REFCOUNT
65608 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
65609 +{
65610 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65611 +
65612 + return (long)atomic64_read_unchecked(v);
65613 +}
65614 +#endif
65615 +
65616 static inline void atomic_long_set(atomic_long_t *l, long i)
65617 {
65618 atomic64_t *v = (atomic64_t *)l;
65619 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
65620 atomic64_set(v, i);
65621 }
65622
65623 +#ifdef CONFIG_PAX_REFCOUNT
65624 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
65625 +{
65626 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65627 +
65628 + atomic64_set_unchecked(v, i);
65629 +}
65630 +#endif
65631 +
65632 static inline void atomic_long_inc(atomic_long_t *l)
65633 {
65634 atomic64_t *v = (atomic64_t *)l;
65635 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
65636 atomic64_inc(v);
65637 }
65638
65639 +#ifdef CONFIG_PAX_REFCOUNT
65640 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
65641 +{
65642 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65643 +
65644 + atomic64_inc_unchecked(v);
65645 +}
65646 +#endif
65647 +
65648 static inline void atomic_long_dec(atomic_long_t *l)
65649 {
65650 atomic64_t *v = (atomic64_t *)l;
65651 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
65652 atomic64_dec(v);
65653 }
65654
65655 +#ifdef CONFIG_PAX_REFCOUNT
65656 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
65657 +{
65658 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65659 +
65660 + atomic64_dec_unchecked(v);
65661 +}
65662 +#endif
65663 +
65664 static inline void atomic_long_add(long i, atomic_long_t *l)
65665 {
65666 atomic64_t *v = (atomic64_t *)l;
65667 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
65668 atomic64_add(i, v);
65669 }
65670
65671 +#ifdef CONFIG_PAX_REFCOUNT
65672 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
65673 +{
65674 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65675 +
65676 + atomic64_add_unchecked(i, v);
65677 +}
65678 +#endif
65679 +
65680 static inline void atomic_long_sub(long i, atomic_long_t *l)
65681 {
65682 atomic64_t *v = (atomic64_t *)l;
65683 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
65684 atomic64_sub(i, v);
65685 }
65686
65687 +#ifdef CONFIG_PAX_REFCOUNT
65688 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
65689 +{
65690 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65691 +
65692 + atomic64_sub_unchecked(i, v);
65693 +}
65694 +#endif
65695 +
65696 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
65697 {
65698 atomic64_t *v = (atomic64_t *)l;
65699 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
65700 return (long)atomic64_add_return(i, v);
65701 }
65702
65703 +#ifdef CONFIG_PAX_REFCOUNT
65704 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
65705 +{
65706 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65707 +
65708 + return (long)atomic64_add_return_unchecked(i, v);
65709 +}
65710 +#endif
65711 +
65712 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
65713 {
65714 atomic64_t *v = (atomic64_t *)l;
65715 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
65716 return (long)atomic64_inc_return(v);
65717 }
65718
65719 +#ifdef CONFIG_PAX_REFCOUNT
65720 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
65721 +{
65722 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65723 +
65724 + return (long)atomic64_inc_return_unchecked(v);
65725 +}
65726 +#endif
65727 +
65728 static inline long atomic_long_dec_return(atomic_long_t *l)
65729 {
65730 atomic64_t *v = (atomic64_t *)l;
65731 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
65732
65733 typedef atomic_t atomic_long_t;
65734
65735 +#ifdef CONFIG_PAX_REFCOUNT
65736 +typedef atomic_unchecked_t atomic_long_unchecked_t;
65737 +#else
65738 +typedef atomic_t atomic_long_unchecked_t;
65739 +#endif
65740 +
65741 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
65742 static inline long atomic_long_read(atomic_long_t *l)
65743 {
65744 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
65745 return (long)atomic_read(v);
65746 }
65747
65748 +#ifdef CONFIG_PAX_REFCOUNT
65749 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
65750 +{
65751 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65752 +
65753 + return (long)atomic_read_unchecked(v);
65754 +}
65755 +#endif
65756 +
65757 static inline void atomic_long_set(atomic_long_t *l, long i)
65758 {
65759 atomic_t *v = (atomic_t *)l;
65760 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
65761 atomic_set(v, i);
65762 }
65763
65764 +#ifdef CONFIG_PAX_REFCOUNT
65765 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
65766 +{
65767 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65768 +
65769 + atomic_set_unchecked(v, i);
65770 +}
65771 +#endif
65772 +
65773 static inline void atomic_long_inc(atomic_long_t *l)
65774 {
65775 atomic_t *v = (atomic_t *)l;
65776 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
65777 atomic_inc(v);
65778 }
65779
65780 +#ifdef CONFIG_PAX_REFCOUNT
65781 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
65782 +{
65783 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65784 +
65785 + atomic_inc_unchecked(v);
65786 +}
65787 +#endif
65788 +
65789 static inline void atomic_long_dec(atomic_long_t *l)
65790 {
65791 atomic_t *v = (atomic_t *)l;
65792 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
65793 atomic_dec(v);
65794 }
65795
65796 +#ifdef CONFIG_PAX_REFCOUNT
65797 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
65798 +{
65799 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65800 +
65801 + atomic_dec_unchecked(v);
65802 +}
65803 +#endif
65804 +
65805 static inline void atomic_long_add(long i, atomic_long_t *l)
65806 {
65807 atomic_t *v = (atomic_t *)l;
65808 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
65809 atomic_add(i, v);
65810 }
65811
65812 +#ifdef CONFIG_PAX_REFCOUNT
65813 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
65814 +{
65815 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65816 +
65817 + atomic_add_unchecked(i, v);
65818 +}
65819 +#endif
65820 +
65821 static inline void atomic_long_sub(long i, atomic_long_t *l)
65822 {
65823 atomic_t *v = (atomic_t *)l;
65824 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
65825 atomic_sub(i, v);
65826 }
65827
65828 +#ifdef CONFIG_PAX_REFCOUNT
65829 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
65830 +{
65831 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65832 +
65833 + atomic_sub_unchecked(i, v);
65834 +}
65835 +#endif
65836 +
65837 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
65838 {
65839 atomic_t *v = (atomic_t *)l;
65840 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
65841 return (long)atomic_add_return(i, v);
65842 }
65843
65844 +#ifdef CONFIG_PAX_REFCOUNT
65845 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
65846 +{
65847 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65848 +
65849 + return (long)atomic_add_return_unchecked(i, v);
65850 +}
65851 +
65852 +#endif
65853 +
65854 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
65855 {
65856 atomic_t *v = (atomic_t *)l;
65857 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
65858 return (long)atomic_inc_return(v);
65859 }
65860
65861 +#ifdef CONFIG_PAX_REFCOUNT
65862 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
65863 +{
65864 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65865 +
65866 + return (long)atomic_inc_return_unchecked(v);
65867 +}
65868 +#endif
65869 +
65870 static inline long atomic_long_dec_return(atomic_long_t *l)
65871 {
65872 atomic_t *v = (atomic_t *)l;
65873 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
65874
65875 #endif /* BITS_PER_LONG == 64 */
65876
65877 +#ifdef CONFIG_PAX_REFCOUNT
65878 +static inline void pax_refcount_needs_these_functions(void)
65879 +{
65880 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
65881 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
65882 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
65883 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
65884 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
65885 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
65886 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
65887 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
65888 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
65889 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
65890 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
65891 +#ifdef CONFIG_X86
65892 + atomic_clear_mask_unchecked(0, NULL);
65893 + atomic_set_mask_unchecked(0, NULL);
65894 +#endif
65895 +
65896 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
65897 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
65898 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
65899 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
65900 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
65901 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
65902 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
65903 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
65904 +}
65905 +#else
65906 +#define atomic_read_unchecked(v) atomic_read(v)
65907 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
65908 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
65909 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
65910 +#define atomic_inc_unchecked(v) atomic_inc(v)
65911 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
65912 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
65913 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
65914 +#define atomic_dec_unchecked(v) atomic_dec(v)
65915 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
65916 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
65917 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
65918 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
65919 +
65920 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
65921 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
65922 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
65923 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
65924 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
65925 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
65926 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
65927 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
65928 +#endif
65929 +
65930 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
65931 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
65932 index 1ced641..c896ee8 100644
65933 --- a/include/asm-generic/atomic.h
65934 +++ b/include/asm-generic/atomic.h
65935 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
65936 * Atomically clears the bits set in @mask from @v
65937 */
65938 #ifndef atomic_clear_mask
65939 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
65940 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
65941 {
65942 unsigned long flags;
65943
65944 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
65945 index b18ce4f..2ee2843 100644
65946 --- a/include/asm-generic/atomic64.h
65947 +++ b/include/asm-generic/atomic64.h
65948 @@ -16,6 +16,8 @@ typedef struct {
65949 long long counter;
65950 } atomic64_t;
65951
65952 +typedef atomic64_t atomic64_unchecked_t;
65953 +
65954 #define ATOMIC64_INIT(i) { (i) }
65955
65956 extern long long atomic64_read(const atomic64_t *v);
65957 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
65958 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
65959 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
65960
65961 +#define atomic64_read_unchecked(v) atomic64_read(v)
65962 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
65963 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
65964 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
65965 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
65966 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
65967 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
65968 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
65969 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
65970 +
65971 #endif /* _ASM_GENERIC_ATOMIC64_H */
65972 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
65973 index 1bfcfe5..e04c5c9 100644
65974 --- a/include/asm-generic/cache.h
65975 +++ b/include/asm-generic/cache.h
65976 @@ -6,7 +6,7 @@
65977 * cache lines need to provide their own cache.h.
65978 */
65979
65980 -#define L1_CACHE_SHIFT 5
65981 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
65982 +#define L1_CACHE_SHIFT 5UL
65983 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
65984
65985 #endif /* __ASM_GENERIC_CACHE_H */
65986 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
65987 index 0d68a1e..b74a761 100644
65988 --- a/include/asm-generic/emergency-restart.h
65989 +++ b/include/asm-generic/emergency-restart.h
65990 @@ -1,7 +1,7 @@
65991 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
65992 #define _ASM_GENERIC_EMERGENCY_RESTART_H
65993
65994 -static inline void machine_emergency_restart(void)
65995 +static inline __noreturn void machine_emergency_restart(void)
65996 {
65997 machine_restart(NULL);
65998 }
65999 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
66000 index 90f99c7..00ce236 100644
66001 --- a/include/asm-generic/kmap_types.h
66002 +++ b/include/asm-generic/kmap_types.h
66003 @@ -2,9 +2,9 @@
66004 #define _ASM_GENERIC_KMAP_TYPES_H
66005
66006 #ifdef __WITH_KM_FENCE
66007 -# define KM_TYPE_NR 41
66008 +# define KM_TYPE_NR 42
66009 #else
66010 -# define KM_TYPE_NR 20
66011 +# define KM_TYPE_NR 21
66012 #endif
66013
66014 #endif
66015 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
66016 index 9ceb03b..62b0b8f 100644
66017 --- a/include/asm-generic/local.h
66018 +++ b/include/asm-generic/local.h
66019 @@ -23,24 +23,37 @@ typedef struct
66020 atomic_long_t a;
66021 } local_t;
66022
66023 +typedef struct {
66024 + atomic_long_unchecked_t a;
66025 +} local_unchecked_t;
66026 +
66027 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
66028
66029 #define local_read(l) atomic_long_read(&(l)->a)
66030 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
66031 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
66032 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
66033 #define local_inc(l) atomic_long_inc(&(l)->a)
66034 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
66035 #define local_dec(l) atomic_long_dec(&(l)->a)
66036 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
66037 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
66038 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
66039 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
66040 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
66041
66042 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
66043 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
66044 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
66045 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
66046 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
66047 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
66048 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
66049 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
66050 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
66051
66052 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66053 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66054 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
66055 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
66056 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
66057 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
66058 index 725612b..9cc513a 100644
66059 --- a/include/asm-generic/pgtable-nopmd.h
66060 +++ b/include/asm-generic/pgtable-nopmd.h
66061 @@ -1,14 +1,19 @@
66062 #ifndef _PGTABLE_NOPMD_H
66063 #define _PGTABLE_NOPMD_H
66064
66065 -#ifndef __ASSEMBLY__
66066 -
66067 #include <asm-generic/pgtable-nopud.h>
66068
66069 -struct mm_struct;
66070 -
66071 #define __PAGETABLE_PMD_FOLDED
66072
66073 +#define PMD_SHIFT PUD_SHIFT
66074 +#define PTRS_PER_PMD 1
66075 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
66076 +#define PMD_MASK (~(PMD_SIZE-1))
66077 +
66078 +#ifndef __ASSEMBLY__
66079 +
66080 +struct mm_struct;
66081 +
66082 /*
66083 * Having the pmd type consist of a pud gets the size right, and allows
66084 * us to conceptually access the pud entry that this pmd is folded into
66085 @@ -16,11 +21,6 @@ struct mm_struct;
66086 */
66087 typedef struct { pud_t pud; } pmd_t;
66088
66089 -#define PMD_SHIFT PUD_SHIFT
66090 -#define PTRS_PER_PMD 1
66091 -#define PMD_SIZE (1UL << PMD_SHIFT)
66092 -#define PMD_MASK (~(PMD_SIZE-1))
66093 -
66094 /*
66095 * The "pud_xxx()" functions here are trivial for a folded two-level
66096 * setup: the pmd is never bad, and a pmd always exists (as it's folded
66097 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
66098 index 810431d..0ec4804f 100644
66099 --- a/include/asm-generic/pgtable-nopud.h
66100 +++ b/include/asm-generic/pgtable-nopud.h
66101 @@ -1,10 +1,15 @@
66102 #ifndef _PGTABLE_NOPUD_H
66103 #define _PGTABLE_NOPUD_H
66104
66105 -#ifndef __ASSEMBLY__
66106 -
66107 #define __PAGETABLE_PUD_FOLDED
66108
66109 +#define PUD_SHIFT PGDIR_SHIFT
66110 +#define PTRS_PER_PUD 1
66111 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
66112 +#define PUD_MASK (~(PUD_SIZE-1))
66113 +
66114 +#ifndef __ASSEMBLY__
66115 +
66116 /*
66117 * Having the pud type consist of a pgd gets the size right, and allows
66118 * us to conceptually access the pgd entry that this pud is folded into
66119 @@ -12,11 +17,6 @@
66120 */
66121 typedef struct { pgd_t pgd; } pud_t;
66122
66123 -#define PUD_SHIFT PGDIR_SHIFT
66124 -#define PTRS_PER_PUD 1
66125 -#define PUD_SIZE (1UL << PUD_SHIFT)
66126 -#define PUD_MASK (~(PUD_SIZE-1))
66127 -
66128 /*
66129 * The "pgd_xxx()" functions here are trivial for a folded two-level
66130 * setup: the pud is never bad, and a pud always exists (as it's folded
66131 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
66132 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
66133
66134 #define pgd_populate(mm, pgd, pud) do { } while (0)
66135 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
66136 /*
66137 * (puds are folded into pgds so this doesn't get actually called,
66138 * but the define is needed for a generic inline function.)
66139 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
66140 index 5cf680a..4b74d62 100644
66141 --- a/include/asm-generic/pgtable.h
66142 +++ b/include/asm-generic/pgtable.h
66143 @@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
66144 }
66145 #endif /* CONFIG_NUMA_BALANCING */
66146
66147 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
66148 +static inline unsigned long pax_open_kernel(void) { return 0; }
66149 +#endif
66150 +
66151 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
66152 +static inline unsigned long pax_close_kernel(void) { return 0; }
66153 +#endif
66154 +
66155 #endif /* CONFIG_MMU */
66156
66157 #endif /* !__ASSEMBLY__ */
66158 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
66159 index d1ea7ce..b1ebf2a 100644
66160 --- a/include/asm-generic/vmlinux.lds.h
66161 +++ b/include/asm-generic/vmlinux.lds.h
66162 @@ -218,6 +218,7 @@
66163 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
66164 VMLINUX_SYMBOL(__start_rodata) = .; \
66165 *(.rodata) *(.rodata.*) \
66166 + *(.data..read_only) \
66167 *(__vermagic) /* Kernel version magic */ \
66168 . = ALIGN(8); \
66169 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
66170 @@ -725,17 +726,18 @@
66171 * section in the linker script will go there too. @phdr should have
66172 * a leading colon.
66173 *
66174 - * Note that this macros defines __per_cpu_load as an absolute symbol.
66175 + * Note that this macros defines per_cpu_load as an absolute symbol.
66176 * If there is no need to put the percpu section at a predetermined
66177 * address, use PERCPU_SECTION.
66178 */
66179 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
66180 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
66181 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
66182 + per_cpu_load = .; \
66183 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
66184 - LOAD_OFFSET) { \
66185 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
66186 PERCPU_INPUT(cacheline) \
66187 } phdr \
66188 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
66189 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
66190
66191 /**
66192 * PERCPU_SECTION - define output section for percpu area, simple version
66193 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
66194 index 418d270..bfd2794 100644
66195 --- a/include/crypto/algapi.h
66196 +++ b/include/crypto/algapi.h
66197 @@ -34,7 +34,7 @@ struct crypto_type {
66198 unsigned int maskclear;
66199 unsigned int maskset;
66200 unsigned int tfmsize;
66201 -};
66202 +} __do_const;
66203
66204 struct crypto_instance {
66205 struct crypto_alg alg;
66206 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
66207 index fad21c9..ab858bc 100644
66208 --- a/include/drm/drmP.h
66209 +++ b/include/drm/drmP.h
66210 @@ -72,6 +72,7 @@
66211 #include <linux/workqueue.h>
66212 #include <linux/poll.h>
66213 #include <asm/pgalloc.h>
66214 +#include <asm/local.h>
66215 #include <drm/drm.h>
66216 #include <drm/drm_sarea.h>
66217
66218 @@ -293,10 +294,12 @@ do { \
66219 * \param cmd command.
66220 * \param arg argument.
66221 */
66222 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
66223 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
66224 + struct drm_file *file_priv);
66225 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
66226 struct drm_file *file_priv);
66227
66228 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66229 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
66230 unsigned long arg);
66231
66232 #define DRM_IOCTL_NR(n) _IOC_NR(n)
66233 @@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66234 struct drm_ioctl_desc {
66235 unsigned int cmd;
66236 int flags;
66237 - drm_ioctl_t *func;
66238 + drm_ioctl_t func;
66239 unsigned int cmd_drv;
66240 -};
66241 +} __do_const;
66242
66243 /**
66244 * Creates a driver or general drm_ioctl_desc array entry for the given
66245 @@ -995,7 +998,7 @@ struct drm_info_list {
66246 int (*show)(struct seq_file*, void*); /** show callback */
66247 u32 driver_features; /**< Required driver features for this entry */
66248 void *data;
66249 -};
66250 +} __do_const;
66251
66252 /**
66253 * debugfs node structure. This structure represents a debugfs file.
66254 @@ -1068,7 +1071,7 @@ struct drm_device {
66255
66256 /** \name Usage Counters */
66257 /*@{ */
66258 - int open_count; /**< Outstanding files open */
66259 + local_t open_count; /**< Outstanding files open */
66260 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
66261 atomic_t vma_count; /**< Outstanding vma areas open */
66262 int buf_use; /**< Buffers in use -- cannot alloc */
66263 @@ -1079,7 +1082,7 @@ struct drm_device {
66264 /*@{ */
66265 unsigned long counters;
66266 enum drm_stat_type types[15];
66267 - atomic_t counts[15];
66268 + atomic_unchecked_t counts[15];
66269 /*@} */
66270
66271 struct list_head filelist;
66272 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
66273 index f43d556..94d9343 100644
66274 --- a/include/drm/drm_crtc_helper.h
66275 +++ b/include/drm/drm_crtc_helper.h
66276 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
66277 struct drm_connector *connector);
66278 /* disable encoder when not in use - more explicit than dpms off */
66279 void (*disable)(struct drm_encoder *encoder);
66280 -};
66281 +} __no_const;
66282
66283 /**
66284 * drm_connector_helper_funcs - helper operations for connectors
66285 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
66286 index 72dcbe8..8db58d7 100644
66287 --- a/include/drm/ttm/ttm_memory.h
66288 +++ b/include/drm/ttm/ttm_memory.h
66289 @@ -48,7 +48,7 @@
66290
66291 struct ttm_mem_shrink {
66292 int (*do_shrink) (struct ttm_mem_shrink *);
66293 -};
66294 +} __no_const;
66295
66296 /**
66297 * struct ttm_mem_global - Global memory accounting structure.
66298 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
66299 index 4b840e8..155d235 100644
66300 --- a/include/keys/asymmetric-subtype.h
66301 +++ b/include/keys/asymmetric-subtype.h
66302 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
66303 /* Verify the signature on a key of this subtype (optional) */
66304 int (*verify_signature)(const struct key *key,
66305 const struct public_key_signature *sig);
66306 -};
66307 +} __do_const;
66308
66309 /**
66310 * asymmetric_key_subtype - Get the subtype from an asymmetric key
66311 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
66312 index c1da539..1dcec55 100644
66313 --- a/include/linux/atmdev.h
66314 +++ b/include/linux/atmdev.h
66315 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
66316 #endif
66317
66318 struct k_atm_aal_stats {
66319 -#define __HANDLE_ITEM(i) atomic_t i
66320 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
66321 __AAL_STAT_ITEMS
66322 #undef __HANDLE_ITEM
66323 };
66324 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
66325 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
66326 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
66327 struct module *owner;
66328 -};
66329 +} __do_const ;
66330
66331 struct atmphy_ops {
66332 int (*start)(struct atm_dev *dev);
66333 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
66334 index 0530b98..96a8ac0 100644
66335 --- a/include/linux/binfmts.h
66336 +++ b/include/linux/binfmts.h
66337 @@ -73,8 +73,9 @@ struct linux_binfmt {
66338 int (*load_binary)(struct linux_binprm *);
66339 int (*load_shlib)(struct file *);
66340 int (*core_dump)(struct coredump_params *cprm);
66341 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
66342 unsigned long min_coredump; /* minimal dump size */
66343 -};
66344 +} __do_const;
66345
66346 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
66347
66348 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
66349 index f94bc83..62b9cfe 100644
66350 --- a/include/linux/blkdev.h
66351 +++ b/include/linux/blkdev.h
66352 @@ -1498,7 +1498,7 @@ struct block_device_operations {
66353 /* this callback is with swap_lock and sometimes page table lock held */
66354 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
66355 struct module *owner;
66356 -};
66357 +} __do_const;
66358
66359 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
66360 unsigned long);
66361 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
66362 index 7c2e030..b72475d 100644
66363 --- a/include/linux/blktrace_api.h
66364 +++ b/include/linux/blktrace_api.h
66365 @@ -23,7 +23,7 @@ struct blk_trace {
66366 struct dentry *dir;
66367 struct dentry *dropped_file;
66368 struct dentry *msg_file;
66369 - atomic_t dropped;
66370 + atomic_unchecked_t dropped;
66371 };
66372
66373 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
66374 diff --git a/include/linux/cache.h b/include/linux/cache.h
66375 index 4c57065..4307975 100644
66376 --- a/include/linux/cache.h
66377 +++ b/include/linux/cache.h
66378 @@ -16,6 +16,10 @@
66379 #define __read_mostly
66380 #endif
66381
66382 +#ifndef __read_only
66383 +#define __read_only __read_mostly
66384 +#endif
66385 +
66386 #ifndef ____cacheline_aligned
66387 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
66388 #endif
66389 diff --git a/include/linux/capability.h b/include/linux/capability.h
66390 index 98503b7..cc36d18 100644
66391 --- a/include/linux/capability.h
66392 +++ b/include/linux/capability.h
66393 @@ -211,8 +211,13 @@ extern bool capable(int cap);
66394 extern bool ns_capable(struct user_namespace *ns, int cap);
66395 extern bool nsown_capable(int cap);
66396 extern bool inode_capable(const struct inode *inode, int cap);
66397 +extern bool capable_nolog(int cap);
66398 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
66399 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
66400
66401 /* audit system wants to get cap info from files as well */
66402 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
66403
66404 +extern int is_privileged_binary(const struct dentry *dentry);
66405 +
66406 #endif /* !_LINUX_CAPABILITY_H */
66407 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
66408 index 8609d57..86e4d79 100644
66409 --- a/include/linux/cdrom.h
66410 +++ b/include/linux/cdrom.h
66411 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
66412
66413 /* driver specifications */
66414 const int capability; /* capability flags */
66415 - int n_minors; /* number of active minor devices */
66416 /* handle uniform packets for scsi type devices (scsi,atapi) */
66417 int (*generic_packet) (struct cdrom_device_info *,
66418 struct packet_command *);
66419 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
66420 index 42e55de..1cd0e66 100644
66421 --- a/include/linux/cleancache.h
66422 +++ b/include/linux/cleancache.h
66423 @@ -31,7 +31,7 @@ struct cleancache_ops {
66424 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
66425 void (*invalidate_inode)(int, struct cleancache_filekey);
66426 void (*invalidate_fs)(int);
66427 -};
66428 +} __no_const;
66429
66430 extern struct cleancache_ops
66431 cleancache_register_ops(struct cleancache_ops *ops);
66432 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
66433 index 662fd1b..e801992 100644
66434 --- a/include/linux/compiler-gcc4.h
66435 +++ b/include/linux/compiler-gcc4.h
66436 @@ -34,6 +34,21 @@
66437 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
66438
66439 #if __GNUC_MINOR__ >= 5
66440 +
66441 +#ifdef CONSTIFY_PLUGIN
66442 +#define __no_const __attribute__((no_const))
66443 +#define __do_const __attribute__((do_const))
66444 +#endif
66445 +
66446 +#ifdef SIZE_OVERFLOW_PLUGIN
66447 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
66448 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
66449 +#endif
66450 +
66451 +#ifdef LATENT_ENTROPY_PLUGIN
66452 +#define __latent_entropy __attribute__((latent_entropy))
66453 +#endif
66454 +
66455 /*
66456 * Mark a position in code as unreachable. This can be used to
66457 * suppress control flow warnings after asm blocks that transfer
66458 @@ -49,6 +64,11 @@
66459 #define __noclone __attribute__((__noclone__))
66460
66461 #endif
66462 +
66463 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
66464 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
66465 +#define __bos0(ptr) __bos((ptr), 0)
66466 +#define __bos1(ptr) __bos((ptr), 1)
66467 #endif
66468
66469 #if __GNUC_MINOR__ >= 6
66470 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
66471 index dd852b7..72924c0 100644
66472 --- a/include/linux/compiler.h
66473 +++ b/include/linux/compiler.h
66474 @@ -5,11 +5,14 @@
66475
66476 #ifdef __CHECKER__
66477 # define __user __attribute__((noderef, address_space(1)))
66478 +# define __force_user __force __user
66479 # define __kernel __attribute__((address_space(0)))
66480 +# define __force_kernel __force __kernel
66481 # define __safe __attribute__((safe))
66482 # define __force __attribute__((force))
66483 # define __nocast __attribute__((nocast))
66484 # define __iomem __attribute__((noderef, address_space(2)))
66485 +# define __force_iomem __force __iomem
66486 # define __must_hold(x) __attribute__((context(x,1,1)))
66487 # define __acquires(x) __attribute__((context(x,0,1)))
66488 # define __releases(x) __attribute__((context(x,1,0)))
66489 @@ -17,20 +20,48 @@
66490 # define __release(x) __context__(x,-1)
66491 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
66492 # define __percpu __attribute__((noderef, address_space(3)))
66493 +# define __force_percpu __force __percpu
66494 #ifdef CONFIG_SPARSE_RCU_POINTER
66495 # define __rcu __attribute__((noderef, address_space(4)))
66496 +# define __force_rcu __force __rcu
66497 #else
66498 # define __rcu
66499 +# define __force_rcu
66500 #endif
66501 extern void __chk_user_ptr(const volatile void __user *);
66502 extern void __chk_io_ptr(const volatile void __iomem *);
66503 +#elif defined(CHECKER_PLUGIN)
66504 +//# define __user
66505 +//# define __force_user
66506 +//# define __kernel
66507 +//# define __force_kernel
66508 +# define __safe
66509 +# define __force
66510 +# define __nocast
66511 +# define __iomem
66512 +# define __force_iomem
66513 +# define __chk_user_ptr(x) (void)0
66514 +# define __chk_io_ptr(x) (void)0
66515 +# define __builtin_warning(x, y...) (1)
66516 +# define __acquires(x)
66517 +# define __releases(x)
66518 +# define __acquire(x) (void)0
66519 +# define __release(x) (void)0
66520 +# define __cond_lock(x,c) (c)
66521 +# define __percpu
66522 +# define __force_percpu
66523 +# define __rcu
66524 +# define __force_rcu
66525 #else
66526 # define __user
66527 +# define __force_user
66528 # define __kernel
66529 +# define __force_kernel
66530 # define __safe
66531 # define __force
66532 # define __nocast
66533 # define __iomem
66534 +# define __force_iomem
66535 # define __chk_user_ptr(x) (void)0
66536 # define __chk_io_ptr(x) (void)0
66537 # define __builtin_warning(x, y...) (1)
66538 @@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
66539 # define __release(x) (void)0
66540 # define __cond_lock(x,c) (c)
66541 # define __percpu
66542 +# define __force_percpu
66543 # define __rcu
66544 +# define __force_rcu
66545 #endif
66546
66547 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
66548 @@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66549 # define __attribute_const__ /* unimplemented */
66550 #endif
66551
66552 +#ifndef __no_const
66553 +# define __no_const
66554 +#endif
66555 +
66556 +#ifndef __do_const
66557 +# define __do_const
66558 +#endif
66559 +
66560 +#ifndef __size_overflow
66561 +# define __size_overflow(...)
66562 +#endif
66563 +
66564 +#ifndef __intentional_overflow
66565 +# define __intentional_overflow(...)
66566 +#endif
66567 +
66568 +#ifndef __latent_entropy
66569 +# define __latent_entropy
66570 +#endif
66571 +
66572 /*
66573 * Tell gcc if a function is cold. The compiler will assume any path
66574 * directly leading to the call is unlikely.
66575 @@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66576 #define __cold
66577 #endif
66578
66579 +#ifndef __alloc_size
66580 +#define __alloc_size(...)
66581 +#endif
66582 +
66583 +#ifndef __bos
66584 +#define __bos(ptr, arg)
66585 +#endif
66586 +
66587 +#ifndef __bos0
66588 +#define __bos0(ptr)
66589 +#endif
66590 +
66591 +#ifndef __bos1
66592 +#define __bos1(ptr)
66593 +#endif
66594 +
66595 /* Simple shorthand for a section definition */
66596 #ifndef __section
66597 # define __section(S) __attribute__ ((__section__(#S)))
66598 @@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66599 * use is to mediate communication between process-level code and irq/NMI
66600 * handlers, all running on the same CPU.
66601 */
66602 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
66603 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
66604 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
66605
66606 #endif /* __LINUX_COMPILER_H */
66607 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
66608 index 34025df..d94bbbc 100644
66609 --- a/include/linux/configfs.h
66610 +++ b/include/linux/configfs.h
66611 @@ -125,7 +125,7 @@ struct configfs_attribute {
66612 const char *ca_name;
66613 struct module *ca_owner;
66614 umode_t ca_mode;
66615 -};
66616 +} __do_const;
66617
66618 /*
66619 * Users often need to create attribute structures for their configurable
66620 diff --git a/include/linux/cpu.h b/include/linux/cpu.h
66621 index ce7a074..01ab8ac 100644
66622 --- a/include/linux/cpu.h
66623 +++ b/include/linux/cpu.h
66624 @@ -115,7 +115,7 @@ enum {
66625 /* Need to know about CPUs going up/down? */
66626 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
66627 #define cpu_notifier(fn, pri) { \
66628 - static struct notifier_block fn##_nb __cpuinitdata = \
66629 + static struct notifier_block fn##_nb = \
66630 { .notifier_call = fn, .priority = pri }; \
66631 register_cpu_notifier(&fn##_nb); \
66632 }
66633 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
66634 index a55b88e..fba90c5 100644
66635 --- a/include/linux/cpufreq.h
66636 +++ b/include/linux/cpufreq.h
66637 @@ -240,7 +240,7 @@ struct cpufreq_driver {
66638 int (*suspend) (struct cpufreq_policy *policy);
66639 int (*resume) (struct cpufreq_policy *policy);
66640 struct freq_attr **attr;
66641 -};
66642 +} __do_const;
66643
66644 /* flags */
66645
66646 @@ -299,6 +299,7 @@ struct global_attr {
66647 ssize_t (*store)(struct kobject *a, struct attribute *b,
66648 const char *c, size_t count);
66649 };
66650 +typedef struct global_attr __no_const global_attr_no_const;
66651
66652 #define define_one_global_ro(_name) \
66653 static struct global_attr _name = \
66654 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
66655 index 24cd1037..20a63aae 100644
66656 --- a/include/linux/cpuidle.h
66657 +++ b/include/linux/cpuidle.h
66658 @@ -54,7 +54,8 @@ struct cpuidle_state {
66659 int index);
66660
66661 int (*enter_dead) (struct cpuidle_device *dev, int index);
66662 -};
66663 +} __do_const;
66664 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
66665
66666 /* Idle State Flags */
66667 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
66668 @@ -216,7 +217,7 @@ struct cpuidle_governor {
66669 void (*reflect) (struct cpuidle_device *dev, int index);
66670
66671 struct module *owner;
66672 -};
66673 +} __do_const;
66674
66675 #ifdef CONFIG_CPU_IDLE
66676
66677 diff --git a/include/linux/cred.h b/include/linux/cred.h
66678 index 04421e8..6bce4ef 100644
66679 --- a/include/linux/cred.h
66680 +++ b/include/linux/cred.h
66681 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
66682 static inline void validate_process_creds(void)
66683 {
66684 }
66685 +static inline void validate_task_creds(struct task_struct *task)
66686 +{
66687 +}
66688 #endif
66689
66690 /**
66691 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
66692 index b92eadf..b4ecdc1 100644
66693 --- a/include/linux/crypto.h
66694 +++ b/include/linux/crypto.h
66695 @@ -373,7 +373,7 @@ struct cipher_tfm {
66696 const u8 *key, unsigned int keylen);
66697 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
66698 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
66699 -};
66700 +} __no_const;
66701
66702 struct hash_tfm {
66703 int (*init)(struct hash_desc *desc);
66704 @@ -394,13 +394,13 @@ struct compress_tfm {
66705 int (*cot_decompress)(struct crypto_tfm *tfm,
66706 const u8 *src, unsigned int slen,
66707 u8 *dst, unsigned int *dlen);
66708 -};
66709 +} __no_const;
66710
66711 struct rng_tfm {
66712 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
66713 unsigned int dlen);
66714 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
66715 -};
66716 +} __no_const;
66717
66718 #define crt_ablkcipher crt_u.ablkcipher
66719 #define crt_aead crt_u.aead
66720 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
66721 index 7925bf0..d5143d2 100644
66722 --- a/include/linux/decompress/mm.h
66723 +++ b/include/linux/decompress/mm.h
66724 @@ -77,7 +77,7 @@ static void free(void *where)
66725 * warnings when not needed (indeed large_malloc / large_free are not
66726 * needed by inflate */
66727
66728 -#define malloc(a) kmalloc(a, GFP_KERNEL)
66729 +#define malloc(a) kmalloc((a), GFP_KERNEL)
66730 #define free(a) kfree(a)
66731
66732 #define large_malloc(a) vmalloc(a)
66733 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
66734 index e83ef39..33e0eb3 100644
66735 --- a/include/linux/devfreq.h
66736 +++ b/include/linux/devfreq.h
66737 @@ -114,7 +114,7 @@ struct devfreq_governor {
66738 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
66739 int (*event_handler)(struct devfreq *devfreq,
66740 unsigned int event, void *data);
66741 -};
66742 +} __do_const;
66743
66744 /**
66745 * struct devfreq - Device devfreq structure
66746 diff --git a/include/linux/device.h b/include/linux/device.h
66747 index 43dcda9..7a1fb65 100644
66748 --- a/include/linux/device.h
66749 +++ b/include/linux/device.h
66750 @@ -294,7 +294,7 @@ struct subsys_interface {
66751 struct list_head node;
66752 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
66753 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
66754 -};
66755 +} __do_const;
66756
66757 int subsys_interface_register(struct subsys_interface *sif);
66758 void subsys_interface_unregister(struct subsys_interface *sif);
66759 @@ -474,7 +474,7 @@ struct device_type {
66760 void (*release)(struct device *dev);
66761
66762 const struct dev_pm_ops *pm;
66763 -};
66764 +} __do_const;
66765
66766 /* interface for exporting device attributes */
66767 struct device_attribute {
66768 @@ -484,11 +484,12 @@ struct device_attribute {
66769 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
66770 const char *buf, size_t count);
66771 };
66772 +typedef struct device_attribute __no_const device_attribute_no_const;
66773
66774 struct dev_ext_attribute {
66775 struct device_attribute attr;
66776 void *var;
66777 -};
66778 +} __do_const;
66779
66780 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
66781 char *buf);
66782 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
66783 index 94af418..b1ca7a2 100644
66784 --- a/include/linux/dma-mapping.h
66785 +++ b/include/linux/dma-mapping.h
66786 @@ -54,7 +54,7 @@ struct dma_map_ops {
66787 u64 (*get_required_mask)(struct device *dev);
66788 #endif
66789 int is_phys;
66790 -};
66791 +} __do_const;
66792
66793 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
66794
66795 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
66796 index d3201e4..8281e63 100644
66797 --- a/include/linux/dmaengine.h
66798 +++ b/include/linux/dmaengine.h
66799 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
66800 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
66801 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
66802
66803 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
66804 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
66805 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
66806 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
66807 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
66808 struct dma_pinned_list *pinned_list, struct page *page,
66809 unsigned int offset, size_t len);
66810
66811 diff --git a/include/linux/efi.h b/include/linux/efi.h
66812 index 7a9498a..155713d 100644
66813 --- a/include/linux/efi.h
66814 +++ b/include/linux/efi.h
66815 @@ -733,6 +733,7 @@ struct efivar_operations {
66816 efi_set_variable_t *set_variable;
66817 efi_query_variable_info_t *query_variable_info;
66818 };
66819 +typedef struct efivar_operations __no_const efivar_operations_no_const;
66820
66821 struct efivars {
66822 /*
66823 diff --git a/include/linux/elf.h b/include/linux/elf.h
66824 index 8c9048e..16a4665 100644
66825 --- a/include/linux/elf.h
66826 +++ b/include/linux/elf.h
66827 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
66828 #define elf_note elf32_note
66829 #define elf_addr_t Elf32_Off
66830 #define Elf_Half Elf32_Half
66831 +#define elf_dyn Elf32_Dyn
66832
66833 #else
66834
66835 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
66836 #define elf_note elf64_note
66837 #define elf_addr_t Elf64_Off
66838 #define Elf_Half Elf64_Half
66839 +#define elf_dyn Elf64_Dyn
66840
66841 #endif
66842
66843 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
66844 index fcb51c8..bdafcf6 100644
66845 --- a/include/linux/extcon.h
66846 +++ b/include/linux/extcon.h
66847 @@ -134,7 +134,7 @@ struct extcon_dev {
66848 /* /sys/class/extcon/.../mutually_exclusive/... */
66849 struct attribute_group attr_g_muex;
66850 struct attribute **attrs_muex;
66851 - struct device_attribute *d_attrs_muex;
66852 + device_attribute_no_const *d_attrs_muex;
66853 };
66854
66855 /**
66856 diff --git a/include/linux/fb.h b/include/linux/fb.h
66857 index c7a9571..02eeffe 100644
66858 --- a/include/linux/fb.h
66859 +++ b/include/linux/fb.h
66860 @@ -302,7 +302,7 @@ struct fb_ops {
66861 /* called at KDB enter and leave time to prepare the console */
66862 int (*fb_debug_enter)(struct fb_info *info);
66863 int (*fb_debug_leave)(struct fb_info *info);
66864 -};
66865 +} __do_const;
66866
66867 #ifdef CONFIG_FB_TILEBLITTING
66868 #define FB_TILE_CURSOR_NONE 0
66869 diff --git a/include/linux/filter.h b/include/linux/filter.h
66870 index c45eabc..baa0be5 100644
66871 --- a/include/linux/filter.h
66872 +++ b/include/linux/filter.h
66873 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
66874
66875 struct sk_buff;
66876 struct sock;
66877 +struct bpf_jit_work;
66878
66879 struct sk_filter
66880 {
66881 @@ -27,6 +28,9 @@ struct sk_filter
66882 unsigned int len; /* Number of filter blocks */
66883 unsigned int (*bpf_func)(const struct sk_buff *skb,
66884 const struct sock_filter *filter);
66885 +#ifdef CONFIG_BPF_JIT
66886 + struct bpf_jit_work *work;
66887 +#endif
66888 struct rcu_head rcu;
66889 struct sock_filter insns[0];
66890 };
66891 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
66892 index 3044254..9767f41 100644
66893 --- a/include/linux/frontswap.h
66894 +++ b/include/linux/frontswap.h
66895 @@ -11,7 +11,7 @@ struct frontswap_ops {
66896 int (*load)(unsigned, pgoff_t, struct page *);
66897 void (*invalidate_page)(unsigned, pgoff_t);
66898 void (*invalidate_area)(unsigned);
66899 -};
66900 +} __no_const;
66901
66902 extern bool frontswap_enabled;
66903 extern struct frontswap_ops
66904 diff --git a/include/linux/fs.h b/include/linux/fs.h
66905 index 7617ee0..b575199 100644
66906 --- a/include/linux/fs.h
66907 +++ b/include/linux/fs.h
66908 @@ -1541,7 +1541,8 @@ struct file_operations {
66909 long (*fallocate)(struct file *file, int mode, loff_t offset,
66910 loff_t len);
66911 int (*show_fdinfo)(struct seq_file *m, struct file *f);
66912 -};
66913 +} __do_const;
66914 +typedef struct file_operations __no_const file_operations_no_const;
66915
66916 struct inode_operations {
66917 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
66918 @@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
66919 inode->i_flags |= S_NOSEC;
66920 }
66921
66922 +static inline bool is_sidechannel_device(const struct inode *inode)
66923 +{
66924 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
66925 + umode_t mode = inode->i_mode;
66926 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
66927 +#else
66928 + return false;
66929 +#endif
66930 +}
66931 +
66932 #endif /* _LINUX_FS_H */
66933 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
66934 index d0ae3a8..0244b34 100644
66935 --- a/include/linux/fs_struct.h
66936 +++ b/include/linux/fs_struct.h
66937 @@ -6,7 +6,7 @@
66938 #include <linux/seqlock.h>
66939
66940 struct fs_struct {
66941 - int users;
66942 + atomic_t users;
66943 spinlock_t lock;
66944 seqcount_t seq;
66945 int umask;
66946 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
66947 index 5dfa0aa..6acf322 100644
66948 --- a/include/linux/fscache-cache.h
66949 +++ b/include/linux/fscache-cache.h
66950 @@ -112,7 +112,7 @@ struct fscache_operation {
66951 fscache_operation_release_t release;
66952 };
66953
66954 -extern atomic_t fscache_op_debug_id;
66955 +extern atomic_unchecked_t fscache_op_debug_id;
66956 extern void fscache_op_work_func(struct work_struct *work);
66957
66958 extern void fscache_enqueue_operation(struct fscache_operation *);
66959 @@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
66960 INIT_WORK(&op->work, fscache_op_work_func);
66961 atomic_set(&op->usage, 1);
66962 op->state = FSCACHE_OP_ST_INITIALISED;
66963 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
66964 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
66965 op->processor = processor;
66966 op->release = release;
66967 INIT_LIST_HEAD(&op->pend_link);
66968 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
66969 index 7a08623..4c07b0f 100644
66970 --- a/include/linux/fscache.h
66971 +++ b/include/linux/fscache.h
66972 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
66973 * - this is mandatory for any object that may have data
66974 */
66975 void (*now_uncached)(void *cookie_netfs_data);
66976 -};
66977 +} __do_const;
66978
66979 /*
66980 * fscache cached network filesystem type
66981 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
66982 index 0fbfb46..508eb0d 100644
66983 --- a/include/linux/fsnotify.h
66984 +++ b/include/linux/fsnotify.h
66985 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
66986 struct inode *inode = path->dentry->d_inode;
66987 __u32 mask = FS_ACCESS;
66988
66989 + if (is_sidechannel_device(inode))
66990 + return;
66991 +
66992 if (S_ISDIR(inode->i_mode))
66993 mask |= FS_ISDIR;
66994
66995 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
66996 struct inode *inode = path->dentry->d_inode;
66997 __u32 mask = FS_MODIFY;
66998
66999 + if (is_sidechannel_device(inode))
67000 + return;
67001 +
67002 if (S_ISDIR(inode->i_mode))
67003 mask |= FS_ISDIR;
67004
67005 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
67006 */
67007 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
67008 {
67009 - return kstrdup(name, GFP_KERNEL);
67010 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
67011 }
67012
67013 /*
67014 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
67015 index a3d4895..ddd2a50 100644
67016 --- a/include/linux/ftrace_event.h
67017 +++ b/include/linux/ftrace_event.h
67018 @@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
67019 extern int trace_add_event_call(struct ftrace_event_call *call);
67020 extern void trace_remove_event_call(struct ftrace_event_call *call);
67021
67022 -#define is_signed_type(type) (((type)(-1)) < 0)
67023 +#define is_signed_type(type) (((type)(-1)) < (type)1)
67024
67025 int trace_set_clr_event(const char *system, const char *event, int set);
67026
67027 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
67028 index 79b8bba..86b539e 100644
67029 --- a/include/linux/genhd.h
67030 +++ b/include/linux/genhd.h
67031 @@ -194,7 +194,7 @@ struct gendisk {
67032 struct kobject *slave_dir;
67033
67034 struct timer_rand_state *random;
67035 - atomic_t sync_io; /* RAID */
67036 + atomic_unchecked_t sync_io; /* RAID */
67037 struct disk_events *ev;
67038 #ifdef CONFIG_BLK_DEV_INTEGRITY
67039 struct blk_integrity *integrity;
67040 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
67041 index 023bc34..b02b46a 100644
67042 --- a/include/linux/genl_magic_func.h
67043 +++ b/include/linux/genl_magic_func.h
67044 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
67045 },
67046
67047 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
67048 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
67049 +static struct genl_ops ZZZ_genl_ops[] = {
67050 #include GENL_MAGIC_INCLUDE_FILE
67051 };
67052
67053 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
67054 index 0f615eb..5c3832f 100644
67055 --- a/include/linux/gfp.h
67056 +++ b/include/linux/gfp.h
67057 @@ -35,6 +35,13 @@ struct vm_area_struct;
67058 #define ___GFP_NO_KSWAPD 0x400000u
67059 #define ___GFP_OTHER_NODE 0x800000u
67060 #define ___GFP_WRITE 0x1000000u
67061 +
67062 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67063 +#define ___GFP_USERCOPY 0x2000000u
67064 +#else
67065 +#define ___GFP_USERCOPY 0
67066 +#endif
67067 +
67068 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
67069
67070 /*
67071 @@ -92,6 +99,7 @@ struct vm_area_struct;
67072 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
67073 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
67074 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
67075 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
67076
67077 /*
67078 * This may seem redundant, but it's a way of annotating false positives vs.
67079 @@ -99,7 +107,7 @@ struct vm_area_struct;
67080 */
67081 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
67082
67083 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
67084 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
67085 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
67086
67087 /* This equals 0, but use constants in case they ever change */
67088 @@ -153,6 +161,8 @@ struct vm_area_struct;
67089 /* 4GB DMA on some platforms */
67090 #define GFP_DMA32 __GFP_DMA32
67091
67092 +#define GFP_USERCOPY __GFP_USERCOPY
67093 +
67094 /* Convert GFP flags to their corresponding migrate type */
67095 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
67096 {
67097 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
67098 new file mode 100644
67099 index 0000000..ebe6d72
67100 --- /dev/null
67101 +++ b/include/linux/gracl.h
67102 @@ -0,0 +1,319 @@
67103 +#ifndef GR_ACL_H
67104 +#define GR_ACL_H
67105 +
67106 +#include <linux/grdefs.h>
67107 +#include <linux/resource.h>
67108 +#include <linux/capability.h>
67109 +#include <linux/dcache.h>
67110 +#include <asm/resource.h>
67111 +
67112 +/* Major status information */
67113 +
67114 +#define GR_VERSION "grsecurity 2.9.1"
67115 +#define GRSECURITY_VERSION 0x2901
67116 +
67117 +enum {
67118 + GR_SHUTDOWN = 0,
67119 + GR_ENABLE = 1,
67120 + GR_SPROLE = 2,
67121 + GR_RELOAD = 3,
67122 + GR_SEGVMOD = 4,
67123 + GR_STATUS = 5,
67124 + GR_UNSPROLE = 6,
67125 + GR_PASSSET = 7,
67126 + GR_SPROLEPAM = 8,
67127 +};
67128 +
67129 +/* Password setup definitions
67130 + * kernel/grhash.c */
67131 +enum {
67132 + GR_PW_LEN = 128,
67133 + GR_SALT_LEN = 16,
67134 + GR_SHA_LEN = 32,
67135 +};
67136 +
67137 +enum {
67138 + GR_SPROLE_LEN = 64,
67139 +};
67140 +
67141 +enum {
67142 + GR_NO_GLOB = 0,
67143 + GR_REG_GLOB,
67144 + GR_CREATE_GLOB
67145 +};
67146 +
67147 +#define GR_NLIMITS 32
67148 +
67149 +/* Begin Data Structures */
67150 +
67151 +struct sprole_pw {
67152 + unsigned char *rolename;
67153 + unsigned char salt[GR_SALT_LEN];
67154 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
67155 +};
67156 +
67157 +struct name_entry {
67158 + __u32 key;
67159 + ino_t inode;
67160 + dev_t device;
67161 + char *name;
67162 + __u16 len;
67163 + __u8 deleted;
67164 + struct name_entry *prev;
67165 + struct name_entry *next;
67166 +};
67167 +
67168 +struct inodev_entry {
67169 + struct name_entry *nentry;
67170 + struct inodev_entry *prev;
67171 + struct inodev_entry *next;
67172 +};
67173 +
67174 +struct acl_role_db {
67175 + struct acl_role_label **r_hash;
67176 + __u32 r_size;
67177 +};
67178 +
67179 +struct inodev_db {
67180 + struct inodev_entry **i_hash;
67181 + __u32 i_size;
67182 +};
67183 +
67184 +struct name_db {
67185 + struct name_entry **n_hash;
67186 + __u32 n_size;
67187 +};
67188 +
67189 +struct crash_uid {
67190 + uid_t uid;
67191 + unsigned long expires;
67192 +};
67193 +
67194 +struct gr_hash_struct {
67195 + void **table;
67196 + void **nametable;
67197 + void *first;
67198 + __u32 table_size;
67199 + __u32 used_size;
67200 + int type;
67201 +};
67202 +
67203 +/* Userspace Grsecurity ACL data structures */
67204 +
67205 +struct acl_subject_label {
67206 + char *filename;
67207 + ino_t inode;
67208 + dev_t device;
67209 + __u32 mode;
67210 + kernel_cap_t cap_mask;
67211 + kernel_cap_t cap_lower;
67212 + kernel_cap_t cap_invert_audit;
67213 +
67214 + struct rlimit res[GR_NLIMITS];
67215 + __u32 resmask;
67216 +
67217 + __u8 user_trans_type;
67218 + __u8 group_trans_type;
67219 + uid_t *user_transitions;
67220 + gid_t *group_transitions;
67221 + __u16 user_trans_num;
67222 + __u16 group_trans_num;
67223 +
67224 + __u32 sock_families[2];
67225 + __u32 ip_proto[8];
67226 + __u32 ip_type;
67227 + struct acl_ip_label **ips;
67228 + __u32 ip_num;
67229 + __u32 inaddr_any_override;
67230 +
67231 + __u32 crashes;
67232 + unsigned long expires;
67233 +
67234 + struct acl_subject_label *parent_subject;
67235 + struct gr_hash_struct *hash;
67236 + struct acl_subject_label *prev;
67237 + struct acl_subject_label *next;
67238 +
67239 + struct acl_object_label **obj_hash;
67240 + __u32 obj_hash_size;
67241 + __u16 pax_flags;
67242 +};
67243 +
67244 +struct role_allowed_ip {
67245 + __u32 addr;
67246 + __u32 netmask;
67247 +
67248 + struct role_allowed_ip *prev;
67249 + struct role_allowed_ip *next;
67250 +};
67251 +
67252 +struct role_transition {
67253 + char *rolename;
67254 +
67255 + struct role_transition *prev;
67256 + struct role_transition *next;
67257 +};
67258 +
67259 +struct acl_role_label {
67260 + char *rolename;
67261 + uid_t uidgid;
67262 + __u16 roletype;
67263 +
67264 + __u16 auth_attempts;
67265 + unsigned long expires;
67266 +
67267 + struct acl_subject_label *root_label;
67268 + struct gr_hash_struct *hash;
67269 +
67270 + struct acl_role_label *prev;
67271 + struct acl_role_label *next;
67272 +
67273 + struct role_transition *transitions;
67274 + struct role_allowed_ip *allowed_ips;
67275 + uid_t *domain_children;
67276 + __u16 domain_child_num;
67277 +
67278 + umode_t umask;
67279 +
67280 + struct acl_subject_label **subj_hash;
67281 + __u32 subj_hash_size;
67282 +};
67283 +
67284 +struct user_acl_role_db {
67285 + struct acl_role_label **r_table;
67286 + __u32 num_pointers; /* Number of allocations to track */
67287 + __u32 num_roles; /* Number of roles */
67288 + __u32 num_domain_children; /* Number of domain children */
67289 + __u32 num_subjects; /* Number of subjects */
67290 + __u32 num_objects; /* Number of objects */
67291 +};
67292 +
67293 +struct acl_object_label {
67294 + char *filename;
67295 + ino_t inode;
67296 + dev_t device;
67297 + __u32 mode;
67298 +
67299 + struct acl_subject_label *nested;
67300 + struct acl_object_label *globbed;
67301 +
67302 + /* next two structures not used */
67303 +
67304 + struct acl_object_label *prev;
67305 + struct acl_object_label *next;
67306 +};
67307 +
67308 +struct acl_ip_label {
67309 + char *iface;
67310 + __u32 addr;
67311 + __u32 netmask;
67312 + __u16 low, high;
67313 + __u8 mode;
67314 + __u32 type;
67315 + __u32 proto[8];
67316 +
67317 + /* next two structures not used */
67318 +
67319 + struct acl_ip_label *prev;
67320 + struct acl_ip_label *next;
67321 +};
67322 +
67323 +struct gr_arg {
67324 + struct user_acl_role_db role_db;
67325 + unsigned char pw[GR_PW_LEN];
67326 + unsigned char salt[GR_SALT_LEN];
67327 + unsigned char sum[GR_SHA_LEN];
67328 + unsigned char sp_role[GR_SPROLE_LEN];
67329 + struct sprole_pw *sprole_pws;
67330 + dev_t segv_device;
67331 + ino_t segv_inode;
67332 + uid_t segv_uid;
67333 + __u16 num_sprole_pws;
67334 + __u16 mode;
67335 +};
67336 +
67337 +struct gr_arg_wrapper {
67338 + struct gr_arg *arg;
67339 + __u32 version;
67340 + __u32 size;
67341 +};
67342 +
67343 +struct subject_map {
67344 + struct acl_subject_label *user;
67345 + struct acl_subject_label *kernel;
67346 + struct subject_map *prev;
67347 + struct subject_map *next;
67348 +};
67349 +
67350 +struct acl_subj_map_db {
67351 + struct subject_map **s_hash;
67352 + __u32 s_size;
67353 +};
67354 +
67355 +/* End Data Structures Section */
67356 +
67357 +/* Hash functions generated by empirical testing by Brad Spengler
67358 + Makes good use of the low bits of the inode. Generally 0-1 times
67359 + in loop for successful match. 0-3 for unsuccessful match.
67360 + Shift/add algorithm with modulus of table size and an XOR*/
67361 +
67362 +static __inline__ unsigned int
67363 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
67364 +{
67365 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
67366 +}
67367 +
67368 + static __inline__ unsigned int
67369 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
67370 +{
67371 + return ((const unsigned long)userp % sz);
67372 +}
67373 +
67374 +static __inline__ unsigned int
67375 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
67376 +{
67377 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
67378 +}
67379 +
67380 +static __inline__ unsigned int
67381 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
67382 +{
67383 + return full_name_hash((const unsigned char *)name, len) % sz;
67384 +}
67385 +
67386 +#define FOR_EACH_ROLE_START(role) \
67387 + role = role_list; \
67388 + while (role) {
67389 +
67390 +#define FOR_EACH_ROLE_END(role) \
67391 + role = role->prev; \
67392 + }
67393 +
67394 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
67395 + subj = NULL; \
67396 + iter = 0; \
67397 + while (iter < role->subj_hash_size) { \
67398 + if (subj == NULL) \
67399 + subj = role->subj_hash[iter]; \
67400 + if (subj == NULL) { \
67401 + iter++; \
67402 + continue; \
67403 + }
67404 +
67405 +#define FOR_EACH_SUBJECT_END(subj,iter) \
67406 + subj = subj->next; \
67407 + if (subj == NULL) \
67408 + iter++; \
67409 + }
67410 +
67411 +
67412 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
67413 + subj = role->hash->first; \
67414 + while (subj != NULL) {
67415 +
67416 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
67417 + subj = subj->next; \
67418 + }
67419 +
67420 +#endif
67421 +
67422 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
67423 new file mode 100644
67424 index 0000000..323ecf2
67425 --- /dev/null
67426 +++ b/include/linux/gralloc.h
67427 @@ -0,0 +1,9 @@
67428 +#ifndef __GRALLOC_H
67429 +#define __GRALLOC_H
67430 +
67431 +void acl_free_all(void);
67432 +int acl_alloc_stack_init(unsigned long size);
67433 +void *acl_alloc(unsigned long len);
67434 +void *acl_alloc_num(unsigned long num, unsigned long len);
67435 +
67436 +#endif
67437 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
67438 new file mode 100644
67439 index 0000000..be66033
67440 --- /dev/null
67441 +++ b/include/linux/grdefs.h
67442 @@ -0,0 +1,140 @@
67443 +#ifndef GRDEFS_H
67444 +#define GRDEFS_H
67445 +
67446 +/* Begin grsecurity status declarations */
67447 +
67448 +enum {
67449 + GR_READY = 0x01,
67450 + GR_STATUS_INIT = 0x00 // disabled state
67451 +};
67452 +
67453 +/* Begin ACL declarations */
67454 +
67455 +/* Role flags */
67456 +
67457 +enum {
67458 + GR_ROLE_USER = 0x0001,
67459 + GR_ROLE_GROUP = 0x0002,
67460 + GR_ROLE_DEFAULT = 0x0004,
67461 + GR_ROLE_SPECIAL = 0x0008,
67462 + GR_ROLE_AUTH = 0x0010,
67463 + GR_ROLE_NOPW = 0x0020,
67464 + GR_ROLE_GOD = 0x0040,
67465 + GR_ROLE_LEARN = 0x0080,
67466 + GR_ROLE_TPE = 0x0100,
67467 + GR_ROLE_DOMAIN = 0x0200,
67468 + GR_ROLE_PAM = 0x0400,
67469 + GR_ROLE_PERSIST = 0x0800
67470 +};
67471 +
67472 +/* ACL Subject and Object mode flags */
67473 +enum {
67474 + GR_DELETED = 0x80000000
67475 +};
67476 +
67477 +/* ACL Object-only mode flags */
67478 +enum {
67479 + GR_READ = 0x00000001,
67480 + GR_APPEND = 0x00000002,
67481 + GR_WRITE = 0x00000004,
67482 + GR_EXEC = 0x00000008,
67483 + GR_FIND = 0x00000010,
67484 + GR_INHERIT = 0x00000020,
67485 + GR_SETID = 0x00000040,
67486 + GR_CREATE = 0x00000080,
67487 + GR_DELETE = 0x00000100,
67488 + GR_LINK = 0x00000200,
67489 + GR_AUDIT_READ = 0x00000400,
67490 + GR_AUDIT_APPEND = 0x00000800,
67491 + GR_AUDIT_WRITE = 0x00001000,
67492 + GR_AUDIT_EXEC = 0x00002000,
67493 + GR_AUDIT_FIND = 0x00004000,
67494 + GR_AUDIT_INHERIT= 0x00008000,
67495 + GR_AUDIT_SETID = 0x00010000,
67496 + GR_AUDIT_CREATE = 0x00020000,
67497 + GR_AUDIT_DELETE = 0x00040000,
67498 + GR_AUDIT_LINK = 0x00080000,
67499 + GR_PTRACERD = 0x00100000,
67500 + GR_NOPTRACE = 0x00200000,
67501 + GR_SUPPRESS = 0x00400000,
67502 + GR_NOLEARN = 0x00800000,
67503 + GR_INIT_TRANSFER= 0x01000000
67504 +};
67505 +
67506 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
67507 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
67508 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
67509 +
67510 +/* ACL subject-only mode flags */
67511 +enum {
67512 + GR_KILL = 0x00000001,
67513 + GR_VIEW = 0x00000002,
67514 + GR_PROTECTED = 0x00000004,
67515 + GR_LEARN = 0x00000008,
67516 + GR_OVERRIDE = 0x00000010,
67517 + /* just a placeholder, this mode is only used in userspace */
67518 + GR_DUMMY = 0x00000020,
67519 + GR_PROTSHM = 0x00000040,
67520 + GR_KILLPROC = 0x00000080,
67521 + GR_KILLIPPROC = 0x00000100,
67522 + /* just a placeholder, this mode is only used in userspace */
67523 + GR_NOTROJAN = 0x00000200,
67524 + GR_PROTPROCFD = 0x00000400,
67525 + GR_PROCACCT = 0x00000800,
67526 + GR_RELAXPTRACE = 0x00001000,
67527 + //GR_NESTED = 0x00002000,
67528 + GR_INHERITLEARN = 0x00004000,
67529 + GR_PROCFIND = 0x00008000,
67530 + GR_POVERRIDE = 0x00010000,
67531 + GR_KERNELAUTH = 0x00020000,
67532 + GR_ATSECURE = 0x00040000,
67533 + GR_SHMEXEC = 0x00080000
67534 +};
67535 +
67536 +enum {
67537 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
67538 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
67539 + GR_PAX_ENABLE_MPROTECT = 0x0004,
67540 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
67541 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
67542 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
67543 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
67544 + GR_PAX_DISABLE_MPROTECT = 0x0400,
67545 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
67546 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
67547 +};
67548 +
67549 +enum {
67550 + GR_ID_USER = 0x01,
67551 + GR_ID_GROUP = 0x02,
67552 +};
67553 +
67554 +enum {
67555 + GR_ID_ALLOW = 0x01,
67556 + GR_ID_DENY = 0x02,
67557 +};
67558 +
67559 +#define GR_CRASH_RES 31
67560 +#define GR_UIDTABLE_MAX 500
67561 +
67562 +/* begin resource learning section */
67563 +enum {
67564 + GR_RLIM_CPU_BUMP = 60,
67565 + GR_RLIM_FSIZE_BUMP = 50000,
67566 + GR_RLIM_DATA_BUMP = 10000,
67567 + GR_RLIM_STACK_BUMP = 1000,
67568 + GR_RLIM_CORE_BUMP = 10000,
67569 + GR_RLIM_RSS_BUMP = 500000,
67570 + GR_RLIM_NPROC_BUMP = 1,
67571 + GR_RLIM_NOFILE_BUMP = 5,
67572 + GR_RLIM_MEMLOCK_BUMP = 50000,
67573 + GR_RLIM_AS_BUMP = 500000,
67574 + GR_RLIM_LOCKS_BUMP = 2,
67575 + GR_RLIM_SIGPENDING_BUMP = 5,
67576 + GR_RLIM_MSGQUEUE_BUMP = 10000,
67577 + GR_RLIM_NICE_BUMP = 1,
67578 + GR_RLIM_RTPRIO_BUMP = 1,
67579 + GR_RLIM_RTTIME_BUMP = 1000000
67580 +};
67581 +
67582 +#endif
67583 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
67584 new file mode 100644
67585 index 0000000..9bb6662
67586 --- /dev/null
67587 +++ b/include/linux/grinternal.h
67588 @@ -0,0 +1,215 @@
67589 +#ifndef __GRINTERNAL_H
67590 +#define __GRINTERNAL_H
67591 +
67592 +#ifdef CONFIG_GRKERNSEC
67593 +
67594 +#include <linux/fs.h>
67595 +#include <linux/mnt_namespace.h>
67596 +#include <linux/nsproxy.h>
67597 +#include <linux/gracl.h>
67598 +#include <linux/grdefs.h>
67599 +#include <linux/grmsg.h>
67600 +
67601 +void gr_add_learn_entry(const char *fmt, ...)
67602 + __attribute__ ((format (printf, 1, 2)));
67603 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
67604 + const struct vfsmount *mnt);
67605 +__u32 gr_check_create(const struct dentry *new_dentry,
67606 + const struct dentry *parent,
67607 + const struct vfsmount *mnt, const __u32 mode);
67608 +int gr_check_protected_task(const struct task_struct *task);
67609 +__u32 to_gr_audit(const __u32 reqmode);
67610 +int gr_set_acls(const int type);
67611 +int gr_apply_subject_to_task(struct task_struct *task);
67612 +int gr_acl_is_enabled(void);
67613 +char gr_roletype_to_char(void);
67614 +
67615 +void gr_handle_alertkill(struct task_struct *task);
67616 +char *gr_to_filename(const struct dentry *dentry,
67617 + const struct vfsmount *mnt);
67618 +char *gr_to_filename1(const struct dentry *dentry,
67619 + const struct vfsmount *mnt);
67620 +char *gr_to_filename2(const struct dentry *dentry,
67621 + const struct vfsmount *mnt);
67622 +char *gr_to_filename3(const struct dentry *dentry,
67623 + const struct vfsmount *mnt);
67624 +
67625 +extern int grsec_enable_ptrace_readexec;
67626 +extern int grsec_enable_harden_ptrace;
67627 +extern int grsec_enable_link;
67628 +extern int grsec_enable_fifo;
67629 +extern int grsec_enable_execve;
67630 +extern int grsec_enable_shm;
67631 +extern int grsec_enable_execlog;
67632 +extern int grsec_enable_signal;
67633 +extern int grsec_enable_audit_ptrace;
67634 +extern int grsec_enable_forkfail;
67635 +extern int grsec_enable_time;
67636 +extern int grsec_enable_rofs;
67637 +extern int grsec_enable_chroot_shmat;
67638 +extern int grsec_enable_chroot_mount;
67639 +extern int grsec_enable_chroot_double;
67640 +extern int grsec_enable_chroot_pivot;
67641 +extern int grsec_enable_chroot_chdir;
67642 +extern int grsec_enable_chroot_chmod;
67643 +extern int grsec_enable_chroot_mknod;
67644 +extern int grsec_enable_chroot_fchdir;
67645 +extern int grsec_enable_chroot_nice;
67646 +extern int grsec_enable_chroot_execlog;
67647 +extern int grsec_enable_chroot_caps;
67648 +extern int grsec_enable_chroot_sysctl;
67649 +extern int grsec_enable_chroot_unix;
67650 +extern int grsec_enable_symlinkown;
67651 +extern kgid_t grsec_symlinkown_gid;
67652 +extern int grsec_enable_tpe;
67653 +extern kgid_t grsec_tpe_gid;
67654 +extern int grsec_enable_tpe_all;
67655 +extern int grsec_enable_tpe_invert;
67656 +extern int grsec_enable_socket_all;
67657 +extern kgid_t grsec_socket_all_gid;
67658 +extern int grsec_enable_socket_client;
67659 +extern kgid_t grsec_socket_client_gid;
67660 +extern int grsec_enable_socket_server;
67661 +extern kgid_t grsec_socket_server_gid;
67662 +extern kgid_t grsec_audit_gid;
67663 +extern int grsec_enable_group;
67664 +extern int grsec_enable_audit_textrel;
67665 +extern int grsec_enable_log_rwxmaps;
67666 +extern int grsec_enable_mount;
67667 +extern int grsec_enable_chdir;
67668 +extern int grsec_resource_logging;
67669 +extern int grsec_enable_blackhole;
67670 +extern int grsec_lastack_retries;
67671 +extern int grsec_enable_brute;
67672 +extern int grsec_lock;
67673 +
67674 +extern spinlock_t grsec_alert_lock;
67675 +extern unsigned long grsec_alert_wtime;
67676 +extern unsigned long grsec_alert_fyet;
67677 +
67678 +extern spinlock_t grsec_audit_lock;
67679 +
67680 +extern rwlock_t grsec_exec_file_lock;
67681 +
67682 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
67683 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
67684 + (tsk)->exec_file->f_vfsmnt) : "/")
67685 +
67686 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
67687 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
67688 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
67689 +
67690 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
67691 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
67692 + (tsk)->exec_file->f_vfsmnt) : "/")
67693 +
67694 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
67695 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
67696 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
67697 +
67698 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
67699 +
67700 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
67701 +
67702 +#define GR_CHROOT_CAPS {{ \
67703 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
67704 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
67705 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
67706 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
67707 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
67708 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
67709 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
67710 +
67711 +#define security_learn(normal_msg,args...) \
67712 +({ \
67713 + read_lock(&grsec_exec_file_lock); \
67714 + gr_add_learn_entry(normal_msg "\n", ## args); \
67715 + read_unlock(&grsec_exec_file_lock); \
67716 +})
67717 +
67718 +enum {
67719 + GR_DO_AUDIT,
67720 + GR_DONT_AUDIT,
67721 + /* used for non-audit messages that we shouldn't kill the task on */
67722 + GR_DONT_AUDIT_GOOD
67723 +};
67724 +
67725 +enum {
67726 + GR_TTYSNIFF,
67727 + GR_RBAC,
67728 + GR_RBAC_STR,
67729 + GR_STR_RBAC,
67730 + GR_RBAC_MODE2,
67731 + GR_RBAC_MODE3,
67732 + GR_FILENAME,
67733 + GR_SYSCTL_HIDDEN,
67734 + GR_NOARGS,
67735 + GR_ONE_INT,
67736 + GR_ONE_INT_TWO_STR,
67737 + GR_ONE_STR,
67738 + GR_STR_INT,
67739 + GR_TWO_STR_INT,
67740 + GR_TWO_INT,
67741 + GR_TWO_U64,
67742 + GR_THREE_INT,
67743 + GR_FIVE_INT_TWO_STR,
67744 + GR_TWO_STR,
67745 + GR_THREE_STR,
67746 + GR_FOUR_STR,
67747 + GR_STR_FILENAME,
67748 + GR_FILENAME_STR,
67749 + GR_FILENAME_TWO_INT,
67750 + GR_FILENAME_TWO_INT_STR,
67751 + GR_TEXTREL,
67752 + GR_PTRACE,
67753 + GR_RESOURCE,
67754 + GR_CAP,
67755 + GR_SIG,
67756 + GR_SIG2,
67757 + GR_CRASH1,
67758 + GR_CRASH2,
67759 + GR_PSACCT,
67760 + GR_RWXMAP
67761 +};
67762 +
67763 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
67764 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
67765 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
67766 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
67767 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
67768 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
67769 +#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)
67770 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
67771 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
67772 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
67773 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
67774 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
67775 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
67776 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
67777 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
67778 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
67779 +#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)
67780 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
67781 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
67782 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
67783 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
67784 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
67785 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
67786 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
67787 +#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)
67788 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
67789 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
67790 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
67791 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
67792 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
67793 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
67794 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
67795 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
67796 +#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)
67797 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
67798 +
67799 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
67800 +
67801 +#endif
67802 +
67803 +#endif
67804 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
67805 new file mode 100644
67806 index 0000000..2bd4c8d
67807 --- /dev/null
67808 +++ b/include/linux/grmsg.h
67809 @@ -0,0 +1,111 @@
67810 +#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"
67811 +#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"
67812 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
67813 +#define GR_STOPMOD_MSG "denied modification of module state by "
67814 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
67815 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
67816 +#define GR_IOPERM_MSG "denied use of ioperm() by "
67817 +#define GR_IOPL_MSG "denied use of iopl() by "
67818 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
67819 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
67820 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
67821 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
67822 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
67823 +#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"
67824 +#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"
67825 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
67826 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
67827 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
67828 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
67829 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
67830 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
67831 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
67832 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
67833 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
67834 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
67835 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
67836 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
67837 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
67838 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
67839 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
67840 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
67841 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
67842 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
67843 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
67844 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
67845 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
67846 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
67847 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
67848 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
67849 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
67850 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
67851 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
67852 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
67853 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
67854 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
67855 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
67856 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
67857 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
67858 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
67859 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
67860 +#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"
67861 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
67862 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
67863 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
67864 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
67865 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
67866 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
67867 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
67868 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
67869 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
67870 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
67871 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
67872 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
67873 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
67874 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
67875 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
67876 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
67877 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
67878 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
67879 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
67880 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
67881 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
67882 +#define GR_NICE_CHROOT_MSG "denied priority change by "
67883 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
67884 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
67885 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
67886 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
67887 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
67888 +#define GR_TIME_MSG "time set by "
67889 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
67890 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
67891 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
67892 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
67893 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
67894 +#define GR_BIND_MSG "denied bind() by "
67895 +#define GR_CONNECT_MSG "denied connect() by "
67896 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
67897 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
67898 +#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"
67899 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
67900 +#define GR_CAP_ACL_MSG "use of %s denied for "
67901 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
67902 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
67903 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
67904 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
67905 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
67906 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
67907 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
67908 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
67909 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
67910 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
67911 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
67912 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
67913 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
67914 +#define GR_VM86_MSG "denied use of vm86 by "
67915 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
67916 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
67917 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
67918 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
67919 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
67920 +#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 "
67921 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
67922 new file mode 100644
67923 index 0000000..1ae241a
67924 --- /dev/null
67925 +++ b/include/linux/grsecurity.h
67926 @@ -0,0 +1,257 @@
67927 +#ifndef GR_SECURITY_H
67928 +#define GR_SECURITY_H
67929 +#include <linux/fs.h>
67930 +#include <linux/fs_struct.h>
67931 +#include <linux/binfmts.h>
67932 +#include <linux/gracl.h>
67933 +
67934 +/* notify of brain-dead configs */
67935 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67936 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
67937 +#endif
67938 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
67939 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
67940 +#endif
67941 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
67942 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
67943 +#endif
67944 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
67945 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
67946 +#endif
67947 +
67948 +#include <linux/compat.h>
67949 +
67950 +struct user_arg_ptr {
67951 +#ifdef CONFIG_COMPAT
67952 + bool is_compat;
67953 +#endif
67954 + union {
67955 + const char __user *const __user *native;
67956 +#ifdef CONFIG_COMPAT
67957 + const compat_uptr_t __user *compat;
67958 +#endif
67959 + } ptr;
67960 +};
67961 +
67962 +void gr_handle_brute_attach(unsigned long mm_flags);
67963 +void gr_handle_brute_check(void);
67964 +void gr_handle_kernel_exploit(void);
67965 +int gr_process_user_ban(void);
67966 +
67967 +char gr_roletype_to_char(void);
67968 +
67969 +int gr_acl_enable_at_secure(void);
67970 +
67971 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
67972 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
67973 +
67974 +void gr_del_task_from_ip_table(struct task_struct *p);
67975 +
67976 +int gr_pid_is_chrooted(struct task_struct *p);
67977 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
67978 +int gr_handle_chroot_nice(void);
67979 +int gr_handle_chroot_sysctl(const int op);
67980 +int gr_handle_chroot_setpriority(struct task_struct *p,
67981 + const int niceval);
67982 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
67983 +int gr_handle_chroot_chroot(const struct dentry *dentry,
67984 + const struct vfsmount *mnt);
67985 +void gr_handle_chroot_chdir(struct path *path);
67986 +int gr_handle_chroot_chmod(const struct dentry *dentry,
67987 + const struct vfsmount *mnt, const int mode);
67988 +int gr_handle_chroot_mknod(const struct dentry *dentry,
67989 + const struct vfsmount *mnt, const int mode);
67990 +int gr_handle_chroot_mount(const struct dentry *dentry,
67991 + const struct vfsmount *mnt,
67992 + const char *dev_name);
67993 +int gr_handle_chroot_pivot(void);
67994 +int gr_handle_chroot_unix(const pid_t pid);
67995 +
67996 +int gr_handle_rawio(const struct inode *inode);
67997 +
67998 +void gr_handle_ioperm(void);
67999 +void gr_handle_iopl(void);
68000 +
68001 +umode_t gr_acl_umask(void);
68002 +
68003 +int gr_tpe_allow(const struct file *file);
68004 +
68005 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
68006 +void gr_clear_chroot_entries(struct task_struct *task);
68007 +
68008 +void gr_log_forkfail(const int retval);
68009 +void gr_log_timechange(void);
68010 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
68011 +void gr_log_chdir(const struct dentry *dentry,
68012 + const struct vfsmount *mnt);
68013 +void gr_log_chroot_exec(const struct dentry *dentry,
68014 + const struct vfsmount *mnt);
68015 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
68016 +void gr_log_remount(const char *devname, const int retval);
68017 +void gr_log_unmount(const char *devname, const int retval);
68018 +void gr_log_mount(const char *from, const char *to, const int retval);
68019 +void gr_log_textrel(struct vm_area_struct *vma);
68020 +void gr_log_rwxmmap(struct file *file);
68021 +void gr_log_rwxmprotect(struct file *file);
68022 +
68023 +int gr_handle_follow_link(const struct inode *parent,
68024 + const struct inode *inode,
68025 + const struct dentry *dentry,
68026 + const struct vfsmount *mnt);
68027 +int gr_handle_fifo(const struct dentry *dentry,
68028 + const struct vfsmount *mnt,
68029 + const struct dentry *dir, const int flag,
68030 + const int acc_mode);
68031 +int gr_handle_hardlink(const struct dentry *dentry,
68032 + const struct vfsmount *mnt,
68033 + struct inode *inode,
68034 + const int mode, const struct filename *to);
68035 +
68036 +int gr_is_capable(const int cap);
68037 +int gr_is_capable_nolog(const int cap);
68038 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
68039 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
68040 +
68041 +void gr_copy_label(struct task_struct *tsk);
68042 +void gr_handle_crash(struct task_struct *task, const int sig);
68043 +int gr_handle_signal(const struct task_struct *p, const int sig);
68044 +int gr_check_crash_uid(const kuid_t uid);
68045 +int gr_check_protected_task(const struct task_struct *task);
68046 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
68047 +int gr_acl_handle_mmap(const struct file *file,
68048 + const unsigned long prot);
68049 +int gr_acl_handle_mprotect(const struct file *file,
68050 + const unsigned long prot);
68051 +int gr_check_hidden_task(const struct task_struct *tsk);
68052 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
68053 + const struct vfsmount *mnt);
68054 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
68055 + const struct vfsmount *mnt);
68056 +__u32 gr_acl_handle_access(const struct dentry *dentry,
68057 + const struct vfsmount *mnt, const int fmode);
68058 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
68059 + const struct vfsmount *mnt, umode_t *mode);
68060 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
68061 + const struct vfsmount *mnt);
68062 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
68063 + const struct vfsmount *mnt);
68064 +int gr_handle_ptrace(struct task_struct *task, const long request);
68065 +int gr_handle_proc_ptrace(struct task_struct *task);
68066 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
68067 + const struct vfsmount *mnt);
68068 +int gr_check_crash_exec(const struct file *filp);
68069 +int gr_acl_is_enabled(void);
68070 +void gr_set_kernel_label(struct task_struct *task);
68071 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
68072 + const kgid_t gid);
68073 +int gr_set_proc_label(const struct dentry *dentry,
68074 + const struct vfsmount *mnt,
68075 + const int unsafe_flags);
68076 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
68077 + const struct vfsmount *mnt);
68078 +__u32 gr_acl_handle_open(const struct dentry *dentry,
68079 + const struct vfsmount *mnt, int acc_mode);
68080 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
68081 + const struct dentry *p_dentry,
68082 + const struct vfsmount *p_mnt,
68083 + int open_flags, int acc_mode, const int imode);
68084 +void gr_handle_create(const struct dentry *dentry,
68085 + const struct vfsmount *mnt);
68086 +void gr_handle_proc_create(const struct dentry *dentry,
68087 + const struct inode *inode);
68088 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
68089 + const struct dentry *parent_dentry,
68090 + const struct vfsmount *parent_mnt,
68091 + const int mode);
68092 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
68093 + const struct dentry *parent_dentry,
68094 + const struct vfsmount *parent_mnt);
68095 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
68096 + const struct vfsmount *mnt);
68097 +void gr_handle_delete(const ino_t ino, const dev_t dev);
68098 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
68099 + const struct vfsmount *mnt);
68100 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
68101 + const struct dentry *parent_dentry,
68102 + const struct vfsmount *parent_mnt,
68103 + const struct filename *from);
68104 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
68105 + const struct dentry *parent_dentry,
68106 + const struct vfsmount *parent_mnt,
68107 + const struct dentry *old_dentry,
68108 + const struct vfsmount *old_mnt, const struct filename *to);
68109 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
68110 +int gr_acl_handle_rename(struct dentry *new_dentry,
68111 + struct dentry *parent_dentry,
68112 + const struct vfsmount *parent_mnt,
68113 + struct dentry *old_dentry,
68114 + struct inode *old_parent_inode,
68115 + struct vfsmount *old_mnt, const struct filename *newname);
68116 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68117 + struct dentry *old_dentry,
68118 + struct dentry *new_dentry,
68119 + struct vfsmount *mnt, const __u8 replace);
68120 +__u32 gr_check_link(const struct dentry *new_dentry,
68121 + const struct dentry *parent_dentry,
68122 + const struct vfsmount *parent_mnt,
68123 + const struct dentry *old_dentry,
68124 + const struct vfsmount *old_mnt);
68125 +int gr_acl_handle_filldir(const struct file *file, const char *name,
68126 + const unsigned int namelen, const ino_t ino);
68127 +
68128 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
68129 + const struct vfsmount *mnt);
68130 +void gr_acl_handle_exit(void);
68131 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
68132 +int gr_acl_handle_procpidmem(const struct task_struct *task);
68133 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
68134 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
68135 +void gr_audit_ptrace(struct task_struct *task);
68136 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
68137 +void gr_put_exec_file(struct task_struct *task);
68138 +
68139 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
68140 +
68141 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
68142 +extern void gr_learn_resource(const struct task_struct *task, const int res,
68143 + const unsigned long wanted, const int gt);
68144 +#else
68145 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
68146 + const unsigned long wanted, const int gt)
68147 +{
68148 +}
68149 +#endif
68150 +
68151 +#ifdef CONFIG_GRKERNSEC_RESLOG
68152 +extern void gr_log_resource(const struct task_struct *task, const int res,
68153 + const unsigned long wanted, const int gt);
68154 +#else
68155 +static inline void gr_log_resource(const struct task_struct *task, const int res,
68156 + const unsigned long wanted, const int gt)
68157 +{
68158 +}
68159 +#endif
68160 +
68161 +#ifdef CONFIG_GRKERNSEC
68162 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
68163 +void gr_handle_vm86(void);
68164 +void gr_handle_mem_readwrite(u64 from, u64 to);
68165 +
68166 +void gr_log_badprocpid(const char *entry);
68167 +
68168 +extern int grsec_enable_dmesg;
68169 +extern int grsec_disable_privio;
68170 +
68171 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68172 +extern kgid_t grsec_proc_gid;
68173 +#endif
68174 +
68175 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68176 +extern int grsec_enable_chroot_findtask;
68177 +#endif
68178 +#ifdef CONFIG_GRKERNSEC_SETXID
68179 +extern int grsec_enable_setxid;
68180 +#endif
68181 +#endif
68182 +
68183 +#endif
68184 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
68185 new file mode 100644
68186 index 0000000..e7ffaaf
68187 --- /dev/null
68188 +++ b/include/linux/grsock.h
68189 @@ -0,0 +1,19 @@
68190 +#ifndef __GRSOCK_H
68191 +#define __GRSOCK_H
68192 +
68193 +extern void gr_attach_curr_ip(const struct sock *sk);
68194 +extern int gr_handle_sock_all(const int family, const int type,
68195 + const int protocol);
68196 +extern int gr_handle_sock_server(const struct sockaddr *sck);
68197 +extern int gr_handle_sock_server_other(const struct sock *sck);
68198 +extern int gr_handle_sock_client(const struct sockaddr *sck);
68199 +extern int gr_search_connect(struct socket * sock,
68200 + struct sockaddr_in * addr);
68201 +extern int gr_search_bind(struct socket * sock,
68202 + struct sockaddr_in * addr);
68203 +extern int gr_search_listen(struct socket * sock);
68204 +extern int gr_search_accept(struct socket * sock);
68205 +extern int gr_search_socket(const int domain, const int type,
68206 + const int protocol);
68207 +
68208 +#endif
68209 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
68210 index ef788b5..ac41b7b 100644
68211 --- a/include/linux/highmem.h
68212 +++ b/include/linux/highmem.h
68213 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
68214 kunmap_atomic(kaddr);
68215 }
68216
68217 +static inline void sanitize_highpage(struct page *page)
68218 +{
68219 + void *kaddr;
68220 + unsigned long flags;
68221 +
68222 + local_irq_save(flags);
68223 + kaddr = kmap_atomic(page);
68224 + clear_page(kaddr);
68225 + kunmap_atomic(kaddr);
68226 + local_irq_restore(flags);
68227 +}
68228 +
68229 static inline void zero_user_segments(struct page *page,
68230 unsigned start1, unsigned end1,
68231 unsigned start2, unsigned end2)
68232 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
68233 index 1c7b89a..7f52502 100644
68234 --- a/include/linux/hwmon-sysfs.h
68235 +++ b/include/linux/hwmon-sysfs.h
68236 @@ -25,7 +25,8 @@
68237 struct sensor_device_attribute{
68238 struct device_attribute dev_attr;
68239 int index;
68240 -};
68241 +} __do_const;
68242 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
68243 #define to_sensor_dev_attr(_dev_attr) \
68244 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
68245
68246 @@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
68247 struct device_attribute dev_attr;
68248 u8 index;
68249 u8 nr;
68250 -};
68251 +} __do_const;
68252 #define to_sensor_dev_attr_2(_dev_attr) \
68253 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
68254
68255 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
68256 index d0c4db7..61b3577 100644
68257 --- a/include/linux/i2c.h
68258 +++ b/include/linux/i2c.h
68259 @@ -369,6 +369,7 @@ struct i2c_algorithm {
68260 /* To determine what the adapter supports */
68261 u32 (*functionality) (struct i2c_adapter *);
68262 };
68263 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
68264
68265 /*
68266 * i2c_adapter is the structure used to identify a physical i2c bus along
68267 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
68268 index d23c3c2..eb63c81 100644
68269 --- a/include/linux/i2o.h
68270 +++ b/include/linux/i2o.h
68271 @@ -565,7 +565,7 @@ struct i2o_controller {
68272 struct i2o_device *exec; /* Executive */
68273 #if BITS_PER_LONG == 64
68274 spinlock_t context_list_lock; /* lock for context_list */
68275 - atomic_t context_list_counter; /* needed for unique contexts */
68276 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
68277 struct list_head context_list; /* list of context id's
68278 and pointers */
68279 #endif
68280 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
68281 index aff7ad8..3942bbd 100644
68282 --- a/include/linux/if_pppox.h
68283 +++ b/include/linux/if_pppox.h
68284 @@ -76,7 +76,7 @@ struct pppox_proto {
68285 int (*ioctl)(struct socket *sock, unsigned int cmd,
68286 unsigned long arg);
68287 struct module *owner;
68288 -};
68289 +} __do_const;
68290
68291 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
68292 extern void unregister_pppox_proto(int proto_num);
68293 diff --git a/include/linux/init.h b/include/linux/init.h
68294 index 10ed4f4..8e8490d 100644
68295 --- a/include/linux/init.h
68296 +++ b/include/linux/init.h
68297 @@ -39,9 +39,36 @@
68298 * Also note, that this data cannot be "const".
68299 */
68300
68301 +#ifdef MODULE
68302 +#define add_init_latent_entropy
68303 +#define add_devinit_latent_entropy
68304 +#define add_cpuinit_latent_entropy
68305 +#define add_meminit_latent_entropy
68306 +#else
68307 +#define add_init_latent_entropy __latent_entropy
68308 +
68309 +#ifdef CONFIG_HOTPLUG
68310 +#define add_devinit_latent_entropy
68311 +#else
68312 +#define add_devinit_latent_entropy __latent_entropy
68313 +#endif
68314 +
68315 +#ifdef CONFIG_HOTPLUG_CPU
68316 +#define add_cpuinit_latent_entropy
68317 +#else
68318 +#define add_cpuinit_latent_entropy __latent_entropy
68319 +#endif
68320 +
68321 +#ifdef CONFIG_MEMORY_HOTPLUG
68322 +#define add_meminit_latent_entropy
68323 +#else
68324 +#define add_meminit_latent_entropy __latent_entropy
68325 +#endif
68326 +#endif
68327 +
68328 /* These are for everybody (although not all archs will actually
68329 discard it in modules) */
68330 -#define __init __section(.init.text) __cold notrace
68331 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
68332 #define __initdata __section(.init.data)
68333 #define __initconst __constsection(.init.rodata)
68334 #define __exitdata __section(.exit.data)
68335 @@ -94,7 +121,7 @@
68336 #define __exit __section(.exit.text) __exitused __cold notrace
68337
68338 /* Used for HOTPLUG_CPU */
68339 -#define __cpuinit __section(.cpuinit.text) __cold notrace
68340 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
68341 #define __cpuinitdata __section(.cpuinit.data)
68342 #define __cpuinitconst __constsection(.cpuinit.rodata)
68343 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
68344 @@ -102,7 +129,7 @@
68345 #define __cpuexitconst __constsection(.cpuexit.rodata)
68346
68347 /* Used for MEMORY_HOTPLUG */
68348 -#define __meminit __section(.meminit.text) __cold notrace
68349 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
68350 #define __meminitdata __section(.meminit.data)
68351 #define __meminitconst __constsection(.meminit.rodata)
68352 #define __memexit __section(.memexit.text) __exitused __cold notrace
68353 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
68354 index 6d087c5..401cab8 100644
68355 --- a/include/linux/init_task.h
68356 +++ b/include/linux/init_task.h
68357 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
68358
68359 #define INIT_TASK_COMM "swapper"
68360
68361 +#ifdef CONFIG_X86
68362 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
68363 +#else
68364 +#define INIT_TASK_THREAD_INFO
68365 +#endif
68366 +
68367 /*
68368 * INIT_TASK is used to set up the first task table, touch at
68369 * your own risk!. Base=0, limit=0x1fffff (=2MB)
68370 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
68371 RCU_POINTER_INITIALIZER(cred, &init_cred), \
68372 .comm = INIT_TASK_COMM, \
68373 .thread = INIT_THREAD, \
68374 + INIT_TASK_THREAD_INFO \
68375 .fs = &init_fs, \
68376 .files = &init_files, \
68377 .signal = &init_signals, \
68378 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
68379 index 5fa5afe..ac55b25 100644
68380 --- a/include/linux/interrupt.h
68381 +++ b/include/linux/interrupt.h
68382 @@ -430,7 +430,7 @@ enum
68383 /* map softirq index to softirq name. update 'softirq_to_name' in
68384 * kernel/softirq.c when adding a new softirq.
68385 */
68386 -extern char *softirq_to_name[NR_SOFTIRQS];
68387 +extern const char * const softirq_to_name[NR_SOFTIRQS];
68388
68389 /* softirq mask and active fields moved to irq_cpustat_t in
68390 * asm/hardirq.h to get better cache usage. KAO
68391 @@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
68392
68393 struct softirq_action
68394 {
68395 - void (*action)(struct softirq_action *);
68396 -};
68397 + void (*action)(void);
68398 +} __no_const;
68399
68400 asmlinkage void do_softirq(void);
68401 asmlinkage void __do_softirq(void);
68402 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
68403 +extern void open_softirq(int nr, void (*action)(void));
68404 extern void softirq_init(void);
68405 extern void __raise_softirq_irqoff(unsigned int nr);
68406
68407 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
68408 index f3b99e1..9b73cee 100644
68409 --- a/include/linux/iommu.h
68410 +++ b/include/linux/iommu.h
68411 @@ -101,7 +101,7 @@ struct iommu_ops {
68412 int (*domain_set_attr)(struct iommu_domain *domain,
68413 enum iommu_attr attr, void *data);
68414 unsigned long pgsize_bitmap;
68415 -};
68416 +} __do_const;
68417
68418 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
68419 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
68420 diff --git a/include/linux/irq.h b/include/linux/irq.h
68421 index fdf2c4a..5332486 100644
68422 --- a/include/linux/irq.h
68423 +++ b/include/linux/irq.h
68424 @@ -328,7 +328,8 @@ struct irq_chip {
68425 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
68426
68427 unsigned long flags;
68428 -};
68429 +} __do_const;
68430 +typedef struct irq_chip __no_const irq_chip_no_const;
68431
68432 /*
68433 * irq_chip specific flags
68434 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
68435 index 6883e19..06992b1 100644
68436 --- a/include/linux/kallsyms.h
68437 +++ b/include/linux/kallsyms.h
68438 @@ -15,7 +15,8 @@
68439
68440 struct module;
68441
68442 -#ifdef CONFIG_KALLSYMS
68443 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
68444 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68445 /* Lookup the address for a symbol. Returns 0 if not found. */
68446 unsigned long kallsyms_lookup_name(const char *name);
68447
68448 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
68449 /* Stupid that this does nothing, but I didn't create this mess. */
68450 #define __print_symbol(fmt, addr)
68451 #endif /*CONFIG_KALLSYMS*/
68452 +#else /* when included by kallsyms.c, vsnprintf.c, or
68453 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
68454 +extern void __print_symbol(const char *fmt, unsigned long address);
68455 +extern int sprint_backtrace(char *buffer, unsigned long address);
68456 +extern int sprint_symbol(char *buffer, unsigned long address);
68457 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
68458 +const char *kallsyms_lookup(unsigned long addr,
68459 + unsigned long *symbolsize,
68460 + unsigned long *offset,
68461 + char **modname, char *namebuf);
68462 +#endif
68463
68464 /* This macro allows us to keep printk typechecking */
68465 static __printf(1, 2)
68466 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
68467 index 518a53a..5e28358 100644
68468 --- a/include/linux/key-type.h
68469 +++ b/include/linux/key-type.h
68470 @@ -125,7 +125,7 @@ struct key_type {
68471 /* internal fields */
68472 struct list_head link; /* link in types list */
68473 struct lock_class_key lock_class; /* key->sem lock class */
68474 -};
68475 +} __do_const;
68476
68477 extern struct key_type key_type_keyring;
68478
68479 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
68480 index 4dff0c6..1ca9b72 100644
68481 --- a/include/linux/kgdb.h
68482 +++ b/include/linux/kgdb.h
68483 @@ -53,7 +53,7 @@ extern int kgdb_connected;
68484 extern int kgdb_io_module_registered;
68485
68486 extern atomic_t kgdb_setting_breakpoint;
68487 -extern atomic_t kgdb_cpu_doing_single_step;
68488 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
68489
68490 extern struct task_struct *kgdb_usethread;
68491 extern struct task_struct *kgdb_contthread;
68492 @@ -255,7 +255,7 @@ struct kgdb_arch {
68493 void (*correct_hw_break)(void);
68494
68495 void (*enable_nmi)(bool on);
68496 -};
68497 +} __do_const;
68498
68499 /**
68500 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
68501 @@ -280,7 +280,7 @@ struct kgdb_io {
68502 void (*pre_exception) (void);
68503 void (*post_exception) (void);
68504 int is_console;
68505 -};
68506 +} __do_const;
68507
68508 extern struct kgdb_arch arch_kgdb_ops;
68509
68510 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
68511 index 5398d58..5883a34 100644
68512 --- a/include/linux/kmod.h
68513 +++ b/include/linux/kmod.h
68514 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
68515 * usually useless though. */
68516 extern __printf(2, 3)
68517 int __request_module(bool wait, const char *name, ...);
68518 +extern __printf(3, 4)
68519 +int ___request_module(bool wait, char *param_name, const char *name, ...);
68520 #define request_module(mod...) __request_module(true, mod)
68521 #define request_module_nowait(mod...) __request_module(false, mod)
68522 #define try_then_request_module(x, mod...) \
68523 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
68524 index 939b112..ed6ed51 100644
68525 --- a/include/linux/kobject.h
68526 +++ b/include/linux/kobject.h
68527 @@ -111,7 +111,7 @@ struct kobj_type {
68528 struct attribute **default_attrs;
68529 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
68530 const void *(*namespace)(struct kobject *kobj);
68531 -};
68532 +} __do_const;
68533
68534 struct kobj_uevent_env {
68535 char *envp[UEVENT_NUM_ENVP];
68536 @@ -134,6 +134,7 @@ struct kobj_attribute {
68537 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
68538 const char *buf, size_t count);
68539 };
68540 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
68541
68542 extern const struct sysfs_ops kobj_sysfs_ops;
68543
68544 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
68545 index f66b065..c2c29b4 100644
68546 --- a/include/linux/kobject_ns.h
68547 +++ b/include/linux/kobject_ns.h
68548 @@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
68549 const void *(*netlink_ns)(struct sock *sk);
68550 const void *(*initial_ns)(void);
68551 void (*drop_ns)(void *);
68552 -};
68553 +} __do_const;
68554
68555 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
68556 int kobj_ns_type_registered(enum kobj_ns_type type);
68557 diff --git a/include/linux/kref.h b/include/linux/kref.h
68558 index 4972e6e..de4d19b 100644
68559 --- a/include/linux/kref.h
68560 +++ b/include/linux/kref.h
68561 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
68562 static inline int kref_sub(struct kref *kref, unsigned int count,
68563 void (*release)(struct kref *kref))
68564 {
68565 - WARN_ON(release == NULL);
68566 + BUG_ON(release == NULL);
68567
68568 if (atomic_sub_and_test((int) count, &kref->refcount)) {
68569 release(kref);
68570 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
68571 index 2c497ab..afe32f5 100644
68572 --- a/include/linux/kvm_host.h
68573 +++ b/include/linux/kvm_host.h
68574 @@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
68575 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
68576 void vcpu_put(struct kvm_vcpu *vcpu);
68577
68578 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
68579 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
68580 struct module *module);
68581 void kvm_exit(void);
68582
68583 @@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
68584 struct kvm_guest_debug *dbg);
68585 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
68586
68587 -int kvm_arch_init(void *opaque);
68588 +int kvm_arch_init(const void *opaque);
68589 void kvm_arch_exit(void);
68590
68591 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
68592 diff --git a/include/linux/libata.h b/include/linux/libata.h
68593 index 649e5f8..ead5194 100644
68594 --- a/include/linux/libata.h
68595 +++ b/include/linux/libata.h
68596 @@ -915,7 +915,7 @@ struct ata_port_operations {
68597 * fields must be pointers.
68598 */
68599 const struct ata_port_operations *inherits;
68600 -};
68601 +} __do_const;
68602
68603 struct ata_port_info {
68604 unsigned long flags;
68605 diff --git a/include/linux/list.h b/include/linux/list.h
68606 index cc6d2aa..c10ee83 100644
68607 --- a/include/linux/list.h
68608 +++ b/include/linux/list.h
68609 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
68610 extern void list_del(struct list_head *entry);
68611 #endif
68612
68613 +extern void __pax_list_add(struct list_head *new,
68614 + struct list_head *prev,
68615 + struct list_head *next);
68616 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
68617 +{
68618 + __pax_list_add(new, head, head->next);
68619 +}
68620 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
68621 +{
68622 + __pax_list_add(new, head->prev, head);
68623 +}
68624 +extern void pax_list_del(struct list_head *entry);
68625 +
68626 /**
68627 * list_replace - replace old entry by new one
68628 * @old : the element to be replaced
68629 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
68630 INIT_LIST_HEAD(entry);
68631 }
68632
68633 +extern void pax_list_del_init(struct list_head *entry);
68634 +
68635 /**
68636 * list_move - delete from one list and add as another's head
68637 * @list: the entry to move
68638 diff --git a/include/linux/mm.h b/include/linux/mm.h
68639 index 66e2f7c..ea88001 100644
68640 --- a/include/linux/mm.h
68641 +++ b/include/linux/mm.h
68642 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
68643 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
68644 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
68645 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
68646 +
68647 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68648 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
68649 +#endif
68650 +
68651 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
68652
68653 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
68654 @@ -231,6 +236,7 @@ struct vm_operations_struct {
68655 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
68656 unsigned long size, pgoff_t pgoff);
68657 };
68658 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
68659
68660 struct mmu_gather;
68661 struct inode;
68662 @@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
68663 int set_page_dirty_lock(struct page *page);
68664 int clear_page_dirty_for_io(struct page *page);
68665
68666 -/* Is the vma a continuation of the stack vma above it? */
68667 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
68668 -{
68669 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
68670 -}
68671 -
68672 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
68673 - unsigned long addr)
68674 -{
68675 - return (vma->vm_flags & VM_GROWSDOWN) &&
68676 - (vma->vm_start == addr) &&
68677 - !vma_growsdown(vma->vm_prev, addr);
68678 -}
68679 -
68680 -/* Is the vma a continuation of the stack vma below it? */
68681 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
68682 -{
68683 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
68684 -}
68685 -
68686 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
68687 - unsigned long addr)
68688 -{
68689 - return (vma->vm_flags & VM_GROWSUP) &&
68690 - (vma->vm_end == addr) &&
68691 - !vma_growsup(vma->vm_next, addr);
68692 -}
68693 -
68694 extern pid_t
68695 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
68696
68697 @@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
68698 }
68699 #endif
68700
68701 +#ifdef CONFIG_MMU
68702 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
68703 +#else
68704 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
68705 +{
68706 + return __pgprot(0);
68707 +}
68708 +#endif
68709 +
68710 int vma_wants_writenotify(struct vm_area_struct *vma);
68711
68712 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
68713 @@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
68714 {
68715 return 0;
68716 }
68717 +
68718 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
68719 + unsigned long address)
68720 +{
68721 + return 0;
68722 +}
68723 #else
68724 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
68725 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
68726 #endif
68727
68728 #ifdef __PAGETABLE_PMD_FOLDED
68729 @@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
68730 {
68731 return 0;
68732 }
68733 +
68734 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
68735 + unsigned long address)
68736 +{
68737 + return 0;
68738 +}
68739 #else
68740 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
68741 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
68742 #endif
68743
68744 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
68745 @@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
68746 NULL: pud_offset(pgd, address);
68747 }
68748
68749 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
68750 +{
68751 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
68752 + NULL: pud_offset(pgd, address);
68753 +}
68754 +
68755 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
68756 {
68757 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
68758 NULL: pmd_offset(pud, address);
68759 }
68760 +
68761 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
68762 +{
68763 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
68764 + NULL: pmd_offset(pud, address);
68765 +}
68766 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
68767
68768 #if USE_SPLIT_PTLOCKS
68769 @@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
68770 unsigned long, unsigned long,
68771 unsigned long, unsigned long);
68772 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
68773 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
68774
68775 /* These take the mm semaphore themselves */
68776 extern unsigned long vm_brk(unsigned long, unsigned long);
68777 @@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
68778 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
68779 struct vm_area_struct **pprev);
68780
68781 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
68782 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
68783 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
68784 +
68785 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
68786 NULL if none. Assume start_addr < end_addr. */
68787 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
68788 @@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
68789 return vma;
68790 }
68791
68792 -#ifdef CONFIG_MMU
68793 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
68794 -#else
68795 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
68796 -{
68797 - return __pgprot(0);
68798 -}
68799 -#endif
68800 -
68801 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
68802 unsigned long change_prot_numa(struct vm_area_struct *vma,
68803 unsigned long start, unsigned long end);
68804 @@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
68805 extern int sysctl_memory_failure_early_kill;
68806 extern int sysctl_memory_failure_recovery;
68807 extern void shake_page(struct page *p, int access);
68808 -extern atomic_long_t mce_bad_pages;
68809 +extern atomic_long_unchecked_t mce_bad_pages;
68810 extern int soft_offline_page(struct page *page, int flags);
68811
68812 extern void dump_page(struct page *page);
68813 @@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
68814 static inline bool page_is_guard(struct page *page) { return false; }
68815 #endif /* CONFIG_DEBUG_PAGEALLOC */
68816
68817 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
68818 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
68819 +#else
68820 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
68821 +#endif
68822 +
68823 #endif /* __KERNEL__ */
68824 #endif /* _LINUX_MM_H */
68825 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
68826 index f8f5162..6276a36 100644
68827 --- a/include/linux/mm_types.h
68828 +++ b/include/linux/mm_types.h
68829 @@ -288,6 +288,8 @@ struct vm_area_struct {
68830 #ifdef CONFIG_NUMA
68831 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
68832 #endif
68833 +
68834 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
68835 };
68836
68837 struct core_thread {
68838 @@ -362,7 +364,7 @@ struct mm_struct {
68839 unsigned long def_flags;
68840 unsigned long nr_ptes; /* Page table pages */
68841 unsigned long start_code, end_code, start_data, end_data;
68842 - unsigned long start_brk, brk, start_stack;
68843 + unsigned long brk_gap, start_brk, brk, start_stack;
68844 unsigned long arg_start, arg_end, env_start, env_end;
68845
68846 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
68847 @@ -436,6 +438,24 @@ struct mm_struct {
68848 int first_nid;
68849 #endif
68850 struct uprobes_state uprobes_state;
68851 +
68852 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
68853 + unsigned long pax_flags;
68854 +#endif
68855 +
68856 +#ifdef CONFIG_PAX_DLRESOLVE
68857 + unsigned long call_dl_resolve;
68858 +#endif
68859 +
68860 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
68861 + unsigned long call_syscall;
68862 +#endif
68863 +
68864 +#ifdef CONFIG_PAX_ASLR
68865 + unsigned long delta_mmap; /* randomized offset */
68866 + unsigned long delta_stack; /* randomized offset */
68867 +#endif
68868 +
68869 };
68870
68871 /* first nid will either be a valid NID or one of these values */
68872 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
68873 index c5d5278..f0b68c8 100644
68874 --- a/include/linux/mmiotrace.h
68875 +++ b/include/linux/mmiotrace.h
68876 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
68877 /* Called from ioremap.c */
68878 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
68879 void __iomem *addr);
68880 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
68881 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
68882
68883 /* For anyone to insert markers. Remember trailing newline. */
68884 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
68885 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
68886 {
68887 }
68888
68889 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
68890 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
68891 {
68892 }
68893
68894 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
68895 index 73b64a3..6562925 100644
68896 --- a/include/linux/mmzone.h
68897 +++ b/include/linux/mmzone.h
68898 @@ -412,7 +412,7 @@ struct zone {
68899 unsigned long flags; /* zone flags, see below */
68900
68901 /* Zone statistics */
68902 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
68903 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
68904
68905 /*
68906 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
68907 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
68908 index fed3def..c933f99 100644
68909 --- a/include/linux/mod_devicetable.h
68910 +++ b/include/linux/mod_devicetable.h
68911 @@ -12,7 +12,7 @@
68912 typedef unsigned long kernel_ulong_t;
68913 #endif
68914
68915 -#define PCI_ANY_ID (~0)
68916 +#define PCI_ANY_ID ((__u16)~0)
68917
68918 struct pci_device_id {
68919 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
68920 @@ -139,7 +139,7 @@ struct usb_device_id {
68921 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
68922 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
68923
68924 -#define HID_ANY_ID (~0)
68925 +#define HID_ANY_ID (~0U)
68926 #define HID_BUS_ANY 0xffff
68927 #define HID_GROUP_ANY 0x0000
68928
68929 @@ -498,7 +498,7 @@ struct dmi_system_id {
68930 const char *ident;
68931 struct dmi_strmatch matches[4];
68932 void *driver_data;
68933 -};
68934 +} __do_const;
68935 /*
68936 * struct dmi_device_id appears during expansion of
68937 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
68938 diff --git a/include/linux/module.h b/include/linux/module.h
68939 index 1375ee3..ced8177 100644
68940 --- a/include/linux/module.h
68941 +++ b/include/linux/module.h
68942 @@ -17,9 +17,11 @@
68943 #include <linux/moduleparam.h>
68944 #include <linux/tracepoint.h>
68945 #include <linux/export.h>
68946 +#include <linux/fs.h>
68947
68948 #include <linux/percpu.h>
68949 #include <asm/module.h>
68950 +#include <asm/pgtable.h>
68951
68952 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
68953 #define MODULE_SIG_STRING "~Module signature appended~\n"
68954 @@ -54,12 +56,13 @@ struct module_attribute {
68955 int (*test)(struct module *);
68956 void (*free)(struct module *);
68957 };
68958 +typedef struct module_attribute __no_const module_attribute_no_const;
68959
68960 struct module_version_attribute {
68961 struct module_attribute mattr;
68962 const char *module_name;
68963 const char *version;
68964 -} __attribute__ ((__aligned__(sizeof(void *))));
68965 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
68966
68967 extern ssize_t __modver_version_show(struct module_attribute *,
68968 struct module_kobject *, char *);
68969 @@ -232,7 +235,7 @@ struct module
68970
68971 /* Sysfs stuff. */
68972 struct module_kobject mkobj;
68973 - struct module_attribute *modinfo_attrs;
68974 + module_attribute_no_const *modinfo_attrs;
68975 const char *version;
68976 const char *srcversion;
68977 struct kobject *holders_dir;
68978 @@ -281,19 +284,16 @@ struct module
68979 int (*init)(void);
68980
68981 /* If this is non-NULL, vfree after init() returns */
68982 - void *module_init;
68983 + void *module_init_rx, *module_init_rw;
68984
68985 /* Here is the actual code + data, vfree'd on unload. */
68986 - void *module_core;
68987 + void *module_core_rx, *module_core_rw;
68988
68989 /* Here are the sizes of the init and core sections */
68990 - unsigned int init_size, core_size;
68991 + unsigned int init_size_rw, core_size_rw;
68992
68993 /* The size of the executable code in each section. */
68994 - unsigned int init_text_size, core_text_size;
68995 -
68996 - /* Size of RO sections of the module (text+rodata) */
68997 - unsigned int init_ro_size, core_ro_size;
68998 + unsigned int init_size_rx, core_size_rx;
68999
69000 /* Arch-specific module values */
69001 struct mod_arch_specific arch;
69002 @@ -349,6 +349,10 @@ struct module
69003 #ifdef CONFIG_EVENT_TRACING
69004 struct ftrace_event_call **trace_events;
69005 unsigned int num_trace_events;
69006 + struct file_operations trace_id;
69007 + struct file_operations trace_enable;
69008 + struct file_operations trace_format;
69009 + struct file_operations trace_filter;
69010 #endif
69011 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
69012 unsigned int num_ftrace_callsites;
69013 @@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
69014 bool is_module_percpu_address(unsigned long addr);
69015 bool is_module_text_address(unsigned long addr);
69016
69017 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
69018 +{
69019 +
69020 +#ifdef CONFIG_PAX_KERNEXEC
69021 + if (ktla_ktva(addr) >= (unsigned long)start &&
69022 + ktla_ktva(addr) < (unsigned long)start + size)
69023 + return 1;
69024 +#endif
69025 +
69026 + return ((void *)addr >= start && (void *)addr < start + size);
69027 +}
69028 +
69029 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
69030 +{
69031 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
69032 +}
69033 +
69034 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
69035 +{
69036 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
69037 +}
69038 +
69039 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
69040 +{
69041 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
69042 +}
69043 +
69044 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
69045 +{
69046 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
69047 +}
69048 +
69049 static inline int within_module_core(unsigned long addr, struct module *mod)
69050 {
69051 - return (unsigned long)mod->module_core <= addr &&
69052 - addr < (unsigned long)mod->module_core + mod->core_size;
69053 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
69054 }
69055
69056 static inline int within_module_init(unsigned long addr, struct module *mod)
69057 {
69058 - return (unsigned long)mod->module_init <= addr &&
69059 - addr < (unsigned long)mod->module_init + mod->init_size;
69060 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
69061 }
69062
69063 /* Search for module by name: must hold module_mutex. */
69064 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
69065 index 560ca53..5ee8d73 100644
69066 --- a/include/linux/moduleloader.h
69067 +++ b/include/linux/moduleloader.h
69068 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
69069
69070 /* Allocator used for allocating struct module, core sections and init
69071 sections. Returns NULL on failure. */
69072 -void *module_alloc(unsigned long size);
69073 +void *module_alloc(unsigned long size) __size_overflow(1);
69074 +
69075 +#ifdef CONFIG_PAX_KERNEXEC
69076 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
69077 +#else
69078 +#define module_alloc_exec(x) module_alloc(x)
69079 +#endif
69080
69081 /* Free memory returned from module_alloc. */
69082 void module_free(struct module *mod, void *module_region);
69083
69084 +#ifdef CONFIG_PAX_KERNEXEC
69085 +void module_free_exec(struct module *mod, void *module_region);
69086 +#else
69087 +#define module_free_exec(x, y) module_free((x), (y))
69088 +#endif
69089 +
69090 /*
69091 * Apply the given relocation to the (simplified) ELF. Return -error
69092 * or 0.
69093 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
69094 unsigned int relsec,
69095 struct module *me)
69096 {
69097 +#ifdef CONFIG_MODULES
69098 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69099 +#endif
69100 return -ENOEXEC;
69101 }
69102 #endif
69103 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
69104 unsigned int relsec,
69105 struct module *me)
69106 {
69107 +#ifdef CONFIG_MODULES
69108 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69109 +#endif
69110 return -ENOEXEC;
69111 }
69112 #endif
69113 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
69114 index 137b419..fe663ec 100644
69115 --- a/include/linux/moduleparam.h
69116 +++ b/include/linux/moduleparam.h
69117 @@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
69118 * @len is usually just sizeof(string).
69119 */
69120 #define module_param_string(name, string, len, perm) \
69121 - static const struct kparam_string __param_string_##name \
69122 + static const struct kparam_string __param_string_##name __used \
69123 = { len, string }; \
69124 __module_param_call(MODULE_PARAM_PREFIX, name, \
69125 &param_ops_string, \
69126 @@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
69127 */
69128 #define module_param_array_named(name, array, type, nump, perm) \
69129 param_check_##type(name, &(array)[0]); \
69130 - static const struct kparam_array __param_arr_##name \
69131 + static const struct kparam_array __param_arr_##name __used \
69132 = { .max = ARRAY_SIZE(array), .num = nump, \
69133 .ops = &param_ops_##type, \
69134 .elemsize = sizeof(array[0]), .elem = array }; \
69135 diff --git a/include/linux/namei.h b/include/linux/namei.h
69136 index 5a5ff57..5ae5070 100644
69137 --- a/include/linux/namei.h
69138 +++ b/include/linux/namei.h
69139 @@ -19,7 +19,7 @@ struct nameidata {
69140 unsigned seq;
69141 int last_type;
69142 unsigned depth;
69143 - char *saved_names[MAX_NESTED_LINKS + 1];
69144 + const char *saved_names[MAX_NESTED_LINKS + 1];
69145 };
69146
69147 /*
69148 @@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
69149
69150 extern void nd_jump_link(struct nameidata *nd, struct path *path);
69151
69152 -static inline void nd_set_link(struct nameidata *nd, char *path)
69153 +static inline void nd_set_link(struct nameidata *nd, const char *path)
69154 {
69155 nd->saved_names[nd->depth] = path;
69156 }
69157
69158 -static inline char *nd_get_link(struct nameidata *nd)
69159 +static inline const char *nd_get_link(const struct nameidata *nd)
69160 {
69161 return nd->saved_names[nd->depth];
69162 }
69163 diff --git a/include/linux/net.h b/include/linux/net.h
69164 index aa16731..514b875 100644
69165 --- a/include/linux/net.h
69166 +++ b/include/linux/net.h
69167 @@ -183,7 +183,7 @@ struct net_proto_family {
69168 int (*create)(struct net *net, struct socket *sock,
69169 int protocol, int kern);
69170 struct module *owner;
69171 -};
69172 +} __do_const;
69173
69174 struct iovec;
69175 struct kvec;
69176 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
69177 index 9ef07d0..130a5d9 100644
69178 --- a/include/linux/netdevice.h
69179 +++ b/include/linux/netdevice.h
69180 @@ -1012,6 +1012,7 @@ struct net_device_ops {
69181 u32 pid, u32 seq,
69182 struct net_device *dev);
69183 };
69184 +typedef struct net_device_ops __no_const net_device_ops_no_const;
69185
69186 /*
69187 * The DEVICE structure.
69188 @@ -1078,7 +1079,7 @@ struct net_device {
69189 int iflink;
69190
69191 struct net_device_stats stats;
69192 - atomic_long_t rx_dropped; /* dropped packets by core network
69193 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
69194 * Do not use this in drivers.
69195 */
69196
69197 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
69198 index ee14284..bc65d63 100644
69199 --- a/include/linux/netfilter.h
69200 +++ b/include/linux/netfilter.h
69201 @@ -82,7 +82,7 @@ struct nf_sockopt_ops {
69202 #endif
69203 /* Use the module struct to lock set/get code in place */
69204 struct module *owner;
69205 -};
69206 +} __do_const;
69207
69208 /* Function to register/unregister hook points. */
69209 int nf_register_hook(struct nf_hook_ops *reg);
69210 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
69211 index 7958e84..ed74d7a 100644
69212 --- a/include/linux/netfilter/ipset/ip_set.h
69213 +++ b/include/linux/netfilter/ipset/ip_set.h
69214 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
69215 /* Return true if "b" set is the same as "a"
69216 * according to the create set parameters */
69217 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
69218 -};
69219 +} __do_const;
69220
69221 /* The core set type structure */
69222 struct ip_set_type {
69223 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
69224 index 4966dde..7d8ce06 100644
69225 --- a/include/linux/netfilter/nfnetlink.h
69226 +++ b/include/linux/netfilter/nfnetlink.h
69227 @@ -16,7 +16,7 @@ struct nfnl_callback {
69228 const struct nlattr * const cda[]);
69229 const struct nla_policy *policy; /* netlink attribute policy */
69230 const u_int16_t attr_count; /* number of nlattr's */
69231 -};
69232 +} __do_const;
69233
69234 struct nfnetlink_subsystem {
69235 const char *name;
69236 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
69237 new file mode 100644
69238 index 0000000..33f4af8
69239 --- /dev/null
69240 +++ b/include/linux/netfilter/xt_gradm.h
69241 @@ -0,0 +1,9 @@
69242 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
69243 +#define _LINUX_NETFILTER_XT_GRADM_H 1
69244 +
69245 +struct xt_gradm_mtinfo {
69246 + __u16 flags;
69247 + __u16 invflags;
69248 +};
69249 +
69250 +#endif
69251 diff --git a/include/linux/nls.h b/include/linux/nls.h
69252 index 5dc635f..35f5e11 100644
69253 --- a/include/linux/nls.h
69254 +++ b/include/linux/nls.h
69255 @@ -31,7 +31,7 @@ struct nls_table {
69256 const unsigned char *charset2upper;
69257 struct module *owner;
69258 struct nls_table *next;
69259 -};
69260 +} __do_const;
69261
69262 /* this value hold the maximum octet of charset */
69263 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
69264 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
69265 index d65746e..62e72c2 100644
69266 --- a/include/linux/notifier.h
69267 +++ b/include/linux/notifier.h
69268 @@ -51,7 +51,8 @@ struct notifier_block {
69269 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
69270 struct notifier_block __rcu *next;
69271 int priority;
69272 -};
69273 +} __do_const;
69274 +typedef struct notifier_block __no_const notifier_block_no_const;
69275
69276 struct atomic_notifier_head {
69277 spinlock_t lock;
69278 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
69279 index a4c5624..79d6d88 100644
69280 --- a/include/linux/oprofile.h
69281 +++ b/include/linux/oprofile.h
69282 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
69283 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
69284 char const * name, ulong * val);
69285
69286 -/** Create a file for read-only access to an atomic_t. */
69287 +/** Create a file for read-only access to an atomic_unchecked_t. */
69288 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
69289 - char const * name, atomic_t * val);
69290 + char const * name, atomic_unchecked_t * val);
69291
69292 /** create a directory */
69293 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
69294 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
69295 index 45fc162..01a4068 100644
69296 --- a/include/linux/pci_hotplug.h
69297 +++ b/include/linux/pci_hotplug.h
69298 @@ -80,7 +80,8 @@ struct hotplug_slot_ops {
69299 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
69300 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
69301 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
69302 -};
69303 +} __do_const;
69304 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
69305
69306 /**
69307 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
69308 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
69309 index 6bfb2faa..e5bc5e5 100644
69310 --- a/include/linux/perf_event.h
69311 +++ b/include/linux/perf_event.h
69312 @@ -328,8 +328,8 @@ struct perf_event {
69313
69314 enum perf_event_active_state state;
69315 unsigned int attach_state;
69316 - local64_t count;
69317 - atomic64_t child_count;
69318 + local64_t count; /* PaX: fix it one day */
69319 + atomic64_unchecked_t child_count;
69320
69321 /*
69322 * These are the total time in nanoseconds that the event
69323 @@ -380,8 +380,8 @@ struct perf_event {
69324 * These accumulate total time (in nanoseconds) that children
69325 * events have been enabled and running, respectively.
69326 */
69327 - atomic64_t child_total_time_enabled;
69328 - atomic64_t child_total_time_running;
69329 + atomic64_unchecked_t child_total_time_enabled;
69330 + atomic64_unchecked_t child_total_time_running;
69331
69332 /*
69333 * Protect attach/detach and child_list:
69334 @@ -801,7 +801,7 @@ static inline void perf_event_task_tick(void) { }
69335 */
69336 #define perf_cpu_notifier(fn) \
69337 do { \
69338 - static struct notifier_block fn##_nb __cpuinitdata = \
69339 + static struct notifier_block fn##_nb = \
69340 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
69341 unsigned long cpu = smp_processor_id(); \
69342 unsigned long flags; \
69343 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
69344 index ad1a427..6419649 100644
69345 --- a/include/linux/pipe_fs_i.h
69346 +++ b/include/linux/pipe_fs_i.h
69347 @@ -45,9 +45,9 @@ struct pipe_buffer {
69348 struct pipe_inode_info {
69349 wait_queue_head_t wait;
69350 unsigned int nrbufs, curbuf, buffers;
69351 - unsigned int readers;
69352 - unsigned int writers;
69353 - unsigned int waiting_writers;
69354 + atomic_t readers;
69355 + atomic_t writers;
69356 + atomic_t waiting_writers;
69357 unsigned int r_counter;
69358 unsigned int w_counter;
69359 struct page *tmp_page;
69360 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
69361 index 5f28cae..3d23723 100644
69362 --- a/include/linux/platform_data/usb-ehci-s5p.h
69363 +++ b/include/linux/platform_data/usb-ehci-s5p.h
69364 @@ -14,7 +14,7 @@
69365 struct s5p_ehci_platdata {
69366 int (*phy_init)(struct platform_device *pdev, int type);
69367 int (*phy_exit)(struct platform_device *pdev, int type);
69368 -};
69369 +} __no_const;
69370
69371 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
69372
69373 diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
69374 index c256c59..8ea94c7 100644
69375 --- a/include/linux/platform_data/usb-exynos.h
69376 +++ b/include/linux/platform_data/usb-exynos.h
69377 @@ -14,7 +14,7 @@
69378 struct exynos4_ohci_platdata {
69379 int (*phy_init)(struct platform_device *pdev, int type);
69380 int (*phy_exit)(struct platform_device *pdev, int type);
69381 -};
69382 +} __no_const;
69383
69384 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
69385
69386 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
69387 index 7c1d252..c5c773e 100644
69388 --- a/include/linux/pm_domain.h
69389 +++ b/include/linux/pm_domain.h
69390 @@ -48,7 +48,7 @@ struct gpd_dev_ops {
69391
69392 struct gpd_cpu_data {
69393 unsigned int saved_exit_latency;
69394 - struct cpuidle_state *idle_state;
69395 + cpuidle_state_no_const *idle_state;
69396 };
69397
69398 struct generic_pm_domain {
69399 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
69400 index f271860..6b3bec5 100644
69401 --- a/include/linux/pm_runtime.h
69402 +++ b/include/linux/pm_runtime.h
69403 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
69404
69405 static inline void pm_runtime_mark_last_busy(struct device *dev)
69406 {
69407 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
69408 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
69409 }
69410
69411 #else /* !CONFIG_PM_RUNTIME */
69412 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
69413 index 195aafc..49a7bc2 100644
69414 --- a/include/linux/pnp.h
69415 +++ b/include/linux/pnp.h
69416 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
69417 struct pnp_fixup {
69418 char id[7];
69419 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
69420 -};
69421 +} __do_const;
69422
69423 /* config parameters */
69424 #define PNP_CONFIG_NORMAL 0x0001
69425 diff --git a/include/linux/poison.h b/include/linux/poison.h
69426 index 2110a81..13a11bb 100644
69427 --- a/include/linux/poison.h
69428 +++ b/include/linux/poison.h
69429 @@ -19,8 +19,8 @@
69430 * under normal circumstances, used to verify that nobody uses
69431 * non-initialized list entries.
69432 */
69433 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
69434 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
69435 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
69436 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
69437
69438 /********** include/linux/timer.h **********/
69439 /*
69440 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
69441 index c0f44c2..1572583 100644
69442 --- a/include/linux/power/smartreflex.h
69443 +++ b/include/linux/power/smartreflex.h
69444 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
69445 int (*notify)(struct omap_sr *sr, u32 status);
69446 u8 notify_flags;
69447 u8 class_type;
69448 -};
69449 +} __do_const;
69450
69451 /**
69452 * struct omap_sr_nvalue_table - Smartreflex n-target value info
69453 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
69454 index 4ea1d37..80f4b33 100644
69455 --- a/include/linux/ppp-comp.h
69456 +++ b/include/linux/ppp-comp.h
69457 @@ -84,7 +84,7 @@ struct compressor {
69458 struct module *owner;
69459 /* Extra skb space needed by the compressor algorithm */
69460 unsigned int comp_extra;
69461 -};
69462 +} __do_const;
69463
69464 /*
69465 * The return value from decompress routine is the length of the
69466 diff --git a/include/linux/printk.h b/include/linux/printk.h
69467 index 9afc01e..92c32e8 100644
69468 --- a/include/linux/printk.h
69469 +++ b/include/linux/printk.h
69470 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
69471 extern int printk_needs_cpu(int cpu);
69472 extern void printk_tick(void);
69473
69474 +extern int kptr_restrict;
69475 +
69476 #ifdef CONFIG_PRINTK
69477 asmlinkage __printf(5, 0)
69478 int vprintk_emit(int facility, int level,
69479 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
69480
69481 extern int printk_delay_msec;
69482 extern int dmesg_restrict;
69483 -extern int kptr_restrict;
69484
69485 void log_buf_kexec_setup(void);
69486 void __init setup_log_buf(int early);
69487 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
69488 index 32676b3..8f7a182 100644
69489 --- a/include/linux/proc_fs.h
69490 +++ b/include/linux/proc_fs.h
69491 @@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
69492 return proc_create_data(name, mode, parent, proc_fops, NULL);
69493 }
69494
69495 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
69496 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
69497 +{
69498 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69499 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
69500 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69501 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
69502 +#else
69503 + return proc_create_data(name, mode, parent, proc_fops, NULL);
69504 +#endif
69505 +}
69506 +
69507 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
69508 umode_t mode, struct proc_dir_entry *base,
69509 read_proc_t *read_proc, void * data)
69510 diff --git a/include/linux/random.h b/include/linux/random.h
69511 index d984608..d6f0042 100644
69512 --- a/include/linux/random.h
69513 +++ b/include/linux/random.h
69514 @@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
69515 u32 prandom_u32_state(struct rnd_state *);
69516 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
69517
69518 +static inline unsigned long pax_get_random_long(void)
69519 +{
69520 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
69521 +}
69522 +
69523 /*
69524 * Handle minimum values for seeds
69525 */
69526 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
69527 index c92dd28..08f4eab 100644
69528 --- a/include/linux/rculist.h
69529 +++ b/include/linux/rculist.h
69530 @@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
69531 struct list_head *prev, struct list_head *next);
69532 #endif
69533
69534 +extern void __pax_list_add_rcu(struct list_head *new,
69535 + struct list_head *prev, struct list_head *next);
69536 +
69537 /**
69538 * list_add_rcu - add a new entry to rcu-protected list
69539 * @new: new entry to be added
69540 @@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
69541 __list_add_rcu(new, head, head->next);
69542 }
69543
69544 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
69545 +{
69546 + __pax_list_add_rcu(new, head, head->next);
69547 +}
69548 +
69549 /**
69550 * list_add_tail_rcu - add a new entry to rcu-protected list
69551 * @new: new entry to be added
69552 @@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
69553 __list_add_rcu(new, head->prev, head);
69554 }
69555
69556 +static inline void pax_list_add_tail_rcu(struct list_head *new,
69557 + struct list_head *head)
69558 +{
69559 + __pax_list_add_rcu(new, head->prev, head);
69560 +}
69561 +
69562 /**
69563 * list_del_rcu - deletes entry from list without re-initialization
69564 * @entry: the element to delete from the list.
69565 @@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
69566 entry->prev = LIST_POISON2;
69567 }
69568
69569 +extern void pax_list_del_rcu(struct list_head *entry);
69570 +
69571 /**
69572 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
69573 * @n: the element to delete from the hash list.
69574 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
69575 index 23b3630..e1bc12b 100644
69576 --- a/include/linux/reboot.h
69577 +++ b/include/linux/reboot.h
69578 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
69579 * Architecture-specific implementations of sys_reboot commands.
69580 */
69581
69582 -extern void machine_restart(char *cmd);
69583 -extern void machine_halt(void);
69584 -extern void machine_power_off(void);
69585 +extern void machine_restart(char *cmd) __noreturn;
69586 +extern void machine_halt(void) __noreturn;
69587 +extern void machine_power_off(void) __noreturn;
69588
69589 extern void machine_shutdown(void);
69590 struct pt_regs;
69591 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
69592 */
69593
69594 extern void kernel_restart_prepare(char *cmd);
69595 -extern void kernel_restart(char *cmd);
69596 -extern void kernel_halt(void);
69597 -extern void kernel_power_off(void);
69598 +extern void kernel_restart(char *cmd) __noreturn;
69599 +extern void kernel_halt(void) __noreturn;
69600 +extern void kernel_power_off(void) __noreturn;
69601
69602 extern int C_A_D; /* for sysctl */
69603 void ctrl_alt_del(void);
69604 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
69605 * Emergency restart, callable from an interrupt handler.
69606 */
69607
69608 -extern void emergency_restart(void);
69609 +extern void emergency_restart(void) __noreturn;
69610 #include <asm/emergency-restart.h>
69611
69612 #endif /* _LINUX_REBOOT_H */
69613 diff --git a/include/linux/regset.h b/include/linux/regset.h
69614 index 8e0c9fe..ac4d221 100644
69615 --- a/include/linux/regset.h
69616 +++ b/include/linux/regset.h
69617 @@ -161,7 +161,8 @@ struct user_regset {
69618 unsigned int align;
69619 unsigned int bias;
69620 unsigned int core_note_type;
69621 -};
69622 +} __do_const;
69623 +typedef struct user_regset __no_const user_regset_no_const;
69624
69625 /**
69626 * struct user_regset_view - available regsets
69627 diff --git a/include/linux/relay.h b/include/linux/relay.h
69628 index 91cacc3..b55ff74 100644
69629 --- a/include/linux/relay.h
69630 +++ b/include/linux/relay.h
69631 @@ -160,7 +160,7 @@ struct rchan_callbacks
69632 * The callback should return 0 if successful, negative if not.
69633 */
69634 int (*remove_buf_file)(struct dentry *dentry);
69635 -};
69636 +} __no_const;
69637
69638 /*
69639 * CONFIG_RELAY kernel API, kernel/relay.c
69640 diff --git a/include/linux/rio.h b/include/linux/rio.h
69641 index a3e7842..d973ca6 100644
69642 --- a/include/linux/rio.h
69643 +++ b/include/linux/rio.h
69644 @@ -339,7 +339,7 @@ struct rio_ops {
69645 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
69646 u64 rstart, u32 size, u32 flags);
69647 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
69648 -};
69649 +} __no_const;
69650
69651 #define RIO_RESOURCE_MEM 0x00000100
69652 #define RIO_RESOURCE_DOORBELL 0x00000200
69653 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
69654 index c20635c..2f5def4 100644
69655 --- a/include/linux/rmap.h
69656 +++ b/include/linux/rmap.h
69657 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
69658 void anon_vma_init(void); /* create anon_vma_cachep */
69659 int anon_vma_prepare(struct vm_area_struct *);
69660 void unlink_anon_vmas(struct vm_area_struct *);
69661 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
69662 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
69663 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
69664 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
69665
69666 static inline void anon_vma_merge(struct vm_area_struct *vma,
69667 struct vm_area_struct *next)
69668 diff --git a/include/linux/sched.h b/include/linux/sched.h
69669 index d211247..a5cbf38b 100644
69670 --- a/include/linux/sched.h
69671 +++ b/include/linux/sched.h
69672 @@ -61,6 +61,7 @@ struct bio_list;
69673 struct fs_struct;
69674 struct perf_event_context;
69675 struct blk_plug;
69676 +struct linux_binprm;
69677
69678 /*
69679 * List of flags we want to share for kernel threads,
69680 @@ -354,10 +355,23 @@ struct user_namespace;
69681 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
69682
69683 extern int sysctl_max_map_count;
69684 +extern unsigned long sysctl_heap_stack_gap;
69685
69686 #include <linux/aio.h>
69687
69688 #ifdef CONFIG_MMU
69689 +
69690 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
69691 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
69692 +#else
69693 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
69694 +{
69695 + return 0;
69696 +}
69697 +#endif
69698 +
69699 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
69700 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
69701 extern void arch_pick_mmap_layout(struct mm_struct *mm);
69702 extern unsigned long
69703 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
69704 @@ -639,6 +653,17 @@ struct signal_struct {
69705 #ifdef CONFIG_TASKSTATS
69706 struct taskstats *stats;
69707 #endif
69708 +
69709 +#ifdef CONFIG_GRKERNSEC
69710 + u32 curr_ip;
69711 + u32 saved_ip;
69712 + u32 gr_saddr;
69713 + u32 gr_daddr;
69714 + u16 gr_sport;
69715 + u16 gr_dport;
69716 + u8 used_accept:1;
69717 +#endif
69718 +
69719 #ifdef CONFIG_AUDIT
69720 unsigned audit_tty;
69721 struct tty_audit_buf *tty_audit_buf;
69722 @@ -717,6 +742,11 @@ struct user_struct {
69723 struct key *session_keyring; /* UID's default session keyring */
69724 #endif
69725
69726 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
69727 + unsigned int banned;
69728 + unsigned long ban_expires;
69729 +#endif
69730 +
69731 /* Hash table maintenance information */
69732 struct hlist_node uidhash_node;
69733 kuid_t uid;
69734 @@ -1116,7 +1146,7 @@ struct sched_class {
69735 #ifdef CONFIG_FAIR_GROUP_SCHED
69736 void (*task_move_group) (struct task_struct *p, int on_rq);
69737 #endif
69738 -};
69739 +} __do_const;
69740
69741 struct load_weight {
69742 unsigned long weight, inv_weight;
69743 @@ -1360,8 +1390,8 @@ struct task_struct {
69744 struct list_head thread_group;
69745
69746 struct completion *vfork_done; /* for vfork() */
69747 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
69748 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
69749 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
69750 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
69751
69752 cputime_t utime, stime, utimescaled, stimescaled;
69753 cputime_t gtime;
69754 @@ -1377,11 +1407,6 @@ struct task_struct {
69755 struct task_cputime cputime_expires;
69756 struct list_head cpu_timers[3];
69757
69758 -/* process credentials */
69759 - const struct cred __rcu *real_cred; /* objective and real subjective task
69760 - * credentials (COW) */
69761 - const struct cred __rcu *cred; /* effective (overridable) subjective task
69762 - * credentials (COW) */
69763 char comm[TASK_COMM_LEN]; /* executable name excluding path
69764 - access with [gs]et_task_comm (which lock
69765 it with task_lock())
69766 @@ -1398,6 +1423,10 @@ struct task_struct {
69767 #endif
69768 /* CPU-specific state of this task */
69769 struct thread_struct thread;
69770 +/* thread_info moved to task_struct */
69771 +#ifdef CONFIG_X86
69772 + struct thread_info tinfo;
69773 +#endif
69774 /* filesystem information */
69775 struct fs_struct *fs;
69776 /* open file information */
69777 @@ -1471,6 +1500,10 @@ struct task_struct {
69778 gfp_t lockdep_reclaim_gfp;
69779 #endif
69780
69781 +/* process credentials */
69782 + const struct cred __rcu *real_cred; /* objective and real subjective task
69783 + * credentials (COW) */
69784 +
69785 /* journalling filesystem info */
69786 void *journal_info;
69787
69788 @@ -1509,6 +1542,10 @@ struct task_struct {
69789 /* cg_list protected by css_set_lock and tsk->alloc_lock */
69790 struct list_head cg_list;
69791 #endif
69792 +
69793 + const struct cred __rcu *cred; /* effective (overridable) subjective task
69794 + * credentials (COW) */
69795 +
69796 #ifdef CONFIG_FUTEX
69797 struct robust_list_head __user *robust_list;
69798 #ifdef CONFIG_COMPAT
69799 @@ -1605,8 +1642,74 @@ struct task_struct {
69800 #ifdef CONFIG_UPROBES
69801 struct uprobe_task *utask;
69802 #endif
69803 +
69804 +#ifdef CONFIG_GRKERNSEC
69805 + /* grsecurity */
69806 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
69807 + u64 exec_id;
69808 +#endif
69809 +#ifdef CONFIG_GRKERNSEC_SETXID
69810 + const struct cred *delayed_cred;
69811 +#endif
69812 + struct dentry *gr_chroot_dentry;
69813 + struct acl_subject_label *acl;
69814 + struct acl_role_label *role;
69815 + struct file *exec_file;
69816 + unsigned long brute_expires;
69817 + u16 acl_role_id;
69818 + /* is this the task that authenticated to the special role */
69819 + u8 acl_sp_role;
69820 + u8 is_writable;
69821 + u8 brute;
69822 + u8 gr_is_chrooted;
69823 +#endif
69824 +
69825 };
69826
69827 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
69828 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
69829 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
69830 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
69831 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
69832 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
69833 +
69834 +#ifdef CONFIG_PAX_SOFTMODE
69835 +extern int pax_softmode;
69836 +#endif
69837 +
69838 +extern int pax_check_flags(unsigned long *);
69839 +
69840 +/* if tsk != current then task_lock must be held on it */
69841 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
69842 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
69843 +{
69844 + if (likely(tsk->mm))
69845 + return tsk->mm->pax_flags;
69846 + else
69847 + return 0UL;
69848 +}
69849 +
69850 +/* if tsk != current then task_lock must be held on it */
69851 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
69852 +{
69853 + if (likely(tsk->mm)) {
69854 + tsk->mm->pax_flags = flags;
69855 + return 0;
69856 + }
69857 + return -EINVAL;
69858 +}
69859 +#endif
69860 +
69861 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
69862 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
69863 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
69864 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
69865 +#endif
69866 +
69867 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
69868 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
69869 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
69870 +
69871 /* Future-safe accessor for struct task_struct's cpus_allowed. */
69872 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
69873
69874 @@ -1696,7 +1799,7 @@ struct pid_namespace;
69875 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
69876 struct pid_namespace *ns);
69877
69878 -static inline pid_t task_pid_nr(struct task_struct *tsk)
69879 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
69880 {
69881 return tsk->pid;
69882 }
69883 @@ -2155,7 +2258,9 @@ void yield(void);
69884 extern struct exec_domain default_exec_domain;
69885
69886 union thread_union {
69887 +#ifndef CONFIG_X86
69888 struct thread_info thread_info;
69889 +#endif
69890 unsigned long stack[THREAD_SIZE/sizeof(long)];
69891 };
69892
69893 @@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
69894 */
69895
69896 extern struct task_struct *find_task_by_vpid(pid_t nr);
69897 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
69898 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
69899 struct pid_namespace *ns);
69900
69901 @@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
69902 extern void exit_itimers(struct signal_struct *);
69903 extern void flush_itimer_signals(void);
69904
69905 -extern void do_group_exit(int);
69906 +extern __noreturn void do_group_exit(int);
69907
69908 extern int allow_signal(int);
69909 extern int disallow_signal(int);
69910 @@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
69911
69912 #endif
69913
69914 -static inline int object_is_on_stack(void *obj)
69915 +static inline int object_starts_on_stack(void *obj)
69916 {
69917 - void *stack = task_stack_page(current);
69918 + const void *stack = task_stack_page(current);
69919
69920 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
69921 }
69922 diff --git a/include/linux/security.h b/include/linux/security.h
69923 index eee7478..290f7ba 100644
69924 --- a/include/linux/security.h
69925 +++ b/include/linux/security.h
69926 @@ -26,6 +26,7 @@
69927 #include <linux/capability.h>
69928 #include <linux/slab.h>
69929 #include <linux/err.h>
69930 +#include <linux/grsecurity.h>
69931
69932 struct linux_binprm;
69933 struct cred;
69934 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
69935 index 68a04a3..866e6a1 100644
69936 --- a/include/linux/seq_file.h
69937 +++ b/include/linux/seq_file.h
69938 @@ -26,6 +26,9 @@ struct seq_file {
69939 struct mutex lock;
69940 const struct seq_operations *op;
69941 int poll_event;
69942 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
69943 + u64 exec_id;
69944 +#endif
69945 #ifdef CONFIG_USER_NS
69946 struct user_namespace *user_ns;
69947 #endif
69948 @@ -38,6 +41,7 @@ struct seq_operations {
69949 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
69950 int (*show) (struct seq_file *m, void *v);
69951 };
69952 +typedef struct seq_operations __no_const seq_operations_no_const;
69953
69954 #define SEQ_SKIP 1
69955
69956 diff --git a/include/linux/shm.h b/include/linux/shm.h
69957 index 429c199..4d42e38 100644
69958 --- a/include/linux/shm.h
69959 +++ b/include/linux/shm.h
69960 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
69961
69962 /* The task created the shm object. NULL if the task is dead. */
69963 struct task_struct *shm_creator;
69964 +#ifdef CONFIG_GRKERNSEC
69965 + time_t shm_createtime;
69966 + pid_t shm_lapid;
69967 +#endif
69968 };
69969
69970 /* shm_mode upper byte flags */
69971 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
69972 index 320e976..fd52553 100644
69973 --- a/include/linux/skbuff.h
69974 +++ b/include/linux/skbuff.h
69975 @@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
69976 extern struct sk_buff *__alloc_skb(unsigned int size,
69977 gfp_t priority, int flags, int node);
69978 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
69979 -static inline struct sk_buff *alloc_skb(unsigned int size,
69980 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
69981 gfp_t priority)
69982 {
69983 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
69984 @@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
69985 */
69986 static inline int skb_queue_empty(const struct sk_buff_head *list)
69987 {
69988 - return list->next == (struct sk_buff *)list;
69989 + return list->next == (const struct sk_buff *)list;
69990 }
69991
69992 /**
69993 @@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
69994 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
69995 const struct sk_buff *skb)
69996 {
69997 - return skb->next == (struct sk_buff *)list;
69998 + return skb->next == (const struct sk_buff *)list;
69999 }
70000
70001 /**
70002 @@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
70003 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
70004 const struct sk_buff *skb)
70005 {
70006 - return skb->prev == (struct sk_buff *)list;
70007 + return skb->prev == (const struct sk_buff *)list;
70008 }
70009
70010 /**
70011 @@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
70012 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
70013 */
70014 #ifndef NET_SKB_PAD
70015 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
70016 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
70017 #endif
70018
70019 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
70020 @@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
70021 int noblock, int *err);
70022 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
70023 struct poll_table_struct *wait);
70024 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
70025 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
70026 int offset, struct iovec *to,
70027 int size);
70028 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
70029 diff --git a/include/linux/slab.h b/include/linux/slab.h
70030 index 5d168d7..720bff3 100644
70031 --- a/include/linux/slab.h
70032 +++ b/include/linux/slab.h
70033 @@ -12,13 +12,20 @@
70034 #include <linux/gfp.h>
70035 #include <linux/types.h>
70036 #include <linux/workqueue.h>
70037 -
70038 +#include <linux/err.h>
70039
70040 /*
70041 * Flags to pass to kmem_cache_create().
70042 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
70043 */
70044 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
70045 +
70046 +#ifdef CONFIG_PAX_USERCOPY_SLABS
70047 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
70048 +#else
70049 +#define SLAB_USERCOPY 0x00000000UL
70050 +#endif
70051 +
70052 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
70053 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
70054 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
70055 @@ -89,10 +96,13 @@
70056 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
70057 * Both make kfree a no-op.
70058 */
70059 -#define ZERO_SIZE_PTR ((void *)16)
70060 +#define ZERO_SIZE_PTR \
70061 +({ \
70062 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
70063 + (void *)(-MAX_ERRNO-1L); \
70064 +})
70065
70066 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
70067 - (unsigned long)ZERO_SIZE_PTR)
70068 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
70069
70070 /*
70071 * Common fields provided in kmem_cache by all slab allocators
70072 @@ -112,7 +122,7 @@ struct kmem_cache {
70073 unsigned int align; /* Alignment as calculated */
70074 unsigned long flags; /* Active flags on the slab */
70075 const char *name; /* Slab name for sysfs */
70076 - int refcount; /* Use counter */
70077 + atomic_t refcount; /* Use counter */
70078 void (*ctor)(void *); /* Called on object slot creation */
70079 struct list_head list; /* List of all slab caches on the system */
70080 };
70081 @@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
70082 void kfree(const void *);
70083 void kzfree(const void *);
70084 size_t ksize(const void *);
70085 +const char *check_heap_object(const void *ptr, unsigned long n);
70086 +bool is_usercopy_object(const void *ptr);
70087
70088 /*
70089 * Allocator specific definitions. These are mainly used to establish optimized
70090 @@ -311,6 +323,7 @@ size_t ksize(const void *);
70091 * for general use, and so are not documented here. For a full list of
70092 * potential flags, always refer to linux/gfp.h.
70093 */
70094 +
70095 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
70096 {
70097 if (size != 0 && n > SIZE_MAX / size)
70098 @@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
70099 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70100 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70101 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70102 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70103 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
70104 #define kmalloc_track_caller(size, flags) \
70105 __kmalloc_track_caller(size, flags, _RET_IP_)
70106 #else
70107 @@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70108 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70109 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70110 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70111 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
70112 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
70113 #define kmalloc_node_track_caller(size, flags, node) \
70114 __kmalloc_node_track_caller(size, flags, node, \
70115 _RET_IP_)
70116 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
70117 index 8bb6e0e..8eb0dbe 100644
70118 --- a/include/linux/slab_def.h
70119 +++ b/include/linux/slab_def.h
70120 @@ -52,7 +52,7 @@ struct kmem_cache {
70121 /* 4) cache creation/removal */
70122 const char *name;
70123 struct list_head list;
70124 - int refcount;
70125 + atomic_t refcount;
70126 int object_size;
70127 int align;
70128
70129 @@ -68,10 +68,10 @@ struct kmem_cache {
70130 unsigned long node_allocs;
70131 unsigned long node_frees;
70132 unsigned long node_overflow;
70133 - atomic_t allochit;
70134 - atomic_t allocmiss;
70135 - atomic_t freehit;
70136 - atomic_t freemiss;
70137 + atomic_unchecked_t allochit;
70138 + atomic_unchecked_t allocmiss;
70139 + atomic_unchecked_t freehit;
70140 + atomic_unchecked_t freemiss;
70141
70142 /*
70143 * If debugging is enabled, then the allocator can add additional
70144 @@ -111,11 +111,16 @@ struct cache_sizes {
70145 #ifdef CONFIG_ZONE_DMA
70146 struct kmem_cache *cs_dmacachep;
70147 #endif
70148 +
70149 +#ifdef CONFIG_PAX_USERCOPY_SLABS
70150 + struct kmem_cache *cs_usercopycachep;
70151 +#endif
70152 +
70153 };
70154 extern struct cache_sizes malloc_sizes[];
70155
70156 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70157 -void *__kmalloc(size_t size, gfp_t flags);
70158 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
70159
70160 #ifdef CONFIG_TRACING
70161 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
70162 @@ -152,6 +157,13 @@ found:
70163 cachep = malloc_sizes[i].cs_dmacachep;
70164 else
70165 #endif
70166 +
70167 +#ifdef CONFIG_PAX_USERCOPY_SLABS
70168 + if (flags & GFP_USERCOPY)
70169 + cachep = malloc_sizes[i].cs_usercopycachep;
70170 + else
70171 +#endif
70172 +
70173 cachep = malloc_sizes[i].cs_cachep;
70174
70175 ret = kmem_cache_alloc_trace(cachep, flags, size);
70176 @@ -162,7 +174,7 @@ found:
70177 }
70178
70179 #ifdef CONFIG_NUMA
70180 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
70181 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70182 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70183
70184 #ifdef CONFIG_TRACING
70185 @@ -205,6 +217,13 @@ found:
70186 cachep = malloc_sizes[i].cs_dmacachep;
70187 else
70188 #endif
70189 +
70190 +#ifdef CONFIG_PAX_USERCOPY_SLABS
70191 + if (flags & GFP_USERCOPY)
70192 + cachep = malloc_sizes[i].cs_usercopycachep;
70193 + else
70194 +#endif
70195 +
70196 cachep = malloc_sizes[i].cs_cachep;
70197
70198 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
70199 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
70200 index f28e14a..7831211 100644
70201 --- a/include/linux/slob_def.h
70202 +++ b/include/linux/slob_def.h
70203 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
70204 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
70205 }
70206
70207 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
70208 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70209
70210 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
70211 {
70212 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70213 return __kmalloc_node(size, flags, NUMA_NO_NODE);
70214 }
70215
70216 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
70217 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
70218 {
70219 return kmalloc(size, flags);
70220 }
70221 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
70222 index 9db4825..ed42fb5 100644
70223 --- a/include/linux/slub_def.h
70224 +++ b/include/linux/slub_def.h
70225 @@ -91,7 +91,7 @@ struct kmem_cache {
70226 struct kmem_cache_order_objects max;
70227 struct kmem_cache_order_objects min;
70228 gfp_t allocflags; /* gfp flags to use on each alloc */
70229 - int refcount; /* Refcount for slab cache destroy */
70230 + atomic_t refcount; /* Refcount for slab cache destroy */
70231 void (*ctor)(void *);
70232 int inuse; /* Offset to metadata */
70233 int align; /* Alignment */
70234 @@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
70235 * Sorry that the following has to be that ugly but some versions of GCC
70236 * have trouble with constant propagation and loops.
70237 */
70238 -static __always_inline int kmalloc_index(size_t size)
70239 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
70240 {
70241 if (!size)
70242 return 0;
70243 @@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
70244 }
70245
70246 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70247 -void *__kmalloc(size_t size, gfp_t flags);
70248 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
70249
70250 static __always_inline void *
70251 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
70252 @@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
70253 }
70254 #endif
70255
70256 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
70257 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
70258 {
70259 unsigned int order = get_order(size);
70260 return kmalloc_order_trace(size, flags, order);
70261 @@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70262 }
70263
70264 #ifdef CONFIG_NUMA
70265 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
70266 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70267 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70268
70269 #ifdef CONFIG_TRACING
70270 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
70271 index e8d702e..0a56eb4 100644
70272 --- a/include/linux/sock_diag.h
70273 +++ b/include/linux/sock_diag.h
70274 @@ -10,7 +10,7 @@ struct sock;
70275 struct sock_diag_handler {
70276 __u8 family;
70277 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
70278 -};
70279 +} __do_const;
70280
70281 int sock_diag_register(const struct sock_diag_handler *h);
70282 void sock_diag_unregister(const struct sock_diag_handler *h);
70283 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
70284 index 680f9a3..f13aeb0 100644
70285 --- a/include/linux/sonet.h
70286 +++ b/include/linux/sonet.h
70287 @@ -7,7 +7,7 @@
70288 #include <uapi/linux/sonet.h>
70289
70290 struct k_sonet_stats {
70291 -#define __HANDLE_ITEM(i) atomic_t i
70292 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
70293 __SONET_ITEMS
70294 #undef __HANDLE_ITEM
70295 };
70296 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
70297 index 34206b8..3db7f1c 100644
70298 --- a/include/linux/sunrpc/clnt.h
70299 +++ b/include/linux/sunrpc/clnt.h
70300 @@ -96,7 +96,7 @@ struct rpc_procinfo {
70301 unsigned int p_timer; /* Which RTT timer to use */
70302 u32 p_statidx; /* Which procedure to account */
70303 const char * p_name; /* name of procedure */
70304 -};
70305 +} __do_const;
70306
70307 #ifdef __KERNEL__
70308
70309 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
70310 {
70311 switch (sap->sa_family) {
70312 case AF_INET:
70313 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
70314 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
70315 case AF_INET6:
70316 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
70317 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
70318 }
70319 return 0;
70320 }
70321 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
70322 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
70323 const struct sockaddr *src)
70324 {
70325 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
70326 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
70327 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
70328
70329 dsin->sin_family = ssin->sin_family;
70330 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
70331 if (sa->sa_family != AF_INET6)
70332 return 0;
70333
70334 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
70335 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
70336 }
70337
70338 #endif /* __KERNEL__ */
70339 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
70340 index 676ddf5..4c519a1 100644
70341 --- a/include/linux/sunrpc/svc.h
70342 +++ b/include/linux/sunrpc/svc.h
70343 @@ -410,7 +410,7 @@ struct svc_procedure {
70344 unsigned int pc_count; /* call count */
70345 unsigned int pc_cachetype; /* cache info (NFS) */
70346 unsigned int pc_xdrressize; /* maximum size of XDR reply */
70347 -};
70348 +} __do_const;
70349
70350 /*
70351 * Function prototypes.
70352 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
70353 index 0b8e3e6..33e0a01 100644
70354 --- a/include/linux/sunrpc/svc_rdma.h
70355 +++ b/include/linux/sunrpc/svc_rdma.h
70356 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
70357 extern unsigned int svcrdma_max_requests;
70358 extern unsigned int svcrdma_max_req_size;
70359
70360 -extern atomic_t rdma_stat_recv;
70361 -extern atomic_t rdma_stat_read;
70362 -extern atomic_t rdma_stat_write;
70363 -extern atomic_t rdma_stat_sq_starve;
70364 -extern atomic_t rdma_stat_rq_starve;
70365 -extern atomic_t rdma_stat_rq_poll;
70366 -extern atomic_t rdma_stat_rq_prod;
70367 -extern atomic_t rdma_stat_sq_poll;
70368 -extern atomic_t rdma_stat_sq_prod;
70369 +extern atomic_unchecked_t rdma_stat_recv;
70370 +extern atomic_unchecked_t rdma_stat_read;
70371 +extern atomic_unchecked_t rdma_stat_write;
70372 +extern atomic_unchecked_t rdma_stat_sq_starve;
70373 +extern atomic_unchecked_t rdma_stat_rq_starve;
70374 +extern atomic_unchecked_t rdma_stat_rq_poll;
70375 +extern atomic_unchecked_t rdma_stat_rq_prod;
70376 +extern atomic_unchecked_t rdma_stat_sq_poll;
70377 +extern atomic_unchecked_t rdma_stat_sq_prod;
70378
70379 #define RPCRDMA_VERSION 1
70380
70381 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
70382 index dd74084a..7f509d5 100644
70383 --- a/include/linux/sunrpc/svcauth.h
70384 +++ b/include/linux/sunrpc/svcauth.h
70385 @@ -109,7 +109,7 @@ struct auth_ops {
70386 int (*release)(struct svc_rqst *rq);
70387 void (*domain_release)(struct auth_domain *);
70388 int (*set_client)(struct svc_rqst *rq);
70389 -};
70390 +} __do_const;
70391
70392 #define SVC_GARBAGE 1
70393 #define SVC_SYSERR 2
70394 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
70395 index 071d62c..4ccc7ac 100644
70396 --- a/include/linux/swiotlb.h
70397 +++ b/include/linux/swiotlb.h
70398 @@ -59,7 +59,8 @@ extern void
70399
70400 extern void
70401 swiotlb_free_coherent(struct device *hwdev, size_t size,
70402 - void *vaddr, dma_addr_t dma_handle);
70403 + void *vaddr, dma_addr_t dma_handle,
70404 + struct dma_attrs *attrs);
70405
70406 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
70407 unsigned long offset, size_t size,
70408 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
70409 index 27b3b0b..e093dd9 100644
70410 --- a/include/linux/syscore_ops.h
70411 +++ b/include/linux/syscore_ops.h
70412 @@ -16,7 +16,7 @@ struct syscore_ops {
70413 int (*suspend)(void);
70414 void (*resume)(void);
70415 void (*shutdown)(void);
70416 -};
70417 +} __do_const;
70418
70419 extern void register_syscore_ops(struct syscore_ops *ops);
70420 extern void unregister_syscore_ops(struct syscore_ops *ops);
70421 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
70422 index 14a8ff2..af52bad 100644
70423 --- a/include/linux/sysctl.h
70424 +++ b/include/linux/sysctl.h
70425 @@ -34,13 +34,13 @@ struct ctl_table_root;
70426 struct ctl_table_header;
70427 struct ctl_dir;
70428
70429 -typedef struct ctl_table ctl_table;
70430 -
70431 typedef int proc_handler (struct ctl_table *ctl, int write,
70432 void __user *buffer, size_t *lenp, loff_t *ppos);
70433
70434 extern int proc_dostring(struct ctl_table *, int,
70435 void __user *, size_t *, loff_t *);
70436 +extern int proc_dostring_modpriv(struct ctl_table *, int,
70437 + void __user *, size_t *, loff_t *);
70438 extern int proc_dointvec(struct ctl_table *, int,
70439 void __user *, size_t *, loff_t *);
70440 extern int proc_dointvec_minmax(struct ctl_table *, int,
70441 @@ -115,7 +115,9 @@ struct ctl_table
70442 struct ctl_table_poll *poll;
70443 void *extra1;
70444 void *extra2;
70445 -};
70446 +} __do_const;
70447 +typedef struct ctl_table __no_const ctl_table_no_const;
70448 +typedef struct ctl_table ctl_table;
70449
70450 struct ctl_node {
70451 struct rb_node node;
70452 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
70453 index 381f06d..dc16cc7 100644
70454 --- a/include/linux/sysfs.h
70455 +++ b/include/linux/sysfs.h
70456 @@ -31,7 +31,8 @@ struct attribute {
70457 struct lock_class_key *key;
70458 struct lock_class_key skey;
70459 #endif
70460 -};
70461 +} __do_const;
70462 +typedef struct attribute __no_const attribute_no_const;
70463
70464 /**
70465 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
70466 @@ -59,8 +60,8 @@ struct attribute_group {
70467 umode_t (*is_visible)(struct kobject *,
70468 struct attribute *, int);
70469 struct attribute **attrs;
70470 -};
70471 -
70472 +} __do_const;
70473 +typedef struct attribute_group __no_const attribute_group_no_const;
70474
70475
70476 /**
70477 @@ -107,7 +108,8 @@ struct bin_attribute {
70478 char *, loff_t, size_t);
70479 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
70480 struct vm_area_struct *vma);
70481 -};
70482 +} __do_const;
70483 +typedef struct bin_attribute __no_const bin_attribute_no_const;
70484
70485 /**
70486 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
70487 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
70488 index 7faf933..4657127 100644
70489 --- a/include/linux/sysrq.h
70490 +++ b/include/linux/sysrq.h
70491 @@ -15,7 +15,9 @@
70492 #define _LINUX_SYSRQ_H
70493
70494 #include <linux/errno.h>
70495 +#include <linux/compiler.h>
70496 #include <linux/types.h>
70497 +#include <linux/compiler.h>
70498
70499 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
70500 #define SYSRQ_DEFAULT_ENABLE 1
70501 @@ -36,7 +38,7 @@ struct sysrq_key_op {
70502 char *help_msg;
70503 char *action_msg;
70504 int enable_mask;
70505 -};
70506 +} __do_const;
70507
70508 #ifdef CONFIG_MAGIC_SYSRQ
70509
70510 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
70511 index e7e0473..39b7b52 100644
70512 --- a/include/linux/thread_info.h
70513 +++ b/include/linux/thread_info.h
70514 @@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
70515 #error "no set_restore_sigmask() provided and default one won't work"
70516 #endif
70517
70518 +extern void __check_object_size(const void *ptr, unsigned long n, bool to);
70519 +static inline void check_object_size(const void *ptr, unsigned long n, bool to)
70520 +{
70521 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
70522 + if (!__builtin_constant_p(n))
70523 +#endif
70524 + __check_object_size(ptr, n, to);
70525 +}
70526 +
70527 #endif /* __KERNEL__ */
70528
70529 #endif /* _LINUX_THREAD_INFO_H */
70530 diff --git a/include/linux/tty.h b/include/linux/tty.h
70531 index 8db1b56..c16a040 100644
70532 --- a/include/linux/tty.h
70533 +++ b/include/linux/tty.h
70534 @@ -194,7 +194,7 @@ struct tty_port {
70535 const struct tty_port_operations *ops; /* Port operations */
70536 spinlock_t lock; /* Lock protecting tty field */
70537 int blocked_open; /* Waiting to open */
70538 - int count; /* Usage count */
70539 + atomic_t count; /* Usage count */
70540 wait_queue_head_t open_wait; /* Open waiters */
70541 wait_queue_head_t close_wait; /* Close waiters */
70542 wait_queue_head_t delta_msr_wait; /* Modem status change */
70543 @@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
70544 struct tty_struct *tty, struct file *filp);
70545 static inline int tty_port_users(struct tty_port *port)
70546 {
70547 - return port->count + port->blocked_open;
70548 + return atomic_read(&port->count) + port->blocked_open;
70549 }
70550
70551 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
70552 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
70553 index dd976cf..e272742 100644
70554 --- a/include/linux/tty_driver.h
70555 +++ b/include/linux/tty_driver.h
70556 @@ -284,7 +284,7 @@ struct tty_operations {
70557 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
70558 #endif
70559 const struct file_operations *proc_fops;
70560 -};
70561 +} __do_const;
70562
70563 struct tty_driver {
70564 int magic; /* magic number for this structure */
70565 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
70566 index fb79dd8d..07d4773 100644
70567 --- a/include/linux/tty_ldisc.h
70568 +++ b/include/linux/tty_ldisc.h
70569 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
70570
70571 struct module *owner;
70572
70573 - int refcount;
70574 + atomic_t refcount;
70575 };
70576
70577 struct tty_ldisc {
70578 diff --git a/include/linux/types.h b/include/linux/types.h
70579 index 4d118ba..c3ee9bf 100644
70580 --- a/include/linux/types.h
70581 +++ b/include/linux/types.h
70582 @@ -176,10 +176,26 @@ typedef struct {
70583 int counter;
70584 } atomic_t;
70585
70586 +#ifdef CONFIG_PAX_REFCOUNT
70587 +typedef struct {
70588 + int counter;
70589 +} atomic_unchecked_t;
70590 +#else
70591 +typedef atomic_t atomic_unchecked_t;
70592 +#endif
70593 +
70594 #ifdef CONFIG_64BIT
70595 typedef struct {
70596 long counter;
70597 } atomic64_t;
70598 +
70599 +#ifdef CONFIG_PAX_REFCOUNT
70600 +typedef struct {
70601 + long counter;
70602 +} atomic64_unchecked_t;
70603 +#else
70604 +typedef atomic64_t atomic64_unchecked_t;
70605 +#endif
70606 #endif
70607
70608 struct list_head {
70609 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
70610 index 5ca0951..ab496a5 100644
70611 --- a/include/linux/uaccess.h
70612 +++ b/include/linux/uaccess.h
70613 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
70614 long ret; \
70615 mm_segment_t old_fs = get_fs(); \
70616 \
70617 - set_fs(KERNEL_DS); \
70618 pagefault_disable(); \
70619 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
70620 - pagefault_enable(); \
70621 + set_fs(KERNEL_DS); \
70622 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
70623 set_fs(old_fs); \
70624 + pagefault_enable(); \
70625 ret; \
70626 })
70627
70628 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
70629 index 8e522cbc..aa8572d 100644
70630 --- a/include/linux/uidgid.h
70631 +++ b/include/linux/uidgid.h
70632 @@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
70633
70634 #endif /* CONFIG_USER_NS */
70635
70636 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
70637 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
70638 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
70639 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
70640 +
70641 #endif /* _LINUX_UIDGID_H */
70642 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
70643 index 99c1b4d..bb94261 100644
70644 --- a/include/linux/unaligned/access_ok.h
70645 +++ b/include/linux/unaligned/access_ok.h
70646 @@ -6,32 +6,32 @@
70647
70648 static inline u16 get_unaligned_le16(const void *p)
70649 {
70650 - return le16_to_cpup((__le16 *)p);
70651 + return le16_to_cpup((const __le16 *)p);
70652 }
70653
70654 static inline u32 get_unaligned_le32(const void *p)
70655 {
70656 - return le32_to_cpup((__le32 *)p);
70657 + return le32_to_cpup((const __le32 *)p);
70658 }
70659
70660 static inline u64 get_unaligned_le64(const void *p)
70661 {
70662 - return le64_to_cpup((__le64 *)p);
70663 + return le64_to_cpup((const __le64 *)p);
70664 }
70665
70666 static inline u16 get_unaligned_be16(const void *p)
70667 {
70668 - return be16_to_cpup((__be16 *)p);
70669 + return be16_to_cpup((const __be16 *)p);
70670 }
70671
70672 static inline u32 get_unaligned_be32(const void *p)
70673 {
70674 - return be32_to_cpup((__be32 *)p);
70675 + return be32_to_cpup((const __be32 *)p);
70676 }
70677
70678 static inline u64 get_unaligned_be64(const void *p)
70679 {
70680 - return be64_to_cpup((__be64 *)p);
70681 + return be64_to_cpup((const __be64 *)p);
70682 }
70683
70684 static inline void put_unaligned_le16(u16 val, void *p)
70685 diff --git a/include/linux/usb.h b/include/linux/usb.h
70686 index 4d22d0f..ac43c2f 100644
70687 --- a/include/linux/usb.h
70688 +++ b/include/linux/usb.h
70689 @@ -554,7 +554,7 @@ struct usb_device {
70690 int maxchild;
70691
70692 u32 quirks;
70693 - atomic_t urbnum;
70694 + atomic_unchecked_t urbnum;
70695
70696 unsigned long active_duration;
70697
70698 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
70699 index c5d36c6..108f4f9 100644
70700 --- a/include/linux/usb/renesas_usbhs.h
70701 +++ b/include/linux/usb/renesas_usbhs.h
70702 @@ -39,7 +39,7 @@ enum {
70703 */
70704 struct renesas_usbhs_driver_callback {
70705 int (*notify_hotplug)(struct platform_device *pdev);
70706 -};
70707 +} __no_const;
70708
70709 /*
70710 * callback functions for platform
70711 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
70712 index b9bd2e6..4ce0093 100644
70713 --- a/include/linux/user_namespace.h
70714 +++ b/include/linux/user_namespace.h
70715 @@ -21,7 +21,7 @@ struct user_namespace {
70716 struct uid_gid_map uid_map;
70717 struct uid_gid_map gid_map;
70718 struct uid_gid_map projid_map;
70719 - struct kref kref;
70720 + atomic_t count;
70721 struct user_namespace *parent;
70722 kuid_t owner;
70723 kgid_t group;
70724 @@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
70725 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
70726 {
70727 if (ns)
70728 - kref_get(&ns->kref);
70729 + atomic_inc(&ns->count);
70730 return ns;
70731 }
70732
70733 extern int create_user_ns(struct cred *new);
70734 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
70735 -extern void free_user_ns(struct kref *kref);
70736 +extern void free_user_ns(struct user_namespace *ns);
70737
70738 static inline void put_user_ns(struct user_namespace *ns)
70739 {
70740 - if (ns)
70741 - kref_put(&ns->kref, free_user_ns);
70742 + if (ns && atomic_dec_and_test(&ns->count))
70743 + free_user_ns(ns);
70744 }
70745
70746 struct seq_operations;
70747 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
70748 index 6f8fbcf..8259001 100644
70749 --- a/include/linux/vermagic.h
70750 +++ b/include/linux/vermagic.h
70751 @@ -25,9 +25,35 @@
70752 #define MODULE_ARCH_VERMAGIC ""
70753 #endif
70754
70755 +#ifdef CONFIG_PAX_REFCOUNT
70756 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
70757 +#else
70758 +#define MODULE_PAX_REFCOUNT ""
70759 +#endif
70760 +
70761 +#ifdef CONSTIFY_PLUGIN
70762 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
70763 +#else
70764 +#define MODULE_CONSTIFY_PLUGIN ""
70765 +#endif
70766 +
70767 +#ifdef STACKLEAK_PLUGIN
70768 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
70769 +#else
70770 +#define MODULE_STACKLEAK_PLUGIN ""
70771 +#endif
70772 +
70773 +#ifdef CONFIG_GRKERNSEC
70774 +#define MODULE_GRSEC "GRSEC "
70775 +#else
70776 +#define MODULE_GRSEC ""
70777 +#endif
70778 +
70779 #define VERMAGIC_STRING \
70780 UTS_RELEASE " " \
70781 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
70782 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
70783 - MODULE_ARCH_VERMAGIC
70784 + MODULE_ARCH_VERMAGIC \
70785 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
70786 + MODULE_GRSEC
70787
70788 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
70789 index 6071e91..ca6a489 100644
70790 --- a/include/linux/vmalloc.h
70791 +++ b/include/linux/vmalloc.h
70792 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
70793 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
70794 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
70795 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
70796 +
70797 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
70798 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
70799 +#endif
70800 +
70801 /* bits [20..32] reserved for arch specific ioremap internals */
70802
70803 /*
70804 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
70805 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
70806 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
70807 unsigned long start, unsigned long end, gfp_t gfp_mask,
70808 - pgprot_t prot, int node, const void *caller);
70809 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
70810 extern void vfree(const void *addr);
70811
70812 extern void *vmap(struct page **pages, unsigned int count,
70813 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
70814 extern void free_vm_area(struct vm_struct *area);
70815
70816 /* for /dev/kmem */
70817 -extern long vread(char *buf, char *addr, unsigned long count);
70818 -extern long vwrite(char *buf, char *addr, unsigned long count);
70819 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
70820 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
70821
70822 /*
70823 * Internals. Dont't use..
70824 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
70825 index a13291f..af51fa3 100644
70826 --- a/include/linux/vmstat.h
70827 +++ b/include/linux/vmstat.h
70828 @@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
70829 /*
70830 * Zone based page accounting with per cpu differentials.
70831 */
70832 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70833 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70834
70835 static inline void zone_page_state_add(long x, struct zone *zone,
70836 enum zone_stat_item item)
70837 {
70838 - atomic_long_add(x, &zone->vm_stat[item]);
70839 - atomic_long_add(x, &vm_stat[item]);
70840 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
70841 + atomic_long_add_unchecked(x, &vm_stat[item]);
70842 }
70843
70844 static inline unsigned long global_page_state(enum zone_stat_item item)
70845 {
70846 - long x = atomic_long_read(&vm_stat[item]);
70847 + long x = atomic_long_read_unchecked(&vm_stat[item]);
70848 #ifdef CONFIG_SMP
70849 if (x < 0)
70850 x = 0;
70851 @@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
70852 static inline unsigned long zone_page_state(struct zone *zone,
70853 enum zone_stat_item item)
70854 {
70855 - long x = atomic_long_read(&zone->vm_stat[item]);
70856 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
70857 #ifdef CONFIG_SMP
70858 if (x < 0)
70859 x = 0;
70860 @@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
70861 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
70862 enum zone_stat_item item)
70863 {
70864 - long x = atomic_long_read(&zone->vm_stat[item]);
70865 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
70866
70867 #ifdef CONFIG_SMP
70868 int cpu;
70869 @@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
70870
70871 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
70872 {
70873 - atomic_long_inc(&zone->vm_stat[item]);
70874 - atomic_long_inc(&vm_stat[item]);
70875 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
70876 + atomic_long_inc_unchecked(&vm_stat[item]);
70877 }
70878
70879 static inline void __inc_zone_page_state(struct page *page,
70880 @@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
70881
70882 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
70883 {
70884 - atomic_long_dec(&zone->vm_stat[item]);
70885 - atomic_long_dec(&vm_stat[item]);
70886 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
70887 + atomic_long_dec_unchecked(&vm_stat[item]);
70888 }
70889
70890 static inline void __dec_zone_page_state(struct page *page,
70891 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
70892 index fdbafc6..b7ffd47 100644
70893 --- a/include/linux/xattr.h
70894 +++ b/include/linux/xattr.h
70895 @@ -28,7 +28,7 @@ struct xattr_handler {
70896 size_t size, int handler_flags);
70897 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
70898 size_t size, int flags, int handler_flags);
70899 -};
70900 +} __do_const;
70901
70902 struct xattr {
70903 char *name;
70904 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
70905 index 95d1c91..6798cca 100644
70906 --- a/include/media/v4l2-dev.h
70907 +++ b/include/media/v4l2-dev.h
70908 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
70909 int (*mmap) (struct file *, struct vm_area_struct *);
70910 int (*open) (struct file *);
70911 int (*release) (struct file *);
70912 -};
70913 +} __do_const;
70914
70915 /*
70916 * Newer version of video_device, handled by videodev2.c
70917 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
70918 index 4118ad1..cb7e25f 100644
70919 --- a/include/media/v4l2-ioctl.h
70920 +++ b/include/media/v4l2-ioctl.h
70921 @@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
70922 bool valid_prio, int cmd, void *arg);
70923 };
70924
70925 -
70926 /* v4l debugging and diagnostics */
70927
70928 /* Debug bitmask flags to be used on V4L2 */
70929 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
70930 index adcbb20..62c2559 100644
70931 --- a/include/net/9p/transport.h
70932 +++ b/include/net/9p/transport.h
70933 @@ -57,7 +57,7 @@ struct p9_trans_module {
70934 int (*cancel) (struct p9_client *, struct p9_req_t *req);
70935 int (*zc_request)(struct p9_client *, struct p9_req_t *,
70936 char *, char *, int , int, int, int);
70937 -};
70938 +} __do_const;
70939
70940 void v9fs_register_trans(struct p9_trans_module *m);
70941 void v9fs_unregister_trans(struct p9_trans_module *m);
70942 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
70943 index 7588ef4..e62d35f 100644
70944 --- a/include/net/bluetooth/l2cap.h
70945 +++ b/include/net/bluetooth/l2cap.h
70946 @@ -552,7 +552,7 @@ struct l2cap_ops {
70947 void (*defer) (struct l2cap_chan *chan);
70948 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
70949 unsigned long len, int nb);
70950 -};
70951 +} __do_const;
70952
70953 struct l2cap_conn {
70954 struct hci_conn *hcon;
70955 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
70956 index 9e5425b..8136ffc 100644
70957 --- a/include/net/caif/cfctrl.h
70958 +++ b/include/net/caif/cfctrl.h
70959 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
70960 void (*radioset_rsp)(void);
70961 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
70962 struct cflayer *client_layer);
70963 -};
70964 +} __no_const;
70965
70966 /* Link Setup Parameters for CAIF-Links. */
70967 struct cfctrl_link_param {
70968 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
70969 struct cfctrl {
70970 struct cfsrvl serv;
70971 struct cfctrl_rsp res;
70972 - atomic_t req_seq_no;
70973 - atomic_t rsp_seq_no;
70974 + atomic_unchecked_t req_seq_no;
70975 + atomic_unchecked_t rsp_seq_no;
70976 struct list_head list;
70977 /* Protects from simultaneous access to first_req list */
70978 spinlock_t info_list_lock;
70979 diff --git a/include/net/flow.h b/include/net/flow.h
70980 index 628e11b..4c475df 100644
70981 --- a/include/net/flow.h
70982 +++ b/include/net/flow.h
70983 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
70984
70985 extern void flow_cache_flush(void);
70986 extern void flow_cache_flush_deferred(void);
70987 -extern atomic_t flow_cache_genid;
70988 +extern atomic_unchecked_t flow_cache_genid;
70989
70990 #endif
70991 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
70992 index bdfbe68..4402ebe 100644
70993 --- a/include/net/genetlink.h
70994 +++ b/include/net/genetlink.h
70995 @@ -118,7 +118,7 @@ struct genl_ops {
70996 struct netlink_callback *cb);
70997 int (*done)(struct netlink_callback *cb);
70998 struct list_head ops_list;
70999 -};
71000 +} __do_const;
71001
71002 extern int genl_register_family(struct genl_family *family);
71003 extern int genl_register_family_with_ops(struct genl_family *family,
71004 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
71005 index e5062c9..48a9a4b 100644
71006 --- a/include/net/gro_cells.h
71007 +++ b/include/net/gro_cells.h
71008 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
71009 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
71010
71011 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
71012 - atomic_long_inc(&dev->rx_dropped);
71013 + atomic_long_inc_unchecked(&dev->rx_dropped);
71014 kfree_skb(skb);
71015 return;
71016 }
71017 @@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
71018 int i;
71019
71020 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
71021 - gcells->cells = kcalloc(sizeof(struct gro_cell),
71022 - gcells->gro_cells_mask + 1,
71023 + gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
71024 + sizeof(struct gro_cell),
71025 GFP_KERNEL);
71026 if (!gcells->cells)
71027 return -ENOMEM;
71028 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
71029 index 1832927..ce39aea 100644
71030 --- a/include/net/inet_connection_sock.h
71031 +++ b/include/net/inet_connection_sock.h
71032 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
71033 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
71034 int (*bind_conflict)(const struct sock *sk,
71035 const struct inet_bind_bucket *tb, bool relax);
71036 -};
71037 +} __do_const;
71038
71039 /** inet_connection_sock - INET connection oriented sock
71040 *
71041 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
71042 index 53f464d..ba76aaa 100644
71043 --- a/include/net/inetpeer.h
71044 +++ b/include/net/inetpeer.h
71045 @@ -47,8 +47,8 @@ struct inet_peer {
71046 */
71047 union {
71048 struct {
71049 - atomic_t rid; /* Frag reception counter */
71050 - atomic_t ip_id_count; /* IP ID for the next packet */
71051 + atomic_unchecked_t rid; /* Frag reception counter */
71052 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
71053 };
71054 struct rcu_head rcu;
71055 struct inet_peer *gc_next;
71056 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
71057 more++;
71058 inet_peer_refcheck(p);
71059 do {
71060 - old = atomic_read(&p->ip_id_count);
71061 + old = atomic_read_unchecked(&p->ip_id_count);
71062 new = old + more;
71063 if (!new)
71064 new = 1;
71065 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
71066 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
71067 return new;
71068 }
71069
71070 diff --git a/include/net/ip.h b/include/net/ip.h
71071 index a68f838..74518ab 100644
71072 --- a/include/net/ip.h
71073 +++ b/include/net/ip.h
71074 @@ -202,7 +202,7 @@ extern struct local_ports {
71075 } sysctl_local_ports;
71076 extern void inet_get_local_port_range(int *low, int *high);
71077
71078 -extern unsigned long *sysctl_local_reserved_ports;
71079 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
71080 static inline int inet_is_reserved_local_port(int port)
71081 {
71082 return test_bit(port, sysctl_local_reserved_ports);
71083 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
71084 index 9497be1..5a4fafe 100644
71085 --- a/include/net/ip_fib.h
71086 +++ b/include/net/ip_fib.h
71087 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
71088
71089 #define FIB_RES_SADDR(net, res) \
71090 ((FIB_RES_NH(res).nh_saddr_genid == \
71091 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
71092 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
71093 FIB_RES_NH(res).nh_saddr : \
71094 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
71095 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
71096 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
71097 index 68c69d5..bdab192 100644
71098 --- a/include/net/ip_vs.h
71099 +++ b/include/net/ip_vs.h
71100 @@ -599,7 +599,7 @@ struct ip_vs_conn {
71101 struct ip_vs_conn *control; /* Master control connection */
71102 atomic_t n_control; /* Number of controlled ones */
71103 struct ip_vs_dest *dest; /* real server */
71104 - atomic_t in_pkts; /* incoming packet counter */
71105 + atomic_unchecked_t in_pkts; /* incoming packet counter */
71106
71107 /* packet transmitter for different forwarding methods. If it
71108 mangles the packet, it must return NF_DROP or better NF_STOLEN,
71109 @@ -737,7 +737,7 @@ struct ip_vs_dest {
71110 __be16 port; /* port number of the server */
71111 union nf_inet_addr addr; /* IP address of the server */
71112 volatile unsigned int flags; /* dest status flags */
71113 - atomic_t conn_flags; /* flags to copy to conn */
71114 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
71115 atomic_t weight; /* server weight */
71116
71117 atomic_t refcnt; /* reference counter */
71118 @@ -980,11 +980,11 @@ struct netns_ipvs {
71119 /* ip_vs_lblc */
71120 int sysctl_lblc_expiration;
71121 struct ctl_table_header *lblc_ctl_header;
71122 - struct ctl_table *lblc_ctl_table;
71123 + ctl_table_no_const *lblc_ctl_table;
71124 /* ip_vs_lblcr */
71125 int sysctl_lblcr_expiration;
71126 struct ctl_table_header *lblcr_ctl_header;
71127 - struct ctl_table *lblcr_ctl_table;
71128 + ctl_table_no_const *lblcr_ctl_table;
71129 /* ip_vs_est */
71130 struct list_head est_list; /* estimator list */
71131 spinlock_t est_lock;
71132 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
71133 index 80ffde3..968b0f4 100644
71134 --- a/include/net/irda/ircomm_tty.h
71135 +++ b/include/net/irda/ircomm_tty.h
71136 @@ -35,6 +35,7 @@
71137 #include <linux/termios.h>
71138 #include <linux/timer.h>
71139 #include <linux/tty.h> /* struct tty_struct */
71140 +#include <asm/local.h>
71141
71142 #include <net/irda/irias_object.h>
71143 #include <net/irda/ircomm_core.h>
71144 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
71145 index cc7c197..9f2da2a 100644
71146 --- a/include/net/iucv/af_iucv.h
71147 +++ b/include/net/iucv/af_iucv.h
71148 @@ -141,7 +141,7 @@ struct iucv_sock {
71149 struct iucv_sock_list {
71150 struct hlist_head head;
71151 rwlock_t lock;
71152 - atomic_t autobind_name;
71153 + atomic_unchecked_t autobind_name;
71154 };
71155
71156 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
71157 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
71158 index df83f69..9b640b8 100644
71159 --- a/include/net/llc_c_ac.h
71160 +++ b/include/net/llc_c_ac.h
71161 @@ -87,7 +87,7 @@
71162 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
71163 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
71164
71165 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71166 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71167
71168 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
71169 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
71170 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
71171 index 6ca3113..f8026dd 100644
71172 --- a/include/net/llc_c_ev.h
71173 +++ b/include/net/llc_c_ev.h
71174 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
71175 return (struct llc_conn_state_ev *)skb->cb;
71176 }
71177
71178 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71179 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71180 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71181 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71182
71183 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
71184 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
71185 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
71186 index 0e79cfb..f46db31 100644
71187 --- a/include/net/llc_c_st.h
71188 +++ b/include/net/llc_c_st.h
71189 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
71190 u8 next_state;
71191 llc_conn_ev_qfyr_t *ev_qualifiers;
71192 llc_conn_action_t *ev_actions;
71193 -};
71194 +} __do_const;
71195
71196 struct llc_conn_state {
71197 u8 current_state;
71198 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
71199 index 37a3bbd..55a4241 100644
71200 --- a/include/net/llc_s_ac.h
71201 +++ b/include/net/llc_s_ac.h
71202 @@ -23,7 +23,7 @@
71203 #define SAP_ACT_TEST_IND 9
71204
71205 /* All action functions must look like this */
71206 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71207 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71208
71209 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
71210 struct sk_buff *skb);
71211 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
71212 index 567c681..cd73ac0 100644
71213 --- a/include/net/llc_s_st.h
71214 +++ b/include/net/llc_s_st.h
71215 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
71216 llc_sap_ev_t ev;
71217 u8 next_state;
71218 llc_sap_action_t *ev_actions;
71219 -};
71220 +} __do_const;
71221
71222 struct llc_sap_state {
71223 u8 curr_state;
71224 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
71225 index ee50c5e..1bc3b1a 100644
71226 --- a/include/net/mac80211.h
71227 +++ b/include/net/mac80211.h
71228 @@ -3996,7 +3996,7 @@ struct rate_control_ops {
71229 void (*add_sta_debugfs)(void *priv, void *priv_sta,
71230 struct dentry *dir);
71231 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
71232 -};
71233 +} __do_const;
71234
71235 static inline int rate_supported(struct ieee80211_sta *sta,
71236 enum ieee80211_band band,
71237 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
71238 index 0dab173..1b76af0 100644
71239 --- a/include/net/neighbour.h
71240 +++ b/include/net/neighbour.h
71241 @@ -123,7 +123,7 @@ struct neigh_ops {
71242 void (*error_report)(struct neighbour *, struct sk_buff *);
71243 int (*output)(struct neighbour *, struct sk_buff *);
71244 int (*connected_output)(struct neighbour *, struct sk_buff *);
71245 -};
71246 +} __do_const;
71247
71248 struct pneigh_entry {
71249 struct pneigh_entry *next;
71250 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
71251 index de644bc..351fd4e 100644
71252 --- a/include/net/net_namespace.h
71253 +++ b/include/net/net_namespace.h
71254 @@ -115,7 +115,7 @@ struct net {
71255 #endif
71256 struct netns_ipvs *ipvs;
71257 struct sock *diag_nlsk;
71258 - atomic_t rt_genid;
71259 + atomic_unchecked_t rt_genid;
71260 };
71261
71262 /*
71263 @@ -282,7 +282,7 @@ struct pernet_operations {
71264 void (*exit_batch)(struct list_head *net_exit_list);
71265 int *id;
71266 size_t size;
71267 -};
71268 +} __do_const;
71269
71270 /*
71271 * Use these carefully. If you implement a network device and it
71272 @@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
71273
71274 static inline int rt_genid(struct net *net)
71275 {
71276 - return atomic_read(&net->rt_genid);
71277 + return atomic_read_unchecked(&net->rt_genid);
71278 }
71279
71280 static inline void rt_genid_bump(struct net *net)
71281 {
71282 - atomic_inc(&net->rt_genid);
71283 + atomic_inc_unchecked(&net->rt_genid);
71284 }
71285
71286 #endif /* __NET_NET_NAMESPACE_H */
71287 diff --git a/include/net/netdma.h b/include/net/netdma.h
71288 index 8ba8ce2..99b7fff 100644
71289 --- a/include/net/netdma.h
71290 +++ b/include/net/netdma.h
71291 @@ -24,7 +24,7 @@
71292 #include <linux/dmaengine.h>
71293 #include <linux/skbuff.h>
71294
71295 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71296 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71297 struct sk_buff *skb, int offset, struct iovec *to,
71298 size_t len, struct dma_pinned_list *pinned_list);
71299
71300 diff --git a/include/net/netlink.h b/include/net/netlink.h
71301 index 9690b0f..87aded7 100644
71302 --- a/include/net/netlink.h
71303 +++ b/include/net/netlink.h
71304 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
71305 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
71306 {
71307 if (mark)
71308 - skb_trim(skb, (unsigned char *) mark - skb->data);
71309 + skb_trim(skb, (const unsigned char *) mark - skb->data);
71310 }
71311
71312 /**
71313 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
71314 index 923cb20..deae816 100644
71315 --- a/include/net/netns/conntrack.h
71316 +++ b/include/net/netns/conntrack.h
71317 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
71318 struct nf_proto_net {
71319 #ifdef CONFIG_SYSCTL
71320 struct ctl_table_header *ctl_table_header;
71321 - struct ctl_table *ctl_table;
71322 + ctl_table_no_const *ctl_table;
71323 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
71324 struct ctl_table_header *ctl_compat_header;
71325 - struct ctl_table *ctl_compat_table;
71326 + ctl_table_no_const *ctl_compat_table;
71327 #endif
71328 #endif
71329 unsigned int users;
71330 @@ -58,7 +58,7 @@ struct nf_ip_net {
71331 struct nf_icmp_net icmpv6;
71332 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
71333 struct ctl_table_header *ctl_table_header;
71334 - struct ctl_table *ctl_table;
71335 + ctl_table_no_const *ctl_table;
71336 #endif
71337 };
71338
71339 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
71340 index 2ae2b83..dbdc85e 100644
71341 --- a/include/net/netns/ipv4.h
71342 +++ b/include/net/netns/ipv4.h
71343 @@ -64,7 +64,7 @@ struct netns_ipv4 {
71344 kgid_t sysctl_ping_group_range[2];
71345 long sysctl_tcp_mem[3];
71346
71347 - atomic_t dev_addr_genid;
71348 + atomic_unchecked_t dev_addr_genid;
71349
71350 #ifdef CONFIG_IP_MROUTE
71351 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
71352 diff --git a/include/net/protocol.h b/include/net/protocol.h
71353 index 047c047..b9dad15 100644
71354 --- a/include/net/protocol.h
71355 +++ b/include/net/protocol.h
71356 @@ -44,7 +44,7 @@ struct net_protocol {
71357 void (*err_handler)(struct sk_buff *skb, u32 info);
71358 unsigned int no_policy:1,
71359 netns_ok:1;
71360 -};
71361 +} __do_const;
71362
71363 #if IS_ENABLED(CONFIG_IPV6)
71364 struct inet6_protocol {
71365 @@ -57,7 +57,7 @@ struct inet6_protocol {
71366 u8 type, u8 code, int offset,
71367 __be32 info);
71368 unsigned int flags; /* INET6_PROTO_xxx */
71369 -};
71370 +} __do_const;
71371
71372 #define INET6_PROTO_NOPOLICY 0x1
71373 #define INET6_PROTO_FINAL 0x2
71374 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
71375 index 5a15fab..d799ea7 100644
71376 --- a/include/net/rtnetlink.h
71377 +++ b/include/net/rtnetlink.h
71378 @@ -81,7 +81,7 @@ struct rtnl_link_ops {
71379 const struct net_device *dev);
71380 unsigned int (*get_num_tx_queues)(void);
71381 unsigned int (*get_num_rx_queues)(void);
71382 -};
71383 +} __do_const;
71384
71385 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
71386 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
71387 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
71388 index 7fdf298..197e9f7 100644
71389 --- a/include/net/sctp/sctp.h
71390 +++ b/include/net/sctp/sctp.h
71391 @@ -330,9 +330,9 @@ do { \
71392
71393 #else /* SCTP_DEBUG */
71394
71395 -#define SCTP_DEBUG_PRINTK(whatever...)
71396 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
71397 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
71398 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
71399 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
71400 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
71401 #define SCTP_ENABLE_DEBUG
71402 #define SCTP_DISABLE_DEBUG
71403 #define SCTP_ASSERT(expr, str, func)
71404 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
71405 index 2a82d13..62a31c2 100644
71406 --- a/include/net/sctp/sm.h
71407 +++ b/include/net/sctp/sm.h
71408 @@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
71409 typedef struct {
71410 sctp_state_fn_t *fn;
71411 const char *name;
71412 -} sctp_sm_table_entry_t;
71413 +} __do_const sctp_sm_table_entry_t;
71414
71415 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
71416 * currently in use.
71417 @@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
71418 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
71419
71420 /* Extern declarations for major data structures. */
71421 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
71422 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
71423
71424
71425 /* Get the size of a DATA chunk payload. */
71426 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
71427 index fdeb85a..1329d95 100644
71428 --- a/include/net/sctp/structs.h
71429 +++ b/include/net/sctp/structs.h
71430 @@ -517,7 +517,7 @@ struct sctp_pf {
71431 struct sctp_association *asoc);
71432 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
71433 struct sctp_af *af;
71434 -};
71435 +} __do_const;
71436
71437
71438 /* Structure to track chunk fragments that have been acked, but peer
71439 diff --git a/include/net/sock.h b/include/net/sock.h
71440 index 25afaa0..8bb0070 100644
71441 --- a/include/net/sock.h
71442 +++ b/include/net/sock.h
71443 @@ -322,7 +322,7 @@ struct sock {
71444 #ifdef CONFIG_RPS
71445 __u32 sk_rxhash;
71446 #endif
71447 - atomic_t sk_drops;
71448 + atomic_unchecked_t sk_drops;
71449 int sk_rcvbuf;
71450
71451 struct sk_filter __rcu *sk_filter;
71452 @@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
71453 }
71454
71455 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
71456 - char __user *from, char *to,
71457 + char __user *from, unsigned char *to,
71458 int copy, int offset)
71459 {
71460 if (skb->ip_summed == CHECKSUM_NONE) {
71461 @@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
71462 }
71463 }
71464
71465 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
71466 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
71467
71468 /**
71469 * sk_page_frag - return an appropriate page_frag
71470 diff --git a/include/net/tcp.h b/include/net/tcp.h
71471 index aed42c7..43890c6 100644
71472 --- a/include/net/tcp.h
71473 +++ b/include/net/tcp.h
71474 @@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
71475 extern void tcp_xmit_retransmit_queue(struct sock *);
71476 extern void tcp_simple_retransmit(struct sock *);
71477 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
71478 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
71479 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
71480
71481 extern void tcp_send_probe0(struct sock *);
71482 extern void tcp_send_partial(struct sock *);
71483 @@ -701,8 +701,8 @@ struct tcp_skb_cb {
71484 struct inet6_skb_parm h6;
71485 #endif
71486 } header; /* For incoming frames */
71487 - __u32 seq; /* Starting sequence number */
71488 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
71489 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
71490 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
71491 __u32 when; /* used to compute rtt's */
71492 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
71493
71494 @@ -716,7 +716,7 @@ struct tcp_skb_cb {
71495
71496 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
71497 /* 1 byte hole */
71498 - __u32 ack_seq; /* Sequence number ACK'd */
71499 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
71500 };
71501
71502 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
71503 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
71504 index 63445ed..d6fc34f 100644
71505 --- a/include/net/xfrm.h
71506 +++ b/include/net/xfrm.h
71507 @@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
71508 struct net_device *dev,
71509 const struct flowi *fl);
71510 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
71511 -};
71512 +} __do_const;
71513
71514 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
71515 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
71516 @@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
71517 struct sk_buff *skb);
71518 int (*transport_finish)(struct sk_buff *skb,
71519 int async);
71520 -};
71521 +} __do_const;
71522
71523 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
71524 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
71525 @@ -423,7 +423,7 @@ struct xfrm_mode {
71526 struct module *owner;
71527 unsigned int encap;
71528 int flags;
71529 -};
71530 +} __do_const;
71531
71532 /* Flags for xfrm_mode. */
71533 enum {
71534 @@ -514,7 +514,7 @@ struct xfrm_policy {
71535 struct timer_list timer;
71536
71537 struct flow_cache_object flo;
71538 - atomic_t genid;
71539 + atomic_unchecked_t genid;
71540 u32 priority;
71541 u32 index;
71542 struct xfrm_mark mark;
71543 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
71544 index 1a046b1..ee0bef0 100644
71545 --- a/include/rdma/iw_cm.h
71546 +++ b/include/rdma/iw_cm.h
71547 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
71548 int backlog);
71549
71550 int (*destroy_listen)(struct iw_cm_id *cm_id);
71551 -};
71552 +} __no_const;
71553
71554 /**
71555 * iw_create_cm_id - Create an IW CM identifier.
71556 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
71557 index 399162b..b337f1a 100644
71558 --- a/include/scsi/libfc.h
71559 +++ b/include/scsi/libfc.h
71560 @@ -762,6 +762,7 @@ struct libfc_function_template {
71561 */
71562 void (*disc_stop_final) (struct fc_lport *);
71563 };
71564 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
71565
71566 /**
71567 * struct fc_disc - Discovery context
71568 @@ -866,7 +867,7 @@ struct fc_lport {
71569 struct fc_vport *vport;
71570
71571 /* Operational Information */
71572 - struct libfc_function_template tt;
71573 + libfc_function_template_no_const tt;
71574 u8 link_up;
71575 u8 qfull;
71576 enum fc_lport_state state;
71577 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
71578 index e65c62e..aa2e5a2 100644
71579 --- a/include/scsi/scsi_device.h
71580 +++ b/include/scsi/scsi_device.h
71581 @@ -170,9 +170,9 @@ struct scsi_device {
71582 unsigned int max_device_blocked; /* what device_blocked counts down from */
71583 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
71584
71585 - atomic_t iorequest_cnt;
71586 - atomic_t iodone_cnt;
71587 - atomic_t ioerr_cnt;
71588 + atomic_unchecked_t iorequest_cnt;
71589 + atomic_unchecked_t iodone_cnt;
71590 + atomic_unchecked_t ioerr_cnt;
71591
71592 struct device sdev_gendev,
71593 sdev_dev;
71594 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
71595 index b797e8f..8e2c3aa 100644
71596 --- a/include/scsi/scsi_transport_fc.h
71597 +++ b/include/scsi/scsi_transport_fc.h
71598 @@ -751,7 +751,8 @@ struct fc_function_template {
71599 unsigned long show_host_system_hostname:1;
71600
71601 unsigned long disable_target_scan:1;
71602 -};
71603 +} __do_const;
71604 +typedef struct fc_function_template __no_const fc_function_template_no_const;
71605
71606
71607 /**
71608 diff --git a/include/sound/soc.h b/include/sound/soc.h
71609 index bc56738..a4be132 100644
71610 --- a/include/sound/soc.h
71611 +++ b/include/sound/soc.h
71612 @@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
71613 /* probe ordering - for components with runtime dependencies */
71614 int probe_order;
71615 int remove_order;
71616 -};
71617 +} __do_const;
71618
71619 /* SoC platform interface */
71620 struct snd_soc_platform_driver {
71621 @@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
71622 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
71623 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
71624 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
71625 -};
71626 +} __do_const;
71627
71628 struct snd_soc_platform {
71629 const char *name;
71630 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
71631 index 663e34a..91b306a 100644
71632 --- a/include/target/target_core_base.h
71633 +++ b/include/target/target_core_base.h
71634 @@ -654,7 +654,7 @@ struct se_device {
71635 spinlock_t stats_lock;
71636 /* Active commands on this virtual SE device */
71637 atomic_t simple_cmds;
71638 - atomic_t dev_ordered_id;
71639 + atomic_unchecked_t dev_ordered_id;
71640 atomic_t dev_ordered_sync;
71641 atomic_t dev_qf_count;
71642 int export_count;
71643 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
71644 new file mode 100644
71645 index 0000000..fb634b7
71646 --- /dev/null
71647 +++ b/include/trace/events/fs.h
71648 @@ -0,0 +1,53 @@
71649 +#undef TRACE_SYSTEM
71650 +#define TRACE_SYSTEM fs
71651 +
71652 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
71653 +#define _TRACE_FS_H
71654 +
71655 +#include <linux/fs.h>
71656 +#include <linux/tracepoint.h>
71657 +
71658 +TRACE_EVENT(do_sys_open,
71659 +
71660 + TP_PROTO(const char *filename, int flags, int mode),
71661 +
71662 + TP_ARGS(filename, flags, mode),
71663 +
71664 + TP_STRUCT__entry(
71665 + __string( filename, filename )
71666 + __field( int, flags )
71667 + __field( int, mode )
71668 + ),
71669 +
71670 + TP_fast_assign(
71671 + __assign_str(filename, filename);
71672 + __entry->flags = flags;
71673 + __entry->mode = mode;
71674 + ),
71675 +
71676 + TP_printk("\"%s\" %x %o",
71677 + __get_str(filename), __entry->flags, __entry->mode)
71678 +);
71679 +
71680 +TRACE_EVENT(open_exec,
71681 +
71682 + TP_PROTO(const char *filename),
71683 +
71684 + TP_ARGS(filename),
71685 +
71686 + TP_STRUCT__entry(
71687 + __string( filename, filename )
71688 + ),
71689 +
71690 + TP_fast_assign(
71691 + __assign_str(filename, filename);
71692 + ),
71693 +
71694 + TP_printk("\"%s\"",
71695 + __get_str(filename))
71696 +);
71697 +
71698 +#endif /* _TRACE_FS_H */
71699 +
71700 +/* This part must be outside protection */
71701 +#include <trace/define_trace.h>
71702 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
71703 index 1c09820..7f5ec79 100644
71704 --- a/include/trace/events/irq.h
71705 +++ b/include/trace/events/irq.h
71706 @@ -36,7 +36,7 @@ struct softirq_action;
71707 */
71708 TRACE_EVENT(irq_handler_entry,
71709
71710 - TP_PROTO(int irq, struct irqaction *action),
71711 + TP_PROTO(int irq, const struct irqaction *action),
71712
71713 TP_ARGS(irq, action),
71714
71715 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
71716 */
71717 TRACE_EVENT(irq_handler_exit,
71718
71719 - TP_PROTO(int irq, struct irqaction *action, int ret),
71720 + TP_PROTO(int irq, const struct irqaction *action, int ret),
71721
71722 TP_ARGS(irq, action, ret),
71723
71724 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
71725 index 7caf44c..23c6f27 100644
71726 --- a/include/uapi/linux/a.out.h
71727 +++ b/include/uapi/linux/a.out.h
71728 @@ -39,6 +39,14 @@ enum machine_type {
71729 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
71730 };
71731
71732 +/* Constants for the N_FLAGS field */
71733 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
71734 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
71735 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
71736 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
71737 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
71738 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
71739 +
71740 #if !defined (N_MAGIC)
71741 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
71742 #endif
71743 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
71744 index d876736..b36014e 100644
71745 --- a/include/uapi/linux/byteorder/little_endian.h
71746 +++ b/include/uapi/linux/byteorder/little_endian.h
71747 @@ -42,51 +42,51 @@
71748
71749 static inline __le64 __cpu_to_le64p(const __u64 *p)
71750 {
71751 - return (__force __le64)*p;
71752 + return (__force const __le64)*p;
71753 }
71754 static inline __u64 __le64_to_cpup(const __le64 *p)
71755 {
71756 - return (__force __u64)*p;
71757 + return (__force const __u64)*p;
71758 }
71759 static inline __le32 __cpu_to_le32p(const __u32 *p)
71760 {
71761 - return (__force __le32)*p;
71762 + return (__force const __le32)*p;
71763 }
71764 static inline __u32 __le32_to_cpup(const __le32 *p)
71765 {
71766 - return (__force __u32)*p;
71767 + return (__force const __u32)*p;
71768 }
71769 static inline __le16 __cpu_to_le16p(const __u16 *p)
71770 {
71771 - return (__force __le16)*p;
71772 + return (__force const __le16)*p;
71773 }
71774 static inline __u16 __le16_to_cpup(const __le16 *p)
71775 {
71776 - return (__force __u16)*p;
71777 + return (__force const __u16)*p;
71778 }
71779 static inline __be64 __cpu_to_be64p(const __u64 *p)
71780 {
71781 - return (__force __be64)__swab64p(p);
71782 + return (__force const __be64)__swab64p(p);
71783 }
71784 static inline __u64 __be64_to_cpup(const __be64 *p)
71785 {
71786 - return __swab64p((__u64 *)p);
71787 + return __swab64p((const __u64 *)p);
71788 }
71789 static inline __be32 __cpu_to_be32p(const __u32 *p)
71790 {
71791 - return (__force __be32)__swab32p(p);
71792 + return (__force const __be32)__swab32p(p);
71793 }
71794 static inline __u32 __be32_to_cpup(const __be32 *p)
71795 {
71796 - return __swab32p((__u32 *)p);
71797 + return __swab32p((const __u32 *)p);
71798 }
71799 static inline __be16 __cpu_to_be16p(const __u16 *p)
71800 {
71801 - return (__force __be16)__swab16p(p);
71802 + return (__force const __be16)__swab16p(p);
71803 }
71804 static inline __u16 __be16_to_cpup(const __be16 *p)
71805 {
71806 - return __swab16p((__u16 *)p);
71807 + return __swab16p((const __u16 *)p);
71808 }
71809 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
71810 #define __le64_to_cpus(x) do { (void)(x); } while (0)
71811 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
71812 index 126a817..d522bd1 100644
71813 --- a/include/uapi/linux/elf.h
71814 +++ b/include/uapi/linux/elf.h
71815 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
71816 #define PT_GNU_EH_FRAME 0x6474e550
71817
71818 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
71819 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
71820 +
71821 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
71822 +
71823 +/* Constants for the e_flags field */
71824 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
71825 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
71826 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
71827 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
71828 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
71829 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
71830
71831 /*
71832 * Extended Numbering
71833 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
71834 #define DT_DEBUG 21
71835 #define DT_TEXTREL 22
71836 #define DT_JMPREL 23
71837 +#define DT_FLAGS 30
71838 + #define DF_TEXTREL 0x00000004
71839 #define DT_ENCODING 32
71840 #define OLD_DT_LOOS 0x60000000
71841 #define DT_LOOS 0x6000000d
71842 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
71843 #define PF_W 0x2
71844 #define PF_X 0x1
71845
71846 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
71847 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
71848 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
71849 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
71850 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
71851 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
71852 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
71853 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
71854 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
71855 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
71856 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
71857 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
71858 +
71859 typedef struct elf32_phdr{
71860 Elf32_Word p_type;
71861 Elf32_Off p_offset;
71862 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
71863 #define EI_OSABI 7
71864 #define EI_PAD 8
71865
71866 +#define EI_PAX 14
71867 +
71868 #define ELFMAG0 0x7f /* EI_MAG */
71869 #define ELFMAG1 'E'
71870 #define ELFMAG2 'L'
71871 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
71872 index aa169c4..6a2771d 100644
71873 --- a/include/uapi/linux/personality.h
71874 +++ b/include/uapi/linux/personality.h
71875 @@ -30,6 +30,7 @@ enum {
71876 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
71877 ADDR_NO_RANDOMIZE | \
71878 ADDR_COMPAT_LAYOUT | \
71879 + ADDR_LIMIT_3GB | \
71880 MMAP_PAGE_ZERO)
71881
71882 /*
71883 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
71884 index 7530e74..e714828 100644
71885 --- a/include/uapi/linux/screen_info.h
71886 +++ b/include/uapi/linux/screen_info.h
71887 @@ -43,7 +43,8 @@ struct screen_info {
71888 __u16 pages; /* 0x32 */
71889 __u16 vesa_attributes; /* 0x34 */
71890 __u32 capabilities; /* 0x36 */
71891 - __u8 _reserved[6]; /* 0x3a */
71892 + __u16 vesapm_size; /* 0x3a */
71893 + __u8 _reserved[4]; /* 0x3c */
71894 } __attribute__((packed));
71895
71896 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
71897 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
71898 index 6d67213..8dab561 100644
71899 --- a/include/uapi/linux/sysctl.h
71900 +++ b/include/uapi/linux/sysctl.h
71901 @@ -155,7 +155,11 @@ enum
71902 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
71903 };
71904
71905 -
71906 +#ifdef CONFIG_PAX_SOFTMODE
71907 +enum {
71908 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
71909 +};
71910 +#endif
71911
71912 /* CTL_VM names: */
71913 enum
71914 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
71915 index 26607bd..588b65f 100644
71916 --- a/include/uapi/linux/xattr.h
71917 +++ b/include/uapi/linux/xattr.h
71918 @@ -60,5 +60,9 @@
71919 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
71920 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
71921
71922 +/* User namespace */
71923 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
71924 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
71925 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
71926
71927 #endif /* _UAPI_LINUX_XATTR_H */
71928 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
71929 index f9466fa..f4e2b81 100644
71930 --- a/include/video/udlfb.h
71931 +++ b/include/video/udlfb.h
71932 @@ -53,10 +53,10 @@ struct dlfb_data {
71933 u32 pseudo_palette[256];
71934 int blank_mode; /*one of FB_BLANK_ */
71935 /* blit-only rendering path metrics, exposed through sysfs */
71936 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
71937 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
71938 - atomic_t bytes_sent; /* to usb, after compression including overhead */
71939 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
71940 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
71941 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
71942 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
71943 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
71944 };
71945
71946 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
71947 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
71948 index 0993a22..32ba2fe 100644
71949 --- a/include/video/uvesafb.h
71950 +++ b/include/video/uvesafb.h
71951 @@ -177,6 +177,7 @@ struct uvesafb_par {
71952 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
71953 u8 pmi_setpal; /* PMI for palette changes */
71954 u16 *pmi_base; /* protected mode interface location */
71955 + u8 *pmi_code; /* protected mode code location */
71956 void *pmi_start;
71957 void *pmi_pal;
71958 u8 *vbe_state_orig; /*
71959 diff --git a/init/Kconfig b/init/Kconfig
71960 index be8b7f5..1eeca9b 100644
71961 --- a/init/Kconfig
71962 +++ b/init/Kconfig
71963 @@ -990,6 +990,7 @@ endif # CGROUPS
71964
71965 config CHECKPOINT_RESTORE
71966 bool "Checkpoint/restore support" if EXPERT
71967 + depends on !GRKERNSEC
71968 default n
71969 help
71970 Enables additional kernel features in a sake of checkpoint/restore.
71971 @@ -1468,7 +1469,7 @@ config SLUB_DEBUG
71972
71973 config COMPAT_BRK
71974 bool "Disable heap randomization"
71975 - default y
71976 + default n
71977 help
71978 Randomizing heap placement makes heap exploits harder, but it
71979 also breaks ancient binaries (including anything libc5 based).
71980 @@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
71981 config STOP_MACHINE
71982 bool
71983 default y
71984 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
71985 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
71986 help
71987 Need stop_machine() primitive.
71988
71989 diff --git a/init/Makefile b/init/Makefile
71990 index 7bc47ee..6da2dc7 100644
71991 --- a/init/Makefile
71992 +++ b/init/Makefile
71993 @@ -2,6 +2,9 @@
71994 # Makefile for the linux kernel.
71995 #
71996
71997 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
71998 +asflags-y := $(GCC_PLUGINS_AFLAGS)
71999 +
72000 obj-y := main.o version.o mounts.o
72001 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
72002 obj-y += noinitramfs.o
72003 diff --git a/init/do_mounts.c b/init/do_mounts.c
72004 index 1d1b634..a1c810f 100644
72005 --- a/init/do_mounts.c
72006 +++ b/init/do_mounts.c
72007 @@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
72008 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
72009 {
72010 struct super_block *s;
72011 - int err = sys_mount(name, "/root", fs, flags, data);
72012 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
72013 if (err)
72014 return err;
72015
72016 - sys_chdir("/root");
72017 + sys_chdir((const char __force_user *)"/root");
72018 s = current->fs->pwd.dentry->d_sb;
72019 ROOT_DEV = s->s_dev;
72020 printk(KERN_INFO
72021 @@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
72022 va_start(args, fmt);
72023 vsprintf(buf, fmt, args);
72024 va_end(args);
72025 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
72026 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
72027 if (fd >= 0) {
72028 sys_ioctl(fd, FDEJECT, 0);
72029 sys_close(fd);
72030 }
72031 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
72032 - fd = sys_open("/dev/console", O_RDWR, 0);
72033 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
72034 if (fd >= 0) {
72035 sys_ioctl(fd, TCGETS, (long)&termios);
72036 termios.c_lflag &= ~ICANON;
72037 sys_ioctl(fd, TCSETSF, (long)&termios);
72038 - sys_read(fd, &c, 1);
72039 + sys_read(fd, (char __user *)&c, 1);
72040 termios.c_lflag |= ICANON;
72041 sys_ioctl(fd, TCSETSF, (long)&termios);
72042 sys_close(fd);
72043 @@ -585,6 +585,6 @@ void __init prepare_namespace(void)
72044 mount_root();
72045 out:
72046 devtmpfs_mount("dev");
72047 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
72048 - sys_chroot(".");
72049 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
72050 + sys_chroot((const char __force_user *)".");
72051 }
72052 diff --git a/init/do_mounts.h b/init/do_mounts.h
72053 index f5b978a..69dbfe8 100644
72054 --- a/init/do_mounts.h
72055 +++ b/init/do_mounts.h
72056 @@ -15,15 +15,15 @@ extern int root_mountflags;
72057
72058 static inline int create_dev(char *name, dev_t dev)
72059 {
72060 - sys_unlink(name);
72061 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
72062 + sys_unlink((char __force_user *)name);
72063 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
72064 }
72065
72066 #if BITS_PER_LONG == 32
72067 static inline u32 bstat(char *name)
72068 {
72069 struct stat64 stat;
72070 - if (sys_stat64(name, &stat) != 0)
72071 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
72072 return 0;
72073 if (!S_ISBLK(stat.st_mode))
72074 return 0;
72075 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
72076 static inline u32 bstat(char *name)
72077 {
72078 struct stat stat;
72079 - if (sys_newstat(name, &stat) != 0)
72080 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
72081 return 0;
72082 if (!S_ISBLK(stat.st_mode))
72083 return 0;
72084 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
72085 index f9acf71..1e19144 100644
72086 --- a/init/do_mounts_initrd.c
72087 +++ b/init/do_mounts_initrd.c
72088 @@ -58,8 +58,8 @@ static void __init handle_initrd(void)
72089 create_dev("/dev/root.old", Root_RAM0);
72090 /* mount initrd on rootfs' /root */
72091 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
72092 - sys_mkdir("/old", 0700);
72093 - sys_chdir("/old");
72094 + sys_mkdir((const char __force_user *)"/old", 0700);
72095 + sys_chdir((const char __force_user *)"/old");
72096
72097 /*
72098 * In case that a resume from disk is carried out by linuxrc or one of
72099 @@ -73,31 +73,31 @@ static void __init handle_initrd(void)
72100 current->flags &= ~PF_FREEZER_SKIP;
72101
72102 /* move initrd to rootfs' /old */
72103 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
72104 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
72105 /* switch root and cwd back to / of rootfs */
72106 - sys_chroot("..");
72107 + sys_chroot((const char __force_user *)"..");
72108
72109 if (new_decode_dev(real_root_dev) == Root_RAM0) {
72110 - sys_chdir("/old");
72111 + sys_chdir((const char __force_user *)"/old");
72112 return;
72113 }
72114
72115 - sys_chdir("/");
72116 + sys_chdir((const char __force_user *)"/");
72117 ROOT_DEV = new_decode_dev(real_root_dev);
72118 mount_root();
72119
72120 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
72121 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
72122 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
72123 if (!error)
72124 printk("okay\n");
72125 else {
72126 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
72127 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
72128 if (error == -ENOENT)
72129 printk("/initrd does not exist. Ignored.\n");
72130 else
72131 printk("failed\n");
72132 printk(KERN_NOTICE "Unmounting old root\n");
72133 - sys_umount("/old", MNT_DETACH);
72134 + sys_umount((char __force_user *)"/old", MNT_DETACH);
72135 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
72136 if (fd < 0) {
72137 error = fd;
72138 @@ -120,11 +120,11 @@ int __init initrd_load(void)
72139 * mounted in the normal path.
72140 */
72141 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
72142 - sys_unlink("/initrd.image");
72143 + sys_unlink((const char __force_user *)"/initrd.image");
72144 handle_initrd();
72145 return 1;
72146 }
72147 }
72148 - sys_unlink("/initrd.image");
72149 + sys_unlink((const char __force_user *)"/initrd.image");
72150 return 0;
72151 }
72152 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
72153 index 8cb6db5..d729f50 100644
72154 --- a/init/do_mounts_md.c
72155 +++ b/init/do_mounts_md.c
72156 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
72157 partitioned ? "_d" : "", minor,
72158 md_setup_args[ent].device_names);
72159
72160 - fd = sys_open(name, 0, 0);
72161 + fd = sys_open((char __force_user *)name, 0, 0);
72162 if (fd < 0) {
72163 printk(KERN_ERR "md: open failed - cannot start "
72164 "array %s\n", name);
72165 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
72166 * array without it
72167 */
72168 sys_close(fd);
72169 - fd = sys_open(name, 0, 0);
72170 + fd = sys_open((char __force_user *)name, 0, 0);
72171 sys_ioctl(fd, BLKRRPART, 0);
72172 }
72173 sys_close(fd);
72174 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
72175
72176 wait_for_device_probe();
72177
72178 - fd = sys_open("/dev/md0", 0, 0);
72179 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
72180 if (fd >= 0) {
72181 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
72182 sys_close(fd);
72183 diff --git a/init/init_task.c b/init/init_task.c
72184 index 8b2f399..f0797c9 100644
72185 --- a/init/init_task.c
72186 +++ b/init/init_task.c
72187 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
72188 * Initial thread structure. Alignment of this is handled by a special
72189 * linker map entry.
72190 */
72191 +#ifdef CONFIG_X86
72192 +union thread_union init_thread_union __init_task_data;
72193 +#else
72194 union thread_union init_thread_union __init_task_data =
72195 { INIT_THREAD_INFO(init_task) };
72196 +#endif
72197 diff --git a/init/initramfs.c b/init/initramfs.c
72198 index 84c6bf1..8899338 100644
72199 --- a/init/initramfs.c
72200 +++ b/init/initramfs.c
72201 @@ -84,7 +84,7 @@ static void __init free_hash(void)
72202 }
72203 }
72204
72205 -static long __init do_utime(char *filename, time_t mtime)
72206 +static long __init do_utime(char __force_user *filename, time_t mtime)
72207 {
72208 struct timespec t[2];
72209
72210 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
72211 struct dir_entry *de, *tmp;
72212 list_for_each_entry_safe(de, tmp, &dir_list, list) {
72213 list_del(&de->list);
72214 - do_utime(de->name, de->mtime);
72215 + do_utime((char __force_user *)de->name, de->mtime);
72216 kfree(de->name);
72217 kfree(de);
72218 }
72219 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
72220 if (nlink >= 2) {
72221 char *old = find_link(major, minor, ino, mode, collected);
72222 if (old)
72223 - return (sys_link(old, collected) < 0) ? -1 : 1;
72224 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
72225 }
72226 return 0;
72227 }
72228 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
72229 {
72230 struct stat st;
72231
72232 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
72233 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
72234 if (S_ISDIR(st.st_mode))
72235 - sys_rmdir(path);
72236 + sys_rmdir((char __force_user *)path);
72237 else
72238 - sys_unlink(path);
72239 + sys_unlink((char __force_user *)path);
72240 }
72241 }
72242
72243 @@ -315,7 +315,7 @@ static int __init do_name(void)
72244 int openflags = O_WRONLY|O_CREAT;
72245 if (ml != 1)
72246 openflags |= O_TRUNC;
72247 - wfd = sys_open(collected, openflags, mode);
72248 + wfd = sys_open((char __force_user *)collected, openflags, mode);
72249
72250 if (wfd >= 0) {
72251 sys_fchown(wfd, uid, gid);
72252 @@ -327,17 +327,17 @@ static int __init do_name(void)
72253 }
72254 }
72255 } else if (S_ISDIR(mode)) {
72256 - sys_mkdir(collected, mode);
72257 - sys_chown(collected, uid, gid);
72258 - sys_chmod(collected, mode);
72259 + sys_mkdir((char __force_user *)collected, mode);
72260 + sys_chown((char __force_user *)collected, uid, gid);
72261 + sys_chmod((char __force_user *)collected, mode);
72262 dir_add(collected, mtime);
72263 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
72264 S_ISFIFO(mode) || S_ISSOCK(mode)) {
72265 if (maybe_link() == 0) {
72266 - sys_mknod(collected, mode, rdev);
72267 - sys_chown(collected, uid, gid);
72268 - sys_chmod(collected, mode);
72269 - do_utime(collected, mtime);
72270 + sys_mknod((char __force_user *)collected, mode, rdev);
72271 + sys_chown((char __force_user *)collected, uid, gid);
72272 + sys_chmod((char __force_user *)collected, mode);
72273 + do_utime((char __force_user *)collected, mtime);
72274 }
72275 }
72276 return 0;
72277 @@ -346,15 +346,15 @@ static int __init do_name(void)
72278 static int __init do_copy(void)
72279 {
72280 if (count >= body_len) {
72281 - sys_write(wfd, victim, body_len);
72282 + sys_write(wfd, (char __force_user *)victim, body_len);
72283 sys_close(wfd);
72284 - do_utime(vcollected, mtime);
72285 + do_utime((char __force_user *)vcollected, mtime);
72286 kfree(vcollected);
72287 eat(body_len);
72288 state = SkipIt;
72289 return 0;
72290 } else {
72291 - sys_write(wfd, victim, count);
72292 + sys_write(wfd, (char __force_user *)victim, count);
72293 body_len -= count;
72294 eat(count);
72295 return 1;
72296 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
72297 {
72298 collected[N_ALIGN(name_len) + body_len] = '\0';
72299 clean_path(collected, 0);
72300 - sys_symlink(collected + N_ALIGN(name_len), collected);
72301 - sys_lchown(collected, uid, gid);
72302 - do_utime(collected, mtime);
72303 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
72304 + sys_lchown((char __force_user *)collected, uid, gid);
72305 + do_utime((char __force_user *)collected, mtime);
72306 state = SkipIt;
72307 next_state = Reset;
72308 return 0;
72309 diff --git a/init/main.c b/init/main.c
72310 index cee4b5c..214fc6e 100644
72311 --- a/init/main.c
72312 +++ b/init/main.c
72313 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
72314 extern void tc_init(void);
72315 #endif
72316
72317 +extern void grsecurity_init(void);
72318 +
72319 /*
72320 * Debug helper: via this flag we know that we are in 'early bootup code'
72321 * where only the boot processor is running with IRQ disabled. This means
72322 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
72323
72324 __setup("reset_devices", set_reset_devices);
72325
72326 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
72327 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
72328 +static int __init setup_grsec_proc_gid(char *str)
72329 +{
72330 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
72331 + return 1;
72332 +}
72333 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
72334 +#endif
72335 +
72336 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
72337 +extern char pax_enter_kernel_user[];
72338 +extern char pax_exit_kernel_user[];
72339 +extern pgdval_t clone_pgd_mask;
72340 +#endif
72341 +
72342 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
72343 +static int __init setup_pax_nouderef(char *str)
72344 +{
72345 +#ifdef CONFIG_X86_32
72346 + unsigned int cpu;
72347 + struct desc_struct *gdt;
72348 +
72349 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
72350 + gdt = get_cpu_gdt_table(cpu);
72351 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
72352 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
72353 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
72354 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
72355 + }
72356 + loadsegment(ds, __KERNEL_DS);
72357 + loadsegment(es, __KERNEL_DS);
72358 + loadsegment(ss, __KERNEL_DS);
72359 +#else
72360 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
72361 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
72362 + clone_pgd_mask = ~(pgdval_t)0UL;
72363 +#endif
72364 +
72365 + return 0;
72366 +}
72367 +early_param("pax_nouderef", setup_pax_nouderef);
72368 +#endif
72369 +
72370 +#ifdef CONFIG_PAX_SOFTMODE
72371 +int pax_softmode;
72372 +
72373 +static int __init setup_pax_softmode(char *str)
72374 +{
72375 + get_option(&str, &pax_softmode);
72376 + return 1;
72377 +}
72378 +__setup("pax_softmode=", setup_pax_softmode);
72379 +#endif
72380 +
72381 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
72382 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
72383 static const char *panic_later, *panic_param;
72384 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
72385 {
72386 int count = preempt_count();
72387 int ret;
72388 + const char *msg1 = "", *msg2 = "";
72389
72390 if (initcall_debug)
72391 ret = do_one_initcall_debug(fn);
72392 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
72393 sprintf(msgbuf, "error code %d ", ret);
72394
72395 if (preempt_count() != count) {
72396 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
72397 + msg1 = " preemption imbalance";
72398 preempt_count() = count;
72399 }
72400 if (irqs_disabled()) {
72401 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
72402 + msg2 = " disabled interrupts";
72403 local_irq_enable();
72404 }
72405 - if (msgbuf[0]) {
72406 - printk("initcall %pF returned with %s\n", fn, msgbuf);
72407 + if (msgbuf[0] || *msg1 || *msg2) {
72408 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
72409 }
72410
72411 return ret;
72412 @@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
72413 level, level,
72414 &repair_env_string);
72415
72416 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
72417 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
72418 do_one_initcall(*fn);
72419 +
72420 +#ifdef CONFIG_PAX_LATENT_ENTROPY
72421 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
72422 +#endif
72423 +
72424 + }
72425 }
72426
72427 static void __init do_initcalls(void)
72428 @@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
72429 {
72430 initcall_t *fn;
72431
72432 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
72433 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
72434 do_one_initcall(*fn);
72435 +
72436 +#ifdef CONFIG_PAX_LATENT_ENTROPY
72437 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
72438 +#endif
72439 +
72440 + }
72441 }
72442
72443 static int run_init_process(const char *init_filename)
72444 @@ -877,7 +947,7 @@ static noinline void __init kernel_init_freeable(void)
72445 do_basic_setup();
72446
72447 /* Open the /dev/console on the rootfs, this should never fail */
72448 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
72449 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
72450 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
72451
72452 (void) sys_dup(0);
72453 @@ -890,11 +960,13 @@ static noinline void __init kernel_init_freeable(void)
72454 if (!ramdisk_execute_command)
72455 ramdisk_execute_command = "/init";
72456
72457 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
72458 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
72459 ramdisk_execute_command = NULL;
72460 prepare_namespace();
72461 }
72462
72463 + grsecurity_init();
72464 +
72465 /*
72466 * Ok, we have completed the initial bootup, and
72467 * we're essentially up and running. Get rid of the
72468 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
72469 index 130dfec..cc88451 100644
72470 --- a/ipc/ipc_sysctl.c
72471 +++ b/ipc/ipc_sysctl.c
72472 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
72473 static int proc_ipc_dointvec(ctl_table *table, int write,
72474 void __user *buffer, size_t *lenp, loff_t *ppos)
72475 {
72476 - struct ctl_table ipc_table;
72477 + ctl_table_no_const ipc_table;
72478
72479 memcpy(&ipc_table, table, sizeof(ipc_table));
72480 ipc_table.data = get_ipc(table);
72481 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
72482 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
72483 void __user *buffer, size_t *lenp, loff_t *ppos)
72484 {
72485 - struct ctl_table ipc_table;
72486 + ctl_table_no_const ipc_table;
72487
72488 memcpy(&ipc_table, table, sizeof(ipc_table));
72489 ipc_table.data = get_ipc(table);
72490 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
72491 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
72492 void __user *buffer, size_t *lenp, loff_t *ppos)
72493 {
72494 - struct ctl_table ipc_table;
72495 + ctl_table_no_const ipc_table;
72496 size_t lenp_bef = *lenp;
72497 int rc;
72498
72499 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
72500 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
72501 void __user *buffer, size_t *lenp, loff_t *ppos)
72502 {
72503 - struct ctl_table ipc_table;
72504 + ctl_table_no_const ipc_table;
72505 memcpy(&ipc_table, table, sizeof(ipc_table));
72506 ipc_table.data = get_ipc(table);
72507
72508 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
72509 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
72510 void __user *buffer, size_t *lenp, loff_t *ppos)
72511 {
72512 - struct ctl_table ipc_table;
72513 + ctl_table_no_const ipc_table;
72514 size_t lenp_bef = *lenp;
72515 int oldval;
72516 int rc;
72517 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
72518 index 383d638..943fdbb 100644
72519 --- a/ipc/mq_sysctl.c
72520 +++ b/ipc/mq_sysctl.c
72521 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
72522 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
72523 void __user *buffer, size_t *lenp, loff_t *ppos)
72524 {
72525 - struct ctl_table mq_table;
72526 + ctl_table_no_const mq_table;
72527 memcpy(&mq_table, table, sizeof(mq_table));
72528 mq_table.data = get_mq(table);
72529
72530 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
72531 index 71a3ca1..cc330ee 100644
72532 --- a/ipc/mqueue.c
72533 +++ b/ipc/mqueue.c
72534 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
72535 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
72536 info->attr.mq_msgsize);
72537
72538 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
72539 spin_lock(&mq_lock);
72540 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
72541 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
72542 diff --git a/ipc/msg.c b/ipc/msg.c
72543 index 950572f..362ea07 100644
72544 --- a/ipc/msg.c
72545 +++ b/ipc/msg.c
72546 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
72547 return security_msg_queue_associate(msq, msgflg);
72548 }
72549
72550 +static struct ipc_ops msg_ops = {
72551 + .getnew = newque,
72552 + .associate = msg_security,
72553 + .more_checks = NULL
72554 +};
72555 +
72556 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
72557 {
72558 struct ipc_namespace *ns;
72559 - struct ipc_ops msg_ops;
72560 struct ipc_params msg_params;
72561
72562 ns = current->nsproxy->ipc_ns;
72563
72564 - msg_ops.getnew = newque;
72565 - msg_ops.associate = msg_security;
72566 - msg_ops.more_checks = NULL;
72567 -
72568 msg_params.key = key;
72569 msg_params.flg = msgflg;
72570
72571 @@ -820,15 +821,17 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp,
72572 struct msg_msg *copy = NULL;
72573 unsigned long copy_number = 0;
72574
72575 + ns = current->nsproxy->ipc_ns;
72576 +
72577 if (msqid < 0 || (long) bufsz < 0)
72578 return -EINVAL;
72579 if (msgflg & MSG_COPY) {
72580 - copy = prepare_copy(buf, bufsz, msgflg, &msgtyp, &copy_number);
72581 + copy = prepare_copy(buf, min_t(size_t, bufsz, ns->msg_ctlmax),
72582 + msgflg, &msgtyp, &copy_number);
72583 if (IS_ERR(copy))
72584 return PTR_ERR(copy);
72585 }
72586 mode = convert_mode(&msgtyp, msgflg);
72587 - ns = current->nsproxy->ipc_ns;
72588
72589 msq = msg_lock_check(ns, msqid);
72590 if (IS_ERR(msq)) {
72591 diff --git a/ipc/msgutil.c b/ipc/msgutil.c
72592 index ebfcbfa..5df8e4b 100644
72593 --- a/ipc/msgutil.c
72594 +++ b/ipc/msgutil.c
72595 @@ -117,9 +117,6 @@ struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst)
72596 if (alen > DATALEN_MSG)
72597 alen = DATALEN_MSG;
72598
72599 - dst->next = NULL;
72600 - dst->security = NULL;
72601 -
72602 memcpy(dst + 1, src + 1, alen);
72603
72604 len -= alen;
72605 diff --git a/ipc/sem.c b/ipc/sem.c
72606 index 58d31f1..cce7a55 100644
72607 --- a/ipc/sem.c
72608 +++ b/ipc/sem.c
72609 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
72610 return 0;
72611 }
72612
72613 +static struct ipc_ops sem_ops = {
72614 + .getnew = newary,
72615 + .associate = sem_security,
72616 + .more_checks = sem_more_checks
72617 +};
72618 +
72619 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
72620 {
72621 struct ipc_namespace *ns;
72622 - struct ipc_ops sem_ops;
72623 struct ipc_params sem_params;
72624
72625 ns = current->nsproxy->ipc_ns;
72626 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
72627 if (nsems < 0 || nsems > ns->sc_semmsl)
72628 return -EINVAL;
72629
72630 - sem_ops.getnew = newary;
72631 - sem_ops.associate = sem_security;
72632 - sem_ops.more_checks = sem_more_checks;
72633 -
72634 sem_params.key = key;
72635 sem_params.flg = semflg;
72636 sem_params.u.nsems = nsems;
72637 diff --git a/ipc/shm.c b/ipc/shm.c
72638 index 4fa6d8f..55cff14 100644
72639 --- a/ipc/shm.c
72640 +++ b/ipc/shm.c
72641 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
72642 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
72643 #endif
72644
72645 +#ifdef CONFIG_GRKERNSEC
72646 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72647 + const time_t shm_createtime, const kuid_t cuid,
72648 + const int shmid);
72649 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72650 + const time_t shm_createtime);
72651 +#endif
72652 +
72653 void shm_init_ns(struct ipc_namespace *ns)
72654 {
72655 ns->shm_ctlmax = SHMMAX;
72656 @@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
72657 shp->shm_lprid = 0;
72658 shp->shm_atim = shp->shm_dtim = 0;
72659 shp->shm_ctim = get_seconds();
72660 +#ifdef CONFIG_GRKERNSEC
72661 + {
72662 + struct timespec timeval;
72663 + do_posix_clock_monotonic_gettime(&timeval);
72664 +
72665 + shp->shm_createtime = timeval.tv_sec;
72666 + }
72667 +#endif
72668 shp->shm_segsz = size;
72669 shp->shm_nattch = 0;
72670 shp->shm_file = file;
72671 @@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
72672 return 0;
72673 }
72674
72675 +static struct ipc_ops shm_ops = {
72676 + .getnew = newseg,
72677 + .associate = shm_security,
72678 + .more_checks = shm_more_checks
72679 +};
72680 +
72681 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
72682 {
72683 struct ipc_namespace *ns;
72684 - struct ipc_ops shm_ops;
72685 struct ipc_params shm_params;
72686
72687 ns = current->nsproxy->ipc_ns;
72688
72689 - shm_ops.getnew = newseg;
72690 - shm_ops.associate = shm_security;
72691 - shm_ops.more_checks = shm_more_checks;
72692 -
72693 shm_params.key = key;
72694 shm_params.flg = shmflg;
72695 shm_params.u.size = size;
72696 @@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
72697 f_mode = FMODE_READ | FMODE_WRITE;
72698 }
72699 if (shmflg & SHM_EXEC) {
72700 +
72701 +#ifdef CONFIG_PAX_MPROTECT
72702 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
72703 + goto out;
72704 +#endif
72705 +
72706 prot |= PROT_EXEC;
72707 acc_mode |= S_IXUGO;
72708 }
72709 @@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
72710 if (err)
72711 goto out_unlock;
72712
72713 +#ifdef CONFIG_GRKERNSEC
72714 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
72715 + shp->shm_perm.cuid, shmid) ||
72716 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
72717 + err = -EACCES;
72718 + goto out_unlock;
72719 + }
72720 +#endif
72721 +
72722 path = shp->shm_file->f_path;
72723 path_get(&path);
72724 shp->shm_nattch++;
72725 +#ifdef CONFIG_GRKERNSEC
72726 + shp->shm_lapid = current->pid;
72727 +#endif
72728 size = i_size_read(path.dentry->d_inode);
72729 shm_unlock(shp);
72730
72731 diff --git a/kernel/acct.c b/kernel/acct.c
72732 index 051e071..15e0920 100644
72733 --- a/kernel/acct.c
72734 +++ b/kernel/acct.c
72735 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
72736 */
72737 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
72738 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
72739 - file->f_op->write(file, (char *)&ac,
72740 + file->f_op->write(file, (char __force_user *)&ac,
72741 sizeof(acct_t), &file->f_pos);
72742 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
72743 set_fs(fs);
72744 diff --git a/kernel/audit.c b/kernel/audit.c
72745 index d596e53..dbef3c3 100644
72746 --- a/kernel/audit.c
72747 +++ b/kernel/audit.c
72748 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
72749 3) suppressed due to audit_rate_limit
72750 4) suppressed due to audit_backlog_limit
72751 */
72752 -static atomic_t audit_lost = ATOMIC_INIT(0);
72753 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
72754
72755 /* The netlink socket. */
72756 static struct sock *audit_sock;
72757 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
72758 unsigned long now;
72759 int print;
72760
72761 - atomic_inc(&audit_lost);
72762 + atomic_inc_unchecked(&audit_lost);
72763
72764 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
72765
72766 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
72767 printk(KERN_WARNING
72768 "audit: audit_lost=%d audit_rate_limit=%d "
72769 "audit_backlog_limit=%d\n",
72770 - atomic_read(&audit_lost),
72771 + atomic_read_unchecked(&audit_lost),
72772 audit_rate_limit,
72773 audit_backlog_limit);
72774 audit_panic(message);
72775 @@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
72776 status_set.pid = audit_pid;
72777 status_set.rate_limit = audit_rate_limit;
72778 status_set.backlog_limit = audit_backlog_limit;
72779 - status_set.lost = atomic_read(&audit_lost);
72780 + status_set.lost = atomic_read_unchecked(&audit_lost);
72781 status_set.backlog = skb_queue_len(&audit_skb_queue);
72782 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
72783 &status_set, sizeof(status_set));
72784 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
72785 index a371f85..da826c1 100644
72786 --- a/kernel/auditsc.c
72787 +++ b/kernel/auditsc.c
72788 @@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
72789 }
72790
72791 /* global counter which is incremented every time something logs in */
72792 -static atomic_t session_id = ATOMIC_INIT(0);
72793 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
72794
72795 /**
72796 * audit_set_loginuid - set current task's audit_context loginuid
72797 @@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
72798 return -EPERM;
72799 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
72800
72801 - sessionid = atomic_inc_return(&session_id);
72802 + sessionid = atomic_inc_return_unchecked(&session_id);
72803 if (context && context->in_syscall) {
72804 struct audit_buffer *ab;
72805
72806 diff --git a/kernel/capability.c b/kernel/capability.c
72807 index 493d972..f87dfbd 100644
72808 --- a/kernel/capability.c
72809 +++ b/kernel/capability.c
72810 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
72811 * before modification is attempted and the application
72812 * fails.
72813 */
72814 + if (tocopy > ARRAY_SIZE(kdata))
72815 + return -EFAULT;
72816 +
72817 if (copy_to_user(dataptr, kdata, tocopy
72818 * sizeof(struct __user_cap_data_struct))) {
72819 return -EFAULT;
72820 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
72821 int ret;
72822
72823 rcu_read_lock();
72824 - ret = security_capable(__task_cred(t), ns, cap);
72825 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
72826 + gr_task_is_capable(t, __task_cred(t), cap);
72827 rcu_read_unlock();
72828
72829 - return (ret == 0);
72830 + return ret;
72831 }
72832
72833 /**
72834 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
72835 int ret;
72836
72837 rcu_read_lock();
72838 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
72839 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
72840 rcu_read_unlock();
72841
72842 - return (ret == 0);
72843 + return ret;
72844 }
72845
72846 /**
72847 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
72848 BUG();
72849 }
72850
72851 - if (security_capable(current_cred(), ns, cap) == 0) {
72852 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
72853 current->flags |= PF_SUPERPRIV;
72854 return true;
72855 }
72856 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
72857 }
72858 EXPORT_SYMBOL(ns_capable);
72859
72860 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
72861 +{
72862 + if (unlikely(!cap_valid(cap))) {
72863 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
72864 + BUG();
72865 + }
72866 +
72867 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
72868 + current->flags |= PF_SUPERPRIV;
72869 + return true;
72870 + }
72871 + return false;
72872 +}
72873 +EXPORT_SYMBOL(ns_capable_nolog);
72874 +
72875 /**
72876 * capable - Determine if the current task has a superior capability in effect
72877 * @cap: The capability to be tested for
72878 @@ -408,6 +427,12 @@ bool capable(int cap)
72879 }
72880 EXPORT_SYMBOL(capable);
72881
72882 +bool capable_nolog(int cap)
72883 +{
72884 + return ns_capable_nolog(&init_user_ns, cap);
72885 +}
72886 +EXPORT_SYMBOL(capable_nolog);
72887 +
72888 /**
72889 * nsown_capable - Check superior capability to one's own user_ns
72890 * @cap: The capability in question
72891 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
72892
72893 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
72894 }
72895 +
72896 +bool inode_capable_nolog(const struct inode *inode, int cap)
72897 +{
72898 + struct user_namespace *ns = current_user_ns();
72899 +
72900 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
72901 +}
72902 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
72903 index 1e23664..570a83d 100644
72904 --- a/kernel/cgroup.c
72905 +++ b/kernel/cgroup.c
72906 @@ -5543,7 +5543,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
72907 struct css_set *cg = link->cg;
72908 struct task_struct *task;
72909 int count = 0;
72910 - seq_printf(seq, "css_set %p\n", cg);
72911 + seq_printf(seq, "css_set %pK\n", cg);
72912 list_for_each_entry(task, &cg->tasks, cg_list) {
72913 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
72914 seq_puts(seq, " ...\n");
72915 diff --git a/kernel/compat.c b/kernel/compat.c
72916 index 36700e9..73d770c 100644
72917 --- a/kernel/compat.c
72918 +++ b/kernel/compat.c
72919 @@ -13,6 +13,7 @@
72920
72921 #include <linux/linkage.h>
72922 #include <linux/compat.h>
72923 +#include <linux/module.h>
72924 #include <linux/errno.h>
72925 #include <linux/time.h>
72926 #include <linux/signal.h>
72927 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
72928 mm_segment_t oldfs;
72929 long ret;
72930
72931 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
72932 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
72933 oldfs = get_fs();
72934 set_fs(KERNEL_DS);
72935 ret = hrtimer_nanosleep_restart(restart);
72936 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
72937 oldfs = get_fs();
72938 set_fs(KERNEL_DS);
72939 ret = hrtimer_nanosleep(&tu,
72940 - rmtp ? (struct timespec __user *)&rmt : NULL,
72941 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
72942 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
72943 set_fs(oldfs);
72944
72945 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
72946 mm_segment_t old_fs = get_fs();
72947
72948 set_fs(KERNEL_DS);
72949 - ret = sys_sigpending((old_sigset_t __user *) &s);
72950 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
72951 set_fs(old_fs);
72952 if (ret == 0)
72953 ret = put_user(s, set);
72954 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
72955 mm_segment_t old_fs = get_fs();
72956
72957 set_fs(KERNEL_DS);
72958 - ret = sys_old_getrlimit(resource, &r);
72959 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
72960 set_fs(old_fs);
72961
72962 if (!ret) {
72963 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
72964 mm_segment_t old_fs = get_fs();
72965
72966 set_fs(KERNEL_DS);
72967 - ret = sys_getrusage(who, (struct rusage __user *) &r);
72968 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
72969 set_fs(old_fs);
72970
72971 if (ret)
72972 @@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
72973 set_fs (KERNEL_DS);
72974 ret = sys_wait4(pid,
72975 (stat_addr ?
72976 - (unsigned int __user *) &status : NULL),
72977 - options, (struct rusage __user *) &r);
72978 + (unsigned int __force_user *) &status : NULL),
72979 + options, (struct rusage __force_user *) &r);
72980 set_fs (old_fs);
72981
72982 if (ret > 0) {
72983 @@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
72984 memset(&info, 0, sizeof(info));
72985
72986 set_fs(KERNEL_DS);
72987 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
72988 - uru ? (struct rusage __user *)&ru : NULL);
72989 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
72990 + uru ? (struct rusage __force_user *)&ru : NULL);
72991 set_fs(old_fs);
72992
72993 if ((ret < 0) || (info.si_signo == 0))
72994 @@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
72995 oldfs = get_fs();
72996 set_fs(KERNEL_DS);
72997 err = sys_timer_settime(timer_id, flags,
72998 - (struct itimerspec __user *) &newts,
72999 - (struct itimerspec __user *) &oldts);
73000 + (struct itimerspec __force_user *) &newts,
73001 + (struct itimerspec __force_user *) &oldts);
73002 set_fs(oldfs);
73003 if (!err && old && put_compat_itimerspec(old, &oldts))
73004 return -EFAULT;
73005 @@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
73006 oldfs = get_fs();
73007 set_fs(KERNEL_DS);
73008 err = sys_timer_gettime(timer_id,
73009 - (struct itimerspec __user *) &ts);
73010 + (struct itimerspec __force_user *) &ts);
73011 set_fs(oldfs);
73012 if (!err && put_compat_itimerspec(setting, &ts))
73013 return -EFAULT;
73014 @@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
73015 oldfs = get_fs();
73016 set_fs(KERNEL_DS);
73017 err = sys_clock_settime(which_clock,
73018 - (struct timespec __user *) &ts);
73019 + (struct timespec __force_user *) &ts);
73020 set_fs(oldfs);
73021 return err;
73022 }
73023 @@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
73024 oldfs = get_fs();
73025 set_fs(KERNEL_DS);
73026 err = sys_clock_gettime(which_clock,
73027 - (struct timespec __user *) &ts);
73028 + (struct timespec __force_user *) &ts);
73029 set_fs(oldfs);
73030 if (!err && put_compat_timespec(&ts, tp))
73031 return -EFAULT;
73032 @@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
73033
73034 oldfs = get_fs();
73035 set_fs(KERNEL_DS);
73036 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
73037 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
73038 set_fs(oldfs);
73039
73040 err = compat_put_timex(utp, &txc);
73041 @@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
73042 oldfs = get_fs();
73043 set_fs(KERNEL_DS);
73044 err = sys_clock_getres(which_clock,
73045 - (struct timespec __user *) &ts);
73046 + (struct timespec __force_user *) &ts);
73047 set_fs(oldfs);
73048 if (!err && tp && put_compat_timespec(&ts, tp))
73049 return -EFAULT;
73050 @@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
73051 long err;
73052 mm_segment_t oldfs;
73053 struct timespec tu;
73054 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
73055 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
73056
73057 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
73058 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
73059 oldfs = get_fs();
73060 set_fs(KERNEL_DS);
73061 err = clock_nanosleep_restart(restart);
73062 @@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
73063 oldfs = get_fs();
73064 set_fs(KERNEL_DS);
73065 err = sys_clock_nanosleep(which_clock, flags,
73066 - (struct timespec __user *) &in,
73067 - (struct timespec __user *) &out);
73068 + (struct timespec __force_user *) &in,
73069 + (struct timespec __force_user *) &out);
73070 set_fs(oldfs);
73071
73072 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
73073 diff --git a/kernel/configs.c b/kernel/configs.c
73074 index 42e8fa0..9e7406b 100644
73075 --- a/kernel/configs.c
73076 +++ b/kernel/configs.c
73077 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
73078 struct proc_dir_entry *entry;
73079
73080 /* create the current config file */
73081 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
73082 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
73083 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
73084 + &ikconfig_file_ops);
73085 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73086 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
73087 + &ikconfig_file_ops);
73088 +#endif
73089 +#else
73090 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
73091 &ikconfig_file_ops);
73092 +#endif
73093 +
73094 if (!entry)
73095 return -ENOMEM;
73096
73097 diff --git a/kernel/cred.c b/kernel/cred.c
73098 index e0573a4..3874e41 100644
73099 --- a/kernel/cred.c
73100 +++ b/kernel/cred.c
73101 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
73102 validate_creds(cred);
73103 alter_cred_subscribers(cred, -1);
73104 put_cred(cred);
73105 +
73106 +#ifdef CONFIG_GRKERNSEC_SETXID
73107 + cred = (struct cred *) tsk->delayed_cred;
73108 + if (cred != NULL) {
73109 + tsk->delayed_cred = NULL;
73110 + validate_creds(cred);
73111 + alter_cred_subscribers(cred, -1);
73112 + put_cred(cred);
73113 + }
73114 +#endif
73115 }
73116
73117 /**
73118 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
73119 * Always returns 0 thus allowing this function to be tail-called at the end
73120 * of, say, sys_setgid().
73121 */
73122 -int commit_creds(struct cred *new)
73123 +static int __commit_creds(struct cred *new)
73124 {
73125 struct task_struct *task = current;
73126 const struct cred *old = task->real_cred;
73127 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
73128
73129 get_cred(new); /* we will require a ref for the subj creds too */
73130
73131 + gr_set_role_label(task, new->uid, new->gid);
73132 +
73133 /* dumpability changes */
73134 if (!uid_eq(old->euid, new->euid) ||
73135 !gid_eq(old->egid, new->egid) ||
73136 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
73137 put_cred(old);
73138 return 0;
73139 }
73140 +#ifdef CONFIG_GRKERNSEC_SETXID
73141 +extern int set_user(struct cred *new);
73142 +
73143 +void gr_delayed_cred_worker(void)
73144 +{
73145 + const struct cred *new = current->delayed_cred;
73146 + struct cred *ncred;
73147 +
73148 + current->delayed_cred = NULL;
73149 +
73150 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
73151 + // from doing get_cred on it when queueing this
73152 + put_cred(new);
73153 + return;
73154 + } else if (new == NULL)
73155 + return;
73156 +
73157 + ncred = prepare_creds();
73158 + if (!ncred)
73159 + goto die;
73160 + // uids
73161 + ncred->uid = new->uid;
73162 + ncred->euid = new->euid;
73163 + ncred->suid = new->suid;
73164 + ncred->fsuid = new->fsuid;
73165 + // gids
73166 + ncred->gid = new->gid;
73167 + ncred->egid = new->egid;
73168 + ncred->sgid = new->sgid;
73169 + ncred->fsgid = new->fsgid;
73170 + // groups
73171 + if (set_groups(ncred, new->group_info) < 0) {
73172 + abort_creds(ncred);
73173 + goto die;
73174 + }
73175 + // caps
73176 + ncred->securebits = new->securebits;
73177 + ncred->cap_inheritable = new->cap_inheritable;
73178 + ncred->cap_permitted = new->cap_permitted;
73179 + ncred->cap_effective = new->cap_effective;
73180 + ncred->cap_bset = new->cap_bset;
73181 +
73182 + if (set_user(ncred)) {
73183 + abort_creds(ncred);
73184 + goto die;
73185 + }
73186 +
73187 + // from doing get_cred on it when queueing this
73188 + put_cred(new);
73189 +
73190 + __commit_creds(ncred);
73191 + return;
73192 +die:
73193 + // from doing get_cred on it when queueing this
73194 + put_cred(new);
73195 + do_group_exit(SIGKILL);
73196 +}
73197 +#endif
73198 +
73199 +int commit_creds(struct cred *new)
73200 +{
73201 +#ifdef CONFIG_GRKERNSEC_SETXID
73202 + int ret;
73203 + int schedule_it = 0;
73204 + struct task_struct *t;
73205 +
73206 + /* we won't get called with tasklist_lock held for writing
73207 + and interrupts disabled as the cred struct in that case is
73208 + init_cred
73209 + */
73210 + if (grsec_enable_setxid && !current_is_single_threaded() &&
73211 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
73212 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
73213 + schedule_it = 1;
73214 + }
73215 + ret = __commit_creds(new);
73216 + if (schedule_it) {
73217 + rcu_read_lock();
73218 + read_lock(&tasklist_lock);
73219 + for (t = next_thread(current); t != current;
73220 + t = next_thread(t)) {
73221 + if (t->delayed_cred == NULL) {
73222 + t->delayed_cred = get_cred(new);
73223 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
73224 + set_tsk_need_resched(t);
73225 + }
73226 + }
73227 + read_unlock(&tasklist_lock);
73228 + rcu_read_unlock();
73229 + }
73230 + return ret;
73231 +#else
73232 + return __commit_creds(new);
73233 +#endif
73234 +}
73235 +
73236 EXPORT_SYMBOL(commit_creds);
73237
73238 /**
73239 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
73240 index 9a61738..c5c8f3a 100644
73241 --- a/kernel/debug/debug_core.c
73242 +++ b/kernel/debug/debug_core.c
73243 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
73244 */
73245 static atomic_t masters_in_kgdb;
73246 static atomic_t slaves_in_kgdb;
73247 -static atomic_t kgdb_break_tasklet_var;
73248 +static atomic_unchecked_t kgdb_break_tasklet_var;
73249 atomic_t kgdb_setting_breakpoint;
73250
73251 struct task_struct *kgdb_usethread;
73252 @@ -132,7 +132,7 @@ int kgdb_single_step;
73253 static pid_t kgdb_sstep_pid;
73254
73255 /* to keep track of the CPU which is doing the single stepping*/
73256 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73257 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73258
73259 /*
73260 * If you are debugging a problem where roundup (the collection of
73261 @@ -540,7 +540,7 @@ return_normal:
73262 * kernel will only try for the value of sstep_tries before
73263 * giving up and continuing on.
73264 */
73265 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
73266 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
73267 (kgdb_info[cpu].task &&
73268 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
73269 atomic_set(&kgdb_active, -1);
73270 @@ -634,8 +634,8 @@ cpu_master_loop:
73271 }
73272
73273 kgdb_restore:
73274 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
73275 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
73276 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
73277 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
73278 if (kgdb_info[sstep_cpu].task)
73279 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
73280 else
73281 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
73282 static void kgdb_tasklet_bpt(unsigned long ing)
73283 {
73284 kgdb_breakpoint();
73285 - atomic_set(&kgdb_break_tasklet_var, 0);
73286 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
73287 }
73288
73289 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
73290
73291 void kgdb_schedule_breakpoint(void)
73292 {
73293 - if (atomic_read(&kgdb_break_tasklet_var) ||
73294 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
73295 atomic_read(&kgdb_active) != -1 ||
73296 atomic_read(&kgdb_setting_breakpoint))
73297 return;
73298 - atomic_inc(&kgdb_break_tasklet_var);
73299 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
73300 tasklet_schedule(&kgdb_tasklet_breakpoint);
73301 }
73302 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
73303 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
73304 index 8875254..7cf4928 100644
73305 --- a/kernel/debug/kdb/kdb_main.c
73306 +++ b/kernel/debug/kdb/kdb_main.c
73307 @@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
73308 continue;
73309
73310 kdb_printf("%-20s%8u 0x%p ", mod->name,
73311 - mod->core_size, (void *)mod);
73312 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
73313 #ifdef CONFIG_MODULE_UNLOAD
73314 kdb_printf("%4ld ", module_refcount(mod));
73315 #endif
73316 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
73317 kdb_printf(" (Loading)");
73318 else
73319 kdb_printf(" (Live)");
73320 - kdb_printf(" 0x%p", mod->module_core);
73321 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
73322
73323 #ifdef CONFIG_MODULE_UNLOAD
73324 {
73325 diff --git a/kernel/events/core.c b/kernel/events/core.c
73326 index 7b6646a..3cb1135 100644
73327 --- a/kernel/events/core.c
73328 +++ b/kernel/events/core.c
73329 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
73330 return 0;
73331 }
73332
73333 -static atomic64_t perf_event_id;
73334 +static atomic64_unchecked_t perf_event_id;
73335
73336 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
73337 enum event_type_t event_type);
73338 @@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
73339
73340 static inline u64 perf_event_count(struct perf_event *event)
73341 {
73342 - return local64_read(&event->count) + atomic64_read(&event->child_count);
73343 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
73344 }
73345
73346 static u64 perf_event_read(struct perf_event *event)
73347 @@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
73348 mutex_lock(&event->child_mutex);
73349 total += perf_event_read(event);
73350 *enabled += event->total_time_enabled +
73351 - atomic64_read(&event->child_total_time_enabled);
73352 + atomic64_read_unchecked(&event->child_total_time_enabled);
73353 *running += event->total_time_running +
73354 - atomic64_read(&event->child_total_time_running);
73355 + atomic64_read_unchecked(&event->child_total_time_running);
73356
73357 list_for_each_entry(child, &event->child_list, child_list) {
73358 total += perf_event_read(child);
73359 @@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
73360 userpg->offset -= local64_read(&event->hw.prev_count);
73361
73362 userpg->time_enabled = enabled +
73363 - atomic64_read(&event->child_total_time_enabled);
73364 + atomic64_read_unchecked(&event->child_total_time_enabled);
73365
73366 userpg->time_running = running +
73367 - atomic64_read(&event->child_total_time_running);
73368 + atomic64_read_unchecked(&event->child_total_time_running);
73369
73370 arch_perf_update_userpage(userpg, now);
73371
73372 @@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
73373 values[n++] = perf_event_count(event);
73374 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
73375 values[n++] = enabled +
73376 - atomic64_read(&event->child_total_time_enabled);
73377 + atomic64_read_unchecked(&event->child_total_time_enabled);
73378 }
73379 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
73380 values[n++] = running +
73381 - atomic64_read(&event->child_total_time_running);
73382 + atomic64_read_unchecked(&event->child_total_time_running);
73383 }
73384 if (read_format & PERF_FORMAT_ID)
73385 values[n++] = primary_event_id(event);
73386 @@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
73387 * need to add enough zero bytes after the string to handle
73388 * the 64bit alignment we do later.
73389 */
73390 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
73391 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
73392 if (!buf) {
73393 name = strncpy(tmp, "//enomem", sizeof(tmp));
73394 goto got_name;
73395 }
73396 - name = d_path(&file->f_path, buf, PATH_MAX);
73397 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
73398 if (IS_ERR(name)) {
73399 name = strncpy(tmp, "//toolong", sizeof(tmp));
73400 goto got_name;
73401 @@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
73402 event->parent = parent_event;
73403
73404 event->ns = get_pid_ns(task_active_pid_ns(current));
73405 - event->id = atomic64_inc_return(&perf_event_id);
73406 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
73407
73408 event->state = PERF_EVENT_STATE_INACTIVE;
73409
73410 @@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
73411 /*
73412 * Add back the child's count to the parent's count:
73413 */
73414 - atomic64_add(child_val, &parent_event->child_count);
73415 - atomic64_add(child_event->total_time_enabled,
73416 + atomic64_add_unchecked(child_val, &parent_event->child_count);
73417 + atomic64_add_unchecked(child_event->total_time_enabled,
73418 &parent_event->child_total_time_enabled);
73419 - atomic64_add(child_event->total_time_running,
73420 + atomic64_add_unchecked(child_event->total_time_running,
73421 &parent_event->child_total_time_running);
73422
73423 /*
73424 diff --git a/kernel/exit.c b/kernel/exit.c
73425 index b4df219..f13c02d 100644
73426 --- a/kernel/exit.c
73427 +++ b/kernel/exit.c
73428 @@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
73429 struct task_struct *leader;
73430 int zap_leader;
73431 repeat:
73432 +#ifdef CONFIG_NET
73433 + gr_del_task_from_ip_table(p);
73434 +#endif
73435 +
73436 /* don't need to get the RCU readlock here - the process is dead and
73437 * can't be modifying its own credentials. But shut RCU-lockdep up */
73438 rcu_read_lock();
73439 @@ -338,7 +342,7 @@ int allow_signal(int sig)
73440 * know it'll be handled, so that they don't get converted to
73441 * SIGKILL or just silently dropped.
73442 */
73443 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
73444 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
73445 recalc_sigpending();
73446 spin_unlock_irq(&current->sighand->siglock);
73447 return 0;
73448 @@ -708,6 +712,8 @@ void do_exit(long code)
73449 struct task_struct *tsk = current;
73450 int group_dead;
73451
73452 + set_fs(USER_DS);
73453 +
73454 profile_task_exit(tsk);
73455
73456 WARN_ON(blk_needs_flush_plug(tsk));
73457 @@ -724,7 +730,6 @@ void do_exit(long code)
73458 * mm_release()->clear_child_tid() from writing to a user-controlled
73459 * kernel address.
73460 */
73461 - set_fs(USER_DS);
73462
73463 ptrace_event(PTRACE_EVENT_EXIT, code);
73464
73465 @@ -783,6 +788,9 @@ void do_exit(long code)
73466 tsk->exit_code = code;
73467 taskstats_exit(tsk, group_dead);
73468
73469 + gr_acl_handle_psacct(tsk, code);
73470 + gr_acl_handle_exit();
73471 +
73472 exit_mm(tsk);
73473
73474 if (group_dead)
73475 @@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
73476 * Take down every thread in the group. This is called by fatal signals
73477 * as well as by sys_exit_group (below).
73478 */
73479 -void
73480 +__noreturn void
73481 do_group_exit(int exit_code)
73482 {
73483 struct signal_struct *sig = current->signal;
73484 diff --git a/kernel/fork.c b/kernel/fork.c
73485 index c535f33..1d768f9 100644
73486 --- a/kernel/fork.c
73487 +++ b/kernel/fork.c
73488 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
73489 *stackend = STACK_END_MAGIC; /* for overflow detection */
73490
73491 #ifdef CONFIG_CC_STACKPROTECTOR
73492 - tsk->stack_canary = get_random_int();
73493 + tsk->stack_canary = pax_get_random_long();
73494 #endif
73495
73496 /*
73497 @@ -344,13 +344,81 @@ free_tsk:
73498 }
73499
73500 #ifdef CONFIG_MMU
73501 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
73502 +{
73503 + struct vm_area_struct *tmp;
73504 + unsigned long charge;
73505 + struct mempolicy *pol;
73506 + struct file *file;
73507 +
73508 + charge = 0;
73509 + if (mpnt->vm_flags & VM_ACCOUNT) {
73510 + unsigned long len = vma_pages(mpnt);
73511 +
73512 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
73513 + goto fail_nomem;
73514 + charge = len;
73515 + }
73516 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73517 + if (!tmp)
73518 + goto fail_nomem;
73519 + *tmp = *mpnt;
73520 + tmp->vm_mm = mm;
73521 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
73522 + pol = mpol_dup(vma_policy(mpnt));
73523 + if (IS_ERR(pol))
73524 + goto fail_nomem_policy;
73525 + vma_set_policy(tmp, pol);
73526 + if (anon_vma_fork(tmp, mpnt))
73527 + goto fail_nomem_anon_vma_fork;
73528 + tmp->vm_flags &= ~VM_LOCKED;
73529 + tmp->vm_next = tmp->vm_prev = NULL;
73530 + tmp->vm_mirror = NULL;
73531 + file = tmp->vm_file;
73532 + if (file) {
73533 + struct inode *inode = file->f_path.dentry->d_inode;
73534 + struct address_space *mapping = file->f_mapping;
73535 +
73536 + get_file(file);
73537 + if (tmp->vm_flags & VM_DENYWRITE)
73538 + atomic_dec(&inode->i_writecount);
73539 + mutex_lock(&mapping->i_mmap_mutex);
73540 + if (tmp->vm_flags & VM_SHARED)
73541 + mapping->i_mmap_writable++;
73542 + flush_dcache_mmap_lock(mapping);
73543 + /* insert tmp into the share list, just after mpnt */
73544 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
73545 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
73546 + else
73547 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
73548 + flush_dcache_mmap_unlock(mapping);
73549 + mutex_unlock(&mapping->i_mmap_mutex);
73550 + }
73551 +
73552 + /*
73553 + * Clear hugetlb-related page reserves for children. This only
73554 + * affects MAP_PRIVATE mappings. Faults generated by the child
73555 + * are not guaranteed to succeed, even if read-only
73556 + */
73557 + if (is_vm_hugetlb_page(tmp))
73558 + reset_vma_resv_huge_pages(tmp);
73559 +
73560 + return tmp;
73561 +
73562 +fail_nomem_anon_vma_fork:
73563 + mpol_put(pol);
73564 +fail_nomem_policy:
73565 + kmem_cache_free(vm_area_cachep, tmp);
73566 +fail_nomem:
73567 + vm_unacct_memory(charge);
73568 + return NULL;
73569 +}
73570 +
73571 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73572 {
73573 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
73574 struct rb_node **rb_link, *rb_parent;
73575 int retval;
73576 - unsigned long charge;
73577 - struct mempolicy *pol;
73578
73579 uprobe_start_dup_mmap();
73580 down_write(&oldmm->mmap_sem);
73581 @@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73582 mm->locked_vm = 0;
73583 mm->mmap = NULL;
73584 mm->mmap_cache = NULL;
73585 - mm->free_area_cache = oldmm->mmap_base;
73586 - mm->cached_hole_size = ~0UL;
73587 + mm->free_area_cache = oldmm->free_area_cache;
73588 + mm->cached_hole_size = oldmm->cached_hole_size;
73589 mm->map_count = 0;
73590 cpumask_clear(mm_cpumask(mm));
73591 mm->mm_rb = RB_ROOT;
73592 @@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73593
73594 prev = NULL;
73595 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
73596 - struct file *file;
73597 -
73598 if (mpnt->vm_flags & VM_DONTCOPY) {
73599 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
73600 -vma_pages(mpnt));
73601 continue;
73602 }
73603 - charge = 0;
73604 - if (mpnt->vm_flags & VM_ACCOUNT) {
73605 - unsigned long len = vma_pages(mpnt);
73606 -
73607 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
73608 - goto fail_nomem;
73609 - charge = len;
73610 - }
73611 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73612 - if (!tmp)
73613 - goto fail_nomem;
73614 - *tmp = *mpnt;
73615 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
73616 - pol = mpol_dup(vma_policy(mpnt));
73617 - retval = PTR_ERR(pol);
73618 - if (IS_ERR(pol))
73619 - goto fail_nomem_policy;
73620 - vma_set_policy(tmp, pol);
73621 - tmp->vm_mm = mm;
73622 - if (anon_vma_fork(tmp, mpnt))
73623 - goto fail_nomem_anon_vma_fork;
73624 - tmp->vm_flags &= ~VM_LOCKED;
73625 - tmp->vm_next = tmp->vm_prev = NULL;
73626 - file = tmp->vm_file;
73627 - if (file) {
73628 - struct inode *inode = file->f_path.dentry->d_inode;
73629 - struct address_space *mapping = file->f_mapping;
73630 -
73631 - get_file(file);
73632 - if (tmp->vm_flags & VM_DENYWRITE)
73633 - atomic_dec(&inode->i_writecount);
73634 - mutex_lock(&mapping->i_mmap_mutex);
73635 - if (tmp->vm_flags & VM_SHARED)
73636 - mapping->i_mmap_writable++;
73637 - flush_dcache_mmap_lock(mapping);
73638 - /* insert tmp into the share list, just after mpnt */
73639 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
73640 - vma_nonlinear_insert(tmp,
73641 - &mapping->i_mmap_nonlinear);
73642 - else
73643 - vma_interval_tree_insert_after(tmp, mpnt,
73644 - &mapping->i_mmap);
73645 - flush_dcache_mmap_unlock(mapping);
73646 - mutex_unlock(&mapping->i_mmap_mutex);
73647 + tmp = dup_vma(mm, oldmm, mpnt);
73648 + if (!tmp) {
73649 + retval = -ENOMEM;
73650 + goto out;
73651 }
73652
73653 /*
73654 @@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73655 if (retval)
73656 goto out;
73657 }
73658 +
73659 +#ifdef CONFIG_PAX_SEGMEXEC
73660 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
73661 + struct vm_area_struct *mpnt_m;
73662 +
73663 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
73664 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
73665 +
73666 + if (!mpnt->vm_mirror)
73667 + continue;
73668 +
73669 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
73670 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
73671 + mpnt->vm_mirror = mpnt_m;
73672 + } else {
73673 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
73674 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
73675 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
73676 + mpnt->vm_mirror->vm_mirror = mpnt;
73677 + }
73678 + }
73679 + BUG_ON(mpnt_m);
73680 + }
73681 +#endif
73682 +
73683 /* a new mm has just been created */
73684 arch_dup_mmap(oldmm, mm);
73685 retval = 0;
73686 @@ -472,14 +523,6 @@ out:
73687 up_write(&oldmm->mmap_sem);
73688 uprobe_end_dup_mmap();
73689 return retval;
73690 -fail_nomem_anon_vma_fork:
73691 - mpol_put(pol);
73692 -fail_nomem_policy:
73693 - kmem_cache_free(vm_area_cachep, tmp);
73694 -fail_nomem:
73695 - retval = -ENOMEM;
73696 - vm_unacct_memory(charge);
73697 - goto out;
73698 }
73699
73700 static inline int mm_alloc_pgd(struct mm_struct *mm)
73701 @@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
73702 return ERR_PTR(err);
73703
73704 mm = get_task_mm(task);
73705 - if (mm && mm != current->mm &&
73706 - !ptrace_may_access(task, mode)) {
73707 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
73708 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
73709 mmput(mm);
73710 mm = ERR_PTR(-EACCES);
73711 }
73712 @@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
73713 spin_unlock(&fs->lock);
73714 return -EAGAIN;
73715 }
73716 - fs->users++;
73717 + atomic_inc(&fs->users);
73718 spin_unlock(&fs->lock);
73719 return 0;
73720 }
73721 tsk->fs = copy_fs_struct(fs);
73722 if (!tsk->fs)
73723 return -ENOMEM;
73724 + /* Carry through gr_chroot_dentry and is_chrooted instead
73725 + of recomputing it here. Already copied when the task struct
73726 + is duplicated. This allows pivot_root to not be treated as
73727 + a chroot
73728 + */
73729 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
73730 +
73731 return 0;
73732 }
73733
73734 @@ -1193,6 +1243,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
73735 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
73736 #endif
73737 retval = -EAGAIN;
73738 +
73739 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
73740 +
73741 if (atomic_read(&p->real_cred->user->processes) >=
73742 task_rlimit(p, RLIMIT_NPROC)) {
73743 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
73744 @@ -1432,6 +1485,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
73745 goto bad_fork_free_pid;
73746 }
73747
73748 + /* synchronizes with gr_set_acls()
73749 + we need to call this past the point of no return for fork()
73750 + */
73751 + gr_copy_label(p);
73752 +
73753 if (clone_flags & CLONE_THREAD) {
73754 current->signal->nr_threads++;
73755 atomic_inc(&current->signal->live);
73756 @@ -1515,6 +1573,8 @@ bad_fork_cleanup_count:
73757 bad_fork_free:
73758 free_task(p);
73759 fork_out:
73760 + gr_log_forkfail(retval);
73761 +
73762 return ERR_PTR(retval);
73763 }
73764
73765 @@ -1565,6 +1625,23 @@ long do_fork(unsigned long clone_flags,
73766 return -EINVAL;
73767 }
73768
73769 +#ifdef CONFIG_GRKERNSEC
73770 + if (clone_flags & CLONE_NEWUSER) {
73771 + /*
73772 + * This doesn't really inspire confidence:
73773 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
73774 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
73775 + * Increases kernel attack surface in areas developers
73776 + * previously cared little about ("low importance due
73777 + * to requiring "root" capability")
73778 + * To be removed when this code receives *proper* review
73779 + */
73780 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
73781 + !capable(CAP_SETGID))
73782 + return -EPERM;
73783 + }
73784 +#endif
73785 +
73786 /*
73787 * Determine whether and which event to report to ptracer. When
73788 * called from kernel_thread or CLONE_UNTRACED is explicitly
73789 @@ -1599,6 +1676,8 @@ long do_fork(unsigned long clone_flags,
73790 if (clone_flags & CLONE_PARENT_SETTID)
73791 put_user(nr, parent_tidptr);
73792
73793 + gr_handle_brute_check();
73794 +
73795 if (clone_flags & CLONE_VFORK) {
73796 p->vfork_done = &vfork;
73797 init_completion(&vfork);
73798 @@ -1752,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
73799 return 0;
73800
73801 /* don't need lock here; in the worst case we'll do useless copy */
73802 - if (fs->users == 1)
73803 + if (atomic_read(&fs->users) == 1)
73804 return 0;
73805
73806 *new_fsp = copy_fs_struct(fs);
73807 @@ -1866,7 +1945,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
73808 fs = current->fs;
73809 spin_lock(&fs->lock);
73810 current->fs = new_fs;
73811 - if (--fs->users)
73812 + gr_set_chroot_entries(current, &current->fs->root);
73813 + if (atomic_dec_return(&fs->users))
73814 new_fs = NULL;
73815 else
73816 new_fs = fs;
73817 diff --git a/kernel/futex.c b/kernel/futex.c
73818 index 8879430..31696f1 100644
73819 --- a/kernel/futex.c
73820 +++ b/kernel/futex.c
73821 @@ -54,6 +54,7 @@
73822 #include <linux/mount.h>
73823 #include <linux/pagemap.h>
73824 #include <linux/syscalls.h>
73825 +#include <linux/ptrace.h>
73826 #include <linux/signal.h>
73827 #include <linux/export.h>
73828 #include <linux/magic.h>
73829 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
73830 struct page *page, *page_head;
73831 int err, ro = 0;
73832
73833 +#ifdef CONFIG_PAX_SEGMEXEC
73834 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
73835 + return -EFAULT;
73836 +#endif
73837 +
73838 /*
73839 * The futex address must be "naturally" aligned.
73840 */
73841 @@ -2731,6 +2737,7 @@ static int __init futex_init(void)
73842 {
73843 u32 curval;
73844 int i;
73845 + mm_segment_t oldfs;
73846
73847 /*
73848 * This will fail and we want it. Some arch implementations do
73849 @@ -2742,8 +2749,11 @@ static int __init futex_init(void)
73850 * implementation, the non-functional ones will return
73851 * -ENOSYS.
73852 */
73853 + oldfs = get_fs();
73854 + set_fs(USER_DS);
73855 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
73856 futex_cmpxchg_enabled = 1;
73857 + set_fs(oldfs);
73858
73859 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
73860 plist_head_init(&futex_queues[i].chain);
73861 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
73862 index 9b22d03..6295b62 100644
73863 --- a/kernel/gcov/base.c
73864 +++ b/kernel/gcov/base.c
73865 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
73866 }
73867
73868 #ifdef CONFIG_MODULES
73869 -static inline int within(void *addr, void *start, unsigned long size)
73870 -{
73871 - return ((addr >= start) && (addr < start + size));
73872 -}
73873 -
73874 /* Update list and generate events when modules are unloaded. */
73875 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
73876 void *data)
73877 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
73878 prev = NULL;
73879 /* Remove entries located in module from linked list. */
73880 for (info = gcov_info_head; info; info = info->next) {
73881 - if (within(info, mod->module_core, mod->core_size)) {
73882 + if (within_module_core_rw((unsigned long)info, mod)) {
73883 if (prev)
73884 prev->next = info->next;
73885 else
73886 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
73887 index cdd5607..c3fc919 100644
73888 --- a/kernel/hrtimer.c
73889 +++ b/kernel/hrtimer.c
73890 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
73891 local_irq_restore(flags);
73892 }
73893
73894 -static void run_hrtimer_softirq(struct softirq_action *h)
73895 +static void run_hrtimer_softirq(void)
73896 {
73897 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
73898
73899 @@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
73900 return NOTIFY_OK;
73901 }
73902
73903 -static struct notifier_block __cpuinitdata hrtimers_nb = {
73904 +static struct notifier_block hrtimers_nb = {
73905 .notifier_call = hrtimer_cpu_notify,
73906 };
73907
73908 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
73909 index 60f48fa..7f3a770 100644
73910 --- a/kernel/jump_label.c
73911 +++ b/kernel/jump_label.c
73912 @@ -13,6 +13,7 @@
73913 #include <linux/sort.h>
73914 #include <linux/err.h>
73915 #include <linux/static_key.h>
73916 +#include <linux/mm.h>
73917
73918 #ifdef HAVE_JUMP_LABEL
73919
73920 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
73921
73922 size = (((unsigned long)stop - (unsigned long)start)
73923 / sizeof(struct jump_entry));
73924 + pax_open_kernel();
73925 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
73926 + pax_close_kernel();
73927 }
73928
73929 static void jump_label_update(struct static_key *key, int enable);
73930 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
73931 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
73932 struct jump_entry *iter;
73933
73934 + pax_open_kernel();
73935 for (iter = iter_start; iter < iter_stop; iter++) {
73936 if (within_module_init(iter->code, mod))
73937 iter->code = 0;
73938 }
73939 + pax_close_kernel();
73940 }
73941
73942 static int
73943 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
73944 index 2169fee..706ccca 100644
73945 --- a/kernel/kallsyms.c
73946 +++ b/kernel/kallsyms.c
73947 @@ -11,6 +11,9 @@
73948 * Changed the compression method from stem compression to "table lookup"
73949 * compression (see scripts/kallsyms.c for a more complete description)
73950 */
73951 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73952 +#define __INCLUDED_BY_HIDESYM 1
73953 +#endif
73954 #include <linux/kallsyms.h>
73955 #include <linux/module.h>
73956 #include <linux/init.h>
73957 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
73958
73959 static inline int is_kernel_inittext(unsigned long addr)
73960 {
73961 + if (system_state != SYSTEM_BOOTING)
73962 + return 0;
73963 +
73964 if (addr >= (unsigned long)_sinittext
73965 && addr <= (unsigned long)_einittext)
73966 return 1;
73967 return 0;
73968 }
73969
73970 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73971 +#ifdef CONFIG_MODULES
73972 +static inline int is_module_text(unsigned long addr)
73973 +{
73974 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
73975 + return 1;
73976 +
73977 + addr = ktla_ktva(addr);
73978 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
73979 +}
73980 +#else
73981 +static inline int is_module_text(unsigned long addr)
73982 +{
73983 + return 0;
73984 +}
73985 +#endif
73986 +#endif
73987 +
73988 static inline int is_kernel_text(unsigned long addr)
73989 {
73990 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
73991 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
73992
73993 static inline int is_kernel(unsigned long addr)
73994 {
73995 +
73996 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73997 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
73998 + return 1;
73999 +
74000 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
74001 +#else
74002 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
74003 +#endif
74004 +
74005 return 1;
74006 return in_gate_area_no_mm(addr);
74007 }
74008
74009 static int is_ksym_addr(unsigned long addr)
74010 {
74011 +
74012 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74013 + if (is_module_text(addr))
74014 + return 0;
74015 +#endif
74016 +
74017 if (all_var)
74018 return is_kernel(addr);
74019
74020 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
74021
74022 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
74023 {
74024 - iter->name[0] = '\0';
74025 iter->nameoff = get_symbol_offset(new_pos);
74026 iter->pos = new_pos;
74027 }
74028 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
74029 {
74030 struct kallsym_iter *iter = m->private;
74031
74032 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74033 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
74034 + return 0;
74035 +#endif
74036 +
74037 /* Some debugging symbols have no name. Ignore them. */
74038 if (!iter->name[0])
74039 return 0;
74040 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
74041 */
74042 type = iter->exported ? toupper(iter->type) :
74043 tolower(iter->type);
74044 +
74045 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
74046 type, iter->name, iter->module_name);
74047 } else
74048 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
74049 struct kallsym_iter *iter;
74050 int ret;
74051
74052 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
74053 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
74054 if (!iter)
74055 return -ENOMEM;
74056 reset_iter(iter, 0);
74057 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
74058 index e30ac0f..3528cac 100644
74059 --- a/kernel/kcmp.c
74060 +++ b/kernel/kcmp.c
74061 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
74062 struct task_struct *task1, *task2;
74063 int ret;
74064
74065 +#ifdef CONFIG_GRKERNSEC
74066 + return -ENOSYS;
74067 +#endif
74068 +
74069 rcu_read_lock();
74070
74071 /*
74072 diff --git a/kernel/kexec.c b/kernel/kexec.c
74073 index 5e4bd78..00c5b91 100644
74074 --- a/kernel/kexec.c
74075 +++ b/kernel/kexec.c
74076 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
74077 unsigned long flags)
74078 {
74079 struct compat_kexec_segment in;
74080 - struct kexec_segment out, __user *ksegments;
74081 + struct kexec_segment out;
74082 + struct kexec_segment __user *ksegments;
74083 unsigned long i, result;
74084
74085 /* Don't allow clients that don't understand the native
74086 diff --git a/kernel/kmod.c b/kernel/kmod.c
74087 index 0023a87..9c0c068 100644
74088 --- a/kernel/kmod.c
74089 +++ b/kernel/kmod.c
74090 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
74091 kfree(info->argv);
74092 }
74093
74094 -static int call_modprobe(char *module_name, int wait)
74095 +static int call_modprobe(char *module_name, char *module_param, int wait)
74096 {
74097 static char *envp[] = {
74098 "HOME=/",
74099 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
74100 NULL
74101 };
74102
74103 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
74104 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
74105 if (!argv)
74106 goto out;
74107
74108 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
74109 argv[1] = "-q";
74110 argv[2] = "--";
74111 argv[3] = module_name; /* check free_modprobe_argv() */
74112 - argv[4] = NULL;
74113 + argv[4] = module_param;
74114 + argv[5] = NULL;
74115
74116 return call_usermodehelper_fns(modprobe_path, argv, envp,
74117 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
74118 @@ -120,9 +121,8 @@ out:
74119 * If module auto-loading support is disabled then this function
74120 * becomes a no-operation.
74121 */
74122 -int __request_module(bool wait, const char *fmt, ...)
74123 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
74124 {
74125 - va_list args;
74126 char module_name[MODULE_NAME_LEN];
74127 unsigned int max_modprobes;
74128 int ret;
74129 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
74130 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
74131 static int kmod_loop_msg;
74132
74133 - va_start(args, fmt);
74134 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
74135 - va_end(args);
74136 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
74137 if (ret >= MODULE_NAME_LEN)
74138 return -ENAMETOOLONG;
74139
74140 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
74141 if (ret)
74142 return ret;
74143
74144 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74145 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74146 + /* hack to workaround consolekit/udisks stupidity */
74147 + read_lock(&tasklist_lock);
74148 + if (!strcmp(current->comm, "mount") &&
74149 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
74150 + read_unlock(&tasklist_lock);
74151 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
74152 + return -EPERM;
74153 + }
74154 + read_unlock(&tasklist_lock);
74155 + }
74156 +#endif
74157 +
74158 /* If modprobe needs a service that is in a module, we get a recursive
74159 * loop. Limit the number of running kmod threads to max_threads/2 or
74160 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
74161 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
74162
74163 trace_module_request(module_name, wait, _RET_IP_);
74164
74165 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74166 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74167
74168 atomic_dec(&kmod_concurrent);
74169 return ret;
74170 }
74171 +
74172 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
74173 +{
74174 + va_list args;
74175 + int ret;
74176 +
74177 + va_start(args, fmt);
74178 + ret = ____request_module(wait, module_param, fmt, args);
74179 + va_end(args);
74180 +
74181 + return ret;
74182 +}
74183 +
74184 +int __request_module(bool wait, const char *fmt, ...)
74185 +{
74186 + va_list args;
74187 + int ret;
74188 +
74189 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74190 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74191 + char module_param[MODULE_NAME_LEN];
74192 +
74193 + memset(module_param, 0, sizeof(module_param));
74194 +
74195 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
74196 +
74197 + va_start(args, fmt);
74198 + ret = ____request_module(wait, module_param, fmt, args);
74199 + va_end(args);
74200 +
74201 + return ret;
74202 + }
74203 +#endif
74204 +
74205 + va_start(args, fmt);
74206 + ret = ____request_module(wait, NULL, fmt, args);
74207 + va_end(args);
74208 +
74209 + return ret;
74210 +}
74211 +
74212 EXPORT_SYMBOL(__request_module);
74213 #endif /* CONFIG_MODULES */
74214
74215 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
74216 *
74217 * Thus the __user pointer cast is valid here.
74218 */
74219 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
74220 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
74221
74222 /*
74223 * If ret is 0, either ____call_usermodehelper failed and the
74224 @@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
74225 static int proc_cap_handler(struct ctl_table *table, int write,
74226 void __user *buffer, size_t *lenp, loff_t *ppos)
74227 {
74228 - struct ctl_table t;
74229 + ctl_table_no_const t;
74230 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
74231 kernel_cap_t new_cap;
74232 int err, i;
74233 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
74234 index 098f396..fe85ff1 100644
74235 --- a/kernel/kprobes.c
74236 +++ b/kernel/kprobes.c
74237 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
74238 * kernel image and loaded module images reside. This is required
74239 * so x86_64 can correctly handle the %rip-relative fixups.
74240 */
74241 - kip->insns = module_alloc(PAGE_SIZE);
74242 + kip->insns = module_alloc_exec(PAGE_SIZE);
74243 if (!kip->insns) {
74244 kfree(kip);
74245 return NULL;
74246 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
74247 */
74248 if (!list_is_singular(&kip->list)) {
74249 list_del(&kip->list);
74250 - module_free(NULL, kip->insns);
74251 + module_free_exec(NULL, kip->insns);
74252 kfree(kip);
74253 }
74254 return 1;
74255 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
74256 {
74257 int i, err = 0;
74258 unsigned long offset = 0, size = 0;
74259 - char *modname, namebuf[128];
74260 + char *modname, namebuf[KSYM_NAME_LEN];
74261 const char *symbol_name;
74262 void *addr;
74263 struct kprobe_blackpoint *kb;
74264 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
74265 kprobe_type = "k";
74266
74267 if (sym)
74268 - seq_printf(pi, "%p %s %s+0x%x %s ",
74269 + seq_printf(pi, "%pK %s %s+0x%x %s ",
74270 p->addr, kprobe_type, sym, offset,
74271 (modname ? modname : " "));
74272 else
74273 - seq_printf(pi, "%p %s %p ",
74274 + seq_printf(pi, "%pK %s %pK ",
74275 p->addr, kprobe_type, p->addr);
74276
74277 if (!pp)
74278 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
74279 const char *sym = NULL;
74280 unsigned int i = *(loff_t *) v;
74281 unsigned long offset = 0;
74282 - char *modname, namebuf[128];
74283 + char *modname, namebuf[KSYM_NAME_LEN];
74284
74285 head = &kprobe_table[i];
74286 preempt_disable();
74287 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
74288 index 6ada93c..dce7d5d 100644
74289 --- a/kernel/ksysfs.c
74290 +++ b/kernel/ksysfs.c
74291 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
74292 {
74293 if (count+1 > UEVENT_HELPER_PATH_LEN)
74294 return -ENOENT;
74295 + if (!capable(CAP_SYS_ADMIN))
74296 + return -EPERM;
74297 memcpy(uevent_helper, buf, count);
74298 uevent_helper[count] = '\0';
74299 if (count && uevent_helper[count-1] == '\n')
74300 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
74301 return count;
74302 }
74303
74304 -static struct bin_attribute notes_attr = {
74305 +static bin_attribute_no_const notes_attr __read_only = {
74306 .attr = {
74307 .name = "notes",
74308 .mode = S_IRUGO,
74309 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
74310 index 7981e5b..7f2105c 100644
74311 --- a/kernel/lockdep.c
74312 +++ b/kernel/lockdep.c
74313 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
74314 end = (unsigned long) &_end,
74315 addr = (unsigned long) obj;
74316
74317 +#ifdef CONFIG_PAX_KERNEXEC
74318 + start = ktla_ktva(start);
74319 +#endif
74320 +
74321 /*
74322 * static variable?
74323 */
74324 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
74325 if (!static_obj(lock->key)) {
74326 debug_locks_off();
74327 printk("INFO: trying to register non-static key.\n");
74328 + printk("lock:%pS key:%pS.\n", lock, lock->key);
74329 printk("the code is fine but needs lockdep annotation.\n");
74330 printk("turning off the locking correctness validator.\n");
74331 dump_stack();
74332 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
74333 if (!class)
74334 return 0;
74335 }
74336 - atomic_inc((atomic_t *)&class->ops);
74337 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
74338 if (very_verbose(class)) {
74339 printk("\nacquire class [%p] %s", class->key, class->name);
74340 if (class->name_version > 1)
74341 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
74342 index b2c71c5..7b88d63 100644
74343 --- a/kernel/lockdep_proc.c
74344 +++ b/kernel/lockdep_proc.c
74345 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
74346 return 0;
74347 }
74348
74349 - seq_printf(m, "%p", class->key);
74350 + seq_printf(m, "%pK", class->key);
74351 #ifdef CONFIG_DEBUG_LOCKDEP
74352 seq_printf(m, " OPS:%8ld", class->ops);
74353 #endif
74354 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
74355
74356 list_for_each_entry(entry, &class->locks_after, entry) {
74357 if (entry->distance == 1) {
74358 - seq_printf(m, " -> [%p] ", entry->class->key);
74359 + seq_printf(m, " -> [%pK] ", entry->class->key);
74360 print_name(m, entry->class);
74361 seq_puts(m, "\n");
74362 }
74363 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
74364 if (!class->key)
74365 continue;
74366
74367 - seq_printf(m, "[%p] ", class->key);
74368 + seq_printf(m, "[%pK] ", class->key);
74369 print_name(m, class);
74370 seq_puts(m, "\n");
74371 }
74372 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
74373 if (!i)
74374 seq_line(m, '-', 40-namelen, namelen);
74375
74376 - snprintf(ip, sizeof(ip), "[<%p>]",
74377 + snprintf(ip, sizeof(ip), "[<%pK>]",
74378 (void *)class->contention_point[i]);
74379 seq_printf(m, "%40s %14lu %29s %pS\n",
74380 name, stats->contention_point[i],
74381 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
74382 if (!i)
74383 seq_line(m, '-', 40-namelen, namelen);
74384
74385 - snprintf(ip, sizeof(ip), "[<%p>]",
74386 + snprintf(ip, sizeof(ip), "[<%pK>]",
74387 (void *)class->contending_point[i]);
74388 seq_printf(m, "%40s %14lu %29s %pS\n",
74389 name, stats->contending_point[i],
74390 diff --git a/kernel/module.c b/kernel/module.c
74391 index eab0827..f488603 100644
74392 --- a/kernel/module.c
74393 +++ b/kernel/module.c
74394 @@ -61,6 +61,7 @@
74395 #include <linux/pfn.h>
74396 #include <linux/bsearch.h>
74397 #include <linux/fips.h>
74398 +#include <linux/grsecurity.h>
74399 #include <uapi/linux/module.h>
74400 #include "module-internal.h"
74401
74402 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
74403
74404 /* Bounds of module allocation, for speeding __module_address.
74405 * Protected by module_mutex. */
74406 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
74407 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
74408 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
74409
74410 int register_module_notifier(struct notifier_block * nb)
74411 {
74412 @@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
74413 return true;
74414
74415 list_for_each_entry_rcu(mod, &modules, list) {
74416 - struct symsearch arr[] = {
74417 + struct symsearch modarr[] = {
74418 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
74419 NOT_GPL_ONLY, false },
74420 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
74421 @@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
74422 if (mod->state == MODULE_STATE_UNFORMED)
74423 continue;
74424
74425 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
74426 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
74427 return true;
74428 }
74429 return false;
74430 @@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
74431 static int percpu_modalloc(struct module *mod,
74432 unsigned long size, unsigned long align)
74433 {
74434 - if (align > PAGE_SIZE) {
74435 + if (align-1 >= PAGE_SIZE) {
74436 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
74437 mod->name, align, PAGE_SIZE);
74438 align = PAGE_SIZE;
74439 @@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
74440 static ssize_t show_coresize(struct module_attribute *mattr,
74441 struct module_kobject *mk, char *buffer)
74442 {
74443 - return sprintf(buffer, "%u\n", mk->mod->core_size);
74444 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
74445 }
74446
74447 static struct module_attribute modinfo_coresize =
74448 @@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
74449 static ssize_t show_initsize(struct module_attribute *mattr,
74450 struct module_kobject *mk, char *buffer)
74451 {
74452 - return sprintf(buffer, "%u\n", mk->mod->init_size);
74453 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
74454 }
74455
74456 static struct module_attribute modinfo_initsize =
74457 @@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
74458 */
74459 #ifdef CONFIG_SYSFS
74460
74461 -#ifdef CONFIG_KALLSYMS
74462 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74463 static inline bool sect_empty(const Elf_Shdr *sect)
74464 {
74465 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
74466 @@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
74467 {
74468 unsigned int notes, loaded, i;
74469 struct module_notes_attrs *notes_attrs;
74470 - struct bin_attribute *nattr;
74471 + bin_attribute_no_const *nattr;
74472
74473 /* failed to create section attributes, so can't create notes */
74474 if (!mod->sect_attrs)
74475 @@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
74476 static int module_add_modinfo_attrs(struct module *mod)
74477 {
74478 struct module_attribute *attr;
74479 - struct module_attribute *temp_attr;
74480 + module_attribute_no_const *temp_attr;
74481 int error = 0;
74482 int i;
74483
74484 @@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
74485
74486 static void unset_module_core_ro_nx(struct module *mod)
74487 {
74488 - set_page_attributes(mod->module_core + mod->core_text_size,
74489 - mod->module_core + mod->core_size,
74490 + set_page_attributes(mod->module_core_rw,
74491 + mod->module_core_rw + mod->core_size_rw,
74492 set_memory_x);
74493 - set_page_attributes(mod->module_core,
74494 - mod->module_core + mod->core_ro_size,
74495 + set_page_attributes(mod->module_core_rx,
74496 + mod->module_core_rx + mod->core_size_rx,
74497 set_memory_rw);
74498 }
74499
74500 static void unset_module_init_ro_nx(struct module *mod)
74501 {
74502 - set_page_attributes(mod->module_init + mod->init_text_size,
74503 - mod->module_init + mod->init_size,
74504 + set_page_attributes(mod->module_init_rw,
74505 + mod->module_init_rw + mod->init_size_rw,
74506 set_memory_x);
74507 - set_page_attributes(mod->module_init,
74508 - mod->module_init + mod->init_ro_size,
74509 + set_page_attributes(mod->module_init_rx,
74510 + mod->module_init_rx + mod->init_size_rx,
74511 set_memory_rw);
74512 }
74513
74514 @@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
74515 list_for_each_entry_rcu(mod, &modules, list) {
74516 if (mod->state == MODULE_STATE_UNFORMED)
74517 continue;
74518 - if ((mod->module_core) && (mod->core_text_size)) {
74519 - set_page_attributes(mod->module_core,
74520 - mod->module_core + mod->core_text_size,
74521 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
74522 + set_page_attributes(mod->module_core_rx,
74523 + mod->module_core_rx + mod->core_size_rx,
74524 set_memory_rw);
74525 }
74526 - if ((mod->module_init) && (mod->init_text_size)) {
74527 - set_page_attributes(mod->module_init,
74528 - mod->module_init + mod->init_text_size,
74529 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
74530 + set_page_attributes(mod->module_init_rx,
74531 + mod->module_init_rx + mod->init_size_rx,
74532 set_memory_rw);
74533 }
74534 }
74535 @@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
74536 list_for_each_entry_rcu(mod, &modules, list) {
74537 if (mod->state == MODULE_STATE_UNFORMED)
74538 continue;
74539 - if ((mod->module_core) && (mod->core_text_size)) {
74540 - set_page_attributes(mod->module_core,
74541 - mod->module_core + mod->core_text_size,
74542 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
74543 + set_page_attributes(mod->module_core_rx,
74544 + mod->module_core_rx + mod->core_size_rx,
74545 set_memory_ro);
74546 }
74547 - if ((mod->module_init) && (mod->init_text_size)) {
74548 - set_page_attributes(mod->module_init,
74549 - mod->module_init + mod->init_text_size,
74550 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
74551 + set_page_attributes(mod->module_init_rx,
74552 + mod->module_init_rx + mod->init_size_rx,
74553 set_memory_ro);
74554 }
74555 }
74556 @@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
74557
74558 /* This may be NULL, but that's OK */
74559 unset_module_init_ro_nx(mod);
74560 - module_free(mod, mod->module_init);
74561 + module_free(mod, mod->module_init_rw);
74562 + module_free_exec(mod, mod->module_init_rx);
74563 kfree(mod->args);
74564 percpu_modfree(mod);
74565
74566 /* Free lock-classes: */
74567 - lockdep_free_key_range(mod->module_core, mod->core_size);
74568 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
74569 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
74570
74571 /* Finally, free the core (containing the module structure) */
74572 unset_module_core_ro_nx(mod);
74573 - module_free(mod, mod->module_core);
74574 + module_free_exec(mod, mod->module_core_rx);
74575 + module_free(mod, mod->module_core_rw);
74576
74577 #ifdef CONFIG_MPU
74578 update_protections(current->mm);
74579 @@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74580 int ret = 0;
74581 const struct kernel_symbol *ksym;
74582
74583 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74584 + int is_fs_load = 0;
74585 + int register_filesystem_found = 0;
74586 + char *p;
74587 +
74588 + p = strstr(mod->args, "grsec_modharden_fs");
74589 + if (p) {
74590 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
74591 + /* copy \0 as well */
74592 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
74593 + is_fs_load = 1;
74594 + }
74595 +#endif
74596 +
74597 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
74598 const char *name = info->strtab + sym[i].st_name;
74599
74600 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74601 + /* it's a real shame this will never get ripped and copied
74602 + upstream! ;(
74603 + */
74604 + if (is_fs_load && !strcmp(name, "register_filesystem"))
74605 + register_filesystem_found = 1;
74606 +#endif
74607 +
74608 switch (sym[i].st_shndx) {
74609 case SHN_COMMON:
74610 /* We compiled with -fno-common. These are not
74611 @@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74612 ksym = resolve_symbol_wait(mod, info, name);
74613 /* Ok if resolved. */
74614 if (ksym && !IS_ERR(ksym)) {
74615 + pax_open_kernel();
74616 sym[i].st_value = ksym->value;
74617 + pax_close_kernel();
74618 break;
74619 }
74620
74621 @@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74622 secbase = (unsigned long)mod_percpu(mod);
74623 else
74624 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
74625 + pax_open_kernel();
74626 sym[i].st_value += secbase;
74627 + pax_close_kernel();
74628 break;
74629 }
74630 }
74631
74632 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74633 + if (is_fs_load && !register_filesystem_found) {
74634 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
74635 + ret = -EPERM;
74636 + }
74637 +#endif
74638 +
74639 return ret;
74640 }
74641
74642 @@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
74643 || s->sh_entsize != ~0UL
74644 || strstarts(sname, ".init"))
74645 continue;
74646 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
74647 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
74648 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
74649 + else
74650 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
74651 pr_debug("\t%s\n", sname);
74652 }
74653 - switch (m) {
74654 - case 0: /* executable */
74655 - mod->core_size = debug_align(mod->core_size);
74656 - mod->core_text_size = mod->core_size;
74657 - break;
74658 - case 1: /* RO: text and ro-data */
74659 - mod->core_size = debug_align(mod->core_size);
74660 - mod->core_ro_size = mod->core_size;
74661 - break;
74662 - case 3: /* whole core */
74663 - mod->core_size = debug_align(mod->core_size);
74664 - break;
74665 - }
74666 }
74667
74668 pr_debug("Init section allocation order:\n");
74669 @@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
74670 || s->sh_entsize != ~0UL
74671 || !strstarts(sname, ".init"))
74672 continue;
74673 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
74674 - | INIT_OFFSET_MASK);
74675 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
74676 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
74677 + else
74678 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
74679 + s->sh_entsize |= INIT_OFFSET_MASK;
74680 pr_debug("\t%s\n", sname);
74681 }
74682 - switch (m) {
74683 - case 0: /* executable */
74684 - mod->init_size = debug_align(mod->init_size);
74685 - mod->init_text_size = mod->init_size;
74686 - break;
74687 - case 1: /* RO: text and ro-data */
74688 - mod->init_size = debug_align(mod->init_size);
74689 - mod->init_ro_size = mod->init_size;
74690 - break;
74691 - case 3: /* whole init */
74692 - mod->init_size = debug_align(mod->init_size);
74693 - break;
74694 - }
74695 }
74696 }
74697
74698 @@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
74699
74700 /* Put symbol section at end of init part of module. */
74701 symsect->sh_flags |= SHF_ALLOC;
74702 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
74703 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
74704 info->index.sym) | INIT_OFFSET_MASK;
74705 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
74706
74707 @@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
74708 }
74709
74710 /* Append room for core symbols at end of core part. */
74711 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
74712 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
74713 - mod->core_size += strtab_size;
74714 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
74715 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
74716 + mod->core_size_rx += strtab_size;
74717
74718 /* Put string table section at end of init part of module. */
74719 strsect->sh_flags |= SHF_ALLOC;
74720 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
74721 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
74722 info->index.str) | INIT_OFFSET_MASK;
74723 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
74724 }
74725 @@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
74726 /* Make sure we get permanent strtab: don't use info->strtab. */
74727 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
74728
74729 + pax_open_kernel();
74730 +
74731 /* Set types up while we still have access to sections. */
74732 for (i = 0; i < mod->num_symtab; i++)
74733 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
74734
74735 - mod->core_symtab = dst = mod->module_core + info->symoffs;
74736 - mod->core_strtab = s = mod->module_core + info->stroffs;
74737 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
74738 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
74739 src = mod->symtab;
74740 for (ndst = i = 0; i < mod->num_symtab; i++) {
74741 if (i == 0 ||
74742 @@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
74743 }
74744 }
74745 mod->core_num_syms = ndst;
74746 +
74747 + pax_close_kernel();
74748 }
74749 #else
74750 static inline void layout_symtab(struct module *mod, struct load_info *info)
74751 @@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
74752 return vmalloc_exec(size);
74753 }
74754
74755 -static void *module_alloc_update_bounds(unsigned long size)
74756 +static void *module_alloc_update_bounds_rw(unsigned long size)
74757 {
74758 void *ret = module_alloc(size);
74759
74760 if (ret) {
74761 mutex_lock(&module_mutex);
74762 /* Update module bounds. */
74763 - if ((unsigned long)ret < module_addr_min)
74764 - module_addr_min = (unsigned long)ret;
74765 - if ((unsigned long)ret + size > module_addr_max)
74766 - module_addr_max = (unsigned long)ret + size;
74767 + if ((unsigned long)ret < module_addr_min_rw)
74768 + module_addr_min_rw = (unsigned long)ret;
74769 + if ((unsigned long)ret + size > module_addr_max_rw)
74770 + module_addr_max_rw = (unsigned long)ret + size;
74771 + mutex_unlock(&module_mutex);
74772 + }
74773 + return ret;
74774 +}
74775 +
74776 +static void *module_alloc_update_bounds_rx(unsigned long size)
74777 +{
74778 + void *ret = module_alloc_exec(size);
74779 +
74780 + if (ret) {
74781 + mutex_lock(&module_mutex);
74782 + /* Update module bounds. */
74783 + if ((unsigned long)ret < module_addr_min_rx)
74784 + module_addr_min_rx = (unsigned long)ret;
74785 + if ((unsigned long)ret + size > module_addr_max_rx)
74786 + module_addr_max_rx = (unsigned long)ret + size;
74787 mutex_unlock(&module_mutex);
74788 }
74789 return ret;
74790 @@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
74791 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
74792 {
74793 const char *modmagic = get_modinfo(info, "vermagic");
74794 + const char *license = get_modinfo(info, "license");
74795 int err;
74796
74797 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
74798 + if (!license || !license_is_gpl_compatible(license))
74799 + return -ENOEXEC;
74800 +#endif
74801 +
74802 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
74803 modmagic = NULL;
74804
74805 @@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
74806 }
74807
74808 /* Set up license info based on the info section */
74809 - set_license(mod, get_modinfo(info, "license"));
74810 + set_license(mod, license);
74811
74812 return 0;
74813 }
74814 @@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
74815 void *ptr;
74816
74817 /* Do the allocs. */
74818 - ptr = module_alloc_update_bounds(mod->core_size);
74819 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
74820 /*
74821 * The pointer to this block is stored in the module structure
74822 * which is inside the block. Just mark it as not being a
74823 @@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
74824 if (!ptr)
74825 return -ENOMEM;
74826
74827 - memset(ptr, 0, mod->core_size);
74828 - mod->module_core = ptr;
74829 + memset(ptr, 0, mod->core_size_rw);
74830 + mod->module_core_rw = ptr;
74831
74832 - if (mod->init_size) {
74833 - ptr = module_alloc_update_bounds(mod->init_size);
74834 + if (mod->init_size_rw) {
74835 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
74836 /*
74837 * The pointer to this block is stored in the module structure
74838 * which is inside the block. This block doesn't need to be
74839 @@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
74840 */
74841 kmemleak_ignore(ptr);
74842 if (!ptr) {
74843 - module_free(mod, mod->module_core);
74844 + module_free(mod, mod->module_core_rw);
74845 return -ENOMEM;
74846 }
74847 - memset(ptr, 0, mod->init_size);
74848 - mod->module_init = ptr;
74849 + memset(ptr, 0, mod->init_size_rw);
74850 + mod->module_init_rw = ptr;
74851 } else
74852 - mod->module_init = NULL;
74853 + mod->module_init_rw = NULL;
74854 +
74855 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
74856 + kmemleak_not_leak(ptr);
74857 + if (!ptr) {
74858 + if (mod->module_init_rw)
74859 + module_free(mod, mod->module_init_rw);
74860 + module_free(mod, mod->module_core_rw);
74861 + return -ENOMEM;
74862 + }
74863 +
74864 + pax_open_kernel();
74865 + memset(ptr, 0, mod->core_size_rx);
74866 + pax_close_kernel();
74867 + mod->module_core_rx = ptr;
74868 +
74869 + if (mod->init_size_rx) {
74870 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
74871 + kmemleak_ignore(ptr);
74872 + if (!ptr && mod->init_size_rx) {
74873 + module_free_exec(mod, mod->module_core_rx);
74874 + if (mod->module_init_rw)
74875 + module_free(mod, mod->module_init_rw);
74876 + module_free(mod, mod->module_core_rw);
74877 + return -ENOMEM;
74878 + }
74879 +
74880 + pax_open_kernel();
74881 + memset(ptr, 0, mod->init_size_rx);
74882 + pax_close_kernel();
74883 + mod->module_init_rx = ptr;
74884 + } else
74885 + mod->module_init_rx = NULL;
74886
74887 /* Transfer each section which specifies SHF_ALLOC */
74888 pr_debug("final section addresses:\n");
74889 @@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
74890 if (!(shdr->sh_flags & SHF_ALLOC))
74891 continue;
74892
74893 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
74894 - dest = mod->module_init
74895 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74896 - else
74897 - dest = mod->module_core + shdr->sh_entsize;
74898 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
74899 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
74900 + dest = mod->module_init_rw
74901 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74902 + else
74903 + dest = mod->module_init_rx
74904 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74905 + } else {
74906 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
74907 + dest = mod->module_core_rw + shdr->sh_entsize;
74908 + else
74909 + dest = mod->module_core_rx + shdr->sh_entsize;
74910 + }
74911 +
74912 + if (shdr->sh_type != SHT_NOBITS) {
74913 +
74914 +#ifdef CONFIG_PAX_KERNEXEC
74915 +#ifdef CONFIG_X86_64
74916 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
74917 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
74918 +#endif
74919 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
74920 + pax_open_kernel();
74921 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
74922 + pax_close_kernel();
74923 + } else
74924 +#endif
74925
74926 - if (shdr->sh_type != SHT_NOBITS)
74927 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
74928 + }
74929 /* Update sh_addr to point to copy in image. */
74930 - shdr->sh_addr = (unsigned long)dest;
74931 +
74932 +#ifdef CONFIG_PAX_KERNEXEC
74933 + if (shdr->sh_flags & SHF_EXECINSTR)
74934 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
74935 + else
74936 +#endif
74937 +
74938 + shdr->sh_addr = (unsigned long)dest;
74939 pr_debug("\t0x%lx %s\n",
74940 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
74941 }
74942 @@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
74943 * Do it before processing of module parameters, so the module
74944 * can provide parameter accessor functions of its own.
74945 */
74946 - if (mod->module_init)
74947 - flush_icache_range((unsigned long)mod->module_init,
74948 - (unsigned long)mod->module_init
74949 - + mod->init_size);
74950 - flush_icache_range((unsigned long)mod->module_core,
74951 - (unsigned long)mod->module_core + mod->core_size);
74952 + if (mod->module_init_rx)
74953 + flush_icache_range((unsigned long)mod->module_init_rx,
74954 + (unsigned long)mod->module_init_rx
74955 + + mod->init_size_rx);
74956 + flush_icache_range((unsigned long)mod->module_core_rx,
74957 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
74958
74959 set_fs(old_fs);
74960 }
74961 @@ -2983,8 +3088,10 @@ out:
74962 static void module_deallocate(struct module *mod, struct load_info *info)
74963 {
74964 percpu_modfree(mod);
74965 - module_free(mod, mod->module_init);
74966 - module_free(mod, mod->module_core);
74967 + module_free_exec(mod, mod->module_init_rx);
74968 + module_free_exec(mod, mod->module_core_rx);
74969 + module_free(mod, mod->module_init_rw);
74970 + module_free(mod, mod->module_core_rw);
74971 }
74972
74973 int __weak module_finalize(const Elf_Ehdr *hdr,
74974 @@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
74975 static int post_relocation(struct module *mod, const struct load_info *info)
74976 {
74977 /* Sort exception table now relocations are done. */
74978 + pax_open_kernel();
74979 sort_extable(mod->extable, mod->extable + mod->num_exentries);
74980 + pax_close_kernel();
74981
74982 /* Copy relocated percpu area over. */
74983 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
74984 @@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
74985 MODULE_STATE_COMING, mod);
74986
74987 /* Set RO and NX regions for core */
74988 - set_section_ro_nx(mod->module_core,
74989 - mod->core_text_size,
74990 - mod->core_ro_size,
74991 - mod->core_size);
74992 + set_section_ro_nx(mod->module_core_rx,
74993 + mod->core_size_rx,
74994 + mod->core_size_rx,
74995 + mod->core_size_rx);
74996
74997 /* Set RO and NX regions for init */
74998 - set_section_ro_nx(mod->module_init,
74999 - mod->init_text_size,
75000 - mod->init_ro_size,
75001 - mod->init_size);
75002 + set_section_ro_nx(mod->module_init_rx,
75003 + mod->init_size_rx,
75004 + mod->init_size_rx,
75005 + mod->init_size_rx);
75006
75007 do_mod_ctors(mod);
75008 /* Start the module */
75009 @@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
75010 mod->strtab = mod->core_strtab;
75011 #endif
75012 unset_module_init_ro_nx(mod);
75013 - module_free(mod, mod->module_init);
75014 - mod->module_init = NULL;
75015 - mod->init_size = 0;
75016 - mod->init_ro_size = 0;
75017 - mod->init_text_size = 0;
75018 + module_free(mod, mod->module_init_rw);
75019 + module_free_exec(mod, mod->module_init_rx);
75020 + mod->module_init_rw = NULL;
75021 + mod->module_init_rx = NULL;
75022 + mod->init_size_rw = 0;
75023 + mod->init_size_rx = 0;
75024 mutex_unlock(&module_mutex);
75025 wake_up_all(&module_wq);
75026
75027 @@ -3209,9 +3319,38 @@ again:
75028 if (err)
75029 goto free_unload;
75030
75031 + /* Now copy in args */
75032 + mod->args = strndup_user(uargs, ~0UL >> 1);
75033 + if (IS_ERR(mod->args)) {
75034 + err = PTR_ERR(mod->args);
75035 + goto free_unload;
75036 + }
75037 +
75038 /* Set up MODINFO_ATTR fields */
75039 setup_modinfo(mod, info);
75040
75041 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75042 + {
75043 + char *p, *p2;
75044 +
75045 + if (strstr(mod->args, "grsec_modharden_netdev")) {
75046 + 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);
75047 + err = -EPERM;
75048 + goto free_modinfo;
75049 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
75050 + p += sizeof("grsec_modharden_normal") - 1;
75051 + p2 = strstr(p, "_");
75052 + if (p2) {
75053 + *p2 = '\0';
75054 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
75055 + *p2 = '_';
75056 + }
75057 + err = -EPERM;
75058 + goto free_modinfo;
75059 + }
75060 + }
75061 +#endif
75062 +
75063 /* Fix up syms, so that st_value is a pointer to location. */
75064 err = simplify_symbols(mod, info);
75065 if (err < 0)
75066 @@ -3227,13 +3366,6 @@ again:
75067
75068 flush_module_icache(mod);
75069
75070 - /* Now copy in args */
75071 - mod->args = strndup_user(uargs, ~0UL >> 1);
75072 - if (IS_ERR(mod->args)) {
75073 - err = PTR_ERR(mod->args);
75074 - goto free_arch_cleanup;
75075 - }
75076 -
75077 dynamic_debug_setup(info->debug, info->num_debug);
75078
75079 mutex_lock(&module_mutex);
75080 @@ -3278,11 +3410,10 @@ again:
75081 mutex_unlock(&module_mutex);
75082 dynamic_debug_remove(info->debug);
75083 synchronize_sched();
75084 - kfree(mod->args);
75085 - free_arch_cleanup:
75086 module_arch_cleanup(mod);
75087 free_modinfo:
75088 free_modinfo(mod);
75089 + kfree(mod->args);
75090 free_unload:
75091 module_unload_free(mod);
75092 unlink_mod:
75093 @@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
75094 unsigned long nextval;
75095
75096 /* At worse, next value is at end of module */
75097 - if (within_module_init(addr, mod))
75098 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
75099 + if (within_module_init_rx(addr, mod))
75100 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
75101 + else if (within_module_init_rw(addr, mod))
75102 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
75103 + else if (within_module_core_rx(addr, mod))
75104 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
75105 + else if (within_module_core_rw(addr, mod))
75106 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
75107 else
75108 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
75109 + return NULL;
75110
75111 /* Scan for closest preceding symbol, and next symbol. (ELF
75112 starts real symbols at 1). */
75113 @@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
75114 return 0;
75115
75116 seq_printf(m, "%s %u",
75117 - mod->name, mod->init_size + mod->core_size);
75118 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
75119 print_unload_info(m, mod);
75120
75121 /* Informative for users. */
75122 @@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
75123 mod->state == MODULE_STATE_COMING ? "Loading":
75124 "Live");
75125 /* Used by oprofile and other similar tools. */
75126 - seq_printf(m, " 0x%pK", mod->module_core);
75127 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
75128
75129 /* Taints info */
75130 if (mod->taints)
75131 @@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
75132
75133 static int __init proc_modules_init(void)
75134 {
75135 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75136 +#ifdef CONFIG_GRKERNSEC_PROC_USER
75137 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75138 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75139 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
75140 +#else
75141 proc_create("modules", 0, NULL, &proc_modules_operations);
75142 +#endif
75143 +#else
75144 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75145 +#endif
75146 return 0;
75147 }
75148 module_init(proc_modules_init);
75149 @@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
75150 {
75151 struct module *mod;
75152
75153 - if (addr < module_addr_min || addr > module_addr_max)
75154 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
75155 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
75156 return NULL;
75157
75158 list_for_each_entry_rcu(mod, &modules, list) {
75159 if (mod->state == MODULE_STATE_UNFORMED)
75160 continue;
75161 - if (within_module_core(addr, mod)
75162 - || within_module_init(addr, mod))
75163 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
75164 return mod;
75165 }
75166 return NULL;
75167 @@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
75168 */
75169 struct module *__module_text_address(unsigned long addr)
75170 {
75171 - struct module *mod = __module_address(addr);
75172 + struct module *mod;
75173 +
75174 +#ifdef CONFIG_X86_32
75175 + addr = ktla_ktva(addr);
75176 +#endif
75177 +
75178 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
75179 + return NULL;
75180 +
75181 + mod = __module_address(addr);
75182 +
75183 if (mod) {
75184 /* Make sure it's within the text section. */
75185 - if (!within(addr, mod->module_init, mod->init_text_size)
75186 - && !within(addr, mod->module_core, mod->core_text_size))
75187 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
75188 mod = NULL;
75189 }
75190 return mod;
75191 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
75192 index 7e3443f..b2a1e6b 100644
75193 --- a/kernel/mutex-debug.c
75194 +++ b/kernel/mutex-debug.c
75195 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
75196 }
75197
75198 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75199 - struct thread_info *ti)
75200 + struct task_struct *task)
75201 {
75202 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
75203
75204 /* Mark the current thread as blocked on the lock: */
75205 - ti->task->blocked_on = waiter;
75206 + task->blocked_on = waiter;
75207 }
75208
75209 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75210 - struct thread_info *ti)
75211 + struct task_struct *task)
75212 {
75213 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
75214 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
75215 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
75216 - ti->task->blocked_on = NULL;
75217 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
75218 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
75219 + task->blocked_on = NULL;
75220
75221 list_del_init(&waiter->list);
75222 waiter->task = NULL;
75223 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
75224 index 0799fd3..d06ae3b 100644
75225 --- a/kernel/mutex-debug.h
75226 +++ b/kernel/mutex-debug.h
75227 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
75228 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
75229 extern void debug_mutex_add_waiter(struct mutex *lock,
75230 struct mutex_waiter *waiter,
75231 - struct thread_info *ti);
75232 + struct task_struct *task);
75233 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75234 - struct thread_info *ti);
75235 + struct task_struct *task);
75236 extern void debug_mutex_unlock(struct mutex *lock);
75237 extern void debug_mutex_init(struct mutex *lock, const char *name,
75238 struct lock_class_key *key);
75239 diff --git a/kernel/mutex.c b/kernel/mutex.c
75240 index a307cc9..27fd2e9 100644
75241 --- a/kernel/mutex.c
75242 +++ b/kernel/mutex.c
75243 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75244 spin_lock_mutex(&lock->wait_lock, flags);
75245
75246 debug_mutex_lock_common(lock, &waiter);
75247 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
75248 + debug_mutex_add_waiter(lock, &waiter, task);
75249
75250 /* add waiting tasks to the end of the waitqueue (FIFO): */
75251 list_add_tail(&waiter.list, &lock->wait_list);
75252 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75253 * TASK_UNINTERRUPTIBLE case.)
75254 */
75255 if (unlikely(signal_pending_state(state, task))) {
75256 - mutex_remove_waiter(lock, &waiter,
75257 - task_thread_info(task));
75258 + mutex_remove_waiter(lock, &waiter, task);
75259 mutex_release(&lock->dep_map, 1, ip);
75260 spin_unlock_mutex(&lock->wait_lock, flags);
75261
75262 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75263 done:
75264 lock_acquired(&lock->dep_map, ip);
75265 /* got the lock - rejoice! */
75266 - mutex_remove_waiter(lock, &waiter, current_thread_info());
75267 + mutex_remove_waiter(lock, &waiter, task);
75268 mutex_set_owner(lock);
75269
75270 /* set it to 0 if there are no waiters left: */
75271 diff --git a/kernel/notifier.c b/kernel/notifier.c
75272 index 2d5cc4c..d9ea600 100644
75273 --- a/kernel/notifier.c
75274 +++ b/kernel/notifier.c
75275 @@ -5,6 +5,7 @@
75276 #include <linux/rcupdate.h>
75277 #include <linux/vmalloc.h>
75278 #include <linux/reboot.h>
75279 +#include <linux/mm.h>
75280
75281 /*
75282 * Notifier list for kernel code which wants to be called
75283 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
75284 while ((*nl) != NULL) {
75285 if (n->priority > (*nl)->priority)
75286 break;
75287 - nl = &((*nl)->next);
75288 + nl = (struct notifier_block **)&((*nl)->next);
75289 }
75290 - n->next = *nl;
75291 + pax_open_kernel();
75292 + *(const void **)&n->next = *nl;
75293 rcu_assign_pointer(*nl, n);
75294 + pax_close_kernel();
75295 return 0;
75296 }
75297
75298 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
75299 return 0;
75300 if (n->priority > (*nl)->priority)
75301 break;
75302 - nl = &((*nl)->next);
75303 + nl = (struct notifier_block **)&((*nl)->next);
75304 }
75305 - n->next = *nl;
75306 + pax_open_kernel();
75307 + *(const void **)&n->next = *nl;
75308 rcu_assign_pointer(*nl, n);
75309 + pax_close_kernel();
75310 return 0;
75311 }
75312
75313 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
75314 {
75315 while ((*nl) != NULL) {
75316 if ((*nl) == n) {
75317 + pax_open_kernel();
75318 rcu_assign_pointer(*nl, n->next);
75319 + pax_close_kernel();
75320 return 0;
75321 }
75322 - nl = &((*nl)->next);
75323 + nl = (struct notifier_block **)&((*nl)->next);
75324 }
75325 return -ENOENT;
75326 }
75327 diff --git a/kernel/panic.c b/kernel/panic.c
75328 index e1b2822..5edc1d9 100644
75329 --- a/kernel/panic.c
75330 +++ b/kernel/panic.c
75331 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
75332 const char *board;
75333
75334 printk(KERN_WARNING "------------[ cut here ]------------\n");
75335 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
75336 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
75337 board = dmi_get_system_info(DMI_PRODUCT_NAME);
75338 if (board)
75339 printk(KERN_WARNING "Hardware name: %s\n", board);
75340 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
75341 */
75342 void __stack_chk_fail(void)
75343 {
75344 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
75345 + dump_stack();
75346 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
75347 __builtin_return_address(0));
75348 }
75349 EXPORT_SYMBOL(__stack_chk_fail);
75350 diff --git a/kernel/pid.c b/kernel/pid.c
75351 index f2c6a68..4922d97 100644
75352 --- a/kernel/pid.c
75353 +++ b/kernel/pid.c
75354 @@ -33,6 +33,7 @@
75355 #include <linux/rculist.h>
75356 #include <linux/bootmem.h>
75357 #include <linux/hash.h>
75358 +#include <linux/security.h>
75359 #include <linux/pid_namespace.h>
75360 #include <linux/init_task.h>
75361 #include <linux/syscalls.h>
75362 @@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
75363
75364 int pid_max = PID_MAX_DEFAULT;
75365
75366 -#define RESERVED_PIDS 300
75367 +#define RESERVED_PIDS 500
75368
75369 int pid_max_min = RESERVED_PIDS + 1;
75370 int pid_max_max = PID_MAX_LIMIT;
75371 @@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
75372 */
75373 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
75374 {
75375 + struct task_struct *task;
75376 +
75377 rcu_lockdep_assert(rcu_read_lock_held(),
75378 "find_task_by_pid_ns() needs rcu_read_lock()"
75379 " protection");
75380 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
75381 +
75382 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
75383 +
75384 + if (gr_pid_is_chrooted(task))
75385 + return NULL;
75386 +
75387 + return task;
75388 }
75389
75390 struct task_struct *find_task_by_vpid(pid_t vnr)
75391 @@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
75392 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
75393 }
75394
75395 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
75396 +{
75397 + rcu_lockdep_assert(rcu_read_lock_held(),
75398 + "find_task_by_pid_ns() needs rcu_read_lock()"
75399 + " protection");
75400 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
75401 +}
75402 +
75403 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
75404 {
75405 struct pid *pid;
75406 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
75407 index c1c3dc1..bbeaf31 100644
75408 --- a/kernel/pid_namespace.c
75409 +++ b/kernel/pid_namespace.c
75410 @@ -248,7 +248,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
75411 void __user *buffer, size_t *lenp, loff_t *ppos)
75412 {
75413 struct pid_namespace *pid_ns = task_active_pid_ns(current);
75414 - struct ctl_table tmp = *table;
75415 + ctl_table_no_const tmp = *table;
75416
75417 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
75418 return -EPERM;
75419 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
75420 index 942ca27..111e609 100644
75421 --- a/kernel/posix-cpu-timers.c
75422 +++ b/kernel/posix-cpu-timers.c
75423 @@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
75424
75425 static __init int init_posix_cpu_timers(void)
75426 {
75427 - struct k_clock process = {
75428 + static struct k_clock process = {
75429 .clock_getres = process_cpu_clock_getres,
75430 .clock_get = process_cpu_clock_get,
75431 .timer_create = process_cpu_timer_create,
75432 .nsleep = process_cpu_nsleep,
75433 .nsleep_restart = process_cpu_nsleep_restart,
75434 };
75435 - struct k_clock thread = {
75436 + static struct k_clock thread = {
75437 .clock_getres = thread_cpu_clock_getres,
75438 .clock_get = thread_cpu_clock_get,
75439 .timer_create = thread_cpu_timer_create,
75440 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
75441 index e885be1..380fe76 100644
75442 --- a/kernel/posix-timers.c
75443 +++ b/kernel/posix-timers.c
75444 @@ -43,6 +43,7 @@
75445 #include <linux/idr.h>
75446 #include <linux/posix-clock.h>
75447 #include <linux/posix-timers.h>
75448 +#include <linux/grsecurity.h>
75449 #include <linux/syscalls.h>
75450 #include <linux/wait.h>
75451 #include <linux/workqueue.h>
75452 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
75453 * which we beg off on and pass to do_sys_settimeofday().
75454 */
75455
75456 -static struct k_clock posix_clocks[MAX_CLOCKS];
75457 +static struct k_clock *posix_clocks[MAX_CLOCKS];
75458
75459 /*
75460 * These ones are defined below.
75461 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
75462 */
75463 static __init int init_posix_timers(void)
75464 {
75465 - struct k_clock clock_realtime = {
75466 + static struct k_clock clock_realtime = {
75467 .clock_getres = hrtimer_get_res,
75468 .clock_get = posix_clock_realtime_get,
75469 .clock_set = posix_clock_realtime_set,
75470 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
75471 .timer_get = common_timer_get,
75472 .timer_del = common_timer_del,
75473 };
75474 - struct k_clock clock_monotonic = {
75475 + static struct k_clock clock_monotonic = {
75476 .clock_getres = hrtimer_get_res,
75477 .clock_get = posix_ktime_get_ts,
75478 .nsleep = common_nsleep,
75479 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
75480 .timer_get = common_timer_get,
75481 .timer_del = common_timer_del,
75482 };
75483 - struct k_clock clock_monotonic_raw = {
75484 + static struct k_clock clock_monotonic_raw = {
75485 .clock_getres = hrtimer_get_res,
75486 .clock_get = posix_get_monotonic_raw,
75487 };
75488 - struct k_clock clock_realtime_coarse = {
75489 + static struct k_clock clock_realtime_coarse = {
75490 .clock_getres = posix_get_coarse_res,
75491 .clock_get = posix_get_realtime_coarse,
75492 };
75493 - struct k_clock clock_monotonic_coarse = {
75494 + static struct k_clock clock_monotonic_coarse = {
75495 .clock_getres = posix_get_coarse_res,
75496 .clock_get = posix_get_monotonic_coarse,
75497 };
75498 - struct k_clock clock_boottime = {
75499 + static struct k_clock clock_boottime = {
75500 .clock_getres = hrtimer_get_res,
75501 .clock_get = posix_get_boottime,
75502 .nsleep = common_nsleep,
75503 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
75504 return;
75505 }
75506
75507 - posix_clocks[clock_id] = *new_clock;
75508 + posix_clocks[clock_id] = new_clock;
75509 }
75510 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
75511
75512 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
75513 return (id & CLOCKFD_MASK) == CLOCKFD ?
75514 &clock_posix_dynamic : &clock_posix_cpu;
75515
75516 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
75517 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
75518 return NULL;
75519 - return &posix_clocks[id];
75520 + return posix_clocks[id];
75521 }
75522
75523 static int common_timer_create(struct k_itimer *new_timer)
75524 @@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
75525 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
75526 return -EFAULT;
75527
75528 + /* only the CLOCK_REALTIME clock can be set, all other clocks
75529 + have their clock_set fptr set to a nosettime dummy function
75530 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
75531 + call common_clock_set, which calls do_sys_settimeofday, which
75532 + we hook
75533 + */
75534 +
75535 return kc->clock_set(which_clock, &new_tp);
75536 }
75537
75538 diff --git a/kernel/power/process.c b/kernel/power/process.c
75539 index d5a258b..4271191 100644
75540 --- a/kernel/power/process.c
75541 +++ b/kernel/power/process.c
75542 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
75543 u64 elapsed_csecs64;
75544 unsigned int elapsed_csecs;
75545 bool wakeup = false;
75546 + bool timedout = false;
75547
75548 do_gettimeofday(&start);
75549
75550 @@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
75551
75552 while (true) {
75553 todo = 0;
75554 + if (time_after(jiffies, end_time))
75555 + timedout = true;
75556 read_lock(&tasklist_lock);
75557 do_each_thread(g, p) {
75558 if (p == current || !freeze_task(p))
75559 continue;
75560
75561 - if (!freezer_should_skip(p))
75562 + if (!freezer_should_skip(p)) {
75563 todo++;
75564 + if (timedout) {
75565 + printk(KERN_ERR "Task refusing to freeze:\n");
75566 + sched_show_task(p);
75567 + }
75568 + }
75569 } while_each_thread(g, p);
75570 read_unlock(&tasklist_lock);
75571
75572 @@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
75573 todo += wq_busy;
75574 }
75575
75576 - if (!todo || time_after(jiffies, end_time))
75577 + if (!todo || timedout)
75578 break;
75579
75580 if (pm_wakeup_pending()) {
75581 diff --git a/kernel/printk.c b/kernel/printk.c
75582 index 267ce78..2487112 100644
75583 --- a/kernel/printk.c
75584 +++ b/kernel/printk.c
75585 @@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
75586 return ret;
75587 }
75588
75589 +static int check_syslog_permissions(int type, bool from_file);
75590 +
75591 static int devkmsg_open(struct inode *inode, struct file *file)
75592 {
75593 struct devkmsg_user *user;
75594 int err;
75595
75596 + err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
75597 + if (err)
75598 + return err;
75599 +
75600 /* write-only does not need any file context */
75601 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
75602 return 0;
75603 @@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
75604 if (dmesg_restrict)
75605 return 1;
75606 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
75607 - return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
75608 + return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
75609 }
75610
75611 static int check_syslog_permissions(int type, bool from_file)
75612 @@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
75613 if (from_file && type != SYSLOG_ACTION_OPEN)
75614 return 0;
75615
75616 +#ifdef CONFIG_GRKERNSEC_DMESG
75617 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
75618 + return -EPERM;
75619 +#endif
75620 +
75621 if (syslog_action_restricted(type)) {
75622 if (capable(CAP_SYSLOG))
75623 return 0;
75624 diff --git a/kernel/profile.c b/kernel/profile.c
75625 index 1f39181..86093471 100644
75626 --- a/kernel/profile.c
75627 +++ b/kernel/profile.c
75628 @@ -40,7 +40,7 @@ struct profile_hit {
75629 /* Oprofile timer tick hook */
75630 static int (*timer_hook)(struct pt_regs *) __read_mostly;
75631
75632 -static atomic_t *prof_buffer;
75633 +static atomic_unchecked_t *prof_buffer;
75634 static unsigned long prof_len, prof_shift;
75635
75636 int prof_on __read_mostly;
75637 @@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
75638 hits[i].pc = 0;
75639 continue;
75640 }
75641 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
75642 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
75643 hits[i].hits = hits[i].pc = 0;
75644 }
75645 }
75646 @@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
75647 * Add the current hit(s) and flush the write-queue out
75648 * to the global buffer:
75649 */
75650 - atomic_add(nr_hits, &prof_buffer[pc]);
75651 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
75652 for (i = 0; i < NR_PROFILE_HIT; ++i) {
75653 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
75654 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
75655 hits[i].pc = hits[i].hits = 0;
75656 }
75657 out:
75658 @@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
75659 {
75660 unsigned long pc;
75661 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
75662 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
75663 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
75664 }
75665 #endif /* !CONFIG_SMP */
75666
75667 @@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
75668 return -EFAULT;
75669 buf++; p++; count--; read++;
75670 }
75671 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
75672 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
75673 if (copy_to_user(buf, (void *)pnt, count))
75674 return -EFAULT;
75675 read += count;
75676 @@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
75677 }
75678 #endif
75679 profile_discard_flip_buffers();
75680 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
75681 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
75682 return count;
75683 }
75684
75685 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
75686 index 6cbeaae..363c48a 100644
75687 --- a/kernel/ptrace.c
75688 +++ b/kernel/ptrace.c
75689 @@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
75690 if (seize)
75691 flags |= PT_SEIZED;
75692 rcu_read_lock();
75693 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
75694 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
75695 flags |= PT_PTRACE_CAP;
75696 rcu_read_unlock();
75697 task->ptrace = flags;
75698 @@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
75699 break;
75700 return -EIO;
75701 }
75702 - if (copy_to_user(dst, buf, retval))
75703 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
75704 return -EFAULT;
75705 copied += retval;
75706 src += retval;
75707 @@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
75708 bool seized = child->ptrace & PT_SEIZED;
75709 int ret = -EIO;
75710 siginfo_t siginfo, *si;
75711 - void __user *datavp = (void __user *) data;
75712 + void __user *datavp = (__force void __user *) data;
75713 unsigned long __user *datalp = datavp;
75714 unsigned long flags;
75715
75716 @@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
75717 goto out;
75718 }
75719
75720 + if (gr_handle_ptrace(child, request)) {
75721 + ret = -EPERM;
75722 + goto out_put_task_struct;
75723 + }
75724 +
75725 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
75726 ret = ptrace_attach(child, request, addr, data);
75727 /*
75728 * Some architectures need to do book-keeping after
75729 * a ptrace attach.
75730 */
75731 - if (!ret)
75732 + if (!ret) {
75733 arch_ptrace_attach(child);
75734 + gr_audit_ptrace(child);
75735 + }
75736 goto out_put_task_struct;
75737 }
75738
75739 @@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
75740 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
75741 if (copied != sizeof(tmp))
75742 return -EIO;
75743 - return put_user(tmp, (unsigned long __user *)data);
75744 + return put_user(tmp, (__force unsigned long __user *)data);
75745 }
75746
75747 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
75748 @@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
75749 goto out;
75750 }
75751
75752 + if (gr_handle_ptrace(child, request)) {
75753 + ret = -EPERM;
75754 + goto out_put_task_struct;
75755 + }
75756 +
75757 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
75758 ret = ptrace_attach(child, request, addr, data);
75759 /*
75760 * Some architectures need to do book-keeping after
75761 * a ptrace attach.
75762 */
75763 - if (!ret)
75764 + if (!ret) {
75765 arch_ptrace_attach(child);
75766 + gr_audit_ptrace(child);
75767 + }
75768 goto out_put_task_struct;
75769 }
75770
75771 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
75772 index e7dce58..ad0d7b7 100644
75773 --- a/kernel/rcutiny.c
75774 +++ b/kernel/rcutiny.c
75775 @@ -46,7 +46,7 @@
75776 struct rcu_ctrlblk;
75777 static void invoke_rcu_callbacks(void);
75778 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
75779 -static void rcu_process_callbacks(struct softirq_action *unused);
75780 +static void rcu_process_callbacks(void);
75781 static void __call_rcu(struct rcu_head *head,
75782 void (*func)(struct rcu_head *rcu),
75783 struct rcu_ctrlblk *rcp);
75784 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
75785 rcu_is_callbacks_kthread()));
75786 }
75787
75788 -static void rcu_process_callbacks(struct softirq_action *unused)
75789 +static void rcu_process_callbacks(void)
75790 {
75791 __rcu_process_callbacks(&rcu_sched_ctrlblk);
75792 __rcu_process_callbacks(&rcu_bh_ctrlblk);
75793 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
75794 index f85016a..91cb03b 100644
75795 --- a/kernel/rcutiny_plugin.h
75796 +++ b/kernel/rcutiny_plugin.h
75797 @@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
75798 have_rcu_kthread_work = morework;
75799 local_irq_restore(flags);
75800 if (work)
75801 - rcu_process_callbacks(NULL);
75802 + rcu_process_callbacks();
75803 schedule_timeout_interruptible(1); /* Leave CPU for others. */
75804 }
75805
75806 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
75807 index 31dea01..ad91ffb 100644
75808 --- a/kernel/rcutorture.c
75809 +++ b/kernel/rcutorture.c
75810 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
75811 { 0 };
75812 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
75813 { 0 };
75814 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
75815 -static atomic_t n_rcu_torture_alloc;
75816 -static atomic_t n_rcu_torture_alloc_fail;
75817 -static atomic_t n_rcu_torture_free;
75818 -static atomic_t n_rcu_torture_mberror;
75819 -static atomic_t n_rcu_torture_error;
75820 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
75821 +static atomic_unchecked_t n_rcu_torture_alloc;
75822 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
75823 +static atomic_unchecked_t n_rcu_torture_free;
75824 +static atomic_unchecked_t n_rcu_torture_mberror;
75825 +static atomic_unchecked_t n_rcu_torture_error;
75826 static long n_rcu_torture_barrier_error;
75827 static long n_rcu_torture_boost_ktrerror;
75828 static long n_rcu_torture_boost_rterror;
75829 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
75830
75831 spin_lock_bh(&rcu_torture_lock);
75832 if (list_empty(&rcu_torture_freelist)) {
75833 - atomic_inc(&n_rcu_torture_alloc_fail);
75834 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
75835 spin_unlock_bh(&rcu_torture_lock);
75836 return NULL;
75837 }
75838 - atomic_inc(&n_rcu_torture_alloc);
75839 + atomic_inc_unchecked(&n_rcu_torture_alloc);
75840 p = rcu_torture_freelist.next;
75841 list_del_init(p);
75842 spin_unlock_bh(&rcu_torture_lock);
75843 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
75844 static void
75845 rcu_torture_free(struct rcu_torture *p)
75846 {
75847 - atomic_inc(&n_rcu_torture_free);
75848 + atomic_inc_unchecked(&n_rcu_torture_free);
75849 spin_lock_bh(&rcu_torture_lock);
75850 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
75851 spin_unlock_bh(&rcu_torture_lock);
75852 @@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
75853 i = rp->rtort_pipe_count;
75854 if (i > RCU_TORTURE_PIPE_LEN)
75855 i = RCU_TORTURE_PIPE_LEN;
75856 - atomic_inc(&rcu_torture_wcount[i]);
75857 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
75858 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
75859 rp->rtort_mbtest = 0;
75860 rcu_torture_free(rp);
75861 @@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
75862 i = rp->rtort_pipe_count;
75863 if (i > RCU_TORTURE_PIPE_LEN)
75864 i = RCU_TORTURE_PIPE_LEN;
75865 - atomic_inc(&rcu_torture_wcount[i]);
75866 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
75867 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
75868 rp->rtort_mbtest = 0;
75869 list_del(&rp->rtort_free);
75870 @@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
75871 i = old_rp->rtort_pipe_count;
75872 if (i > RCU_TORTURE_PIPE_LEN)
75873 i = RCU_TORTURE_PIPE_LEN;
75874 - atomic_inc(&rcu_torture_wcount[i]);
75875 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
75876 old_rp->rtort_pipe_count++;
75877 cur_ops->deferred_free(old_rp);
75878 }
75879 @@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
75880 }
75881 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
75882 if (p->rtort_mbtest == 0)
75883 - atomic_inc(&n_rcu_torture_mberror);
75884 + atomic_inc_unchecked(&n_rcu_torture_mberror);
75885 spin_lock(&rand_lock);
75886 cur_ops->read_delay(&rand);
75887 n_rcu_torture_timers++;
75888 @@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
75889 }
75890 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
75891 if (p->rtort_mbtest == 0)
75892 - atomic_inc(&n_rcu_torture_mberror);
75893 + atomic_inc_unchecked(&n_rcu_torture_mberror);
75894 cur_ops->read_delay(&rand);
75895 preempt_disable();
75896 pipe_count = p->rtort_pipe_count;
75897 @@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
75898 rcu_torture_current,
75899 rcu_torture_current_version,
75900 list_empty(&rcu_torture_freelist),
75901 - atomic_read(&n_rcu_torture_alloc),
75902 - atomic_read(&n_rcu_torture_alloc_fail),
75903 - atomic_read(&n_rcu_torture_free));
75904 + atomic_read_unchecked(&n_rcu_torture_alloc),
75905 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
75906 + atomic_read_unchecked(&n_rcu_torture_free));
75907 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
75908 - atomic_read(&n_rcu_torture_mberror),
75909 + atomic_read_unchecked(&n_rcu_torture_mberror),
75910 n_rcu_torture_boost_ktrerror,
75911 n_rcu_torture_boost_rterror);
75912 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
75913 @@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
75914 n_barrier_attempts,
75915 n_rcu_torture_barrier_error);
75916 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
75917 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
75918 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
75919 n_rcu_torture_barrier_error != 0 ||
75920 n_rcu_torture_boost_ktrerror != 0 ||
75921 n_rcu_torture_boost_rterror != 0 ||
75922 n_rcu_torture_boost_failure != 0 ||
75923 i > 1) {
75924 cnt += sprintf(&page[cnt], "!!! ");
75925 - atomic_inc(&n_rcu_torture_error);
75926 + atomic_inc_unchecked(&n_rcu_torture_error);
75927 WARN_ON_ONCE(1);
75928 }
75929 cnt += sprintf(&page[cnt], "Reader Pipe: ");
75930 @@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
75931 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
75932 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
75933 cnt += sprintf(&page[cnt], " %d",
75934 - atomic_read(&rcu_torture_wcount[i]));
75935 + atomic_read_unchecked(&rcu_torture_wcount[i]));
75936 }
75937 cnt += sprintf(&page[cnt], "\n");
75938 if (cur_ops->stats)
75939 @@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
75940
75941 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
75942
75943 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
75944 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
75945 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
75946 else if (n_online_successes != n_online_attempts ||
75947 n_offline_successes != n_offline_attempts)
75948 @@ -1989,18 +1989,18 @@ rcu_torture_init(void)
75949
75950 rcu_torture_current = NULL;
75951 rcu_torture_current_version = 0;
75952 - atomic_set(&n_rcu_torture_alloc, 0);
75953 - atomic_set(&n_rcu_torture_alloc_fail, 0);
75954 - atomic_set(&n_rcu_torture_free, 0);
75955 - atomic_set(&n_rcu_torture_mberror, 0);
75956 - atomic_set(&n_rcu_torture_error, 0);
75957 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
75958 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
75959 + atomic_set_unchecked(&n_rcu_torture_free, 0);
75960 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
75961 + atomic_set_unchecked(&n_rcu_torture_error, 0);
75962 n_rcu_torture_barrier_error = 0;
75963 n_rcu_torture_boost_ktrerror = 0;
75964 n_rcu_torture_boost_rterror = 0;
75965 n_rcu_torture_boost_failure = 0;
75966 n_rcu_torture_boosts = 0;
75967 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
75968 - atomic_set(&rcu_torture_wcount[i], 0);
75969 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
75970 for_each_possible_cpu(cpu) {
75971 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
75972 per_cpu(rcu_torture_count, cpu)[i] = 0;
75973 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
75974 index e441b77..dd54f17 100644
75975 --- a/kernel/rcutree.c
75976 +++ b/kernel/rcutree.c
75977 @@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
75978 rcu_prepare_for_idle(smp_processor_id());
75979 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
75980 smp_mb__before_atomic_inc(); /* See above. */
75981 - atomic_inc(&rdtp->dynticks);
75982 + atomic_inc_unchecked(&rdtp->dynticks);
75983 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
75984 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
75985 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
75986
75987 /*
75988 * It is illegal to enter an extended quiescent state while
75989 @@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
75990 int user)
75991 {
75992 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
75993 - atomic_inc(&rdtp->dynticks);
75994 + atomic_inc_unchecked(&rdtp->dynticks);
75995 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
75996 smp_mb__after_atomic_inc(); /* See above. */
75997 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
75998 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
75999 rcu_cleanup_after_idle(smp_processor_id());
76000 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
76001 if (!user && !is_idle_task(current)) {
76002 @@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
76003 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
76004
76005 if (rdtp->dynticks_nmi_nesting == 0 &&
76006 - (atomic_read(&rdtp->dynticks) & 0x1))
76007 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
76008 return;
76009 rdtp->dynticks_nmi_nesting++;
76010 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
76011 - atomic_inc(&rdtp->dynticks);
76012 + atomic_inc_unchecked(&rdtp->dynticks);
76013 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76014 smp_mb__after_atomic_inc(); /* See above. */
76015 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76016 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76017 }
76018
76019 /**
76020 @@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
76021 return;
76022 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
76023 smp_mb__before_atomic_inc(); /* See above. */
76024 - atomic_inc(&rdtp->dynticks);
76025 + atomic_inc_unchecked(&rdtp->dynticks);
76026 smp_mb__after_atomic_inc(); /* Force delay to next write. */
76027 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
76028 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
76029 }
76030
76031 /**
76032 @@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
76033 int ret;
76034
76035 preempt_disable();
76036 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76037 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76038 preempt_enable();
76039 return ret;
76040 }
76041 @@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
76042 */
76043 static int dyntick_save_progress_counter(struct rcu_data *rdp)
76044 {
76045 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
76046 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76047 return (rdp->dynticks_snap & 0x1) == 0;
76048 }
76049
76050 @@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
76051 unsigned int curr;
76052 unsigned int snap;
76053
76054 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
76055 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76056 snap = (unsigned int)rdp->dynticks_snap;
76057
76058 /*
76059 @@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
76060 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
76061 */
76062 if (till_stall_check < 3) {
76063 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
76064 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
76065 till_stall_check = 3;
76066 } else if (till_stall_check > 300) {
76067 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
76068 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
76069 till_stall_check = 300;
76070 }
76071 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
76072 @@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
76073 rsp->qlen += rdp->qlen;
76074 rdp->n_cbs_orphaned += rdp->qlen;
76075 rdp->qlen_lazy = 0;
76076 - ACCESS_ONCE(rdp->qlen) = 0;
76077 + ACCESS_ONCE_RW(rdp->qlen) = 0;
76078 }
76079
76080 /*
76081 @@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
76082 }
76083 smp_mb(); /* List handling before counting for rcu_barrier(). */
76084 rdp->qlen_lazy -= count_lazy;
76085 - ACCESS_ONCE(rdp->qlen) -= count;
76086 + ACCESS_ONCE_RW(rdp->qlen) -= count;
76087 rdp->n_cbs_invoked += count;
76088
76089 /* Reinstate batch limit if we have worked down the excess. */
76090 @@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
76091 /*
76092 * Do RCU core processing for the current CPU.
76093 */
76094 -static void rcu_process_callbacks(struct softirq_action *unused)
76095 +static void rcu_process_callbacks(void)
76096 {
76097 struct rcu_state *rsp;
76098
76099 @@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
76100 local_irq_restore(flags);
76101 return;
76102 }
76103 - ACCESS_ONCE(rdp->qlen)++;
76104 + ACCESS_ONCE_RW(rdp->qlen)++;
76105 if (lazy)
76106 rdp->qlen_lazy++;
76107 else
76108 @@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
76109 * counter wrap on a 32-bit system. Quite a few more CPUs would of
76110 * course be required on a 64-bit system.
76111 */
76112 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
76113 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
76114 (ulong)atomic_long_read(&rsp->expedited_done) +
76115 ULONG_MAX / 8)) {
76116 synchronize_sched();
76117 - atomic_long_inc(&rsp->expedited_wrap);
76118 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
76119 return;
76120 }
76121
76122 @@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
76123 * Take a ticket. Note that atomic_inc_return() implies a
76124 * full memory barrier.
76125 */
76126 - snap = atomic_long_inc_return(&rsp->expedited_start);
76127 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
76128 firstsnap = snap;
76129 get_online_cpus();
76130 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
76131 @@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
76132 synchronize_sched_expedited_cpu_stop,
76133 NULL) == -EAGAIN) {
76134 put_online_cpus();
76135 - atomic_long_inc(&rsp->expedited_tryfail);
76136 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
76137
76138 /* Check to see if someone else did our work for us. */
76139 s = atomic_long_read(&rsp->expedited_done);
76140 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76141 /* ensure test happens before caller kfree */
76142 smp_mb__before_atomic_inc(); /* ^^^ */
76143 - atomic_long_inc(&rsp->expedited_workdone1);
76144 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
76145 return;
76146 }
76147
76148 @@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
76149 udelay(trycount * num_online_cpus());
76150 } else {
76151 wait_rcu_gp(call_rcu_sched);
76152 - atomic_long_inc(&rsp->expedited_normal);
76153 + atomic_long_inc_unchecked(&rsp->expedited_normal);
76154 return;
76155 }
76156
76157 @@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
76158 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76159 /* ensure test happens before caller kfree */
76160 smp_mb__before_atomic_inc(); /* ^^^ */
76161 - atomic_long_inc(&rsp->expedited_workdone2);
76162 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
76163 return;
76164 }
76165
76166 @@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
76167 * period works for us.
76168 */
76169 get_online_cpus();
76170 - snap = atomic_long_read(&rsp->expedited_start);
76171 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
76172 smp_mb(); /* ensure read is before try_stop_cpus(). */
76173 }
76174 - atomic_long_inc(&rsp->expedited_stoppedcpus);
76175 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
76176
76177 /*
76178 * Everyone up to our most recent fetch is covered by our grace
76179 @@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
76180 * than we did already did their update.
76181 */
76182 do {
76183 - atomic_long_inc(&rsp->expedited_done_tries);
76184 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
76185 s = atomic_long_read(&rsp->expedited_done);
76186 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
76187 /* ensure test happens before caller kfree */
76188 smp_mb__before_atomic_inc(); /* ^^^ */
76189 - atomic_long_inc(&rsp->expedited_done_lost);
76190 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
76191 break;
76192 }
76193 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
76194 - atomic_long_inc(&rsp->expedited_done_exit);
76195 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
76196
76197 put_online_cpus();
76198 }
76199 @@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76200 * ACCESS_ONCE() to prevent the compiler from speculating
76201 * the increment to precede the early-exit check.
76202 */
76203 - ACCESS_ONCE(rsp->n_barrier_done)++;
76204 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76205 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
76206 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
76207 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
76208 @@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76209
76210 /* Increment ->n_barrier_done to prevent duplicate work. */
76211 smp_mb(); /* Keep increment after above mechanism. */
76212 - ACCESS_ONCE(rsp->n_barrier_done)++;
76213 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76214 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
76215 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
76216 smp_mb(); /* Keep increment before caller's subsequent code. */
76217 @@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
76218 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
76219 init_callback_list(rdp);
76220 rdp->qlen_lazy = 0;
76221 - ACCESS_ONCE(rdp->qlen) = 0;
76222 + ACCESS_ONCE_RW(rdp->qlen) = 0;
76223 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
76224 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
76225 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
76226 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
76227 #ifdef CONFIG_RCU_USER_QS
76228 WARN_ON_ONCE(rdp->dynticks->in_user);
76229 #endif
76230 @@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
76231 rdp->blimit = blimit;
76232 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
76233 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
76234 - atomic_set(&rdp->dynticks->dynticks,
76235 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
76236 + atomic_set_unchecked(&rdp->dynticks->dynticks,
76237 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
76238 rcu_prepare_for_idle_init(cpu);
76239 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
76240
76241 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
76242 index 4b69291..704c92e 100644
76243 --- a/kernel/rcutree.h
76244 +++ b/kernel/rcutree.h
76245 @@ -86,7 +86,7 @@ struct rcu_dynticks {
76246 long long dynticks_nesting; /* Track irq/process nesting level. */
76247 /* Process level is worth LLONG_MAX/2. */
76248 int dynticks_nmi_nesting; /* Track NMI nesting level. */
76249 - atomic_t dynticks; /* Even value for idle, else odd. */
76250 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
76251 #ifdef CONFIG_RCU_FAST_NO_HZ
76252 int dyntick_drain; /* Prepare-for-idle state variable. */
76253 unsigned long dyntick_holdoff;
76254 @@ -423,17 +423,17 @@ struct rcu_state {
76255 /* _rcu_barrier(). */
76256 /* End of fields guarded by barrier_mutex. */
76257
76258 - atomic_long_t expedited_start; /* Starting ticket. */
76259 - atomic_long_t expedited_done; /* Done ticket. */
76260 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
76261 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
76262 - atomic_long_t expedited_workdone1; /* # done by others #1. */
76263 - atomic_long_t expedited_workdone2; /* # done by others #2. */
76264 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
76265 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
76266 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
76267 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
76268 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
76269 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
76270 + atomic_long_t expedited_done; /* Done ticket. */
76271 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
76272 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
76273 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
76274 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
76275 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
76276 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
76277 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
76278 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
76279 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
76280
76281 unsigned long jiffies_force_qs; /* Time at which to invoke */
76282 /* force_quiescent_state(). */
76283 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
76284 index c1cc7e1..f62e436 100644
76285 --- a/kernel/rcutree_plugin.h
76286 +++ b/kernel/rcutree_plugin.h
76287 @@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
76288
76289 /* Clean up and exit. */
76290 smp_mb(); /* ensure expedited GP seen before counter increment. */
76291 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
76292 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
76293 unlock_mb_ret:
76294 mutex_unlock(&sync_rcu_preempt_exp_mutex);
76295 mb_ret:
76296 @@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
76297 free_cpumask_var(cm);
76298 }
76299
76300 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
76301 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
76302 .store = &rcu_cpu_kthread_task,
76303 .thread_should_run = rcu_cpu_kthread_should_run,
76304 .thread_fn = rcu_cpu_kthread,
76305 @@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
76306 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
76307 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
76308 cpu, ticks_value, ticks_title,
76309 - atomic_read(&rdtp->dynticks) & 0xfff,
76310 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
76311 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
76312 fast_no_hz);
76313 }
76314 @@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
76315
76316 /* Enqueue the callback on the nocb list and update counts. */
76317 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
76318 - ACCESS_ONCE(*old_rhpp) = rhp;
76319 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
76320 atomic_long_add(rhcount, &rdp->nocb_q_count);
76321 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
76322
76323 @@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
76324 * Extract queued callbacks, update counts, and wait
76325 * for a grace period to elapse.
76326 */
76327 - ACCESS_ONCE(rdp->nocb_head) = NULL;
76328 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
76329 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
76330 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
76331 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
76332 - ACCESS_ONCE(rdp->nocb_p_count) += c;
76333 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
76334 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
76335 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
76336 wait_rcu_gp(rdp->rsp->call_remote);
76337
76338 /* Each pass through the following loop invokes a callback. */
76339 @@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
76340 list = next;
76341 }
76342 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
76343 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
76344 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
76345 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
76346 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
76347 rdp->n_nocbs_invoked += c;
76348 }
76349 return 0;
76350 @@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
76351 rdp = per_cpu_ptr(rsp->rda, cpu);
76352 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
76353 BUG_ON(IS_ERR(t));
76354 - ACCESS_ONCE(rdp->nocb_kthread) = t;
76355 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
76356 }
76357 }
76358
76359 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
76360 index 0d095dc..1985b19 100644
76361 --- a/kernel/rcutree_trace.c
76362 +++ b/kernel/rcutree_trace.c
76363 @@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
76364 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
76365 rdp->passed_quiesce, rdp->qs_pending);
76366 seq_printf(m, " dt=%d/%llx/%d df=%lu",
76367 - atomic_read(&rdp->dynticks->dynticks),
76368 + atomic_read_unchecked(&rdp->dynticks->dynticks),
76369 rdp->dynticks->dynticks_nesting,
76370 rdp->dynticks->dynticks_nmi_nesting,
76371 rdp->dynticks_fqs);
76372 @@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
76373 struct rcu_state *rsp = (struct rcu_state *)m->private;
76374
76375 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",
76376 - atomic_long_read(&rsp->expedited_start),
76377 + atomic_long_read_unchecked(&rsp->expedited_start),
76378 atomic_long_read(&rsp->expedited_done),
76379 - atomic_long_read(&rsp->expedited_wrap),
76380 - atomic_long_read(&rsp->expedited_tryfail),
76381 - atomic_long_read(&rsp->expedited_workdone1),
76382 - atomic_long_read(&rsp->expedited_workdone2),
76383 - atomic_long_read(&rsp->expedited_normal),
76384 - atomic_long_read(&rsp->expedited_stoppedcpus),
76385 - atomic_long_read(&rsp->expedited_done_tries),
76386 - atomic_long_read(&rsp->expedited_done_lost),
76387 - atomic_long_read(&rsp->expedited_done_exit));
76388 + atomic_long_read_unchecked(&rsp->expedited_wrap),
76389 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
76390 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
76391 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
76392 + atomic_long_read_unchecked(&rsp->expedited_normal),
76393 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
76394 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
76395 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
76396 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
76397 return 0;
76398 }
76399
76400 diff --git a/kernel/resource.c b/kernel/resource.c
76401 index 73f35d4..4684fc4 100644
76402 --- a/kernel/resource.c
76403 +++ b/kernel/resource.c
76404 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
76405
76406 static int __init ioresources_init(void)
76407 {
76408 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
76409 +#ifdef CONFIG_GRKERNSEC_PROC_USER
76410 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
76411 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
76412 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76413 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
76414 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
76415 +#endif
76416 +#else
76417 proc_create("ioports", 0, NULL, &proc_ioports_operations);
76418 proc_create("iomem", 0, NULL, &proc_iomem_operations);
76419 +#endif
76420 return 0;
76421 }
76422 __initcall(ioresources_init);
76423 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
76424 index 98ec494..4241d6d 100644
76425 --- a/kernel/rtmutex-tester.c
76426 +++ b/kernel/rtmutex-tester.c
76427 @@ -20,7 +20,7 @@
76428 #define MAX_RT_TEST_MUTEXES 8
76429
76430 static spinlock_t rttest_lock;
76431 -static atomic_t rttest_event;
76432 +static atomic_unchecked_t rttest_event;
76433
76434 struct test_thread_data {
76435 int opcode;
76436 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76437
76438 case RTTEST_LOCKCONT:
76439 td->mutexes[td->opdata] = 1;
76440 - td->event = atomic_add_return(1, &rttest_event);
76441 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76442 return 0;
76443
76444 case RTTEST_RESET:
76445 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76446 return 0;
76447
76448 case RTTEST_RESETEVENT:
76449 - atomic_set(&rttest_event, 0);
76450 + atomic_set_unchecked(&rttest_event, 0);
76451 return 0;
76452
76453 default:
76454 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76455 return ret;
76456
76457 td->mutexes[id] = 1;
76458 - td->event = atomic_add_return(1, &rttest_event);
76459 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76460 rt_mutex_lock(&mutexes[id]);
76461 - td->event = atomic_add_return(1, &rttest_event);
76462 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76463 td->mutexes[id] = 4;
76464 return 0;
76465
76466 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76467 return ret;
76468
76469 td->mutexes[id] = 1;
76470 - td->event = atomic_add_return(1, &rttest_event);
76471 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76472 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
76473 - td->event = atomic_add_return(1, &rttest_event);
76474 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76475 td->mutexes[id] = ret ? 0 : 4;
76476 return ret ? -EINTR : 0;
76477
76478 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76479 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
76480 return ret;
76481
76482 - td->event = atomic_add_return(1, &rttest_event);
76483 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76484 rt_mutex_unlock(&mutexes[id]);
76485 - td->event = atomic_add_return(1, &rttest_event);
76486 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76487 td->mutexes[id] = 0;
76488 return 0;
76489
76490 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76491 break;
76492
76493 td->mutexes[dat] = 2;
76494 - td->event = atomic_add_return(1, &rttest_event);
76495 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76496 break;
76497
76498 default:
76499 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76500 return;
76501
76502 td->mutexes[dat] = 3;
76503 - td->event = atomic_add_return(1, &rttest_event);
76504 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76505 break;
76506
76507 case RTTEST_LOCKNOWAIT:
76508 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76509 return;
76510
76511 td->mutexes[dat] = 1;
76512 - td->event = atomic_add_return(1, &rttest_event);
76513 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76514 return;
76515
76516 default:
76517 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
76518 index 0984a21..939f183 100644
76519 --- a/kernel/sched/auto_group.c
76520 +++ b/kernel/sched/auto_group.c
76521 @@ -11,7 +11,7 @@
76522
76523 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
76524 static struct autogroup autogroup_default;
76525 -static atomic_t autogroup_seq_nr;
76526 +static atomic_unchecked_t autogroup_seq_nr;
76527
76528 void __init autogroup_init(struct task_struct *init_task)
76529 {
76530 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
76531
76532 kref_init(&ag->kref);
76533 init_rwsem(&ag->lock);
76534 - ag->id = atomic_inc_return(&autogroup_seq_nr);
76535 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
76536 ag->tg = tg;
76537 #ifdef CONFIG_RT_GROUP_SCHED
76538 /*
76539 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
76540 index 26058d0..f9d3c76 100644
76541 --- a/kernel/sched/core.c
76542 +++ b/kernel/sched/core.c
76543 @@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
76544 /* convert nice value [19,-20] to rlimit style value [1,40] */
76545 int nice_rlim = 20 - nice;
76546
76547 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
76548 +
76549 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
76550 capable(CAP_SYS_NICE));
76551 }
76552 @@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
76553 if (nice > 19)
76554 nice = 19;
76555
76556 - if (increment < 0 && !can_nice(current, nice))
76557 + if (increment < 0 && (!can_nice(current, nice) ||
76558 + gr_handle_chroot_nice()))
76559 return -EPERM;
76560
76561 retval = security_task_setnice(current, nice);
76562 @@ -3818,6 +3821,7 @@ recheck:
76563 unsigned long rlim_rtprio =
76564 task_rlimit(p, RLIMIT_RTPRIO);
76565
76566 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
76567 /* can't set/change the rt policy */
76568 if (policy != p->policy && !rlim_rtprio)
76569 return -EPERM;
76570 @@ -4901,7 +4905,7 @@ static void migrate_tasks(unsigned int dead_cpu)
76571
76572 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
76573
76574 -static struct ctl_table sd_ctl_dir[] = {
76575 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
76576 {
76577 .procname = "sched_domain",
76578 .mode = 0555,
76579 @@ -4918,17 +4922,17 @@ static struct ctl_table sd_ctl_root[] = {
76580 {}
76581 };
76582
76583 -static struct ctl_table *sd_alloc_ctl_entry(int n)
76584 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
76585 {
76586 - struct ctl_table *entry =
76587 + ctl_table_no_const *entry =
76588 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
76589
76590 return entry;
76591 }
76592
76593 -static void sd_free_ctl_entry(struct ctl_table **tablep)
76594 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
76595 {
76596 - struct ctl_table *entry;
76597 + ctl_table_no_const *entry;
76598
76599 /*
76600 * In the intermediate directories, both the child directory and
76601 @@ -4936,22 +4940,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
76602 * will always be set. In the lowest directory the names are
76603 * static strings and all have proc handlers.
76604 */
76605 - for (entry = *tablep; entry->mode; entry++) {
76606 - if (entry->child)
76607 - sd_free_ctl_entry(&entry->child);
76608 + for (entry = tablep; entry->mode; entry++) {
76609 + if (entry->child) {
76610 + sd_free_ctl_entry(entry->child);
76611 + pax_open_kernel();
76612 + entry->child = NULL;
76613 + pax_close_kernel();
76614 + }
76615 if (entry->proc_handler == NULL)
76616 kfree(entry->procname);
76617 }
76618
76619 - kfree(*tablep);
76620 - *tablep = NULL;
76621 + kfree(tablep);
76622 }
76623
76624 static int min_load_idx = 0;
76625 static int max_load_idx = CPU_LOAD_IDX_MAX;
76626
76627 static void
76628 -set_table_entry(struct ctl_table *entry,
76629 +set_table_entry(ctl_table_no_const *entry,
76630 const char *procname, void *data, int maxlen,
76631 umode_t mode, proc_handler *proc_handler,
76632 bool load_idx)
76633 @@ -4971,7 +4978,7 @@ set_table_entry(struct ctl_table *entry,
76634 static struct ctl_table *
76635 sd_alloc_ctl_domain_table(struct sched_domain *sd)
76636 {
76637 - struct ctl_table *table = sd_alloc_ctl_entry(13);
76638 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
76639
76640 if (table == NULL)
76641 return NULL;
76642 @@ -5006,9 +5013,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
76643 return table;
76644 }
76645
76646 -static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
76647 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
76648 {
76649 - struct ctl_table *entry, *table;
76650 + ctl_table_no_const *entry, *table;
76651 struct sched_domain *sd;
76652 int domain_num = 0, i;
76653 char buf[32];
76654 @@ -5035,11 +5042,13 @@ static struct ctl_table_header *sd_sysctl_header;
76655 static void register_sched_domain_sysctl(void)
76656 {
76657 int i, cpu_num = num_possible_cpus();
76658 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
76659 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
76660 char buf[32];
76661
76662 WARN_ON(sd_ctl_dir[0].child);
76663 + pax_open_kernel();
76664 sd_ctl_dir[0].child = entry;
76665 + pax_close_kernel();
76666
76667 if (entry == NULL)
76668 return;
76669 @@ -5062,8 +5071,12 @@ static void unregister_sched_domain_sysctl(void)
76670 if (sd_sysctl_header)
76671 unregister_sysctl_table(sd_sysctl_header);
76672 sd_sysctl_header = NULL;
76673 - if (sd_ctl_dir[0].child)
76674 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
76675 + if (sd_ctl_dir[0].child) {
76676 + sd_free_ctl_entry(sd_ctl_dir[0].child);
76677 + pax_open_kernel();
76678 + sd_ctl_dir[0].child = NULL;
76679 + pax_close_kernel();
76680 + }
76681 }
76682 #else
76683 static void register_sched_domain_sysctl(void)
76684 @@ -5162,7 +5175,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
76685 * happens before everything else. This has to be lower priority than
76686 * the notifier in the perf_event subsystem, though.
76687 */
76688 -static struct notifier_block __cpuinitdata migration_notifier = {
76689 +static struct notifier_block migration_notifier = {
76690 .notifier_call = migration_call,
76691 .priority = CPU_PRI_MIGRATION,
76692 };
76693 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
76694 index 81fa536..6ccf96a 100644
76695 --- a/kernel/sched/fair.c
76696 +++ b/kernel/sched/fair.c
76697 @@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
76698
76699 static void reset_ptenuma_scan(struct task_struct *p)
76700 {
76701 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
76702 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
76703 p->mm->numa_scan_offset = 0;
76704 }
76705
76706 @@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
76707 */
76708 static int select_idle_sibling(struct task_struct *p, int target)
76709 {
76710 - int cpu = smp_processor_id();
76711 - int prev_cpu = task_cpu(p);
76712 struct sched_domain *sd;
76713 struct sched_group *sg;
76714 - int i;
76715 + int i = task_cpu(p);
76716
76717 - /*
76718 - * If the task is going to be woken-up on this cpu and if it is
76719 - * already idle, then it is the right target.
76720 - */
76721 - if (target == cpu && idle_cpu(cpu))
76722 - return cpu;
76723 + if (idle_cpu(target))
76724 + return target;
76725
76726 /*
76727 - * If the task is going to be woken-up on the cpu where it previously
76728 - * ran and if it is currently idle, then it the right target.
76729 + * If the prevous cpu is cache affine and idle, don't be stupid.
76730 */
76731 - if (target == prev_cpu && idle_cpu(prev_cpu))
76732 - return prev_cpu;
76733 + if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
76734 + return i;
76735
76736 /*
76737 * Otherwise, iterate the domains and find an elegible idle cpu.
76738 @@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
76739 goto next;
76740
76741 for_each_cpu(i, sched_group_cpus(sg)) {
76742 - if (!idle_cpu(i))
76743 + if (i == target || !idle_cpu(i))
76744 goto next;
76745 }
76746
76747 @@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
76748 * run_rebalance_domains is triggered when needed from the scheduler tick.
76749 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
76750 */
76751 -static void run_rebalance_domains(struct softirq_action *h)
76752 +static void run_rebalance_domains(void)
76753 {
76754 int this_cpu = smp_processor_id();
76755 struct rq *this_rq = cpu_rq(this_cpu);
76756 diff --git a/kernel/signal.c b/kernel/signal.c
76757 index 3d09cf6..a67d2c6 100644
76758 --- a/kernel/signal.c
76759 +++ b/kernel/signal.c
76760 @@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
76761
76762 int print_fatal_signals __read_mostly;
76763
76764 -static void __user *sig_handler(struct task_struct *t, int sig)
76765 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
76766 {
76767 return t->sighand->action[sig - 1].sa.sa_handler;
76768 }
76769
76770 -static int sig_handler_ignored(void __user *handler, int sig)
76771 +static int sig_handler_ignored(__sighandler_t handler, int sig)
76772 {
76773 /* Is it explicitly or implicitly ignored? */
76774 return handler == SIG_IGN ||
76775 @@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
76776
76777 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
76778 {
76779 - void __user *handler;
76780 + __sighandler_t handler;
76781
76782 handler = sig_handler(t, sig);
76783
76784 @@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
76785 atomic_inc(&user->sigpending);
76786 rcu_read_unlock();
76787
76788 + if (!override_rlimit)
76789 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
76790 +
76791 if (override_rlimit ||
76792 atomic_read(&user->sigpending) <=
76793 task_rlimit(t, RLIMIT_SIGPENDING)) {
76794 @@ -492,7 +495,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
76795
76796 int unhandled_signal(struct task_struct *tsk, int sig)
76797 {
76798 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
76799 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
76800 if (is_global_init(tsk))
76801 return 1;
76802 if (handler != SIG_IGN && handler != SIG_DFL)
76803 @@ -812,6 +815,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
76804 }
76805 }
76806
76807 + /* allow glibc communication via tgkill to other threads in our
76808 + thread group */
76809 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
76810 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
76811 + && gr_handle_signal(t, sig))
76812 + return -EPERM;
76813 +
76814 return security_task_kill(t, info, sig, 0);
76815 }
76816
76817 @@ -1194,7 +1204,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
76818 return send_signal(sig, info, p, 1);
76819 }
76820
76821 -static int
76822 +int
76823 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76824 {
76825 return send_signal(sig, info, t, 0);
76826 @@ -1231,6 +1241,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76827 unsigned long int flags;
76828 int ret, blocked, ignored;
76829 struct k_sigaction *action;
76830 + int is_unhandled = 0;
76831
76832 spin_lock_irqsave(&t->sighand->siglock, flags);
76833 action = &t->sighand->action[sig-1];
76834 @@ -1245,9 +1256,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76835 }
76836 if (action->sa.sa_handler == SIG_DFL)
76837 t->signal->flags &= ~SIGNAL_UNKILLABLE;
76838 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
76839 + is_unhandled = 1;
76840 ret = specific_send_sig_info(sig, info, t);
76841 spin_unlock_irqrestore(&t->sighand->siglock, flags);
76842
76843 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
76844 + normal operation */
76845 + if (is_unhandled) {
76846 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
76847 + gr_handle_crash(t, sig);
76848 + }
76849 +
76850 return ret;
76851 }
76852
76853 @@ -1314,8 +1334,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
76854 ret = check_kill_permission(sig, info, p);
76855 rcu_read_unlock();
76856
76857 - if (!ret && sig)
76858 + if (!ret && sig) {
76859 ret = do_send_sig_info(sig, info, p, true);
76860 + if (!ret)
76861 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
76862 + }
76863
76864 return ret;
76865 }
76866 @@ -2852,7 +2875,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
76867 int error = -ESRCH;
76868
76869 rcu_read_lock();
76870 - p = find_task_by_vpid(pid);
76871 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76872 + /* allow glibc communication via tgkill to other threads in our
76873 + thread group */
76874 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
76875 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
76876 + p = find_task_by_vpid_unrestricted(pid);
76877 + else
76878 +#endif
76879 + p = find_task_by_vpid(pid);
76880 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
76881 error = check_kill_permission(sig, info, p);
76882 /*
76883 @@ -3135,8 +3166,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
76884 }
76885 seg = get_fs();
76886 set_fs(KERNEL_DS);
76887 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
76888 - (stack_t __force __user *) &uoss,
76889 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
76890 + (stack_t __force_user *) &uoss,
76891 compat_user_stack_pointer());
76892 set_fs(seg);
76893 if (ret >= 0 && uoss_ptr) {
76894 diff --git a/kernel/smp.c b/kernel/smp.c
76895 index 69f38bd..77bbf12 100644
76896 --- a/kernel/smp.c
76897 +++ b/kernel/smp.c
76898 @@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
76899 return NOTIFY_OK;
76900 }
76901
76902 -static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
76903 +static struct notifier_block hotplug_cfd_notifier = {
76904 .notifier_call = hotplug_cfd,
76905 };
76906
76907 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
76908 index d6c5fc0..530560c 100644
76909 --- a/kernel/smpboot.c
76910 +++ b/kernel/smpboot.c
76911 @@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
76912 }
76913 smpboot_unpark_thread(plug_thread, cpu);
76914 }
76915 - list_add(&plug_thread->list, &hotplug_threads);
76916 + pax_list_add(&plug_thread->list, &hotplug_threads);
76917 out:
76918 mutex_unlock(&smpboot_threads_lock);
76919 return ret;
76920 @@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
76921 {
76922 get_online_cpus();
76923 mutex_lock(&smpboot_threads_lock);
76924 - list_del(&plug_thread->list);
76925 + pax_list_del(&plug_thread->list);
76926 smpboot_destroy_threads(plug_thread);
76927 mutex_unlock(&smpboot_threads_lock);
76928 put_online_cpus();
76929 diff --git a/kernel/softirq.c b/kernel/softirq.c
76930 index ed567ba..e71dabf 100644
76931 --- a/kernel/softirq.c
76932 +++ b/kernel/softirq.c
76933 @@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
76934 EXPORT_SYMBOL(irq_stat);
76935 #endif
76936
76937 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
76938 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
76939
76940 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
76941
76942 -char *softirq_to_name[NR_SOFTIRQS] = {
76943 +const char * const softirq_to_name[NR_SOFTIRQS] = {
76944 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
76945 "TASKLET", "SCHED", "HRTIMER", "RCU"
76946 };
76947 @@ -244,7 +244,7 @@ restart:
76948 kstat_incr_softirqs_this_cpu(vec_nr);
76949
76950 trace_softirq_entry(vec_nr);
76951 - h->action(h);
76952 + h->action();
76953 trace_softirq_exit(vec_nr);
76954 if (unlikely(prev_count != preempt_count())) {
76955 printk(KERN_ERR "huh, entered softirq %u %s %p"
76956 @@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
76957 or_softirq_pending(1UL << nr);
76958 }
76959
76960 -void open_softirq(int nr, void (*action)(struct softirq_action *))
76961 +void __init open_softirq(int nr, void (*action)(void))
76962 {
76963 softirq_vec[nr].action = action;
76964 }
76965 @@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
76966
76967 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
76968
76969 -static void tasklet_action(struct softirq_action *a)
76970 +static void tasklet_action(void)
76971 {
76972 struct tasklet_struct *list;
76973
76974 @@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
76975 }
76976 }
76977
76978 -static void tasklet_hi_action(struct softirq_action *a)
76979 +static void tasklet_hi_action(void)
76980 {
76981 struct tasklet_struct *list;
76982
76983 @@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
76984 return NOTIFY_OK;
76985 }
76986
76987 -static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
76988 +static struct notifier_block remote_softirq_cpu_notifier = {
76989 .notifier_call = remote_softirq_cpu_notify,
76990 };
76991
76992 @@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
76993 return NOTIFY_OK;
76994 }
76995
76996 -static struct notifier_block __cpuinitdata cpu_nfb = {
76997 +static struct notifier_block cpu_nfb = {
76998 .notifier_call = cpu_callback
76999 };
77000
77001 -static struct smp_hotplug_thread softirq_threads = {
77002 +static struct smp_hotplug_thread softirq_threads __read_only = {
77003 .store = &ksoftirqd,
77004 .thread_should_run = ksoftirqd_should_run,
77005 .thread_fn = run_ksoftirqd,
77006 diff --git a/kernel/srcu.c b/kernel/srcu.c
77007 index 2b85982..d52ab26 100644
77008 --- a/kernel/srcu.c
77009 +++ b/kernel/srcu.c
77010 @@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
77011 preempt_disable();
77012 idx = rcu_dereference_index_check(sp->completed,
77013 rcu_read_lock_sched_held()) & 0x1;
77014 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77015 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77016 smp_mb(); /* B */ /* Avoid leaking the critical section. */
77017 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77018 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77019 preempt_enable();
77020 return idx;
77021 }
77022 @@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
77023 {
77024 preempt_disable();
77025 smp_mb(); /* C */ /* Avoid leaking the critical section. */
77026 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77027 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77028 preempt_enable();
77029 }
77030 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
77031 diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
77032 index 2f194e9..2c05ea9 100644
77033 --- a/kernel/stop_machine.c
77034 +++ b/kernel/stop_machine.c
77035 @@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
77036 * cpu notifiers. It currently shares the same priority as sched
77037 * migration_notifier.
77038 */
77039 -static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
77040 +static struct notifier_block cpu_stop_cpu_notifier = {
77041 .notifier_call = cpu_stop_cpu_callback,
77042 .priority = 10,
77043 };
77044 diff --git a/kernel/sys.c b/kernel/sys.c
77045 index 265b376..4e42ef5 100644
77046 --- a/kernel/sys.c
77047 +++ b/kernel/sys.c
77048 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
77049 error = -EACCES;
77050 goto out;
77051 }
77052 +
77053 + if (gr_handle_chroot_setpriority(p, niceval)) {
77054 + error = -EACCES;
77055 + goto out;
77056 + }
77057 +
77058 no_nice = security_task_setnice(p, niceval);
77059 if (no_nice) {
77060 error = no_nice;
77061 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
77062 goto error;
77063 }
77064
77065 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
77066 + goto error;
77067 +
77068 if (rgid != (gid_t) -1 ||
77069 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
77070 new->sgid = new->egid;
77071 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
77072 old = current_cred();
77073
77074 retval = -EPERM;
77075 +
77076 + if (gr_check_group_change(kgid, kgid, kgid))
77077 + goto error;
77078 +
77079 if (nsown_capable(CAP_SETGID))
77080 new->gid = new->egid = new->sgid = new->fsgid = kgid;
77081 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
77082 @@ -647,7 +660,7 @@ error:
77083 /*
77084 * change the user struct in a credentials set to match the new UID
77085 */
77086 -static int set_user(struct cred *new)
77087 +int set_user(struct cred *new)
77088 {
77089 struct user_struct *new_user;
77090
77091 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
77092 goto error;
77093 }
77094
77095 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
77096 + goto error;
77097 +
77098 if (!uid_eq(new->uid, old->uid)) {
77099 retval = set_user(new);
77100 if (retval < 0)
77101 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
77102 old = current_cred();
77103
77104 retval = -EPERM;
77105 +
77106 + if (gr_check_crash_uid(kuid))
77107 + goto error;
77108 + if (gr_check_user_change(kuid, kuid, kuid))
77109 + goto error;
77110 +
77111 if (nsown_capable(CAP_SETUID)) {
77112 new->suid = new->uid = kuid;
77113 if (!uid_eq(kuid, old->uid)) {
77114 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
77115 goto error;
77116 }
77117
77118 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
77119 + goto error;
77120 +
77121 if (ruid != (uid_t) -1) {
77122 new->uid = kruid;
77123 if (!uid_eq(kruid, old->uid)) {
77124 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
77125 goto error;
77126 }
77127
77128 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
77129 + goto error;
77130 +
77131 if (rgid != (gid_t) -1)
77132 new->gid = krgid;
77133 if (egid != (gid_t) -1)
77134 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77135 if (!uid_valid(kuid))
77136 return old_fsuid;
77137
77138 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
77139 + goto error;
77140 +
77141 new = prepare_creds();
77142 if (!new)
77143 return old_fsuid;
77144 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77145 }
77146 }
77147
77148 +error:
77149 abort_creds(new);
77150 return old_fsuid;
77151
77152 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
77153 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
77154 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
77155 nsown_capable(CAP_SETGID)) {
77156 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
77157 + goto error;
77158 +
77159 if (!gid_eq(kgid, old->fsgid)) {
77160 new->fsgid = kgid;
77161 goto change_okay;
77162 }
77163 }
77164
77165 +error:
77166 abort_creds(new);
77167 return old_fsgid;
77168
77169 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
77170 return -EFAULT;
77171
77172 down_read(&uts_sem);
77173 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
77174 + error = __copy_to_user(name->sysname, &utsname()->sysname,
77175 __OLD_UTS_LEN);
77176 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
77177 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
77178 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
77179 __OLD_UTS_LEN);
77180 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
77181 - error |= __copy_to_user(&name->release, &utsname()->release,
77182 + error |= __copy_to_user(name->release, &utsname()->release,
77183 __OLD_UTS_LEN);
77184 error |= __put_user(0, name->release + __OLD_UTS_LEN);
77185 - error |= __copy_to_user(&name->version, &utsname()->version,
77186 + error |= __copy_to_user(name->version, &utsname()->version,
77187 __OLD_UTS_LEN);
77188 error |= __put_user(0, name->version + __OLD_UTS_LEN);
77189 - error |= __copy_to_user(&name->machine, &utsname()->machine,
77190 + error |= __copy_to_user(name->machine, &utsname()->machine,
77191 __OLD_UTS_LEN);
77192 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
77193 up_read(&uts_sem);
77194 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
77195 error = get_dumpable(me->mm);
77196 break;
77197 case PR_SET_DUMPABLE:
77198 - if (arg2 < 0 || arg2 > 1) {
77199 + if (arg2 > 1) {
77200 error = -EINVAL;
77201 break;
77202 }
77203 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
77204 index c88878d..e4fa5d1 100644
77205 --- a/kernel/sysctl.c
77206 +++ b/kernel/sysctl.c
77207 @@ -92,7 +92,6 @@
77208
77209
77210 #if defined(CONFIG_SYSCTL)
77211 -
77212 /* External variables not in a header file. */
77213 extern int sysctl_overcommit_memory;
77214 extern int sysctl_overcommit_ratio;
77215 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
77216 void __user *buffer, size_t *lenp, loff_t *ppos);
77217 #endif
77218
77219 -#ifdef CONFIG_PRINTK
77220 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77221 void __user *buffer, size_t *lenp, loff_t *ppos);
77222 -#endif
77223
77224 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
77225 void __user *buffer, size_t *lenp, loff_t *ppos);
77226 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
77227
77228 #endif
77229
77230 +extern struct ctl_table grsecurity_table[];
77231 +
77232 static struct ctl_table kern_table[];
77233 static struct ctl_table vm_table[];
77234 static struct ctl_table fs_table[];
77235 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
77236 int sysctl_legacy_va_layout;
77237 #endif
77238
77239 +#ifdef CONFIG_PAX_SOFTMODE
77240 +static ctl_table pax_table[] = {
77241 + {
77242 + .procname = "softmode",
77243 + .data = &pax_softmode,
77244 + .maxlen = sizeof(unsigned int),
77245 + .mode = 0600,
77246 + .proc_handler = &proc_dointvec,
77247 + },
77248 +
77249 + { }
77250 +};
77251 +#endif
77252 +
77253 /* The default sysctl tables: */
77254
77255 static struct ctl_table sysctl_base_table[] = {
77256 @@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
77257 #endif
77258
77259 static struct ctl_table kern_table[] = {
77260 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
77261 + {
77262 + .procname = "grsecurity",
77263 + .mode = 0500,
77264 + .child = grsecurity_table,
77265 + },
77266 +#endif
77267 +
77268 +#ifdef CONFIG_PAX_SOFTMODE
77269 + {
77270 + .procname = "pax",
77271 + .mode = 0500,
77272 + .child = pax_table,
77273 + },
77274 +#endif
77275 +
77276 {
77277 .procname = "sched_child_runs_first",
77278 .data = &sysctl_sched_child_runs_first,
77279 @@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
77280 .data = &modprobe_path,
77281 .maxlen = KMOD_PATH_LEN,
77282 .mode = 0644,
77283 - .proc_handler = proc_dostring,
77284 + .proc_handler = proc_dostring_modpriv,
77285 },
77286 {
77287 .procname = "modules_disabled",
77288 @@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
77289 .extra1 = &zero,
77290 .extra2 = &one,
77291 },
77292 +#endif
77293 {
77294 .procname = "kptr_restrict",
77295 .data = &kptr_restrict,
77296 .maxlen = sizeof(int),
77297 .mode = 0644,
77298 .proc_handler = proc_dointvec_minmax_sysadmin,
77299 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77300 + .extra1 = &two,
77301 +#else
77302 .extra1 = &zero,
77303 +#endif
77304 .extra2 = &two,
77305 },
77306 -#endif
77307 {
77308 .procname = "ngroups_max",
77309 .data = &ngroups_max,
77310 @@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
77311 .proc_handler = proc_dointvec_minmax,
77312 .extra1 = &zero,
77313 },
77314 + {
77315 + .procname = "heap_stack_gap",
77316 + .data = &sysctl_heap_stack_gap,
77317 + .maxlen = sizeof(sysctl_heap_stack_gap),
77318 + .mode = 0644,
77319 + .proc_handler = proc_doulongvec_minmax,
77320 + },
77321 #else
77322 {
77323 .procname = "nr_trim_pages",
77324 @@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
77325 buffer, lenp, ppos);
77326 }
77327
77328 +int proc_dostring_modpriv(struct ctl_table *table, int write,
77329 + void __user *buffer, size_t *lenp, loff_t *ppos)
77330 +{
77331 + if (write && !capable(CAP_SYS_MODULE))
77332 + return -EPERM;
77333 +
77334 + return _proc_do_string(table->data, table->maxlen, write,
77335 + buffer, lenp, ppos);
77336 +}
77337 +
77338 static size_t proc_skip_spaces(char **buf)
77339 {
77340 size_t ret;
77341 @@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
77342 len = strlen(tmp);
77343 if (len > *size)
77344 len = *size;
77345 + if (len > sizeof(tmp))
77346 + len = sizeof(tmp);
77347 if (copy_to_user(*buf, tmp, len))
77348 return -EFAULT;
77349 *size -= len;
77350 @@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
77351 static int proc_taint(struct ctl_table *table, int write,
77352 void __user *buffer, size_t *lenp, loff_t *ppos)
77353 {
77354 - struct ctl_table t;
77355 + ctl_table_no_const t;
77356 unsigned long tmptaint = get_taint();
77357 int err;
77358
77359 @@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
77360 return err;
77361 }
77362
77363 -#ifdef CONFIG_PRINTK
77364 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77365 void __user *buffer, size_t *lenp, loff_t *ppos)
77366 {
77367 @@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77368
77369 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
77370 }
77371 -#endif
77372
77373 struct do_proc_dointvec_minmax_conv_param {
77374 int *min;
77375 @@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
77376 *i = val;
77377 } else {
77378 val = convdiv * (*i) / convmul;
77379 - if (!first)
77380 + if (!first) {
77381 err = proc_put_char(&buffer, &left, '\t');
77382 + if (err)
77383 + break;
77384 + }
77385 err = proc_put_long(&buffer, &left, val, false);
77386 if (err)
77387 break;
77388 @@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
77389 return -ENOSYS;
77390 }
77391
77392 +int proc_dostring_modpriv(struct ctl_table *table, int write,
77393 + void __user *buffer, size_t *lenp, loff_t *ppos)
77394 +{
77395 + return -ENOSYS;
77396 +}
77397 +
77398 int proc_dointvec(struct ctl_table *table, int write,
77399 void __user *buffer, size_t *lenp, loff_t *ppos)
77400 {
77401 @@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
77402 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
77403 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
77404 EXPORT_SYMBOL(proc_dostring);
77405 +EXPORT_SYMBOL(proc_dostring_modpriv);
77406 EXPORT_SYMBOL(proc_doulongvec_minmax);
77407 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
77408 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
77409 index 0ddf3a0..a199f50 100644
77410 --- a/kernel/sysctl_binary.c
77411 +++ b/kernel/sysctl_binary.c
77412 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
77413 int i;
77414
77415 set_fs(KERNEL_DS);
77416 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
77417 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
77418 set_fs(old_fs);
77419 if (result < 0)
77420 goto out_kfree;
77421 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
77422 }
77423
77424 set_fs(KERNEL_DS);
77425 - result = vfs_write(file, buffer, str - buffer, &pos);
77426 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
77427 set_fs(old_fs);
77428 if (result < 0)
77429 goto out_kfree;
77430 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
77431 int i;
77432
77433 set_fs(KERNEL_DS);
77434 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
77435 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
77436 set_fs(old_fs);
77437 if (result < 0)
77438 goto out_kfree;
77439 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
77440 }
77441
77442 set_fs(KERNEL_DS);
77443 - result = vfs_write(file, buffer, str - buffer, &pos);
77444 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
77445 set_fs(old_fs);
77446 if (result < 0)
77447 goto out_kfree;
77448 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
77449 int i;
77450
77451 set_fs(KERNEL_DS);
77452 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
77453 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
77454 set_fs(old_fs);
77455 if (result < 0)
77456 goto out;
77457 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
77458 __le16 dnaddr;
77459
77460 set_fs(KERNEL_DS);
77461 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
77462 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
77463 set_fs(old_fs);
77464 if (result < 0)
77465 goto out;
77466 @@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
77467 le16_to_cpu(dnaddr) & 0x3ff);
77468
77469 set_fs(KERNEL_DS);
77470 - result = vfs_write(file, buf, len, &pos);
77471 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
77472 set_fs(old_fs);
77473 if (result < 0)
77474 goto out;
77475 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
77476 index 145bb4d..b2aa969 100644
77477 --- a/kernel/taskstats.c
77478 +++ b/kernel/taskstats.c
77479 @@ -28,9 +28,12 @@
77480 #include <linux/fs.h>
77481 #include <linux/file.h>
77482 #include <linux/pid_namespace.h>
77483 +#include <linux/grsecurity.h>
77484 #include <net/genetlink.h>
77485 #include <linux/atomic.h>
77486
77487 +extern int gr_is_taskstats_denied(int pid);
77488 +
77489 /*
77490 * Maximum length of a cpumask that can be specified in
77491 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
77492 @@ -570,6 +573,9 @@ err:
77493
77494 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
77495 {
77496 + if (gr_is_taskstats_denied(current->pid))
77497 + return -EACCES;
77498 +
77499 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
77500 return cmd_attr_register_cpumask(info);
77501 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
77502 diff --git a/kernel/time.c b/kernel/time.c
77503 index d226c6a..c7c0960 100644
77504 --- a/kernel/time.c
77505 +++ b/kernel/time.c
77506 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
77507 return error;
77508
77509 if (tz) {
77510 + /* we log in do_settimeofday called below, so don't log twice
77511 + */
77512 + if (!tv)
77513 + gr_log_timechange();
77514 +
77515 sys_tz = *tz;
77516 update_vsyscall_tz();
77517 if (firsttime) {
77518 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
77519 index f11d83b..d016d91 100644
77520 --- a/kernel/time/alarmtimer.c
77521 +++ b/kernel/time/alarmtimer.c
77522 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
77523 struct platform_device *pdev;
77524 int error = 0;
77525 int i;
77526 - struct k_clock alarm_clock = {
77527 + static struct k_clock alarm_clock = {
77528 .clock_getres = alarm_clock_getres,
77529 .clock_get = alarm_clock_get,
77530 .timer_create = alarm_timer_create,
77531 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
77532 index f113755..ec24223 100644
77533 --- a/kernel/time/tick-broadcast.c
77534 +++ b/kernel/time/tick-broadcast.c
77535 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
77536 * then clear the broadcast bit.
77537 */
77538 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
77539 - int cpu = smp_processor_id();
77540 + cpu = smp_processor_id();
77541
77542 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
77543 tick_broadcast_clear_oneshot(cpu);
77544 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
77545 index cbc6acb..3a77191 100644
77546 --- a/kernel/time/timekeeping.c
77547 +++ b/kernel/time/timekeeping.c
77548 @@ -15,6 +15,7 @@
77549 #include <linux/init.h>
77550 #include <linux/mm.h>
77551 #include <linux/sched.h>
77552 +#include <linux/grsecurity.h>
77553 #include <linux/syscore_ops.h>
77554 #include <linux/clocksource.h>
77555 #include <linux/jiffies.h>
77556 @@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
77557 if (!timespec_valid_strict(tv))
77558 return -EINVAL;
77559
77560 + gr_log_timechange();
77561 +
77562 write_seqlock_irqsave(&tk->lock, flags);
77563
77564 timekeeping_forward_now(tk);
77565 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
77566 index af5a7e9..715611a 100644
77567 --- a/kernel/time/timer_list.c
77568 +++ b/kernel/time/timer_list.c
77569 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
77570
77571 static void print_name_offset(struct seq_file *m, void *sym)
77572 {
77573 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77574 + SEQ_printf(m, "<%p>", NULL);
77575 +#else
77576 char symname[KSYM_NAME_LEN];
77577
77578 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
77579 SEQ_printf(m, "<%pK>", sym);
77580 else
77581 SEQ_printf(m, "%s", symname);
77582 +#endif
77583 }
77584
77585 static void
77586 @@ -112,7 +116,11 @@ next_one:
77587 static void
77588 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
77589 {
77590 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77591 + SEQ_printf(m, " .base: %p\n", NULL);
77592 +#else
77593 SEQ_printf(m, " .base: %pK\n", base);
77594 +#endif
77595 SEQ_printf(m, " .index: %d\n",
77596 base->index);
77597 SEQ_printf(m, " .resolution: %Lu nsecs\n",
77598 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
77599 {
77600 struct proc_dir_entry *pe;
77601
77602 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
77603 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
77604 +#else
77605 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
77606 +#endif
77607 if (!pe)
77608 return -ENOMEM;
77609 return 0;
77610 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
77611 index 0b537f2..40d6c20 100644
77612 --- a/kernel/time/timer_stats.c
77613 +++ b/kernel/time/timer_stats.c
77614 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
77615 static unsigned long nr_entries;
77616 static struct entry entries[MAX_ENTRIES];
77617
77618 -static atomic_t overflow_count;
77619 +static atomic_unchecked_t overflow_count;
77620
77621 /*
77622 * The entries are in a hash-table, for fast lookup:
77623 @@ -140,7 +140,7 @@ static void reset_entries(void)
77624 nr_entries = 0;
77625 memset(entries, 0, sizeof(entries));
77626 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
77627 - atomic_set(&overflow_count, 0);
77628 + atomic_set_unchecked(&overflow_count, 0);
77629 }
77630
77631 static struct entry *alloc_entry(void)
77632 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
77633 if (likely(entry))
77634 entry->count++;
77635 else
77636 - atomic_inc(&overflow_count);
77637 + atomic_inc_unchecked(&overflow_count);
77638
77639 out_unlock:
77640 raw_spin_unlock_irqrestore(lock, flags);
77641 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
77642
77643 static void print_name_offset(struct seq_file *m, unsigned long addr)
77644 {
77645 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77646 + seq_printf(m, "<%p>", NULL);
77647 +#else
77648 char symname[KSYM_NAME_LEN];
77649
77650 if (lookup_symbol_name(addr, symname) < 0)
77651 - seq_printf(m, "<%p>", (void *)addr);
77652 + seq_printf(m, "<%pK>", (void *)addr);
77653 else
77654 seq_printf(m, "%s", symname);
77655 +#endif
77656 }
77657
77658 static int tstats_show(struct seq_file *m, void *v)
77659 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
77660
77661 seq_puts(m, "Timer Stats Version: v0.2\n");
77662 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
77663 - if (atomic_read(&overflow_count))
77664 + if (atomic_read_unchecked(&overflow_count))
77665 seq_printf(m, "Overflow: %d entries\n",
77666 - atomic_read(&overflow_count));
77667 + atomic_read_unchecked(&overflow_count));
77668
77669 for (i = 0; i < nr_entries; i++) {
77670 entry = entries + i;
77671 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
77672 {
77673 struct proc_dir_entry *pe;
77674
77675 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
77676 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
77677 +#else
77678 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
77679 +#endif
77680 if (!pe)
77681 return -ENOMEM;
77682 return 0;
77683 diff --git a/kernel/timer.c b/kernel/timer.c
77684 index 367d008..1ee9ed9 100644
77685 --- a/kernel/timer.c
77686 +++ b/kernel/timer.c
77687 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
77688 /*
77689 * This function runs timers and the timer-tq in bottom half context.
77690 */
77691 -static void run_timer_softirq(struct softirq_action *h)
77692 +static void run_timer_softirq(void)
77693 {
77694 struct tvec_base *base = __this_cpu_read(tvec_bases);
77695
77696 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
77697 return NOTIFY_OK;
77698 }
77699
77700 -static struct notifier_block __cpuinitdata timers_nb = {
77701 +static struct notifier_block timers_nb = {
77702 .notifier_call = timer_cpu_notify,
77703 };
77704
77705 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
77706 index c0bd030..62a1927 100644
77707 --- a/kernel/trace/blktrace.c
77708 +++ b/kernel/trace/blktrace.c
77709 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
77710 struct blk_trace *bt = filp->private_data;
77711 char buf[16];
77712
77713 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
77714 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
77715
77716 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
77717 }
77718 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
77719 return 1;
77720
77721 bt = buf->chan->private_data;
77722 - atomic_inc(&bt->dropped);
77723 + atomic_inc_unchecked(&bt->dropped);
77724 return 0;
77725 }
77726
77727 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
77728
77729 bt->dir = dir;
77730 bt->dev = dev;
77731 - atomic_set(&bt->dropped, 0);
77732 + atomic_set_unchecked(&bt->dropped, 0);
77733
77734 ret = -EIO;
77735 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
77736 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
77737 index 43defd1..76da436 100644
77738 --- a/kernel/trace/ftrace.c
77739 +++ b/kernel/trace/ftrace.c
77740 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
77741 if (unlikely(ftrace_disabled))
77742 return 0;
77743
77744 + ret = ftrace_arch_code_modify_prepare();
77745 + FTRACE_WARN_ON(ret);
77746 + if (ret)
77747 + return 0;
77748 +
77749 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
77750 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
77751 if (ret) {
77752 ftrace_bug(ret, ip);
77753 - return 0;
77754 }
77755 - return 1;
77756 + return ret ? 0 : 1;
77757 }
77758
77759 /*
77760 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
77761
77762 int
77763 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
77764 - void *data)
77765 + void *data)
77766 {
77767 struct ftrace_func_probe *entry;
77768 struct ftrace_page *pg;
77769 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
77770 if (!count)
77771 return 0;
77772
77773 + pax_open_kernel();
77774 sort(start, count, sizeof(*start),
77775 ftrace_cmp_ips, ftrace_swap_ips);
77776 + pax_close_kernel();
77777
77778 start_pg = ftrace_allocate_pages(count);
77779 if (!start_pg)
77780 @@ -4559,8 +4566,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
77781 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
77782
77783 static int ftrace_graph_active;
77784 -static struct notifier_block ftrace_suspend_notifier;
77785 -
77786 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
77787 {
77788 return 0;
77789 @@ -4704,6 +4709,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
77790 return NOTIFY_DONE;
77791 }
77792
77793 +static struct notifier_block ftrace_suspend_notifier = {
77794 + .notifier_call = ftrace_suspend_notifier_call
77795 +};
77796 +
77797 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
77798 trace_func_graph_ent_t entryfunc)
77799 {
77800 @@ -4717,7 +4726,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
77801 goto out;
77802 }
77803
77804 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
77805 register_pm_notifier(&ftrace_suspend_notifier);
77806
77807 ftrace_graph_active++;
77808 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
77809 index ce8514f..8233573 100644
77810 --- a/kernel/trace/ring_buffer.c
77811 +++ b/kernel/trace/ring_buffer.c
77812 @@ -346,9 +346,9 @@ struct buffer_data_page {
77813 */
77814 struct buffer_page {
77815 struct list_head list; /* list of buffer pages */
77816 - local_t write; /* index for next write */
77817 + local_unchecked_t write; /* index for next write */
77818 unsigned read; /* index for next read */
77819 - local_t entries; /* entries on this page */
77820 + local_unchecked_t entries; /* entries on this page */
77821 unsigned long real_end; /* real end of data */
77822 struct buffer_data_page *page; /* Actual data page */
77823 };
77824 @@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
77825 unsigned long last_overrun;
77826 local_t entries_bytes;
77827 local_t entries;
77828 - local_t overrun;
77829 - local_t commit_overrun;
77830 + local_unchecked_t overrun;
77831 + local_unchecked_t commit_overrun;
77832 local_t dropped_events;
77833 local_t committing;
77834 local_t commits;
77835 @@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
77836 *
77837 * We add a counter to the write field to denote this.
77838 */
77839 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
77840 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
77841 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
77842 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
77843
77844 /*
77845 * Just make sure we have seen our old_write and synchronize
77846 @@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
77847 * cmpxchg to only update if an interrupt did not already
77848 * do it for us. If the cmpxchg fails, we don't care.
77849 */
77850 - (void)local_cmpxchg(&next_page->write, old_write, val);
77851 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
77852 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
77853 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
77854
77855 /*
77856 * No need to worry about races with clearing out the commit.
77857 @@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
77858
77859 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
77860 {
77861 - return local_read(&bpage->entries) & RB_WRITE_MASK;
77862 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
77863 }
77864
77865 static inline unsigned long rb_page_write(struct buffer_page *bpage)
77866 {
77867 - return local_read(&bpage->write) & RB_WRITE_MASK;
77868 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
77869 }
77870
77871 static int
77872 @@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
77873 * bytes consumed in ring buffer from here.
77874 * Increment overrun to account for the lost events.
77875 */
77876 - local_add(page_entries, &cpu_buffer->overrun);
77877 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
77878 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
77879 }
77880
77881 @@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
77882 * it is our responsibility to update
77883 * the counters.
77884 */
77885 - local_add(entries, &cpu_buffer->overrun);
77886 + local_add_unchecked(entries, &cpu_buffer->overrun);
77887 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
77888
77889 /*
77890 @@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77891 if (tail == BUF_PAGE_SIZE)
77892 tail_page->real_end = 0;
77893
77894 - local_sub(length, &tail_page->write);
77895 + local_sub_unchecked(length, &tail_page->write);
77896 return;
77897 }
77898
77899 @@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77900 rb_event_set_padding(event);
77901
77902 /* Set the write back to the previous setting */
77903 - local_sub(length, &tail_page->write);
77904 + local_sub_unchecked(length, &tail_page->write);
77905 return;
77906 }
77907
77908 @@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77909
77910 /* Set write to end of buffer */
77911 length = (tail + length) - BUF_PAGE_SIZE;
77912 - local_sub(length, &tail_page->write);
77913 + local_sub_unchecked(length, &tail_page->write);
77914 }
77915
77916 /*
77917 @@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
77918 * about it.
77919 */
77920 if (unlikely(next_page == commit_page)) {
77921 - local_inc(&cpu_buffer->commit_overrun);
77922 + local_inc_unchecked(&cpu_buffer->commit_overrun);
77923 goto out_reset;
77924 }
77925
77926 @@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
77927 cpu_buffer->tail_page) &&
77928 (cpu_buffer->commit_page ==
77929 cpu_buffer->reader_page))) {
77930 - local_inc(&cpu_buffer->commit_overrun);
77931 + local_inc_unchecked(&cpu_buffer->commit_overrun);
77932 goto out_reset;
77933 }
77934 }
77935 @@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
77936 length += RB_LEN_TIME_EXTEND;
77937
77938 tail_page = cpu_buffer->tail_page;
77939 - write = local_add_return(length, &tail_page->write);
77940 + write = local_add_return_unchecked(length, &tail_page->write);
77941
77942 /* set write to only the index of the write */
77943 write &= RB_WRITE_MASK;
77944 @@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
77945 kmemcheck_annotate_bitfield(event, bitfield);
77946 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
77947
77948 - local_inc(&tail_page->entries);
77949 + local_inc_unchecked(&tail_page->entries);
77950
77951 /*
77952 * If this is the first commit on the page, then update
77953 @@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
77954
77955 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
77956 unsigned long write_mask =
77957 - local_read(&bpage->write) & ~RB_WRITE_MASK;
77958 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
77959 unsigned long event_length = rb_event_length(event);
77960 /*
77961 * This is on the tail page. It is possible that
77962 @@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
77963 */
77964 old_index += write_mask;
77965 new_index += write_mask;
77966 - index = local_cmpxchg(&bpage->write, old_index, new_index);
77967 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
77968 if (index == old_index) {
77969 /* update counters */
77970 local_sub(event_length, &cpu_buffer->entries_bytes);
77971 @@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
77972
77973 /* Do the likely case first */
77974 if (likely(bpage->page == (void *)addr)) {
77975 - local_dec(&bpage->entries);
77976 + local_dec_unchecked(&bpage->entries);
77977 return;
77978 }
77979
77980 @@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
77981 start = bpage;
77982 do {
77983 if (bpage->page == (void *)addr) {
77984 - local_dec(&bpage->entries);
77985 + local_dec_unchecked(&bpage->entries);
77986 return;
77987 }
77988 rb_inc_page(cpu_buffer, &bpage);
77989 @@ -2926,7 +2926,7 @@ static inline unsigned long
77990 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
77991 {
77992 return local_read(&cpu_buffer->entries) -
77993 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
77994 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
77995 }
77996
77997 /**
77998 @@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
77999 return 0;
78000
78001 cpu_buffer = buffer->buffers[cpu];
78002 - ret = local_read(&cpu_buffer->overrun);
78003 + ret = local_read_unchecked(&cpu_buffer->overrun);
78004
78005 return ret;
78006 }
78007 @@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
78008 return 0;
78009
78010 cpu_buffer = buffer->buffers[cpu];
78011 - ret = local_read(&cpu_buffer->commit_overrun);
78012 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
78013
78014 return ret;
78015 }
78016 @@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
78017 /* if you care about this being correct, lock the buffer */
78018 for_each_buffer_cpu(buffer, cpu) {
78019 cpu_buffer = buffer->buffers[cpu];
78020 - overruns += local_read(&cpu_buffer->overrun);
78021 + overruns += local_read_unchecked(&cpu_buffer->overrun);
78022 }
78023
78024 return overruns;
78025 @@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78026 /*
78027 * Reset the reader page to size zero.
78028 */
78029 - local_set(&cpu_buffer->reader_page->write, 0);
78030 - local_set(&cpu_buffer->reader_page->entries, 0);
78031 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78032 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78033 local_set(&cpu_buffer->reader_page->page->commit, 0);
78034 cpu_buffer->reader_page->real_end = 0;
78035
78036 @@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78037 * want to compare with the last_overrun.
78038 */
78039 smp_mb();
78040 - overwrite = local_read(&(cpu_buffer->overrun));
78041 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
78042
78043 /*
78044 * Here's the tricky part.
78045 @@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78046
78047 cpu_buffer->head_page
78048 = list_entry(cpu_buffer->pages, struct buffer_page, list);
78049 - local_set(&cpu_buffer->head_page->write, 0);
78050 - local_set(&cpu_buffer->head_page->entries, 0);
78051 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
78052 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
78053 local_set(&cpu_buffer->head_page->page->commit, 0);
78054
78055 cpu_buffer->head_page->read = 0;
78056 @@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78057
78058 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
78059 INIT_LIST_HEAD(&cpu_buffer->new_pages);
78060 - local_set(&cpu_buffer->reader_page->write, 0);
78061 - local_set(&cpu_buffer->reader_page->entries, 0);
78062 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78063 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78064 local_set(&cpu_buffer->reader_page->page->commit, 0);
78065 cpu_buffer->reader_page->read = 0;
78066
78067 local_set(&cpu_buffer->entries_bytes, 0);
78068 - local_set(&cpu_buffer->overrun, 0);
78069 - local_set(&cpu_buffer->commit_overrun, 0);
78070 + local_set_unchecked(&cpu_buffer->overrun, 0);
78071 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
78072 local_set(&cpu_buffer->dropped_events, 0);
78073 local_set(&cpu_buffer->entries, 0);
78074 local_set(&cpu_buffer->committing, 0);
78075 @@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
78076 rb_init_page(bpage);
78077 bpage = reader->page;
78078 reader->page = *data_page;
78079 - local_set(&reader->write, 0);
78080 - local_set(&reader->entries, 0);
78081 + local_set_unchecked(&reader->write, 0);
78082 + local_set_unchecked(&reader->entries, 0);
78083 reader->read = 0;
78084 *data_page = bpage;
78085
78086 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
78087 index 3c13e46..883d039 100644
78088 --- a/kernel/trace/trace.c
78089 +++ b/kernel/trace/trace.c
78090 @@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
78091 };
78092 #endif
78093
78094 -static struct dentry *d_tracer;
78095 -
78096 struct dentry *tracing_init_dentry(void)
78097 {
78098 + static struct dentry *d_tracer;
78099 static int once;
78100
78101 if (d_tracer)
78102 @@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
78103 return d_tracer;
78104 }
78105
78106 -static struct dentry *d_percpu;
78107 -
78108 struct dentry *tracing_dentry_percpu(void)
78109 {
78110 + static struct dentry *d_percpu;
78111 static int once;
78112 struct dentry *d_tracer;
78113
78114 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
78115 index 880073d..42db7c3 100644
78116 --- a/kernel/trace/trace_events.c
78117 +++ b/kernel/trace/trace_events.c
78118 @@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
78119 struct ftrace_module_file_ops {
78120 struct list_head list;
78121 struct module *mod;
78122 - struct file_operations id;
78123 - struct file_operations enable;
78124 - struct file_operations format;
78125 - struct file_operations filter;
78126 };
78127
78128 static struct ftrace_module_file_ops *
78129 @@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
78130
78131 file_ops->mod = mod;
78132
78133 - file_ops->id = ftrace_event_id_fops;
78134 - file_ops->id.owner = mod;
78135 -
78136 - file_ops->enable = ftrace_enable_fops;
78137 - file_ops->enable.owner = mod;
78138 -
78139 - file_ops->filter = ftrace_event_filter_fops;
78140 - file_ops->filter.owner = mod;
78141 -
78142 - file_ops->format = ftrace_event_format_fops;
78143 - file_ops->format.owner = mod;
78144 + pax_open_kernel();
78145 + mod->trace_id.owner = mod;
78146 + mod->trace_enable.owner = mod;
78147 + mod->trace_filter.owner = mod;
78148 + mod->trace_format.owner = mod;
78149 + pax_close_kernel();
78150
78151 list_add(&file_ops->list, &ftrace_module_file_list);
78152
78153 @@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
78154
78155 for_each_event(call, start, end) {
78156 __trace_add_event_call(*call, mod,
78157 - &file_ops->id, &file_ops->enable,
78158 - &file_ops->filter, &file_ops->format);
78159 + &mod->trace_id, &mod->trace_enable,
78160 + &mod->trace_filter, &mod->trace_format);
78161 }
78162 }
78163
78164 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
78165 index fd3c8aa..5f324a6 100644
78166 --- a/kernel/trace/trace_mmiotrace.c
78167 +++ b/kernel/trace/trace_mmiotrace.c
78168 @@ -24,7 +24,7 @@ struct header_iter {
78169 static struct trace_array *mmio_trace_array;
78170 static bool overrun_detected;
78171 static unsigned long prev_overruns;
78172 -static atomic_t dropped_count;
78173 +static atomic_unchecked_t dropped_count;
78174
78175 static void mmio_reset_data(struct trace_array *tr)
78176 {
78177 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
78178
78179 static unsigned long count_overruns(struct trace_iterator *iter)
78180 {
78181 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
78182 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
78183 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
78184
78185 if (over > prev_overruns)
78186 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
78187 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
78188 sizeof(*entry), 0, pc);
78189 if (!event) {
78190 - atomic_inc(&dropped_count);
78191 + atomic_inc_unchecked(&dropped_count);
78192 return;
78193 }
78194 entry = ring_buffer_event_data(event);
78195 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
78196 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
78197 sizeof(*entry), 0, pc);
78198 if (!event) {
78199 - atomic_inc(&dropped_count);
78200 + atomic_inc_unchecked(&dropped_count);
78201 return;
78202 }
78203 entry = ring_buffer_event_data(event);
78204 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
78205 index 194d796..76edb8f 100644
78206 --- a/kernel/trace/trace_output.c
78207 +++ b/kernel/trace/trace_output.c
78208 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
78209
78210 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
78211 if (!IS_ERR(p)) {
78212 - p = mangle_path(s->buffer + s->len, p, "\n");
78213 + p = mangle_path(s->buffer + s->len, p, "\n\\");
78214 if (p) {
78215 s->len = p - s->buffer;
78216 return 1;
78217 @@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
78218 goto out;
78219 }
78220
78221 + pax_open_kernel();
78222 if (event->funcs->trace == NULL)
78223 - event->funcs->trace = trace_nop_print;
78224 + *(void **)&event->funcs->trace = trace_nop_print;
78225 if (event->funcs->raw == NULL)
78226 - event->funcs->raw = trace_nop_print;
78227 + *(void **)&event->funcs->raw = trace_nop_print;
78228 if (event->funcs->hex == NULL)
78229 - event->funcs->hex = trace_nop_print;
78230 + *(void **)&event->funcs->hex = trace_nop_print;
78231 if (event->funcs->binary == NULL)
78232 - event->funcs->binary = trace_nop_print;
78233 + *(void **)&event->funcs->binary = trace_nop_print;
78234 + pax_close_kernel();
78235
78236 key = event->type & (EVENT_HASHSIZE - 1);
78237
78238 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
78239 index 42ca822..cdcacc6 100644
78240 --- a/kernel/trace/trace_stack.c
78241 +++ b/kernel/trace/trace_stack.c
78242 @@ -52,7 +52,7 @@ static inline void check_stack(void)
78243 return;
78244
78245 /* we do not handle interrupt stacks yet */
78246 - if (!object_is_on_stack(&this_size))
78247 + if (!object_starts_on_stack(&this_size))
78248 return;
78249
78250 local_irq_save(flags);
78251 diff --git a/kernel/user.c b/kernel/user.c
78252 index 33acb5e..57ebfd4 100644
78253 --- a/kernel/user.c
78254 +++ b/kernel/user.c
78255 @@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
78256 .count = 4294967295U,
78257 },
78258 },
78259 - .kref = {
78260 - .refcount = ATOMIC_INIT(3),
78261 - },
78262 + .count = ATOMIC_INIT(3),
78263 .owner = GLOBAL_ROOT_UID,
78264 .group = GLOBAL_ROOT_GID,
78265 .proc_inum = PROC_USER_INIT_INO,
78266 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
78267 index 2b042c4..24f8ec3 100644
78268 --- a/kernel/user_namespace.c
78269 +++ b/kernel/user_namespace.c
78270 @@ -78,7 +78,7 @@ int create_user_ns(struct cred *new)
78271 return ret;
78272 }
78273
78274 - kref_init(&ns->kref);
78275 + atomic_set(&ns->count, 1);
78276 /* Leave the new->user_ns reference with the new user namespace. */
78277 ns->parent = parent_ns;
78278 ns->owner = owner;
78279 @@ -104,15 +104,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
78280 return create_user_ns(cred);
78281 }
78282
78283 -void free_user_ns(struct kref *kref)
78284 +void free_user_ns(struct user_namespace *ns)
78285 {
78286 - struct user_namespace *parent, *ns =
78287 - container_of(kref, struct user_namespace, kref);
78288 + struct user_namespace *parent;
78289
78290 - parent = ns->parent;
78291 - proc_free_inum(ns->proc_inum);
78292 - kmem_cache_free(user_ns_cachep, ns);
78293 - put_user_ns(parent);
78294 + do {
78295 + parent = ns->parent;
78296 + proc_free_inum(ns->proc_inum);
78297 + kmem_cache_free(user_ns_cachep, ns);
78298 + ns = parent;
78299 + } while (atomic_dec_and_test(&parent->count));
78300 }
78301 EXPORT_SYMBOL(free_user_ns);
78302
78303 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
78304 index 63da38c..639904e 100644
78305 --- a/kernel/utsname_sysctl.c
78306 +++ b/kernel/utsname_sysctl.c
78307 @@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
78308 static int proc_do_uts_string(ctl_table *table, int write,
78309 void __user *buffer, size_t *lenp, loff_t *ppos)
78310 {
78311 - struct ctl_table uts_table;
78312 + ctl_table_no_const uts_table;
78313 int r;
78314 memcpy(&uts_table, table, sizeof(uts_table));
78315 uts_table.data = get_uts(table, write);
78316 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
78317 index 75a2ab3..5961da7 100644
78318 --- a/kernel/watchdog.c
78319 +++ b/kernel/watchdog.c
78320 @@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
78321 }
78322 #endif /* CONFIG_SYSCTL */
78323
78324 -static struct smp_hotplug_thread watchdog_threads = {
78325 +static struct smp_hotplug_thread watchdog_threads __read_only = {
78326 .store = &softlockup_watchdog,
78327 .thread_should_run = watchdog_should_run,
78328 .thread_fn = watchdog,
78329 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
78330 index 67604e5..fe94fb1 100644
78331 --- a/lib/Kconfig.debug
78332 +++ b/lib/Kconfig.debug
78333 @@ -550,7 +550,7 @@ config DEBUG_MUTEXES
78334
78335 config DEBUG_LOCK_ALLOC
78336 bool "Lock debugging: detect incorrect freeing of live locks"
78337 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78338 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78339 select DEBUG_SPINLOCK
78340 select DEBUG_MUTEXES
78341 select LOCKDEP
78342 @@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
78343
78344 config PROVE_LOCKING
78345 bool "Lock debugging: prove locking correctness"
78346 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78347 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78348 select LOCKDEP
78349 select DEBUG_SPINLOCK
78350 select DEBUG_MUTEXES
78351 @@ -670,7 +670,7 @@ config LOCKDEP
78352
78353 config LOCK_STAT
78354 bool "Lock usage statistics"
78355 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78356 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78357 select LOCKDEP
78358 select DEBUG_SPINLOCK
78359 select DEBUG_MUTEXES
78360 @@ -1278,6 +1278,7 @@ config LATENCYTOP
78361 depends on DEBUG_KERNEL
78362 depends on STACKTRACE_SUPPORT
78363 depends on PROC_FS
78364 + depends on !GRKERNSEC_HIDESYM
78365 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
78366 select KALLSYMS
78367 select KALLSYMS_ALL
78368 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
78369
78370 config PROVIDE_OHCI1394_DMA_INIT
78371 bool "Remote debugging over FireWire early on boot"
78372 - depends on PCI && X86
78373 + depends on PCI && X86 && !GRKERNSEC
78374 help
78375 If you want to debug problems which hang or crash the kernel early
78376 on boot and the crashing machine has a FireWire port, you can use
78377 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
78378
78379 config FIREWIRE_OHCI_REMOTE_DMA
78380 bool "Remote debugging over FireWire with firewire-ohci"
78381 - depends on FIREWIRE_OHCI
78382 + depends on FIREWIRE_OHCI && !GRKERNSEC
78383 help
78384 This option lets you use the FireWire bus for remote debugging
78385 with help of the firewire-ohci driver. It enables unfiltered
78386 diff --git a/lib/Makefile b/lib/Makefile
78387 index 02ed6c0..bd243da 100644
78388 --- a/lib/Makefile
78389 +++ b/lib/Makefile
78390 @@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
78391
78392 obj-$(CONFIG_BTREE) += btree.o
78393 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
78394 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
78395 +obj-y += list_debug.o
78396 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
78397
78398 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
78399 diff --git a/lib/bitmap.c b/lib/bitmap.c
78400 index 06f7e4f..f3cf2b0 100644
78401 --- a/lib/bitmap.c
78402 +++ b/lib/bitmap.c
78403 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
78404 {
78405 int c, old_c, totaldigits, ndigits, nchunks, nbits;
78406 u32 chunk;
78407 - const char __user __force *ubuf = (const char __user __force *)buf;
78408 + const char __user *ubuf = (const char __force_user *)buf;
78409
78410 bitmap_zero(maskp, nmaskbits);
78411
78412 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
78413 {
78414 if (!access_ok(VERIFY_READ, ubuf, ulen))
78415 return -EFAULT;
78416 - return __bitmap_parse((const char __force *)ubuf,
78417 + return __bitmap_parse((const char __force_kernel *)ubuf,
78418 ulen, 1, maskp, nmaskbits);
78419
78420 }
78421 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
78422 {
78423 unsigned a, b;
78424 int c, old_c, totaldigits;
78425 - const char __user __force *ubuf = (const char __user __force *)buf;
78426 + const char __user *ubuf = (const char __force_user *)buf;
78427 int exp_digit, in_range;
78428
78429 totaldigits = c = 0;
78430 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
78431 {
78432 if (!access_ok(VERIFY_READ, ubuf, ulen))
78433 return -EFAULT;
78434 - return __bitmap_parselist((const char __force *)ubuf,
78435 + return __bitmap_parselist((const char __force_kernel *)ubuf,
78436 ulen, 1, maskp, nmaskbits);
78437 }
78438 EXPORT_SYMBOL(bitmap_parselist_user);
78439 diff --git a/lib/bug.c b/lib/bug.c
78440 index d0cdf14..4d07bd2 100644
78441 --- a/lib/bug.c
78442 +++ b/lib/bug.c
78443 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
78444 return BUG_TRAP_TYPE_NONE;
78445
78446 bug = find_bug(bugaddr);
78447 + if (!bug)
78448 + return BUG_TRAP_TYPE_NONE;
78449
78450 file = NULL;
78451 line = 0;
78452 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
78453 index d11808c..dc2d6f8 100644
78454 --- a/lib/debugobjects.c
78455 +++ b/lib/debugobjects.c
78456 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
78457 if (limit > 4)
78458 return;
78459
78460 - is_on_stack = object_is_on_stack(addr);
78461 + is_on_stack = object_starts_on_stack(addr);
78462 if (is_on_stack == onstack)
78463 return;
78464
78465 diff --git a/lib/devres.c b/lib/devres.c
78466 index 80b9c76..9e32279 100644
78467 --- a/lib/devres.c
78468 +++ b/lib/devres.c
78469 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
78470 void devm_iounmap(struct device *dev, void __iomem *addr)
78471 {
78472 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
78473 - (void *)addr));
78474 + (void __force *)addr));
78475 iounmap(addr);
78476 }
78477 EXPORT_SYMBOL(devm_iounmap);
78478 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
78479 {
78480 ioport_unmap(addr);
78481 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
78482 - devm_ioport_map_match, (void *)addr));
78483 + devm_ioport_map_match, (void __force *)addr));
78484 }
78485 EXPORT_SYMBOL(devm_ioport_unmap);
78486
78487 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
78488 index 5e396ac..58d5de1 100644
78489 --- a/lib/dma-debug.c
78490 +++ b/lib/dma-debug.c
78491 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
78492
78493 void dma_debug_add_bus(struct bus_type *bus)
78494 {
78495 - struct notifier_block *nb;
78496 + notifier_block_no_const *nb;
78497
78498 if (global_disable)
78499 return;
78500 @@ -942,7 +942,7 @@ out:
78501
78502 static void check_for_stack(struct device *dev, void *addr)
78503 {
78504 - if (object_is_on_stack(addr))
78505 + if (object_starts_on_stack(addr))
78506 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
78507 "stack [addr=%p]\n", addr);
78508 }
78509 diff --git a/lib/inflate.c b/lib/inflate.c
78510 index 013a761..c28f3fc 100644
78511 --- a/lib/inflate.c
78512 +++ b/lib/inflate.c
78513 @@ -269,7 +269,7 @@ static void free(void *where)
78514 malloc_ptr = free_mem_ptr;
78515 }
78516 #else
78517 -#define malloc(a) kmalloc(a, GFP_KERNEL)
78518 +#define malloc(a) kmalloc((a), GFP_KERNEL)
78519 #define free(a) kfree(a)
78520 #endif
78521
78522 diff --git a/lib/ioremap.c b/lib/ioremap.c
78523 index 0c9216c..863bd89 100644
78524 --- a/lib/ioremap.c
78525 +++ b/lib/ioremap.c
78526 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
78527 unsigned long next;
78528
78529 phys_addr -= addr;
78530 - pmd = pmd_alloc(&init_mm, pud, addr);
78531 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
78532 if (!pmd)
78533 return -ENOMEM;
78534 do {
78535 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
78536 unsigned long next;
78537
78538 phys_addr -= addr;
78539 - pud = pud_alloc(&init_mm, pgd, addr);
78540 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
78541 if (!pud)
78542 return -ENOMEM;
78543 do {
78544 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
78545 index bd2bea9..6b3c95e 100644
78546 --- a/lib/is_single_threaded.c
78547 +++ b/lib/is_single_threaded.c
78548 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
78549 struct task_struct *p, *t;
78550 bool ret;
78551
78552 + if (!mm)
78553 + return true;
78554 +
78555 if (atomic_read(&task->signal->live) != 1)
78556 return false;
78557
78558 diff --git a/lib/kobject.c b/lib/kobject.c
78559 index e07ee1f..998489d 100644
78560 --- a/lib/kobject.c
78561 +++ b/lib/kobject.c
78562 @@ -852,9 +852,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
78563
78564
78565 static DEFINE_SPINLOCK(kobj_ns_type_lock);
78566 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
78567 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
78568
78569 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
78570 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
78571 {
78572 enum kobj_ns_type type = ops->type;
78573 int error;
78574 diff --git a/lib/list_debug.c b/lib/list_debug.c
78575 index c24c2f7..0475b78 100644
78576 --- a/lib/list_debug.c
78577 +++ b/lib/list_debug.c
78578 @@ -11,7 +11,9 @@
78579 #include <linux/bug.h>
78580 #include <linux/kernel.h>
78581 #include <linux/rculist.h>
78582 +#include <linux/mm.h>
78583
78584 +#ifdef CONFIG_DEBUG_LIST
78585 /*
78586 * Insert a new entry between two known consecutive entries.
78587 *
78588 @@ -19,21 +21,32 @@
78589 * the prev/next entries already!
78590 */
78591
78592 -void __list_add(struct list_head *new,
78593 - struct list_head *prev,
78594 - struct list_head *next)
78595 +static bool __list_add_debug(struct list_head *new,
78596 + struct list_head *prev,
78597 + struct list_head *next)
78598 {
78599 - WARN(next->prev != prev,
78600 + if (WARN(next->prev != prev,
78601 "list_add corruption. next->prev should be "
78602 "prev (%p), but was %p. (next=%p).\n",
78603 - prev, next->prev, next);
78604 - WARN(prev->next != next,
78605 + prev, next->prev, next) ||
78606 + WARN(prev->next != next,
78607 "list_add corruption. prev->next should be "
78608 "next (%p), but was %p. (prev=%p).\n",
78609 - next, prev->next, prev);
78610 - WARN(new == prev || new == next,
78611 + next, prev->next, prev) ||
78612 + WARN(new == prev || new == next,
78613 "list_add double add: new=%p, prev=%p, next=%p.\n",
78614 - new, prev, next);
78615 + new, prev, next))
78616 + return false;
78617 + return true;
78618 +}
78619 +
78620 +void __list_add(struct list_head *new,
78621 + struct list_head *prev,
78622 + struct list_head *next)
78623 +{
78624 + if (!__list_add_debug(new, prev, next))
78625 + return;
78626 +
78627 next->prev = new;
78628 new->next = next;
78629 new->prev = prev;
78630 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
78631 }
78632 EXPORT_SYMBOL(__list_add);
78633
78634 -void __list_del_entry(struct list_head *entry)
78635 +static bool __list_del_entry_debug(struct list_head *entry)
78636 {
78637 struct list_head *prev, *next;
78638
78639 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
78640 WARN(next->prev != entry,
78641 "list_del corruption. next->prev should be %p, "
78642 "but was %p\n", entry, next->prev))
78643 + return false;
78644 + return true;
78645 +}
78646 +
78647 +void __list_del_entry(struct list_head *entry)
78648 +{
78649 + if (!__list_del_entry_debug(entry))
78650 return;
78651
78652 - __list_del(prev, next);
78653 + __list_del(entry->prev, entry->next);
78654 }
78655 EXPORT_SYMBOL(__list_del_entry);
78656
78657 @@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
78658 void __list_add_rcu(struct list_head *new,
78659 struct list_head *prev, struct list_head *next)
78660 {
78661 - WARN(next->prev != prev,
78662 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
78663 - prev, next->prev, next);
78664 - WARN(prev->next != next,
78665 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
78666 - next, prev->next, prev);
78667 + if (!__list_add_debug(new, prev, next))
78668 + return;
78669 +
78670 new->next = next;
78671 new->prev = prev;
78672 rcu_assign_pointer(list_next_rcu(prev), new);
78673 next->prev = new;
78674 }
78675 EXPORT_SYMBOL(__list_add_rcu);
78676 +#endif
78677 +
78678 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
78679 +{
78680 +#ifdef CONFIG_DEBUG_LIST
78681 + if (!__list_add_debug(new, prev, next))
78682 + return;
78683 +#endif
78684 +
78685 + pax_open_kernel();
78686 + next->prev = new;
78687 + new->next = next;
78688 + new->prev = prev;
78689 + prev->next = new;
78690 + pax_close_kernel();
78691 +}
78692 +EXPORT_SYMBOL(__pax_list_add);
78693 +
78694 +void pax_list_del(struct list_head *entry)
78695 +{
78696 +#ifdef CONFIG_DEBUG_LIST
78697 + if (!__list_del_entry_debug(entry))
78698 + return;
78699 +#endif
78700 +
78701 + pax_open_kernel();
78702 + __list_del(entry->prev, entry->next);
78703 + entry->next = LIST_POISON1;
78704 + entry->prev = LIST_POISON2;
78705 + pax_close_kernel();
78706 +}
78707 +EXPORT_SYMBOL(pax_list_del);
78708 +
78709 +void pax_list_del_init(struct list_head *entry)
78710 +{
78711 + pax_open_kernel();
78712 + __list_del(entry->prev, entry->next);
78713 + INIT_LIST_HEAD(entry);
78714 + pax_close_kernel();
78715 +}
78716 +EXPORT_SYMBOL(pax_list_del_init);
78717 +
78718 +void __pax_list_add_rcu(struct list_head *new,
78719 + struct list_head *prev, struct list_head *next)
78720 +{
78721 +#ifdef CONFIG_DEBUG_LIST
78722 + if (!__list_add_debug(new, prev, next))
78723 + return;
78724 +#endif
78725 +
78726 + pax_open_kernel();
78727 + new->next = next;
78728 + new->prev = prev;
78729 + rcu_assign_pointer(list_next_rcu(prev), new);
78730 + next->prev = new;
78731 + pax_close_kernel();
78732 +}
78733 +EXPORT_SYMBOL(__pax_list_add_rcu);
78734 +
78735 +void pax_list_del_rcu(struct list_head *entry)
78736 +{
78737 +#ifdef CONFIG_DEBUG_LIST
78738 + if (!__list_del_entry_debug(entry))
78739 + return;
78740 +#endif
78741 +
78742 + pax_open_kernel();
78743 + __list_del(entry->prev, entry->next);
78744 + entry->next = LIST_POISON1;
78745 + entry->prev = LIST_POISON2;
78746 + pax_close_kernel();
78747 +}
78748 +EXPORT_SYMBOL(pax_list_del_rcu);
78749 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
78750 index e796429..6e38f9f 100644
78751 --- a/lib/radix-tree.c
78752 +++ b/lib/radix-tree.c
78753 @@ -92,7 +92,7 @@ struct radix_tree_preload {
78754 int nr;
78755 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
78756 };
78757 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
78758 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
78759
78760 static inline void *ptr_to_indirect(void *ptr)
78761 {
78762 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
78763 index bb2b201..46abaf9 100644
78764 --- a/lib/strncpy_from_user.c
78765 +++ b/lib/strncpy_from_user.c
78766 @@ -21,7 +21,7 @@
78767 */
78768 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
78769 {
78770 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78771 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78772 long res = 0;
78773
78774 /*
78775 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
78776 index a28df52..3d55877 100644
78777 --- a/lib/strnlen_user.c
78778 +++ b/lib/strnlen_user.c
78779 @@ -26,7 +26,7 @@
78780 */
78781 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
78782 {
78783 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78784 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78785 long align, res = 0;
78786 unsigned long c;
78787
78788 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
78789 index 196b069..358f342 100644
78790 --- a/lib/swiotlb.c
78791 +++ b/lib/swiotlb.c
78792 @@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
78793
78794 void
78795 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
78796 - dma_addr_t dev_addr)
78797 + dma_addr_t dev_addr, struct dma_attrs *attrs)
78798 {
78799 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
78800
78801 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
78802 index fab33a9..3b5fe68 100644
78803 --- a/lib/vsprintf.c
78804 +++ b/lib/vsprintf.c
78805 @@ -16,6 +16,9 @@
78806 * - scnprintf and vscnprintf
78807 */
78808
78809 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78810 +#define __INCLUDED_BY_HIDESYM 1
78811 +#endif
78812 #include <stdarg.h>
78813 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
78814 #include <linux/types.h>
78815 @@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
78816 char sym[KSYM_SYMBOL_LEN];
78817 if (ext == 'B')
78818 sprint_backtrace(sym, value);
78819 - else if (ext != 'f' && ext != 's')
78820 + else if (ext != 'f' && ext != 's' && ext != 'a')
78821 sprint_symbol(sym, value);
78822 else
78823 sprint_symbol_no_offset(sym, value);
78824 @@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
78825 return number(buf, end, *(const netdev_features_t *)addr, spec);
78826 }
78827
78828 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78829 +int kptr_restrict __read_mostly = 2;
78830 +#else
78831 int kptr_restrict __read_mostly;
78832 +#endif
78833
78834 /*
78835 * Show a '%p' thing. A kernel extension is that the '%p' is followed
78836 @@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
78837 * - 'S' For symbolic direct pointers with offset
78838 * - 's' For symbolic direct pointers without offset
78839 * - 'B' For backtraced symbolic direct pointers with offset
78840 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
78841 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
78842 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
78843 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
78844 * - 'M' For a 6-byte MAC address, it prints the address in the
78845 @@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78846
78847 if (!ptr && *fmt != 'K') {
78848 /*
78849 - * Print (null) with the same width as a pointer so it makes
78850 + * Print (nil) with the same width as a pointer so it makes
78851 * tabular output look nice.
78852 */
78853 if (spec.field_width == -1)
78854 spec.field_width = default_width;
78855 - return string(buf, end, "(null)", spec);
78856 + return string(buf, end, "(nil)", spec);
78857 }
78858
78859 switch (*fmt) {
78860 @@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78861 /* Fallthrough */
78862 case 'S':
78863 case 's':
78864 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78865 + break;
78866 +#else
78867 + return symbol_string(buf, end, ptr, spec, *fmt);
78868 +#endif
78869 + case 'A':
78870 + case 'a':
78871 case 'B':
78872 return symbol_string(buf, end, ptr, spec, *fmt);
78873 case 'R':
78874 @@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78875 va_end(va);
78876 return buf;
78877 }
78878 + case 'P':
78879 + break;
78880 case 'K':
78881 /*
78882 * %pK cannot be used in IRQ context because its test
78883 @@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78884 }
78885 break;
78886 }
78887 +
78888 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78889 + /* 'P' = approved pointers to copy to userland,
78890 + as in the /proc/kallsyms case, as we make it display nothing
78891 + for non-root users, and the real contents for root users
78892 + Also ignore 'K' pointers, since we force their NULLing for non-root users
78893 + above
78894 + */
78895 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
78896 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
78897 + dump_stack();
78898 + ptr = NULL;
78899 + }
78900 +#endif
78901 +
78902 spec.flags |= SMALL;
78903 if (spec.field_width == -1) {
78904 spec.field_width = default_width;
78905 @@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
78906 typeof(type) value; \
78907 if (sizeof(type) == 8) { \
78908 args = PTR_ALIGN(args, sizeof(u32)); \
78909 - *(u32 *)&value = *(u32 *)args; \
78910 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
78911 + *(u32 *)&value = *(const u32 *)args; \
78912 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
78913 } else { \
78914 args = PTR_ALIGN(args, sizeof(type)); \
78915 - value = *(typeof(type) *)args; \
78916 + value = *(const typeof(type) *)args; \
78917 } \
78918 args += sizeof(type); \
78919 value; \
78920 @@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
78921 case FORMAT_TYPE_STR: {
78922 const char *str_arg = args;
78923 args += strlen(str_arg) + 1;
78924 - str = string(str, end, (char *)str_arg, spec);
78925 + str = string(str, end, str_arg, spec);
78926 break;
78927 }
78928
78929 diff --git a/localversion-grsec b/localversion-grsec
78930 new file mode 100644
78931 index 0000000..7cd6065
78932 --- /dev/null
78933 +++ b/localversion-grsec
78934 @@ -0,0 +1 @@
78935 +-grsec
78936 diff --git a/mm/Kconfig b/mm/Kconfig
78937 index 278e3ab..87c384d 100644
78938 --- a/mm/Kconfig
78939 +++ b/mm/Kconfig
78940 @@ -286,10 +286,10 @@ config KSM
78941 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
78942
78943 config DEFAULT_MMAP_MIN_ADDR
78944 - int "Low address space to protect from user allocation"
78945 + int "Low address space to protect from user allocation"
78946 depends on MMU
78947 - default 4096
78948 - help
78949 + default 65536
78950 + help
78951 This is the portion of low virtual memory which should be protected
78952 from userspace allocation. Keeping a user from writing to low pages
78953 can help reduce the impact of kernel NULL pointer bugs.
78954 @@ -320,7 +320,7 @@ config MEMORY_FAILURE
78955
78956 config HWPOISON_INJECT
78957 tristate "HWPoison pages injector"
78958 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
78959 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
78960 select PROC_PAGE_MONITOR
78961
78962 config NOMMU_INITIAL_TRIM_EXCESS
78963 diff --git a/mm/filemap.c b/mm/filemap.c
78964 index 83efee7..3f99381 100644
78965 --- a/mm/filemap.c
78966 +++ b/mm/filemap.c
78967 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
78968 struct address_space *mapping = file->f_mapping;
78969
78970 if (!mapping->a_ops->readpage)
78971 - return -ENOEXEC;
78972 + return -ENODEV;
78973 file_accessed(file);
78974 vma->vm_ops = &generic_file_vm_ops;
78975 return 0;
78976 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
78977 *pos = i_size_read(inode);
78978
78979 if (limit != RLIM_INFINITY) {
78980 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
78981 if (*pos >= limit) {
78982 send_sig(SIGXFSZ, current, 0);
78983 return -EFBIG;
78984 diff --git a/mm/fremap.c b/mm/fremap.c
78985 index a0aaf0e..20325c3 100644
78986 --- a/mm/fremap.c
78987 +++ b/mm/fremap.c
78988 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
78989 retry:
78990 vma = find_vma(mm, start);
78991
78992 +#ifdef CONFIG_PAX_SEGMEXEC
78993 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
78994 + goto out;
78995 +#endif
78996 +
78997 /*
78998 * Make sure the vma is shared, that it supports prefaulting,
78999 * and that the remapped range is valid and fully within
79000 diff --git a/mm/highmem.c b/mm/highmem.c
79001 index b32b70c..e512eb0 100644
79002 --- a/mm/highmem.c
79003 +++ b/mm/highmem.c
79004 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
79005 * So no dangers, even with speculative execution.
79006 */
79007 page = pte_page(pkmap_page_table[i]);
79008 + pax_open_kernel();
79009 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
79010 -
79011 + pax_close_kernel();
79012 set_page_address(page, NULL);
79013 need_flush = 1;
79014 }
79015 @@ -198,9 +199,11 @@ start:
79016 }
79017 }
79018 vaddr = PKMAP_ADDR(last_pkmap_nr);
79019 +
79020 + pax_open_kernel();
79021 set_pte_at(&init_mm, vaddr,
79022 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
79023 -
79024 + pax_close_kernel();
79025 pkmap_count[last_pkmap_nr] = 1;
79026 set_page_address(page, (void *)vaddr);
79027
79028 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
79029 index 546db81..34830af 100644
79030 --- a/mm/hugetlb.c
79031 +++ b/mm/hugetlb.c
79032 @@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
79033 struct hstate *h = &default_hstate;
79034 unsigned long tmp;
79035 int ret;
79036 + ctl_table_no_const hugetlb_table;
79037
79038 tmp = h->max_huge_pages;
79039
79040 if (write && h->order >= MAX_ORDER)
79041 return -EINVAL;
79042
79043 - table->data = &tmp;
79044 - table->maxlen = sizeof(unsigned long);
79045 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79046 + hugetlb_table = *table;
79047 + hugetlb_table.data = &tmp;
79048 + hugetlb_table.maxlen = sizeof(unsigned long);
79049 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79050 if (ret)
79051 goto out;
79052
79053 @@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
79054 struct hstate *h = &default_hstate;
79055 unsigned long tmp;
79056 int ret;
79057 + ctl_table_no_const hugetlb_table;
79058
79059 tmp = h->nr_overcommit_huge_pages;
79060
79061 if (write && h->order >= MAX_ORDER)
79062 return -EINVAL;
79063
79064 - table->data = &tmp;
79065 - table->maxlen = sizeof(unsigned long);
79066 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79067 + hugetlb_table = *table;
79068 + hugetlb_table.data = &tmp;
79069 + hugetlb_table.maxlen = sizeof(unsigned long);
79070 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79071 if (ret)
79072 goto out;
79073
79074 @@ -2511,6 +2515,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
79075 return 1;
79076 }
79077
79078 +#ifdef CONFIG_PAX_SEGMEXEC
79079 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
79080 +{
79081 + struct mm_struct *mm = vma->vm_mm;
79082 + struct vm_area_struct *vma_m;
79083 + unsigned long address_m;
79084 + pte_t *ptep_m;
79085 +
79086 + vma_m = pax_find_mirror_vma(vma);
79087 + if (!vma_m)
79088 + return;
79089 +
79090 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79091 + address_m = address + SEGMEXEC_TASK_SIZE;
79092 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
79093 + get_page(page_m);
79094 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
79095 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
79096 +}
79097 +#endif
79098 +
79099 /*
79100 * Hugetlb_cow() should be called with page lock of the original hugepage held.
79101 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
79102 @@ -2629,6 +2654,11 @@ retry_avoidcopy:
79103 make_huge_pte(vma, new_page, 1));
79104 page_remove_rmap(old_page);
79105 hugepage_add_new_anon_rmap(new_page, vma, address);
79106 +
79107 +#ifdef CONFIG_PAX_SEGMEXEC
79108 + pax_mirror_huge_pte(vma, address, new_page);
79109 +#endif
79110 +
79111 /* Make the old page be freed below */
79112 new_page = old_page;
79113 }
79114 @@ -2788,6 +2818,10 @@ retry:
79115 && (vma->vm_flags & VM_SHARED)));
79116 set_huge_pte_at(mm, address, ptep, new_pte);
79117
79118 +#ifdef CONFIG_PAX_SEGMEXEC
79119 + pax_mirror_huge_pte(vma, address, page);
79120 +#endif
79121 +
79122 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
79123 /* Optimization, do the COW without a second fault */
79124 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
79125 @@ -2817,6 +2851,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79126 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
79127 struct hstate *h = hstate_vma(vma);
79128
79129 +#ifdef CONFIG_PAX_SEGMEXEC
79130 + struct vm_area_struct *vma_m;
79131 +#endif
79132 +
79133 address &= huge_page_mask(h);
79134
79135 ptep = huge_pte_offset(mm, address);
79136 @@ -2830,6 +2868,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79137 VM_FAULT_SET_HINDEX(hstate_index(h));
79138 }
79139
79140 +#ifdef CONFIG_PAX_SEGMEXEC
79141 + vma_m = pax_find_mirror_vma(vma);
79142 + if (vma_m) {
79143 + unsigned long address_m;
79144 +
79145 + if (vma->vm_start > vma_m->vm_start) {
79146 + address_m = address;
79147 + address -= SEGMEXEC_TASK_SIZE;
79148 + vma = vma_m;
79149 + h = hstate_vma(vma);
79150 + } else
79151 + address_m = address + SEGMEXEC_TASK_SIZE;
79152 +
79153 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
79154 + return VM_FAULT_OOM;
79155 + address_m &= HPAGE_MASK;
79156 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
79157 + }
79158 +#endif
79159 +
79160 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
79161 if (!ptep)
79162 return VM_FAULT_OOM;
79163 diff --git a/mm/internal.h b/mm/internal.h
79164 index 9ba2110..eaf0674 100644
79165 --- a/mm/internal.h
79166 +++ b/mm/internal.h
79167 @@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
79168 * in mm/page_alloc.c
79169 */
79170 extern void __free_pages_bootmem(struct page *page, unsigned int order);
79171 +extern void free_compound_page(struct page *page);
79172 extern void prep_compound_page(struct page *page, unsigned long order);
79173 #ifdef CONFIG_MEMORY_FAILURE
79174 extern bool is_free_buddy_page(struct page *page);
79175 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
79176 index 752a705..6c3102e 100644
79177 --- a/mm/kmemleak.c
79178 +++ b/mm/kmemleak.c
79179 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
79180
79181 for (i = 0; i < object->trace_len; i++) {
79182 void *ptr = (void *)object->trace[i];
79183 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
79184 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
79185 }
79186 }
79187
79188 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
79189 return -ENOMEM;
79190 }
79191
79192 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
79193 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
79194 &kmemleak_fops);
79195 if (!dentry)
79196 pr_warning("Failed to create the debugfs kmemleak file\n");
79197 diff --git a/mm/maccess.c b/mm/maccess.c
79198 index d53adf9..03a24bf 100644
79199 --- a/mm/maccess.c
79200 +++ b/mm/maccess.c
79201 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
79202 set_fs(KERNEL_DS);
79203 pagefault_disable();
79204 ret = __copy_from_user_inatomic(dst,
79205 - (__force const void __user *)src, size);
79206 + (const void __force_user *)src, size);
79207 pagefault_enable();
79208 set_fs(old_fs);
79209
79210 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
79211
79212 set_fs(KERNEL_DS);
79213 pagefault_disable();
79214 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
79215 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
79216 pagefault_enable();
79217 set_fs(old_fs);
79218
79219 diff --git a/mm/madvise.c b/mm/madvise.c
79220 index 03dfa5c..b032917 100644
79221 --- a/mm/madvise.c
79222 +++ b/mm/madvise.c
79223 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
79224 pgoff_t pgoff;
79225 unsigned long new_flags = vma->vm_flags;
79226
79227 +#ifdef CONFIG_PAX_SEGMEXEC
79228 + struct vm_area_struct *vma_m;
79229 +#endif
79230 +
79231 switch (behavior) {
79232 case MADV_NORMAL:
79233 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
79234 @@ -123,6 +127,13 @@ success:
79235 /*
79236 * vm_flags is protected by the mmap_sem held in write mode.
79237 */
79238 +
79239 +#ifdef CONFIG_PAX_SEGMEXEC
79240 + vma_m = pax_find_mirror_vma(vma);
79241 + if (vma_m)
79242 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
79243 +#endif
79244 +
79245 vma->vm_flags = new_flags;
79246
79247 out:
79248 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
79249 struct vm_area_struct ** prev,
79250 unsigned long start, unsigned long end)
79251 {
79252 +
79253 +#ifdef CONFIG_PAX_SEGMEXEC
79254 + struct vm_area_struct *vma_m;
79255 +#endif
79256 +
79257 *prev = vma;
79258 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
79259 return -EINVAL;
79260 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
79261 zap_page_range(vma, start, end - start, &details);
79262 } else
79263 zap_page_range(vma, start, end - start, NULL);
79264 +
79265 +#ifdef CONFIG_PAX_SEGMEXEC
79266 + vma_m = pax_find_mirror_vma(vma);
79267 + if (vma_m) {
79268 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
79269 + struct zap_details details = {
79270 + .nonlinear_vma = vma_m,
79271 + .last_index = ULONG_MAX,
79272 + };
79273 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
79274 + } else
79275 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
79276 + }
79277 +#endif
79278 +
79279 return 0;
79280 }
79281
79282 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
79283 if (end < start)
79284 goto out;
79285
79286 +#ifdef CONFIG_PAX_SEGMEXEC
79287 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
79288 + if (end > SEGMEXEC_TASK_SIZE)
79289 + goto out;
79290 + } else
79291 +#endif
79292 +
79293 + if (end > TASK_SIZE)
79294 + goto out;
79295 +
79296 error = 0;
79297 if (end == start)
79298 goto out;
79299 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
79300 index c6e4dd3..1f41988 100644
79301 --- a/mm/memory-failure.c
79302 +++ b/mm/memory-failure.c
79303 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
79304
79305 int sysctl_memory_failure_recovery __read_mostly = 1;
79306
79307 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
79308 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
79309
79310 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
79311
79312 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
79313 pfn, t->comm, t->pid);
79314 si.si_signo = SIGBUS;
79315 si.si_errno = 0;
79316 - si.si_addr = (void *)addr;
79317 + si.si_addr = (void __user *)addr;
79318 #ifdef __ARCH_SI_TRAPNO
79319 si.si_trapno = trapno;
79320 #endif
79321 @@ -760,7 +760,7 @@ static struct page_state {
79322 unsigned long res;
79323 char *msg;
79324 int (*action)(struct page *p, unsigned long pfn);
79325 -} error_states[] = {
79326 +} __do_const error_states[] = {
79327 { reserved, reserved, "reserved kernel", me_kernel },
79328 /*
79329 * free pages are specially detected outside this table:
79330 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79331 }
79332
79333 nr_pages = 1 << compound_trans_order(hpage);
79334 - atomic_long_add(nr_pages, &mce_bad_pages);
79335 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
79336
79337 /*
79338 * We need/can do nothing about count=0 pages.
79339 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79340 if (!PageHWPoison(hpage)
79341 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
79342 || (p != hpage && TestSetPageHWPoison(hpage))) {
79343 - atomic_long_sub(nr_pages, &mce_bad_pages);
79344 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79345 return 0;
79346 }
79347 set_page_hwpoison_huge_page(hpage);
79348 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79349 }
79350 if (hwpoison_filter(p)) {
79351 if (TestClearPageHWPoison(p))
79352 - atomic_long_sub(nr_pages, &mce_bad_pages);
79353 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79354 unlock_page(hpage);
79355 put_page(hpage);
79356 return 0;
79357 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
79358 return 0;
79359 }
79360 if (TestClearPageHWPoison(p))
79361 - atomic_long_sub(nr_pages, &mce_bad_pages);
79362 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79363 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
79364 return 0;
79365 }
79366 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
79367 */
79368 if (TestClearPageHWPoison(page)) {
79369 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
79370 - atomic_long_sub(nr_pages, &mce_bad_pages);
79371 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79372 freeit = 1;
79373 if (PageHuge(page))
79374 clear_page_hwpoison_huge_page(page);
79375 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
79376 }
79377 done:
79378 if (!PageHWPoison(hpage))
79379 - atomic_long_add(1 << compound_trans_order(hpage),
79380 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
79381 &mce_bad_pages);
79382 set_page_hwpoison_huge_page(hpage);
79383 dequeue_hwpoisoned_huge_page(hpage);
79384 @@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
79385 return ret;
79386
79387 done:
79388 - atomic_long_add(1, &mce_bad_pages);
79389 + atomic_long_add_unchecked(1, &mce_bad_pages);
79390 SetPageHWPoison(page);
79391 /* keep elevated page count for bad page */
79392 return ret;
79393 diff --git a/mm/memory.c b/mm/memory.c
79394 index bb1369f..efb96b5 100644
79395 --- a/mm/memory.c
79396 +++ b/mm/memory.c
79397 @@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
79398 free_pte_range(tlb, pmd, addr);
79399 } while (pmd++, addr = next, addr != end);
79400
79401 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
79402 start &= PUD_MASK;
79403 if (start < floor)
79404 return;
79405 @@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
79406 pmd = pmd_offset(pud, start);
79407 pud_clear(pud);
79408 pmd_free_tlb(tlb, pmd, start);
79409 +#endif
79410 +
79411 }
79412
79413 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79414 @@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79415 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
79416 } while (pud++, addr = next, addr != end);
79417
79418 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
79419 start &= PGDIR_MASK;
79420 if (start < floor)
79421 return;
79422 @@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79423 pud = pud_offset(pgd, start);
79424 pgd_clear(pgd);
79425 pud_free_tlb(tlb, pud, start);
79426 +#endif
79427 +
79428 }
79429
79430 /*
79431 @@ -1618,12 +1624,6 @@ no_page_table:
79432 return page;
79433 }
79434
79435 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
79436 -{
79437 - return stack_guard_page_start(vma, addr) ||
79438 - stack_guard_page_end(vma, addr+PAGE_SIZE);
79439 -}
79440 -
79441 /**
79442 * __get_user_pages() - pin user pages in memory
79443 * @tsk: task_struct of target task
79444 @@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79445
79446 i = 0;
79447
79448 - do {
79449 + while (nr_pages) {
79450 struct vm_area_struct *vma;
79451
79452 - vma = find_extend_vma(mm, start);
79453 + vma = find_vma(mm, start);
79454 if (!vma && in_gate_area(mm, start)) {
79455 unsigned long pg = start & PAGE_MASK;
79456 pgd_t *pgd;
79457 @@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79458 goto next_page;
79459 }
79460
79461 - if (!vma ||
79462 + if (!vma || start < vma->vm_start ||
79463 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
79464 !(vm_flags & vma->vm_flags))
79465 return i ? : -EFAULT;
79466 @@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79467 int ret;
79468 unsigned int fault_flags = 0;
79469
79470 - /* For mlock, just skip the stack guard page. */
79471 - if (foll_flags & FOLL_MLOCK) {
79472 - if (stack_guard_page(vma, start))
79473 - goto next_page;
79474 - }
79475 if (foll_flags & FOLL_WRITE)
79476 fault_flags |= FAULT_FLAG_WRITE;
79477 if (nonblocking)
79478 @@ -1865,7 +1860,7 @@ next_page:
79479 start += PAGE_SIZE;
79480 nr_pages--;
79481 } while (nr_pages && start < vma->vm_end);
79482 - } while (nr_pages);
79483 + }
79484 return i;
79485 }
79486 EXPORT_SYMBOL(__get_user_pages);
79487 @@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
79488 page_add_file_rmap(page);
79489 set_pte_at(mm, addr, pte, mk_pte(page, prot));
79490
79491 +#ifdef CONFIG_PAX_SEGMEXEC
79492 + pax_mirror_file_pte(vma, addr, page, ptl);
79493 +#endif
79494 +
79495 retval = 0;
79496 pte_unmap_unlock(pte, ptl);
79497 return retval;
79498 @@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
79499 if (!page_count(page))
79500 return -EINVAL;
79501 if (!(vma->vm_flags & VM_MIXEDMAP)) {
79502 +
79503 +#ifdef CONFIG_PAX_SEGMEXEC
79504 + struct vm_area_struct *vma_m;
79505 +#endif
79506 +
79507 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
79508 BUG_ON(vma->vm_flags & VM_PFNMAP);
79509 vma->vm_flags |= VM_MIXEDMAP;
79510 +
79511 +#ifdef CONFIG_PAX_SEGMEXEC
79512 + vma_m = pax_find_mirror_vma(vma);
79513 + if (vma_m)
79514 + vma_m->vm_flags |= VM_MIXEDMAP;
79515 +#endif
79516 +
79517 }
79518 return insert_page(vma, addr, page, vma->vm_page_prot);
79519 }
79520 @@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
79521 unsigned long pfn)
79522 {
79523 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
79524 + BUG_ON(vma->vm_mirror);
79525
79526 if (addr < vma->vm_start || addr >= vma->vm_end)
79527 return -EFAULT;
79528 @@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
79529
79530 BUG_ON(pud_huge(*pud));
79531
79532 - pmd = pmd_alloc(mm, pud, addr);
79533 + pmd = (mm == &init_mm) ?
79534 + pmd_alloc_kernel(mm, pud, addr) :
79535 + pmd_alloc(mm, pud, addr);
79536 if (!pmd)
79537 return -ENOMEM;
79538 do {
79539 @@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
79540 unsigned long next;
79541 int err;
79542
79543 - pud = pud_alloc(mm, pgd, addr);
79544 + pud = (mm == &init_mm) ?
79545 + pud_alloc_kernel(mm, pgd, addr) :
79546 + pud_alloc(mm, pgd, addr);
79547 if (!pud)
79548 return -ENOMEM;
79549 do {
79550 @@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
79551 copy_user_highpage(dst, src, va, vma);
79552 }
79553
79554 +#ifdef CONFIG_PAX_SEGMEXEC
79555 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
79556 +{
79557 + struct mm_struct *mm = vma->vm_mm;
79558 + spinlock_t *ptl;
79559 + pte_t *pte, entry;
79560 +
79561 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
79562 + entry = *pte;
79563 + if (!pte_present(entry)) {
79564 + if (!pte_none(entry)) {
79565 + BUG_ON(pte_file(entry));
79566 + free_swap_and_cache(pte_to_swp_entry(entry));
79567 + pte_clear_not_present_full(mm, address, pte, 0);
79568 + }
79569 + } else {
79570 + struct page *page;
79571 +
79572 + flush_cache_page(vma, address, pte_pfn(entry));
79573 + entry = ptep_clear_flush(vma, address, pte);
79574 + BUG_ON(pte_dirty(entry));
79575 + page = vm_normal_page(vma, address, entry);
79576 + if (page) {
79577 + update_hiwater_rss(mm);
79578 + if (PageAnon(page))
79579 + dec_mm_counter_fast(mm, MM_ANONPAGES);
79580 + else
79581 + dec_mm_counter_fast(mm, MM_FILEPAGES);
79582 + page_remove_rmap(page);
79583 + page_cache_release(page);
79584 + }
79585 + }
79586 + pte_unmap_unlock(pte, ptl);
79587 +}
79588 +
79589 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
79590 + *
79591 + * the ptl of the lower mapped page is held on entry and is not released on exit
79592 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
79593 + */
79594 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
79595 +{
79596 + struct mm_struct *mm = vma->vm_mm;
79597 + unsigned long address_m;
79598 + spinlock_t *ptl_m;
79599 + struct vm_area_struct *vma_m;
79600 + pmd_t *pmd_m;
79601 + pte_t *pte_m, entry_m;
79602 +
79603 + BUG_ON(!page_m || !PageAnon(page_m));
79604 +
79605 + vma_m = pax_find_mirror_vma(vma);
79606 + if (!vma_m)
79607 + return;
79608 +
79609 + BUG_ON(!PageLocked(page_m));
79610 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79611 + address_m = address + SEGMEXEC_TASK_SIZE;
79612 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79613 + pte_m = pte_offset_map(pmd_m, address_m);
79614 + ptl_m = pte_lockptr(mm, pmd_m);
79615 + if (ptl != ptl_m) {
79616 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79617 + if (!pte_none(*pte_m))
79618 + goto out;
79619 + }
79620 +
79621 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
79622 + page_cache_get(page_m);
79623 + page_add_anon_rmap(page_m, vma_m, address_m);
79624 + inc_mm_counter_fast(mm, MM_ANONPAGES);
79625 + set_pte_at(mm, address_m, pte_m, entry_m);
79626 + update_mmu_cache(vma_m, address_m, entry_m);
79627 +out:
79628 + if (ptl != ptl_m)
79629 + spin_unlock(ptl_m);
79630 + pte_unmap(pte_m);
79631 + unlock_page(page_m);
79632 +}
79633 +
79634 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
79635 +{
79636 + struct mm_struct *mm = vma->vm_mm;
79637 + unsigned long address_m;
79638 + spinlock_t *ptl_m;
79639 + struct vm_area_struct *vma_m;
79640 + pmd_t *pmd_m;
79641 + pte_t *pte_m, entry_m;
79642 +
79643 + BUG_ON(!page_m || PageAnon(page_m));
79644 +
79645 + vma_m = pax_find_mirror_vma(vma);
79646 + if (!vma_m)
79647 + return;
79648 +
79649 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79650 + address_m = address + SEGMEXEC_TASK_SIZE;
79651 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79652 + pte_m = pte_offset_map(pmd_m, address_m);
79653 + ptl_m = pte_lockptr(mm, pmd_m);
79654 + if (ptl != ptl_m) {
79655 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79656 + if (!pte_none(*pte_m))
79657 + goto out;
79658 + }
79659 +
79660 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
79661 + page_cache_get(page_m);
79662 + page_add_file_rmap(page_m);
79663 + inc_mm_counter_fast(mm, MM_FILEPAGES);
79664 + set_pte_at(mm, address_m, pte_m, entry_m);
79665 + update_mmu_cache(vma_m, address_m, entry_m);
79666 +out:
79667 + if (ptl != ptl_m)
79668 + spin_unlock(ptl_m);
79669 + pte_unmap(pte_m);
79670 +}
79671 +
79672 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
79673 +{
79674 + struct mm_struct *mm = vma->vm_mm;
79675 + unsigned long address_m;
79676 + spinlock_t *ptl_m;
79677 + struct vm_area_struct *vma_m;
79678 + pmd_t *pmd_m;
79679 + pte_t *pte_m, entry_m;
79680 +
79681 + vma_m = pax_find_mirror_vma(vma);
79682 + if (!vma_m)
79683 + return;
79684 +
79685 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79686 + address_m = address + SEGMEXEC_TASK_SIZE;
79687 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79688 + pte_m = pte_offset_map(pmd_m, address_m);
79689 + ptl_m = pte_lockptr(mm, pmd_m);
79690 + if (ptl != ptl_m) {
79691 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79692 + if (!pte_none(*pte_m))
79693 + goto out;
79694 + }
79695 +
79696 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
79697 + set_pte_at(mm, address_m, pte_m, entry_m);
79698 +out:
79699 + if (ptl != ptl_m)
79700 + spin_unlock(ptl_m);
79701 + pte_unmap(pte_m);
79702 +}
79703 +
79704 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
79705 +{
79706 + struct page *page_m;
79707 + pte_t entry;
79708 +
79709 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
79710 + goto out;
79711 +
79712 + entry = *pte;
79713 + page_m = vm_normal_page(vma, address, entry);
79714 + if (!page_m)
79715 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
79716 + else if (PageAnon(page_m)) {
79717 + if (pax_find_mirror_vma(vma)) {
79718 + pte_unmap_unlock(pte, ptl);
79719 + lock_page(page_m);
79720 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
79721 + if (pte_same(entry, *pte))
79722 + pax_mirror_anon_pte(vma, address, page_m, ptl);
79723 + else
79724 + unlock_page(page_m);
79725 + }
79726 + } else
79727 + pax_mirror_file_pte(vma, address, page_m, ptl);
79728 +
79729 +out:
79730 + pte_unmap_unlock(pte, ptl);
79731 +}
79732 +#endif
79733 +
79734 /*
79735 * This routine handles present pages, when users try to write
79736 * to a shared page. It is done by copying the page to a new address
79737 @@ -2725,6 +2921,12 @@ gotten:
79738 */
79739 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
79740 if (likely(pte_same(*page_table, orig_pte))) {
79741 +
79742 +#ifdef CONFIG_PAX_SEGMEXEC
79743 + if (pax_find_mirror_vma(vma))
79744 + BUG_ON(!trylock_page(new_page));
79745 +#endif
79746 +
79747 if (old_page) {
79748 if (!PageAnon(old_page)) {
79749 dec_mm_counter_fast(mm, MM_FILEPAGES);
79750 @@ -2776,6 +2978,10 @@ gotten:
79751 page_remove_rmap(old_page);
79752 }
79753
79754 +#ifdef CONFIG_PAX_SEGMEXEC
79755 + pax_mirror_anon_pte(vma, address, new_page, ptl);
79756 +#endif
79757 +
79758 /* Free the old page.. */
79759 new_page = old_page;
79760 ret |= VM_FAULT_WRITE;
79761 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
79762 swap_free(entry);
79763 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
79764 try_to_free_swap(page);
79765 +
79766 +#ifdef CONFIG_PAX_SEGMEXEC
79767 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
79768 +#endif
79769 +
79770 unlock_page(page);
79771 if (swapcache) {
79772 /*
79773 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
79774
79775 /* No need to invalidate - it was non-present before */
79776 update_mmu_cache(vma, address, page_table);
79777 +
79778 +#ifdef CONFIG_PAX_SEGMEXEC
79779 + pax_mirror_anon_pte(vma, address, page, ptl);
79780 +#endif
79781 +
79782 unlock:
79783 pte_unmap_unlock(page_table, ptl);
79784 out:
79785 @@ -3093,40 +3309,6 @@ out_release:
79786 }
79787
79788 /*
79789 - * This is like a special single-page "expand_{down|up}wards()",
79790 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
79791 - * doesn't hit another vma.
79792 - */
79793 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
79794 -{
79795 - address &= PAGE_MASK;
79796 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
79797 - struct vm_area_struct *prev = vma->vm_prev;
79798 -
79799 - /*
79800 - * Is there a mapping abutting this one below?
79801 - *
79802 - * That's only ok if it's the same stack mapping
79803 - * that has gotten split..
79804 - */
79805 - if (prev && prev->vm_end == address)
79806 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
79807 -
79808 - expand_downwards(vma, address - PAGE_SIZE);
79809 - }
79810 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
79811 - struct vm_area_struct *next = vma->vm_next;
79812 -
79813 - /* As VM_GROWSDOWN but s/below/above/ */
79814 - if (next && next->vm_start == address + PAGE_SIZE)
79815 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
79816 -
79817 - expand_upwards(vma, address + PAGE_SIZE);
79818 - }
79819 - return 0;
79820 -}
79821 -
79822 -/*
79823 * We enter with non-exclusive mmap_sem (to exclude vma changes,
79824 * but allow concurrent faults), and pte mapped but not yet locked.
79825 * We return with mmap_sem still held, but pte unmapped and unlocked.
79826 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
79827 unsigned long address, pte_t *page_table, pmd_t *pmd,
79828 unsigned int flags)
79829 {
79830 - struct page *page;
79831 + struct page *page = NULL;
79832 spinlock_t *ptl;
79833 pte_t entry;
79834
79835 - pte_unmap(page_table);
79836 -
79837 - /* Check if we need to add a guard page to the stack */
79838 - if (check_stack_guard_page(vma, address) < 0)
79839 - return VM_FAULT_SIGBUS;
79840 -
79841 - /* Use the zero-page for reads */
79842 if (!(flags & FAULT_FLAG_WRITE)) {
79843 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
79844 vma->vm_page_prot));
79845 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
79846 + ptl = pte_lockptr(mm, pmd);
79847 + spin_lock(ptl);
79848 if (!pte_none(*page_table))
79849 goto unlock;
79850 goto setpte;
79851 }
79852
79853 /* Allocate our own private page. */
79854 + pte_unmap(page_table);
79855 +
79856 if (unlikely(anon_vma_prepare(vma)))
79857 goto oom;
79858 page = alloc_zeroed_user_highpage_movable(vma, address);
79859 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
79860 if (!pte_none(*page_table))
79861 goto release;
79862
79863 +#ifdef CONFIG_PAX_SEGMEXEC
79864 + if (pax_find_mirror_vma(vma))
79865 + BUG_ON(!trylock_page(page));
79866 +#endif
79867 +
79868 inc_mm_counter_fast(mm, MM_ANONPAGES);
79869 page_add_new_anon_rmap(page, vma, address);
79870 setpte:
79871 @@ -3181,6 +3364,12 @@ setpte:
79872
79873 /* No need to invalidate - it was non-present before */
79874 update_mmu_cache(vma, address, page_table);
79875 +
79876 +#ifdef CONFIG_PAX_SEGMEXEC
79877 + if (page)
79878 + pax_mirror_anon_pte(vma, address, page, ptl);
79879 +#endif
79880 +
79881 unlock:
79882 pte_unmap_unlock(page_table, ptl);
79883 return 0;
79884 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79885 */
79886 /* Only go through if we didn't race with anybody else... */
79887 if (likely(pte_same(*page_table, orig_pte))) {
79888 +
79889 +#ifdef CONFIG_PAX_SEGMEXEC
79890 + if (anon && pax_find_mirror_vma(vma))
79891 + BUG_ON(!trylock_page(page));
79892 +#endif
79893 +
79894 flush_icache_page(vma, page);
79895 entry = mk_pte(page, vma->vm_page_prot);
79896 if (flags & FAULT_FLAG_WRITE)
79897 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79898
79899 /* no need to invalidate: a not-present page won't be cached */
79900 update_mmu_cache(vma, address, page_table);
79901 +
79902 +#ifdef CONFIG_PAX_SEGMEXEC
79903 + if (anon)
79904 + pax_mirror_anon_pte(vma, address, page, ptl);
79905 + else
79906 + pax_mirror_file_pte(vma, address, page, ptl);
79907 +#endif
79908 +
79909 } else {
79910 if (cow_page)
79911 mem_cgroup_uncharge_page(cow_page);
79912 @@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
79913 if (flags & FAULT_FLAG_WRITE)
79914 flush_tlb_fix_spurious_fault(vma, address);
79915 }
79916 +
79917 +#ifdef CONFIG_PAX_SEGMEXEC
79918 + pax_mirror_pte(vma, address, pte, pmd, ptl);
79919 + return 0;
79920 +#endif
79921 +
79922 unlock:
79923 pte_unmap_unlock(pte, ptl);
79924 return 0;
79925 @@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79926 pmd_t *pmd;
79927 pte_t *pte;
79928
79929 +#ifdef CONFIG_PAX_SEGMEXEC
79930 + struct vm_area_struct *vma_m;
79931 +#endif
79932 +
79933 __set_current_state(TASK_RUNNING);
79934
79935 count_vm_event(PGFAULT);
79936 @@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79937 if (unlikely(is_vm_hugetlb_page(vma)))
79938 return hugetlb_fault(mm, vma, address, flags);
79939
79940 +#ifdef CONFIG_PAX_SEGMEXEC
79941 + vma_m = pax_find_mirror_vma(vma);
79942 + if (vma_m) {
79943 + unsigned long address_m;
79944 + pgd_t *pgd_m;
79945 + pud_t *pud_m;
79946 + pmd_t *pmd_m;
79947 +
79948 + if (vma->vm_start > vma_m->vm_start) {
79949 + address_m = address;
79950 + address -= SEGMEXEC_TASK_SIZE;
79951 + vma = vma_m;
79952 + } else
79953 + address_m = address + SEGMEXEC_TASK_SIZE;
79954 +
79955 + pgd_m = pgd_offset(mm, address_m);
79956 + pud_m = pud_alloc(mm, pgd_m, address_m);
79957 + if (!pud_m)
79958 + return VM_FAULT_OOM;
79959 + pmd_m = pmd_alloc(mm, pud_m, address_m);
79960 + if (!pmd_m)
79961 + return VM_FAULT_OOM;
79962 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
79963 + return VM_FAULT_OOM;
79964 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
79965 + }
79966 +#endif
79967 +
79968 retry:
79969 pgd = pgd_offset(mm, address);
79970 pud = pud_alloc(mm, pgd, address);
79971 @@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79972 spin_unlock(&mm->page_table_lock);
79973 return 0;
79974 }
79975 +
79976 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79977 +{
79978 + pud_t *new = pud_alloc_one(mm, address);
79979 + if (!new)
79980 + return -ENOMEM;
79981 +
79982 + smp_wmb(); /* See comment in __pte_alloc */
79983 +
79984 + spin_lock(&mm->page_table_lock);
79985 + if (pgd_present(*pgd)) /* Another has populated it */
79986 + pud_free(mm, new);
79987 + else
79988 + pgd_populate_kernel(mm, pgd, new);
79989 + spin_unlock(&mm->page_table_lock);
79990 + return 0;
79991 +}
79992 #endif /* __PAGETABLE_PUD_FOLDED */
79993
79994 #ifndef __PAGETABLE_PMD_FOLDED
79995 @@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
79996 spin_unlock(&mm->page_table_lock);
79997 return 0;
79998 }
79999 +
80000 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80001 +{
80002 + pmd_t *new = pmd_alloc_one(mm, address);
80003 + if (!new)
80004 + return -ENOMEM;
80005 +
80006 + smp_wmb(); /* See comment in __pte_alloc */
80007 +
80008 + spin_lock(&mm->page_table_lock);
80009 +#ifndef __ARCH_HAS_4LEVEL_HACK
80010 + if (pud_present(*pud)) /* Another has populated it */
80011 + pmd_free(mm, new);
80012 + else
80013 + pud_populate_kernel(mm, pud, new);
80014 +#else
80015 + if (pgd_present(*pud)) /* Another has populated it */
80016 + pmd_free(mm, new);
80017 + else
80018 + pgd_populate_kernel(mm, pud, new);
80019 +#endif /* __ARCH_HAS_4LEVEL_HACK */
80020 + spin_unlock(&mm->page_table_lock);
80021 + return 0;
80022 +}
80023 #endif /* __PAGETABLE_PMD_FOLDED */
80024
80025 int make_pages_present(unsigned long addr, unsigned long end)
80026 @@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
80027 gate_vma.vm_start = FIXADDR_USER_START;
80028 gate_vma.vm_end = FIXADDR_USER_END;
80029 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
80030 - gate_vma.vm_page_prot = __P101;
80031 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
80032
80033 return 0;
80034 }
80035 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
80036 index e2df1c1..1e31d57 100644
80037 --- a/mm/mempolicy.c
80038 +++ b/mm/mempolicy.c
80039 @@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80040 unsigned long vmstart;
80041 unsigned long vmend;
80042
80043 +#ifdef CONFIG_PAX_SEGMEXEC
80044 + struct vm_area_struct *vma_m;
80045 +#endif
80046 +
80047 vma = find_vma(mm, start);
80048 if (!vma || vma->vm_start > start)
80049 return -EFAULT;
80050 @@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80051 if (err)
80052 goto out;
80053 }
80054 +
80055 err = vma_replace_policy(vma, new_pol);
80056 if (err)
80057 goto out;
80058 +
80059 +#ifdef CONFIG_PAX_SEGMEXEC
80060 + vma_m = pax_find_mirror_vma(vma);
80061 + if (vma_m) {
80062 + err = vma_replace_policy(vma_m, new_pol);
80063 + if (err)
80064 + goto out;
80065 + }
80066 +#endif
80067 +
80068 }
80069
80070 out:
80071 @@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
80072
80073 if (end < start)
80074 return -EINVAL;
80075 +
80076 +#ifdef CONFIG_PAX_SEGMEXEC
80077 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
80078 + if (end > SEGMEXEC_TASK_SIZE)
80079 + return -EINVAL;
80080 + } else
80081 +#endif
80082 +
80083 + if (end > TASK_SIZE)
80084 + return -EINVAL;
80085 +
80086 if (end == start)
80087 return 0;
80088
80089 @@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80090 */
80091 tcred = __task_cred(task);
80092 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80093 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80094 - !capable(CAP_SYS_NICE)) {
80095 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80096 rcu_read_unlock();
80097 err = -EPERM;
80098 goto out_put;
80099 @@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80100 goto out;
80101 }
80102
80103 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80104 + if (mm != current->mm &&
80105 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
80106 + mmput(mm);
80107 + err = -EPERM;
80108 + goto out;
80109 + }
80110 +#endif
80111 +
80112 err = do_migrate_pages(mm, old, new,
80113 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
80114
80115 diff --git a/mm/migrate.c b/mm/migrate.c
80116 index 2fd8b4a..d70358f 100644
80117 --- a/mm/migrate.c
80118 +++ b/mm/migrate.c
80119 @@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
80120 */
80121 tcred = __task_cred(task);
80122 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80123 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80124 - !capable(CAP_SYS_NICE)) {
80125 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80126 rcu_read_unlock();
80127 err = -EPERM;
80128 goto out;
80129 diff --git a/mm/mlock.c b/mm/mlock.c
80130 index c9bd528..da8d069 100644
80131 --- a/mm/mlock.c
80132 +++ b/mm/mlock.c
80133 @@ -13,6 +13,7 @@
80134 #include <linux/pagemap.h>
80135 #include <linux/mempolicy.h>
80136 #include <linux/syscalls.h>
80137 +#include <linux/security.h>
80138 #include <linux/sched.h>
80139 #include <linux/export.h>
80140 #include <linux/rmap.h>
80141 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
80142 {
80143 unsigned long nstart, end, tmp;
80144 struct vm_area_struct * vma, * prev;
80145 - int error;
80146 + int error = 0;
80147
80148 VM_BUG_ON(start & ~PAGE_MASK);
80149 VM_BUG_ON(len != PAGE_ALIGN(len));
80150 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
80151 return -EINVAL;
80152 if (end == start)
80153 return 0;
80154 + if (end > TASK_SIZE)
80155 + return -EINVAL;
80156 +
80157 vma = find_vma(current->mm, start);
80158 if (!vma || vma->vm_start > start)
80159 return -ENOMEM;
80160 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
80161 for (nstart = start ; ; ) {
80162 vm_flags_t newflags;
80163
80164 +#ifdef CONFIG_PAX_SEGMEXEC
80165 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80166 + break;
80167 +#endif
80168 +
80169 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
80170
80171 newflags = vma->vm_flags | VM_LOCKED;
80172 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
80173 lock_limit >>= PAGE_SHIFT;
80174
80175 /* check against resource limits */
80176 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
80177 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
80178 error = do_mlock(start, len, 1);
80179 up_write(&current->mm->mmap_sem);
80180 @@ -528,6 +538,12 @@ static int do_mlockall(int flags)
80181 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
80182 vm_flags_t newflags;
80183
80184 +#ifdef CONFIG_PAX_SEGMEXEC
80185 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80186 + break;
80187 +#endif
80188 +
80189 + BUG_ON(vma->vm_end > TASK_SIZE);
80190 newflags = vma->vm_flags | VM_LOCKED;
80191 if (!(flags & MCL_CURRENT))
80192 newflags &= ~VM_LOCKED;
80193 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
80194 lock_limit >>= PAGE_SHIFT;
80195
80196 ret = -ENOMEM;
80197 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
80198 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
80199 capable(CAP_IPC_LOCK))
80200 ret = do_mlockall(flags);
80201 diff --git a/mm/mmap.c b/mm/mmap.c
80202 index 8832b87..7d36e4f 100644
80203 --- a/mm/mmap.c
80204 +++ b/mm/mmap.c
80205 @@ -32,6 +32,7 @@
80206 #include <linux/khugepaged.h>
80207 #include <linux/uprobes.h>
80208 #include <linux/rbtree_augmented.h>
80209 +#include <linux/random.h>
80210
80211 #include <asm/uaccess.h>
80212 #include <asm/cacheflush.h>
80213 @@ -48,6 +49,16 @@
80214 #define arch_rebalance_pgtables(addr, len) (addr)
80215 #endif
80216
80217 +static inline void verify_mm_writelocked(struct mm_struct *mm)
80218 +{
80219 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
80220 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
80221 + up_read(&mm->mmap_sem);
80222 + BUG();
80223 + }
80224 +#endif
80225 +}
80226 +
80227 static void unmap_region(struct mm_struct *mm,
80228 struct vm_area_struct *vma, struct vm_area_struct *prev,
80229 unsigned long start, unsigned long end);
80230 @@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
80231 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
80232 *
80233 */
80234 -pgprot_t protection_map[16] = {
80235 +pgprot_t protection_map[16] __read_only = {
80236 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
80237 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
80238 };
80239
80240 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
80241 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80242 {
80243 - return __pgprot(pgprot_val(protection_map[vm_flags &
80244 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
80245 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
80246 pgprot_val(arch_vm_get_page_prot(vm_flags)));
80247 +
80248 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80249 + if (!(__supported_pte_mask & _PAGE_NX) &&
80250 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
80251 + (vm_flags & (VM_READ | VM_WRITE)))
80252 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
80253 +#endif
80254 +
80255 + return prot;
80256 }
80257 EXPORT_SYMBOL(vm_get_page_prot);
80258
80259 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
80260 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
80261 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
80262 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
80263 /*
80264 * Make sure vm_committed_as in one cacheline and not cacheline shared with
80265 * other variables. It can be updated by several CPUs frequently.
80266 @@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
80267 struct vm_area_struct *next = vma->vm_next;
80268
80269 might_sleep();
80270 + BUG_ON(vma->vm_mirror);
80271 if (vma->vm_ops && vma->vm_ops->close)
80272 vma->vm_ops->close(vma);
80273 if (vma->vm_file)
80274 @@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
80275 * not page aligned -Ram Gupta
80276 */
80277 rlim = rlimit(RLIMIT_DATA);
80278 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
80279 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
80280 (mm->end_data - mm->start_data) > rlim)
80281 goto out;
80282 @@ -888,6 +911,12 @@ static int
80283 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
80284 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
80285 {
80286 +
80287 +#ifdef CONFIG_PAX_SEGMEXEC
80288 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
80289 + return 0;
80290 +#endif
80291 +
80292 if (is_mergeable_vma(vma, file, vm_flags) &&
80293 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
80294 if (vma->vm_pgoff == vm_pgoff)
80295 @@ -907,6 +936,12 @@ static int
80296 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
80297 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
80298 {
80299 +
80300 +#ifdef CONFIG_PAX_SEGMEXEC
80301 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
80302 + return 0;
80303 +#endif
80304 +
80305 if (is_mergeable_vma(vma, file, vm_flags) &&
80306 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
80307 pgoff_t vm_pglen;
80308 @@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
80309 struct vm_area_struct *vma_merge(struct mm_struct *mm,
80310 struct vm_area_struct *prev, unsigned long addr,
80311 unsigned long end, unsigned long vm_flags,
80312 - struct anon_vma *anon_vma, struct file *file,
80313 + struct anon_vma *anon_vma, struct file *file,
80314 pgoff_t pgoff, struct mempolicy *policy)
80315 {
80316 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
80317 struct vm_area_struct *area, *next;
80318 int err;
80319
80320 +#ifdef CONFIG_PAX_SEGMEXEC
80321 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
80322 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
80323 +
80324 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
80325 +#endif
80326 +
80327 /*
80328 * We later require that vma->vm_flags == vm_flags,
80329 * so this tests vma->vm_flags & VM_SPECIAL, too.
80330 @@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80331 if (next && next->vm_end == end) /* cases 6, 7, 8 */
80332 next = next->vm_next;
80333
80334 +#ifdef CONFIG_PAX_SEGMEXEC
80335 + if (prev)
80336 + prev_m = pax_find_mirror_vma(prev);
80337 + if (area)
80338 + area_m = pax_find_mirror_vma(area);
80339 + if (next)
80340 + next_m = pax_find_mirror_vma(next);
80341 +#endif
80342 +
80343 /*
80344 * Can it merge with the predecessor?
80345 */
80346 @@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80347 /* cases 1, 6 */
80348 err = vma_adjust(prev, prev->vm_start,
80349 next->vm_end, prev->vm_pgoff, NULL);
80350 - } else /* cases 2, 5, 7 */
80351 +
80352 +#ifdef CONFIG_PAX_SEGMEXEC
80353 + if (!err && prev_m)
80354 + err = vma_adjust(prev_m, prev_m->vm_start,
80355 + next_m->vm_end, prev_m->vm_pgoff, NULL);
80356 +#endif
80357 +
80358 + } else { /* cases 2, 5, 7 */
80359 err = vma_adjust(prev, prev->vm_start,
80360 end, prev->vm_pgoff, NULL);
80361 +
80362 +#ifdef CONFIG_PAX_SEGMEXEC
80363 + if (!err && prev_m)
80364 + err = vma_adjust(prev_m, prev_m->vm_start,
80365 + end_m, prev_m->vm_pgoff, NULL);
80366 +#endif
80367 +
80368 + }
80369 if (err)
80370 return NULL;
80371 khugepaged_enter_vma_merge(prev);
80372 @@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80373 mpol_equal(policy, vma_policy(next)) &&
80374 can_vma_merge_before(next, vm_flags,
80375 anon_vma, file, pgoff+pglen)) {
80376 - if (prev && addr < prev->vm_end) /* case 4 */
80377 + if (prev && addr < prev->vm_end) { /* case 4 */
80378 err = vma_adjust(prev, prev->vm_start,
80379 addr, prev->vm_pgoff, NULL);
80380 - else /* cases 3, 8 */
80381 +
80382 +#ifdef CONFIG_PAX_SEGMEXEC
80383 + if (!err && prev_m)
80384 + err = vma_adjust(prev_m, prev_m->vm_start,
80385 + addr_m, prev_m->vm_pgoff, NULL);
80386 +#endif
80387 +
80388 + } else { /* cases 3, 8 */
80389 err = vma_adjust(area, addr, next->vm_end,
80390 next->vm_pgoff - pglen, NULL);
80391 +
80392 +#ifdef CONFIG_PAX_SEGMEXEC
80393 + if (!err && area_m)
80394 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
80395 + next_m->vm_pgoff - pglen, NULL);
80396 +#endif
80397 +
80398 + }
80399 if (err)
80400 return NULL;
80401 khugepaged_enter_vma_merge(area);
80402 @@ -1120,16 +1201,13 @@ none:
80403 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
80404 struct file *file, long pages)
80405 {
80406 - const unsigned long stack_flags
80407 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
80408 -
80409 mm->total_vm += pages;
80410
80411 if (file) {
80412 mm->shared_vm += pages;
80413 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
80414 mm->exec_vm += pages;
80415 - } else if (flags & stack_flags)
80416 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
80417 mm->stack_vm += pages;
80418 }
80419 #endif /* CONFIG_PROC_FS */
80420 @@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80421 * (the exception is when the underlying filesystem is noexec
80422 * mounted, in which case we dont add PROT_EXEC.)
80423 */
80424 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
80425 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
80426 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
80427 prot |= PROT_EXEC;
80428
80429 @@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80430 /* Obtain the address to map to. we verify (or select) it and ensure
80431 * that it represents a valid section of the address space.
80432 */
80433 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
80434 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
80435 if (addr & ~PAGE_MASK)
80436 return addr;
80437
80438 @@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80439 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
80440 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
80441
80442 +#ifdef CONFIG_PAX_MPROTECT
80443 + if (mm->pax_flags & MF_PAX_MPROTECT) {
80444 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
80445 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
80446 + gr_log_rwxmmap(file);
80447 +
80448 +#ifdef CONFIG_PAX_EMUPLT
80449 + vm_flags &= ~VM_EXEC;
80450 +#else
80451 + return -EPERM;
80452 +#endif
80453 +
80454 + }
80455 +
80456 + if (!(vm_flags & VM_EXEC))
80457 + vm_flags &= ~VM_MAYEXEC;
80458 +#else
80459 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
80460 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
80461 +#endif
80462 + else
80463 + vm_flags &= ~VM_MAYWRITE;
80464 + }
80465 +#endif
80466 +
80467 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80468 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
80469 + vm_flags &= ~VM_PAGEEXEC;
80470 +#endif
80471 +
80472 if (flags & MAP_LOCKED)
80473 if (!can_do_mlock())
80474 return -EPERM;
80475 @@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80476 locked += mm->locked_vm;
80477 lock_limit = rlimit(RLIMIT_MEMLOCK);
80478 lock_limit >>= PAGE_SHIFT;
80479 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
80480 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
80481 return -EAGAIN;
80482 }
80483 @@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80484 }
80485 }
80486
80487 + if (!gr_acl_handle_mmap(file, prot))
80488 + return -EACCES;
80489 +
80490 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
80491 }
80492
80493 @@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
80494 vm_flags_t vm_flags = vma->vm_flags;
80495
80496 /* If it was private or non-writable, the write bit is already clear */
80497 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
80498 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
80499 return 0;
80500
80501 /* The backer wishes to know when pages are first written to? */
80502 @@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
80503 unsigned long charged = 0;
80504 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
80505
80506 +#ifdef CONFIG_PAX_SEGMEXEC
80507 + struct vm_area_struct *vma_m = NULL;
80508 +#endif
80509 +
80510 + /*
80511 + * mm->mmap_sem is required to protect against another thread
80512 + * changing the mappings in case we sleep.
80513 + */
80514 + verify_mm_writelocked(mm);
80515 +
80516 /* Clear old maps */
80517 error = -ENOMEM;
80518 -munmap_back:
80519 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
80520 if (do_munmap(mm, addr, len))
80521 return -ENOMEM;
80522 - goto munmap_back;
80523 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
80524 }
80525
80526 /* Check against address space limit. */
80527 @@ -1460,6 +1581,16 @@ munmap_back:
80528 goto unacct_error;
80529 }
80530
80531 +#ifdef CONFIG_PAX_SEGMEXEC
80532 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
80533 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
80534 + if (!vma_m) {
80535 + error = -ENOMEM;
80536 + goto free_vma;
80537 + }
80538 + }
80539 +#endif
80540 +
80541 vma->vm_mm = mm;
80542 vma->vm_start = addr;
80543 vma->vm_end = addr + len;
80544 @@ -1484,6 +1615,13 @@ munmap_back:
80545 if (error)
80546 goto unmap_and_free_vma;
80547
80548 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80549 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
80550 + vma->vm_flags |= VM_PAGEEXEC;
80551 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
80552 + }
80553 +#endif
80554 +
80555 /* Can addr have changed??
80556 *
80557 * Answer: Yes, several device drivers can do it in their
80558 @@ -1522,6 +1660,11 @@ munmap_back:
80559 vma_link(mm, vma, prev, rb_link, rb_parent);
80560 file = vma->vm_file;
80561
80562 +#ifdef CONFIG_PAX_SEGMEXEC
80563 + if (vma_m)
80564 + BUG_ON(pax_mirror_vma(vma_m, vma));
80565 +#endif
80566 +
80567 /* Once vma denies write, undo our temporary denial count */
80568 if (correct_wcount)
80569 atomic_inc(&inode->i_writecount);
80570 @@ -1529,6 +1672,7 @@ out:
80571 perf_event_mmap(vma);
80572
80573 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
80574 + track_exec_limit(mm, addr, addr + len, vm_flags);
80575 if (vm_flags & VM_LOCKED) {
80576 if (!mlock_vma_pages_range(vma, addr, addr + len))
80577 mm->locked_vm += (len >> PAGE_SHIFT);
80578 @@ -1550,6 +1694,12 @@ unmap_and_free_vma:
80579 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
80580 charged = 0;
80581 free_vma:
80582 +
80583 +#ifdef CONFIG_PAX_SEGMEXEC
80584 + if (vma_m)
80585 + kmem_cache_free(vm_area_cachep, vma_m);
80586 +#endif
80587 +
80588 kmem_cache_free(vm_area_cachep, vma);
80589 unacct_error:
80590 if (charged)
80591 @@ -1557,6 +1707,62 @@ unacct_error:
80592 return error;
80593 }
80594
80595 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
80596 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
80597 +{
80598 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
80599 + return (random32() & 0xFF) << PAGE_SHIFT;
80600 +
80601 + return 0;
80602 +}
80603 +#endif
80604 +
80605 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
80606 +{
80607 + if (!vma) {
80608 +#ifdef CONFIG_STACK_GROWSUP
80609 + if (addr > sysctl_heap_stack_gap)
80610 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
80611 + else
80612 + vma = find_vma(current->mm, 0);
80613 + if (vma && (vma->vm_flags & VM_GROWSUP))
80614 + return false;
80615 +#endif
80616 + return true;
80617 + }
80618 +
80619 + if (addr + len > vma->vm_start)
80620 + return false;
80621 +
80622 + if (vma->vm_flags & VM_GROWSDOWN)
80623 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
80624 +#ifdef CONFIG_STACK_GROWSUP
80625 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
80626 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
80627 +#endif
80628 + else if (offset)
80629 + return offset <= vma->vm_start - addr - len;
80630 +
80631 + return true;
80632 +}
80633 +
80634 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
80635 +{
80636 + if (vma->vm_start < len)
80637 + return -ENOMEM;
80638 +
80639 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
80640 + if (offset <= vma->vm_start - len)
80641 + return vma->vm_start - len - offset;
80642 + else
80643 + return -ENOMEM;
80644 + }
80645 +
80646 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
80647 + return vma->vm_start - len - sysctl_heap_stack_gap;
80648 + return -ENOMEM;
80649 +}
80650 +
80651 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
80652 {
80653 /*
80654 @@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80655 struct mm_struct *mm = current->mm;
80656 struct vm_area_struct *vma;
80657 struct vm_unmapped_area_info info;
80658 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
80659
80660 if (len > TASK_SIZE)
80661 return -ENOMEM;
80662 @@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80663 if (flags & MAP_FIXED)
80664 return addr;
80665
80666 +#ifdef CONFIG_PAX_RANDMMAP
80667 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
80668 +#endif
80669 +
80670 if (addr) {
80671 addr = PAGE_ALIGN(addr);
80672 vma = find_vma(mm, addr);
80673 - if (TASK_SIZE - len >= addr &&
80674 - (!vma || addr + len <= vma->vm_start))
80675 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
80676 return addr;
80677 }
80678
80679 info.flags = 0;
80680 info.length = len;
80681 info.low_limit = TASK_UNMAPPED_BASE;
80682 +
80683 +#ifdef CONFIG_PAX_RANDMMAP
80684 + if (mm->pax_flags & MF_PAX_RANDMMAP)
80685 + info.low_limit += mm->delta_mmap;
80686 +#endif
80687 +
80688 info.high_limit = TASK_SIZE;
80689 info.align_mask = 0;
80690 return vm_unmapped_area(&info);
80691 @@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80692
80693 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
80694 {
80695 +
80696 +#ifdef CONFIG_PAX_SEGMEXEC
80697 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
80698 + return;
80699 +#endif
80700 +
80701 /*
80702 * Is this a new hole at the lowest possible address?
80703 */
80704 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
80705 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
80706 mm->free_area_cache = addr;
80707 }
80708
80709 @@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80710 struct mm_struct *mm = current->mm;
80711 unsigned long addr = addr0;
80712 struct vm_unmapped_area_info info;
80713 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
80714
80715 /* requested length too big for entire address space */
80716 if (len > TASK_SIZE)
80717 @@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80718 if (flags & MAP_FIXED)
80719 return addr;
80720
80721 +#ifdef CONFIG_PAX_RANDMMAP
80722 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
80723 +#endif
80724 +
80725 /* requesting a specific address */
80726 if (addr) {
80727 addr = PAGE_ALIGN(addr);
80728 vma = find_vma(mm, addr);
80729 - if (TASK_SIZE - len >= addr &&
80730 - (!vma || addr + len <= vma->vm_start))
80731 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
80732 return addr;
80733 }
80734
80735 @@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80736 VM_BUG_ON(addr != -ENOMEM);
80737 info.flags = 0;
80738 info.low_limit = TASK_UNMAPPED_BASE;
80739 +
80740 +#ifdef CONFIG_PAX_RANDMMAP
80741 + if (mm->pax_flags & MF_PAX_RANDMMAP)
80742 + info.low_limit += mm->delta_mmap;
80743 +#endif
80744 +
80745 info.high_limit = TASK_SIZE;
80746 addr = vm_unmapped_area(&info);
80747 }
80748 @@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80749
80750 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
80751 {
80752 +
80753 +#ifdef CONFIG_PAX_SEGMEXEC
80754 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
80755 + return;
80756 +#endif
80757 +
80758 /*
80759 * Is this a new hole at the highest possible address?
80760 */
80761 @@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
80762 mm->free_area_cache = addr;
80763
80764 /* dont allow allocations above current base */
80765 - if (mm->free_area_cache > mm->mmap_base)
80766 + if (mm->free_area_cache > mm->mmap_base) {
80767 mm->free_area_cache = mm->mmap_base;
80768 + mm->cached_hole_size = ~0UL;
80769 + }
80770 }
80771
80772 unsigned long
80773 @@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
80774 return vma;
80775 }
80776
80777 +#ifdef CONFIG_PAX_SEGMEXEC
80778 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
80779 +{
80780 + struct vm_area_struct *vma_m;
80781 +
80782 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
80783 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
80784 + BUG_ON(vma->vm_mirror);
80785 + return NULL;
80786 + }
80787 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
80788 + vma_m = vma->vm_mirror;
80789 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
80790 + BUG_ON(vma->vm_file != vma_m->vm_file);
80791 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
80792 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
80793 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
80794 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
80795 + return vma_m;
80796 +}
80797 +#endif
80798 +
80799 /*
80800 * Verify that the stack growth is acceptable and
80801 * update accounting. This is shared with both the
80802 @@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80803 return -ENOMEM;
80804
80805 /* Stack limit test */
80806 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
80807 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
80808 return -ENOMEM;
80809
80810 @@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80811 locked = mm->locked_vm + grow;
80812 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
80813 limit >>= PAGE_SHIFT;
80814 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
80815 if (locked > limit && !capable(CAP_IPC_LOCK))
80816 return -ENOMEM;
80817 }
80818 @@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80819 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
80820 * vma is the last one with address > vma->vm_end. Have to extend vma.
80821 */
80822 +#ifndef CONFIG_IA64
80823 +static
80824 +#endif
80825 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
80826 {
80827 int error;
80828 + bool locknext;
80829
80830 if (!(vma->vm_flags & VM_GROWSUP))
80831 return -EFAULT;
80832
80833 + /* Also guard against wrapping around to address 0. */
80834 + if (address < PAGE_ALIGN(address+1))
80835 + address = PAGE_ALIGN(address+1);
80836 + else
80837 + return -ENOMEM;
80838 +
80839 /*
80840 * We must make sure the anon_vma is allocated
80841 * so that the anon_vma locking is not a noop.
80842 */
80843 if (unlikely(anon_vma_prepare(vma)))
80844 return -ENOMEM;
80845 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
80846 + if (locknext && anon_vma_prepare(vma->vm_next))
80847 + return -ENOMEM;
80848 vma_lock_anon_vma(vma);
80849 + if (locknext)
80850 + vma_lock_anon_vma(vma->vm_next);
80851
80852 /*
80853 * vma->vm_start/vm_end cannot change under us because the caller
80854 * is required to hold the mmap_sem in read mode. We need the
80855 - * anon_vma lock to serialize against concurrent expand_stacks.
80856 - * Also guard against wrapping around to address 0.
80857 + * anon_vma locks to serialize against concurrent expand_stacks
80858 + * and expand_upwards.
80859 */
80860 - if (address < PAGE_ALIGN(address+4))
80861 - address = PAGE_ALIGN(address+4);
80862 - else {
80863 - vma_unlock_anon_vma(vma);
80864 - return -ENOMEM;
80865 - }
80866 error = 0;
80867
80868 /* Somebody else might have raced and expanded it already */
80869 - if (address > vma->vm_end) {
80870 + 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)
80871 + error = -ENOMEM;
80872 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
80873 unsigned long size, grow;
80874
80875 size = address - vma->vm_start;
80876 @@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
80877 }
80878 }
80879 }
80880 + if (locknext)
80881 + vma_unlock_anon_vma(vma->vm_next);
80882 vma_unlock_anon_vma(vma);
80883 khugepaged_enter_vma_merge(vma);
80884 validate_mm(vma->vm_mm);
80885 @@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
80886 unsigned long address)
80887 {
80888 int error;
80889 + bool lockprev = false;
80890 + struct vm_area_struct *prev;
80891
80892 /*
80893 * We must make sure the anon_vma is allocated
80894 @@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
80895 if (error)
80896 return error;
80897
80898 + prev = vma->vm_prev;
80899 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
80900 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
80901 +#endif
80902 + if (lockprev && anon_vma_prepare(prev))
80903 + return -ENOMEM;
80904 + if (lockprev)
80905 + vma_lock_anon_vma(prev);
80906 +
80907 vma_lock_anon_vma(vma);
80908
80909 /*
80910 @@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
80911 */
80912
80913 /* Somebody else might have raced and expanded it already */
80914 - if (address < vma->vm_start) {
80915 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
80916 + error = -ENOMEM;
80917 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
80918 unsigned long size, grow;
80919
80920 +#ifdef CONFIG_PAX_SEGMEXEC
80921 + struct vm_area_struct *vma_m;
80922 +
80923 + vma_m = pax_find_mirror_vma(vma);
80924 +#endif
80925 +
80926 size = vma->vm_end - address;
80927 grow = (vma->vm_start - address) >> PAGE_SHIFT;
80928
80929 @@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
80930 vma->vm_pgoff -= grow;
80931 anon_vma_interval_tree_post_update_vma(vma);
80932 vma_gap_update(vma);
80933 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
80934 +
80935 +#ifdef CONFIG_PAX_SEGMEXEC
80936 + if (vma_m) {
80937 + anon_vma_interval_tree_pre_update_vma(vma_m);
80938 + vma_m->vm_start -= grow << PAGE_SHIFT;
80939 + vma_m->vm_pgoff -= grow;
80940 + anon_vma_interval_tree_post_update_vma(vma_m);
80941 + vma_gap_update(vma_m);
80942 + }
80943 +#endif
80944 +
80945 spin_unlock(&vma->vm_mm->page_table_lock);
80946
80947 perf_event_mmap(vma);
80948 @@ -2263,6 +2571,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
80949 do {
80950 long nrpages = vma_pages(vma);
80951
80952 +#ifdef CONFIG_PAX_SEGMEXEC
80953 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
80954 + vma = remove_vma(vma);
80955 + continue;
80956 + }
80957 +#endif
80958 +
80959 if (vma->vm_flags & VM_ACCOUNT)
80960 nr_accounted += nrpages;
80961 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
80962 @@ -2308,6 +2623,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
80963 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
80964 vma->vm_prev = NULL;
80965 do {
80966 +
80967 +#ifdef CONFIG_PAX_SEGMEXEC
80968 + if (vma->vm_mirror) {
80969 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
80970 + vma->vm_mirror->vm_mirror = NULL;
80971 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
80972 + vma->vm_mirror = NULL;
80973 + }
80974 +#endif
80975 +
80976 vma_rb_erase(vma, &mm->mm_rb);
80977 mm->map_count--;
80978 tail_vma = vma;
80979 @@ -2339,14 +2664,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
80980 struct vm_area_struct *new;
80981 int err = -ENOMEM;
80982
80983 +#ifdef CONFIG_PAX_SEGMEXEC
80984 + struct vm_area_struct *vma_m, *new_m = NULL;
80985 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
80986 +#endif
80987 +
80988 if (is_vm_hugetlb_page(vma) && (addr &
80989 ~(huge_page_mask(hstate_vma(vma)))))
80990 return -EINVAL;
80991
80992 +#ifdef CONFIG_PAX_SEGMEXEC
80993 + vma_m = pax_find_mirror_vma(vma);
80994 +#endif
80995 +
80996 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80997 if (!new)
80998 goto out_err;
80999
81000 +#ifdef CONFIG_PAX_SEGMEXEC
81001 + if (vma_m) {
81002 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81003 + if (!new_m) {
81004 + kmem_cache_free(vm_area_cachep, new);
81005 + goto out_err;
81006 + }
81007 + }
81008 +#endif
81009 +
81010 /* most fields are the same, copy all, and then fixup */
81011 *new = *vma;
81012
81013 @@ -2359,6 +2703,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81014 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
81015 }
81016
81017 +#ifdef CONFIG_PAX_SEGMEXEC
81018 + if (vma_m) {
81019 + *new_m = *vma_m;
81020 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
81021 + new_m->vm_mirror = new;
81022 + new->vm_mirror = new_m;
81023 +
81024 + if (new_below)
81025 + new_m->vm_end = addr_m;
81026 + else {
81027 + new_m->vm_start = addr_m;
81028 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
81029 + }
81030 + }
81031 +#endif
81032 +
81033 pol = mpol_dup(vma_policy(vma));
81034 if (IS_ERR(pol)) {
81035 err = PTR_ERR(pol);
81036 @@ -2381,6 +2741,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81037 else
81038 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
81039
81040 +#ifdef CONFIG_PAX_SEGMEXEC
81041 + if (!err && vma_m) {
81042 + if (anon_vma_clone(new_m, vma_m))
81043 + goto out_free_mpol;
81044 +
81045 + mpol_get(pol);
81046 + vma_set_policy(new_m, pol);
81047 +
81048 + if (new_m->vm_file)
81049 + get_file(new_m->vm_file);
81050 +
81051 + if (new_m->vm_ops && new_m->vm_ops->open)
81052 + new_m->vm_ops->open(new_m);
81053 +
81054 + if (new_below)
81055 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
81056 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
81057 + else
81058 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
81059 +
81060 + if (err) {
81061 + if (new_m->vm_ops && new_m->vm_ops->close)
81062 + new_m->vm_ops->close(new_m);
81063 + if (new_m->vm_file)
81064 + fput(new_m->vm_file);
81065 + mpol_put(pol);
81066 + }
81067 + }
81068 +#endif
81069 +
81070 /* Success. */
81071 if (!err)
81072 return 0;
81073 @@ -2390,10 +2780,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81074 new->vm_ops->close(new);
81075 if (new->vm_file)
81076 fput(new->vm_file);
81077 - unlink_anon_vmas(new);
81078 out_free_mpol:
81079 mpol_put(pol);
81080 out_free_vma:
81081 +
81082 +#ifdef CONFIG_PAX_SEGMEXEC
81083 + if (new_m) {
81084 + unlink_anon_vmas(new_m);
81085 + kmem_cache_free(vm_area_cachep, new_m);
81086 + }
81087 +#endif
81088 +
81089 + unlink_anon_vmas(new);
81090 kmem_cache_free(vm_area_cachep, new);
81091 out_err:
81092 return err;
81093 @@ -2406,6 +2804,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81094 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81095 unsigned long addr, int new_below)
81096 {
81097 +
81098 +#ifdef CONFIG_PAX_SEGMEXEC
81099 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
81100 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
81101 + if (mm->map_count >= sysctl_max_map_count-1)
81102 + return -ENOMEM;
81103 + } else
81104 +#endif
81105 +
81106 if (mm->map_count >= sysctl_max_map_count)
81107 return -ENOMEM;
81108
81109 @@ -2417,11 +2824,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81110 * work. This now handles partial unmappings.
81111 * Jeremy Fitzhardinge <jeremy@goop.org>
81112 */
81113 +#ifdef CONFIG_PAX_SEGMEXEC
81114 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81115 {
81116 + int ret = __do_munmap(mm, start, len);
81117 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
81118 + return ret;
81119 +
81120 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
81121 +}
81122 +
81123 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81124 +#else
81125 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81126 +#endif
81127 +{
81128 unsigned long end;
81129 struct vm_area_struct *vma, *prev, *last;
81130
81131 + /*
81132 + * mm->mmap_sem is required to protect against another thread
81133 + * changing the mappings in case we sleep.
81134 + */
81135 + verify_mm_writelocked(mm);
81136 +
81137 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
81138 return -EINVAL;
81139
81140 @@ -2496,6 +2922,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81141 /* Fix up all other VM information */
81142 remove_vma_list(mm, vma);
81143
81144 + track_exec_limit(mm, start, end, 0UL);
81145 +
81146 return 0;
81147 }
81148
81149 @@ -2504,6 +2932,13 @@ int vm_munmap(unsigned long start, size_t len)
81150 int ret;
81151 struct mm_struct *mm = current->mm;
81152
81153 +
81154 +#ifdef CONFIG_PAX_SEGMEXEC
81155 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
81156 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
81157 + return -EINVAL;
81158 +#endif
81159 +
81160 down_write(&mm->mmap_sem);
81161 ret = do_munmap(mm, start, len);
81162 up_write(&mm->mmap_sem);
81163 @@ -2517,16 +2952,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
81164 return vm_munmap(addr, len);
81165 }
81166
81167 -static inline void verify_mm_writelocked(struct mm_struct *mm)
81168 -{
81169 -#ifdef CONFIG_DEBUG_VM
81170 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
81171 - WARN_ON(1);
81172 - up_read(&mm->mmap_sem);
81173 - }
81174 -#endif
81175 -}
81176 -
81177 /*
81178 * this is really a simplified "do_mmap". it only handles
81179 * anonymous maps. eventually we may be able to do some
81180 @@ -2540,6 +2965,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81181 struct rb_node ** rb_link, * rb_parent;
81182 pgoff_t pgoff = addr >> PAGE_SHIFT;
81183 int error;
81184 + unsigned long charged;
81185
81186 len = PAGE_ALIGN(len);
81187 if (!len)
81188 @@ -2547,16 +2973,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81189
81190 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
81191
81192 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
81193 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
81194 + flags &= ~VM_EXEC;
81195 +
81196 +#ifdef CONFIG_PAX_MPROTECT
81197 + if (mm->pax_flags & MF_PAX_MPROTECT)
81198 + flags &= ~VM_MAYEXEC;
81199 +#endif
81200 +
81201 + }
81202 +#endif
81203 +
81204 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
81205 if (error & ~PAGE_MASK)
81206 return error;
81207
81208 + charged = len >> PAGE_SHIFT;
81209 +
81210 /*
81211 * mlock MCL_FUTURE?
81212 */
81213 if (mm->def_flags & VM_LOCKED) {
81214 unsigned long locked, lock_limit;
81215 - locked = len >> PAGE_SHIFT;
81216 + locked = charged;
81217 locked += mm->locked_vm;
81218 lock_limit = rlimit(RLIMIT_MEMLOCK);
81219 lock_limit >>= PAGE_SHIFT;
81220 @@ -2573,21 +3013,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81221 /*
81222 * Clear old maps. this also does some error checking for us
81223 */
81224 - munmap_back:
81225 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
81226 if (do_munmap(mm, addr, len))
81227 return -ENOMEM;
81228 - goto munmap_back;
81229 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
81230 }
81231
81232 /* Check against address space limits *after* clearing old maps... */
81233 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
81234 + if (!may_expand_vm(mm, charged))
81235 return -ENOMEM;
81236
81237 if (mm->map_count > sysctl_max_map_count)
81238 return -ENOMEM;
81239
81240 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
81241 + if (security_vm_enough_memory_mm(mm, charged))
81242 return -ENOMEM;
81243
81244 /* Can we just expand an old private anonymous mapping? */
81245 @@ -2601,7 +3040,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81246 */
81247 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81248 if (!vma) {
81249 - vm_unacct_memory(len >> PAGE_SHIFT);
81250 + vm_unacct_memory(charged);
81251 return -ENOMEM;
81252 }
81253
81254 @@ -2615,11 +3054,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81255 vma_link(mm, vma, prev, rb_link, rb_parent);
81256 out:
81257 perf_event_mmap(vma);
81258 - mm->total_vm += len >> PAGE_SHIFT;
81259 + mm->total_vm += charged;
81260 if (flags & VM_LOCKED) {
81261 if (!mlock_vma_pages_range(vma, addr, addr + len))
81262 - mm->locked_vm += (len >> PAGE_SHIFT);
81263 + mm->locked_vm += charged;
81264 }
81265 + track_exec_limit(mm, addr, addr + len, flags);
81266 return addr;
81267 }
81268
81269 @@ -2677,6 +3117,7 @@ void exit_mmap(struct mm_struct *mm)
81270 while (vma) {
81271 if (vma->vm_flags & VM_ACCOUNT)
81272 nr_accounted += vma_pages(vma);
81273 + vma->vm_mirror = NULL;
81274 vma = remove_vma(vma);
81275 }
81276 vm_unacct_memory(nr_accounted);
81277 @@ -2693,6 +3134,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
81278 struct vm_area_struct *prev;
81279 struct rb_node **rb_link, *rb_parent;
81280
81281 +#ifdef CONFIG_PAX_SEGMEXEC
81282 + struct vm_area_struct *vma_m = NULL;
81283 +#endif
81284 +
81285 + if (security_mmap_addr(vma->vm_start))
81286 + return -EPERM;
81287 +
81288 /*
81289 * The vm_pgoff of a purely anonymous vma should be irrelevant
81290 * until its first write fault, when page's anon_vma and index
81291 @@ -2716,7 +3164,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
81292 security_vm_enough_memory_mm(mm, vma_pages(vma)))
81293 return -ENOMEM;
81294
81295 +#ifdef CONFIG_PAX_SEGMEXEC
81296 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
81297 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81298 + if (!vma_m)
81299 + return -ENOMEM;
81300 + }
81301 +#endif
81302 +
81303 vma_link(mm, vma, prev, rb_link, rb_parent);
81304 +
81305 +#ifdef CONFIG_PAX_SEGMEXEC
81306 + if (vma_m)
81307 + BUG_ON(pax_mirror_vma(vma_m, vma));
81308 +#endif
81309 +
81310 return 0;
81311 }
81312
81313 @@ -2736,6 +3198,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
81314 struct mempolicy *pol;
81315 bool faulted_in_anon_vma = true;
81316
81317 + BUG_ON(vma->vm_mirror);
81318 +
81319 /*
81320 * If anonymous vma has not yet been faulted, update new pgoff
81321 * to match new location, to increase its chance of merging.
81322 @@ -2802,6 +3266,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
81323 return NULL;
81324 }
81325
81326 +#ifdef CONFIG_PAX_SEGMEXEC
81327 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
81328 +{
81329 + struct vm_area_struct *prev_m;
81330 + struct rb_node **rb_link_m, *rb_parent_m;
81331 + struct mempolicy *pol_m;
81332 +
81333 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
81334 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
81335 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
81336 + *vma_m = *vma;
81337 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
81338 + if (anon_vma_clone(vma_m, vma))
81339 + return -ENOMEM;
81340 + pol_m = vma_policy(vma_m);
81341 + mpol_get(pol_m);
81342 + vma_set_policy(vma_m, pol_m);
81343 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
81344 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
81345 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
81346 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
81347 + if (vma_m->vm_file)
81348 + get_file(vma_m->vm_file);
81349 + if (vma_m->vm_ops && vma_m->vm_ops->open)
81350 + vma_m->vm_ops->open(vma_m);
81351 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
81352 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
81353 + vma_m->vm_mirror = vma;
81354 + vma->vm_mirror = vma_m;
81355 + return 0;
81356 +}
81357 +#endif
81358 +
81359 /*
81360 * Return true if the calling process may expand its vm space by the passed
81361 * number of pages
81362 @@ -2813,6 +3310,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
81363
81364 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
81365
81366 +#ifdef CONFIG_PAX_RANDMMAP
81367 + if (mm->pax_flags & MF_PAX_RANDMMAP)
81368 + cur -= mm->brk_gap;
81369 +#endif
81370 +
81371 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
81372 if (cur + npages > lim)
81373 return 0;
81374 return 1;
81375 @@ -2883,6 +3386,22 @@ int install_special_mapping(struct mm_struct *mm,
81376 vma->vm_start = addr;
81377 vma->vm_end = addr + len;
81378
81379 +#ifdef CONFIG_PAX_MPROTECT
81380 + if (mm->pax_flags & MF_PAX_MPROTECT) {
81381 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
81382 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
81383 + return -EPERM;
81384 + if (!(vm_flags & VM_EXEC))
81385 + vm_flags &= ~VM_MAYEXEC;
81386 +#else
81387 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
81388 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
81389 +#endif
81390 + else
81391 + vm_flags &= ~VM_MAYWRITE;
81392 + }
81393 +#endif
81394 +
81395 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
81396 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
81397
81398 diff --git a/mm/mprotect.c b/mm/mprotect.c
81399 index 94722a4..9837984 100644
81400 --- a/mm/mprotect.c
81401 +++ b/mm/mprotect.c
81402 @@ -23,10 +23,17 @@
81403 #include <linux/mmu_notifier.h>
81404 #include <linux/migrate.h>
81405 #include <linux/perf_event.h>
81406 +
81407 +#ifdef CONFIG_PAX_MPROTECT
81408 +#include <linux/elf.h>
81409 +#include <linux/binfmts.h>
81410 +#endif
81411 +
81412 #include <asm/uaccess.h>
81413 #include <asm/pgtable.h>
81414 #include <asm/cacheflush.h>
81415 #include <asm/tlbflush.h>
81416 +#include <asm/mmu_context.h>
81417
81418 #ifndef pgprot_modify
81419 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
81420 @@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
81421 return pages;
81422 }
81423
81424 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81425 +/* called while holding the mmap semaphor for writing except stack expansion */
81426 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
81427 +{
81428 + unsigned long oldlimit, newlimit = 0UL;
81429 +
81430 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
81431 + return;
81432 +
81433 + spin_lock(&mm->page_table_lock);
81434 + oldlimit = mm->context.user_cs_limit;
81435 + if ((prot & VM_EXEC) && oldlimit < end)
81436 + /* USER_CS limit moved up */
81437 + newlimit = end;
81438 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
81439 + /* USER_CS limit moved down */
81440 + newlimit = start;
81441 +
81442 + if (newlimit) {
81443 + mm->context.user_cs_limit = newlimit;
81444 +
81445 +#ifdef CONFIG_SMP
81446 + wmb();
81447 + cpus_clear(mm->context.cpu_user_cs_mask);
81448 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
81449 +#endif
81450 +
81451 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
81452 + }
81453 + spin_unlock(&mm->page_table_lock);
81454 + if (newlimit == end) {
81455 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
81456 +
81457 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
81458 + if (is_vm_hugetlb_page(vma))
81459 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
81460 + else
81461 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
81462 + }
81463 +}
81464 +#endif
81465 +
81466 int
81467 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81468 unsigned long start, unsigned long end, unsigned long newflags)
81469 @@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81470 int error;
81471 int dirty_accountable = 0;
81472
81473 +#ifdef CONFIG_PAX_SEGMEXEC
81474 + struct vm_area_struct *vma_m = NULL;
81475 + unsigned long start_m, end_m;
81476 +
81477 + start_m = start + SEGMEXEC_TASK_SIZE;
81478 + end_m = end + SEGMEXEC_TASK_SIZE;
81479 +#endif
81480 +
81481 if (newflags == oldflags) {
81482 *pprev = vma;
81483 return 0;
81484 }
81485
81486 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
81487 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
81488 +
81489 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
81490 + return -ENOMEM;
81491 +
81492 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
81493 + return -ENOMEM;
81494 + }
81495 +
81496 /*
81497 * If we make a private mapping writable we increase our commit;
81498 * but (without finer accounting) cannot reduce our commit if we
81499 @@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81500 }
81501 }
81502
81503 +#ifdef CONFIG_PAX_SEGMEXEC
81504 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
81505 + if (start != vma->vm_start) {
81506 + error = split_vma(mm, vma, start, 1);
81507 + if (error)
81508 + goto fail;
81509 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
81510 + *pprev = (*pprev)->vm_next;
81511 + }
81512 +
81513 + if (end != vma->vm_end) {
81514 + error = split_vma(mm, vma, end, 0);
81515 + if (error)
81516 + goto fail;
81517 + }
81518 +
81519 + if (pax_find_mirror_vma(vma)) {
81520 + error = __do_munmap(mm, start_m, end_m - start_m);
81521 + if (error)
81522 + goto fail;
81523 + } else {
81524 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81525 + if (!vma_m) {
81526 + error = -ENOMEM;
81527 + goto fail;
81528 + }
81529 + vma->vm_flags = newflags;
81530 + error = pax_mirror_vma(vma_m, vma);
81531 + if (error) {
81532 + vma->vm_flags = oldflags;
81533 + goto fail;
81534 + }
81535 + }
81536 + }
81537 +#endif
81538 +
81539 /*
81540 * First try to merge with previous and/or next vma.
81541 */
81542 @@ -296,9 +399,21 @@ success:
81543 * vm_flags and vm_page_prot are protected by the mmap_sem
81544 * held in write mode.
81545 */
81546 +
81547 +#ifdef CONFIG_PAX_SEGMEXEC
81548 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
81549 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
81550 +#endif
81551 +
81552 vma->vm_flags = newflags;
81553 +
81554 +#ifdef CONFIG_PAX_MPROTECT
81555 + if (mm->binfmt && mm->binfmt->handle_mprotect)
81556 + mm->binfmt->handle_mprotect(vma, newflags);
81557 +#endif
81558 +
81559 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
81560 - vm_get_page_prot(newflags));
81561 + vm_get_page_prot(vma->vm_flags));
81562
81563 if (vma_wants_writenotify(vma)) {
81564 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
81565 @@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81566 end = start + len;
81567 if (end <= start)
81568 return -ENOMEM;
81569 +
81570 +#ifdef CONFIG_PAX_SEGMEXEC
81571 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81572 + if (end > SEGMEXEC_TASK_SIZE)
81573 + return -EINVAL;
81574 + } else
81575 +#endif
81576 +
81577 + if (end > TASK_SIZE)
81578 + return -EINVAL;
81579 +
81580 if (!arch_validate_prot(prot))
81581 return -EINVAL;
81582
81583 @@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81584 /*
81585 * Does the application expect PROT_READ to imply PROT_EXEC:
81586 */
81587 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
81588 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
81589 prot |= PROT_EXEC;
81590
81591 vm_flags = calc_vm_prot_bits(prot);
81592 @@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81593 if (start > vma->vm_start)
81594 prev = vma;
81595
81596 +#ifdef CONFIG_PAX_MPROTECT
81597 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
81598 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
81599 +#endif
81600 +
81601 for (nstart = start ; ; ) {
81602 unsigned long newflags;
81603
81604 @@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81605
81606 /* newflags >> 4 shift VM_MAY% in place of VM_% */
81607 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
81608 + if (prot & (PROT_WRITE | PROT_EXEC))
81609 + gr_log_rwxmprotect(vma->vm_file);
81610 +
81611 + error = -EACCES;
81612 + goto out;
81613 + }
81614 +
81615 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
81616 error = -EACCES;
81617 goto out;
81618 }
81619 @@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81620 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
81621 if (error)
81622 goto out;
81623 +
81624 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
81625 +
81626 nstart = tmp;
81627
81628 if (nstart < prev->vm_end)
81629 diff --git a/mm/mremap.c b/mm/mremap.c
81630 index e1031e1..1f2a0a1 100644
81631 --- a/mm/mremap.c
81632 +++ b/mm/mremap.c
81633 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
81634 continue;
81635 pte = ptep_get_and_clear(mm, old_addr, old_pte);
81636 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
81637 +
81638 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81639 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
81640 + pte = pte_exprotect(pte);
81641 +#endif
81642 +
81643 set_pte_at(mm, new_addr, new_pte, pte);
81644 }
81645
81646 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
81647 if (is_vm_hugetlb_page(vma))
81648 goto Einval;
81649
81650 +#ifdef CONFIG_PAX_SEGMEXEC
81651 + if (pax_find_mirror_vma(vma))
81652 + goto Einval;
81653 +#endif
81654 +
81655 /* We can't remap across vm area boundaries */
81656 if (old_len > vma->vm_end - addr)
81657 goto Efault;
81658 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
81659 unsigned long ret = -EINVAL;
81660 unsigned long charged = 0;
81661 unsigned long map_flags;
81662 + unsigned long pax_task_size = TASK_SIZE;
81663
81664 if (new_addr & ~PAGE_MASK)
81665 goto out;
81666
81667 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
81668 +#ifdef CONFIG_PAX_SEGMEXEC
81669 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
81670 + pax_task_size = SEGMEXEC_TASK_SIZE;
81671 +#endif
81672 +
81673 + pax_task_size -= PAGE_SIZE;
81674 +
81675 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
81676 goto out;
81677
81678 /* Check if the location we're moving into overlaps the
81679 * old location at all, and fail if it does.
81680 */
81681 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
81682 - goto out;
81683 -
81684 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
81685 + if (addr + old_len > new_addr && new_addr + new_len > addr)
81686 goto out;
81687
81688 ret = do_munmap(mm, new_addr, new_len);
81689 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81690 struct vm_area_struct *vma;
81691 unsigned long ret = -EINVAL;
81692 unsigned long charged = 0;
81693 + unsigned long pax_task_size = TASK_SIZE;
81694
81695 down_write(&current->mm->mmap_sem);
81696
81697 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81698 if (!new_len)
81699 goto out;
81700
81701 +#ifdef CONFIG_PAX_SEGMEXEC
81702 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
81703 + pax_task_size = SEGMEXEC_TASK_SIZE;
81704 +#endif
81705 +
81706 + pax_task_size -= PAGE_SIZE;
81707 +
81708 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
81709 + old_len > pax_task_size || addr > pax_task_size-old_len)
81710 + goto out;
81711 +
81712 if (flags & MREMAP_FIXED) {
81713 if (flags & MREMAP_MAYMOVE)
81714 ret = mremap_to(addr, old_len, new_addr, new_len);
81715 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81716 addr + new_len);
81717 }
81718 ret = addr;
81719 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
81720 goto out;
81721 }
81722 }
81723 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81724 goto out;
81725 }
81726
81727 + map_flags = vma->vm_flags;
81728 ret = move_vma(vma, addr, old_len, new_len, new_addr);
81729 + if (!(ret & ~PAGE_MASK)) {
81730 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
81731 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
81732 + }
81733 }
81734 out:
81735 if (ret & ~PAGE_MASK)
81736 diff --git a/mm/nommu.c b/mm/nommu.c
81737 index 79c3cac..4d357e0 100644
81738 --- a/mm/nommu.c
81739 +++ b/mm/nommu.c
81740 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
81741 int sysctl_overcommit_ratio = 50; /* default is 50% */
81742 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
81743 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
81744 -int heap_stack_gap = 0;
81745
81746 atomic_long_t mmap_pages_allocated;
81747
81748 @@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
81749 EXPORT_SYMBOL(find_vma);
81750
81751 /*
81752 - * find a VMA
81753 - * - we don't extend stack VMAs under NOMMU conditions
81754 - */
81755 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
81756 -{
81757 - return find_vma(mm, addr);
81758 -}
81759 -
81760 -/*
81761 * expand a stack to a given address
81762 * - not supported under NOMMU conditions
81763 */
81764 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81765
81766 /* most fields are the same, copy all, and then fixup */
81767 *new = *vma;
81768 + INIT_LIST_HEAD(&new->anon_vma_chain);
81769 *region = *vma->vm_region;
81770 new->vm_region = region;
81771
81772 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
81773 index 0713bfb..e3774e0 100644
81774 --- a/mm/page-writeback.c
81775 +++ b/mm/page-writeback.c
81776 @@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
81777 }
81778 }
81779
81780 -static struct notifier_block __cpuinitdata ratelimit_nb = {
81781 +static struct notifier_block ratelimit_nb = {
81782 .notifier_call = ratelimit_handler,
81783 .next = NULL,
81784 };
81785 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
81786 index 6a83cd3..fbe7cab 100644
81787 --- a/mm/page_alloc.c
81788 +++ b/mm/page_alloc.c
81789 @@ -58,6 +58,7 @@
81790 #include <linux/prefetch.h>
81791 #include <linux/migrate.h>
81792 #include <linux/page-debug-flags.h>
81793 +#include <linux/random.h>
81794
81795 #include <asm/tlbflush.h>
81796 #include <asm/div64.h>
81797 @@ -338,7 +339,7 @@ out:
81798 * This usage means that zero-order pages may not be compound.
81799 */
81800
81801 -static void free_compound_page(struct page *page)
81802 +void free_compound_page(struct page *page)
81803 {
81804 __free_pages_ok(page, compound_order(page));
81805 }
81806 @@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
81807 int i;
81808 int bad = 0;
81809
81810 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81811 + unsigned long index = 1UL << order;
81812 +#endif
81813 +
81814 trace_mm_page_free(page, order);
81815 kmemcheck_free_shadow(page, order);
81816
81817 @@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
81818 debug_check_no_obj_freed(page_address(page),
81819 PAGE_SIZE << order);
81820 }
81821 +
81822 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81823 + for (; index; --index)
81824 + sanitize_highpage(page + index - 1);
81825 +#endif
81826 +
81827 arch_free_page(page, order);
81828 kernel_map_pages(page, 1 << order, 0);
81829
81830 @@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
81831 local_irq_restore(flags);
81832 }
81833
81834 +#ifdef CONFIG_PAX_LATENT_ENTROPY
81835 +bool __meminitdata extra_latent_entropy;
81836 +
81837 +static int __init setup_pax_extra_latent_entropy(char *str)
81838 +{
81839 + extra_latent_entropy = true;
81840 + return 0;
81841 +}
81842 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
81843 +
81844 +u64 latent_entropy;
81845 +#endif
81846 +
81847 /*
81848 * Read access to zone->managed_pages is safe because it's unsigned long,
81849 * but we still need to serialize writers. Currently all callers of
81850 @@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
81851 set_page_count(p, 0);
81852 }
81853
81854 +#ifdef CONFIG_PAX_LATENT_ENTROPY
81855 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
81856 + u64 hash = 0;
81857 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
81858 + const u64 *data = lowmem_page_address(page);
81859 +
81860 + for (index = 0; index < end; index++)
81861 + hash ^= hash + data[index];
81862 + latent_entropy ^= hash;
81863 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
81864 + }
81865 +#endif
81866 +
81867 page_zone(page)->managed_pages += 1 << order;
81868 set_page_refcounted(page);
81869 __free_pages(page, order);
81870 @@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
81871 arch_alloc_page(page, order);
81872 kernel_map_pages(page, 1 << order, 1);
81873
81874 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
81875 if (gfp_flags & __GFP_ZERO)
81876 prep_zero_page(page, order, gfp_flags);
81877 +#endif
81878
81879 if (order && (gfp_flags & __GFP_COMP))
81880 prep_compound_page(page, order);
81881 @@ -3752,7 +3791,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
81882 unsigned long pfn;
81883
81884 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
81885 +#ifdef CONFIG_X86_32
81886 + /* boot failures in VMware 8 on 32bit vanilla since
81887 + this change */
81888 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
81889 +#else
81890 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
81891 +#endif
81892 return 1;
81893 }
81894 return 0;
81895 diff --git a/mm/percpu.c b/mm/percpu.c
81896 index 8c8e08f..73a5cda 100644
81897 --- a/mm/percpu.c
81898 +++ b/mm/percpu.c
81899 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
81900 static unsigned int pcpu_high_unit_cpu __read_mostly;
81901
81902 /* the address of the first chunk which starts with the kernel static area */
81903 -void *pcpu_base_addr __read_mostly;
81904 +void *pcpu_base_addr __read_only;
81905 EXPORT_SYMBOL_GPL(pcpu_base_addr);
81906
81907 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
81908 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
81909 index 926b466..b23df53 100644
81910 --- a/mm/process_vm_access.c
81911 +++ b/mm/process_vm_access.c
81912 @@ -13,6 +13,7 @@
81913 #include <linux/uio.h>
81914 #include <linux/sched.h>
81915 #include <linux/highmem.h>
81916 +#include <linux/security.h>
81917 #include <linux/ptrace.h>
81918 #include <linux/slab.h>
81919 #include <linux/syscalls.h>
81920 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
81921 size_t iov_l_curr_offset = 0;
81922 ssize_t iov_len;
81923
81924 + return -ENOSYS; // PaX: until properly audited
81925 +
81926 /*
81927 * Work out how many pages of struct pages we're going to need
81928 * when eventually calling get_user_pages
81929 */
81930 for (i = 0; i < riovcnt; i++) {
81931 iov_len = rvec[i].iov_len;
81932 - if (iov_len > 0) {
81933 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
81934 - + iov_len)
81935 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
81936 - / PAGE_SIZE + 1;
81937 - nr_pages = max(nr_pages, nr_pages_iov);
81938 - }
81939 + if (iov_len <= 0)
81940 + continue;
81941 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
81942 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
81943 + nr_pages = max(nr_pages, nr_pages_iov);
81944 }
81945
81946 if (nr_pages == 0)
81947 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
81948 goto free_proc_pages;
81949 }
81950
81951 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
81952 + rc = -EPERM;
81953 + goto put_task_struct;
81954 + }
81955 +
81956 mm = mm_access(task, PTRACE_MODE_ATTACH);
81957 if (!mm || IS_ERR(mm)) {
81958 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
81959 diff --git a/mm/rmap.c b/mm/rmap.c
81960 index 2c78f8c..9e9c624 100644
81961 --- a/mm/rmap.c
81962 +++ b/mm/rmap.c
81963 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81964 struct anon_vma *anon_vma = vma->anon_vma;
81965 struct anon_vma_chain *avc;
81966
81967 +#ifdef CONFIG_PAX_SEGMEXEC
81968 + struct anon_vma_chain *avc_m = NULL;
81969 +#endif
81970 +
81971 might_sleep();
81972 if (unlikely(!anon_vma)) {
81973 struct mm_struct *mm = vma->vm_mm;
81974 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81975 if (!avc)
81976 goto out_enomem;
81977
81978 +#ifdef CONFIG_PAX_SEGMEXEC
81979 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
81980 + if (!avc_m)
81981 + goto out_enomem_free_avc;
81982 +#endif
81983 +
81984 anon_vma = find_mergeable_anon_vma(vma);
81985 allocated = NULL;
81986 if (!anon_vma) {
81987 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81988 /* page_table_lock to protect against threads */
81989 spin_lock(&mm->page_table_lock);
81990 if (likely(!vma->anon_vma)) {
81991 +
81992 +#ifdef CONFIG_PAX_SEGMEXEC
81993 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
81994 +
81995 + if (vma_m) {
81996 + BUG_ON(vma_m->anon_vma);
81997 + vma_m->anon_vma = anon_vma;
81998 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
81999 + avc_m = NULL;
82000 + }
82001 +#endif
82002 +
82003 vma->anon_vma = anon_vma;
82004 anon_vma_chain_link(vma, avc, anon_vma);
82005 allocated = NULL;
82006 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82007
82008 if (unlikely(allocated))
82009 put_anon_vma(allocated);
82010 +
82011 +#ifdef CONFIG_PAX_SEGMEXEC
82012 + if (unlikely(avc_m))
82013 + anon_vma_chain_free(avc_m);
82014 +#endif
82015 +
82016 if (unlikely(avc))
82017 anon_vma_chain_free(avc);
82018 }
82019 return 0;
82020
82021 out_enomem_free_avc:
82022 +
82023 +#ifdef CONFIG_PAX_SEGMEXEC
82024 + if (avc_m)
82025 + anon_vma_chain_free(avc_m);
82026 +#endif
82027 +
82028 anon_vma_chain_free(avc);
82029 out_enomem:
82030 return -ENOMEM;
82031 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
82032 * Attach the anon_vmas from src to dst.
82033 * Returns 0 on success, -ENOMEM on failure.
82034 */
82035 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82036 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
82037 {
82038 struct anon_vma_chain *avc, *pavc;
82039 struct anon_vma *root = NULL;
82040 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82041 * the corresponding VMA in the parent process is attached to.
82042 * Returns 0 on success, non-zero on failure.
82043 */
82044 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
82045 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
82046 {
82047 struct anon_vma_chain *avc;
82048 struct anon_vma *anon_vma;
82049 diff --git a/mm/shmem.c b/mm/shmem.c
82050 index efd0b3a..994b702 100644
82051 --- a/mm/shmem.c
82052 +++ b/mm/shmem.c
82053 @@ -31,7 +31,7 @@
82054 #include <linux/export.h>
82055 #include <linux/swap.h>
82056
82057 -static struct vfsmount *shm_mnt;
82058 +struct vfsmount *shm_mnt;
82059
82060 #ifdef CONFIG_SHMEM
82061 /*
82062 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
82063 #define BOGO_DIRENT_SIZE 20
82064
82065 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
82066 -#define SHORT_SYMLINK_LEN 128
82067 +#define SHORT_SYMLINK_LEN 64
82068
82069 /*
82070 * shmem_fallocate and shmem_writepage communicate via inode->i_private
82071 @@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
82072 static int shmem_xattr_validate(const char *name)
82073 {
82074 struct { const char *prefix; size_t len; } arr[] = {
82075 +
82076 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82077 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
82078 +#endif
82079 +
82080 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
82081 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
82082 };
82083 @@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
82084 if (err)
82085 return err;
82086
82087 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82088 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
82089 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
82090 + return -EOPNOTSUPP;
82091 + if (size > 8)
82092 + return -EINVAL;
82093 + }
82094 +#endif
82095 +
82096 return simple_xattr_set(&info->xattrs, name, value, size, flags);
82097 }
82098
82099 @@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
82100 int err = -ENOMEM;
82101
82102 /* Round up to L1_CACHE_BYTES to resist false sharing */
82103 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
82104 - L1_CACHE_BYTES), GFP_KERNEL);
82105 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
82106 if (!sbinfo)
82107 return -ENOMEM;
82108
82109 diff --git a/mm/slab.c b/mm/slab.c
82110 index e7667a3..b62c169 100644
82111 --- a/mm/slab.c
82112 +++ b/mm/slab.c
82113 @@ -306,7 +306,7 @@ struct kmem_list3 {
82114 * Need this for bootstrapping a per node allocator.
82115 */
82116 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
82117 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
82118 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
82119 #define CACHE_CACHE 0
82120 #define SIZE_AC MAX_NUMNODES
82121 #define SIZE_L3 (2 * MAX_NUMNODES)
82122 @@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
82123 if ((x)->max_freeable < i) \
82124 (x)->max_freeable = i; \
82125 } while (0)
82126 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
82127 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
82128 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
82129 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
82130 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
82131 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
82132 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
82133 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
82134 #else
82135 #define STATS_INC_ACTIVE(x) do { } while (0)
82136 #define STATS_DEC_ACTIVE(x) do { } while (0)
82137 @@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
82138 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
82139 */
82140 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
82141 - const struct slab *slab, void *obj)
82142 + const struct slab *slab, const void *obj)
82143 {
82144 u32 offset = (obj - slab->s_mem);
82145 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
82146 @@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
82147 struct cache_names {
82148 char *name;
82149 char *name_dma;
82150 + char *name_usercopy;
82151 };
82152
82153 static struct cache_names __initdata cache_names[] = {
82154 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
82155 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
82156 #include <linux/kmalloc_sizes.h>
82157 - {NULL,}
82158 + {NULL}
82159 #undef CACHE
82160 };
82161
82162 @@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
82163 if (unlikely(gfpflags & GFP_DMA))
82164 return csizep->cs_dmacachep;
82165 #endif
82166 +
82167 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82168 + if (unlikely(gfpflags & GFP_USERCOPY))
82169 + return csizep->cs_usercopycachep;
82170 +#endif
82171 +
82172 return csizep->cs_cachep;
82173 }
82174
82175 @@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
82176 return notifier_from_errno(err);
82177 }
82178
82179 -static struct notifier_block __cpuinitdata cpucache_notifier = {
82180 +static struct notifier_block cpucache_notifier = {
82181 &cpuup_callback, NULL, 0
82182 };
82183
82184 @@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
82185 */
82186
82187 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
82188 - sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
82189 + sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82190
82191 if (INDEX_AC != INDEX_L3)
82192 sizes[INDEX_L3].cs_cachep =
82193 create_kmalloc_cache(names[INDEX_L3].name,
82194 - sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
82195 + sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82196
82197 slab_early_init = 0;
82198
82199 @@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
82200 */
82201 if (!sizes->cs_cachep)
82202 sizes->cs_cachep = create_kmalloc_cache(names->name,
82203 - sizes->cs_size, ARCH_KMALLOC_FLAGS);
82204 + sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82205
82206 #ifdef CONFIG_ZONE_DMA
82207 sizes->cs_dmacachep = create_kmalloc_cache(
82208 names->name_dma, sizes->cs_size,
82209 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
82210 #endif
82211 +
82212 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82213 + sizes->cs_usercopycachep = create_kmalloc_cache(
82214 + names->name_usercopy, sizes->cs_size,
82215 + ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82216 +#endif
82217 +
82218 sizes++;
82219 names++;
82220 }
82221 @@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
82222 }
82223 /* cpu stats */
82224 {
82225 - unsigned long allochit = atomic_read(&cachep->allochit);
82226 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
82227 - unsigned long freehit = atomic_read(&cachep->freehit);
82228 - unsigned long freemiss = atomic_read(&cachep->freemiss);
82229 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
82230 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
82231 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
82232 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
82233
82234 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
82235 allochit, allocmiss, freehit, freemiss);
82236 @@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
82237 static int __init slab_proc_init(void)
82238 {
82239 #ifdef CONFIG_DEBUG_SLAB_LEAK
82240 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
82241 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
82242 #endif
82243 return 0;
82244 }
82245 module_init(slab_proc_init);
82246 #endif
82247
82248 +bool is_usercopy_object(const void *ptr)
82249 +{
82250 + struct page *page;
82251 + struct kmem_cache *cachep;
82252 +
82253 + if (ZERO_OR_NULL_PTR(ptr))
82254 + return false;
82255 +
82256 + if (!slab_is_available())
82257 + return false;
82258 +
82259 + if (!virt_addr_valid(ptr))
82260 + return false;
82261 +
82262 + page = virt_to_head_page(ptr);
82263 +
82264 + if (!PageSlab(page))
82265 + return false;
82266 +
82267 + cachep = page->slab_cache;
82268 + return cachep->flags & SLAB_USERCOPY;
82269 +}
82270 +
82271 +#ifdef CONFIG_PAX_USERCOPY
82272 +const char *check_heap_object(const void *ptr, unsigned long n)
82273 +{
82274 + struct page *page;
82275 + struct kmem_cache *cachep;
82276 + struct slab *slabp;
82277 + unsigned int objnr;
82278 + unsigned long offset;
82279 +
82280 + if (ZERO_OR_NULL_PTR(ptr))
82281 + return "<null>";
82282 +
82283 + if (!virt_addr_valid(ptr))
82284 + return NULL;
82285 +
82286 + page = virt_to_head_page(ptr);
82287 +
82288 + if (!PageSlab(page))
82289 + return NULL;
82290 +
82291 + cachep = page->slab_cache;
82292 + if (!(cachep->flags & SLAB_USERCOPY))
82293 + return cachep->name;
82294 +
82295 + slabp = page->slab_page;
82296 + objnr = obj_to_index(cachep, slabp, ptr);
82297 + BUG_ON(objnr >= cachep->num);
82298 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
82299 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
82300 + return NULL;
82301 +
82302 + return cachep->name;
82303 +}
82304 +#endif
82305 +
82306 /**
82307 * ksize - get the actual amount of memory allocated for a given object
82308 * @objp: Pointer to the object
82309 diff --git a/mm/slab.h b/mm/slab.h
82310 index 34a98d6..73633d1 100644
82311 --- a/mm/slab.h
82312 +++ b/mm/slab.h
82313 @@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82314
82315 /* Legal flag mask for kmem_cache_create(), for various configurations */
82316 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
82317 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
82318 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
82319
82320 #if defined(CONFIG_DEBUG_SLAB)
82321 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
82322 @@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
82323 return s;
82324
82325 page = virt_to_head_page(x);
82326 +
82327 + BUG_ON(!PageSlab(page));
82328 +
82329 cachep = page->slab_cache;
82330 if (slab_equal_or_root(cachep, s))
82331 return cachep;
82332 diff --git a/mm/slab_common.c b/mm/slab_common.c
82333 index 3f3cd97..93b0236 100644
82334 --- a/mm/slab_common.c
82335 +++ b/mm/slab_common.c
82336 @@ -22,7 +22,7 @@
82337
82338 #include "slab.h"
82339
82340 -enum slab_state slab_state;
82341 +enum slab_state slab_state __read_only;
82342 LIST_HEAD(slab_caches);
82343 DEFINE_MUTEX(slab_mutex);
82344 struct kmem_cache *kmem_cache;
82345 @@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
82346
82347 err = __kmem_cache_create(s, flags);
82348 if (!err) {
82349 - s->refcount = 1;
82350 + atomic_set(&s->refcount, 1);
82351 list_add(&s->list, &slab_caches);
82352 memcg_cache_list_add(memcg, s);
82353 } else {
82354 @@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
82355
82356 get_online_cpus();
82357 mutex_lock(&slab_mutex);
82358 - s->refcount--;
82359 - if (!s->refcount) {
82360 + if (atomic_dec_and_test(&s->refcount)) {
82361 list_del(&s->list);
82362
82363 if (!__kmem_cache_shutdown(s)) {
82364 @@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
82365 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
82366 name, size, err);
82367
82368 - s->refcount = -1; /* Exempt from merging for now */
82369 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
82370 }
82371
82372 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
82373 @@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
82374
82375 create_boot_cache(s, name, size, flags);
82376 list_add(&s->list, &slab_caches);
82377 - s->refcount = 1;
82378 + atomic_set(&s->refcount, 1);
82379 return s;
82380 }
82381
82382 diff --git a/mm/slob.c b/mm/slob.c
82383 index a99fdf7..f5b6577 100644
82384 --- a/mm/slob.c
82385 +++ b/mm/slob.c
82386 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
82387 /*
82388 * Return the size of a slob block.
82389 */
82390 -static slobidx_t slob_units(slob_t *s)
82391 +static slobidx_t slob_units(const slob_t *s)
82392 {
82393 if (s->units > 0)
82394 return s->units;
82395 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
82396 /*
82397 * Return the next free slob block pointer after this one.
82398 */
82399 -static slob_t *slob_next(slob_t *s)
82400 +static slob_t *slob_next(const slob_t *s)
82401 {
82402 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
82403 slobidx_t next;
82404 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
82405 /*
82406 * Returns true if s is the last free block in its page.
82407 */
82408 -static int slob_last(slob_t *s)
82409 +static int slob_last(const slob_t *s)
82410 {
82411 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
82412 }
82413
82414 -static void *slob_new_pages(gfp_t gfp, int order, int node)
82415 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
82416 {
82417 - void *page;
82418 + struct page *page;
82419
82420 #ifdef CONFIG_NUMA
82421 if (node != NUMA_NO_NODE)
82422 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
82423 if (!page)
82424 return NULL;
82425
82426 - return page_address(page);
82427 + __SetPageSlab(page);
82428 + return page;
82429 }
82430
82431 -static void slob_free_pages(void *b, int order)
82432 +static void slob_free_pages(struct page *sp, int order)
82433 {
82434 if (current->reclaim_state)
82435 current->reclaim_state->reclaimed_slab += 1 << order;
82436 - free_pages((unsigned long)b, order);
82437 + __ClearPageSlab(sp);
82438 + reset_page_mapcount(sp);
82439 + sp->private = 0;
82440 + __free_pages(sp, order);
82441 }
82442
82443 /*
82444 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
82445
82446 /* Not enough space: must allocate a new page */
82447 if (!b) {
82448 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
82449 - if (!b)
82450 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
82451 + if (!sp)
82452 return NULL;
82453 - sp = virt_to_page(b);
82454 - __SetPageSlab(sp);
82455 + b = page_address(sp);
82456
82457 spin_lock_irqsave(&slob_lock, flags);
82458 sp->units = SLOB_UNITS(PAGE_SIZE);
82459 sp->freelist = b;
82460 + sp->private = 0;
82461 INIT_LIST_HEAD(&sp->list);
82462 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
82463 set_slob_page_free(sp, slob_list);
82464 @@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
82465 if (slob_page_free(sp))
82466 clear_slob_page_free(sp);
82467 spin_unlock_irqrestore(&slob_lock, flags);
82468 - __ClearPageSlab(sp);
82469 - reset_page_mapcount(sp);
82470 - slob_free_pages(b, 0);
82471 + slob_free_pages(sp, 0);
82472 return;
82473 }
82474
82475 @@ -424,11 +426,10 @@ out:
82476 */
82477
82478 static __always_inline void *
82479 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82480 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
82481 {
82482 - unsigned int *m;
82483 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82484 - void *ret;
82485 + slob_t *m;
82486 + void *ret = NULL;
82487
82488 gfp &= gfp_allowed_mask;
82489
82490 @@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82491
82492 if (!m)
82493 return NULL;
82494 - *m = size;
82495 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
82496 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
82497 + m[0].units = size;
82498 + m[1].units = align;
82499 ret = (void *)m + align;
82500
82501 trace_kmalloc_node(caller, ret,
82502 size, size + align, gfp, node);
82503 } else {
82504 unsigned int order = get_order(size);
82505 + struct page *page;
82506
82507 if (likely(order))
82508 gfp |= __GFP_COMP;
82509 - ret = slob_new_pages(gfp, order, node);
82510 + page = slob_new_pages(gfp, order, node);
82511 + if (page) {
82512 + ret = page_address(page);
82513 + page->private = size;
82514 + }
82515
82516 trace_kmalloc_node(caller, ret,
82517 size, PAGE_SIZE << order, gfp, node);
82518 }
82519
82520 - kmemleak_alloc(ret, size, 1, gfp);
82521 + return ret;
82522 +}
82523 +
82524 +static __always_inline void *
82525 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82526 +{
82527 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82528 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
82529 +
82530 + if (!ZERO_OR_NULL_PTR(ret))
82531 + kmemleak_alloc(ret, size, 1, gfp);
82532 return ret;
82533 }
82534
82535 @@ -494,33 +513,110 @@ void kfree(const void *block)
82536 kmemleak_free(block);
82537
82538 sp = virt_to_page(block);
82539 - if (PageSlab(sp)) {
82540 + VM_BUG_ON(!PageSlab(sp));
82541 + if (!sp->private) {
82542 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82543 - unsigned int *m = (unsigned int *)(block - align);
82544 - slob_free(m, *m + align);
82545 - } else
82546 + slob_t *m = (slob_t *)(block - align);
82547 + slob_free(m, m[0].units + align);
82548 + } else {
82549 + __ClearPageSlab(sp);
82550 + reset_page_mapcount(sp);
82551 + sp->private = 0;
82552 __free_pages(sp, compound_order(sp));
82553 + }
82554 }
82555 EXPORT_SYMBOL(kfree);
82556
82557 +bool is_usercopy_object(const void *ptr)
82558 +{
82559 + if (!slab_is_available())
82560 + return false;
82561 +
82562 + // PAX: TODO
82563 +
82564 + return false;
82565 +}
82566 +
82567 +#ifdef CONFIG_PAX_USERCOPY
82568 +const char *check_heap_object(const void *ptr, unsigned long n)
82569 +{
82570 + struct page *page;
82571 + const slob_t *free;
82572 + const void *base;
82573 + unsigned long flags;
82574 +
82575 + if (ZERO_OR_NULL_PTR(ptr))
82576 + return "<null>";
82577 +
82578 + if (!virt_addr_valid(ptr))
82579 + return NULL;
82580 +
82581 + page = virt_to_head_page(ptr);
82582 + if (!PageSlab(page))
82583 + return NULL;
82584 +
82585 + if (page->private) {
82586 + base = page;
82587 + if (base <= ptr && n <= page->private - (ptr - base))
82588 + return NULL;
82589 + return "<slob>";
82590 + }
82591 +
82592 + /* some tricky double walking to find the chunk */
82593 + spin_lock_irqsave(&slob_lock, flags);
82594 + base = (void *)((unsigned long)ptr & PAGE_MASK);
82595 + free = page->freelist;
82596 +
82597 + while (!slob_last(free) && (void *)free <= ptr) {
82598 + base = free + slob_units(free);
82599 + free = slob_next(free);
82600 + }
82601 +
82602 + while (base < (void *)free) {
82603 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
82604 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
82605 + int offset;
82606 +
82607 + if (ptr < base + align)
82608 + break;
82609 +
82610 + offset = ptr - base - align;
82611 + if (offset >= m) {
82612 + base += size;
82613 + continue;
82614 + }
82615 +
82616 + if (n > m - offset)
82617 + break;
82618 +
82619 + spin_unlock_irqrestore(&slob_lock, flags);
82620 + return NULL;
82621 + }
82622 +
82623 + spin_unlock_irqrestore(&slob_lock, flags);
82624 + return "<slob>";
82625 +}
82626 +#endif
82627 +
82628 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
82629 size_t ksize(const void *block)
82630 {
82631 struct page *sp;
82632 int align;
82633 - unsigned int *m;
82634 + slob_t *m;
82635
82636 BUG_ON(!block);
82637 if (unlikely(block == ZERO_SIZE_PTR))
82638 return 0;
82639
82640 sp = virt_to_page(block);
82641 - if (unlikely(!PageSlab(sp)))
82642 - return PAGE_SIZE << compound_order(sp);
82643 + VM_BUG_ON(!PageSlab(sp));
82644 + if (sp->private)
82645 + return sp->private;
82646
82647 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82648 - m = (unsigned int *)(block - align);
82649 - return SLOB_UNITS(*m) * SLOB_UNIT;
82650 + m = (slob_t *)(block - align);
82651 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
82652 }
82653 EXPORT_SYMBOL(ksize);
82654
82655 @@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
82656
82657 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
82658 {
82659 - void *b;
82660 + void *b = NULL;
82661
82662 flags &= gfp_allowed_mask;
82663
82664 lockdep_trace_alloc(flags);
82665
82666 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82667 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
82668 +#else
82669 if (c->size < PAGE_SIZE) {
82670 b = slob_alloc(c->size, flags, c->align, node);
82671 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
82672 SLOB_UNITS(c->size) * SLOB_UNIT,
82673 flags, node);
82674 } else {
82675 - b = slob_new_pages(flags, get_order(c->size), node);
82676 + struct page *sp;
82677 +
82678 + sp = slob_new_pages(flags, get_order(c->size), node);
82679 + if (sp) {
82680 + b = page_address(sp);
82681 + sp->private = c->size;
82682 + }
82683 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
82684 PAGE_SIZE << get_order(c->size),
82685 flags, node);
82686 }
82687 +#endif
82688
82689 if (c->ctor)
82690 c->ctor(b);
82691 @@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
82692
82693 static void __kmem_cache_free(void *b, int size)
82694 {
82695 - if (size < PAGE_SIZE)
82696 + struct page *sp;
82697 +
82698 + sp = virt_to_page(b);
82699 + BUG_ON(!PageSlab(sp));
82700 + if (!sp->private)
82701 slob_free(b, size);
82702 else
82703 - slob_free_pages(b, get_order(size));
82704 + slob_free_pages(sp, get_order(size));
82705 }
82706
82707 static void kmem_rcu_free(struct rcu_head *head)
82708 @@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
82709
82710 void kmem_cache_free(struct kmem_cache *c, void *b)
82711 {
82712 + int size = c->size;
82713 +
82714 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82715 + if (size + c->align < PAGE_SIZE) {
82716 + size += c->align;
82717 + b -= c->align;
82718 + }
82719 +#endif
82720 +
82721 kmemleak_free_recursive(b, c->flags);
82722 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
82723 struct slob_rcu *slob_rcu;
82724 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
82725 - slob_rcu->size = c->size;
82726 + slob_rcu = b + (size - sizeof(struct slob_rcu));
82727 + slob_rcu->size = size;
82728 call_rcu(&slob_rcu->head, kmem_rcu_free);
82729 } else {
82730 - __kmem_cache_free(b, c->size);
82731 + __kmem_cache_free(b, size);
82732 }
82733
82734 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82735 + trace_kfree(_RET_IP_, b);
82736 +#else
82737 trace_kmem_cache_free(_RET_IP_, b);
82738 +#endif
82739 +
82740 }
82741 EXPORT_SYMBOL(kmem_cache_free);
82742
82743 diff --git a/mm/slub.c b/mm/slub.c
82744 index ba2ca53..00b1f4e 100644
82745 --- a/mm/slub.c
82746 +++ b/mm/slub.c
82747 @@ -197,7 +197,7 @@ struct track {
82748
82749 enum track_item { TRACK_ALLOC, TRACK_FREE };
82750
82751 -#ifdef CONFIG_SYSFS
82752 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82753 static int sysfs_slab_add(struct kmem_cache *);
82754 static int sysfs_slab_alias(struct kmem_cache *, const char *);
82755 static void sysfs_slab_remove(struct kmem_cache *);
82756 @@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
82757 if (!t->addr)
82758 return;
82759
82760 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
82761 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
82762 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
82763 #ifdef CONFIG_STACKTRACE
82764 {
82765 @@ -2653,7 +2653,7 @@ static int slub_min_objects;
82766 * Merge control. If this is set then no merging of slab caches will occur.
82767 * (Could be removed. This was introduced to pacify the merge skeptics.)
82768 */
82769 -static int slub_nomerge;
82770 +static int slub_nomerge = 1;
82771
82772 /*
82773 * Calculate the order of allocation given an slab object size.
82774 @@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
82775 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
82776 #endif
82777
82778 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82779 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
82780 +#endif
82781 +
82782 static int __init setup_slub_min_order(char *str)
82783 {
82784 get_option(&str, &slub_min_order);
82785 @@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
82786 return kmalloc_dma_caches[index];
82787
82788 #endif
82789 +
82790 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82791 + if (flags & SLAB_USERCOPY)
82792 + return kmalloc_usercopy_caches[index];
82793 +
82794 +#endif
82795 +
82796 return kmalloc_caches[index];
82797 }
82798
82799 @@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
82800 EXPORT_SYMBOL(__kmalloc_node);
82801 #endif
82802
82803 +bool is_usercopy_object(const void *ptr)
82804 +{
82805 + struct page *page;
82806 + struct kmem_cache *s;
82807 +
82808 + if (ZERO_OR_NULL_PTR(ptr))
82809 + return false;
82810 +
82811 + if (!slab_is_available())
82812 + return false;
82813 +
82814 + if (!virt_addr_valid(ptr))
82815 + return false;
82816 +
82817 + page = virt_to_head_page(ptr);
82818 +
82819 + if (!PageSlab(page))
82820 + return false;
82821 +
82822 + s = page->slab_cache;
82823 + return s->flags & SLAB_USERCOPY;
82824 +}
82825 +
82826 +#ifdef CONFIG_PAX_USERCOPY
82827 +const char *check_heap_object(const void *ptr, unsigned long n)
82828 +{
82829 + struct page *page;
82830 + struct kmem_cache *s;
82831 + unsigned long offset;
82832 +
82833 + if (ZERO_OR_NULL_PTR(ptr))
82834 + return "<null>";
82835 +
82836 + if (!virt_addr_valid(ptr))
82837 + return NULL;
82838 +
82839 + page = virt_to_head_page(ptr);
82840 +
82841 + if (!PageSlab(page))
82842 + return NULL;
82843 +
82844 + s = page->slab_cache;
82845 + if (!(s->flags & SLAB_USERCOPY))
82846 + return s->name;
82847 +
82848 + offset = (ptr - page_address(page)) % s->size;
82849 + if (offset <= s->object_size && n <= s->object_size - offset)
82850 + return NULL;
82851 +
82852 + return s->name;
82853 +}
82854 +#endif
82855 +
82856 size_t ksize(const void *object)
82857 {
82858 struct page *page;
82859 @@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
82860
82861 /* Caches that are not of the two-to-the-power-of size */
82862 if (KMALLOC_MIN_SIZE <= 32) {
82863 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
82864 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
82865 caches++;
82866 }
82867
82868 if (KMALLOC_MIN_SIZE <= 64) {
82869 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
82870 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
82871 caches++;
82872 }
82873
82874 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
82875 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
82876 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
82877 caches++;
82878 }
82879
82880 @@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
82881 }
82882 }
82883 #endif
82884 +
82885 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82886 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
82887 + struct kmem_cache *s = kmalloc_caches[i];
82888 +
82889 + if (s && s->size) {
82890 + char *name = kasprintf(GFP_NOWAIT,
82891 + "usercopy-kmalloc-%d", s->object_size);
82892 +
82893 + BUG_ON(!name);
82894 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
82895 + s->object_size, SLAB_USERCOPY);
82896 + }
82897 + }
82898 +#endif
82899 +
82900 printk(KERN_INFO
82901 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
82902 " CPUs=%d, Nodes=%d\n",
82903 @@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
82904 /*
82905 * We may have set a slab to be unmergeable during bootstrap.
82906 */
82907 - if (s->refcount < 0)
82908 + if (atomic_read(&s->refcount) < 0)
82909 return 1;
82910
82911 return 0;
82912 @@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82913
82914 s = find_mergeable(memcg, size, align, flags, name, ctor);
82915 if (s) {
82916 - s->refcount++;
82917 + atomic_inc(&s->refcount);
82918 /*
82919 * Adjust the object sizes so that we clear
82920 * the complete object on kzalloc.
82921 @@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82922 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
82923
82924 if (sysfs_slab_alias(s, name)) {
82925 - s->refcount--;
82926 + atomic_dec(&s->refcount);
82927 s = NULL;
82928 }
82929 }
82930 @@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
82931 return NOTIFY_OK;
82932 }
82933
82934 -static struct notifier_block __cpuinitdata slab_notifier = {
82935 +static struct notifier_block slab_notifier = {
82936 .notifier_call = slab_cpuup_callback
82937 };
82938
82939 @@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
82940 }
82941 #endif
82942
82943 -#ifdef CONFIG_SYSFS
82944 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82945 static int count_inuse(struct page *page)
82946 {
82947 return page->inuse;
82948 @@ -4364,12 +4444,12 @@ static void resiliency_test(void)
82949 validate_slab_cache(kmalloc_caches[9]);
82950 }
82951 #else
82952 -#ifdef CONFIG_SYSFS
82953 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82954 static void resiliency_test(void) {};
82955 #endif
82956 #endif
82957
82958 -#ifdef CONFIG_SYSFS
82959 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82960 enum slab_stat_type {
82961 SL_ALL, /* All slabs */
82962 SL_PARTIAL, /* Only partially allocated slabs */
82963 @@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
82964
82965 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
82966 {
82967 - return sprintf(buf, "%d\n", s->refcount - 1);
82968 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
82969 }
82970 SLAB_ATTR_RO(aliases);
82971
82972 @@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
82973 return name;
82974 }
82975
82976 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82977 static int sysfs_slab_add(struct kmem_cache *s)
82978 {
82979 int err;
82980 @@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
82981 kobject_del(&s->kobj);
82982 kobject_put(&s->kobj);
82983 }
82984 +#endif
82985
82986 /*
82987 * Need to buffer aliases during bootup until sysfs becomes
82988 @@ -5336,6 +5418,7 @@ struct saved_alias {
82989
82990 static struct saved_alias *alias_list;
82991
82992 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82993 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
82994 {
82995 struct saved_alias *al;
82996 @@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
82997 alias_list = al;
82998 return 0;
82999 }
83000 +#endif
83001
83002 static int __init slab_sysfs_init(void)
83003 {
83004 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
83005 index 1b7e22a..3fcd4f3 100644
83006 --- a/mm/sparse-vmemmap.c
83007 +++ b/mm/sparse-vmemmap.c
83008 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
83009 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83010 if (!p)
83011 return NULL;
83012 - pud_populate(&init_mm, pud, p);
83013 + pud_populate_kernel(&init_mm, pud, p);
83014 }
83015 return pud;
83016 }
83017 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
83018 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83019 if (!p)
83020 return NULL;
83021 - pgd_populate(&init_mm, pgd, p);
83022 + pgd_populate_kernel(&init_mm, pgd, p);
83023 }
83024 return pgd;
83025 }
83026 diff --git a/mm/sparse.c b/mm/sparse.c
83027 index 6b5fb76..db0c190 100644
83028 --- a/mm/sparse.c
83029 +++ b/mm/sparse.c
83030 @@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
83031
83032 for (i = 0; i < PAGES_PER_SECTION; i++) {
83033 if (PageHWPoison(&memmap[i])) {
83034 - atomic_long_sub(1, &mce_bad_pages);
83035 + atomic_long_sub_unchecked(1, &mce_bad_pages);
83036 ClearPageHWPoison(&memmap[i]);
83037 }
83038 }
83039 diff --git a/mm/swap.c b/mm/swap.c
83040 index 6310dc2..3662b3f 100644
83041 --- a/mm/swap.c
83042 +++ b/mm/swap.c
83043 @@ -30,6 +30,7 @@
83044 #include <linux/backing-dev.h>
83045 #include <linux/memcontrol.h>
83046 #include <linux/gfp.h>
83047 +#include <linux/hugetlb.h>
83048
83049 #include "internal.h"
83050
83051 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
83052
83053 __page_cache_release(page);
83054 dtor = get_compound_page_dtor(page);
83055 + if (!PageHuge(page))
83056 + BUG_ON(dtor != free_compound_page);
83057 (*dtor)(page);
83058 }
83059
83060 diff --git a/mm/swapfile.c b/mm/swapfile.c
83061 index e97a0e5..b50e796 100644
83062 --- a/mm/swapfile.c
83063 +++ b/mm/swapfile.c
83064 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
83065
83066 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
83067 /* Activity counter to indicate that a swapon or swapoff has occurred */
83068 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
83069 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
83070
83071 static inline unsigned char swap_count(unsigned char ent)
83072 {
83073 @@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
83074 }
83075 filp_close(swap_file, NULL);
83076 err = 0;
83077 - atomic_inc(&proc_poll_event);
83078 + atomic_inc_unchecked(&proc_poll_event);
83079 wake_up_interruptible(&proc_poll_wait);
83080
83081 out_dput:
83082 @@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
83083
83084 poll_wait(file, &proc_poll_wait, wait);
83085
83086 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
83087 - seq->poll_event = atomic_read(&proc_poll_event);
83088 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
83089 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83090 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
83091 }
83092
83093 @@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
83094 return ret;
83095
83096 seq = file->private_data;
83097 - seq->poll_event = atomic_read(&proc_poll_event);
83098 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83099 return 0;
83100 }
83101
83102 @@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
83103 (frontswap_map) ? "FS" : "");
83104
83105 mutex_unlock(&swapon_mutex);
83106 - atomic_inc(&proc_poll_event);
83107 + atomic_inc_unchecked(&proc_poll_event);
83108 wake_up_interruptible(&proc_poll_wait);
83109
83110 if (S_ISREG(inode->i_mode))
83111 diff --git a/mm/util.c b/mm/util.c
83112 index c55e26b..3f913a9 100644
83113 --- a/mm/util.c
83114 +++ b/mm/util.c
83115 @@ -292,6 +292,12 @@ done:
83116 void arch_pick_mmap_layout(struct mm_struct *mm)
83117 {
83118 mm->mmap_base = TASK_UNMAPPED_BASE;
83119 +
83120 +#ifdef CONFIG_PAX_RANDMMAP
83121 + if (mm->pax_flags & MF_PAX_RANDMMAP)
83122 + mm->mmap_base += mm->delta_mmap;
83123 +#endif
83124 +
83125 mm->get_unmapped_area = arch_get_unmapped_area;
83126 mm->unmap_area = arch_unmap_area;
83127 }
83128 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
83129 index 5123a16..f234a48 100644
83130 --- a/mm/vmalloc.c
83131 +++ b/mm/vmalloc.c
83132 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
83133
83134 pte = pte_offset_kernel(pmd, addr);
83135 do {
83136 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83137 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83138 +
83139 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83140 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
83141 + BUG_ON(!pte_exec(*pte));
83142 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
83143 + continue;
83144 + }
83145 +#endif
83146 +
83147 + {
83148 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83149 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83150 + }
83151 } while (pte++, addr += PAGE_SIZE, addr != end);
83152 }
83153
83154 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
83155 pte = pte_alloc_kernel(pmd, addr);
83156 if (!pte)
83157 return -ENOMEM;
83158 +
83159 + pax_open_kernel();
83160 do {
83161 struct page *page = pages[*nr];
83162
83163 - if (WARN_ON(!pte_none(*pte)))
83164 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83165 + if (pgprot_val(prot) & _PAGE_NX)
83166 +#endif
83167 +
83168 + if (!pte_none(*pte)) {
83169 + pax_close_kernel();
83170 + WARN_ON(1);
83171 return -EBUSY;
83172 - if (WARN_ON(!page))
83173 + }
83174 + if (!page) {
83175 + pax_close_kernel();
83176 + WARN_ON(1);
83177 return -ENOMEM;
83178 + }
83179 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
83180 (*nr)++;
83181 } while (pte++, addr += PAGE_SIZE, addr != end);
83182 + pax_close_kernel();
83183 return 0;
83184 }
83185
83186 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
83187 pmd_t *pmd;
83188 unsigned long next;
83189
83190 - pmd = pmd_alloc(&init_mm, pud, addr);
83191 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
83192 if (!pmd)
83193 return -ENOMEM;
83194 do {
83195 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
83196 pud_t *pud;
83197 unsigned long next;
83198
83199 - pud = pud_alloc(&init_mm, pgd, addr);
83200 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
83201 if (!pud)
83202 return -ENOMEM;
83203 do {
83204 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
83205 * and fall back on vmalloc() if that fails. Others
83206 * just put it in the vmalloc space.
83207 */
83208 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
83209 +#ifdef CONFIG_MODULES
83210 +#ifdef MODULES_VADDR
83211 unsigned long addr = (unsigned long)x;
83212 if (addr >= MODULES_VADDR && addr < MODULES_END)
83213 return 1;
83214 #endif
83215 +
83216 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83217 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
83218 + return 1;
83219 +#endif
83220 +
83221 +#endif
83222 +
83223 return is_vmalloc_addr(x);
83224 }
83225
83226 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
83227
83228 if (!pgd_none(*pgd)) {
83229 pud_t *pud = pud_offset(pgd, addr);
83230 +#ifdef CONFIG_X86
83231 + if (!pud_large(*pud))
83232 +#endif
83233 if (!pud_none(*pud)) {
83234 pmd_t *pmd = pmd_offset(pud, addr);
83235 +#ifdef CONFIG_X86
83236 + if (!pmd_large(*pmd))
83237 +#endif
83238 if (!pmd_none(*pmd)) {
83239 pte_t *ptep, pte;
83240
83241 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
83242 * Allocate a region of KVA of the specified size and alignment, within the
83243 * vstart and vend.
83244 */
83245 -static struct vmap_area *alloc_vmap_area(unsigned long size,
83246 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
83247 unsigned long align,
83248 unsigned long vstart, unsigned long vend,
83249 int node, gfp_t gfp_mask)
83250 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
83251 struct vm_struct *area;
83252
83253 BUG_ON(in_interrupt());
83254 +
83255 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83256 + if (flags & VM_KERNEXEC) {
83257 + if (start != VMALLOC_START || end != VMALLOC_END)
83258 + return NULL;
83259 + start = (unsigned long)MODULES_EXEC_VADDR;
83260 + end = (unsigned long)MODULES_EXEC_END;
83261 + }
83262 +#endif
83263 +
83264 if (flags & VM_IOREMAP) {
83265 int bit = fls(size);
83266
83267 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
83268 if (count > totalram_pages)
83269 return NULL;
83270
83271 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83272 + if (!(pgprot_val(prot) & _PAGE_NX))
83273 + flags |= VM_KERNEXEC;
83274 +#endif
83275 +
83276 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
83277 __builtin_return_address(0));
83278 if (!area)
83279 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
83280 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
83281 goto fail;
83282
83283 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83284 + if (!(pgprot_val(prot) & _PAGE_NX))
83285 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
83286 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
83287 + else
83288 +#endif
83289 +
83290 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
83291 start, end, node, gfp_mask, caller);
83292 if (!area)
83293 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
83294 * For tight control over page level allocator and protection flags
83295 * use __vmalloc() instead.
83296 */
83297 -
83298 void *vmalloc_exec(unsigned long size)
83299 {
83300 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
83301 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
83302 -1, __builtin_return_address(0));
83303 }
83304
83305 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
83306 unsigned long uaddr = vma->vm_start;
83307 unsigned long usize = vma->vm_end - vma->vm_start;
83308
83309 + BUG_ON(vma->vm_mirror);
83310 +
83311 if ((PAGE_SIZE-1) & (unsigned long)addr)
83312 return -EINVAL;
83313
83314 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
83315 v->addr, v->addr + v->size, v->size);
83316
83317 if (v->caller)
83318 +#ifdef CONFIG_GRKERNSEC_HIDESYM
83319 + seq_printf(m, " %pK", v->caller);
83320 +#else
83321 seq_printf(m, " %pS", v->caller);
83322 +#endif
83323
83324 if (v->nr_pages)
83325 seq_printf(m, " pages=%d", v->nr_pages);
83326 diff --git a/mm/vmstat.c b/mm/vmstat.c
83327 index 9800306..76b4b27 100644
83328 --- a/mm/vmstat.c
83329 +++ b/mm/vmstat.c
83330 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
83331 *
83332 * vm_stat contains the global counters
83333 */
83334 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
83335 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
83336 EXPORT_SYMBOL(vm_stat);
83337
83338 #ifdef CONFIG_SMP
83339 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
83340 v = p->vm_stat_diff[i];
83341 p->vm_stat_diff[i] = 0;
83342 local_irq_restore(flags);
83343 - atomic_long_add(v, &zone->vm_stat[i]);
83344 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
83345 global_diff[i] += v;
83346 #ifdef CONFIG_NUMA
83347 /* 3 seconds idle till flush */
83348 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
83349
83350 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
83351 if (global_diff[i])
83352 - atomic_long_add(global_diff[i], &vm_stat[i]);
83353 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
83354 }
83355
83356 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
83357 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
83358 if (pset->vm_stat_diff[i]) {
83359 int v = pset->vm_stat_diff[i];
83360 pset->vm_stat_diff[i] = 0;
83361 - atomic_long_add(v, &zone->vm_stat[i]);
83362 - atomic_long_add(v, &vm_stat[i]);
83363 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
83364 + atomic_long_add_unchecked(v, &vm_stat[i]);
83365 }
83366 }
83367 #endif
83368 @@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
83369 return NOTIFY_OK;
83370 }
83371
83372 -static struct notifier_block __cpuinitdata vmstat_notifier =
83373 +static struct notifier_block vmstat_notifier =
83374 { &vmstat_cpuup_callback, NULL, 0 };
83375 #endif
83376
83377 @@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
83378 start_cpu_timer(cpu);
83379 #endif
83380 #ifdef CONFIG_PROC_FS
83381 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
83382 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
83383 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
83384 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
83385 + {
83386 + mode_t gr_mode = S_IRUGO;
83387 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
83388 + gr_mode = S_IRUSR;
83389 +#endif
83390 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
83391 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
83392 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83393 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
83394 +#else
83395 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
83396 +#endif
83397 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
83398 + }
83399 #endif
83400 return 0;
83401 }
83402 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
83403 index a292e80..785ee68 100644
83404 --- a/net/8021q/vlan.c
83405 +++ b/net/8021q/vlan.c
83406 @@ -485,7 +485,7 @@ out:
83407 return NOTIFY_DONE;
83408 }
83409
83410 -static struct notifier_block vlan_notifier_block __read_mostly = {
83411 +static struct notifier_block vlan_notifier_block = {
83412 .notifier_call = vlan_device_event,
83413 };
83414
83415 @@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
83416 err = -EPERM;
83417 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
83418 break;
83419 - if ((args.u.name_type >= 0) &&
83420 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
83421 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
83422 struct vlan_net *vn;
83423
83424 vn = net_generic(net, vlan_net_id);
83425 diff --git a/net/9p/mod.c b/net/9p/mod.c
83426 index 6ab36ae..6f1841b 100644
83427 --- a/net/9p/mod.c
83428 +++ b/net/9p/mod.c
83429 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
83430 void v9fs_register_trans(struct p9_trans_module *m)
83431 {
83432 spin_lock(&v9fs_trans_lock);
83433 - list_add_tail(&m->list, &v9fs_trans_list);
83434 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
83435 spin_unlock(&v9fs_trans_lock);
83436 }
83437 EXPORT_SYMBOL(v9fs_register_trans);
83438 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
83439 void v9fs_unregister_trans(struct p9_trans_module *m)
83440 {
83441 spin_lock(&v9fs_trans_lock);
83442 - list_del_init(&m->list);
83443 + pax_list_del_init((struct list_head *)&m->list);
83444 spin_unlock(&v9fs_trans_lock);
83445 }
83446 EXPORT_SYMBOL(v9fs_unregister_trans);
83447 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
83448 index 02efb25..41541a9 100644
83449 --- a/net/9p/trans_fd.c
83450 +++ b/net/9p/trans_fd.c
83451 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
83452 oldfs = get_fs();
83453 set_fs(get_ds());
83454 /* The cast to a user pointer is valid due to the set_fs() */
83455 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
83456 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
83457 set_fs(oldfs);
83458
83459 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
83460 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
83461 index 876fbe8..8bbea9f 100644
83462 --- a/net/atm/atm_misc.c
83463 +++ b/net/atm/atm_misc.c
83464 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
83465 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
83466 return 1;
83467 atm_return(vcc, truesize);
83468 - atomic_inc(&vcc->stats->rx_drop);
83469 + atomic_inc_unchecked(&vcc->stats->rx_drop);
83470 return 0;
83471 }
83472 EXPORT_SYMBOL(atm_charge);
83473 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
83474 }
83475 }
83476 atm_return(vcc, guess);
83477 - atomic_inc(&vcc->stats->rx_drop);
83478 + atomic_inc_unchecked(&vcc->stats->rx_drop);
83479 return NULL;
83480 }
83481 EXPORT_SYMBOL(atm_alloc_charge);
83482 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
83483
83484 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
83485 {
83486 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
83487 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
83488 __SONET_ITEMS
83489 #undef __HANDLE_ITEM
83490 }
83491 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
83492
83493 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
83494 {
83495 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
83496 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
83497 __SONET_ITEMS
83498 #undef __HANDLE_ITEM
83499 }
83500 diff --git a/net/atm/lec.h b/net/atm/lec.h
83501 index a86aff9..3a0d6f6 100644
83502 --- a/net/atm/lec.h
83503 +++ b/net/atm/lec.h
83504 @@ -48,7 +48,7 @@ struct lane2_ops {
83505 const u8 *tlvs, u32 sizeoftlvs);
83506 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
83507 const u8 *tlvs, u32 sizeoftlvs);
83508 -};
83509 +} __no_const;
83510
83511 /*
83512 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
83513 diff --git a/net/atm/proc.c b/net/atm/proc.c
83514 index 0d020de..011c7bb 100644
83515 --- a/net/atm/proc.c
83516 +++ b/net/atm/proc.c
83517 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
83518 const struct k_atm_aal_stats *stats)
83519 {
83520 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
83521 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
83522 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
83523 - atomic_read(&stats->rx_drop));
83524 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
83525 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
83526 + atomic_read_unchecked(&stats->rx_drop));
83527 }
83528
83529 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
83530 diff --git a/net/atm/resources.c b/net/atm/resources.c
83531 index 0447d5d..3cf4728 100644
83532 --- a/net/atm/resources.c
83533 +++ b/net/atm/resources.c
83534 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
83535 static void copy_aal_stats(struct k_atm_aal_stats *from,
83536 struct atm_aal_stats *to)
83537 {
83538 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
83539 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
83540 __AAL_STAT_ITEMS
83541 #undef __HANDLE_ITEM
83542 }
83543 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
83544 static void subtract_aal_stats(struct k_atm_aal_stats *from,
83545 struct atm_aal_stats *to)
83546 {
83547 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
83548 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
83549 __AAL_STAT_ITEMS
83550 #undef __HANDLE_ITEM
83551 }
83552 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
83553 index d5744b7..506bae3 100644
83554 --- a/net/ax25/sysctl_net_ax25.c
83555 +++ b/net/ax25/sysctl_net_ax25.c
83556 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
83557 {
83558 char path[sizeof("net/ax25/") + IFNAMSIZ];
83559 int k;
83560 - struct ctl_table *table;
83561 + ctl_table_no_const *table;
83562
83563 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
83564 if (!table)
83565 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
83566 index 7d02ebd..4d4cc01 100644
83567 --- a/net/batman-adv/bat_iv_ogm.c
83568 +++ b/net/batman-adv/bat_iv_ogm.c
83569 @@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
83570
83571 /* randomize initial seqno to avoid collision */
83572 get_random_bytes(&random_seqno, sizeof(random_seqno));
83573 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
83574 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
83575
83576 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
83577 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
83578 @@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
83579 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
83580
83581 /* change sequence number to network order */
83582 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
83583 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
83584 batadv_ogm_packet->seqno = htonl(seqno);
83585 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
83586 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
83587
83588 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
83589 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
83590 @@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
83591 return;
83592
83593 /* could be changed by schedule_own_packet() */
83594 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
83595 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
83596
83597 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
83598 has_directlink_flag = 1;
83599 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
83600 index f1d37cd..4190879 100644
83601 --- a/net/batman-adv/hard-interface.c
83602 +++ b/net/batman-adv/hard-interface.c
83603 @@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
83604 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
83605 dev_add_pack(&hard_iface->batman_adv_ptype);
83606
83607 - atomic_set(&hard_iface->frag_seqno, 1);
83608 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
83609 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
83610 hard_iface->net_dev->name);
83611
83612 @@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
83613 /* This can't be called via a bat_priv callback because
83614 * we have no bat_priv yet.
83615 */
83616 - atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
83617 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
83618 hard_iface->bat_iv.ogm_buff = NULL;
83619
83620 return hard_iface;
83621 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
83622 index 6b548fd..fc32c8d 100644
83623 --- a/net/batman-adv/soft-interface.c
83624 +++ b/net/batman-adv/soft-interface.c
83625 @@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
83626 primary_if->net_dev->dev_addr, ETH_ALEN);
83627
83628 /* set broadcast sequence number */
83629 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
83630 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
83631 bcast_packet->seqno = htonl(seqno);
83632
83633 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
83634 @@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
83635 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
83636
83637 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
83638 - atomic_set(&bat_priv->bcast_seqno, 1);
83639 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
83640 atomic_set(&bat_priv->tt.vn, 0);
83641 atomic_set(&bat_priv->tt.local_changes, 0);
83642 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
83643 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
83644 index ae9ac9a..11e0fe7 100644
83645 --- a/net/batman-adv/types.h
83646 +++ b/net/batman-adv/types.h
83647 @@ -48,7 +48,7 @@
83648 struct batadv_hard_iface_bat_iv {
83649 unsigned char *ogm_buff;
83650 int ogm_buff_len;
83651 - atomic_t ogm_seqno;
83652 + atomic_unchecked_t ogm_seqno;
83653 };
83654
83655 struct batadv_hard_iface {
83656 @@ -56,7 +56,7 @@ struct batadv_hard_iface {
83657 int16_t if_num;
83658 char if_status;
83659 struct net_device *net_dev;
83660 - atomic_t frag_seqno;
83661 + atomic_unchecked_t frag_seqno;
83662 struct kobject *hardif_obj;
83663 atomic_t refcount;
83664 struct packet_type batman_adv_ptype;
83665 @@ -284,7 +284,7 @@ struct batadv_priv {
83666 atomic_t orig_interval; /* uint */
83667 atomic_t hop_penalty; /* uint */
83668 atomic_t log_level; /* uint */
83669 - atomic_t bcast_seqno;
83670 + atomic_unchecked_t bcast_seqno;
83671 atomic_t bcast_queue_left;
83672 atomic_t batman_queue_left;
83673 char num_ifaces;
83674 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
83675 index 10aff49..ea8e021 100644
83676 --- a/net/batman-adv/unicast.c
83677 +++ b/net/batman-adv/unicast.c
83678 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
83679 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
83680 frag2->flags = large_tail;
83681
83682 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
83683 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
83684 frag1->seqno = htons(seqno - 1);
83685 frag2->seqno = htons(seqno);
83686
83687 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
83688 index 07f0739..3c42e34 100644
83689 --- a/net/bluetooth/hci_sock.c
83690 +++ b/net/bluetooth/hci_sock.c
83691 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
83692 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
83693 }
83694
83695 - len = min_t(unsigned int, len, sizeof(uf));
83696 + len = min((size_t)len, sizeof(uf));
83697 if (copy_from_user(&uf, optval, len)) {
83698 err = -EFAULT;
83699 break;
83700 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
83701 index 22e6583..426e2f3 100644
83702 --- a/net/bluetooth/l2cap_core.c
83703 +++ b/net/bluetooth/l2cap_core.c
83704 @@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
83705 break;
83706
83707 case L2CAP_CONF_RFC:
83708 - if (olen == sizeof(rfc))
83709 - memcpy(&rfc, (void *)val, olen);
83710 + if (olen != sizeof(rfc))
83711 + break;
83712 +
83713 + memcpy(&rfc, (void *)val, olen);
83714
83715 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
83716 rfc.mode != chan->mode)
83717 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
83718 index 1bcfb84..dad9f98 100644
83719 --- a/net/bluetooth/l2cap_sock.c
83720 +++ b/net/bluetooth/l2cap_sock.c
83721 @@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
83722 struct sock *sk = sock->sk;
83723 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
83724 struct l2cap_options opts;
83725 - int len, err = 0;
83726 + int err = 0;
83727 + size_t len = optlen;
83728 u32 opt;
83729
83730 BT_DBG("sk %p", sk);
83731 @@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
83732 opts.max_tx = chan->max_tx;
83733 opts.txwin_size = chan->tx_win;
83734
83735 - len = min_t(unsigned int, sizeof(opts), optlen);
83736 + len = min(sizeof(opts), len);
83737 if (copy_from_user((char *) &opts, optval, len)) {
83738 err = -EFAULT;
83739 break;
83740 @@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83741 struct bt_security sec;
83742 struct bt_power pwr;
83743 struct l2cap_conn *conn;
83744 - int len, err = 0;
83745 + int err = 0;
83746 + size_t len = optlen;
83747 u32 opt;
83748
83749 BT_DBG("sk %p", sk);
83750 @@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83751
83752 sec.level = BT_SECURITY_LOW;
83753
83754 - len = min_t(unsigned int, sizeof(sec), optlen);
83755 + len = min(sizeof(sec), len);
83756 if (copy_from_user((char *) &sec, optval, len)) {
83757 err = -EFAULT;
83758 break;
83759 @@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83760
83761 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
83762
83763 - len = min_t(unsigned int, sizeof(pwr), optlen);
83764 + len = min(sizeof(pwr), len);
83765 if (copy_from_user((char *) &pwr, optval, len)) {
83766 err = -EFAULT;
83767 break;
83768 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
83769 index ce3f665..2c7d08f 100644
83770 --- a/net/bluetooth/rfcomm/sock.c
83771 +++ b/net/bluetooth/rfcomm/sock.c
83772 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
83773 struct sock *sk = sock->sk;
83774 struct bt_security sec;
83775 int err = 0;
83776 - size_t len;
83777 + size_t len = optlen;
83778 u32 opt;
83779
83780 BT_DBG("sk %p", sk);
83781 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
83782
83783 sec.level = BT_SECURITY_LOW;
83784
83785 - len = min_t(unsigned int, sizeof(sec), optlen);
83786 + len = min(sizeof(sec), len);
83787 if (copy_from_user((char *) &sec, optval, len)) {
83788 err = -EFAULT;
83789 break;
83790 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
83791 index bd6fd0f..6492cba 100644
83792 --- a/net/bluetooth/rfcomm/tty.c
83793 +++ b/net/bluetooth/rfcomm/tty.c
83794 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
83795 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
83796
83797 spin_lock_irqsave(&dev->port.lock, flags);
83798 - if (dev->port.count > 0) {
83799 + if (atomic_read(&dev->port.count) > 0) {
83800 spin_unlock_irqrestore(&dev->port.lock, flags);
83801 return;
83802 }
83803 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
83804 return -ENODEV;
83805
83806 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
83807 - dev->channel, dev->port.count);
83808 + dev->channel, atomic_read(&dev->port.count));
83809
83810 spin_lock_irqsave(&dev->port.lock, flags);
83811 - if (++dev->port.count > 1) {
83812 + if (atomic_inc_return(&dev->port.count) > 1) {
83813 spin_unlock_irqrestore(&dev->port.lock, flags);
83814 return 0;
83815 }
83816 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
83817 return;
83818
83819 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
83820 - dev->port.count);
83821 + atomic_read(&dev->port.count));
83822
83823 spin_lock_irqsave(&dev->port.lock, flags);
83824 - if (!--dev->port.count) {
83825 + if (!atomic_dec_return(&dev->port.count)) {
83826 spin_unlock_irqrestore(&dev->port.lock, flags);
83827 if (dev->tty_dev->parent)
83828 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
83829 diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
83830 index acc9f4c..2897e40 100644
83831 --- a/net/bridge/br_mdb.c
83832 +++ b/net/bridge/br_mdb.c
83833 @@ -82,6 +82,7 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
83834 port = p->port;
83835 if (port) {
83836 struct br_mdb_entry e;
83837 + memset(&e, 0, sizeof(e));
83838 e.ifindex = port->dev->ifindex;
83839 e.state = p->state;
83840 if (p->addr.proto == htons(ETH_P_IP))
83841 @@ -138,6 +139,7 @@ static int br_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
83842 break;
83843
83844 bpm = nlmsg_data(nlh);
83845 + memset(bpm, 0, sizeof(*bpm));
83846 bpm->ifindex = dev->ifindex;
83847 if (br_mdb_fill_info(skb, cb, dev) < 0)
83848 goto out;
83849 @@ -173,6 +175,7 @@ static int nlmsg_populate_mdb_fill(struct sk_buff *skb,
83850 return -EMSGSIZE;
83851
83852 bpm = nlmsg_data(nlh);
83853 + memset(bpm, 0, sizeof(*bpm));
83854 bpm->family = AF_BRIDGE;
83855 bpm->ifindex = dev->ifindex;
83856 nest = nla_nest_start(skb, MDBA_MDB);
83857 @@ -230,6 +233,7 @@ void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
83858 {
83859 struct br_mdb_entry entry;
83860
83861 + memset(&entry, 0, sizeof(entry));
83862 entry.ifindex = port->dev->ifindex;
83863 entry.addr.proto = group->proto;
83864 entry.addr.u.ip4 = group->u.ip4;
83865 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
83866 index 5fe2ff3..121d696 100644
83867 --- a/net/bridge/netfilter/ebtables.c
83868 +++ b/net/bridge/netfilter/ebtables.c
83869 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
83870 tmp.valid_hooks = t->table->valid_hooks;
83871 }
83872 mutex_unlock(&ebt_mutex);
83873 - if (copy_to_user(user, &tmp, *len) != 0){
83874 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
83875 BUGPRINT("c2u Didn't work\n");
83876 ret = -EFAULT;
83877 break;
83878 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
83879 goto out;
83880 tmp.valid_hooks = t->valid_hooks;
83881
83882 - if (copy_to_user(user, &tmp, *len) != 0) {
83883 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
83884 ret = -EFAULT;
83885 break;
83886 }
83887 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
83888 tmp.entries_size = t->table->entries_size;
83889 tmp.valid_hooks = t->table->valid_hooks;
83890
83891 - if (copy_to_user(user, &tmp, *len) != 0) {
83892 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
83893 ret = -EFAULT;
83894 break;
83895 }
83896 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
83897 index a376ec1..1fbd6be 100644
83898 --- a/net/caif/cfctrl.c
83899 +++ b/net/caif/cfctrl.c
83900 @@ -10,6 +10,7 @@
83901 #include <linux/spinlock.h>
83902 #include <linux/slab.h>
83903 #include <linux/pkt_sched.h>
83904 +#include <linux/sched.h>
83905 #include <net/caif/caif_layer.h>
83906 #include <net/caif/cfpkt.h>
83907 #include <net/caif/cfctrl.h>
83908 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
83909 memset(&dev_info, 0, sizeof(dev_info));
83910 dev_info.id = 0xff;
83911 cfsrvl_init(&this->serv, 0, &dev_info, false);
83912 - atomic_set(&this->req_seq_no, 1);
83913 - atomic_set(&this->rsp_seq_no, 1);
83914 + atomic_set_unchecked(&this->req_seq_no, 1);
83915 + atomic_set_unchecked(&this->rsp_seq_no, 1);
83916 this->serv.layer.receive = cfctrl_recv;
83917 sprintf(this->serv.layer.name, "ctrl");
83918 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
83919 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
83920 struct cfctrl_request_info *req)
83921 {
83922 spin_lock_bh(&ctrl->info_list_lock);
83923 - atomic_inc(&ctrl->req_seq_no);
83924 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
83925 + atomic_inc_unchecked(&ctrl->req_seq_no);
83926 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
83927 list_add_tail(&req->list, &ctrl->list);
83928 spin_unlock_bh(&ctrl->info_list_lock);
83929 }
83930 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
83931 if (p != first)
83932 pr_warn("Requests are not received in order\n");
83933
83934 - atomic_set(&ctrl->rsp_seq_no,
83935 + atomic_set_unchecked(&ctrl->rsp_seq_no,
83936 p->sequence_no);
83937 list_del(&p->list);
83938 goto out;
83939 diff --git a/net/can/af_can.c b/net/can/af_can.c
83940 index ddac1ee..3ee0a78 100644
83941 --- a/net/can/af_can.c
83942 +++ b/net/can/af_can.c
83943 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
83944 };
83945
83946 /* notifier block for netdevice event */
83947 -static struct notifier_block can_netdev_notifier __read_mostly = {
83948 +static struct notifier_block can_netdev_notifier = {
83949 .notifier_call = can_notifier,
83950 };
83951
83952 diff --git a/net/can/gw.c b/net/can/gw.c
83953 index 574dda78e..3d2b3da 100644
83954 --- a/net/can/gw.c
83955 +++ b/net/can/gw.c
83956 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
83957 MODULE_ALIAS("can-gw");
83958
83959 static HLIST_HEAD(cgw_list);
83960 -static struct notifier_block notifier;
83961
83962 static struct kmem_cache *cgw_cache __read_mostly;
83963
83964 @@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
83965 return err;
83966 }
83967
83968 +static struct notifier_block notifier = {
83969 + .notifier_call = cgw_notifier
83970 +};
83971 +
83972 static __init int cgw_module_init(void)
83973 {
83974 printk(banner);
83975 @@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
83976 return -ENOMEM;
83977
83978 /* set notifier */
83979 - notifier.notifier_call = cgw_notifier;
83980 register_netdevice_notifier(&notifier);
83981
83982 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
83983 diff --git a/net/compat.c b/net/compat.c
83984 index 79ae884..17c5c09 100644
83985 --- a/net/compat.c
83986 +++ b/net/compat.c
83987 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
83988 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
83989 __get_user(kmsg->msg_flags, &umsg->msg_flags))
83990 return -EFAULT;
83991 - kmsg->msg_name = compat_ptr(tmp1);
83992 - kmsg->msg_iov = compat_ptr(tmp2);
83993 - kmsg->msg_control = compat_ptr(tmp3);
83994 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
83995 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
83996 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
83997 return 0;
83998 }
83999
84000 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84001
84002 if (kern_msg->msg_namelen) {
84003 if (mode == VERIFY_READ) {
84004 - int err = move_addr_to_kernel(kern_msg->msg_name,
84005 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
84006 kern_msg->msg_namelen,
84007 kern_address);
84008 if (err < 0)
84009 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84010 kern_msg->msg_name = NULL;
84011
84012 tot_len = iov_from_user_compat_to_kern(kern_iov,
84013 - (struct compat_iovec __user *)kern_msg->msg_iov,
84014 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
84015 kern_msg->msg_iovlen);
84016 if (tot_len >= 0)
84017 kern_msg->msg_iov = kern_iov;
84018 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84019
84020 #define CMSG_COMPAT_FIRSTHDR(msg) \
84021 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
84022 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
84023 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
84024 (struct compat_cmsghdr __user *)NULL)
84025
84026 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
84027 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
84028 (ucmlen) <= (unsigned long) \
84029 ((mhdr)->msg_controllen - \
84030 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
84031 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
84032
84033 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
84034 struct compat_cmsghdr __user *cmsg, int cmsg_len)
84035 {
84036 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
84037 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
84038 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
84039 msg->msg_controllen)
84040 return NULL;
84041 return (struct compat_cmsghdr __user *)ptr;
84042 @@ -219,7 +219,7 @@ Efault:
84043
84044 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
84045 {
84046 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84047 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84048 struct compat_cmsghdr cmhdr;
84049 struct compat_timeval ctv;
84050 struct compat_timespec cts[3];
84051 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
84052
84053 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
84054 {
84055 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84056 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84057 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
84058 int fdnum = scm->fp->count;
84059 struct file **fp = scm->fp->fp;
84060 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
84061 return -EFAULT;
84062 old_fs = get_fs();
84063 set_fs(KERNEL_DS);
84064 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
84065 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
84066 set_fs(old_fs);
84067
84068 return err;
84069 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
84070 len = sizeof(ktime);
84071 old_fs = get_fs();
84072 set_fs(KERNEL_DS);
84073 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
84074 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
84075 set_fs(old_fs);
84076
84077 if (!err) {
84078 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84079 case MCAST_JOIN_GROUP:
84080 case MCAST_LEAVE_GROUP:
84081 {
84082 - struct compat_group_req __user *gr32 = (void *)optval;
84083 + struct compat_group_req __user *gr32 = (void __user *)optval;
84084 struct group_req __user *kgr =
84085 compat_alloc_user_space(sizeof(struct group_req));
84086 u32 interface;
84087 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84088 case MCAST_BLOCK_SOURCE:
84089 case MCAST_UNBLOCK_SOURCE:
84090 {
84091 - struct compat_group_source_req __user *gsr32 = (void *)optval;
84092 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
84093 struct group_source_req __user *kgsr = compat_alloc_user_space(
84094 sizeof(struct group_source_req));
84095 u32 interface;
84096 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84097 }
84098 case MCAST_MSFILTER:
84099 {
84100 - struct compat_group_filter __user *gf32 = (void *)optval;
84101 + struct compat_group_filter __user *gf32 = (void __user *)optval;
84102 struct group_filter __user *kgf;
84103 u32 interface, fmode, numsrc;
84104
84105 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
84106 char __user *optval, int __user *optlen,
84107 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
84108 {
84109 - struct compat_group_filter __user *gf32 = (void *)optval;
84110 + struct compat_group_filter __user *gf32 = (void __user *)optval;
84111 struct group_filter __user *kgf;
84112 int __user *koptlen;
84113 u32 interface, fmode, numsrc;
84114 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
84115
84116 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
84117 return -EINVAL;
84118 - if (copy_from_user(a, args, nas[call]))
84119 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
84120 return -EFAULT;
84121 a0 = a[0];
84122 a1 = a[1];
84123 diff --git a/net/core/datagram.c b/net/core/datagram.c
84124 index 368f9c3..f82d4a3 100644
84125 --- a/net/core/datagram.c
84126 +++ b/net/core/datagram.c
84127 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
84128 }
84129
84130 kfree_skb(skb);
84131 - atomic_inc(&sk->sk_drops);
84132 + atomic_inc_unchecked(&sk->sk_drops);
84133 sk_mem_reclaim_partial(sk);
84134
84135 return err;
84136 diff --git a/net/core/dev.c b/net/core/dev.c
84137 index f64e439..8f959e6 100644
84138 --- a/net/core/dev.c
84139 +++ b/net/core/dev.c
84140 @@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
84141 if (no_module && capable(CAP_NET_ADMIN))
84142 no_module = request_module("netdev-%s", name);
84143 if (no_module && capable(CAP_SYS_MODULE)) {
84144 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
84145 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
84146 +#else
84147 if (!request_module("%s", name))
84148 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
84149 name);
84150 +#endif
84151 }
84152 }
84153 EXPORT_SYMBOL(dev_load);
84154 @@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84155 {
84156 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
84157 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
84158 - atomic_long_inc(&dev->rx_dropped);
84159 + atomic_long_inc_unchecked(&dev->rx_dropped);
84160 kfree_skb(skb);
84161 return NET_RX_DROP;
84162 }
84163 @@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84164 nf_reset(skb);
84165
84166 if (unlikely(!is_skb_forwardable(dev, skb))) {
84167 - atomic_long_inc(&dev->rx_dropped);
84168 + atomic_long_inc_unchecked(&dev->rx_dropped);
84169 kfree_skb(skb);
84170 return NET_RX_DROP;
84171 }
84172 @@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
84173
84174 struct dev_gso_cb {
84175 void (*destructor)(struct sk_buff *skb);
84176 -};
84177 +} __no_const;
84178
84179 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
84180
84181 @@ -3053,7 +3057,7 @@ enqueue:
84182
84183 local_irq_restore(flags);
84184
84185 - atomic_long_inc(&skb->dev->rx_dropped);
84186 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84187 kfree_skb(skb);
84188 return NET_RX_DROP;
84189 }
84190 @@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
84191 }
84192 EXPORT_SYMBOL(netif_rx_ni);
84193
84194 -static void net_tx_action(struct softirq_action *h)
84195 +static void net_tx_action(void)
84196 {
84197 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84198
84199 @@ -3456,7 +3460,7 @@ ncls:
84200 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
84201 } else {
84202 drop:
84203 - atomic_long_inc(&skb->dev->rx_dropped);
84204 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84205 kfree_skb(skb);
84206 /* Jamal, now you will not able to escape explaining
84207 * me how you were going to use this. :-)
84208 @@ -4039,7 +4043,7 @@ void netif_napi_del(struct napi_struct *napi)
84209 }
84210 EXPORT_SYMBOL(netif_napi_del);
84211
84212 -static void net_rx_action(struct softirq_action *h)
84213 +static void net_rx_action(void)
84214 {
84215 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84216 unsigned long time_limit = jiffies + 2;
84217 @@ -4523,8 +4527,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
84218 else
84219 seq_printf(seq, "%04x", ntohs(pt->type));
84220
84221 +#ifdef CONFIG_GRKERNSEC_HIDESYM
84222 + seq_printf(seq, " %-8s %p\n",
84223 + pt->dev ? pt->dev->name : "", NULL);
84224 +#else
84225 seq_printf(seq, " %-8s %pF\n",
84226 pt->dev ? pt->dev->name : "", pt->func);
84227 +#endif
84228 }
84229
84230 return 0;
84231 @@ -6096,7 +6105,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
84232 } else {
84233 netdev_stats_to_stats64(storage, &dev->stats);
84234 }
84235 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
84236 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
84237 return storage;
84238 }
84239 EXPORT_SYMBOL(dev_get_stats);
84240 diff --git a/net/core/flow.c b/net/core/flow.c
84241 index b0901ee..7d3c2ca 100644
84242 --- a/net/core/flow.c
84243 +++ b/net/core/flow.c
84244 @@ -61,7 +61,7 @@ struct flow_cache {
84245 struct timer_list rnd_timer;
84246 };
84247
84248 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
84249 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
84250 EXPORT_SYMBOL(flow_cache_genid);
84251 static struct flow_cache flow_cache_global;
84252 static struct kmem_cache *flow_cachep __read_mostly;
84253 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
84254
84255 static int flow_entry_valid(struct flow_cache_entry *fle)
84256 {
84257 - if (atomic_read(&flow_cache_genid) != fle->genid)
84258 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
84259 return 0;
84260 if (fle->object && !fle->object->ops->check(fle->object))
84261 return 0;
84262 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
84263 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
84264 fcp->hash_count++;
84265 }
84266 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
84267 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
84268 flo = fle->object;
84269 if (!flo)
84270 goto ret_object;
84271 @@ -280,7 +280,7 @@ nocache:
84272 }
84273 flo = resolver(net, key, family, dir, flo, ctx);
84274 if (fle) {
84275 - fle->genid = atomic_read(&flow_cache_genid);
84276 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
84277 if (!IS_ERR(flo))
84278 fle->object = flo;
84279 else
84280 diff --git a/net/core/iovec.c b/net/core/iovec.c
84281 index 7e7aeb0..2a998cb 100644
84282 --- a/net/core/iovec.c
84283 +++ b/net/core/iovec.c
84284 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
84285 if (m->msg_namelen) {
84286 if (mode == VERIFY_READ) {
84287 void __user *namep;
84288 - namep = (void __user __force *) m->msg_name;
84289 + namep = (void __force_user *) m->msg_name;
84290 err = move_addr_to_kernel(namep, m->msg_namelen,
84291 address);
84292 if (err < 0)
84293 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
84294 }
84295
84296 size = m->msg_iovlen * sizeof(struct iovec);
84297 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
84298 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
84299 return -EFAULT;
84300
84301 m->msg_iov = iov;
84302 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
84303 index c815f28..e6403f2 100644
84304 --- a/net/core/neighbour.c
84305 +++ b/net/core/neighbour.c
84306 @@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
84307 size_t *lenp, loff_t *ppos)
84308 {
84309 int size, ret;
84310 - ctl_table tmp = *ctl;
84311 + ctl_table_no_const tmp = *ctl;
84312
84313 tmp.extra1 = &zero;
84314 tmp.extra2 = &unres_qlen_max;
84315 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
84316 index 28c5f5a..7edf2e2 100644
84317 --- a/net/core/net-sysfs.c
84318 +++ b/net/core/net-sysfs.c
84319 @@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
84320 }
84321 EXPORT_SYMBOL(netdev_class_remove_file);
84322
84323 -int netdev_kobject_init(void)
84324 +int __init netdev_kobject_init(void)
84325 {
84326 kobj_ns_type_register(&net_ns_type_operations);
84327 return class_register(&net_class);
84328 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
84329 index 8acce01..2e306bb 100644
84330 --- a/net/core/net_namespace.c
84331 +++ b/net/core/net_namespace.c
84332 @@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
84333 int error;
84334 LIST_HEAD(net_exit_list);
84335
84336 - list_add_tail(&ops->list, list);
84337 + pax_list_add_tail((struct list_head *)&ops->list, list);
84338 if (ops->init || (ops->id && ops->size)) {
84339 for_each_net(net) {
84340 error = ops_init(ops, net);
84341 @@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
84342
84343 out_undo:
84344 /* If I have an error cleanup all namespaces I initialized */
84345 - list_del(&ops->list);
84346 + pax_list_del((struct list_head *)&ops->list);
84347 ops_exit_list(ops, &net_exit_list);
84348 ops_free_list(ops, &net_exit_list);
84349 return error;
84350 @@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
84351 struct net *net;
84352 LIST_HEAD(net_exit_list);
84353
84354 - list_del(&ops->list);
84355 + pax_list_del((struct list_head *)&ops->list);
84356 for_each_net(net)
84357 list_add_tail(&net->exit_list, &net_exit_list);
84358 ops_exit_list(ops, &net_exit_list);
84359 @@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
84360 mutex_lock(&net_mutex);
84361 error = register_pernet_operations(&pernet_list, ops);
84362 if (!error && (first_device == &pernet_list))
84363 - first_device = &ops->list;
84364 + first_device = (struct list_head *)&ops->list;
84365 mutex_unlock(&net_mutex);
84366 return error;
84367 }
84368 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
84369 index 1868625..e2261f5 100644
84370 --- a/net/core/rtnetlink.c
84371 +++ b/net/core/rtnetlink.c
84372 @@ -58,7 +58,7 @@ struct rtnl_link {
84373 rtnl_doit_func doit;
84374 rtnl_dumpit_func dumpit;
84375 rtnl_calcit_func calcit;
84376 -};
84377 +} __no_const;
84378
84379 static DEFINE_MUTEX(rtnl_mutex);
84380
84381 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
84382 if (rtnl_link_ops_get(ops->kind))
84383 return -EEXIST;
84384
84385 - if (!ops->dellink)
84386 - ops->dellink = unregister_netdevice_queue;
84387 + if (!ops->dellink) {
84388 + pax_open_kernel();
84389 + *(void **)&ops->dellink = unregister_netdevice_queue;
84390 + pax_close_kernel();
84391 + }
84392
84393 - list_add_tail(&ops->list, &link_ops);
84394 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
84395 return 0;
84396 }
84397 EXPORT_SYMBOL_GPL(__rtnl_link_register);
84398 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
84399 for_each_net(net) {
84400 __rtnl_kill_links(net, ops);
84401 }
84402 - list_del(&ops->list);
84403 + pax_list_del((struct list_head *)&ops->list);
84404 }
84405 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
84406
84407 @@ -976,6 +979,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
84408 * report anything.
84409 */
84410 ivi.spoofchk = -1;
84411 + memset(ivi.mac, 0, sizeof(ivi.mac));
84412 if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi))
84413 break;
84414 vf_mac.vf =
84415 diff --git a/net/core/scm.c b/net/core/scm.c
84416 index 905dcc6..14ee2d6 100644
84417 --- a/net/core/scm.c
84418 +++ b/net/core/scm.c
84419 @@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
84420 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
84421 {
84422 struct cmsghdr __user *cm
84423 - = (__force struct cmsghdr __user *)msg->msg_control;
84424 + = (struct cmsghdr __force_user *)msg->msg_control;
84425 struct cmsghdr cmhdr;
84426 int cmlen = CMSG_LEN(len);
84427 int err;
84428 @@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
84429 err = -EFAULT;
84430 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
84431 goto out;
84432 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
84433 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
84434 goto out;
84435 cmlen = CMSG_SPACE(len);
84436 if (msg->msg_controllen < cmlen)
84437 @@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
84438 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
84439 {
84440 struct cmsghdr __user *cm
84441 - = (__force struct cmsghdr __user*)msg->msg_control;
84442 + = (struct cmsghdr __force_user *)msg->msg_control;
84443
84444 int fdmax = 0;
84445 int fdnum = scm->fp->count;
84446 @@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
84447 if (fdnum < fdmax)
84448 fdmax = fdnum;
84449
84450 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
84451 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
84452 i++, cmfptr++)
84453 {
84454 struct socket *sock;
84455 diff --git a/net/core/sock.c b/net/core/sock.c
84456 index bc131d4..029e378 100644
84457 --- a/net/core/sock.c
84458 +++ b/net/core/sock.c
84459 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84460 struct sk_buff_head *list = &sk->sk_receive_queue;
84461
84462 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
84463 - atomic_inc(&sk->sk_drops);
84464 + atomic_inc_unchecked(&sk->sk_drops);
84465 trace_sock_rcvqueue_full(sk, skb);
84466 return -ENOMEM;
84467 }
84468 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84469 return err;
84470
84471 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
84472 - atomic_inc(&sk->sk_drops);
84473 + atomic_inc_unchecked(&sk->sk_drops);
84474 return -ENOBUFS;
84475 }
84476
84477 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84478 skb_dst_force(skb);
84479
84480 spin_lock_irqsave(&list->lock, flags);
84481 - skb->dropcount = atomic_read(&sk->sk_drops);
84482 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
84483 __skb_queue_tail(list, skb);
84484 spin_unlock_irqrestore(&list->lock, flags);
84485
84486 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
84487 skb->dev = NULL;
84488
84489 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
84490 - atomic_inc(&sk->sk_drops);
84491 + atomic_inc_unchecked(&sk->sk_drops);
84492 goto discard_and_relse;
84493 }
84494 if (nested)
84495 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
84496 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
84497 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
84498 bh_unlock_sock(sk);
84499 - atomic_inc(&sk->sk_drops);
84500 + atomic_inc_unchecked(&sk->sk_drops);
84501 goto discard_and_relse;
84502 }
84503
84504 @@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84505 struct timeval tm;
84506 } v;
84507
84508 - int lv = sizeof(int);
84509 - int len;
84510 + unsigned int lv = sizeof(int);
84511 + unsigned int len;
84512
84513 if (get_user(len, optlen))
84514 return -EFAULT;
84515 - if (len < 0)
84516 + if (len > INT_MAX)
84517 return -EINVAL;
84518
84519 memset(&v, 0, sizeof(v));
84520 @@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84521
84522 case SO_PEERNAME:
84523 {
84524 - char address[128];
84525 + char address[_K_SS_MAXSIZE];
84526
84527 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
84528 return -ENOTCONN;
84529 - if (lv < len)
84530 + if (lv < len || sizeof address < len)
84531 return -EINVAL;
84532 if (copy_to_user(optval, address, len))
84533 return -EFAULT;
84534 @@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84535
84536 if (len > lv)
84537 len = lv;
84538 - if (copy_to_user(optval, &v, len))
84539 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
84540 return -EFAULT;
84541 lenout:
84542 if (put_user(len, optlen))
84543 @@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
84544 */
84545 smp_wmb();
84546 atomic_set(&sk->sk_refcnt, 1);
84547 - atomic_set(&sk->sk_drops, 0);
84548 + atomic_set_unchecked(&sk->sk_drops, 0);
84549 }
84550 EXPORT_SYMBOL(sock_init_data);
84551
84552 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
84553 index 750f44f..922399c 100644
84554 --- a/net/core/sock_diag.c
84555 +++ b/net/core/sock_diag.c
84556 @@ -9,26 +9,33 @@
84557 #include <linux/inet_diag.h>
84558 #include <linux/sock_diag.h>
84559
84560 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
84561 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
84562 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
84563 static DEFINE_MUTEX(sock_diag_table_mutex);
84564
84565 int sock_diag_check_cookie(void *sk, __u32 *cookie)
84566 {
84567 +#ifndef CONFIG_GRKERNSEC_HIDESYM
84568 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
84569 cookie[1] != INET_DIAG_NOCOOKIE) &&
84570 ((u32)(unsigned long)sk != cookie[0] ||
84571 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
84572 return -ESTALE;
84573 else
84574 +#endif
84575 return 0;
84576 }
84577 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
84578
84579 void sock_diag_save_cookie(void *sk, __u32 *cookie)
84580 {
84581 +#ifdef CONFIG_GRKERNSEC_HIDESYM
84582 + cookie[0] = 0;
84583 + cookie[1] = 0;
84584 +#else
84585 cookie[0] = (u32)(unsigned long)sk;
84586 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
84587 +#endif
84588 }
84589 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
84590
84591 @@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
84592 mutex_lock(&sock_diag_table_mutex);
84593 if (sock_diag_handlers[hndl->family])
84594 err = -EBUSY;
84595 - else
84596 + else {
84597 + pax_open_kernel();
84598 sock_diag_handlers[hndl->family] = hndl;
84599 + pax_close_kernel();
84600 + }
84601 mutex_unlock(&sock_diag_table_mutex);
84602
84603 return err;
84604 @@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
84605
84606 mutex_lock(&sock_diag_table_mutex);
84607 BUG_ON(sock_diag_handlers[family] != hnld);
84608 + pax_open_kernel();
84609 sock_diag_handlers[family] = NULL;
84610 + pax_close_kernel();
84611 mutex_unlock(&sock_diag_table_mutex);
84612 }
84613 EXPORT_SYMBOL_GPL(sock_diag_unregister);
84614
84615 -static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
84616 -{
84617 - if (sock_diag_handlers[family] == NULL)
84618 - request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
84619 - NETLINK_SOCK_DIAG, family);
84620 -
84621 - mutex_lock(&sock_diag_table_mutex);
84622 - return sock_diag_handlers[family];
84623 -}
84624 -
84625 -static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
84626 -{
84627 - mutex_unlock(&sock_diag_table_mutex);
84628 -}
84629 -
84630 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84631 {
84632 int err;
84633 @@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84634 if (req->sdiag_family >= AF_MAX)
84635 return -EINVAL;
84636
84637 - hndl = sock_diag_lock_handler(req->sdiag_family);
84638 + if (sock_diag_handlers[req->sdiag_family] == NULL)
84639 + request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
84640 + NETLINK_SOCK_DIAG, req->sdiag_family);
84641 +
84642 + mutex_lock(&sock_diag_table_mutex);
84643 + hndl = sock_diag_handlers[req->sdiag_family];
84644 if (hndl == NULL)
84645 err = -ENOENT;
84646 else
84647 err = hndl->dump(skb, nlh);
84648 - sock_diag_unlock_handler(hndl);
84649 + mutex_unlock(&sock_diag_table_mutex);
84650
84651 return err;
84652 }
84653 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
84654 index d1b0804..4aed0a5 100644
84655 --- a/net/core/sysctl_net_core.c
84656 +++ b/net/core/sysctl_net_core.c
84657 @@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
84658 {
84659 unsigned int orig_size, size;
84660 int ret, i;
84661 - ctl_table tmp = {
84662 + ctl_table_no_const tmp = {
84663 .data = &size,
84664 .maxlen = sizeof(size),
84665 .mode = table->mode
84666 @@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
84667
84668 static __net_init int sysctl_core_net_init(struct net *net)
84669 {
84670 - struct ctl_table *tbl;
84671 + ctl_table_no_const *tbl = NULL;
84672
84673 net->core.sysctl_somaxconn = SOMAXCONN;
84674
84675 - tbl = netns_core_table;
84676 if (!net_eq(net, &init_net)) {
84677 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
84678 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
84679 if (tbl == NULL)
84680 goto err_dup;
84681
84682 @@ -221,16 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
84683 if (net->user_ns != &init_user_ns) {
84684 tbl[0].procname = NULL;
84685 }
84686 - }
84687 -
84688 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
84689 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
84690 + } else
84691 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
84692 if (net->core.sysctl_hdr == NULL)
84693 goto err_reg;
84694
84695 return 0;
84696
84697 err_reg:
84698 - if (tbl != netns_core_table)
84699 + if (tbl)
84700 kfree(tbl);
84701 err_dup:
84702 return -ENOMEM;
84703 @@ -246,7 +245,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
84704 kfree(tbl);
84705 }
84706
84707 -static __net_initdata struct pernet_operations sysctl_core_ops = {
84708 +static __net_initconst struct pernet_operations sysctl_core_ops = {
84709 .init = sysctl_core_net_init,
84710 .exit = sysctl_core_net_exit,
84711 };
84712 diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
84713 index 1b588e2..21291f1 100644
84714 --- a/net/dcb/dcbnl.c
84715 +++ b/net/dcb/dcbnl.c
84716 @@ -284,6 +284,7 @@ static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlmsghdr *nlh,
84717 if (!netdev->dcbnl_ops->getpermhwaddr)
84718 return -EOPNOTSUPP;
84719
84720 + memset(perm_addr, 0, sizeof(perm_addr));
84721 netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
84722
84723 return nla_put(skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr), perm_addr);
84724 @@ -1042,6 +1043,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84725
84726 if (ops->ieee_getets) {
84727 struct ieee_ets ets;
84728 + memset(&ets, 0, sizeof(ets));
84729 err = ops->ieee_getets(netdev, &ets);
84730 if (!err &&
84731 nla_put(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets))
84732 @@ -1050,6 +1052,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84733
84734 if (ops->ieee_getmaxrate) {
84735 struct ieee_maxrate maxrate;
84736 + memset(&maxrate, 0, sizeof(maxrate));
84737 err = ops->ieee_getmaxrate(netdev, &maxrate);
84738 if (!err) {
84739 err = nla_put(skb, DCB_ATTR_IEEE_MAXRATE,
84740 @@ -1061,6 +1064,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84741
84742 if (ops->ieee_getpfc) {
84743 struct ieee_pfc pfc;
84744 + memset(&pfc, 0, sizeof(pfc));
84745 err = ops->ieee_getpfc(netdev, &pfc);
84746 if (!err &&
84747 nla_put(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc))
84748 @@ -1094,6 +1098,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84749 /* get peer info if available */
84750 if (ops->ieee_peer_getets) {
84751 struct ieee_ets ets;
84752 + memset(&ets, 0, sizeof(ets));
84753 err = ops->ieee_peer_getets(netdev, &ets);
84754 if (!err &&
84755 nla_put(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets))
84756 @@ -1102,6 +1107,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84757
84758 if (ops->ieee_peer_getpfc) {
84759 struct ieee_pfc pfc;
84760 + memset(&pfc, 0, sizeof(pfc));
84761 err = ops->ieee_peer_getpfc(netdev, &pfc);
84762 if (!err &&
84763 nla_put(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc))
84764 @@ -1280,6 +1286,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
84765 /* peer info if available */
84766 if (ops->cee_peer_getpg) {
84767 struct cee_pg pg;
84768 + memset(&pg, 0, sizeof(pg));
84769 err = ops->cee_peer_getpg(netdev, &pg);
84770 if (!err &&
84771 nla_put(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg))
84772 @@ -1288,6 +1295,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
84773
84774 if (ops->cee_peer_getpfc) {
84775 struct cee_pfc pfc;
84776 + memset(&pfc, 0, sizeof(pfc));
84777 err = ops->cee_peer_getpfc(netdev, &pfc);
84778 if (!err &&
84779 nla_put(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc))
84780 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
84781 index 307c322..78a4c6f 100644
84782 --- a/net/decnet/af_decnet.c
84783 +++ b/net/decnet/af_decnet.c
84784 @@ -468,6 +468,7 @@ static struct proto dn_proto = {
84785 .sysctl_rmem = sysctl_decnet_rmem,
84786 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
84787 .obj_size = sizeof(struct dn_sock),
84788 + .slab_flags = SLAB_USERCOPY,
84789 };
84790
84791 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
84792 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
84793 index a55eecc..dd8428c 100644
84794 --- a/net/decnet/sysctl_net_decnet.c
84795 +++ b/net/decnet/sysctl_net_decnet.c
84796 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
84797
84798 if (len > *lenp) len = *lenp;
84799
84800 - if (copy_to_user(buffer, addr, len))
84801 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
84802 return -EFAULT;
84803
84804 *lenp = len;
84805 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
84806
84807 if (len > *lenp) len = *lenp;
84808
84809 - if (copy_to_user(buffer, devname, len))
84810 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
84811 return -EFAULT;
84812
84813 *lenp = len;
84814 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
84815 index fcf104e..95552d4 100644
84816 --- a/net/ipv4/af_inet.c
84817 +++ b/net/ipv4/af_inet.c
84818 @@ -1717,13 +1717,9 @@ static int __init inet_init(void)
84819
84820 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
84821
84822 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
84823 - if (!sysctl_local_reserved_ports)
84824 - goto out;
84825 -
84826 rc = proto_register(&tcp_prot, 1);
84827 if (rc)
84828 - goto out_free_reserved_ports;
84829 + goto out;
84830
84831 rc = proto_register(&udp_prot, 1);
84832 if (rc)
84833 @@ -1832,8 +1828,6 @@ out_unregister_udp_proto:
84834 proto_unregister(&udp_prot);
84835 out_unregister_tcp_proto:
84836 proto_unregister(&tcp_prot);
84837 -out_free_reserved_ports:
84838 - kfree(sysctl_local_reserved_ports);
84839 goto out;
84840 }
84841
84842 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
84843 index a69b4e4..dbccba5 100644
84844 --- a/net/ipv4/ah4.c
84845 +++ b/net/ipv4/ah4.c
84846 @@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
84847 return;
84848
84849 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
84850 - atomic_inc(&flow_cache_genid);
84851 + atomic_inc_unchecked(&flow_cache_genid);
84852 rt_genid_bump(net);
84853
84854 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
84855 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
84856 index a8e4f26..25e5f40 100644
84857 --- a/net/ipv4/devinet.c
84858 +++ b/net/ipv4/devinet.c
84859 @@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
84860 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
84861 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
84862
84863 -static struct devinet_sysctl_table {
84864 +static const struct devinet_sysctl_table {
84865 struct ctl_table_header *sysctl_header;
84866 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
84867 } devinet_sysctl = {
84868 @@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
84869 int err;
84870 struct ipv4_devconf *all, *dflt;
84871 #ifdef CONFIG_SYSCTL
84872 - struct ctl_table *tbl = ctl_forward_entry;
84873 + ctl_table_no_const *tbl = NULL;
84874 struct ctl_table_header *forw_hdr;
84875 #endif
84876
84877 @@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
84878 goto err_alloc_dflt;
84879
84880 #ifdef CONFIG_SYSCTL
84881 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
84882 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
84883 if (tbl == NULL)
84884 goto err_alloc_ctl;
84885
84886 @@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
84887 goto err_reg_dflt;
84888
84889 err = -ENOMEM;
84890 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
84891 + if (!net_eq(net, &init_net))
84892 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
84893 + else
84894 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
84895 if (forw_hdr == NULL)
84896 goto err_reg_ctl;
84897 net->ipv4.forw_hdr = forw_hdr;
84898 @@ -1935,8 +1938,7 @@ err_reg_ctl:
84899 err_reg_dflt:
84900 __devinet_sysctl_unregister(all);
84901 err_reg_all:
84902 - if (tbl != ctl_forward_entry)
84903 - kfree(tbl);
84904 + kfree(tbl);
84905 err_alloc_ctl:
84906 #endif
84907 if (dflt != &ipv4_devconf_dflt)
84908 diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
84909 index 3b4f0cd..8cb864c 100644
84910 --- a/net/ipv4/esp4.c
84911 +++ b/net/ipv4/esp4.c
84912 @@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
84913 return;
84914
84915 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
84916 - atomic_inc(&flow_cache_genid);
84917 + atomic_inc_unchecked(&flow_cache_genid);
84918 rt_genid_bump(net);
84919
84920 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
84921 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
84922 index 5cd75e2..f57ef39 100644
84923 --- a/net/ipv4/fib_frontend.c
84924 +++ b/net/ipv4/fib_frontend.c
84925 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
84926 #ifdef CONFIG_IP_ROUTE_MULTIPATH
84927 fib_sync_up(dev);
84928 #endif
84929 - atomic_inc(&net->ipv4.dev_addr_genid);
84930 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84931 rt_cache_flush(dev_net(dev));
84932 break;
84933 case NETDEV_DOWN:
84934 fib_del_ifaddr(ifa, NULL);
84935 - atomic_inc(&net->ipv4.dev_addr_genid);
84936 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84937 if (ifa->ifa_dev->ifa_list == NULL) {
84938 /* Last address was deleted from this interface.
84939 * Disable IP.
84940 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
84941 #ifdef CONFIG_IP_ROUTE_MULTIPATH
84942 fib_sync_up(dev);
84943 #endif
84944 - atomic_inc(&net->ipv4.dev_addr_genid);
84945 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84946 rt_cache_flush(net);
84947 break;
84948 case NETDEV_DOWN:
84949 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
84950 index 4797a80..2bd54e9 100644
84951 --- a/net/ipv4/fib_semantics.c
84952 +++ b/net/ipv4/fib_semantics.c
84953 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
84954 nh->nh_saddr = inet_select_addr(nh->nh_dev,
84955 nh->nh_gw,
84956 nh->nh_parent->fib_scope);
84957 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
84958 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
84959
84960 return nh->nh_saddr;
84961 }
84962 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
84963 index d0670f0..744ac80 100644
84964 --- a/net/ipv4/inet_connection_sock.c
84965 +++ b/net/ipv4/inet_connection_sock.c
84966 @@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
84967 .range = { 32768, 61000 },
84968 };
84969
84970 -unsigned long *sysctl_local_reserved_ports;
84971 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
84972 EXPORT_SYMBOL(sysctl_local_reserved_ports);
84973
84974 void inet_get_local_port_range(int *low, int *high)
84975 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
84976 index fa3ae81..0dbe6b8 100644
84977 --- a/net/ipv4/inet_hashtables.c
84978 +++ b/net/ipv4/inet_hashtables.c
84979 @@ -18,12 +18,15 @@
84980 #include <linux/sched.h>
84981 #include <linux/slab.h>
84982 #include <linux/wait.h>
84983 +#include <linux/security.h>
84984
84985 #include <net/inet_connection_sock.h>
84986 #include <net/inet_hashtables.h>
84987 #include <net/secure_seq.h>
84988 #include <net/ip.h>
84989
84990 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
84991 +
84992 /*
84993 * Allocate and initialize a new local port bind bucket.
84994 * The bindhash mutex for snum's hash chain must be held here.
84995 @@ -540,6 +543,8 @@ ok:
84996 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
84997 spin_unlock(&head->lock);
84998
84999 + gr_update_task_in_ip_table(current, inet_sk(sk));
85000 +
85001 if (tw) {
85002 inet_twsk_deschedule(tw, death_row);
85003 while (twrefcnt) {
85004 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
85005 index 000e3d2..5472da3 100644
85006 --- a/net/ipv4/inetpeer.c
85007 +++ b/net/ipv4/inetpeer.c
85008 @@ -503,8 +503,8 @@ relookup:
85009 if (p) {
85010 p->daddr = *daddr;
85011 atomic_set(&p->refcnt, 1);
85012 - atomic_set(&p->rid, 0);
85013 - atomic_set(&p->ip_id_count,
85014 + atomic_set_unchecked(&p->rid, 0);
85015 + atomic_set_unchecked(&p->ip_id_count,
85016 (daddr->family == AF_INET) ?
85017 secure_ip_id(daddr->addr.a4) :
85018 secure_ipv6_id(daddr->addr.a6));
85019 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
85020 index eb9d63a..31c5372 100644
85021 --- a/net/ipv4/ip_fragment.c
85022 +++ b/net/ipv4/ip_fragment.c
85023 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
85024 return 0;
85025
85026 start = qp->rid;
85027 - end = atomic_inc_return(&peer->rid);
85028 + end = atomic_inc_return_unchecked(&peer->rid);
85029 qp->rid = end;
85030
85031 rc = qp->q.fragments && (end - start) > max;
85032 @@ -789,12 +789,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
85033
85034 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85035 {
85036 - struct ctl_table *table;
85037 + ctl_table_no_const *table = NULL;
85038 struct ctl_table_header *hdr;
85039
85040 - table = ip4_frags_ns_ctl_table;
85041 if (!net_eq(net, &init_net)) {
85042 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85043 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85044 if (table == NULL)
85045 goto err_alloc;
85046
85047 @@ -805,9 +804,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85048 /* Don't export sysctls to unprivileged users */
85049 if (net->user_ns != &init_user_ns)
85050 table[0].procname = NULL;
85051 - }
85052 + hdr = register_net_sysctl(net, "net/ipv4", table);
85053 + } else
85054 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
85055
85056 - hdr = register_net_sysctl(net, "net/ipv4", table);
85057 if (hdr == NULL)
85058 goto err_reg;
85059
85060 @@ -815,8 +815,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85061 return 0;
85062
85063 err_reg:
85064 - if (!net_eq(net, &init_net))
85065 - kfree(table);
85066 + kfree(table);
85067 err_alloc:
85068 return -ENOMEM;
85069 }
85070 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
85071 index e81b1ca..6f3b5b9 100644
85072 --- a/net/ipv4/ip_gre.c
85073 +++ b/net/ipv4/ip_gre.c
85074 @@ -124,7 +124,7 @@ static bool log_ecn_error = true;
85075 module_param(log_ecn_error, bool, 0644);
85076 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
85077
85078 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
85079 +static struct rtnl_link_ops ipgre_link_ops;
85080 static int ipgre_tunnel_init(struct net_device *dev);
85081 static void ipgre_tunnel_setup(struct net_device *dev);
85082 static int ipgre_tunnel_bind_dev(struct net_device *dev);
85083 @@ -1756,7 +1756,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
85084 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
85085 };
85086
85087 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85088 +static struct rtnl_link_ops ipgre_link_ops = {
85089 .kind = "gre",
85090 .maxtype = IFLA_GRE_MAX,
85091 .policy = ipgre_policy,
85092 @@ -1769,7 +1769,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85093 .fill_info = ipgre_fill_info,
85094 };
85095
85096 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
85097 +static struct rtnl_link_ops ipgre_tap_ops = {
85098 .kind = "gretap",
85099 .maxtype = IFLA_GRE_MAX,
85100 .policy = ipgre_policy,
85101 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
85102 index d9c4f11..02b82db 100644
85103 --- a/net/ipv4/ip_sockglue.c
85104 +++ b/net/ipv4/ip_sockglue.c
85105 @@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85106 len = min_t(unsigned int, len, opt->optlen);
85107 if (put_user(len, optlen))
85108 return -EFAULT;
85109 - if (copy_to_user(optval, opt->__data, len))
85110 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
85111 + copy_to_user(optval, opt->__data, len))
85112 return -EFAULT;
85113 return 0;
85114 }
85115 @@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85116 if (sk->sk_type != SOCK_STREAM)
85117 return -ENOPROTOOPT;
85118
85119 - msg.msg_control = optval;
85120 + msg.msg_control = (void __force_kernel *)optval;
85121 msg.msg_controllen = len;
85122 msg.msg_flags = flags;
85123
85124 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
85125 index c3a4233..1412161 100644
85126 --- a/net/ipv4/ip_vti.c
85127 +++ b/net/ipv4/ip_vti.c
85128 @@ -47,7 +47,7 @@
85129 #define HASH_SIZE 16
85130 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
85131
85132 -static struct rtnl_link_ops vti_link_ops __read_mostly;
85133 +static struct rtnl_link_ops vti_link_ops;
85134
85135 static int vti_net_id __read_mostly;
85136 struct vti_net {
85137 @@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
85138 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
85139 };
85140
85141 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
85142 +static struct rtnl_link_ops vti_link_ops = {
85143 .kind = "vti",
85144 .maxtype = IFLA_VTI_MAX,
85145 .policy = vti_policy,
85146 diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
85147 index 9a46dae..5f793a0 100644
85148 --- a/net/ipv4/ipcomp.c
85149 +++ b/net/ipv4/ipcomp.c
85150 @@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
85151 return;
85152
85153 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85154 - atomic_inc(&flow_cache_genid);
85155 + atomic_inc_unchecked(&flow_cache_genid);
85156 rt_genid_bump(net);
85157
85158 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
85159 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
85160 index a2e50ae..e152b7c 100644
85161 --- a/net/ipv4/ipconfig.c
85162 +++ b/net/ipv4/ipconfig.c
85163 @@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
85164
85165 mm_segment_t oldfs = get_fs();
85166 set_fs(get_ds());
85167 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85168 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85169 set_fs(oldfs);
85170 return res;
85171 }
85172 @@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
85173
85174 mm_segment_t oldfs = get_fs();
85175 set_fs(get_ds());
85176 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85177 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85178 set_fs(oldfs);
85179 return res;
85180 }
85181 @@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
85182
85183 mm_segment_t oldfs = get_fs();
85184 set_fs(get_ds());
85185 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
85186 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
85187 set_fs(oldfs);
85188 return res;
85189 }
85190 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
85191 index 191fc24..1b3b804 100644
85192 --- a/net/ipv4/ipip.c
85193 +++ b/net/ipv4/ipip.c
85194 @@ -138,7 +138,7 @@ struct ipip_net {
85195 static int ipip_tunnel_init(struct net_device *dev);
85196 static void ipip_tunnel_setup(struct net_device *dev);
85197 static void ipip_dev_free(struct net_device *dev);
85198 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
85199 +static struct rtnl_link_ops ipip_link_ops;
85200
85201 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
85202 struct rtnl_link_stats64 *tot)
85203 @@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
85204 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
85205 };
85206
85207 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
85208 +static struct rtnl_link_ops ipip_link_ops = {
85209 .kind = "ipip",
85210 .maxtype = IFLA_IPTUN_MAX,
85211 .policy = ipip_policy,
85212 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
85213 index 3ea4127..849297b 100644
85214 --- a/net/ipv4/netfilter/arp_tables.c
85215 +++ b/net/ipv4/netfilter/arp_tables.c
85216 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
85217 #endif
85218
85219 static int get_info(struct net *net, void __user *user,
85220 - const int *len, int compat)
85221 + int len, int compat)
85222 {
85223 char name[XT_TABLE_MAXNAMELEN];
85224 struct xt_table *t;
85225 int ret;
85226
85227 - if (*len != sizeof(struct arpt_getinfo)) {
85228 - duprintf("length %u != %Zu\n", *len,
85229 + if (len != sizeof(struct arpt_getinfo)) {
85230 + duprintf("length %u != %Zu\n", len,
85231 sizeof(struct arpt_getinfo));
85232 return -EINVAL;
85233 }
85234 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
85235 info.size = private->size;
85236 strcpy(info.name, name);
85237
85238 - if (copy_to_user(user, &info, *len) != 0)
85239 + if (copy_to_user(user, &info, len) != 0)
85240 ret = -EFAULT;
85241 else
85242 ret = 0;
85243 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
85244
85245 switch (cmd) {
85246 case ARPT_SO_GET_INFO:
85247 - ret = get_info(sock_net(sk), user, len, 1);
85248 + ret = get_info(sock_net(sk), user, *len, 1);
85249 break;
85250 case ARPT_SO_GET_ENTRIES:
85251 ret = compat_get_entries(sock_net(sk), user, len);
85252 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
85253
85254 switch (cmd) {
85255 case ARPT_SO_GET_INFO:
85256 - ret = get_info(sock_net(sk), user, len, 0);
85257 + ret = get_info(sock_net(sk), user, *len, 0);
85258 break;
85259
85260 case ARPT_SO_GET_ENTRIES:
85261 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
85262 index 17c5e06..1b91206 100644
85263 --- a/net/ipv4/netfilter/ip_tables.c
85264 +++ b/net/ipv4/netfilter/ip_tables.c
85265 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
85266 #endif
85267
85268 static int get_info(struct net *net, void __user *user,
85269 - const int *len, int compat)
85270 + int len, int compat)
85271 {
85272 char name[XT_TABLE_MAXNAMELEN];
85273 struct xt_table *t;
85274 int ret;
85275
85276 - if (*len != sizeof(struct ipt_getinfo)) {
85277 - duprintf("length %u != %zu\n", *len,
85278 + if (len != sizeof(struct ipt_getinfo)) {
85279 + duprintf("length %u != %zu\n", len,
85280 sizeof(struct ipt_getinfo));
85281 return -EINVAL;
85282 }
85283 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
85284 info.size = private->size;
85285 strcpy(info.name, name);
85286
85287 - if (copy_to_user(user, &info, *len) != 0)
85288 + if (copy_to_user(user, &info, len) != 0)
85289 ret = -EFAULT;
85290 else
85291 ret = 0;
85292 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85293
85294 switch (cmd) {
85295 case IPT_SO_GET_INFO:
85296 - ret = get_info(sock_net(sk), user, len, 1);
85297 + ret = get_info(sock_net(sk), user, *len, 1);
85298 break;
85299 case IPT_SO_GET_ENTRIES:
85300 ret = compat_get_entries(sock_net(sk), user, len);
85301 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85302
85303 switch (cmd) {
85304 case IPT_SO_GET_INFO:
85305 - ret = get_info(sock_net(sk), user, len, 0);
85306 + ret = get_info(sock_net(sk), user, *len, 0);
85307 break;
85308
85309 case IPT_SO_GET_ENTRIES:
85310 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
85311 index dc454cc..5bb917f 100644
85312 --- a/net/ipv4/ping.c
85313 +++ b/net/ipv4/ping.c
85314 @@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
85315 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
85316 0, sock_i_ino(sp),
85317 atomic_read(&sp->sk_refcnt), sp,
85318 - atomic_read(&sp->sk_drops), len);
85319 + atomic_read_unchecked(&sp->sk_drops), len);
85320 }
85321
85322 static int ping_seq_show(struct seq_file *seq, void *v)
85323 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
85324 index 6f08991..55867ad 100644
85325 --- a/net/ipv4/raw.c
85326 +++ b/net/ipv4/raw.c
85327 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
85328 int raw_rcv(struct sock *sk, struct sk_buff *skb)
85329 {
85330 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
85331 - atomic_inc(&sk->sk_drops);
85332 + atomic_inc_unchecked(&sk->sk_drops);
85333 kfree_skb(skb);
85334 return NET_RX_DROP;
85335 }
85336 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
85337
85338 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
85339 {
85340 + struct icmp_filter filter;
85341 +
85342 if (optlen > sizeof(struct icmp_filter))
85343 optlen = sizeof(struct icmp_filter);
85344 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
85345 + if (copy_from_user(&filter, optval, optlen))
85346 return -EFAULT;
85347 + raw_sk(sk)->filter = filter;
85348 return 0;
85349 }
85350
85351 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
85352 {
85353 int len, ret = -EFAULT;
85354 + struct icmp_filter filter;
85355
85356 if (get_user(len, optlen))
85357 goto out;
85358 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
85359 if (len > sizeof(struct icmp_filter))
85360 len = sizeof(struct icmp_filter);
85361 ret = -EFAULT;
85362 - if (put_user(len, optlen) ||
85363 - copy_to_user(optval, &raw_sk(sk)->filter, len))
85364 + filter = raw_sk(sk)->filter;
85365 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
85366 goto out;
85367 ret = 0;
85368 out: return ret;
85369 @@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
85370 0, 0L, 0,
85371 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
85372 0, sock_i_ino(sp),
85373 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
85374 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
85375 }
85376
85377 static int raw_seq_show(struct seq_file *seq, void *v)
85378 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
85379 index a0fcc47..32e2c89 100644
85380 --- a/net/ipv4/route.c
85381 +++ b/net/ipv4/route.c
85382 @@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
85383 .maxlen = sizeof(int),
85384 .mode = 0200,
85385 .proc_handler = ipv4_sysctl_rtcache_flush,
85386 + .extra1 = &init_net,
85387 },
85388 { },
85389 };
85390
85391 static __net_init int sysctl_route_net_init(struct net *net)
85392 {
85393 - struct ctl_table *tbl;
85394 + ctl_table_no_const *tbl = NULL;
85395
85396 - tbl = ipv4_route_flush_table;
85397 if (!net_eq(net, &init_net)) {
85398 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
85399 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
85400 if (tbl == NULL)
85401 goto err_dup;
85402
85403 /* Don't export sysctls to unprivileged users */
85404 if (net->user_ns != &init_user_ns)
85405 tbl[0].procname = NULL;
85406 - }
85407 - tbl[0].extra1 = net;
85408 + tbl[0].extra1 = net;
85409 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
85410 + } else
85411 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
85412
85413 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
85414 if (net->ipv4.route_hdr == NULL)
85415 goto err_reg;
85416 return 0;
85417
85418 err_reg:
85419 - if (tbl != ipv4_route_flush_table)
85420 - kfree(tbl);
85421 + kfree(tbl);
85422 err_dup:
85423 return -ENOMEM;
85424 }
85425 @@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
85426
85427 static __net_init int rt_genid_init(struct net *net)
85428 {
85429 - atomic_set(&net->rt_genid, 0);
85430 + atomic_set_unchecked(&net->rt_genid, 0);
85431 get_random_bytes(&net->ipv4.dev_addr_genid,
85432 sizeof(net->ipv4.dev_addr_genid));
85433 return 0;
85434 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
85435 index d84400b..62e066e 100644
85436 --- a/net/ipv4/sysctl_net_ipv4.c
85437 +++ b/net/ipv4/sysctl_net_ipv4.c
85438 @@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
85439 {
85440 int ret;
85441 int range[2];
85442 - ctl_table tmp = {
85443 + ctl_table_no_const tmp = {
85444 .data = &range,
85445 .maxlen = sizeof(range),
85446 .mode = table->mode,
85447 @@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
85448 int ret;
85449 gid_t urange[2];
85450 kgid_t low, high;
85451 - ctl_table tmp = {
85452 + ctl_table_no_const tmp = {
85453 .data = &urange,
85454 .maxlen = sizeof(urange),
85455 .mode = table->mode,
85456 @@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
85457 void __user *buffer, size_t *lenp, loff_t *ppos)
85458 {
85459 char val[TCP_CA_NAME_MAX];
85460 - ctl_table tbl = {
85461 + ctl_table_no_const tbl = {
85462 .data = val,
85463 .maxlen = TCP_CA_NAME_MAX,
85464 };
85465 @@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
85466 void __user *buffer, size_t *lenp,
85467 loff_t *ppos)
85468 {
85469 - ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
85470 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
85471 int ret;
85472
85473 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
85474 @@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
85475 void __user *buffer, size_t *lenp,
85476 loff_t *ppos)
85477 {
85478 - ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
85479 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
85480 int ret;
85481
85482 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
85483 @@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
85484 struct mem_cgroup *memcg;
85485 #endif
85486
85487 - ctl_table tmp = {
85488 + ctl_table_no_const tmp = {
85489 .data = &vec,
85490 .maxlen = sizeof(vec),
85491 .mode = ctl->mode,
85492 };
85493
85494 if (!write) {
85495 - ctl->data = &net->ipv4.sysctl_tcp_mem;
85496 - return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
85497 + ctl_table_no_const tcp_mem = *ctl;
85498 +
85499 + tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
85500 + return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
85501 }
85502
85503 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
85504 @@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
85505 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
85506 size_t *lenp, loff_t *ppos)
85507 {
85508 - ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
85509 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
85510 struct tcp_fastopen_context *ctxt;
85511 int ret;
85512 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
85513 @@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
85514 },
85515 {
85516 .procname = "ip_local_reserved_ports",
85517 - .data = NULL, /* initialized in sysctl_ipv4_init */
85518 + .data = sysctl_local_reserved_ports,
85519 .maxlen = 65536,
85520 .mode = 0644,
85521 .proc_handler = proc_do_large_bitmap,
85522 @@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
85523
85524 static __net_init int ipv4_sysctl_init_net(struct net *net)
85525 {
85526 - struct ctl_table *table;
85527 + ctl_table_no_const *table = NULL;
85528
85529 - table = ipv4_net_table;
85530 if (!net_eq(net, &init_net)) {
85531 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
85532 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
85533 if (table == NULL)
85534 goto err_alloc;
85535
85536 @@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
85537
85538 tcp_init_mem(net);
85539
85540 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
85541 + if (!net_eq(net, &init_net))
85542 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
85543 + else
85544 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
85545 if (net->ipv4.ipv4_hdr == NULL)
85546 goto err_reg;
85547
85548 return 0;
85549
85550 err_reg:
85551 - if (!net_eq(net, &init_net))
85552 - kfree(table);
85553 + kfree(table);
85554 err_alloc:
85555 return -ENOMEM;
85556 }
85557 @@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
85558 static __init int sysctl_ipv4_init(void)
85559 {
85560 struct ctl_table_header *hdr;
85561 - struct ctl_table *i;
85562 -
85563 - for (i = ipv4_table; i->procname; i++) {
85564 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
85565 - i->data = sysctl_local_reserved_ports;
85566 - break;
85567 - }
85568 - }
85569 - if (!i->procname)
85570 - return -EINVAL;
85571
85572 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
85573 if (hdr == NULL)
85574 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
85575 index ad70a96..50cb55b 100644
85576 --- a/net/ipv4/tcp_input.c
85577 +++ b/net/ipv4/tcp_input.c
85578 @@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
85579 * simplifies code)
85580 */
85581 static void
85582 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
85583 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
85584 struct sk_buff *head, struct sk_buff *tail,
85585 u32 start, u32 end)
85586 {
85587 @@ -5850,6 +5850,7 @@ discard:
85588 tcp_paws_reject(&tp->rx_opt, 0))
85589 goto discard_and_undo;
85590
85591 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
85592 if (th->syn) {
85593 /* We see SYN without ACK. It is attempt of
85594 * simultaneous connect with crossed SYNs.
85595 @@ -5900,6 +5901,7 @@ discard:
85596 goto discard;
85597 #endif
85598 }
85599 +#endif
85600 /* "fifth, if neither of the SYN or RST bits is set then
85601 * drop the segment and return."
85602 */
85603 @@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
85604 goto discard;
85605
85606 if (th->syn) {
85607 - if (th->fin)
85608 + if (th->fin || th->urg || th->psh)
85609 goto discard;
85610 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
85611 return 1;
85612 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
85613 index eadb693..e8f7251 100644
85614 --- a/net/ipv4/tcp_ipv4.c
85615 +++ b/net/ipv4/tcp_ipv4.c
85616 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
85617 EXPORT_SYMBOL(sysctl_tcp_low_latency);
85618
85619
85620 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85621 +extern int grsec_enable_blackhole;
85622 +#endif
85623 +
85624 #ifdef CONFIG_TCP_MD5SIG
85625 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
85626 __be32 daddr, __be32 saddr, const struct tcphdr *th);
85627 @@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
85628 return 0;
85629
85630 reset:
85631 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85632 + if (!grsec_enable_blackhole)
85633 +#endif
85634 tcp_v4_send_reset(rsk, skb);
85635 discard:
85636 kfree_skb(skb);
85637 @@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
85638 TCP_SKB_CB(skb)->sacked = 0;
85639
85640 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
85641 - if (!sk)
85642 + if (!sk) {
85643 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85644 + ret = 1;
85645 +#endif
85646 goto no_tcp_socket;
85647 -
85648 + }
85649 process:
85650 - if (sk->sk_state == TCP_TIME_WAIT)
85651 + if (sk->sk_state == TCP_TIME_WAIT) {
85652 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85653 + ret = 2;
85654 +#endif
85655 goto do_time_wait;
85656 + }
85657
85658 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
85659 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
85660 @@ -2050,6 +2064,10 @@ no_tcp_socket:
85661 bad_packet:
85662 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
85663 } else {
85664 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85665 + if (!grsec_enable_blackhole || (ret == 1 &&
85666 + (skb->dev->flags & IFF_LOOPBACK)))
85667 +#endif
85668 tcp_v4_send_reset(NULL, skb);
85669 }
85670
85671 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
85672 index f35f2df..ccb5ca6 100644
85673 --- a/net/ipv4/tcp_minisocks.c
85674 +++ b/net/ipv4/tcp_minisocks.c
85675 @@ -27,6 +27,10 @@
85676 #include <net/inet_common.h>
85677 #include <net/xfrm.h>
85678
85679 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85680 +extern int grsec_enable_blackhole;
85681 +#endif
85682 +
85683 int sysctl_tcp_syncookies __read_mostly = 1;
85684 EXPORT_SYMBOL(sysctl_tcp_syncookies);
85685
85686 @@ -742,7 +746,10 @@ embryonic_reset:
85687 * avoid becoming vulnerable to outside attack aiming at
85688 * resetting legit local connections.
85689 */
85690 - req->rsk_ops->send_reset(sk, skb);
85691 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85692 + if (!grsec_enable_blackhole)
85693 +#endif
85694 + req->rsk_ops->send_reset(sk, skb);
85695 } else if (fastopen) { /* received a valid RST pkt */
85696 reqsk_fastopen_remove(sk, req, true);
85697 tcp_reset(sk);
85698 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
85699 index 4526fe6..1a34e43 100644
85700 --- a/net/ipv4/tcp_probe.c
85701 +++ b/net/ipv4/tcp_probe.c
85702 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
85703 if (cnt + width >= len)
85704 break;
85705
85706 - if (copy_to_user(buf + cnt, tbuf, width))
85707 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
85708 return -EFAULT;
85709 cnt += width;
85710 }
85711 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
85712 index b78aac3..e18230b 100644
85713 --- a/net/ipv4/tcp_timer.c
85714 +++ b/net/ipv4/tcp_timer.c
85715 @@ -22,6 +22,10 @@
85716 #include <linux/gfp.h>
85717 #include <net/tcp.h>
85718
85719 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85720 +extern int grsec_lastack_retries;
85721 +#endif
85722 +
85723 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
85724 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
85725 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
85726 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
85727 }
85728 }
85729
85730 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85731 + if ((sk->sk_state == TCP_LAST_ACK) &&
85732 + (grsec_lastack_retries > 0) &&
85733 + (grsec_lastack_retries < retry_until))
85734 + retry_until = grsec_lastack_retries;
85735 +#endif
85736 +
85737 if (retransmits_timed_out(sk, retry_until,
85738 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
85739 /* Has it gone just too far? */
85740 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
85741 index 1f4d405..3524677 100644
85742 --- a/net/ipv4/udp.c
85743 +++ b/net/ipv4/udp.c
85744 @@ -87,6 +87,7 @@
85745 #include <linux/types.h>
85746 #include <linux/fcntl.h>
85747 #include <linux/module.h>
85748 +#include <linux/security.h>
85749 #include <linux/socket.h>
85750 #include <linux/sockios.h>
85751 #include <linux/igmp.h>
85752 @@ -111,6 +112,10 @@
85753 #include <trace/events/skb.h>
85754 #include "udp_impl.h"
85755
85756 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85757 +extern int grsec_enable_blackhole;
85758 +#endif
85759 +
85760 struct udp_table udp_table __read_mostly;
85761 EXPORT_SYMBOL(udp_table);
85762
85763 @@ -569,6 +574,9 @@ found:
85764 return s;
85765 }
85766
85767 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
85768 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
85769 +
85770 /*
85771 * This routine is called by the ICMP module when it gets some
85772 * sort of error condition. If err < 0 then the socket should
85773 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
85774 dport = usin->sin_port;
85775 if (dport == 0)
85776 return -EINVAL;
85777 +
85778 + err = gr_search_udp_sendmsg(sk, usin);
85779 + if (err)
85780 + return err;
85781 } else {
85782 if (sk->sk_state != TCP_ESTABLISHED)
85783 return -EDESTADDRREQ;
85784 +
85785 + err = gr_search_udp_sendmsg(sk, NULL);
85786 + if (err)
85787 + return err;
85788 +
85789 daddr = inet->inet_daddr;
85790 dport = inet->inet_dport;
85791 /* Open fast path for connected socket.
85792 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
85793 udp_lib_checksum_complete(skb)) {
85794 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
85795 IS_UDPLITE(sk));
85796 - atomic_inc(&sk->sk_drops);
85797 + atomic_inc_unchecked(&sk->sk_drops);
85798 __skb_unlink(skb, rcvq);
85799 __skb_queue_tail(&list_kill, skb);
85800 }
85801 @@ -1194,6 +1211,10 @@ try_again:
85802 if (!skb)
85803 goto out;
85804
85805 + err = gr_search_udp_recvmsg(sk, skb);
85806 + if (err)
85807 + goto out_free;
85808 +
85809 ulen = skb->len - sizeof(struct udphdr);
85810 copied = len;
85811 if (copied > ulen)
85812 @@ -1227,7 +1248,7 @@ try_again:
85813 if (unlikely(err)) {
85814 trace_kfree_skb(skb, udp_recvmsg);
85815 if (!peeked) {
85816 - atomic_inc(&sk->sk_drops);
85817 + atomic_inc_unchecked(&sk->sk_drops);
85818 UDP_INC_STATS_USER(sock_net(sk),
85819 UDP_MIB_INERRORS, is_udplite);
85820 }
85821 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85822
85823 drop:
85824 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
85825 - atomic_inc(&sk->sk_drops);
85826 + atomic_inc_unchecked(&sk->sk_drops);
85827 kfree_skb(skb);
85828 return -1;
85829 }
85830 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
85831 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
85832
85833 if (!skb1) {
85834 - atomic_inc(&sk->sk_drops);
85835 + atomic_inc_unchecked(&sk->sk_drops);
85836 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
85837 IS_UDPLITE(sk));
85838 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
85839 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
85840 goto csum_error;
85841
85842 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
85843 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85844 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
85845 +#endif
85846 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
85847
85848 /*
85849 @@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
85850 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
85851 0, sock_i_ino(sp),
85852 atomic_read(&sp->sk_refcnt), sp,
85853 - atomic_read(&sp->sk_drops), len);
85854 + atomic_read_unchecked(&sp->sk_drops), len);
85855 }
85856
85857 int udp4_seq_show(struct seq_file *seq, void *v)
85858 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
85859 index 1b5d8cb..ffb0833 100644
85860 --- a/net/ipv6/addrconf.c
85861 +++ b/net/ipv6/addrconf.c
85862 @@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
85863 p.iph.ihl = 5;
85864 p.iph.protocol = IPPROTO_IPV6;
85865 p.iph.ttl = 64;
85866 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
85867 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
85868
85869 if (ops->ndo_do_ioctl) {
85870 mm_segment_t oldfs = get_fs();
85871 @@ -4388,7 +4388,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
85872 int *valp = ctl->data;
85873 int val = *valp;
85874 loff_t pos = *ppos;
85875 - ctl_table lctl;
85876 + ctl_table_no_const lctl;
85877 int ret;
85878
85879 /*
85880 @@ -4470,7 +4470,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
85881 int *valp = ctl->data;
85882 int val = *valp;
85883 loff_t pos = *ppos;
85884 - ctl_table lctl;
85885 + ctl_table_no_const lctl;
85886 int ret;
85887
85888 /*
85889 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
85890 index fff5bdd..15194fb 100644
85891 --- a/net/ipv6/icmp.c
85892 +++ b/net/ipv6/icmp.c
85893 @@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
85894
85895 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
85896 {
85897 - struct ctl_table *table;
85898 + ctl_table_no_const *table;
85899
85900 table = kmemdup(ipv6_icmp_table_template,
85901 sizeof(ipv6_icmp_table_template),
85902 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
85903 index 131dd09..f7ed64f 100644
85904 --- a/net/ipv6/ip6_gre.c
85905 +++ b/net/ipv6/ip6_gre.c
85906 @@ -73,7 +73,7 @@ struct ip6gre_net {
85907 struct net_device *fb_tunnel_dev;
85908 };
85909
85910 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
85911 +static struct rtnl_link_ops ip6gre_link_ops;
85912 static int ip6gre_tunnel_init(struct net_device *dev);
85913 static void ip6gre_tunnel_setup(struct net_device *dev);
85914 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
85915 @@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
85916 }
85917
85918
85919 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
85920 +static struct inet6_protocol ip6gre_protocol = {
85921 .handler = ip6gre_rcv,
85922 .err_handler = ip6gre_err,
85923 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
85924 @@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
85925 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
85926 };
85927
85928 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
85929 +static struct rtnl_link_ops ip6gre_link_ops = {
85930 .kind = "ip6gre",
85931 .maxtype = IFLA_GRE_MAX,
85932 .policy = ip6gre_policy,
85933 @@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
85934 .fill_info = ip6gre_fill_info,
85935 };
85936
85937 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
85938 +static struct rtnl_link_ops ip6gre_tap_ops = {
85939 .kind = "ip6gretap",
85940 .maxtype = IFLA_GRE_MAX,
85941 .policy = ip6gre_policy,
85942 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
85943 index a14f28b..b4b8956 100644
85944 --- a/net/ipv6/ip6_tunnel.c
85945 +++ b/net/ipv6/ip6_tunnel.c
85946 @@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
85947
85948 static int ip6_tnl_dev_init(struct net_device *dev);
85949 static void ip6_tnl_dev_setup(struct net_device *dev);
85950 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
85951 +static struct rtnl_link_ops ip6_link_ops;
85952
85953 static int ip6_tnl_net_id __read_mostly;
85954 struct ip6_tnl_net {
85955 @@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
85956 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
85957 };
85958
85959 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
85960 +static struct rtnl_link_ops ip6_link_ops = {
85961 .kind = "ip6tnl",
85962 .maxtype = IFLA_IPTUN_MAX,
85963 .policy = ip6_tnl_policy,
85964 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
85965 index d1e2e8e..51c19ae 100644
85966 --- a/net/ipv6/ipv6_sockglue.c
85967 +++ b/net/ipv6/ipv6_sockglue.c
85968 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
85969 if (sk->sk_type != SOCK_STREAM)
85970 return -ENOPROTOOPT;
85971
85972 - msg.msg_control = optval;
85973 + msg.msg_control = (void __force_kernel *)optval;
85974 msg.msg_controllen = len;
85975 msg.msg_flags = flags;
85976
85977 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
85978 index 125a90d..2a11f36 100644
85979 --- a/net/ipv6/netfilter/ip6_tables.c
85980 +++ b/net/ipv6/netfilter/ip6_tables.c
85981 @@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
85982 #endif
85983
85984 static int get_info(struct net *net, void __user *user,
85985 - const int *len, int compat)
85986 + int len, int compat)
85987 {
85988 char name[XT_TABLE_MAXNAMELEN];
85989 struct xt_table *t;
85990 int ret;
85991
85992 - if (*len != sizeof(struct ip6t_getinfo)) {
85993 - duprintf("length %u != %zu\n", *len,
85994 + if (len != sizeof(struct ip6t_getinfo)) {
85995 + duprintf("length %u != %zu\n", len,
85996 sizeof(struct ip6t_getinfo));
85997 return -EINVAL;
85998 }
85999 @@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
86000 info.size = private->size;
86001 strcpy(info.name, name);
86002
86003 - if (copy_to_user(user, &info, *len) != 0)
86004 + if (copy_to_user(user, &info, len) != 0)
86005 ret = -EFAULT;
86006 else
86007 ret = 0;
86008 @@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86009
86010 switch (cmd) {
86011 case IP6T_SO_GET_INFO:
86012 - ret = get_info(sock_net(sk), user, len, 1);
86013 + ret = get_info(sock_net(sk), user, *len, 1);
86014 break;
86015 case IP6T_SO_GET_ENTRIES:
86016 ret = compat_get_entries(sock_net(sk), user, len);
86017 @@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86018
86019 switch (cmd) {
86020 case IP6T_SO_GET_INFO:
86021 - ret = get_info(sock_net(sk), user, len, 0);
86022 + ret = get_info(sock_net(sk), user, *len, 0);
86023 break;
86024
86025 case IP6T_SO_GET_ENTRIES:
86026 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
86027 index 3dacecc..2939087 100644
86028 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
86029 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
86030 @@ -87,12 +87,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
86031
86032 static int nf_ct_frag6_sysctl_register(struct net *net)
86033 {
86034 - struct ctl_table *table;
86035 + ctl_table_no_const *table = NULL;
86036 struct ctl_table_header *hdr;
86037
86038 - table = nf_ct_frag6_sysctl_table;
86039 if (!net_eq(net, &init_net)) {
86040 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
86041 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
86042 GFP_KERNEL);
86043 if (table == NULL)
86044 goto err_alloc;
86045 @@ -100,9 +99,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86046 table[0].data = &net->ipv6.frags.high_thresh;
86047 table[1].data = &net->ipv6.frags.low_thresh;
86048 table[2].data = &net->ipv6.frags.timeout;
86049 - }
86050 -
86051 - hdr = register_net_sysctl(net, "net/netfilter", table);
86052 + hdr = register_net_sysctl(net, "net/netfilter", table);
86053 + } else
86054 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
86055 if (hdr == NULL)
86056 goto err_reg;
86057
86058 @@ -110,8 +109,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86059 return 0;
86060
86061 err_reg:
86062 - if (!net_eq(net, &init_net))
86063 - kfree(table);
86064 + kfree(table);
86065 err_alloc:
86066 return -ENOMEM;
86067 }
86068 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
86069 index 70fa814..d70c28c 100644
86070 --- a/net/ipv6/raw.c
86071 +++ b/net/ipv6/raw.c
86072 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
86073 {
86074 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
86075 skb_checksum_complete(skb)) {
86076 - atomic_inc(&sk->sk_drops);
86077 + atomic_inc_unchecked(&sk->sk_drops);
86078 kfree_skb(skb);
86079 return NET_RX_DROP;
86080 }
86081 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86082 struct raw6_sock *rp = raw6_sk(sk);
86083
86084 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
86085 - atomic_inc(&sk->sk_drops);
86086 + atomic_inc_unchecked(&sk->sk_drops);
86087 kfree_skb(skb);
86088 return NET_RX_DROP;
86089 }
86090 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86091
86092 if (inet->hdrincl) {
86093 if (skb_checksum_complete(skb)) {
86094 - atomic_inc(&sk->sk_drops);
86095 + atomic_inc_unchecked(&sk->sk_drops);
86096 kfree_skb(skb);
86097 return NET_RX_DROP;
86098 }
86099 @@ -604,7 +604,7 @@ out:
86100 return err;
86101 }
86102
86103 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
86104 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
86105 struct flowi6 *fl6, struct dst_entry **dstp,
86106 unsigned int flags)
86107 {
86108 @@ -916,12 +916,15 @@ do_confirm:
86109 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
86110 char __user *optval, int optlen)
86111 {
86112 + struct icmp6_filter filter;
86113 +
86114 switch (optname) {
86115 case ICMPV6_FILTER:
86116 if (optlen > sizeof(struct icmp6_filter))
86117 optlen = sizeof(struct icmp6_filter);
86118 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
86119 + if (copy_from_user(&filter, optval, optlen))
86120 return -EFAULT;
86121 + raw6_sk(sk)->filter = filter;
86122 return 0;
86123 default:
86124 return -ENOPROTOOPT;
86125 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86126 char __user *optval, int __user *optlen)
86127 {
86128 int len;
86129 + struct icmp6_filter filter;
86130
86131 switch (optname) {
86132 case ICMPV6_FILTER:
86133 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86134 len = sizeof(struct icmp6_filter);
86135 if (put_user(len, optlen))
86136 return -EFAULT;
86137 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
86138 + filter = raw6_sk(sk)->filter;
86139 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
86140 return -EFAULT;
86141 return 0;
86142 default:
86143 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86144 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86145 0,
86146 sock_i_ino(sp),
86147 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86148 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86149 }
86150
86151 static int raw6_seq_show(struct seq_file *seq, void *v)
86152 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
86153 index e5253ec..0410257 100644
86154 --- a/net/ipv6/reassembly.c
86155 +++ b/net/ipv6/reassembly.c
86156 @@ -604,12 +604,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
86157
86158 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86159 {
86160 - struct ctl_table *table;
86161 + ctl_table_no_const *table = NULL;
86162 struct ctl_table_header *hdr;
86163
86164 - table = ip6_frags_ns_ctl_table;
86165 if (!net_eq(net, &init_net)) {
86166 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86167 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86168 if (table == NULL)
86169 goto err_alloc;
86170
86171 @@ -620,9 +619,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86172 /* Don't export sysctls to unprivileged users */
86173 if (net->user_ns != &init_user_ns)
86174 table[0].procname = NULL;
86175 - }
86176 + hdr = register_net_sysctl(net, "net/ipv6", table);
86177 + } else
86178 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
86179
86180 - hdr = register_net_sysctl(net, "net/ipv6", table);
86181 if (hdr == NULL)
86182 goto err_reg;
86183
86184 @@ -630,8 +630,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86185 return 0;
86186
86187 err_reg:
86188 - if (!net_eq(net, &init_net))
86189 - kfree(table);
86190 + kfree(table);
86191 err_alloc:
86192 return -ENOMEM;
86193 }
86194 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
86195 index 6f9f7b6..2306d63 100644
86196 --- a/net/ipv6/route.c
86197 +++ b/net/ipv6/route.c
86198 @@ -2965,7 +2965,7 @@ ctl_table ipv6_route_table_template[] = {
86199
86200 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
86201 {
86202 - struct ctl_table *table;
86203 + ctl_table_no_const *table;
86204
86205 table = kmemdup(ipv6_route_table_template,
86206 sizeof(ipv6_route_table_template),
86207 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
86208 index cfba99b..20ca511 100644
86209 --- a/net/ipv6/sit.c
86210 +++ b/net/ipv6/sit.c
86211 @@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
86212 static int ipip6_tunnel_init(struct net_device *dev);
86213 static void ipip6_tunnel_setup(struct net_device *dev);
86214 static void ipip6_dev_free(struct net_device *dev);
86215 -static struct rtnl_link_ops sit_link_ops __read_mostly;
86216 +static struct rtnl_link_ops sit_link_ops;
86217
86218 static int sit_net_id __read_mostly;
86219 struct sit_net {
86220 @@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
86221 #endif
86222 };
86223
86224 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
86225 +static struct rtnl_link_ops sit_link_ops = {
86226 .kind = "sit",
86227 .maxtype = IFLA_IPTUN_MAX,
86228 .policy = ipip6_policy,
86229 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
86230 index e85c48b..b8268d3 100644
86231 --- a/net/ipv6/sysctl_net_ipv6.c
86232 +++ b/net/ipv6/sysctl_net_ipv6.c
86233 @@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
86234
86235 static int __net_init ipv6_sysctl_net_init(struct net *net)
86236 {
86237 - struct ctl_table *ipv6_table;
86238 + ctl_table_no_const *ipv6_table;
86239 struct ctl_table *ipv6_route_table;
86240 struct ctl_table *ipv6_icmp_table;
86241 int err;
86242 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
86243 index 4f435371..5de9da7 100644
86244 --- a/net/ipv6/tcp_ipv6.c
86245 +++ b/net/ipv6/tcp_ipv6.c
86246 @@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
86247 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
86248 }
86249
86250 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86251 +extern int grsec_enable_blackhole;
86252 +#endif
86253 +
86254 static void tcp_v6_hash(struct sock *sk)
86255 {
86256 if (sk->sk_state != TCP_CLOSE) {
86257 @@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
86258 return 0;
86259
86260 reset:
86261 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86262 + if (!grsec_enable_blackhole)
86263 +#endif
86264 tcp_v6_send_reset(sk, skb);
86265 discard:
86266 if (opt_skb)
86267 @@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
86268 TCP_SKB_CB(skb)->sacked = 0;
86269
86270 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
86271 - if (!sk)
86272 + if (!sk) {
86273 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86274 + ret = 1;
86275 +#endif
86276 goto no_tcp_socket;
86277 + }
86278
86279 process:
86280 - if (sk->sk_state == TCP_TIME_WAIT)
86281 + if (sk->sk_state == TCP_TIME_WAIT) {
86282 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86283 + ret = 2;
86284 +#endif
86285 goto do_time_wait;
86286 + }
86287
86288 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
86289 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
86290 @@ -1568,6 +1583,10 @@ no_tcp_socket:
86291 bad_packet:
86292 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
86293 } else {
86294 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86295 + if (!grsec_enable_blackhole || (ret == 1 &&
86296 + (skb->dev->flags & IFF_LOOPBACK)))
86297 +#endif
86298 tcp_v6_send_reset(NULL, skb);
86299 }
86300
86301 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
86302 index fb08329..2d6919e 100644
86303 --- a/net/ipv6/udp.c
86304 +++ b/net/ipv6/udp.c
86305 @@ -51,6 +51,10 @@
86306 #include <trace/events/skb.h>
86307 #include "udp_impl.h"
86308
86309 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86310 +extern int grsec_enable_blackhole;
86311 +#endif
86312 +
86313 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
86314 {
86315 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
86316 @@ -395,7 +399,7 @@ try_again:
86317 if (unlikely(err)) {
86318 trace_kfree_skb(skb, udpv6_recvmsg);
86319 if (!peeked) {
86320 - atomic_inc(&sk->sk_drops);
86321 + atomic_inc_unchecked(&sk->sk_drops);
86322 if (is_udp4)
86323 UDP_INC_STATS_USER(sock_net(sk),
86324 UDP_MIB_INERRORS,
86325 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86326 return rc;
86327 drop:
86328 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
86329 - atomic_inc(&sk->sk_drops);
86330 + atomic_inc_unchecked(&sk->sk_drops);
86331 kfree_skb(skb);
86332 return -1;
86333 }
86334 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
86335 if (likely(skb1 == NULL))
86336 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
86337 if (!skb1) {
86338 - atomic_inc(&sk->sk_drops);
86339 + atomic_inc_unchecked(&sk->sk_drops);
86340 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
86341 IS_UDPLITE(sk));
86342 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86343 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
86344 goto discard;
86345
86346 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
86347 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86348 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
86349 +#endif
86350 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
86351
86352 kfree_skb(skb);
86353 @@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
86354 0,
86355 sock_i_ino(sp),
86356 atomic_read(&sp->sk_refcnt), sp,
86357 - atomic_read(&sp->sk_drops));
86358 + atomic_read_unchecked(&sp->sk_drops));
86359 }
86360
86361 int udp6_seq_show(struct seq_file *seq, void *v)
86362 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
86363 index a68c88c..d55b0c5 100644
86364 --- a/net/irda/ircomm/ircomm_tty.c
86365 +++ b/net/irda/ircomm/ircomm_tty.c
86366 @@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
86367 add_wait_queue(&port->open_wait, &wait);
86368
86369 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
86370 - __FILE__, __LINE__, tty->driver->name, port->count);
86371 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
86372
86373 spin_lock_irqsave(&port->lock, flags);
86374 if (!tty_hung_up_p(filp)) {
86375 extra_count = 1;
86376 - port->count--;
86377 + atomic_dec(&port->count);
86378 }
86379 spin_unlock_irqrestore(&port->lock, flags);
86380 port->blocked_open++;
86381 @@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
86382 }
86383
86384 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
86385 - __FILE__, __LINE__, tty->driver->name, port->count);
86386 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
86387
86388 schedule();
86389 }
86390 @@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
86391 if (extra_count) {
86392 /* ++ is not atomic, so this should be protected - Jean II */
86393 spin_lock_irqsave(&port->lock, flags);
86394 - port->count++;
86395 + atomic_inc(&port->count);
86396 spin_unlock_irqrestore(&port->lock, flags);
86397 }
86398 port->blocked_open--;
86399
86400 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
86401 - __FILE__, __LINE__, tty->driver->name, port->count);
86402 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
86403
86404 if (!retval)
86405 port->flags |= ASYNC_NORMAL_ACTIVE;
86406 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
86407
86408 /* ++ is not atomic, so this should be protected - Jean II */
86409 spin_lock_irqsave(&self->port.lock, flags);
86410 - self->port.count++;
86411 + atomic_inc(&self->port.count);
86412 spin_unlock_irqrestore(&self->port.lock, flags);
86413 tty_port_tty_set(&self->port, tty);
86414
86415 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
86416 - self->line, self->port.count);
86417 + self->line, atomic_read(&self->port.count));
86418
86419 /* Not really used by us, but lets do it anyway */
86420 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
86421 @@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
86422 tty_kref_put(port->tty);
86423 }
86424 port->tty = NULL;
86425 - port->count = 0;
86426 + atomic_set(&port->count, 0);
86427 spin_unlock_irqrestore(&port->lock, flags);
86428
86429 wake_up_interruptible(&port->open_wait);
86430 @@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
86431 seq_putc(m, '\n');
86432
86433 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
86434 - seq_printf(m, "Open count: %d\n", self->port.count);
86435 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
86436 seq_printf(m, "Max data size: %d\n", self->max_data_size);
86437 seq_printf(m, "Max header size: %d\n", self->max_header_size);
86438
86439 diff --git a/net/irda/iriap.c b/net/irda/iriap.c
86440 index e71e85b..29340a9 100644
86441 --- a/net/irda/iriap.c
86442 +++ b/net/irda/iriap.c
86443 @@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
86444 /* case CS_ISO_8859_9: */
86445 /* case CS_UNICODE: */
86446 default:
86447 - IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
86448 - __func__, ias_charset_types[charset]);
86449 + IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
86450 + __func__, charset,
86451 + charset < ARRAY_SIZE(ias_charset_types) ?
86452 + ias_charset_types[charset] :
86453 + "(unknown)");
86454
86455 /* Aborting, close connection! */
86456 iriap_disconnect_request(self);
86457 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
86458 index cd6f7a9..e63fe89 100644
86459 --- a/net/iucv/af_iucv.c
86460 +++ b/net/iucv/af_iucv.c
86461 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
86462
86463 write_lock_bh(&iucv_sk_list.lock);
86464
86465 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
86466 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
86467 while (__iucv_get_sock_by_name(name)) {
86468 sprintf(name, "%08x",
86469 - atomic_inc_return(&iucv_sk_list.autobind_name));
86470 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
86471 }
86472
86473 write_unlock_bh(&iucv_sk_list.lock);
86474 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
86475 index df08250..02021fe 100644
86476 --- a/net/iucv/iucv.c
86477 +++ b/net/iucv/iucv.c
86478 @@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
86479 return NOTIFY_OK;
86480 }
86481
86482 -static struct notifier_block __refdata iucv_cpu_notifier = {
86483 +static struct notifier_block iucv_cpu_notifier = {
86484 .notifier_call = iucv_cpu_notify,
86485 };
86486
86487 diff --git a/net/key/af_key.c b/net/key/af_key.c
86488 index 5b426a6..970032b 100644
86489 --- a/net/key/af_key.c
86490 +++ b/net/key/af_key.c
86491 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
86492 static u32 get_acqseq(void)
86493 {
86494 u32 res;
86495 - static atomic_t acqseq;
86496 + static atomic_unchecked_t acqseq;
86497
86498 do {
86499 - res = atomic_inc_return(&acqseq);
86500 + res = atomic_inc_return_unchecked(&acqseq);
86501 } while (!res);
86502 return res;
86503 }
86504 diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
86505 index 716605c..044e9e1 100644
86506 --- a/net/l2tp/l2tp_ppp.c
86507 +++ b/net/l2tp/l2tp_ppp.c
86508 @@ -355,6 +355,7 @@ static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msgh
86509 l2tp_xmit_skb(session, skb, session->hdr_len);
86510
86511 sock_put(ps->tunnel_sock);
86512 + sock_put(sk);
86513
86514 return error;
86515
86516 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
86517 index 0479c64..d031db6 100644
86518 --- a/net/mac80211/cfg.c
86519 +++ b/net/mac80211/cfg.c
86520 @@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
86521 ret = ieee80211_vif_use_channel(sdata, chandef,
86522 IEEE80211_CHANCTX_EXCLUSIVE);
86523 }
86524 - } else if (local->open_count == local->monitors) {
86525 + } else if (local_read(&local->open_count) == local->monitors) {
86526 local->_oper_channel = chandef->chan;
86527 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
86528 ieee80211_hw_config(local, 0);
86529 @@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
86530 else
86531 local->probe_req_reg--;
86532
86533 - if (!local->open_count)
86534 + if (!local_read(&local->open_count))
86535 break;
86536
86537 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
86538 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
86539 index 2ed065c..948177f 100644
86540 --- a/net/mac80211/ieee80211_i.h
86541 +++ b/net/mac80211/ieee80211_i.h
86542 @@ -28,6 +28,7 @@
86543 #include <net/ieee80211_radiotap.h>
86544 #include <net/cfg80211.h>
86545 #include <net/mac80211.h>
86546 +#include <asm/local.h>
86547 #include "key.h"
86548 #include "sta_info.h"
86549 #include "debug.h"
86550 @@ -909,7 +910,7 @@ struct ieee80211_local {
86551 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
86552 spinlock_t queue_stop_reason_lock;
86553
86554 - int open_count;
86555 + local_t open_count;
86556 int monitors, cooked_mntrs;
86557 /* number of interfaces with corresponding FIF_ flags */
86558 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
86559 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
86560 index 8be854e..ad72a69 100644
86561 --- a/net/mac80211/iface.c
86562 +++ b/net/mac80211/iface.c
86563 @@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86564 break;
86565 }
86566
86567 - if (local->open_count == 0) {
86568 + if (local_read(&local->open_count) == 0) {
86569 res = drv_start(local);
86570 if (res)
86571 goto err_del_bss;
86572 @@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86573 break;
86574 }
86575
86576 - if (local->monitors == 0 && local->open_count == 0) {
86577 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
86578 res = ieee80211_add_virtual_monitor(local);
86579 if (res)
86580 goto err_stop;
86581 @@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86582 mutex_unlock(&local->mtx);
86583
86584 if (coming_up)
86585 - local->open_count++;
86586 + local_inc(&local->open_count);
86587
86588 if (hw_reconf_flags)
86589 ieee80211_hw_config(local, hw_reconf_flags);
86590 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86591 err_del_interface:
86592 drv_remove_interface(local, sdata);
86593 err_stop:
86594 - if (!local->open_count)
86595 + if (!local_read(&local->open_count))
86596 drv_stop(local);
86597 err_del_bss:
86598 sdata->bss = NULL;
86599 @@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86600 }
86601
86602 if (going_down)
86603 - local->open_count--;
86604 + local_dec(&local->open_count);
86605
86606 switch (sdata->vif.type) {
86607 case NL80211_IFTYPE_AP_VLAN:
86608 @@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86609
86610 ieee80211_recalc_ps(local, -1);
86611
86612 - if (local->open_count == 0) {
86613 + if (local_read(&local->open_count) == 0) {
86614 if (local->ops->napi_poll)
86615 napi_disable(&local->napi);
86616 ieee80211_clear_tx_pending(local);
86617 @@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86618 }
86619 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
86620
86621 - if (local->monitors == local->open_count && local->monitors > 0)
86622 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
86623 ieee80211_add_virtual_monitor(local);
86624 }
86625
86626 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
86627 index 1b087ff..bf600e9 100644
86628 --- a/net/mac80211/main.c
86629 +++ b/net/mac80211/main.c
86630 @@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
86631 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
86632 IEEE80211_CONF_CHANGE_POWER);
86633
86634 - if (changed && local->open_count) {
86635 + if (changed && local_read(&local->open_count)) {
86636 ret = drv_config(local, changed);
86637 /*
86638 * Goal:
86639 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
86640 index 79a48f3..5e185c9 100644
86641 --- a/net/mac80211/pm.c
86642 +++ b/net/mac80211/pm.c
86643 @@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86644 struct sta_info *sta;
86645 struct ieee80211_chanctx *ctx;
86646
86647 - if (!local->open_count)
86648 + if (!local_read(&local->open_count))
86649 goto suspend;
86650
86651 ieee80211_scan_cancel(local);
86652 @@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86653 cancel_work_sync(&local->dynamic_ps_enable_work);
86654 del_timer_sync(&local->dynamic_ps_timer);
86655
86656 - local->wowlan = wowlan && local->open_count;
86657 + local->wowlan = wowlan && local_read(&local->open_count);
86658 if (local->wowlan) {
86659 int err = drv_suspend(local, wowlan);
86660 if (err < 0) {
86661 @@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86662 mutex_unlock(&local->chanctx_mtx);
86663
86664 /* stop hardware - this must stop RX */
86665 - if (local->open_count)
86666 + if (local_read(&local->open_count))
86667 ieee80211_stop_device(local);
86668
86669 suspend:
86670 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
86671 index dd88381..eef4dd6 100644
86672 --- a/net/mac80211/rate.c
86673 +++ b/net/mac80211/rate.c
86674 @@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
86675
86676 ASSERT_RTNL();
86677
86678 - if (local->open_count)
86679 + if (local_read(&local->open_count))
86680 return -EBUSY;
86681
86682 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
86683 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
86684 index c97a065..ff61928 100644
86685 --- a/net/mac80211/rc80211_pid_debugfs.c
86686 +++ b/net/mac80211/rc80211_pid_debugfs.c
86687 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
86688
86689 spin_unlock_irqrestore(&events->lock, status);
86690
86691 - if (copy_to_user(buf, pb, p))
86692 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
86693 return -EFAULT;
86694
86695 return p;
86696 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
86697 index f11e8c5..08d0013 100644
86698 --- a/net/mac80211/util.c
86699 +++ b/net/mac80211/util.c
86700 @@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
86701 }
86702 #endif
86703 /* everything else happens only if HW was up & running */
86704 - if (!local->open_count)
86705 + if (!local_read(&local->open_count))
86706 goto wake_up;
86707
86708 /*
86709 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
86710 index 49e96df..63a51c3 100644
86711 --- a/net/netfilter/Kconfig
86712 +++ b/net/netfilter/Kconfig
86713 @@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
86714
86715 To compile it as a module, choose M here. If unsure, say N.
86716
86717 +config NETFILTER_XT_MATCH_GRADM
86718 + tristate '"gradm" match support'
86719 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
86720 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
86721 + ---help---
86722 + The gradm match allows to match on grsecurity RBAC being enabled.
86723 + It is useful when iptables rules are applied early on bootup to
86724 + prevent connections to the machine (except from a trusted host)
86725 + while the RBAC system is disabled.
86726 +
86727 config NETFILTER_XT_MATCH_HASHLIMIT
86728 tristate '"hashlimit" match support'
86729 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
86730 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
86731 index 3259697..54d5393 100644
86732 --- a/net/netfilter/Makefile
86733 +++ b/net/netfilter/Makefile
86734 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
86735 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
86736 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
86737 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
86738 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
86739 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
86740 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
86741 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
86742 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
86743 index 6d6d8f2..a676749 100644
86744 --- a/net/netfilter/ipset/ip_set_core.c
86745 +++ b/net/netfilter/ipset/ip_set_core.c
86746 @@ -1800,7 +1800,7 @@ done:
86747 return ret;
86748 }
86749
86750 -static struct nf_sockopt_ops so_set __read_mostly = {
86751 +static struct nf_sockopt_ops so_set = {
86752 .pf = PF_INET,
86753 .get_optmin = SO_IP_SET,
86754 .get_optmax = SO_IP_SET + 1,
86755 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
86756 index 30e764a..c3b6a9d 100644
86757 --- a/net/netfilter/ipvs/ip_vs_conn.c
86758 +++ b/net/netfilter/ipvs/ip_vs_conn.c
86759 @@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
86760 /* Increase the refcnt counter of the dest */
86761 atomic_inc(&dest->refcnt);
86762
86763 - conn_flags = atomic_read(&dest->conn_flags);
86764 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
86765 if (cp->protocol != IPPROTO_UDP)
86766 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
86767 flags = cp->flags;
86768 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
86769 atomic_set(&cp->refcnt, 1);
86770
86771 atomic_set(&cp->n_control, 0);
86772 - atomic_set(&cp->in_pkts, 0);
86773 + atomic_set_unchecked(&cp->in_pkts, 0);
86774
86775 atomic_inc(&ipvs->conn_count);
86776 if (flags & IP_VS_CONN_F_NO_CPORT)
86777 @@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
86778
86779 /* Don't drop the entry if its number of incoming packets is not
86780 located in [0, 8] */
86781 - i = atomic_read(&cp->in_pkts);
86782 + i = atomic_read_unchecked(&cp->in_pkts);
86783 if (i > 8 || i < 0) return 0;
86784
86785 if (!todrop_rate[i]) return 0;
86786 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
86787 index 47edf5a..235b07d 100644
86788 --- a/net/netfilter/ipvs/ip_vs_core.c
86789 +++ b/net/netfilter/ipvs/ip_vs_core.c
86790 @@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
86791 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
86792 /* do not touch skb anymore */
86793
86794 - atomic_inc(&cp->in_pkts);
86795 + atomic_inc_unchecked(&cp->in_pkts);
86796 ip_vs_conn_put(cp);
86797 return ret;
86798 }
86799 @@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
86800 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
86801 pkts = sysctl_sync_threshold(ipvs);
86802 else
86803 - pkts = atomic_add_return(1, &cp->in_pkts);
86804 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86805
86806 if (ipvs->sync_state & IP_VS_STATE_MASTER)
86807 ip_vs_sync_conn(net, cp, pkts);
86808 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
86809 index ec664cb..7f34a77 100644
86810 --- a/net/netfilter/ipvs/ip_vs_ctl.c
86811 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
86812 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
86813 ip_vs_rs_hash(ipvs, dest);
86814 write_unlock_bh(&ipvs->rs_lock);
86815 }
86816 - atomic_set(&dest->conn_flags, conn_flags);
86817 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
86818
86819 /* bind the service */
86820 if (!dest->svc) {
86821 @@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
86822 * align with netns init in ip_vs_control_net_init()
86823 */
86824
86825 -static struct ctl_table vs_vars[] = {
86826 +static ctl_table_no_const vs_vars[] __read_only = {
86827 {
86828 .procname = "amemthresh",
86829 .maxlen = sizeof(int),
86830 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
86831 " %-7s %-6d %-10d %-10d\n",
86832 &dest->addr.in6,
86833 ntohs(dest->port),
86834 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
86835 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
86836 atomic_read(&dest->weight),
86837 atomic_read(&dest->activeconns),
86838 atomic_read(&dest->inactconns));
86839 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
86840 "%-7s %-6d %-10d %-10d\n",
86841 ntohl(dest->addr.ip),
86842 ntohs(dest->port),
86843 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
86844 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
86845 atomic_read(&dest->weight),
86846 atomic_read(&dest->activeconns),
86847 atomic_read(&dest->inactconns));
86848 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
86849
86850 entry.addr = dest->addr.ip;
86851 entry.port = dest->port;
86852 - entry.conn_flags = atomic_read(&dest->conn_flags);
86853 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
86854 entry.weight = atomic_read(&dest->weight);
86855 entry.u_threshold = dest->u_threshold;
86856 entry.l_threshold = dest->l_threshold;
86857 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
86858 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
86859 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
86860 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
86861 - (atomic_read(&dest->conn_flags) &
86862 + (atomic_read_unchecked(&dest->conn_flags) &
86863 IP_VS_CONN_F_FWD_MASK)) ||
86864 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
86865 atomic_read(&dest->weight)) ||
86866 @@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
86867 {
86868 int idx;
86869 struct netns_ipvs *ipvs = net_ipvs(net);
86870 - struct ctl_table *tbl;
86871 + ctl_table_no_const *tbl;
86872
86873 atomic_set(&ipvs->dropentry, 0);
86874 spin_lock_init(&ipvs->dropentry_lock);
86875 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
86876 index fdd89b9..bd96aa9 100644
86877 --- a/net/netfilter/ipvs/ip_vs_lblc.c
86878 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
86879 @@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
86880 * IPVS LBLC sysctl table
86881 */
86882 #ifdef CONFIG_SYSCTL
86883 -static ctl_table vs_vars_table[] = {
86884 +static ctl_table_no_const vs_vars_table[] __read_only = {
86885 {
86886 .procname = "lblc_expiration",
86887 .data = NULL,
86888 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
86889 index c03b6a3..8ce3681 100644
86890 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
86891 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
86892 @@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
86893 * IPVS LBLCR sysctl table
86894 */
86895
86896 -static ctl_table vs_vars_table[] = {
86897 +static ctl_table_no_const vs_vars_table[] __read_only = {
86898 {
86899 .procname = "lblcr_expiration",
86900 .data = NULL,
86901 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
86902 index 44fd10c..2a163b3 100644
86903 --- a/net/netfilter/ipvs/ip_vs_sync.c
86904 +++ b/net/netfilter/ipvs/ip_vs_sync.c
86905 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
86906 cp = cp->control;
86907 if (cp) {
86908 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
86909 - pkts = atomic_add_return(1, &cp->in_pkts);
86910 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86911 else
86912 pkts = sysctl_sync_threshold(ipvs);
86913 ip_vs_sync_conn(net, cp->control, pkts);
86914 @@ -758,7 +758,7 @@ control:
86915 if (!cp)
86916 return;
86917 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
86918 - pkts = atomic_add_return(1, &cp->in_pkts);
86919 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86920 else
86921 pkts = sysctl_sync_threshold(ipvs);
86922 goto sloop;
86923 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
86924
86925 if (opt)
86926 memcpy(&cp->in_seq, opt, sizeof(*opt));
86927 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
86928 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
86929 cp->state = state;
86930 cp->old_state = cp->state;
86931 /*
86932 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
86933 index ee6b7a9..f9a89f6 100644
86934 --- a/net/netfilter/ipvs/ip_vs_xmit.c
86935 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
86936 @@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
86937 else
86938 rc = NF_ACCEPT;
86939 /* do not touch skb anymore */
86940 - atomic_inc(&cp->in_pkts);
86941 + atomic_inc_unchecked(&cp->in_pkts);
86942 goto out;
86943 }
86944
86945 @@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
86946 else
86947 rc = NF_ACCEPT;
86948 /* do not touch skb anymore */
86949 - atomic_inc(&cp->in_pkts);
86950 + atomic_inc_unchecked(&cp->in_pkts);
86951 goto out;
86952 }
86953
86954 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
86955 index 7df424e..a527b02 100644
86956 --- a/net/netfilter/nf_conntrack_acct.c
86957 +++ b/net/netfilter/nf_conntrack_acct.c
86958 @@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
86959 #ifdef CONFIG_SYSCTL
86960 static int nf_conntrack_acct_init_sysctl(struct net *net)
86961 {
86962 - struct ctl_table *table;
86963 + ctl_table_no_const *table;
86964
86965 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
86966 GFP_KERNEL);
86967 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
86968 index e4a0c4f..c263f28 100644
86969 --- a/net/netfilter/nf_conntrack_core.c
86970 +++ b/net/netfilter/nf_conntrack_core.c
86971 @@ -1529,6 +1529,10 @@ err_extend:
86972 #define DYING_NULLS_VAL ((1<<30)+1)
86973 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
86974
86975 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86976 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
86977 +#endif
86978 +
86979 static int nf_conntrack_init_net(struct net *net)
86980 {
86981 int ret;
86982 @@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
86983 goto err_stat;
86984 }
86985
86986 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86987 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
86988 +#else
86989 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
86990 +#endif
86991 if (!net->ct.slabname) {
86992 ret = -ENOMEM;
86993 goto err_slabname;
86994 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
86995 index faa978f..1afb18f 100644
86996 --- a/net/netfilter/nf_conntrack_ecache.c
86997 +++ b/net/netfilter/nf_conntrack_ecache.c
86998 @@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
86999 #ifdef CONFIG_SYSCTL
87000 static int nf_conntrack_event_init_sysctl(struct net *net)
87001 {
87002 - struct ctl_table *table;
87003 + ctl_table_no_const *table;
87004
87005 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
87006 GFP_KERNEL);
87007 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
87008 index 884f2b3..d53b33a 100644
87009 --- a/net/netfilter/nf_conntrack_helper.c
87010 +++ b/net/netfilter/nf_conntrack_helper.c
87011 @@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
87012
87013 static int nf_conntrack_helper_init_sysctl(struct net *net)
87014 {
87015 - struct ctl_table *table;
87016 + ctl_table_no_const *table;
87017
87018 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
87019 GFP_KERNEL);
87020 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
87021 index 51e928d..72a413a 100644
87022 --- a/net/netfilter/nf_conntrack_proto.c
87023 +++ b/net/netfilter/nf_conntrack_proto.c
87024 @@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
87025
87026 static void
87027 nf_ct_unregister_sysctl(struct ctl_table_header **header,
87028 - struct ctl_table **table,
87029 + ctl_table_no_const **table,
87030 unsigned int users)
87031 {
87032 if (users > 0)
87033 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
87034 index e7185c6..4ad6c9c 100644
87035 --- a/net/netfilter/nf_conntrack_standalone.c
87036 +++ b/net/netfilter/nf_conntrack_standalone.c
87037 @@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
87038
87039 static int nf_conntrack_standalone_init_sysctl(struct net *net)
87040 {
87041 - struct ctl_table *table;
87042 + ctl_table_no_const *table;
87043
87044 if (net_eq(net, &init_net)) {
87045 nf_ct_netfilter_header =
87046 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
87047 index 7ea8026..bc9512d 100644
87048 --- a/net/netfilter/nf_conntrack_timestamp.c
87049 +++ b/net/netfilter/nf_conntrack_timestamp.c
87050 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
87051 #ifdef CONFIG_SYSCTL
87052 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
87053 {
87054 - struct ctl_table *table;
87055 + ctl_table_no_const *table;
87056
87057 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
87058 GFP_KERNEL);
87059 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
87060 index 9e31269..bc4c1b7 100644
87061 --- a/net/netfilter/nf_log.c
87062 +++ b/net/netfilter/nf_log.c
87063 @@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
87064
87065 #ifdef CONFIG_SYSCTL
87066 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
87067 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
87068 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
87069 static struct ctl_table_header *nf_log_dir_header;
87070
87071 static int nf_log_proc_dostring(ctl_table *table, int write,
87072 @@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
87073 rcu_assign_pointer(nf_loggers[tindex], logger);
87074 mutex_unlock(&nf_log_mutex);
87075 } else {
87076 + ctl_table_no_const nf_log_table = *table;
87077 +
87078 mutex_lock(&nf_log_mutex);
87079 logger = rcu_dereference_protected(nf_loggers[tindex],
87080 lockdep_is_held(&nf_log_mutex));
87081 if (!logger)
87082 - table->data = "NONE";
87083 + nf_log_table.data = "NONE";
87084 else
87085 - table->data = logger->name;
87086 - r = proc_dostring(table, write, buffer, lenp, ppos);
87087 + nf_log_table.data = logger->name;
87088 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
87089 mutex_unlock(&nf_log_mutex);
87090 }
87091
87092 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
87093 index f042ae5..30ea486 100644
87094 --- a/net/netfilter/nf_sockopt.c
87095 +++ b/net/netfilter/nf_sockopt.c
87096 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
87097 }
87098 }
87099
87100 - list_add(&reg->list, &nf_sockopts);
87101 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
87102 out:
87103 mutex_unlock(&nf_sockopt_mutex);
87104 return ret;
87105 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
87106 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
87107 {
87108 mutex_lock(&nf_sockopt_mutex);
87109 - list_del(&reg->list);
87110 + pax_list_del((struct list_head *)&reg->list);
87111 mutex_unlock(&nf_sockopt_mutex);
87112 }
87113 EXPORT_SYMBOL(nf_unregister_sockopt);
87114 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
87115 index 92fd8ec..3f6ea4b 100644
87116 --- a/net/netfilter/nfnetlink_log.c
87117 +++ b/net/netfilter/nfnetlink_log.c
87118 @@ -72,7 +72,7 @@ struct nfulnl_instance {
87119 };
87120
87121 static DEFINE_SPINLOCK(instances_lock);
87122 -static atomic_t global_seq;
87123 +static atomic_unchecked_t global_seq;
87124
87125 #define INSTANCE_BUCKETS 16
87126 static struct hlist_head instance_table[INSTANCE_BUCKETS];
87127 @@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
87128 /* global sequence number */
87129 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
87130 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
87131 - htonl(atomic_inc_return(&global_seq))))
87132 + htonl(atomic_inc_return_unchecked(&global_seq))))
87133 goto nla_put_failure;
87134
87135 if (data_len) {
87136 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
87137 new file mode 100644
87138 index 0000000..c566332
87139 --- /dev/null
87140 +++ b/net/netfilter/xt_gradm.c
87141 @@ -0,0 +1,51 @@
87142 +/*
87143 + * gradm match for netfilter
87144 + * Copyright © Zbigniew Krzystolik, 2010
87145 + *
87146 + * This program is free software; you can redistribute it and/or modify
87147 + * it under the terms of the GNU General Public License; either version
87148 + * 2 or 3 as published by the Free Software Foundation.
87149 + */
87150 +#include <linux/module.h>
87151 +#include <linux/moduleparam.h>
87152 +#include <linux/skbuff.h>
87153 +#include <linux/netfilter/x_tables.h>
87154 +#include <linux/grsecurity.h>
87155 +#include <linux/netfilter/xt_gradm.h>
87156 +
87157 +static bool
87158 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
87159 +{
87160 + const struct xt_gradm_mtinfo *info = par->matchinfo;
87161 + bool retval = false;
87162 + if (gr_acl_is_enabled())
87163 + retval = true;
87164 + return retval ^ info->invflags;
87165 +}
87166 +
87167 +static struct xt_match gradm_mt_reg __read_mostly = {
87168 + .name = "gradm",
87169 + .revision = 0,
87170 + .family = NFPROTO_UNSPEC,
87171 + .match = gradm_mt,
87172 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
87173 + .me = THIS_MODULE,
87174 +};
87175 +
87176 +static int __init gradm_mt_init(void)
87177 +{
87178 + return xt_register_match(&gradm_mt_reg);
87179 +}
87180 +
87181 +static void __exit gradm_mt_exit(void)
87182 +{
87183 + xt_unregister_match(&gradm_mt_reg);
87184 +}
87185 +
87186 +module_init(gradm_mt_init);
87187 +module_exit(gradm_mt_exit);
87188 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
87189 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
87190 +MODULE_LICENSE("GPL");
87191 +MODULE_ALIAS("ipt_gradm");
87192 +MODULE_ALIAS("ip6t_gradm");
87193 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
87194 index 4fe4fb4..87a89e5 100644
87195 --- a/net/netfilter/xt_statistic.c
87196 +++ b/net/netfilter/xt_statistic.c
87197 @@ -19,7 +19,7 @@
87198 #include <linux/module.h>
87199
87200 struct xt_statistic_priv {
87201 - atomic_t count;
87202 + atomic_unchecked_t count;
87203 } ____cacheline_aligned_in_smp;
87204
87205 MODULE_LICENSE("GPL");
87206 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
87207 break;
87208 case XT_STATISTIC_MODE_NTH:
87209 do {
87210 - oval = atomic_read(&info->master->count);
87211 + oval = atomic_read_unchecked(&info->master->count);
87212 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
87213 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
87214 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
87215 if (nval == 0)
87216 ret = !ret;
87217 break;
87218 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
87219 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
87220 if (info->master == NULL)
87221 return -ENOMEM;
87222 - atomic_set(&info->master->count, info->u.nth.count);
87223 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
87224
87225 return 0;
87226 }
87227 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
87228 index c0353d5..fcb0270 100644
87229 --- a/net/netlink/af_netlink.c
87230 +++ b/net/netlink/af_netlink.c
87231 @@ -785,7 +785,7 @@ static void netlink_overrun(struct sock *sk)
87232 sk->sk_error_report(sk);
87233 }
87234 }
87235 - atomic_inc(&sk->sk_drops);
87236 + atomic_inc_unchecked(&sk->sk_drops);
87237 }
87238
87239 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
87240 @@ -2071,7 +2071,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
87241 sk_wmem_alloc_get(s),
87242 nlk->cb,
87243 atomic_read(&s->sk_refcnt),
87244 - atomic_read(&s->sk_drops),
87245 + atomic_read_unchecked(&s->sk_drops),
87246 sock_i_ino(s)
87247 );
87248
87249 diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
87250 index f2aabb6..2e5e66e 100644
87251 --- a/net/netlink/genetlink.c
87252 +++ b/net/netlink/genetlink.c
87253 @@ -295,18 +295,20 @@ int genl_register_ops(struct genl_family *family, struct genl_ops *ops)
87254 goto errout;
87255 }
87256
87257 + pax_open_kernel();
87258 if (ops->dumpit)
87259 - ops->flags |= GENL_CMD_CAP_DUMP;
87260 + *(unsigned int *)&ops->flags |= GENL_CMD_CAP_DUMP;
87261 if (ops->doit)
87262 - ops->flags |= GENL_CMD_CAP_DO;
87263 + *(unsigned int *)&ops->flags |= GENL_CMD_CAP_DO;
87264 if (ops->policy)
87265 - ops->flags |= GENL_CMD_CAP_HASPOL;
87266 + *(unsigned int *)&ops->flags |= GENL_CMD_CAP_HASPOL;
87267 + pax_close_kernel();
87268
87269 genl_lock();
87270 - list_add_tail(&ops->ops_list, &family->ops_list);
87271 + pax_list_add_tail((struct list_head *)&ops->ops_list, &family->ops_list);
87272 genl_unlock();
87273
87274 - genl_ctrl_event(CTRL_CMD_NEWOPS, ops);
87275 + genl_ctrl_event(CTRL_CMD_NEWOPS, (void *)ops);
87276 err = 0;
87277 errout:
87278 return err;
87279 @@ -336,9 +338,9 @@ int genl_unregister_ops(struct genl_family *family, struct genl_ops *ops)
87280 genl_lock();
87281 list_for_each_entry(rc, &family->ops_list, ops_list) {
87282 if (rc == ops) {
87283 - list_del(&ops->ops_list);
87284 + pax_list_del((struct list_head *)&ops->ops_list);
87285 genl_unlock();
87286 - genl_ctrl_event(CTRL_CMD_DELOPS, ops);
87287 + genl_ctrl_event(CTRL_CMD_DELOPS, (void *)ops);
87288 return 0;
87289 }
87290 }
87291 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
87292 index 7261eb8..44e8ac6 100644
87293 --- a/net/netrom/af_netrom.c
87294 +++ b/net/netrom/af_netrom.c
87295 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
87296 struct sock *sk = sock->sk;
87297 struct nr_sock *nr = nr_sk(sk);
87298
87299 + memset(sax, 0, sizeof(*sax));
87300 lock_sock(sk);
87301 if (peer != 0) {
87302 if (sk->sk_state != TCP_ESTABLISHED) {
87303 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
87304 *uaddr_len = sizeof(struct full_sockaddr_ax25);
87305 } else {
87306 sax->fsa_ax25.sax25_family = AF_NETROM;
87307 - sax->fsa_ax25.sax25_ndigis = 0;
87308 sax->fsa_ax25.sax25_call = nr->source_addr;
87309 *uaddr_len = sizeof(struct sockaddr_ax25);
87310 }
87311 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
87312 index c111bd0..7788ff7 100644
87313 --- a/net/packet/af_packet.c
87314 +++ b/net/packet/af_packet.c
87315 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
87316
87317 spin_lock(&sk->sk_receive_queue.lock);
87318 po->stats.tp_packets++;
87319 - skb->dropcount = atomic_read(&sk->sk_drops);
87320 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
87321 __skb_queue_tail(&sk->sk_receive_queue, skb);
87322 spin_unlock(&sk->sk_receive_queue.lock);
87323 sk->sk_data_ready(sk, skb->len);
87324 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
87325 drop_n_acct:
87326 spin_lock(&sk->sk_receive_queue.lock);
87327 po->stats.tp_drops++;
87328 - atomic_inc(&sk->sk_drops);
87329 + atomic_inc_unchecked(&sk->sk_drops);
87330 spin_unlock(&sk->sk_receive_queue.lock);
87331
87332 drop_n_restore:
87333 @@ -2565,6 +2565,7 @@ out:
87334
87335 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
87336 {
87337 + struct sock_extended_err ee;
87338 struct sock_exterr_skb *serr;
87339 struct sk_buff *skb, *skb2;
87340 int copied, err;
87341 @@ -2586,8 +2587,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
87342 sock_recv_timestamp(msg, sk, skb);
87343
87344 serr = SKB_EXT_ERR(skb);
87345 + ee = serr->ee;
87346 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
87347 - sizeof(serr->ee), &serr->ee);
87348 + sizeof ee, &ee);
87349
87350 msg->msg_flags |= MSG_ERRQUEUE;
87351 err = copied;
87352 @@ -3212,7 +3214,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
87353 case PACKET_HDRLEN:
87354 if (len > sizeof(int))
87355 len = sizeof(int);
87356 - if (copy_from_user(&val, optval, len))
87357 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
87358 return -EFAULT;
87359 switch (val) {
87360 case TPACKET_V1:
87361 @@ -3254,7 +3256,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
87362 len = lv;
87363 if (put_user(len, optlen))
87364 return -EFAULT;
87365 - if (copy_to_user(optval, data, len))
87366 + if (len > sizeof(st) || copy_to_user(optval, data, len))
87367 return -EFAULT;
87368 return 0;
87369 }
87370 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
87371 index 5a940db..f0b9c12 100644
87372 --- a/net/phonet/af_phonet.c
87373 +++ b/net/phonet/af_phonet.c
87374 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
87375 {
87376 struct phonet_protocol *pp;
87377
87378 - if (protocol >= PHONET_NPROTO)
87379 + if (protocol < 0 || protocol >= PHONET_NPROTO)
87380 return NULL;
87381
87382 rcu_read_lock();
87383 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
87384 {
87385 int err = 0;
87386
87387 - if (protocol >= PHONET_NPROTO)
87388 + if (protocol < 0 || protocol >= PHONET_NPROTO)
87389 return -EINVAL;
87390
87391 err = proto_register(pp->prot, 1);
87392 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
87393 index 576f22c..bc7a71b 100644
87394 --- a/net/phonet/pep.c
87395 +++ b/net/phonet/pep.c
87396 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
87397
87398 case PNS_PEP_CTRL_REQ:
87399 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
87400 - atomic_inc(&sk->sk_drops);
87401 + atomic_inc_unchecked(&sk->sk_drops);
87402 break;
87403 }
87404 __skb_pull(skb, 4);
87405 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
87406 }
87407
87408 if (pn->rx_credits == 0) {
87409 - atomic_inc(&sk->sk_drops);
87410 + atomic_inc_unchecked(&sk->sk_drops);
87411 err = -ENOBUFS;
87412 break;
87413 }
87414 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
87415 }
87416
87417 if (pn->rx_credits == 0) {
87418 - atomic_inc(&sk->sk_drops);
87419 + atomic_inc_unchecked(&sk->sk_drops);
87420 err = NET_RX_DROP;
87421 break;
87422 }
87423 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
87424 index b7e9827..c264c85 100644
87425 --- a/net/phonet/socket.c
87426 +++ b/net/phonet/socket.c
87427 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
87428 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
87429 sock_i_ino(sk),
87430 atomic_read(&sk->sk_refcnt), sk,
87431 - atomic_read(&sk->sk_drops), &len);
87432 + atomic_read_unchecked(&sk->sk_drops), &len);
87433 }
87434 seq_printf(seq, "%*s\n", 127 - len, "");
87435 return 0;
87436 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
87437 index d6bbbbd..61561e4 100644
87438 --- a/net/phonet/sysctl.c
87439 +++ b/net/phonet/sysctl.c
87440 @@ -67,7 +67,7 @@ static int proc_local_port_range(ctl_table *table, int write,
87441 {
87442 int ret;
87443 int range[2] = {local_port_range[0], local_port_range[1]};
87444 - ctl_table tmp = {
87445 + ctl_table_no_const tmp = {
87446 .data = &range,
87447 .maxlen = sizeof(range),
87448 .mode = table->mode,
87449 diff --git a/net/rds/cong.c b/net/rds/cong.c
87450 index e5b65ac..f3b6fb7 100644
87451 --- a/net/rds/cong.c
87452 +++ b/net/rds/cong.c
87453 @@ -78,7 +78,7 @@
87454 * finds that the saved generation number is smaller than the global generation
87455 * number, it wakes up the process.
87456 */
87457 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
87458 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
87459
87460 /*
87461 * Congestion monitoring
87462 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
87463 rdsdebug("waking map %p for %pI4\n",
87464 map, &map->m_addr);
87465 rds_stats_inc(s_cong_update_received);
87466 - atomic_inc(&rds_cong_generation);
87467 + atomic_inc_unchecked(&rds_cong_generation);
87468 if (waitqueue_active(&map->m_waitq))
87469 wake_up(&map->m_waitq);
87470 if (waitqueue_active(&rds_poll_waitq))
87471 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
87472
87473 int rds_cong_updated_since(unsigned long *recent)
87474 {
87475 - unsigned long gen = atomic_read(&rds_cong_generation);
87476 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
87477
87478 if (likely(*recent == gen))
87479 return 0;
87480 diff --git a/net/rds/ib.h b/net/rds/ib.h
87481 index 7280ab8..e04f4ea 100644
87482 --- a/net/rds/ib.h
87483 +++ b/net/rds/ib.h
87484 @@ -128,7 +128,7 @@ struct rds_ib_connection {
87485 /* sending acks */
87486 unsigned long i_ack_flags;
87487 #ifdef KERNEL_HAS_ATOMIC64
87488 - atomic64_t i_ack_next; /* next ACK to send */
87489 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
87490 #else
87491 spinlock_t i_ack_lock; /* protect i_ack_next */
87492 u64 i_ack_next; /* next ACK to send */
87493 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
87494 index 31b74f5..dc1fbfa 100644
87495 --- a/net/rds/ib_cm.c
87496 +++ b/net/rds/ib_cm.c
87497 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
87498 /* Clear the ACK state */
87499 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
87500 #ifdef KERNEL_HAS_ATOMIC64
87501 - atomic64_set(&ic->i_ack_next, 0);
87502 + atomic64_set_unchecked(&ic->i_ack_next, 0);
87503 #else
87504 ic->i_ack_next = 0;
87505 #endif
87506 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
87507 index 8eb9501..0c386ff 100644
87508 --- a/net/rds/ib_recv.c
87509 +++ b/net/rds/ib_recv.c
87510 @@ -597,7 +597,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
87511 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
87512 int ack_required)
87513 {
87514 - atomic64_set(&ic->i_ack_next, seq);
87515 + atomic64_set_unchecked(&ic->i_ack_next, seq);
87516 if (ack_required) {
87517 smp_mb__before_clear_bit();
87518 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87519 @@ -609,7 +609,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
87520 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87521 smp_mb__after_clear_bit();
87522
87523 - return atomic64_read(&ic->i_ack_next);
87524 + return atomic64_read_unchecked(&ic->i_ack_next);
87525 }
87526 #endif
87527
87528 diff --git a/net/rds/iw.h b/net/rds/iw.h
87529 index 04ce3b1..48119a6 100644
87530 --- a/net/rds/iw.h
87531 +++ b/net/rds/iw.h
87532 @@ -134,7 +134,7 @@ struct rds_iw_connection {
87533 /* sending acks */
87534 unsigned long i_ack_flags;
87535 #ifdef KERNEL_HAS_ATOMIC64
87536 - atomic64_t i_ack_next; /* next ACK to send */
87537 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
87538 #else
87539 spinlock_t i_ack_lock; /* protect i_ack_next */
87540 u64 i_ack_next; /* next ACK to send */
87541 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
87542 index a91e1db..cf3053f 100644
87543 --- a/net/rds/iw_cm.c
87544 +++ b/net/rds/iw_cm.c
87545 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
87546 /* Clear the ACK state */
87547 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
87548 #ifdef KERNEL_HAS_ATOMIC64
87549 - atomic64_set(&ic->i_ack_next, 0);
87550 + atomic64_set_unchecked(&ic->i_ack_next, 0);
87551 #else
87552 ic->i_ack_next = 0;
87553 #endif
87554 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
87555 index 4503335..db566b4 100644
87556 --- a/net/rds/iw_recv.c
87557 +++ b/net/rds/iw_recv.c
87558 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
87559 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
87560 int ack_required)
87561 {
87562 - atomic64_set(&ic->i_ack_next, seq);
87563 + atomic64_set_unchecked(&ic->i_ack_next, seq);
87564 if (ack_required) {
87565 smp_mb__before_clear_bit();
87566 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87567 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
87568 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87569 smp_mb__after_clear_bit();
87570
87571 - return atomic64_read(&ic->i_ack_next);
87572 + return atomic64_read_unchecked(&ic->i_ack_next);
87573 }
87574 #endif
87575
87576 diff --git a/net/rds/message.c b/net/rds/message.c
87577 index f0a4658..aff589c 100644
87578 --- a/net/rds/message.c
87579 +++ b/net/rds/message.c
87580 @@ -197,6 +197,9 @@ struct rds_message *rds_message_alloc(unsigned int extra_len, gfp_t gfp)
87581 {
87582 struct rds_message *rm;
87583
87584 + if (extra_len > KMALLOC_MAX_SIZE - sizeof(struct rds_message))
87585 + return NULL;
87586 +
87587 rm = kzalloc(sizeof(struct rds_message) + extra_len, gfp);
87588 if (!rm)
87589 goto out;
87590 diff --git a/net/rds/rds.h b/net/rds/rds.h
87591 index ec1d731..90a3a8d 100644
87592 --- a/net/rds/rds.h
87593 +++ b/net/rds/rds.h
87594 @@ -449,7 +449,7 @@ struct rds_transport {
87595 void (*sync_mr)(void *trans_private, int direction);
87596 void (*free_mr)(void *trans_private, int invalidate);
87597 void (*flush_mrs)(void);
87598 -};
87599 +} __do_const;
87600
87601 struct rds_sock {
87602 struct sock rs_sk;
87603 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
87604 index edac9ef..16bcb98 100644
87605 --- a/net/rds/tcp.c
87606 +++ b/net/rds/tcp.c
87607 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
87608 int val = 1;
87609
87610 set_fs(KERNEL_DS);
87611 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
87612 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
87613 sizeof(val));
87614 set_fs(oldfs);
87615 }
87616 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
87617 index 81cf5a4..b5826ff 100644
87618 --- a/net/rds/tcp_send.c
87619 +++ b/net/rds/tcp_send.c
87620 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
87621
87622 oldfs = get_fs();
87623 set_fs(KERNEL_DS);
87624 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
87625 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
87626 sizeof(val));
87627 set_fs(oldfs);
87628 }
87629 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
87630 index 05996d0..5a1dfe0 100644
87631 --- a/net/rxrpc/af_rxrpc.c
87632 +++ b/net/rxrpc/af_rxrpc.c
87633 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
87634 __be32 rxrpc_epoch;
87635
87636 /* current debugging ID */
87637 -atomic_t rxrpc_debug_id;
87638 +atomic_unchecked_t rxrpc_debug_id;
87639
87640 /* count of skbs currently in use */
87641 atomic_t rxrpc_n_skbs;
87642 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
87643 index e4d9cbc..b229649 100644
87644 --- a/net/rxrpc/ar-ack.c
87645 +++ b/net/rxrpc/ar-ack.c
87646 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
87647
87648 _enter("{%d,%d,%d,%d},",
87649 call->acks_hard, call->acks_unacked,
87650 - atomic_read(&call->sequence),
87651 + atomic_read_unchecked(&call->sequence),
87652 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
87653
87654 stop = 0;
87655 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
87656
87657 /* each Tx packet has a new serial number */
87658 sp->hdr.serial =
87659 - htonl(atomic_inc_return(&call->conn->serial));
87660 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
87661
87662 hdr = (struct rxrpc_header *) txb->head;
87663 hdr->serial = sp->hdr.serial;
87664 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
87665 */
87666 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
87667 {
87668 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
87669 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
87670 }
87671
87672 /*
87673 @@ -629,7 +629,7 @@ process_further:
87674
87675 latest = ntohl(sp->hdr.serial);
87676 hard = ntohl(ack.firstPacket);
87677 - tx = atomic_read(&call->sequence);
87678 + tx = atomic_read_unchecked(&call->sequence);
87679
87680 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
87681 latest,
87682 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
87683 goto maybe_reschedule;
87684
87685 send_ACK_with_skew:
87686 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
87687 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
87688 ntohl(ack.serial));
87689 send_ACK:
87690 mtu = call->conn->trans->peer->if_mtu;
87691 @@ -1173,7 +1173,7 @@ send_ACK:
87692 ackinfo.rxMTU = htonl(5692);
87693 ackinfo.jumbo_max = htonl(4);
87694
87695 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
87696 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
87697 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
87698 ntohl(hdr.serial),
87699 ntohs(ack.maxSkew),
87700 @@ -1191,7 +1191,7 @@ send_ACK:
87701 send_message:
87702 _debug("send message");
87703
87704 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
87705 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
87706 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
87707 send_message_2:
87708
87709 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
87710 index a3bbb36..3341fb9 100644
87711 --- a/net/rxrpc/ar-call.c
87712 +++ b/net/rxrpc/ar-call.c
87713 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
87714 spin_lock_init(&call->lock);
87715 rwlock_init(&call->state_lock);
87716 atomic_set(&call->usage, 1);
87717 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
87718 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87719 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
87720
87721 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
87722 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
87723 index 4106ca9..a338d7a 100644
87724 --- a/net/rxrpc/ar-connection.c
87725 +++ b/net/rxrpc/ar-connection.c
87726 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
87727 rwlock_init(&conn->lock);
87728 spin_lock_init(&conn->state_lock);
87729 atomic_set(&conn->usage, 1);
87730 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
87731 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87732 conn->avail_calls = RXRPC_MAXCALLS;
87733 conn->size_align = 4;
87734 conn->header_size = sizeof(struct rxrpc_header);
87735 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
87736 index e7ed43a..6afa140 100644
87737 --- a/net/rxrpc/ar-connevent.c
87738 +++ b/net/rxrpc/ar-connevent.c
87739 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
87740
87741 len = iov[0].iov_len + iov[1].iov_len;
87742
87743 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
87744 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
87745 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
87746
87747 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
87748 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
87749 index 529572f..c758ca7 100644
87750 --- a/net/rxrpc/ar-input.c
87751 +++ b/net/rxrpc/ar-input.c
87752 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
87753 /* track the latest serial number on this connection for ACK packet
87754 * information */
87755 serial = ntohl(sp->hdr.serial);
87756 - hi_serial = atomic_read(&call->conn->hi_serial);
87757 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
87758 while (serial > hi_serial)
87759 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
87760 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
87761 serial);
87762
87763 /* request ACK generation for any ACK or DATA packet that requests
87764 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
87765 index a693aca..81e7293 100644
87766 --- a/net/rxrpc/ar-internal.h
87767 +++ b/net/rxrpc/ar-internal.h
87768 @@ -272,8 +272,8 @@ struct rxrpc_connection {
87769 int error; /* error code for local abort */
87770 int debug_id; /* debug ID for printks */
87771 unsigned int call_counter; /* call ID counter */
87772 - atomic_t serial; /* packet serial number counter */
87773 - atomic_t hi_serial; /* highest serial number received */
87774 + atomic_unchecked_t serial; /* packet serial number counter */
87775 + atomic_unchecked_t hi_serial; /* highest serial number received */
87776 u8 avail_calls; /* number of calls available */
87777 u8 size_align; /* data size alignment (for security) */
87778 u8 header_size; /* rxrpc + security header size */
87779 @@ -346,7 +346,7 @@ struct rxrpc_call {
87780 spinlock_t lock;
87781 rwlock_t state_lock; /* lock for state transition */
87782 atomic_t usage;
87783 - atomic_t sequence; /* Tx data packet sequence counter */
87784 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
87785 u32 abort_code; /* local/remote abort code */
87786 enum { /* current state of call */
87787 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
87788 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
87789 */
87790 extern atomic_t rxrpc_n_skbs;
87791 extern __be32 rxrpc_epoch;
87792 -extern atomic_t rxrpc_debug_id;
87793 +extern atomic_unchecked_t rxrpc_debug_id;
87794 extern struct workqueue_struct *rxrpc_workqueue;
87795
87796 /*
87797 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
87798 index 87f7135..74d3703 100644
87799 --- a/net/rxrpc/ar-local.c
87800 +++ b/net/rxrpc/ar-local.c
87801 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
87802 spin_lock_init(&local->lock);
87803 rwlock_init(&local->services_lock);
87804 atomic_set(&local->usage, 1);
87805 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
87806 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87807 memcpy(&local->srx, srx, sizeof(*srx));
87808 }
87809
87810 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
87811 index e1ac183..b43e10e 100644
87812 --- a/net/rxrpc/ar-output.c
87813 +++ b/net/rxrpc/ar-output.c
87814 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
87815 sp->hdr.cid = call->cid;
87816 sp->hdr.callNumber = call->call_id;
87817 sp->hdr.seq =
87818 - htonl(atomic_inc_return(&call->sequence));
87819 + htonl(atomic_inc_return_unchecked(&call->sequence));
87820 sp->hdr.serial =
87821 - htonl(atomic_inc_return(&conn->serial));
87822 + htonl(atomic_inc_return_unchecked(&conn->serial));
87823 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
87824 sp->hdr.userStatus = 0;
87825 sp->hdr.securityIndex = conn->security_ix;
87826 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
87827 index bebaa43..2644591 100644
87828 --- a/net/rxrpc/ar-peer.c
87829 +++ b/net/rxrpc/ar-peer.c
87830 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
87831 INIT_LIST_HEAD(&peer->error_targets);
87832 spin_lock_init(&peer->lock);
87833 atomic_set(&peer->usage, 1);
87834 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
87835 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87836 memcpy(&peer->srx, srx, sizeof(*srx));
87837
87838 rxrpc_assess_MTU_size(peer);
87839 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
87840 index 38047f7..9f48511 100644
87841 --- a/net/rxrpc/ar-proc.c
87842 +++ b/net/rxrpc/ar-proc.c
87843 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
87844 atomic_read(&conn->usage),
87845 rxrpc_conn_states[conn->state],
87846 key_serial(conn->key),
87847 - atomic_read(&conn->serial),
87848 - atomic_read(&conn->hi_serial));
87849 + atomic_read_unchecked(&conn->serial),
87850 + atomic_read_unchecked(&conn->hi_serial));
87851
87852 return 0;
87853 }
87854 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
87855 index 92df566..87ec1bf 100644
87856 --- a/net/rxrpc/ar-transport.c
87857 +++ b/net/rxrpc/ar-transport.c
87858 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
87859 spin_lock_init(&trans->client_lock);
87860 rwlock_init(&trans->conn_lock);
87861 atomic_set(&trans->usage, 1);
87862 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
87863 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87864
87865 if (peer->srx.transport.family == AF_INET) {
87866 switch (peer->srx.transport_type) {
87867 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
87868 index f226709..0e735a8 100644
87869 --- a/net/rxrpc/rxkad.c
87870 +++ b/net/rxrpc/rxkad.c
87871 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
87872
87873 len = iov[0].iov_len + iov[1].iov_len;
87874
87875 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
87876 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
87877 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
87878
87879 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
87880 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
87881
87882 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
87883
87884 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
87885 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
87886 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
87887
87888 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
87889 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
87890 index 391a245..296b3d7 100644
87891 --- a/net/sctp/ipv6.c
87892 +++ b/net/sctp/ipv6.c
87893 @@ -981,7 +981,7 @@ static const struct inet6_protocol sctpv6_protocol = {
87894 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
87895 };
87896
87897 -static struct sctp_af sctp_af_inet6 = {
87898 +static struct sctp_af sctp_af_inet6 __read_only = {
87899 .sa_family = AF_INET6,
87900 .sctp_xmit = sctp_v6_xmit,
87901 .setsockopt = ipv6_setsockopt,
87902 @@ -1013,7 +1013,7 @@ static struct sctp_af sctp_af_inet6 = {
87903 #endif
87904 };
87905
87906 -static struct sctp_pf sctp_pf_inet6 = {
87907 +static struct sctp_pf sctp_pf_inet6 __read_only = {
87908 .event_msgname = sctp_inet6_event_msgname,
87909 .skb_msgname = sctp_inet6_skb_msgname,
87910 .af_supported = sctp_inet6_af_supported,
87911 @@ -1038,7 +1038,7 @@ void sctp_v6_pf_init(void)
87912
87913 void sctp_v6_pf_exit(void)
87914 {
87915 - list_del(&sctp_af_inet6.list);
87916 + pax_list_del(&sctp_af_inet6.list);
87917 }
87918
87919 /* Initialize IPv6 support and register with socket layer. */
87920 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
87921 index 8c19e97..16264b8 100644
87922 --- a/net/sctp/proc.c
87923 +++ b/net/sctp/proc.c
87924 @@ -338,7 +338,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
87925 seq_printf(seq,
87926 "%8pK %8pK %-3d %-3d %-2d %-4d "
87927 "%4d %8d %8d %7d %5lu %-5d %5d ",
87928 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
87929 + assoc, sk,
87930 + sctp_sk(sk)->type, sk->sk_state,
87931 assoc->state, hash,
87932 assoc->assoc_id,
87933 assoc->sndbuf_used,
87934 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
87935 index f898b1c..a2d0fe8 100644
87936 --- a/net/sctp/protocol.c
87937 +++ b/net/sctp/protocol.c
87938 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
87939 return 0;
87940 }
87941
87942 + pax_open_kernel();
87943 INIT_LIST_HEAD(&af->list);
87944 - list_add_tail(&af->list, &sctp_address_families);
87945 + pax_close_kernel();
87946 + pax_list_add_tail(&af->list, &sctp_address_families);
87947 return 1;
87948 }
87949
87950 @@ -966,7 +968,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
87951
87952 static struct sctp_af sctp_af_inet;
87953
87954 -static struct sctp_pf sctp_pf_inet = {
87955 +static struct sctp_pf sctp_pf_inet __read_only = {
87956 .event_msgname = sctp_inet_event_msgname,
87957 .skb_msgname = sctp_inet_skb_msgname,
87958 .af_supported = sctp_inet_af_supported,
87959 @@ -1037,7 +1039,7 @@ static const struct net_protocol sctp_protocol = {
87960 };
87961
87962 /* IPv4 address related functions. */
87963 -static struct sctp_af sctp_af_inet = {
87964 +static struct sctp_af sctp_af_inet __read_only = {
87965 .sa_family = AF_INET,
87966 .sctp_xmit = sctp_v4_xmit,
87967 .setsockopt = ip_setsockopt,
87968 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
87969
87970 static void sctp_v4_pf_exit(void)
87971 {
87972 - list_del(&sctp_af_inet.list);
87973 + pax_list_del(&sctp_af_inet.list);
87974 }
87975
87976 static int sctp_v4_protosw_init(void)
87977 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
87978 index c957775..6d4593a 100644
87979 --- a/net/sctp/sm_sideeffect.c
87980 +++ b/net/sctp/sm_sideeffect.c
87981 @@ -447,7 +447,7 @@ static void sctp_generate_sack_event(unsigned long data)
87982 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
87983 }
87984
87985 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
87986 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
87987 NULL,
87988 sctp_generate_t1_cookie_event,
87989 sctp_generate_t1_init_event,
87990 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
87991 index cedd9bf..d577d71 100644
87992 --- a/net/sctp/socket.c
87993 +++ b/net/sctp/socket.c
87994 @@ -4665,6 +4665,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
87995 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
87996 if (space_left < addrlen)
87997 return -ENOMEM;
87998 + if (addrlen > sizeof(temp) || addrlen < 0)
87999 + return -EFAULT;
88000 if (copy_to_user(to, &temp, addrlen))
88001 return -EFAULT;
88002 to += addrlen;
88003 @@ -5653,6 +5655,9 @@ static int sctp_getsockopt_assoc_stats(struct sock *sk, int len,
88004 if (len < sizeof(sctp_assoc_t))
88005 return -EINVAL;
88006
88007 + /* Allow the struct to grow and fill in as much as possible */
88008 + len = min_t(size_t, len, sizeof(sas));
88009 +
88010 if (copy_from_user(&sas, optval, len))
88011 return -EFAULT;
88012
88013 @@ -5686,9 +5691,6 @@ static int sctp_getsockopt_assoc_stats(struct sock *sk, int len,
88014 /* Mark beginning of a new observation period */
88015 asoc->stats.max_obs_rto = asoc->rto_min;
88016
88017 - /* Allow the struct to grow and fill in as much as possible */
88018 - len = min_t(size_t, len, sizeof(sas));
88019 -
88020 if (put_user(len, optlen))
88021 return -EFAULT;
88022
88023 diff --git a/net/sctp/ssnmap.c b/net/sctp/ssnmap.c
88024 index 442ad4e..825ea94 100644
88025 --- a/net/sctp/ssnmap.c
88026 +++ b/net/sctp/ssnmap.c
88027 @@ -41,8 +41,6 @@
88028 #include <net/sctp/sctp.h>
88029 #include <net/sctp/sm.h>
88030
88031 -#define MAX_KMALLOC_SIZE 131072
88032 -
88033 static struct sctp_ssnmap *sctp_ssnmap_init(struct sctp_ssnmap *map, __u16 in,
88034 __u16 out);
88035
88036 @@ -65,7 +63,7 @@ struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
88037 int size;
88038
88039 size = sctp_ssnmap_size(in, out);
88040 - if (size <= MAX_KMALLOC_SIZE)
88041 + if (size <= KMALLOC_MAX_SIZE)
88042 retval = kmalloc(size, gfp);
88043 else
88044 retval = (struct sctp_ssnmap *)
88045 @@ -82,7 +80,7 @@ struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
88046 return retval;
88047
88048 fail_map:
88049 - if (size <= MAX_KMALLOC_SIZE)
88050 + if (size <= KMALLOC_MAX_SIZE)
88051 kfree(retval);
88052 else
88053 free_pages((unsigned long)retval, get_order(size));
88054 @@ -124,7 +122,7 @@ void sctp_ssnmap_free(struct sctp_ssnmap *map)
88055 int size;
88056
88057 size = sctp_ssnmap_size(map->in.len, map->out.len);
88058 - if (size <= MAX_KMALLOC_SIZE)
88059 + if (size <= KMALLOC_MAX_SIZE)
88060 kfree(map);
88061 else
88062 free_pages((unsigned long)map, get_order(size));
88063 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
88064 index bf3c6e8..376d8d0 100644
88065 --- a/net/sctp/sysctl.c
88066 +++ b/net/sctp/sysctl.c
88067 @@ -307,7 +307,7 @@ static int proc_sctp_do_hmac_alg(ctl_table *ctl,
88068 {
88069 struct net *net = current->nsproxy->net_ns;
88070 char tmp[8];
88071 - ctl_table tbl;
88072 + ctl_table_no_const tbl;
88073 int ret;
88074 int changed = 0;
88075 char *none = "none";
88076 @@ -350,7 +350,7 @@ static int proc_sctp_do_hmac_alg(ctl_table *ctl,
88077
88078 int sctp_sysctl_net_register(struct net *net)
88079 {
88080 - struct ctl_table *table;
88081 + ctl_table_no_const *table;
88082 int i;
88083
88084 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
88085 diff --git a/net/socket.c b/net/socket.c
88086 index 2ca51c7..45d0b31 100644
88087 --- a/net/socket.c
88088 +++ b/net/socket.c
88089 @@ -89,6 +89,7 @@
88090 #include <linux/magic.h>
88091 #include <linux/slab.h>
88092 #include <linux/xattr.h>
88093 +#include <linux/in.h>
88094
88095 #include <asm/uaccess.h>
88096 #include <asm/unistd.h>
88097 @@ -106,6 +107,8 @@
88098 #include <linux/sockios.h>
88099 #include <linux/atalk.h>
88100
88101 +#include <linux/grsock.h>
88102 +
88103 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
88104 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
88105 unsigned long nr_segs, loff_t pos);
88106 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
88107 &sockfs_dentry_operations, SOCKFS_MAGIC);
88108 }
88109
88110 -static struct vfsmount *sock_mnt __read_mostly;
88111 +struct vfsmount *sock_mnt __read_mostly;
88112
88113 static struct file_system_type sock_fs_type = {
88114 .name = "sockfs",
88115 @@ -1270,6 +1273,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
88116 return -EAFNOSUPPORT;
88117 if (type < 0 || type >= SOCK_MAX)
88118 return -EINVAL;
88119 + if (protocol < 0)
88120 + return -EINVAL;
88121
88122 /* Compatibility.
88123
88124 @@ -1401,6 +1406,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
88125 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
88126 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
88127
88128 + if(!gr_search_socket(family, type, protocol)) {
88129 + retval = -EACCES;
88130 + goto out;
88131 + }
88132 +
88133 + if (gr_handle_sock_all(family, type, protocol)) {
88134 + retval = -EACCES;
88135 + goto out;
88136 + }
88137 +
88138 retval = sock_create(family, type, protocol, &sock);
88139 if (retval < 0)
88140 goto out;
88141 @@ -1528,6 +1543,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
88142 if (sock) {
88143 err = move_addr_to_kernel(umyaddr, addrlen, &address);
88144 if (err >= 0) {
88145 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
88146 + err = -EACCES;
88147 + goto error;
88148 + }
88149 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
88150 + if (err)
88151 + goto error;
88152 +
88153 err = security_socket_bind(sock,
88154 (struct sockaddr *)&address,
88155 addrlen);
88156 @@ -1536,6 +1559,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
88157 (struct sockaddr *)
88158 &address, addrlen);
88159 }
88160 +error:
88161 fput_light(sock->file, fput_needed);
88162 }
88163 return err;
88164 @@ -1559,10 +1583,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
88165 if ((unsigned int)backlog > somaxconn)
88166 backlog = somaxconn;
88167
88168 + if (gr_handle_sock_server_other(sock->sk)) {
88169 + err = -EPERM;
88170 + goto error;
88171 + }
88172 +
88173 + err = gr_search_listen(sock);
88174 + if (err)
88175 + goto error;
88176 +
88177 err = security_socket_listen(sock, backlog);
88178 if (!err)
88179 err = sock->ops->listen(sock, backlog);
88180
88181 +error:
88182 fput_light(sock->file, fput_needed);
88183 }
88184 return err;
88185 @@ -1606,6 +1640,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
88186 newsock->type = sock->type;
88187 newsock->ops = sock->ops;
88188
88189 + if (gr_handle_sock_server_other(sock->sk)) {
88190 + err = -EPERM;
88191 + sock_release(newsock);
88192 + goto out_put;
88193 + }
88194 +
88195 + err = gr_search_accept(sock);
88196 + if (err) {
88197 + sock_release(newsock);
88198 + goto out_put;
88199 + }
88200 +
88201 /*
88202 * We don't need try_module_get here, as the listening socket (sock)
88203 * has the protocol module (sock->ops->owner) held.
88204 @@ -1651,6 +1697,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
88205 fd_install(newfd, newfile);
88206 err = newfd;
88207
88208 + gr_attach_curr_ip(newsock->sk);
88209 +
88210 out_put:
88211 fput_light(sock->file, fput_needed);
88212 out:
88213 @@ -1683,6 +1731,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
88214 int, addrlen)
88215 {
88216 struct socket *sock;
88217 + struct sockaddr *sck;
88218 struct sockaddr_storage address;
88219 int err, fput_needed;
88220
88221 @@ -1693,6 +1742,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
88222 if (err < 0)
88223 goto out_put;
88224
88225 + sck = (struct sockaddr *)&address;
88226 +
88227 + if (gr_handle_sock_client(sck)) {
88228 + err = -EACCES;
88229 + goto out_put;
88230 + }
88231 +
88232 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
88233 + if (err)
88234 + goto out_put;
88235 +
88236 err =
88237 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
88238 if (err)
88239 @@ -2047,7 +2107,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
88240 * checking falls down on this.
88241 */
88242 if (copy_from_user(ctl_buf,
88243 - (void __user __force *)msg_sys->msg_control,
88244 + (void __force_user *)msg_sys->msg_control,
88245 ctl_len))
88246 goto out_freectl;
88247 msg_sys->msg_control = ctl_buf;
88248 @@ -2215,7 +2275,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
88249 * kernel msghdr to use the kernel address space)
88250 */
88251
88252 - uaddr = (__force void __user *)msg_sys->msg_name;
88253 + uaddr = (void __force_user *)msg_sys->msg_name;
88254 uaddr_len = COMPAT_NAMELEN(msg);
88255 if (MSG_CMSG_COMPAT & flags) {
88256 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
88257 @@ -2838,7 +2898,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
88258 }
88259
88260 ifr = compat_alloc_user_space(buf_size);
88261 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
88262 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
88263
88264 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
88265 return -EFAULT;
88266 @@ -2862,12 +2922,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
88267 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
88268
88269 if (copy_in_user(rxnfc, compat_rxnfc,
88270 - (void *)(&rxnfc->fs.m_ext + 1) -
88271 - (void *)rxnfc) ||
88272 + (void __user *)(&rxnfc->fs.m_ext + 1) -
88273 + (void __user *)rxnfc) ||
88274 copy_in_user(&rxnfc->fs.ring_cookie,
88275 &compat_rxnfc->fs.ring_cookie,
88276 - (void *)(&rxnfc->fs.location + 1) -
88277 - (void *)&rxnfc->fs.ring_cookie) ||
88278 + (void __user *)(&rxnfc->fs.location + 1) -
88279 + (void __user *)&rxnfc->fs.ring_cookie) ||
88280 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
88281 sizeof(rxnfc->rule_cnt)))
88282 return -EFAULT;
88283 @@ -2879,12 +2939,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
88284
88285 if (convert_out) {
88286 if (copy_in_user(compat_rxnfc, rxnfc,
88287 - (const void *)(&rxnfc->fs.m_ext + 1) -
88288 - (const void *)rxnfc) ||
88289 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
88290 + (const void __user *)rxnfc) ||
88291 copy_in_user(&compat_rxnfc->fs.ring_cookie,
88292 &rxnfc->fs.ring_cookie,
88293 - (const void *)(&rxnfc->fs.location + 1) -
88294 - (const void *)&rxnfc->fs.ring_cookie) ||
88295 + (const void __user *)(&rxnfc->fs.location + 1) -
88296 + (const void __user *)&rxnfc->fs.ring_cookie) ||
88297 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
88298 sizeof(rxnfc->rule_cnt)))
88299 return -EFAULT;
88300 @@ -2954,7 +3014,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
88301 old_fs = get_fs();
88302 set_fs(KERNEL_DS);
88303 err = dev_ioctl(net, cmd,
88304 - (struct ifreq __user __force *) &kifr);
88305 + (struct ifreq __force_user *) &kifr);
88306 set_fs(old_fs);
88307
88308 return err;
88309 @@ -3063,7 +3123,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
88310
88311 old_fs = get_fs();
88312 set_fs(KERNEL_DS);
88313 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
88314 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
88315 set_fs(old_fs);
88316
88317 if (cmd == SIOCGIFMAP && !err) {
88318 @@ -3168,7 +3228,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
88319 ret |= __get_user(rtdev, &(ur4->rt_dev));
88320 if (rtdev) {
88321 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
88322 - r4.rt_dev = (char __user __force *)devname;
88323 + r4.rt_dev = (char __force_user *)devname;
88324 devname[15] = 0;
88325 } else
88326 r4.rt_dev = NULL;
88327 @@ -3394,8 +3454,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
88328 int __user *uoptlen;
88329 int err;
88330
88331 - uoptval = (char __user __force *) optval;
88332 - uoptlen = (int __user __force *) optlen;
88333 + uoptval = (char __force_user *) optval;
88334 + uoptlen = (int __force_user *) optlen;
88335
88336 set_fs(KERNEL_DS);
88337 if (level == SOL_SOCKET)
88338 @@ -3415,7 +3475,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
88339 char __user *uoptval;
88340 int err;
88341
88342 - uoptval = (char __user __force *) optval;
88343 + uoptval = (char __force_user *) optval;
88344
88345 set_fs(KERNEL_DS);
88346 if (level == SOL_SOCKET)
88347 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
88348 index 507b5e8..049e64a 100644
88349 --- a/net/sunrpc/clnt.c
88350 +++ b/net/sunrpc/clnt.c
88351 @@ -1272,7 +1272,9 @@ call_start(struct rpc_task *task)
88352 (RPC_IS_ASYNC(task) ? "async" : "sync"));
88353
88354 /* Increment call count */
88355 - task->tk_msg.rpc_proc->p_count++;
88356 + pax_open_kernel();
88357 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
88358 + pax_close_kernel();
88359 clnt->cl_stats->rpccnt++;
88360 task->tk_action = call_reserve;
88361 }
88362 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
88363 index fb20f25..e3ba316 100644
88364 --- a/net/sunrpc/sched.c
88365 +++ b/net/sunrpc/sched.c
88366 @@ -259,9 +259,9 @@ static int rpc_wait_bit_killable(void *word)
88367 #ifdef RPC_DEBUG
88368 static void rpc_task_set_debuginfo(struct rpc_task *task)
88369 {
88370 - static atomic_t rpc_pid;
88371 + static atomic_unchecked_t rpc_pid;
88372
88373 - task->tk_pid = atomic_inc_return(&rpc_pid);
88374 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
88375 }
88376 #else
88377 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
88378 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
88379 index 2d34b6b..e2d584d 100644
88380 --- a/net/sunrpc/svc.c
88381 +++ b/net/sunrpc/svc.c
88382 @@ -1156,7 +1156,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
88383 svc_putnl(resv, RPC_SUCCESS);
88384
88385 /* Bump per-procedure stats counter */
88386 - procp->pc_count++;
88387 + pax_open_kernel();
88388 + (*(unsigned int *)&procp->pc_count)++;
88389 + pax_close_kernel();
88390
88391 /* Initialize storage for argp and resp */
88392 memset(rqstp->rq_argp, 0, procp->pc_argsize);
88393 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
88394 index 8343737..677025e 100644
88395 --- a/net/sunrpc/xprtrdma/svc_rdma.c
88396 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
88397 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
88398 static unsigned int min_max_inline = 4096;
88399 static unsigned int max_max_inline = 65536;
88400
88401 -atomic_t rdma_stat_recv;
88402 -atomic_t rdma_stat_read;
88403 -atomic_t rdma_stat_write;
88404 -atomic_t rdma_stat_sq_starve;
88405 -atomic_t rdma_stat_rq_starve;
88406 -atomic_t rdma_stat_rq_poll;
88407 -atomic_t rdma_stat_rq_prod;
88408 -atomic_t rdma_stat_sq_poll;
88409 -atomic_t rdma_stat_sq_prod;
88410 +atomic_unchecked_t rdma_stat_recv;
88411 +atomic_unchecked_t rdma_stat_read;
88412 +atomic_unchecked_t rdma_stat_write;
88413 +atomic_unchecked_t rdma_stat_sq_starve;
88414 +atomic_unchecked_t rdma_stat_rq_starve;
88415 +atomic_unchecked_t rdma_stat_rq_poll;
88416 +atomic_unchecked_t rdma_stat_rq_prod;
88417 +atomic_unchecked_t rdma_stat_sq_poll;
88418 +atomic_unchecked_t rdma_stat_sq_prod;
88419
88420 /* Temporary NFS request map and context caches */
88421 struct kmem_cache *svc_rdma_map_cachep;
88422 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
88423 len -= *ppos;
88424 if (len > *lenp)
88425 len = *lenp;
88426 - if (len && copy_to_user(buffer, str_buf, len))
88427 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
88428 return -EFAULT;
88429 *lenp = len;
88430 *ppos += len;
88431 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
88432 {
88433 .procname = "rdma_stat_read",
88434 .data = &rdma_stat_read,
88435 - .maxlen = sizeof(atomic_t),
88436 + .maxlen = sizeof(atomic_unchecked_t),
88437 .mode = 0644,
88438 .proc_handler = read_reset_stat,
88439 },
88440 {
88441 .procname = "rdma_stat_recv",
88442 .data = &rdma_stat_recv,
88443 - .maxlen = sizeof(atomic_t),
88444 + .maxlen = sizeof(atomic_unchecked_t),
88445 .mode = 0644,
88446 .proc_handler = read_reset_stat,
88447 },
88448 {
88449 .procname = "rdma_stat_write",
88450 .data = &rdma_stat_write,
88451 - .maxlen = sizeof(atomic_t),
88452 + .maxlen = sizeof(atomic_unchecked_t),
88453 .mode = 0644,
88454 .proc_handler = read_reset_stat,
88455 },
88456 {
88457 .procname = "rdma_stat_sq_starve",
88458 .data = &rdma_stat_sq_starve,
88459 - .maxlen = sizeof(atomic_t),
88460 + .maxlen = sizeof(atomic_unchecked_t),
88461 .mode = 0644,
88462 .proc_handler = read_reset_stat,
88463 },
88464 {
88465 .procname = "rdma_stat_rq_starve",
88466 .data = &rdma_stat_rq_starve,
88467 - .maxlen = sizeof(atomic_t),
88468 + .maxlen = sizeof(atomic_unchecked_t),
88469 .mode = 0644,
88470 .proc_handler = read_reset_stat,
88471 },
88472 {
88473 .procname = "rdma_stat_rq_poll",
88474 .data = &rdma_stat_rq_poll,
88475 - .maxlen = sizeof(atomic_t),
88476 + .maxlen = sizeof(atomic_unchecked_t),
88477 .mode = 0644,
88478 .proc_handler = read_reset_stat,
88479 },
88480 {
88481 .procname = "rdma_stat_rq_prod",
88482 .data = &rdma_stat_rq_prod,
88483 - .maxlen = sizeof(atomic_t),
88484 + .maxlen = sizeof(atomic_unchecked_t),
88485 .mode = 0644,
88486 .proc_handler = read_reset_stat,
88487 },
88488 {
88489 .procname = "rdma_stat_sq_poll",
88490 .data = &rdma_stat_sq_poll,
88491 - .maxlen = sizeof(atomic_t),
88492 + .maxlen = sizeof(atomic_unchecked_t),
88493 .mode = 0644,
88494 .proc_handler = read_reset_stat,
88495 },
88496 {
88497 .procname = "rdma_stat_sq_prod",
88498 .data = &rdma_stat_sq_prod,
88499 - .maxlen = sizeof(atomic_t),
88500 + .maxlen = sizeof(atomic_unchecked_t),
88501 .mode = 0644,
88502 .proc_handler = read_reset_stat,
88503 },
88504 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
88505 index 0ce7552..d074459 100644
88506 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
88507 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
88508 @@ -501,7 +501,7 @@ next_sge:
88509 svc_rdma_put_context(ctxt, 0);
88510 goto out;
88511 }
88512 - atomic_inc(&rdma_stat_read);
88513 + atomic_inc_unchecked(&rdma_stat_read);
88514
88515 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
88516 chl_map->ch[ch_no].count -= read_wr.num_sge;
88517 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
88518 dto_q);
88519 list_del_init(&ctxt->dto_q);
88520 } else {
88521 - atomic_inc(&rdma_stat_rq_starve);
88522 + atomic_inc_unchecked(&rdma_stat_rq_starve);
88523 clear_bit(XPT_DATA, &xprt->xpt_flags);
88524 ctxt = NULL;
88525 }
88526 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
88527 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
88528 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
88529 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
88530 - atomic_inc(&rdma_stat_recv);
88531 + atomic_inc_unchecked(&rdma_stat_recv);
88532
88533 /* Build up the XDR from the receive buffers. */
88534 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
88535 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
88536 index c1d124d..acfc59e 100644
88537 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
88538 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
88539 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
88540 write_wr.wr.rdma.remote_addr = to;
88541
88542 /* Post It */
88543 - atomic_inc(&rdma_stat_write);
88544 + atomic_inc_unchecked(&rdma_stat_write);
88545 if (svc_rdma_send(xprt, &write_wr))
88546 goto err;
88547 return 0;
88548 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
88549 index 62e4f9b..dd3f2d7 100644
88550 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
88551 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
88552 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
88553 return;
88554
88555 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
88556 - atomic_inc(&rdma_stat_rq_poll);
88557 + atomic_inc_unchecked(&rdma_stat_rq_poll);
88558
88559 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
88560 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
88561 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
88562 }
88563
88564 if (ctxt)
88565 - atomic_inc(&rdma_stat_rq_prod);
88566 + atomic_inc_unchecked(&rdma_stat_rq_prod);
88567
88568 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
88569 /*
88570 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
88571 return;
88572
88573 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
88574 - atomic_inc(&rdma_stat_sq_poll);
88575 + atomic_inc_unchecked(&rdma_stat_sq_poll);
88576 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
88577 if (wc.status != IB_WC_SUCCESS)
88578 /* Close the transport */
88579 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
88580 }
88581
88582 if (ctxt)
88583 - atomic_inc(&rdma_stat_sq_prod);
88584 + atomic_inc_unchecked(&rdma_stat_sq_prod);
88585 }
88586
88587 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
88588 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
88589 spin_lock_bh(&xprt->sc_lock);
88590 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
88591 spin_unlock_bh(&xprt->sc_lock);
88592 - atomic_inc(&rdma_stat_sq_starve);
88593 + atomic_inc_unchecked(&rdma_stat_sq_starve);
88594
88595 /* See if we can opportunistically reap SQ WR to make room */
88596 sq_cq_reap(xprt);
88597 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
88598 index 9bc6db0..47ac8c0 100644
88599 --- a/net/sysctl_net.c
88600 +++ b/net/sysctl_net.c
88601 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
88602 kgid_t root_gid = make_kgid(net->user_ns, 0);
88603
88604 /* Allow network administrator to have same access as root. */
88605 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
88606 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
88607 uid_eq(root_uid, current_uid())) {
88608 int mode = (table->mode >> 6) & 7;
88609 return (mode << 6) | (mode << 3) | mode;
88610 diff --git a/net/tipc/link.c b/net/tipc/link.c
88611 index daa6080..02d357f 100644
88612 --- a/net/tipc/link.c
88613 +++ b/net/tipc/link.c
88614 @@ -1201,7 +1201,7 @@ static int link_send_sections_long(struct tipc_port *sender,
88615 struct tipc_msg fragm_hdr;
88616 struct sk_buff *buf, *buf_chain, *prev;
88617 u32 fragm_crs, fragm_rest, hsz, sect_rest;
88618 - const unchar *sect_crs;
88619 + const unchar __user *sect_crs;
88620 int curr_sect;
88621 u32 fragm_no;
88622
88623 @@ -1242,7 +1242,7 @@ again:
88624
88625 if (!sect_rest) {
88626 sect_rest = msg_sect[++curr_sect].iov_len;
88627 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
88628 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
88629 }
88630
88631 if (sect_rest < fragm_rest)
88632 @@ -1261,7 +1261,7 @@ error:
88633 }
88634 } else
88635 skb_copy_to_linear_data_offset(buf, fragm_crs,
88636 - sect_crs, sz);
88637 + (const void __force_kernel *)sect_crs, sz);
88638 sect_crs += sz;
88639 sect_rest -= sz;
88640 fragm_crs += sz;
88641 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
88642 index f2db8a8..9245aa4 100644
88643 --- a/net/tipc/msg.c
88644 +++ b/net/tipc/msg.c
88645 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
88646 msg_sect[cnt].iov_len);
88647 else
88648 skb_copy_to_linear_data_offset(*buf, pos,
88649 - msg_sect[cnt].iov_base,
88650 + (const void __force_kernel *)msg_sect[cnt].iov_base,
88651 msg_sect[cnt].iov_len);
88652 pos += msg_sect[cnt].iov_len;
88653 }
88654 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
88655 index 6b42d47..2ac24d5 100644
88656 --- a/net/tipc/subscr.c
88657 +++ b/net/tipc/subscr.c
88658 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
88659 {
88660 struct iovec msg_sect;
88661
88662 - msg_sect.iov_base = (void *)&sub->evt;
88663 + msg_sect.iov_base = (void __force_user *)&sub->evt;
88664 msg_sect.iov_len = sizeof(struct tipc_event);
88665
88666 sub->evt.event = htohl(event, sub->swap);
88667 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
88668 index 5b5c876..3127bf7 100644
88669 --- a/net/unix/af_unix.c
88670 +++ b/net/unix/af_unix.c
88671 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
88672 err = -ECONNREFUSED;
88673 if (!S_ISSOCK(inode->i_mode))
88674 goto put_fail;
88675 +
88676 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
88677 + err = -EACCES;
88678 + goto put_fail;
88679 + }
88680 +
88681 u = unix_find_socket_byinode(inode);
88682 if (!u)
88683 goto put_fail;
88684 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
88685 if (u) {
88686 struct dentry *dentry;
88687 dentry = unix_sk(u)->path.dentry;
88688 +
88689 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
88690 + err = -EPERM;
88691 + sock_put(u);
88692 + goto fail;
88693 + }
88694 +
88695 if (dentry)
88696 touch_atime(&unix_sk(u)->path);
88697 } else
88698 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
88699 */
88700 err = security_path_mknod(&path, dentry, mode, 0);
88701 if (!err) {
88702 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
88703 + err = -EACCES;
88704 + goto out;
88705 + }
88706 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
88707 if (!err) {
88708 res->mnt = mntget(path.mnt);
88709 res->dentry = dget(dentry);
88710 + gr_handle_create(dentry, path.mnt);
88711 }
88712 }
88713 +out:
88714 done_path_create(&path, dentry);
88715 return err;
88716 }
88717 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
88718 index 8800604..0526440 100644
88719 --- a/net/unix/sysctl_net_unix.c
88720 +++ b/net/unix/sysctl_net_unix.c
88721 @@ -28,7 +28,7 @@ static ctl_table unix_table[] = {
88722
88723 int __net_init unix_sysctl_register(struct net *net)
88724 {
88725 - struct ctl_table *table;
88726 + ctl_table_no_const *table;
88727
88728 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
88729 if (table == NULL)
88730 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
88731 index c8717c1..08539f5 100644
88732 --- a/net/wireless/wext-core.c
88733 +++ b/net/wireless/wext-core.c
88734 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
88735 */
88736
88737 /* Support for very large requests */
88738 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
88739 - (user_length > descr->max_tokens)) {
88740 + if (user_length > descr->max_tokens) {
88741 /* Allow userspace to GET more than max so
88742 * we can support any size GET requests.
88743 * There is still a limit : -ENOMEM.
88744 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
88745 }
88746 }
88747
88748 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
88749 - /*
88750 - * If this is a GET, but not NOMAX, it means that the extra
88751 - * data is not bounded by userspace, but by max_tokens. Thus
88752 - * set the length to max_tokens. This matches the extra data
88753 - * allocation.
88754 - * The driver should fill it with the number of tokens it
88755 - * provided, and it may check iwp->length rather than having
88756 - * knowledge of max_tokens. If the driver doesn't change the
88757 - * iwp->length, this ioctl just copies back max_token tokens
88758 - * filled with zeroes. Hopefully the driver isn't claiming
88759 - * them to be valid data.
88760 - */
88761 - iwp->length = descr->max_tokens;
88762 - }
88763 -
88764 err = handler(dev, info, (union iwreq_data *) iwp, extra);
88765
88766 iwp->length += essid_compat;
88767 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
88768 index 07c5857..fde4018 100644
88769 --- a/net/xfrm/xfrm_policy.c
88770 +++ b/net/xfrm/xfrm_policy.c
88771 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
88772 {
88773 policy->walk.dead = 1;
88774
88775 - atomic_inc(&policy->genid);
88776 + atomic_inc_unchecked(&policy->genid);
88777
88778 if (del_timer(&policy->timer))
88779 xfrm_pol_put(policy);
88780 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
88781 hlist_add_head(&policy->bydst, chain);
88782 xfrm_pol_hold(policy);
88783 net->xfrm.policy_count[dir]++;
88784 - atomic_inc(&flow_cache_genid);
88785 + atomic_inc_unchecked(&flow_cache_genid);
88786 rt_genid_bump(net);
88787 if (delpol)
88788 __xfrm_policy_unlink(delpol, dir);
88789 @@ -1550,7 +1550,7 @@ free_dst:
88790 goto out;
88791 }
88792
88793 -static int inline
88794 +static inline int
88795 xfrm_dst_alloc_copy(void **target, const void *src, int size)
88796 {
88797 if (!*target) {
88798 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
88799 return 0;
88800 }
88801
88802 -static int inline
88803 +static inline int
88804 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
88805 {
88806 #ifdef CONFIG_XFRM_SUB_POLICY
88807 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
88808 #endif
88809 }
88810
88811 -static int inline
88812 +static inline int
88813 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
88814 {
88815 #ifdef CONFIG_XFRM_SUB_POLICY
88816 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
88817
88818 xdst->num_pols = num_pols;
88819 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
88820 - xdst->policy_genid = atomic_read(&pols[0]->genid);
88821 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
88822
88823 return xdst;
88824 }
88825 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
88826 if (xdst->xfrm_genid != dst->xfrm->genid)
88827 return 0;
88828 if (xdst->num_pols > 0 &&
88829 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
88830 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
88831 return 0;
88832
88833 mtu = dst_mtu(dst->child);
88834 @@ -2457,8 +2457,11 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
88835 dst_ops->link_failure = xfrm_link_failure;
88836 if (likely(dst_ops->neigh_lookup == NULL))
88837 dst_ops->neigh_lookup = xfrm_neigh_lookup;
88838 - if (likely(afinfo->garbage_collect == NULL))
88839 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
88840 + if (likely(afinfo->garbage_collect == NULL)) {
88841 + pax_open_kernel();
88842 + *(void **)&afinfo->garbage_collect = xfrm_garbage_collect_deferred;
88843 + pax_close_kernel();
88844 + }
88845 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
88846 }
88847 spin_unlock(&xfrm_policy_afinfo_lock);
88848 @@ -2512,7 +2515,9 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
88849 dst_ops->check = NULL;
88850 dst_ops->negative_advice = NULL;
88851 dst_ops->link_failure = NULL;
88852 - afinfo->garbage_collect = NULL;
88853 + pax_open_kernel();
88854 + *(void **)&afinfo->garbage_collect = NULL;
88855 + pax_close_kernel();
88856 }
88857 return err;
88858 }
88859 @@ -2896,7 +2901,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
88860 sizeof(pol->xfrm_vec[i].saddr));
88861 pol->xfrm_vec[i].encap_family = mp->new_family;
88862 /* flush bundles */
88863 - atomic_inc(&pol->genid);
88864 + atomic_inc_unchecked(&pol->genid);
88865 }
88866 }
88867
88868 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
88869 index 3459692..e7cdb1a 100644
88870 --- a/net/xfrm/xfrm_state.c
88871 +++ b/net/xfrm/xfrm_state.c
88872 @@ -194,11 +194,13 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
88873
88874 if (unlikely(afinfo == NULL))
88875 return -EAFNOSUPPORT;
88876 - typemap = afinfo->type_map;
88877 + typemap = (const struct xfrm_type **)afinfo->type_map;
88878
88879 - if (likely(typemap[type->proto] == NULL))
88880 + if (likely(typemap[type->proto] == NULL)) {
88881 + pax_open_kernel();
88882 typemap[type->proto] = type;
88883 - else
88884 + pax_close_kernel();
88885 + } else
88886 err = -EEXIST;
88887 xfrm_state_unlock_afinfo(afinfo);
88888 return err;
88889 @@ -213,12 +215,15 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
88890
88891 if (unlikely(afinfo == NULL))
88892 return -EAFNOSUPPORT;
88893 - typemap = afinfo->type_map;
88894 + typemap = (const struct xfrm_type **)afinfo->type_map;
88895
88896 if (unlikely(typemap[type->proto] != type))
88897 err = -ENOENT;
88898 - else
88899 + else {
88900 + pax_open_kernel();
88901 typemap[type->proto] = NULL;
88902 + pax_close_kernel();
88903 + }
88904 xfrm_state_unlock_afinfo(afinfo);
88905 return err;
88906 }
88907 @@ -227,7 +232,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
88908 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
88909 {
88910 struct xfrm_state_afinfo *afinfo;
88911 - const struct xfrm_type **typemap;
88912 const struct xfrm_type *type;
88913 int modload_attempted = 0;
88914
88915 @@ -235,9 +239,8 @@ retry:
88916 afinfo = xfrm_state_get_afinfo(family);
88917 if (unlikely(afinfo == NULL))
88918 return NULL;
88919 - typemap = afinfo->type_map;
88920
88921 - type = typemap[proto];
88922 + type = afinfo->type_map[proto];
88923 if (unlikely(type && !try_module_get(type->owner)))
88924 type = NULL;
88925 if (!type && !modload_attempted) {
88926 @@ -270,7 +273,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
88927 return -EAFNOSUPPORT;
88928
88929 err = -EEXIST;
88930 - modemap = afinfo->mode_map;
88931 + modemap = (struct xfrm_mode **)afinfo->mode_map;
88932 if (modemap[mode->encap])
88933 goto out;
88934
88935 @@ -278,8 +281,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
88936 if (!try_module_get(afinfo->owner))
88937 goto out;
88938
88939 - mode->afinfo = afinfo;
88940 + pax_open_kernel();
88941 + *(const void **)&mode->afinfo = afinfo;
88942 modemap[mode->encap] = mode;
88943 + pax_close_kernel();
88944 err = 0;
88945
88946 out:
88947 @@ -302,9 +307,11 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
88948 return -EAFNOSUPPORT;
88949
88950 err = -ENOENT;
88951 - modemap = afinfo->mode_map;
88952 + modemap = (struct xfrm_mode **)afinfo->mode_map;
88953 if (likely(modemap[mode->encap] == mode)) {
88954 + pax_open_kernel();
88955 modemap[mode->encap] = NULL;
88956 + pax_close_kernel();
88957 module_put(mode->afinfo->owner);
88958 err = 0;
88959 }
88960 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
88961 index 05a6e3d..6716ec9 100644
88962 --- a/net/xfrm/xfrm_sysctl.c
88963 +++ b/net/xfrm/xfrm_sysctl.c
88964 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
88965
88966 int __net_init xfrm_sysctl_init(struct net *net)
88967 {
88968 - struct ctl_table *table;
88969 + ctl_table_no_const *table;
88970
88971 __xfrm_sysctl_init(net);
88972
88973 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
88974 index 0e801c3..5c8ad3b 100644
88975 --- a/scripts/Makefile.build
88976 +++ b/scripts/Makefile.build
88977 @@ -111,7 +111,7 @@ endif
88978 endif
88979
88980 # Do not include host rules unless needed
88981 -ifneq ($(hostprogs-y)$(hostprogs-m),)
88982 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
88983 include scripts/Makefile.host
88984 endif
88985
88986 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
88987 index 686cb0d..9d653bf 100644
88988 --- a/scripts/Makefile.clean
88989 +++ b/scripts/Makefile.clean
88990 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
88991 __clean-files := $(extra-y) $(always) \
88992 $(targets) $(clean-files) \
88993 $(host-progs) \
88994 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
88995 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
88996 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
88997
88998 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
88999
89000 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
89001 index 1ac414f..38575f7 100644
89002 --- a/scripts/Makefile.host
89003 +++ b/scripts/Makefile.host
89004 @@ -31,6 +31,8 @@
89005 # Note: Shared libraries consisting of C++ files are not supported
89006
89007 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
89008 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
89009 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
89010
89011 # C code
89012 # Executables compiled from a single .c file
89013 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
89014 # Shared libaries (only .c supported)
89015 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
89016 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
89017 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
89018 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
89019 # Remove .so files from "xxx-objs"
89020 host-cobjs := $(filter-out %.so,$(host-cobjs))
89021 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
89022
89023 -#Object (.o) files used by the shared libaries
89024 +# Object (.o) files used by the shared libaries
89025 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
89026 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
89027
89028 # output directory for programs/.o files
89029 # hostprogs-y := tools/build may have been specified. Retrieve directory
89030 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
89031 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
89032 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
89033 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
89034 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
89035 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
89036 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
89037 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
89038
89039 obj-dirs += $(host-objdirs)
89040 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
89041 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
89042 $(call if_changed_dep,host-cshobjs)
89043
89044 +# Compile .c file, create position independent .o file
89045 +# host-cxxshobjs -> .o
89046 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
89047 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
89048 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
89049 + $(call if_changed_dep,host-cxxshobjs)
89050 +
89051 # Link a shared library, based on position independent .o files
89052 # *.o -> .so shared library (host-cshlib)
89053 quiet_cmd_host-cshlib = HOSTLLD -shared $@
89054 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
89055 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
89056 $(call if_changed,host-cshlib)
89057
89058 +# Link a shared library, based on position independent .o files
89059 +# *.o -> .so shared library (host-cxxshlib)
89060 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
89061 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
89062 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
89063 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
89064 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
89065 + $(call if_changed,host-cxxshlib)
89066 +
89067 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
89068 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
89069 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
89070
89071 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
89072 index cb1f50c..cef2a7c 100644
89073 --- a/scripts/basic/fixdep.c
89074 +++ b/scripts/basic/fixdep.c
89075 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
89076 /*
89077 * Lookup a value in the configuration string.
89078 */
89079 -static int is_defined_config(const char *name, int len, unsigned int hash)
89080 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
89081 {
89082 struct item *aux;
89083
89084 @@ -211,10 +211,10 @@ static void clear_config(void)
89085 /*
89086 * Record the use of a CONFIG_* word.
89087 */
89088 -static void use_config(const char *m, int slen)
89089 +static void use_config(const char *m, unsigned int slen)
89090 {
89091 unsigned int hash = strhash(m, slen);
89092 - int c, i;
89093 + unsigned int c, i;
89094
89095 if (is_defined_config(m, slen, hash))
89096 return;
89097 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
89098
89099 static void parse_config_file(const char *map, size_t len)
89100 {
89101 - const int *end = (const int *) (map + len);
89102 + const unsigned int *end = (const unsigned int *) (map + len);
89103 /* start at +1, so that p can never be < map */
89104 - const int *m = (const int *) map + 1;
89105 + const unsigned int *m = (const unsigned int *) map + 1;
89106 const char *p, *q;
89107
89108 for (; m < end; m++) {
89109 @@ -406,7 +406,7 @@ static void print_deps(void)
89110 static void traps(void)
89111 {
89112 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
89113 - int *p = (int *)test;
89114 + unsigned int *p = (unsigned int *)test;
89115
89116 if (*p != INT_CONF) {
89117 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
89118 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
89119 new file mode 100644
89120 index 0000000..5e0222d
89121 --- /dev/null
89122 +++ b/scripts/gcc-plugin.sh
89123 @@ -0,0 +1,17 @@
89124 +#!/bin/bash
89125 +plugincc=`$1 -E -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
89126 +#include "gcc-plugin.h"
89127 +#include "tree.h"
89128 +#include "tm.h"
89129 +#include "rtl.h"
89130 +#ifdef ENABLE_BUILD_WITH_CXX
89131 +#warning $2
89132 +#else
89133 +#warning $1
89134 +#endif
89135 +EOF`
89136 +if [ $? -eq 0 ]
89137 +then
89138 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
89139 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
89140 +fi
89141 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
89142 index b3d907e..a4782ab 100644
89143 --- a/scripts/link-vmlinux.sh
89144 +++ b/scripts/link-vmlinux.sh
89145 @@ -152,7 +152,7 @@ else
89146 fi;
89147
89148 # final build of init/
89149 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
89150 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
89151
89152 kallsymso=""
89153 kallsyms_vmlinux=""
89154 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
89155 index df4fc23..0ea719d 100644
89156 --- a/scripts/mod/file2alias.c
89157 +++ b/scripts/mod/file2alias.c
89158 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
89159 unsigned long size, unsigned long id_size,
89160 void *symval)
89161 {
89162 - int i;
89163 + unsigned int i;
89164
89165 if (size % id_size || size < id_size) {
89166 if (cross_build != 0)
89167 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
89168 /* USB is special because the bcdDevice can be matched against a numeric range */
89169 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
89170 static void do_usb_entry(struct usb_device_id *id,
89171 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
89172 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
89173 unsigned char range_lo, unsigned char range_hi,
89174 unsigned char max, struct module *mod)
89175 {
89176 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
89177 {
89178 unsigned int devlo, devhi;
89179 unsigned char chi, clo, max;
89180 - int ndigits;
89181 + unsigned int ndigits;
89182
89183 id->match_flags = TO_NATIVE(id->match_flags);
89184 id->idVendor = TO_NATIVE(id->idVendor);
89185 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
89186 for (i = 0; i < count; i++) {
89187 const char *id = (char *)devs[i].id;
89188 char acpi_id[sizeof(devs[0].id)];
89189 - int j;
89190 + unsigned int j;
89191
89192 buf_printf(&mod->dev_table_buf,
89193 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
89194 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
89195
89196 for (j = 0; j < PNP_MAX_DEVICES; j++) {
89197 const char *id = (char *)card->devs[j].id;
89198 - int i2, j2;
89199 + unsigned int i2, j2;
89200 int dup = 0;
89201
89202 if (!id[0])
89203 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
89204 /* add an individual alias for every device entry */
89205 if (!dup) {
89206 char acpi_id[sizeof(card->devs[0].id)];
89207 - int k;
89208 + unsigned int k;
89209
89210 buf_printf(&mod->dev_table_buf,
89211 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
89212 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
89213 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
89214 char *alias)
89215 {
89216 - int i, j;
89217 + unsigned int i, j;
89218
89219 sprintf(alias, "dmi*");
89220
89221 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
89222 index ff36c50..7ab4fa9 100644
89223 --- a/scripts/mod/modpost.c
89224 +++ b/scripts/mod/modpost.c
89225 @@ -929,6 +929,7 @@ enum mismatch {
89226 ANY_INIT_TO_ANY_EXIT,
89227 ANY_EXIT_TO_ANY_INIT,
89228 EXPORT_TO_INIT_EXIT,
89229 + DATA_TO_TEXT
89230 };
89231
89232 struct sectioncheck {
89233 @@ -1043,6 +1044,12 @@ const struct sectioncheck sectioncheck[] = {
89234 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
89235 .mismatch = EXPORT_TO_INIT_EXIT,
89236 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
89237 +},
89238 +/* Do not reference code from writable data */
89239 +{
89240 + .fromsec = { DATA_SECTIONS, NULL },
89241 + .tosec = { TEXT_SECTIONS, NULL },
89242 + .mismatch = DATA_TO_TEXT
89243 }
89244 };
89245
89246 @@ -1165,10 +1172,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
89247 continue;
89248 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
89249 continue;
89250 - if (sym->st_value == addr)
89251 - return sym;
89252 /* Find a symbol nearby - addr are maybe negative */
89253 d = sym->st_value - addr;
89254 + if (d == 0)
89255 + return sym;
89256 if (d < 0)
89257 d = addr - sym->st_value;
89258 if (d < distance) {
89259 @@ -1447,6 +1454,14 @@ static void report_sec_mismatch(const char *modname,
89260 tosym, prl_to, prl_to, tosym);
89261 free(prl_to);
89262 break;
89263 + case DATA_TO_TEXT:
89264 +#if 0
89265 + fprintf(stderr,
89266 + "The %s %s:%s references\n"
89267 + "the %s %s:%s%s\n",
89268 + from, fromsec, fromsym, to, tosec, tosym, to_p);
89269 +#endif
89270 + break;
89271 }
89272 fprintf(stderr, "\n");
89273 }
89274 @@ -1681,7 +1696,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
89275 static void check_sec_ref(struct module *mod, const char *modname,
89276 struct elf_info *elf)
89277 {
89278 - int i;
89279 + unsigned int i;
89280 Elf_Shdr *sechdrs = elf->sechdrs;
89281
89282 /* Walk through all sections */
89283 @@ -1779,7 +1794,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
89284 va_end(ap);
89285 }
89286
89287 -void buf_write(struct buffer *buf, const char *s, int len)
89288 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
89289 {
89290 if (buf->size - buf->pos < len) {
89291 buf->size += len + SZ;
89292 @@ -1997,7 +2012,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
89293 if (fstat(fileno(file), &st) < 0)
89294 goto close_write;
89295
89296 - if (st.st_size != b->pos)
89297 + if (st.st_size != (off_t)b->pos)
89298 goto close_write;
89299
89300 tmp = NOFAIL(malloc(b->pos));
89301 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
89302 index 51207e4..f7d603d 100644
89303 --- a/scripts/mod/modpost.h
89304 +++ b/scripts/mod/modpost.h
89305 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
89306
89307 struct buffer {
89308 char *p;
89309 - int pos;
89310 - int size;
89311 + unsigned int pos;
89312 + unsigned int size;
89313 };
89314
89315 void __attribute__((format(printf, 2, 3)))
89316 buf_printf(struct buffer *buf, const char *fmt, ...);
89317
89318 void
89319 -buf_write(struct buffer *buf, const char *s, int len);
89320 +buf_write(struct buffer *buf, const char *s, unsigned int len);
89321
89322 struct module {
89323 struct module *next;
89324 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
89325 index 9dfcd6d..099068e 100644
89326 --- a/scripts/mod/sumversion.c
89327 +++ b/scripts/mod/sumversion.c
89328 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
89329 goto out;
89330 }
89331
89332 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
89333 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
89334 warn("writing sum in %s failed: %s\n",
89335 filename, strerror(errno));
89336 goto out;
89337 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
89338 index 68bb4ef..2f419e1 100644
89339 --- a/scripts/pnmtologo.c
89340 +++ b/scripts/pnmtologo.c
89341 @@ -244,14 +244,14 @@ static void write_header(void)
89342 fprintf(out, " * Linux logo %s\n", logoname);
89343 fputs(" */\n\n", out);
89344 fputs("#include <linux/linux_logo.h>\n\n", out);
89345 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
89346 + fprintf(out, "static unsigned char %s_data[] = {\n",
89347 logoname);
89348 }
89349
89350 static void write_footer(void)
89351 {
89352 fputs("\n};\n\n", out);
89353 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
89354 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
89355 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
89356 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
89357 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
89358 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
89359 fputs("\n};\n\n", out);
89360
89361 /* write logo clut */
89362 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
89363 + fprintf(out, "static unsigned char %s_clut[] = {\n",
89364 logoname);
89365 write_hex_cnt = 0;
89366 for (i = 0; i < logo_clutsize; i++) {
89367 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
89368 index e4fd45b..2eeb5c4 100644
89369 --- a/scripts/sortextable.h
89370 +++ b/scripts/sortextable.h
89371 @@ -106,9 +106,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
89372 const char *secstrtab;
89373 const char *strtab;
89374 char *extab_image;
89375 - int extab_index = 0;
89376 - int i;
89377 - int idx;
89378 + unsigned int extab_index = 0;
89379 + unsigned int i;
89380 + unsigned int idx;
89381
89382 shdr = (Elf_Shdr *)((char *)ehdr + _r(&ehdr->e_shoff));
89383 shstrtab_sec = shdr + r2(&ehdr->e_shstrndx);
89384 diff --git a/security/Kconfig b/security/Kconfig
89385 index e9c6ac7..952353c 100644
89386 --- a/security/Kconfig
89387 +++ b/security/Kconfig
89388 @@ -4,6 +4,925 @@
89389
89390 menu "Security options"
89391
89392 +menu "Grsecurity"
89393 +
89394 + config ARCH_TRACK_EXEC_LIMIT
89395 + bool
89396 +
89397 + config PAX_KERNEXEC_PLUGIN
89398 + bool
89399 +
89400 + config PAX_PER_CPU_PGD
89401 + bool
89402 +
89403 + config TASK_SIZE_MAX_SHIFT
89404 + int
89405 + depends on X86_64
89406 + default 47 if !PAX_PER_CPU_PGD
89407 + default 42 if PAX_PER_CPU_PGD
89408 +
89409 + config PAX_ENABLE_PAE
89410 + bool
89411 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
89412 +
89413 + config PAX_USERCOPY_SLABS
89414 + bool
89415 +
89416 +config GRKERNSEC
89417 + bool "Grsecurity"
89418 + select CRYPTO
89419 + select CRYPTO_SHA256
89420 + select PROC_FS
89421 + select STOP_MACHINE
89422 + help
89423 + If you say Y here, you will be able to configure many features
89424 + that will enhance the security of your system. It is highly
89425 + recommended that you say Y here and read through the help
89426 + for each option so that you fully understand the features and
89427 + can evaluate their usefulness for your machine.
89428 +
89429 +choice
89430 + prompt "Configuration Method"
89431 + depends on GRKERNSEC
89432 + default GRKERNSEC_CONFIG_CUSTOM
89433 + help
89434 +
89435 +config GRKERNSEC_CONFIG_AUTO
89436 + bool "Automatic"
89437 + help
89438 + If you choose this configuration method, you'll be able to answer a small
89439 + number of simple questions about how you plan to use this kernel.
89440 + The settings of grsecurity and PaX will be automatically configured for
89441 + the highest commonly-used settings within the provided constraints.
89442 +
89443 + If you require additional configuration, custom changes can still be made
89444 + from the "custom configuration" menu.
89445 +
89446 +config GRKERNSEC_CONFIG_CUSTOM
89447 + bool "Custom"
89448 + help
89449 + If you choose this configuration method, you'll be able to configure all
89450 + grsecurity and PaX settings manually. Via this method, no options are
89451 + automatically enabled.
89452 +
89453 +endchoice
89454 +
89455 +choice
89456 + prompt "Usage Type"
89457 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
89458 + default GRKERNSEC_CONFIG_SERVER
89459 + help
89460 +
89461 +config GRKERNSEC_CONFIG_SERVER
89462 + bool "Server"
89463 + help
89464 + Choose this option if you plan to use this kernel on a server.
89465 +
89466 +config GRKERNSEC_CONFIG_DESKTOP
89467 + bool "Desktop"
89468 + help
89469 + Choose this option if you plan to use this kernel on a desktop.
89470 +
89471 +endchoice
89472 +
89473 +choice
89474 + prompt "Virtualization Type"
89475 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
89476 + default GRKERNSEC_CONFIG_VIRT_NONE
89477 + help
89478 +
89479 +config GRKERNSEC_CONFIG_VIRT_NONE
89480 + bool "None"
89481 + help
89482 + Choose this option if this kernel will be run on bare metal.
89483 +
89484 +config GRKERNSEC_CONFIG_VIRT_GUEST
89485 + bool "Guest"
89486 + help
89487 + Choose this option if this kernel will be run as a VM guest.
89488 +
89489 +config GRKERNSEC_CONFIG_VIRT_HOST
89490 + bool "Host"
89491 + help
89492 + Choose this option if this kernel will be run as a VM host.
89493 +
89494 +endchoice
89495 +
89496 +choice
89497 + prompt "Virtualization Hardware"
89498 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
89499 + help
89500 +
89501 +config GRKERNSEC_CONFIG_VIRT_EPT
89502 + bool "EPT/RVI Processor Support"
89503 + depends on X86
89504 + help
89505 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
89506 + hardware virtualization. This allows for additional kernel hardening protections
89507 + to operate without additional performance impact.
89508 +
89509 + To see if your Intel processor supports EPT, see:
89510 + http://ark.intel.com/Products/VirtualizationTechnology
89511 + (Most Core i3/5/7 support EPT)
89512 +
89513 + To see if your AMD processor supports RVI, see:
89514 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
89515 +
89516 +config GRKERNSEC_CONFIG_VIRT_SOFT
89517 + bool "First-gen/No Hardware Virtualization"
89518 + help
89519 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
89520 + support hardware virtualization or doesn't support the EPT/RVI extensions.
89521 +
89522 +endchoice
89523 +
89524 +choice
89525 + prompt "Virtualization Software"
89526 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
89527 + help
89528 +
89529 +config GRKERNSEC_CONFIG_VIRT_XEN
89530 + bool "Xen"
89531 + help
89532 + Choose this option if this kernel is running as a Xen guest or host.
89533 +
89534 +config GRKERNSEC_CONFIG_VIRT_VMWARE
89535 + bool "VMWare"
89536 + help
89537 + Choose this option if this kernel is running as a VMWare guest or host.
89538 +
89539 +config GRKERNSEC_CONFIG_VIRT_KVM
89540 + bool "KVM"
89541 + help
89542 + Choose this option if this kernel is running as a KVM guest or host.
89543 +
89544 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
89545 + bool "VirtualBox"
89546 + help
89547 + Choose this option if this kernel is running as a VirtualBox guest or host.
89548 +
89549 +endchoice
89550 +
89551 +choice
89552 + prompt "Required Priorities"
89553 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
89554 + default GRKERNSEC_CONFIG_PRIORITY_PERF
89555 + help
89556 +
89557 +config GRKERNSEC_CONFIG_PRIORITY_PERF
89558 + bool "Performance"
89559 + help
89560 + Choose this option if performance is of highest priority for this deployment
89561 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
89562 + and freed memory sanitizing will be disabled.
89563 +
89564 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
89565 + bool "Security"
89566 + help
89567 + Choose this option if security is of highest priority for this deployment of
89568 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
89569 + be enabled for this kernel. In a worst-case scenario, these features can
89570 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
89571 +
89572 +endchoice
89573 +
89574 +menu "Default Special Groups"
89575 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
89576 +
89577 +config GRKERNSEC_PROC_GID
89578 + int "GID exempted from /proc restrictions"
89579 + default 1001
89580 + help
89581 + Setting this GID determines which group will be exempted from
89582 + grsecurity's /proc restrictions, allowing users of the specified
89583 + group to view network statistics and the existence of other users'
89584 + processes on the system. This GID may also be chosen at boot time
89585 + via "grsec_proc_gid=" on the kernel commandline.
89586 +
89587 +config GRKERNSEC_TPE_UNTRUSTED_GID
89588 + int "GID for TPE-untrusted users"
89589 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
89590 + default 1005
89591 + help
89592 + Setting this GID determines which group untrusted users should
89593 + be added to. These users will be placed under grsecurity's Trusted Path
89594 + Execution mechanism, preventing them from executing their own binaries.
89595 + The users will only be able to execute binaries in directories owned and
89596 + writable only by the root user. If the sysctl option is enabled, a sysctl
89597 + option with name "tpe_gid" is created.
89598 +
89599 +config GRKERNSEC_TPE_TRUSTED_GID
89600 + int "GID for TPE-trusted users"
89601 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
89602 + default 1005
89603 + help
89604 + Setting this GID determines what group TPE restrictions will be
89605 + *disabled* for. If the sysctl option is enabled, a sysctl option
89606 + with name "tpe_gid" is created.
89607 +
89608 +config GRKERNSEC_SYMLINKOWN_GID
89609 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
89610 + depends on GRKERNSEC_CONFIG_SERVER
89611 + default 1006
89612 + help
89613 + Setting this GID determines what group kernel-enforced
89614 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
89615 + is enabled, a sysctl option with name "symlinkown_gid" is created.
89616 +
89617 +
89618 +endmenu
89619 +
89620 +menu "Customize Configuration"
89621 +depends on GRKERNSEC
89622 +
89623 +menu "PaX"
89624 +
89625 +config PAX
89626 + bool "Enable various PaX features"
89627 + default y if GRKERNSEC_CONFIG_AUTO
89628 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
89629 + help
89630 + This allows you to enable various PaX features. PaX adds
89631 + intrusion prevention mechanisms to the kernel that reduce
89632 + the risks posed by exploitable memory corruption bugs.
89633 +
89634 +menu "PaX Control"
89635 + depends on PAX
89636 +
89637 +config PAX_SOFTMODE
89638 + bool 'Support soft mode'
89639 + help
89640 + Enabling this option will allow you to run PaX in soft mode, that
89641 + is, PaX features will not be enforced by default, only on executables
89642 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
89643 + support as they are the only way to mark executables for soft mode use.
89644 +
89645 + Soft mode can be activated by using the "pax_softmode=1" kernel command
89646 + line option on boot. Furthermore you can control various PaX features
89647 + at runtime via the entries in /proc/sys/kernel/pax.
89648 +
89649 +config PAX_EI_PAX
89650 + bool 'Use legacy ELF header marking'
89651 + default y if GRKERNSEC_CONFIG_AUTO
89652 + help
89653 + Enabling this option will allow you to control PaX features on
89654 + a per executable basis via the 'chpax' utility available at
89655 + http://pax.grsecurity.net/. The control flags will be read from
89656 + an otherwise reserved part of the ELF header. This marking has
89657 + numerous drawbacks (no support for soft-mode, toolchain does not
89658 + know about the non-standard use of the ELF header) therefore it
89659 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
89660 + support.
89661 +
89662 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
89663 + support as well, they will override the legacy EI_PAX marks.
89664 +
89665 + If you enable none of the marking options then all applications
89666 + will run with PaX enabled on them by default.
89667 +
89668 +config PAX_PT_PAX_FLAGS
89669 + bool 'Use ELF program header marking'
89670 + default y if GRKERNSEC_CONFIG_AUTO
89671 + help
89672 + Enabling this option will allow you to control PaX features on
89673 + a per executable basis via the 'paxctl' utility available at
89674 + http://pax.grsecurity.net/. The control flags will be read from
89675 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
89676 + has the benefits of supporting both soft mode and being fully
89677 + integrated into the toolchain (the binutils patch is available
89678 + from http://pax.grsecurity.net).
89679 +
89680 + Note that if you enable the legacy EI_PAX marking support as well,
89681 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
89682 +
89683 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
89684 + must make sure that the marks are the same if a binary has both marks.
89685 +
89686 + If you enable none of the marking options then all applications
89687 + will run with PaX enabled on them by default.
89688 +
89689 +config PAX_XATTR_PAX_FLAGS
89690 + bool 'Use filesystem extended attributes marking'
89691 + default y if GRKERNSEC_CONFIG_AUTO
89692 + select CIFS_XATTR if CIFS
89693 + select EXT2_FS_XATTR if EXT2_FS
89694 + select EXT3_FS_XATTR if EXT3_FS
89695 + select EXT4_FS_XATTR if EXT4_FS
89696 + select JFFS2_FS_XATTR if JFFS2_FS
89697 + select REISERFS_FS_XATTR if REISERFS_FS
89698 + select SQUASHFS_XATTR if SQUASHFS
89699 + select TMPFS_XATTR if TMPFS
89700 + select UBIFS_FS_XATTR if UBIFS_FS
89701 + help
89702 + Enabling this option will allow you to control PaX features on
89703 + a per executable basis via the 'setfattr' utility. The control
89704 + flags will be read from the user.pax.flags extended attribute of
89705 + the file. This marking has the benefit of supporting binary-only
89706 + applications that self-check themselves (e.g., skype) and would
89707 + not tolerate chpax/paxctl changes. The main drawback is that
89708 + extended attributes are not supported by some filesystems (e.g.,
89709 + isofs, udf, vfat) so copying files through such filesystems will
89710 + lose the extended attributes and these PaX markings.
89711 +
89712 + Note that if you enable the legacy EI_PAX marking support as well,
89713 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
89714 +
89715 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
89716 + must make sure that the marks are the same if a binary has both marks.
89717 +
89718 + If you enable none of the marking options then all applications
89719 + will run with PaX enabled on them by default.
89720 +
89721 +choice
89722 + prompt 'MAC system integration'
89723 + default PAX_HAVE_ACL_FLAGS
89724 + help
89725 + Mandatory Access Control systems have the option of controlling
89726 + PaX flags on a per executable basis, choose the method supported
89727 + by your particular system.
89728 +
89729 + - "none": if your MAC system does not interact with PaX,
89730 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
89731 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
89732 +
89733 + NOTE: this option is for developers/integrators only.
89734 +
89735 + config PAX_NO_ACL_FLAGS
89736 + bool 'none'
89737 +
89738 + config PAX_HAVE_ACL_FLAGS
89739 + bool 'direct'
89740 +
89741 + config PAX_HOOK_ACL_FLAGS
89742 + bool 'hook'
89743 +endchoice
89744 +
89745 +endmenu
89746 +
89747 +menu "Non-executable pages"
89748 + depends on PAX
89749 +
89750 +config PAX_NOEXEC
89751 + bool "Enforce non-executable pages"
89752 + default y if GRKERNSEC_CONFIG_AUTO
89753 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
89754 + help
89755 + By design some architectures do not allow for protecting memory
89756 + pages against execution or even if they do, Linux does not make
89757 + use of this feature. In practice this means that if a page is
89758 + readable (such as the stack or heap) it is also executable.
89759 +
89760 + There is a well known exploit technique that makes use of this
89761 + fact and a common programming mistake where an attacker can
89762 + introduce code of his choice somewhere in the attacked program's
89763 + memory (typically the stack or the heap) and then execute it.
89764 +
89765 + If the attacked program was running with different (typically
89766 + higher) privileges than that of the attacker, then he can elevate
89767 + his own privilege level (e.g. get a root shell, write to files for
89768 + which he does not have write access to, etc).
89769 +
89770 + Enabling this option will let you choose from various features
89771 + that prevent the injection and execution of 'foreign' code in
89772 + a program.
89773 +
89774 + This will also break programs that rely on the old behaviour and
89775 + expect that dynamically allocated memory via the malloc() family
89776 + of functions is executable (which it is not). Notable examples
89777 + are the XFree86 4.x server, the java runtime and wine.
89778 +
89779 +config PAX_PAGEEXEC
89780 + bool "Paging based non-executable pages"
89781 + default y if GRKERNSEC_CONFIG_AUTO
89782 + 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)
89783 + select S390_SWITCH_AMODE if S390
89784 + select S390_EXEC_PROTECT if S390
89785 + select ARCH_TRACK_EXEC_LIMIT if X86_32
89786 + help
89787 + This implementation is based on the paging feature of the CPU.
89788 + On i386 without hardware non-executable bit support there is a
89789 + variable but usually low performance impact, however on Intel's
89790 + P4 core based CPUs it is very high so you should not enable this
89791 + for kernels meant to be used on such CPUs.
89792 +
89793 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
89794 + with hardware non-executable bit support there is no performance
89795 + impact, on ppc the impact is negligible.
89796 +
89797 + Note that several architectures require various emulations due to
89798 + badly designed userland ABIs, this will cause a performance impact
89799 + but will disappear as soon as userland is fixed. For example, ppc
89800 + userland MUST have been built with secure-plt by a recent toolchain.
89801 +
89802 +config PAX_SEGMEXEC
89803 + bool "Segmentation based non-executable pages"
89804 + default y if GRKERNSEC_CONFIG_AUTO
89805 + depends on PAX_NOEXEC && X86_32
89806 + help
89807 + This implementation is based on the segmentation feature of the
89808 + CPU and has a very small performance impact, however applications
89809 + will be limited to a 1.5 GB address space instead of the normal
89810 + 3 GB.
89811 +
89812 +config PAX_EMUTRAMP
89813 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
89814 + default y if PARISC
89815 + help
89816 + There are some programs and libraries that for one reason or
89817 + another attempt to execute special small code snippets from
89818 + non-executable memory pages. Most notable examples are the
89819 + signal handler return code generated by the kernel itself and
89820 + the GCC trampolines.
89821 +
89822 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
89823 + such programs will no longer work under your kernel.
89824 +
89825 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
89826 + utilities to enable trampoline emulation for the affected programs
89827 + yet still have the protection provided by the non-executable pages.
89828 +
89829 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
89830 + your system will not even boot.
89831 +
89832 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
89833 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
89834 + for the affected files.
89835 +
89836 + NOTE: enabling this feature *may* open up a loophole in the
89837 + protection provided by non-executable pages that an attacker
89838 + could abuse. Therefore the best solution is to not have any
89839 + files on your system that would require this option. This can
89840 + be achieved by not using libc5 (which relies on the kernel
89841 + signal handler return code) and not using or rewriting programs
89842 + that make use of the nested function implementation of GCC.
89843 + Skilled users can just fix GCC itself so that it implements
89844 + nested function calls in a way that does not interfere with PaX.
89845 +
89846 +config PAX_EMUSIGRT
89847 + bool "Automatically emulate sigreturn trampolines"
89848 + depends on PAX_EMUTRAMP && PARISC
89849 + default y
89850 + help
89851 + Enabling this option will have the kernel automatically detect
89852 + and emulate signal return trampolines executing on the stack
89853 + that would otherwise lead to task termination.
89854 +
89855 + This solution is intended as a temporary one for users with
89856 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
89857 + Modula-3 runtime, etc) or executables linked to such, basically
89858 + everything that does not specify its own SA_RESTORER function in
89859 + normal executable memory like glibc 2.1+ does.
89860 +
89861 + On parisc you MUST enable this option, otherwise your system will
89862 + not even boot.
89863 +
89864 + NOTE: this feature cannot be disabled on a per executable basis
89865 + and since it *does* open up a loophole in the protection provided
89866 + by non-executable pages, the best solution is to not have any
89867 + files on your system that would require this option.
89868 +
89869 +config PAX_MPROTECT
89870 + bool "Restrict mprotect()"
89871 + default y if GRKERNSEC_CONFIG_AUTO
89872 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
89873 + help
89874 + Enabling this option will prevent programs from
89875 + - changing the executable status of memory pages that were
89876 + not originally created as executable,
89877 + - making read-only executable pages writable again,
89878 + - creating executable pages from anonymous memory,
89879 + - making read-only-after-relocations (RELRO) data pages writable again.
89880 +
89881 + You should say Y here to complete the protection provided by
89882 + the enforcement of non-executable pages.
89883 +
89884 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
89885 + this feature on a per file basis.
89886 +
89887 +config PAX_MPROTECT_COMPAT
89888 + bool "Use legacy/compat protection demoting (read help)"
89889 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
89890 + depends on PAX_MPROTECT
89891 + help
89892 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
89893 + by sending the proper error code to the application. For some broken
89894 + userland, this can cause problems with Python or other applications. The
89895 + current implementation however allows for applications like clamav to
89896 + detect if JIT compilation/execution is allowed and to fall back gracefully
89897 + to an interpreter-based mode if it does not. While we encourage everyone
89898 + to use the current implementation as-is and push upstream to fix broken
89899 + userland (note that the RWX logging option can assist with this), in some
89900 + environments this may not be possible. Having to disable MPROTECT
89901 + completely on certain binaries reduces the security benefit of PaX,
89902 + so this option is provided for those environments to revert to the old
89903 + behavior.
89904 +
89905 +config PAX_ELFRELOCS
89906 + bool "Allow ELF text relocations (read help)"
89907 + depends on PAX_MPROTECT
89908 + default n
89909 + help
89910 + Non-executable pages and mprotect() restrictions are effective
89911 + in preventing the introduction of new executable code into an
89912 + attacked task's address space. There remain only two venues
89913 + for this kind of attack: if the attacker can execute already
89914 + existing code in the attacked task then he can either have it
89915 + create and mmap() a file containing his code or have it mmap()
89916 + an already existing ELF library that does not have position
89917 + independent code in it and use mprotect() on it to make it
89918 + writable and copy his code there. While protecting against
89919 + the former approach is beyond PaX, the latter can be prevented
89920 + by having only PIC ELF libraries on one's system (which do not
89921 + need to relocate their code). If you are sure this is your case,
89922 + as is the case with all modern Linux distributions, then leave
89923 + this option disabled. You should say 'n' here.
89924 +
89925 +config PAX_ETEXECRELOCS
89926 + bool "Allow ELF ET_EXEC text relocations"
89927 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
89928 + select PAX_ELFRELOCS
89929 + default y
89930 + help
89931 + On some architectures there are incorrectly created applications
89932 + that require text relocations and would not work without enabling
89933 + this option. If you are an alpha, ia64 or parisc user, you should
89934 + enable this option and disable it once you have made sure that
89935 + none of your applications need it.
89936 +
89937 +config PAX_EMUPLT
89938 + bool "Automatically emulate ELF PLT"
89939 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
89940 + default y
89941 + help
89942 + Enabling this option will have the kernel automatically detect
89943 + and emulate the Procedure Linkage Table entries in ELF files.
89944 + On some architectures such entries are in writable memory, and
89945 + become non-executable leading to task termination. Therefore
89946 + it is mandatory that you enable this option on alpha, parisc,
89947 + sparc and sparc64, otherwise your system would not even boot.
89948 +
89949 + NOTE: this feature *does* open up a loophole in the protection
89950 + provided by the non-executable pages, therefore the proper
89951 + solution is to modify the toolchain to produce a PLT that does
89952 + not need to be writable.
89953 +
89954 +config PAX_DLRESOLVE
89955 + bool 'Emulate old glibc resolver stub'
89956 + depends on PAX_EMUPLT && SPARC
89957 + default n
89958 + help
89959 + This option is needed if userland has an old glibc (before 2.4)
89960 + that puts a 'save' instruction into the runtime generated resolver
89961 + stub that needs special emulation.
89962 +
89963 +config PAX_KERNEXEC
89964 + bool "Enforce non-executable kernel pages"
89965 + 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))
89966 + depends on ((X86 && (!X86_32 || X86_WP_WORKS_OK)) || (ARM && (CPU_V6 || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
89967 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
89968 + select PAX_KERNEXEC_PLUGIN if X86_64
89969 + help
89970 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
89971 + that is, enabling this option will make it harder to inject
89972 + and execute 'foreign' code in kernel memory itself.
89973 +
89974 +choice
89975 + prompt "Return Address Instrumentation Method"
89976 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
89977 + depends on PAX_KERNEXEC_PLUGIN
89978 + help
89979 + Select the method used to instrument function pointer dereferences.
89980 + Note that binary modules cannot be instrumented by this approach.
89981 +
89982 + Note that the implementation requires a gcc with plugin support,
89983 + i.e., gcc 4.5 or newer. You may need to install the supporting
89984 + headers explicitly in addition to the normal gcc package.
89985 +
89986 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
89987 + bool "bts"
89988 + help
89989 + This method is compatible with binary only modules but has
89990 + a higher runtime overhead.
89991 +
89992 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
89993 + bool "or"
89994 + depends on !PARAVIRT
89995 + help
89996 + This method is incompatible with binary only modules but has
89997 + a lower runtime overhead.
89998 +endchoice
89999 +
90000 +config PAX_KERNEXEC_PLUGIN_METHOD
90001 + string
90002 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
90003 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
90004 + default ""
90005 +
90006 +config PAX_KERNEXEC_MODULE_TEXT
90007 + int "Minimum amount of memory reserved for module code"
90008 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
90009 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
90010 + depends on PAX_KERNEXEC && X86_32 && MODULES
90011 + help
90012 + Due to implementation details the kernel must reserve a fixed
90013 + amount of memory for module code at compile time that cannot be
90014 + changed at runtime. Here you can specify the minimum amount
90015 + in MB that will be reserved. Due to the same implementation
90016 + details this size will always be rounded up to the next 2/4 MB
90017 + boundary (depends on PAE) so the actually available memory for
90018 + module code will usually be more than this minimum.
90019 +
90020 + The default 4 MB should be enough for most users but if you have
90021 + an excessive number of modules (e.g., most distribution configs
90022 + compile many drivers as modules) or use huge modules such as
90023 + nvidia's kernel driver, you will need to adjust this amount.
90024 + A good rule of thumb is to look at your currently loaded kernel
90025 + modules and add up their sizes.
90026 +
90027 +endmenu
90028 +
90029 +menu "Address Space Layout Randomization"
90030 + depends on PAX
90031 +
90032 +config PAX_ASLR
90033 + bool "Address Space Layout Randomization"
90034 + default y if GRKERNSEC_CONFIG_AUTO
90035 + help
90036 + Many if not most exploit techniques rely on the knowledge of
90037 + certain addresses in the attacked program. The following options
90038 + will allow the kernel to apply a certain amount of randomization
90039 + to specific parts of the program thereby forcing an attacker to
90040 + guess them in most cases. Any failed guess will most likely crash
90041 + the attacked program which allows the kernel to detect such attempts
90042 + and react on them. PaX itself provides no reaction mechanisms,
90043 + instead it is strongly encouraged that you make use of Nergal's
90044 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
90045 + (http://www.grsecurity.net/) built-in crash detection features or
90046 + develop one yourself.
90047 +
90048 + By saying Y here you can choose to randomize the following areas:
90049 + - top of the task's kernel stack
90050 + - top of the task's userland stack
90051 + - base address for mmap() requests that do not specify one
90052 + (this includes all libraries)
90053 + - base address of the main executable
90054 +
90055 + It is strongly recommended to say Y here as address space layout
90056 + randomization has negligible impact on performance yet it provides
90057 + a very effective protection.
90058 +
90059 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
90060 + this feature on a per file basis.
90061 +
90062 +config PAX_RANDKSTACK
90063 + bool "Randomize kernel stack base"
90064 + default y if GRKERNSEC_CONFIG_AUTO
90065 + depends on X86_TSC && X86
90066 + help
90067 + By saying Y here the kernel will randomize every task's kernel
90068 + stack on every system call. This will not only force an attacker
90069 + to guess it but also prevent him from making use of possible
90070 + leaked information about it.
90071 +
90072 + Since the kernel stack is a rather scarce resource, randomization
90073 + may cause unexpected stack overflows, therefore you should very
90074 + carefully test your system. Note that once enabled in the kernel
90075 + configuration, this feature cannot be disabled on a per file basis.
90076 +
90077 +config PAX_RANDUSTACK
90078 + bool "Randomize user stack base"
90079 + default y if GRKERNSEC_CONFIG_AUTO
90080 + depends on PAX_ASLR
90081 + help
90082 + By saying Y here the kernel will randomize every task's userland
90083 + stack. The randomization is done in two steps where the second
90084 + one may apply a big amount of shift to the top of the stack and
90085 + cause problems for programs that want to use lots of memory (more
90086 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
90087 + For this reason the second step can be controlled by 'chpax' or
90088 + 'paxctl' on a per file basis.
90089 +
90090 +config PAX_RANDMMAP
90091 + bool "Randomize mmap() base"
90092 + default y if GRKERNSEC_CONFIG_AUTO
90093 + depends on PAX_ASLR
90094 + help
90095 + By saying Y here the kernel will use a randomized base address for
90096 + mmap() requests that do not specify one themselves. As a result
90097 + all dynamically loaded libraries will appear at random addresses
90098 + and therefore be harder to exploit by a technique where an attacker
90099 + attempts to execute library code for his purposes (e.g. spawn a
90100 + shell from an exploited program that is running at an elevated
90101 + privilege level).
90102 +
90103 + Furthermore, if a program is relinked as a dynamic ELF file, its
90104 + base address will be randomized as well, completing the full
90105 + randomization of the address space layout. Attacking such programs
90106 + becomes a guess game. You can find an example of doing this at
90107 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
90108 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
90109 +
90110 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
90111 + feature on a per file basis.
90112 +
90113 +endmenu
90114 +
90115 +menu "Miscellaneous hardening features"
90116 +
90117 +config PAX_MEMORY_SANITIZE
90118 + bool "Sanitize all freed memory"
90119 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
90120 + depends on !HIBERNATION
90121 + help
90122 + By saying Y here the kernel will erase memory pages as soon as they
90123 + are freed. This in turn reduces the lifetime of data stored in the
90124 + pages, making it less likely that sensitive information such as
90125 + passwords, cryptographic secrets, etc stay in memory for too long.
90126 +
90127 + This is especially useful for programs whose runtime is short, long
90128 + lived processes and the kernel itself benefit from this as long as
90129 + they operate on whole memory pages and ensure timely freeing of pages
90130 + that may hold sensitive information.
90131 +
90132 + The tradeoff is performance impact, on a single CPU system kernel
90133 + compilation sees a 3% slowdown, other systems and workloads may vary
90134 + and you are advised to test this feature on your expected workload
90135 + before deploying it.
90136 +
90137 + Note that this feature does not protect data stored in live pages,
90138 + e.g., process memory swapped to disk may stay there for a long time.
90139 +
90140 +config PAX_MEMORY_STACKLEAK
90141 + bool "Sanitize kernel stack"
90142 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
90143 + depends on X86
90144 + help
90145 + By saying Y here the kernel will erase the kernel stack before it
90146 + returns from a system call. This in turn reduces the information
90147 + that a kernel stack leak bug can reveal.
90148 +
90149 + Note that such a bug can still leak information that was put on
90150 + the stack by the current system call (the one eventually triggering
90151 + the bug) but traces of earlier system calls on the kernel stack
90152 + cannot leak anymore.
90153 +
90154 + The tradeoff is performance impact: on a single CPU system kernel
90155 + compilation sees a 1% slowdown, other systems and workloads may vary
90156 + and you are advised to test this feature on your expected workload
90157 + before deploying it.
90158 +
90159 + Note that the full feature requires a gcc with plugin support,
90160 + i.e., gcc 4.5 or newer. You may need to install the supporting
90161 + headers explicitly in addition to the normal gcc package. Using
90162 + older gcc versions means that functions with large enough stack
90163 + frames may leave uninitialized memory behind that may be exposed
90164 + to a later syscall leaking the stack.
90165 +
90166 +config PAX_MEMORY_UDEREF
90167 + bool "Prevent invalid userland pointer dereference"
90168 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
90169 + depends on (X86 || (ARM && (CPU_V6 || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
90170 + select PAX_PER_CPU_PGD if X86_64
90171 + help
90172 + By saying Y here the kernel will be prevented from dereferencing
90173 + userland pointers in contexts where the kernel expects only kernel
90174 + pointers. This is both a useful runtime debugging feature and a
90175 + security measure that prevents exploiting a class of kernel bugs.
90176 +
90177 + The tradeoff is that some virtualization solutions may experience
90178 + a huge slowdown and therefore you should not enable this feature
90179 + for kernels meant to run in such environments. Whether a given VM
90180 + solution is affected or not is best determined by simply trying it
90181 + out, the performance impact will be obvious right on boot as this
90182 + mechanism engages from very early on. A good rule of thumb is that
90183 + VMs running on CPUs without hardware virtualization support (i.e.,
90184 + the majority of IA-32 CPUs) will likely experience the slowdown.
90185 +
90186 +config PAX_REFCOUNT
90187 + bool "Prevent various kernel object reference counter overflows"
90188 + default y if GRKERNSEC_CONFIG_AUTO
90189 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
90190 + help
90191 + By saying Y here the kernel will detect and prevent overflowing
90192 + various (but not all) kinds of object reference counters. Such
90193 + overflows can normally occur due to bugs only and are often, if
90194 + not always, exploitable.
90195 +
90196 + The tradeoff is that data structures protected by an overflowed
90197 + refcount will never be freed and therefore will leak memory. Note
90198 + that this leak also happens even without this protection but in
90199 + that case the overflow can eventually trigger the freeing of the
90200 + data structure while it is still being used elsewhere, resulting
90201 + in the exploitable situation that this feature prevents.
90202 +
90203 + Since this has a negligible performance impact, you should enable
90204 + this feature.
90205 +
90206 +config PAX_CONSTIFY_PLUGIN
90207 + bool "Automatically constify eligible structures"
90208 + default y
90209 + depends on !UML
90210 + help
90211 + By saying Y here the compiler will automatically constify a class
90212 + of types that contain only function pointers. This reduces the
90213 + kernel's attack surface and also produces a better memory layout.
90214 +
90215 + Note that the implementation requires a gcc with plugin support,
90216 + i.e., gcc 4.5 or newer. You may need to install the supporting
90217 + headers explicitly in addition to the normal gcc package.
90218 +
90219 + Note that if some code really has to modify constified variables
90220 + then the source code will have to be patched to allow it. Examples
90221 + can be found in PaX itself (the no_const attribute) and for some
90222 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
90223 +
90224 +config PAX_USERCOPY
90225 + bool "Harden heap object copies between kernel and userland"
90226 + default y if GRKERNSEC_CONFIG_AUTO
90227 + depends on ARM || IA64 || PPC || SPARC || X86
90228 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
90229 + select PAX_USERCOPY_SLABS
90230 + help
90231 + By saying Y here the kernel will enforce the size of heap objects
90232 + when they are copied in either direction between the kernel and
90233 + userland, even if only a part of the heap object is copied.
90234 +
90235 + Specifically, this checking prevents information leaking from the
90236 + kernel heap during kernel to userland copies (if the kernel heap
90237 + object is otherwise fully initialized) and prevents kernel heap
90238 + overflows during userland to kernel copies.
90239 +
90240 + Note that the current implementation provides the strictest bounds
90241 + checks for the SLUB allocator.
90242 +
90243 + Enabling this option also enables per-slab cache protection against
90244 + data in a given cache being copied into/out of via userland
90245 + accessors. Though the whitelist of regions will be reduced over
90246 + time, it notably protects important data structures like task structs.
90247 +
90248 + If frame pointers are enabled on x86, this option will also restrict
90249 + copies into and out of the kernel stack to local variables within a
90250 + single frame.
90251 +
90252 + Since this has a negligible performance impact, you should enable
90253 + this feature.
90254 +
90255 +
90256 +config PAX_USERCOPY_DEBUG
90257 + bool
90258 + depends on X86 && PAX_USERCOPY
90259 + default n
90260 +
90261 +config PAX_SIZE_OVERFLOW
90262 + bool "Prevent various integer overflows in function size parameters"
90263 + default y if GRKERNSEC_CONFIG_AUTO
90264 + depends on X86
90265 + help
90266 + By saying Y here the kernel recomputes expressions of function
90267 + arguments marked by a size_overflow attribute with double integer
90268 + precision (DImode/TImode for 32/64 bit integer types).
90269 +
90270 + The recomputed argument is checked against TYPE_MAX and an event
90271 + is logged on overflow and the triggering process is killed.
90272 +
90273 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
90274 +
90275 + Note that the implementation requires a gcc with plugin support,
90276 + i.e., gcc 4.5 or newer. You may need to install the supporting
90277 + headers explicitly in addition to the normal gcc package.
90278 +
90279 +config PAX_LATENT_ENTROPY
90280 + bool "Generate some entropy during boot"
90281 + default y if GRKERNSEC_CONFIG_AUTO
90282 + help
90283 + By saying Y here the kernel will instrument early boot code to
90284 + extract some entropy from both original and artificially created
90285 + program state. This will help especially embedded systems where
90286 + there is little 'natural' source of entropy normally. The cost
90287 + is some slowdown of the boot process.
90288 +
90289 + When pax_extra_latent_entropy is passed on the kernel command line,
90290 + entropy will be extracted from up to the first 4GB of RAM while the
90291 + runtime memory allocator is being initialized. This costs even more
90292 + slowdown of the boot process.
90293 +
90294 + Note that the implementation requires a gcc with plugin support,
90295 + i.e., gcc 4.5 or newer. You may need to install the supporting
90296 + headers explicitly in addition to the normal gcc package.
90297 +
90298 + Note that entropy extracted this way is not cryptographically
90299 + secure!
90300 +
90301 +endmenu
90302 +
90303 +endmenu
90304 +
90305 +source grsecurity/Kconfig
90306 +
90307 +endmenu
90308 +
90309 +endmenu
90310 +
90311 source security/keys/Kconfig
90312
90313 config SECURITY_DMESG_RESTRICT
90314 @@ -103,7 +1022,7 @@ config INTEL_TXT
90315 config LSM_MMAP_MIN_ADDR
90316 int "Low address space for LSM to protect from user allocation"
90317 depends on SECURITY && SECURITY_SELINUX
90318 - default 32768 if ARM
90319 + default 32768 if ALPHA || ARM || PARISC || SPARC32
90320 default 65536
90321 help
90322 This is the portion of low virtual memory which should be protected
90323 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
90324 index 8c2a7f6..b133ac9 100644
90325 --- a/security/apparmor/lsm.c
90326 +++ b/security/apparmor/lsm.c
90327 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
90328 return error;
90329 }
90330
90331 -static struct security_operations apparmor_ops = {
90332 +static struct security_operations apparmor_ops __read_only = {
90333 .name = "apparmor",
90334
90335 .ptrace_access_check = apparmor_ptrace_access_check,
90336 diff --git a/security/commoncap.c b/security/commoncap.c
90337 index 7ee08c7..8d1a9d6 100644
90338 --- a/security/commoncap.c
90339 +++ b/security/commoncap.c
90340 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
90341 return 0;
90342 }
90343
90344 +/* returns:
90345 + 1 for suid privilege
90346 + 2 for sgid privilege
90347 + 3 for fscap privilege
90348 +*/
90349 +int is_privileged_binary(const struct dentry *dentry)
90350 +{
90351 + struct cpu_vfs_cap_data capdata;
90352 + struct inode *inode = dentry->d_inode;
90353 +
90354 + if (!inode || S_ISDIR(inode->i_mode))
90355 + return 0;
90356 +
90357 + if (inode->i_mode & S_ISUID)
90358 + return 1;
90359 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
90360 + return 2;
90361 +
90362 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
90363 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
90364 + return 3;
90365 + }
90366 +
90367 + return 0;
90368 +}
90369 +
90370 /*
90371 * Attempt to get the on-exec apply capability sets for an executable file from
90372 * its xattrs and, if present, apply them to the proposed credentials being
90373 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
90374 const struct cred *cred = current_cred();
90375 kuid_t root_uid = make_kuid(cred->user_ns, 0);
90376
90377 + if (gr_acl_enable_at_secure())
90378 + return 1;
90379 +
90380 if (!uid_eq(cred->uid, root_uid)) {
90381 if (bprm->cap_effective)
90382 return 1;
90383 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
90384 index 079a85d..12e93f8 100644
90385 --- a/security/integrity/ima/ima.h
90386 +++ b/security/integrity/ima/ima.h
90387 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
90388 extern spinlock_t ima_queue_lock;
90389
90390 struct ima_h_table {
90391 - atomic_long_t len; /* number of stored measurements in the list */
90392 - atomic_long_t violations;
90393 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
90394 + atomic_long_unchecked_t violations;
90395 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
90396 };
90397 extern struct ima_h_table ima_htable;
90398 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
90399 index 0cea3db..2f0ef77 100644
90400 --- a/security/integrity/ima/ima_api.c
90401 +++ b/security/integrity/ima/ima_api.c
90402 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
90403 int result;
90404
90405 /* can overflow, only indicator */
90406 - atomic_long_inc(&ima_htable.violations);
90407 + atomic_long_inc_unchecked(&ima_htable.violations);
90408
90409 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
90410 if (!entry) {
90411 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
90412 index 38477c9..87a60c7 100644
90413 --- a/security/integrity/ima/ima_fs.c
90414 +++ b/security/integrity/ima/ima_fs.c
90415 @@ -28,12 +28,12 @@
90416 static int valid_policy = 1;
90417 #define TMPBUFLEN 12
90418 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
90419 - loff_t *ppos, atomic_long_t *val)
90420 + loff_t *ppos, atomic_long_unchecked_t *val)
90421 {
90422 char tmpbuf[TMPBUFLEN];
90423 ssize_t len;
90424
90425 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
90426 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
90427 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
90428 }
90429
90430 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
90431 index 55a6271..ad829c3 100644
90432 --- a/security/integrity/ima/ima_queue.c
90433 +++ b/security/integrity/ima/ima_queue.c
90434 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
90435 INIT_LIST_HEAD(&qe->later);
90436 list_add_tail_rcu(&qe->later, &ima_measurements);
90437
90438 - atomic_long_inc(&ima_htable.len);
90439 + atomic_long_inc_unchecked(&ima_htable.len);
90440 key = ima_hash_key(entry->digest);
90441 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
90442 return 0;
90443 diff --git a/security/keys/compat.c b/security/keys/compat.c
90444 index 1c26176..64a1ba2 100644
90445 --- a/security/keys/compat.c
90446 +++ b/security/keys/compat.c
90447 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
90448 if (ret == 0)
90449 goto no_payload_free;
90450
90451 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
90452 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
90453
90454 if (iov != iovstack)
90455 kfree(iov);
90456 diff --git a/security/keys/key.c b/security/keys/key.c
90457 index 8fb7c7b..ba3610d 100644
90458 --- a/security/keys/key.c
90459 +++ b/security/keys/key.c
90460 @@ -284,7 +284,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
90461
90462 atomic_set(&key->usage, 1);
90463 init_rwsem(&key->sem);
90464 - lockdep_set_class(&key->sem, &type->lock_class);
90465 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
90466 key->type = type;
90467 key->user = user;
90468 key->quotalen = quotalen;
90469 @@ -1032,7 +1032,9 @@ int register_key_type(struct key_type *ktype)
90470 struct key_type *p;
90471 int ret;
90472
90473 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
90474 + pax_open_kernel();
90475 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
90476 + pax_close_kernel();
90477
90478 ret = -EEXIST;
90479 down_write(&key_types_sem);
90480 @@ -1044,7 +1046,7 @@ int register_key_type(struct key_type *ktype)
90481 }
90482
90483 /* store the type */
90484 - list_add(&ktype->link, &key_types_list);
90485 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
90486
90487 pr_notice("Key type %s registered\n", ktype->name);
90488 ret = 0;
90489 @@ -1066,7 +1068,7 @@ EXPORT_SYMBOL(register_key_type);
90490 void unregister_key_type(struct key_type *ktype)
90491 {
90492 down_write(&key_types_sem);
90493 - list_del_init(&ktype->link);
90494 + pax_list_del_init((struct list_head *)&ktype->link);
90495 downgrade_write(&key_types_sem);
90496 key_gc_keytype(ktype);
90497 pr_notice("Key type %s unregistered\n", ktype->name);
90498 @@ -1084,10 +1086,10 @@ void __init key_init(void)
90499 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
90500
90501 /* add the special key types */
90502 - list_add_tail(&key_type_keyring.link, &key_types_list);
90503 - list_add_tail(&key_type_dead.link, &key_types_list);
90504 - list_add_tail(&key_type_user.link, &key_types_list);
90505 - list_add_tail(&key_type_logon.link, &key_types_list);
90506 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
90507 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
90508 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
90509 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
90510
90511 /* record the root user tracking */
90512 rb_link_node(&root_key_user.node,
90513 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
90514 index 4b5c948..2054dc1 100644
90515 --- a/security/keys/keyctl.c
90516 +++ b/security/keys/keyctl.c
90517 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
90518 /*
90519 * Copy the iovec data from userspace
90520 */
90521 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
90522 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
90523 unsigned ioc)
90524 {
90525 for (; ioc > 0; ioc--) {
90526 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
90527 * If successful, 0 will be returned.
90528 */
90529 long keyctl_instantiate_key_common(key_serial_t id,
90530 - const struct iovec *payload_iov,
90531 + const struct iovec __user *payload_iov,
90532 unsigned ioc,
90533 size_t plen,
90534 key_serial_t ringid)
90535 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
90536 [0].iov_len = plen
90537 };
90538
90539 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
90540 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
90541 }
90542
90543 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
90544 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
90545 if (ret == 0)
90546 goto no_payload_free;
90547
90548 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
90549 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
90550 err:
90551 if (iov != iovstack)
90552 kfree(iov);
90553 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
90554 index 6ece7f2..ecdb55c 100644
90555 --- a/security/keys/keyring.c
90556 +++ b/security/keys/keyring.c
90557 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
90558 ret = -EFAULT;
90559
90560 for (loop = 0; loop < klist->nkeys; loop++) {
90561 + key_serial_t serial;
90562 key = rcu_deref_link_locked(klist, loop,
90563 keyring);
90564 + serial = key->serial;
90565
90566 tmp = sizeof(key_serial_t);
90567 if (tmp > buflen)
90568 tmp = buflen;
90569
90570 - if (copy_to_user(buffer,
90571 - &key->serial,
90572 - tmp) != 0)
90573 + if (copy_to_user(buffer, &serial, tmp))
90574 goto error;
90575
90576 buflen -= tmp;
90577 diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
90578 index 58dfe08..c5ec083 100644
90579 --- a/security/keys/process_keys.c
90580 +++ b/security/keys/process_keys.c
90581 @@ -57,7 +57,7 @@ int install_user_keyrings(void)
90582
90583 kenter("%p{%u}", user, uid);
90584
90585 - if (user->uid_keyring) {
90586 + if (user->uid_keyring && user->session_keyring) {
90587 kleave(" = 0 [exist]");
90588 return 0;
90589 }
90590 diff --git a/security/min_addr.c b/security/min_addr.c
90591 index f728728..6457a0c 100644
90592 --- a/security/min_addr.c
90593 +++ b/security/min_addr.c
90594 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
90595 */
90596 static void update_mmap_min_addr(void)
90597 {
90598 +#ifndef SPARC
90599 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
90600 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
90601 mmap_min_addr = dac_mmap_min_addr;
90602 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
90603 #else
90604 mmap_min_addr = dac_mmap_min_addr;
90605 #endif
90606 +#endif
90607 }
90608
90609 /*
90610 diff --git a/security/security.c b/security/security.c
90611 index 7b88c6a..1e3ea8f 100644
90612 --- a/security/security.c
90613 +++ b/security/security.c
90614 @@ -20,6 +20,7 @@
90615 #include <linux/ima.h>
90616 #include <linux/evm.h>
90617 #include <linux/fsnotify.h>
90618 +#include <linux/mm.h>
90619 #include <linux/mman.h>
90620 #include <linux/mount.h>
90621 #include <linux/personality.h>
90622 @@ -32,8 +33,8 @@
90623 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
90624 CONFIG_DEFAULT_SECURITY;
90625
90626 -static struct security_operations *security_ops;
90627 -static struct security_operations default_security_ops = {
90628 +static struct security_operations *security_ops __read_only;
90629 +static struct security_operations default_security_ops __read_only = {
90630 .name = "default",
90631 };
90632
90633 @@ -74,7 +75,9 @@ int __init security_init(void)
90634
90635 void reset_security_ops(void)
90636 {
90637 + pax_open_kernel();
90638 security_ops = &default_security_ops;
90639 + pax_close_kernel();
90640 }
90641
90642 /* Save user chosen LSM */
90643 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
90644 index ef26e96..642fb78 100644
90645 --- a/security/selinux/hooks.c
90646 +++ b/security/selinux/hooks.c
90647 @@ -95,8 +95,6 @@
90648
90649 #define NUM_SEL_MNT_OPTS 5
90650
90651 -extern struct security_operations *security_ops;
90652 -
90653 /* SECMARK reference count */
90654 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
90655
90656 @@ -5501,7 +5499,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
90657
90658 #endif
90659
90660 -static struct security_operations selinux_ops = {
90661 +static struct security_operations selinux_ops __read_only = {
90662 .name = "selinux",
90663
90664 .ptrace_access_check = selinux_ptrace_access_check,
90665 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
90666 index 65f67cb..3f141ef 100644
90667 --- a/security/selinux/include/xfrm.h
90668 +++ b/security/selinux/include/xfrm.h
90669 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
90670
90671 static inline void selinux_xfrm_notify_policyload(void)
90672 {
90673 - atomic_inc(&flow_cache_genid);
90674 + atomic_inc_unchecked(&flow_cache_genid);
90675 rt_genid_bump(&init_net);
90676 }
90677 #else
90678 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
90679 index 38be92c..21f49ee 100644
90680 --- a/security/smack/smack_lsm.c
90681 +++ b/security/smack/smack_lsm.c
90682 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
90683 return 0;
90684 }
90685
90686 -struct security_operations smack_ops = {
90687 +struct security_operations smack_ops __read_only = {
90688 .name = "smack",
90689
90690 .ptrace_access_check = smack_ptrace_access_check,
90691 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
90692 index 390c646..f2f8db3 100644
90693 --- a/security/tomoyo/mount.c
90694 +++ b/security/tomoyo/mount.c
90695 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
90696 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
90697 need_dev = -1; /* dev_name is a directory */
90698 } else {
90699 + if (!capable(CAP_SYS_ADMIN)) {
90700 + error = -EPERM;
90701 + goto out;
90702 + }
90703 fstype = get_fs_type(type);
90704 if (!fstype) {
90705 error = -ENODEV;
90706 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
90707 index a2ee362..5754f34 100644
90708 --- a/security/tomoyo/tomoyo.c
90709 +++ b/security/tomoyo/tomoyo.c
90710 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
90711 * tomoyo_security_ops is a "struct security_operations" which is used for
90712 * registering TOMOYO.
90713 */
90714 -static struct security_operations tomoyo_security_ops = {
90715 +static struct security_operations tomoyo_security_ops __read_only = {
90716 .name = "tomoyo",
90717 .cred_alloc_blank = tomoyo_cred_alloc_blank,
90718 .cred_prepare = tomoyo_cred_prepare,
90719 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
90720 index 20ef514..4182bed 100644
90721 --- a/security/yama/Kconfig
90722 +++ b/security/yama/Kconfig
90723 @@ -1,6 +1,6 @@
90724 config SECURITY_YAMA
90725 bool "Yama support"
90726 - depends on SECURITY
90727 + depends on SECURITY && !GRKERNSEC
90728 select SECURITYFS
90729 select SECURITY_PATH
90730 default n
90731 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
90732 index 23414b9..b92b314 100644
90733 --- a/security/yama/yama_lsm.c
90734 +++ b/security/yama/yama_lsm.c
90735 @@ -367,7 +367,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
90736 }
90737
90738 #ifndef CONFIG_SECURITY_YAMA_STACKED
90739 -static struct security_operations yama_ops = {
90740 +static struct security_operations yama_ops __read_only = {
90741 .name = "yama",
90742
90743 .ptrace_access_check = yama_ptrace_access_check,
90744 @@ -378,28 +378,24 @@ static struct security_operations yama_ops = {
90745 #endif
90746
90747 #ifdef CONFIG_SYSCTL
90748 +static int zero __read_only;
90749 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
90750 +
90751 static int yama_dointvec_minmax(struct ctl_table *table, int write,
90752 void __user *buffer, size_t *lenp, loff_t *ppos)
90753 {
90754 - int rc;
90755 + ctl_table_no_const yama_table;
90756
90757 if (write && !capable(CAP_SYS_PTRACE))
90758 return -EPERM;
90759
90760 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90761 - if (rc)
90762 - return rc;
90763 -
90764 + yama_table = *table;
90765 /* Lock the max value if it ever gets set. */
90766 - if (write && *(int *)table->data == *(int *)table->extra2)
90767 - table->extra1 = table->extra2;
90768 -
90769 - return rc;
90770 + if (ptrace_scope == max_scope)
90771 + yama_table.extra1 = &max_scope;
90772 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
90773 }
90774
90775 -static int zero;
90776 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
90777 -
90778 struct ctl_path yama_sysctl_path[] = {
90779 { .procname = "kernel", },
90780 { .procname = "yama", },
90781 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
90782 index 4cedc69..e59d8a3 100644
90783 --- a/sound/aoa/codecs/onyx.c
90784 +++ b/sound/aoa/codecs/onyx.c
90785 @@ -54,7 +54,7 @@ struct onyx {
90786 spdif_locked:1,
90787 analog_locked:1,
90788 original_mute:2;
90789 - int open_count;
90790 + local_t open_count;
90791 struct codec_info *codec_info;
90792
90793 /* mutex serializes concurrent access to the device
90794 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
90795 struct onyx *onyx = cii->codec_data;
90796
90797 mutex_lock(&onyx->mutex);
90798 - onyx->open_count++;
90799 + local_inc(&onyx->open_count);
90800 mutex_unlock(&onyx->mutex);
90801
90802 return 0;
90803 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
90804 struct onyx *onyx = cii->codec_data;
90805
90806 mutex_lock(&onyx->mutex);
90807 - onyx->open_count--;
90808 - if (!onyx->open_count)
90809 + if (local_dec_and_test(&onyx->open_count))
90810 onyx->spdif_locked = onyx->analog_locked = 0;
90811 mutex_unlock(&onyx->mutex);
90812
90813 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
90814 index ffd2025..df062c9 100644
90815 --- a/sound/aoa/codecs/onyx.h
90816 +++ b/sound/aoa/codecs/onyx.h
90817 @@ -11,6 +11,7 @@
90818 #include <linux/i2c.h>
90819 #include <asm/pmac_low_i2c.h>
90820 #include <asm/prom.h>
90821 +#include <asm/local.h>
90822
90823 /* PCM3052 register definitions */
90824
90825 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
90826 index 4c1cc51..16040040 100644
90827 --- a/sound/core/oss/pcm_oss.c
90828 +++ b/sound/core/oss/pcm_oss.c
90829 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
90830 if (in_kernel) {
90831 mm_segment_t fs;
90832 fs = snd_enter_user();
90833 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
90834 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
90835 snd_leave_user(fs);
90836 } else {
90837 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
90838 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
90839 }
90840 if (ret != -EPIPE && ret != -ESTRPIPE)
90841 break;
90842 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
90843 if (in_kernel) {
90844 mm_segment_t fs;
90845 fs = snd_enter_user();
90846 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
90847 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
90848 snd_leave_user(fs);
90849 } else {
90850 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
90851 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
90852 }
90853 if (ret == -EPIPE) {
90854 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
90855 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
90856 struct snd_pcm_plugin_channel *channels;
90857 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
90858 if (!in_kernel) {
90859 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
90860 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
90861 return -EFAULT;
90862 buf = runtime->oss.buffer;
90863 }
90864 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
90865 }
90866 } else {
90867 tmp = snd_pcm_oss_write2(substream,
90868 - (const char __force *)buf,
90869 + (const char __force_kernel *)buf,
90870 runtime->oss.period_bytes, 0);
90871 if (tmp <= 0)
90872 goto err;
90873 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
90874 struct snd_pcm_runtime *runtime = substream->runtime;
90875 snd_pcm_sframes_t frames, frames1;
90876 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
90877 - char __user *final_dst = (char __force __user *)buf;
90878 + char __user *final_dst = (char __force_user *)buf;
90879 if (runtime->oss.plugin_first) {
90880 struct snd_pcm_plugin_channel *channels;
90881 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
90882 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
90883 xfer += tmp;
90884 runtime->oss.buffer_used -= tmp;
90885 } else {
90886 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
90887 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
90888 runtime->oss.period_bytes, 0);
90889 if (tmp <= 0)
90890 goto err;
90891 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
90892 size1);
90893 size1 /= runtime->channels; /* frames */
90894 fs = snd_enter_user();
90895 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
90896 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
90897 snd_leave_user(fs);
90898 }
90899 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
90900 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
90901 index af49721..e85058e 100644
90902 --- a/sound/core/pcm_compat.c
90903 +++ b/sound/core/pcm_compat.c
90904 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
90905 int err;
90906
90907 fs = snd_enter_user();
90908 - err = snd_pcm_delay(substream, &delay);
90909 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
90910 snd_leave_user(fs);
90911 if (err < 0)
90912 return err;
90913 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
90914 index 09b4286..8620fac 100644
90915 --- a/sound/core/pcm_native.c
90916 +++ b/sound/core/pcm_native.c
90917 @@ -2806,11 +2806,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
90918 switch (substream->stream) {
90919 case SNDRV_PCM_STREAM_PLAYBACK:
90920 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
90921 - (void __user *)arg);
90922 + (void __force_user *)arg);
90923 break;
90924 case SNDRV_PCM_STREAM_CAPTURE:
90925 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
90926 - (void __user *)arg);
90927 + (void __force_user *)arg);
90928 break;
90929 default:
90930 result = -EINVAL;
90931 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
90932 index 040c60e..989a19a 100644
90933 --- a/sound/core/seq/seq_device.c
90934 +++ b/sound/core/seq/seq_device.c
90935 @@ -64,7 +64,7 @@ struct ops_list {
90936 int argsize; /* argument size */
90937
90938 /* operators */
90939 - struct snd_seq_dev_ops ops;
90940 + struct snd_seq_dev_ops *ops;
90941
90942 /* registered devices */
90943 struct list_head dev_list; /* list of devices */
90944 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
90945
90946 mutex_lock(&ops->reg_mutex);
90947 /* copy driver operators */
90948 - ops->ops = *entry;
90949 + ops->ops = entry;
90950 ops->driver |= DRIVER_LOADED;
90951 ops->argsize = argsize;
90952
90953 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
90954 dev->name, ops->id, ops->argsize, dev->argsize);
90955 return -EINVAL;
90956 }
90957 - if (ops->ops.init_device(dev) >= 0) {
90958 + if (ops->ops->init_device(dev) >= 0) {
90959 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
90960 ops->num_init_devices++;
90961 } else {
90962 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
90963 dev->name, ops->id, ops->argsize, dev->argsize);
90964 return -EINVAL;
90965 }
90966 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
90967 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
90968 dev->status = SNDRV_SEQ_DEVICE_FREE;
90969 dev->driver_data = NULL;
90970 ops->num_init_devices--;
90971 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
90972 index 4e0dd22..7a1f32c 100644
90973 --- a/sound/drivers/mts64.c
90974 +++ b/sound/drivers/mts64.c
90975 @@ -29,6 +29,7 @@
90976 #include <sound/initval.h>
90977 #include <sound/rawmidi.h>
90978 #include <sound/control.h>
90979 +#include <asm/local.h>
90980
90981 #define CARD_NAME "Miditerminal 4140"
90982 #define DRIVER_NAME "MTS64"
90983 @@ -67,7 +68,7 @@ struct mts64 {
90984 struct pardevice *pardev;
90985 int pardev_claimed;
90986
90987 - int open_count;
90988 + local_t open_count;
90989 int current_midi_output_port;
90990 int current_midi_input_port;
90991 u8 mode[MTS64_NUM_INPUT_PORTS];
90992 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
90993 {
90994 struct mts64 *mts = substream->rmidi->private_data;
90995
90996 - if (mts->open_count == 0) {
90997 + if (local_read(&mts->open_count) == 0) {
90998 /* We don't need a spinlock here, because this is just called
90999 if the device has not been opened before.
91000 So there aren't any IRQs from the device */
91001 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
91002
91003 msleep(50);
91004 }
91005 - ++(mts->open_count);
91006 + local_inc(&mts->open_count);
91007
91008 return 0;
91009 }
91010 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
91011 struct mts64 *mts = substream->rmidi->private_data;
91012 unsigned long flags;
91013
91014 - --(mts->open_count);
91015 - if (mts->open_count == 0) {
91016 + if (local_dec_return(&mts->open_count) == 0) {
91017 /* We need the spinlock_irqsave here because we can still
91018 have IRQs at this point */
91019 spin_lock_irqsave(&mts->lock, flags);
91020 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
91021
91022 msleep(500);
91023
91024 - } else if (mts->open_count < 0)
91025 - mts->open_count = 0;
91026 + } else if (local_read(&mts->open_count) < 0)
91027 + local_set(&mts->open_count, 0);
91028
91029 return 0;
91030 }
91031 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
91032 index b953fb4..1999c01 100644
91033 --- a/sound/drivers/opl4/opl4_lib.c
91034 +++ b/sound/drivers/opl4/opl4_lib.c
91035 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
91036 MODULE_DESCRIPTION("OPL4 driver");
91037 MODULE_LICENSE("GPL");
91038
91039 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
91040 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
91041 {
91042 int timeout = 10;
91043 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
91044 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
91045 index 991018d..8984740 100644
91046 --- a/sound/drivers/portman2x4.c
91047 +++ b/sound/drivers/portman2x4.c
91048 @@ -48,6 +48,7 @@
91049 #include <sound/initval.h>
91050 #include <sound/rawmidi.h>
91051 #include <sound/control.h>
91052 +#include <asm/local.h>
91053
91054 #define CARD_NAME "Portman 2x4"
91055 #define DRIVER_NAME "portman"
91056 @@ -85,7 +86,7 @@ struct portman {
91057 struct pardevice *pardev;
91058 int pardev_claimed;
91059
91060 - int open_count;
91061 + local_t open_count;
91062 int mode[PORTMAN_NUM_INPUT_PORTS];
91063 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
91064 };
91065 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
91066 index ea995af..f1bfa37 100644
91067 --- a/sound/firewire/amdtp.c
91068 +++ b/sound/firewire/amdtp.c
91069 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
91070 ptr = s->pcm_buffer_pointer + data_blocks;
91071 if (ptr >= pcm->runtime->buffer_size)
91072 ptr -= pcm->runtime->buffer_size;
91073 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
91074 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
91075
91076 s->pcm_period_pointer += data_blocks;
91077 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
91078 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
91079 */
91080 void amdtp_out_stream_update(struct amdtp_out_stream *s)
91081 {
91082 - ACCESS_ONCE(s->source_node_id_field) =
91083 + ACCESS_ONCE_RW(s->source_node_id_field) =
91084 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
91085 }
91086 EXPORT_SYMBOL(amdtp_out_stream_update);
91087 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
91088 index b680c5e..061b7a0 100644
91089 --- a/sound/firewire/amdtp.h
91090 +++ b/sound/firewire/amdtp.h
91091 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
91092 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
91093 struct snd_pcm_substream *pcm)
91094 {
91095 - ACCESS_ONCE(s->pcm) = pcm;
91096 + ACCESS_ONCE_RW(s->pcm) = pcm;
91097 }
91098
91099 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
91100 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
91101 index d428ffe..751ef78 100644
91102 --- a/sound/firewire/isight.c
91103 +++ b/sound/firewire/isight.c
91104 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
91105 ptr += count;
91106 if (ptr >= runtime->buffer_size)
91107 ptr -= runtime->buffer_size;
91108 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
91109 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
91110
91111 isight->period_counter += count;
91112 if (isight->period_counter >= runtime->period_size) {
91113 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
91114 if (err < 0)
91115 return err;
91116
91117 - ACCESS_ONCE(isight->pcm_active) = true;
91118 + ACCESS_ONCE_RW(isight->pcm_active) = true;
91119
91120 return 0;
91121 }
91122 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
91123 {
91124 struct isight *isight = substream->private_data;
91125
91126 - ACCESS_ONCE(isight->pcm_active) = false;
91127 + ACCESS_ONCE_RW(isight->pcm_active) = false;
91128
91129 mutex_lock(&isight->mutex);
91130 isight_stop_streaming(isight);
91131 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
91132
91133 switch (cmd) {
91134 case SNDRV_PCM_TRIGGER_START:
91135 - ACCESS_ONCE(isight->pcm_running) = true;
91136 + ACCESS_ONCE_RW(isight->pcm_running) = true;
91137 break;
91138 case SNDRV_PCM_TRIGGER_STOP:
91139 - ACCESS_ONCE(isight->pcm_running) = false;
91140 + ACCESS_ONCE_RW(isight->pcm_running) = false;
91141 break;
91142 default:
91143 return -EINVAL;
91144 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
91145 index 844a555..985ab83 100644
91146 --- a/sound/firewire/scs1x.c
91147 +++ b/sound/firewire/scs1x.c
91148 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
91149 {
91150 struct scs *scs = stream->rmidi->private_data;
91151
91152 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
91153 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
91154 if (up) {
91155 scs->output_idle = false;
91156 tasklet_schedule(&scs->tasklet);
91157 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
91158 {
91159 struct scs *scs = stream->rmidi->private_data;
91160
91161 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
91162 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
91163 }
91164
91165 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
91166 @@ -457,8 +457,8 @@ static int scs_remove(struct device *dev)
91167
91168 snd_card_disconnect(scs->card);
91169
91170 - ACCESS_ONCE(scs->output) = NULL;
91171 - ACCESS_ONCE(scs->input) = NULL;
91172 + ACCESS_ONCE_RW(scs->output) = NULL;
91173 + ACCESS_ONCE_RW(scs->input) = NULL;
91174
91175 wait_event(scs->idle_wait, scs->output_idle);
91176
91177 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
91178 index 048439a..3be9f6f 100644
91179 --- a/sound/oss/sb_audio.c
91180 +++ b/sound/oss/sb_audio.c
91181 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
91182 buf16 = (signed short *)(localbuf + localoffs);
91183 while (c)
91184 {
91185 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
91186 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
91187 if (copy_from_user(lbuf8,
91188 userbuf+useroffs + p,
91189 locallen))
91190 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
91191 index 7d8803a..559f8d0 100644
91192 --- a/sound/oss/swarm_cs4297a.c
91193 +++ b/sound/oss/swarm_cs4297a.c
91194 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
91195 {
91196 struct cs4297a_state *s;
91197 u32 pwr, id;
91198 - mm_segment_t fs;
91199 int rval;
91200 #ifndef CONFIG_BCM_CS4297A_CSWARM
91201 u64 cfg;
91202 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
91203 if (!rval) {
91204 char *sb1250_duart_present;
91205
91206 +#if 0
91207 + mm_segment_t fs;
91208 fs = get_fs();
91209 set_fs(KERNEL_DS);
91210 -#if 0
91211 val = SOUND_MASK_LINE;
91212 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
91213 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
91214 val = initvol[i].vol;
91215 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
91216 }
91217 + set_fs(fs);
91218 // cs4297a_write_ac97(s, 0x18, 0x0808);
91219 #else
91220 // cs4297a_write_ac97(s, 0x5e, 0x180);
91221 cs4297a_write_ac97(s, 0x02, 0x0808);
91222 cs4297a_write_ac97(s, 0x18, 0x0808);
91223 #endif
91224 - set_fs(fs);
91225
91226 list_add(&s->list, &cs4297a_devs);
91227
91228 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
91229 index 4631a23..001ae57 100644
91230 --- a/sound/pci/ymfpci/ymfpci.h
91231 +++ b/sound/pci/ymfpci/ymfpci.h
91232 @@ -358,7 +358,7 @@ struct snd_ymfpci {
91233 spinlock_t reg_lock;
91234 spinlock_t voice_lock;
91235 wait_queue_head_t interrupt_sleep;
91236 - atomic_t interrupt_sleep_count;
91237 + atomic_unchecked_t interrupt_sleep_count;
91238 struct snd_info_entry *proc_entry;
91239 const struct firmware *dsp_microcode;
91240 const struct firmware *controller_microcode;
91241 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
91242 index 22056c5..25d3244 100644
91243 --- a/sound/pci/ymfpci/ymfpci_main.c
91244 +++ b/sound/pci/ymfpci/ymfpci_main.c
91245 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
91246 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
91247 break;
91248 }
91249 - if (atomic_read(&chip->interrupt_sleep_count)) {
91250 - atomic_set(&chip->interrupt_sleep_count, 0);
91251 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
91252 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
91253 wake_up(&chip->interrupt_sleep);
91254 }
91255 __end:
91256 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
91257 continue;
91258 init_waitqueue_entry(&wait, current);
91259 add_wait_queue(&chip->interrupt_sleep, &wait);
91260 - atomic_inc(&chip->interrupt_sleep_count);
91261 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
91262 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
91263 remove_wait_queue(&chip->interrupt_sleep, &wait);
91264 }
91265 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
91266 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
91267 spin_unlock(&chip->reg_lock);
91268
91269 - if (atomic_read(&chip->interrupt_sleep_count)) {
91270 - atomic_set(&chip->interrupt_sleep_count, 0);
91271 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
91272 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
91273 wake_up(&chip->interrupt_sleep);
91274 }
91275 }
91276 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
91277 spin_lock_init(&chip->reg_lock);
91278 spin_lock_init(&chip->voice_lock);
91279 init_waitqueue_head(&chip->interrupt_sleep);
91280 - atomic_set(&chip->interrupt_sleep_count, 0);
91281 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
91282 chip->card = card;
91283 chip->pci = pci;
91284 chip->irq = -1;
91285 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
91286 new file mode 100644
91287 index 0000000..50f2f2f
91288 --- /dev/null
91289 +++ b/tools/gcc/.gitignore
91290 @@ -0,0 +1 @@
91291 +size_overflow_hash.h
91292 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
91293 new file mode 100644
91294 index 0000000..6920fb3
91295 --- /dev/null
91296 +++ b/tools/gcc/Makefile
91297 @@ -0,0 +1,43 @@
91298 +#CC := gcc
91299 +#PLUGIN_SOURCE_FILES := pax_plugin.c
91300 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
91301 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
91302 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
91303 +
91304 +ifeq ($(PLUGINCC),$(HOSTCC))
91305 +HOSTLIBS := hostlibs
91306 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
91307 +else
91308 +HOSTLIBS := hostcxxlibs
91309 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -ggdb -Wno-unused-parameter
91310 +endif
91311 +
91312 +$(HOSTLIBS)-y := constify_plugin.so
91313 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
91314 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
91315 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
91316 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
91317 +$(HOSTLIBS)-y += colorize_plugin.so
91318 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
91319 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
91320 +
91321 +always := $($(HOSTLIBS)-y)
91322 +
91323 +constify_plugin-objs := constify_plugin.o
91324 +stackleak_plugin-objs := stackleak_plugin.o
91325 +kallocstat_plugin-objs := kallocstat_plugin.o
91326 +kernexec_plugin-objs := kernexec_plugin.o
91327 +checker_plugin-objs := checker_plugin.o
91328 +colorize_plugin-objs := colorize_plugin.o
91329 +size_overflow_plugin-objs := size_overflow_plugin.o
91330 +latent_entropy_plugin-objs := latent_entropy_plugin.o
91331 +
91332 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
91333 +
91334 +quiet_cmd_build_size_overflow_hash = GENHASH $@
91335 + cmd_build_size_overflow_hash = \
91336 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
91337 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
91338 + $(call if_changed,build_size_overflow_hash)
91339 +
91340 +targets += size_overflow_hash.h
91341 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
91342 new file mode 100644
91343 index 0000000..d41b5af
91344 --- /dev/null
91345 +++ b/tools/gcc/checker_plugin.c
91346 @@ -0,0 +1,171 @@
91347 +/*
91348 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
91349 + * Licensed under the GPL v2
91350 + *
91351 + * Note: the choice of the license means that the compilation process is
91352 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
91353 + * but for the kernel it doesn't matter since it doesn't link against
91354 + * any of the gcc libraries
91355 + *
91356 + * gcc plugin to implement various sparse (source code checker) features
91357 + *
91358 + * TODO:
91359 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
91360 + *
91361 + * BUGS:
91362 + * - none known
91363 + */
91364 +#include "gcc-plugin.h"
91365 +#include "config.h"
91366 +#include "system.h"
91367 +#include "coretypes.h"
91368 +#include "tree.h"
91369 +#include "tree-pass.h"
91370 +#include "flags.h"
91371 +#include "intl.h"
91372 +#include "toplev.h"
91373 +#include "plugin.h"
91374 +//#include "expr.h" where are you...
91375 +#include "diagnostic.h"
91376 +#include "plugin-version.h"
91377 +#include "tm.h"
91378 +#include "function.h"
91379 +#include "basic-block.h"
91380 +#include "gimple.h"
91381 +#include "rtl.h"
91382 +#include "emit-rtl.h"
91383 +#include "tree-flow.h"
91384 +#include "target.h"
91385 +
91386 +extern void c_register_addr_space (const char *str, addr_space_t as);
91387 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
91388 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
91389 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
91390 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
91391 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
91392 +
91393 +extern void print_gimple_stmt(FILE *, gimple, int, int);
91394 +extern rtx emit_move_insn(rtx x, rtx y);
91395 +
91396 +int plugin_is_GPL_compatible;
91397 +
91398 +static struct plugin_info checker_plugin_info = {
91399 + .version = "201111150100",
91400 +};
91401 +
91402 +#define ADDR_SPACE_KERNEL 0
91403 +#define ADDR_SPACE_FORCE_KERNEL 1
91404 +#define ADDR_SPACE_USER 2
91405 +#define ADDR_SPACE_FORCE_USER 3
91406 +#define ADDR_SPACE_IOMEM 0
91407 +#define ADDR_SPACE_FORCE_IOMEM 0
91408 +#define ADDR_SPACE_PERCPU 0
91409 +#define ADDR_SPACE_FORCE_PERCPU 0
91410 +#define ADDR_SPACE_RCU 0
91411 +#define ADDR_SPACE_FORCE_RCU 0
91412 +
91413 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
91414 +{
91415 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
91416 +}
91417 +
91418 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
91419 +{
91420 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
91421 +}
91422 +
91423 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
91424 +{
91425 + return default_addr_space_valid_pointer_mode(mode, as);
91426 +}
91427 +
91428 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
91429 +{
91430 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
91431 +}
91432 +
91433 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
91434 +{
91435 + return default_addr_space_legitimize_address(x, oldx, mode, as);
91436 +}
91437 +
91438 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
91439 +{
91440 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
91441 + return true;
91442 +
91443 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
91444 + return true;
91445 +
91446 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
91447 + return true;
91448 +
91449 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
91450 + return true;
91451 +
91452 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
91453 + return true;
91454 +
91455 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
91456 + return true;
91457 +
91458 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
91459 + return true;
91460 +
91461 + return subset == superset;
91462 +}
91463 +
91464 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
91465 +{
91466 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
91467 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
91468 +
91469 + return op;
91470 +}
91471 +
91472 +static void register_checker_address_spaces(void *event_data, void *data)
91473 +{
91474 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
91475 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
91476 + c_register_addr_space("__user", ADDR_SPACE_USER);
91477 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
91478 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
91479 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
91480 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
91481 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
91482 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
91483 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
91484 +
91485 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
91486 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
91487 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
91488 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
91489 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
91490 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
91491 + targetm.addr_space.convert = checker_addr_space_convert;
91492 +}
91493 +
91494 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91495 +{
91496 + const char * const plugin_name = plugin_info->base_name;
91497 + const int argc = plugin_info->argc;
91498 + const struct plugin_argument * const argv = plugin_info->argv;
91499 + int i;
91500 +
91501 + if (!plugin_default_version_check(version, &gcc_version)) {
91502 + error(G_("incompatible gcc/plugin versions"));
91503 + return 1;
91504 + }
91505 +
91506 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
91507 +
91508 + for (i = 0; i < argc; ++i)
91509 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
91510 +
91511 + if (TARGET_64BIT == 0)
91512 + return 0;
91513 +
91514 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
91515 +
91516 + return 0;
91517 +}
91518 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
91519 new file mode 100644
91520 index 0000000..414fe5e
91521 --- /dev/null
91522 +++ b/tools/gcc/colorize_plugin.c
91523 @@ -0,0 +1,151 @@
91524 +/*
91525 + * Copyright 2012-2013 by PaX Team <pageexec@freemail.hu>
91526 + * Licensed under the GPL v2
91527 + *
91528 + * Note: the choice of the license means that the compilation process is
91529 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
91530 + * but for the kernel it doesn't matter since it doesn't link against
91531 + * any of the gcc libraries
91532 + *
91533 + * gcc plugin to colorize diagnostic output
91534 + *
91535 + */
91536 +
91537 +#include "gcc-plugin.h"
91538 +#include "config.h"
91539 +#include "system.h"
91540 +#include "coretypes.h"
91541 +#include "tree.h"
91542 +#include "tree-pass.h"
91543 +#include "flags.h"
91544 +#include "intl.h"
91545 +#include "toplev.h"
91546 +#include "plugin.h"
91547 +#include "diagnostic.h"
91548 +#include "plugin-version.h"
91549 +#include "tm.h"
91550 +
91551 +int plugin_is_GPL_compatible;
91552 +
91553 +static struct plugin_info colorize_plugin_info = {
91554 + .version = "201302112000",
91555 + .help = NULL,
91556 +};
91557 +
91558 +#define GREEN "\033[32m\033[2m"
91559 +#define LIGHTGREEN "\033[32m\033[1m"
91560 +#define YELLOW "\033[33m\033[2m"
91561 +#define LIGHTYELLOW "\033[33m\033[1m"
91562 +#define RED "\033[31m\033[2m"
91563 +#define LIGHTRED "\033[31m\033[1m"
91564 +#define BLUE "\033[34m\033[2m"
91565 +#define LIGHTBLUE "\033[34m\033[1m"
91566 +#define BRIGHT "\033[m\033[1m"
91567 +#define NORMAL "\033[m"
91568 +
91569 +static diagnostic_starter_fn old_starter;
91570 +static diagnostic_finalizer_fn old_finalizer;
91571 +
91572 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
91573 +{
91574 + const char *color;
91575 + char *newprefix;
91576 +
91577 + switch (diagnostic->kind) {
91578 + case DK_NOTE:
91579 + color = LIGHTBLUE;
91580 + break;
91581 +
91582 + case DK_PEDWARN:
91583 + case DK_WARNING:
91584 + color = LIGHTYELLOW;
91585 + break;
91586 +
91587 + case DK_ERROR:
91588 + case DK_FATAL:
91589 + case DK_ICE:
91590 + case DK_PERMERROR:
91591 + case DK_SORRY:
91592 + color = LIGHTRED;
91593 + break;
91594 +
91595 + default:
91596 + color = NORMAL;
91597 + }
91598 +
91599 + old_starter(context, diagnostic);
91600 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
91601 + return;
91602 + pp_destroy_prefix(context->printer);
91603 + pp_set_prefix(context->printer, newprefix);
91604 +}
91605 +
91606 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
91607 +{
91608 + old_finalizer(context, diagnostic);
91609 +}
91610 +
91611 +static void colorize_arm(void)
91612 +{
91613 + old_starter = diagnostic_starter(global_dc);
91614 + old_finalizer = diagnostic_finalizer(global_dc);
91615 +
91616 + diagnostic_starter(global_dc) = start_colorize;
91617 + diagnostic_finalizer(global_dc) = finalize_colorize;
91618 +}
91619 +
91620 +static unsigned int execute_colorize_rearm(void)
91621 +{
91622 + if (diagnostic_starter(global_dc) == start_colorize)
91623 + return 0;
91624 +
91625 + colorize_arm();
91626 + return 0;
91627 +}
91628 +
91629 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
91630 + .pass = {
91631 + .type = SIMPLE_IPA_PASS,
91632 + .name = "colorize_rearm",
91633 +#if BUILDING_GCC_VERSION >= 4008
91634 + .optinfo_flags = OPTGROUP_NONE,
91635 +#endif
91636 + .gate = NULL,
91637 + .execute = execute_colorize_rearm,
91638 + .sub = NULL,
91639 + .next = NULL,
91640 + .static_pass_number = 0,
91641 + .tv_id = TV_NONE,
91642 + .properties_required = 0,
91643 + .properties_provided = 0,
91644 + .properties_destroyed = 0,
91645 + .todo_flags_start = 0,
91646 + .todo_flags_finish = 0
91647 + }
91648 +};
91649 +
91650 +static void colorize_start_unit(void *gcc_data, void *user_data)
91651 +{
91652 + colorize_arm();
91653 +}
91654 +
91655 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91656 +{
91657 + const char * const plugin_name = plugin_info->base_name;
91658 + struct register_pass_info colorize_rearm_pass_info = {
91659 + .pass = &pass_ipa_colorize_rearm.pass,
91660 + .reference_pass_name = "*free_lang_data",
91661 + .ref_pass_instance_number = 1,
91662 + .pos_op = PASS_POS_INSERT_AFTER
91663 + };
91664 +
91665 + if (!plugin_default_version_check(version, &gcc_version)) {
91666 + error(G_("incompatible gcc/plugin versions"));
91667 + return 1;
91668 + }
91669 +
91670 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
91671 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
91672 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
91673 + return 0;
91674 +}
91675 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
91676 new file mode 100644
91677 index 0000000..43e86d6
91678 --- /dev/null
91679 +++ b/tools/gcc/constify_plugin.c
91680 @@ -0,0 +1,512 @@
91681 +/*
91682 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
91683 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
91684 + * Licensed under the GPL v2, or (at your option) v3
91685 + *
91686 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
91687 + *
91688 + * Homepage:
91689 + * http://www.grsecurity.net/~ephox/const_plugin/
91690 + *
91691 + * Usage:
91692 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
91693 + * $ gcc -fplugin=constify_plugin.so test.c -O2
91694 + */
91695 +
91696 +#include "gcc-plugin.h"
91697 +#include "config.h"
91698 +#include "system.h"
91699 +#include "coretypes.h"
91700 +#include "tree.h"
91701 +#include "tree-pass.h"
91702 +#include "flags.h"
91703 +#include "intl.h"
91704 +#include "toplev.h"
91705 +#include "plugin.h"
91706 +#include "diagnostic.h"
91707 +#include "plugin-version.h"
91708 +#include "tm.h"
91709 +#include "function.h"
91710 +#include "basic-block.h"
91711 +#include "gimple.h"
91712 +#include "rtl.h"
91713 +#include "emit-rtl.h"
91714 +#include "tree-flow.h"
91715 +#include "target.h"
91716 +
91717 +// should come from c-tree.h if only it were installed for gcc 4.5...
91718 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
91719 +
91720 +// unused type flag in all versions 4.5-4.8
91721 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
91722 +
91723 +int plugin_is_GPL_compatible;
91724 +
91725 +static struct plugin_info const_plugin_info = {
91726 + .version = "201303070020",
91727 + .help = "no-constify\tturn off constification\n",
91728 +};
91729 +
91730 +typedef struct {
91731 + bool has_fptr_field;
91732 + bool has_writable_field;
91733 + bool has_do_const_field;
91734 + bool has_no_const_field;
91735 +} constify_info;
91736 +
91737 +static const_tree get_field_type(const_tree field)
91738 +{
91739 + return strip_array_types(TREE_TYPE(field));
91740 +}
91741 +
91742 +static bool is_fptr(const_tree field)
91743 +{
91744 + const_tree ptr = get_field_type(field);
91745 +
91746 + if (TREE_CODE(ptr) != POINTER_TYPE)
91747 + return false;
91748 +
91749 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
91750 +}
91751 +
91752 +/*
91753 + * determine whether the given structure type meets the requirements for automatic constification,
91754 + * including the constification attributes on nested structure types
91755 + */
91756 +static void constifiable(const_tree node, constify_info *cinfo)
91757 +{
91758 + const_tree field;
91759 +
91760 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
91761 +
91762 + // e.g., pointer to structure fields while still constructing the structure type
91763 + if (TYPE_FIELDS(node) == NULL_TREE)
91764 + return;
91765 +
91766 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
91767 + const_tree type = get_field_type(field);
91768 + enum tree_code code = TREE_CODE(type);
91769 +
91770 + if (node == type)
91771 + continue;
91772 +
91773 + if (is_fptr(field))
91774 + cinfo->has_fptr_field = true;
91775 + else if (!TREE_READONLY(field))
91776 + cinfo->has_writable_field = true;
91777 +
91778 + if (code == RECORD_TYPE || code == UNION_TYPE) {
91779 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91780 + cinfo->has_do_const_field = true;
91781 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
91782 + cinfo->has_no_const_field = true;
91783 + else
91784 + constifiable(type, cinfo);
91785 + }
91786 + }
91787 +}
91788 +
91789 +static bool constified(const_tree node)
91790 +{
91791 + constify_info cinfo = {
91792 + .has_fptr_field = false,
91793 + .has_writable_field = false,
91794 + .has_do_const_field = false,
91795 + .has_no_const_field = false
91796 + };
91797 +
91798 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
91799 +
91800 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
91801 + gcc_assert(!TYPE_READONLY(node));
91802 + return false;
91803 + }
91804 +
91805 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
91806 + gcc_assert(TYPE_READONLY(node));
91807 + return true;
91808 + }
91809 +
91810 + constifiable(node, &cinfo);
91811 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
91812 + return false;
91813 +
91814 + return TYPE_READONLY(node);
91815 +}
91816 +
91817 +static void deconstify_tree(tree node);
91818 +
91819 +static void deconstify_type(tree type)
91820 +{
91821 + tree field;
91822 +
91823 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
91824 +
91825 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
91826 + const_tree fieldtype = get_field_type(field);
91827 +
91828 + // special case handling of simple ptr-to-same-array-type members
91829 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
91830 + const_tree ptrtype = TREE_TYPE(TREE_TYPE(field));
91831 +
91832 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
91833 + continue;
91834 + if (TREE_TYPE(TREE_TYPE(field)) == type)
91835 + continue;
91836 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
91837 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
91838 + TREE_TYPE(TREE_TYPE(field)) = type;
91839 + }
91840 + continue;
91841 + }
91842 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
91843 + continue;
91844 + if (!constified(fieldtype))
91845 + continue;
91846 +
91847 + deconstify_tree(field);
91848 + TREE_READONLY(field) = 0;
91849 + }
91850 + TYPE_READONLY(type) = 0;
91851 + C_TYPE_FIELDS_READONLY(type) = 0;
91852 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91853 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
91854 +}
91855 +
91856 +static void deconstify_tree(tree node)
91857 +{
91858 + tree old_type, new_type, field;
91859 +
91860 + old_type = TREE_TYPE(node);
91861 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
91862 + node = TREE_TYPE(node) = copy_node(old_type);
91863 + old_type = TREE_TYPE(old_type);
91864 + }
91865 +
91866 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
91867 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
91868 +
91869 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
91870 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
91871 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
91872 + DECL_FIELD_CONTEXT(field) = new_type;
91873 +
91874 + deconstify_type(new_type);
91875 +
91876 + TREE_TYPE(node) = new_type;
91877 +}
91878 +
91879 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
91880 +{
91881 + tree type;
91882 + constify_info cinfo = {
91883 + .has_fptr_field = false,
91884 + .has_writable_field = false,
91885 + .has_do_const_field = false,
91886 + .has_no_const_field = false
91887 + };
91888 +
91889 + *no_add_attrs = true;
91890 + if (TREE_CODE(*node) == FUNCTION_DECL) {
91891 + error("%qE attribute does not apply to functions", name);
91892 + return NULL_TREE;
91893 + }
91894 +
91895 + if (TREE_CODE(*node) == PARM_DECL) {
91896 + error("%qE attribute does not apply to function parameters", name);
91897 + return NULL_TREE;
91898 + }
91899 +
91900 + if (TREE_CODE(*node) == VAR_DECL) {
91901 + error("%qE attribute does not apply to variables", name);
91902 + return NULL_TREE;
91903 + }
91904 +
91905 + if (TYPE_P(*node)) {
91906 + *no_add_attrs = false;
91907 + type = *node;
91908 + } else {
91909 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
91910 + type = TREE_TYPE(*node);
91911 + }
91912 +
91913 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
91914 + error("%qE attribute applies to struct and union types only", name);
91915 + return NULL_TREE;
91916 + }
91917 +
91918 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
91919 + error("%qE attribute is already applied to the type", name);
91920 + return NULL_TREE;
91921 + }
91922 +
91923 + if (TYPE_P(*node)) {
91924 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91925 + error("%qE attribute is incompatible with 'do_const'", name);
91926 + return NULL_TREE;
91927 + }
91928 +
91929 + constifiable(type, &cinfo);
91930 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
91931 + deconstify_tree(*node);
91932 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
91933 + return NULL_TREE;
91934 + }
91935 +
91936 + error("%qE attribute used on type that is not constified", name);
91937 + return NULL_TREE;
91938 +}
91939 +
91940 +static void constify_type(tree type)
91941 +{
91942 + TYPE_READONLY(type) = 1;
91943 + C_TYPE_FIELDS_READONLY(type) = 1;
91944 + TYPE_CONSTIFY_VISITED(type) = 1;
91945 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
91946 +}
91947 +
91948 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
91949 +{
91950 + *no_add_attrs = true;
91951 + if (!TYPE_P(*node)) {
91952 + error("%qE attribute applies to types only", name);
91953 + return NULL_TREE;
91954 + }
91955 +
91956 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
91957 + error("%qE attribute applies to struct and union types only", name);
91958 + return NULL_TREE;
91959 + }
91960 +
91961 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
91962 + error("%qE attribute is already applied to the type", name);
91963 + return NULL_TREE;
91964 + }
91965 +
91966 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
91967 + error("%qE attribute is incompatible with 'no_const'", name);
91968 + return NULL_TREE;
91969 + }
91970 +
91971 + *no_add_attrs = false;
91972 + return NULL_TREE;
91973 +}
91974 +
91975 +static struct attribute_spec no_const_attr = {
91976 + .name = "no_const",
91977 + .min_length = 0,
91978 + .max_length = 0,
91979 + .decl_required = false,
91980 + .type_required = false,
91981 + .function_type_required = false,
91982 + .handler = handle_no_const_attribute,
91983 +#if BUILDING_GCC_VERSION >= 4007
91984 + .affects_type_identity = true
91985 +#endif
91986 +};
91987 +
91988 +static struct attribute_spec do_const_attr = {
91989 + .name = "do_const",
91990 + .min_length = 0,
91991 + .max_length = 0,
91992 + .decl_required = false,
91993 + .type_required = false,
91994 + .function_type_required = false,
91995 + .handler = handle_do_const_attribute,
91996 +#if BUILDING_GCC_VERSION >= 4007
91997 + .affects_type_identity = true
91998 +#endif
91999 +};
92000 +
92001 +static void register_attributes(void *event_data, void *data)
92002 +{
92003 + register_attribute(&no_const_attr);
92004 + register_attribute(&do_const_attr);
92005 +}
92006 +
92007 +static void finish_type(void *event_data, void *data)
92008 +{
92009 + tree type = (tree)event_data;
92010 + constify_info cinfo = {
92011 + .has_fptr_field = false,
92012 + .has_writable_field = false,
92013 + .has_do_const_field = false,
92014 + .has_no_const_field = false
92015 + };
92016 +
92017 + if (type == NULL_TREE || type == error_mark_node)
92018 + return;
92019 +
92020 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
92021 + return;
92022 +
92023 + constifiable(type, &cinfo);
92024 +
92025 + if (TYPE_READONLY(type) && C_TYPE_FIELDS_READONLY(type)) {
92026 + if (!lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
92027 + return;
92028 + if (cinfo.has_writable_field)
92029 + return;
92030 + error("'do_const' attribute used on type that is%sconstified", cinfo.has_fptr_field ? " " : " not ");
92031 + return;
92032 + }
92033 +
92034 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
92035 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
92036 + deconstify_type(type);
92037 + TYPE_CONSTIFY_VISITED(type) = 1;
92038 + } else
92039 + error("'no_const' attribute used on type that is not constified");
92040 + return;
92041 + }
92042 +
92043 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
92044 + constify_type(type);
92045 + return;
92046 + }
92047 +
92048 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
92049 + constify_type(type);
92050 + return;
92051 + }
92052 +
92053 + deconstify_type(type);
92054 + TYPE_CONSTIFY_VISITED(type) = 1;
92055 +}
92056 +
92057 +static unsigned int check_local_variables(void)
92058 +{
92059 + unsigned int ret = 0;
92060 + tree var;
92061 +
92062 +#if BUILDING_GCC_VERSION == 4005
92063 + tree vars;
92064 +#else
92065 + unsigned int i;
92066 +#endif
92067 +
92068 +#if BUILDING_GCC_VERSION == 4005
92069 + for (vars = cfun->local_decls; vars; vars = TREE_CHAIN(vars)) {
92070 + var = TREE_VALUE(vars);
92071 +#else
92072 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
92073 +#endif
92074 + tree type = TREE_TYPE(var);
92075 +
92076 + gcc_assert(DECL_P(var));
92077 + if (is_global_var(var))
92078 + continue;
92079 +
92080 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
92081 + continue;
92082 +
92083 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
92084 + continue;
92085 +
92086 + if (!TYPE_CONSTIFY_VISITED(type))
92087 + continue;
92088 +
92089 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
92090 + ret = 1;
92091 + }
92092 + return ret;
92093 +}
92094 +
92095 +static struct gimple_opt_pass pass_local_variable = {
92096 + {
92097 + .type = GIMPLE_PASS,
92098 + .name = "check_local_variables",
92099 +#if BUILDING_GCC_VERSION >= 4008
92100 + .optinfo_flags = OPTGROUP_NONE,
92101 +#endif
92102 + .gate = NULL,
92103 + .execute = check_local_variables,
92104 + .sub = NULL,
92105 + .next = NULL,
92106 + .static_pass_number = 0,
92107 + .tv_id = TV_NONE,
92108 + .properties_required = 0,
92109 + .properties_provided = 0,
92110 + .properties_destroyed = 0,
92111 + .todo_flags_start = 0,
92112 + .todo_flags_finish = 0
92113 + }
92114 +};
92115 +
92116 +static struct {
92117 + const char *name;
92118 + const char *asm_op;
92119 +} sections[] = {
92120 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
92121 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
92122 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
92123 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
92124 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
92125 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
92126 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
92127 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
92128 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
92129 +};
92130 +
92131 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
92132 +
92133 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
92134 +{
92135 + size_t i;
92136 +
92137 + for (i = 0; i < ARRAY_SIZE(sections); i++)
92138 + if (!strcmp(sections[i].name, name))
92139 + return 0;
92140 + return old_section_type_flags(decl, name, reloc);
92141 +}
92142 +
92143 +static void constify_start_unit(void *gcc_data, void *user_data)
92144 +{
92145 +// size_t i;
92146 +
92147 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
92148 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
92149 +// sections[i].section = get_section(sections[i].name, 0, NULL);
92150 +
92151 + old_section_type_flags = targetm.section_type_flags;
92152 + targetm.section_type_flags = constify_section_type_flags;
92153 +}
92154 +
92155 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92156 +{
92157 + const char * const plugin_name = plugin_info->base_name;
92158 + const int argc = plugin_info->argc;
92159 + const struct plugin_argument * const argv = plugin_info->argv;
92160 + int i;
92161 + bool constify = true;
92162 +
92163 + struct register_pass_info local_variable_pass_info = {
92164 + .pass = &pass_local_variable.pass,
92165 + .reference_pass_name = "ssa",
92166 + .ref_pass_instance_number = 1,
92167 + .pos_op = PASS_POS_INSERT_BEFORE
92168 + };
92169 +
92170 + if (!plugin_default_version_check(version, &gcc_version)) {
92171 + error(G_("incompatible gcc/plugin versions"));
92172 + return 1;
92173 + }
92174 +
92175 + for (i = 0; i < argc; ++i) {
92176 + if (!(strcmp(argv[i].key, "no-constify"))) {
92177 + constify = false;
92178 + continue;
92179 + }
92180 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92181 + }
92182 +
92183 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
92184 + if (constify) {
92185 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
92186 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
92187 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
92188 + }
92189 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
92190 +
92191 + return 0;
92192 +}
92193 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
92194 new file mode 100644
92195 index 0000000..e518932
92196 --- /dev/null
92197 +++ b/tools/gcc/generate_size_overflow_hash.sh
92198 @@ -0,0 +1,94 @@
92199 +#!/bin/bash
92200 +
92201 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
92202 +
92203 +header1="size_overflow_hash.h"
92204 +database="size_overflow_hash.data"
92205 +n=65536
92206 +
92207 +usage() {
92208 +cat <<EOF
92209 +usage: $0 options
92210 +OPTIONS:
92211 + -h|--help help
92212 + -o header file
92213 + -d database file
92214 + -n hash array size
92215 +EOF
92216 + return 0
92217 +}
92218 +
92219 +while true
92220 +do
92221 + case "$1" in
92222 + -h|--help) usage && exit 0;;
92223 + -n) n=$2; shift 2;;
92224 + -o) header1="$2"; shift 2;;
92225 + -d) database="$2"; shift 2;;
92226 + --) shift 1; break ;;
92227 + *) break ;;
92228 + esac
92229 +done
92230 +
92231 +create_defines() {
92232 + for i in `seq 0 31`
92233 + do
92234 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
92235 + done
92236 + echo >> "$header1"
92237 +}
92238 +
92239 +create_structs() {
92240 + rm -f "$header1"
92241 +
92242 + create_defines
92243 +
92244 + cat "$database" | while read data
92245 + do
92246 + data_array=($data)
92247 + struct_hash_name="${data_array[0]}"
92248 + funcn="${data_array[1]}"
92249 + params="${data_array[2]}"
92250 + next="${data_array[4]}"
92251 +
92252 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
92253 +
92254 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
92255 + echo -en "\t.param\t= " >> "$header1"
92256 + line=
92257 + for param_num in ${params//-/ };
92258 + do
92259 + line="${line}PARAM"$param_num"|"
92260 + done
92261 +
92262 + echo -e "${line%?},\n};\n" >> "$header1"
92263 + done
92264 +}
92265 +
92266 +create_headers() {
92267 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
92268 +}
92269 +
92270 +create_array_elements() {
92271 + index=0
92272 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
92273 + do
92274 + data_array=($data)
92275 + i="${data_array[3]}"
92276 + hash="${data_array[0]}"
92277 + while [[ $index -lt $i ]]
92278 + do
92279 + echo -e "\t["$index"]\t= NULL," >> "$header1"
92280 + index=$(($index + 1))
92281 + done
92282 + index=$(($index + 1))
92283 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
92284 + done
92285 + echo '};' >> $header1
92286 +}
92287 +
92288 +create_structs
92289 +create_headers
92290 +create_array_elements
92291 +
92292 +exit 0
92293 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
92294 new file mode 100644
92295 index 0000000..568b360
92296 --- /dev/null
92297 +++ b/tools/gcc/kallocstat_plugin.c
92298 @@ -0,0 +1,170 @@
92299 +/*
92300 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
92301 + * Licensed under the GPL v2
92302 + *
92303 + * Note: the choice of the license means that the compilation process is
92304 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92305 + * but for the kernel it doesn't matter since it doesn't link against
92306 + * any of the gcc libraries
92307 + *
92308 + * gcc plugin to find the distribution of k*alloc sizes
92309 + *
92310 + * TODO:
92311 + *
92312 + * BUGS:
92313 + * - none known
92314 + */
92315 +#include "gcc-plugin.h"
92316 +#include "config.h"
92317 +#include "system.h"
92318 +#include "coretypes.h"
92319 +#include "tree.h"
92320 +#include "tree-pass.h"
92321 +#include "flags.h"
92322 +#include "intl.h"
92323 +#include "toplev.h"
92324 +#include "plugin.h"
92325 +//#include "expr.h" where are you...
92326 +#include "diagnostic.h"
92327 +#include "plugin-version.h"
92328 +#include "tm.h"
92329 +#include "function.h"
92330 +#include "basic-block.h"
92331 +#include "gimple.h"
92332 +#include "rtl.h"
92333 +#include "emit-rtl.h"
92334 +
92335 +extern void print_gimple_stmt(FILE *, gimple, int, int);
92336 +
92337 +int plugin_is_GPL_compatible;
92338 +
92339 +static const char * const kalloc_functions[] = {
92340 + "__kmalloc",
92341 + "kmalloc",
92342 + "kmalloc_large",
92343 + "kmalloc_node",
92344 + "kmalloc_order",
92345 + "kmalloc_order_trace",
92346 + "kmalloc_slab",
92347 + "kzalloc",
92348 + "kzalloc_node",
92349 +};
92350 +
92351 +static struct plugin_info kallocstat_plugin_info = {
92352 + .version = "201302112000",
92353 +};
92354 +
92355 +static unsigned int execute_kallocstat(void);
92356 +
92357 +static struct gimple_opt_pass kallocstat_pass = {
92358 + .pass = {
92359 + .type = GIMPLE_PASS,
92360 + .name = "kallocstat",
92361 +#if BUILDING_GCC_VERSION >= 4008
92362 + .optinfo_flags = OPTGROUP_NONE,
92363 +#endif
92364 + .gate = NULL,
92365 + .execute = execute_kallocstat,
92366 + .sub = NULL,
92367 + .next = NULL,
92368 + .static_pass_number = 0,
92369 + .tv_id = TV_NONE,
92370 + .properties_required = 0,
92371 + .properties_provided = 0,
92372 + .properties_destroyed = 0,
92373 + .todo_flags_start = 0,
92374 + .todo_flags_finish = 0
92375 + }
92376 +};
92377 +
92378 +static bool is_kalloc(const char *fnname)
92379 +{
92380 + size_t i;
92381 +
92382 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
92383 + if (!strcmp(fnname, kalloc_functions[i]))
92384 + return true;
92385 + return false;
92386 +}
92387 +
92388 +static unsigned int execute_kallocstat(void)
92389 +{
92390 + basic_block bb;
92391 +
92392 + // 1. loop through BBs and GIMPLE statements
92393 + FOR_EACH_BB(bb) {
92394 + gimple_stmt_iterator gsi;
92395 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92396 + // gimple match:
92397 + tree fndecl, size;
92398 + gimple call_stmt;
92399 + const char *fnname;
92400 +
92401 + // is it a call
92402 + call_stmt = gsi_stmt(gsi);
92403 + if (!is_gimple_call(call_stmt))
92404 + continue;
92405 + fndecl = gimple_call_fndecl(call_stmt);
92406 + if (fndecl == NULL_TREE)
92407 + continue;
92408 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
92409 + continue;
92410 +
92411 + // is it a call to k*alloc
92412 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
92413 + if (!is_kalloc(fnname))
92414 + continue;
92415 +
92416 + // is the size arg the result of a simple const assignment
92417 + size = gimple_call_arg(call_stmt, 0);
92418 + while (true) {
92419 + gimple def_stmt;
92420 + expanded_location xloc;
92421 + size_t size_val;
92422 +
92423 + if (TREE_CODE(size) != SSA_NAME)
92424 + break;
92425 + def_stmt = SSA_NAME_DEF_STMT(size);
92426 + if (!def_stmt || !is_gimple_assign(def_stmt))
92427 + break;
92428 + if (gimple_num_ops(def_stmt) != 2)
92429 + break;
92430 + size = gimple_assign_rhs1(def_stmt);
92431 + if (!TREE_CONSTANT(size))
92432 + continue;
92433 + xloc = expand_location(gimple_location(def_stmt));
92434 + if (!xloc.file)
92435 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
92436 + size_val = TREE_INT_CST_LOW(size);
92437 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
92438 + break;
92439 + }
92440 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
92441 +//debug_tree(gimple_call_fn(call_stmt));
92442 +//print_node(stderr, "pax", fndecl, 4);
92443 + }
92444 + }
92445 +
92446 + return 0;
92447 +}
92448 +
92449 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92450 +{
92451 + const char * const plugin_name = plugin_info->base_name;
92452 + struct register_pass_info kallocstat_pass_info = {
92453 + .pass = &kallocstat_pass.pass,
92454 + .reference_pass_name = "ssa",
92455 + .ref_pass_instance_number = 1,
92456 + .pos_op = PASS_POS_INSERT_AFTER
92457 + };
92458 +
92459 + if (!plugin_default_version_check(version, &gcc_version)) {
92460 + error(G_("incompatible gcc/plugin versions"));
92461 + return 1;
92462 + }
92463 +
92464 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
92465 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
92466 +
92467 + return 0;
92468 +}
92469 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
92470 new file mode 100644
92471 index 0000000..0408e06
92472 --- /dev/null
92473 +++ b/tools/gcc/kernexec_plugin.c
92474 @@ -0,0 +1,465 @@
92475 +/*
92476 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
92477 + * Licensed under the GPL v2
92478 + *
92479 + * Note: the choice of the license means that the compilation process is
92480 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92481 + * but for the kernel it doesn't matter since it doesn't link against
92482 + * any of the gcc libraries
92483 + *
92484 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
92485 + *
92486 + * TODO:
92487 + *
92488 + * BUGS:
92489 + * - none known
92490 + */
92491 +#include "gcc-plugin.h"
92492 +#include "config.h"
92493 +#include "system.h"
92494 +#include "coretypes.h"
92495 +#include "tree.h"
92496 +#include "tree-pass.h"
92497 +#include "flags.h"
92498 +#include "intl.h"
92499 +#include "toplev.h"
92500 +#include "plugin.h"
92501 +//#include "expr.h" where are you...
92502 +#include "diagnostic.h"
92503 +#include "plugin-version.h"
92504 +#include "tm.h"
92505 +#include "function.h"
92506 +#include "basic-block.h"
92507 +#include "gimple.h"
92508 +#include "rtl.h"
92509 +#include "emit-rtl.h"
92510 +#include "tree-flow.h"
92511 +
92512 +extern void print_gimple_stmt(FILE *, gimple, int, int);
92513 +extern rtx emit_move_insn(rtx x, rtx y);
92514 +
92515 +#if BUILDING_GCC_VERSION <= 4006
92516 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
92517 +#endif
92518 +
92519 +#if BUILDING_GCC_VERSION >= 4008
92520 +#define TODO_dump_func 0
92521 +#endif
92522 +
92523 +int plugin_is_GPL_compatible;
92524 +
92525 +static struct plugin_info kernexec_plugin_info = {
92526 + .version = "201302112000",
92527 + .help = "method=[bts|or]\tinstrumentation method\n"
92528 +};
92529 +
92530 +static unsigned int execute_kernexec_reload(void);
92531 +static unsigned int execute_kernexec_fptr(void);
92532 +static unsigned int execute_kernexec_retaddr(void);
92533 +static bool kernexec_cmodel_check(void);
92534 +
92535 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
92536 +static void (*kernexec_instrument_retaddr)(rtx);
92537 +
92538 +static struct gimple_opt_pass kernexec_reload_pass = {
92539 + .pass = {
92540 + .type = GIMPLE_PASS,
92541 + .name = "kernexec_reload",
92542 +#if BUILDING_GCC_VERSION >= 4008
92543 + .optinfo_flags = OPTGROUP_NONE,
92544 +#endif
92545 + .gate = kernexec_cmodel_check,
92546 + .execute = execute_kernexec_reload,
92547 + .sub = NULL,
92548 + .next = NULL,
92549 + .static_pass_number = 0,
92550 + .tv_id = TV_NONE,
92551 + .properties_required = 0,
92552 + .properties_provided = 0,
92553 + .properties_destroyed = 0,
92554 + .todo_flags_start = 0,
92555 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
92556 + }
92557 +};
92558 +
92559 +static struct gimple_opt_pass kernexec_fptr_pass = {
92560 + .pass = {
92561 + .type = GIMPLE_PASS,
92562 + .name = "kernexec_fptr",
92563 +#if BUILDING_GCC_VERSION >= 4008
92564 + .optinfo_flags = OPTGROUP_NONE,
92565 +#endif
92566 + .gate = kernexec_cmodel_check,
92567 + .execute = execute_kernexec_fptr,
92568 + .sub = NULL,
92569 + .next = NULL,
92570 + .static_pass_number = 0,
92571 + .tv_id = TV_NONE,
92572 + .properties_required = 0,
92573 + .properties_provided = 0,
92574 + .properties_destroyed = 0,
92575 + .todo_flags_start = 0,
92576 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
92577 + }
92578 +};
92579 +
92580 +static struct rtl_opt_pass kernexec_retaddr_pass = {
92581 + .pass = {
92582 + .type = RTL_PASS,
92583 + .name = "kernexec_retaddr",
92584 +#if BUILDING_GCC_VERSION >= 4008
92585 + .optinfo_flags = OPTGROUP_NONE,
92586 +#endif
92587 + .gate = kernexec_cmodel_check,
92588 + .execute = execute_kernexec_retaddr,
92589 + .sub = NULL,
92590 + .next = NULL,
92591 + .static_pass_number = 0,
92592 + .tv_id = TV_NONE,
92593 + .properties_required = 0,
92594 + .properties_provided = 0,
92595 + .properties_destroyed = 0,
92596 + .todo_flags_start = 0,
92597 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
92598 + }
92599 +};
92600 +
92601 +static bool kernexec_cmodel_check(void)
92602 +{
92603 + tree section;
92604 +
92605 + if (ix86_cmodel != CM_KERNEL)
92606 + return false;
92607 +
92608 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
92609 + if (!section || !TREE_VALUE(section))
92610 + return true;
92611 +
92612 + section = TREE_VALUE(TREE_VALUE(section));
92613 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
92614 + return true;
92615 +
92616 + return false;
92617 +}
92618 +
92619 +/*
92620 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
92621 + */
92622 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
92623 +{
92624 + gimple asm_movabs_stmt;
92625 +
92626 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
92627 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
92628 + gimple_asm_set_volatile(asm_movabs_stmt, true);
92629 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
92630 + update_stmt(asm_movabs_stmt);
92631 +}
92632 +
92633 +/*
92634 + * find all asm() stmts that clobber r10 and add a reload of r10
92635 + */
92636 +static unsigned int execute_kernexec_reload(void)
92637 +{
92638 + basic_block bb;
92639 +
92640 + // 1. loop through BBs and GIMPLE statements
92641 + FOR_EACH_BB(bb) {
92642 + gimple_stmt_iterator gsi;
92643 +
92644 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92645 + // gimple match: __asm__ ("" : : : "r10");
92646 + gimple asm_stmt;
92647 + size_t nclobbers;
92648 +
92649 + // is it an asm ...
92650 + asm_stmt = gsi_stmt(gsi);
92651 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
92652 + continue;
92653 +
92654 + // ... clobbering r10
92655 + nclobbers = gimple_asm_nclobbers(asm_stmt);
92656 + while (nclobbers--) {
92657 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
92658 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
92659 + continue;
92660 + kernexec_reload_fptr_mask(&gsi);
92661 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
92662 + break;
92663 + }
92664 + }
92665 + }
92666 +
92667 + return 0;
92668 +}
92669 +
92670 +/*
92671 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
92672 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
92673 + */
92674 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
92675 +{
92676 + gimple assign_intptr, assign_new_fptr, call_stmt;
92677 + tree intptr, old_fptr, new_fptr, kernexec_mask;
92678 +
92679 + call_stmt = gsi_stmt(*gsi);
92680 + old_fptr = gimple_call_fn(call_stmt);
92681 +
92682 + // create temporary unsigned long variable used for bitops and cast fptr to it
92683 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
92684 +#if BUILDING_GCC_VERSION <= 4007
92685 + add_referenced_var(intptr);
92686 + mark_sym_for_renaming(intptr);
92687 +#endif
92688 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
92689 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
92690 + update_stmt(assign_intptr);
92691 +
92692 + // apply logical or to temporary unsigned long and bitmask
92693 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
92694 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
92695 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
92696 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
92697 + update_stmt(assign_intptr);
92698 +
92699 + // cast temporary unsigned long back to a temporary fptr variable
92700 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
92701 +#if BUILDING_GCC_VERSION <= 4007
92702 + add_referenced_var(new_fptr);
92703 + mark_sym_for_renaming(new_fptr);
92704 +#endif
92705 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
92706 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
92707 + update_stmt(assign_new_fptr);
92708 +
92709 + // replace call stmt fn with the new fptr
92710 + gimple_call_set_fn(call_stmt, new_fptr);
92711 + update_stmt(call_stmt);
92712 +}
92713 +
92714 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
92715 +{
92716 + gimple asm_or_stmt, call_stmt;
92717 + tree old_fptr, new_fptr, input, output;
92718 +#if BUILDING_GCC_VERSION <= 4007
92719 + VEC(tree, gc) *inputs = NULL;
92720 + VEC(tree, gc) *outputs = NULL;
92721 +#else
92722 + vec<tree, va_gc> *inputs = NULL;
92723 + vec<tree, va_gc> *outputs = NULL;
92724 +#endif
92725 +
92726 + call_stmt = gsi_stmt(*gsi);
92727 + old_fptr = gimple_call_fn(call_stmt);
92728 +
92729 + // create temporary fptr variable
92730 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
92731 +#if BUILDING_GCC_VERSION <= 4007
92732 + add_referenced_var(new_fptr);
92733 + mark_sym_for_renaming(new_fptr);
92734 +#endif
92735 +
92736 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
92737 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
92738 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
92739 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
92740 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
92741 +#if BUILDING_GCC_VERSION <= 4007
92742 + VEC_safe_push(tree, gc, inputs, input);
92743 + VEC_safe_push(tree, gc, outputs, output);
92744 +#else
92745 + vec_safe_push(inputs, input);
92746 + vec_safe_push(outputs, output);
92747 +#endif
92748 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
92749 + gimple_asm_set_volatile(asm_or_stmt, true);
92750 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
92751 + update_stmt(asm_or_stmt);
92752 +
92753 + // replace call stmt fn with the new fptr
92754 + gimple_call_set_fn(call_stmt, new_fptr);
92755 + update_stmt(call_stmt);
92756 +}
92757 +
92758 +/*
92759 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
92760 + */
92761 +static unsigned int execute_kernexec_fptr(void)
92762 +{
92763 + basic_block bb;
92764 +
92765 + // 1. loop through BBs and GIMPLE statements
92766 + FOR_EACH_BB(bb) {
92767 + gimple_stmt_iterator gsi;
92768 +
92769 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92770 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
92771 + tree fn;
92772 + gimple call_stmt;
92773 +
92774 + // is it a call ...
92775 + call_stmt = gsi_stmt(gsi);
92776 + if (!is_gimple_call(call_stmt))
92777 + continue;
92778 + fn = gimple_call_fn(call_stmt);
92779 + if (TREE_CODE(fn) == ADDR_EXPR)
92780 + continue;
92781 + if (TREE_CODE(fn) != SSA_NAME)
92782 + gcc_unreachable();
92783 +
92784 + // ... through a function pointer
92785 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
92786 + fn = SSA_NAME_VAR(fn);
92787 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
92788 + debug_tree(fn);
92789 + gcc_unreachable();
92790 + }
92791 + }
92792 + fn = TREE_TYPE(fn);
92793 + if (TREE_CODE(fn) != POINTER_TYPE)
92794 + continue;
92795 + fn = TREE_TYPE(fn);
92796 + if (TREE_CODE(fn) != FUNCTION_TYPE)
92797 + continue;
92798 +
92799 + kernexec_instrument_fptr(&gsi);
92800 +
92801 +//debug_tree(gimple_call_fn(call_stmt));
92802 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
92803 + }
92804 + }
92805 +
92806 + return 0;
92807 +}
92808 +
92809 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
92810 +static void kernexec_instrument_retaddr_bts(rtx insn)
92811 +{
92812 + rtx btsq;
92813 + rtvec argvec, constraintvec, labelvec;
92814 + int line;
92815 +
92816 + // create asm volatile("btsq $63,(%%rsp)":::)
92817 + argvec = rtvec_alloc(0);
92818 + constraintvec = rtvec_alloc(0);
92819 + labelvec = rtvec_alloc(0);
92820 + line = expand_location(RTL_LOCATION(insn)).line;
92821 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
92822 + MEM_VOLATILE_P(btsq) = 1;
92823 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
92824 + emit_insn_before(btsq, insn);
92825 +}
92826 +
92827 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
92828 +static void kernexec_instrument_retaddr_or(rtx insn)
92829 +{
92830 + rtx orq;
92831 + rtvec argvec, constraintvec, labelvec;
92832 + int line;
92833 +
92834 + // create asm volatile("orq %%r10,(%%rsp)":::)
92835 + argvec = rtvec_alloc(0);
92836 + constraintvec = rtvec_alloc(0);
92837 + labelvec = rtvec_alloc(0);
92838 + line = expand_location(RTL_LOCATION(insn)).line;
92839 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
92840 + MEM_VOLATILE_P(orq) = 1;
92841 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
92842 + emit_insn_before(orq, insn);
92843 +}
92844 +
92845 +/*
92846 + * find all asm level function returns and forcibly set the highest bit of the return address
92847 + */
92848 +static unsigned int execute_kernexec_retaddr(void)
92849 +{
92850 + rtx insn;
92851 +
92852 + // 1. find function returns
92853 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
92854 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
92855 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
92856 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
92857 + rtx body;
92858 +
92859 + // is it a retn
92860 + if (!JUMP_P(insn))
92861 + continue;
92862 + body = PATTERN(insn);
92863 + if (GET_CODE(body) == PARALLEL)
92864 + body = XVECEXP(body, 0, 0);
92865 + if (!ANY_RETURN_P(body))
92866 + continue;
92867 + kernexec_instrument_retaddr(insn);
92868 + }
92869 +
92870 +// print_simple_rtl(stderr, get_insns());
92871 +// print_rtl(stderr, get_insns());
92872 +
92873 + return 0;
92874 +}
92875 +
92876 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92877 +{
92878 + const char * const plugin_name = plugin_info->base_name;
92879 + const int argc = plugin_info->argc;
92880 + const struct plugin_argument * const argv = plugin_info->argv;
92881 + int i;
92882 + struct register_pass_info kernexec_reload_pass_info = {
92883 + .pass = &kernexec_reload_pass.pass,
92884 + .reference_pass_name = "ssa",
92885 + .ref_pass_instance_number = 1,
92886 + .pos_op = PASS_POS_INSERT_AFTER
92887 + };
92888 + struct register_pass_info kernexec_fptr_pass_info = {
92889 + .pass = &kernexec_fptr_pass.pass,
92890 + .reference_pass_name = "ssa",
92891 + .ref_pass_instance_number = 1,
92892 + .pos_op = PASS_POS_INSERT_AFTER
92893 + };
92894 + struct register_pass_info kernexec_retaddr_pass_info = {
92895 + .pass = &kernexec_retaddr_pass.pass,
92896 + .reference_pass_name = "pro_and_epilogue",
92897 + .ref_pass_instance_number = 1,
92898 + .pos_op = PASS_POS_INSERT_AFTER
92899 + };
92900 +
92901 + if (!plugin_default_version_check(version, &gcc_version)) {
92902 + error(G_("incompatible gcc/plugin versions"));
92903 + return 1;
92904 + }
92905 +
92906 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
92907 +
92908 + if (TARGET_64BIT == 0)
92909 + return 0;
92910 +
92911 + for (i = 0; i < argc; ++i) {
92912 + if (!strcmp(argv[i].key, "method")) {
92913 + if (!argv[i].value) {
92914 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92915 + continue;
92916 + }
92917 + if (!strcmp(argv[i].value, "bts")) {
92918 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
92919 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
92920 + } else if (!strcmp(argv[i].value, "or")) {
92921 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
92922 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
92923 + fix_register("r10", 1, 1);
92924 + } else
92925 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92926 + continue;
92927 + }
92928 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92929 + }
92930 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
92931 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
92932 +
92933 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
92934 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
92935 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
92936 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
92937 +
92938 + return 0;
92939 +}
92940 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
92941 new file mode 100644
92942 index 0000000..dff9e83
92943 --- /dev/null
92944 +++ b/tools/gcc/latent_entropy_plugin.c
92945 @@ -0,0 +1,324 @@
92946 +/*
92947 + * Copyright 2012-2013 by the PaX Team <pageexec@freemail.hu>
92948 + * Licensed under the GPL v2
92949 + *
92950 + * Note: the choice of the license means that the compilation process is
92951 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92952 + * but for the kernel it doesn't matter since it doesn't link against
92953 + * any of the gcc libraries
92954 + *
92955 + * gcc plugin to help generate a little bit of entropy from program state,
92956 + * used during boot in the kernel
92957 + *
92958 + * TODO:
92959 + * - add ipa pass to identify not explicitly marked candidate functions
92960 + * - mix in more program state (function arguments/return values, loop variables, etc)
92961 + * - more instrumentation control via attribute parameters
92962 + *
92963 + * BUGS:
92964 + * - LTO needs -flto-partition=none for now
92965 + */
92966 +#include "gcc-plugin.h"
92967 +#include "config.h"
92968 +#include "system.h"
92969 +#include "coretypes.h"
92970 +#include "tree.h"
92971 +#include "tree-pass.h"
92972 +#include "flags.h"
92973 +#include "intl.h"
92974 +#include "toplev.h"
92975 +#include "plugin.h"
92976 +//#include "expr.h" where are you...
92977 +#include "diagnostic.h"
92978 +#include "plugin-version.h"
92979 +#include "tm.h"
92980 +#include "function.h"
92981 +#include "basic-block.h"
92982 +#include "gimple.h"
92983 +#include "rtl.h"
92984 +#include "emit-rtl.h"
92985 +#include "tree-flow.h"
92986 +#include "langhooks.h"
92987 +
92988 +#if BUILDING_GCC_VERSION >= 4008
92989 +#define TODO_dump_func 0
92990 +#endif
92991 +
92992 +int plugin_is_GPL_compatible;
92993 +
92994 +static tree latent_entropy_decl;
92995 +
92996 +static struct plugin_info latent_entropy_plugin_info = {
92997 + .version = "201303092140",
92998 + .help = NULL
92999 +};
93000 +
93001 +static unsigned int execute_latent_entropy(void);
93002 +static bool gate_latent_entropy(void);
93003 +
93004 +static struct gimple_opt_pass latent_entropy_pass = {
93005 + .pass = {
93006 + .type = GIMPLE_PASS,
93007 + .name = "latent_entropy",
93008 +#if BUILDING_GCC_VERSION >= 4008
93009 + .optinfo_flags = OPTGROUP_NONE,
93010 +#endif
93011 + .gate = gate_latent_entropy,
93012 + .execute = execute_latent_entropy,
93013 + .sub = NULL,
93014 + .next = NULL,
93015 + .static_pass_number = 0,
93016 + .tv_id = TV_NONE,
93017 + .properties_required = PROP_gimple_leh | PROP_cfg,
93018 + .properties_provided = 0,
93019 + .properties_destroyed = 0,
93020 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
93021 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
93022 + }
93023 +};
93024 +
93025 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
93026 +{
93027 + if (TREE_CODE(*node) != FUNCTION_DECL) {
93028 + *no_add_attrs = true;
93029 + error("%qE attribute only applies to functions", name);
93030 + }
93031 + return NULL_TREE;
93032 +}
93033 +
93034 +static struct attribute_spec latent_entropy_attr = {
93035 + .name = "latent_entropy",
93036 + .min_length = 0,
93037 + .max_length = 0,
93038 + .decl_required = true,
93039 + .type_required = false,
93040 + .function_type_required = false,
93041 + .handler = handle_latent_entropy_attribute,
93042 +#if BUILDING_GCC_VERSION >= 4007
93043 + .affects_type_identity = false
93044 +#endif
93045 +};
93046 +
93047 +static void register_attributes(void *event_data, void *data)
93048 +{
93049 + register_attribute(&latent_entropy_attr);
93050 +}
93051 +
93052 +static bool gate_latent_entropy(void)
93053 +{
93054 + tree latent_entropy_attr;
93055 +
93056 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
93057 + return latent_entropy_attr != NULL_TREE;
93058 +}
93059 +
93060 +static unsigned HOST_WIDE_INT seed;
93061 +static unsigned HOST_WIDE_INT get_random_const(void)
93062 +{
93063 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
93064 + return seed;
93065 +}
93066 +
93067 +static enum tree_code get_op(tree *rhs)
93068 +{
93069 + static enum tree_code op;
93070 + unsigned HOST_WIDE_INT random_const;
93071 +
93072 + random_const = get_random_const();
93073 +
93074 + switch (op) {
93075 + case BIT_XOR_EXPR:
93076 + op = PLUS_EXPR;
93077 + break;
93078 +
93079 + case PLUS_EXPR:
93080 + if (rhs) {
93081 + op = LROTATE_EXPR;
93082 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
93083 + break;
93084 + }
93085 +
93086 + case LROTATE_EXPR:
93087 + default:
93088 + op = BIT_XOR_EXPR;
93089 + break;
93090 + }
93091 + if (rhs)
93092 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
93093 + return op;
93094 +}
93095 +
93096 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
93097 +{
93098 + gimple_stmt_iterator gsi;
93099 + gimple assign;
93100 + tree addxorrol, rhs;
93101 + enum tree_code op;
93102 +
93103 + op = get_op(&rhs);
93104 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
93105 + assign = gimple_build_assign(local_entropy, addxorrol);
93106 +#if BUILDING_GCC_VERSION <= 4007
93107 + find_referenced_vars_in(assign);
93108 +#endif
93109 +//debug_bb(bb);
93110 + gsi = gsi_after_labels(bb);
93111 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
93112 + update_stmt(assign);
93113 +}
93114 +
93115 +static void perturb_latent_entropy(basic_block bb, tree rhs)
93116 +{
93117 + gimple_stmt_iterator gsi;
93118 + gimple assign;
93119 + tree addxorrol, temp;
93120 +
93121 + // 1. create temporary copy of latent_entropy
93122 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
93123 +#if BUILDING_GCC_VERSION <= 4007
93124 + add_referenced_var(temp);
93125 + mark_sym_for_renaming(temp);
93126 +#endif
93127 +
93128 + // 2. read...
93129 + assign = gimple_build_assign(temp, latent_entropy_decl);
93130 +#if BUILDING_GCC_VERSION <= 4007
93131 + find_referenced_vars_in(assign);
93132 +#endif
93133 + gsi = gsi_after_labels(bb);
93134 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
93135 + update_stmt(assign);
93136 +
93137 + // 3. ...modify...
93138 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
93139 + assign = gimple_build_assign(temp, addxorrol);
93140 +#if BUILDING_GCC_VERSION <= 4007
93141 + find_referenced_vars_in(assign);
93142 +#endif
93143 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
93144 + update_stmt(assign);
93145 +
93146 + // 4. ...write latent_entropy
93147 + assign = gimple_build_assign(latent_entropy_decl, temp);
93148 +#if BUILDING_GCC_VERSION <= 4007
93149 + find_referenced_vars_in(assign);
93150 +#endif
93151 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
93152 + update_stmt(assign);
93153 +}
93154 +
93155 +static unsigned int execute_latent_entropy(void)
93156 +{
93157 + basic_block bb;
93158 + gimple assign;
93159 + gimple_stmt_iterator gsi;
93160 + tree local_entropy;
93161 +
93162 + if (!latent_entropy_decl) {
93163 + struct varpool_node *node;
93164 +
93165 +#if BUILDING_GCC_VERSION <= 4007
93166 + for (node = varpool_nodes; node; node = node->next) {
93167 + tree var = node->decl;
93168 +#else
93169 + FOR_EACH_VARIABLE(node) {
93170 + tree var = node->symbol.decl;
93171 +#endif
93172 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
93173 + continue;
93174 + latent_entropy_decl = var;
93175 +// debug_tree(var);
93176 + break;
93177 + }
93178 + if (!latent_entropy_decl) {
93179 +// debug_tree(current_function_decl);
93180 + return 0;
93181 + }
93182 + }
93183 +
93184 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
93185 +
93186 + // 1. create local entropy variable
93187 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
93188 +#if BUILDING_GCC_VERSION <= 4007
93189 + add_referenced_var(local_entropy);
93190 + mark_sym_for_renaming(local_entropy);
93191 +#endif
93192 +
93193 + // 2. initialize local entropy variable
93194 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
93195 + if (dom_info_available_p(CDI_DOMINATORS))
93196 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
93197 + gsi = gsi_start_bb(bb);
93198 +
93199 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
93200 +// gimple_set_location(assign, loc);
93201 +#if BUILDING_GCC_VERSION <= 4007
93202 + find_referenced_vars_in(assign);
93203 +#endif
93204 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
93205 + update_stmt(assign);
93206 + bb = bb->next_bb;
93207 +
93208 + // 3. instrument each BB with an operation on the local entropy variable
93209 + while (bb != EXIT_BLOCK_PTR) {
93210 + perturb_local_entropy(bb, local_entropy);
93211 + bb = bb->next_bb;
93212 + };
93213 +
93214 + // 4. mix local entropy into the global entropy variable
93215 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
93216 + return 0;
93217 +}
93218 +
93219 +static void start_unit_callback(void *gcc_data, void *user_data)
93220 +{
93221 +#if BUILDING_GCC_VERSION >= 4007
93222 + seed = get_random_seed(false);
93223 +#else
93224 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
93225 + seed *= seed;
93226 +#endif
93227 +
93228 + if (in_lto_p)
93229 + return;
93230 +
93231 + // extern u64 latent_entropy
93232 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
93233 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), long_long_unsigned_type_node);
93234 +
93235 + TREE_STATIC(latent_entropy_decl) = 1;
93236 + TREE_PUBLIC(latent_entropy_decl) = 1;
93237 + TREE_USED(latent_entropy_decl) = 1;
93238 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
93239 + DECL_EXTERNAL(latent_entropy_decl) = 1;
93240 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
93241 + DECL_INITIAL(latent_entropy_decl) = NULL;
93242 + lang_hooks.decls.pushdecl(latent_entropy_decl);
93243 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
93244 +// varpool_finalize_decl(latent_entropy_decl);
93245 +// varpool_mark_needed_node(latent_entropy_decl);
93246 +}
93247 +
93248 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
93249 +{
93250 + const char * const plugin_name = plugin_info->base_name;
93251 + struct register_pass_info latent_entropy_pass_info = {
93252 + .pass = &latent_entropy_pass.pass,
93253 + .reference_pass_name = "optimized",
93254 + .ref_pass_instance_number = 1,
93255 + .pos_op = PASS_POS_INSERT_BEFORE
93256 + };
93257 +
93258 + if (!plugin_default_version_check(version, &gcc_version)) {
93259 + error(G_("incompatible gcc/plugin versions"));
93260 + return 1;
93261 + }
93262 +
93263 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
93264 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
93265 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
93266 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
93267 +
93268 + return 0;
93269 +}
93270 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
93271 new file mode 100644
93272 index 0000000..5921fd7
93273 --- /dev/null
93274 +++ b/tools/gcc/size_overflow_hash.data
93275 @@ -0,0 +1,3713 @@
93276 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
93277 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
93278 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
93279 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
93280 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
93281 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
93282 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
93283 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
93284 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
93285 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
93286 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
93287 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
93288 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
93289 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
93290 +create_log_8225 create_log 2 8225 NULL
93291 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
93292 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
93293 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
93294 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
93295 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
93296 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
93297 +padzero_55 padzero 1 55 &sel_read_policyvers_55
93298 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
93299 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
93300 +read_file_blob_57406 read_file_blob 3 57406 NULL
93301 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
93302 +enclosure_register_57412 enclosure_register 3 57412 NULL
93303 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
93304 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
93305 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
93306 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
93307 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
93308 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
93309 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
93310 +init_cdev_8274 init_cdev 1 8274 NULL
93311 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
93312 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
93313 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
93314 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
93315 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
93316 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
93317 +load_msg_95 load_msg 2 95 NULL
93318 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
93319 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
93320 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
93321 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
93322 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
93323 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
93324 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
93325 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
93326 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
93327 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
93328 +send_midi_async_57463 send_midi_async 3 57463 NULL
93329 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
93330 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
93331 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
93332 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
93333 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
93334 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
93335 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
93336 +init_q_132 init_q 4 132 NULL
93337 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
93338 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
93339 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
93340 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
93341 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
93342 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
93343 +uio_read_49300 uio_read 3 49300 NULL
93344 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
93345 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
93346 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
93347 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
93348 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
93349 +play_iframe_8219 play_iframe 3 8219 NULL
93350 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
93351 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
93352 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
93353 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
93354 +init_tag_map_57515 init_tag_map 3 57515 NULL
93355 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
93356 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
93357 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
93358 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
93359 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
93360 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
93361 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
93362 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
93363 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
93364 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
93365 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
93366 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
93367 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
93368 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
93369 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
93370 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
93371 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
93372 +cache_read_24790 cache_read 3 24790 NULL
93373 +px_raw_event_49371 px_raw_event 4 49371 NULL
93374 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
93375 +compat_filldir_32999 compat_filldir 3 32999 NULL
93376 +hci_si_event_1404 hci_si_event 3 1404 NULL
93377 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
93378 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
93379 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
93380 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
93381 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
93382 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
93383 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
93384 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
93385 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
93386 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
93387 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
93388 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
93389 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
93390 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
93391 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
93392 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
93393 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
93394 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
93395 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
93396 +mem_read_57631 mem_read 3 57631 NULL
93397 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
93398 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
93399 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
93400 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
93401 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
93402 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
93403 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
93404 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
93405 +queues_read_24877 queues_read 3 24877 NULL
93406 +__fprog_create_41263 __fprog_create 2 41263 NULL
93407 +syslog_print_307 syslog_print 2 307 NULL
93408 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
93409 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
93410 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
93411 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
93412 +r3964_write_57662 r3964_write 4 57662 NULL
93413 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
93414 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
93415 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
93416 +alloc_context_41283 alloc_context 1 41283 NULL
93417 +__lgwrite_57669 __lgwrite 4 57669 NULL
93418 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
93419 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
93420 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
93421 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
93422 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
93423 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
93424 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
93425 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
93426 +write_node_33121 write_node 4 33121 NULL
93427 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
93428 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
93429 +profile_remove_8556 profile_remove 3 8556 NULL
93430 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
93431 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
93432 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
93433 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
93434 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
93435 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
93436 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
93437 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
93438 +tower_write_8580 tower_write 3 8580 NULL
93439 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
93440 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
93441 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
93442 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
93443 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
93444 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
93445 +smk_write_access_49561 smk_write_access 3 49561 NULL
93446 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
93447 +kmp_init_41373 kmp_init 2 41373 NULL
93448 +context_alloc_24645 context_alloc 3 24645 NULL
93449 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
93450 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
93451 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
93452 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
93453 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
93454 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
93455 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
93456 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
93457 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
93458 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
93459 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
93460 +pp_read_33210 pp_read 3 33210 NULL
93461 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
93462 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
93463 +ivtv_read_57796 ivtv_read 3 57796 NULL
93464 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
93465 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
93466 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
93467 +heap_init_49617 heap_init 2 49617 NULL
93468 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
93469 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
93470 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
93471 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
93472 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
93473 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
93474 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
93475 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
93476 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
93477 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
93478 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
93479 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
93480 +st_write_16874 st_write 3 16874 NULL
93481 +copy_to_user_57835 copy_to_user 3 57835 NULL
93482 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
93483 +pidlist_resize_496 pidlist_resize 2 496 NULL
93484 +flash_read_57843 flash_read 3 57843 NULL
93485 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
93486 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
93487 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
93488 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
93489 +arcfb_write_8702 arcfb_write 3 8702 NULL
93490 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
93491 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
93492 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
93493 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
93494 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
93495 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
93496 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
93497 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
93498 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
93499 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
93500 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
93501 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
93502 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
93503 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
93504 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
93505 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
93506 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
93507 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
93508 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
93509 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
93510 +devres_alloc_551 devres_alloc 2 551 NULL
93511 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
93512 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
93513 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
93514 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
93515 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
93516 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
93517 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
93518 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
93519 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
93520 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
93521 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
93522 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
93523 +sys_prctl_8766 sys_prctl 4 8766 NULL
93524 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
93525 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
93526 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
93527 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
93528 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
93529 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
93530 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
93531 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
93532 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
93533 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
93534 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
93535 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
93536 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
93537 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
93538 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
93539 +gserial_setup_41558 gserial_setup 2 41558 NULL
93540 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
93541 +rx_57944 rx 4 57944 NULL
93542 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
93543 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
93544 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
93545 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
93546 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
93547 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
93548 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
93549 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
93550 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
93551 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
93552 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
93553 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
93554 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
93555 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
93556 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
93557 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
93558 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
93559 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
93560 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
93561 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
93562 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
93563 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
93564 +a2mp_send_41615 a2mp_send 4 41615 NULL
93565 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
93566 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
93567 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
93568 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
93569 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
93570 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
93571 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
93572 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
93573 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
93574 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
93575 +add_uuid_49831 add_uuid 4 49831 NULL
93576 +send_pages_8872 send_pages 3 8872 NULL
93577 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
93578 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
93579 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
93580 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
93581 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
93582 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
93583 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
93584 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
93585 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
93586 +vfs_writev_25278 vfs_writev 3 25278 NULL
93587 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
93588 +alloc_async_14208 alloc_async 1 14208 NULL
93589 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
93590 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
93591 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
93592 +create_entry_33479 create_entry 2 33479 NULL
93593 +mce_async_out_58056 mce_async_out 3 58056 NULL
93594 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
93595 +sys_preadv_17100 sys_preadv 3 17100 NULL
93596 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
93597 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
93598 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
93599 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
93600 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
93601 +res_counter_read_33499 res_counter_read 4 33499 NULL
93602 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
93603 +cm4040_write_58079 cm4040_write 3 58079 NULL
93604 +fb_read_33506 fb_read 3 33506 NULL
93605 +help_25316 help 5 25316 NULL nohasharray
93606 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
93607 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
93608 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
93609 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
93610 +ddp_set_map_751 ddp_set_map 4 751 NULL
93611 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
93612 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
93613 +dvb_video_write_754 dvb_video_write 3 754 NULL
93614 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
93615 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
93616 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
93617 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
93618 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
93619 +udi_log_event_58105 udi_log_event 3 58105 NULL
93620 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
93621 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
93622 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
93623 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
93624 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
93625 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
93626 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
93627 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
93628 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
93629 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
93630 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
93631 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
93632 +sep_read_17161 sep_read 3 17161 NULL
93633 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
93634 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
93635 +dup_array_33551 dup_array 3 33551 NULL
93636 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
93637 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
93638 +fillonedir_41746 fillonedir 3 41746 NULL
93639 +init_bch_64130 init_bch 1-2 64130 NULL
93640 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
93641 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
93642 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
93643 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
93644 +savemem_58129 savemem 3 58129 NULL
93645 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
93646 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
93647 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
93648 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
93649 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
93650 +if_writecmd_815 if_writecmd 2 815 NULL
93651 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
93652 +read_fifo_826 read_fifo 3 826 NULL
93653 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
93654 +scsi_execute_33596 scsi_execute 5 33596 NULL
93655 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
93656 +ms_rw_17220 ms_rw 3-4 17220 NULL
93657 +read_tree_block_841 read_tree_block 3 841 NULL
93658 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
93659 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
93660 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
93661 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
93662 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
93663 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
93664 +um_idi_read_850 um_idi_read 3 850 NULL
93665 +__module_alloc_50004 __module_alloc 1 50004 NULL
93666 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
93667 +ts_read_44687 ts_read 3 44687 NULL
93668 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
93669 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
93670 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
93671 +provide_user_output_41105 provide_user_output 3 41105 NULL
93672 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
93673 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
93674 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
93675 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
93676 +alloc_ep_17269 alloc_ep 1 17269 NULL
93677 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
93678 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
93679 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
93680 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
93681 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
93682 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
93683 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
93684 +create_queues_9088 create_queues 2-3 9088 NULL
93685 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
93686 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
93687 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
93688 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
93689 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
93690 +read_file_debug_58256 read_file_debug 3 58256 NULL
93691 +skb_pad_17302 skb_pad 2 17302 NULL
93692 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
93693 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
93694 +profile_load_58267 profile_load 3 58267 NULL
93695 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
93696 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
93697 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
93698 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
93699 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
93700 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
93701 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
93702 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
93703 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
93704 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
93705 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
93706 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
93707 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
93708 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
93709 +get_packet_41914 get_packet 3 41914 NULL
93710 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
93711 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
93712 +read_file_slot_50111 read_file_slot 3 50111 NULL
93713 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
93714 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
93715 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
93716 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
93717 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
93718 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
93719 +copy_items_50140 copy_items 6 50140 NULL
93720 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
93721 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
93722 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
93723 +map_addr_56144 map_addr 7 56144 NULL
93724 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
93725 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
93726 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
93727 +portnames_read_41958 portnames_read 3 41958 NULL
93728 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
93729 +hashtab_create_33769 hashtab_create 3 33769 NULL
93730 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
93731 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
93732 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
93733 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
93734 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
93735 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
93736 +odev_update_50169 odev_update 2 50169 NULL
93737 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
93738 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
93739 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
93740 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
93741 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
93742 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
93743 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
93744 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
93745 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
93746 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
93747 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
93748 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
93749 +lguest_map_42008 lguest_map 1-2 42008 NULL
93750 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
93751 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
93752 +pool_allocate_42012 pool_allocate 3 42012 NULL
93753 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
93754 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
93755 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
93756 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
93757 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
93758 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
93759 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
93760 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
93761 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
93762 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
93763 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
93764 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
93765 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
93766 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
93767 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
93768 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
93769 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
93770 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
93771 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
93772 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
93773 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
93774 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
93775 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
93776 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
93777 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
93778 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
93779 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
93780 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
93781 +config_proc_write_33878 config_proc_write 3 33878 NULL
93782 +capabilities_read_58457 capabilities_read 3 58457 NULL
93783 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
93784 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
93785 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
93786 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
93787 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
93788 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
93789 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
93790 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
93791 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
93792 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
93793 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
93794 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
93795 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
93796 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
93797 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
93798 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
93799 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
93800 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
93801 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
93802 +vme_user_write_15587 vme_user_write 3 15587 NULL
93803 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
93804 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
93805 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
93806 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
93807 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
93808 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
93809 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
93810 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
93811 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
93812 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
93813 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
93814 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
93815 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
93816 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
93817 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
93818 +read_9397 read 3 9397 NULL
93819 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
93820 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
93821 +printer_write_60276 printer_write 3 60276 NULL
93822 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
93823 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
93824 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
93825 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
93826 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
93827 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
93828 +osst_execute_17607 osst_execute 7-6 17607 NULL
93829 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
93830 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
93831 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
93832 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
93833 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
93834 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
93835 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
93836 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
93837 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
93838 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
93839 +xip_file_read_58592 xip_file_read 3 58592 NULL
93840 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
93841 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
93842 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
93843 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
93844 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
93845 +ppp_write_34034 ppp_write 3 34034 NULL
93846 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
93847 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
93848 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
93849 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
93850 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
93851 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
93852 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
93853 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
93854 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
93855 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
93856 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
93857 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
93858 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
93859 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
93860 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
93861 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
93862 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
93863 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
93864 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
93865 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
93866 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
93867 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
93868 +lp_write_9511 lp_write 3 9511 NULL
93869 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
93870 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
93871 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
93872 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
93873 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
93874 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
93875 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
93876 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
93877 +read_file_dma_9530 read_file_dma 3 9530 NULL
93878 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
93879 +rcname_read_25919 rcname_read 3 25919 NULL
93880 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
93881 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
93882 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
93883 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
93884 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
93885 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
93886 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
93887 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
93888 +key_flags_read_25931 key_flags_read 3 25931 NULL
93889 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
93890 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
93891 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
93892 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
93893 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
93894 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
93895 +fw_node_create_9559 fw_node_create 2 9559 NULL
93896 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
93897 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
93898 +kobj_map_9566 kobj_map 2-3 9566 NULL
93899 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
93900 +acpi_map_58725 acpi_map 1-2 58725 NULL
93901 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
93902 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
93903 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
93904 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
93905 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
93906 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
93907 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
93908 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
93909 +file_read_actor_1401 file_read_actor 4 1401 NULL
93910 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
93911 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
93912 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
93913 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
93914 +do_sync_9604 do_sync 1 9604 NULL
93915 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
93916 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
93917 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
93918 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
93919 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
93920 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
93921 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
93922 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
93923 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
93924 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
93925 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
93926 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
93927 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
93928 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
93929 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
93930 +sge_rx_50594 sge_rx 3 50594 NULL
93931 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
93932 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
93933 +skb_padto_50759 skb_padto 2 50759 NULL
93934 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
93935 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
93936 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
93937 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
93938 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
93939 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
93940 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
93941 +ep_read_58813 ep_read 3 58813 NULL
93942 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
93943 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
93944 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
93945 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
93946 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
93947 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
93948 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
93949 +dns_query_9676 dns_query 3 9676 NULL
93950 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
93951 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
93952 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
93953 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
93954 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
93955 +command_write_58841 command_write 3 58841 NULL
93956 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
93957 +dev_config_8506 dev_config 3 8506 NULL
93958 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
93959 +sys_readv_50664 sys_readv 3 50664 NULL
93960 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
93961 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
93962 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
93963 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
93964 +recover_head_17904 recover_head 3 17904 NULL
93965 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
93966 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
93967 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
93968 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
93969 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
93970 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
93971 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
93972 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
93973 +skb_cow_26138 skb_cow 2 26138 NULL
93974 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
93975 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
93976 +do_sigpending_9766 do_sigpending 2 9766 NULL
93977 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
93978 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
93979 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
93980 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
93981 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
93982 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
93983 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
93984 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
93985 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
93986 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
93987 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
93988 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
93989 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
93990 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
93991 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
93992 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
93993 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
93994 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
93995 +get_registers_26187 get_registers 3 26187 NULL
93996 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
93997 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
93998 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
93999 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
94000 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
94001 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
94002 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
94003 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
94004 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
94005 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
94006 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
94007 +mce_write_26201 mce_write 3 26201 NULL
94008 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
94009 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
94010 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
94011 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
94012 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
94013 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
94014 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
94015 +tpm_write_50798 tpm_write 3 50798 NULL
94016 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
94017 +tun_do_read_50800 tun_do_read 4 50800 NULL
94018 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
94019 +write_flush_50803 write_flush 3 50803 NULL
94020 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
94021 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
94022 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
94023 +dvb_play_50814 dvb_play 3 50814 NULL
94024 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
94025 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
94026 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
94027 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
94028 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
94029 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
94030 +dma_attach_50831 dma_attach 6-7 50831 NULL
94031 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
94032 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
94033 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
94034 +packet_came_18072 packet_came 3 18072 NULL
94035 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
94036 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
94037 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
94038 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
94039 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
94040 +get_vm_area_18080 get_vm_area 1 18080 NULL
94041 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
94042 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
94043 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
94044 +self_check_write_50856 self_check_write 5 50856 NULL
94045 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
94046 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
94047 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
94048 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
94049 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
94050 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
94051 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
94052 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
94053 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
94054 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
94055 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
94056 +vb2_read_42703 vb2_read 3 42703 NULL
94057 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
94058 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
94059 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
94060 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
94061 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
94062 +read_file_misc_9948 read_file_misc 3 9948 NULL
94063 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
94064 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
94065 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
94066 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
94067 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
94068 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
94069 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
94070 +cosa_write_1774 cosa_write 3 1774 NULL
94071 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
94072 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
94073 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
94074 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
94075 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
94076 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
94077 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
94078 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
94079 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
94080 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
94081 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
94082 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
94083 +mld_newpack_50950 mld_newpack 2 50950 NULL
94084 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
94085 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
94086 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
94087 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
94088 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
94089 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
94090 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
94091 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
94092 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
94093 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
94094 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
94095 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
94096 +handle_request_10024 handle_request 9 10024 NULL
94097 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
94098 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
94099 +timeout_write_50991 timeout_write 3 50991 NULL
94100 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
94101 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
94102 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
94103 +proc_write_51003 proc_write 3 51003 NULL
94104 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
94105 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
94106 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
94107 +set_arg_42824 set_arg 3 42824 NULL
94108 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
94109 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
94110 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
94111 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
94112 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
94113 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
94114 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
94115 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
94116 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
94117 +dt3155_read_59226 dt3155_read 3 59226 NULL
94118 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
94119 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
94120 +dump_midi_51040 dump_midi 3 51040 NULL
94121 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
94122 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
94123 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
94124 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
94125 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
94126 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
94127 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
94128 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
94129 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
94130 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
94131 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
94132 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
94133 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
94134 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
94135 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
94136 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
94137 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
94138 +read_vmcore_26501 read_vmcore 3 26501 NULL
94139 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
94140 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
94141 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
94142 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
94143 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
94144 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
94145 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
94146 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
94147 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
94148 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
94149 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
94150 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
94151 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
94152 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
94153 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
94154 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
94155 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
94156 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
94157 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
94158 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
94159 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
94160 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
94161 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
94162 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
94163 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
94164 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
94165 +fd_copyout_59323 fd_copyout 3 59323 NULL
94166 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
94167 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
94168 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
94169 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
94170 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
94171 +solos_param_store_34755 solos_param_store 4 34755 NULL
94172 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
94173 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
94174 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
94175 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
94176 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
94177 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
94178 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
94179 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
94180 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
94181 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
94182 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
94183 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
94184 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
94185 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
94186 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
94187 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
94188 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
94189 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
94190 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
94191 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
94192 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
94193 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
94194 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
94195 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
94196 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
94197 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
94198 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
94199 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
94200 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
94201 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
94202 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
94203 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
94204 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
94205 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
94206 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
94207 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
94208 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
94209 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
94210 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
94211 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
94212 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
94213 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
94214 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
94215 +tipc_send_51238 tipc_send 4 51238 NULL
94216 +drm_property_create_51239 drm_property_create 4 51239 NULL
94217 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
94218 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
94219 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
94220 +audit_expand_2098 audit_expand 2 2098 NULL
94221 +st_read_51251 st_read 3 51251 NULL
94222 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
94223 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
94224 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
94225 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
94226 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
94227 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
94228 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
94229 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
94230 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
94231 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
94232 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
94233 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
94234 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
94235 +c4_add_card_54968 c4_add_card 3 54968 NULL
94236 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
94237 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
94238 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
94239 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
94240 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
94241 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
94242 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
94243 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
94244 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
94245 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
94246 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
94247 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
94248 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
94249 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
94250 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
94251 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
94252 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
94253 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
94254 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
94255 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
94256 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
94257 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
94258 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
94259 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
94260 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
94261 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
94262 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
94263 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
94264 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
94265 +debug_output_18575 debug_output 3 18575 NULL
94266 +Realloc_34961 Realloc 2 34961 NULL
94267 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
94268 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
94269 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
94270 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
94271 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
94272 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
94273 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
94274 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
94275 +vhci_write_2224 vhci_write 3 2224 NULL
94276 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
94277 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
94278 +rb_alloc_3102 rb_alloc 1 3102 NULL
94279 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
94280 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
94281 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
94282 +write_pbl_59583 write_pbl 4 59583 NULL
94283 +from_buffer_18625 from_buffer 3 18625 NULL
94284 +uio_write_43202 uio_write 3 43202 NULL
94285 +memdup_user_59590 memdup_user 2 59590 NULL
94286 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
94287 +iso_callback_43208 iso_callback 3 43208 NULL
94288 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
94289 +smk_write_load_26829 smk_write_load 3 26829 NULL
94290 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
94291 +do_update_counters_2259 do_update_counters 4 2259 NULL
94292 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
94293 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
94294 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
94295 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
94296 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
94297 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
94298 +mtrr_write_59622 mtrr_write 3 59622 NULL
94299 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
94300 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
94301 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
94302 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
94303 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
94304 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
94305 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
94306 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
94307 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
94308 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
94309 +fixup_leb_43256 fixup_leb 3 43256 NULL
94310 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
94311 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
94312 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
94313 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
94314 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
94315 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
94316 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
94317 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
94318 +evtchn_write_43278 evtchn_write 3 43278 NULL
94319 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
94320 +store_ifalias_35088 store_ifalias 4 35088 NULL
94321 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
94322 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
94323 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
94324 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
94325 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
94326 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
94327 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
94328 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
94329 +capi_write_35104 capi_write 3 35104 NULL nohasharray
94330 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
94331 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
94332 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
94333 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
94334 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
94335 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
94336 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
94337 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
94338 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
94339 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
94340 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
94341 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
94342 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
94343 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
94344 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
94345 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
94346 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
94347 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
94348 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
94349 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
94350 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
94351 +do_trimming_26952 do_trimming 3 26952 NULL
94352 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
94353 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
94354 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
94355 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
94356 +alloc_buf_34532 alloc_buf 1 34532 NULL
94357 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
94358 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
94359 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
94360 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
94361 +otp_read_10594 otp_read 2-4-5 10594 NULL
94362 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
94363 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
94364 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
94365 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
94366 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
94367 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
94368 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
94369 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
94370 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
94371 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
94372 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
94373 +venus_remove_59781 venus_remove 4 59781 NULL
94374 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
94375 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
94376 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
94377 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
94378 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
94379 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
94380 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
94381 +xenfb_write_43412 xenfb_write 3 43412 NULL
94382 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
94383 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
94384 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
94385 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
94386 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
94387 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
94388 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
94389 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
94390 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
94391 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
94392 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
94393 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
94394 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
94395 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
94396 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
94397 +cmd_complete_51629 cmd_complete 6 51629 NULL
94398 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
94399 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
94400 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
94401 +set_fd_set_35249 set_fd_set 1 35249 NULL
94402 +wiphy_new_2482 wiphy_new 2 2482 NULL
94403 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
94404 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
94405 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
94406 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
94407 +tcp_push_10680 tcp_push 3 10680 NULL
94408 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
94409 +c101_run_37279 c101_run 2 37279 NULL
94410 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
94411 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
94412 +tun_put_user_59849 tun_put_user 4 59849 NULL
94413 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
94414 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
94415 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
94416 +dm_write_2513 dm_write 3 2513 NULL
94417 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
94418 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
94419 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
94420 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
94421 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
94422 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
94423 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
94424 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
94425 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
94426 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
94427 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
94428 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
94429 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
94430 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
94431 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
94432 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
94433 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
94434 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
94435 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
94436 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
94437 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
94438 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
94439 +sel_write_access_51704 sel_write_access 3 51704 NULL
94440 +sys_syslog_10746 sys_syslog 3 10746 NULL
94441 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
94442 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
94443 +do_readlink_43518 do_readlink 2 43518 NULL
94444 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
94445 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
94446 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
94447 +read_file_reset_52310 read_file_reset 3 52310 NULL
94448 +pms_capture_27142 pms_capture 4 27142 NULL
94449 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
94450 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
94451 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
94452 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
94453 +msg_set_51725 msg_set 3 51725 NULL
94454 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
94455 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
94456 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
94457 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
94458 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
94459 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
94460 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
94461 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
94462 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
94463 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
94464 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
94465 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
94466 +sys_bind_10799 sys_bind 3 10799 NULL
94467 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
94468 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
94469 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
94470 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
94471 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
94472 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
94473 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
94474 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
94475 +send_command_10832 send_command 4 10832 NULL
94476 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
94477 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
94478 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
94479 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
94480 +proc_read_43614 proc_read 3 43614 NULL
94481 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
94482 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
94483 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
94484 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
94485 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
94486 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
94487 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
94488 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
94489 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
94490 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
94491 +vmalloc_15464 vmalloc 1 15464 NULL
94492 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
94493 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
94494 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
94495 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
94496 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
94497 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
94498 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
94499 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
94500 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
94501 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
94502 +adu_write_30487 adu_write 3 30487 NULL
94503 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
94504 +get_scq_10897 get_scq 2 10897 NULL
94505 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
94506 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
94507 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
94508 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
94509 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
94510 +load_module_60056 load_module 2 60056 NULL nohasharray
94511 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
94512 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
94513 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
94514 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
94515 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
94516 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
94517 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
94518 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
94519 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
94520 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
94521 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
94522 +user_read_51881 user_read 3 51881 NULL
94523 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
94524 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
94525 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
94526 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
94527 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
94528 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
94529 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
94530 +async_setkey_35521 async_setkey 3 35521 NULL
94531 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
94532 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
94533 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
94534 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
94535 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
94536 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
94537 +add_tty_40055 add_tty 1 40055 NULL nohasharray
94538 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
94539 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
94540 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
94541 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
94542 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
94543 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
94544 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
94545 +alloc_context_3194 alloc_context 1 3194 NULL
94546 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
94547 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
94548 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
94549 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
94550 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
94551 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
94552 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
94553 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
94554 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
94555 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
94556 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
94557 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
94558 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
94559 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
94560 +init_state_60165 init_state 2 60165 NULL
94561 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
94562 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
94563 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
94564 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
94565 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
94566 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
94567 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
94568 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
94569 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
94570 +calc_hmac_32010 calc_hmac 3 32010 NULL
94571 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
94572 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
94573 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
94574 +kernel_readv_35617 kernel_readv 3 35617 NULL
94575 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
94576 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
94577 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
94578 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
94579 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
94580 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
94581 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
94582 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
94583 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
94584 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
94585 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
94586 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
94587 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
94588 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
94589 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
94590 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
94591 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
94592 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
94593 +store_debug_level_35652 store_debug_level 3 35652 NULL
94594 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
94595 +read_flush_43851 read_flush 3 43851 NULL
94596 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
94597 +cmm_write_2896 cmm_write 3 2896 NULL
94598 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
94599 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
94600 +tunables_write_59563 tunables_write 3 59563 NULL
94601 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
94602 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
94603 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
94604 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
94605 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
94606 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
94607 +dm_table_create_35687 dm_table_create 3 35687 NULL
94608 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
94609 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
94610 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
94611 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
94612 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
94613 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
94614 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
94615 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
94616 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
94617 +debug_read_19322 debug_read 3 19322 NULL
94618 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
94619 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
94620 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
94621 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
94622 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
94623 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
94624 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
94625 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
94626 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
94627 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
94628 +doc_probe_23285 doc_probe 1 23285 NULL
94629 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
94630 +SendString_43928 SendString 3 43928 NULL
94631 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
94632 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
94633 +retry_count_read_52129 retry_count_read 3 52129 NULL
94634 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
94635 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
94636 +read_zero_19366 read_zero 3 19366 NULL
94637 +bch_alloc_4593 bch_alloc 1 4593 NULL
94638 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
94639 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
94640 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
94641 +raid5_resize_63306 raid5_resize 2 63306 NULL
94642 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
94643 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
94644 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
94645 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
94646 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
94647 +depth_write_3021 depth_write 3 3021 NULL
94648 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
94649 +read_file_stations_35795 read_file_stations 3 35795 NULL
94650 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
94651 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
94652 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
94653 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
94654 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
94655 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
94656 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
94657 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
94658 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
94659 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
94660 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
94661 +driver_names_read_60399 driver_names_read 3 60399 NULL
94662 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
94663 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
94664 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
94665 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
94666 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
94667 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
94668 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
94669 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
94670 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
94671 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
94672 +rx_data_60442 rx_data 4 60442 NULL
94673 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
94674 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
94675 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
94676 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
94677 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
94678 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
94679 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
94680 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
94681 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
94682 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
94683 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
94684 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
94685 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
94686 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
94687 +construct_key_11329 construct_key 3 11329 NULL
94688 +evm_write_key_27715 evm_write_key 3 27715 NULL
94689 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
94690 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
94691 +filldir_55137 filldir 3 55137 NULL
94692 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
94693 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
94694 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
94695 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
94696 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
94697 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
94698 +sel_write_create_11353 sel_write_create 3 11353 NULL
94699 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
94700 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
94701 +hwflags_read_52318 hwflags_read 3 52318 NULL
94702 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
94703 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
94704 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
94705 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
94706 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
94707 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
94708 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
94709 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
94710 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
94711 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
94712 +nfsd_read_19568 nfsd_read 5 19568 NULL
94713 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
94714 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
94715 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
94716 +kcalloc_27770 kcalloc 1-2 27770 NULL
94717 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
94718 +bm_status_read_19583 bm_status_read 3 19583 NULL
94719 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
94720 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
94721 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
94722 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
94723 +acl_alloc_35979 acl_alloc 1 35979 NULL
94724 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
94725 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
94726 +str_to_user_11411 str_to_user 2 11411 NULL
94727 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
94728 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
94729 +trace_options_read_11419 trace_options_read 3 11419 NULL
94730 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
94731 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
94732 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
94733 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
94734 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
94735 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
94736 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
94737 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
94738 +console_store_36007 console_store 4 36007 NULL
94739 +bttv_read_11432 bttv_read 3 11432 NULL
94740 +key_key_read_3241 key_key_read 3 3241 NULL
94741 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
94742 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
94743 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
94744 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
94745 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
94746 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
94747 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
94748 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
94749 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
94750 +um_idi_write_18293 um_idi_write 3 18293 NULL
94751 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
94752 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
94753 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
94754 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
94755 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
94756 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
94757 +sys_init_module_36047 sys_init_module 2 36047 NULL
94758 +read_profile_27859 read_profile 3 27859 NULL
94759 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
94760 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
94761 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
94762 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
94763 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
94764 +refill_pool_19477 refill_pool 2 19477 NULL
94765 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
94766 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
94767 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
94768 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
94769 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
94770 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
94771 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
94772 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
94773 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
94774 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
94775 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
94776 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
94777 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
94778 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
94779 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
94780 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
94781 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
94782 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
94783 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
94784 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
94785 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
94786 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
94787 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
94788 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
94789 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
94790 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
94791 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
94792 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
94793 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
94794 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
94795 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
94796 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
94797 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
94798 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
94799 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
94800 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
94801 +init_data_container_60709 init_data_container 1 60709 NULL
94802 +p9_client_read_19750 p9_client_read 5 19750 NULL
94803 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
94804 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
94805 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
94806 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
94807 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
94808 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
94809 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
94810 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
94811 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
94812 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
94813 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
94814 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
94815 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
94816 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
94817 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
94818 +send_stream_3397 send_stream 4 3397 NULL
94819 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
94820 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
94821 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
94822 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
94823 +msix_map_region_3411 msix_map_region 3 3411 NULL
94824 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
94825 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
94826 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
94827 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
94828 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
94829 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
94830 +opticon_write_60775 opticon_write 4 60775 NULL
94831 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
94832 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
94833 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
94834 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
94835 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
94836 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
94837 +vip_read_19832 vip_read 3 19832 NULL
94838 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
94839 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
94840 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
94841 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
94842 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
94843 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
94844 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
94845 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
94846 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
94847 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
94848 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
94849 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
94850 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
94851 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
94852 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
94853 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
94854 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
94855 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
94856 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
94857 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
94858 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
94859 +split_11691 split 2 11691 NULL
94860 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
94861 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
94862 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
94863 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
94864 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
94865 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
94866 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
94867 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
94868 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
94869 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
94870 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
94871 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
94872 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
94873 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
94874 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
94875 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
94876 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
94877 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
94878 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
94879 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
94880 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
94881 +spidev_write_44510 spidev_write 3 44510 NULL
94882 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
94883 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
94884 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
94885 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
94886 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
94887 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
94888 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
94889 +kone_receive_4690 kone_receive 4 4690 NULL
94890 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
94891 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
94892 +evtchn_read_3569 evtchn_read 3 3569 NULL
94893 +video_read_28148 video_read 3 28148 NULL
94894 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
94895 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
94896 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
94897 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
94898 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
94899 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
94900 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
94901 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
94902 +vc_resize_3585 vc_resize 2-3 3585 NULL
94903 +gluebi_write_27905 gluebi_write 3 27905 NULL
94904 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
94905 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
94906 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
94907 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
94908 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
94909 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
94910 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
94911 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
94912 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
94913 +pti_char_write_60960 pti_char_write 3 60960 NULL
94914 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
94915 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
94916 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
94917 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
94918 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
94919 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
94920 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
94921 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
94922 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
94923 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
94924 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
94925 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
94926 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
94927 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
94928 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
94929 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
94930 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
94931 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
94932 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
94933 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
94934 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
94935 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
94936 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
94937 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
94938 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
94939 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
94940 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
94941 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
94942 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
94943 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
94944 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
94945 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
94946 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
94947 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
94948 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
94949 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
94950 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
94951 +symtab_init_61050 symtab_init 2 61050 NULL
94952 +team_options_register_20091 team_options_register 3 20091 NULL
94953 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
94954 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
94955 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
94956 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
94957 +mpi_resize_44674 mpi_resize 2 44674 NULL
94958 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
94959 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
94960 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
94961 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
94962 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
94963 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
94964 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
94965 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
94966 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
94967 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
94968 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
94969 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
94970 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
94971 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
94972 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
94973 +pms_read_53873 pms_read 3 53873 NULL
94974 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
94975 +get_derived_key_61100 get_derived_key 4 61100 NULL
94976 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
94977 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
94978 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
94979 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
94980 +dm_read_15674 dm_read 3 15674 NULL
94981 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
94982 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
94983 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
94984 +kone_send_63435 kone_send 4 63435 NULL
94985 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
94986 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
94987 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
94988 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
94989 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
94990 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
94991 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
94992 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
94993 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
94994 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
94995 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
94996 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
94997 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
94998 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
94999 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
95000 +send_packet_52960 send_packet 4 52960 NULL
95001 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
95002 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
95003 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
95004 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
95005 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
95006 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
95007 +put_cmsg_36589 put_cmsg 4 36589 NULL
95008 +__vmalloc_61168 __vmalloc 1 61168 NULL
95009 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
95010 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
95011 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
95012 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
95013 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
95014 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
95015 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
95016 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
95017 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
95018 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
95019 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
95020 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
95021 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
95022 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
95023 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
95024 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
95025 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
95026 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
95027 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
95028 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
95029 +get_fd_set_3866 get_fd_set 1 3866 NULL
95030 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
95031 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
95032 +unlink_queued_645 unlink_queued 3-4 645 NULL
95033 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
95034 +sisusb_write_44834 sisusb_write 3 44834 NULL
95035 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
95036 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
95037 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
95038 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
95039 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
95040 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
95041 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
95042 +nvram_write_3894 nvram_write 3 3894 NULL
95043 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
95044 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
95045 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
95046 +vcs_write_3910 vcs_write 3 3910 NULL
95047 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
95048 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
95049 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
95050 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
95051 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
95052 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
95053 +do_tty_write_44896 do_tty_write 5 44896 NULL
95054 +set_powered_12129 set_powered 4 12129 NULL
95055 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
95056 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
95057 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
95058 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
95059 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
95060 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
95061 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
95062 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
95063 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
95064 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
95065 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
95066 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
95067 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
95068 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
95069 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
95070 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
95071 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
95072 +gather_array_56641 gather_array 3 56641 NULL
95073 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
95074 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
95075 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
95076 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
95077 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
95078 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
95079 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
95080 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
95081 +do_add_counters_3992 do_add_counters 3 3992 NULL
95082 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
95083 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
95084 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
95085 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
95086 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
95087 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
95088 +mei_write_4005 mei_write 3 4005 NULL
95089 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
95090 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
95091 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
95092 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
95093 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
95094 +receive_copy_12216 receive_copy 3 12216 NULL
95095 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
95096 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
95097 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
95098 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
95099 +change_xattr_61390 change_xattr 5 61390 NULL
95100 +find_skb_20431 find_skb 2 20431 NULL
95101 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
95102 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
95103 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
95104 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
95105 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
95106 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
95107 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
95108 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
95109 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
95110 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
95111 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
95112 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
95113 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
95114 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
95115 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
95116 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
95117 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
95118 +read_buf_20469 read_buf 2 20469 NULL
95119 +cm_write_36858 cm_write 3 36858 NULL
95120 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
95121 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
95122 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
95123 +sel_write_user_45060 sel_write_user 3 45060 NULL
95124 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
95125 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
95126 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
95127 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
95128 +fast_user_write_20494 fast_user_write 5 20494 NULL
95129 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
95130 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
95131 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
95132 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
95133 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
95134 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
95135 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
95136 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
95137 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
95138 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
95139 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
95140 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
95141 +osst_read_40237 osst_read 3 40237 NULL
95142 +tm6000_read_4151 tm6000_read 3 4151 NULL
95143 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
95144 +usbdev_read_45114 usbdev_read 3 45114 NULL
95145 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
95146 +spi_execute_28736 spi_execute 5 28736 NULL
95147 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
95148 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
95149 +get_alua_req_4166 get_alua_req 3 4166 NULL
95150 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
95151 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
95152 +venus_create_20555 venus_create 4 20555 NULL
95153 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
95154 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
95155 +receive_packet_12367 receive_packet 2 12367 NULL
95156 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
95157 +mem_write_22232 mem_write 3 22232 NULL
95158 +read_file_bool_4180 read_file_bool 3 4180 NULL
95159 +send_to_tty_45141 send_to_tty 3 45141 NULL
95160 +fops_read_40672 fops_read 3 40672 NULL
95161 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
95162 +write_leb_36957 write_leb 5 36957 NULL
95163 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
95164 +device_write_45156 device_write 3 45156 NULL
95165 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
95166 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
95167 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
95168 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
95169 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
95170 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
95171 +isp1760_register_628 isp1760_register 1-2 628 NULL
95172 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
95173 +lirc_write_20604 lirc_write 3 20604 NULL
95174 +sel_write_member_28800 sel_write_member 3 28800 NULL
95175 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
95176 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
95177 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
95178 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
95179 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
95180 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
95181 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
95182 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
95183 +setxattr_37006 setxattr 4 37006 NULL
95184 +add_child_45201 add_child 4 45201 NULL
95185 +seq_open_private_61589 seq_open_private 3 61589 NULL
95186 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
95187 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
95188 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
95189 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
95190 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
95191 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
95192 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
95193 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
95194 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
95195 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
95196 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
95197 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
95198 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
95199 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
95200 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
95201 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
95202 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
95203 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
95204 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
95205 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
95206 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
95207 +resize_stripes_61650 resize_stripes 2 61650 NULL
95208 +n2_run_53459 n2_run 3 53459 NULL
95209 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
95210 +parse_command_37079 parse_command 2 37079 NULL
95211 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
95212 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
95213 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
95214 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
95215 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
95216 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
95217 +insert_one_name_61668 insert_one_name 7 61668 NULL
95218 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
95219 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
95220 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
95221 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
95222 +lock_loop_61681 lock_loop 1 61681 NULL
95223 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
95224 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
95225 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
95226 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
95227 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
95228 +push_rx_28939 push_rx 3 28939 NULL
95229 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
95230 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
95231 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
95232 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
95233 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
95234 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
95235 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
95236 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
95237 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
95238 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
95239 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
95240 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
95241 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
95242 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
95243 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
95244 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
95245 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
95246 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
95247 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
95248 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
95249 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
95250 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
95251 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
95252 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
95253 +bin_uuid_28999 bin_uuid 3 28999 NULL
95254 +sys_sendto_20809 sys_sendto 6 20809 NULL
95255 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
95256 +set_registers_53582 set_registers 3 53582 NULL
95257 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
95258 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
95259 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
95260 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
95261 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
95262 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
95263 +keymap_store_45406 keymap_store 4 45406 NULL
95264 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
95265 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
95266 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
95267 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
95268 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
95269 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
95270 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
95271 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
95272 +__do_replace_37227 __do_replace 5 37227 NULL
95273 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
95274 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
95275 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
95276 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
95277 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
95278 +tso_fragment_29050 tso_fragment 3 29050 NULL
95279 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
95280 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
95281 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
95282 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
95283 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
95284 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
95285 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
95286 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
95287 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
95288 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
95289 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
95290 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
95291 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
95292 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
95293 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
95294 +set_link_security_4502 set_link_security 4 4502 NULL
95295 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
95296 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
95297 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
95298 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
95299 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
95300 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
95301 +mmio_read_40348 mmio_read 4 40348 NULL
95302 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
95303 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
95304 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
95305 +ivtv_write_12721 ivtv_write 3 12721 NULL
95306 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
95307 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
95308 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
95309 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
95310 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
95311 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
95312 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
95313 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
95314 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
95315 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
95316 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
95317 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
95318 +send_msg_37323 send_msg 4 37323 NULL
95319 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
95320 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
95321 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
95322 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
95323 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
95324 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
95325 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
95326 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
95327 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
95328 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
95329 +reshape_ring_29147 reshape_ring 2 29147 NULL
95330 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
95331 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
95332 +copy_macs_45534 copy_macs 4 45534 NULL
95333 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
95334 +listxattr_12769 listxattr 3 12769 NULL
95335 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
95336 +wdm_write_53735 wdm_write 3 53735 NULL
95337 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
95338 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
95339 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
95340 +mempool_create_29437 mempool_create 1 29437 NULL
95341 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
95342 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
95343 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
95344 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
95345 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
95346 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
95347 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
95348 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
95349 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
95350 +mgmt_event_12810 mgmt_event 4 12810 NULL
95351 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
95352 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
95353 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
95354 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
95355 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
95356 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
95357 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
95358 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
95359 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
95360 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
95361 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
95362 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
95363 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
95364 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
95365 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
95366 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
95367 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
95368 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
95369 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
95370 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
95371 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
95372 +recover_peb_29238 recover_peb 6-7 29238 NULL
95373 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
95374 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
95375 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
95376 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
95377 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
95378 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
95379 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
95380 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
95381 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
95382 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
95383 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
95384 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
95385 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
95386 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
95387 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
95388 +do_pselect_62061 do_pselect 1 62061 NULL
95389 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
95390 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
95391 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
95392 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
95393 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
95394 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
95395 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
95396 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
95397 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
95398 +sg_read_25799 sg_read 3 25799 NULL
95399 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
95400 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
95401 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
95402 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
95403 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
95404 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
95405 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
95406 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
95407 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
95408 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
95409 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
95410 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
95411 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
95412 +new_skb_21148 new_skb 1 21148 NULL
95413 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
95414 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
95415 +bm_status_write_12964 bm_status_write 3 12964 NULL
95416 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
95417 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
95418 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
95419 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
95420 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
95421 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
95422 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
95423 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
95424 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
95425 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
95426 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
95427 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
95428 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
95429 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
95430 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
95431 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
95432 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
95433 +video_usercopy_62151 video_usercopy 2 62151 NULL
95434 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
95435 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
95436 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
95437 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
95438 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
95439 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
95440 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
95441 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
95442 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
95443 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
95444 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
95445 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
95446 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
95447 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
95448 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
95449 +input_ff_create_21240 input_ff_create 2 21240 NULL
95450 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
95451 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
95452 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
95453 +amthi_read_45831 amthi_read 4 45831 NULL
95454 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
95455 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
95456 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
95457 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
95458 +sys_ipc_4889 sys_ipc 3 4889 NULL
95459 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
95460 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
95461 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
95462 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
95463 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
95464 +do_register_entry_29478 do_register_entry 4 29478 NULL
95465 +isdn_write_45863 isdn_write 3 45863 NULL
95466 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
95467 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
95468 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
95469 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
95470 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
95471 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
95472 +_malloc_54077 _malloc 1 54077 NULL
95473 +add_res_range_21310 add_res_range 4 21310 NULL
95474 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
95475 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
95476 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
95477 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
95478 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
95479 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
95480 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
95481 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
95482 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
95483 +create_xattr_54106 create_xattr 5 54106 NULL
95484 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
95485 +ep_write_59008 ep_write 3 59008 NULL
95486 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
95487 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
95488 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
95489 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
95490 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
95491 +alloc_mr_45935 alloc_mr 1 45935 NULL
95492 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
95493 +isku_receive_54130 isku_receive 4 54130 NULL
95494 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
95495 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
95496 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
95497 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
95498 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
95499 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
95500 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
95501 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
95502 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
95503 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
95504 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
95505 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
95506 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
95507 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
95508 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
95509 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
95510 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
95511 +comedi_read_13199 comedi_read 3 13199 NULL
95512 +flash_write_62354 flash_write 3 62354 NULL
95513 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
95514 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
95515 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
95516 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
95517 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
95518 +proc_file_read_53905 proc_file_read 3 53905 NULL
95519 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
95520 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
95521 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
95522 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
95523 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
95524 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
95525 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
95526 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
95527 +cru_detect_11272 cru_detect 1 11272 NULL
95528 +altera_irscan_62396 altera_irscan 2 62396 NULL
95529 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
95530 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
95531 +fw_download_code_13249 fw_download_code 3 13249 NULL
95532 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
95533 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
95534 +set_ssp_62411 set_ssp 4 62411 NULL
95535 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
95536 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
95537 +get_free_entries_46030 get_free_entries 1 46030 NULL
95538 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
95539 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
95540 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
95541 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
95542 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
95543 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
95544 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
95545 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
95546 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
95547 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
95548 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
95549 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
95550 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
95551 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
95552 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
95553 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
95554 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
95555 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
95556 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
95557 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
95558 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
95559 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
95560 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
95561 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
95562 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
95563 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
95564 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
95565 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
95566 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
95567 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
95568 +probes_write_29711 probes_write 3 29711 NULL
95569 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
95570 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
95571 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
95572 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
95573 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
95574 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
95575 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
95576 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
95577 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
95578 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
95579 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
95580 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
95581 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
95582 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
95583 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
95584 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
95585 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
95586 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
95587 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
95588 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
95589 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
95590 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
95591 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
95592 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
95593 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
95594 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
95595 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
95596 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
95597 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
95598 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
95599 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
95600 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
95601 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
95602 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
95603 +isdn_read_50021 isdn_read 3 50021 NULL
95604 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
95605 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
95606 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
95607 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
95608 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
95609 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
95610 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
95611 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
95612 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
95613 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
95614 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
95615 +get_subdir_62581 get_subdir 3 62581 NULL
95616 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
95617 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
95618 +vfs_readv_38011 vfs_readv 3 38011 NULL
95619 +keyring_read_13438 keyring_read 3 13438 NULL
95620 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
95621 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
95622 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
95623 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
95624 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
95625 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
95626 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
95627 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
95628 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
95629 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
95630 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
95631 +ftrace_write_29551 ftrace_write 3 29551 NULL
95632 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
95633 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
95634 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
95635 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
95636 +dev_write_7708 dev_write 3 7708 NULL
95637 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
95638 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
95639 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
95640 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
95641 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
95642 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
95643 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
95644 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
95645 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
95646 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
95647 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
95648 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
95649 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
95650 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
95651 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
95652 +bm_init_13529 bm_init 2 13529 NULL
95653 +check586_29914 check586 2 29914 NULL
95654 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
95655 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
95656 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
95657 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
95658 +pg_read_17276 pg_read 3 17276 NULL
95659 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
95660 +ep0_read_38095 ep0_read 3 38095 NULL
95661 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
95662 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
95663 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
95664 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
95665 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
95666 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
95667 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
95668 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
95669 +l2down_create_21755 l2down_create 4 21755 NULL
95670 +alloc_tio_13564 alloc_tio 3 13564 NULL
95671 +viacam_read_54526 viacam_read 3 54526 NULL
95672 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
95673 +tunables_read_36385 tunables_read 3 36385 NULL
95674 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
95675 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
95676 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
95677 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
95678 +setsockopt_54539 setsockopt 5 54539 NULL
95679 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
95680 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
95681 +tty_register_device_4544 tty_register_device 2 4544 NULL
95682 +cache_write_13589 cache_write 3 13589 NULL
95683 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
95684 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
95685 +key_replays_read_62746 key_replays_read 3 62746 NULL
95686 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
95687 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
95688 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
95689 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
95690 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
95691 +cdev_add_38176 cdev_add 2-3 38176 NULL
95692 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
95693 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
95694 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
95695 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
95696 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
95697 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
95698 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
95699 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
95700 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
95701 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
95702 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
95703 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
95704 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
95705 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
95706 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
95707 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
95708 +packet_snd_13634 packet_snd 3 13634 NULL
95709 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
95710 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
95711 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
95712 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
95713 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
95714 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
95715 +drp_wmove_30043 drp_wmove 4 30043 NULL
95716 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
95717 +cache_downcall_13666 cache_downcall 3 13666 NULL
95718 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
95719 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
95720 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
95721 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
95722 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
95723 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
95724 +tty_write_5494 tty_write 3 5494 NULL
95725 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
95726 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
95727 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
95728 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
95729 +teiup_create_43201 teiup_create 3 43201 NULL
95730 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
95731 +filldir64_46469 filldir64 3 46469 NULL
95732 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
95733 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
95734 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
95735 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
95736 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
95737 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
95738 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
95739 +spidev_message_5518 spidev_message 3 5518 NULL
95740 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
95741 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
95742 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
95743 +evm_read_key_54674 evm_read_key 3 54674 NULL
95744 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
95745 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
95746 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
95747 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
95748 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
95749 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
95750 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
95751 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
95752 +u32_array_read_2219 u32_array_read 3 2219 NULL
95753 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
95754 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
95755 +sys_add_key_61288 sys_add_key 4 61288 NULL
95756 +kmsg_read_46514 kmsg_read 3 46514 NULL
95757 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
95758 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
95759 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
95760 +recv_stream_30138 recv_stream 4 30138 NULL
95761 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
95762 +getdqbuf_62908 getdqbuf 1 62908 NULL
95763 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
95764 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
95765 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
95766 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
95767 +fir16_create_5574 fir16_create 3 5574 NULL
95768 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
95769 +pt_write_40159 pt_write 3 40159 NULL
95770 +bioset_create_5580 bioset_create 1 5580 NULL
95771 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
95772 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
95773 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
95774 +kzalloc_54740 kzalloc 1 54740 NULL
95775 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
95776 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
95777 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
95778 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
95779 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
95780 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
95781 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
95782 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
95783 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
95784 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
95785 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
95786 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
95787 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
95788 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
95789 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
95790 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
95791 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
95792 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
95793 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
95794 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
95795 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
95796 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
95797 +ti_recv_22027 ti_recv 4 22027 NULL
95798 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
95799 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
95800 +nfsd_write_54809 nfsd_write 6 54809 NULL
95801 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
95802 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
95803 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
95804 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
95805 +get_skb_63008 get_skb 2 63008 NULL
95806 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
95807 +netlink_send_38434 netlink_send 5 38434 NULL
95808 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
95809 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
95810 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
95811 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
95812 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
95813 +write_rio_54837 write_rio 3 54837 NULL
95814 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
95815 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
95816 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
95817 +get_arg_5694 get_arg 3 5694 NULL
95818 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
95819 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
95820 +compat_readv_30273 compat_readv 3 30273 NULL
95821 +printer_read_54851 printer_read 3 54851 NULL
95822 +mem_rw_22085 mem_rw 3 22085 NULL
95823 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
95824 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
95825 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
95826 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
95827 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
95828 +unlink1_63059 unlink1 3 63059 NULL
95829 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
95830 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
95831 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
95832 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
95833 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
95834 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
95835 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
95836 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
95837 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
95838 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
95839 +dev_names_read_38509 dev_names_read 3 38509 NULL
95840 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
95841 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
95842 +get_packet_5747 get_packet 3 5747 NULL
95843 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
95844 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
95845 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
95846 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
95847 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
95848 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
95849 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
95850 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
95851 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
95852 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
95853 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
95854 +resource_from_user_30341 resource_from_user 3 30341 NULL
95855 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
95856 +sound_write_5102 sound_write 3 5102 NULL
95857 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
95858 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
95859 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
95860 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
95861 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
95862 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
95863 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
95864 +com90xx_found_13974 com90xx_found 3 13974 NULL
95865 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
95866 +qcam_read_13977 qcam_read 3 13977 NULL
95867 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
95868 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
95869 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
95870 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
95871 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
95872 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
95873 +generic_readlink_32654 generic_readlink 3 32654 NULL
95874 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
95875 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
95876 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
95877 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
95878 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
95879 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
95880 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
95881 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
95882 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
95883 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
95884 +concat_writev_21451 concat_writev 3 21451 NULL
95885 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
95886 +_queue_data_54983 _queue_data 4 54983 NULL
95887 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
95888 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
95889 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
95890 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
95891 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
95892 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
95893 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
95894 +setup_req_5848 setup_req 3 5848 NULL
95895 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
95896 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
95897 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
95898 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
95899 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
95900 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
95901 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
95902 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
95903 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
95904 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
95905 +cma_create_area_38642 cma_create_area 2 38642 NULL
95906 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
95907 +sriov_enable_59689 sriov_enable 2 59689 NULL
95908 +enable_write_30456 enable_write 3 30456 NULL
95909 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
95910 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
95911 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
95912 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
95913 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
95914 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
95915 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
95916 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
95917 +port_show_regs_5904 port_show_regs 3 5904 NULL
95918 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
95919 +ptp_read_63251 ptp_read 4 63251 NULL
95920 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
95921 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
95922 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
95923 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
95924 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
95925 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
95926 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
95927 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
95928 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
95929 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
95930 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
95931 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
95932 +read_dma_55086 read_dma 3 55086 NULL
95933 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
95934 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
95935 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
95936 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
95937 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
95938 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
95939 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
95940 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
95941 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
95942 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
95943 +em_canid_change_14150 em_canid_change 3 14150 NULL
95944 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
95945 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
95946 +fb_write_46924 fb_write 3 46924 NULL
95947 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
95948 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
95949 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
95950 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
95951 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
95952 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
95953 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
95954 +udf_readpages_38761 udf_readpages 4 38761 NULL
95955 +reada_add_block_54247 reada_add_block 2 54247 NULL
95956 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
95957 +proc_info_read_63344 proc_info_read 3 63344 NULL
95958 +pep_indicate_38611 pep_indicate 5 38611 NULL
95959 +set_le_30581 set_le 4 30581 NULL
95960 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
95961 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
95962 +alloc_private_22399 alloc_private 2 22399 NULL
95963 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
95964 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
95965 +zoran_write_22404 zoran_write 3 22404 NULL
95966 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
95967 +idmouse_read_63374 idmouse_read 3 63374 NULL
95968 +queue_reply_22416 queue_reply 3 22416 NULL
95969 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
95970 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
95971 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
95972 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
95973 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
95974 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
95975 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
95976 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
95977 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
95978 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
95979 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
95980 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
95981 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
95982 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
95983 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
95984 +sys_select_38827 sys_select 1 38827 NULL
95985 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
95986 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
95987 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
95988 +direct_entry_38836 direct_entry 3 38836 NULL
95989 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
95990 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
95991 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
95992 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
95993 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
95994 +write_head_30481 write_head 4 30481 NULL
95995 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
95996 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
95997 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
95998 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
95999 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
96000 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
96001 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
96002 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
96003 +agp_remap_30665 agp_remap 2 30665 NULL
96004 +interfaces_38859 interfaces 2 38859 NULL
96005 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
96006 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
96007 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
96008 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
96009 +qc_capture_19298 qc_capture 3 19298 NULL
96010 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
96011 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
96012 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
96013 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
96014 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
96015 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
96016 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
96017 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
96018 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
96019 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
96020 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
96021 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
96022 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
96023 +read_kcore_63488 read_kcore 3 63488 NULL
96024 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
96025 +__skb_cow_39254 __skb_cow 2 39254 NULL
96026 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
96027 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
96028 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
96029 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
96030 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
96031 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
96032 +mousedev_read_47123 mousedev_read 3 47123 NULL
96033 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
96034 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
96035 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
96036 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
96037 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
96038 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
96039 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
96040 +vme_user_read_55338 vme_user_read 3 55338 NULL
96041 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
96042 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
96043 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
96044 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
96045 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
96046 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
96047 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
96048 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
96049 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
96050 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
96051 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
96052 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
96053 +snapshot_read_22601 snapshot_read 3 22601 NULL
96054 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
96055 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
96056 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
96057 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
96058 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
96059 +__send_to_port_55383 __send_to_port 3 55383 NULL
96060 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
96061 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
96062 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
96063 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
96064 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
96065 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
96066 +get_nodes_39012 get_nodes 3 39012 NULL
96067 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
96068 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
96069 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
96070 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
96071 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
96072 +create_subvol_30836 create_subvol 4 30836 NULL
96073 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
96074 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
96075 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
96076 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
96077 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
96078 +read_oldmem_55658 read_oldmem 3 55658 NULL
96079 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
96080 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
96081 +options_write_47243 options_write 3 47243 NULL
96082 +module_alloc_63630 module_alloc 1 63630 NULL
96083 +alloc_skb_55439 alloc_skb 1 55439 NULL
96084 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
96085 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
96086 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
96087 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
96088 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
96089 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
96090 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
96091 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
96092 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
96093 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
96094 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
96095 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
96096 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
96097 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
96098 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
96099 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
96100 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
96101 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
96102 +vbi_read_63673 vbi_read 3 63673 NULL
96103 +tun_get_user_39099 tun_get_user 4 39099 NULL
96104 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
96105 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
96106 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
96107 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
96108 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
96109 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
96110 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
96111 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
96112 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
96113 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
96114 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
96115 +ax25_output_22736 ax25_output 2 22736 NULL
96116 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
96117 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
96118 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
96119 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
96120 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
96121 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
96122 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
96123 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
96124 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
96125 +hid_input_report_32458 hid_input_report 4 32458 NULL
96126 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
96127 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
96128 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
96129 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
96130 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
96131 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
96132 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
96133 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
96134 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
96135 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
96136 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
96137 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
96138 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
96139 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
96140 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
96141 +get_info_55681 get_info 3 55681 NULL
96142 +setkey_14987 setkey 3 14987 NULL
96143 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
96144 +init_list_set_39188 init_list_set 2-3 39188 NULL
96145 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
96146 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
96147 +l2up_create_6430 l2up_create 3 6430 NULL
96148 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
96149 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
96150 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
96151 +add_partition_55588 add_partition 2 55588 NULL
96152 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
96153 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
96154 +depth_read_31112 depth_read 3 31112 NULL
96155 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
96156 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
96157 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
96158 +profile_replace_14652 profile_replace 3 14652 NULL
96159 +vzalloc_47421 vzalloc 1 47421 NULL
96160 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
96161 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
96162 +sys_writev_28384 sys_writev 3 28384 NULL
96163 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
96164 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
96165 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
96166 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
96167 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
96168 +create_attr_set_22861 create_attr_set 1 22861 NULL
96169 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
96170 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
96171 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
96172 +sel_write_load_63830 sel_write_load 3 63830 NULL
96173 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
96174 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
96175 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
96176 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
96177 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
96178 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
96179 +probe_bios_17467 probe_bios 1 17467 NULL
96180 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
96181 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
96182 +mei_read_6507 mei_read 3 6507 NULL
96183 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
96184 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
96185 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
96186 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
96187 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
96188 +SetArea_50835 SetArea 4 50835 NULL
96189 +tpm_read_50344 tpm_read 3 50344 NULL
96190 +newpart_47485 newpart 6 47485 NULL
96191 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
96192 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
96193 +core_sys_select_47494 core_sys_select 1 47494 NULL
96194 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
96195 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
96196 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
96197 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
96198 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
96199 +unlink_simple_47506 unlink_simple 3 47506 NULL
96200 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
96201 +wdm_read_6549 wdm_read 3 6549 NULL
96202 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
96203 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
96204 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
96205 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
96206 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
96207 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
96208 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
96209 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
96210 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
96211 +filter_read_61692 filter_read 3 61692 NULL
96212 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
96213 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
96214 +debugfs_read_62535 debugfs_read 3 62535 NULL
96215 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
96216 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
96217 +divas_write_63901 divas_write 3 63901 NULL
96218 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
96219 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
96220 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
96221 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
96222 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
96223 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
96224 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
96225 +ipw_write_59807 ipw_write 3 59807 NULL
96226 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
96227 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
96228 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
96229 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
96230 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
96231 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
96232 +cycx_setup_47562 cycx_setup 4 47562 NULL
96233 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
96234 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
96235 +set_local_name_55757 set_local_name 4 55757 NULL
96236 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
96237 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
96238 +read_ldt_47570 read_ldt 2 47570 NULL
96239 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
96240 +pci_iomap_47575 pci_iomap 3 47575 NULL
96241 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
96242 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
96243 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
96244 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
96245 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
96246 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
96247 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
96248 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
96249 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
96250 +conf_read_55786 conf_read 3 55786 NULL
96251 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
96252 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
96253 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
96254 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
96255 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
96256 +user_power_read_39414 user_power_read 3 39414 NULL
96257 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
96258 +uea_request_47613 uea_request 4 47613 NULL
96259 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
96260 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
96261 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
96262 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
96263 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
96264 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
96265 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
96266 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
96267 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
96268 +kmemdup_64015 kmemdup 2 64015 NULL
96269 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
96270 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
96271 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
96272 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
96273 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
96274 +oz_events_read_47535 oz_events_read 3 47535 NULL
96275 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
96276 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
96277 +sys_semop_39457 sys_semop 3 39457 NULL
96278 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
96279 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
96280 +update_pmkid_2481 update_pmkid 4 2481 NULL
96281 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
96282 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
96283 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
96284 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
96285 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
96286 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
96287 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
96288 +mpeg_read_6708 mpeg_read 3 6708 NULL
96289 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
96290 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
96291 +sky2_receive_13407 sky2_receive 2 13407 NULL
96292 +krealloc_14908 krealloc 2 14908 NULL
96293 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
96294 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
96295 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
96296 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
96297 +video_proc_write_6724 video_proc_write 3 6724 NULL
96298 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
96299 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
96300 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
96301 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
96302 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
96303 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
96304 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
96305 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
96306 +command_file_write_31318 command_file_write 3 31318 NULL
96307 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
96308 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
96309 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
96310 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
96311 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
96312 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
96313 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
96314 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
96315 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
96316 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
96317 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
96318 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
96319 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
96320 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
96321 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
96322 +int_proc_write_39542 int_proc_write 3 39542 NULL
96323 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
96324 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
96325 +read_file_ani_23161 read_file_ani 3 23161 NULL
96326 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
96327 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
96328 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
96329 +pp_write_39554 pp_write 3 39554 NULL
96330 +ioremap_23172 ioremap 1-2 23172 NULL
96331 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
96332 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
96333 +usblp_write_23178 usblp_write 3 23178 NULL
96334 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
96335 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
96336 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
96337 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
96338 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
96339 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
96340 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
96341 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
96342 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
96343 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
96344 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
96345 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
96346 +__team_options_register_63941 __team_options_register 3 63941 NULL
96347 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
96348 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
96349 +rvmalloc_46873 rvmalloc 1 46873 NULL
96350 +vmap_15025 vmap 2 15025 NULL
96351 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
96352 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
96353 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
96354 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
96355 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
96356 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
96357 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
96358 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
96359 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
96360 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
96361 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
96362 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
96363 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
96364 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
96365 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
96366 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
96367 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
96368 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
96369 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
96370 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
96371 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
96372 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
96373 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
96374 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
96375 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
96376 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
96377 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
96378 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
96379 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
96380 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
96381 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
96382 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
96383 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
96384 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
96385 +alg_setkey_31485 alg_setkey 3 31485 NULL
96386 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
96387 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
96388 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
96389 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
96390 +vhci_read_47878 vhci_read 3 47878 NULL
96391 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
96392 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
96393 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
96394 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
96395 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
96396 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
96397 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
96398 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
96399 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
96400 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
96401 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
96402 +timeout_read_47915 timeout_read 3 47915 NULL
96403 +hidraw_write_31536 hidraw_write 3 31536 NULL
96404 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
96405 +page_readlink_23346 page_readlink 3 23346 NULL
96406 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
96407 +comedi_write_47926 comedi_write 3 47926 NULL
96408 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
96409 +dsp_write_46218 dsp_write 2 46218 NULL
96410 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
96411 +usbvision_read_31555 usbvision_read 3 31555 NULL
96412 +pd_video_read_24510 pd_video_read 3 24510 NULL
96413 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
96414 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
96415 +request_key_async_6990 request_key_async 4 6990 NULL
96416 +ts_write_64336 ts_write 3 64336 NULL
96417 +handle_response_55951 handle_response 5 55951 NULL
96418 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
96419 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
96420 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
96421 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
96422 +osst_write_31581 osst_write 3 31581 NULL
96423 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
96424 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
96425 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
96426 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
96427 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
96428 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
96429 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
96430 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
96431 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
96432 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
96433 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
96434 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
96435 +ilo_write_64378 ilo_write 3 64378 NULL
96436 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
96437 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
96438 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
96439 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
96440 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
96441 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
96442 +copy_from_user_17559 copy_from_user 3 17559 NULL
96443 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
96444 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
96445 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
96446 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
96447 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
96448 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
96449 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
96450 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
96451 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
96452 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
96453 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
96454 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
96455 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
96456 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
96457 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
96458 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
96459 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
96460 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
96461 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
96462 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
96463 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
96464 +__lgread_31668 __lgread 4 31668 NULL
96465 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
96466 +fd_copyin_56247 fd_copyin 3 56247 NULL
96467 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
96468 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
96469 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
96470 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
96471 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
96472 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
96473 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
96474 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
96475 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
96476 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
96477 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
96478 +event_filter_read_23494 event_filter_read 3 23494 NULL
96479 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
96480 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
96481 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
96482 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
96483 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
96484 +pkt_add_39897 pkt_add 3 39897 NULL
96485 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
96486 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
96487 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
96488 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
96489 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
96490 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
96491 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
96492 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
96493 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
96494 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
96495 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
96496 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
96497 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
96498 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
96499 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
96500 +remove_uuid_64505 remove_uuid 4 64505 NULL
96501 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
96502 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
96503 +create_table_16213 create_table 2 16213 NULL
96504 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
96505 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
96506 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
96507 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
96508 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
96509 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
96510 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
96511 +set_discoverable_48141 set_discoverable 4 48141 NULL
96512 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
96513 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
96514 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
96515 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
96516 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
96517 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
96518 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
96519 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
96520 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
96521 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
96522 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
96523 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
96524 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
96525 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
96526 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
96527 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
96528 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
96529 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
96530 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
96531 +dev_read_56369 dev_read 3 56369 NULL
96532 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
96533 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
96534 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
96535 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
96536 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
96537 +init_ipath_48187 init_ipath 1 48187 NULL
96538 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
96539 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
96540 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
96541 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
96542 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
96543 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
96544 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
96545 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
96546 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
96547 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
96548 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
96549 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
96550 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
96551 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
96552 +use_pool_64607 use_pool 2 64607 NULL
96553 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
96554 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
96555 +store_msg_56417 store_msg 3 56417 NULL
96556 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
96557 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
96558 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
96559 +read_file_recv_48232 read_file_recv 3 48232 NULL
96560 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
96561 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
96562 +fanotify_write_64623 fanotify_write 3 64623 NULL
96563 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
96564 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
96565 +fl_create_56435 fl_create 5 56435 NULL
96566 +gnttab_map_56439 gnttab_map 2 56439 NULL
96567 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
96568 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
96569 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
96570 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
96571 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
96572 +set_connectable_56458 set_connectable 4 56458 NULL
96573 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
96574 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
96575 +add_port_54941 add_port 2 54941 NULL
96576 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
96577 +cx18_read_23699 cx18_read 3 23699 NULL
96578 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
96579 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
96580 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
96581 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
96582 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
96583 +send_set_info_48288 send_set_info 7 48288 NULL
96584 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
96585 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
96586 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
96587 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
96588 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
96589 +new_dir_31919 new_dir 3 31919 NULL
96590 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
96591 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
96592 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
96593 +mgmt_control_7349 mgmt_control 3 7349 NULL
96594 +hash_setkey_48310 hash_setkey 3 48310 NULL
96595 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
96596 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
96597 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
96598 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
96599 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
96600 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
96601 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
96602 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
96603 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
96604 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
96605 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
96606 +vb2_write_31948 vb2_write 3 31948 NULL
96607 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
96608 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
96609 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
96610 +ip_options_get_56538 ip_options_get 4 56538 NULL
96611 +write_62671 write 3 62671 NULL
96612 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
96613 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
96614 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
96615 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
96616 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
96617 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
96618 +skb_add_data_48363 skb_add_data 3 48363 NULL
96619 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
96620 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
96621 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
96622 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
96623 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
96624 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
96625 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
96626 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
96627 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
96628 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
96629 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
96630 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
96631 +system_enable_read_25815 system_enable_read 3 25815 NULL
96632 +allocate_probes_40204 allocate_probes 1 40204 NULL
96633 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
96634 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
96635 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
96636 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
96637 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
96638 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
96639 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
96640 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
96641 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
96642 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
96643 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
96644 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
96645 +fs_path_add_15648 fs_path_add 3 15648 NULL
96646 +event_filter_write_56609 event_filter_write 3 56609 NULL
96647 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
96648 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
96649 +xsd_read_15653 xsd_read 3 15653 NULL
96650 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
96651 +p54_init_common_23850 p54_init_common 1 23850 NULL
96652 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
96653 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
96654 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
96655 +garp_request_join_7471 garp_request_join 4 7471 NULL
96656 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
96657 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
96658 +unifi_read_14899 unifi_read 3 14899 NULL
96659 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
96660 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
96661 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
96662 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
96663 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
96664 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
96665 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
96666 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
96667 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
96668 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
96669 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
96670 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
96671 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
96672 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
96673 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
96674 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
96675 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
96676 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
96677 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
96678 +bio_alloc_32095 bio_alloc 2 32095 NULL
96679 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
96680 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
96681 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
96682 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
96683 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
96684 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
96685 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
96686 +send_control_msg_48498 send_control_msg 6 48498 NULL
96687 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
96688 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
96689 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
96690 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
96691 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
96692 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
96693 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
96694 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
96695 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
96696 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
96697 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
96698 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
96699 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
96700 +alloc_tx_32143 alloc_tx 2 32143 NULL
96701 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
96702 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
96703 +hsc_write_55875 hsc_write 3 55875 NULL
96704 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
96705 +do_test_15766 do_test 1 15766 NULL
96706 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
96707 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
96708 +named_distribute_48544 named_distribute 4 48544 NULL
96709 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
96710 +venus_link_32165 venus_link 5 32165 NULL
96711 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
96712 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
96713 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
96714 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
96715 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
96716 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
96717 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
96718 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
96719 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
96720 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
96721 +groups_alloc_7614 groups_alloc 1 7614 NULL
96722 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
96723 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
96724 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
96725 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
96726 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
96727 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
96728 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
96729 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
96730 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
96731 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
96732 +snapshot_write_28351 snapshot_write 3 28351 NULL
96733 +event_enable_read_7074 event_enable_read 3 7074 NULL
96734 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
96735 +do_syslog_56807 do_syslog 3 56807 NULL
96736 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
96737 +pskb_pull_65005 pskb_pull 2 65005 NULL
96738 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
96739 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
96740 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
96741 +unifi_write_65012 unifi_write 3 65012 NULL
96742 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
96743 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
96744 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
96745 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
96746 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
96747 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
96748 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
96749 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
96750 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
96751 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
96752 +if_write_51756 if_write 3 51756 NULL
96753 +insert_dent_65034 insert_dent 7 65034 NULL
96754 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
96755 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
96756 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
96757 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
96758 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
96759 +lc_create_48662 lc_create 3 48662 NULL
96760 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
96761 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
96762 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
96763 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
96764 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
96765 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
96766 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
96767 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
96768 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
96769 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
96770 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
96771 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
96772 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
96773 +altera_drscan_48698 altera_drscan 2 48698 NULL
96774 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
96775 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
96776 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
96777 +power_read_15939 power_read 3 15939 NULL
96778 +recv_msg_48709 recv_msg 4 48709 NULL
96779 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
96780 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
96781 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
96782 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
96783 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
96784 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
96785 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
96786 +revalidate_19043 revalidate 2 19043 NULL
96787 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
96788 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
96789 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
96790 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
96791 +check_header_56930 check_header 2 56930 NULL
96792 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
96793 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
96794 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
96795 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
96796 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
96797 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
96798 +frame_alloc_15981 frame_alloc 4 15981 NULL
96799 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
96800 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
96801 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
96802 +adu_read_24177 adu_read 3 24177 NULL
96803 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
96804 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
96805 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
96806 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
96807 +vfd_write_14717 vfd_write 3 14717 NULL
96808 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
96809 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
96810 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
96811 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
96812 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
96813 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
96814 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
96815 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
96816 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
96817 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
96818 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
96819 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
96820 +register_device_60015 register_device 2-3 60015 NULL
96821 +got_frame_16028 got_frame 2 16028 NULL
96822 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
96823 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
96824 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
96825 +scsi_register_49094 scsi_register 2 49094 NULL
96826 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
96827 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
96828 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
96829 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
96830 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
96831 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
96832 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
96833 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
96834 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
96835 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
96836 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
96837 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
96838 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
96839 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
96840 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
96841 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
96842 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
96843 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
96844 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
96845 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
96846 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
96847 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
96848 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
96849 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
96850 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
96851 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
96852 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
96853 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
96854 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
96855 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
96856 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
96857 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
96858 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
96859 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
96860 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
96861 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
96862 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
96863 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
96864 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
96865 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
96866 +fsm_init_16134 fsm_init 2 16134 NULL
96867 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
96868 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
96869 +disconnect_32521 disconnect 4 32521 NULL
96870 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
96871 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
96872 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
96873 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
96874 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
96875 +ilo_read_32531 ilo_read 3 32531 NULL
96876 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
96877 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
96878 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
96879 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
96880 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
96881 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
96882 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
96883 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
96884 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
96885 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
96886 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
96887 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
96888 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
96889 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
96890 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
96891 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
96892 +card_send_command_40757 card_send_command 3 40757 NULL
96893 +sys_mbind_7990 sys_mbind 5 7990 NULL
96894 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
96895 +pg_write_40766 pg_write 3 40766 NULL
96896 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
96897 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
96898 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
96899 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
96900 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
96901 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
96902 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
96903 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
96904 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
96905 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
96906 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
96907 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
96908 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
96909 +vcs_read_8017 vcs_read 3 8017 NULL
96910 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
96911 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
96912 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
96913 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
96914 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
96915 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
96916 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
96917 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
96918 +copy_and_check_19089 copy_and_check 3 19089 NULL
96919 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
96920 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
96921 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
96922 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
96923 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
96924 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
96925 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
96926 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
96927 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
96928 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
96929 +smk_user_access_24440 smk_user_access 3 24440 NULL
96930 +xd_rw_49020 xd_rw 3-4 49020 NULL
96931 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
96932 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
96933 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
96934 +kvmalloc_32646 kvmalloc 1 32646 NULL
96935 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
96936 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
96937 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
96938 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
96939 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
96940 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
96941 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
96942 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
96943 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
96944 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
96945 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
96946 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
96947 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
96948 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
96949 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
96950 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
96951 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
96952 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
96953 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
96954 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
96955 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
96956 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
96957 +venus_lookup_8121 venus_lookup 4 8121 NULL
96958 +compat_writev_60063 compat_writev 3 60063 NULL
96959 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
96960 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
96961 +read_file_queue_40895 read_file_queue 3 40895 NULL
96962 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
96963 +waiters_read_40902 waiters_read 3 40902 NULL
96964 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
96965 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
96966 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
96967 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
96968 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
96969 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
96970 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
96971 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
96972 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
96973 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
96974 +alloc_dr_65495 alloc_dr 2 65495 NULL
96975 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
96976 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
96977 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
96978 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
96979 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
96980 +rbd_add_16366 rbd_add 3 16366 NULL
96981 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
96982 +pt_read_49136 pt_read 3 49136 NULL
96983 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
96984 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
96985 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
96986 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
96987 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
96988 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
96989 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
96990 new file mode 100644
96991 index 0000000..838ea58
96992 --- /dev/null
96993 +++ b/tools/gcc/size_overflow_plugin.c
96994 @@ -0,0 +1,1936 @@
96995 +/*
96996 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
96997 + * Licensed under the GPL v2, or (at your option) v3
96998 + *
96999 + * Homepage:
97000 + * http://www.grsecurity.net/~ephox/overflow_plugin/
97001 + *
97002 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
97003 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
97004 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
97005 + *
97006 + * Usage:
97007 + * $ 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
97008 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
97009 + */
97010 +
97011 +#include "gcc-plugin.h"
97012 +#include "config.h"
97013 +#include "system.h"
97014 +#include "coretypes.h"
97015 +#include "tree.h"
97016 +#include "tree-pass.h"
97017 +#include "intl.h"
97018 +#include "plugin-version.h"
97019 +#include "tm.h"
97020 +#include "toplev.h"
97021 +#include "function.h"
97022 +#include "tree-flow.h"
97023 +#include "plugin.h"
97024 +#include "gimple.h"
97025 +#include "diagnostic.h"
97026 +#include "cfgloop.h"
97027 +
97028 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2(EXP)
97029 +
97030 +#if BUILDING_GCC_VERSION >= 4008
97031 +#define TODO_dump_func 0
97032 +#endif
97033 +
97034 +struct size_overflow_hash {
97035 + const struct size_overflow_hash * const next;
97036 + const char * const name;
97037 + const unsigned int param;
97038 +};
97039 +
97040 +#include "size_overflow_hash.h"
97041 +
97042 +enum marked {
97043 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
97044 +};
97045 +
97046 +static unsigned int call_count = 0;
97047 +
97048 +#define __unused __attribute__((__unused__))
97049 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
97050 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
97051 +#define BEFORE_STMT true
97052 +#define AFTER_STMT false
97053 +#define CREATE_NEW_VAR NULL_TREE
97054 +#define CODES_LIMIT 32
97055 +#define MAX_PARAM 32
97056 +#define MY_STMT GF_PLF_1
97057 +#define NO_CAST_CHECK GF_PLF_2
97058 +
97059 +#if BUILDING_GCC_VERSION == 4005
97060 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
97061 +#endif
97062 +
97063 +int plugin_is_GPL_compatible;
97064 +void debug_gimple_stmt(gimple gs);
97065 +
97066 +static tree expand(struct pointer_set_t *visited, tree lhs);
97067 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
97068 +static tree report_size_overflow_decl;
97069 +static const_tree const_char_ptr_type_node;
97070 +static unsigned int handle_function(void);
97071 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
97072 +static tree get_size_overflow_type(gimple stmt, const_tree node);
97073 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
97074 +
97075 +static struct plugin_info size_overflow_plugin_info = {
97076 + .version = "20130109beta",
97077 + .help = "no-size-overflow\tturn off size overflow checking\n",
97078 +};
97079 +
97080 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
97081 +{
97082 + unsigned int arg_count;
97083 + enum tree_code code = TREE_CODE(*node);
97084 +
97085 + switch (code) {
97086 + case FUNCTION_DECL:
97087 + arg_count = type_num_arguments(TREE_TYPE(*node));
97088 + break;
97089 + case FUNCTION_TYPE:
97090 + case METHOD_TYPE:
97091 + arg_count = type_num_arguments(*node);
97092 + break;
97093 + default:
97094 + *no_add_attrs = true;
97095 + error("%s: %qE attribute only applies to functions", __func__, name);
97096 + return NULL_TREE;
97097 + }
97098 +
97099 + for (; args; args = TREE_CHAIN(args)) {
97100 + tree position = TREE_VALUE(args);
97101 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
97102 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
97103 + *no_add_attrs = true;
97104 + }
97105 + }
97106 + return NULL_TREE;
97107 +}
97108 +
97109 +static const char* get_asm_name(tree node)
97110 +{
97111 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
97112 +}
97113 +
97114 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
97115 +{
97116 + unsigned int arg_count, arg_num;
97117 + enum tree_code code = TREE_CODE(*node);
97118 +
97119 + switch (code) {
97120 + case FUNCTION_DECL:
97121 + arg_count = type_num_arguments(TREE_TYPE(*node));
97122 + break;
97123 + case FUNCTION_TYPE:
97124 + case METHOD_TYPE:
97125 + arg_count = type_num_arguments(*node);
97126 + break;
97127 + case FIELD_DECL:
97128 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
97129 + if (arg_num != 0) {
97130 + *no_add_attrs = true;
97131 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
97132 + }
97133 + return NULL_TREE;
97134 + default:
97135 + *no_add_attrs = true;
97136 + error("%qE attribute only applies to functions", name);
97137 + return NULL_TREE;
97138 + }
97139 +
97140 + for (; args; args = TREE_CHAIN(args)) {
97141 + tree position = TREE_VALUE(args);
97142 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
97143 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
97144 + *no_add_attrs = true;
97145 + }
97146 + }
97147 + return NULL_TREE;
97148 +}
97149 +
97150 +static struct attribute_spec size_overflow_attr = {
97151 + .name = "size_overflow",
97152 + .min_length = 1,
97153 + .max_length = -1,
97154 + .decl_required = true,
97155 + .type_required = false,
97156 + .function_type_required = false,
97157 + .handler = handle_size_overflow_attribute,
97158 +#if BUILDING_GCC_VERSION >= 4007
97159 + .affects_type_identity = false
97160 +#endif
97161 +};
97162 +
97163 +static struct attribute_spec intentional_overflow_attr = {
97164 + .name = "intentional_overflow",
97165 + .min_length = 1,
97166 + .max_length = -1,
97167 + .decl_required = true,
97168 + .type_required = false,
97169 + .function_type_required = false,
97170 + .handler = handle_intentional_overflow_attribute,
97171 +#if BUILDING_GCC_VERSION >= 4007
97172 + .affects_type_identity = false
97173 +#endif
97174 +};
97175 +
97176 +static void register_attributes(void __unused *event_data, void __unused *data)
97177 +{
97178 + register_attribute(&size_overflow_attr);
97179 + register_attribute(&intentional_overflow_attr);
97180 +}
97181 +
97182 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
97183 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
97184 +{
97185 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
97186 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
97187 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
97188 +
97189 + unsigned int m = 0x57559429;
97190 + unsigned int n = 0x5052acdb;
97191 + const unsigned int *key4 = (const unsigned int *)key;
97192 + unsigned int h = len;
97193 + unsigned int k = len + seed + n;
97194 + unsigned long long p;
97195 +
97196 + while (len >= 8) {
97197 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
97198 + len -= 8;
97199 + }
97200 + if (len >= 4) {
97201 + cwmixb(key4[0]) key4 += 1;
97202 + len -= 4;
97203 + }
97204 + if (len)
97205 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
97206 + cwmixb(h ^ (k + n));
97207 + return k ^ h;
97208 +
97209 +#undef cwfold
97210 +#undef cwmixa
97211 +#undef cwmixb
97212 +}
97213 +
97214 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
97215 +{
97216 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
97217 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
97218 + return fn ^ codes;
97219 +}
97220 +
97221 +static inline tree get_original_function_decl(tree fndecl)
97222 +{
97223 + if (DECL_ABSTRACT_ORIGIN(fndecl))
97224 + return DECL_ABSTRACT_ORIGIN(fndecl);
97225 + return fndecl;
97226 +}
97227 +
97228 +static inline gimple get_def_stmt(const_tree node)
97229 +{
97230 + gcc_assert(node != NULL_TREE);
97231 + gcc_assert(TREE_CODE(node) == SSA_NAME);
97232 + return SSA_NAME_DEF_STMT(node);
97233 +}
97234 +
97235 +static unsigned char get_tree_code(const_tree type)
97236 +{
97237 + switch (TREE_CODE(type)) {
97238 + case ARRAY_TYPE:
97239 + return 0;
97240 + case BOOLEAN_TYPE:
97241 + return 1;
97242 + case ENUMERAL_TYPE:
97243 + return 2;
97244 + case FUNCTION_TYPE:
97245 + return 3;
97246 + case INTEGER_TYPE:
97247 + return 4;
97248 + case POINTER_TYPE:
97249 + return 5;
97250 + case RECORD_TYPE:
97251 + return 6;
97252 + case UNION_TYPE:
97253 + return 7;
97254 + case VOID_TYPE:
97255 + return 8;
97256 + case REAL_TYPE:
97257 + return 9;
97258 + case VECTOR_TYPE:
97259 + return 10;
97260 + case REFERENCE_TYPE:
97261 + return 11;
97262 + case OFFSET_TYPE:
97263 + return 12;
97264 + case COMPLEX_TYPE:
97265 + return 13;
97266 + default:
97267 + debug_tree((tree)type);
97268 + gcc_unreachable();
97269 + }
97270 +}
97271 +
97272 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
97273 +{
97274 + gcc_assert(type != NULL_TREE);
97275 +
97276 + while (type && len < CODES_LIMIT) {
97277 + tree_codes[len] = get_tree_code(type);
97278 + len++;
97279 + type = TREE_TYPE(type);
97280 + }
97281 + return len;
97282 +}
97283 +
97284 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
97285 +{
97286 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
97287 + enum tree_code code = TREE_CODE(type);
97288 + size_t len = 0;
97289 +
97290 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
97291 +
97292 + arg = TYPE_ARG_TYPES(type);
97293 + // skip builtins __builtin_constant_p
97294 + if (!arg && DECL_BUILT_IN(fndecl))
97295 + return 0;
97296 +
97297 + if (TREE_CODE_CLASS(code) == tcc_type)
97298 + result = type;
97299 + else
97300 + result = DECL_RESULT(fndecl);
97301 +
97302 + gcc_assert(result != NULL_TREE);
97303 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
97304 +
97305 + if (arg == NULL_TREE) {
97306 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
97307 + arg_field = DECL_ARGUMENT_FLD(fndecl);
97308 + if (arg_field == NULL_TREE)
97309 + return 0;
97310 + arg = TREE_TYPE(arg_field);
97311 + len = add_type_codes(arg, tree_codes, len);
97312 + gcc_assert(len != 0);
97313 + return len;
97314 + }
97315 +
97316 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
97317 + while (arg && len < CODES_LIMIT) {
97318 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
97319 + arg = TREE_CHAIN(arg);
97320 + }
97321 +
97322 + gcc_assert(len != 0);
97323 + return len;
97324 +}
97325 +
97326 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
97327 +{
97328 + unsigned int hash;
97329 + const struct size_overflow_hash *entry;
97330 + unsigned char tree_codes[CODES_LIMIT];
97331 + size_t len;
97332 + const char *func_name = get_asm_name(fndecl);
97333 +
97334 + len = get_function_decl(fndecl, tree_codes);
97335 + if (len == 0)
97336 + return NULL;
97337 +
97338 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
97339 +
97340 + entry = size_overflow_hash[hash];
97341 + while (entry) {
97342 + if (!strcmp(entry->name, func_name))
97343 + return entry;
97344 + entry = entry->next;
97345 + }
97346 +
97347 + return NULL;
97348 +}
97349 +
97350 +static void check_arg_type(const_tree arg)
97351 +{
97352 + const_tree type = TREE_TYPE(arg);
97353 + enum tree_code code = TREE_CODE(type);
97354 +
97355 + if (code == BOOLEAN_TYPE)
97356 + return;
97357 +
97358 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
97359 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
97360 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
97361 +}
97362 +
97363 +static unsigned int find_arg_number(const_tree arg, tree func)
97364 +{
97365 + tree var;
97366 + unsigned int argnum = 1;
97367 +
97368 + if (TREE_CODE(arg) == SSA_NAME)
97369 + arg = SSA_NAME_VAR(arg);
97370 +
97371 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
97372 + if (strcmp(NAME(arg), NAME(var))) {
97373 + argnum++;
97374 + continue;
97375 + }
97376 + check_arg_type(var);
97377 + return argnum;
97378 + }
97379 + gcc_unreachable();
97380 +}
97381 +
97382 +static tree create_new_var(tree type)
97383 +{
97384 + tree new_var = create_tmp_var(type, "cicus");
97385 +
97386 +#if BUILDING_GCC_VERSION <= 4007
97387 + add_referenced_var(new_var);
97388 + mark_sym_for_renaming(new_var);
97389 +#endif
97390 + return new_var;
97391 +}
97392 +
97393 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
97394 +{
97395 + gimple assign;
97396 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
97397 + tree type = TREE_TYPE(rhs1);
97398 + tree lhs = create_new_var(type);
97399 +
97400 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
97401 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
97402 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
97403 +
97404 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
97405 + update_stmt(assign);
97406 + gimple_set_plf(assign, MY_STMT, true);
97407 + return assign;
97408 +}
97409 +
97410 +static bool is_bool(const_tree node)
97411 +{
97412 + const_tree type;
97413 +
97414 + if (node == NULL_TREE)
97415 + return false;
97416 +
97417 + type = TREE_TYPE(node);
97418 + if (!INTEGRAL_TYPE_P(type))
97419 + return false;
97420 + if (TREE_CODE(type) == BOOLEAN_TYPE)
97421 + return true;
97422 + if (TYPE_PRECISION(type) == 1)
97423 + return true;
97424 + return false;
97425 +}
97426 +
97427 +static tree cast_a_tree(tree type, tree var)
97428 +{
97429 + gcc_assert(type != NULL_TREE);
97430 + gcc_assert(var != NULL_TREE);
97431 + gcc_assert(fold_convertible_p(type, var));
97432 +
97433 + return fold_convert(type, var);
97434 +}
97435 +
97436 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
97437 +{
97438 + gimple assign;
97439 +
97440 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
97441 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
97442 + gcc_unreachable();
97443 +
97444 + if (lhs == CREATE_NEW_VAR)
97445 + lhs = create_new_var(dst_type);
97446 +
97447 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
97448 +
97449 + if (!gsi_end_p(*gsi)) {
97450 + location_t loc = gimple_location(gsi_stmt(*gsi));
97451 + gimple_set_location(assign, loc);
97452 + }
97453 +
97454 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
97455 +
97456 + if (before)
97457 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
97458 + else
97459 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
97460 + update_stmt(assign);
97461 + gimple_set_plf(assign, MY_STMT, true);
97462 +
97463 + return assign;
97464 +}
97465 +
97466 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
97467 +{
97468 + gimple assign;
97469 + gimple_stmt_iterator gsi;
97470 +
97471 + if (rhs == NULL_TREE)
97472 + return NULL_TREE;
97473 +
97474 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
97475 + return rhs;
97476 +
97477 + gsi = gsi_for_stmt(stmt);
97478 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
97479 + gimple_set_plf(assign, MY_STMT, true);
97480 + return gimple_get_lhs(assign);
97481 +}
97482 +
97483 +static tree cast_to_TI_type(gimple stmt, tree node)
97484 +{
97485 + gimple_stmt_iterator gsi;
97486 + gimple cast_stmt;
97487 + tree type = TREE_TYPE(node);
97488 +
97489 + if (types_compatible_p(type, intTI_type_node))
97490 + return node;
97491 +
97492 + gsi = gsi_for_stmt(stmt);
97493 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
97494 + gimple_set_plf(cast_stmt, MY_STMT, true);
97495 + return gimple_get_lhs(cast_stmt);
97496 +}
97497 +
97498 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
97499 +{
97500 + tree lhs;
97501 + gimple_stmt_iterator gsi;
97502 +
97503 + if (rhs1 == NULL_TREE) {
97504 + debug_gimple_stmt(oldstmt);
97505 + error("%s: rhs1 is NULL_TREE", __func__);
97506 + gcc_unreachable();
97507 + }
97508 +
97509 + switch (gimple_code(oldstmt)) {
97510 + case GIMPLE_ASM:
97511 + lhs = rhs1;
97512 + break;
97513 + case GIMPLE_CALL:
97514 + lhs = gimple_call_lhs(oldstmt);
97515 + break;
97516 + case GIMPLE_ASSIGN:
97517 + lhs = gimple_get_lhs(oldstmt);
97518 + break;
97519 + default:
97520 + debug_gimple_stmt(oldstmt);
97521 + gcc_unreachable();
97522 + }
97523 +
97524 + gsi = gsi_for_stmt(oldstmt);
97525 + pointer_set_insert(visited, oldstmt);
97526 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
97527 + basic_block next_bb, cur_bb;
97528 + const_edge e;
97529 +
97530 + gcc_assert(before == false);
97531 + gcc_assert(stmt_can_throw_internal(oldstmt));
97532 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
97533 + gcc_assert(!gsi_end_p(gsi));
97534 +
97535 + cur_bb = gimple_bb(oldstmt);
97536 + next_bb = cur_bb->next_bb;
97537 + e = find_edge(cur_bb, next_bb);
97538 + gcc_assert(e != NULL);
97539 + gcc_assert(e->flags & EDGE_FALLTHRU);
97540 +
97541 + gsi = gsi_after_labels(next_bb);
97542 + gcc_assert(!gsi_end_p(gsi));
97543 +
97544 + before = true;
97545 + oldstmt = gsi_stmt(gsi);
97546 + }
97547 +
97548 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
97549 +}
97550 +
97551 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
97552 +{
97553 + gimple stmt;
97554 + gimple_stmt_iterator gsi;
97555 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
97556 +
97557 + if (gimple_plf(oldstmt, MY_STMT))
97558 + return lhs;
97559 +
97560 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
97561 + rhs1 = gimple_assign_rhs1(oldstmt);
97562 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
97563 + }
97564 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
97565 + rhs2 = gimple_assign_rhs2(oldstmt);
97566 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
97567 + }
97568 +
97569 + stmt = gimple_copy(oldstmt);
97570 + gimple_set_location(stmt, gimple_location(oldstmt));
97571 + gimple_set_plf(stmt, MY_STMT, true);
97572 +
97573 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
97574 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
97575 +
97576 + size_overflow_type = get_size_overflow_type(oldstmt, node);
97577 +
97578 + if (is_bool(lhs))
97579 + new_var = SSA_NAME_VAR(lhs);
97580 + else
97581 + new_var = create_new_var(size_overflow_type);
97582 + new_var = make_ssa_name(new_var, stmt);
97583 + gimple_set_lhs(stmt, new_var);
97584 +
97585 + if (rhs1 != NULL_TREE)
97586 + gimple_assign_set_rhs1(stmt, rhs1);
97587 +
97588 + if (rhs2 != NULL_TREE)
97589 + gimple_assign_set_rhs2(stmt, rhs2);
97590 +#if BUILDING_GCC_VERSION >= 4007
97591 + if (rhs3 != NULL_TREE)
97592 + gimple_assign_set_rhs3(stmt, rhs3);
97593 +#endif
97594 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
97595 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
97596 +
97597 + gsi = gsi_for_stmt(oldstmt);
97598 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
97599 + update_stmt(stmt);
97600 + pointer_set_insert(visited, oldstmt);
97601 + return gimple_get_lhs(stmt);
97602 +}
97603 +
97604 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
97605 +{
97606 + basic_block bb;
97607 + gimple phi;
97608 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
97609 + gimple_seq seq;
97610 +
97611 + bb = gsi_bb(gsi);
97612 +
97613 + phi = create_phi_node(result, bb);
97614 + seq = phi_nodes(bb);
97615 + gsi = gsi_last(seq);
97616 + gsi_remove(&gsi, false);
97617 +
97618 + gsi = gsi_for_stmt(oldstmt);
97619 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
97620 + gimple_set_bb(phi, bb);
97621 + gimple_set_plf(phi, MY_STMT, true);
97622 + return phi;
97623 +}
97624 +
97625 +static basic_block create_a_first_bb(void)
97626 +{
97627 + basic_block first_bb;
97628 +
97629 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
97630 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
97631 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
97632 + return first_bb;
97633 +}
97634 +
97635 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
97636 +{
97637 + basic_block bb;
97638 + const_gimple newstmt;
97639 + gimple_stmt_iterator gsi;
97640 + bool before = BEFORE_STMT;
97641 +
97642 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
97643 + gsi = gsi_for_stmt(get_def_stmt(arg));
97644 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
97645 + return gimple_get_lhs(newstmt);
97646 + }
97647 +
97648 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
97649 + gsi = gsi_after_labels(bb);
97650 + if (bb->index == 0) {
97651 + bb = create_a_first_bb();
97652 + gsi = gsi_start_bb(bb);
97653 + }
97654 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
97655 + return gimple_get_lhs(newstmt);
97656 +}
97657 +
97658 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
97659 +{
97660 + gimple newstmt;
97661 + gimple_stmt_iterator gsi;
97662 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
97663 + gimple def_newstmt = get_def_stmt(new_rhs);
97664 +
97665 + gsi_insert = gsi_insert_after;
97666 + gsi = gsi_for_stmt(def_newstmt);
97667 +
97668 + switch (gimple_code(get_def_stmt(arg))) {
97669 + case GIMPLE_PHI:
97670 + newstmt = gimple_build_assign(new_var, new_rhs);
97671 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
97672 + gsi_insert = gsi_insert_before;
97673 + break;
97674 + case GIMPLE_ASM:
97675 + case GIMPLE_CALL:
97676 + newstmt = gimple_build_assign(new_var, new_rhs);
97677 + break;
97678 + case GIMPLE_ASSIGN:
97679 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
97680 + break;
97681 + default:
97682 + /* unknown gimple_code (handle_build_new_phi_arg) */
97683 + gcc_unreachable();
97684 + }
97685 +
97686 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
97687 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
97688 + gimple_set_plf(newstmt, MY_STMT, true);
97689 + update_stmt(newstmt);
97690 + return newstmt;
97691 +}
97692 +
97693 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
97694 +{
97695 + const_gimple newstmt;
97696 + gimple def_stmt;
97697 + tree new_rhs;
97698 +
97699 + new_rhs = expand(visited, arg);
97700 + if (new_rhs == NULL_TREE)
97701 + return NULL_TREE;
97702 +
97703 + def_stmt = get_def_stmt(new_rhs);
97704 + if (gimple_code(def_stmt) == GIMPLE_NOP)
97705 + return NULL_TREE;
97706 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
97707 +
97708 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
97709 + return gimple_get_lhs(newstmt);
97710 +}
97711 +
97712 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
97713 +{
97714 + gimple phi, oldstmt = get_def_stmt(orig_result);
97715 + tree new_result, size_overflow_type;
97716 + unsigned int i;
97717 + unsigned int n = gimple_phi_num_args(oldstmt);
97718 +
97719 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
97720 +
97721 + new_result = create_new_var(size_overflow_type);
97722 +
97723 + pointer_set_insert(visited, oldstmt);
97724 + phi = overflow_create_phi_node(oldstmt, new_result);
97725 + for (i = 0; i < n; i++) {
97726 + tree arg, lhs;
97727 +
97728 + arg = gimple_phi_arg_def(oldstmt, i);
97729 + if (is_gimple_constant(arg))
97730 + arg = cast_a_tree(size_overflow_type, arg);
97731 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
97732 + if (lhs == NULL_TREE)
97733 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
97734 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
97735 + }
97736 +
97737 + update_stmt(phi);
97738 + return gimple_phi_result(phi);
97739 +}
97740 +
97741 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
97742 +{
97743 + const_gimple assign;
97744 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
97745 + tree origtype = TREE_TYPE(orig_rhs);
97746 +
97747 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
97748 +
97749 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
97750 + return gimple_get_lhs(assign);
97751 +}
97752 +
97753 +static void change_rhs1(gimple stmt, tree new_rhs1)
97754 +{
97755 + tree assign_rhs;
97756 + const_tree rhs = gimple_assign_rhs1(stmt);
97757 +
97758 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
97759 + gimple_assign_set_rhs1(stmt, assign_rhs);
97760 + update_stmt(stmt);
97761 +}
97762 +
97763 +static bool check_mode_type(const_gimple stmt)
97764 +{
97765 + const_tree lhs = gimple_get_lhs(stmt);
97766 + const_tree lhs_type = TREE_TYPE(lhs);
97767 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
97768 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
97769 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
97770 +
97771 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
97772 + return false;
97773 +
97774 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
97775 + return false;
97776 +
97777 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
97778 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
97779 + return false;
97780 +
97781 + return true;
97782 +}
97783 +
97784 +static bool check_undefined_integer_operation(const_gimple stmt)
97785 +{
97786 + const_gimple def_stmt;
97787 + const_tree lhs = gimple_get_lhs(stmt);
97788 + const_tree rhs1 = gimple_assign_rhs1(stmt);
97789 + const_tree rhs1_type = TREE_TYPE(rhs1);
97790 + const_tree lhs_type = TREE_TYPE(lhs);
97791 +
97792 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
97793 + return false;
97794 +
97795 + def_stmt = get_def_stmt(rhs1);
97796 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
97797 + return false;
97798 +
97799 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
97800 + return false;
97801 + return true;
97802 +}
97803 +
97804 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
97805 +{
97806 + const_tree rhs1, lhs, rhs1_type, lhs_type;
97807 + enum machine_mode lhs_mode, rhs_mode;
97808 + gimple def_stmt = get_def_stmt(no_const_rhs);
97809 +
97810 + if (!gimple_assign_cast_p(def_stmt))
97811 + return false;
97812 +
97813 + rhs1 = gimple_assign_rhs1(def_stmt);
97814 + lhs = gimple_get_lhs(def_stmt);
97815 + rhs1_type = TREE_TYPE(rhs1);
97816 + lhs_type = TREE_TYPE(lhs);
97817 + rhs_mode = TYPE_MODE(rhs1_type);
97818 + lhs_mode = TYPE_MODE(lhs_type);
97819 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
97820 + return false;
97821 +
97822 + return true;
97823 +}
97824 +
97825 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
97826 +{
97827 + tree rhs1 = gimple_assign_rhs1(stmt);
97828 + tree lhs = gimple_get_lhs(stmt);
97829 + const_tree rhs1_type = TREE_TYPE(rhs1);
97830 + const_tree lhs_type = TREE_TYPE(lhs);
97831 +
97832 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
97833 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97834 +
97835 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
97836 +}
97837 +
97838 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
97839 +{
97840 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
97841 + tree new_rhs1 = NULL_TREE;
97842 + tree rhs1 = gimple_assign_rhs1(stmt);
97843 + const_tree rhs1_type = TREE_TYPE(rhs1);
97844 + const_tree lhs_type = TREE_TYPE(lhs);
97845 +
97846 + if (gimple_plf(stmt, MY_STMT))
97847 + return lhs;
97848 +
97849 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
97850 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97851 +
97852 + new_rhs1 = expand(visited, rhs1);
97853 +
97854 + if (new_rhs1 == NULL_TREE)
97855 + return create_cast_assign(visited, stmt);
97856 +
97857 + if (gimple_plf(stmt, NO_CAST_CHECK))
97858 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
97859 +
97860 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
97861 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
97862 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
97863 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
97864 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97865 + }
97866 +
97867 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
97868 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
97869 +
97870 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
97871 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
97872 +
97873 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
97874 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
97875 +
97876 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
97877 +
97878 + change_rhs1(stmt, new_rhs1);
97879 +
97880 + if (!check_mode_type(stmt))
97881 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97882 +
97883 + size_overflow_type = get_size_overflow_type(stmt, lhs);
97884 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
97885 +
97886 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
97887 +
97888 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97889 +}
97890 +
97891 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
97892 +{
97893 + tree rhs1, lhs = gimple_get_lhs(stmt);
97894 + gimple def_stmt = get_def_stmt(lhs);
97895 +
97896 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
97897 + rhs1 = gimple_assign_rhs1(def_stmt);
97898 +
97899 + if (is_gimple_constant(rhs1))
97900 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
97901 +
97902 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
97903 + switch (TREE_CODE(rhs1)) {
97904 + case SSA_NAME:
97905 + return handle_unary_rhs(visited, def_stmt);
97906 + case ARRAY_REF:
97907 + case BIT_FIELD_REF:
97908 + case ADDR_EXPR:
97909 + case COMPONENT_REF:
97910 + case INDIRECT_REF:
97911 +#if BUILDING_GCC_VERSION >= 4006
97912 + case MEM_REF:
97913 +#endif
97914 + case TARGET_MEM_REF:
97915 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
97916 + case PARM_DECL:
97917 + case VAR_DECL:
97918 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97919 +
97920 + default:
97921 + debug_gimple_stmt(def_stmt);
97922 + debug_tree(rhs1);
97923 + gcc_unreachable();
97924 + }
97925 +}
97926 +
97927 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
97928 +{
97929 + gimple cond_stmt;
97930 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
97931 +
97932 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
97933 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
97934 + update_stmt(cond_stmt);
97935 +}
97936 +
97937 +static tree create_string_param(tree string)
97938 +{
97939 + tree i_type, a_type;
97940 + const int length = TREE_STRING_LENGTH(string);
97941 +
97942 + gcc_assert(length > 0);
97943 +
97944 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
97945 + a_type = build_array_type(char_type_node, i_type);
97946 +
97947 + TREE_TYPE(string) = a_type;
97948 + TREE_CONSTANT(string) = 1;
97949 + TREE_READONLY(string) = 1;
97950 +
97951 + return build1(ADDR_EXPR, ptr_type_node, string);
97952 +}
97953 +
97954 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
97955 +{
97956 + gimple func_stmt;
97957 + const_gimple def_stmt;
97958 + const_tree loc_line;
97959 + tree loc_file, ssa_name, current_func;
97960 + expanded_location xloc;
97961 + char *ssa_name_buf;
97962 + int len;
97963 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
97964 +
97965 + def_stmt = get_def_stmt(arg);
97966 + xloc = expand_location(gimple_location(def_stmt));
97967 +
97968 + if (!gimple_has_location(def_stmt)) {
97969 + xloc = expand_location(gimple_location(stmt));
97970 + if (!gimple_has_location(stmt))
97971 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
97972 + }
97973 +
97974 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
97975 +
97976 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
97977 + loc_file = create_string_param(loc_file);
97978 +
97979 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
97980 + current_func = create_string_param(current_func);
97981 +
97982 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
97983 + call_count++;
97984 + 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);
97985 + gcc_assert(len > 0);
97986 + ssa_name = build_string(len + 1, ssa_name_buf);
97987 + free(ssa_name_buf);
97988 + ssa_name = create_string_param(ssa_name);
97989 +
97990 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
97991 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
97992 +
97993 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
97994 +}
97995 +
97996 +static void __unused print_the_code_insertions(const_gimple stmt)
97997 +{
97998 + location_t loc = gimple_location(stmt);
97999 +
98000 + inform(loc, "Integer size_overflow check applied here.");
98001 +}
98002 +
98003 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
98004 +{
98005 + basic_block cond_bb, join_bb, bb_true;
98006 + edge e;
98007 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
98008 +
98009 + cond_bb = gimple_bb(stmt);
98010 + if (before)
98011 + gsi_prev(&gsi);
98012 + if (gsi_end_p(gsi))
98013 + e = split_block_after_labels(cond_bb);
98014 + else
98015 + e = split_block(cond_bb, gsi_stmt(gsi));
98016 + cond_bb = e->src;
98017 + join_bb = e->dest;
98018 + e->flags = EDGE_FALSE_VALUE;
98019 + e->probability = REG_BR_PROB_BASE;
98020 +
98021 + bb_true = create_empty_bb(cond_bb);
98022 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
98023 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
98024 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
98025 +
98026 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
98027 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
98028 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
98029 +
98030 + if (current_loops != NULL) {
98031 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
98032 + add_bb_to_loop(bb_true, cond_bb->loop_father);
98033 + }
98034 +
98035 + insert_cond(cond_bb, arg, cond_code, type_value);
98036 + insert_cond_result(bb_true, stmt, arg, min);
98037 +
98038 +// print_the_code_insertions(stmt);
98039 +}
98040 +
98041 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
98042 +{
98043 + const_tree rhs_type = TREE_TYPE(rhs);
98044 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
98045 +
98046 + gcc_assert(rhs_type != NULL_TREE);
98047 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
98048 + return;
98049 +
98050 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
98051 +
98052 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
98053 + // typemax (-1) < typemin (0)
98054 + if (TREE_OVERFLOW(type_max))
98055 + return;
98056 +
98057 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
98058 +
98059 + cast_rhs_type = TREE_TYPE(cast_rhs);
98060 + type_max_type = TREE_TYPE(type_max);
98061 + type_min_type = TREE_TYPE(type_min);
98062 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
98063 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
98064 +
98065 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
98066 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
98067 +}
98068 +
98069 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
98070 +{
98071 + gimple change_rhs_def_stmt;
98072 + tree lhs = gimple_get_lhs(def_stmt);
98073 + tree lhs_type = TREE_TYPE(lhs);
98074 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
98075 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
98076 +
98077 + if (change_rhs == NULL_TREE)
98078 + return get_size_overflow_type(def_stmt, lhs);
98079 +
98080 + change_rhs_def_stmt = get_def_stmt(change_rhs);
98081 +
98082 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
98083 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
98084 +
98085 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
98086 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
98087 +
98088 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
98089 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
98090 +
98091 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
98092 + debug_gimple_stmt(def_stmt);
98093 + gcc_unreachable();
98094 + }
98095 +
98096 + return get_size_overflow_type(def_stmt, lhs);
98097 +}
98098 +
98099 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
98100 +{
98101 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
98102 + return false;
98103 + if (!is_gimple_constant(rhs))
98104 + return false;
98105 + return true;
98106 +}
98107 +
98108 +static bool is_subtraction_special(const_gimple stmt)
98109 +{
98110 + gimple rhs1_def_stmt, rhs2_def_stmt;
98111 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
98112 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
98113 + const_tree rhs1 = gimple_assign_rhs1(stmt);
98114 + const_tree rhs2 = gimple_assign_rhs2(stmt);
98115 +
98116 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
98117 + return false;
98118 +
98119 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
98120 +
98121 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
98122 + return false;
98123 +
98124 + rhs1_def_stmt = get_def_stmt(rhs1);
98125 + rhs2_def_stmt = get_def_stmt(rhs2);
98126 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
98127 + return false;
98128 +
98129 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
98130 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
98131 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
98132 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
98133 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
98134 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
98135 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
98136 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
98137 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
98138 + return false;
98139 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
98140 + return false;
98141 +
98142 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
98143 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
98144 + return true;
98145 +}
98146 +
98147 +static tree get_def_stmt_rhs(const_tree var)
98148 +{
98149 + tree rhs1, def_stmt_rhs1;
98150 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
98151 +
98152 + def_stmt = get_def_stmt(var);
98153 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
98154 +
98155 + rhs1 = gimple_assign_rhs1(def_stmt);
98156 + rhs1_def_stmt = get_def_stmt(rhs1);
98157 + if (!gimple_assign_cast_p(rhs1_def_stmt))
98158 + return rhs1;
98159 +
98160 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
98161 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
98162 +
98163 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
98164 + case GIMPLE_CALL:
98165 + case GIMPLE_NOP:
98166 + case GIMPLE_ASM:
98167 + return def_stmt_rhs1;
98168 + case GIMPLE_ASSIGN:
98169 + return rhs1;
98170 + default:
98171 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
98172 + gcc_unreachable();
98173 + }
98174 +}
98175 +
98176 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
98177 +{
98178 + tree new_rhs1, new_rhs2;
98179 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
98180 + gimple assign, stmt = get_def_stmt(lhs);
98181 + tree rhs1 = gimple_assign_rhs1(stmt);
98182 + tree rhs2 = gimple_assign_rhs2(stmt);
98183 +
98184 + if (!is_subtraction_special(stmt))
98185 + return NULL_TREE;
98186 +
98187 + new_rhs1 = expand(visited, rhs1);
98188 + new_rhs2 = expand(visited, rhs2);
98189 +
98190 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
98191 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
98192 +
98193 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
98194 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
98195 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
98196 + }
98197 +
98198 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
98199 + new_lhs = gimple_get_lhs(assign);
98200 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
98201 +
98202 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
98203 +}
98204 +
98205 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
98206 +{
98207 + const_gimple def_stmt;
98208 +
98209 + if (TREE_CODE(rhs) != SSA_NAME)
98210 + return false;
98211 +
98212 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
98213 + return false;
98214 +
98215 + def_stmt = get_def_stmt(rhs);
98216 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
98217 + return false;
98218 +
98219 + return true;
98220 +}
98221 +
98222 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
98223 +{
98224 + tree new_rhs, size_overflow_type, orig_rhs;
98225 + void (*gimple_assign_set_rhs)(gimple, tree);
98226 + tree rhs1 = gimple_assign_rhs1(stmt);
98227 + tree rhs2 = gimple_assign_rhs2(stmt);
98228 + tree lhs = gimple_get_lhs(stmt);
98229 +
98230 + if (change_rhs == NULL_TREE)
98231 + return create_assign(visited, stmt, lhs, AFTER_STMT);
98232 +
98233 + if (new_rhs2 == NULL_TREE) {
98234 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
98235 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
98236 + orig_rhs = rhs1;
98237 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
98238 + } else {
98239 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
98240 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
98241 + orig_rhs = rhs2;
98242 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
98243 + }
98244 +
98245 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
98246 +
98247 + if (check_overflow)
98248 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
98249 +
98250 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
98251 + gimple_assign_set_rhs(stmt, new_rhs);
98252 + update_stmt(stmt);
98253 +
98254 + return create_assign(visited, stmt, lhs, AFTER_STMT);
98255 +}
98256 +
98257 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
98258 +{
98259 + tree rhs1, rhs2, new_lhs;
98260 + gimple def_stmt = get_def_stmt(lhs);
98261 + tree new_rhs1 = NULL_TREE;
98262 + tree new_rhs2 = NULL_TREE;
98263 +
98264 + rhs1 = gimple_assign_rhs1(def_stmt);
98265 + rhs2 = gimple_assign_rhs2(def_stmt);
98266 +
98267 + /* no DImode/TImode division in the 32/64 bit kernel */
98268 + switch (gimple_assign_rhs_code(def_stmt)) {
98269 + case RDIV_EXPR:
98270 + case TRUNC_DIV_EXPR:
98271 + case CEIL_DIV_EXPR:
98272 + case FLOOR_DIV_EXPR:
98273 + case ROUND_DIV_EXPR:
98274 + case TRUNC_MOD_EXPR:
98275 + case CEIL_MOD_EXPR:
98276 + case FLOOR_MOD_EXPR:
98277 + case ROUND_MOD_EXPR:
98278 + case EXACT_DIV_EXPR:
98279 + case POINTER_PLUS_EXPR:
98280 + case BIT_AND_EXPR:
98281 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
98282 + default:
98283 + break;
98284 + }
98285 +
98286 + new_lhs = handle_integer_truncation(visited, lhs);
98287 + if (new_lhs != NULL_TREE)
98288 + return new_lhs;
98289 +
98290 + if (TREE_CODE(rhs1) == SSA_NAME)
98291 + new_rhs1 = expand(visited, rhs1);
98292 + if (TREE_CODE(rhs2) == SSA_NAME)
98293 + new_rhs2 = expand(visited, rhs2);
98294 +
98295 + if (is_a_neg_overflow(def_stmt, rhs2))
98296 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
98297 + if (is_a_neg_overflow(def_stmt, rhs1))
98298 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
98299 +
98300 + if (is_a_constant_overflow(def_stmt, rhs2))
98301 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
98302 + if (is_a_constant_overflow(def_stmt, rhs1))
98303 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
98304 +
98305 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
98306 +}
98307 +
98308 +#if BUILDING_GCC_VERSION >= 4007
98309 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
98310 +{
98311 + if (is_gimple_constant(rhs))
98312 + return cast_a_tree(size_overflow_type, rhs);
98313 + if (TREE_CODE(rhs) != SSA_NAME)
98314 + return NULL_TREE;
98315 + return expand(visited, rhs);
98316 +}
98317 +
98318 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
98319 +{
98320 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
98321 + gimple def_stmt = get_def_stmt(lhs);
98322 +
98323 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
98324 +
98325 + rhs1 = gimple_assign_rhs1(def_stmt);
98326 + rhs2 = gimple_assign_rhs2(def_stmt);
98327 + rhs3 = gimple_assign_rhs3(def_stmt);
98328 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
98329 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
98330 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
98331 +
98332 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
98333 +}
98334 +#endif
98335 +
98336 +static tree get_size_overflow_type(gimple stmt, const_tree node)
98337 +{
98338 + const_tree type;
98339 + tree new_type;
98340 +
98341 + gcc_assert(node != NULL_TREE);
98342 +
98343 + type = TREE_TYPE(node);
98344 +
98345 + if (gimple_plf(stmt, MY_STMT))
98346 + return TREE_TYPE(node);
98347 +
98348 + switch (TYPE_MODE(type)) {
98349 + case QImode:
98350 + new_type = intHI_type_node;
98351 + break;
98352 + case HImode:
98353 + new_type = intSI_type_node;
98354 + break;
98355 + case SImode:
98356 + new_type = intDI_type_node;
98357 + break;
98358 + case DImode:
98359 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
98360 + new_type = intDI_type_node;
98361 + else
98362 + new_type = intTI_type_node;
98363 + break;
98364 + default:
98365 + debug_tree((tree)node);
98366 + error("%s: unsupported gcc configuration.", __func__);
98367 + gcc_unreachable();
98368 + }
98369 +
98370 + if (TYPE_QUALS(type) != 0)
98371 + return build_qualified_type(new_type, TYPE_QUALS(type));
98372 + return new_type;
98373 +}
98374 +
98375 +static tree expand_visited(gimple def_stmt)
98376 +{
98377 + const_gimple next_stmt;
98378 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
98379 +
98380 + gsi_next(&gsi);
98381 + next_stmt = gsi_stmt(gsi);
98382 +
98383 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
98384 +
98385 + switch (gimple_code(next_stmt)) {
98386 + case GIMPLE_ASSIGN:
98387 + return gimple_get_lhs(next_stmt);
98388 + case GIMPLE_PHI:
98389 + return gimple_phi_result(next_stmt);
98390 + case GIMPLE_CALL:
98391 + return gimple_call_lhs(next_stmt);
98392 + default:
98393 + return NULL_TREE;
98394 + }
98395 +}
98396 +
98397 +static tree expand(struct pointer_set_t *visited, tree lhs)
98398 +{
98399 + gimple def_stmt;
98400 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
98401 +
98402 + if (is_gimple_constant(lhs))
98403 + return NULL_TREE;
98404 +
98405 + if (TREE_CODE(lhs) == ADDR_EXPR)
98406 + return NULL_TREE;
98407 +
98408 + if (code == REAL_TYPE)
98409 + return NULL_TREE;
98410 +
98411 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
98412 +
98413 + def_stmt = get_def_stmt(lhs);
98414 +
98415 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
98416 + return NULL_TREE;
98417 +
98418 + if (gimple_plf(def_stmt, MY_STMT))
98419 + return lhs;
98420 +
98421 + if (pointer_set_contains(visited, def_stmt))
98422 + return expand_visited(def_stmt);
98423 +
98424 + switch (gimple_code(def_stmt)) {
98425 + case GIMPLE_PHI:
98426 + return build_new_phi(visited, lhs);
98427 + case GIMPLE_CALL:
98428 + case GIMPLE_ASM:
98429 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
98430 + case GIMPLE_ASSIGN:
98431 + switch (gimple_num_ops(def_stmt)) {
98432 + case 2:
98433 + return handle_unary_ops(visited, def_stmt);
98434 + case 3:
98435 + return handle_binary_ops(visited, lhs);
98436 +#if BUILDING_GCC_VERSION >= 4007
98437 + case 4:
98438 + return handle_ternary_ops(visited, lhs);
98439 +#endif
98440 + }
98441 + default:
98442 + debug_gimple_stmt(def_stmt);
98443 + error("%s: unknown gimple code", __func__);
98444 + gcc_unreachable();
98445 + }
98446 +}
98447 +
98448 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
98449 +{
98450 + const_gimple assign;
98451 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
98452 + tree origtype = TREE_TYPE(origarg);
98453 +
98454 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
98455 +
98456 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
98457 +
98458 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
98459 + update_stmt(stmt);
98460 +}
98461 +
98462 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
98463 +{
98464 + const char *origid;
98465 + tree arg;
98466 + const_tree origarg;
98467 +
98468 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
98469 + return true;
98470 +
98471 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
98472 + while (origarg && *argnum) {
98473 + (*argnum)--;
98474 + origarg = TREE_CHAIN(origarg);
98475 + }
98476 +
98477 + gcc_assert(*argnum == 0);
98478 +
98479 + gcc_assert(origarg != NULL_TREE);
98480 + origid = NAME(origarg);
98481 + *argnum = 0;
98482 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
98483 + if (!strcmp(origid, NAME(arg)))
98484 + return true;
98485 + (*argnum)++;
98486 + }
98487 + return false;
98488 +}
98489 +
98490 +static bool skip_types(const_tree var)
98491 +{
98492 + const_tree type;
98493 +
98494 + switch (TREE_CODE(var)) {
98495 + case ADDR_EXPR:
98496 +#if BUILDING_GCC_VERSION >= 4006
98497 + case MEM_REF:
98498 +#endif
98499 + case ARRAY_REF:
98500 + case BIT_FIELD_REF:
98501 + case INDIRECT_REF:
98502 + case TARGET_MEM_REF:
98503 + case VAR_DECL:
98504 + return true;
98505 + default:
98506 + break;
98507 + }
98508 +
98509 + type = TREE_TYPE(TREE_TYPE(var));
98510 + if (!type)
98511 + return false;
98512 + switch (TREE_CODE(type)) {
98513 + case RECORD_TYPE:
98514 + return true;
98515 + default:
98516 + break;
98517 + }
98518 +
98519 + return false;
98520 +}
98521 +
98522 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
98523 +{
98524 + gimple phi = get_def_stmt(result);
98525 + unsigned int i, n = gimple_phi_num_args(phi);
98526 +
98527 + if (!phi)
98528 + return false;
98529 +
98530 + pointer_set_insert(visited, phi);
98531 + for (i = 0; i < n; i++) {
98532 + const_tree arg = gimple_phi_arg_def(phi, i);
98533 + if (pre_expand(visited, arg))
98534 + return true;
98535 + }
98536 + return false;
98537 +}
98538 +
98539 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
98540 +{
98541 + gimple def_stmt = get_def_stmt(lhs);
98542 + const_tree rhs;
98543 +
98544 + if (!def_stmt)
98545 + return false;
98546 +
98547 + rhs = gimple_assign_rhs1(def_stmt);
98548 + if (pre_expand(visited, rhs))
98549 + return true;
98550 + return false;
98551 +}
98552 +
98553 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
98554 +{
98555 + bool rhs1_found, rhs2_found;
98556 + gimple def_stmt = get_def_stmt(lhs);
98557 + const_tree rhs1, rhs2;
98558 +
98559 + if (!def_stmt)
98560 + return false;
98561 +
98562 + rhs1 = gimple_assign_rhs1(def_stmt);
98563 + rhs2 = gimple_assign_rhs2(def_stmt);
98564 + rhs1_found = pre_expand(visited, rhs1);
98565 + rhs2_found = pre_expand(visited, rhs2);
98566 +
98567 + return rhs1_found || rhs2_found;
98568 +}
98569 +
98570 +static const_tree search_field_decl(const_tree comp_ref)
98571 +{
98572 + const_tree field = NULL_TREE;
98573 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
98574 +
98575 + for (i = 0; i < len; i++) {
98576 + field = TREE_OPERAND(comp_ref, i);
98577 + if (TREE_CODE(field) == FIELD_DECL)
98578 + break;
98579 + }
98580 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
98581 + return field;
98582 +}
98583 +
98584 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
98585 +{
98586 + const_tree attr, p;
98587 +
98588 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
98589 + if (!attr || !TREE_VALUE(attr))
98590 + return MARKED_NO;
98591 +
98592 + p = TREE_VALUE(attr);
98593 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
98594 + return MARKED_NOT_INTENTIONAL;
98595 +
98596 + do {
98597 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
98598 + return MARKED_YES;
98599 + p = TREE_CHAIN(p);
98600 + } while (p);
98601 +
98602 + return MARKED_NO;
98603 +}
98604 +
98605 +static void print_missing_msg(tree func, unsigned int argnum)
98606 +{
98607 + unsigned int new_hash;
98608 + size_t len;
98609 + unsigned char tree_codes[CODES_LIMIT];
98610 + location_t loc = DECL_SOURCE_LOCATION(func);
98611 + const char *curfunc = get_asm_name(func);
98612 +
98613 + len = get_function_decl(func, tree_codes);
98614 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
98615 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
98616 +}
98617 +
98618 +static unsigned int search_missing_attribute(const_tree arg)
98619 +{
98620 + const_tree type = TREE_TYPE(arg);
98621 + tree func = get_original_function_decl(current_function_decl);
98622 + unsigned int argnum;
98623 + const struct size_overflow_hash *hash;
98624 +
98625 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
98626 +
98627 + if (TREE_CODE(type) == POINTER_TYPE)
98628 + return 0;
98629 +
98630 + argnum = find_arg_number(arg, func);
98631 + if (argnum == 0)
98632 + return 0;
98633 +
98634 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
98635 + return argnum;
98636 +
98637 + hash = get_function_hash(func);
98638 + if (!hash || !(hash->param & (1U << argnum))) {
98639 + print_missing_msg(func, argnum);
98640 + return 0;
98641 + }
98642 + return argnum;
98643 +}
98644 +
98645 +static bool is_already_marked(const_tree lhs)
98646 +{
98647 + unsigned int argnum;
98648 + const_tree fndecl;
98649 +
98650 + argnum = search_missing_attribute(lhs);
98651 + fndecl = get_original_function_decl(current_function_decl);
98652 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
98653 + return true;
98654 + return false;
98655 +}
98656 +
98657 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
98658 +{
98659 + const_gimple def_stmt;
98660 +
98661 + if (is_gimple_constant(lhs))
98662 + return false;
98663 +
98664 + if (skip_types(lhs))
98665 + return false;
98666 +
98667 + // skip char type (FIXME: only kernel)
98668 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
98669 + return false;
98670 +
98671 + if (TREE_CODE(lhs) == PARM_DECL)
98672 + return is_already_marked(lhs);
98673 +
98674 + if (TREE_CODE(lhs) == COMPONENT_REF) {
98675 + const_tree field, attr;
98676 +
98677 + field = search_field_decl(lhs);
98678 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
98679 + if (!attr || !TREE_VALUE(attr))
98680 + return false;
98681 + return true;
98682 + }
98683 +
98684 + def_stmt = get_def_stmt(lhs);
98685 +
98686 + if (!def_stmt)
98687 + return false;
98688 +
98689 + if (pointer_set_contains(visited, def_stmt))
98690 + return false;
98691 +
98692 + switch (gimple_code(def_stmt)) {
98693 + case GIMPLE_NOP:
98694 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
98695 + return is_already_marked(lhs);
98696 + return false;
98697 + case GIMPLE_PHI:
98698 + return walk_phi(visited, lhs);
98699 + case GIMPLE_CALL:
98700 + case GIMPLE_ASM:
98701 + return false;
98702 + case GIMPLE_ASSIGN:
98703 + switch (gimple_num_ops(def_stmt)) {
98704 + case 2:
98705 + return walk_unary_ops(visited, lhs);
98706 + case 3:
98707 + return walk_binary_ops(visited, lhs);
98708 + }
98709 + default:
98710 + debug_gimple_stmt((gimple)def_stmt);
98711 + error("%s: unknown gimple code", __func__);
98712 + gcc_unreachable();
98713 + }
98714 +}
98715 +
98716 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
98717 +{
98718 + struct pointer_set_t *visited;
98719 + bool is_found;
98720 + enum marked is_marked;
98721 + location_t loc;
98722 +
98723 + visited = pointer_set_create();
98724 + is_found = pre_expand(visited, arg);
98725 + pointer_set_destroy(visited);
98726 +
98727 + is_marked = mark_status(fndecl, argnum + 1);
98728 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
98729 + return true;
98730 +
98731 + if (is_found) {
98732 + loc = DECL_SOURCE_LOCATION(fndecl);
98733 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
98734 + return true;
98735 + }
98736 + return false;
98737 +}
98738 +
98739 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
98740 +{
98741 + struct pointer_set_t *visited;
98742 + tree arg, newarg;
98743 + bool match;
98744 +
98745 + match = get_function_arg(&argnum, fndecl);
98746 + if (!match)
98747 + return;
98748 + gcc_assert(gimple_call_num_args(stmt) > argnum);
98749 + arg = gimple_call_arg(stmt, argnum);
98750 + if (arg == NULL_TREE)
98751 + return;
98752 +
98753 + if (is_gimple_constant(arg))
98754 + return;
98755 +
98756 + if (search_attributes(fndecl, arg, argnum))
98757 + return;
98758 +
98759 + if (TREE_CODE(arg) != SSA_NAME)
98760 + return;
98761 +
98762 + check_arg_type(arg);
98763 +
98764 + visited = pointer_set_create();
98765 + newarg = expand(visited, arg);
98766 + pointer_set_destroy(visited);
98767 +
98768 + if (newarg == NULL_TREE)
98769 + return;
98770 +
98771 + change_function_arg(stmt, arg, argnum, newarg);
98772 +
98773 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
98774 +}
98775 +
98776 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
98777 +{
98778 + tree p = TREE_VALUE(attr);
98779 + do {
98780 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
98781 + p = TREE_CHAIN(p);
98782 + } while (p);
98783 +}
98784 +
98785 +static void handle_function_by_hash(gimple stmt, tree fndecl)
98786 +{
98787 + tree orig_fndecl;
98788 + unsigned int num;
98789 + const struct size_overflow_hash *hash;
98790 +
98791 + orig_fndecl = get_original_function_decl(fndecl);
98792 + if (C_DECL_IMPLICIT(orig_fndecl))
98793 + return;
98794 + hash = get_function_hash(orig_fndecl);
98795 + if (!hash)
98796 + return;
98797 +
98798 + for (num = 1; num <= MAX_PARAM; num++)
98799 + if (hash->param & (1U << num))
98800 + handle_function_arg(stmt, fndecl, num - 1);
98801 +}
98802 +
98803 +static void set_plf_false(void)
98804 +{
98805 + basic_block bb;
98806 +
98807 + FOR_ALL_BB(bb) {
98808 + gimple_stmt_iterator si;
98809 +
98810 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
98811 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
98812 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
98813 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
98814 + }
98815 +}
98816 +
98817 +static unsigned int handle_function(void)
98818 +{
98819 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
98820 +
98821 + set_plf_false();
98822 +
98823 + do {
98824 + gimple_stmt_iterator gsi;
98825 + next = bb->next_bb;
98826 +
98827 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
98828 + tree fndecl, attr;
98829 + gimple stmt = gsi_stmt(gsi);
98830 +
98831 + if (!(is_gimple_call(stmt)))
98832 + continue;
98833 + fndecl = gimple_call_fndecl(stmt);
98834 + if (fndecl == NULL_TREE)
98835 + continue;
98836 + if (gimple_call_num_args(stmt) == 0)
98837 + continue;
98838 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
98839 + if (!attr || !TREE_VALUE(attr))
98840 + handle_function_by_hash(stmt, fndecl);
98841 + else
98842 + handle_function_by_attribute(stmt, attr, fndecl);
98843 + gsi = gsi_for_stmt(stmt);
98844 + next = gimple_bb(stmt)->next_bb;
98845 + }
98846 + bb = next;
98847 + } while (bb);
98848 + return 0;
98849 +}
98850 +
98851 +static struct gimple_opt_pass size_overflow_pass = {
98852 + .pass = {
98853 + .type = GIMPLE_PASS,
98854 + .name = "size_overflow",
98855 +#if BUILDING_GCC_VERSION >= 4008
98856 + .optinfo_flags = OPTGROUP_NONE,
98857 +#endif
98858 + .gate = NULL,
98859 + .execute = handle_function,
98860 + .sub = NULL,
98861 + .next = NULL,
98862 + .static_pass_number = 0,
98863 + .tv_id = TV_NONE,
98864 + .properties_required = PROP_cfg,
98865 + .properties_provided = 0,
98866 + .properties_destroyed = 0,
98867 + .todo_flags_start = 0,
98868 + .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
98869 + }
98870 +};
98871 +
98872 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
98873 +{
98874 + tree fntype;
98875 +
98876 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
98877 +
98878 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
98879 + fntype = build_function_type_list(void_type_node,
98880 + const_char_ptr_type_node,
98881 + unsigned_type_node,
98882 + const_char_ptr_type_node,
98883 + const_char_ptr_type_node,
98884 + NULL_TREE);
98885 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
98886 +
98887 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
98888 + TREE_PUBLIC(report_size_overflow_decl) = 1;
98889 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
98890 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
98891 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
98892 +}
98893 +
98894 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
98895 +{
98896 + int i;
98897 + const char * const plugin_name = plugin_info->base_name;
98898 + const int argc = plugin_info->argc;
98899 + const struct plugin_argument * const argv = plugin_info->argv;
98900 + bool enable = true;
98901 +
98902 + struct register_pass_info size_overflow_pass_info = {
98903 + .pass = &size_overflow_pass.pass,
98904 + .reference_pass_name = "ssa",
98905 + .ref_pass_instance_number = 1,
98906 + .pos_op = PASS_POS_INSERT_AFTER
98907 + };
98908 +
98909 + if (!plugin_default_version_check(version, &gcc_version)) {
98910 + error(G_("incompatible gcc/plugin versions"));
98911 + return 1;
98912 + }
98913 +
98914 + for (i = 0; i < argc; ++i) {
98915 + if (!strcmp(argv[i].key, "no-size-overflow")) {
98916 + enable = false;
98917 + continue;
98918 + }
98919 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
98920 + }
98921 +
98922 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
98923 + if (enable) {
98924 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
98925 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
98926 + }
98927 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
98928 +
98929 + return 0;
98930 +}
98931 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
98932 new file mode 100644
98933 index 0000000..ac2901e
98934 --- /dev/null
98935 +++ b/tools/gcc/stackleak_plugin.c
98936 @@ -0,0 +1,327 @@
98937 +/*
98938 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
98939 + * Licensed under the GPL v2
98940 + *
98941 + * Note: the choice of the license means that the compilation process is
98942 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
98943 + * but for the kernel it doesn't matter since it doesn't link against
98944 + * any of the gcc libraries
98945 + *
98946 + * gcc plugin to help implement various PaX features
98947 + *
98948 + * - track lowest stack pointer
98949 + *
98950 + * TODO:
98951 + * - initialize all local variables
98952 + *
98953 + * BUGS:
98954 + * - none known
98955 + */
98956 +#include "gcc-plugin.h"
98957 +#include "config.h"
98958 +#include "system.h"
98959 +#include "coretypes.h"
98960 +#include "tree.h"
98961 +#include "tree-pass.h"
98962 +#include "flags.h"
98963 +#include "intl.h"
98964 +#include "toplev.h"
98965 +#include "plugin.h"
98966 +//#include "expr.h" where are you...
98967 +#include "diagnostic.h"
98968 +#include "plugin-version.h"
98969 +#include "tm.h"
98970 +#include "function.h"
98971 +#include "basic-block.h"
98972 +#include "gimple.h"
98973 +#include "rtl.h"
98974 +#include "emit-rtl.h"
98975 +
98976 +#if BUILDING_GCC_VERSION >= 4008
98977 +#define TODO_dump_func 0
98978 +#endif
98979 +
98980 +extern void print_gimple_stmt(FILE *, gimple, int, int);
98981 +
98982 +int plugin_is_GPL_compatible;
98983 +
98984 +static int track_frame_size = -1;
98985 +static const char track_function[] = "pax_track_stack";
98986 +static const char check_function[] = "pax_check_alloca";
98987 +static bool init_locals;
98988 +
98989 +static struct plugin_info stackleak_plugin_info = {
98990 + .version = "201302112000",
98991 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
98992 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
98993 +};
98994 +
98995 +static bool gate_stackleak_track_stack(void);
98996 +static unsigned int execute_stackleak_tree_instrument(void);
98997 +static unsigned int execute_stackleak_final(void);
98998 +
98999 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
99000 + .pass = {
99001 + .type = GIMPLE_PASS,
99002 + .name = "stackleak_tree_instrument",
99003 +#if BUILDING_GCC_VERSION >= 4008
99004 + .optinfo_flags = OPTGROUP_NONE,
99005 +#endif
99006 + .gate = gate_stackleak_track_stack,
99007 + .execute = execute_stackleak_tree_instrument,
99008 + .sub = NULL,
99009 + .next = NULL,
99010 + .static_pass_number = 0,
99011 + .tv_id = TV_NONE,
99012 + .properties_required = PROP_gimple_leh | PROP_cfg,
99013 + .properties_provided = 0,
99014 + .properties_destroyed = 0,
99015 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
99016 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
99017 + }
99018 +};
99019 +
99020 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
99021 + .pass = {
99022 + .type = RTL_PASS,
99023 + .name = "stackleak_final",
99024 +#if BUILDING_GCC_VERSION >= 4008
99025 + .optinfo_flags = OPTGROUP_NONE,
99026 +#endif
99027 + .gate = gate_stackleak_track_stack,
99028 + .execute = execute_stackleak_final,
99029 + .sub = NULL,
99030 + .next = NULL,
99031 + .static_pass_number = 0,
99032 + .tv_id = TV_NONE,
99033 + .properties_required = 0,
99034 + .properties_provided = 0,
99035 + .properties_destroyed = 0,
99036 + .todo_flags_start = 0,
99037 + .todo_flags_finish = TODO_dump_func
99038 + }
99039 +};
99040 +
99041 +static bool gate_stackleak_track_stack(void)
99042 +{
99043 + return track_frame_size >= 0;
99044 +}
99045 +
99046 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
99047 +{
99048 + gimple check_alloca;
99049 + tree fntype, fndecl, alloca_size;
99050 +
99051 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
99052 + fndecl = build_fn_decl(check_function, fntype);
99053 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
99054 +
99055 + // insert call to void pax_check_alloca(unsigned long size)
99056 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
99057 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
99058 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
99059 +}
99060 +
99061 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
99062 +{
99063 + gimple track_stack;
99064 + tree fntype, fndecl;
99065 +
99066 + fntype = build_function_type_list(void_type_node, NULL_TREE);
99067 + fndecl = build_fn_decl(track_function, fntype);
99068 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
99069 +
99070 + // insert call to void pax_track_stack(void)
99071 + track_stack = gimple_build_call(fndecl, 0);
99072 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
99073 +}
99074 +
99075 +#if BUILDING_GCC_VERSION == 4005
99076 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
99077 +{
99078 + tree fndecl;
99079 +
99080 + if (!is_gimple_call(stmt))
99081 + return false;
99082 + fndecl = gimple_call_fndecl(stmt);
99083 + if (!fndecl)
99084 + return false;
99085 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
99086 + return false;
99087 +// print_node(stderr, "pax", fndecl, 4);
99088 + return DECL_FUNCTION_CODE(fndecl) == code;
99089 +}
99090 +#endif
99091 +
99092 +static bool is_alloca(gimple stmt)
99093 +{
99094 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
99095 + return true;
99096 +
99097 +#if BUILDING_GCC_VERSION >= 4007
99098 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
99099 + return true;
99100 +#endif
99101 +
99102 + return false;
99103 +}
99104 +
99105 +static unsigned int execute_stackleak_tree_instrument(void)
99106 +{
99107 + basic_block bb, entry_bb;
99108 + bool prologue_instrumented = false, is_leaf = true;
99109 +
99110 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
99111 +
99112 + // 1. loop through BBs and GIMPLE statements
99113 + FOR_EACH_BB(bb) {
99114 + gimple_stmt_iterator gsi;
99115 +
99116 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
99117 + gimple stmt;
99118 +
99119 + stmt = gsi_stmt(gsi);
99120 +
99121 + if (is_gimple_call(stmt))
99122 + is_leaf = false;
99123 +
99124 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
99125 + if (!is_alloca(stmt))
99126 + continue;
99127 +
99128 + // 2. insert stack overflow check before each __builtin_alloca call
99129 + stackleak_check_alloca(&gsi);
99130 +
99131 + // 3. insert track call after each __builtin_alloca call
99132 + stackleak_add_instrumentation(&gsi);
99133 + if (bb == entry_bb)
99134 + prologue_instrumented = true;
99135 + }
99136 + }
99137 +
99138 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
99139 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
99140 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
99141 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
99142 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
99143 + return 0;
99144 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
99145 + return 0;
99146 +
99147 + // 4. insert track call at the beginning
99148 + if (!prologue_instrumented) {
99149 + gimple_stmt_iterator gsi;
99150 +
99151 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
99152 + if (dom_info_available_p(CDI_DOMINATORS))
99153 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
99154 + gsi = gsi_start_bb(bb);
99155 + stackleak_add_instrumentation(&gsi);
99156 + }
99157 +
99158 + return 0;
99159 +}
99160 +
99161 +static unsigned int execute_stackleak_final(void)
99162 +{
99163 + rtx insn, next;
99164 +
99165 + if (cfun->calls_alloca)
99166 + return 0;
99167 +
99168 + // keep calls only if function frame is big enough
99169 + if (get_frame_size() >= track_frame_size)
99170 + return 0;
99171 +
99172 + // 1. find pax_track_stack calls
99173 + for (insn = get_insns(); insn; insn = next) {
99174 + // 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))
99175 + rtx body;
99176 +
99177 + next = NEXT_INSN(insn);
99178 + if (!CALL_P(insn))
99179 + continue;
99180 + body = PATTERN(insn);
99181 + if (GET_CODE(body) != CALL)
99182 + continue;
99183 + body = XEXP(body, 0);
99184 + if (GET_CODE(body) != MEM)
99185 + continue;
99186 + body = XEXP(body, 0);
99187 + if (GET_CODE(body) != SYMBOL_REF)
99188 + continue;
99189 + if (strcmp(XSTR(body, 0), track_function))
99190 + continue;
99191 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
99192 + // 2. delete call
99193 + delete_insn_and_edges(insn);
99194 +#if BUILDING_GCC_VERSION >= 4007
99195 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
99196 + insn = next;
99197 + next = NEXT_INSN(insn);
99198 + delete_insn_and_edges(insn);
99199 + }
99200 +#endif
99201 + }
99202 +
99203 +// print_simple_rtl(stderr, get_insns());
99204 +// print_rtl(stderr, get_insns());
99205 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
99206 +
99207 + return 0;
99208 +}
99209 +
99210 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
99211 +{
99212 + const char * const plugin_name = plugin_info->base_name;
99213 + const int argc = plugin_info->argc;
99214 + const struct plugin_argument * const argv = plugin_info->argv;
99215 + int i;
99216 + struct register_pass_info stackleak_tree_instrument_pass_info = {
99217 + .pass = &stackleak_tree_instrument_pass.pass,
99218 +// .reference_pass_name = "tree_profile",
99219 + .reference_pass_name = "optimized",
99220 + .ref_pass_instance_number = 1,
99221 + .pos_op = PASS_POS_INSERT_BEFORE
99222 + };
99223 + struct register_pass_info stackleak_final_pass_info = {
99224 + .pass = &stackleak_final_rtl_opt_pass.pass,
99225 + .reference_pass_name = "final",
99226 + .ref_pass_instance_number = 1,
99227 + .pos_op = PASS_POS_INSERT_BEFORE
99228 + };
99229 +
99230 + if (!plugin_default_version_check(version, &gcc_version)) {
99231 + error(G_("incompatible gcc/plugin versions"));
99232 + return 1;
99233 + }
99234 +
99235 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
99236 +
99237 + for (i = 0; i < argc; ++i) {
99238 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
99239 + if (!argv[i].value) {
99240 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
99241 + continue;
99242 + }
99243 + track_frame_size = atoi(argv[i].value);
99244 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
99245 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
99246 + continue;
99247 + }
99248 + if (!strcmp(argv[i].key, "initialize-locals")) {
99249 + if (argv[i].value) {
99250 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
99251 + continue;
99252 + }
99253 + init_locals = true;
99254 + continue;
99255 + }
99256 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
99257 + }
99258 +
99259 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
99260 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
99261 +
99262 + return 0;
99263 +}
99264 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
99265 index 6789d78..4afd019e 100644
99266 --- a/tools/perf/util/include/asm/alternative-asm.h
99267 +++ b/tools/perf/util/include/asm/alternative-asm.h
99268 @@ -5,4 +5,7 @@
99269
99270 #define altinstruction_entry #
99271
99272 + .macro pax_force_retaddr rip=0, reload=0
99273 + .endm
99274 +
99275 #endif
99276 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
99277 index 1cd693a..f4a7b20 100644
99278 --- a/virt/kvm/kvm_main.c
99279 +++ b/virt/kvm/kvm_main.c
99280 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
99281
99282 static cpumask_var_t cpus_hardware_enabled;
99283 static int kvm_usage_count = 0;
99284 -static atomic_t hardware_enable_failed;
99285 +static atomic_unchecked_t hardware_enable_failed;
99286
99287 struct kmem_cache *kvm_vcpu_cache;
99288 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
99289
99290 -static __read_mostly struct preempt_ops kvm_preempt_ops;
99291 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
99292 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
99293 +static struct preempt_ops kvm_preempt_ops = {
99294 + .sched_in = kvm_sched_in,
99295 + .sched_out = kvm_sched_out,
99296 +};
99297
99298 struct dentry *kvm_debugfs_dir;
99299
99300 @@ -731,7 +736,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
99301 /* We can read the guest memory with __xxx_user() later on. */
99302 if (user_alloc &&
99303 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
99304 - !access_ok(VERIFY_WRITE,
99305 + !__access_ok(VERIFY_WRITE,
99306 (void __user *)(unsigned long)mem->userspace_addr,
99307 mem->memory_size)))
99308 goto out;
99309 @@ -1783,7 +1788,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
99310 return 0;
99311 }
99312
99313 -static struct file_operations kvm_vcpu_fops = {
99314 +static file_operations_no_const kvm_vcpu_fops __read_only = {
99315 .release = kvm_vcpu_release,
99316 .unlocked_ioctl = kvm_vcpu_ioctl,
99317 #ifdef CONFIG_COMPAT
99318 @@ -2304,7 +2309,7 @@ static int kvm_vm_mmap(struct file *file, struct vm_area_struct *vma)
99319 return 0;
99320 }
99321
99322 -static struct file_operations kvm_vm_fops = {
99323 +static file_operations_no_const kvm_vm_fops __read_only = {
99324 .release = kvm_vm_release,
99325 .unlocked_ioctl = kvm_vm_ioctl,
99326 #ifdef CONFIG_COMPAT
99327 @@ -2402,7 +2407,7 @@ out:
99328 return r;
99329 }
99330
99331 -static struct file_operations kvm_chardev_ops = {
99332 +static file_operations_no_const kvm_chardev_ops __read_only = {
99333 .unlocked_ioctl = kvm_dev_ioctl,
99334 .compat_ioctl = kvm_dev_ioctl,
99335 .llseek = noop_llseek,
99336 @@ -2428,7 +2433,7 @@ static void hardware_enable_nolock(void *junk)
99337
99338 if (r) {
99339 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
99340 - atomic_inc(&hardware_enable_failed);
99341 + atomic_inc_unchecked(&hardware_enable_failed);
99342 printk(KERN_INFO "kvm: enabling virtualization on "
99343 "CPU%d failed\n", cpu);
99344 }
99345 @@ -2482,10 +2487,10 @@ static int hardware_enable_all(void)
99346
99347 kvm_usage_count++;
99348 if (kvm_usage_count == 1) {
99349 - atomic_set(&hardware_enable_failed, 0);
99350 + atomic_set_unchecked(&hardware_enable_failed, 0);
99351 on_each_cpu(hardware_enable_nolock, NULL, 1);
99352
99353 - if (atomic_read(&hardware_enable_failed)) {
99354 + if (atomic_read_unchecked(&hardware_enable_failed)) {
99355 hardware_disable_all_nolock();
99356 r = -EBUSY;
99357 }
99358 @@ -2843,7 +2848,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
99359 kvm_arch_vcpu_put(vcpu);
99360 }
99361
99362 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99363 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99364 struct module *module)
99365 {
99366 int r;
99367 @@ -2879,7 +2884,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99368 if (!vcpu_align)
99369 vcpu_align = __alignof__(struct kvm_vcpu);
99370 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
99371 - 0, NULL);
99372 + SLAB_USERCOPY, NULL);
99373 if (!kvm_vcpu_cache) {
99374 r = -ENOMEM;
99375 goto out_free_3;
99376 @@ -2889,9 +2894,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99377 if (r)
99378 goto out_free;
99379
99380 + pax_open_kernel();
99381 kvm_chardev_ops.owner = module;
99382 kvm_vm_fops.owner = module;
99383 kvm_vcpu_fops.owner = module;
99384 + pax_close_kernel();
99385
99386 r = misc_register(&kvm_dev);
99387 if (r) {
99388 @@ -2901,9 +2908,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99389
99390 register_syscore_ops(&kvm_syscore_ops);
99391
99392 - kvm_preempt_ops.sched_in = kvm_sched_in;
99393 - kvm_preempt_ops.sched_out = kvm_sched_out;
99394 -
99395 r = kvm_init_debug();
99396 if (r) {
99397 printk(KERN_ERR "kvm: create debugfs files failed\n");